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