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