]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
ctdb-recoverd: Factor out fetching node map and local flags
authorMartin Schwenke <mschwenke@ddn.com>
Wed, 13 May 2026 12:02:19 +0000 (22:02 +1000)
committerStefan Metzmacher <metze@samba.org>
Thu, 6 Aug 2026 14:22:45 +0000 (14:22 +0000)
This will be used in more places.

Indexing by PNN is technically incorrect, so iterate to find the
correct slot in the nodemap.

BUG: https://bugzilla.samba.org/show_bug.cgi?id=16082

Signed-off-by: Martin Schwenke <mschwenke@ddn.com>
Reviewed-by: Amitay Isaacs <amitay@gmail.com>
ctdb/server/ctdb_recoverd.c

index aacf886dae89de240053af4a45aef8436a52cdfd..58aedbad92e8e3351504ca7c44470fbb8c43b4f9 100644 (file)
@@ -1275,6 +1275,37 @@ done:
        return ok;
 }
 
+static struct ctdb_node_map_old *update_node_map_and_flags(
+       struct ctdb_recoverd *rec)
+{
+       struct ctdb_context *ctdb = rec->ctdb;
+       struct ctdb_node_map_old *nodemap = NULL;
+       unsigned int i = 0;
+       int ret = 0;
+
+       ret = ctdb_ctrl_getnodemap(ctdb,
+                                  CONTROL_TIMEOUT(),
+                                  rec->pnn,
+                                  rec,
+                                  &nodemap);
+       if (ret != 0) {
+               return NULL;
+       }
+
+       talloc_free(rec->nodemap);
+       rec->nodemap = nodemap;
+
+       /* Remember this node's flags */
+       for (i = 0; i < nodemap->num; i++) {
+               if (nodemap->nodes[i].pnn == rec->pnn) {
+                       rec->node_flags = nodemap->nodes[i].flags;
+                       break;
+               }
+       }
+
+       return nodemap;
+}
+
 static int db_recovery_parallel(struct ctdb_recoverd *rec, TALLOC_CTX *mem_ctx)
 {
        const char *arg;
@@ -2590,21 +2621,11 @@ static void main_loop(struct ctdb_context *ctdb, struct ctdb_recoverd *rec,
                return;
        }
 
-       /* get nodemap */
-       ret = ctdb_ctrl_getnodemap(ctdb,
-                                  CONTROL_TIMEOUT(),
-                                  rec->pnn,
-                                  rec,
-                                  &nodemap);
-       if (ret != 0) {
+       nodemap = update_node_map_and_flags(rec);
+       if (nodemap == NULL) {
                DBG_ERR("Unable to get nodemap from node %"PRIu32"\n", rec->pnn);
                return;
        }
-       talloc_free(rec->nodemap);
-       rec->nodemap = nodemap;
-
-       /* remember our own node flags */
-       rec->node_flags = nodemap->nodes[rec->pnn].flags;
 
        ban_misbehaving_nodes(rec, &self_ban);
        if (self_ban) {