From d974bad6fc195c89c5da55240a4f000df8b1fb09 Mon Sep 17 00:00:00 2001 From: Artur Paszkiewicz Date: Tue, 21 Jun 2022 13:03:44 +0200 Subject: [PATCH] =?UTF-8?q?ftl:=20retrieve=20device=E2=80=99s=20attributes?= =?UTF-8?q?=20and=20configuration?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Artur Paszkiewicz Signed-off-by: Kozlowski Mateusz Change-Id: Ide6bb24d2c1ec2b0da3f20ce4013a4cd6e339114 Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/13297 Community-CI: Mellanox Build Bot Tested-by: SPDK CI Jenkins Reviewed-by: Jim Harris Reviewed-by: Ben Walker Reviewed-by: Konrad Sztyber --- include/spdk/ftl.h | 29 +++++++++++++++++++++++++++++ lib/ftl/ftl_core.c | 10 ++++++++++ lib/ftl/ftl_core.h | 12 ++++++++++++ lib/ftl/spdk_ftl.map | 2 ++ lib/ftl/utils/ftl_conf.c | 6 ++++++ 5 files changed, 59 insertions(+) diff --git a/include/spdk/ftl.h b/include/spdk/ftl.h index f30700b5f..877c29818 100644 --- a/include/spdk/ftl.h +++ b/include/spdk/ftl.h @@ -48,6 +48,19 @@ enum spdk_ftl_mode { SPDK_FTL_MODE_CREATE = (1 << 0), }; +struct spdk_ftl_attrs { + /* Number of logical blocks */ + uint64_t num_blocks; + /* Logical block size */ + uint64_t block_size; + /* Number of zones in the underlying device (including any offline ones) */ + uint64_t num_zones; + /* Number of logical blocks per zone */ + uint64_t zone_size; + /* Optimal IO size - bdev layer will split requests over this size */ + uint64_t optimum_io_size; +}; + typedef void (*spdk_ftl_fn)(void *cb_arg, int status); typedef void (*spdk_ftl_init_fn)(struct spdk_ftl_dev *dev, void *cb_arg, int status); @@ -74,6 +87,22 @@ int spdk_ftl_dev_init(const struct spdk_ftl_conf *conf, spdk_ftl_init_fn cb, voi */ int spdk_ftl_dev_free(struct spdk_ftl_dev *dev, spdk_ftl_fn cb, void *cb_arg); +/** + * Retrieve device’s attributes. + * + * \param dev device + * \param attr Attribute structure to fill + */ +void spdk_ftl_dev_get_attrs(const struct spdk_ftl_dev *dev, struct spdk_ftl_attrs *attr); + +/** + * Retrieve device’s configuration. + * + * \param dev device + * \param conf FTL configuration structure to fill + */ +void spdk_ftl_dev_get_conf(const struct spdk_ftl_dev *dev, struct spdk_ftl_conf *conf); + /** * Initialize FTL configuration structure with default values. * diff --git a/lib/ftl/ftl_core.c b/lib/ftl/ftl_core.c index ffe9c22d0..81f885d19 100644 --- a/lib/ftl/ftl_core.c +++ b/lib/ftl/ftl_core.c @@ -17,4 +17,14 @@ #include "ftl_internal.h" #include "mngt/ftl_mngt.h" +void +spdk_ftl_dev_get_attrs(const struct spdk_ftl_dev *dev, struct spdk_ftl_attrs *attrs) +{ + attrs->num_blocks = dev->num_lbas; + attrs->block_size = FTL_BLOCK_SIZE; + attrs->num_zones = ftl_get_num_zones(dev); + attrs->zone_size = ftl_get_num_blocks_in_zone(dev); + attrs->optimum_io_size = dev->xfer_size; +} + SPDK_LOG_REGISTER_COMPONENT(ftl_core) diff --git a/lib/ftl/ftl_core.h b/lib/ftl/ftl_core.h index 964cb34bf..734a86a65 100644 --- a/lib/ftl/ftl_core.h +++ b/lib/ftl/ftl_core.h @@ -122,4 +122,16 @@ ftl_get_write_unit_size(struct spdk_bdev *bdev) return 32; } +static inline size_t +ftl_get_num_bands(const struct spdk_ftl_dev *dev) +{ + return dev->num_bands; +} + +static inline size_t +ftl_get_num_zones(const struct spdk_ftl_dev *dev) +{ + return ftl_get_num_bands(dev) * ftl_get_num_zones_in_band(dev); +} + #endif /* FTL_CORE_H */ diff --git a/lib/ftl/spdk_ftl.map b/lib/ftl/spdk_ftl.map index 0f2ee71cf..98ed555e5 100644 --- a/lib/ftl/spdk_ftl.map +++ b/lib/ftl/spdk_ftl.map @@ -5,6 +5,8 @@ spdk_ftl_dev_init; spdk_ftl_dev_free; spdk_ftl_get_default_conf; + spdk_ftl_dev_get_attrs; + spdk_ftl_dev_get_conf; local: *; }; diff --git a/lib/ftl/utils/ftl_conf.c b/lib/ftl/utils/ftl_conf.c index 7cfd54b31..35c3506f0 100644 --- a/lib/ftl/utils/ftl_conf.c +++ b/lib/ftl/utils/ftl_conf.c @@ -20,6 +20,12 @@ spdk_ftl_get_default_conf(struct spdk_ftl_conf *conf) *conf = g_default_conf; } +void +spdk_ftl_dev_get_conf(const struct spdk_ftl_dev *dev, struct spdk_ftl_conf *conf) +{ + *conf = dev->conf; +} + int ftl_conf_cpy(struct spdk_ftl_conf *dst, const struct spdk_ftl_conf *src) {