Blob Blame History Raw
From 8816a046c4c249b99ca5dff1aaaac031c7c4dae4 Mon Sep 17 00:00:00 2001
From: Samikshan Bairagya <samikshan@gmail.com>
Date: Sun, 23 Jul 2017 22:07:34 +0530
Subject: [PATCH 614/616] glusterd: Add option to get all volume options
 through get-state CLI

This commit makes the get-state CLI capable to returning the values
for all volume options for all volumes. This is similar to what you
get when you issue a `gluster volume get <volname> all` command.

This is the new usage for the get-state CLI:

 # gluster get-state [<daemon>] [[odir </path/to/output/dir/>] \
[file <filename>]] [detail|volumeoptions]

>Fixes: #277
>Change-Id: Ice52d936a5a389c6fa0ba5ab32416a65cdfde46d
>Signed-off-by: Samikshan Bairagya <samikshan@gmail.com>
>Reviewed-on: https://review.gluster.org/17858
>CentOS-regression: Gluster Build System <jenkins@build.gluster.org>
>Reviewed-by: Atin Mukherjee <amukherj@redhat.com>
>Reviewed-by: Gaurav Yadav <gyadav@redhat.com>
>Smoke: Gluster Build System <jenkins@build.gluster.org>

Bug: 1475326
>Change-Id: Ice52d936a5a389c6fa0ba5ab32416a65cdfde46d
>Signed-off-by: Samikshan Bairagya <samikshan@gmail.com>

Change-Id: Ifd2d6f56576d631c0fef50e89b0b8885dedd5131
Reviewed-on: https://code.engineering.redhat.com/gerrit/117182
Tested-by: Atin Mukherjee <amukherj@redhat.com>
Reviewed-by: Atin Mukherjee <amukherj@redhat.com>
---
 cli/src/cli-cmd-global.c                           |  4 +-
 cli/src/cli-cmd-parser.c                           | 28 ++++++++++----
 doc/gluster.8                                      |  2 +-
 rpc/xdr/src/cli1-xdr.x                             |  3 +-
 .../cli/bug-1353156-get-state-cli-validations.t    | 18 +++++++++
 xlators/mgmt/glusterd/src/glusterd-handler.c       | 45 ++++++++++++++++++----
 6 files changed, 81 insertions(+), 19 deletions(-)

diff --git a/cli/src/cli-cmd-global.c b/cli/src/cli-cmd-global.c
index 4312d24..d79f3a8 100644
--- a/cli/src/cli-cmd-global.c
+++ b/cli/src/cli-cmd-global.c
@@ -47,8 +47,8 @@ struct cli_cmd global_cmds[] = {
            cli_cmd_ganesha_cbk,
           "Enable/disable NFS-Ganesha support",
         },
-        { "get-state [<daemon>] [odir </path/to/output/dir/>] "
-          "[file <filename>]] [detail]",
+        { "get-state [<daemon>] [[odir </path/to/output/dir/>] "
+          "[file <filename>]] [detail|volumeoptions]",
           cli_cmd_get_state_cbk,
           "Get local state representation of mentioned daemon",
         },
diff --git a/cli/src/cli-cmd-parser.c b/cli/src/cli-cmd-parser.c
index a068beb..71af744 100644
--- a/cli/src/cli-cmd-parser.c
+++ b/cli/src/cli-cmd-parser.c
@@ -990,10 +990,16 @@ cli_cmd_get_state_parse (struct cli_state *state,
                                 }
                         } else {
                                 if (count > 1) {
-                                        if (count == wordcount-1 &&
-                                            !strcmp (words[count], "detail")) {
-                                                cmd = GF_CLI_GET_STATE_DETAIL;
-                                                continue;
+                                        if (count == wordcount-1) {
+                                                if (strcmp (words[count],
+                                                            "detail") == 0) {
+                                                        cmd = GF_CLI_GET_STATE_DETAIL;
+                                                        continue;
+                                                } else if (strcmp (words[count],
+                                                                   "volumeoptions") == 0) {
+                                                        cmd = GF_CLI_GET_STATE_VOLOPTS;
+                                                        continue;
+                                                }
                                         } else {
                                                 *op_errstr = gf_strdup ("Problem"
                                                         " parsing arguments. "
@@ -1006,10 +1012,16 @@ cli_cmd_get_state_parse (struct cli_state *state,
                                 if (strcmp (words[count], "glusterd") == 0) {
                                         continue;
                                 } else {
-                                        if (count == wordcount-1 &&
-                                            !strcmp (words[count], "detail")) {
-                                                cmd = GF_CLI_GET_STATE_DETAIL;
-                                                continue;
+                                        if (count == wordcount-1) {
+                                                if (strcmp (words[count],
+                                                            "detail") == 0) {
+                                                        cmd = GF_CLI_GET_STATE_DETAIL;
+                                                        continue;
+                                                } else if (strcmp (words[count],
+                                                                   "volumeoptions") == 0) {
+                                                        cmd = GF_CLI_GET_STATE_VOLOPTS;
+                                                        continue;
+                                                }
                                         }
 
                                         *op_errstr = gf_strdup ("glusterd is "
diff --git a/doc/gluster.8 b/doc/gluster.8
index c7b6f22..ed6f644 100644
--- a/doc/gluster.8
+++ b/doc/gluster.8
@@ -269,7 +269,7 @@ Selects <HOSTNAME:BRICKNAME> as the source for all the files that are in split-b
 Selects the split-brained <FILE> present in <HOSTNAME:BRICKNAME> as source and completes heal.
 .SS "Other Commands"
 .TP
-\fB\ get-state [<daemon>] [[odir </path/to/output/dir/>] [file <filename>]] [detail] \fR
+\fB\ get-state [<daemon>] [[odir </path/to/output/dir/>] [file <filename>]] [detail|volumeoptions] \fR
 Get local state representation of mentioned daemon and store data in provided path information
 .TP
 \fB\ help \fR
diff --git a/rpc/xdr/src/cli1-xdr.x b/rpc/xdr/src/cli1-xdr.x
index c90d564..e33ea4f 100644
--- a/rpc/xdr/src/cli1-xdr.x
+++ b/rpc/xdr/src/cli1-xdr.x
@@ -132,7 +132,8 @@ enum gf1_cli_info_op {
 };
 
 enum gf_cli_get_state_op {
-        GF_CLI_GET_STATE_DETAIL = 1
+        GF_CLI_GET_STATE_DETAIL = 1,
+        GF_CLI_GET_STATE_VOLOPTS = 2
 };
 
 enum gf1_cli_top_op {
diff --git a/tests/bugs/cli/bug-1353156-get-state-cli-validations.t b/tests/bugs/cli/bug-1353156-get-state-cli-validations.t
index f6e72a5..c9c06cc 100644
--- a/tests/bugs/cli/bug-1353156-get-state-cli-validations.t
+++ b/tests/bugs/cli/bug-1353156-get-state-cli-validations.t
@@ -87,6 +87,16 @@ TEST positive_test $CLI get-state glusterd odir $ODIR detail
 
 TEST positive_test $CLI get-state glusterd odir $ODIR file gdstate detail
 
+TEST positive_test $CLI get-state volumeoptions
+
+TEST positive_test $CLI get-state glusterd volumeoptions
+
+TEST positive_test $CLI get-state odir $ODIR volumeoptions
+
+TEST positive_test $CLI get-state glusterd odir $ODIR volumeoptions
+
+TEST positive_test $CLI get-state glusterd odir $ODIR file gdstate volumeoptions
+
 TEST ! $CLI get-state glusterfsd odir $ODIR;
 ERRSTR=$($CLI get-state glusterfsd odir $ODIR 2>&1 >/dev/null);
 EXPECT 'glusterd' get_daemon_not_supported_part $ERRSTR;
@@ -127,4 +137,12 @@ TEST ! $CLI get-state glusterd foo bar detail;
 ERRSTR=$($CLI get-state glusterd foo bar 2>&1 >/dev/null);
 EXPECT 'Problem' get_parsing_arguments_part $ERRSTR;
 
+TEST ! $CLI get-state glusterd volumeoptions file gdstate;
+ERRSTR=$($CLI get-state glusterd foo bar 2>&1 >/dev/null);
+EXPECT 'Problem' get_parsing_arguments_part $ERRSTR;
+
+TEST ! $CLI get-state glusterd foo bar volumeoptions;
+ERRSTR=$($CLI get-state glusterd foo bar 2>&1 >/dev/null);
+EXPECT 'Problem' get_parsing_arguments_part $ERRSTR;
+
 cleanup;
diff --git a/xlators/mgmt/glusterd/src/glusterd-handler.c b/xlators/mgmt/glusterd/src/glusterd-handler.c
index 7e24c9b..e194dca 100644
--- a/xlators/mgmt/glusterd/src/glusterd-handler.c
+++ b/xlators/mgmt/glusterd/src/glusterd-handler.c
@@ -5270,6 +5270,7 @@ glusterd_get_state (rpcsvc_request_t *req, dict_t *dict)
         glusterd_brickinfo_t        *brickinfo = NULL;
         glusterd_snap_t             *snapinfo = NULL;
         xlator_t                    *this = NULL;
+        dict_t                      *vol_all_opts = NULL;
         struct statvfs               brickstat = {0};
         char                        *odir = NULL;
         char                        *filename = NULL;
@@ -5364,6 +5365,41 @@ glusterd_get_state (rpcsvc_request_t *req, dict_t *dict)
                 goto out;
         }
 
+        ret = dict_get_uint32 (dict, "getstate-cmd", &get_state_cmd);
+        if (ret) {
+                gf_msg_debug (this->name, 0, "get-state command type not set");
+                ret = 0;
+        }
+
+        if (get_state_cmd == GF_CLI_GET_STATE_VOLOPTS) {
+                fprintf (fp, "[Volume Options]\n");
+                cds_list_for_each_entry (volinfo, &priv->volumes, vol_list) {
+                        fprintf (fp, "Volume%d.name: %s\n",
+                                 ++count, volinfo->volname);
+
+                        volcount = count;
+                        vol_all_opts = dict_new ();
+
+                        ret = glusterd_get_default_val_for_volopt (vol_all_opts,
+                                        _gf_true, NULL, NULL, volinfo, &rsp.op_errstr);
+                        if (ret) {
+                                gf_msg (this->name, GF_LOG_ERROR, 0,
+                                        GD_MSG_VOL_OPTS_IMPORT_FAIL, "Failed to "
+                                        "fetch the value of all volume options "
+                                        "for volume %s", volinfo->volname);
+                                continue;
+                        }
+
+                        dict_foreach (vol_all_opts, glusterd_print_volume_options,
+                                      fp);
+
+                        if (vol_all_opts)
+                                dict_unref (vol_all_opts);
+                }
+                ret = 0;
+                goto out;
+        }
+
         fprintf (fp, "[Global]\n");
 
         fprintf (fp, "MYUUID: %s\n", gf_strdup (uuid_utoa (priv->uuid)));
@@ -5405,12 +5441,6 @@ glusterd_get_state (rpcsvc_request_t *req, dict_t *dict)
         }
         rcu_read_unlock ();
 
-        ret = dict_get_uint32 (dict, "getstate-cmd", &get_state_cmd);
-        if (ret) {
-                gf_msg_debug (this->name, 0, "get-state command type not set");
-                ret = 0;
-        }
-
         count = 0;
         fprintf (fp, "\n[Volumes]\n");
 
@@ -5708,7 +5738,8 @@ out:
                 fclose(fp);
 
         rsp.op_ret = ret;
-        rsp.op_errstr = err_str;
+        if (rsp.op_errstr == NULL)
+                rsp.op_errstr = err_str;
 
         ret = dict_allocate_and_serialize (dict, &rsp.dict.dict_val,
                                            &rsp.dict.dict_len);
-- 
1.8.3.1