Commit 28092d2f authored by Dennis Maisenbacher's avatar Dennis Maisenbacher Committed by Tomasz Zawadzki
Browse files

nvmf: Find a NS for an identify cmd through a helper function



Refactoring to avoid code duplication in the following commits.

Signed-off-by: default avatarDennis Maisenbacher <dennis.maisenbacher@wdc.com>
Change-Id: I5a597a02c810cfa1fad6dc397d012cf6a3f189ca
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/16043


Community-CI: Mellanox Build Bot
Reviewed-by: default avatarBen Walker <benjamin.walker@intel.com>
Reviewed-by: default avatarJim Harris <james.r.harris@intel.com>
Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
parent b1b2ccbf
Loading
Loading
Loading
Loading
+27 −14
Original line number Diff line number Diff line
@@ -2591,34 +2591,47 @@ invalid_log_page:
	return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
}

int
spdk_nvmf_ctrlr_identify_ns(struct spdk_nvmf_ctrlr *ctrlr,
			    struct spdk_nvme_cmd *cmd,
			    struct spdk_nvme_cpl *rsp,
			    struct spdk_nvme_ns_data *nsdata)
static struct spdk_nvmf_ns *
_nvmf_subsystem_get_ns_safe(struct spdk_nvmf_subsystem *subsystem,
			    uint32_t nsid,
			    struct spdk_nvme_cpl *rsp)
{
	struct spdk_nvmf_subsystem *subsystem = ctrlr->subsys;
	struct spdk_nvmf_ns *ns;
	uint32_t max_num_blocks;
	enum spdk_nvme_ana_state ana_state;

	if (cmd->nsid == 0 || cmd->nsid > subsystem->max_nsid) {
		SPDK_ERRLOG("Identify Namespace for invalid NSID %u\n", cmd->nsid);
	if (nsid == 0 || nsid > subsystem->max_nsid) {
		SPDK_ERRLOG("Identify Namespace for invalid NSID %u\n", nsid);
		rsp->status.sct = SPDK_NVME_SCT_GENERIC;
		rsp->status.sc = SPDK_NVME_SC_INVALID_NAMESPACE_OR_FORMAT;
		return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
		return NULL;
	}

	ns = _nvmf_subsystem_get_ns(subsystem, cmd->nsid);
	ns = _nvmf_subsystem_get_ns(subsystem, nsid);
	if (ns == NULL || ns->bdev == NULL) {
		/*
		 * Inactive namespaces should return a zero filled data structure.
		 * The data buffer is already zeroed by nvmf_ctrlr_process_admin_cmd(),
		 * so we can just return early here.
		 */
		SPDK_DEBUGLOG(nvmf, "Identify Namespace for inactive NSID %u\n", cmd->nsid);
		SPDK_DEBUGLOG(nvmf, "Identify Namespace for inactive NSID %u\n", nsid);
		rsp->status.sct = SPDK_NVME_SCT_GENERIC;
		rsp->status.sc = SPDK_NVME_SC_SUCCESS;
		return NULL;
	}
	return ns;
}

int
spdk_nvmf_ctrlr_identify_ns(struct spdk_nvmf_ctrlr *ctrlr,
			    struct spdk_nvme_cmd *cmd,
			    struct spdk_nvme_cpl *rsp,
			    struct spdk_nvme_ns_data *nsdata)
{
	struct spdk_nvmf_subsystem *subsystem = ctrlr->subsys;
	struct spdk_nvmf_ns *ns;
	uint32_t max_num_blocks;
	enum spdk_nvme_ana_state ana_state;

	ns = _nvmf_subsystem_get_ns_safe(subsystem, cmd->nsid, rsp);
	if (ns == NULL) {
		return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
	}