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