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