cb8e9e
From da4ec76974997af637db6987d8c8465d4c580e9c Mon Sep 17 00:00:00 2001
cb8e9e
From: vmallika <vmallika@redhat.com>
cb8e9e
Date: Thu, 25 Jun 2015 14:58:50 +0530
cb8e9e
Subject: [PATCH 149/190] quota: marker accounting goes bad with rename while writing a file
cb8e9e
cb8e9e
This is a backport of http://review.gluster.org/#/c/11403/
cb8e9e
cb8e9e
> With below test-case, marker accounting becomes bad:
cb8e9e
> 1) Create a volume with 1 brick
cb8e9e
> 2) fuse mount
cb8e9e
> 3) on one terminal write some data
cb8e9e
>    dd if=/dev/zero of=f1 bs=1M count=500 oflag=sync
cb8e9e
> 4) on another terminal execute below rename operation while the write is
cb8e9e
> still in progress
cb8e9e
>     for i in {1..50}; do
cb8e9e
>         ii=`expr $i + 1`;
cb8e9e
>         mv f$i f$ii;
cb8e9e
>     done
cb8e9e
>
cb8e9e
> remove-xattr is already on while doing rename operation,
cb8e9e
> we should not be doing again in background when reducing the
cb8e9e
> parent size
cb8e9e
>
cb8e9e
> Change-Id: I969a64bb559e2341315928b55b99203e9ddee3f2
cb8e9e
> BUG: 1235195
cb8e9e
> Signed-off-by: vmallika <vmallika@redhat.com>
cb8e9e
> Reviewed-on: http://review.gluster.org/11403
cb8e9e
> Tested-by: NetBSD Build System <jenkins@build.gluster.org>
cb8e9e
> Reviewed-by: Raghavendra G <rgowdapp@redhat.com>
cb8e9e
> Tested-by: Gluster Build System <jenkins@build.gluster.com>
cb8e9e
> Tested-by: Raghavendra G <rgowdapp@redhat.com>
cb8e9e
cb8e9e
Change-Id: If1c21d5a58fe5aec594efefe2425119dc98eed18
cb8e9e
BUG: 1235182
cb8e9e
Signed-off-by: vmallika <vmallika@redhat.com>
cb8e9e
Reviewed-on: https://code.engineering.redhat.com/gerrit/51679
cb8e9e
Reviewed-by: Raghavendra Gowdappa <rgowdapp@redhat.com>
cb8e9e
Tested-by: Raghavendra Gowdappa <rgowdapp@redhat.com>
cb8e9e
---
cb8e9e
 tests/bugs/quota/bug-1235182.t             |   58 ++++++++++++++++++++++++++++
cb8e9e
 xlators/features/marker/src/marker-quota.c |   17 +++++++-
cb8e9e
 2 files changed, 72 insertions(+), 3 deletions(-)
cb8e9e
 create mode 100644 tests/bugs/quota/bug-1235182.t
cb8e9e
cb8e9e
diff --git a/tests/bugs/quota/bug-1235182.t b/tests/bugs/quota/bug-1235182.t
cb8e9e
new file mode 100644
cb8e9e
index 0000000..0bd43a9
cb8e9e
--- /dev/null
cb8e9e
+++ b/tests/bugs/quota/bug-1235182.t
cb8e9e
@@ -0,0 +1,58 @@
cb8e9e
+#!/bin/bash
cb8e9e
+
cb8e9e
+# This regression test tries to ensure renaming a directory with content, and
cb8e9e
+# no limit set, is accounted properly, when moved into a directory with quota
cb8e9e
+# limit set.
cb8e9e
+
cb8e9e
+. $(dirname $0)/../../include.rc
cb8e9e
+. $(dirname $0)/../../volume.rc
cb8e9e
+
cb8e9e
+cleanup;
cb8e9e
+
cb8e9e
+function usage()
cb8e9e
+{
cb8e9e
+        local QUOTA_PATH=$1;
cb8e9e
+        $CLI volume quota $V0 list $QUOTA_PATH | grep "$QUOTA_PATH" | awk '{print $4}'
cb8e9e
+}
cb8e9e
+
cb8e9e
+QDD=$(dirname $0)/quota
cb8e9e
+# compile the test write program and run it
cb8e9e
+build_tester $(dirname $0)/../../basic/quota.c -o $QDD
cb8e9e
+
cb8e9e
+TEST glusterd
cb8e9e
+TEST pidof glusterd;
cb8e9e
+TEST $CLI volume info;
cb8e9e
+
cb8e9e
+TEST $CLI volume create $V0 $H0:$B0/${V0}{1};
cb8e9e
+TEST $CLI volume start $V0;
cb8e9e
+
cb8e9e
+TEST $CLI volume quota $V0 enable;
cb8e9e
+
cb8e9e
+TEST glusterfs --volfile-id=$V0 --volfile-server=$H0 $M0;
cb8e9e
+
cb8e9e
+TEST $CLI volume quota $V0 limit-usage / 1GB
cb8e9e
+TEST $CLI volume quota $V0 hard-timeout 0
cb8e9e
+TEST $CLI volume quota $V0 soft-timeout 0
cb8e9e
+
cb8e9e
+$QDD $M0/f1 256 400&
cb8e9e
+PID=$!
cb8e9e
+EXPECT_WITHIN $PROCESS_UP_TIMEOUT "0" STAT $M0/f1
cb8e9e
+TESTS_EXPECTED_IN_LOOP=50
cb8e9e
+for i in {1..50}; do
cb8e9e
+        ii=`expr $i + 1`;
cb8e9e
+        TEST_IN_LOOP mv $M0/f$i $M0/f$ii;
cb8e9e
+done
cb8e9e
+
cb8e9e
+echo "Wait for process with pid $PID to complete"
cb8e9e
+wait $PID
cb8e9e
+echo "Process with pid $PID finished"
cb8e9e
+
cb8e9e
+EXPECT_WITHIN $MARKER_UPDATE_TIMEOUT "100.0MB" usage "/"
cb8e9e
+
cb8e9e
+TEST $CLI volume stop $V0
cb8e9e
+TEST $CLI volume delete $V0
cb8e9e
+EXPECT "1" get_aux
cb8e9e
+
cb8e9e
+rm -f $QDD
cb8e9e
+
cb8e9e
+cleanup;
cb8e9e
diff --git a/xlators/features/marker/src/marker-quota.c b/xlators/features/marker/src/marker-quota.c
cb8e9e
index bbe2d9d..0b015ef 100644
cb8e9e
--- a/xlators/features/marker/src/marker-quota.c
cb8e9e
+++ b/xlators/features/marker/src/marker-quota.c
cb8e9e
@@ -2585,11 +2585,15 @@ out:
cb8e9e
 
cb8e9e
 int32_t
cb8e9e
 mq_remove_contri (xlator_t *this, loc_t *loc, quota_inode_ctx_t *ctx,
cb8e9e
-                  inode_contribution_t *contri, quota_meta_t *delta)
cb8e9e
+                  inode_contribution_t *contri, quota_meta_t *delta,
cb8e9e
+                  gf_boolean_t remove_xattr)
cb8e9e
 {
cb8e9e
         int32_t              ret                         = -1;
cb8e9e
         char                 contri_key[CONTRI_KEY_MAX]  = {0, };
cb8e9e
 
cb8e9e
+        if (remove_xattr == _gf_false)
cb8e9e
+                goto done;
cb8e9e
+
cb8e9e
         GET_CONTRI_KEY (contri_key, contri->gfid, ret);
cb8e9e
         if (ret < 0) {
cb8e9e
                 gf_log (this->name, GF_LOG_ERROR, "get contri_key "
cb8e9e
@@ -2615,6 +2619,7 @@ mq_remove_contri (xlator_t *this, loc_t *loc, quota_inode_ctx_t *ctx,
cb8e9e
                 }
cb8e9e
         }
cb8e9e
 
cb8e9e
+done:
cb8e9e
         LOCK (&contri->lock);
cb8e9e
         {
cb8e9e
                 contri->contribution += delta->size;
cb8e9e
@@ -3042,6 +3047,7 @@ mq_reduce_parent_size_task (void *opaque)
cb8e9e
         xlator_t                *this          = NULL;
cb8e9e
         loc_t                   *loc           = NULL;
cb8e9e
         int64_t                  contri        = 0;
cb8e9e
+        gf_boolean_t             remove_xattr  = _gf_true;
cb8e9e
 
cb8e9e
         GF_ASSERT (opaque);
cb8e9e
 
cb8e9e
@@ -3068,7 +3074,11 @@ mq_reduce_parent_size_task (void *opaque)
cb8e9e
         }
cb8e9e
 
cb8e9e
         if (contri >= 0) {
cb8e9e
-                /* contri paramater is supplied only for rename operation */
cb8e9e
+                /* contri paramater is supplied only for rename operation.
cb8e9e
+                 * remove xattr is alreday performed, we need to skip
cb8e9e
+                 * removexattr for rename operation
cb8e9e
+                 */
cb8e9e
+                remove_xattr = _gf_false;
cb8e9e
                 delta.size = contri;
cb8e9e
                 delta.file_count = 1;
cb8e9e
                 delta.dir_count = 0;
cb8e9e
@@ -3122,7 +3132,8 @@ mq_reduce_parent_size_task (void *opaque)
cb8e9e
 
cb8e9e
         mq_sub_meta (&delta, NULL);
cb8e9e
 
cb8e9e
-        ret = mq_remove_contri (this, loc, ctx, contribution, &delta);
cb8e9e
+        ret = mq_remove_contri (this, loc, ctx, contribution, &delta,
cb8e9e
+                                remove_xattr);
cb8e9e
         if (ret < 0)
cb8e9e
                 goto out;
cb8e9e
 
cb8e9e
-- 
cb8e9e
1.7.1
cb8e9e