From 0f7080e779031dc4bcbcd290f0e39568bab216ac Mon Sep 17 00:00:00 2001 From: Konrad Sztyber Date: Wed, 19 Jun 2019 11:04:46 +0200 Subject: [PATCH] lib/ftl: helper function to check for nv_cache Added ftl_dev_has_nv_cache to check if the FTL is configured to use non-volatile cache or not. It makes these checks a bit more readable. Change-Id: I0140df184d89a675e40bd5056718cd64301c553e Signed-off-by: Konrad Sztyber Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/459617 Tested-by: SPDK CI Jenkins Reviewed-by: Ben Walker Reviewed-by: Wojciech Malikowski Reviewed-by: Darek Stojaczyk Reviewed-by: Mateusz Kozlowski --- lib/ftl/ftl_core.c | 4 ++-- lib/ftl/ftl_core.h | 6 ++++++ lib/ftl/ftl_init.c | 6 +++--- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/lib/ftl/ftl_core.c b/lib/ftl/ftl_core.c index 03c3c55f6..d4934aae7 100644 --- a/lib/ftl/ftl_core.c +++ b/lib/ftl/ftl_core.c @@ -218,7 +218,7 @@ ftl_md_write_cb(struct ftl_io *io, void *arg, int status) ftl_band_set_next_state(band); if (band->state == FTL_BAND_STATE_CLOSED) { - if (nv_cache->bdev_desc) { + if (ftl_dev_has_nv_cache(dev)) { pthread_spin_lock(&nv_cache->lock); nv_cache->num_available += ftl_band_user_lbks(band); @@ -1653,7 +1653,7 @@ ftl_rwb_fill(struct ftl_io *io) } if (ftl_io_done(io)) { - if (dev->nv_cache.bdev_desc && !(io->flags & FTL_IO_BYPASS_CACHE)) { + if (ftl_dev_has_nv_cache(dev) && !(io->flags & FTL_IO_BYPASS_CACHE)) { ftl_write_nv_cache(io); } else { ftl_io_complete(io); diff --git a/lib/ftl/ftl_core.h b/lib/ftl/ftl_core.h index 5997d14dc..18602caa7 100644 --- a/lib/ftl/ftl_core.h +++ b/lib/ftl/ftl_core.h @@ -491,6 +491,12 @@ ftl_vld_map_size(const struct spdk_ftl_dev *dev) return (size_t)spdk_divide_round_up(ftl_num_band_lbks(dev), CHAR_BIT); } +static inline bool +ftl_dev_has_nv_cache(const struct spdk_ftl_dev *dev) +{ + return dev->nv_cache.bdev_desc != NULL; +} + #define FTL_NV_CACHE_HEADER_VERSION (1) #define FTL_NV_CACHE_DATA_OFFSET (1) #define FTL_NV_CACHE_PHASE_OFFSET (62) diff --git a/lib/ftl/ftl_init.c b/lib/ftl/ftl_init.c index 04eda9c0f..e440955b8 100644 --- a/lib/ftl/ftl_init.c +++ b/lib/ftl/ftl_init.c @@ -955,7 +955,7 @@ ftl_setup_initial_state(struct spdk_ftl_dev *dev) return -1; } - if (!nv_cache->bdev_desc) { + if (!ftl_dev_has_nv_cache(dev)) { ftl_init_complete(dev); } else { ioch = spdk_io_channel_get_ctx(dev->ioch); @@ -1001,7 +1001,7 @@ ftl_restore_device_cb(struct spdk_ftl_dev *dev, struct ftl_restore *restore, int return; } - if (!dev->nv_cache.bdev_desc) { + if (!ftl_dev_has_nv_cache(dev)) { ftl_init_complete(dev); return; } @@ -1067,7 +1067,7 @@ ftl_io_channel_create_cb(void *io_device, void *ctx) return -1; } - if (dev->nv_cache.bdev_desc) { + if (ftl_dev_has_nv_cache(dev)) { ioch->cache_ioch = spdk_bdev_get_io_channel(dev->nv_cache.bdev_desc); if (!ioch->cache_ioch) { SPDK_ERRLOG("Failed to create cache IO channel\n");