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