14f8ab
From 8c366f34a279a5ab2a6301bfd93534fe746a23e8 Mon Sep 17 00:00:00 2001
14f8ab
From: Ravishankar N <ravishankar@redhat.com>
14f8ab
Date: Mon, 7 Dec 2020 09:53:27 +0530
14f8ab
Subject: [PATCH 483/511] afr: more quorum checks in lookup and new entry
14f8ab
 marking
14f8ab
14f8ab
Problem: See upstream github issue for details.
14f8ab
14f8ab
Fix:
14f8ab
-In lookup if the entry exists in 2 out of 3 bricks, don't fail the
14f8ab
lookup with ENOENT just because there is an entrylk on the parent.
14f8ab
Consider quorum before deciding.
14f8ab
14f8ab
-If entry FOP does not succeed on quorum no. of bricks, do not perform
14f8ab
new entry mark.
14f8ab
14f8ab
Upstream patch details:
14f8ab
> Reviewed-on: https://review.gluster.org/#/c/glusterfs/+/24499/
14f8ab
> Fixes: #1303
14f8ab
> Change-Id: I56df8c89ad53b29fa450c7930a7b7ccec9f4a6c5
14f8ab
> Signed-off-by: Ravishankar N <ravishankar@redhat.com>
14f8ab
14f8ab
BUG: 1821599
14f8ab
Change-Id: If513e8a7d6088a676288927630d8e616269bf5d5
14f8ab
Signed-off-by: Ravishankar N <ravishankar@redhat.com>
14f8ab
Reviewed-on: https://code.engineering.redhat.com/gerrit/220363
14f8ab
Tested-by: RHGS Build Bot <nigelb@redhat.com>
14f8ab
Reviewed-by: Sunil Kumar Heggodu Gopala Acharya <sheggodu@redhat.com>
14f8ab
---
14f8ab
 ...20-mark-dirty-for-entry-txn-on-quorum-failure.t |  2 --
14f8ab
 xlators/cluster/afr/src/afr-common.c               | 24 ++++++++++++----------
14f8ab
 xlators/cluster/afr/src/afr-dir-write.c            |  8 ++++++++
14f8ab
 xlators/cluster/afr/src/afr.h                      |  4 ++++
14f8ab
 4 files changed, 25 insertions(+), 13 deletions(-)
14f8ab
14f8ab
diff --git a/tests/bugs/replicate/bug-1586020-mark-dirty-for-entry-txn-on-quorum-failure.t b/tests/bugs/replicate/bug-1586020-mark-dirty-for-entry-txn-on-quorum-failure.t
14f8ab
index 26f9049..49c4dea 100644
14f8ab
--- a/tests/bugs/replicate/bug-1586020-mark-dirty-for-entry-txn-on-quorum-failure.t
14f8ab
+++ b/tests/bugs/replicate/bug-1586020-mark-dirty-for-entry-txn-on-quorum-failure.t
14f8ab
@@ -53,8 +53,6 @@ TEST ! ls $B0/${V0}1/file$i
14f8ab
 TEST ls $B0/${V0}2/file$i
14f8ab
 dirty=$(get_hex_xattr trusted.afr.dirty $B0/${V0}2)
14f8ab
 TEST [ "$dirty" != "000000000000000000000000" ]
14f8ab
-EXPECT "000000010000000100000000" get_hex_xattr trusted.afr.$V0-client-0 $B0/${V0}2/file$i
14f8ab
-EXPECT "000000010000000100000000" get_hex_xattr trusted.afr.$V0-client-1 $B0/${V0}2/file$i
14f8ab
 
14f8ab
 TEST $CLI volume set $V0 self-heal-daemon on
14f8ab
 EXPECT_WITHIN $PROCESS_UP_TIMEOUT "Y" glustershd_up_status
14f8ab
diff --git a/xlators/cluster/afr/src/afr-common.c b/xlators/cluster/afr/src/afr-common.c
14f8ab
index 89e2483..851ccad 100644
14f8ab
--- a/xlators/cluster/afr/src/afr-common.c
14f8ab
+++ b/xlators/cluster/afr/src/afr-common.c
14f8ab
@@ -1236,7 +1236,7 @@ refresh_done:
14f8ab
     return 0;
14f8ab
 }
14f8ab
 
14f8ab
-static void
14f8ab
+void
14f8ab
 afr_fill_success_replies(afr_local_t *local, afr_private_t *priv,
14f8ab
                          unsigned char *replies)
14f8ab
 {
14f8ab
@@ -2290,6 +2290,7 @@ afr_lookup_done(call_frame_t *frame, xlator_t *this)
14f8ab
         0,
14f8ab
     };
14f8ab
     gf_boolean_t locked_entry = _gf_false;
14f8ab
+    gf_boolean_t in_flight_create = _gf_false;
14f8ab
     gf_boolean_t can_interpret = _gf_true;
14f8ab
     inode_t *parent = NULL;
14f8ab
     ia_type_t ia_type = IA_INVAL;
14f8ab
@@ -2333,17 +2334,12 @@ afr_lookup_done(call_frame_t *frame, xlator_t *this)
14f8ab
         if (!replies[i].valid)
14f8ab
             continue;
14f8ab
 
14f8ab
-        if (locked_entry && replies[i].op_ret == -1 &&
14f8ab
-            replies[i].op_errno == ENOENT) {
14f8ab
-            /* Second, check entry is still
14f8ab
-               "underway" in creation */
14f8ab
-            local->op_ret = -1;
14f8ab
-            local->op_errno = ENOENT;
14f8ab
-            goto error;
14f8ab
-        }
14f8ab
-
14f8ab
-        if (replies[i].op_ret == -1)
14f8ab
+        if (replies[i].op_ret == -1) {
14f8ab
+            if (locked_entry && replies[i].op_errno == ENOENT) {
14f8ab
+                in_flight_create = _gf_true;
14f8ab
+            }
14f8ab
             continue;
14f8ab
+        }
14f8ab
 
14f8ab
         if (read_subvol == -1 || !readable[read_subvol]) {
14f8ab
             read_subvol = i;
14f8ab
@@ -2353,6 +2349,12 @@ afr_lookup_done(call_frame_t *frame, xlator_t *this)
14f8ab
         }
14f8ab
     }
14f8ab
 
14f8ab
+    if (in_flight_create && !afr_has_quorum(success_replies, this, NULL)) {
14f8ab
+        local->op_ret = -1;
14f8ab
+        local->op_errno = ENOENT;
14f8ab
+        goto error;
14f8ab
+    }
14f8ab
+
14f8ab
     if (read_subvol == -1)
14f8ab
         goto error;
14f8ab
     /* We now have a read_subvol, which is readable[] (if there
14f8ab
diff --git a/xlators/cluster/afr/src/afr-dir-write.c b/xlators/cluster/afr/src/afr-dir-write.c
14f8ab
index 84e2a34..416c19d 100644
14f8ab
--- a/xlators/cluster/afr/src/afr-dir-write.c
14f8ab
+++ b/xlators/cluster/afr/src/afr-dir-write.c
14f8ab
@@ -349,6 +349,7 @@ afr_mark_entry_pending_changelog(call_frame_t *frame, xlator_t *this)
14f8ab
     afr_private_t *priv = NULL;
14f8ab
     int pre_op_count = 0;
14f8ab
     int failed_count = 0;
14f8ab
+    unsigned char *success_replies = NULL;
14f8ab
 
14f8ab
     local = frame->local;
14f8ab
     priv = this->private;
14f8ab
@@ -364,9 +365,16 @@ afr_mark_entry_pending_changelog(call_frame_t *frame, xlator_t *this)
14f8ab
     failed_count = AFR_COUNT(local->transaction.failed_subvols,
14f8ab
                              priv->child_count);
14f8ab
 
14f8ab
+    /* FOP succeeded on all bricks. */
14f8ab
     if (pre_op_count == priv->child_count && !failed_count)
14f8ab
         return;
14f8ab
 
14f8ab
+    /* FOP did not suceed on quorum no. of bricks. */
14f8ab
+    success_replies = alloca0(priv->child_count);
14f8ab
+    afr_fill_success_replies(local, priv, success_replies);
14f8ab
+    if (!afr_has_quorum(success_replies, this, NULL))
14f8ab
+        return;
14f8ab
+
14f8ab
     if (priv->thin_arbiter_count) {
14f8ab
         /*Mark new entry using ta file*/
14f8ab
         local->is_new_entry = _gf_true;
14f8ab
diff --git a/xlators/cluster/afr/src/afr.h b/xlators/cluster/afr/src/afr.h
14f8ab
index ff96246..ed5096e 100644
14f8ab
--- a/xlators/cluster/afr/src/afr.h
14f8ab
+++ b/xlators/cluster/afr/src/afr.h
14f8ab
@@ -1334,4 +1334,8 @@ afr_mark_new_entry_changelog(call_frame_t *frame, xlator_t *this);
14f8ab
 
14f8ab
 void
14f8ab
 afr_selfheal_childup(xlator_t *this, afr_private_t *priv);
14f8ab
+
14f8ab
+void
14f8ab
+afr_fill_success_replies(afr_local_t *local, afr_private_t *priv,
14f8ab
+                         unsigned char *replies);
14f8ab
 #endif /* __AFR_H__ */
14f8ab
-- 
14f8ab
1.8.3.1
14f8ab