From def5f4b1bfeeddba97141a3d3c08ac5a1187ce32 Mon Sep 17 00:00:00 2001 From: Amitay Isaacs Date: Mon, 12 Sep 2016 11:25:11 +1000 Subject: [PATCH] ctdb-daemon: Drop implementation of eventscript controls Following controls are now implemented by event daemon - RUN_EVENTSCRIPTS - GET_EVENT_SCRIPT_STATUS - ENABLE_SCRIPT - DISABLE_SCRIPT Signed-off-by: Amitay Isaacs Reviewed-by: Martin Schwenke --- ctdb/include/ctdb_private.h | 11 --- ctdb/server/ctdb_control.c | 13 ++- ctdb/server/eventscript.c | 233 -------------------------------------------- 3 files changed, 6 insertions(+), 251 deletions(-) diff --git a/ctdb/include/ctdb_private.h b/ctdb/include/ctdb_private.h index 63735898037..e464e349b18 100644 --- a/ctdb/include/ctdb_private.h +++ b/ctdb/include/ctdb_private.h @@ -995,10 +995,6 @@ void ctdb_local_remove_from_delete_queue(struct ctdb_db_context *ctdb_db, /* from eventscript.c */ -int32_t ctdb_control_get_event_script_status(struct ctdb_context *ctdb, - uint32_t call_type, - TDB_DATA *outdata); - int ctdb_event_script_callback(struct ctdb_context *ctdb, TALLOC_CTX *mem_ctx, void (*callback)(struct ctdb_context *, @@ -1014,11 +1010,4 @@ int ctdb_event_script_args(struct ctdb_context *ctdb, int ctdb_event_script(struct ctdb_context *ctdb, enum ctdb_event call); -int32_t ctdb_run_eventscripts(struct ctdb_context *ctdb, - struct ctdb_req_control_old *c, - TDB_DATA data, bool *async_reply); - -int32_t ctdb_control_enable_script(struct ctdb_context *ctdb, TDB_DATA indata); -int32_t ctdb_control_disable_script(struct ctdb_context *ctdb, TDB_DATA indata); - #endif diff --git a/ctdb/server/ctdb_control.c b/ctdb/server/ctdb_control.c index 4c6648380a6..de86a18c632 100644 --- a/ctdb/server/ctdb_control.c +++ b/ctdb/server/ctdb_control.c @@ -332,9 +332,9 @@ static int32_t ctdb_control_dispatch(struct ctdb_context *ctdb, CHECK_CONTROL_DATA_SIZE(0); ctdb_enable_monitoring(ctdb); return 0; - - case CTDB_CONTROL_RUN_EVENTSCRIPTS: - return ctdb_run_eventscripts(ctdb, c, indata, async_reply); + + case CTDB_CONTROL_RUN_EVENTSCRIPTS: + return control_not_implemented("RUN_EVENTSCRIPTS", NULL); case CTDB_CONTROL_DISABLE_MONITOR: CHECK_CONTROL_DATA_SIZE(0); @@ -496,8 +496,7 @@ static int32_t ctdb_control_dispatch(struct ctdb_context *ctdb, return ctdb_control_recd_ping(ctdb); case CTDB_CONTROL_GET_EVENT_SCRIPT_STATUS: - CHECK_CONTROL_DATA_SIZE(sizeof(uint32_t)); - return ctdb_control_get_event_script_status(ctdb, *(uint32_t *)indata.dptr, outdata); + return control_not_implemented("GET_EVENT_SCRIPT_STATUS", NULL); case CTDB_CONTROL_RECD_RECLOCK_LATENCY: CHECK_CONTROL_DATA_SIZE(sizeof(double)); @@ -551,10 +550,10 @@ static int32_t ctdb_control_dispatch(struct ctdb_context *ctdb, } case CTDB_CONTROL_ENABLE_SCRIPT: - return ctdb_control_enable_script(ctdb, indata); + return control_not_implemented("ENABLE_SCRIPT", NULL); case CTDB_CONTROL_DISABLE_SCRIPT: - return ctdb_control_disable_script(ctdb, indata); + return control_not_implemented("DISABLE_SCRIPT", NULL); case CTDB_CONTROL_SET_BAN_STATE: CHECK_CONTROL_DATA_SIZE(sizeof(struct ctdb_ban_state)); diff --git a/ctdb/server/eventscript.c b/ctdb/server/eventscript.c index 8f6ffd18829..579ca5cc32b 100644 --- a/ctdb/server/eventscript.c +++ b/ctdb/server/eventscript.c @@ -96,24 +96,6 @@ static void log_event_script_output(const char *str, uint16_t len, void *p) memcpy(current->output + slen, str, min); } -int32_t ctdb_control_get_event_script_status(struct ctdb_context *ctdb, - uint32_t call_type, - TDB_DATA *outdata) -{ - if (call_type >= CTDB_EVENT_MAX) { - return -1; - } - - if (ctdb->last_status[call_type] == NULL) { - /* If it's never been run, return nothing so they can tell. */ - outdata->dsize = 0; - } else { - outdata->dsize = talloc_get_size(ctdb->last_status[call_type]); - outdata->dptr = (uint8_t *)ctdb->last_status[call_type]; - } - return 0; -} - /* To ignore directory entry return 0, else return non-zero */ static int script_filter(const struct dirent *de) { @@ -994,218 +976,3 @@ int ctdb_event_script(struct ctdb_context *ctdb, enum ctdb_event call) /* GCC complains about empty format string, so use %s and "". */ return ctdb_event_script_args(ctdb, call, "%s", ""); } - -struct eventscript_callback_state { - struct ctdb_req_control_old *c; -}; - -/* - called when a forced eventscript run has finished - */ -static void run_eventscripts_callback(struct ctdb_context *ctdb, int status, - void *private_data) -{ - const char *errmsg = NULL; - - struct eventscript_callback_state *state = - talloc_get_type(private_data, struct eventscript_callback_state); - - if (status != 0) { - if (status == -ECANCELED) { - DEBUG(DEBUG_WARNING, - (__location__ " Eventscript cancelled\n")); - errmsg = "cancelled"; - } else { - DEBUG(DEBUG_ERR, - (__location__ " Failed to run eventscripts\n")); - } - } - - ctdb_request_control_reply(ctdb, state->c, NULL, status, errmsg); - /* This will free the struct ctdb_event_script_state we are in! */ - talloc_free(state); - return; -} - - -/* Returns rest of string, or NULL if no match. */ -static const char *get_call(const char *p, enum ctdb_event *call) -{ - unsigned int len; - - /* Skip any initial whitespace. */ - p += strspn(p, " \t"); - - /* See if we match any. */ - for (*call = 0; *call < CTDB_EVENT_MAX; (*call)++) { - len = strlen(ctdb_eventscript_call_names[*call]); - if (strncmp(p, ctdb_eventscript_call_names[*call], len) == 0) { - /* If end of string or whitespace, we're done. */ - if (strcspn(p + len, " \t") == 0) { - return p + len; - } - } - } - return NULL; -} - -/* - A control to force running of the eventscripts from the ctdb client tool -*/ -int32_t ctdb_run_eventscripts(struct ctdb_context *ctdb, - struct ctdb_req_control_old *c, - TDB_DATA indata, bool *async_reply) -{ - int ret; - struct eventscript_callback_state *state; - const char *options; - enum ctdb_event call; - - /* Figure out what call they want. */ - options = get_call((const char *)indata.dptr, &call); - if (!options) { - DEBUG(DEBUG_ERR, (__location__ " Invalid event name \"%s\"\n", (const char *)indata.dptr)); - return -1; - } - - if (ctdb->recovery_mode != CTDB_RECOVERY_NORMAL) { - DEBUG(DEBUG_ERR, (__location__ " Aborted running eventscript \"%s\" while in RECOVERY mode\n", indata.dptr)); - return -1; - } - - state = talloc(ctdb->event_script_ctx, struct eventscript_callback_state); - CTDB_NO_MEMORY(ctdb, state); - - state->c = NULL; - - DEBUG(DEBUG_NOTICE,("Running eventscripts with arguments %s\n", indata.dptr)); - - ret = ctdb_event_script_callback(ctdb, - ctdb, run_eventscripts_callback, state, - call, "%s", options); - - if (ret != 0) { - DEBUG(DEBUG_ERR,(__location__ " Failed to run eventscripts with arguments %s\n", indata.dptr)); - talloc_free(state); - return -1; - } - - /* tell ctdb_control.c that we will be replying asynchronously */ - *async_reply = true; - state->c = talloc_steal(state, c); - return 0; -} - - - -int32_t ctdb_control_enable_script(struct ctdb_context *ctdb, TDB_DATA indata) -{ - const char *script; - struct stat st; - char *filename; - TALLOC_CTX *tmp_ctx = talloc_new(ctdb); - - script = (char *)indata.dptr; - if (indata.dsize == 0) { - DEBUG(DEBUG_ERR,(__location__ " No script specified.\n")); - talloc_free(tmp_ctx); - return -1; - } - if (indata.dptr[indata.dsize - 1] != '\0') { - DEBUG(DEBUG_ERR,(__location__ " String is not null terminated.\n")); - talloc_free(tmp_ctx); - return -1; - } - if (index(script,'/') != NULL) { - DEBUG(DEBUG_ERR,(__location__ " Script name contains '/'. Failed to enable script %s\n", script)); - talloc_free(tmp_ctx); - return -1; - } - - - if (stat(ctdb->event_script_dir, &st) != 0 && - errno == ENOENT) { - DEBUG(DEBUG_CRIT,("No event script directory found at '%s'\n", ctdb->event_script_dir)); - talloc_free(tmp_ctx); - return -1; - } - - - filename = talloc_asprintf(tmp_ctx, "%s/%s", ctdb->event_script_dir, script); - if (filename == NULL) { - DEBUG(DEBUG_ERR,(__location__ " Failed to create script path\n")); - talloc_free(tmp_ctx); - return -1; - } - - if (stat(filename, &st) != 0) { - DEBUG(DEBUG_ERR,("Could not stat event script %s. Failed to enable script.\n", filename)); - talloc_free(tmp_ctx); - return -1; - } - - if (chmod(filename, st.st_mode | S_IXUSR) == -1) { - DEBUG(DEBUG_ERR,("Could not chmod %s. Failed to enable script.\n", filename)); - talloc_free(tmp_ctx); - return -1; - } - - talloc_free(tmp_ctx); - return 0; -} - -int32_t ctdb_control_disable_script(struct ctdb_context *ctdb, TDB_DATA indata) -{ - const char *script; - struct stat st; - char *filename; - TALLOC_CTX *tmp_ctx = talloc_new(ctdb); - - script = (char *)indata.dptr; - if (indata.dsize == 0) { - DEBUG(DEBUG_ERR,(__location__ " No script specified.\n")); - talloc_free(tmp_ctx); - return -1; - } - if (indata.dptr[indata.dsize - 1] != '\0') { - DEBUG(DEBUG_ERR,(__location__ " String is not null terminated.\n")); - talloc_free(tmp_ctx); - return -1; - } - if (index(script,'/') != NULL) { - DEBUG(DEBUG_ERR,(__location__ " Script name contains '/'. Failed to disable script %s\n", script)); - talloc_free(tmp_ctx); - return -1; - } - - - if (stat(ctdb->event_script_dir, &st) != 0 && - errno == ENOENT) { - DEBUG(DEBUG_CRIT,("No event script directory found at '%s'\n", ctdb->event_script_dir)); - talloc_free(tmp_ctx); - return -1; - } - - - filename = talloc_asprintf(tmp_ctx, "%s/%s", ctdb->event_script_dir, script); - if (filename == NULL) { - DEBUG(DEBUG_ERR,(__location__ " Failed to create script path\n")); - talloc_free(tmp_ctx); - return -1; - } - - if (stat(filename, &st) != 0) { - DEBUG(DEBUG_ERR,("Could not stat event script %s. Failed to disable script.\n", filename)); - talloc_free(tmp_ctx); - return -1; - } - - if (chmod(filename, st.st_mode & ~(S_IXUSR|S_IXGRP|S_IXOTH)) == -1) { - DEBUG(DEBUG_ERR,("Could not chmod %s. Failed to disable script.\n", filename)); - talloc_free(tmp_ctx); - return -1; - } - - talloc_free(tmp_ctx); - return 0; -} -- 2.11.4.GIT