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