From 22e14d7f8eb40838a0af8486abfbbd54364e9154 Mon Sep 17 00:00:00 2001 From: N Balachandran Date: Mon, 6 Nov 2017 10:00:54 +0530 Subject: cli: gluster help changes gluster cli help now shows only the top level help commands. gluster help will now show help commands for . > BUG: 1474768 > Signed-off-by: N Balachandran (cherry picked from commit 89dc54f50c9f800ca4446ea8fe736e4860588845) Change-Id: I263f53a0870d80ef4cfaad455fdaa47e2ac4423b BUG: 1509789 Signed-off-by: N Balachandran --- cli/src/cli-cmd-global.c | 3 + cli/src/cli-cmd-misc.c | 77 ++++++++-- cli/src/cli-cmd-parser.c | 20 ++- cli/src/cli-cmd-peer.c | 9 +- cli/src/cli-cmd-snapshot.c | 5 + cli/src/cli-cmd-volume.c | 347 ++++++++++++++++++++++++++++++++++++++------- cli/src/cli.c | 2 +- 7 files changed, 387 insertions(+), 76 deletions(-) (limited to 'cli') diff --git a/cli/src/cli-cmd-global.c b/cli/src/cli-cmd-global.c index 9873192686e..fb2ecb1d3de 100644 --- a/cli/src/cli-cmd-global.c +++ b/cli/src/cli-cmd-global.c @@ -62,11 +62,14 @@ cli_cmd_global_help_cbk (struct cli_state *state, struct cli_cmd_word *in_word, count = (sizeof (global_cmds) / sizeof (struct cli_cmd)); cli_cmd_sort (cmd, count); + cli_out ("\ngluster global commands"); + cli_out ("========================\n"); for (global_cmd = cmd; global_cmd->pattern; global_cmd++) if (_gf_false == global_cmd->disable) cli_out ("%s - %s", global_cmd->pattern, global_cmd->desc); + cli_out ("\n"); GF_FREE (cmd); return 0; } diff --git a/cli/src/cli-cmd-misc.c b/cli/src/cli-cmd-misc.c index 9f8c159f073..c887515af85 100644 --- a/cli/src/cli-cmd-misc.c +++ b/cli/src/cli-cmd-misc.c @@ -23,6 +23,9 @@ extern struct rpc_clnt *global_rpc; extern rpc_clnt_prog_t *cli_rpc_prog; extern struct cli_cmd volume_cmds[]; +extern struct cli_cmd bitrot_cmds[]; +extern struct cli_cmd quota_cmds[]; +extern struct cli_cmd tier_cmds[]; extern struct cli_cmd cli_probe_cmds[]; extern struct cli_cmd cli_log_cmds[]; extern struct cli_cmd cli_system_cmds[]; @@ -38,37 +41,76 @@ cli_cmd_quit_cbk (struct cli_state *state, struct cli_cmd_word *word, exit (0); } + +static gf_boolean_t +cli_is_help_command (const char *pattern) +{ + /* FixFixFix + * This is not the best way to determine whether + * this is a help command + */ + if (strstr (pattern, "help")) + return _gf_true; + + return _gf_false; +} + + int cli_cmd_display_help (struct cli_state *state, struct cli_cmd_word *in_word, const char **words, int wordcount) { - struct cli_cmd *cmd[] = {volume_cmds, cli_probe_cmds, - cli_misc_cmds, snapshot_cmds, - global_cmds, NULL}; - struct cli_cmd *cmd_ind = NULL; - int i = 0; + struct cli_cmd *cmd[] = {cli_misc_cmds, cli_probe_cmds, + volume_cmds, bitrot_cmds, quota_cmds, +#if !defined(__NetBSD__) + tier_cmds, +#endif + snapshot_cmds, global_cmds, NULL}; + struct cli_cmd *cmd_ind = NULL; + int i = 0; + gf_boolean_t list_all = _gf_false; /* cli_system_cmds commands for internal usage they are not exposed */ - for (i=0; cmd[i]!=NULL; i++) - for (cmd_ind = cmd[i]; cmd_ind->pattern; cmd_ind++) - if (_gf_false == cmd_ind->disable) - cli_out ("%s - %s", cmd_ind->pattern, - cmd_ind->desc); + /* If "help all" */ + if (wordcount == 2) + list_all = _gf_true; + + for (i = 0; cmd[i] != NULL; i++) { + for (cmd_ind = cmd[i]; cmd_ind->pattern; cmd_ind++) { + if ((_gf_false == cmd_ind->disable) && + cli_is_help_command (cmd_ind->pattern)) { + if (list_all && (cmd_ind->cbk)) { + cmd_ind->cbk (state, in_word, words, + wordcount); + } else { + cli_out (" %-25s- %s", cmd_ind->pattern, + cmd_ind->desc); + } + } + } + } + + cli_out ("\n"); return 0; } + +struct cli_cmd cli_help_cmds[] = { + { "help [all]", + cli_cmd_display_help, + "display help for command classes"}, + + { NULL, NULL, NULL } +}; + + struct cli_cmd cli_misc_cmds[] = { { "quit", cli_cmd_quit_cbk, "quit"}, - - { "help", - cli_cmd_display_help, - "display command options"}, - { "exit", cli_cmd_quit_cbk, "exit"}, @@ -84,7 +126,12 @@ cli_cmd_misc_register (struct cli_state *state) struct cli_cmd *cmd = NULL; for (cmd = cli_misc_cmds; cmd->pattern; cmd++) { + ret = cli_cmd_register (&state->tree, cmd); + if (ret) + goto out; + } + for (cmd = cli_help_cmds; cmd->pattern; cmd++) { ret = cli_cmd_register (&state->tree, cmd); if (ret) goto out; diff --git a/cli/src/cli-cmd-parser.c b/cli/src/cli-cmd-parser.c index 482010ce502..9e112954811 100644 --- a/cli/src/cli-cmd-parser.c +++ b/cli/src/cli-cmd-parser.c @@ -1075,8 +1075,13 @@ cli_cmd_quota_parse (const char **words, int wordcount, dict_t **options) goto out; } - if (wordcount < 4) + if (wordcount < 4) { + + if ((wordcount == 3) && !(strcmp (words[2], "help"))) { + ret = 1; + } goto out; + } volname = (char *)words[2]; if (!volname) { @@ -5477,15 +5482,22 @@ cli_cmd_bitrot_parse (const char **words, int wordcount, dict_t **options) GF_ASSERT (words); GF_ASSERT (options); - dict = dict_new (); - if (!dict) - goto out; + + /* Hack to print out bitrot help properly */ + if ((wordcount == 3) && !(strcmp (words[2], "help"))) { + ret = 1; + return ret; + } if (wordcount < 4 || wordcount > 5) { gf_log ("cli", GF_LOG_ERROR, "Invalid syntax"); goto out; } + dict = dict_new (); + if (!dict) + goto out; + volname = (char *)words[2]; if (!volname) { ret = -1; diff --git a/cli/src/cli-cmd-peer.c b/cli/src/cli-cmd-peer.c index 4802f71eca8..7df60bcb2be 100644 --- a/cli/src/cli-cmd-peer.c +++ b/cli/src/cli-cmd-peer.c @@ -264,7 +264,7 @@ struct cli_cmd cli_probe_cmds[] = { { "peer help", cli_cmd_peer_help_cbk, - "Help command for peer "}, + "display help for peer commands"}, { "pool list", cli_cmd_pool_list_cbk, @@ -281,17 +281,20 @@ cli_cmd_peer_help_cbk (struct cli_state *state, struct cli_cmd_word *in_word, struct cli_cmd *probe_cmd = NULL; int count = 0; + cli_out ("\ngluster peer commands"); + cli_out ("======================\n"); + cmd = GF_CALLOC (1, sizeof (cli_probe_cmds), cli_mt_cli_cmd); memcpy (cmd, cli_probe_cmds, sizeof (cli_probe_cmds)); count = (sizeof (cli_probe_cmds) / sizeof (struct cli_cmd)); cli_cmd_sort (cmd, count); - - for (probe_cmd = cmd; probe_cmd->pattern; probe_cmd++) cli_out ("%s - %s", probe_cmd->pattern, probe_cmd->desc); GF_FREE (cmd); + + cli_out ("\n"); return 0; } diff --git a/cli/src/cli-cmd-snapshot.c b/cli/src/cli-cmd-snapshot.c index e79128c5a59..88b4737cd65 100644 --- a/cli/src/cli-cmd-snapshot.c +++ b/cli/src/cli-cmd-snapshot.c @@ -140,9 +140,14 @@ cli_cmd_snapshot_help_cbk (struct cli_state *state, count = (sizeof (snapshot_cmds) / sizeof (struct cli_cmd)); cli_cmd_sort (cmd, count); + cli_out ("\ngluster snapshot commands"); + cli_out ("=========================\n"); + for (snap_cmd = cmd; snap_cmd->pattern; snap_cmd++) if (_gf_false == snap_cmd->disable) cli_out ("%s - %s", snap_cmd->pattern, snap_cmd->desc); + cli_out ("\n"); + GF_FREE (cmd); return 0; } diff --git a/cli/src/cli-cmd-volume.c b/cli/src/cli-cmd-volume.c index 7bedd29306f..f9c16c3d792 100644 --- a/cli/src/cli-cmd-volume.c +++ b/cli/src/cli-cmd-volume.c @@ -36,7 +36,19 @@ extern rpc_clnt_prog_t cli_quotad_clnt; int cli_cmd_volume_help_cbk (struct cli_state *state, struct cli_cmd_word *in_word, - const char **words, int wordcount); + const char **words, int wordcount); + +int +cli_cmd_bitrot_help_cbk (struct cli_state *state, struct cli_cmd_word *in_word, + const char **words, int wordcount); + +int +cli_cmd_quota_help_cbk (struct cli_state *state, struct cli_cmd_word *in_word, + const char **words, int wordcount); + +int +cli_cmd_tier_help_cbk (struct cli_state *state, struct cli_cmd_word *in_word, + const char **words, int wordcount); int cli_cmd_volume_info_cbk (struct cli_state *state, struct cli_cmd_word *word, @@ -1293,9 +1305,12 @@ cli_cmd_volume_tier_cbk (struct cli_state *state, if (wordcount < 4) { - cli_usage_out (word->pattern); - if (wordcount == 3 && !strcmp(words[2], "help")) + if (wordcount == 3 && !strcmp(words[2], "help")) { + cli_cmd_tier_help_cbk (state, word, words, wordcount); ret = 0; + } else { + cli_usage_out (word->pattern); + } goto out; } @@ -1719,6 +1734,8 @@ out: return ret; } + + int cli_cmd_bitrot_cbk (struct cli_state *state, struct cli_cmd_word *word, const char **words, int wordcount) @@ -1746,6 +1763,13 @@ cli_cmd_bitrot_cbk (struct cli_state *state, struct cli_cmd_word *word, goto out; } + if (ret == 1) { + /* this is 'volume bitrot help' */ + cli_cmd_bitrot_help_cbk (state, word, words, wordcount); + ret = 0; + goto out2; + } + frame = create_frame (THIS, THIS->ctx->pool); if (!frame) { ret = -1; @@ -1834,7 +1858,7 @@ out: #endif CLI_STACK_DESTROY (frame); - +out2: return ret; } @@ -1866,6 +1890,12 @@ cli_cmd_quota_cbk (struct cli_state *state, struct cli_cmd_word *word, } } else { ret = cli_cmd_quota_parse (words, wordcount, &options); + + if (ret == 1) { + cli_cmd_quota_help_cbk (state, word, words, wordcount); + ret = 0; + goto out; + } if (ret < 0) { cli_usage_out (word->pattern); parse_err = 1; @@ -3164,7 +3194,159 @@ out: return ret; } + +/* This is a bit of a hack to display the help. The current bitrot cmd + * format does not work well when registering the cmds. + * Ideally the should have been of the form + * gluster volume bitrot ... + */ + +struct cli_cmd bitrot_cmds[] = { + + {"volume bitrot help", + cli_cmd_bitrot_help_cbk, + "display help for volume bitrot commands" + }, + + {"volume bitrot {enable|disable}", + NULL, /*cli_cmd_bitrot_cbk,*/ + "Enable/disable bitrot for volume " + }, + + {"volume bitrot scrub-throttle {lazy|normal|aggressive}", + NULL, /*cli_cmd_bitrot_cbk,*/ + "Set the speed of the scrubber for volume " + }, + + {"volume bitrot scrub-frequency {hourly|daily|weekly|biweekly" + "|monthly}", + NULL, /*cli_cmd_bitrot_cbk,*/ + "Set the frequency of the scrubber for volume " + }, + + {"volume bitrot scrub {pause|resume|status|ondemand}", + NULL, /*cli_cmd_bitrot_cbk,*/ + "Pause/resume the scrubber for . Status displays the status of " + "the scrubber. ondemand starts the scrubber immediately." + }, + + {"volume bitrot {enable|disable}\n" + "volume bitrot scrub-throttle {lazy|normal|aggressive}\n" + "volume bitrot scrub-frequency {hourly|daily|weekly|biweekly" + "|monthly}\n" + "volume bitrot scrub {pause|resume|status|ondemand}", + cli_cmd_bitrot_cbk, + NULL + }, + + { NULL, NULL, NULL } +}; + + +struct cli_cmd quota_cmds[] = { + + /* Quota commands */ + {"volume quota help", + cli_cmd_quota_help_cbk, + "display help for volume quota commands" + }, + + {"volume quota {enable|disable|list [ ...]| " + "list-objects [ ...] | remove | remove-objects | " + "default-soft-limit }", + cli_cmd_quota_cbk, + "Enable/disable and configure quota for " + }, + + {"volume quota {limit-usage []}", + cli_cmd_quota_cbk, + "Set maximum size for for " + }, + + {"volume quota {limit-objects []}", + cli_cmd_quota_cbk, + "Set the maximum number of entries allowed in for " + }, + + {"volume quota {alert-time|soft-timeout|hard-timeout} {