Commit fb6c49f2 authored by Konrad Sztyber's avatar Konrad Sztyber
Browse files

bdev: add spdk_bdev_get_nvme_nsid()



The id of a namespace is required to be sent in some, but not all, admin
commands.  So, without it, it's impossible to send an admin command that
does require it.

This is not a problem for IO commands, as bdev_nvme always fills in nsid
for IO command passthru.  However, we can't do that for admin commands,
as some admin commands require nsid to be cleared or behave differently
when it's set to the broadcast value (0xffffffff).

Signed-off-by: default avatarKonrad Sztyber <konrad.sztyber@intel.com>
Change-Id: Ic943a1c52cd9043cc09469ad421be2f089aac606
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/25363


Community-CI: Broadcom CI <spdk-ci.pdl@broadcom.com>
Community-CI: Mellanox Build Bot
Community-CI: Community CI Samsung <spdk.community.ci.samsung@gmail.com>
Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: default avatarJim Harris <jim.harris@samsung.com>
Reviewed-by: default avatarChangpeng Liu <changpeliu@tencent.com>
parent 427304da
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -2291,6 +2291,15 @@ void spdk_bdev_for_each_channel(struct spdk_bdev *bdev, spdk_bdev_for_each_chann
 */
union spdk_bdev_nvme_ctratt spdk_bdev_get_nvme_ctratt(struct spdk_bdev *bdev);

/**
 * Get NVMe namespace ID for a given bdev (only for NVMe bdevs).
 *
 * \param bdev Block device to query.
 *
 * \return Namespace ID or 0 if it's not available.
 */
uint32_t spdk_bdev_get_nvme_nsid(struct spdk_bdev *bdev);

#ifdef __cplusplus
}
#endif
+5 −0
Original line number Diff line number Diff line
@@ -612,6 +612,11 @@ struct spdk_bdev {
	 */
	union spdk_bdev_nvme_ctratt ctratt;

	/**
	 * NVMe namespace ID.
	 */
	uint32_t nsid;

	/* Upon receiving a reset request, this is the amount of time in seconds
	 * to wait for all I/O to complete before moving forward with the reset.
	 * If all I/O completes prior to this time out, the reset will be skipped.
+6 −0
Original line number Diff line number Diff line
@@ -5049,6 +5049,12 @@ union spdk_bdev_nvme_ctratt spdk_bdev_get_nvme_ctratt(struct spdk_bdev *bdev)
	return bdev->ctratt;
}

uint32_t
spdk_bdev_get_nvme_nsid(struct spdk_bdev *bdev)
{
	return bdev->nsid;
}

static void bdev_update_qd_sampling_period(void *ctx);

static void
+1 −0
Original line number Diff line number Diff line
@@ -115,6 +115,7 @@
	spdk_bdev_get_max_copy;
	spdk_bdev_copy_blocks;
	spdk_bdev_get_nvme_ctratt;
	spdk_bdev_get_nvme_nsid;
	spdk_bdev_get_io_type_name;
	spdk_bdev_get_io_type;

+2 −6
Original line number Diff line number Diff line
@@ -2078,7 +2078,6 @@ spdk_nvmf_subsystem_add_ns_ext(struct spdk_nvmf_subsystem *subsystem, const char
	struct spdk_nvmf_ns *ns, *first_ns;
	struct spdk_nvmf_ctrlr *ctrlr;
	struct spdk_nvmf_reservation_info info = {0};
	struct spdk_nvme_ns *nvme_ns;
	int rc;
	bool zone_append_supported;
	uint64_t max_zone_append_size_kib;
@@ -2180,11 +2179,8 @@ spdk_nvmf_subsystem_add_ns_ext(struct spdk_nvmf_subsystem *subsystem, const char
		return 0;
	}

	if (!strncmp(spdk_bdev_get_module_name(ns->bdev), "nvme",
		     strlen(spdk_bdev_get_module_name(ns->bdev)))) {
		nvme_ns = (struct spdk_nvme_ns *) spdk_bdev_get_module_ctx(ns->desc);
		ns->passthrough_nsid = spdk_nvme_ns_get_id(nvme_ns);
	} else if (subsystem->passthrough) {
	ns->passthrough_nsid = spdk_bdev_get_nvme_nsid(ns->bdev);
	if (subsystem->passthrough && ns->passthrough_nsid == 0) {
		SPDK_ERRLOG("Only bdev_nvme namespaces can be added to a passthrough subsystem.\n");
		goto err;
	}
Loading