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