From 45372c57685d9d13cf76e8c2e94c179f120ad267 Mon Sep 17 00:00:00 2001 From: Konrad Sztyber Date: Tue, 25 Jun 2019 10:43:16 +0200 Subject: [PATCH] lib/ftl: separate non-volatile scrub function The cache needs to be scrubbed during the initial device creation as well as after power loss recovery. This patch extracts the scrubbing code into a separate function. Change-Id: I2cb32e6993a3531470f29f466d990f0d96e45def Signed-off-by: Konrad Sztyber Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/459621 Tested-by: SPDK CI Jenkins Reviewed-by: Ben Walker Reviewed-by: Darek Stojaczyk Reviewed-by: Wojciech Malikowski Reviewed-by: Mateusz Kozlowski --- lib/ftl/ftl_core.c | 15 +++++++++++++++ lib/ftl/ftl_core.h | 2 ++ lib/ftl/ftl_init.c | 10 +--------- 3 files changed, 18 insertions(+), 9 deletions(-) diff --git a/lib/ftl/ftl_core.c b/lib/ftl/ftl_core.c index 4fa50b5fc..7e578fd6b 100644 --- a/lib/ftl/ftl_core.c +++ b/lib/ftl/ftl_core.c @@ -1276,6 +1276,21 @@ ftl_nv_cache_write_header(struct ftl_nv_cache *nv_cache, spdk_bdev_io_completion cb_fn, cb_arg); } +int +ftl_nv_cache_scrub(struct ftl_nv_cache *nv_cache, spdk_bdev_io_completion_cb cb_fn, void *cb_arg) +{ + struct spdk_ftl_dev *dev = SPDK_CONTAINEROF(nv_cache, struct spdk_ftl_dev, nv_cache); + struct ftl_io_channel *ioch; + struct spdk_bdev *bdev; + + ioch = spdk_io_channel_get_ctx(dev->ioch); + bdev = spdk_bdev_desc_get_bdev(nv_cache->bdev_desc); + + return spdk_bdev_write_zeroes_blocks(nv_cache->bdev_desc, ioch->cache_ioch, 1, + spdk_bdev_get_num_blocks(bdev) - 1, + cb_fn, cb_arg); +} + static void ftl_write_fail(struct ftl_io *io, int status) { diff --git a/lib/ftl/ftl_core.h b/lib/ftl/ftl_core.h index 1950b07a2..8803d1b8c 100644 --- a/lib/ftl/ftl_core.h +++ b/lib/ftl/ftl_core.h @@ -296,6 +296,8 @@ bool ftl_ppa_is_written(struct ftl_band *band, struct ftl_ppa ppa); int ftl_flush_active_bands(struct spdk_ftl_dev *dev, spdk_ftl_fn cb_fn, void *cb_arg); int ftl_nv_cache_write_header(struct ftl_nv_cache *nv_cache, spdk_bdev_io_completion_cb cb_fn, void *cb_arg); +int ftl_nv_cache_scrub(struct ftl_nv_cache *nv_cache, spdk_bdev_io_completion_cb cb_fn, + void *cb_arg); #define ftl_to_ppa(addr) \ (struct ftl_ppa) { .ppa = (uint64_t)(addr) } diff --git a/lib/ftl/ftl_init.c b/lib/ftl/ftl_init.c index 7b1cfa451..10ce08e62 100644 --- a/lib/ftl/ftl_init.c +++ b/lib/ftl/ftl_init.c @@ -907,9 +907,6 @@ static int ftl_setup_initial_state(struct spdk_ftl_dev *dev) { struct spdk_ftl_conf *conf = &dev->conf; - struct ftl_nv_cache *nv_cache = &dev->nv_cache; - struct spdk_bdev *bdev; - struct ftl_io_channel *ioch; size_t i; int rc; @@ -935,12 +932,7 @@ ftl_setup_initial_state(struct spdk_ftl_dev *dev) if (!ftl_dev_has_nv_cache(dev)) { ftl_init_complete(dev); } else { - ioch = spdk_io_channel_get_ctx(dev->ioch); - bdev = spdk_bdev_desc_get_bdev(nv_cache->bdev_desc); - - rc = spdk_bdev_write_zeroes_blocks(nv_cache->bdev_desc, ioch->cache_ioch, - 1, spdk_bdev_get_num_blocks(bdev) - 1, - ftl_clear_nv_cache_cb, dev); + rc = ftl_nv_cache_scrub(&dev->nv_cache, ftl_clear_nv_cache_cb, dev); if (spdk_unlikely(rc != 0)) { SPDK_ERRLOG("Unable to clear the non-volatile cache bdev: %s\n", spdk_strerror(-rc));