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