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