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