From: Ronnie Sahlberg Date: Wed, 6 Jun 2007 23:16:17 +0000 (+1000) Subject: add a control to permanently enable/disable a node X-Git-Tag: tevent-0.9.20~348^2~2544^2~1 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=9ff733c784bae7150e3772f3318ab8a6274aa81c;p=thirdparty%2Fsamba.git add a control to permanently enable/disable a node (This used to be ctdb commit d66fdba16ca22f62ddac6882a17614879b08a798) --- diff --git a/ctdb/common/ctdb_client.c b/ctdb/common/ctdb_client.c index eb3b67560f8..271a34085f9 100644 --- a/ctdb/common/ctdb_client.c +++ b/ctdb/common/ctdb_client.c @@ -1918,3 +1918,26 @@ int ctdb_ctrl_get_public_ips(struct ctdb_context *ctdb, return 0; } +/* + set/clear the permanent disabled bit on a remote node + */ +int ctdb_ctrl_permdisable(struct ctdb_context *ctdb, struct timeval timeout, uint32_t destnode, uint32_t mode) +{ + int ret; + TDB_DATA data; + int32_t res; + + data.dsize = sizeof(uint32_t); + data.dptr = (unsigned char *)&mode; + + ret = ctdb_control(ctdb, destnode, 0, + CTDB_CONTROL_PERMANENTLY_DISABLE, 0, data, + NULL, NULL, &res, &timeout, NULL); + if (ret != 0 || res != 0) { + DEBUG(0,(__location__ " ctdb_control for setpermdisable failed\n")); + return -1; + } + + return 0; +} + diff --git a/ctdb/common/ctdb_control.c b/ctdb/common/ctdb_control.c index ac2522131f6..83a4ee33a64 100644 --- a/ctdb/common/ctdb_control.c +++ b/ctdb/common/ctdb_control.c @@ -288,6 +288,15 @@ static int32_t ctdb_control_dispatch(struct ctdb_context *ctdb, case CTDB_CONTROL_LIST_TUNABLES: return ctdb_control_list_tunables(ctdb, outdata); + case CTDB_CONTROL_PERMANENTLY_DISABLE: + CHECK_CONTROL_DATA_SIZE(sizeof(uint32_t)); + if ( *(uint32_t *)indata.dptr ){ + ctdb->nodes[ctdb->vnn]->flags |= NODE_FLAGS_PERMANENTLY_DISABLED; + } else { + ctdb->nodes[ctdb->vnn]->flags &= ~NODE_FLAGS_PERMANENTLY_DISABLED; + } + return 0; + default: DEBUG(0,(__location__ " Unknown CTDB control opcode %u\n", opcode)); return -1; diff --git a/ctdb/common/ctdb_monitor.c b/ctdb/common/ctdb_monitor.c index 166ee65df96..8461dca242c 100644 --- a/ctdb/common/ctdb_monitor.c +++ b/ctdb/common/ctdb_monitor.c @@ -104,7 +104,12 @@ static void ctdb_health_callback(struct ctdb_context *ctdb, int status, void *p) timeval_current_ofs(ctdb->tunable.monitor_interval, 0), ctdb_check_health, ctdb); - if (status != 0 && !(node->flags & NODE_FLAGS_DISABLED)) { + if (node->flags & NODE_FLAGS_PERMANENTLY_DISABLED) { + if ( !(node->flags & NODE_FLAGS_DISABLED) ) { + DEBUG(0,("monitoring - node is permanently disabled\n")); + node->flags |= NODE_FLAGS_DISABLED; + } + } else if (status != 0 && !(node->flags & NODE_FLAGS_DISABLED)) { DEBUG(0,("monitor event failed - disabling node\n")); node->flags |= NODE_FLAGS_DISABLED; } else if (status == 0 && (node->flags & NODE_FLAGS_DISABLED)) { diff --git a/ctdb/include/ctdb.h b/ctdb/include/ctdb.h index 8a19c19ec53..4e8fe4fa3c0 100644 --- a/ctdb/include/ctdb.h +++ b/ctdb/include/ctdb.h @@ -351,6 +351,9 @@ int ctdb_ctrl_list_tunables(struct ctdb_context *ctdb, TALLOC_CTX *mem_ctx, const char ***list, uint32_t *count); - +int ctdb_ctrl_permdisable(struct ctdb_context *ctdb, + struct timeval timeout, + uint32_t destnode, + uint32_t mode); #endif diff --git a/ctdb/include/ctdb_private.h b/ctdb/include/ctdb_private.h index 0e5e361d70c..c22c8a6d996 100644 --- a/ctdb/include/ctdb_private.h +++ b/ctdb/include/ctdb_private.h @@ -111,8 +111,9 @@ struct ctdb_node { const char *name; /* for debug messages */ void *private_data; /* private to transport */ uint32_t vnn; -#define NODE_FLAGS_CONNECTED 0x00000001 -#define NODE_FLAGS_DISABLED 0x00000002 +#define NODE_FLAGS_CONNECTED 0x00000001 +#define NODE_FLAGS_DISABLED 0x00000002 +#define NODE_FLAGS_PERMANENTLY_DISABLED 0x00000004 uint32_t flags; /* used by the dead node monitoring */ @@ -412,6 +413,7 @@ enum ctdb_controls {CTDB_CONTROL_PROCESS_EXISTS = 0, CTDB_CONTROL_GET_TUNABLE = 49, CTDB_CONTROL_LIST_TUNABLES = 50, CTDB_CONTROL_GET_PUBLIC_IPS = 51, + CTDB_CONTROL_PERMANENTLY_DISABLE = 52, }; /* diff --git a/ctdb/tools/ctdb_control.c b/ctdb/tools/ctdb_control.c index d5ffbd96be1..b0771689ee0 100644 --- a/ctdb/tools/ctdb_control.c +++ b/ctdb/tools/ctdb_control.c @@ -297,7 +297,9 @@ static int control_status(struct ctdb_context *ctdb, int argc, const char **argv printf("Number of nodes:%d\n", nodemap->num); for(i=0;inum;i++){ const char *flags_str; - if (nodemap->nodes[i].flags & NODE_FLAGS_DISABLED) { + if (nodemap->nodes[i].flags & NODE_FLAGS_PERMANENTLY_DISABLED) { + flags_str = "PERM DISABLED"; + } else if (nodemap->nodes[i].flags & NODE_FLAGS_DISABLED) { flags_str = "DISABLED"; } else if (nodemap->nodes[i].flags & NODE_FLAGS_CONNECTED) { flags_str = "CONNECTED"; @@ -394,6 +396,38 @@ static int control_getpid(struct ctdb_context *ctdb, int argc, const char **argv return 0; } +/* + disable a remote node + */ +static int control_disable(struct ctdb_context *ctdb, int argc, const char **argv) +{ + int ret; + + ret = ctdb_ctrl_permdisable(ctdb, TIMELIMIT(), options.vnn, NODE_FLAGS_PERMANENTLY_DISABLED); + if (ret != 0) { + printf("Unable to disable node %u\n", options.vnn); + return ret; + } + + return 0; +} + +/* + enable a disabled remote node + */ +static int control_enable(struct ctdb_context *ctdb, int argc, const char **argv) +{ + int ret; + + ret = ctdb_ctrl_permdisable(ctdb, TIMELIMIT(), options.vnn, 0); + if (ret != 0) { + printf("Unable to enable node %u\n", options.vnn); + return ret; + } + + return 0; +} + /* shutdown a daemon */ @@ -835,6 +869,8 @@ static const struct { { "attach", control_attach, "attach to a database", "" }, { "dumpmemory", control_dumpmemory, "dump memory map to logs" }, { "getpid", control_getpid, "get ctdbd process ID" }, + { "disable", control_disable, "disable a node" }, + { "enable", control_enable, "enable a node" }, { "shutdown", control_shutdown, "shutdown ctdbd" }, { "recover", control_recover, "force recovery" }, { "freeze", control_freeze, "freeze all databases" },