d1681e
From df907fc49b6ecddd20fa06558c36e779521e85f3 Mon Sep 17 00:00:00 2001
d1681e
From: Pranith Kumar K <pkarampu@redhat.com>
d1681e
Date: Tue, 3 Jul 2018 14:14:59 +0530
d1681e
Subject: [PATCH 312/325] glusterd: show brick online after port registration
d1681e
 even in brick-mux
d1681e
d1681e
	Upstream-patch: https://review.gluster.org/20451
d1681e
d1681e
Problem:
d1681e
With brick-mux even before brick attach is complete on the bricks
d1681e
glusterd marks them as online. This can lead to a race where
d1681e
scripts that check if the bricks are online to assume that the
d1681e
brick is online before it is completely online.
d1681e
d1681e
Fix:
d1681e
Wait for the callback from the brick before marking the port
d1681e
as registered so that volume status will show the correct status
d1681e
of the brick.
d1681e
d1681e
 >fixes bz#1597568
d1681e
BUG: 1598356
d1681e
Change-Id: Icd3dc62506af0cf75195e96746695db823312051
d1681e
Signed-off-by: Pranith Kumar K <pkarampu@redhat.com>
d1681e
Reviewed-on: https://code.engineering.redhat.com/gerrit/143592
d1681e
Tested-by: RHGS Build Bot <nigelb@redhat.com>
d1681e
Reviewed-by: Sunil Kumar Heggodu Gopala Acharya <sheggodu@redhat.com>
d1681e
---
d1681e
 xlators/mgmt/glusterd/src/glusterd-snapshot.c |  2 +-
d1681e
 xlators/mgmt/glusterd/src/glusterd-utils.c    | 36 +++++++++++++++++++++------
d1681e
 xlators/mgmt/glusterd/src/glusterd-utils.h    |  3 ++-
d1681e
 3 files changed, 31 insertions(+), 10 deletions(-)
d1681e
d1681e
diff --git a/xlators/mgmt/glusterd/src/glusterd-snapshot.c b/xlators/mgmt/glusterd/src/glusterd-snapshot.c
d1681e
index 5bdf27f..84335ef 100644
d1681e
--- a/xlators/mgmt/glusterd/src/glusterd-snapshot.c
d1681e
+++ b/xlators/mgmt/glusterd/src/glusterd-snapshot.c
d1681e
@@ -2844,7 +2844,7 @@ glusterd_do_lvm_snapshot_remove (glusterd_volinfo_t *snap_vol,
d1681e
         GLUSTERD_GET_BRICK_PIDFILE (pidfile, snap_vol, brickinfo, priv);
d1681e
         if (gf_is_service_running (pidfile, &pid)) {
d1681e
                 (void) send_attach_req (this, brickinfo->rpc,
d1681e
-                                        brickinfo->path,
d1681e
+                                        brickinfo->path, NULL,
d1681e
                                         GLUSTERD_BRICK_TERMINATE);
d1681e
                 brickinfo->status = GF_BRICK_STOPPED;
d1681e
         }
d1681e
diff --git a/xlators/mgmt/glusterd/src/glusterd-utils.c b/xlators/mgmt/glusterd/src/glusterd-utils.c
d1681e
index e08c053..f62c917 100644
d1681e
--- a/xlators/mgmt/glusterd/src/glusterd-utils.c
d1681e
+++ b/xlators/mgmt/glusterd/src/glusterd-utils.c
d1681e
@@ -93,9 +93,6 @@
d1681e
 #define NLMV4_VERSION       4
d1681e
 #define NLMV1_VERSION       1
d1681e
 
d1681e
-int
d1681e
-send_attach_req (xlator_t *this, struct rpc_clnt *rpc, char *path, int op);
d1681e
-
d1681e
 gf_boolean_t
d1681e
 is_brick_mx_enabled (void)
d1681e
 {
d1681e
@@ -2481,7 +2478,7 @@ glusterd_volume_stop_glusterfs (glusterd_volinfo_t *volinfo,
d1681e
                                       brickinfo->hostname, brickinfo->path);
d1681e
 
d1681e
                         (void) send_attach_req (this, brickinfo->rpc,
d1681e
-                                                brickinfo->path,
d1681e
+                                                brickinfo->path, NULL,
d1681e
                                                 GLUSTERD_BRICK_TERMINATE);
d1681e
                 } else {
d1681e
                         gf_msg_debug (this->name, 0, "About to stop glusterfsd"
d1681e
@@ -5403,8 +5400,27 @@ my_callback (struct rpc_req *req, struct iovec *iov, int count, void *v_frame)
d1681e
         return 0;
d1681e
 }
d1681e
 
d1681e
+static int32_t
d1681e
+attach_brick_callback (struct rpc_req *req, struct iovec *iov, int count,
d1681e
+                       void *v_frame)
d1681e
+{
d1681e
+        call_frame_t    *frame  = v_frame;
d1681e
+        glusterd_conf_t *conf   = frame->this->private;
d1681e
+        glusterd_brickinfo_t *brickinfo = frame->local;
d1681e
+
d1681e
+        frame->local = NULL;
d1681e
+        brickinfo->port_registered = _gf_true;
d1681e
+        synclock_lock (&conf->big_lock);
d1681e
+        --(conf->blockers);
d1681e
+        synclock_unlock (&conf->big_lock);
d1681e
+
d1681e
+        STACK_DESTROY (frame->root);
d1681e
+        return 0;
d1681e
+}
d1681e
+
d1681e
 int
d1681e
-send_attach_req (xlator_t *this, struct rpc_clnt *rpc, char *path, int op)
d1681e
+send_attach_req (xlator_t *this, struct rpc_clnt *rpc, char *path,
d1681e
+                 glusterd_brickinfo_t *brickinfo, int op)
d1681e
 {
d1681e
         int                             ret      = -1;
d1681e
         struct iobuf                    *iobuf    = NULL;
d1681e
@@ -5418,6 +5434,7 @@ send_attach_req (xlator_t *this, struct rpc_clnt *rpc, char *path, int op)
d1681e
         struct rpc_clnt_connection      *conn;
d1681e
         glusterd_conf_t                 *conf     = this->private;
d1681e
         extern struct rpc_clnt_program  gd_brick_prog;
d1681e
+        fop_cbk_fn_t cbkfn = my_callback;
d1681e
 
d1681e
         if (!rpc) {
d1681e
                 gf_log (this->name, GF_LOG_ERROR, "called with null rpc");
d1681e
@@ -5475,10 +5492,14 @@ send_attach_req (xlator_t *this, struct rpc_clnt *rpc, char *path, int op)
d1681e
 
d1681e
         iov.iov_len = ret;
d1681e
 
d1681e
+        if (op == GLUSTERD_BRICK_ATTACH) {
d1681e
+                frame->local = brickinfo;
d1681e
+                cbkfn = attach_brick_callback;
d1681e
+        }
d1681e
         /* Send the msg */
d1681e
         ++(conf->blockers);
d1681e
         ret = rpc_clnt_submit (rpc, &gd_brick_prog, op,
d1681e
-                               my_callback, &iov, 1, NULL, 0, iobref,
d1681e
+                               cbkfn, &iov, 1, NULL, 0, iobref,
d1681e
                                frame, NULL, 0, NULL, 0, NULL);
d1681e
         return ret;
d1681e
 
d1681e
@@ -5538,7 +5559,7 @@ attach_brick (xlator_t *this,
d1681e
         for (tries = 15; tries > 0; --tries) {
d1681e
                 rpc = rpc_clnt_ref (other_brick->rpc);
d1681e
                 if (rpc) {
d1681e
-                        ret = send_attach_req (this, rpc, path,
d1681e
+                        ret = send_attach_req (this, rpc, path, brickinfo,
d1681e
                                                GLUSTERD_BRICK_ATTACH);
d1681e
                         rpc_clnt_unref (rpc);
d1681e
                         if (!ret) {
d1681e
@@ -5558,7 +5579,6 @@ attach_brick (xlator_t *this,
d1681e
                                 brickinfo->status = GF_BRICK_STARTED;
d1681e
                                 brickinfo->rpc =
d1681e
                                         rpc_clnt_ref (other_brick->rpc);
d1681e
-                                brickinfo->port_registered = _gf_true;
d1681e
                                 ret = glusterd_brick_process_add_brick (brickinfo,
d1681e
                                                                         volinfo);
d1681e
                                 if (ret) {
d1681e
diff --git a/xlators/mgmt/glusterd/src/glusterd-utils.h b/xlators/mgmt/glusterd/src/glusterd-utils.h
d1681e
index e69a779..4c9561e 100644
d1681e
--- a/xlators/mgmt/glusterd/src/glusterd-utils.h
d1681e
+++ b/xlators/mgmt/glusterd/src/glusterd-utils.h
d1681e
@@ -199,7 +199,8 @@ glusterd_volume_stop_glusterfs (glusterd_volinfo_t *volinfo,
d1681e
                                 gf_boolean_t del_brick);
d1681e
 
d1681e
 int
d1681e
-send_attach_req (xlator_t *this, struct rpc_clnt *rpc, char *path, int op);
d1681e
+send_attach_req (xlator_t *this, struct rpc_clnt *rpc, char *path,
d1681e
+                 glusterd_brickinfo_t *brick, int op);
d1681e
 
d1681e
 glusterd_volinfo_t *
d1681e
 glusterd_volinfo_ref (glusterd_volinfo_t *volinfo);
d1681e
-- 
d1681e
1.8.3.1
d1681e