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