14f8ab
From a0661449cd8ba7b851fec473191733767f4541b8 Mon Sep 17 00:00:00 2001
14f8ab
From: Pranith Kumar K <pkarampu@redhat.com>
14f8ab
Date: Thu, 28 Mar 2019 17:55:54 +0530
14f8ab
Subject: [PATCH 46/52] protocol/client: Do not fallback to anon-fd if fd is
14f8ab
 not open
14f8ab
14f8ab
If an open comes on a file when a brick is down and after the brick comes up,
14f8ab
a fop comes on the fd, client xlator would still wind the fop on anon-fd
14f8ab
leading to wrong behavior of the fops in some cases.
14f8ab
14f8ab
Example:
14f8ab
If lk fop is issued on the fd just after the brick is up in the scenario above,
14f8ab
lk fop will be sent on anon-fd instead of failing it on that client xlator.
14f8ab
This lock will never be freed upon close of the fd as flush on anon-fd is
14f8ab
invalid and is not wound below server xlator.
14f8ab
14f8ab
As a fix, failing the fop unless the fd has FALLBACK_TO_ANON_FD flag.
14f8ab
14f8ab
 >Upstream-patch: https://review.gluster.org/c/glusterfs/+/15804
14f8ab
 >Change-Id: I77692d056660b2858e323bdabdfe0a381807cccc
14f8ab
 >fixes bz#1390914
14f8ab
14f8ab
BUG: 1695057
14f8ab
Change-Id: Id656bea8dde14327212fbe7ecc97519dc5b32098
14f8ab
Signed-off-by: Pranith Kumar K <pkarampu@redhat.com>
14f8ab
Reviewed-on: https://code.engineering.redhat.com/gerrit/166833
14f8ab
Tested-by: RHGS Build Bot <nigelb@redhat.com>
14f8ab
Reviewed-by: Sunil Kumar Heggodu Gopala Acharya <sheggodu@redhat.com>
14f8ab
---
14f8ab
 tests/bugs/protocol/bug-1390914.t            | 36 ++++++++++++++++++++++++++++
14f8ab
 xlators/protocol/client/src/client-helpers.c |  8 ++++++-
14f8ab
 2 files changed, 43 insertions(+), 1 deletion(-)
14f8ab
 create mode 100644 tests/bugs/protocol/bug-1390914.t
14f8ab
14f8ab
diff --git a/tests/bugs/protocol/bug-1390914.t b/tests/bugs/protocol/bug-1390914.t
14f8ab
new file mode 100644
14f8ab
index 0000000..e3dab92
14f8ab
--- /dev/null
14f8ab
+++ b/tests/bugs/protocol/bug-1390914.t
14f8ab
@@ -0,0 +1,36 @@
14f8ab
+#!/bin/bash
14f8ab
+
14f8ab
+. $(dirname $0)/../../include.rc
14f8ab
+. $(dirname $0)/../../volume.rc
14f8ab
+. $(dirname $0)/../../fileio.rc
14f8ab
+cleanup;
14f8ab
+
14f8ab
+#test that fops are not wound on anon-fd when fd is not open on that brick
14f8ab
+TEST glusterd;
14f8ab
+TEST pidof glusterd
14f8ab
+
14f8ab
+TEST $CLI volume create $V0 replica 3 $H0:$B0/${V0}{1,2,3};
14f8ab
+TEST $CLI volume set $V0 performance.open-behind off
14f8ab
+TEST $CLI volume set $V0 diagnostics.client-log-level DEBUG
14f8ab
+TEST $CLI volume heal $V0 disable
14f8ab
+TEST $CLI volume start $V0
14f8ab
+TEST $CLI volume profile $V0 start
14f8ab
+TEST $GFS -s $H0 --volfile-id=$V0 --direct-io-mode=enable $M0;
14f8ab
+
14f8ab
+TEST touch $M0/1
14f8ab
+TEST kill_brick $V0 $H0 $B0/${V0}1
14f8ab
+TEST fd_open 200 'w' "$M0/1"
14f8ab
+TEST $CLI volume start $V0 force
14f8ab
+EXPECT_WITHIN $PROCESS_UP_TIMEOUT "1" afr_child_up_status $V0 0
14f8ab
+
14f8ab
+#lk should only happen on 2 bricks, if there is a bug, it will plant a lock
14f8ab
+#with anon-fd on first-brick which will never be released because flush won't
14f8ab
+#be wound below server xlator for anon-fd
14f8ab
+TEST flock -x -n 200
14f8ab
+TEST fd_close 200
14f8ab
+
14f8ab
+TEST fd_open 200 'w' "$M0/1"
14f8ab
+#this lock will fail if there is a stale lock
14f8ab
+TEST flock -x -n 200
14f8ab
+TEST fd_close 200
14f8ab
+cleanup;
14f8ab
diff --git a/xlators/protocol/client/src/client-helpers.c b/xlators/protocol/client/src/client-helpers.c
14f8ab
index 55e87b3..2dd7106 100644
14f8ab
--- a/xlators/protocol/client/src/client-helpers.c
14f8ab
+++ b/xlators/protocol/client/src/client-helpers.c
14f8ab
@@ -419,7 +419,13 @@ client_get_remote_fd(xlator_t *this, fd_t *fd, int flags, int64_t *remote_fd)
14f8ab
     {
14f8ab
         fdctx = this_fd_get_ctx(fd, this);
14f8ab
         if (!fdctx) {
14f8ab
-            *remote_fd = GF_ANON_FD_NO;
14f8ab
+            if (fd->anonymous) {
14f8ab
+                *remote_fd = GF_ANON_FD_NO;
14f8ab
+            } else {
14f8ab
+                *remote_fd = -1;
14f8ab
+                gf_msg_debug(this->name, EBADF, "not a valid fd for gfid: %s",
14f8ab
+                             uuid_utoa(fd->inode->gfid));
14f8ab
+            }
14f8ab
         } else {
14f8ab
             if (__is_fd_reopen_in_progress(fdctx))
14f8ab
                 *remote_fd = -1;
14f8ab
-- 
14f8ab
1.8.3.1
14f8ab