21ab4e
From 86a24b1c3d749721ba54137abb8c9b62e87be77a Mon Sep 17 00:00:00 2001
21ab4e
From: Samikshan Bairagya <samikshan@gmail.com>
21ab4e
Date: Mon, 20 Feb 2017 18:35:01 +0530
21ab4e
Subject: [PATCH 341/361] core: Clean up pmap registry up correctly on
21ab4e
 volume/brick stop
21ab4e
21ab4e
This commit changes the following:
21ab4e
1. In glusterfs_handle_terminate, send out individual pmap signout
21ab4e
requests to glusterd for every brick.
21ab4e
2. Add another parameter to glusterfs_mgmt_pmap_signout function to
21ab4e
pass the brickname that needs to be removed from the pmap registry.
21ab4e
3. Make sure pmap_registry_search doesn't break out from the loop
21ab4e
iterating over the list of bricks per port if the first brick entry
21ab4e
corresponding to a port is whitespaced out.
21ab4e
4. Make sure the pmap registry entries are removed for other
21ab4e
daemons like snapd.
21ab4e
21ab4e
mainline:
21ab4e
> BUG: 1421590
21ab4e
> Reviewed-on: https://review.gluster.org/16689
21ab4e
> Smoke: Gluster Build System <jenkins@build.gluster.org>
21ab4e
> NetBSD-regression: NetBSD Build System <jenkins@build.gluster.org>
21ab4e
> CentOS-regression: Gluster Build System <jenkins@build.gluster.org>
21ab4e
> Reviewed-by: Gaurav Yadav <gyadav@redhat.com>
21ab4e
> Reviewed-by: Jeff Darcy <jdarcy@redhat.com>
21ab4e
(cherry picked from commit 2cf0062984ae2c159cc94bfa7093f6e38bfd99fe)
21ab4e
21ab4e
BUG: 1417815
21ab4e
Change-Id: I69949874435b02699e5708dab811777ccb297174
21ab4e
Signed-off-by: Samikshan Bairagya <samikshan@gmail.com>
21ab4e
Reviewed-on: https://code.engineering.redhat.com/gerrit/101322
21ab4e
Tested-by: Milind Changire <mchangir@redhat.com>
21ab4e
Reviewed-by: Atin Mukherjee <amukherj@redhat.com>
21ab4e
---
21ab4e
 glusterfsd/src/glusterfsd-mgmt.c                   | 15 ++++--
21ab4e
 glusterfsd/src/glusterfsd.c                        |  2 +-
21ab4e
 glusterfsd/src/glusterfsd.h                        |  2 +-
21ab4e
 .../bugs/core/bug-1421590-brick-mux-resuse-ports.t | 55 ++++++++++++++++++++++
21ab4e
 xlators/mgmt/glusterd/src/glusterd-pmap.c          | 15 +++---
21ab4e
 5 files changed, 75 insertions(+), 14 deletions(-)
21ab4e
 create mode 100644 tests/bugs/core/bug-1421590-brick-mux-resuse-ports.t
21ab4e
21ab4e
diff --git a/glusterfsd/src/glusterfsd-mgmt.c b/glusterfsd/src/glusterfsd-mgmt.c
21ab4e
index 44ddc64..9cb8b41 100644
21ab4e
--- a/glusterfsd/src/glusterfsd-mgmt.c
21ab4e
+++ b/glusterfsd/src/glusterfsd-mgmt.c
21ab4e
@@ -236,6 +236,7 @@ glusterfs_handle_terminate (rpcsvc_request_t *req)
21ab4e
                 gf_log (THIS->name, GF_LOG_INFO,
21ab4e
                         "terminating after loss of last child %s",
21ab4e
                         xlator_req.name);
21ab4e
+                glusterfs_mgmt_pmap_signout (glusterfsd_ctx, xlator_req.name);
21ab4e
                 cleanup_and_exit (SIGTERM);
21ab4e
         } else {
21ab4e
                 /*
21ab4e
@@ -248,6 +249,8 @@ glusterfs_handle_terminate (rpcsvc_request_t *req)
21ab4e
                 gf_log (THIS->name, GF_LOG_INFO, "detaching not-only child %s",
21ab4e
                         xlator_req.name);
21ab4e
                 top->notify (top, GF_EVENT_TRANSPORT_CLEANUP, victim);
21ab4e
+                glusterfs_mgmt_pmap_signout (glusterfsd_ctx, xlator_req.name);
21ab4e
+
21ab4e
                 *trav_p = (*trav_p)->next;
21ab4e
                 glusterfs_autoscale_threads (THIS->ctx, -1);
21ab4e
         }
21ab4e
@@ -2560,7 +2563,7 @@ out:
21ab4e
 
21ab4e
 
21ab4e
 int
21ab4e
-glusterfs_mgmt_pmap_signout (glusterfs_ctx_t *ctx)
21ab4e
+glusterfs_mgmt_pmap_signout (glusterfs_ctx_t *ctx, char *brickname)
21ab4e
 {
21ab4e
         int               ret = 0;
21ab4e
         pmap_signout_req  req = {0, };
21ab4e
@@ -2571,7 +2574,7 @@ glusterfs_mgmt_pmap_signout (glusterfs_ctx_t *ctx)
21ab4e
         frame = create_frame (THIS, ctx->pool);
21ab4e
         cmd_args = &ctx->cmd_args;
21ab4e
 
21ab4e
-        if (!cmd_args->brick_port || !cmd_args->brick_name) {
21ab4e
+        if (!cmd_args->brick_port && (!cmd_args->brick_name || !brickname)) {
21ab4e
                 gf_log ("fsd-mgmt", GF_LOG_DEBUG,
21ab4e
                         "portmapper signout arguments not given");
21ab4e
                 goto out;
21ab4e
@@ -2582,8 +2585,12 @@ glusterfs_mgmt_pmap_signout (glusterfs_ctx_t *ctx)
21ab4e
                 snprintf (brick_name, sizeof(brick_name), "%s.rdma",
21ab4e
                           cmd_args->brick_name);
21ab4e
                 req.brick = brick_name;
21ab4e
-        } else
21ab4e
-                req.brick = cmd_args->brick_name;
21ab4e
+        } else {
21ab4e
+                if (brickname)
21ab4e
+                        req.brick = brickname;
21ab4e
+                else
21ab4e
+                        req.brick = cmd_args->brick_name;
21ab4e
+        }
21ab4e
 
21ab4e
         req.port  = cmd_args->brick_port;
21ab4e
         req.rdma_port = cmd_args->brick_port2;
21ab4e
diff --git a/glusterfsd/src/glusterfsd.c b/glusterfsd/src/glusterfsd.c
21ab4e
index 485da4e..cbc1b93 100644
21ab4e
--- a/glusterfsd/src/glusterfsd.c
21ab4e
+++ b/glusterfsd/src/glusterfsd.c
21ab4e
@@ -1291,7 +1291,7 @@ cleanup_and_exit (int signum)
21ab4e
                 return;
21ab4e
 
21ab4e
         ctx->cleanup_started = 1;
21ab4e
-        glusterfs_mgmt_pmap_signout (ctx);
21ab4e
+        glusterfs_mgmt_pmap_signout (ctx, NULL);
21ab4e
 
21ab4e
         /* below part is a racy code where the rpcsvc object is freed.
21ab4e
          * But in another thread (epoll thread), upon poll error in the
21ab4e
diff --git a/glusterfsd/src/glusterfsd.h b/glusterfsd/src/glusterfsd.h
21ab4e
index 62aae2a..e13896d 100644
21ab4e
--- a/glusterfsd/src/glusterfsd.h
21ab4e
+++ b/glusterfsd/src/glusterfsd.h
21ab4e
@@ -111,7 +111,7 @@ struct _gfd_vol_top_priv_t {
21ab4e
 };
21ab4e
 typedef struct _gfd_vol_top_priv_t gfd_vol_top_priv_t;
21ab4e
 
21ab4e
-int glusterfs_mgmt_pmap_signout (glusterfs_ctx_t *ctx);
21ab4e
+int glusterfs_mgmt_pmap_signout (glusterfs_ctx_t *ctx, char *brick_name);
21ab4e
 int glusterfs_mgmt_pmap_signin (glusterfs_ctx_t *ctx);
21ab4e
 int glusterfs_volfile_fetch (glusterfs_ctx_t *ctx);
21ab4e
 void cleanup_and_exit (int signum);
21ab4e
diff --git a/tests/bugs/core/bug-1421590-brick-mux-resuse-ports.t b/tests/bugs/core/bug-1421590-brick-mux-resuse-ports.t
21ab4e
new file mode 100644
21ab4e
index 0000000..ed401f6
21ab4e
--- /dev/null
21ab4e
+++ b/tests/bugs/core/bug-1421590-brick-mux-resuse-ports.t
21ab4e
@@ -0,0 +1,55 @@
21ab4e
+#!/bin/bash
21ab4e
+
21ab4e
+. $(dirname $0)/../../include.rc
21ab4e
+. $(dirname $0)/../../traps.rc
21ab4e
+. $(dirname $0)/../../volume.rc
21ab4e
+
21ab4e
+function get_nth_brick_port_for_volume () {
21ab4e
+        local VOL=$1
21ab4e
+        local n=$2
21ab4e
+
21ab4e
+        $CLI volume status $VOL --xml | sed -ne 's/.*<port>\([-0-9]*\)<\/port>/\1/p' \
21ab4e
+                                      | head -n $n | tail -n 1
21ab4e
+}
21ab4e
+
21ab4e
+TEST glusterd
21ab4e
+
21ab4e
+TEST $CLI volume set all cluster.brick-multiplex on
21ab4e
+push_trapfunc "$CLI volume set all cluster.brick-multiplex off"
21ab4e
+push_trapfunc "cleanup"
21ab4e
+
21ab4e
+TEST $CLI volume create $V0 $H0:$B0/brick{0,1}
21ab4e
+TEST $CLI volume start $V0
21ab4e
+
21ab4e
+port_brick0=$(get_nth_brick_port_for_volume $V0 1)
21ab4e
+
21ab4e
+# restart the volume
21ab4e
+TEST $CLI volume stop $V0
21ab4e
+TEST $CLI volume start $V0
21ab4e
+
21ab4e
+EXPECT_WITHIN $PROCESS_UP_TIMEOUT $port_brick0 get_nth_brick_port_for_volume $V0 1
21ab4e
+
21ab4e
+TEST $CLI volume stop $V0
21ab4e
+TEST $CLI volume set all cluster.brick-multiplex off
21ab4e
+
21ab4e
+TEST $CLI volume start $V0
21ab4e
+
21ab4e
+EXPECT_WITHIN $PROCESS_UP_TIMEOUT $port_brick0 get_nth_brick_port_for_volume $V0 1
21ab4e
+
21ab4e
+port_brick1=$(get_nth_brick_port_for_volume $V0 2)
21ab4e
+
21ab4e
+# restart the volume
21ab4e
+TEST $CLI volume stop $V0
21ab4e
+TEST $CLI volume start $V0
21ab4e
+
21ab4e
+EXPECT_WITHIN $PROCESS_UP_TIMEOUT $port_brick0 get_nth_brick_port_for_volume $V0 1
21ab4e
+EXPECT_WITHIN $PROCESS_UP_TIMEOUT $port_brick1 get_nth_brick_port_for_volume $V0 2
21ab4e
+
21ab4e
+TEST $CLI volume stop $V0
21ab4e
+
21ab4e
+TEST $CLI volume set all cluster.brick-multiplex on
21ab4e
+
21ab4e
+TEST $CLI volume start $V0
21ab4e
+
21ab4e
+EXPECT_WITHIN $PROCESS_UP_TIMEOUT $port_brick0 get_nth_brick_port_for_volume $V0 1
21ab4e
+
21ab4e
diff --git a/xlators/mgmt/glusterd/src/glusterd-pmap.c b/xlators/mgmt/glusterd/src/glusterd-pmap.c
21ab4e
index 8a39fc2..d87c31e 100644
21ab4e
--- a/xlators/mgmt/glusterd/src/glusterd-pmap.c
21ab4e
+++ b/xlators/mgmt/glusterd/src/glusterd-pmap.c
21ab4e
@@ -119,9 +119,9 @@ pmap_registry_search (xlator_t *this, const char *brickname,
21ab4e
                 for (;;) {
21ab4e
                         for (i = 0; brck[i] && !isspace (brck[i]); ++i)
21ab4e
                                 ;
21ab4e
-                        if (!i) {
21ab4e
+                        if (i == 0 && brck[i] == '\0')
21ab4e
                                 break;
21ab4e
-                        }
21ab4e
+
21ab4e
                         if (strncmp (brck, brickname, i) == 0) {
21ab4e
                                 /*
21ab4e
                                  * Without this check, we'd break when brck
21ab4e
@@ -134,7 +134,9 @@ pmap_registry_search (xlator_t *this, const char *brickname,
21ab4e
                                         return p;
21ab4e
                                 }
21ab4e
                         }
21ab4e
+
21ab4e
                         brck += i;
21ab4e
+
21ab4e
                         /*
21ab4e
                          * Skip over *any* amount of whitespace, including
21ab4e
                          * none (if we're already at the end of the string).
21ab4e
@@ -260,7 +262,6 @@ pmap_registry_bind (xlator_t *this, int port, const char *brickname,
21ab4e
                 goto out;
21ab4e
 
21ab4e
         p = port;
21ab4e
-        pmap->ports[p].type = type;
21ab4e
         if (pmap->ports[p].brickname) {
21ab4e
                 char *tmp = pmap->ports[p].brickname;
21ab4e
                 asprintf (&pmap->ports[p].brickname, "%s %s", tmp, brickname);
21ab4e
@@ -356,10 +357,9 @@ pmap_registry_remove (xlator_t *this, int port, const char *brickname,
21ab4e
                         goto out;
21ab4e
 
21ab4e
                 p = port;
21ab4e
-                goto remove;
21ab4e
         }
21ab4e
 
21ab4e
-        if (brickname && strchr (brickname, '/')) {
21ab4e
+        if (brickname) {
21ab4e
                 p = pmap_registry_search (this, brickname, type, _gf_true);
21ab4e
                 if (p)
21ab4e
                         goto remove;
21ab4e
@@ -373,9 +373,8 @@ pmap_registry_remove (xlator_t *this, int port, const char *brickname,
21ab4e
 
21ab4e
         goto out;
21ab4e
 remove:
21ab4e
-        gf_msg ("pmap", GF_LOG_INFO, 0,
21ab4e
-                GD_MSG_BRICK_REMOVE, "removing brick %s on port %d",
21ab4e
-                pmap->ports[p].brickname, p);
21ab4e
+        gf_msg ("pmap", GF_LOG_INFO, 0, GD_MSG_BRICK_REMOVE,
21ab4e
+                "removing brick %s on port %d", brickname, p);
21ab4e
 
21ab4e
         if (xprt && (xprt == pmap->ports[p].xprt)) {
21ab4e
                 pmap->ports[p].xprt = NULL;
21ab4e
-- 
21ab4e
1.8.3.1
21ab4e