diff options
author | Samikshan Bairagya <samikshan@gmail.com> | 2016-09-23 16:35:15 +0530 |
---|---|---|
committer | Atin Mukherjee <amukherj@redhat.com> | 2016-12-30 20:47:27 -0800 |
commit | 08056421b886b1ebf1e0eed93d9f6f9b6d017489 (patch) | |
tree | a83374aa443f956d17d4b0de897345c7be47c1a4 /xlators/mgmt/glusterd/src/glusterd-utils.c | |
parent | 14ae0c6b14c9a32f15cdb3c94edbf08bb2e708b6 (diff) |
glusterd, cli: Get global options through volume get functionality
Currently it is not possible to retrieve values of global options
by using the 'gluster volume get' functionality if there are no
volumes present. In order to get the global options one has to use
'gluster volume get' with a specific volume name. This usage makes
the illusion as though the option is set only on one volume, which
is incorrect. When setting the global options, 'gluster volume set'
provides a way to set them using the volume name as 'all'.
Similarly, retrieving the global options should be made possible by
using the volume name 'all' with the 'gluster volume get'
functionality. This patch adds that functionality to 'volume get'
Usage:
# gluster volume get all <OPTION/all>
Change-Id: Ic2fdb9eda69d4806d432dae26d117d9660fe6d4e
BUG: 1378842
Signed-off-by: Samikshan Bairagya <samikshan@gmail.com>
Reviewed-on: http://review.gluster.org/15563
Smoke: Gluster Build System <jenkins@build.gluster.org>
NetBSD-regression: NetBSD Build System <jenkins@build.gluster.org>
CentOS-regression: Gluster Build System <jenkins@build.gluster.org>
Reviewed-by: Atin Mukherjee <amukherj@redhat.com>
Diffstat (limited to 'xlators/mgmt/glusterd/src/glusterd-utils.c')
-rw-r--r-- | xlators/mgmt/glusterd/src/glusterd-utils.c | 120 |
1 files changed, 120 insertions, 0 deletions
diff --git a/xlators/mgmt/glusterd/src/glusterd-utils.c b/xlators/mgmt/glusterd/src/glusterd-utils.c index a1c9132feda..998c5a0d5da 100644 --- a/xlators/mgmt/glusterd/src/glusterd-utils.c +++ b/xlators/mgmt/glusterd/src/glusterd-utils.c @@ -93,6 +93,7 @@ #define NLMV1_VERSION 1 extern struct volopt_map_entry glusterd_volopt_map[]; +extern glusterd_all_vol_opts valid_all_vol_opts[]; static glusterd_lock_t lock; @@ -10912,6 +10913,125 @@ out: } int +glusterd_get_global_options_for_all_vols (dict_t *ctx, char **op_errstr) +{ + int ret = -1; + int count = 0; + gf_boolean_t all_opts = _gf_false; + gf_boolean_t key_found = _gf_false; + glusterd_conf_t *priv = NULL; + xlator_t *this = NULL; + char *key = NULL; + char *key_fixed = NULL; + char dict_key[50] = {0,}; + char *def_val = NULL; + char err_str[PATH_MAX] = {0,}; + char *allvolopt = NULL; + int32_t i = 0; + gf_boolean_t exists = _gf_false; + + this = THIS; + GF_VALIDATE_OR_GOTO (THIS->name, this, out); + + priv = this->private; + GF_VALIDATE_OR_GOTO (this->name, priv, out); + + GF_VALIDATE_OR_GOTO (this->name, ctx, out); + + ret = dict_get_str (ctx, "key", &key); + if (ret) { + gf_msg (this->name, GF_LOG_ERROR, 0, + GD_MSG_DICT_GET_FAILED, + "Failed to get option key from dictionary"); + goto out; + } + + if (strcasecmp (key, "all") == 0) + all_opts = _gf_true; + else { + exists = glusterd_check_option_exists (key, &key_fixed); + if (!exists) { + snprintf (err_str, sizeof (err_str), "Option " + "with name: %s does not exist", key); + gf_msg (this->name, GF_LOG_ERROR, EINVAL, + GD_MSG_UNKNOWN_KEY, "%s", err_str); + if (key_fixed) + snprintf (err_str, sizeof (err_str), + "Did you mean %s?", key_fixed); + ret = -1; + goto out; + } + if (key_fixed) + key = key_fixed; + } + + ALL_VOLUME_OPTION_CHECK ("all", _gf_true, key, ret, op_errstr, out); + + for (i = 0; valid_all_vol_opts[i].option; i++) { + allvolopt = gf_strdup (valid_all_vol_opts[i].option); + + if (!all_opts && strcmp (key, allvolopt) != 0) + continue; + + ret = dict_get_str (priv->opts, allvolopt, &def_val); + + /* If global option isn't set explicitly */ + if (!def_val) { + if (!strcmp (allvolopt, GLUSTERD_GLOBAL_OP_VERSION_KEY)) + gf_asprintf (&def_val, "%d", priv->op_version); + else if (!strcmp (allvolopt, GLUSTERD_QUORUM_RATIO_KEY)) + gf_asprintf (&def_val, "%d", 0); + else if (!strcmp (allvolopt, GLUSTERD_SHARED_STORAGE_KEY)) + gf_asprintf (&def_val, "%s", "disable"); + } + + count++; + sprintf (dict_key, "key%d", count); + ret = dict_set_str (ctx, dict_key, allvolopt); + if (ret) { + gf_msg (this->name, GF_LOG_ERROR, 0, + GD_MSG_DICT_SET_FAILED, + "Failed to set %s in dictionary", allvolopt); + goto out; + } + + sprintf (dict_key, "value%d", count); + ret = dict_set_dynstr_with_alloc (ctx, dict_key, def_val); + if (ret) { + gf_msg (this->name, GF_LOG_ERROR, 0, + GD_MSG_DICT_SET_FAILED, + "Failed to set %s for key %s in dictionary", + def_val, allvolopt); + goto out; + } + + def_val = NULL; + allvolopt = NULL; + + if (!all_opts) + break; + } + + ret = dict_set_int32 (ctx, "count", count); + if (ret) { + gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_SET_FAILED, + "Failed to set count in dictionary"); + } + +out: + if (ret && !all_opts && !key_found) { + if (err_str == NULL) + snprintf (err_str, sizeof (err_str), + "option %s does not exist", key); + if (*op_errstr == NULL) + *op_errstr = gf_strdup (err_str); + } + gf_msg_debug (THIS->name, 0, "Returning %d", ret); + + return ret; +} + +int glusterd_get_default_val_for_volopt (dict_t *ctx, gf_boolean_t all_opts, char *input_key, char *orig_key, dict_t *vol_dict, char **op_errstr) |