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