a3470f
From 67c89f4fc9a80c9ed4a7d78df57c1ca76f4adc3d Mon Sep 17 00:00:00 2001
a3470f
From: N Balachandran <nbalacha@redhat.com>
a3470f
Date: Tue, 17 Apr 2018 15:37:05 +0530
a3470f
Subject: [PATCH 237/260] cluster/dht: Fix dht_rename lock order
a3470f
a3470f
Fixed dht_order_rename_lock to use the same inodelk ordering
a3470f
as that of the dht selfheal locks (dictionary order of
a3470f
lock subvolumes).
a3470f
a3470f
upstream: https://review.gluster.org/#/c/19886/
a3470f
a3470f
> Change-Id: Ia3f8353b33ea2fd3bc1ba7e8e777dda6c1d33e0d
a3470f
> fixes: bz#1568348
a3470f
> Signed-off-by: N Balachandran <nbalacha@redhat.com>
a3470f
a3470f
Change-Id: I09022705f5b77af0f50a2bab4579d4d3cb902155
a3470f
BUG: 1565119
a3470f
Signed-off-by: N Balachandran <nbalacha@redhat.com>
a3470f
Reviewed-on: https://code.engineering.redhat.com/gerrit/136451
a3470f
Tested-by: RHGS Build Bot <nigelb@redhat.com>
a3470f
Reviewed-by: Sunil Kumar Heggodu Gopala Acharya <sheggodu@redhat.com>
a3470f
---
a3470f
 xlators/cluster/dht/src/dht-rename.c | 65 ++++++++++++++++++++++++++----------
a3470f
 1 file changed, 47 insertions(+), 18 deletions(-)
a3470f
a3470f
diff --git a/xlators/cluster/dht/src/dht-rename.c b/xlators/cluster/dht/src/dht-rename.c
a3470f
index 3068499..ca6b5f4 100644
a3470f
--- a/xlators/cluster/dht/src/dht-rename.c
a3470f
+++ b/xlators/cluster/dht/src/dht-rename.c
a3470f
@@ -490,37 +490,66 @@ err:
a3470f
         return 0;
a3470f
 }
a3470f
 
a3470f
+
a3470f
+/*
a3470f
+ * If the hashed subvolumes of both source and dst are the different,
a3470f
+ * lock in dictionary order of hashed subvol->name. This is important
a3470f
+ * in case the parent directory is the same for both src and dst to
a3470f
+ * prevent inodelk deadlocks when racing with a fix-layout op on the parent.
a3470f
+ *
a3470f
+ * If the hashed subvols are the same, use the gfid/name to determine
a3470f
+ * the order of taking locks to prevent entrylk deadlocks when the parent
a3470f
+ * dirs are the same.
a3470f
+ *
a3470f
+ */
a3470f
 static void
a3470f
 dht_order_rename_lock (call_frame_t *frame, loc_t **loc, xlator_t **subvol)
a3470f
 {
a3470f
-        dht_local_t        *local                       = NULL;
a3470f
-        char                src[GF_UUID_BNAME_BUF_SIZE] = {0};
a3470f
-        char                dst[GF_UUID_BNAME_BUF_SIZE] = {0};
a3470f
+        int ret                 = 0;
a3470f
+        dht_local_t   *local    = NULL;
a3470f
+        char           src[GF_UUID_BNAME_BUF_SIZE] = {0};
a3470f
+        char           dst[GF_UUID_BNAME_BUF_SIZE] = {0};
a3470f
+
a3470f
 
a3470f
         local = frame->local;
a3470f
 
a3470f
-        if (local->loc.pargfid)
a3470f
-                uuid_utoa_r (local->loc.pargfid, src);
a3470f
-        else if (local->loc.parent)
a3470f
-                uuid_utoa_r (local->loc.parent->gfid, src);
a3470f
+        if (local->src_hashed->name == local->dst_hashed->name) {
a3470f
+                ret = 0;
a3470f
+        } else {
a3470f
+                ret = strcmp (local->src_hashed->name, local->dst_hashed->name);
a3470f
+        }
a3470f
 
a3470f
-        strcat (src, local->loc.name);
a3470f
+        if (ret == 0) {
a3470f
 
a3470f
-        if (local->loc2.pargfid)
a3470f
-                uuid_utoa_r (local->loc2.pargfid, dst);
a3470f
-        else if (local->loc2.parent)
a3470f
-                uuid_utoa_r (local->loc2.parent->gfid, dst);
a3470f
+                /* hashed subvols are the same for src and dst */
a3470f
+                /* Entrylks need to be ordered*/
a3470f
+                if (local->loc.pargfid)
a3470f
+                        uuid_utoa_r (local->loc.pargfid, src);
a3470f
+                else if (local->loc.parent)
a3470f
+                        uuid_utoa_r (local->loc.parent->gfid, src);
a3470f
 
a3470f
-        strcat (dst, local->loc2.name);
a3470f
+                strcat (src, local->loc.name);
a3470f
 
a3470f
-        if (strcmp(src, dst) > 0) {
a3470f
-                local->current = &local->lock[1];
a3470f
-                *loc = &local->loc2;
a3470f
-                *subvol = local->dst_hashed;
a3470f
-        } else {
a3470f
+                if (local->loc2.pargfid)
a3470f
+                        uuid_utoa_r (local->loc2.pargfid, dst);
a3470f
+                else if (local->loc2.parent)
a3470f
+                        uuid_utoa_r (local->loc2.parent->gfid, dst);
a3470f
+
a3470f
+                strcat (dst, local->loc2.name);
a3470f
+                ret = strcmp (src, dst);
a3470f
+        }
a3470f
+
a3470f
+        if (ret <= 0) {
a3470f
+                /*inodelk in dictionary order of hashed subvol names*/
a3470f
+                /*entrylk in dictionary order of gfid/basename */
a3470f
                 local->current = &local->lock[0];
a3470f
                 *loc = &local->loc;
a3470f
                 *subvol = local->src_hashed;
a3470f
+
a3470f
+        } else {
a3470f
+                local->current = &local->lock[1];
a3470f
+                *loc = &local->loc2;
a3470f
+                *subvol = local->dst_hashed;
a3470f
         }
a3470f
 
a3470f
         return;
a3470f
-- 
a3470f
1.8.3.1
a3470f