14f8ab
From 32281b4b5cf79d0ef6f0c65775bb81093e1ba479 Mon Sep 17 00:00:00 2001
14f8ab
From: Mohit Agrawal <moagrawa@redhat.com>
14f8ab
Date: Wed, 24 Feb 2021 18:44:12 +0530
14f8ab
Subject: [PATCH 536/538] dht: Ongoing IO is failed during volume shrink
14f8ab
 operation (#2188)
14f8ab
14f8ab
In the commit (c878174) we have introduced a check
14f8ab
to avoid stale layout issue.To avoid a stale layout
14f8ab
issue dht has set a key along with layout at the time
14f8ab
of wind a create fop and posix validates the parent
14f8ab
layout based on the key value. If layout does not match
14f8ab
it throw and error.In case of volume shrink layout has
14f8ab
been changed by reabalance daemon and if layout does not
14f8ab
matches dht is not able to wind a create fop successfully.
14f8ab
14f8ab
Solution: To avoid the issue populate a key only while
14f8ab
          dht has wind a fop first time. After got an
14f8ab
          error in 2nd attempt dht takes a lock and then
14f8ab
          reattempt to wind a fop again.
14f8ab
14f8ab
> Fixes: #2187
14f8ab
> Change-Id: Ie018386e7823a11eea415496bb226ca032453a55
14f8ab
> Signed-off-by: Mohit Agrawal <moagrawa@redhat.com>
14f8ab
> (Cherry pick from commit da6ce622b722f7d12619c5860293faf03f7cd00c
14f8ab
> Reviewed on upstream link https://github.com/gluster/glusterfs/pull/2188
14f8ab
14f8ab
Bug: 1924044
14f8ab
Change-Id: I7670dbe2d562b83db0af3753f994653ffdd49591
14f8ab
Signed-off-by: Mohit Agrawal <moagrawa@redhat.com>
14f8ab
Reviewed-on: https://code.engineering.redhat.com/gerrit/228941
14f8ab
Tested-by: RHGS Build Bot <nigelb@redhat.com>
14f8ab
Reviewed-by: Sunil Kumar Heggodu Gopala Acharya <sheggodu@redhat.com>
14f8ab
---
14f8ab
 xlators/cluster/dht/src/dht-common.c | 41 ++++++++++++++++++++++++++----------
14f8ab
 1 file changed, 30 insertions(+), 11 deletions(-)
14f8ab
14f8ab
diff --git a/xlators/cluster/dht/src/dht-common.c b/xlators/cluster/dht/src/dht-common.c
14f8ab
index fe1d0ee..7425c1a 100644
14f8ab
--- a/xlators/cluster/dht/src/dht-common.c
14f8ab
+++ b/xlators/cluster/dht/src/dht-common.c
14f8ab
@@ -8526,15 +8526,32 @@ dht_create_wind_to_avail_subvol(call_frame_t *frame, xlator_t *this,
14f8ab
 {
14f8ab
     dht_local_t *local = NULL;
14f8ab
     xlator_t *avail_subvol = NULL;
14f8ab
+    int lk_count = 0;
14f8ab
 
14f8ab
     local = frame->local;
14f8ab
 
14f8ab
     if (!dht_is_subvol_filled(this, subvol)) {
14f8ab
-        gf_msg_debug(this->name, 0, "creating %s on %s", loc->path,
14f8ab
-                     subvol->name);
14f8ab
-
14f8ab
-        dht_set_parent_layout_in_dict(loc, this, local);
14f8ab
-
14f8ab
+        lk_count = local->lock[0].layout.parent_layout.lk_count;
14f8ab
+        gf_msg_debug(this->name, 0, "creating %s on %s with lock_count %d",
14f8ab
+                     loc->path, subvol->name, lk_count);
14f8ab
+        /*The function dht_set_parent_layout_in_dict sets the layout
14f8ab
+          in dictionary and posix_create validates a layout before
14f8ab
+          creating a file.In case if parent layout does not match
14f8ab
+          with disk layout posix xlator throw an error but in case
14f8ab
+          if volume is shrunk layout has been changed by rebalance daemon
14f8ab
+          so we need to call this function only while a function is calling
14f8ab
+          without taking any lock otherwise we would not able to populate a
14f8ab
+          layout on disk in case if layout has changed.
14f8ab
+        */
14f8ab
+        if (!lk_count) {
14f8ab
+            dht_set_parent_layout_in_dict(loc, this, local);
14f8ab
+        } else {
14f8ab
+            /* Delete a key to avoid layout validate if it was set by
14f8ab
+               previous STACK_WIND attempt when a lock was not taken
14f8ab
+               by dht_create
14f8ab
+            */
14f8ab
+            (void)dict_del_sizen(local->params, GF_PREOP_PARENT_KEY);
14f8ab
+        }
14f8ab
         STACK_WIND_COOKIE(frame, dht_create_cbk, subvol, subvol,
14f8ab
                           subvol->fops->create, loc, flags, mode, umask, fd,
14f8ab
                           params);
14f8ab
@@ -8554,12 +8571,14 @@ dht_create_wind_to_avail_subvol(call_frame_t *frame, xlator_t *this,
14f8ab
 
14f8ab
             goto out;
14f8ab
         }
14f8ab
-
14f8ab
-        gf_msg_debug(this->name, 0, "creating %s on %s", loc->path,
14f8ab
-                     subvol->name);
14f8ab
-
14f8ab
-        dht_set_parent_layout_in_dict(loc, this, local);
14f8ab
-
14f8ab
+        lk_count = local->lock[0].layout.parent_layout.lk_count;
14f8ab
+        gf_msg_debug(this->name, 0, "creating %s on %s with lk_count %d",
14f8ab
+                     loc->path, subvol->name, lk_count);
14f8ab
+        if (!lk_count) {
14f8ab
+            dht_set_parent_layout_in_dict(loc, this, local);
14f8ab
+        } else {
14f8ab
+            (void)dict_del_sizen(local->params, GF_PREOP_PARENT_KEY);
14f8ab
+        }
14f8ab
         STACK_WIND_COOKIE(frame, dht_create_cbk, subvol, subvol,
14f8ab
                           subvol->fops->create, loc, flags, mode, umask, fd,
14f8ab
                           params);
14f8ab
-- 
14f8ab
1.8.3.1
14f8ab