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