From 6c9fe8fa8896c5f4fbe8c9bac6c2c7f9add92a0b Mon Sep 17 00:00:00 2001 From: Varun Shastry Date: Mon, 2 Dec 2013 15:49:58 +0530 Subject: cluster/dht: Set quota limit key in dht_selfheal of dirs. Also fixed check in dht_is_subvol_in_layout to check if the layouts are zero'ed out. Change-Id: I4bf8ebf66d3ef1946309b6c9aac9e79bf8a6d495 BUG: 969461 Signed-off-by: shishir gowda Signed-off-by: Varun Shastry Reviewed-on: http://review.gluster.org/6392 Reviewed-by: Raghavendra G Tested-by: Gluster Build System Reviewed-by: Vijay Bellur --- tests/basic/quota.t | 71 ++++++++++++++++++++++++++++++++++ xlators/cluster/dht/src/dht-layout.c | 9 ++++- xlators/cluster/dht/src/dht-selfheal.c | 26 +++++++++++-- 3 files changed, 100 insertions(+), 6 deletions(-) diff --git a/tests/basic/quota.t b/tests/basic/quota.t index 5c531adbf..81b1c2100 100755 --- a/tests/basic/quota.t +++ b/tests/basic/quota.t @@ -5,6 +5,8 @@ cleanup; +TESTS_EXPECTED_IN_LOOP=19 + TEST glusterd TEST pidof glusterd TEST $CLI volume info; @@ -102,6 +104,75 @@ TEST $CLI volume quota $V0 limit-usage /test_dir/in_test_dir 150MB EXPECT "150.0MB" hard_limit "/test_dir/in_test_dir"; ## ----------------------------- + +################################################### +## ------------------------------------------------ +## +## ------------------------------------------------ +################################################### +QUOTALIMIT=1024 +QUOTALIMITROOT=2048 +TESTDIR="addbricktest" + +rm -rf $M0/*; + +## +## ----------------------------- +# 41-42 +TEST mkdir $M0/$TESTDIR +TEST mkdir $M0/$TESTDIR/dir{1..10}; + + +# 43-52 +## +## ----------------------------- +TEST $CLI volume quota $V0 limit-usage / "$QUOTALIMITROOT"MB; +for i in {1..10}; do + TEST_IN_LOOP $CLI volume quota $V0 limit-usage /$TESTDIR/dir$i \ + "$QUOTALIMIT"MB; +done +## + +#53-62 +for i in `seq 1 9`; do + TEST_IN_LOOP dd if=/dev/urandom of="$M0/$TESTDIR/dir1/100MBfile$i" \ + bs=1M count=100; +done + +# 63-64 +## +## ------------------------------- +TEST $CLI volume add-brick $V0 $H0:$B0/brick{3,4} +TEST $CLI volume rebalance $V0 start; + + +## +## -------------------------------- +for i in `seq 1 200`; do + dd if=/dev/urandom of="$M0/$TESTDIR/dir1/10MBfile$i" bs=1M count=10 \ + &>/dev/null +done + +# 65 +## +## --------------------------------------------------------- +USED_KB=`du -s $M0/$TESTDIR/dir1 | cut -f1`; +USED_MB=$(($USED_KB/1024)); +TEST [ $USED_MB -le $((($QUOTALIMIT * 110) / 100)) ] + +# 66-67 +## +## ------------------------------------- +TEST getfattr -d -m "trusted.glusterfs.quota.limit-set" -e hex \ + --absolute-names $B0/brick{3,4}/$TESTDIR/dir{1..10}; +# Test on root. +TEST getfattr -d -m "trusted.glusterfs.quota.limit-set" -e hex \ + --absolute-names $B0/brick{3,4}; + +## ------------------------------------------------- +## +## ------------------------------------------------- + TEST $CLI volume quota $V0 disable TEST $CLI volume stop $V0; EXPECT 'Stopped' volinfo_field $V0 'Status'; diff --git a/xlators/cluster/dht/src/dht-layout.c b/xlators/cluster/dht/src/dht-layout.c index f7413c8a0..1e38d6be1 100644 --- a/xlators/cluster/dht/src/dht-layout.c +++ b/xlators/cluster/dht/src/dht-layout.c @@ -443,8 +443,13 @@ dht_is_subvol_in_layout (dht_layout_t *layout, xlator_t *xlator) int i = 0; for (i = 0; i < layout->cnt; i++) { - if (!strcmp (layout->list[i].xlator->name, xlator->name)) - return _gf_true; + /* Check if xlator is already part of layout, and layout is + * non-zero. */ + if (!strcmp (layout->list[i].xlator->name, xlator->name)) { + if (layout->list[i].start != layout->list[i].stop) + return _gf_true; + break; + } } return _gf_false; } diff --git a/xlators/cluster/dht/src/dht-selfheal.c b/xlators/cluster/dht/src/dht-selfheal.c index 06fa1ed3a..0e6527544 100644 --- a/xlators/cluster/dht/src/dht-selfheal.c +++ b/xlators/cluster/dht/src/dht-selfheal.c @@ -127,6 +127,7 @@ dht_selfheal_dir_xattr_persubvol (call_frame_t *frame, loc_t *loc, int32_t *disk_layout = NULL; dht_local_t *local = NULL; dht_conf_t *conf = NULL; + data_t *data = NULL; local = frame->local; if (req_subvol) @@ -171,7 +172,16 @@ dht_selfheal_dir_xattr_persubvol (call_frame_t *frame, loc_t *loc, layout->type, subvol->name, loc->path); dict_ref (xattr); - + if (local->xattr) { + data = dict_get (local->xattr, QUOTA_LIMIT_KEY); + if (data) { + ret = dict_add (xattr, QUOTA_LIMIT_KEY, data); + if (ret) { + gf_log (this->name, GF_LOG_ERROR, "Failed to " + "set quota limit key on %s",loc->path); + } + } + } if (!uuid_is_null (local->gfid)) uuid_copy (loc->gfid, local->gfid); @@ -265,7 +275,14 @@ dht_selfheal_dir_xattr (call_frame_t *frame, loc_t *loc, dht_layout_t *layout) } missing_xattr++; } - + /* Also account for subvolumes with no-layout. Used for zero'ing out + * the layouts and for setting quota key's if present */ + for (i = 0; i < conf->subvolume_cnt; i++) { + if (_gf_false == + dht_is_subvol_in_layout (layout, conf->subvolumes[i])) { + missing_xattr++; + } + } gf_log (this->name, GF_LOG_TRACE, "%d subvolumes missing xattr for %s", missing_xattr, loc->path); @@ -276,7 +293,6 @@ dht_selfheal_dir_xattr (call_frame_t *frame, loc_t *loc, dht_layout_t *layout) } local->call_cnt = missing_xattr; - for (i = 0; i < layout->cnt; i++) { if (layout->list[i].err != -1 || !layout->list[i].stop) continue; @@ -289,13 +305,15 @@ dht_selfheal_dir_xattr (call_frame_t *frame, loc_t *loc, dht_layout_t *layout) dummy = dht_layout_new (this, 1); if (!dummy) goto out; - for (i = 0; i < conf->subvolume_cnt; i++) { + for (i = 0; i < conf->subvolume_cnt && missing_xattr; i++) { if (_gf_false == dht_is_subvol_in_layout (layout, conf->subvolumes[i])) { dht_selfheal_dir_xattr_persubvol (frame, loc, dummy, 0, conf->subvolumes[i]); + missing_xattr--; } } + dht_layout_unref (this, dummy); out: return 0; -- cgit