ctdb-daemon: Factor out new function release_ip_post()
authorMartin Schwenke <martin@meltin.net>
Thu, 11 Aug 2016 03:57:43 +0000 (13:57 +1000)
committerMartin Schwenke <martins@samba.org>
Wed, 17 Aug 2016 21:00:26 +0000 (23:00 +0200)
This contains the cleanup that needs to be done after an IP address is
released from an interface.

state->vnn is set to the return value from release_ip_post(), which is
either the original VNN, or NULL if it was deleted.  This allows
correct handling of the in-flight flag in the destructor for state.

BUG: https://bugzilla.samba.org/show_bug.cgi?id=12158

Signed-off-by: Martin Schwenke <martin@meltin.net>
Reviewed-by: Amitay Isaacs <amitay@gmail.com>
ctdb/server/ctdb_takeover.c

index bbf38bad58137b203db2d0432a08045fb21b6e0d..1687bb495200ed1f8a8f3f6d354feea66b9b1429 100644 (file)
@@ -850,6 +850,32 @@ static void do_delete_ip(struct ctdb_context *ctdb, struct ctdb_vnn *vnn)
        talloc_free(vnn);
 }
 
+static struct ctdb_vnn *release_ip_post(struct ctdb_context *ctdb,
+                                       struct ctdb_vnn *vnn,
+                                       ctdb_sock_addr *addr)
+{
+       TDB_DATA data;
+
+       /* Send a message to all clients of this node telling them
+        * that the cluster has been reconfigured and they should
+        * close any connections on this IP address
+        */
+       data.dptr = (uint8_t *)ctdb_addr_to_str(addr);
+       data.dsize = strlen((char *)data.dptr)+1;
+       DEBUG(DEBUG_INFO, ("Sending RELEASE_IP message for %s\n", data.dptr));
+       ctdb_daemon_send_message(ctdb, ctdb->pnn, CTDB_SRVID_RELEASE_IP, data);
+
+       ctdb_vnn_unassign_iface(ctdb, vnn);
+
+       /* Process the IP if it has been marked for deletion */
+       if (vnn->delete_pending) {
+               do_delete_ip(ctdb, vnn);
+               return NULL;
+       }
+
+       return vnn;
+}
+
 /*
   called when releaseip event finishes
  */
@@ -858,7 +884,6 @@ static void release_ip_callback(struct ctdb_context *ctdb, int status,
 {
        struct takeover_callback_state *state = 
                talloc_get_type(private_data, struct takeover_callback_state);
-       TDB_DATA data;
 
        if (status == -ETIME) {
                ctdb_ban_self(ctdb);
@@ -876,23 +901,7 @@ static void release_ip_callback(struct ctdb_context *ctdb, int status,
                }
        }
 
-       /* send a message to all clients of this node telling them
-          that the cluster has been reconfigured and they should
-          release any sockets on this IP */
-       data.dptr = (uint8_t *) ctdb_addr_to_str(state->addr);
-       data.dsize = strlen((char *)data.dptr)+1;
-
-       DEBUG(DEBUG_INFO,(__location__ " sending RELEASE_IP for '%s'\n", data.dptr));
-
-       ctdb_daemon_send_message(ctdb, ctdb->pnn, CTDB_SRVID_RELEASE_IP, data);
-
-       ctdb_vnn_unassign_iface(ctdb, state->vnn);
-
-       /* Process the IP if it has been marked for deletion */
-       if (state->vnn->delete_pending) {
-               do_delete_ip(ctdb, state->vnn);
-               state->vnn = NULL;
-       }
+       state->vnn = release_ip_post(ctdb, state->vnn, state->addr);
 
        /* the control succeeded */
        ctdb_request_control_reply(ctdb, state->c, NULL, 0, NULL);