17b94a
From 3bcffadcd77eebe6b4f7e5015ad41ec7c1d1ec3e Mon Sep 17 00:00:00 2001
17b94a
From: Mohit Agrawal <moagrawal@redhat.com>
17b94a
Date: Thu, 11 Apr 2019 20:38:53 +0530
17b94a
Subject: [PATCH 096/124] core: Brick is not able to detach successfully in
17b94a
 brick_mux environment
17b94a
17b94a
Problem: In brick_mux environment, while volumes are stopped in a
17b94a
         loop bricks are not detached successfully. Brick's are not
17b94a
         detached because xprtrefcnt has not become 0 for detached brick.
17b94a
         At the time of initiating brick detach process server_notify
17b94a
         saves xprtrefcnt on detach brick and once counter has become
17b94a
         0 then server_rpc_notify spawn a server_graph_janitor_threads
17b94a
         for cleanup brick resources.xprtrefcnt has not become 0 because
17b94a
         socket framework is not working due to assigning 0 as a fd for socket.
17b94a
         In commit dc25d2c1eeace91669052e3cecc083896e7329b2
17b94a
         there was a change in changelog fini to close htime_fd if htime_fd is not
17b94a
         negative, by default htime_fd is 0 so it close 0 also.
17b94a
17b94a
Solution: Initialize htime_fd to -1 after just allocate changelog_priv
17b94a
          by GF_CALLOC
17b94a
17b94a
> Fixes: bz#1699025
17b94a
> Change-Id: I5f7ca62a0eb1c0510c3e9b880d6ab8af8d736a25
17b94a
> Signed-off-by: Mohit Agrawal <moagrawal@redhat.com>
17b94a
> (Cherry picked from commit b777d83001d8006420b6c7d2d88fe68950aa7e00)
17b94a
> (Reviewed on upstream link https://review.gluster.org/#/c/glusterfs/+/22549/
17b94a
17b94a
Fixes: bz#1698919
17b94a
Change-Id: Ib5b74aa0818235625f8aac7c23d4daa599da3fd1
17b94a
Signed-off-by: Mohit Agrawal <moagrawal@redhat.com>
17b94a
Reviewed-on: https://code.engineering.redhat.com/gerrit/167826
17b94a
Tested-by: Mohit Agrawal <moagrawa@redhat.com>
17b94a
Tested-by: RHGS Build Bot <nigelb@redhat.com>
17b94a
Reviewed-by: Sunil Kumar Heggodu Gopala Acharya <sheggodu@redhat.com>
17b94a
---
17b94a
 .../bug-1699025-brick-mux-detach-brick-fd-issue.t  | 33 ++++++++++++++++++++++
17b94a
 xlators/features/changelog/src/changelog.c         |  1 +
17b94a
 2 files changed, 34 insertions(+)
17b94a
 create mode 100644 tests/bugs/core/bug-1699025-brick-mux-detach-brick-fd-issue.t
17b94a
17b94a
diff --git a/tests/bugs/core/bug-1699025-brick-mux-detach-brick-fd-issue.t b/tests/bugs/core/bug-1699025-brick-mux-detach-brick-fd-issue.t
17b94a
new file mode 100644
17b94a
index 0000000..1acbaa8
17b94a
--- /dev/null
17b94a
+++ b/tests/bugs/core/bug-1699025-brick-mux-detach-brick-fd-issue.t
17b94a
@@ -0,0 +1,33 @@
17b94a
+#!/bin/bash
17b94a
+
17b94a
+. $(dirname $0)/../../include.rc
17b94a
+. $(dirname $0)/../../volume.rc
17b94a
+. $(dirname $0)/../../cluster.rc
17b94a
+
17b94a
+function count_brick_processes {
17b94a
+        pgrep glusterfsd | wc -l
17b94a
+}
17b94a
+
17b94a
+cleanup
17b94a
+
17b94a
+#bug-1444596 - validating brick mux
17b94a
+
17b94a
+TEST glusterd
17b94a
+TEST $CLI volume create $V0 $H0:$B0/brick{0,1}
17b94a
+TEST $CLI volume create $V1 $H0:$B0/brick{2,3}
17b94a
+
17b94a
+TEST $CLI volume set all cluster.brick-multiplex on
17b94a
+
17b94a
+TEST $CLI volume start $V0
17b94a
+TEST $CLI volume start $V1
17b94a
+EXPECT_WITHIN $PROCESS_UP_TIMEOUT 4 online_brick_count
17b94a
+EXPECT 1 count_brick_processes
17b94a
+
17b94a
+TEST $CLI volume stop $V1
17b94a
+# At the time initialize brick daemon it always keeps open
17b94a
+# standard fd's (0, 1 , 2) so after stop 1 volume fd's should
17b94a
+# be open
17b94a
+nofds=$(ls -lrth /proc/`pgrep glusterfsd`/fd | grep dev/null | wc -l)
17b94a
+TEST [ $((nofds)) -eq 3 ]
17b94a
+
17b94a
+cleanup
17b94a
diff --git a/xlators/features/changelog/src/changelog.c b/xlators/features/changelog/src/changelog.c
17b94a
index 1f22a97..d9025f3 100644
17b94a
--- a/xlators/features/changelog/src/changelog.c
17b94a
+++ b/xlators/features/changelog/src/changelog.c
17b94a
@@ -2740,6 +2740,7 @@ init(xlator_t *this)
17b94a
     GF_ATOMIC_INIT(priv->clntcnt, 0);
17b94a
     GF_ATOMIC_INIT(priv->xprtcnt, 0);
17b94a
     INIT_LIST_HEAD(&priv->xprt_list);
17b94a
+    priv->htime_fd = -1;
17b94a
 
17b94a
     ret = changelog_init_options(this, priv);
17b94a
     if (ret)
17b94a
-- 
17b94a
1.8.3.1
17b94a