From 7c871756c93c276f8d7725408115021231c033ed Mon Sep 17 00:00:00 2001 From: Samikshan Bairagya Date: Sun, 23 Jul 2017 22:07:34 +0530 Subject: 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 all` command. This is the new usage for the get-state CLI: # gluster get-state [] [[odir ] \ [file ]] [detail|volumeoptions] > Reviewed-on: https://review.gluster.org/17858 > CentOS-regression: Gluster Build System > Reviewed-by: Atin Mukherjee > Reviewed-by: Gaurav Yadav > Smoke: Gluster Build System (cherry picked from commit 8dcf91660e0bd10eb75ef25a29ca02ec51c81be4) Change-Id: Ice52d936a5a389c6fa0ba5ab32416a65cdfde46d Fixes: #277 Signed-off-by: Samikshan Bairagya Reviewed-on: https://review.gluster.org/17874 Reviewed-by: Atin Mukherjee CentOS-regression: Gluster Build System Smoke: Gluster Build System --- cli/src/cli-cmd-global.c | 2 +- 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, 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 [] [[odir ] " - "[file ]] [detail]", + "[file ]] [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 d087fd34fa8..984ce5bbad0 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 as the source for all the files that are in split-b Selects the split-brained present in as source and completes heal. .SS "Other Commands" .TP -\fB\ get-state [] [[odir ] [file ]] [detail] \fR +\fB\ get-state [] [[odir ] [file ]] [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 05587316246..7039e3027bc 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; @@ -5313,6 +5314,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))); @@ -5354,12 +5390,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"); @@ -5655,7 +5685,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); -- cgit