From 0489d5319ea6a0918c1bc7bd9c3d1da61543467b Mon Sep 17 00:00:00 2001
From: zhanghongtao <zhanghongtao22@huawei.com>
Date: Mon, 18 Dec 2023 19:52:56 +0800
Subject: [PATCH] Fix deadlock due to lock sequence in bdev_unregister_unsafe

Signed-off-by: Hongtao Zhang <zhanghongtao22@huawei.com>
---
 lib/bdev/bdev.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/bdev/bdev.c b/lib/bdev/bdev.c
index 4c63e8b..64027c6 100644
--- a/lib/bdev/bdev.c
+++ b/lib/bdev/bdev.c
@@ -5758,8 +5758,8 @@ bdev_unregister_unsafe(struct spdk_bdev *bdev)
 		pthread_mutex_unlock(&bdev->internal.mutex);
 		pthread_mutex_unlock(&g_bdev_mgr.mutex);
 		_remove_notify(desc);
-		pthread_mutex_lock(&bdev->internal.mutex);
 		pthread_mutex_lock(&g_bdev_mgr.mutex);
+		pthread_mutex_lock(&bdev->internal.mutex);
 	}
 
 	/* If there are no descriptors, proceed removing the bdev */
-- 
2.27.0

