From: Ronnie Sahlberg Date: Thu, 17 May 2007 00:45:31 +0000 (+1000) Subject: add a control to shutdown/kill a node X-Git-Tag: tevent-0.9.20~348^2~2722^2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=cc760cf13ad9b09354664b028b407e84c9dea8b7;p=thirdparty%2Fsamba.git add a control to shutdown/kill a node (This used to be ctdb commit 3802f7304fd59d56062c855987e2561753e85a69) --- diff --git a/ctdb/common/ctdb_client.c b/ctdb/common/ctdb_client.c index d31ddd5861e..cde9584fb76 100644 --- a/ctdb/common/ctdb_client.c +++ b/ctdb/common/ctdb_client.c @@ -839,6 +839,27 @@ int ctdb_ctrl_status(struct ctdb_context *ctdb, uint32_t destnode, struct ctdb_s return 0; } +/* + shutdown a remote ctdb node + */ +int ctdb_ctrl_shutdown(struct ctdb_context *ctdb, struct timeval timeout, uint32_t destnode) +{ + int ret; + TDB_DATA data; + int32_t res; + + ZERO_STRUCT(data); + ret = ctdb_control(ctdb, destnode, 0, + CTDB_CONTROL_SHUTDOWN, CTDB_CTRL_FLAG_NOREPLY, data, + ctdb, &data, &res, &timeout, NULL); + if (ret != 0) { + DEBUG(0,(__location__ " ctdb_control for shutdown failed\n")); + return -1; + } + + return 0; +} + /* get vnn map from a remote node */ diff --git a/ctdb/common/ctdb_control.c b/ctdb/common/ctdb_control.c index 79e0eb64dc6..119ca858ea0 100644 --- a/ctdb/common/ctdb_control.c +++ b/ctdb/common/ctdb_control.c @@ -240,6 +240,9 @@ static int32_t ctdb_control_dispatch(struct ctdb_context *ctdb, CHECK_CONTROL_DATA_SIZE(sizeof(uint32_t)); return ctdb_control_set_recmode(ctdb, indata, errormsg); + case CTDB_CONTROL_SHUTDOWN: + exit(10); + default: DEBUG(0,(__location__ " Unknown CTDB control opcode %u\n", opcode)); return -1; diff --git a/ctdb/include/ctdb.h b/ctdb/include/ctdb.h index 9292fd6e532..59bfbdea115 100644 --- a/ctdb/include/ctdb.h +++ b/ctdb/include/ctdb.h @@ -203,6 +203,8 @@ struct ctdb_context *ctdb_cmdline_client(struct event_context *ev); struct ctdb_status; int ctdb_ctrl_status(struct ctdb_context *ctdb, uint32_t destnode, struct ctdb_status *status); +int ctdb_ctrl_shutdown(struct ctdb_context *ctdb, struct timeval timeout, uint32_t destnode); + struct ctdb_vnn_map; int ctdb_ctrl_getvnnmap(struct ctdb_context *ctdb, struct timeval timeout, uint32_t destnode, diff --git a/ctdb/include/ctdb_private.h b/ctdb/include/ctdb_private.h index ca045c18d1a..79be2e489c0 100644 --- a/ctdb/include/ctdb_private.h +++ b/ctdb/include/ctdb_private.h @@ -353,6 +353,7 @@ enum ctdb_controls {CTDB_CONTROL_PROCESS_EXISTS, CTDB_CONTROL_FREEZE, CTDB_CONTROL_THAW, CTDB_CONTROL_GET_VNN, + CTDB_CONTROL_SHUTDOWN, }; diff --git a/ctdb/tools/ctdb_control.c b/ctdb/tools/ctdb_control.c index 1c3e047033a..f8691fe5fdc 100644 --- a/ctdb/tools/ctdb_control.c +++ b/ctdb/tools/ctdb_control.c @@ -57,6 +57,7 @@ static void usage(void) " setrecmaster set recovery master\n" " attach attach a database\n" " getpid get the pid of a ctdb daemon\n" + " shutdown shutdown a remote ctdb\n" " freeze freeze a node\n" " thaw thaw a node\n" ); @@ -343,6 +344,30 @@ static int control_getpid(struct ctdb_context *ctdb, int argc, const char **argv return 0; } +/* + shutdown a daemon + */ +static int control_shutdown(struct ctdb_context *ctdb, int argc, const char **argv) +{ + uint32_t vnn; + int ret; + + + if (argc < 1) { + usage(); + } + + vnn = strtoul(argv[0], NULL, 0); + + ret = ctdb_ctrl_shutdown(ctdb, timeval_current_ofs(1, 0), vnn); + if (ret != 0) { + printf("Unable to shutdown node %u\n", vnn); + return ret; + } + + return 0; +} + /* display recovery mode of a remote node */ @@ -973,6 +998,7 @@ int main(int argc, const char *argv[]) { "attach", control_attach }, { "dumpmemory", control_dumpmemory }, { "getpid", control_getpid }, + { "shutdown", control_shutdown }, { "freeze", control_freeze }, { "thaw", control_thaw }, };