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