bdev/zone: add support for get num zones

There are three modules implementing the bdev-zone API:
bdev_nvme, bdev_ocssd, and vbdev_zone_block.

For all three modules, the number of zones can be calculated using:
block_count / zone_size.

To avoid this calculation being performed everywhere, create a helper
function in bdev_zone.h, together with the other zone APIs, such that
a user can easily get the number of zones.

Signed-off-by: Niklas Cassel <niklas.cassel@wdc.com>
Change-Id: I2967b15a604ab8bf4420588e7510b9820762f925
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/7451
Reviewed-by: Konrad Sztyber <konrad.sztyber@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
Reviewed-by: Ben Walker <benjamin.walker@intel.com>
Community-CI: Broadcom CI
Community-CI: Mellanox Build Bot
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
This commit is contained in:
Niklas Cassel 2021-04-16 11:22:07 +00:00 committed by Jim Harris
parent d69349af6b
commit 0859db6b69
4 changed files with 29 additions and 0 deletions

View File

@ -84,6 +84,14 @@ struct spdk_bdev_zone_info {
*/
uint64_t spdk_bdev_get_zone_size(const struct spdk_bdev *bdev);
/**
* Get the number of zones for the given device.
*
* \param bdev Block device to query.
* \return The number of zones.
*/
uint64_t spdk_bdev_get_num_zones(const struct spdk_bdev *bdev);
/**
* Get device maximum zone append data transfer size in logical blocks.
*

View File

@ -44,6 +44,12 @@ spdk_bdev_get_zone_size(const struct spdk_bdev *bdev)
return bdev->zone_size;
}
uint64_t
spdk_bdev_get_num_zones(const struct spdk_bdev *bdev)
{
return bdev->zone_size ? bdev->blockcnt / bdev->zone_size : 0;
}
uint32_t
spdk_bdev_get_max_zone_append_size(const struct spdk_bdev *bdev)
{

View File

@ -143,6 +143,7 @@
# Public functions in bdev_zone.h
spdk_bdev_get_zone_size;
spdk_bdev_get_num_zones;
spdk_bdev_get_max_zone_append_size;
spdk_bdev_get_max_open_zones;
spdk_bdev_get_max_active_zones;

View File

@ -254,6 +254,19 @@ test_get_zone_size(void)
CU_ASSERT(get_zone_size == 1024 * 4096);
}
static void
test_get_num_zones(void)
{
struct spdk_bdev bdev = {};
uint64_t get_num_zones;
bdev.blockcnt = 1024 * 1024 * 1024;
bdev.zone_size = 1024 * 4096;
get_num_zones = spdk_bdev_get_num_zones(&bdev);
CU_ASSERT(get_num_zones == 256);
}
static void
test_get_max_zone_append_size(void)
{
@ -318,6 +331,7 @@ static void
test_zone_get_operation(void)
{
test_get_zone_size();
test_get_num_zones();
test_get_max_zone_append_size();
test_get_max_open_zones();
test_get_max_active_zones();