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