nvmf: Find a NS for an identify cmd through a helper function
Refactoring to avoid code duplication in the following commits. Signed-off-by: Dennis 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: Ben Walker <benjamin.walker@intel.com> Reviewed-by: Jim Harris <james.r.harris@intel.com> Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
This commit is contained in:
parent
b1b2ccbf44
commit
28092d2fee
@ -2591,6 +2591,34 @@ invalid_log_page:
|
|||||||
return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
|
return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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_ns *ns;
|
||||||
|
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 NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
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", nsid);
|
||||||
|
rsp->status.sct = SPDK_NVME_SCT_GENERIC;
|
||||||
|
rsp->status.sc = SPDK_NVME_SC_SUCCESS;
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
return ns;
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
spdk_nvmf_ctrlr_identify_ns(struct spdk_nvmf_ctrlr *ctrlr,
|
spdk_nvmf_ctrlr_identify_ns(struct spdk_nvmf_ctrlr *ctrlr,
|
||||||
struct spdk_nvme_cmd *cmd,
|
struct spdk_nvme_cmd *cmd,
|
||||||
@ -2602,23 +2630,8 @@ spdk_nvmf_ctrlr_identify_ns(struct spdk_nvmf_ctrlr *ctrlr,
|
|||||||
uint32_t max_num_blocks;
|
uint32_t max_num_blocks;
|
||||||
enum spdk_nvme_ana_state ana_state;
|
enum spdk_nvme_ana_state ana_state;
|
||||||
|
|
||||||
if (cmd->nsid == 0 || cmd->nsid > subsystem->max_nsid) {
|
ns = _nvmf_subsystem_get_ns_safe(subsystem, cmd->nsid, rsp);
|
||||||
SPDK_ERRLOG("Identify Namespace for invalid NSID %u\n", cmd->nsid);
|
if (ns == NULL) {
|
||||||
rsp->status.sct = SPDK_NVME_SCT_GENERIC;
|
|
||||||
rsp->status.sc = SPDK_NVME_SC_INVALID_NAMESPACE_OR_FORMAT;
|
|
||||||
return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
|
|
||||||
}
|
|
||||||
|
|
||||||
ns = _nvmf_subsystem_get_ns(subsystem, cmd->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);
|
|
||||||
rsp->status.sct = SPDK_NVME_SCT_GENERIC;
|
|
||||||
rsp->status.sc = SPDK_NVME_SC_SUCCESS;
|
|
||||||
return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
|
return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user