Commit 6178d62e authored by Dor Deri's avatar Dor Deri Committed by Tomasz Zawadzki
Browse files

nvmf: set correct cntlid for reservation report



Previously, the Controller ID (cntlid) in the Reservation Report was
always set to 0xFFFF, which is only valid when the registrant of the
namespace is not associated with any controller.

Updated the logic for setting ctrlr_data.cntlid to align with the
NVMe specification.

As defined in the NVMe spec:
Controller ID (CNTLID): If a registrant of the namespace is associated
with a controller in the NVM subsystem, then this field contains the
controller ID (i.e., the value of the CNTLID field in the Identify
Controller data structure) of the controller that is associated with
the registrant whose host identifier is indicated in the Host identifier
field of this Registrant data structure. If a registrant of the namespace
is not associated with any controller in the NVM subsystem, then the
controller processing the command shall set this field to FFFFh.

This ensures accurate reporting of registered controllers in compliance
with NVMe specification.

Change-Id: I1d6b374433411c50103a8c1c674a0132e4ca9382
Signed-off-by: default avatarDor Deri <dor.deri@dell.com>
Reviewed-on: https://review.spdk.io/c/spdk/spdk/+/26473


Community-CI: Mellanox Build Bot
Reviewed-by: default avatarChangpeng Liu <changpeliu@tencent.com>
Reviewed-by: default avatarJim Harris <jim.harris@nvidia.com>
Tested-by: default avatarSPDK Automated Test System <spdkbot@gmail.com>
parent becf0996
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -164,6 +164,7 @@ struct spdk_nvmf_registrant {
	struct spdk_uuid hostid;
	/* Registration key */
	uint64_t rkey;
	uint16_t cntlid;
};

struct spdk_nvmf_ns {
+2 −2
Original line number Diff line number Diff line
@@ -3051,6 +3051,7 @@ nvmf_ns_reservation_add_registrant(struct spdk_nvmf_ns *ns,
	}

	reg->rkey = nrkey;
	reg->cntlid = ctrlr->cntlid;
	/* set hostid for the registrant */
	spdk_uuid_copy(&reg->hostid, &ctrlr->hostid);
	TAILQ_INSERT_TAIL(&ns->registrants, reg, link);
@@ -3629,8 +3630,7 @@ nvmf_ns_reservation_report(const struct spdk_nvmf_ns *ns,
	TAILQ_FOREACH_SAFE(reg, &ns->registrants, link, tmp) {
		struct spdk_nvme_registered_ctrlr_extended_data ctrlr_data = { 0 };

		/* Set to 0xffffh for dynamic controller */
		ctrlr_data.cntlid = 0xffff;
		ctrlr_data.cntlid = reg->cntlid ? reg->cntlid : 0xffff;
		ctrlr_data.rcsts.status = (ns->holder == reg) ? true : false;
		ctrlr_data.rkey = reg->rkey;
		spdk_uuid_copy((struct spdk_uuid *)ctrlr_data.hostid, &reg->hostid);
+4 −2
Original line number Diff line number Diff line
@@ -2031,7 +2031,9 @@ test_nvmf_ns_reservation_report(void)
	cmd.nvme_cmd.cdw11_bits.resv_report.eds = true;
	cmd.nvme_cmd.cdw10 = 100;
	reg[0].rkey = 0xa;
	reg[0].cntlid = 11;
	reg[1].rkey = 0xb;
	reg[1].cntlid = 12;
	spdk_uuid_generate(&reg[0].hostid);
	spdk_uuid_generate(&reg[1].hostid);
	TAILQ_INIT(&ns.registrants);
@@ -2049,13 +2051,13 @@ test_nvmf_ns_reservation_report(void)
	CU_ASSERT(status_data->data.rtype == SPDK_NVME_RESERVE_WRITE_EXCLUSIVE);
	CU_ASSERT(status_data->data.ptpls == true);
	CU_ASSERT(status_data->data.regctl == 2);
	CU_ASSERT(ctrlr_data->cntlid == 0xffff);
	CU_ASSERT(ctrlr_data->cntlid == 11);
	CU_ASSERT(ctrlr_data->rcsts.status == false);
	CU_ASSERT(ctrlr_data->rkey ==  0xa);
	CU_ASSERT(!spdk_uuid_compare((struct spdk_uuid *)ctrlr_data->hostid, &reg[0].hostid));
	/* Check second ctrlr data */
	ctrlr_data++;
	CU_ASSERT(ctrlr_data->cntlid == 0xffff);
	CU_ASSERT(ctrlr_data->cntlid == 12);
	CU_ASSERT(ctrlr_data->rcsts.status == false);
	CU_ASSERT(ctrlr_data->rkey ==  0xb);
	CU_ASSERT(!spdk_uuid_compare((struct spdk_uuid *)ctrlr_data->hostid, &reg[1].hostid));