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