bdev/zone: add support for get zone id

In the bdev-zone API, there are a few functions that takes a zone_id:
spdk_bdev_get_zone_info(), spdk_bdev_zone_management(), and the
spdk_bdev_zone_append() functions.

The way a zoned application is usually written is that it starts off
by getting the zone report for all zones (zone_id will be sent in as 0),
and then the application will keep the whole zone report in memory.

Therefore, an application usually have access to the zone_id/zslba for
all zones. However, there are cases, e.g. when getting an error on write,
where the completion callback will only have the lba of the write that
failed.

Add a helper function that can be used to get the zone_id/slba for a
given lba. Having this helper in bdev-zone will avoid SPDK applications
needing to provide their own implementation for this.

Signed-off-by: Niklas Cassel <niklas.cassel@wdc.com>
Change-Id: I978335f87f7d49bc33aed81afcaa6d9f0af8a1e4
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/10180
Community-CI: Broadcom CI <spdk-ci.pdl@broadcom.com>
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
Reviewed-by: Ben Walker <benjamin.walker@intel.com>
This commit is contained in:
Niklas Cassel 2021-11-11 01:06:46 +00:00 committed by Jim Harris
parent 01f94ea947
commit b7ad5b0b90
5 changed files with 43 additions and 1 deletions

View File

@ -92,6 +92,16 @@ uint64_t spdk_bdev_get_zone_size(const struct spdk_bdev *bdev);
*/
uint64_t spdk_bdev_get_num_zones(const struct spdk_bdev *bdev);
/**
* Get the first logical block of a zone (known as zone_id or zslba)
* for a given offset.
*
* \param bdev Block device to query.
* \param offset_blocks The offset, in blocks, from the start of the block device.
* \return The zone_id (also known as zslba) for the given offset.
*/
uint64_t spdk_bdev_get_zone_id(const struct spdk_bdev *bdev, uint64_t offset_blocks);
/**
* Get device maximum zone append data transfer size in logical blocks.
*

View File

@ -35,7 +35,7 @@ SPDK_ROOT_DIR := $(abspath $(CURDIR)/../..)
include $(SPDK_ROOT_DIR)/mk/spdk.common.mk
SO_VER := 8
SO_MINOR := 0
SO_MINOR := 1
ifeq ($(CONFIG_VTUNE),y)
CFLAGS += -I$(CONFIG_VTUNE_DIR)/include -I$(CONFIG_VTUNE_DIR)/sdk/src/ittnotify

View File

@ -35,6 +35,7 @@
#include "spdk/bdev_zone.h"
#include "spdk/bdev_module.h"
#include "spdk/likely.h"
#include "bdev_internal.h"
@ -50,6 +51,22 @@ spdk_bdev_get_num_zones(const struct spdk_bdev *bdev)
return bdev->zone_size ? bdev->blockcnt / bdev->zone_size : 0;
}
uint64_t
spdk_bdev_get_zone_id(const struct spdk_bdev *bdev, uint64_t offset_blocks)
{
uint64_t zslba;
if (spdk_likely(spdk_u64_is_pow2(bdev->zone_size))) {
uint64_t zone_mask = bdev->zone_size - 1;
zslba = offset_blocks & ~zone_mask;
} else {
/* integer division */
zslba = (offset_blocks / bdev->zone_size) * bdev->zone_size;
}
return zslba;
}
uint32_t
spdk_bdev_get_max_zone_append_size(const struct spdk_bdev *bdev)
{

View File

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

View File

@ -267,6 +267,19 @@ test_get_num_zones(void)
CU_ASSERT(get_num_zones == 256);
}
static void
test_get_zone_id(void)
{
struct spdk_bdev bdev = {};
uint64_t get_zone_id;
bdev.blockcnt = 1024 * 1024 * 1024;
bdev.zone_size = 1024 * 4096;
get_zone_id = spdk_bdev_get_zone_id(&bdev, 0x800032);
CU_ASSERT(get_zone_id == 0x800000);
}
static void
test_get_max_zone_append_size(void)
{
@ -332,6 +345,7 @@ test_zone_get_operation(void)
{
test_get_zone_size();
test_get_num_zones();
test_get_zone_id();
test_get_max_zone_append_size();
test_get_max_open_zones();
test_get_max_active_zones();