From a975c385c9cb0bb0b42993c2eb23a6f9bf277991 Mon Sep 17 00:00:00 2001 From: Mohammed Rafi KC Date: Mon, 11 May 2015 14:43:23 +0530 Subject: tier/volume set: Validate volume set option for tier Volume set option related to tier volume can only be set for tier volume, also currently all volume set i for tier option accepts a non-negative integer. This patch validate both condition. Back port of: >Change-Id: I3611af048ff4ab193544058cace8db205ea92336 >BUG: 1216960 >Signed-off-by: Mohammed Rafi KC >Signed-off-by: Dan Lambright >Reviewed-on: http://review.gluster.org/10751 >Tested-by: Gluster Build System >Tested-by: NetBSD Build System >Reviewed-by: Joseph Fernandes (cherry picked from commit f6a062044a3447bea5bf0fcf21a3f85c00fb6c7d) Change-Id: Ic6081f0ce7ae7effac69ba192bd35c8d382a11d5 BUG: 1230560 Signed-off-by: Mohammed Rafi KC Reviewed-on: http://review.gluster.org/11173 Tested-by: NetBSD Build System Tested-by: Gluster Build System Reviewed-by: Joseph Fernandes Tested-by: Joseph Fernandes --- xlators/mgmt/glusterd/src/glusterd-volume-set.c | 82 +++++++++++++++++++++++-- 1 file changed, 78 insertions(+), 4 deletions(-) (limited to 'xlators/mgmt/glusterd/src/glusterd-volume-set.c') diff --git a/xlators/mgmt/glusterd/src/glusterd-volume-set.c b/xlators/mgmt/glusterd/src/glusterd-volume-set.c index aed24469608..5c13abd1861 100644 --- a/xlators/mgmt/glusterd/src/glusterd-volume-set.c +++ b/xlators/mgmt/glusterd/src/glusterd-volume-set.c @@ -16,6 +16,76 @@ #include "glusterd-volgen.h" #include "glusterd-utils.h" +static int +validate_tier (glusterd_volinfo_t *volinfo, dict_t *dict, char *key, + char *value, char **op_errstr) +{ + char errstr[2048] = ""; + int ret = 0; + xlator_t *this = NULL; + int origin_val = -1; + + this = THIS; + GF_ASSERT (this); + + if (volinfo->type != GF_CLUSTER_TYPE_TIER) { + snprintf (errstr, sizeof (errstr), "Volume %s is not a tier " + "volume. Option %s is only valid for tier volume.", + volinfo->volname, key); + gf_log (this->name, GF_LOG_ERROR, "%s", errstr); + *op_errstr = gf_strdup (errstr); + ret = -1; + goto out; + } + + /* + * All the volume set options for tier are expecting a positive + * Integer. Change the function accordingly if this constraint is + * changed. + */ + + ret = gf_string2int (value, &origin_val); + if (ret) { + snprintf (errstr, sizeof (errstr), "%s is not a compatible " + "value. %s expects an integer value.", + value, key); + gf_log (this->name, GF_LOG_ERROR, "%s", errstr); + *op_errstr = gf_strdup (errstr); + ret = -1; + goto out; + } + + if (strstr ("cluster.tier-promote-frequency", key) || + strstr ("cluster.tier-demote-frequency", key)) { + if (origin_val < 1) { + snprintf (errstr, sizeof (errstr), "%s is not a " + "compatible value. %s expects a positive " + "integer value.", + value, key); + gf_log (this->name, GF_LOG_ERROR, "%s", errstr); + *op_errstr = gf_strdup (errstr); + ret = -1; + goto out; + } + } else { + if (origin_val < 0) { + snprintf (errstr, sizeof (errstr), "%s is not a " + "compatible value. %s expects a non-negative" + " integer value.", + value, key); + gf_log (this->name, GF_LOG_ERROR, "%s", errstr); + *op_errstr = gf_strdup (errstr); + ret = -1; + goto out; + } + } + +out: + gf_log (this->name, GF_LOG_DEBUG, "Returning %d", ret); + + return ret; +} + static int validate_cache_max_min_size (glusterd_volinfo_t *volinfo, dict_t *dict, char *key, char *value, char **op_errstr) @@ -1764,25 +1834,29 @@ struct volopt_map_entry glusterd_volopt_map[] = { .voltype = "cluster/tier", .option = "write-freq-threshold", .op_version = GD_OP_VERSION_3_7_0, - .flags = OPT_FLAG_CLIENT_OPT + .flags = OPT_FLAG_CLIENT_OPT, + .validate_fn = validate_tier }, { .key = "cluster.read-freq-threshold", .voltype = "cluster/tier", .option = "read-freq-threshold", .op_version = GD_OP_VERSION_3_7_0, - .flags = OPT_FLAG_CLIENT_OPT + .flags = OPT_FLAG_CLIENT_OPT, + .validate_fn = validate_tier }, { .key = "cluster.tier-promote-frequency", .voltype = "cluster/tier", .option = "tier-promote-frequency", .op_version = GD_OP_VERSION_3_7_0, - .flags = OPT_FLAG_CLIENT_OPT + .flags = OPT_FLAG_CLIENT_OPT, + .validate_fn = validate_tier }, { .key = "cluster.tier-demote-frequency", .voltype = "cluster/tier", .option = "tier-demote-frequency", .op_version = GD_OP_VERSION_3_7_0, - .flags = OPT_FLAG_CLIENT_OPT + .flags = OPT_FLAG_CLIENT_OPT, + .validate_fn = validate_tier }, { .key = "features.ctr-enabled", .voltype = "features/changetimerecorder", -- cgit