7f4c2a
From d4565510f62bb3c5f347e1083f18b1398f6bd803 Mon Sep 17 00:00:00 2001
7f4c2a
From: vmallika <vmallika@redhat.com>
7f4c2a
Date: Wed, 17 Jun 2015 10:33:13 +0530
7f4c2a
Subject: [PATCH 104/129] quota: fix double accounting with rename operation
7f4c2a
7f4c2a
This is a backport of http://review.gluster.org/#/c/11264/
7f4c2a
7f4c2a
> When a rename operation is performed, we are renaming
7f4c2a
> the file first and performing remove-xattr when reducing
7f4c2a
> the contri size from parents.
7f4c2a
> This remove-xattr fails as the file is alreday renamed,
7f4c2a
> this failure causes reduce-parent-size to abort resulting
7f4c2a
> in double quota accounting
7f4c2a
>
7f4c2a
> This patch fixes the problem. We don't need to perform remove-xattr
7f4c2a
> operation on a file when performing reduce-parent-size txn as this
7f4c2a
> will be alreday done before starting reduce-parent-size txn
7f4c2a
>
7f4c2a
> Change-Id: If86e3dbb0233f6deaaa90bee72cb0ec1689c7325
7f4c2a
> BUG: 1232572
7f4c2a
> Signed-off-by: vmallika <vmallika@redhat.com>
7f4c2a
> Reviewed-on: http://review.gluster.org/11264
7f4c2a
> Reviewed-by: Raghavendra G <rgowdapp@redhat.com>
7f4c2a
> Tested-by: NetBSD Build System <jenkins@build.gluster.org>
7f4c2a
7f4c2a
Change-Id: I98ce323495daa57f2911daf0bd6554e51f78217b
7f4c2a
BUG: 1178130
7f4c2a
Signed-off-by: vmallika <vmallika@redhat.com>
7f4c2a
Reviewed-on: https://code.engineering.redhat.com/gerrit/51097
7f4c2a
Reviewed-by: Raghavendra Gowdappa <rgowdapp@redhat.com>
7f4c2a
Tested-by: Raghavendra Gowdappa <rgowdapp@redhat.com>
7f4c2a
---
7f4c2a
 tests/bugs/quota/bug-1178130.t             |   56 ++++++++++++++++++++++++++++
7f4c2a
 xlators/features/marker/src/marker-quota.c |    4 +-
7f4c2a
 2 files changed, 59 insertions(+), 1 deletions(-)
7f4c2a
 create mode 100644 tests/bugs/quota/bug-1178130.t
7f4c2a
7f4c2a
diff --git a/tests/bugs/quota/bug-1178130.t b/tests/bugs/quota/bug-1178130.t
7f4c2a
new file mode 100644
7f4c2a
index 0000000..a1ed110
7f4c2a
--- /dev/null
7f4c2a
+++ b/tests/bugs/quota/bug-1178130.t
7f4c2a
@@ -0,0 +1,56 @@
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 replica 2 $H0:$B0/${V0}{1,2};
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 / 500MB
7f4c2a
+TEST $CLI volume quota $V0 hard-timeout 0
7f4c2a
+TEST $CLI volume quota $V0 soft-timeout 0
7f4c2a
+
7f4c2a
+TEST $QDD $M0/file 256 40
7f4c2a
+EXPECT "10.0MB" usage "/"
7f4c2a
+
7f4c2a
+TEST kill_brick $V0 $H0 $B0/${V0}2
7f4c2a
+TEST mv $M0/file $M0/file2
7f4c2a
+TEST $CLI volume start $V0 force;
7f4c2a
+
7f4c2a
+#wait for self heal to complete
7f4c2a
+EXPECT_WITHIN $HEAL_TIMEOUT "0" STAT "$B0/${V0}2/file2"
7f4c2a
+
7f4c2a
+#usage should remain same after rename and self-heal operation
7f4c2a
+EXPECT "10.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 ef70236..e183829 100644
7f4c2a
--- a/xlators/features/marker/src/marker-quota.c
7f4c2a
+++ b/xlators/features/marker/src/marker-quota.c
7f4c2a
@@ -2588,9 +2588,11 @@ mq_remove_contri (xlator_t *this, loc_t *loc, inode_contribution_t *contri)
7f4c2a
 
7f4c2a
         ret = syncop_removexattr (FIRST_CHILD(this), loc, contri_key, 0, NULL);
7f4c2a
         if (ret < 0) {
7f4c2a
-                if (-ret == ENOENT || -ret == ESTALE) {
7f4c2a
+                if (-ret == ENOENT || -ret == ESTALE || -ret == ENODATA) {
7f4c2a
                         /* Remove contri in done when unlink operation is
7f4c2a
                          * performed, so return success on ENOENT/ESTSLE
7f4c2a
+                         * rename operation removes xattr earlier,
7f4c2a
+                         * so return success on ENODATA
7f4c2a
                          */
7f4c2a
                         ret = 0;
7f4c2a
                 } else {
7f4c2a
-- 
7f4c2a
1.7.1
7f4c2a