8 Star 3 Fork 42

src-openEuler/spdk

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
0002-backport-Add-ctrlr_lock-for-cuse-register-and-unregister.patch 2.96 KB
一键复制 编辑 原始数据 按行查看 历史
From 253cca4fc3a89c38e79d2e940c5a0b7bb082afcc Mon Sep 17 00:00:00 2001
From: Zhanghongtao2417 <651380626@qq.com>
Date: Fri, 26 Apr 2024 22:01:25 +0800
Subject: [PATCH] nvme/cuse: Add ctrlr_lock for cuse register and unregister
conflicts:
lib/nvme/nvme_io_msg.c nvme_io_msg_ctrlr_update
spdk_nvme_cuse_unregister and spdk_nvme_ctrlr_process_admin_completions
running at the same time, concurrently operate external_io_msgs.
So we add locks to protect.
Fixes #3353
Change-Id: Id5176975676c29a475e8e2a0d7c93e44646c00dc
Signed-off-by: Zhanghongtao2417 <651380626@qq.com>
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/22927
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Community-CI: Mellanox Build Bot
Reviewed-by: Jim Harris <jim.harris@samsung.com>
Reviewed-by: Konrad Sztyber <konrad.sztyber@intel.com>
---
lib/nvme/nvme_io_msg.c | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/lib/nvme/nvme_io_msg.c b/lib/nvme/nvme_io_msg.c
index 94c4d07..9f5ee6d 100644
--- a/lib/nvme/nvme_io_msg.c
+++ b/lib/nvme/nvme_io_msg.c
@@ -111,13 +111,16 @@ nvme_io_msg_ctrlr_register(struct spdk_nvme_ctrlr *ctrlr,
return -EINVAL;
}
+ nvme_robust_mutex_lock(&ctrlr->ctrlr_lock);
if (nvme_io_msg_is_producer_registered(ctrlr, io_msg_producer)) {
+ nvme_robust_mutex_unlock(&ctrlr->ctrlr_lock);
return -EEXIST;
}
if (!STAILQ_EMPTY(&ctrlr->io_producers) || ctrlr->is_resetting) {
/* There are registered producers - IO messaging already started */
STAILQ_INSERT_TAIL(&ctrlr->io_producers, io_msg_producer, link);
+ nvme_robust_mutex_unlock(&ctrlr->ctrlr_lock);
return 0;
}
@@ -129,6 +132,7 @@ nvme_io_msg_ctrlr_register(struct spdk_nvme_ctrlr *ctrlr,
ctrlr->external_io_msgs = spdk_ring_create(SPDK_RING_TYPE_MP_SC, 65536, SPDK_ENV_SOCKET_ID_ANY);
if (!ctrlr->external_io_msgs) {
SPDK_ERRLOG("Unable to allocate memory for message ring\n");
+ nvme_robust_mutex_unlock(&ctrlr->ctrlr_lock);
return -ENOMEM;
}
@@ -141,6 +145,7 @@ nvme_io_msg_ctrlr_register(struct spdk_nvme_ctrlr *ctrlr,
}
STAILQ_INSERT_TAIL(&ctrlr->io_producers, io_msg_producer, link);
+ nvme_robust_mutex_unlock(&ctrlr->ctrlr_lock);
return 0;
}
@@ -156,9 +161,11 @@ nvme_io_msg_ctrlr_update(struct spdk_nvme_ctrlr *ctrlr)
}
/* Update all producers */
+ nvme_robust_mutex_lock(&ctrlr->ctrlr_lock);
STAILQ_FOREACH(io_msg_producer, &ctrlr->io_producers, link) {
io_msg_producer->update(ctrlr);
}
+ nvme_robust_mutex_unlock(&ctrlr->ctrlr_lock);
}
void
@@ -195,7 +202,9 @@ nvme_io_msg_ctrlr_unregister(struct spdk_nvme_ctrlr *ctrlr,
{
assert(io_msg_producer != NULL);
+ nvme_robust_mutex_lock(&ctrlr->ctrlr_lock);
if (!nvme_io_msg_is_producer_registered(ctrlr, io_msg_producer)) {
+ nvme_robust_mutex_unlock(&ctrlr->ctrlr_lock);
return;
}
@@ -203,4 +212,5 @@ nvme_io_msg_ctrlr_unregister(struct spdk_nvme_ctrlr *ctrlr,
if (STAILQ_EMPTY(&ctrlr->io_producers)) {
nvme_io_msg_ctrlr_detach(ctrlr);
}
+ nvme_robust_mutex_unlock(&ctrlr->ctrlr_lock);
}
--
2.27.0
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/src-openeuler/spdk.git
git@gitee.com:src-openeuler/spdk.git
src-openeuler
spdk
spdk
master

搜索帮助