diff options
author | Kaushik BV <kaushikbv@gluster.com> | 2011-04-21 06:55:44 +0000 |
---|---|---|
committer | Anand Avati <avati@gluster.com> | 2011-04-22 03:52:24 -0700 |
commit | 49603aec03e98a2a38fad66627593b69b6269cbf (patch) | |
tree | c779d7f8be2e4477d057f17d49713fdb007639f6 /cli/src | |
parent | b5848ed21b9e718011a8f3f3870c4ed978ff17a5 (diff) |
cli: changes in struct cli_cmd to disable gluster command at run-time
Signed-off-by: Kaushik BV <kaushikbv@gluster.com>
Signed-off-by: Anand Avati <avati@gluster.com>
BUG: 2744 (make geo-replication package friendly)
URL: http://bugs.gluster.com/cgi-bin/bugzilla3/show_bug.cgi?id=2744
Diffstat (limited to 'cli/src')
-rw-r--r-- | cli/src/cli-cmd-misc.c | 30 | ||||
-rw-r--r-- | cli/src/cli-cmd-peer.c | 4 | ||||
-rw-r--r-- | cli/src/cli-cmd-system.c | 4 | ||||
-rw-r--r-- | cli/src/cli-cmd-volume.c | 7 | ||||
-rw-r--r-- | cli/src/cli-cmd.h | 9 | ||||
-rw-r--r-- | cli/src/cli.h | 6 | ||||
-rw-r--r-- | cli/src/registry.c | 37 |
7 files changed, 54 insertions, 43 deletions
diff --git a/cli/src/cli-cmd-misc.c b/cli/src/cli-cmd-misc.c index 1e356c63bea..55825f6993b 100644 --- a/cli/src/cli-cmd-misc.c +++ b/cli/src/cli-cmd-misc.c @@ -54,23 +54,19 @@ int cli_cmd_display_help (struct cli_state *state, struct cli_cmd_word *in_word, const char **words, int wordcount) { - struct cli_cmd *cmd = NULL; + struct cli_cmd *cmd[] = {volume_cmds, cli_probe_cmds, + cli_misc_cmds, NULL}; + struct cli_cmd *cmd_ind = NULL; + int i = 0; - for (cmd = volume_cmds; cmd->pattern; cmd++) - cli_out ("%s - %s", cmd->pattern, cmd->desc); - - for (cmd = cli_probe_cmds; cmd->pattern; cmd++) - cli_out ("%s - %s", cmd->pattern, cmd->desc); - - /* - * commands for internal usage, don't expose - - for (cmd = cli_system_cmds; cmd->pattern; cmd++) - cli_out ("%s - %s", cmd->pattern, cmd->desc); + /* cli_systerm_cmds commands for internal usage + they are not exposed */ - - for (cmd = cli_misc_cmds; cmd->pattern; cmd++) - cli_out ("%s - %s", cmd->pattern, cmd->desc); + 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); return 0; } @@ -95,8 +91,8 @@ 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->pattern, cmd->cbk, - cmd->desc); + + ret = cli_cmd_register (&state->tree, cmd); if (ret) goto out; } diff --git a/cli/src/cli-cmd-peer.c b/cli/src/cli-cmd-peer.c index c931341c38b..11d029bf1c6 100644 --- a/cli/src/cli-cmd-peer.c +++ b/cli/src/cli-cmd-peer.c @@ -224,8 +224,8 @@ cli_cmd_probe_register (struct cli_state *state) struct cli_cmd *cmd = NULL; for (cmd = cli_probe_cmds; cmd->pattern; cmd++) { - ret = cli_cmd_register (&state->tree, cmd->pattern, cmd->cbk, - cmd->desc); + + ret = cli_cmd_register (&state->tree, cmd); if (ret) goto out; } diff --git a/cli/src/cli-cmd-system.c b/cli/src/cli-cmd-system.c index 36300248909..2dff572fda7 100644 --- a/cli/src/cli-cmd-system.c +++ b/cli/src/cli-cmd-system.c @@ -221,8 +221,8 @@ cli_cmd_system_register (struct cli_state *state) struct cli_cmd *cmd = NULL; for (cmd = cli_system_cmds; cmd->pattern; cmd++) { - ret = cli_cmd_register (&state->tree, cmd->pattern, cmd->cbk, - cmd->desc); + + ret = cli_cmd_register (&state->tree, cmd); if (ret) goto out; } diff --git a/cli/src/cli-cmd-volume.c b/cli/src/cli-cmd-volume.c index 55044b33aa5..e49b8f23011 100644 --- a/cli/src/cli-cmd-volume.c +++ b/cli/src/cli-cmd-volume.c @@ -1194,7 +1194,8 @@ cli_cmd_volume_help_cbk (struct cli_state *state, struct cli_cmd_word *in_word, struct cli_cmd *cmd = NULL; for (cmd = volume_cmds; cmd->pattern; cmd++) - cli_out ("%s - %s", cmd->pattern, cmd->desc); + if (_gf_false == cmd->disable) + cli_out ("%s - %s", cmd->pattern, cmd->desc); return 0; } @@ -1206,8 +1207,8 @@ cli_cmd_volume_register (struct cli_state *state) struct cli_cmd *cmd = NULL; for (cmd = volume_cmds; cmd->pattern; cmd++) { - ret = cli_cmd_register (&state->tree, cmd->pattern, cmd->cbk, - cmd->desc); + + ret = cli_cmd_register (&state->tree, cmd); if (ret) goto out; } diff --git a/cli/src/cli-cmd.h b/cli/src/cli-cmd.h index ee784f0e95b..acb40017a5b 100644 --- a/cli/src/cli-cmd.h +++ b/cli/src/cli-cmd.h @@ -33,9 +33,12 @@ typedef enum { } gf_answer_t; struct cli_cmd { - const char *pattern; - cli_cmd_cbk_t *cbk; - const char *desc; + const char *pattern; + cli_cmd_cbk_t *cbk; + const char *desc; + cli_cmd_reg_cbk_t *reg_cbk; /* callback to check in runtime if the * + * command should be enabled or disabled */ + gf_boolean_t disable; }; struct cli_cmd_volume_get_ctx_ { diff --git a/cli/src/cli.h b/cli/src/cli.h index f365da70f81..70d6cfb271a 100644 --- a/cli/src/cli.h +++ b/cli/src/cli.h @@ -46,11 +46,14 @@ enum argp_option_keys { struct cli_state; struct cli_cmd_word; struct cli_cmd_tree; +struct cli_cmd; typedef int (cli_cmd_cbk_t)(struct cli_state *state, struct cli_cmd_word *word, const char **words, int wordcount); +typedef void (cli_cmd_reg_cbk_t)( struct cli_cmd *this); + typedef int (cli_cmd_match_t)(struct cli_cmd_word *word); typedef int (cli_cmd_filler_t)(struct cli_cmd_word *word); @@ -147,8 +150,7 @@ typedef ssize_t (*cli_serialize_t) (struct iovec outmsg, void *args); extern struct cli_state *global_state; /* use only in readline callback */ -int cli_cmd_register (struct cli_cmd_tree *tree, const char *template, - cli_cmd_cbk_t cbk, const char *desc); +int cli_cmd_register (struct cli_cmd_tree *tree, struct cli_cmd *cmd); int cli_cmds_register (struct cli_state *state); int cli_input_init (struct cli_state *state); diff --git a/cli/src/registry.c b/cli/src/registry.c index a65e26ecaee..8fa116a48c7 100644 --- a/cli/src/registry.c +++ b/cli/src/registry.c @@ -362,31 +362,40 @@ cli_cmd_ingest (struct cli_cmd_tree *tree, char **tokens, cli_cmd_cbk_t *cbkfn, int -cli_cmd_register (struct cli_cmd_tree *tree, const char *template, - cli_cmd_cbk_t cbk, const char *desc) +cli_cmd_register (struct cli_cmd_tree *tree, struct cli_cmd *cmd) { char **tokens = NULL; int ret = 0; - if (!template) - return -1; + GF_ASSERT (cmd) - tokens = cli_cmd_tokenize (template); - if (!tokens) - return -1; + if (cmd->reg_cbk) + cmd->reg_cbk (cmd); - ret = cli_cmd_ingest (tree, tokens, cbk, desc, template); - if (ret) - goto err; + if (cmd->disable) { + ret = 0; + goto out; + } - if (tokens) - cli_cmd_tokens_destroy (tokens); + tokens = cli_cmd_tokenize (cmd->pattern); + if (!tokens) { + ret = -1; + goto out; + } - return 0; -err: + ret = cli_cmd_ingest (tree, tokens, cmd->cbk, cmd->desc, cmd->pattern); + if (ret) { + ret = -1; + goto out; + } + + ret = 0; + +out: if (tokens) cli_cmd_tokens_destroy (tokens); + gf_log ("cli", GF_LOG_DEBUG, "Returning %d", ret); return ret; } |