3604df
From 83daccd63fa23ec2f3d95d866a0fec5ff85d05ba Mon Sep 17 00:00:00 2001
3604df
From: Krutika Dhananjay <kdhananj@redhat.com>
3604df
Date: Tue, 10 Jan 2017 13:26:02 +0530
3604df
Subject: [PATCH 270/270] cluster/afr: Do not log of split-brain when there
3604df
 isn't one
3604df
3604df
        Backport of: http://review.gluster.org/16362
3604df
3604df
* Even on errors like ENOENT, AFR logs split-brain after
3604df
  read-txn refresh, introduced by commit a07ddd8f.
3604df
  This can be a cause of much panic and confusion and needs to be fixed.
3604df
3604df
* Also fixed this issue in write-txns.
3604df
3604df
* Fixed afr read txns to log about split-brain only after knowing that
3604df
  there is no split-brain choice configured.
3604df
3604df
* Removed code duplication
3604df
3604df
* Fixed incorrect passing of error code in afr_write_txn_refresh_done()
3604df
  (the function was passing -0 as errno to gf_msg().
3604df
3604df
Change-Id: I1faca12fe9eb7fb6a5eedc9e41141c1d06acfee4
3604df
BUG: 1411617
3604df
Signed-off-by: Krutika Dhananjay <kdhananj@redhat.com>
3604df
Reviewed-on: https://code.engineering.redhat.com/gerrit/94936
3604df
Reviewed-by: Atin Mukherjee <amukherj@redhat.com>
3604df
---
3604df
 xlators/cluster/afr/src/afr-read-txn.c    | 26 ++++++++------------------
3604df
 xlators/cluster/afr/src/afr-transaction.c |  8 +-------
3604df
 xlators/cluster/afr/src/afr.h             | 12 ++++++++++++
3604df
 3 files changed, 21 insertions(+), 25 deletions(-)
3604df
3604df
diff --git a/xlators/cluster/afr/src/afr-read-txn.c b/xlators/cluster/afr/src/afr-read-txn.c
3604df
index 6ed1bcd..ecc9194 100644
3604df
--- a/xlators/cluster/afr/src/afr-read-txn.c
3604df
+++ b/xlators/cluster/afr/src/afr-read-txn.c
3604df
@@ -48,17 +48,6 @@ afr_read_txn_next_subvol (call_frame_t *frame, xlator_t *this)
3604df
 	return 0;
3604df
 }
3604df
 
3604df
-#define AFR_READ_TXN_SET_ERROR_AND_GOTO(ret, errnum, index, label) \
3604df
-        do {                                                      \
3604df
-                local->op_ret = ret;                              \
3604df
-                local->op_errno = errnum;                          \
3604df
-                read_subvol = index;                              \
3604df
-                gf_msg (this->name, GF_LOG_ERROR, EIO, AFR_MSG_SPLIT_BRAIN,\
3604df
-                        "Failing %s on gfid %s: split-brain observed.",\
3604df
-                        gf_fop_list[local->op], uuid_utoa (inode->gfid));\
3604df
-                goto label;                                       \
3604df
-        } while (0)
3604df
-
3604df
 int
3604df
 afr_read_txn_refresh_done (call_frame_t *frame, xlator_t *this, int err)
3604df
 {
3604df
@@ -72,19 +61,16 @@ afr_read_txn_refresh_done (call_frame_t *frame, xlator_t *this, int err)
3604df
 	inode = local->inode;
3604df
 
3604df
         if (err) {
3604df
-                local->op_errno = -err;
3604df
-                local->op_ret = -1;
3604df
                 read_subvol = -1;
3604df
-                gf_msg (this->name, GF_LOG_ERROR, EIO, AFR_MSG_SPLIT_BRAIN,
3604df
-                        "Failing %s on gfid %s: split-brain observed.",
3604df
-                        gf_fop_list[local->op], uuid_utoa (inode->gfid));
3604df
                 goto readfn;
3604df
         }
3604df
 
3604df
 	read_subvol = afr_read_subvol_select_by_policy (inode, this,
3604df
 							local->readable, NULL);
3604df
-	if (read_subvol == -1)
3604df
-                AFR_READ_TXN_SET_ERROR_AND_GOTO (-1, EIO, -1, readfn);
3604df
+	if (read_subvol == -1) {
3604df
+                err = -EIO;
3604df
+                goto readfn;
3604df
+        }
3604df
 
3604df
 	if (local->read_attempted[read_subvol]) {
3604df
 		afr_read_txn_next_subvol (frame, this);
3604df
@@ -99,6 +85,10 @@ readfn:
3604df
                 if ((ret == 0) && spb_choice >= 0)
3604df
                         read_subvol = spb_choice;
3604df
         }
3604df
+
3604df
+        if (read_subvol == -1) {
3604df
+                AFR_SET_ERROR_AND_CHECK_SPLIT_BRAIN (-1, -err);
3604df
+        }
3604df
 	local->readfn (frame, this, read_subvol);
3604df
 
3604df
 	return 0;
3604df
diff --git a/xlators/cluster/afr/src/afr-transaction.c b/xlators/cluster/afr/src/afr-transaction.c
3604df
index 1e70c1c..75999b5 100644
3604df
--- a/xlators/cluster/afr/src/afr-transaction.c
3604df
+++ b/xlators/cluster/afr/src/afr-transaction.c
3604df
@@ -2601,15 +2601,9 @@ int
3604df
 afr_write_txn_refresh_done (call_frame_t *frame, xlator_t *this, int err)
3604df
 {
3604df
         afr_local_t   *local           = frame->local;
3604df
-        afr_private_t *priv            = this->private;
3604df
-        int           ret              = 0;
3604df
 
3604df
         if (err) {
3604df
-                local->op_errno = -err;
3604df
-                local->op_ret = -1;
3604df
-                gf_msg (this->name, GF_LOG_ERROR, -ret, AFR_MSG_SPLIT_BRAIN,
3604df
-                        "Failing %s on gfid %s: split-brain observed.",
3604df
-                        gf_fop_list[local->op], uuid_utoa (local->inode->gfid));
3604df
+                AFR_SET_ERROR_AND_CHECK_SPLIT_BRAIN(-1, -err);
3604df
                 goto fail;
3604df
         }
3604df
 
3604df
diff --git a/xlators/cluster/afr/src/afr.h b/xlators/cluster/afr/src/afr.h
3604df
index c48507b..92b54f8 100644
3604df
--- a/xlators/cluster/afr/src/afr.h
3604df
+++ b/xlators/cluster/afr/src/afr.h
3604df
@@ -55,6 +55,18 @@ typedef int (*afr_compound_cbk_t) (call_frame_t *frame, void *cookie,
3604df
 #define AFR_CMP(a1,a2,len) ({int __cmp = 0; int __i; for (__i = 0; __i < len; __i++) if (a1[__i] != a2[__i]) { __cmp = 1; break;} __cmp;})
3604df
 #define AFR_IS_ARBITER_BRICK(priv, index) ((priv->arbiter_count == 1) && (index == ARBITER_BRICK_INDEX))
3604df
 
3604df
+#define AFR_SET_ERROR_AND_CHECK_SPLIT_BRAIN(ret, errnum)                       \
3604df
+        do {                                                                   \
3604df
+                local->op_ret = ret;                                           \
3604df
+                local->op_errno = errnum;                                      \
3604df
+                if (local->op_errno == EIO)                                    \
3604df
+                        gf_msg (this->name, GF_LOG_ERROR, local->op_errno,     \
3604df
+                                AFR_MSG_SPLIT_BRAIN, "Failing %s on gfid %s: " \
3604df
+                                "split-brain observed.",                       \
3604df
+                                gf_fop_list[local->op],                        \
3604df
+                                uuid_utoa (local->inode->gfid));               \
3604df
+        } while (0)
3604df
+
3604df
 typedef enum {
3604df
         AFR_FAV_CHILD_NONE,
3604df
         AFR_FAV_CHILD_BY_SIZE,
3604df
-- 
3604df
2.9.3
3604df