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