50dc83
From 4fc0a77db5b9760fa5c00d3803c6d11a28a00b74 Mon Sep 17 00:00:00 2001
50dc83
From: Mohit Agrawal <moagrawal@redhat.com>
50dc83
Date: Wed, 3 Jul 2019 15:22:38 +0530
50dc83
Subject: [PATCH 229/255] glusterd: Show the correct brick status in get-state
50dc83
50dc83
Problem: get-state does not show correct brick status if brick
50dc83
         status is not Started, it always shows started if any value
50dc83
         is set brickinfo->status
50dc83
50dc83
Solution: Check the value of brickinfo->status to show correct status
50dc83
          in get-state
50dc83
50dc83
> Change-Id: I12a79619024c2cf59f338220d144f2f034059b3b
50dc83
> fixes: bz#1726906
50dc83
> (Cherry pick from commit af989db23d1db00e087f2b9d3dfc43b13ef17153)
50dc83
> (Reviewed on upstream link https://review.gluster.org/#/c/glusterfs/+/22983/)
50dc83
50dc83
BUG: 1726991
50dc83
Change-Id: I12a79619024c2cf59f338220d144f2f034059b3b
50dc83
Signed-off-by: Mohit Agrawal <moagrawal@redhat.com>
50dc83
Reviewed-on: https://code.engineering.redhat.com/gerrit/175355
50dc83
Tested-by: Mohit Agrawal <moagrawa@redhat.com>
50dc83
Tested-by: RHGS Build Bot <nigelb@redhat.com>
50dc83
Reviewed-by: Atin Mukherjee <amukherj@redhat.com>
50dc83
---
50dc83
 xlators/mgmt/glusterd/src/glusterd-handler.c |  7 +++++--
50dc83
 xlators/mgmt/glusterd/src/glusterd-utils.c   | 28 ++++++++++++++++++++++++++++
50dc83
 xlators/mgmt/glusterd/src/glusterd-utils.h   |  4 ++++
50dc83
 3 files changed, 37 insertions(+), 2 deletions(-)
50dc83
50dc83
diff --git a/xlators/mgmt/glusterd/src/glusterd-handler.c b/xlators/mgmt/glusterd/src/glusterd-handler.c
50dc83
index cc1f1df..94e1be5 100644
50dc83
--- a/xlators/mgmt/glusterd/src/glusterd-handler.c
50dc83
+++ b/xlators/mgmt/glusterd/src/glusterd-handler.c
50dc83
@@ -5589,7 +5589,9 @@ glusterd_get_state(rpcsvc_request_t *req, dict_t *dict)
50dc83
     char vol_status_str[STATUS_STRLEN] = {
50dc83
         0,
50dc83
     };
50dc83
-
50dc83
+    char brick_status_str[STATUS_STRLEN] = {
50dc83
+        0,
50dc83
+    };
50dc83
     this = THIS;
50dc83
     GF_VALIDATE_OR_GOTO(THIS->name, this, out);
50dc83
 
50dc83
@@ -5852,8 +5854,9 @@ glusterd_get_state(rpcsvc_request_t *req, dict_t *dict)
50dc83
                     brickinfo->rdma_port);
50dc83
             fprintf(fp, "Volume%d.Brick%d.port_registered: %d\n", count_bkp,
50dc83
                     count, brickinfo->port_registered);
50dc83
+            glusterd_brick_get_status_str(brickinfo, brick_status_str);
50dc83
             fprintf(fp, "Volume%d.Brick%d.status: %s\n", count_bkp, count,
50dc83
-                    brickinfo->status ? "Started" : "Stopped");
50dc83
+                    brick_status_str);
50dc83
 
50dc83
             /*FIXME: This is a hacky way of figuring out whether a
50dc83
              * brick belongs to the hot or cold tier */
50dc83
diff --git a/xlators/mgmt/glusterd/src/glusterd-utils.c b/xlators/mgmt/glusterd/src/glusterd-utils.c
50dc83
index 2eb5116..3bdfd49 100644
50dc83
--- a/xlators/mgmt/glusterd/src/glusterd-utils.c
50dc83
+++ b/xlators/mgmt/glusterd/src/glusterd-utils.c
50dc83
@@ -13898,6 +13898,34 @@ out:
50dc83
     return ret;
50dc83
 }
50dc83
 
50dc83
+void
50dc83
+glusterd_brick_get_status_str(glusterd_brickinfo_t *brickinfo, char *status_str)
50dc83
+{
50dc83
+    GF_VALIDATE_OR_GOTO(THIS->name, brickinfo, out);
50dc83
+    GF_VALIDATE_OR_GOTO(THIS->name, status_str, out);
50dc83
+
50dc83
+    switch (brickinfo->status) {
50dc83
+        case GF_BRICK_STOPPED:
50dc83
+            sprintf(status_str, "%s", "Stopped");
50dc83
+            break;
50dc83
+        case GF_BRICK_STARTED:
50dc83
+            sprintf(status_str, "%s", "Started");
50dc83
+            break;
50dc83
+        case GF_BRICK_STARTING:
50dc83
+            sprintf(status_str, "%s", "Starting");
50dc83
+            break;
50dc83
+        case GF_BRICK_STOPPING:
50dc83
+            sprintf(status_str, "%s", "Stopping");
50dc83
+            break;
50dc83
+        default:
50dc83
+            sprintf(status_str, "%s", "None");
50dc83
+            break;
50dc83
+    }
50dc83
+
50dc83
+out:
50dc83
+    return;
50dc83
+}
50dc83
+
50dc83
 int
50dc83
 glusterd_volume_get_transport_type_str(glusterd_volinfo_t *volinfo,
50dc83
                                        char *transport_type_str)
50dc83
diff --git a/xlators/mgmt/glusterd/src/glusterd-utils.h b/xlators/mgmt/glusterd/src/glusterd-utils.h
50dc83
index 6ad8062..5c6a453 100644
50dc83
--- a/xlators/mgmt/glusterd/src/glusterd-utils.h
50dc83
+++ b/xlators/mgmt/glusterd/src/glusterd-utils.h
50dc83
@@ -781,6 +781,10 @@ glusterd_volume_get_type_str(glusterd_volinfo_t *volinfo, char **vol_type_str);
50dc83
 int
50dc83
 glusterd_volume_get_status_str(glusterd_volinfo_t *volinfo, char *status_str);
50dc83
 
50dc83
+void
50dc83
+glusterd_brick_get_status_str(glusterd_brickinfo_t *brickinfo,
50dc83
+                              char *status_str);
50dc83
+
50dc83
 int
50dc83
 glusterd_volume_get_transport_type_str(glusterd_volinfo_t *volinfo,
50dc83
                                        char *transport_type_str);
50dc83
-- 
50dc83
1.8.3.1
50dc83