From: Martin Schwenke Date: Fri, 19 Apr 2013 03:05:02 +0000 (+1000) Subject: ctdbd: New control CTDB_CONTROL_IPREALLOCATED X-Git-Url: http://git.samba.org/?p=metze%2Fsamba%2Fwip.git;a=commitdiff_plain;h=2e59cd54281a6a852c6037d68a3973feec60b7c8 ctdbd: New control CTDB_CONTROL_IPREALLOCATED This is an alternative to using ctdb_run_eventscripts() that can be used when in recovery. Signed-off-by: Martin Schwenke (This used to be ctdb commit 27a44685f0d7a88804b61a1542bb42adc8f88cb1) --- diff --git a/ctdb/include/ctdb_private.h b/ctdb/include/ctdb_private.h index 03e996bc7ebf..410e670fdadc 100644 --- a/ctdb/include/ctdb_private.h +++ b/ctdb/include/ctdb_private.h @@ -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); diff --git a/ctdb/include/ctdb_protocol.h b/ctdb/include/ctdb_protocol.h index 4755b4c18ba6..728edc08b915 100644 --- a/ctdb/include/ctdb_protocol.h +++ b/ctdb/include/ctdb_protocol.h @@ -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, }; /* diff --git a/ctdb/server/ctdb_control.c b/ctdb/server/ctdb_control.c index 0d0f61c07e35..4dff05e65f37 100644 --- a/ctdb/server/ctdb_control.c +++ b/ctdb/server/ctdb_control.c @@ -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); diff --git a/ctdb/server/ctdb_takeover.c b/ctdb/server/ctdb_takeover.c index 48704bda1cfc..15a8bbb409d0 100644 --- a/ctdb/server/ctdb_takeover.c +++ b/ctdb/server/ctdb_takeover.c @@ -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 diff --git a/ctdb/server/eventscript.c b/ctdb/server/eventscript.c index 41bf21db35d6..752543fbe5e6 100644 --- a/ctdb/server/eventscript.c +++ b/ctdb/server/eventscript.c @@ -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;