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