74096c
From 71fc5b7949e00c4448f5ec1291e756b201a70082 Mon Sep 17 00:00:00 2001
74096c
From: Ravishankar N <ravishankar@redhat.com>
74096c
Date: Thu, 29 Apr 2021 18:34:57 +0530
74096c
Subject: [PATCH 543/543] glusterd: handle custom xlator failure cases
74096c
74096c
Problem-1:
74096c
custom xlator insertion was failing for those xlators in the brick graph
74096c
whose dbg_key was NULL in the server_graph_table. Looking at the git log,
74096c
the dbg_key was added in commit d1397dbd7d6cdbd2d81d5d36d608b6175d449db4
74096c
for inserting debug xlators.
74096c
74096c
Fix: I think it is fine to define it for all brick xlators below server.
74096c
74096c
Problem-2:
74096c
In the commit-op phase, glusterd_op_set_volume() updates the volinfo
74096c
dict with the key-value pairs and then proceeds to create the volfiles.
74096c
If any of the steps fail, the volinfo dict retains those key-values,
74096c
until glusterd is restarted or `gluster vol reset $VOLNAME` is issued.
74096c
74096c
Fix:
74096c
Make a copy of the volinfo dict and if there are any failures in
74096c
proceeding with the set volume logic, restore the dict to its original
74096c
state.
74096c
74096c
Backport of:
74096c
> Upstream-patch-link: https://github.com/gluster/glusterfs/pull/2371
74096c
> Change-Id: I9010dab33d0139b8e6d603308e331b6d220a4849
74096c
> Updates: #2370
74096c
> Signed-off-by: Ravishankar N <ravishankar@redhat.com>
74096c
74096c
Change-Id: I9010dab33d0139b8e6d603308e331b6d220a4849
74096c
BUG: 1953901
74096c
Signed-off-by: Ravishankar N <ravishankar@redhat.com>
74096c
Reviewed-on: https://code.engineering.redhat.com/gerrit/239889
74096c
Reviewed-by: Sunil Kumar Heggodu Gopala Acharya <sheggodu@redhat.com>
74096c
---
74096c
 tests/basic/user-xlator.t                   | 16 ++++++++++++++--
74096c
 xlators/mgmt/glusterd/src/glusterd-op-sm.c  | 16 ++++++++++++++++
74096c
 xlators/mgmt/glusterd/src/glusterd-volgen.c | 14 +++++++-------
74096c
 3 files changed, 37 insertions(+), 9 deletions(-)
74096c
74096c
diff --git a/tests/basic/user-xlator.t b/tests/basic/user-xlator.t
74096c
index a711f9f..ed2d831 100755
74096c
--- a/tests/basic/user-xlator.t
74096c
+++ b/tests/basic/user-xlator.t
74096c
@@ -35,8 +35,18 @@ EXPECT_WITHIN $PROCESS_UP_TIMEOUT "1" brick_up_status $V0 $H0 $B0/${V0}4
74096c
 EXPECT_WITHIN $PROCESS_UP_TIMEOUT "1" brick_up_status $V0 $H0 $B0/${V0}5
74096c
 EXPECT_WITHIN $PROCESS_UP_TIMEOUT "1" brick_up_status $V0 $H0 $B0/${V0}6
74096c
 
74096c
-TEST $CLI volume set $V0 user.xlator.hoge trash
74096c
-TEST grep -q 'user/hoge' ${SERVER_VOLFILE}
74096c
+# Test that the insertion at all positions between server and posix is successful.
74096c
+# It is not guaranteed that the brick process will start/work in all positions though.
74096c
+TESTS_EXPECTED_IN_LOOP=34
74096c
+declare -a brick_side_xlators=("decompounder" "io-stats" "quota" "index" "barrier"
74096c
+                               "marker" "selinux" "io-threads" "upcall" "leases"
74096c
+                               "read-only" "worm" "locks"  "access-control"
74096c
+                               "bitrot-stub" "changelog" "trash")
74096c
+for xlator in "${brick_side_xlators[@]}"
74096c
+  do
74096c
+    TEST_IN_LOOP $CLI volume set $V0 user.xlator.hoge $xlator
74096c
+    TEST_IN_LOOP grep -q 'user/hoge' ${SERVER_VOLFILE}
74096c
+  done
74096c
 
74096c
 TEST $CLI volume stop $V0
74096c
 TEST $CLI volume start $V0
74096c
@@ -49,6 +59,8 @@ EXPECT_WITHIN $PROCESS_UP_TIMEOUT "1" brick_up_status $V0 $H0 $B0/${V0}6
74096c
 
74096c
 TEST ! $CLI volume set $V0 user.xlator.hoge unknown
74096c
 TEST grep -q 'user/hoge' ${SERVER_VOLFILE} # When the CLI fails, the volfile is not modified.
74096c
+# User xlator insert failures must not prevent setting other volume options.
74096c
+TEST $CLI volume set $V0 storage.reserve 10%
74096c
 
74096c
 TEST $CLI volume stop $V0
74096c
 TEST $CLI volume start $V0
74096c
diff --git a/xlators/mgmt/glusterd/src/glusterd-op-sm.c b/xlators/mgmt/glusterd/src/glusterd-op-sm.c
74096c
index 1e84f5f..893af29 100644
74096c
--- a/xlators/mgmt/glusterd/src/glusterd-op-sm.c
74096c
+++ b/xlators/mgmt/glusterd/src/glusterd-op-sm.c
74096c
@@ -2911,6 +2911,7 @@ glusterd_op_set_volume(dict_t *dict, char **errstr)
74096c
     uint32_t new_op_version = 0;
74096c
     gf_boolean_t quorum_action = _gf_false;
74096c
     glusterd_svc_t *svc = NULL;
74096c
+    dict_t *volinfo_dict_orig = NULL;
74096c
 
74096c
     this = THIS;
74096c
     GF_ASSERT(this);
74096c
@@ -2918,6 +2919,10 @@ glusterd_op_set_volume(dict_t *dict, char **errstr)
74096c
     priv = this->private;
74096c
     GF_ASSERT(priv);
74096c
 
74096c
+    volinfo_dict_orig = dict_new();
74096c
+    if (!volinfo_dict_orig)
74096c
+        goto out;
74096c
+
74096c
     ret = dict_get_int32n(dict, "count", SLEN("count"), &dict_count);
74096c
     if (ret) {
74096c
         gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED,
74096c
@@ -2949,6 +2954,11 @@ glusterd_op_set_volume(dict_t *dict, char **errstr)
74096c
         goto out;
74096c
     }
74096c
 
74096c
+    if (dict_copy(volinfo->dict, volinfo_dict_orig) == NULL) {
74096c
+        ret = -ENOMEM;
74096c
+        goto out;
74096c
+    }
74096c
+
74096c
     /* TODO: Remove this once v3.3 compatibility is not required */
74096c
     check_op_version = dict_get_str_boolean(dict, "check-op-version",
74096c
                                             _gf_false);
74096c
@@ -3171,6 +3181,12 @@ out:
74096c
     gf_msg_debug(this->name, 0, "returning %d", ret);
74096c
     if (quorum_action)
74096c
         glusterd_do_quorum_action();
74096c
+    if (ret < 0 && count > 1) {
74096c
+        if (dict_reset(volinfo->dict) == 0)
74096c
+            dict_copy(volinfo_dict_orig, volinfo->dict);
74096c
+    }
74096c
+    if (volinfo_dict_orig)
74096c
+        dict_unref(volinfo_dict_orig);
74096c
     return ret;
74096c
 }
74096c
 
74096c
diff --git a/xlators/mgmt/glusterd/src/glusterd-volgen.c b/xlators/mgmt/glusterd/src/glusterd-volgen.c
74096c
index 71aed08..aa85bdb 100644
74096c
--- a/xlators/mgmt/glusterd/src/glusterd-volgen.c
74096c
+++ b/xlators/mgmt/glusterd/src/glusterd-volgen.c
74096c
@@ -2706,24 +2706,24 @@ out:
74096c
 static volgen_brick_xlator_t server_graph_table[] = {
74096c
     {brick_graph_add_server, NULL},
74096c
     {brick_graph_add_decompounder, "decompounder"},
74096c
-    {brick_graph_add_io_stats, "NULL"},
74096c
+    {brick_graph_add_io_stats, "io-stats"},
74096c
     {brick_graph_add_sdfs, "sdfs"},
74096c
     {brick_graph_add_namespace, "namespace"},
74096c
-    {brick_graph_add_cdc, NULL},
74096c
+    {brick_graph_add_cdc, "cdc" },
74096c
     {brick_graph_add_quota, "quota"},
74096c
     {brick_graph_add_index, "index"},
74096c
-    {brick_graph_add_barrier, NULL},
74096c
+    {brick_graph_add_barrier, "barrier" },
74096c
     {brick_graph_add_marker, "marker"},
74096c
     {brick_graph_add_selinux, "selinux"},
74096c
     {brick_graph_add_fdl, "fdl"},
74096c
     {brick_graph_add_iot, "io-threads"},
74096c
     {brick_graph_add_upcall, "upcall"},
74096c
     {brick_graph_add_leases, "leases"},
74096c
-    {brick_graph_add_pump, NULL},
74096c
-    {brick_graph_add_ro, NULL},
74096c
-    {brick_graph_add_worm, NULL},
74096c
+    {brick_graph_add_pump, "pump" },
74096c
+    {brick_graph_add_ro, "read-only" },
74096c
+    {brick_graph_add_worm, "worm" },
74096c
     {brick_graph_add_locks, "locks"},
74096c
-    {brick_graph_add_acl, "acl"},
74096c
+    {brick_graph_add_acl, "access-control"},
74096c
     {brick_graph_add_bitrot_stub, "bitrot-stub"},
74096c
     {brick_graph_add_changelog, "changelog"},
74096c
 #if USE_GFDB /* changetimerecorder depends on gfdb */
74096c
-- 
74096c
1.8.3.1
74096c