]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
ctdb-tools: Handle leader broadcasts in ctdb tool
authorMartin Schwenke <martin@meltin.net>
Mon, 4 May 2020 07:56:22 +0000 (17:56 +1000)
committerMartin Schwenke <martins@samba.org>
Mon, 17 Jan 2022 10:21:33 +0000 (10:21 +0000)
Signed-off-by: Martin Schwenke <martin@meltin.net>
Reviewed-by: Amitay Isaacs <amitay@gmail.com>
ctdb/tools/ctdb.c

index 5f0c32b317da7308d8cd3f4981cc9d0ccb67a07e..21221fe9212c1e4d70ecf79eaa0316c84c1c66ca 100644 (file)
@@ -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;