From 0608244512f1ab0ba9916ab3da9f0bc57ee234fc Mon Sep 17 00:00:00 2001 From: Krutika Dhananjay Date: Mon, 22 Oct 2012 10:18:32 +0530 Subject: cli: Mark port as N/A in volume status when process is not online Change-Id: Ie11c7331e3bc58c0f934f424dde4341cdffb9e2c BUG: 861542 Signed-off-by: Krutika Dhananjay Reviewed-on: http://review.gluster.org/4048 Tested-by: Gluster Build System Reviewed-by: Vijay Bellur --- cli/src/cli-cmd-volume.c | 21 ++++++++++++++++----- cli/src/cli-xml-output.c | 30 +++++++++++++++++++++--------- 2 files changed, 37 insertions(+), 14 deletions(-) (limited to 'cli') diff --git a/cli/src/cli-cmd-volume.c b/cli/src/cli-cmd-volume.c index ac70cd5c0..f7586c44c 100644 --- a/cli/src/cli-cmd-volume.c +++ b/cli/src/cli-cmd-volume.c @@ -1490,7 +1490,10 @@ void cli_print_detailed_status (cli_volume_status_t *status) { cli_out ("%-20s : %-20s", "Brick", status->brick); - cli_out ("%-20s : %-20d", "Port", status->port); + if (status->online) + cli_out ("%-20s : %-20d", "Port", status->port); + else + cli_out ("%-20s : %-20s", "Port", "N/A"); cli_out ("%-20s : %-20c", "Online", (status->online) ? 'Y' : 'N'); cli_out ("%-20s : %-20s", "Pid", status->pid_str); @@ -1565,10 +1568,18 @@ cli_print_brick_status (cli_volume_status_t *status) printf ("%s", p); while (num_tabs-- != 0) printf ("\t"); - if (status->port) - cli_out ("%d\t%c\t%s", - status->port, status->online?'Y':'N', - status->pid_str); + if (status->port) { + if (status->online) + cli_out ("%d\t%c\t%s", + status->port, + status->online?'Y':'N', + status->pid_str); + else + cli_out ("%s\t%c\t%s", + "N/A", + status->online?'Y':'N', + status->pid_str); + } else cli_out ("%s\t%c\t%s", "N/A", status->online?'Y':'N', diff --git a/cli/src/cli-xml-output.c b/cli/src/cli-xml-output.c index 004ded765..34b046cc9 100644 --- a/cli/src/cli-xml-output.c +++ b/cli/src/cli-xml-output.c @@ -229,15 +229,6 @@ cli_xml_output_vol_status_common (xmlTextWriterPtr writer, dict_t *dict, "%s", path); XML_RET_CHECK_AND_GOTO (ret, out); - memset (key, 0, sizeof (key)); - snprintf (key, sizeof (key), "brick%d.port", brick_index); - ret = dict_get_int32 (dict, key, &port); - if (ret) - goto out; - ret = xmlTextWriterWriteFormatElement (writer, (xmlChar *)"port", - "%d", port); - XML_RET_CHECK_AND_GOTO (ret, out); - memset (key, 0, sizeof (key)); snprintf (key, sizeof (key), "brick%d.status", brick_index); ret = dict_get_int32 (dict, key, &status); @@ -248,6 +239,27 @@ cli_xml_output_vol_status_common (xmlTextWriterPtr writer, dict_t *dict, XML_RET_CHECK_AND_GOTO (ret, out); *online = status; + memset (key, 0, sizeof (key)); + snprintf (key, sizeof (key), "brick%d.port", brick_index); + ret = dict_get_int32 (dict, key, &port); + if (ret) + goto out; + + /* If the process is either offline or doesn't provide a port (shd) + * port = "N/A" + * else print the port number of the process. + */ + + if (*online == 1 && port != 0) + ret = xmlTextWriterWriteFormatElement (writer, + (xmlChar *)"port", + "%d", port); + else + ret = xmlTextWriterWriteFormatElement (writer, + (xmlChar *)"port", + "%s", "N/A"); + XML_RET_CHECK_AND_GOTO (ret, out); + memset (key, 0, sizeof (key)); snprintf (key, sizeof (key), "brick%d.pid", brick_index); ret = dict_get_int32 (dict, key, &pid); -- cgit