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