nvme: add function to get ZNS num zones

Add a function to get the number of zones for a zoned namespace.

Since the ZNS specification does not allow zone size == 0,
divide by zero should not be possible on a spec compliant drive.

Signed-off-by: Niklas Cassel <niklas.cassel@wdc.com>
Change-Id: I15e0ac8a72e244e248b7fb44f7156b182ecd98b4
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/4792
Reviewed-by: Jim Harris <james.r.harris@intel.com>
Reviewed-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Community-CI: Broadcom CI
This commit is contained in:
Niklas Cassel 2020-10-20 09:30:12 +00:00 committed by Tomasz Zawadzki
parent 6abee9a205
commit be3ff9c0b5
3 changed files with 19 additions and 0 deletions

View File

@ -72,6 +72,18 @@ const struct spdk_nvme_zns_ns_data *spdk_nvme_zns_ns_get_data(struct spdk_nvme_n
*/
uint64_t spdk_nvme_zns_ns_get_zone_size(struct spdk_nvme_ns *ns);
/**
* Get the number of zones for the given namespace.
*
* This function is thread safe and can be called at any point while the controller
* is attached to the SPDK NVMe driver.
*
* \param ns Namespace to query.
*
* \return the number of zones.
*/
uint64_t spdk_nvme_zns_ns_get_num_zones(struct spdk_nvme_ns *ns);
/**
* Get the Zoned Namespace Command Set Specific Identify Controller data
* as defined by the NVMe Zoned Namespace Command Set Specification.

View File

@ -48,6 +48,12 @@ spdk_nvme_zns_ns_get_zone_size(struct spdk_nvme_ns *ns)
return nsdata_zns->lbafe[nsdata->flbas.format].zsze * spdk_nvme_ns_get_sector_size(ns);
}
uint64_t
spdk_nvme_zns_ns_get_num_zones(struct spdk_nvme_ns *ns)
{
return spdk_nvme_ns_get_size(ns) / spdk_nvme_zns_ns_get_zone_size(ns);
}
const struct spdk_nvme_zns_ctrlr_data *
spdk_nvme_zns_ctrlr_get_data(struct spdk_nvme_ctrlr *ctrlr)
{

View File

@ -161,6 +161,7 @@
# public functions from nvme_zns.h
spdk_nvme_zns_ns_get_data;
spdk_nvme_zns_ns_get_zone_size;
spdk_nvme_zns_ns_get_num_zones;
spdk_nvme_zns_ctrlr_get_data;
spdk_nvme_zns_close_zone;
spdk_nvme_zns_finish_zone;