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