The branch, master has been updated
       via  be293a125fc ctdb-tests: Add new tool unit tests to cover UNKNOWN 
state
       via  794f1258029 ctdb-tool: Add UNKNOWN pseudo state
       via  428bc71f98f ctdb-tests: Add runstate handling to fake ctdbd
       via  05601cebc91 ctdb-tests: Return error on empty fake ctdbd 
configuration blocks
      from  fbf134c8d9e s3:libads: Check if we have a valid sockaddr

https://git.samba.org/?p=samba.git;a=shortlog;h=master


- Log -----------------------------------------------------------------
commit be293a125fc222867ca1c96e3898073e58f5fa0c
Author: Martin Schwenke <mar...@meltin.net>
Date:   Fri May 27 08:38:11 2022 +1000

    ctdb-tests: Add new tool unit tests to cover UNKNOWN state
    
    Signed-off-by: Vinit Agnihotri <vagniho...@ddn.com>
    Signed-off-by: Martin Schwenke <mar...@meltin.net>
    Reviewed-by: Amitay Isaacs <ami...@gmail.com>
    
    Autobuild-User(master): Amitay Isaacs <ami...@samba.org>
    Autobuild-Date(master): Tue Jun 28 10:16:59 UTC 2022 on sn-devel-184

commit 794f125802969a6b99f2758f70d7c2318309d924
Author: Vinit Agnihotri <vagniho...@ddn.com>
Date:   Tue Apr 26 17:20:21 2022 +1000

    ctdb-tool: Add UNKNOWN pseudo state
    
    When a node is starting, CTDB reports remote nodes as unhealthy by
    default.  This can be misleading.
    
    To hide this, report an "UNKNOWN" pseudo state when a remote node is
    not disconnected and the runstate is less than or equal to
    "FIRST_RECOVERY".
    
    Signed-off-by: Vinit Agnihotri <vagniho...@ddn.com>
    Signed-off-by: Martin Schwenke <mar...@meltin.net>
    Reviewed-by: Amitay Isaacs <ami...@gmail.com>

commit 428bc71f98fd560e1d8ea17fd76b4a34ac9421c6
Author: Vinit Agnihotri <vagniho...@ddn.com>
Date:   Tue Apr 26 17:20:21 2022 +1000

    ctdb-tests: Add runstate handling to fake ctdbd
    
    Signed-off-by: Vinit Agnihotri <vagniho...@ddn.com>
    Signed-off-by: Martin Schwenke <mar...@meltin.net>
    Reviewed-by: Amitay Isaacs <ami...@gmail.com>

commit 05601cebc91e21a65837fcd8fc4635660f7d6ca1
Author: Martin Schwenke <mar...@meltin.net>
Date:   Mon Jun 27 10:34:13 2022 +1000

    ctdb-tests: Return error on empty fake ctdbd configuration blocks
    
    These would be unintended errors.  The block should be omitted to keep
    the default value.
    
    Signed-off-by: Martin Schwenke <mar...@meltin.net>
    Reviewed-by: Amitay Isaacs <ami...@gmail.com>

-----------------------------------------------------------------------

Summary of changes:
 ctdb/tests/UNIT/tool/ctdb.nodestatus.001.sh        |  8 +--
 ctdb/tests/UNIT/tool/ctdb.nodestatus.002.sh        |  8 +--
 ctdb/tests/UNIT/tool/ctdb.nodestatus.003.sh        |  8 +--
 ctdb/tests/UNIT/tool/ctdb.nodestatus.004.sh        |  4 +-
 ctdb/tests/UNIT/tool/ctdb.nodestatus.005.sh        |  4 +-
 ctdb/tests/UNIT/tool/ctdb.nodestatus.006.sh        |  4 +-
 ctdb/tests/UNIT/tool/ctdb.nodestatus.007.sh        | 36 ++++++++++
 ctdb/tests/UNIT/tool/ctdb.status.001.sh            |  8 +--
 ctdb/tests/UNIT/tool/ctdb.status.002.sh            |  8 +--
 .../{ctdb.status.002.sh => ctdb.status.003.sh}     | 15 ++--
 ctdb/tests/scripts/integration.bash                | 16 ++---
 ctdb/tests/src/fake_ctdbd.c                        | 70 ++++++++++++++++--
 ctdb/tools/ctdb.c                                  | 83 ++++++++++++++++++++--
 ctdb/tools/ctdb_lvs                                |  8 +--
 ctdb/tools/ctdb_natgw                              | 10 +--
 15 files changed, 232 insertions(+), 58 deletions(-)
 create mode 100755 ctdb/tests/UNIT/tool/ctdb.nodestatus.007.sh
 copy ctdb/tests/UNIT/tool/{ctdb.status.002.sh => ctdb.status.003.sh} (65%)


Changeset truncated at 500 lines:

diff --git a/ctdb/tests/UNIT/tool/ctdb.nodestatus.001.sh 
b/ctdb/tests/UNIT/tool/ctdb.nodestatus.001.sh
index 2217afcc0b9..3c754e2a838 100755
--- a/ctdb/tests/UNIT/tool/ctdb.nodestatus.001.sh
+++ b/ctdb/tests/UNIT/tool/ctdb.nodestatus.001.sh
@@ -25,9 +25,9 @@ EOF
 simple_test all
 
 required_result 0 <<EOF
-|Node|IP|Disconnected|Banned|Disabled|Unhealthy|Stopped|Inactive|PartiallyOnline|ThisNode|
-|0|192.168.20.41|0|0|0|0|0|0|0|N|
-|1|192.168.20.42|0|0|0|0|0|0|0|N|
-|2|192.168.20.43|0|0|0|0|0|0|0|Y|
+|Node|IP|Disconnected|Unknown|Banned|Disabled|Unhealthy|Stopped|Inactive|PartiallyOnline|ThisNode|
+|0|192.168.20.41|0|0|0|0|0|0|0|0|N|
+|1|192.168.20.42|0|0|0|0|0|0|0|0|N|
+|2|192.168.20.43|0|0|0|0|0|0|0|0|Y|
 EOF
 simple_test -X all
diff --git a/ctdb/tests/UNIT/tool/ctdb.nodestatus.002.sh 
b/ctdb/tests/UNIT/tool/ctdb.nodestatus.002.sh
index c1706fd98e7..a5981dffa52 100755
--- a/ctdb/tests/UNIT/tool/ctdb.nodestatus.002.sh
+++ b/ctdb/tests/UNIT/tool/ctdb.nodestatus.002.sh
@@ -25,9 +25,9 @@ EOF
 simple_test all
 
 required_result 1 <<EOF
-|Node|IP|Disconnected|Banned|Disabled|Unhealthy|Stopped|Inactive|PartiallyOnline|ThisNode|
-|0|192.168.20.41|0|0|0|0|0|0|0|N|
-|1|192.168.20.42|1|0|0|0|0|1|0|N|
-|2|192.168.20.43|0|0|0|0|0|0|0|Y|
+|Node|IP|Disconnected|Unknown|Banned|Disabled|Unhealthy|Stopped|Inactive|PartiallyOnline|ThisNode|
+|0|192.168.20.41|0|0|0|0|0|0|0|0|N|
+|1|192.168.20.42|1|0|0|0|0|0|1|0|N|
+|2|192.168.20.43|0|0|0|0|0|0|0|0|Y|
 EOF
 simple_test -X all
diff --git a/ctdb/tests/UNIT/tool/ctdb.nodestatus.003.sh 
b/ctdb/tests/UNIT/tool/ctdb.nodestatus.003.sh
index 5912e6501aa..52c2691876f 100755
--- a/ctdb/tests/UNIT/tool/ctdb.nodestatus.003.sh
+++ b/ctdb/tests/UNIT/tool/ctdb.nodestatus.003.sh
@@ -25,9 +25,9 @@ EOF
 simple_test all
 
 required_result 2 <<EOF
-|Node|IP|Disconnected|Banned|Disabled|Unhealthy|Stopped|Inactive|PartiallyOnline|ThisNode|
-|0|192.168.20.41|0|0|0|1|0|0|0|N|
-|1|192.168.20.42|0|0|0|0|0|0|0|N|
-|2|192.168.20.43|0|0|0|0|0|0|0|Y|
+|Node|IP|Disconnected|Unknown|Banned|Disabled|Unhealthy|Stopped|Inactive|PartiallyOnline|ThisNode|
+|0|192.168.20.41|0|0|0|0|1|0|0|0|N|
+|1|192.168.20.42|0|0|0|0|0|0|0|0|N|
+|2|192.168.20.43|0|0|0|0|0|0|0|0|Y|
 EOF
 simple_test -X all
diff --git a/ctdb/tests/UNIT/tool/ctdb.nodestatus.004.sh 
b/ctdb/tests/UNIT/tool/ctdb.nodestatus.004.sh
index 01ccd5129b4..c060fb98b90 100755
--- a/ctdb/tests/UNIT/tool/ctdb.nodestatus.004.sh
+++ b/ctdb/tests/UNIT/tool/ctdb.nodestatus.004.sh
@@ -22,7 +22,7 @@ EOF
 simple_test
 
 required_result 0 <<EOF
-|Node|IP|Disconnected|Banned|Disabled|Unhealthy|Stopped|Inactive|PartiallyOnline|ThisNode|
-|2|192.168.20.43|0|0|0|0|0|0|0|Y|
+|Node|IP|Disconnected|Unknown|Banned|Disabled|Unhealthy|Stopped|Inactive|PartiallyOnline|ThisNode|
+|2|192.168.20.43|0|0|0|0|0|0|0|0|Y|
 EOF
 simple_test -X
diff --git a/ctdb/tests/UNIT/tool/ctdb.nodestatus.005.sh 
b/ctdb/tests/UNIT/tool/ctdb.nodestatus.005.sh
index 0cd24ba9cab..59f6905b059 100755
--- a/ctdb/tests/UNIT/tool/ctdb.nodestatus.005.sh
+++ b/ctdb/tests/UNIT/tool/ctdb.nodestatus.005.sh
@@ -22,7 +22,7 @@ EOF
 simple_test 0
 
 required_result 2 <<EOF
-|Node|IP|Disconnected|Banned|Disabled|Unhealthy|Stopped|Inactive|PartiallyOnline|ThisNode|
-|0|192.168.20.41|0|0|0|1|0|0|0|N|
+|Node|IP|Disconnected|Unknown|Banned|Disabled|Unhealthy|Stopped|Inactive|PartiallyOnline|ThisNode|
+|0|192.168.20.41|0|0|0|0|1|0|0|0|N|
 EOF
 simple_test -X 0
diff --git a/ctdb/tests/UNIT/tool/ctdb.nodestatus.006.sh 
b/ctdb/tests/UNIT/tool/ctdb.nodestatus.006.sh
index ec189fc4690..7d744510d53 100755
--- a/ctdb/tests/UNIT/tool/ctdb.nodestatus.006.sh
+++ b/ctdb/tests/UNIT/tool/ctdb.nodestatus.006.sh
@@ -22,8 +22,8 @@ EOF
 simple_test 0
 
 required_result 36 <<EOF
-|Node|IP|Disconnected|Banned|Disabled|Unhealthy|Stopped|Inactive|PartiallyOnline|ThisNode|
-|0|192.168.20.41|0|0|1|0|1|1|0|N|
+|Node|IP|Disconnected|Unknown|Banned|Disabled|Unhealthy|Stopped|Inactive|PartiallyOnline|ThisNode|
+|0|192.168.20.41|0|0|0|1|0|1|1|0|N|
 EOF
 simple_test -X 0
 
diff --git a/ctdb/tests/UNIT/tool/ctdb.nodestatus.007.sh 
b/ctdb/tests/UNIT/tool/ctdb.nodestatus.007.sh
new file mode 100755
index 00000000000..c96df4d9616
--- /dev/null
+++ b/ctdb/tests/UNIT/tool/ctdb.nodestatus.007.sh
@@ -0,0 +1,36 @@
+#!/bin/sh
+
+. "${TEST_SCRIPTS_DIR}/unit.sh"
+
+define_test "all, 3 nodes, 1 unhealthy, runstate init"
+
+setup_ctdbd <<EOF
+NODEMAP
+0       192.168.20.41   0x2
+1       192.168.20.42   0x0
+2       192.168.20.43   0x0     CURRENT RECMASTER
+
+IFACES
+:Name:LinkStatus:References:
+:eth2:1:2:
+:eth1:1:4:
+
+RUNSTATE
+INIT
+EOF
+
+required_result 64 <<EOF
+Number of nodes:3
+pnn:0 192.168.20.41    UNKNOWN
+pnn:1 192.168.20.42    UNKNOWN
+pnn:2 192.168.20.43    OK (THIS NODE)
+EOF
+simple_test all
+
+required_result 64 <<EOF
+|Node|IP|Disconnected|Unknown|Banned|Disabled|Unhealthy|Stopped|Inactive|PartiallyOnline|ThisNode|
+|0|192.168.20.41|0|1|0|0|0|0|0|0|N|
+|1|192.168.20.42|0|1|0|0|0|0|0|0|N|
+|2|192.168.20.43|0|0|0|0|0|0|0|0|Y|
+EOF
+simple_test -X all
diff --git a/ctdb/tests/UNIT/tool/ctdb.status.001.sh 
b/ctdb/tests/UNIT/tool/ctdb.status.001.sh
index 0742bd870a2..62c1dc7c98a 100755
--- a/ctdb/tests/UNIT/tool/ctdb.status.001.sh
+++ b/ctdb/tests/UNIT/tool/ctdb.status.001.sh
@@ -38,9 +38,9 @@ EOF
 simple_test
 
 required_result 0 <<EOF
-|Node|IP|Disconnected|Banned|Disabled|Unhealthy|Stopped|Inactive|PartiallyOnline|ThisNode|
-|0|192.168.20.41|0|0|0|0|0|0|0|Y|
-|1|192.168.20.42|0|0|0|0|0|0|0|N|
-|2|192.168.20.43|0|0|0|0|0|0|0|N|
+|Node|IP|Disconnected|Unknown|Banned|Disabled|Unhealthy|Stopped|Inactive|PartiallyOnline|ThisNode|
+|0|192.168.20.41|0|0|0|0|0|0|0|0|Y|
+|1|192.168.20.42|0|0|0|0|0|0|0|0|N|
+|2|192.168.20.43|0|0|0|0|0|0|0|0|N|
 EOF
 simple_test -X
diff --git a/ctdb/tests/UNIT/tool/ctdb.status.002.sh 
b/ctdb/tests/UNIT/tool/ctdb.status.002.sh
index 259e91438db..0cce4435ee4 100755
--- a/ctdb/tests/UNIT/tool/ctdb.status.002.sh
+++ b/ctdb/tests/UNIT/tool/ctdb.status.002.sh
@@ -38,9 +38,9 @@ EOF
 simple_test
 
 required_result 0 <<EOF
-|Node|IP|Disconnected|Banned|Disabled|Unhealthy|Stopped|Inactive|PartiallyOnline|ThisNode|
-|0|192.168.20.41|0|0|0|1|0|0|0|N|
-|1|192.168.20.42|0|0|0|0|0|0|0|Y|
-|2|192.168.20.43|0|0|0|0|0|0|0|N|
+|Node|IP|Disconnected|Unknown|Banned|Disabled|Unhealthy|Stopped|Inactive|PartiallyOnline|ThisNode|
+|0|192.168.20.41|0|0|0|0|1|0|0|0|N|
+|1|192.168.20.42|0|0|0|0|0|0|0|0|Y|
+|2|192.168.20.43|0|0|0|0|0|0|0|0|N|
 EOF
 simple_test -X
diff --git a/ctdb/tests/UNIT/tool/ctdb.status.002.sh 
b/ctdb/tests/UNIT/tool/ctdb.status.003.sh
similarity index 65%
copy from ctdb/tests/UNIT/tool/ctdb.status.002.sh
copy to ctdb/tests/UNIT/tool/ctdb.status.003.sh
index 259e91438db..67a2966ea4d 100755
--- a/ctdb/tests/UNIT/tool/ctdb.status.002.sh
+++ b/ctdb/tests/UNIT/tool/ctdb.status.003.sh
@@ -20,13 +20,16 @@ IFACES
 :Name:LinkStatus:References:
 :eth2:1:2:
 :eth1:1:4:
+
+RUNSTATE
+FIRST_RECOVERY
 EOF
 
 required_result 0 <<EOF
 Number of nodes:3
-pnn:0 192.168.20.41    UNHEALTHY
+pnn:0 192.168.20.41    UNKNOWN
 pnn:1 192.168.20.42    OK (THIS NODE)
-pnn:2 192.168.20.43    OK
+pnn:2 192.168.20.43    UNKNOWN
 Generation:654321
 Size:3
 hash:0 lmaster:0
@@ -38,9 +41,9 @@ EOF
 simple_test
 
 required_result 0 <<EOF
-|Node|IP|Disconnected|Banned|Disabled|Unhealthy|Stopped|Inactive|PartiallyOnline|ThisNode|
-|0|192.168.20.41|0|0|0|1|0|0|0|N|
-|1|192.168.20.42|0|0|0|0|0|0|0|Y|
-|2|192.168.20.43|0|0|0|0|0|0|0|N|
+|Node|IP|Disconnected|Unknown|Banned|Disabled|Unhealthy|Stopped|Inactive|PartiallyOnline|ThisNode|
+|0|192.168.20.41|0|1|0|0|0|0|0|0|N|
+|1|192.168.20.42|0|0|0|0|0|0|0|0|Y|
+|2|192.168.20.43|0|1|0|0|0|0|0|0|N|
 EOF
 simple_test -X
diff --git a/ctdb/tests/scripts/integration.bash 
b/ctdb/tests/scripts/integration.bash
index eb3db1e1849..dbf9af0b346 100644
--- a/ctdb/tests/scripts/integration.bash
+++ b/ctdb/tests/scripts/integration.bash
@@ -446,16 +446,16 @@ node_has_status ()
 
        local bits
        case "$status" in
-       unhealthy)    bits="?|?|?|1|*" ;;
-       healthy)      bits="?|?|?|0|*" ;;
+       unhealthy)    bits="?|?|?|?|1|*" ;;
+       healthy)      bits="?|?|?|?|0|*" ;;
        disconnected) bits="1|*" ;;
        connected)    bits="0|*" ;;
-       banned)       bits="?|1|*" ;;
-       unbanned)     bits="?|0|*" ;;
-       disabled)     bits="?|?|1|*" ;;
-       enabled)      bits="?|?|0|*" ;;
-       stopped)      bits="?|?|?|?|1|*" ;;
-       notstopped)   bits="?|?|?|?|0|*" ;;
+       banned)       bits="?|?|1|*" ;;
+       unbanned)     bits="?|?|0|*" ;;
+       disabled)     bits="?|?|?|1|*" ;;
+       enabled)      bits="?|?|?|0|*" ;;
+       stopped)      bits="?|?|?|?|?|1|*" ;;
+       notstopped)   bits="?|?|?|?|?|0|*" ;;
        *)
                echo "node_has_status: unknown status \"$status\""
                return 1
diff --git a/ctdb/tests/src/fake_ctdbd.c b/ctdb/tests/src/fake_ctdbd.c
index 4d5c41f3fd2..a04ad853306 100644
--- a/ctdb/tests/src/fake_ctdbd.c
+++ b/ctdb/tests/src/fake_ctdbd.c
@@ -272,6 +272,10 @@ static bool nodemap_parse(struct node_map *node_map)
                node_map->num_nodes += 1;
        }
 
+       if (node_map->num_nodes == 0) {
+               goto fail;
+       }
+
        DEBUG(DEBUG_INFO, ("Parsing nodemap done\n"));
        return true;
 
@@ -521,6 +525,10 @@ static bool interfaces_parse(struct interface_map 
*iface_map)
                iface_map->num += 1;
        }
 
+       if (iface_map->num == 0) {
+               goto fail;
+       }
+
        DEBUG(DEBUG_INFO, ("Parsing interfaces done\n"));
        return true;
 
@@ -588,6 +596,10 @@ static bool vnnmap_parse(struct vnn_map *vnn_map)
                vnn_map->size += 1;
        }
 
+       if (vnn_map->size == 0) {
+               goto fail;
+       }
+
        DEBUG(DEBUG_INFO, ("Parsing vnnmap done\n"));
        return true;
 
@@ -606,8 +618,7 @@ static bool reclock_parse(struct ctdbd_context *ctdb)
        }
 
        if (line[0] == '\n') {
-               /* Recovery lock remains unset */
-               goto ok;
+               goto fail;
        }
 
        /* Get rid of pesky newline */
@@ -619,7 +630,7 @@ static bool reclock_parse(struct ctdbd_context *ctdb)
        if (ctdb->reclock == NULL) {
                goto fail;
        }
-ok:
+
        /* Swallow possible blank line following section.  Picky
         * compiler settings don't allow the return value to be
         * ignored, so make the compiler happy.
@@ -745,6 +756,10 @@ static bool dbmap_parse(struct database_map *db_map)
                DLIST_ADD_END(db_map->db, db);
        }
 
+       if (db_map->db == NULL) {
+               goto fail;
+       }
+
        DEBUG(DEBUG_INFO, ("Parsing dbmap done\n"));
        return true;
 
@@ -1046,7 +1061,7 @@ static bool public_ips_parse(struct ctdbd_context *ctdb,
 
        ctdb->known_ips = ipalloc_read_known_ips(ctdb, numnodes, false);
 
-       status = (ctdb->known_ips != NULL);
+       status = (ctdb->known_ips != NULL && ctdb->known_ips->num != 0);
 
        if (status) {
                D_INFO("Parsing public IPs done\n");
@@ -1139,6 +1154,10 @@ static bool control_failures_parse(struct ctdbd_context 
*ctdb)
                DLIST_ADD(ctdb->control_failures, failure);
        }
 
+       if (ctdb->control_failures == NULL) {
+               goto fail;
+       }
+
        D_INFO("Parsing fake control failures done\n");
        return true;
 
@@ -1147,6 +1166,44 @@ fail:
        return false;
 }
 
+static bool runstate_parse(struct ctdbd_context *ctdb)
+{
+       char line[1024];
+       char *t;
+
+       if (fgets(line, sizeof(line), stdin) == NULL) {
+               goto fail;
+       }
+
+       if (line[0] == '\n') {
+               goto fail;
+       }
+
+       /* Get rid of pesky newline */
+       if ((t = strchr(line, '\n')) != NULL) {
+               *t = '\0';
+       }
+
+       ctdb->runstate = ctdb_runstate_from_string(line);
+       if (ctdb->runstate == CTDB_RUNSTATE_UNKNOWN) {
+               goto fail;
+       }
+
+       /* Swallow possible blank line following section.  Picky
+        * compiler settings don't allow the return value to be
+        * ignored, so make the compiler happy.
+        */
+       if (fgets(line, sizeof(line), stdin) == NULL) {
+               ;
+       }
+       D_INFO("Parsing runstate done\n");
+       return true;
+
+fail:
+       D_ERR("Parsing runstate failed\n");
+       return false;
+}
+
 /*
  * Manage clients
  */
@@ -1246,6 +1303,8 @@ static struct ctdbd_context *ctdbd_setup(TALLOC_CTX 
*mem_ctx,
                goto fail;
        }
 
+       ctdb->runstate = CTDB_RUNSTATE_RUNNING;
+
        while (fgets(line, sizeof(line), stdin) != NULL) {
                char *t;
 
@@ -1268,6 +1327,8 @@ static struct ctdbd_context *ctdbd_setup(TALLOC_CTX 
*mem_ctx,
                        status = reclock_parse(ctdb);
                } else if (strcmp(line, "CONTROLFAILS") == 0) {
                        status = control_failures_parse(ctdb);
+               } else if (strcmp(line, "RUNSTATE") == 0) {
+                       status = runstate_parse(ctdb);
                } else {
                        fprintf(stderr, "Unknown line %s\n", line);
                        status = false;
@@ -1288,7 +1349,6 @@ static struct ctdbd_context *ctdbd_setup(TALLOC_CTX 
*mem_ctx,
        ctdb->recovery_end_time = tevent_timeval_current();
 
        ctdb->log_level = DEBUG_ERR;
-       ctdb->runstate = CTDB_RUNSTATE_RUNNING;
 
        ctdb_tunable_set_defaults(&ctdb->tun_list);
 
diff --git a/ctdb/tools/ctdb.c b/ctdb/tools/ctdb.c
index b5303289f38..dd2245ecfa6 100644
--- a/ctdb/tools/ctdb.c
+++ b/ctdb/tools/ctdb.c
@@ -52,6 +52,8 @@
 #define SRVID_CTDB_TOOL    (CTDB_SRVID_TOOL_RANGE | 0x0001000000000000LL)
 #define SRVID_CTDB_PUSHDB  (CTDB_SRVID_TOOL_RANGE | 0x0002000000000000LL)
 
+#define NODE_FLAGS_UNKNOWN 0x00000040
+
 static struct {
        const char *debuglevelstr;
        int timelimit;
@@ -111,6 +113,7 @@ static const char *pretty_print_flags(TALLOC_CTX *mem_ctx, 
uint32_t flags)
                const char *name;
        } flag_names[] = {
                { NODE_FLAGS_DISCONNECTED,          "DISCONNECTED" },
+               { NODE_FLAGS_UNKNOWN,               "UNKNOWN" },
                { NODE_FLAGS_PERMANENTLY_DISABLED,  "DISABLED" },
                { NODE_FLAGS_BANNED,                "BANNED" },
                { NODE_FLAGS_UNHEALTHY,             "UNHEALTHY" },
@@ -367,6 +370,64 @@ done:
        return true;
 }
 
+/*
+ *  Remote nodes are initialised as UNHEALTHY in the daemon and their
+ *  true status is udpated after they are connected.  However, there
+ *  is a small window when a healthy node may be shown as unhealthy
+ *  between connecting and the status update.  Hide this for nodes
+ *  that are not DISCONNECTED nodes by reporting them as UNKNOWN until
+ *  the runstate passes FIRST_RECOVERY.  Code paths where this is used
+ *  do not make any control decisions depending upon unknown/unhealthy
+ *  state.
+ */
+static struct ctdb_node_map *get_nodemap_unknown(
+       TALLOC_CTX *mem_ctx,
+       struct ctdb_context *ctdb,
+       struct ctdb_node_map *nodemap_in)
+{
+       unsigned int i;
+       int ret;
+       enum ctdb_runstate runstate;
+       struct ctdb_node_map *nodemap;
+
+       ret = ctdb_ctrl_get_runstate(mem_ctx,
+                                    ctdb->ev,
+                                    ctdb->client,
+                                    ctdb->cmd_pnn,
+                                    TIMEOUT(),
+                                    &runstate);
+       if (ret != 0 ) {
+               printf("Unable to get runstate");
+               return NULL;
+       }
+
+       nodemap = talloc_nodemap(mem_ctx, nodemap_in);
+       if (nodemap == NULL) {
+               printf("Unable to get nodemap");
+               return NULL;
+       }
+
+       nodemap->num = nodemap_in->num;
+       for (i=0; i<nodemap->num; i++) {
+               struct ctdb_node_and_flags *node_in = &nodemap_in->node[i];
+               struct ctdb_node_and_flags *node = &nodemap->node[i];
+
+               *node = *node_in;
+
+               if (node->flags & NODE_FLAGS_DELETED) {
+                       continue;
+               }
+
+               if ((runstate <= CTDB_RUNSTATE_FIRST_RECOVERY) &&
+                   !(node->flags & NODE_FLAGS_DISCONNECTED) &&
+                   (node->pnn != ctdb->cmd_pnn)) {
+                       node->flags = NODE_FLAGS_UNKNOWN;
+               }
+       }
+
+       return nodemap;
+}
+
 /* Compare IP address */
 static bool ctdb_same_ip(ctdb_sock_addr *ip1, ctdb_sock_addr *ip2)
 {
@@ -826,11 +887,12 @@ static void print_nodemap_machine(TALLOC_CTX *mem_ctx,
        struct ctdb_node_and_flags *node;
        unsigned int i;
 
-       printf("%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s\n",
+       printf("%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s\n",
               options.sep,
               "Node", options.sep,
               "IP", options.sep,
               "Disconnected", options.sep,
+              "Unknown", options.sep,
               "Banned", options.sep,


-- 
Samba Shared Repository

Reply via email to