From 4224fc348bc320803ee7af2d091353cfb0f5981b Mon Sep 17 00:00:00 2001
From: Marcin Spiewak <marcin.spiewak@intel.com>
Date: Wed, 20 Mar 2024 16:59:06 +0100
Subject: [PATCH] lib/nvme: add mutex before submit admin request

Conflict:NA
Reference:https://github.com/spdk/spdk/commit/4224fc348bc320803ee7af2d091353cfb0f5981b

In nvme_ctrlr_cmd_identify(), the call to
nvme_ctrlr_submit_admin_request() shall be
preceeded by taking ctrlr->ctrlr_lock mutex,
like in other places in the code.

Change-Id: Ibd4ef2aa02d906dac853e537df9a837974b6c358
Signed-off-by: Marcin Spiewak <marcin.spiewak@intel.com>
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/22419
Reviewed-by: Konrad Sztyber <konrad.sztyber@intel.com>
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: Jim Harris <jim.harris@samsung.com>
---
 lib/nvme/nvme_ctrlr_cmd.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/lib/nvme/nvme_ctrlr_cmd.c b/lib/nvme/nvme_ctrlr_cmd.c
index bcc92b29c..2f00ef83c 100644
--- a/lib/nvme/nvme_ctrlr_cmd.c
+++ b/lib/nvme/nvme_ctrlr_cmd.c
@@ -152,11 +152,14 @@ nvme_ctrlr_cmd_identify(struct spdk_nvme_ctrlr *ctrlr, uint8_t cns, uint16_t cnt
 {
 	struct nvme_request *req;
 	struct spdk_nvme_cmd *cmd;
+	int		     rc;
 
+	nvme_robust_mutex_lock(&ctrlr->ctrlr_lock);
 	req = nvme_allocate_request_user_copy(ctrlr->adminq,
 					      payload, payload_size,
 					      cb_fn, cb_arg, false);
 	if (req == NULL) {
+		nvme_robust_mutex_unlock(&ctrlr->ctrlr_lock);
 		return -ENOMEM;
 	}
 
@@ -167,7 +170,10 @@ nvme_ctrlr_cmd_identify(struct spdk_nvme_ctrlr *ctrlr, uint8_t cns, uint16_t cnt
 	cmd->cdw11_bits.identify.csi = csi;
 	cmd->nsid = nsid;
 
-	return nvme_ctrlr_submit_admin_request(ctrlr, req);
+	rc = nvme_ctrlr_submit_admin_request(ctrlr, req);
+
+	nvme_robust_mutex_unlock(&ctrlr->ctrlr_lock);
+	return rc;
 }
 
 int
-- 
2.27.0

