d1681e
From a1da6900ac8030dd9c156b38373837a00dbb37c0 Mon Sep 17 00:00:00 2001
d1681e
From: Ravishankar N <ravishankar@redhat.com>
d1681e
Date: Thu, 18 Jan 2018 14:21:57 +0530
d1681e
Subject: [PATCH 153/180] afr: add quorum checks in post-op
d1681e
d1681e
Backport of https://review.gluster.org/#/c/18571/
d1681e
d1681e
afr relies on pending changelog xattrs to identify source and sinks and the
d1681e
setting of these xattrs happen in post-op. So if post-op fails, we need to
d1681e
unwind the write txn with a failure.
d1681e
d1681e
Change-Id: I0f019ac03890108324ee7672883d774918b20be1
d1681e
BUG: 1384983
d1681e
Signed-off-by: Ravishankar N <ravishankar@redhat.com>
d1681e
Reviewed-on: https://code.engineering.redhat.com/gerrit/129219
d1681e
Reviewed-by: Pranith Kumar Karampuri <pkarampu@redhat.com>
d1681e
Tested-by: RHGS Build Bot <nigelb@redhat.com>
d1681e
---
d1681e
 xlators/cluster/afr/src/afr-transaction.c | 29 +++++++++++++++++++++++++++++
d1681e
 1 file changed, 29 insertions(+)
d1681e
d1681e
diff --git a/xlators/cluster/afr/src/afr-transaction.c b/xlators/cluster/afr/src/afr-transaction.c
d1681e
index 7e40bba..18d2ded 100644
d1681e
--- a/xlators/cluster/afr/src/afr-transaction.c
d1681e
+++ b/xlators/cluster/afr/src/afr-transaction.c
d1681e
@@ -534,6 +534,29 @@ afr_lock_server_count (afr_private_t *priv, afr_transaction_type type)
d1681e
 /* {{{ pending */
d1681e
 
d1681e
 
d1681e
+gf_boolean_t
d1681e
+afr_post_op_has_quorum (afr_local_t *local, xlator_t *this)
d1681e
+{
d1681e
+        afr_private_t *priv = NULL;
d1681e
+        int i = 0;
d1681e
+        unsigned char *post_op_children = NULL;
d1681e
+
d1681e
+        priv = this->private;
d1681e
+        post_op_children = alloca0 (priv->child_count);
d1681e
+
d1681e
+        for (i = 0; i < priv->child_count; i++) {
d1681e
+                if (!local->transaction.failed_subvols[i]) {
d1681e
+                        post_op_children[i] = 1;
d1681e
+                }
d1681e
+        }
d1681e
+
d1681e
+        if (afr_has_quorum (post_op_children, this)) {
d1681e
+                return _gf_true;
d1681e
+        }
d1681e
+
d1681e
+        return _gf_false;
d1681e
+}
d1681e
+
d1681e
 int
d1681e
 afr_changelog_post_op_done (call_frame_t *frame, xlator_t *this)
d1681e
 {
d1681e
@@ -545,6 +568,12 @@ afr_changelog_post_op_done (call_frame_t *frame, xlator_t *this)
d1681e
 	priv = this->private;
d1681e
         int_lock = &local->internal_lock;
d1681e
 
d1681e
+        /* Fail the FOP if post-op did not succeed on quorum no. of bricks. */
d1681e
+        if (!afr_post_op_has_quorum (local, this)) {
d1681e
+                local->op_ret = -1;
d1681e
+                local->op_errno = ENOTCONN;
d1681e
+        }
d1681e
+
d1681e
 	if (local->transaction.resume_stub) {
d1681e
 		call_resume (local->transaction.resume_stub);
d1681e
 		local->transaction.resume_stub = NULL;
d1681e
-- 
d1681e
1.8.3.1
d1681e