d2787b
From 96c4c3c47c914aced8864e7d178a4d57f7fced05 Mon Sep 17 00:00:00 2001
d2787b
From: Tamar Shacked <tshacked@redhat.com>
d2787b
Date: Sun, 6 Jun 2021 14:26:18 +0300
d2787b
Subject: [PATCH 579/584] cli: changing rebal task ID to "None" in case status
d2787b
 is being reset
d2787b
d2787b
Rebalance status is being reset during replace/reset-brick operations.
d2787b
This cause 'volume status' to shows rebalance as "not started".
d2787b
d2787b
Fix:
d2787b
change rebalance-status to "reset due to (replace|reset)-brick"
d2787b
d2787b
Backport of:
d2787b
> Upstream-patch-link: https://github.com/gluster/glusterfs/pull/1869
d2787b
> Change-Id: Ia73a8bea3dcd8e51acf4faa6434c3cb0d09856d0
d2787b
> Signed-off-by: Tamar Shacked <tshacked@redhat.com>
d2787b
> Fixes: #1717
d2787b
d2787b
BUG: 1889966
d2787b
d2787b
Signed-off-by: Tamar Shacked <tshacked@redhat.com>
d2787b
Change-Id: Ia73a8bea3dcd8e51acf4faa6434c3cb0d09856d0
d2787b
Reviewed-on: https://code.engineering.redhat.com/gerrit/c/rhs-glusterfs/+/245402
d2787b
Tested-by: RHGS Build Bot <nigelb@redhat.com>
d2787b
Reviewed-by: Sunil Kumar Heggodu Gopala Acharya <sheggodu@redhat.com>
d2787b
---
d2787b
 cli/src/cli-rpc-ops.c                              | 15 ++++++-
d2787b
 rpc/xdr/src/cli1-xdr.x                             |  2 +
d2787b
 tests/bugs/glusterd/reset-rebalance-state.t        | 46 ++++++++++++++++++++++
d2787b
 xlators/mgmt/glusterd/src/glusterd-replace-brick.c |  4 +-
d2787b
 xlators/mgmt/glusterd/src/glusterd-reset-brick.c   |  3 +-
d2787b
 5 files changed, 65 insertions(+), 5 deletions(-)
d2787b
 create mode 100644 tests/bugs/glusterd/reset-rebalance-state.t
d2787b
d2787b
diff --git a/cli/src/cli-rpc-ops.c b/cli/src/cli-rpc-ops.c
d2787b
index 51b5447..4167c68 100644
d2787b
--- a/cli/src/cli-rpc-ops.c
d2787b
+++ b/cli/src/cli-rpc-ops.c
d2787b
@@ -72,6 +72,8 @@ char *cli_vol_task_status_str[] = {"not started",
d2787b
                                    "fix-layout stopped",
d2787b
                                    "fix-layout completed",
d2787b
                                    "fix-layout failed",
d2787b
+                                   "reset due to replace-brick",
d2787b
+                                   "reset due to reset-brick",
d2787b
                                    "unknown"};
d2787b
 
d2787b
 int32_t
d2787b
@@ -8357,12 +8359,21 @@ cli_print_volume_status_tasks(dict_t *dict)
d2787b
         ret = dict_get_str(dict, key, &task_id_str);
d2787b
         if (ret)
d2787b
             return;
d2787b
-        cli_out("%-20s : %-20s", "ID", task_id_str);
d2787b
 
d2787b
         snprintf(key, sizeof(key), "task%d.status", i);
d2787b
         ret = dict_get_int32(dict, key, &status);
d2787b
-        if (ret)
d2787b
+        if (ret) {
d2787b
+            cli_out("%-20s : %-20s", "ID", task_id_str);
d2787b
             return;
d2787b
+        }
d2787b
+
d2787b
+        if (!strcmp(op, "Rebalance") &&
d2787b
+            (status == GF_DEFRAG_STATUS_RESET_DUE_REPLACE_BRC ||
d2787b
+             status == GF_DEFRAG_STATUS_RESET_DUE_RESET_BRC)) {
d2787b
+            task_id_str = "None";
d2787b
+        }
d2787b
+
d2787b
+        cli_out("%-20s : %-20s", "ID", task_id_str);
d2787b
 
d2787b
         snprintf(task, sizeof(task), "task%d", i);
d2787b
 
d2787b
diff --git a/rpc/xdr/src/cli1-xdr.x b/rpc/xdr/src/cli1-xdr.x
d2787b
index 777cb00..17d96f1 100644
d2787b
--- a/rpc/xdr/src/cli1-xdr.x
d2787b
+++ b/rpc/xdr/src/cli1-xdr.x
d2787b
@@ -45,6 +45,8 @@
d2787b
         GF_DEFRAG_STATUS_LAYOUT_FIX_STOPPED,
d2787b
         GF_DEFRAG_STATUS_LAYOUT_FIX_COMPLETE,
d2787b
         GF_DEFRAG_STATUS_LAYOUT_FIX_FAILED,
d2787b
+        GF_DEFRAG_STATUS_RESET_DUE_REPLACE_BRC,
d2787b
+        GF_DEFRAG_STATUS_RESET_DUE_RESET_BRC,
d2787b
         GF_DEFRAG_STATUS_MAX
d2787b
 };
d2787b
 
d2787b
diff --git a/tests/bugs/glusterd/reset-rebalance-state.t b/tests/bugs/glusterd/reset-rebalance-state.t
d2787b
new file mode 100644
d2787b
index 0000000..829d2b1
d2787b
--- /dev/null
d2787b
+++ b/tests/bugs/glusterd/reset-rebalance-state.t
d2787b
@@ -0,0 +1,46 @@
d2787b
+#!/bin/bash
d2787b
+
d2787b
+. $(dirname $0)/../../include.rc
d2787b
+. $(dirname $0)/../../cluster.rc
d2787b
+. $(dirname $0)/../../volume.rc
d2787b
+
d2787b
+
d2787b
+get_rebalance_status() {
d2787b
+    $CLI volume status $V0 | egrep ^"Status   " | awk '{print $3}'
d2787b
+}
d2787b
+
d2787b
+run_rebal_check_status() {
d2787b
+    TEST $CLI volume rebalance $V0 start
d2787b
+    EXPECT_WITHIN $REBALANCE_TIMEOUT "completed" rebalance_status_field $V0
d2787b
+    REBAL_STATE=$(get_rebalance_status)
d2787b
+    TEST [ $REBAL_STATE == "completed" ]
d2787b
+}
d2787b
+
d2787b
+replace_brick_check_status() {
d2787b
+    TEST $CLI volume replace-brick $V0 $H0:$B0/${V0}1 $H0:$B0/${V0}1_replace commit force
d2787b
+    REBAL_STATE=$(get_rebalance_status)
d2787b
+    TEST [ $REBAL_STATE == "reset" ]
d2787b
+}
d2787b
+
d2787b
+reset_brick_check_status() {
d2787b
+    TEST $CLI volume reset-brick $V0 $H0:$B0/${V0}2 start
d2787b
+    TEST $CLI volume reset-brick $V0 $H0:$B0/${V0}2 $H0:$B0/${V0}2 commit force
d2787b
+    REBAL_STATE=$(get_rebalance_status)
d2787b
+    TEST [ $REBAL_STATE == "reset" ]
d2787b
+}
d2787b
+
d2787b
+cleanup;
d2787b
+
d2787b
+TEST glusterd;
d2787b
+TEST pidof glusterd;
d2787b
+
d2787b
+TEST $CLI volume info;
d2787b
+TEST $CLI volume create $V0 replica 3 $H0:$B0/${V0}{1..6} force;
d2787b
+TEST $CLI volume start $V0;
d2787b
+
d2787b
+run_rebal_check_status;
d2787b
+replace_brick_check_status;
d2787b
+reset_brick_check_status;
d2787b
+
d2787b
+cleanup;
d2787b
+
d2787b
diff --git a/xlators/mgmt/glusterd/src/glusterd-replace-brick.c b/xlators/mgmt/glusterd/src/glusterd-replace-brick.c
d2787b
index 0615081..80b80e4 100644
d2787b
--- a/xlators/mgmt/glusterd/src/glusterd-replace-brick.c
d2787b
+++ b/xlators/mgmt/glusterd/src/glusterd-replace-brick.c
d2787b
@@ -548,8 +548,8 @@ glusterd_op_replace_brick(dict_t *dict, dict_t *rsp_dict)
d2787b
         (void)glusterd_svcs_manager(volinfo);
d2787b
         goto out;
d2787b
     }
d2787b
-
d2787b
-    volinfo->rebal.defrag_status = 0;
d2787b
+    if (volinfo->rebal.defrag_status != GF_DEFRAG_STATUS_NOT_STARTED)
d2787b
+        volinfo->rebal.defrag_status = GF_DEFRAG_STATUS_RESET_DUE_REPLACE_BRC;
d2787b
 
d2787b
     ret = glusterd_svcs_manager(volinfo);
d2787b
     if (ret) {
d2787b
diff --git a/xlators/mgmt/glusterd/src/glusterd-reset-brick.c b/xlators/mgmt/glusterd/src/glusterd-reset-brick.c
d2787b
index cf04ce8..19d7549 100644
d2787b
--- a/xlators/mgmt/glusterd/src/glusterd-reset-brick.c
d2787b
+++ b/xlators/mgmt/glusterd/src/glusterd-reset-brick.c
d2787b
@@ -342,7 +342,8 @@ glusterd_op_reset_brick(dict_t *dict, dict_t *rsp_dict)
d2787b
             goto out;
d2787b
         }
d2787b
 
d2787b
-        volinfo->rebal.defrag_status = 0;
d2787b
+        if (volinfo->rebal.defrag_status != GF_DEFRAG_STATUS_NOT_STARTED)
d2787b
+            volinfo->rebal.defrag_status = GF_DEFRAG_STATUS_RESET_DUE_RESET_BRC;
d2787b
 
d2787b
         ret = glusterd_svcs_manager(volinfo);
d2787b
         if (ret) {
d2787b
-- 
d2787b
1.8.3.1
d2787b