summaryrefslogtreecommitdiff
path: root/ctdb/tools/ctdb.c
diff options
context:
space:
mode:
authorMartin Schwenke <martin@meltin.net>2020-05-04 17:56:22 +1000
committerMartin Schwenke <martins@samba.org>2022-01-17 10:21:33 +0000
commit17ba15ccd88367dca82b0c4c8e4ff3f859896d87 (patch)
tree2ba048001942faf2f5e14a679340d7b8ea25182a /ctdb/tools/ctdb.c
parentec90f36cc6185fc6ed13164fb13ec3630aff68ad (diff)
downloadsamba-17ba15ccd88367dca82b0c4c8e4ff3f859896d87.tar.gz
ctdb-tools: Handle leader broadcasts in ctdb tool
Signed-off-by: Martin Schwenke <martin@meltin.net> Reviewed-by: Amitay Isaacs <amitay@gmail.com>
Diffstat (limited to 'ctdb/tools/ctdb.c')
-rw-r--r--ctdb/tools/ctdb.c33
1 files changed, 32 insertions, 1 deletions
diff --git a/ctdb/tools/ctdb.c b/ctdb/tools/ctdb.c
index 5f0c32b317d..21221fe9212 100644
--- a/ctdb/tools/ctdb.c
+++ b/ctdb/tools/ctdb.c
@@ -40,6 +40,7 @@
#include "common/logging.h"
#include "common/path.h"
#include "protocol/protocol.h"
+#include "protocol/protocol_basic.h"
#include "protocol/protocol_api.h"
#include "protocol/protocol_util.h"
#include "common/system_socket.h"
@@ -73,7 +74,7 @@ struct ctdb_context {
struct tevent_context *ev;
struct ctdb_client_context *client;
struct ctdb_node_map *nodemap;
- uint32_t pnn, cmd_pnn;
+ uint32_t pnn, cmd_pnn, leader_pnn;
uint64_t srvid;
};
@@ -724,6 +725,25 @@ static int run_helper(TALLOC_CTX *mem_ctx, const char *command,
return 0;
}
+static void leader_handler(uint64_t srvid,
+ TDB_DATA data,
+ void *private_data)
+{
+ struct ctdb_context *ctdb = talloc_get_type_abort(
+ private_data, struct ctdb_context);
+ uint32_t leader_pnn;
+ size_t np;
+ int ret;
+
+ ret = ctdb_uint32_pull(data.dptr, data.dsize, &leader_pnn, &np);
+ if (ret != 0) {
+ /* Ignore packet */
+ return;
+ }
+
+ ctdb->leader_pnn = leader_pnn;
+}
+
/*
* Command Functions
*/
@@ -6216,6 +6236,17 @@ static int process_command(const struct ctdb_cmd *cmd, int argc,
goto fail;
}
+ ctdb->leader_pnn = CTDB_UNKNOWN_PNN;
+ ret = ctdb_client_set_message_handler(ctdb->ev,
+ ctdb->client,
+ CTDB_SRVID_LEADER,
+ leader_handler,
+ ctdb);
+ if (ret != 0) {
+ fprintf(stderr, "Failed to setup leader handler\n");
+ goto fail;
+ }
+
ret = cmd->fn(tmp_ctx, ctdb, argc-1, argv+1);
talloc_free(tmp_ctx);
return ret;