features/quota: Failure of quota commands if the dir-name contains ':' in it
PROBLEM: The first colon in the limit string is used to separate the path and the limit-value. The ':' in the path was the source of problem. FIX: Search for the last colon and separate based on the same. Added regression test. TEST: Create and set quota on directories with names containing ':' in start, middle and end. Change-Id: I363c8ad4cbfd02c23fc73974bef9aa8bc362d29c BUG: 848251 Signed-off-by: Varun Shastry <vshastry@redhat.com> Reviewed-on: http://review.gluster.org/4137 Tested-by: Gluster Build System <jenkins@build.gluster.com> Reviewed-by: Vijay Bellur <vbellur@redhat.com>
This commit is contained in:
parent
b0cb7aaf04
commit
0d9a38bb57
@ -1998,7 +1998,7 @@ gf_cli_print_limit_list (char *volname, char *limit_list,
|
||||
{
|
||||
int64_t size = 0;
|
||||
int64_t limit_value = 0;
|
||||
int32_t i, j, k;
|
||||
int32_t i, j;
|
||||
int32_t len = 0, ret = -1;
|
||||
char *size_str = NULL;
|
||||
char path [PATH_MAX] = {0, };
|
||||
@ -2006,6 +2006,7 @@ gf_cli_print_limit_list (char *volname, char *limit_list,
|
||||
char value [1024] = {0, };
|
||||
char mountdir [] = "/tmp/mntXXXXXX";
|
||||
char abspath [PATH_MAX] = {0, };
|
||||
char *colon_ptr = NULL;
|
||||
runner_t runner = {0,};
|
||||
|
||||
GF_VALIDATE_OR_GOTO ("cli", volname, out);
|
||||
@ -2053,19 +2054,16 @@ gf_cli_print_limit_list (char *volname, char *limit_list,
|
||||
"-----------------------");
|
||||
while (i < len) {
|
||||
j = 0;
|
||||
k = 0;
|
||||
|
||||
while (limit_list [i] != ':') {
|
||||
path [k++] = limit_list [i++];
|
||||
}
|
||||
path [k] = '\0';
|
||||
|
||||
i++; //skip ':'
|
||||
|
||||
while (limit_list [i] != ',' && limit_list [i] != '\0') {
|
||||
value [j++] = limit_list[i++];
|
||||
path [j++] = limit_list[i++];
|
||||
}
|
||||
value [j] = '\0';
|
||||
path [j] = '\0';
|
||||
//here path[] contains both path and limit value
|
||||
|
||||
colon_ptr = strrchr (path, ':');
|
||||
*colon_ptr = '\0';
|
||||
strcpy (value, ++colon_ptr);
|
||||
|
||||
snprintf (abspath, sizeof (abspath), "%s/%s", mountdir, path);
|
||||
|
||||
|
50
tests/bugs/bug-848251.t
Normal file
50
tests/bugs/bug-848251.t
Normal file
@ -0,0 +1,50 @@
|
||||
#!/bin/bash
|
||||
|
||||
. $(dirname $0)/../include.rc
|
||||
|
||||
cleanup;
|
||||
|
||||
TEST glusterd
|
||||
TEST pidof glusterd
|
||||
TEST $CLI volume info;
|
||||
|
||||
TEST $CLI volume create $V0 $H0:$B0/brick1;
|
||||
|
||||
TEST $CLI volume start $V0;
|
||||
|
||||
#enable quota
|
||||
TEST $CLI volume quota $V0 enable;
|
||||
|
||||
#mount on a random dir
|
||||
TEST MOUNTDIR="/tmp/$RANDOM"
|
||||
TEST mkdir $MOUNTDIR
|
||||
TEST glusterfs -s $H0 --volfile-id=$V0 $MOUNTDIR
|
||||
|
||||
function set_quota(){
|
||||
mkdir "$MOUNTDIR/$name"
|
||||
$CLI volume quota $V0 limit-usage /$name 50KB
|
||||
}
|
||||
|
||||
function quota_list(){
|
||||
$CLI volume quota $V0 list | grep -- /$name | awk '{print $3}'
|
||||
}
|
||||
|
||||
TEST name=":d1"
|
||||
#file name containing ':' in the start
|
||||
TEST set_quota
|
||||
EXPECT "0Bytes" quota_list
|
||||
|
||||
TEST name=":d1/d:1"
|
||||
#file name containing ':' in between
|
||||
TEST set_quota
|
||||
EXPECT "0Bytes" quota_list
|
||||
|
||||
TEST name=":d1/d:1/d1:"
|
||||
#file name containing ':' in the end
|
||||
TEST set_quota
|
||||
EXPECT "0Bytes" quota_list
|
||||
|
||||
TEST umount $MOUNTDIR
|
||||
TEST rm -rf $MOUNTDIR
|
||||
|
||||
cleanup;
|
@ -3025,14 +3025,17 @@ quota_parse_limits (quota_priv_t *priv, xlator_t *this, dict_t *xl_options,
|
||||
char *path = NULL, *saveptr = NULL;
|
||||
uint64_t value = 0;
|
||||
limits_t *quota_lim = NULL, *old = NULL;
|
||||
char *last_colon= NULL;
|
||||
|
||||
ret = dict_get_str (xl_options, "limit-set", &str);
|
||||
|
||||
if (str) {
|
||||
path = strtok_r (str, ":", &saveptr);
|
||||
path = strtok_r (str, ",", &saveptr);
|
||||
|
||||
while (path) {
|
||||
str_val = strtok_r (NULL, ",", &saveptr);
|
||||
last_colon = strrchr (path, ':');
|
||||
*last_colon = '\0';
|
||||
str_val = last_colon + 1;
|
||||
|
||||
ret = gf_string2bytesize (str_val, &value);
|
||||
if (ret != 0)
|
||||
@ -3066,7 +3069,7 @@ quota_parse_limits (quota_priv_t *priv, xlator_t *this, dict_t *xl_options,
|
||||
}
|
||||
UNLOCK (&priv->lock);
|
||||
|
||||
path = strtok_r (NULL, ":", &saveptr);
|
||||
path = strtok_r (NULL, ",", &saveptr);
|
||||
}
|
||||
} else {
|
||||
gf_log (this->name, GF_LOG_INFO,
|
||||
|
Loading…
x
Reference in New Issue
Block a user