From 1ee8ce725f0e70f45419aa0e2f4d85db7223d766 Mon Sep 17 00:00:00 2001 From: GauravKumarGarg Date: Tue, 6 Jan 2015 16:58:38 +0530 Subject: glusterd: option features.uss should accept only boolean value "features.uss" with a non-boolean value gets set in the volume option table because of which subsequent volume set operation fails since features.uss does not contain a valid boolean value. Fix is not to allow a non-boolean value to get set in the volume option table. "features.uss" option should have validation function "validate_uss" which validate the input value given by user. Change-Id: I4a212f876627a4979715183b0d488fd69095f193 BUG: 1179175 Signed-off-by: ggarg Reviewed-on: http://review.gluster.org/9395 Tested-by: Gluster Build System Reviewed-by: Krishnan Parthasarathi Tested-by: Krishnan Parthasarathi --- .../glusterd/bug-1179175-uss-option-validation.t | 37 ++++++++++++++++++++++ xlators/mgmt/glusterd/src/glusterd-volume-set.c | 27 ++++++++++++++++ 2 files changed, 64 insertions(+) create mode 100644 tests/bugs/glusterd/bug-1179175-uss-option-validation.t diff --git a/tests/bugs/glusterd/bug-1179175-uss-option-validation.t b/tests/bugs/glusterd/bug-1179175-uss-option-validation.t new file mode 100644 index 0000000000..6bbe3c9336 --- /dev/null +++ b/tests/bugs/glusterd/bug-1179175-uss-option-validation.t @@ -0,0 +1,37 @@ +#!/bin/bash + +## Test case for option features.uss validation. + +. $(dirname $0)/../../include.rc +. $(dirname $0)/../../volume.rc + +cleanup; + +## Start glusterd +TEST glusterd; +TEST pidof glusterd; + +## Lets create and start volume +TEST $CLI volume create $V0 $H0:$B0/${V0}{1,2}; +TEST $CLI volume start $V0 + +## Set features.uss option with non-boolean value. These non-boolean value +## for features.uss option should fail. +TEST ! $CLI volume set $V0 features.uss abcd +TEST ! $CLI volume set $V0 features.uss #$#$ +TEST ! $CLI volume set $V0 features.uss 2324 + +## Setting other options with valid value. These options should succeed. +TEST $CLI volume set $V0 barrier enable +TEST $CLI volume set $V0 ping-timeout 60 + +## Set features.uss option with valid boolean value. It should succeed. +TEST $CLI volume set $V0 features.uss enable +TEST $CLI volume set $V0 features.uss disable + + +## Setting other options with valid value. These options should succeed. +TEST $CLI volume set $V0 barrier enable +TEST $CLI volume set $V0 ping-timeout 60 + +cleanup; diff --git a/xlators/mgmt/glusterd/src/glusterd-volume-set.c b/xlators/mgmt/glusterd/src/glusterd-volume-set.c index a92bfffdb4..27f35238da 100644 --- a/xlators/mgmt/glusterd/src/glusterd-volume-set.c +++ b/xlators/mgmt/glusterd/src/glusterd-volume-set.c @@ -196,6 +196,32 @@ out: return ret; } +static int +validate_uss (dict_t *dict, char *key, char *value, char **op_errstr) +{ + char errstr[2048] = ""; + int ret = 0; + xlator_t *this = NULL; + gf_boolean_t b = _gf_false; + + this = THIS; + GF_ASSERT (this); + + ret = gf_string2boolean (value, &b); + if (ret) { + snprintf (errstr, sizeof (errstr), "%s is not a valid boolean " + "value. %s expects a valid boolean value.", value, + key); + gf_log (this->name, GF_LOG_ERROR, "%s", errstr); + *op_errstr = gf_strdup (errstr); + goto out; + } +out: + gf_log (this->name, GF_LOG_DEBUG, "Returning %d", ret); + + return ret; +} + static int validate_stripe (dict_t *dict, char *key, char *value, char **op_errstr) { @@ -1141,6 +1167,7 @@ struct volopt_map_entry glusterd_volopt_map[] = { .op_version = GD_OP_VERSION_3_6_0, .value = "off", .flags = OPT_FLAG_CLIENT_OPT | OPT_FLAG_XLATOR_OPT, + .validate_fn = validate_uss, .description = "enable/disable User Serviceable Snapshots on the " "volume." }, -- cgit