diff options
-rw-r--r-- | tests/basic/uss.t | 12 | ||||
-rw-r--r-- | tests/bugs/snapshot/bug-1164613.t | 34 | ||||
-rw-r--r-- | xlators/mgmt/glusterd/src/glusterd-volume-set.c | 56 |
3 files changed, 67 insertions, 35 deletions
diff --git a/tests/basic/uss.t b/tests/basic/uss.t index 60fcadffd2e..7a4f043d260 100644 --- a/tests/basic/uss.t +++ b/tests/basic/uss.t @@ -68,6 +68,18 @@ for i in {1..10}; do TEST_IN_LOOP ! $CLI volume set $V0 features.uss $RANDOM_STRING done +## Test that features.snapshot-directory: +## contains only '0-9a-z-_' +# starts with dot (.) +# value cannot exceed 255 characters +## and throws error for any other argument. +TEST ! $CLI volume set $V0 features.snapshot-directory a/b +TEST ! $CLI volume set $V0 features.snapshot-directory snaps +TEST ! $CLI volume set $V0 features.snapshot-directory -a +TEST ! $CLI volume set $V0 features.snapshot-directory . +TEST ! $CLI volume set $V0 features.snapshot-directory .. +TEST ! $CLI volume set $V0 features.snapshot-directory .123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345 + TEST $CLI volume set $V0 features.uss enable; EXPECT_WITHIN $UMOUNT_TIMEOUT "Y" force_umount $M0 diff --git a/tests/bugs/snapshot/bug-1164613.t b/tests/bugs/snapshot/bug-1164613.t deleted file mode 100644 index d7f956ce369..00000000000 --- a/tests/bugs/snapshot/bug-1164613.t +++ /dev/null @@ -1,34 +0,0 @@ -#!/bin/bash - -. $(dirname $0)/../../include.rc -. $(dirname $0)/../../snapshot.rc - -cleanup; -TEST verify_lvm_version; -TEST glusterd; -TEST pidof glusterd; - -TEST setup_lvm 1 - -TEST $CLI volume create $V0 $H0:$L1 -TEST $CLI volume start $V0 -TEST glusterfs -s $H0 --volfile-id=$V0 $M0 - -TEST touch $M0/testfile - -TEST $CLI snapshot create snaps $V0 no-timestamp -TEST $CLI snapshot activate snaps -TEST $CLI volume set $V0 features.uss enable -TEST $CLI volume set $V0 snapshot-directory snaps - -EXPECT_WITHIN $PROCESS_UP_TIMEOUT "0" STAT $M0/snaps/snaps/testfile - -umount -f $M0 - -#Clean up -TEST $CLI snapshot delete snaps -TEST $CLI volume stop $V0 force -TEST $CLI volume delete $V0 - -cleanup; - diff --git a/xlators/mgmt/glusterd/src/glusterd-volume-set.c b/xlators/mgmt/glusterd/src/glusterd-volume-set.c index 09ee73aba66..7a81fad13ae 100644 --- a/xlators/mgmt/glusterd/src/glusterd-volume-set.c +++ b/xlators/mgmt/glusterd/src/glusterd-volume-set.c @@ -634,6 +634,57 @@ out: } static int +validate_uss_dir (glusterd_volinfo_t *volinfo, dict_t *dict, char *key, + char *value, char **op_errstr) +{ + char errstr[2048] = ""; + int ret = -1; + int i = 0; + xlator_t *this = NULL; + + this = THIS; + GF_ASSERT (this); + + i = strlen (value); + if (i > NAME_MAX) { + snprintf (errstr, sizeof (errstr), "value of %s exceedes %d " + "characters", key, NAME_MAX); + goto out; + } else if (i < 2) { + snprintf (errstr, sizeof (errstr), "value of %s too short, " + "expects atleast two characters", key); + goto out; + } + + if (value[0] != '.') { + snprintf (errstr, sizeof (errstr), "%s expects value starting " + "with '.' ", key); + goto out; + } + + for (i = 1; value[i]; i++) { + if (isalnum (value[i]) || value[i] == '_' || value[i] == '-') + continue; + + snprintf (errstr, sizeof (errstr), "%s expects value to" + " contain only '0-9a-z-_'", key); + goto out; + } + + ret = 0; +out: + if (ret) { + gf_msg (this->name, GF_LOG_ERROR, EINVAL, + GD_MSG_INVALID_ENTRY, "%s", errstr); + *op_errstr = gf_strdup (errstr); + } + + gf_msg_debug (this->name, 0, "Returning %d", ret); + + return ret; +} + +static int validate_stripe (glusterd_volinfo_t *volinfo, dict_t *dict, char *key, char *value, char **op_errstr) { @@ -1677,7 +1728,10 @@ struct volopt_map_entry glusterd_volopt_map[] = { .op_version = GD_OP_VERSION_3_6_0, .value = ".snaps", .flags = OPT_FLAG_CLIENT_OPT | OPT_FLAG_XLATOR_OPT, - .description = "Entry point directory for entering snapshot world" + .validate_fn = validate_uss_dir, + .description = "Entry point directory for entering snapshot world. " + "Value can have only [0-9a-z-_] and starts with " + "dot (.) and cannot exceed 255 character" }, { .key = "features.show-snapshot-directory", |