a3470f
From 385b61f9a6f818c2810cc0a2223c9d71340cd345 Mon Sep 17 00:00:00 2001
a3470f
From: Atin Mukherjee <amukherj@redhat.com>
a3470f
Date: Tue, 17 Oct 2017 21:32:44 +0530
a3470f
Subject: [PATCH 43/74] glusterd: clean up portmap on brick disconnect
a3470f
a3470f
GlusterD's portmap entry for a brick is cleaned up when a PMAP_SIGNOUT event is
a3470f
initiated by the brick process at the shutdown. But if the brick process crashes
a3470f
or gets killed through SIGKILL then this event is not initiated and glusterd
a3470f
ends up with a stale port. Since GlusterD's portmap traversal happens both ways,
a3470f
forward for allocation and backward for registry search, there is a possibility
a3470f
that glusterd might end up running with a stale port for a brick which
a3470f
eventually will end up with clients to fail to connect to the bricks.
a3470f
a3470f
Solution is to clean up the port entry in case the process is down as
a3470f
part of the brick disconnect event. Although with this the handling
a3470f
PMAP_SIGNOUT event becomes redundant in most of the cases, but this is
a3470f
the safeguard method to avoid glusterd getting into the stale port
a3470f
issues.
a3470f
a3470f
>mainline patch : https://review.gluster.org/#/c/18541
a3470f
a3470f
Change-Id: I04c5be6d11e772ee4de16caf56dbb37d5c944303
a3470f
BUG: 1503244
a3470f
Signed-off-by: Atin Mukherjee <amukherj@redhat.com>
a3470f
Reviewed-on: https://code.engineering.redhat.com/gerrit/123057
a3470f
Reviewed-by: Gaurav Yadav <gyadav@redhat.com>
a3470f
---
a3470f
 xlators/mgmt/glusterd/src/glusterd-handler.c | 25 +++++++++++++++++++++++++
a3470f
 xlators/mgmt/glusterd/src/glusterd-pmap.c    | 26 +++++++++++++++++---------
a3470f
 xlators/mgmt/glusterd/src/glusterd-pmap.h    |  3 ++-
a3470f
 xlators/mgmt/glusterd/src/glusterd.c         |  3 ++-
a3470f
 4 files changed, 46 insertions(+), 11 deletions(-)
a3470f
a3470f
diff --git a/xlators/mgmt/glusterd/src/glusterd-handler.c b/xlators/mgmt/glusterd/src/glusterd-handler.c
a3470f
index af9a796..34e751c 100644
a3470f
--- a/xlators/mgmt/glusterd/src/glusterd-handler.c
a3470f
+++ b/xlators/mgmt/glusterd/src/glusterd-handler.c
a3470f
@@ -5974,8 +5974,10 @@ __glusterd_brick_rpc_notify (struct rpc_clnt *rpc, void *mydata,
a3470f
         glusterd_volinfo_t      *volinfo           = NULL;
a3470f
         xlator_t                *this              = NULL;
a3470f
         int                      temp              = 0;
a3470f
+        int32_t                  pid               = -1;
a3470f
         glusterd_brickinfo_t    *brickinfo_tmp     = NULL;
a3470f
         glusterd_brick_proc_t   *brick_proc        = NULL;
a3470f
+        char                     pidfile[PATH_MAX] = {0};
a3470f
 
a3470f
         brickid = mydata;
a3470f
         if (!brickid)
a3470f
@@ -6074,6 +6076,29 @@ __glusterd_brick_rpc_notify (struct rpc_clnt *rpc, void *mydata,
a3470f
                                   "peer=%s;volume=%s;brick=%s",
a3470f
                                   brickinfo->hostname, volinfo->volname,
a3470f
                                   brickinfo->path);
a3470f
+                        /* In case of an abrupt shutdown of a brick PMAP_SIGNOUT
a3470f
+                         * event is not received by glusterd which can lead to a
a3470f
+                         * stale port entry in glusterd, so forcibly clean up
a3470f
+                         * the same if the process is not running
a3470f
+                         */
a3470f
+                        GLUSTERD_GET_BRICK_PIDFILE (pidfile, volinfo,
a3470f
+                                                    brickinfo, conf);
a3470f
+                        if (!gf_is_service_running (pidfile, &pid)) {
a3470f
+                                ret = pmap_registry_remove (
a3470f
+                                                      THIS, brickinfo->port,
a3470f
+                                                      brickinfo->path,
a3470f
+                                                      GF_PMAP_PORT_BRICKSERVER,
a3470f
+                                                      NULL, _gf_true);
a3470f
+                                if (ret) {
a3470f
+                                        gf_msg (this->name, GF_LOG_WARNING,
a3470f
+                                                GD_MSG_PMAP_REGISTRY_REMOVE_FAIL,
a3470f
+                                                0, "Failed to remove pmap "
a3470f
+                                                "registry for port %d for "
a3470f
+                                                "brick %s", brickinfo->port,
a3470f
+                                                brickinfo->path);
a3470f
+                                        ret = 0;
a3470f
+                                }
a3470f
+                        }
a3470f
                 }
a3470f
 
a3470f
                 if (is_brick_mx_enabled()) {
a3470f
diff --git a/xlators/mgmt/glusterd/src/glusterd-pmap.c b/xlators/mgmt/glusterd/src/glusterd-pmap.c
a3470f
index 2a75476..1b547e7 100644
a3470f
--- a/xlators/mgmt/glusterd/src/glusterd-pmap.c
a3470f
+++ b/xlators/mgmt/glusterd/src/glusterd-pmap.c
a3470f
@@ -239,7 +239,8 @@ pmap_assign_port (xlator_t *this, int old_port, const char *path)
a3470f
 
a3470f
         if (old_port) {
a3470f
                 ret = pmap_registry_remove (this, 0, path,
a3470f
-                                            GF_PMAP_PORT_BRICKSERVER, NULL);
a3470f
+                                            GF_PMAP_PORT_BRICKSERVER, NULL,
a3470f
+                                            _gf_false);
a3470f
                 if (ret) {
a3470f
                         gf_msg (this->name, GF_LOG_WARNING,
a3470f
                                 GD_MSG_PMAP_REGISTRY_REMOVE_FAIL, 0, "Failed to"
a3470f
@@ -342,7 +343,8 @@ pmap_registry_extend (xlator_t *this, int port, const char *brickname)
a3470f
 
a3470f
 int
a3470f
 pmap_registry_remove (xlator_t *this, int port, const char *brickname,
a3470f
-                      gf_pmap_port_type_t type, void *xprt)
a3470f
+                      gf_pmap_port_type_t type, void *xprt,
a3470f
+                      gf_boolean_t brick_disconnect)
a3470f
 {
a3470f
         struct pmap_registry *pmap = NULL;
a3470f
         int                   p = 0;
a3470f
@@ -389,11 +391,16 @@ remove:
a3470f
          * can delete the entire entry.
a3470f
          */
a3470f
         if (!pmap->ports[p].xprt) {
a3470f
-                brick_str = pmap->ports[p].brickname;
a3470f
-                if (brick_str) {
a3470f
-                        while (*brick_str != '\0') {
a3470f
-                                if (*(brick_str++) != ' ') {
a3470f
-                                        goto out;
a3470f
+                /* If the signout call is being triggered by brick disconnect
a3470f
+                 * then clean up all the bricks (in case of brick mux)
a3470f
+                 */
a3470f
+                if (!brick_disconnect) {
a3470f
+                        brick_str = pmap->ports[p].brickname;
a3470f
+                        if (brick_str) {
a3470f
+                                while (*brick_str != '\0') {
a3470f
+                                        if (*(brick_str++) != ' ') {
a3470f
+                                                goto out;
a3470f
+                                        }
a3470f
                                 }
a3470f
                         }
a3470f
                 }
a3470f
@@ -548,14 +555,15 @@ __gluster_pmap_signout (rpcsvc_request_t *req)
a3470f
                 goto fail;
a3470f
         }
a3470f
         rsp.op_ret = pmap_registry_remove (THIS, args.port, args.brick,
a3470f
-                                           GF_PMAP_PORT_BRICKSERVER, req->trans);
a3470f
+                                           GF_PMAP_PORT_BRICKSERVER, req->trans,
a3470f
+                                           _gf_false);
a3470f
 
a3470f
         ret = glusterd_get_brickinfo (THIS, args.brick, args.port, &brickinfo);
a3470f
         if (args.rdma_port) {
a3470f
                 snprintf(brick_path, PATH_MAX, "%s.rdma", args.brick);
a3470f
                 rsp.op_ret = pmap_registry_remove (THIS, args.rdma_port,
a3470f
                                 brick_path, GF_PMAP_PORT_BRICKSERVER,
a3470f
-                                req->trans);
a3470f
+                                req->trans, _gf_false);
a3470f
         }
a3470f
         /* Update portmap status on brickinfo */
a3470f
         if (brickinfo)
a3470f
diff --git a/xlators/mgmt/glusterd/src/glusterd-pmap.h b/xlators/mgmt/glusterd/src/glusterd-pmap.h
a3470f
index 9965a95..253b4cc 100644
a3470f
--- a/xlators/mgmt/glusterd/src/glusterd-pmap.h
a3470f
+++ b/xlators/mgmt/glusterd/src/glusterd-pmap.h
a3470f
@@ -42,7 +42,8 @@ int pmap_registry_bind (xlator_t *this, int port, const char *brickname,
a3470f
                         gf_pmap_port_type_t type, void *xprt);
a3470f
 int pmap_registry_extend (xlator_t *this, int port, const char *brickname);
a3470f
 int pmap_registry_remove (xlator_t *this, int port, const char *brickname,
a3470f
-                          gf_pmap_port_type_t type, void *xprt);
a3470f
+                          gf_pmap_port_type_t type, void *xprt,
a3470f
+                          gf_boolean_t brick_disconnect);
a3470f
 int pmap_registry_search (xlator_t *this, const char *brickname,
a3470f
                           gf_pmap_port_type_t type, gf_boolean_t destroy);
a3470f
 struct pmap_registry *pmap_registry_get (xlator_t *this);
a3470f
diff --git a/xlators/mgmt/glusterd/src/glusterd.c b/xlators/mgmt/glusterd/src/glusterd.c
a3470f
index 4887ff4..81a3206 100644
a3470f
--- a/xlators/mgmt/glusterd/src/glusterd.c
a3470f
+++ b/xlators/mgmt/glusterd/src/glusterd.c
a3470f
@@ -424,7 +424,8 @@ glusterd_rpcsvc_notify (rpcsvc_t *rpc, void *xl, rpcsvc_event_t event,
a3470f
                 pthread_mutex_lock (&priv->xprt_lock);
a3470f
                 list_del (&xprt->list);
a3470f
                 pthread_mutex_unlock (&priv->xprt_lock);
a3470f
-                pmap_registry_remove (this, 0, NULL, GF_PMAP_PORT_ANY, xprt);
a3470f
+                pmap_registry_remove (this, 0, NULL, GF_PMAP_PORT_ANY, xprt,
a3470f
+                                      _gf_false);
a3470f
                 break;
a3470f
         }
a3470f
 
a3470f
-- 
a3470f
1.8.3.1
a3470f