diff options
author | Kaushal M <kaushal@gluster.com> | 2011-09-26 10:33:56 +0530 |
---|---|---|
committer | Vijay Bellur <vijay@gluster.com> | 2011-09-27 05:38:36 -0700 |
commit | 9dc9fb48f1790a76c499b105687cee82b2840865 (patch) | |
tree | 9762abee91054ec8a1314cf5cddc4dca6f635f02 /xlators | |
parent | ea71efe027e9f741032b6bf9dd995bcaa2fa7947 (diff) |
glusterd: support for resetting single option
Allows resetting of only single options using 'volume reset' command.
New syntax of volume reset is: 'volume reset [option] [force]'.
Giving "all" as options or not specifying an option, causes all options
to be reset.
Change-Id: Ib9e220f326adeb1be1a774737a0b12c910012cea
BUG: 2980
Reviewed-on: http://review.gluster.com/450
Tested-by: Gluster Build System <jenkins@build.gluster.com>
Reviewed-by: Amar Tumballi <amar@gluster.com>
Diffstat (limited to 'xlators')
-rw-r--r-- | xlators/mgmt/glusterd/src/glusterd-op-sm.c | 63 | ||||
-rw-r--r-- | xlators/mgmt/glusterd/src/glusterd-op-sm.h | 2 |
2 files changed, 57 insertions, 8 deletions
diff --git a/xlators/mgmt/glusterd/src/glusterd-op-sm.c b/xlators/mgmt/glusterd/src/glusterd-op-sm.c index 11cbeba0851..4271fe2460e 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 97385e6a49b..668da556df1 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); |