17b94a
From 8d24d891aade910b0bb86b27c25a8d2382e19ba0 Mon Sep 17 00:00:00 2001
17b94a
From: karthik-us <ksubrahm@redhat.com>
17b94a
Date: Tue, 15 Dec 2020 15:04:19 +0530
17b94a
Subject: [PATCH 516/517] afr: return -EIO for gfid split-brains.
17b94a
17b94a
Problem:
17b94a
entry-self-heal-anon-dir-off.t was failing occasionally because
17b94a
afr_gfid_split_brain_source() returned -1 instead of -EIO for
17b94a
split-brains, causing the code to proceed to afr_lookup_done(), which
17b94a
in turn succeeded the lookup if there was a parallel client side heal
17b94a
going on.
17b94a
17b94a
Fix:
17b94a
Return -EIO instead of -1 so that lookp fails.
17b94a
17b94a
Also, afr_selfheal_name() was using the same dict to get and set values. This
17b94a
could be problematic if the caller passed local->xdata_req, since
17b94a
setting a response in a request dict can lead to bugs.So changed it to use
17b94a
separate request and response dicts.
17b94a
17b94a
Upstream patch details:
17b94a
> Fixes: #1739
17b94a
> Credits Pranith Karampuri <pranith.karampuri@phonepe.com>
17b94a
> Signed-off-by: Ravishankar N <ravishankar@redhat.com>
17b94a
>Change-Id: I5cb4c547fb25e6bfc8bec1740f7eb64e1a5ad443
17b94a
Upstream patch: https://github.com/gluster/glusterfs/pull/1819/
17b94a
17b94a
BUG: 1640148
17b94a
Signed-off-by: karthik-us <ksubrahm@redhat.com>
17b94a
Change-Id: I5cb4c547fb25e6bfc8bec1740f7eb64e1a5ad443
17b94a
Reviewed-on: https://code.engineering.redhat.com/gerrit/221209
17b94a
Tested-by: RHGS Build Bot <nigelb@redhat.com>
17b94a
Reviewed-by: Ravishankar Narayanankutty <ravishankar@redhat.com>
17b94a
---
17b94a
 xlators/cluster/afr/src/afr-common.c           | 12 ++++++++----
17b94a
 xlators/cluster/afr/src/afr-self-heal-common.c | 27 +++++++++++++-------------
17b94a
 xlators/cluster/afr/src/afr-self-heal-entry.c  |  8 ++++----
17b94a
 xlators/cluster/afr/src/afr-self-heal-name.c   | 23 +++++++++++-----------
17b94a
 xlators/cluster/afr/src/afr-self-heal.h        |  5 +++--
17b94a
 xlators/cluster/afr/src/afr-self-heald.c       |  2 +-
17b94a
 6 files changed, 42 insertions(+), 35 deletions(-)
17b94a
17b94a
diff --git a/xlators/cluster/afr/src/afr-common.c b/xlators/cluster/afr/src/afr-common.c
17b94a
index 6f2da11..416012c 100644
17b94a
--- a/xlators/cluster/afr/src/afr-common.c
17b94a
+++ b/xlators/cluster/afr/src/afr-common.c
17b94a
@@ -2366,7 +2366,7 @@ afr_lookup_done(call_frame_t *frame, xlator_t *this)
17b94a
         /* If we were called from glfsheal and there is still a gfid
17b94a
          * mismatch, succeed the lookup and let glfsheal print the
17b94a
          * response via gfid-heal-msg.*/
17b94a
-        if (!dict_get_str_sizen(local->xattr_req, "gfid-heal-msg",
17b94a
+        if (!dict_get_str_sizen(local->xattr_rsp, "gfid-heal-msg",
17b94a
                                 &gfid_heal_msg))
17b94a
             goto cant_interpret;
17b94a
 
17b94a
@@ -2421,7 +2421,7 @@ afr_lookup_done(call_frame_t *frame, xlator_t *this)
17b94a
         goto error;
17b94a
     }
17b94a
 
17b94a
-    ret = dict_get_str_sizen(local->xattr_req, "gfid-heal-msg", &gfid_heal_msg);
17b94a
+    ret = dict_get_str_sizen(local->xattr_rsp, "gfid-heal-msg", &gfid_heal_msg);
17b94a
     if (!ret) {
17b94a
         ret = dict_set_str_sizen(local->replies[read_subvol].xdata,
17b94a
                                  "gfid-heal-msg", gfid_heal_msg);
17b94a
@@ -2768,9 +2768,12 @@ afr_lookup_selfheal_wrap(void *opaque)
17b94a
     local = frame->local;
17b94a
     this = frame->this;
17b94a
     loc_pargfid(&local->loc, pargfid);
17b94a
+    if (!local->xattr_rsp)
17b94a
+        local->xattr_rsp = dict_new();
17b94a
 
17b94a
     ret = afr_selfheal_name(frame->this, pargfid, local->loc.name,
17b94a
-                            &local->cont.lookup.gfid_req, local->xattr_req);
17b94a
+                            &local->cont.lookup.gfid_req, local->xattr_req,
17b94a
+                            local->xattr_rsp);
17b94a
     if (ret == -EIO)
17b94a
         goto unwind;
17b94a
 
17b94a
@@ -2786,7 +2789,8 @@ afr_lookup_selfheal_wrap(void *opaque)
17b94a
     return 0;
17b94a
 
17b94a
 unwind:
17b94a
-    AFR_STACK_UNWIND(lookup, frame, -1, EIO, NULL, NULL, NULL, NULL);
17b94a
+    AFR_STACK_UNWIND(lookup, frame, -1, EIO, NULL, NULL, local->xattr_rsp,
17b94a
+                     NULL);
17b94a
     return 0;
17b94a
 }
17b94a
 
17b94a
diff --git a/xlators/cluster/afr/src/afr-self-heal-common.c b/xlators/cluster/afr/src/afr-self-heal-common.c
17b94a
index 0a8a7fd..0954d2c 100644
17b94a
--- a/xlators/cluster/afr/src/afr-self-heal-common.c
17b94a
+++ b/xlators/cluster/afr/src/afr-self-heal-common.c
17b94a
@@ -245,7 +245,8 @@ int
17b94a
 afr_gfid_split_brain_source(xlator_t *this, struct afr_reply *replies,
17b94a
                             inode_t *inode, uuid_t pargfid, const char *bname,
17b94a
                             int src_idx, int child_idx,
17b94a
-                            unsigned char *locked_on, int *src, dict_t *xdata)
17b94a
+                            unsigned char *locked_on, int *src, dict_t *req,
17b94a
+                            dict_t *rsp)
17b94a
 {
17b94a
     afr_private_t *priv = NULL;
17b94a
     char g1[64] = {
17b94a
@@ -266,8 +267,8 @@ afr_gfid_split_brain_source(xlator_t *this, struct afr_reply *replies,
17b94a
         gf_msg(this->name, GF_LOG_ERROR, 0, AFR_MSG_SPLIT_BRAIN,
17b94a
                "All the bricks should be up to resolve the gfid split "
17b94a
                "barin");
17b94a
-        if (xdata) {
17b94a
-            ret = dict_set_sizen_str_sizen(xdata, "gfid-heal-msg",
17b94a
+        if (rsp) {
17b94a
+            ret = dict_set_sizen_str_sizen(rsp, "gfid-heal-msg",
17b94a
                                            SALL_BRICKS_UP_TO_RESOLVE);
17b94a
             if (ret)
17b94a
                 gf_msg(this->name, GF_LOG_ERROR, 0, AFR_MSG_DICT_SET_FAILED,
17b94a
@@ -277,8 +278,8 @@ afr_gfid_split_brain_source(xlator_t *this, struct afr_reply *replies,
17b94a
         goto out;
17b94a
     }
17b94a
 
17b94a
-    if (xdata) {
17b94a
-        ret = dict_get_int32_sizen(xdata, "heal-op", &heal_op);
17b94a
+    if (req) {
17b94a
+        ret = dict_get_int32_sizen(req, "heal-op", &heal_op);
17b94a
         if (ret)
17b94a
             goto fav_child;
17b94a
     } else {
17b94a
@@ -292,8 +293,8 @@ afr_gfid_split_brain_source(xlator_t *this, struct afr_reply *replies,
17b94a
             if (*src == -1) {
17b94a
                 gf_msg(this->name, GF_LOG_ERROR, 0, AFR_MSG_SPLIT_BRAIN,
17b94a
                        SNO_BIGGER_FILE);
17b94a
-                if (xdata) {
17b94a
-                    ret = dict_set_sizen_str_sizen(xdata, "gfid-heal-msg",
17b94a
+                if (rsp) {
17b94a
+                    ret = dict_set_sizen_str_sizen(rsp, "gfid-heal-msg",
17b94a
                                                    SNO_BIGGER_FILE);
17b94a
                     if (ret)
17b94a
                         gf_msg(this->name, GF_LOG_ERROR, 0,
17b94a
@@ -310,8 +311,8 @@ afr_gfid_split_brain_source(xlator_t *this, struct afr_reply *replies,
17b94a
             if (*src == -1) {
17b94a
                 gf_msg(this->name, GF_LOG_ERROR, 0, AFR_MSG_SPLIT_BRAIN,
17b94a
                        SNO_DIFF_IN_MTIME);
17b94a
-                if (xdata) {
17b94a
-                    ret = dict_set_sizen_str_sizen(xdata, "gfid-heal-msg",
17b94a
+                if (rsp) {
17b94a
+                    ret = dict_set_sizen_str_sizen(rsp, "gfid-heal-msg",
17b94a
                                                    SNO_DIFF_IN_MTIME);
17b94a
                     if (ret)
17b94a
                         gf_msg(this->name, GF_LOG_ERROR, 0,
17b94a
@@ -323,7 +324,7 @@ afr_gfid_split_brain_source(xlator_t *this, struct afr_reply *replies,
17b94a
             break;
17b94a
 
17b94a
         case GF_SHD_OP_SBRAIN_HEAL_FROM_BRICK:
17b94a
-            ret = dict_get_str_sizen(xdata, "child-name", &src_brick);
17b94a
+            ret = dict_get_str_sizen(req, "child-name", &src_brick);
17b94a
             if (ret) {
17b94a
                 gf_msg(this->name, GF_LOG_ERROR, 0, AFR_MSG_SPLIT_BRAIN,
17b94a
                        "Error getting the source "
17b94a
@@ -335,8 +336,8 @@ afr_gfid_split_brain_source(xlator_t *this, struct afr_reply *replies,
17b94a
             if (*src == -1) {
17b94a
                 gf_msg(this->name, GF_LOG_ERROR, 0, AFR_MSG_SPLIT_BRAIN,
17b94a
                        SERROR_GETTING_SRC_BRICK);
17b94a
-                if (xdata) {
17b94a
-                    ret = dict_set_sizen_str_sizen(xdata, "gfid-heal-msg",
17b94a
+                if (rsp) {
17b94a
+                    ret = dict_set_sizen_str_sizen(rsp, "gfid-heal-msg",
17b94a
                                                    SERROR_GETTING_SRC_BRICK);
17b94a
                     if (ret)
17b94a
                         gf_msg(this->name, GF_LOG_ERROR, 0,
17b94a
@@ -400,7 +401,7 @@ out:
17b94a
                  uuid_utoa_r(replies[child_idx].poststat.ia_gfid, g1), src_idx,
17b94a
                  priv->children[src_idx]->name, src_idx,
17b94a
                  uuid_utoa_r(replies[src_idx].poststat.ia_gfid, g2));
17b94a
-        return -1;
17b94a
+        return -EIO;
17b94a
     }
17b94a
     return 0;
17b94a
 }
17b94a
diff --git a/xlators/cluster/afr/src/afr-self-heal-entry.c b/xlators/cluster/afr/src/afr-self-heal-entry.c
17b94a
index 20b07dd..a17dd93 100644
17b94a
--- a/xlators/cluster/afr/src/afr-self-heal-entry.c
17b94a
+++ b/xlators/cluster/afr/src/afr-self-heal-entry.c
17b94a
@@ -399,7 +399,7 @@ afr_selfheal_detect_gfid_and_type_mismatch(xlator_t *this,
17b94a
             (ia_type == replies[i].poststat.ia_type)) {
17b94a
             ret = afr_gfid_split_brain_source(this, replies, inode, pargfid,
17b94a
                                               bname, src_idx, i, locked_on, src,
17b94a
-                                              NULL);
17b94a
+                                              NULL, NULL);
17b94a
             if (ret)
17b94a
                 gf_msg(this->name, GF_LOG_ERROR, 0, AFR_MSG_SPLIT_BRAIN,
17b94a
                        "Skipping conservative merge on the "
17b94a
@@ -474,7 +474,7 @@ __afr_selfheal_merge_dirent(call_frame_t *frame, xlator_t *this, fd_t *fd,
17b94a
         return ret;
17b94a
 
17b94a
     /* In case of type mismatch / unable to resolve gfid mismatch on the
17b94a
-     * entry, return -1.*/
17b94a
+     * entry, return -EIO.*/
17b94a
     ret = afr_selfheal_detect_gfid_and_type_mismatch(
17b94a
         this, replies, inode, fd->inode->gfid, name, source, locked_on, &src;;
17b94a
 
17b94a
@@ -905,7 +905,7 @@ afr_selfheal_entry_do_subvol(call_frame_t *frame, xlator_t *this, fd_t *fd,
17b94a
                 break;
17b94a
             }
17b94a
 
17b94a
-            if (ret == -1) {
17b94a
+            if (ret == -EIO) {
17b94a
                 /* gfid or type mismatch. */
17b94a
                 mismatch = _gf_true;
17b94a
                 ret = 0;
17b94a
@@ -1072,7 +1072,7 @@ afr_selfheal_entry_do(call_frame_t *frame, xlator_t *this, fd_t *fd, int source,
17b94a
         else
17b94a
             ret = afr_selfheal_entry_do_subvol(frame, this, fd, i);
17b94a
 
17b94a
-        if (ret == -1) {
17b94a
+        if (ret == -EIO) {
17b94a
             /* gfid or type mismatch. */
17b94a
             mismatch = _gf_true;
17b94a
             ret = 0;
17b94a
diff --git a/xlators/cluster/afr/src/afr-self-heal-name.c b/xlators/cluster/afr/src/afr-self-heal-name.c
17b94a
index 51e3d8c..9ec2066 100644
17b94a
--- a/xlators/cluster/afr/src/afr-self-heal-name.c
17b94a
+++ b/xlators/cluster/afr/src/afr-self-heal-name.c
17b94a
@@ -217,7 +217,8 @@ afr_selfheal_name_gfid_mismatch_check(xlator_t *this, struct afr_reply *replies,
17b94a
                                       int source, unsigned char *sources,
17b94a
                                       int *gfid_idx, uuid_t pargfid,
17b94a
                                       const char *bname, inode_t *inode,
17b94a
-                                      unsigned char *locked_on, dict_t *xdata)
17b94a
+                                      unsigned char *locked_on, dict_t *req,
17b94a
+                                      dict_t *rsp)
17b94a
 {
17b94a
     int i = 0;
17b94a
     int gfid_idx_iter = -1;
17b94a
@@ -245,11 +246,11 @@ afr_selfheal_name_gfid_mismatch_check(xlator_t *this, struct afr_reply *replies,
17b94a
         if (sources[i] || source == -1) {
17b94a
             if ((sources[gfid_idx_iter] || source == -1) &&
17b94a
                 gf_uuid_compare(gfid, gfid1)) {
17b94a
-                ret = afr_gfid_split_brain_source(this, replies, inode, pargfid,
17b94a
-                                                  bname, gfid_idx_iter, i,
17b94a
-                                                  locked_on, gfid_idx, xdata);
17b94a
+                ret = afr_gfid_split_brain_source(
17b94a
+                    this, replies, inode, pargfid, bname, gfid_idx_iter, i,
17b94a
+                    locked_on, gfid_idx, req, rsp);
17b94a
                 if (!ret && *gfid_idx >= 0) {
17b94a
-                    ret = dict_set_sizen_str_sizen(xdata, "gfid-heal-msg",
17b94a
+                    ret = dict_set_sizen_str_sizen(rsp, "gfid-heal-msg",
17b94a
                                                    "GFID split-brain resolved");
17b94a
                     if (ret)
17b94a
                         gf_msg(this->name, GF_LOG_ERROR, 0,
17b94a
@@ -303,7 +304,7 @@ __afr_selfheal_name_do(call_frame_t *frame, xlator_t *this, inode_t *parent,
17b94a
                        unsigned char *sources, unsigned char *sinks,
17b94a
                        unsigned char *healed_sinks, int source,
17b94a
                        unsigned char *locked_on, struct afr_reply *replies,
17b94a
-                       void *gfid_req, dict_t *xdata)
17b94a
+                       void *gfid_req, dict_t *req, dict_t *rsp)
17b94a
 {
17b94a
     int gfid_idx = -1;
17b94a
     int ret = -1;
17b94a
@@ -333,7 +334,7 @@ __afr_selfheal_name_do(call_frame_t *frame, xlator_t *this, inode_t *parent,
17b94a
 
17b94a
     ret = afr_selfheal_name_gfid_mismatch_check(this, replies, source, sources,
17b94a
                                                 &gfid_idx, pargfid, bname,
17b94a
-                                                inode, locked_on, xdata);
17b94a
+                                                inode, locked_on, req, rsp);
17b94a
     if (ret)
17b94a
         return ret;
17b94a
 
17b94a
@@ -450,7 +451,7 @@ out:
17b94a
 int
17b94a
 afr_selfheal_name_do(call_frame_t *frame, xlator_t *this, inode_t *parent,
17b94a
                      uuid_t pargfid, const char *bname, void *gfid_req,
17b94a
-                     dict_t *xdata)
17b94a
+                     dict_t *req, dict_t *rsp)
17b94a
 {
17b94a
     afr_private_t *priv = NULL;
17b94a
     unsigned char *sources = NULL;
17b94a
@@ -505,7 +506,7 @@ afr_selfheal_name_do(call_frame_t *frame, xlator_t *this, inode_t *parent,
17b94a
 
17b94a
         ret = __afr_selfheal_name_do(frame, this, parent, pargfid, bname, inode,
17b94a
                                      sources, sinks, healed_sinks, source,
17b94a
-                                     locked_on, replies, gfid_req, xdata);
17b94a
+                                     locked_on, replies, gfid_req, req, rsp);
17b94a
     }
17b94a
 unlock:
17b94a
     afr_selfheal_unentrylk(frame, this, parent, this->name, bname, locked_on,
17b94a
@@ -578,7 +579,7 @@ afr_selfheal_name_unlocked_inspect(call_frame_t *frame, xlator_t *this,
17b94a
 
17b94a
 int
17b94a
 afr_selfheal_name(xlator_t *this, uuid_t pargfid, const char *bname,
17b94a
-                  void *gfid_req, dict_t *xdata)
17b94a
+                  void *gfid_req, dict_t *req, dict_t *rsp)
17b94a
 {
17b94a
     inode_t *parent = NULL;
17b94a
     call_frame_t *frame = NULL;
17b94a
@@ -600,7 +601,7 @@ afr_selfheal_name(xlator_t *this, uuid_t pargfid, const char *bname,
17b94a
 
17b94a
     if (need_heal) {
17b94a
         ret = afr_selfheal_name_do(frame, this, parent, pargfid, bname,
17b94a
-                                   gfid_req, xdata);
17b94a
+                                   gfid_req, req, rsp);
17b94a
         if (ret)
17b94a
             goto out;
17b94a
     }
17b94a
diff --git a/xlators/cluster/afr/src/afr-self-heal.h b/xlators/cluster/afr/src/afr-self-heal.h
17b94a
index c8dc384..6b0bf69 100644
17b94a
--- a/xlators/cluster/afr/src/afr-self-heal.h
17b94a
+++ b/xlators/cluster/afr/src/afr-self-heal.h
17b94a
@@ -127,7 +127,7 @@ afr_throttled_selfheal(call_frame_t *frame, xlator_t *this);
17b94a
 
17b94a
 int
17b94a
 afr_selfheal_name(xlator_t *this, uuid_t gfid, const char *name, void *gfid_req,
17b94a
-                  dict_t *xdata);
17b94a
+                  dict_t *req, dict_t *rsp);
17b94a
 
17b94a
 int
17b94a
 afr_selfheal_data(call_frame_t *frame, xlator_t *this, fd_t *fd);
17b94a
@@ -357,7 +357,8 @@ int
17b94a
 afr_gfid_split_brain_source(xlator_t *this, struct afr_reply *replies,
17b94a
                             inode_t *inode, uuid_t pargfid, const char *bname,
17b94a
                             int src_idx, int child_idx,
17b94a
-                            unsigned char *locked_on, int *src, dict_t *xdata);
17b94a
+                            unsigned char *locked_on, int *src, dict_t *req,
17b94a
+                            dict_t *rsp);
17b94a
 int
17b94a
 afr_mark_source_sinks_if_file_empty(xlator_t *this, unsigned char *sources,
17b94a
                                     unsigned char *sinks,
17b94a
diff --git a/xlators/cluster/afr/src/afr-self-heald.c b/xlators/cluster/afr/src/afr-self-heald.c
17b94a
index 939a135..18aed93 100644
17b94a
--- a/xlators/cluster/afr/src/afr-self-heald.c
17b94a
+++ b/xlators/cluster/afr/src/afr-self-heald.c
17b94a
@@ -295,7 +295,7 @@ afr_shd_selfheal_name(struct subvol_healer *healer, int child, uuid_t parent,
17b94a
 {
17b94a
     int ret = -1;
17b94a
 
17b94a
-    ret = afr_selfheal_name(THIS, parent, bname, NULL, NULL);
17b94a
+    ret = afr_selfheal_name(THIS, parent, bname, NULL, NULL, NULL);
17b94a
 
17b94a
     return ret;
17b94a
 }
17b94a
-- 
17b94a
1.8.3.1
17b94a