14f8ab
From 2d172144810956225eac3599c943416c4a7e25d0 Mon Sep 17 00:00:00 2001
14f8ab
From: Ravishankar N <ravishankar@redhat.com>
14f8ab
Date: Tue, 8 Dec 2020 20:30:23 +0530
14f8ab
Subject: [PATCH 489/511] glusterd: fix bug in enabling granular-entry-heal
14f8ab
14f8ab
Upstream patch details:
14f8ab
/------------------------------------------------------------------------------/
14f8ab
commit f5e1eb87d4af44be3b317b7f99ab88f89c2f0b1a meant to enable  the
14f8ab
volume option only for replica volumes but inadvertently enabled
14f8ab
it for all volume types. Fixing it now.
14f8ab
14f8ab
Also found a bug in glusterd where disabling the option on plain
14f8ab
distribute was succeeding even though setting it in the fist place
14f8ab
fails. Fixed that too.
14f8ab
14f8ab
>Fixes: #1483
14f8ab
>Change-Id: Icb6c169a8eec44cc4fb4dd636405d3b3485e91b4
14f8ab
>Reported-by: Sheetal Pamecha <spamecha@redhat.com>
14f8ab
>Signed-off-by: Ravishankar N <ravishankar@redhat.com>
14f8ab
Upstream Patch: https://github.com/gluster/glusterfs/pull/1752
14f8ab
/------------------------------------------------------------------------------/
14f8ab
14f8ab
BUG: 1890506
14f8ab
Change-Id: Id63655dac08d2cfda4899d7ee0efe96e72cd6986
14f8ab
Signed-off-by: Ravishankar N <ravishankar@redhat.com>
14f8ab
Reviewed-on: https://code.engineering.redhat.com/gerrit/220556
14f8ab
Tested-by: Sunil Kumar Heggodu Gopala Acharya <sheggodu@redhat.com>
14f8ab
Tested-by: RHGS Build Bot <nigelb@redhat.com>
14f8ab
Reviewed-by: Sunil Kumar Heggodu Gopala Acharya <sheggodu@redhat.com>
14f8ab
---
14f8ab
 tests/basic/afr/granular-esh/cli.t              | 30 ++++++++++++++++++++-----
14f8ab
 xlators/mgmt/glusterd/src/glusterd-utils.c      |  3 ++-
14f8ab
 xlators/mgmt/glusterd/src/glusterd-volume-ops.c | 12 +++++-----
14f8ab
 3 files changed, 34 insertions(+), 11 deletions(-)
14f8ab
14f8ab
diff --git a/tests/basic/afr/granular-esh/cli.t b/tests/basic/afr/granular-esh/cli.t
14f8ab
index 995d93e..5ab2e39 100644
14f8ab
--- a/tests/basic/afr/granular-esh/cli.t
14f8ab
+++ b/tests/basic/afr/granular-esh/cli.t
14f8ab
@@ -11,25 +11,38 @@ TESTS_EXPECTED_IN_LOOP=4
14f8ab
 TEST glusterd
14f8ab
 TEST pidof glusterd
14f8ab
 
14f8ab
-TEST   $CLI volume create $V0 replica 2 $H0:$B0/${V0}{0,1}
14f8ab
-# Test that enabling the option should work on a newly created volume
14f8ab
-TEST   $CLI volume set $V0 cluster.granular-entry-heal on
14f8ab
-TEST   $CLI volume set $V0 cluster.granular-entry-heal off
14f8ab
-
14f8ab
 #########################
14f8ab
 ##### DISPERSE TEST #####
14f8ab
 #########################
14f8ab
 # Execute the same command on a disperse volume and make sure it fails.
14f8ab
 TEST $CLI volume create $V1 disperse 3 redundancy 1 $H0:$B0/${V1}{0,1,2}
14f8ab
+EXPECT "no" volume_get_field $V1 cluster.granular-entry-heal
14f8ab
+TEST $CLI volume start $V1
14f8ab
+TEST ! $CLI volume heal $V1 granular-entry-heal enable
14f8ab
+TEST ! $CLI volume heal $V1 granular-entry-heal disable
14f8ab
+
14f8ab
+TEST $CLI volume stop $V1
14f8ab
+TEST $CLI volume delete $V1
14f8ab
+
14f8ab
+#########################
14f8ab
+##### PLAIN DISTRIBUTE TEST #####
14f8ab
+#########################
14f8ab
+# Execute the same command on a distribute volume and make sure it fails.
14f8ab
+TEST $CLI volume create $V1 $H0:$B0/${V1}{0,1,2}
14f8ab
+EXPECT "no" volume_get_field $V1 cluster.granular-entry-heal
14f8ab
 TEST $CLI volume start $V1
14f8ab
 TEST ! $CLI volume heal $V1 granular-entry-heal enable
14f8ab
 TEST ! $CLI volume heal $V1 granular-entry-heal disable
14f8ab
+TEST $CLI volume stop $V1
14f8ab
+TEST $CLI volume delete $V1
14f8ab
 
14f8ab
 #######################
14f8ab
 ###### TIER TEST ######
14f8ab
 #######################
14f8ab
 # Execute the same command on a disperse + replicate tiered volume and make
14f8ab
 # sure the option is set on the replicate leg of the volume
14f8ab
+TEST $CLI volume create $V1 disperse 3 redundancy 1 $H0:$B0/${V1}{0,1,2}
14f8ab
+TEST $CLI volume start $V1
14f8ab
 TEST $CLI volume tier $V1 attach replica 2 $H0:$B0/${V1}{3,4}
14f8ab
 TEST $CLI volume heal $V1 granular-entry-heal enable
14f8ab
 EXPECT "enable" volume_get_field $V1 cluster.granular-entry-heal
14f8ab
@@ -52,10 +65,17 @@ TEST kill_brick $V1 $H0 $B0/${V1}3
14f8ab
 # failed.
14f8ab
 TEST ! $CLI volume heal $V1 granular-entry-heal enable
14f8ab
 EXPECT "disable" volume_get_field $V1 cluster.granular-entry-heal
14f8ab
+TEST $CLI volume stop $V1
14f8ab
+TEST $CLI volume delete $V1
14f8ab
 
14f8ab
 ######################
14f8ab
 ### REPLICATE TEST ###
14f8ab
 ######################
14f8ab
+TEST   $CLI volume create $V0 replica 3 $H0:$B0/${V0}{0,1,2}
14f8ab
+EXPECT "on" volume_get_field $V0 cluster.granular-entry-heal
14f8ab
+# Test that enabling the option should work on a newly created volume
14f8ab
+TEST   $CLI volume set $V0 cluster.granular-entry-heal on
14f8ab
+TEST   $CLI volume set $V0 cluster.granular-entry-heal off
14f8ab
 TEST   $CLI volume start $V0
14f8ab
 TEST   $CLI volume set $V0 cluster.data-self-heal off
14f8ab
 TEST   $CLI volume set $V0 cluster.metadata-self-heal off
14f8ab
diff --git a/xlators/mgmt/glusterd/src/glusterd-utils.c b/xlators/mgmt/glusterd/src/glusterd-utils.c
14f8ab
index bd17a82..ad3750e 100644
14f8ab
--- a/xlators/mgmt/glusterd/src/glusterd-utils.c
14f8ab
+++ b/xlators/mgmt/glusterd/src/glusterd-utils.c
14f8ab
@@ -13183,7 +13183,8 @@ glusterd_enable_default_options(glusterd_volinfo_t *volinfo, char *option)
14f8ab
     }
14f8ab
 
14f8ab
     if ((conf->op_version >= GD_OP_VERSION_7_1) &&
14f8ab
-        (volinfo->status == GLUSTERD_STATUS_NONE)) {
14f8ab
+        (volinfo->status == GLUSTERD_STATUS_NONE) &&
14f8ab
+        (volinfo->type == GF_CLUSTER_TYPE_REPLICATE)) {
14f8ab
         ret = dict_set_dynstr_with_alloc(volinfo->dict,
14f8ab
                                          "cluster.granular-entry-heal", "on");
14f8ab
         if (ret) {
14f8ab
diff --git a/xlators/mgmt/glusterd/src/glusterd-volume-ops.c b/xlators/mgmt/glusterd/src/glusterd-volume-ops.c
14f8ab
index 134b04c..09e6ead 100644
14f8ab
--- a/xlators/mgmt/glusterd/src/glusterd-volume-ops.c
14f8ab
+++ b/xlators/mgmt/glusterd/src/glusterd-volume-ops.c
14f8ab
@@ -621,11 +621,13 @@ glusterd_handle_heal_options_enable_disable(rpcsvc_request_t *req, dict_t *dict,
14f8ab
         goto out;
14f8ab
     }
14f8ab
 
14f8ab
-    if (((heal_op == GF_SHD_OP_GRANULAR_ENTRY_HEAL_ENABLE) ||
14f8ab
-         (heal_op == GF_SHD_OP_GRANULAR_ENTRY_HEAL_DISABLE)) &&
14f8ab
-        (volinfo->type == GF_CLUSTER_TYPE_DISPERSE)) {
14f8ab
-        ret = -1;
14f8ab
-        goto out;
14f8ab
+    if ((heal_op == GF_SHD_OP_GRANULAR_ENTRY_HEAL_ENABLE) ||
14f8ab
+        (heal_op == GF_SHD_OP_GRANULAR_ENTRY_HEAL_DISABLE)) {
14f8ab
+        if ((volinfo->type != GF_CLUSTER_TYPE_REPLICATE) &&
14f8ab
+            (volinfo->type != GF_CLUSTER_TYPE_TIER)) {
14f8ab
+            ret = -1;
14f8ab
+            goto out;
14f8ab
+        }
14f8ab
     }
14f8ab
 
14f8ab
     if ((heal_op == GF_SHD_OP_HEAL_ENABLE) ||
14f8ab
-- 
14f8ab
1.8.3.1
14f8ab