Blob Blame History Raw
From 83daccd63fa23ec2f3d95d866a0fec5ff85d05ba Mon Sep 17 00:00:00 2001
From: Krutika Dhananjay <kdhananj@redhat.com>
Date: Tue, 10 Jan 2017 13:26:02 +0530
Subject: [PATCH 270/270] cluster/afr: Do not log of split-brain when there
 isn't one

        Backport of: http://review.gluster.org/16362

* Even on errors like ENOENT, AFR logs split-brain after
  read-txn refresh, introduced by commit a07ddd8f.
  This can be a cause of much panic and confusion and needs to be fixed.

* Also fixed this issue in write-txns.

* Fixed afr read txns to log about split-brain only after knowing that
  there is no split-brain choice configured.

* Removed code duplication

* Fixed incorrect passing of error code in afr_write_txn_refresh_done()
  (the function was passing -0 as errno to gf_msg().

Change-Id: I1faca12fe9eb7fb6a5eedc9e41141c1d06acfee4
BUG: 1411617
Signed-off-by: Krutika Dhananjay <kdhananj@redhat.com>
Reviewed-on: https://code.engineering.redhat.com/gerrit/94936
Reviewed-by: Atin Mukherjee <amukherj@redhat.com>
---
 xlators/cluster/afr/src/afr-read-txn.c    | 26 ++++++++------------------
 xlators/cluster/afr/src/afr-transaction.c |  8 +-------
 xlators/cluster/afr/src/afr.h             | 12 ++++++++++++
 3 files changed, 21 insertions(+), 25 deletions(-)

diff --git a/xlators/cluster/afr/src/afr-read-txn.c b/xlators/cluster/afr/src/afr-read-txn.c
index 6ed1bcd..ecc9194 100644
--- a/xlators/cluster/afr/src/afr-read-txn.c
+++ b/xlators/cluster/afr/src/afr-read-txn.c
@@ -48,17 +48,6 @@ afr_read_txn_next_subvol (call_frame_t *frame, xlator_t *this)
 	return 0;
 }
 
-#define AFR_READ_TXN_SET_ERROR_AND_GOTO(ret, errnum, index, label) \
-        do {                                                      \
-                local->op_ret = ret;                              \
-                local->op_errno = errnum;                          \
-                read_subvol = index;                              \
-                gf_msg (this->name, GF_LOG_ERROR, EIO, AFR_MSG_SPLIT_BRAIN,\
-                        "Failing %s on gfid %s: split-brain observed.",\
-                        gf_fop_list[local->op], uuid_utoa (inode->gfid));\
-                goto label;                                       \
-        } while (0)
-
 int
 afr_read_txn_refresh_done (call_frame_t *frame, xlator_t *this, int err)
 {
@@ -72,19 +61,16 @@ afr_read_txn_refresh_done (call_frame_t *frame, xlator_t *this, int err)
 	inode = local->inode;
 
         if (err) {
-                local->op_errno = -err;
-                local->op_ret = -1;
                 read_subvol = -1;
-                gf_msg (this->name, GF_LOG_ERROR, EIO, AFR_MSG_SPLIT_BRAIN,
-                        "Failing %s on gfid %s: split-brain observed.",
-                        gf_fop_list[local->op], uuid_utoa (inode->gfid));
                 goto readfn;
         }
 
 	read_subvol = afr_read_subvol_select_by_policy (inode, this,
 							local->readable, NULL);
-	if (read_subvol == -1)
-                AFR_READ_TXN_SET_ERROR_AND_GOTO (-1, EIO, -1, readfn);
+	if (read_subvol == -1) {
+                err = -EIO;
+                goto readfn;
+        }
 
 	if (local->read_attempted[read_subvol]) {
 		afr_read_txn_next_subvol (frame, this);
@@ -99,6 +85,10 @@ readfn:
                 if ((ret == 0) && spb_choice >= 0)
                         read_subvol = spb_choice;
         }
+
+        if (read_subvol == -1) {
+                AFR_SET_ERROR_AND_CHECK_SPLIT_BRAIN (-1, -err);
+        }
 	local->readfn (frame, this, read_subvol);
 
 	return 0;
diff --git a/xlators/cluster/afr/src/afr-transaction.c b/xlators/cluster/afr/src/afr-transaction.c
index 1e70c1c..75999b5 100644
--- a/xlators/cluster/afr/src/afr-transaction.c
+++ b/xlators/cluster/afr/src/afr-transaction.c
@@ -2601,15 +2601,9 @@ int
 afr_write_txn_refresh_done (call_frame_t *frame, xlator_t *this, int err)
 {
         afr_local_t   *local           = frame->local;
-        afr_private_t *priv            = this->private;
-        int           ret              = 0;
 
         if (err) {
-                local->op_errno = -err;
-                local->op_ret = -1;
-                gf_msg (this->name, GF_LOG_ERROR, -ret, AFR_MSG_SPLIT_BRAIN,
-                        "Failing %s on gfid %s: split-brain observed.",
-                        gf_fop_list[local->op], uuid_utoa (local->inode->gfid));
+                AFR_SET_ERROR_AND_CHECK_SPLIT_BRAIN(-1, -err);
                 goto fail;
         }
 
diff --git a/xlators/cluster/afr/src/afr.h b/xlators/cluster/afr/src/afr.h
index c48507b..92b54f8 100644
--- a/xlators/cluster/afr/src/afr.h
+++ b/xlators/cluster/afr/src/afr.h
@@ -55,6 +55,18 @@ typedef int (*afr_compound_cbk_t) (call_frame_t *frame, void *cookie,
 #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;})
 #define AFR_IS_ARBITER_BRICK(priv, index) ((priv->arbiter_count == 1) && (index == ARBITER_BRICK_INDEX))
 
+#define AFR_SET_ERROR_AND_CHECK_SPLIT_BRAIN(ret, errnum)                       \
+        do {                                                                   \
+                local->op_ret = ret;                                           \
+                local->op_errno = errnum;                                      \
+                if (local->op_errno == EIO)                                    \
+                        gf_msg (this->name, GF_LOG_ERROR, local->op_errno,     \
+                                AFR_MSG_SPLIT_BRAIN, "Failing %s on gfid %s: " \
+                                "split-brain observed.",                       \
+                                gf_fop_list[local->op],                        \
+                                uuid_utoa (local->inode->gfid));               \
+        } while (0)
+
 typedef enum {
         AFR_FAV_CHILD_NONE,
         AFR_FAV_CHILD_BY_SIZE,
-- 
2.9.3