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