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