Blob Blame History Raw
From 4054c96ec56c90ccd5955af555a7e953417206fa Mon Sep 17 00:00:00 2001
From: Raghavendra Bhat <raghavendra@redhat.com>
Date: Mon, 20 Jul 2015 16:03:40 +0530
Subject: [PATCH 286/304] tests: set inode-lru-limit to 1 and check if bit-rot xattrs are wrongy created

       Backport of http://review.gluster.org/11718

This test sets the lru limit of the inode table to 1 and checks if inode forgets
and resolve cause any problem with bit-rot xattrs (especially bad-file xattr).

> Change-Id: I1fa25fa2d31dda8d26e8192562e896e5bddd0381
> BUG: 1244613
> Signed-off-by: Raghavendra Bhat <raghavendra@redhat.com>
> Reviewed-on: http://review.gluster.org/11718
> Tested-by: NetBSD Build System <jenkins@build.gluster.org>
> Tested-by: Gluster Build System <jenkins@build.gluster.com>
> Reviewed-by: Venky Shankar <vshankar@redhat.com>
> Signed-off-by: Raghavendra Bhat <raghavendra@redhat.com>

Change-Id: I0daddac9b47211e2e6b9f1299396eadf0ec1e207
BUG: 1251409
Signed-off-by: Raghavendra Bhat <raghavendra@redhat.com>
Reviewed-on: https://code.engineering.redhat.com/gerrit/55884
---
 tests/bitrot/bug-1244613.t                   |   87 ++++++++++++++++++++++++++
 xlators/protocol/server/src/server-resolve.c |   28 +++++----
 2 files changed, 103 insertions(+), 12 deletions(-)
 create mode 100644 tests/bitrot/bug-1244613.t

diff --git a/tests/bitrot/bug-1244613.t b/tests/bitrot/bug-1244613.t
new file mode 100644
index 0000000..000a1d3
--- /dev/null
+++ b/tests/bitrot/bug-1244613.t
@@ -0,0 +1,87 @@
+#!/bin/bash
+
+. $(dirname $0)/../include.rc
+. $(dirname $0)/../volume.rc
+. $(dirname $0)/../nfs.rc
+. $(dirname $0)/../fileio.rc
+
+cleanup;
+
+TESTS_EXPECTED_IN_LOOP=16
+TEST glusterd
+TEST pidof glusterd
+TEST $CLI volume info;
+
+TEST $CLI volume create $V0 $H0:$B0/brick1;
+EXPECT 'Created' volinfo_field $V0 'Status';
+
+
+# The test makes use of inode-lru-limit to hit a scenario, where we
+# find an inode whose ancestry is not there. Following is the
+# hypothesis (which is confirmed by seeing logs indicating that
+# codepath has been executed, but not through a good understanding of
+# NFS internals).
+
+#     At the end of an fop, the reference count of an inode would be
+#     zero. The inode (and its ancestry) persists in memory only
+#     because of non-zero lookup count. These looked up inodes are put
+#     in an lru queue of size 1 (here). So, there can be at most one
+#     such inode in memory.
+
+#     NFS Server makes use of anonymous fds. So, if it cannot find
+#     valid fd, it does a nameless lookup. This gives us an inode
+#     whose ancestry is NULL. When a write happens on this inode,
+#     quota-enforcer/marker finds a NULL ancestry and asks
+#     storage/posix to build it.
+
+TEST $CLI volume set $V0 network.inode-lru-limit 1
+TEST $CLI volume set $V0 performance.nfs.write-behind off
+
+TEST $CLI volume start $V0;
+EXPECT 'Started' volinfo_field $V0 'Status';
+
+TEST mount_nfs $H0:/$V0 $N0;
+deep=/0/1/2/3/4/5/6/7/8/9
+TEST mkdir -p $N0/$deep
+
+TEST touch $N0/$deep/file1 $N0/$deep/file2 $N0/$deep/file3 $N0/$deep/file4
+
+TEST fd_open 3 'w' "$N0/$deep/file1"
+TEST fd_open 4 'w' "$N0/$deep/file2"
+TEST fd_open 5 'w' "$N0/$deep/file3"
+TEST fd_open 6 'w' "$N0/$deep/file4"
+
+# consume all quota
+echo "Hello" > $N0/$deep/new_file_1
+echo "World" >> $N0/$deep/new_file_1
+echo 1 >> $N0/$deep/new_file_1
+echo 2 >> $N0/$deep/new_file_1
+
+
+# At the end of each fop in server, reference count of the
+# inode associated with each of the file above drops to zero and hence
+# put into lru queue. Since lru-limit is set to 1, an fop next file
+# will displace the current inode from itable. This will ensure that
+# when writes happens on same fd, fd resolution results in
+# nameless lookup from server and encounters an fd
+# associated with an inode whose parent is not present in itable.
+
+for j in $(seq 1 2); do
+    for i in $(seq 3 6); do
+        TEST_IN_LOOP fd_write $i "content"
+        TEST_IN_LOOP sync
+    done
+done
+
+exec 3>&-
+exec 4>&-
+exec 5>&-
+exec 6>&-
+
+$CLI volume statedump $V0 all
+
+EXPECT_WITHIN $UMOUNT_TIMEOUT "Y" force_umount $N0
+
+TEST $CLI volume stop $V0
+
+cleanup;
diff --git a/xlators/protocol/server/src/server-resolve.c b/xlators/protocol/server/src/server-resolve.c
index 906dc00..5f3d475 100644
--- a/xlators/protocol/server/src/server-resolve.c
+++ b/xlators/protocol/server/src/server-resolve.c
@@ -167,12 +167,14 @@ resolve_gfid_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
         inode_path (resolve_loc->parent, resolve_loc->name,
                     (char **) &resolve_loc->path);
 
-        dict = dict_copy_with_ref (state->xdata, NULL);
-        if (!dict && state->xdata)
-                gf_msg (this->name, GF_LOG_ERROR, ENOMEM, PS_MSG_NO_MEMORY,
-                        "BUG: dict allocation failed (pargfid: %s, name: %s), "
-                        "still continuing", uuid_utoa (resolve_loc->gfid),
-                        resolve_loc->name);
+        if (state->xdata) {
+                dict = dict_copy_with_ref (state->xdata, NULL);
+                if (!dict)
+                        gf_msg (this->name, GF_LOG_ERROR, ENOMEM, PS_MSG_NO_MEMORY,
+                                "BUG: dict allocation failed (pargfid: %s, name: %s), "
+                                "still continuing", uuid_utoa (resolve_loc->gfid),
+                                resolve_loc->name);
+        }
 
         STACK_WIND (frame, resolve_gfid_entry_cbk,
                     frame->root->client->bound_xl,
@@ -210,12 +212,14 @@ resolve_gfid (call_frame_t *frame)
         resolve_loc->inode = inode_new (state->itable);
         ret = loc_path (resolve_loc, NULL);
 
-        xdata = dict_copy_with_ref (state->xdata, NULL);
-        if (!xdata && state->xdata)
-                gf_msg (this->name, GF_LOG_ERROR, ENOMEM, PS_MSG_NO_MEMORY,
-                        "BUG: dict allocation failed (gfid: %s), "
-                        "still continuing",
-                        uuid_utoa (resolve_loc->gfid));
+        if (state->xdata) {
+                xdata = dict_copy_with_ref (state->xdata, NULL);
+                if (!xdata)
+                        gf_msg (this->name, GF_LOG_ERROR, ENOMEM, PS_MSG_NO_MEMORY,
+                                "BUG: dict allocation failed (gfid: %s), "
+                                "still continuing",
+                                uuid_utoa (resolve_loc->gfid));
+        }
 
         STACK_WIND (frame, resolve_gfid_cbk,
                     frame->root->client->bound_xl,
-- 
1.7.1