887953
From 1de7497540b8428187df5048a1b8e82c2feec604 Mon Sep 17 00:00:00 2001
887953
From: Mohit Agrawal <moagrawa@redhat.com>
887953
Date: Mon, 19 Nov 2018 13:00:57 +0530
887953
Subject: [PATCH 446/450] core: Portmap entries showing stale brick entries
887953
 when bricks are down
887953
887953
Problem: pmap is showing stale brick entries after down the brick
887953
         because of glusterd_brick_rpc_notify call gf_is_service_running
887953
         before call pmap_registry_remove to ensure about brick instance.
887953
887953
Solutiom: 1) Change the condition in gf_is_pid_running to ensure about
887953
             process existence, use open instead of access to achieve
887953
             the same
887953
          2) Call search_brick_path_from_proc in __glusterd_brick_rpc_notify
887953
             along with gf_is_service_running
887953
887953
> Change-Id: Ia663ac61c01fdee6c12f47c0300cdf93f19b6a19
887953
> fixes: bz#1646892
887953
> Signed-off-by: Mohit Agrawal <moagrawal@redhat.com>
887953
> (Cherry picked from commit bcf1e8b07491b48c5372924dbbbad5b8391c6d81)
887953
> (Reviwed on upstream link https://review.gluster.org/#/c/glusterfs/+/21568/)
887953
887953
BUG: 1649651
887953
Change-Id: I06b0842d5e3ffc909304529311709064237ccc94
887953
Signed-off-by: Mohit Agrawal <moagrawa@redhat.com>
887953
Reviewed-on: https://code.engineering.redhat.com/gerrit/156326
887953
Tested-by: RHGS Build Bot <nigelb@redhat.com>
887953
Reviewed-by: Atin Mukherjee <amukherj@redhat.com>
887953
---
887953
 libglusterfs/src/common-utils.c              | 5 ++++-
887953
 xlators/mgmt/glusterd/src/glusterd-handler.c | 7 +++++--
887953
 xlators/mgmt/glusterd/src/glusterd-utils.h   | 2 ++
887953
 3 files changed, 11 insertions(+), 3 deletions(-)
887953
887953
diff --git a/libglusterfs/src/common-utils.c b/libglusterfs/src/common-utils.c
887953
index 54ef875..dd6cdb3 100644
887953
--- a/libglusterfs/src/common-utils.c
887953
+++ b/libglusterfs/src/common-utils.c
887953
@@ -3986,13 +3986,16 @@ gf_boolean_t
887953
 gf_is_pid_running (int pid)
887953
 {
887953
         char fname[32] = {0,};
887953
+        int fd = -1;
887953
 
887953
         snprintf(fname, sizeof(fname), "/proc/%d/cmdline", pid);
887953
 
887953
-        if (sys_access (fname , R_OK) != 0) {
887953
+        fd = sys_open(fname, O_RDONLY, 0);
887953
+        if (fd < 0) {
887953
                 return _gf_false;
887953
         }
887953
 
887953
+        sys_close(fd);
887953
         return _gf_true;
887953
 
887953
 }
887953
diff --git a/xlators/mgmt/glusterd/src/glusterd-handler.c b/xlators/mgmt/glusterd/src/glusterd-handler.c
887953
index bf37e70..a129afc 100644
887953
--- a/xlators/mgmt/glusterd/src/glusterd-handler.c
887953
+++ b/xlators/mgmt/glusterd/src/glusterd-handler.c
887953
@@ -6193,11 +6193,14 @@ __glusterd_brick_rpc_notify (struct rpc_clnt *rpc, void *mydata,
887953
                         /* In case of an abrupt shutdown of a brick PMAP_SIGNOUT
887953
                          * event is not received by glusterd which can lead to a
887953
                          * stale port entry in glusterd, so forcibly clean up
887953
-                         * the same if the process is not running
887953
+                         * the same if the process is not running sometime
887953
+                         * gf_is_service_running true so to ensure about brick instance
887953
+                         * call search_brick_path_from_proc
887953
                          */
887953
                         GLUSTERD_GET_BRICK_PIDFILE (pidfile, volinfo,
887953
                                                     brickinfo, conf);
887953
-                        if (!gf_is_service_running (pidfile, &pid)) {
887953
+                        if (!gf_is_service_running (pidfile, &pid) ||
887953
+                            !search_brick_path_from_proc(pid, brickinfo->path)) {
887953
                                 ret = pmap_registry_remove (
887953
                                                       THIS, brickinfo->port,
887953
                                                       brickinfo->path,
887953
diff --git a/xlators/mgmt/glusterd/src/glusterd-utils.h b/xlators/mgmt/glusterd/src/glusterd-utils.h
887953
index ffcc636..8e5320d 100644
887953
--- a/xlators/mgmt/glusterd/src/glusterd-utils.h
887953
+++ b/xlators/mgmt/glusterd/src/glusterd-utils.h
887953
@@ -897,4 +897,6 @@ glusterd_get_index_basepath (glusterd_brickinfo_t *brickinfo, char *buffer,
887953
 gf_boolean_t
887953
 glusterd_is_profile_on (glusterd_volinfo_t *volinfo);
887953
 
887953
+char *
887953
+search_brick_path_from_proc(pid_t brick_pid, char *brickpath);
887953
 #endif
887953
-- 
887953
1.8.3.1
887953