]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
ctdb-daemon: Factor out a function to get node structure from PNN
authorMartin Schwenke <martin@meltin.net>
Fri, 9 Jul 2021 04:01:33 +0000 (14:01 +1000)
committerAmitay Isaacs <amitay@samba.org>
Thu, 9 Sep 2021 01:46:49 +0000 (01:46 +0000)
BUG: https://bugzilla.samba.org/show_bug.cgi?id=14784
Signed-off-by: Martin Schwenke <martin@meltin.net>
Reviewed-by: Amitay Isaacs <amitay@gmail.com>
ctdb/include/ctdb_private.h
ctdb/server/ctdb_daemon.c

index 8eb6686f953a3ac2fe9b8adfe46a6f84484d17d4..f5e647f08a544348d065b25c5e671c7dd24c202b 100644 (file)
@@ -565,6 +565,8 @@ int daemon_deregister_message_handler(struct ctdb_context *ctdb,
 void daemon_tunnel_handler(uint64_t tunnel_id, TDB_DATA data,
                           void *private_data);
 
+struct ctdb_node *ctdb_find_node(struct ctdb_context *ctdb, uint32_t pnn);
+
 int ctdb_start_daemon(struct ctdb_context *ctdb,
                      bool interactive,
                      bool test_mode_enabled);
index 3071e3cad54d8791383afe62526eba6a0f915091..e204bae73ad82d54bb33c12ca48c4250054501a7 100644 (file)
@@ -1235,19 +1235,40 @@ failed:
        return -1;
 }
 
-static void initialise_node_flags (struct ctdb_context *ctdb)
+struct ctdb_node *ctdb_find_node(struct ctdb_context *ctdb, uint32_t pnn)
 {
        struct ctdb_node *node = NULL;
        unsigned int i;
 
+       if (pnn == CTDB_CURRENT_NODE) {
+               pnn = ctdb->pnn;
+       }
+
        /* Always found: PNN correctly set just before this is called */
        for (i = 0; i < ctdb->num_nodes; i++) {
                node = ctdb->nodes[i];
-               if (ctdb->pnn == node->pnn) {
-                       break;
+               if (pnn == node->pnn) {
+                       return node;
                }
        }
 
+       return NULL;
+}
+
+static void initialise_node_flags (struct ctdb_context *ctdb)
+{
+       struct ctdb_node *node = NULL;
+
+       node = ctdb_find_node(ctdb, CTDB_CURRENT_NODE);
+       /*
+        * PNN correctly set just before this is called so always
+        * found but keep static analysers happy...
+        */
+       if (node == NULL) {
+               DBG_ERR("Unable to find current node\n");
+               return;
+       }
+
        node->flags &= ~NODE_FLAGS_DISCONNECTED;
 
        /* do we start out in DISABLED mode? */