The branch, master has been updated
       via  e02156b0b77 ctdb-doc: add section to manpage for -j/--json option
       via  5e5426528ab ctdb-tools: add some tests cases for ctdb status --json
       via  82a26efe1bf ctdb-tests: add wrapper helper over JSON-mode command
       via  0a153977488 ctdb-tools: add --json support to 'version' sub-command
       via  3812798c20e ctdb-tools: add a --json option for ctdb status
       via  2c4c9fd5070 ctdb-wscript: support building ctdb command with jansson
       via  138aa2b63a9 build: Move jansson detection and related options to 
lib/util
       via  d688eedf66b ctdb-tools: reformat ctdb.c with clang-format
      from  7c5ce115f2c ctdb-failover: Add sm-notify to statd_callout

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


- Log -----------------------------------------------------------------
commit e02156b0b77c852512b4eb389457e018e992e559
Author: John Mulligan <[email protected]>
Date:   Mon Feb 9 13:02:01 2026 -0500

    ctdb-doc: add section to manpage for -j/--json option
    
    Signed-off-by: John Mulligan <[email protected]>
    Reviewed-by: Martin Schwenke <[email protected]>
    Reviewed-by: Anoop C S <[email protected]>
    
    Autobuild-User(master): Martin Schwenke <[email protected]>
    Autobuild-Date(master): Fri Feb 20 01:50:20 UTC 2026 on atb-devel-224

commit 5e5426528ab1f3269f2b680e09441b4bdf2c242a
Author: John Mulligan <[email protected]>
Date:   Thu Feb 12 17:44:59 2026 -0500

    ctdb-tools: add some tests cases for ctdb status --json
    
    Signed-off-by: John Mulligan <[email protected]>
    Reviewed-by: Martin Schwenke <[email protected]>
    Reviewed-by: Anoop C S <[email protected]>

commit 82a26efe1bf19bb9d1920858a7b5aae676c3dbb4
Author: Shachar Sharon <[email protected]>
Date:   Sun Feb 8 13:39:53 2026 +0200

    ctdb-tests: add wrapper helper over JSON-mode command
    
    Run ctdb sub-command with '--json' flag only when code has been compiled
    with json support. Otherwise, ignore the test silently.
    
    Signed-off-by: Shachar Sharon <[email protected]>
    Reviewed-by: Martin Schwenke <[email protected]>
    Reviewed-by: Anoop C S <[email protected]>

commit 0a153977488ea5e60e6a9e1ddc61469f5f3dab8c
Author: Shachar Sharon <[email protected]>
Date:   Sun Feb 8 13:15:02 2026 +0200

    ctdb-tools: add --json support to 'version' sub-command
    
    When building ctdb with json-outpuit support, enable json output when
    running 'ctdb version --json'. This may be used as indication to json
    support in other sub-commands.
    
    Pair-Programmed-With: John Mulligan <[email protected]>
    Signed-off-by: Shachar Sharon <[email protected]>
    Signed-off-by: John Mulligan <[email protected]>
    Reviewed-by: Martin Schwenke <[email protected]>
    Reviewed-by: Anoop C S <[email protected]>

commit 3812798c20ef53bc6ff2dee4c475b1f95eccb077
Author: John Mulligan <[email protected]>
Date:   Thu Feb 12 17:47:58 2026 -0500

    ctdb-tools: add a --json option for ctdb status
    
    Add a new --json option that prints JSON as a higher-level machine
    parse-able output. The --json option is only supported if the
    jansson library is available.
    
    The --json option will ONLY print json.  If the subcommand does not
    (yet) support json it will raise an error rather than fall back to
    emitting human readable text. This way a json parser is never given
    "invalid" input.
    
    Pair-Programmed-With: Shachar Sharon <[email protected]>
    Signed-off-by: Shachar Sharon <[email protected]>
    Signed-off-by: John Mulligan <[email protected]>
    Reviewed-by: Martin Schwenke <[email protected]>
    Reviewed-by: Anoop C S <[email protected]>

commit 2c4c9fd507046d50e58933333d6b73a109f99d80
Author: John Mulligan <[email protected]>
Date:   Thu Feb 12 17:47:58 2026 -0500

    ctdb-wscript: support building ctdb command with jansson
    
    Pair-Programmed-With: Shachar Sharon <[email protected]>
    Signed-off-by: Shachar Sharon <[email protected]>
    Signed-off-by: John Mulligan <[email protected]>
    Reviewed-by: Martin Schwenke <[email protected]>
    Reviewed-by: Anoop C S <[email protected]>

commit 138aa2b63a9eccb145c1c44fb74d052a5dc40242
Author: Martin Schwenke <[email protected]>
Date:   Tue Feb 17 11:17:57 2026 +1100

    build: Move jansson detection and related options to lib/util
    
    This means that standalone builds (e.g. CTDB) can use it.
    
    The check for without JSON but with AD DC stays in the top-level
    wscript.
    
    Signed-off-by: Martin Schwenke <[email protected]>
    Reviewed-by: Anoop C S <[email protected]>

commit d688eedf66b1b650fad7b0210c5c6eb33b0548af
Author: John Mulligan <[email protected]>
Date:   Tue Feb 10 13:55:11 2026 -0500

    ctdb-tools: reformat ctdb.c with clang-format
    
    This is the result of running:
        clang-format -i ctdb/tools/ctdb.c
    
    This is in preparation for some upcoming changes that add fields to the
    struct tables and general recommendations to use `clang-format` and/or
    `git clang-format` to keep samba code formatted consistently.
    
    Signed-off-by: John Mulligan <[email protected]>
    Reviewed-by: Martin Schwenke <[email protected]>
    Reviewed-by: Anoop C S <[email protected]>

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

Summary of changes:
 ctdb/doc/ctdb.1.xml                     |   17 +
 ctdb/tests/UNIT/tool/ctdb.status.001.sh |   87 +
 ctdb/tests/UNIT/tool/ctdb.status.002.sh |   87 +
 ctdb/tests/UNIT/tool/ctdb.status.003.sh |   87 +
 ctdb/tests/UNIT/tool/scripts/local.sh   |    8 +
 ctdb/tools/ctdb.c                       | 3936 +++++++++++++++++++++----------
 ctdb/wscript                            |    4 +-
 lib/util/wscript                        |   17 +
 lib/util/wscript_configure              |   16 +
 wscript                                 |   28 +-
 10 files changed, 3033 insertions(+), 1254 deletions(-)


Changeset truncated at 500 lines:

diff --git a/ctdb/doc/ctdb.1.xml b/ctdb/doc/ctdb.1.xml
index 12075b86958..dab0e4c6c0e 100644
--- a/ctdb/doc/ctdb.1.xml
+++ b/ctdb/doc/ctdb.1.xml
@@ -166,6 +166,23 @@
       </listitem>
       </varlistentry>
 
+      <varlistentry><term>-j --json</term>
+      <listitem>
+       <para>
+         Produce output in JSON encoded text. JSON is widely supported
+         by many programming languages and command line tools and can
+         represent common structured data types. Not all commands support
+         this option. A command that does not support JSON will exit with
+         an error code when --json is specified. Commands will not
+         produce human-readable output when --json is specified.
+       </para>
+       <para>
+         The ctdb command line tool must be compiled with JSON support
+         to enable this option.
+       </para>
+      </listitem>
+      </varlistentry>
+
       <varlistentry><term>-t <parameter>TIMEOUT</parameter></term>
       <listitem>
        <para>
diff --git a/ctdb/tests/UNIT/tool/ctdb.status.001.sh 
b/ctdb/tests/UNIT/tool/ctdb.status.001.sh
index 62c1dc7c98a..1f8202adad1 100755
--- a/ctdb/tests/UNIT/tool/ctdb.status.001.sh
+++ b/ctdb/tests/UNIT/tool/ctdb.status.001.sh
@@ -44,3 +44,90 @@ required_result 0 <<EOF
 |2|192.168.20.43|0|0|0|0|0|0|0|0|N|
 EOF
 simple_test -X
+
+required_result 0 <<EOF
+{
+  "node_status": {
+    "node_count": 3,
+    "deleted_node_count": 0,
+    "nodes": {
+      "0": {
+        "pnn": 0,
+        "address": "192.168.20.41",
+        "partially_online": false,
+        "flags_raw": 0,
+        "flags_ok": true,
+        "flags": {
+          "disconnected": false,
+          "unknown": false,
+          "disabled": false,
+          "banned": false,
+          "unhealthy": false,
+          "deleted": false,
+          "stopped": false,
+          "inactive": false
+        },
+        "this_node": true
+      },
+      "1": {
+        "pnn": 1,
+        "address": "192.168.20.42",
+        "partially_online": false,
+        "flags_raw": 0,
+        "flags_ok": true,
+        "flags": {
+          "disconnected": false,
+          "unknown": false,
+          "disabled": false,
+          "banned": false,
+          "unhealthy": false,
+          "deleted": false,
+          "stopped": false,
+          "inactive": false
+        },
+        "this_node": false
+      },
+      "2": {
+        "pnn": 2,
+        "address": "192.168.20.43",
+        "partially_online": false,
+        "flags_raw": 0,
+        "flags_ok": true,
+        "flags": {
+          "disconnected": false,
+          "unknown": false,
+          "disabled": false,
+          "banned": false,
+          "unhealthy": false,
+          "deleted": false,
+          "stopped": false,
+          "inactive": false
+        },
+        "this_node": false
+      }
+    }
+  },
+  "vnn_status": {
+    "generation": 654321,
+    "size": 3,
+    "vnn_map": [
+      {
+        "hash": 0,
+        "lmaster": 0
+      },
+      {
+        "hash": 1,
+        "lmaster": 1
+      },
+      {
+        "hash": 2,
+        "lmaster": 2
+      }
+    ]
+  },
+  "recovery_mode": "NORMAL",
+  "recovery_mode_raw": 0,
+  "leader": 0
+}
+EOF
+simple_json_test
diff --git a/ctdb/tests/UNIT/tool/ctdb.status.002.sh 
b/ctdb/tests/UNIT/tool/ctdb.status.002.sh
index 0cce4435ee4..5a86122e1c9 100755
--- a/ctdb/tests/UNIT/tool/ctdb.status.002.sh
+++ b/ctdb/tests/UNIT/tool/ctdb.status.002.sh
@@ -44,3 +44,90 @@ required_result 0 <<EOF
 |2|192.168.20.43|0|0|0|0|0|0|0|0|N|
 EOF
 simple_test -X
+
+required_result 0 <<EOF
+{
+  "node_status": {
+    "node_count": 3,
+    "deleted_node_count": 0,
+    "nodes": {
+      "0": {
+        "pnn": 0,
+        "address": "192.168.20.41",
+        "partially_online": false,
+        "flags_raw": 2,
+        "flags_ok": false,
+        "flags": {
+          "disconnected": false,
+          "unknown": false,
+          "disabled": false,
+          "banned": false,
+          "unhealthy": true,
+          "deleted": false,
+          "stopped": false,
+          "inactive": false
+        },
+        "this_node": false
+      },
+      "1": {
+        "pnn": 1,
+        "address": "192.168.20.42",
+        "partially_online": false,
+        "flags_raw": 0,
+        "flags_ok": true,
+        "flags": {
+          "disconnected": false,
+          "unknown": false,
+          "disabled": false,
+          "banned": false,
+          "unhealthy": false,
+          "deleted": false,
+          "stopped": false,
+          "inactive": false
+        },
+        "this_node": true
+      },
+      "2": {
+        "pnn": 2,
+        "address": "192.168.20.43",
+        "partially_online": false,
+        "flags_raw": 0,
+        "flags_ok": true,
+        "flags": {
+          "disconnected": false,
+          "unknown": false,
+          "disabled": false,
+          "banned": false,
+          "unhealthy": false,
+          "deleted": false,
+          "stopped": false,
+          "inactive": false
+        },
+        "this_node": false
+      }
+    }
+  },
+  "vnn_status": {
+    "generation": 654321,
+    "size": 3,
+    "vnn_map": [
+      {
+        "hash": 0,
+        "lmaster": 0
+      },
+      {
+        "hash": 1,
+        "lmaster": 1
+      },
+      {
+        "hash": 2,
+        "lmaster": 2
+      }
+    ]
+  },
+  "recovery_mode": "NORMAL",
+  "recovery_mode_raw": 0,
+  "leader": 1
+}
+EOF
+simple_json_test
diff --git a/ctdb/tests/UNIT/tool/ctdb.status.003.sh 
b/ctdb/tests/UNIT/tool/ctdb.status.003.sh
index 67a2966ea4d..bff2faa5f81 100755
--- a/ctdb/tests/UNIT/tool/ctdb.status.003.sh
+++ b/ctdb/tests/UNIT/tool/ctdb.status.003.sh
@@ -47,3 +47,90 @@ required_result 0 <<EOF
 |2|192.168.20.43|0|1|0|0|0|0|0|0|N|
 EOF
 simple_test -X
+
+required_result 0 <<EOF
+{
+  "node_status": {
+    "node_count": 3,
+    "deleted_node_count": 0,
+    "nodes": {
+      "0": {
+        "pnn": 0,
+        "address": "192.168.20.41",
+        "partially_online": false,
+        "flags_raw": 64,
+        "flags_ok": false,
+        "flags": {
+          "disconnected": false,
+          "unknown": true,
+          "disabled": false,
+          "banned": false,
+          "unhealthy": false,
+          "deleted": false,
+          "stopped": false,
+          "inactive": false
+        },
+        "this_node": false
+      },
+      "1": {
+        "pnn": 1,
+        "address": "192.168.20.42",
+        "partially_online": false,
+        "flags_raw": 0,
+        "flags_ok": true,
+        "flags": {
+          "disconnected": false,
+          "unknown": false,
+          "disabled": false,
+          "banned": false,
+          "unhealthy": false,
+          "deleted": false,
+          "stopped": false,
+          "inactive": false
+        },
+        "this_node": true
+      },
+      "2": {
+        "pnn": 2,
+        "address": "192.168.20.43",
+        "partially_online": false,
+        "flags_raw": 64,
+        "flags_ok": false,
+        "flags": {
+          "disconnected": false,
+          "unknown": true,
+          "disabled": false,
+          "banned": false,
+          "unhealthy": false,
+          "deleted": false,
+          "stopped": false,
+          "inactive": false
+        },
+        "this_node": false
+      }
+    }
+  },
+  "vnn_status": {
+    "generation": 654321,
+    "size": 3,
+    "vnn_map": [
+      {
+        "hash": 0,
+        "lmaster": 0
+      },
+      {
+        "hash": 1,
+        "lmaster": 1
+      },
+      {
+        "hash": 2,
+        "lmaster": 2
+      }
+    ]
+  },
+  "recovery_mode": "NORMAL",
+  "recovery_mode_raw": 0,
+  "leader": 1
+}
+EOF
+simple_json_test
diff --git a/ctdb/tests/UNIT/tool/scripts/local.sh 
b/ctdb/tests/UNIT/tool/scripts/local.sh
index 618fa36cd87..11b1a711bca 100644
--- a/ctdb/tests/UNIT/tool/scripts/local.sh
+++ b/ctdb/tests/UNIT/tool/scripts/local.sh
@@ -110,3 +110,11 @@ simple_test ()
 {
        simple_test_other $test_args "$@"
 }
+
+simple_json_test ()
+{
+       if ! "$CTDB" version --json > /dev/null 2>&1; then
+               return 0
+       fi
+       simple_test "$@" --json
+}
diff --git a/ctdb/tools/ctdb.c b/ctdb/tools/ctdb.c
index 44ab248391b..1162cff1817 100644
--- a/ctdb/tools/ctdb.c
+++ b/ctdb/tools/ctdb.c
@@ -51,10 +51,14 @@
 #include "conf/ctdb_config.h"
 #include "conf/node.h"
 
-#define TIMEOUT()      timeval_current_ofs(options.timelimit, 0)
+#ifdef HAVE_JANSSON
+#include <jansson.h>
+#endif /* HAVE_JANSSON */
 
-#define SRVID_CTDB_TOOL    (CTDB_SRVID_TOOL_RANGE | 0x0001000000000000LL)
-#define SRVID_CTDB_PUSHDB  (CTDB_SRVID_TOOL_RANGE | 0x0002000000000000LL)
+#define TIMEOUT() timeval_current_ofs(options.timelimit, 0)
+
+#define SRVID_CTDB_TOOL (CTDB_SRVID_TOOL_RANGE | 0x0001000000000000LL)
+#define SRVID_CTDB_PUSHDB (CTDB_SRVID_TOOL_RANGE | 0x0002000000000000LL)
 
 #define NODE_FLAGS_UNKNOWN 0x00000040
 
@@ -63,6 +67,7 @@ static struct {
        int timelimit;
        int pnn;
        int machinereadable;
+       int json_output;
        const char *sep;
        int machineparsable;
        int verbose;
@@ -108,12 +113,12 @@ static double timeval_delta(struct timeval *tv2, struct 
timeval *tv)
 }
 
 static struct ctdb_node_and_flags *get_node_by_pnn(
-                                       struct ctdb_node_map *nodemap,
-                                       uint32_t pnn)
+       struct ctdb_node_map *nodemap,
+       uint32_t pnn)
 {
        unsigned int i;
 
-       for (i=0; i<nodemap->num; i++) {
+       for (i = 0; i < nodemap->num; i++) {
                if (nodemap->node[i].pnn == pnn) {
                        return &nodemap->node[i];
                }
@@ -127,26 +132,27 @@ static const char *pretty_print_flags(TALLOC_CTX 
*mem_ctx, uint32_t flags)
                uint32_t flag;
                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" },
-               { NODE_FLAGS_DELETED,               "DELETED" },
-               { NODE_FLAGS_STOPPED,               "STOPPED" },
-               { NODE_FLAGS_INACTIVE,              "INACTIVE" },
+               {NODE_FLAGS_DISCONNECTED, "DISCONNECTED"},
+               {NODE_FLAGS_UNKNOWN, "UNKNOWN"},
+               {NODE_FLAGS_PERMANENTLY_DISABLED, "DISABLED"},
+               {NODE_FLAGS_BANNED, "BANNED"},
+               {NODE_FLAGS_UNHEALTHY, "UNHEALTHY"},
+               {NODE_FLAGS_DELETED, "DELETED"},
+               {NODE_FLAGS_STOPPED, "STOPPED"},
+               {NODE_FLAGS_INACTIVE, "INACTIVE"},
        };
        char *flags_str = NULL;
        size_t i;
 
-       for (i=0; i<ARRAY_SIZE(flag_names); i++) {
+       for (i = 0; i < ARRAY_SIZE(flag_names); i++) {
                if (flags & flag_names[i].flag) {
                        if (flags_str == NULL) {
                                flags_str = talloc_asprintf(mem_ctx,
-                                               "%s", flag_names[i].name);
+                                                           "%s",
+                                                           flag_names[i].name);
                        } else {
-                               flags_str = talloc_asprintf_append(flags_str,
-                                               "|%s", flag_names[i].name);
+                               flags_str = talloc_asprintf_append(
+                                       flags_str, "|%s", flag_names[i].name);
                        }
                        if (flags_str == NULL) {
                                return "OUT-OF-MEMORY";
@@ -195,10 +201,15 @@ static struct ctdb_node_map *get_nodemap(struct 
ctdb_context *ctdb, bool force)
 
        current_node = ctdb->pnn;
 again:
-       ret = ctdb_ctrl_get_nodemap(tmp_ctx, ctdb->ev, ctdb->client,
-                                   current_node, TIMEOUT(), &nodemap);
+       ret = ctdb_ctrl_get_nodemap(tmp_ctx,
+                                   ctdb->ev,
+                                   ctdb->client,
+                                   current_node,
+                                   TIMEOUT(),
+                                   &nodemap);
        if (ret != 0) {
-               fprintf(stderr, "Failed to get nodemap from node %u\n",
+               fprintf(stderr,
+                       "Failed to get nodemap from node %u\n",
                        current_node);
                goto failed;
        }
@@ -209,8 +220,9 @@ again:
                do {
                        current_node = (current_node + 1) % nodemap->num;
                        node = get_node_by_pnn(nodemap, current_node);
-                       if (! (node->flags &
-                             (NODE_FLAGS_DELETED|NODE_FLAGS_DISCONNECTED))) {
+                       if (!(node->flags &
+                             (NODE_FLAGS_DELETED | NODE_FLAGS_DISCONNECTED)))
+                       {
                                break;
                        }
                } while (current_node != ctdb->pnn);
@@ -258,20 +270,23 @@ static bool verify_pnn(struct ctdb_context *ctdb, int pnn)
        }
 
        found = false;
-       for (i=0; i<nodemap->num; i++) {
+       for (i = 0; i < nodemap->num; i++) {
                if (nodemap->node[i].pnn == (uint32_t)pnn) {
                        found = true;
                        break;
                }
        }
-       if (! found) {
+       if (!found) {
                fprintf(stderr, "Node %u does not exist\n", pnn);
                return false;
        }
 
        if (nodemap->node[i].flags &
-           (NODE_FLAGS_DISCONNECTED|NODE_FLAGS_DELETED)) {
-               fprintf(stderr, "Node %u has status %s\n", pnn,
+           (NODE_FLAGS_DISCONNECTED | NODE_FLAGS_DELETED))
+       {
+               fprintf(stderr,
+                       "Node %u has status %s\n",
+                       pnn,
                        pretty_print_flags(ctdb, nodemap->node[i].flags));
                return false;
        }
@@ -289,7 +304,8 @@ static struct ctdb_node_map *talloc_nodemap(TALLOC_CTX 
*mem_ctx,
                return NULL;
        }
 
-       nodemap2->node = talloc_array(nodemap2, struct ctdb_node_and_flags,
+       nodemap2->node = talloc_array(nodemap2,
+                                     struct ctdb_node_and_flags,
                                      nodemap->num);
        if (nodemap2->node == NULL) {
                talloc_free(nodemap2);
@@ -306,7 +322,8 @@ static struct ctdb_node_map *talloc_nodemap(TALLOC_CTX 
*mem_ctx,
  *
  * If nodestring is NULL, use the current node.
  */
-static bool parse_nodestring(TALLOC_CTX *mem_ctx, struct ctdb_context *ctdb,
+static bool parse_nodestring(TALLOC_CTX *mem_ctx,
+                            struct ctdb_context *ctdb,
                             const char *nodestring,
                             struct ctdb_node_map **out)
 {
@@ -325,7 +342,7 @@ static bool parse_nodestring(TALLOC_CTX *mem_ctx, struct 
ctdb_context *ctdb,
        }
 
        if (nodestring == NULL) {
-               for (i=0; i<nodemap->num; i++) {
+               for (i = 0; i < nodemap->num; i++) {


-- 
Samba Shared Repository

Reply via email to