cb8e9e
From 4054c96ec56c90ccd5955af555a7e953417206fa Mon Sep 17 00:00:00 2001
cb8e9e
From: Raghavendra Bhat <raghavendra@redhat.com>
cb8e9e
Date: Mon, 20 Jul 2015 16:03:40 +0530
cb8e9e
Subject: [PATCH 286/304] tests: set inode-lru-limit to 1 and check if bit-rot xattrs are wrongy created
cb8e9e
cb8e9e
       Backport of http://review.gluster.org/11718
cb8e9e
cb8e9e
This test sets the lru limit of the inode table to 1 and checks if inode forgets
cb8e9e
and resolve cause any problem with bit-rot xattrs (especially bad-file xattr).
cb8e9e
cb8e9e
> Change-Id: I1fa25fa2d31dda8d26e8192562e896e5bddd0381
cb8e9e
> BUG: 1244613
cb8e9e
> Signed-off-by: Raghavendra Bhat <raghavendra@redhat.com>
cb8e9e
> Reviewed-on: http://review.gluster.org/11718
cb8e9e
> Tested-by: NetBSD Build System <jenkins@build.gluster.org>
cb8e9e
> Tested-by: Gluster Build System <jenkins@build.gluster.com>
cb8e9e
> Reviewed-by: Venky Shankar <vshankar@redhat.com>
cb8e9e
> Signed-off-by: Raghavendra Bhat <raghavendra@redhat.com>
cb8e9e
cb8e9e
Change-Id: I0daddac9b47211e2e6b9f1299396eadf0ec1e207
cb8e9e
BUG: 1251409
cb8e9e
Signed-off-by: Raghavendra Bhat <raghavendra@redhat.com>
cb8e9e
Reviewed-on: https://code.engineering.redhat.com/gerrit/55884
cb8e9e
---
cb8e9e
 tests/bitrot/bug-1244613.t                   |   87 ++++++++++++++++++++++++++
cb8e9e
 xlators/protocol/server/src/server-resolve.c |   28 +++++----
cb8e9e
 2 files changed, 103 insertions(+), 12 deletions(-)
cb8e9e
 create mode 100644 tests/bitrot/bug-1244613.t
cb8e9e
cb8e9e
diff --git a/tests/bitrot/bug-1244613.t b/tests/bitrot/bug-1244613.t
cb8e9e
new file mode 100644
cb8e9e
index 0000000..000a1d3
cb8e9e
--- /dev/null
cb8e9e
+++ b/tests/bitrot/bug-1244613.t
cb8e9e
@@ -0,0 +1,87 @@
cb8e9e
+#!/bin/bash
cb8e9e
+
cb8e9e
+. $(dirname $0)/../include.rc
cb8e9e
+. $(dirname $0)/../volume.rc
cb8e9e
+. $(dirname $0)/../nfs.rc
cb8e9e
+. $(dirname $0)/../fileio.rc
cb8e9e
+
cb8e9e
+cleanup;
cb8e9e
+
cb8e9e
+TESTS_EXPECTED_IN_LOOP=16
cb8e9e
+TEST glusterd
cb8e9e
+TEST pidof glusterd
cb8e9e
+TEST $CLI volume info;
cb8e9e
+
cb8e9e
+TEST $CLI volume create $V0 $H0:$B0/brick1;
cb8e9e
+EXPECT 'Created' volinfo_field $V0 'Status';
cb8e9e
+
cb8e9e
+
cb8e9e
+# The test makes use of inode-lru-limit to hit a scenario, where we
cb8e9e
+# find an inode whose ancestry is not there. Following is the
cb8e9e
+# hypothesis (which is confirmed by seeing logs indicating that
cb8e9e
+# codepath has been executed, but not through a good understanding of
cb8e9e
+# NFS internals).
cb8e9e
+
cb8e9e
+#     At the end of an fop, the reference count of an inode would be
cb8e9e
+#     zero. The inode (and its ancestry) persists in memory only
cb8e9e
+#     because of non-zero lookup count. These looked up inodes are put
cb8e9e
+#     in an lru queue of size 1 (here). So, there can be at most one
cb8e9e
+#     such inode in memory.
cb8e9e
+
cb8e9e
+#     NFS Server makes use of anonymous fds. So, if it cannot find
cb8e9e
+#     valid fd, it does a nameless lookup. This gives us an inode
cb8e9e
+#     whose ancestry is NULL. When a write happens on this inode,
cb8e9e
+#     quota-enforcer/marker finds a NULL ancestry and asks
cb8e9e
+#     storage/posix to build it.
cb8e9e
+
cb8e9e
+TEST $CLI volume set $V0 network.inode-lru-limit 1
cb8e9e
+TEST $CLI volume set $V0 performance.nfs.write-behind off
cb8e9e
+
cb8e9e
+TEST $CLI volume start $V0;
cb8e9e
+EXPECT 'Started' volinfo_field $V0 'Status';
cb8e9e
+
cb8e9e
+TEST mount_nfs $H0:/$V0 $N0;
cb8e9e
+deep=/0/1/2/3/4/5/6/7/8/9
cb8e9e
+TEST mkdir -p $N0/$deep
cb8e9e
+
cb8e9e
+TEST touch $N0/$deep/file1 $N0/$deep/file2 $N0/$deep/file3 $N0/$deep/file4
cb8e9e
+
cb8e9e
+TEST fd_open 3 'w' "$N0/$deep/file1"
cb8e9e
+TEST fd_open 4 'w' "$N0/$deep/file2"
cb8e9e
+TEST fd_open 5 'w' "$N0/$deep/file3"
cb8e9e
+TEST fd_open 6 'w' "$N0/$deep/file4"
cb8e9e
+
cb8e9e
+# consume all quota
cb8e9e
+echo "Hello" > $N0/$deep/new_file_1
cb8e9e
+echo "World" >> $N0/$deep/new_file_1
cb8e9e
+echo 1 >> $N0/$deep/new_file_1
cb8e9e
+echo 2 >> $N0/$deep/new_file_1
cb8e9e
+
cb8e9e
+
cb8e9e
+# At the end of each fop in server, reference count of the
cb8e9e
+# inode associated with each of the file above drops to zero and hence
cb8e9e
+# put into lru queue. Since lru-limit is set to 1, an fop next file
cb8e9e
+# will displace the current inode from itable. This will ensure that
cb8e9e
+# when writes happens on same fd, fd resolution results in
cb8e9e
+# nameless lookup from server and encounters an fd
cb8e9e
+# associated with an inode whose parent is not present in itable.
cb8e9e
+
cb8e9e
+for j in $(seq 1 2); do
cb8e9e
+    for i in $(seq 3 6); do
cb8e9e
+        TEST_IN_LOOP fd_write $i "content"
cb8e9e
+        TEST_IN_LOOP sync
cb8e9e
+    done
cb8e9e
+done
cb8e9e
+
cb8e9e
+exec 3>&-
cb8e9e
+exec 4>&-
cb8e9e
+exec 5>&-
cb8e9e
+exec 6>&-
cb8e9e
+
cb8e9e
+$CLI volume statedump $V0 all
cb8e9e
+
cb8e9e
+EXPECT_WITHIN $UMOUNT_TIMEOUT "Y" force_umount $N0
cb8e9e
+
cb8e9e
+TEST $CLI volume stop $V0
cb8e9e
+
cb8e9e
+cleanup;
cb8e9e
diff --git a/xlators/protocol/server/src/server-resolve.c b/xlators/protocol/server/src/server-resolve.c
cb8e9e
index 906dc00..5f3d475 100644
cb8e9e
--- a/xlators/protocol/server/src/server-resolve.c
cb8e9e
+++ b/xlators/protocol/server/src/server-resolve.c
cb8e9e
@@ -167,12 +167,14 @@ resolve_gfid_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
cb8e9e
         inode_path (resolve_loc->parent, resolve_loc->name,
cb8e9e
                     (char **) &resolve_loc->path);
cb8e9e
 
cb8e9e
-        dict = dict_copy_with_ref (state->xdata, NULL);
cb8e9e
-        if (!dict && state->xdata)
cb8e9e
-                gf_msg (this->name, GF_LOG_ERROR, ENOMEM, PS_MSG_NO_MEMORY,
cb8e9e
-                        "BUG: dict allocation failed (pargfid: %s, name: %s), "
cb8e9e
-                        "still continuing", uuid_utoa (resolve_loc->gfid),
cb8e9e
-                        resolve_loc->name);
cb8e9e
+        if (state->xdata) {
cb8e9e
+                dict = dict_copy_with_ref (state->xdata, NULL);
cb8e9e
+                if (!dict)
cb8e9e
+                        gf_msg (this->name, GF_LOG_ERROR, ENOMEM, PS_MSG_NO_MEMORY,
cb8e9e
+                                "BUG: dict allocation failed (pargfid: %s, name: %s), "
cb8e9e
+                                "still continuing", uuid_utoa (resolve_loc->gfid),
cb8e9e
+                                resolve_loc->name);
cb8e9e
+        }
cb8e9e
 
cb8e9e
         STACK_WIND (frame, resolve_gfid_entry_cbk,
cb8e9e
                     frame->root->client->bound_xl,
cb8e9e
@@ -210,12 +212,14 @@ resolve_gfid (call_frame_t *frame)
cb8e9e
         resolve_loc->inode = inode_new (state->itable);
cb8e9e
         ret = loc_path (resolve_loc, NULL);
cb8e9e
 
cb8e9e
-        xdata = dict_copy_with_ref (state->xdata, NULL);
cb8e9e
-        if (!xdata && state->xdata)
cb8e9e
-                gf_msg (this->name, GF_LOG_ERROR, ENOMEM, PS_MSG_NO_MEMORY,
cb8e9e
-                        "BUG: dict allocation failed (gfid: %s), "
cb8e9e
-                        "still continuing",
cb8e9e
-                        uuid_utoa (resolve_loc->gfid));
cb8e9e
+        if (state->xdata) {
cb8e9e
+                xdata = dict_copy_with_ref (state->xdata, NULL);
cb8e9e
+                if (!xdata)
cb8e9e
+                        gf_msg (this->name, GF_LOG_ERROR, ENOMEM, PS_MSG_NO_MEMORY,
cb8e9e
+                                "BUG: dict allocation failed (gfid: %s), "
cb8e9e
+                                "still continuing",
cb8e9e
+                                uuid_utoa (resolve_loc->gfid));
cb8e9e
+        }
cb8e9e
 
cb8e9e
         STACK_WIND (frame, resolve_gfid_cbk,
cb8e9e
                     frame->root->client->bound_xl,
cb8e9e
-- 
cb8e9e
1.7.1
cb8e9e