From: Ronnie Sahlberg Date: Sun, 7 Oct 2007 23:47:20 +0000 (+1000) Subject: add a function in the ctdb tool to determine whether the local node is X-Git-Tag: tevent-0.9.20~348^2~2381^2~11 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=ab5d098bf666dc6093c8a56424f7df60b688f120;p=thirdparty%2Fsamba.git add a function in the ctdb tool to determine whether the local node is the recmaster or not. return 0 if the node is the recmaster and 1 (true) if it is not or if we could not communicate with the ctdb daemon. call it 'isnotrecmaster' to cope with that if the tool could not bind to the socket to tyalk to the daemon, the tool will automatically return an error and exit code 1 thus the tool will only return 0 if it could talk successfully to the local daemon and if the local daemon confirms this node is the recmaster (This used to be ctdb commit ae5fcb790b6c3985f514fa8a96bc00c2619f2a28) --- diff --git a/ctdb/tools/ctdb.c b/ctdb/tools/ctdb.c index ed544e5c41b..dbefaf946a9 100644 --- a/ctdb/tools/ctdb.c +++ b/ctdb/tools/ctdb.c @@ -2,6 +2,7 @@ ctdb control tool Copyright (C) Andrew Tridgell 2007 + Copyright (C) Ronnie Sahlberg 2007 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -812,6 +813,37 @@ static int control_getdbmap(struct ctdb_context *ctdb, int argc, const char **ar return 0; } +/* + check if the local node is recmaster or not + it will return 1 if this node is the recmaster and 0 if it is not + or if the local ctdb daemon could not be contacted + */ +static int control_isnotrecmaster(struct ctdb_context *ctdb, int argc, const char **argv) +{ + uint32_t mypnn, recmaster; + int ret; + + mypnn = ctdb_ctrl_getpnn(ctdb, TIMELIMIT(), options.pnn); + if (mypnn == -1) { + printf("Failed to get pnn of node\n"); + return 1; + } + + ret = ctdb_ctrl_getrecmaster(ctdb, ctdb, TIMELIMIT(), options.pnn, &recmaster); + if (ret != 0) { + printf("Failed to get the recmaster\n"); + return 1; + } + + if (recmaster != mypnn) { + printf("this node is not the recmaster\n"); + return 1; + } + + printf("this node is the recmaster\n"); + return 0; +} + /* ping a node */ @@ -1037,6 +1069,7 @@ static const struct { { "recover", control_recover, true, "force recovery" }, { "freeze", control_freeze, true, "freeze all databases" }, { "thaw", control_thaw, true, "thaw all databases" }, + { "isnotrecmaster", control_isnotrecmaster, false, "check if the local node is recmaster or not" }, { "killtcp", kill_tcp, false, "kill a tcp connection.", " " }, { "tickle", tickle_tcp, false, "send a tcp tickle ack", " " }, { "gettickles", control_get_tickles, false, "get the list of tickles registered for this ip", "" },