nvme: add spdk_nvme_ns_is_active() function

This function returns true if the namespace is active or false if it is
inactive (e.g. no namespace has been attached to the specified namespace
ID yet).

Also use the new function to add checks in the examples and tests where
applicable.

Change-Id: I35465b315ae1a1677c5a82191ad9b1da1c216d50
Signed-off-by: Daniel Verkamp <daniel.verkamp@intel.com>
This commit is contained in:
Daniel Verkamp 2016-03-01 14:39:24 -07:00
parent 6eb18e2f3d
commit 5ee7a5df37
5 changed files with 37 additions and 0 deletions

View File

@ -338,6 +338,11 @@ print_namespace(struct spdk_nvme_ns *ns)
printf("\n");
}
if (!spdk_nvme_ns_is_active(ns)) {
printf("Inactive namespace ID\n\n");
return;
}
printf("Deallocate: %s\n",
(flags & SPDK_NVME_NS_DEALLOCATE_SUPPORTED) ? "Supported" : "Not Supported");
printf("Flush: %s\n",

View File

@ -152,6 +152,13 @@ register_ns(struct spdk_nvme_ctrlr *ctrlr, struct spdk_nvme_ns *ns)
cdata = spdk_nvme_ctrlr_get_data(ctrlr);
if (!spdk_nvme_ns_is_active(ns)) {
printf("Controller %-20.20s (%-20.20s): Skipping inactive NS %u\n",
cdata->mn, cdata->sn,
spdk_nvme_ns_get_id(ns));
return;
}
if (spdk_nvme_ns_get_size(ns) < g_io_size_bytes ||
spdk_nvme_ns_get_sector_size(ns) > g_io_size_bytes) {
printf("WARNING: controller %-20.20s (%-20.20s) ns %u has invalid "

View File

@ -356,6 +356,13 @@ const struct spdk_nvme_ns_data *spdk_nvme_ns_get_data(struct spdk_nvme_ns *ns);
*/
uint32_t spdk_nvme_ns_get_id(struct spdk_nvme_ns *ns);
/**
* \brief Determine whether a namespace is active.
*
* Inactive namespaces cannot be the target of I/O commands.
*/
bool spdk_nvme_ns_is_active(struct spdk_nvme_ns *ns);
/**
* \brief Get the maximum transfer size, in bytes, for an I/O sent to the given namespace.
*

View File

@ -45,6 +45,19 @@ spdk_nvme_ns_get_id(struct spdk_nvme_ns *ns)
return ns->id;
}
bool
spdk_nvme_ns_is_active(struct spdk_nvme_ns *ns)
{
const struct spdk_nvme_ns_data *nsdata = _nvme_ns_get_data(ns);
/*
* According to the spec, Identify Namespace will return a zero-filled structure for
* inactive namespace IDs.
* Check NCAP since it must be nonzero for an active namespace.
*/
return nsdata->ncap != 0;
}
uint32_t
spdk_nvme_ns_get_max_io_xfer_size(struct spdk_nvme_ns *ns)
{

View File

@ -106,6 +106,11 @@ register_ns(struct spdk_nvme_ctrlr *ctrlr, struct spdk_nvme_ns *ns)
struct ns_entry *entry;
const struct spdk_nvme_ctrlr_data *cdata;
if (!spdk_nvme_ns_is_active(ns)) {
printf("Skipping inactive NS %u\n", spdk_nvme_ns_get_id(ns));
return;
}
entry = malloc(sizeof(struct ns_entry));
if (entry == NULL) {
perror("ns_entry malloc");