From: Martin Schwenke Date: Wed, 24 May 2017 10:27:58 +0000 (+1000) Subject: ctdb-tools: "ctdb nodestatus" should only display header for "all" X-Git-Tag: samba-4.5.11~39 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=29b9e1945600efdbdaebe29817149c2dba98c520;p=thirdparty%2Fsamba.git ctdb-tools: "ctdb nodestatus" should only display header for "all" The "Number of nodes:" header should only be displayed when "all" is specified. This is how the command behaved in Samba <= 4.4. Printing the number of nodes is not helpful and is rather confusing in the default case where only the status of the current node is printed. BUG: https://bugzilla.samba.org/show_bug.cgi?id=12802 Signed-off-by: Martin Schwenke Reviewed-by: Amitay Isaacs (cherry picked from commit 1d10c8e9e637619b754b4a273d3c714fbca7d503) --- diff --git a/ctdb/tools/ctdb.c b/ctdb/tools/ctdb.c index 086735c1342..d8d690aa0f1 100644 --- a/ctdb/tools/ctdb.c +++ b/ctdb/tools/ctdb.c @@ -774,7 +774,8 @@ static void print_nodemap_machine(TALLOC_CTX *mem_ctx, } static void print_nodemap(TALLOC_CTX *mem_ctx, struct ctdb_context *ctdb, - struct ctdb_node_map *nodemap, uint32_t mypnn) + struct ctdb_node_map *nodemap, uint32_t mypnn, + bool print_header) { struct ctdb_node_and_flags *node; int num_deleted_nodes = 0; @@ -786,11 +787,14 @@ static void print_nodemap(TALLOC_CTX *mem_ctx, struct ctdb_context *ctdb, } } - if (num_deleted_nodes == 0) { - printf("Number of nodes:%d\n", nodemap->num); - } else { - printf("Number of nodes:%d (including %d deleted nodes)\n", - nodemap->num, num_deleted_nodes); + if (print_header) { + if (num_deleted_nodes == 0) { + printf("Number of nodes:%d\n", nodemap->num); + } else { + printf("Number of nodes:%d " + "(including %d deleted nodes)\n", + nodemap->num, num_deleted_nodes); + } } for (i=0; inum; i++) { @@ -816,7 +820,7 @@ static void print_status(TALLOC_CTX *mem_ctx, struct ctdb_context *ctdb, { int i; - print_nodemap(mem_ctx, ctdb, nodemap, mypnn); + print_nodemap(mem_ctx, ctdb, nodemap, mypnn, true); if (vnnmap->generation == INVALID_GENERATION) { printf("Generation:INVALID\n"); @@ -5813,6 +5817,7 @@ static int control_nodestatus(TALLOC_CTX *mem_ctx, struct ctdb_context *ctdb, const char *nodestring = NULL; struct ctdb_node_map *nodemap; int ret, i; + bool print_hdr = false; if (argc > 1) { usage("nodestatus"); @@ -5820,6 +5825,9 @@ static int control_nodestatus(TALLOC_CTX *mem_ctx, struct ctdb_context *ctdb, if (argc == 1) { nodestring = argv[0]; + if (strcmp(nodestring, "all") == 0) { + print_hdr = true; + } } if (! parse_nodestring(mem_ctx, ctdb, nodestring, &nodemap)) { @@ -5829,7 +5837,7 @@ static int control_nodestatus(TALLOC_CTX *mem_ctx, struct ctdb_context *ctdb, if (options.machinereadable) { print_nodemap_machine(mem_ctx, ctdb, nodemap, ctdb->cmd_pnn); } else { - print_nodemap(mem_ctx, ctdb, nodemap, ctdb->cmd_pnn); + print_nodemap(mem_ctx, ctdb, nodemap, ctdb->cmd_pnn, print_hdr); } ret = 0;