ctdbd: New control CTDB_CONTROL_IPREALLOCATED
authorMartin Schwenke <martin@meltin.net>
Fri, 19 Apr 2013 03:05:02 +0000 (13:05 +1000)
committerAmitay Isaacs <amitay@gmail.com>
Mon, 6 May 2013 03:38:21 +0000 (13:38 +1000)
This is an alternative to using ctdb_run_eventscripts() that can be
used when in recovery.

Signed-off-by: Martin Schwenke <martin@meltin.net>
(This used to be ctdb commit 27a44685f0d7a88804b61a1542bb42adc8f88cb1)

ctdb/include/ctdb_private.h
ctdb/include/ctdb_protocol.h
ctdb/server/ctdb_control.c
ctdb/server/ctdb_takeover.c
ctdb/server/eventscript.c

index 03e996bc7ebf6a162e43bd636a6ae7f05adeba2d..410e670fdadc17dcf0e551d6b385f3ef9b4b8a9f 100644 (file)
@@ -1102,6 +1102,9 @@ int32_t ctdb_control_release_ipv4(struct ctdb_context *ctdb,
                                 struct ctdb_req_control *c,
                                 TDB_DATA indata, 
                                 bool *async_reply);
+int32_t ctdb_control_ipreallocated(struct ctdb_context *ctdb, 
+                                struct ctdb_req_control *c,
+                                bool *async_reply);
 int32_t ctdb_control_start_recovery(struct ctdb_context *ctdb, 
                                 struct ctdb_req_control *c,
                                 bool *async_reply);
index 4755b4c18ba665ff8df8bd18bb01aff2eef23a55..728edc08b915a1c8f9f9dd2edaf32e7f161fba40 100644 (file)
@@ -404,6 +404,7 @@ enum ctdb_controls {CTDB_CONTROL_PROCESS_EXISTS          = 0,
                    CTDB_CONTROL_RELOAD_PUBLIC_IPS       = 134,
                    CTDB_CONTROL_TRAVERSE_ALL_EXT        = 135,
                    CTDB_CONTROL_RECEIVE_RECORDS         = 136,
+                   CTDB_CONTROL_IPREALLOCATED           = 137,
 };
 
 /*
index 0d0f61c07e352601f100a47fae240a29a2d0192e..4dff05e65f3749bc8d76df1ff97721844bb73a8b 100644 (file)
@@ -351,6 +351,10 @@ static int32_t ctdb_control_dispatch(struct ctdb_context *ctdb,
                CHECK_CONTROL_DATA_SIZE(sizeof(struct ctdb_public_ip));
                return ctdb_control_release_ip(ctdb, c, indata, async_reply);
 
+       case CTDB_CONTROL_IPREALLOCATED:
+               CHECK_CONTROL_DATA_SIZE(0);
+               return ctdb_control_ipreallocated(ctdb, c, async_reply);
+
        case CTDB_CONTROL_GET_PUBLIC_IPSv4:
                CHECK_CONTROL_DATA_SIZE(0);
                return ctdb_control_get_public_ipsv4(ctdb, c, outdata);
index 48704bda1cfc3c06fb3c90a69a2e1bbfb6871637..15a8bbb409d06280dd43e0d7f6192adaed4ce204 100644 (file)
@@ -3810,6 +3810,62 @@ int32_t ctdb_control_del_public_address(struct ctdb_context *ctdb, TDB_DATA inda
        return -1;
 }
 
+
+struct ipreallocated_callback_state {
+       struct ctdb_req_control *c;
+};
+
+static void ctdb_ipreallocated_callback(struct ctdb_context *ctdb,
+                                       int status, void *p)
+{
+       struct ipreallocated_callback_state *state =
+               talloc_get_type(p, struct ipreallocated_callback_state);
+
+       if (status != 0) {
+               DEBUG(DEBUG_ERR,
+                     (" \"ipreallocated\" event script failed (status %d)\n",
+                      status));
+               if (status == -ETIME) {
+                       ctdb_ban_self(ctdb);
+               }
+       }
+
+       ctdb_request_control_reply(ctdb, state->c, NULL, status, NULL);
+       talloc_free(state);
+}
+
+/* A control to run the ipreallocated event */
+int32_t ctdb_control_ipreallocated(struct ctdb_context *ctdb,
+                                  struct ctdb_req_control *c,
+                                  bool *async_reply)
+{
+       int ret;
+       struct ipreallocated_callback_state *state;
+
+       state = talloc(ctdb, struct ipreallocated_callback_state);
+       CTDB_NO_MEMORY(ctdb, state);
+
+       DEBUG(DEBUG_INFO,(__location__ " Running \"ipreallocated\" event\n"));
+
+       ret = ctdb_event_script_callback(ctdb, state,
+                                        ctdb_ipreallocated_callback, state,
+                                        false, CTDB_EVENT_IPREALLOCATED,
+                                        "%s", "");
+
+       if (ret != 0) {
+               DEBUG(DEBUG_ERR,("Failed to run \"ipreallocated\" event \n"));
+               talloc_free(state);
+               return -1;
+       }
+
+       /* tell the control that we will be reply asynchronously */
+       state->c    = talloc_steal(state, c);
+       *async_reply = true;
+
+       return 0;
+}
+
+
 /* This function is called from the recovery daemon to verify that a remote
    node has the expected ip allocation.
    This is verified against ctdb->ip_tree
index 41bf21db35d65992d1c4292b77067b6b9c2d2120..752543fbe5e646bd7d611a4a51f239943523a3a0 100644 (file)
@@ -716,6 +716,7 @@ static int ctdb_event_script_callback_v(struct ctdb_context *ctdb,
                        CTDB_EVENT_START_RECOVERY,
                        CTDB_EVENT_SHUTDOWN,
                        CTDB_EVENT_RELEASE_IP,
+                       CTDB_EVENT_IPREALLOCATED,
                        CTDB_EVENT_STOPPED
                };
                int i;