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