Commit c156f3e1 authored by Karl Bonde Torp's avatar Karl Bonde Torp Committed by Konrad Sztyber
Browse files

nvmf: ensure correct nsid for passthrough commands



This handles the case where a user adds an nvme namespace to a fabrics
subsystem with a different nsid than the underlying nvme namespace.

Fixes issue #3486

Change-Id: Iede7001fd2a4b87fde1e3a1b201def792049394a
Signed-off-by: default avatarKarl Bonde Torp <k.torp@samsung.com>
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/24454


Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: default avatarJim Harris <jim.harris@samsung.com>
Reviewed-by: default avatarAleksey Marchuk <alexeymar@nvidia.com>
Reviewed-by: default avatarShuhei Matsumoto <smatsumoto@nvidia.com>
Community-CI: Mellanox Build Bot
parent 3cd7b237
Loading
Loading
Loading
Loading
+13 −0
Original line number Diff line number Diff line
@@ -4478,6 +4478,9 @@ nvmf_ctrlr_process_io_cmd(struct spdk_nvmf_request *req)
			if (spdk_unlikely(qpair->transport->opts.disable_command_passthru)) {
				goto invalid_opcode;
			}
			if (ns->passthrough_nsid) {
				req->cmd->nvme_cmd.nsid = ns->passthrough_nsid;
			}
			return nvmf_bdev_ctrlr_nvme_passthru_io(bdev, desc, ch, req);
		}
	}
@@ -4877,6 +4880,8 @@ nvmf_passthru_admin_cmd_for_bdev_nsid(struct spdk_nvmf_request *req, uint32_t bd
	struct spdk_bdev *bdev;
	struct spdk_bdev_desc *desc;
	struct spdk_io_channel *ch;
	struct spdk_nvmf_ns *ns;
	struct spdk_nvmf_ctrlr *ctrlr;
	struct spdk_nvme_cpl *response = spdk_nvmf_request_get_response(req);
	int rc;

@@ -4886,6 +4891,14 @@ nvmf_passthru_admin_cmd_for_bdev_nsid(struct spdk_nvmf_request *req, uint32_t bd
		response->status.sc = SPDK_NVME_SC_INVALID_NAMESPACE_OR_FORMAT;
		return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
	}

	ctrlr = req->qpair->ctrlr;
	ns = nvmf_ctrlr_get_ns(ctrlr, bdev_nsid);

	if (ns->passthrough_nsid) {
		req->cmd->nvme_cmd.nsid = ns->passthrough_nsid;
	}

	return spdk_nvmf_bdev_ctrlr_nvme_passthru_admin(bdev, desc, ch, req, NULL);
}

+2 −0
Original line number Diff line number Diff line
@@ -185,6 +185,8 @@ struct spdk_nvmf_ns {
	TAILQ_HEAD(, spdk_nvmf_host) hosts;
	/* Namespace is always visible to all controllers */
	bool always_visible;
	/* Namespace id of the underlying device, used for passthrough commands */
	uint32_t passthrough_nsid;
};

/*
+7 −0
Original line number Diff line number Diff line
@@ -2027,6 +2027,7 @@ 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;
@@ -2130,6 +2131,12 @@ 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);
	}

	/* Cache the zcopy capability of the bdev device */
	ns->zcopy = spdk_bdev_io_type_supported(ns->bdev, SPDK_BDEV_IO_TYPE_ZCOPY);

+4 −0
Original line number Diff line number Diff line
@@ -74,6 +74,10 @@ DEFINE_STUB_V(spdk_keyring_put_key, (struct spdk_key *k));
DEFINE_STUB(nvmf_auth_is_supported, bool, (void), false);
DEFINE_STUB(nvmf_tgt_update_mdns_prr, int, (struct spdk_nvmf_tgt *tgt), 0);

DEFINE_STUB(spdk_bdev_get_module_name, const char *, (const struct spdk_bdev *bdev), "nvme");
DEFINE_STUB(spdk_bdev_get_module_ctx, void *, (struct spdk_bdev_desc *desc), NULL);
DEFINE_STUB(spdk_nvme_ns_get_id, uint32_t, (struct spdk_nvme_ns *ns), 0);

static struct spdk_nvmf_transport g_transport = {};

struct spdk_nvmf_subsystem *