diff options
| -rw-r--r-- | cli/src/cli-cmd-global.c | 2 | ||||
| -rw-r--r-- | cli/src/cli-cmd-parser.c | 28 | ||||
| -rw-r--r-- | doc/gluster.8 | 2 | ||||
| -rw-r--r-- | rpc/xdr/src/cli1-xdr.x | 3 | ||||
| -rw-r--r-- | tests/bugs/cli/bug-1353156-get-state-cli-validations.t | 18 | ||||
| -rw-r--r-- | xlators/mgmt/glusterd/src/glusterd-handler.c | 45 | 
6 files changed, 80 insertions, 18 deletions
diff --git a/cli/src/cli-cmd-global.c b/cli/src/cli-cmd-global.c index 0f08985318e..9873192686e 100644 --- a/cli/src/cli-cmd-global.c +++ b/cli/src/cli-cmd-global.c @@ -42,7 +42,7 @@ struct cli_cmd global_cmds[] = {             "list global commands",          },          { "get-state [<daemon>] [[odir </path/to/output/dir/>] " -          "[file <filename>]] [detail]", +          "[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 c3058b673f8..7d6fd3c28d0 100644 --- a/cli/src/cli-cmd-parser.c +++ b/cli/src/cli-cmd-parser.c @@ -887,10 +887,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. " @@ -903,10 +909,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 6306969de97..316a3d21ff7 100644 --- a/doc/gluster.8 +++ b/doc/gluster.8 @@ -268,7 +268,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 b7d07c2853c..f62248396ca 100644 --- a/rpc/xdr/src/cli1-xdr.x +++ b/rpc/xdr/src/cli1-xdr.x @@ -154,7 +154,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 f6e72a591ce..c9c06cc6567 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 2968c1413d6..126d5f211d0 100644 --- a/xlators/mgmt/glusterd/src/glusterd-handler.c +++ b/xlators/mgmt/glusterd/src/glusterd-handler.c @@ -5219,6 +5219,7 @@ glusterd_get_state (rpcsvc_request_t *req, dict_t *dict)          glusterd_volinfo_t          *volinfo = NULL;          glusterd_brickinfo_t        *brickinfo = NULL;          xlator_t                    *this = NULL; +        dict_t                      *vol_all_opts = NULL;          struct statvfs               brickstat = {0};          char                        *odir = NULL;          char                        *filename = NULL; @@ -5312,6 +5313,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))); @@ -5353,12 +5389,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"); @@ -5633,7 +5663,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);  | 
