14f8ab
From bffdcce7119f3ed68694df918e504cc241502835 Mon Sep 17 00:00:00 2001
14f8ab
From: Anuradha Talur <atalur@commvault.com>
14f8ab
Date: Mon, 19 Nov 2018 17:57:18 -0800
14f8ab
Subject: [PATCH 151/169] mgmt/glusterd: Make changes related to cloudsync
14f8ab
 xlator
14f8ab
14f8ab
1) The placement of cloudsync xlator has been changed
14f8ab
to make it shard xlator's child. If cloudsync has to
14f8ab
work with shard in the graph, it needs to be child of shard.
14f8ab
14f8ab
backport of: https://review.gluster.org/#/c/glusterfs/+/21681/
14f8ab
14f8ab
> Change-Id: Ib55424fdcb7ce8edae9f19b8a6e3d3ba86c1f0c4
14f8ab
> fixes: bz#1642168
14f8ab
> Signed-off-by: Anuradha Talur <atalur@commvault.com>
14f8ab
14f8ab
Change-Id: I68fd43b2c559cc2d9f05e1ab19784b174233d690
14f8ab
Signed-off-by: Susant Palai <spalai@redhat.com>
14f8ab
Reviewed-on: https://code.engineering.redhat.com/gerrit/172190
14f8ab
Tested-by: RHGS Build Bot <nigelb@redhat.com>
14f8ab
Reviewed-by: Atin Mukherjee <amukherj@redhat.com>
14f8ab
---
14f8ab
 tests/basic/glusterd/check-cloudsync-ancestry.t | 48 +++++++++++++++++++++++++
14f8ab
 tests/volume.rc                                 | 21 +++++++++++
14f8ab
 xlators/mgmt/glusterd/src/glusterd-volgen.c     | 24 ++++++-------
14f8ab
 3 files changed, 81 insertions(+), 12 deletions(-)
14f8ab
 create mode 100644 tests/basic/glusterd/check-cloudsync-ancestry.t
14f8ab
14f8ab
diff --git a/tests/basic/glusterd/check-cloudsync-ancestry.t b/tests/basic/glusterd/check-cloudsync-ancestry.t
14f8ab
new file mode 100644
14f8ab
index 0000000..ff6ffee
14f8ab
--- /dev/null
14f8ab
+++ b/tests/basic/glusterd/check-cloudsync-ancestry.t
14f8ab
@@ -0,0 +1,48 @@
14f8ab
+#!/bin/bash
14f8ab
+
14f8ab
+. $(dirname $0)/../../include.rc
14f8ab
+. $(dirname $0)/../../volume.rc
14f8ab
+
14f8ab
+# When shard and cloudsync xlators enabled on a volume, shard xlator
14f8ab
+# should be an ancestor of cloudsync. This testcase is to check this condition.
14f8ab
+
14f8ab
+cleanup;
14f8ab
+TEST glusterd
14f8ab
+TEST pidof glusterd
14f8ab
+TEST $CLI volume create $V0 $H0:$B0/b1 $H0:$B0/b2 $H0:$B0/b3
14f8ab
+
14f8ab
+volfile=$(gluster system:: getwd)"/vols/$V0/trusted-$V0.tcp-fuse.vol"
14f8ab
+
14f8ab
+#Test that both shard and cloudsync are not loaded
14f8ab
+EXPECT "N" volgen_volume_exists $volfile $V0-shard features shard
14f8ab
+EXPECT "N" volgen_volume_exists $volfile $V0-cloudsync features cloudsync
14f8ab
+
14f8ab
+#Enable shard and cloudsync in that order and check if volfile is correct
14f8ab
+TEST $CLI volume set $V0 shard on
14f8ab
+TEST $CLI volume set $V0 cloudsync on
14f8ab
+
14f8ab
+#Test that both shard and cloudsync are loaded
14f8ab
+EXPECT "Y" volgen_volume_exists $volfile $V0-shard features shard
14f8ab
+EXPECT "Y" volgen_volume_exists $volfile $V0-cloudsync features cloudsync
14f8ab
+
14f8ab
+EXPECT "Y" volgen_check_ancestry $volfile features shard features cloudsync
14f8ab
+
14f8ab
+#Disable shard and cloudsync
14f8ab
+TEST $CLI volume set $V0 shard off
14f8ab
+TEST $CLI volume set $V0 cloudsync off
14f8ab
+
14f8ab
+#Test that both shard and cloudsync are not loaded
14f8ab
+EXPECT "N" volgen_volume_exists $volfile $V0-shard features shard
14f8ab
+EXPECT "N" volgen_volume_exists $volfile $V0-cloudsync features cloudsync
14f8ab
+
14f8ab
+#Enable cloudsync and shard in that order and check if volfile is correct
14f8ab
+TEST $CLI volume set $V0 cloudsync on
14f8ab
+TEST $CLI volume set $V0 shard on
14f8ab
+
14f8ab
+#Test that both shard and cloudsync are loaded
14f8ab
+EXPECT "Y" volgen_volume_exists $volfile $V0-shard features shard
14f8ab
+EXPECT "Y" volgen_volume_exists $volfile $V0-cloudsync features cloudsync
14f8ab
+
14f8ab
+EXPECT "Y" volgen_check_ancestry $volfile features shard features cloudsync
14f8ab
+
14f8ab
+cleanup;
14f8ab
diff --git a/tests/volume.rc b/tests/volume.rc
14f8ab
index b326098..a0ea3b8 100644
14f8ab
--- a/tests/volume.rc
14f8ab
+++ b/tests/volume.rc
14f8ab
@@ -891,3 +891,24 @@ function check_changelog_op {
14f8ab
 
14f8ab
         $PYTHON $(dirname $0)/../../utils/changelogparser.py ${clog_path}/CHANGELOG | grep "$op" | wc -l
14f8ab
 }
14f8ab
+
14f8ab
+function volgen_check_ancestry {
14f8ab
+        #Returns Y if ancestor_xl is an ancestor of $child_xl according to the volfile
14f8ab
+        local volfile="$1"
14f8ab
+
14f8ab
+        local child_xl_type="$2"
14f8ab
+        local child_xl="$3"
14f8ab
+
14f8ab
+        local ancestor_xl_type="$4"
14f8ab
+        local ancestor_xl="$5"
14f8ab
+
14f8ab
+        child_linenum=$(awk '/type $child_xl_type\/$child_xl/ {print FNR}' $volfile)
14f8ab
+        ancestor_linenum=$(awk '/type $ancestor_xl_type\/$ancestor_xl/ {print FNR}' $volfile)
14f8ab
+
14f8ab
+        if [ $child_linenum -lt $ancestor_linenum ];
14f8ab
+        then
14f8ab
+                echo "Y"
14f8ab
+        else
14f8ab
+                echo "N"
14f8ab
+        fi
14f8ab
+}
14f8ab
diff --git a/xlators/mgmt/glusterd/src/glusterd-volgen.c b/xlators/mgmt/glusterd/src/glusterd-volgen.c
14f8ab
index 77aa705..8b58d40 100644
14f8ab
--- a/xlators/mgmt/glusterd/src/glusterd-volgen.c
14f8ab
+++ b/xlators/mgmt/glusterd/src/glusterd-volgen.c
14f8ab
@@ -4360,6 +4360,18 @@ client_graph_builder(volgen_graph_t *graph, glusterd_volinfo_t *volinfo,
14f8ab
                                   "tcp", set_dict);
14f8ab
     }
14f8ab
 
14f8ab
+    ret = dict_get_str_boolean(set_dict, "features.cloudsync", _gf_false);
14f8ab
+    if (ret == -1)
14f8ab
+        goto out;
14f8ab
+
14f8ab
+    if (ret) {
14f8ab
+        xl = volgen_graph_add(graph, "features/cloudsync", volname);
14f8ab
+        if (!xl) {
14f8ab
+            ret = -1;
14f8ab
+            goto out;
14f8ab
+        }
14f8ab
+    }
14f8ab
+
14f8ab
     ret = dict_get_str_boolean(set_dict, "features.shard", _gf_false);
14f8ab
     if (ret == -1)
14f8ab
         goto out;
14f8ab
@@ -4567,18 +4579,6 @@ client_graph_builder(volgen_graph_t *graph, glusterd_volinfo_t *volinfo,
14f8ab
     if (ret)
14f8ab
         return -1;
14f8ab
 
14f8ab
-    ret = dict_get_str_boolean(set_dict, "features.cloudsync", _gf_false);
14f8ab
-    if (ret == -1)
14f8ab
-        goto out;
14f8ab
-
14f8ab
-    if (ret) {
14f8ab
-        xl = volgen_graph_add(graph, "features/cloudsync", volname);
14f8ab
-        if (!xl) {
14f8ab
-            ret = -1;
14f8ab
-            goto out;
14f8ab
-        }
14f8ab
-    }
14f8ab
-
14f8ab
     /* if the client is part of 'gfproxyd' server, then we need to keep the
14f8ab
        volume name as 'gfproxyd-<volname>', for better portmapper options */
14f8ab
     subvol = volname;
14f8ab
-- 
14f8ab
1.8.3.1
14f8ab