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