diff options
-rw-r--r--[-rwxr-xr-x] | tests/basic/volume.t | 33 | ||||
-rw-r--r-- | xlators/mgmt/glusterd/src/glusterd-volume-set.c | 31 |
2 files changed, 57 insertions, 7 deletions
diff --git a/tests/basic/volume.t b/tests/basic/volume.t index 7648ae1d6e1..27fe093d07d 100755..100644 --- a/tests/basic/volume.t +++ b/tests/basic/volume.t @@ -11,7 +11,6 @@ TEST $CLI volume info; TEST $CLI volume create $V0 replica 3 $H0:$B0/${V0}{1,2,3,4,5,6}; - EXPECT "$V0" volinfo_field $V0 'Volume Name'; EXPECT 'Created' volinfo_field $V0 'Status'; EXPECT '6' brick_count $V0 @@ -28,10 +27,34 @@ EXPECT '6' brick_count $V0 TEST $CLI volume top $V0 read-perf bs 4096 count 1000 TEST $CLI volume top $V0 write-perf bs 1048576 count 2 -TEST $CLI volume stop $V0; -EXPECT 'Stopped' volinfo_field $V0 'Status'; +TEST touch $M0/foo + +# statedump path should be a directory, setting it to a file path should fail + +TEST ! $CLI v set $V0 server.statedump-path $M0/foo; +EXPECT '/var/run/gluster' $CLI v get $V0 server.statedump-path + +#set the statedump path to an existing ditectory which should succeed +TEST mkdir $D0/level; +TEST $CLI v set $V0 server.statedump-path $D0/level +EXPECT '/level' volinfo_field $V0 'server.statedump-path' + +ret=$(ls $D0/level | wc -l); +TEST [ $ret == 0 ] +TEST $CLI v statedump $V0; +ret=$(ls $D0/level | wc -l); +TEST ! [ $ret == 0 ] + +#set the statedump path to a non - existing directory which should fail +TEST ! $CLI v set $V0 server.statedump-path /root/test +EXPECT '/level' volinfo_field $V0 'server.statedump-path' + +TEST rm -rf $D0/level + +TEST $CLI volume stop $V0 +EXPECT 'Stopped' volinfo_field $V0 'Status' -TEST $CLI volume delete $V0; -TEST ! $CLI volume info $V0; +TEST $CLI volume delete $V0 +TEST ! $CLI volume info $V0 cleanup; diff --git a/xlators/mgmt/glusterd/src/glusterd-volume-set.c b/xlators/mgmt/glusterd/src/glusterd-volume-set.c index 63de3ef685c..04ec9a6e571 100644 --- a/xlators/mgmt/glusterd/src/glusterd-volume-set.c +++ b/xlators/mgmt/glusterd/src/glusterd-volume-set.c @@ -10,7 +10,7 @@ cases as published by the Free Software Foundation. #include "glusterd-volgen.h" #include "glusterd-utils.h" - +#include "sys/stat.h" static int validate_cache_max_min_size(glusterd_volinfo_t *volinfo, dict_t *dict, char *key, char *value, char **op_errstr) @@ -786,6 +786,32 @@ out: return ret; } +static int +is_directory(const char *path) +{ + struct stat statbuf; + if (stat(path, &statbuf) != 0) + return 0; + return S_ISDIR(statbuf.st_mode); +} +static int +validate_statedump_path(glusterd_volinfo_t *volinfo, dict_t *dict, char *key, + char *value, char **op_errstr) +{ + xlator_t *this = NULL; + this = THIS; + GF_ASSERT(this); + + int ret = 0; + if (!is_directory(value)) { + gf_asprintf(op_errstr, "Failed: %s is not a directory", value); + ret = -1; + gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_INVALID_ENTRY, "%s", + *op_errstr); + } + + return ret; +} /* dispatch table for VOLUME SET * ----------------------------- @@ -1588,7 +1614,8 @@ struct volopt_map_entry glusterd_volopt_map[] = { {.key = "server.statedump-path", .voltype = "protocol/server", .option = "statedump-path", - .op_version = 1}, + .op_version = 1, + .validate_fn = validate_statedump_path}, {.key = "server.outstanding-rpc-limit", .voltype = "protocol/server", .option = "rpc.outstanding-rpc-limit", |