From c618de80696c4572fad9e28f0454e63ebb2ff4ed Mon Sep 17 00:00:00 2001 From: Gaurav Yadav Date: Tue, 31 Jan 2017 16:14:46 +0530 Subject: glusterd : Fix for replicate and disperse volume option While setting volume option(disperse-shd-max-threads) for replicate volume and volume option(cluster-shd-max-threads) for disperse volume, glusterd is not validating volume options and setting all the values irrespective of proper validation for disperse-shd-max-threads and cluster-shd-max-threads Change-Id: Ic88815ad49e901e74ffc042170f5caabf7c17a89 BUG: 1417588 Signed-off-by: Gaurav Yadav Reviewed-on: https://review.gluster.org/16489 Smoke: Gluster Build System Reviewed-by: Atin Mukherjee NetBSD-regression: NetBSD Build System CentOS-regression: Gluster Build System --- xlators/mgmt/glusterd/src/glusterd-messages.h | 8 ++++++ xlators/mgmt/glusterd/src/glusterd-volume-set.c | 35 +++++++++++++++++++++++-- 2 files changed, 41 insertions(+), 2 deletions(-) (limited to 'xlators/mgmt/glusterd') diff --git a/xlators/mgmt/glusterd/src/glusterd-messages.h b/xlators/mgmt/glusterd/src/glusterd-messages.h index 5f1339cb5fd..28c73d23d82 100644 --- a/xlators/mgmt/glusterd/src/glusterd-messages.h +++ b/xlators/mgmt/glusterd/src/glusterd-messages.h @@ -2304,6 +2304,14 @@ */ #define GD_MSG_VOL_NOT_REPLICA (GLUSTERD_COMP_BASE + 281) +/*! + * @messageid + * @diagnosis + * @recommendedaction + * + */ +#define GD_MSG_VOL_NOT_DISPERSE (GLUSTERD_COMP_BASE + 282) + /*! * @messageid * @diagnosis diff --git a/xlators/mgmt/glusterd/src/glusterd-volume-set.c b/xlators/mgmt/glusterd/src/glusterd-volume-set.c index b3f6c40d7f0..3229e17fd5f 100644 --- a/xlators/mgmt/glusterd/src/glusterd-volume-set.c +++ b/xlators/mgmt/glusterd/src/glusterd-volume-set.c @@ -719,6 +719,35 @@ out: return ret; } +static int +validate_disperse (glusterd_volinfo_t *volinfo, dict_t *dict, char *key, + char *value, char **op_errstr) +{ + char errstr[2048] = ""; + int ret = -1; + xlator_t *this = NULL; + + this = THIS; + GF_VALIDATE_OR_GOTO ("glusterd", this, out); + + if (volinfo->type != GF_CLUSTER_TYPE_DISPERSE) { + snprintf (errstr, sizeof (errstr), + "Cannot set %s for a non-disperse volume.", key); + gf_msg (this->name, GF_LOG_ERROR, 0, + GD_MSG_VOL_NOT_DISPERSE, "%s", errstr); + *op_errstr = gf_strdup (errstr); + ret = -1; + goto out; + } + ret = 0; + +out: + gf_msg_debug (ret == 0 ? THIS->name : "glusterd", 0, "Returning %d", + ret); + + return ret; +} + static int validate_replica (glusterd_volinfo_t *volinfo, dict_t *dict, char *key, char *value, char **op_errstr) @@ -3044,7 +3073,8 @@ struct volopt_map_entry glusterd_volopt_map[] = { { .key = "cluster.shd-max-threads", .voltype = "cluster/replicate", .op_version = GD_OP_VERSION_3_7_12, - .flags = OPT_FLAG_CLIENT_OPT + .flags = OPT_FLAG_CLIENT_OPT, + .validate_fn = validate_replica }, { .key = "cluster.shd-wait-qlength", .voltype = "cluster/replicate", @@ -3087,7 +3117,8 @@ struct volopt_map_entry glusterd_volopt_map[] = { { .key = "disperse.shd-max-threads", .voltype = "cluster/disperse", .op_version = GD_OP_VERSION_3_9_0, - .flags = OPT_FLAG_CLIENT_OPT + .flags = OPT_FLAG_CLIENT_OPT, + .validate_fn = validate_disperse }, { .key = "disperse.shd-wait-qlength", .voltype = "cluster/disperse", -- cgit