diff options
-rw-r--r-- | cli/src/cli-cmd-parser.c | 27 | ||||
-rw-r--r-- | cli/src/cli-cmd-volume.c | 2 | ||||
-rw-r--r-- | xlators/mgmt/glusterd/src/glusterd-op-sm.c | 63 | ||||
-rw-r--r-- | xlators/mgmt/glusterd/src/glusterd-op-sm.h | 2 |
4 files changed, 82 insertions, 12 deletions
diff --git a/cli/src/cli-cmd-parser.c b/cli/src/cli-cmd-parser.c index 2b3db1939..6d984680e 100644 --- a/cli/src/cli-cmd-parser.c +++ b/cli/src/cli-cmd-parser.c @@ -406,7 +406,7 @@ cli_cmd_volume_reset_parse (const char **words, int wordcount, dict_t **options) if (wordcount < 3) goto out; - if (wordcount > 4) + if (wordcount > 5) goto out; volname = (char *)words[2]; @@ -420,8 +420,29 @@ cli_cmd_volume_reset_parse (const char **words, int wordcount, dict_t **options) if (ret) goto out; - if (wordcount == 4) { - if (strcmp ("force", (char*)words[3])) { + if (wordcount == 3) { + ret = dict_set_str (dict, "key", "all"); + if (ret) + goto out; + } + + if (wordcount >= 4) { + if (!strcmp ("force", (char*)words[3])) { + ret = dict_set_int32 (dict, "force", 1); + if (ret) + goto out; + ret = dict_set_str (dict, "key", "all"); + if (ret) + goto out; + } else { + ret = dict_set_str (dict, "key", (char *)words[3]); + if (ret) + goto out; + } + } + + if (wordcount == 5) { + if (strcmp ("force", (char*)words[4])) { ret = -1; goto out; } else { diff --git a/cli/src/cli-cmd-volume.c b/cli/src/cli-cmd-volume.c index a2ec50863..000772532 100644 --- a/cli/src/cli-cmd-volume.c +++ b/cli/src/cli-cmd-volume.c @@ -1579,7 +1579,7 @@ struct cli_cmd volume_cmds[] = { cli_cmd_sync_volume_cbk, "sync the volume information from a peer"}, - { "volume reset <VOLNAME> [force]", + { "volume reset <VOLNAME> [option] [force]", cli_cmd_volume_reset_cbk, "reset all the reconfigured options"}, diff --git a/xlators/mgmt/glusterd/src/glusterd-op-sm.c b/xlators/mgmt/glusterd/src/glusterd-op-sm.c index 11cbeba08..4271fe246 100644 --- a/xlators/mgmt/glusterd/src/glusterd-op-sm.c +++ b/xlators/mgmt/glusterd/src/glusterd-op-sm.c @@ -429,6 +429,8 @@ glusterd_op_stage_reset_volume (dict_t *dict, char **op_errstr) char *volname = NULL; gf_boolean_t exists = _gf_false; char msg[2048] = {0}; + char *key = NULL; + char *key_fixed = NULL; ret = dict_get_str (dict, "volname", &volname); @@ -448,8 +450,35 @@ glusterd_op_stage_reset_volume (dict_t *dict, char **op_errstr) goto out; } + ret = dict_get_str (dict, "key", &key); + if (ret) { + gf_log ("glusterd", GF_LOG_ERROR, "Unable to get option key"); + goto out; + } + if (strcmp(key, "all")) { + exists = glusterd_check_option_exists (key, &key_fixed); + if (exists == -1) { + ret = -1; + goto out; + } + if (!exists) { + gf_log ("glusterd", GF_LOG_ERROR, + "Option %s does not exist", key); + ret = snprintf (msg, 2048, + "Option %s does not exist", key); + if (key_fixed) + snprintf (msg + ret, 2048 - ret, + "\nDid you mean %s?", key_fixed); + *op_errstr = gf_strdup (msg); + ret = -1; + goto out; + } + } out: + if (key_fixed) + GF_FREE (key_fixed); + gf_log ("", GF_LOG_DEBUG, "Returning %d", ret); return ret; @@ -678,15 +707,28 @@ out: } int -glusterd_options_reset (glusterd_volinfo_t *volinfo, int32_t is_force) +glusterd_options_reset (glusterd_volinfo_t *volinfo, char *key, + int32_t is_force) { int ret = 0; + data_t *value = NULL; gf_log ("", GF_LOG_DEBUG, "Received volume set reset command"); GF_ASSERT (volinfo->dict); + GF_ASSERT (key); - dict_foreach (volinfo->dict, _delete_reconfig_opt, &is_force); + if (!strncmp(key, "all", 3)) + dict_foreach (volinfo->dict, _delete_reconfig_opt, &is_force); + else { + value = dict_get (volinfo->dict, key); + if (!value) { + gf_log ("glusterd", GF_LOG_ERROR, + "Could not get value"); + goto out; + } + _delete_reconfig_opt (volinfo->dict, key, value, &is_force); + } ret = glusterd_create_volfiles_and_notify_services (volinfo); @@ -718,10 +760,11 @@ out: static int glusterd_op_reset_volume (dict_t *dict) { - glusterd_volinfo_t *volinfo = NULL; - int ret = -1; - char *volname = NULL; - int32_t is_force = 0; + glusterd_volinfo_t *volinfo = NULL; + int ret = -1; + char *volname = NULL; + char *key = NULL; + int32_t is_force = 0; ret = dict_get_str (dict, "volname", &volname); if (ret) { @@ -733,13 +776,19 @@ glusterd_op_reset_volume (dict_t *dict) if (ret) is_force = 0; + ret = dict_get_str (dict, "key", &key); + if (ret) { + gf_log ("glusterd", GF_LOG_ERROR, "Unable to get option key"); + goto out; + } + ret = glusterd_volinfo_find (volname, &volinfo); if (ret) { gf_log ("", GF_LOG_ERROR, "Unable to allocate memory"); goto out; } - ret = glusterd_options_reset (volinfo, is_force); + ret = glusterd_options_reset (volinfo, key, is_force); out: gf_log ("", GF_LOG_DEBUG, "'volume reset' returning %d", ret); diff --git a/xlators/mgmt/glusterd/src/glusterd-op-sm.h b/xlators/mgmt/glusterd/src/glusterd-op-sm.h index 97385e6a4..668da556d 100644 --- a/xlators/mgmt/glusterd/src/glusterd-op-sm.h +++ b/xlators/mgmt/glusterd/src/glusterd-op-sm.h @@ -230,7 +230,7 @@ glusterd_check_brick_rb_part (char *bricks, int count, glusterd_volinfo_t *volin void glusterd_do_replace_brick (void *data); int -glusterd_options_reset (glusterd_volinfo_t *volinfo, int32_t is_force); +glusterd_options_reset (glusterd_volinfo_t *volinfo, char *key, int32_t is_force); char* glusterd_op_sm_state_name_get (int state); |