From 67d027ece90267c02d949de2d7a9c1eaf2c42ded Mon Sep 17 00:00:00 2001 From: Mateusz Kozlowski Date: Tue, 18 Jun 2019 11:18:29 +0200 Subject: [PATCH] lib/ftl: Fix lba_map cleanup during restore Band's lba_map needs to be set to NULL before restore completes, as it's not allocated on a per band basis and instead uses a pool from restore struct itself. Without the fix initializing a band for writing would hit an assert during proper allocation in ftl_band_alloc_lba_map. Signed-off-by: Mateusz Kozlowski Change-Id: Icff4f54cbe722cb6030b9dfd55726b9b0d6c1e27 Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/458422 Reviewed-by: Konrad Sztyber Reviewed-by: Wojciech Malikowski Reviewed-by: Darek Stojaczyk Reviewed-by: Ben Walker Tested-by: SPDK CI Jenkins --- lib/ftl/ftl_restore.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/lib/ftl/ftl_restore.c b/lib/ftl/ftl_restore.c index 257258c65..e269a0537 100644 --- a/lib/ftl/ftl_restore.c +++ b/lib/ftl/ftl_restore.c @@ -353,7 +353,6 @@ ftl_restore_l2p(struct ftl_band *band) ftl_l2p_set(dev, lba, ppa); } - band->lba_map.map = NULL; return 0; } @@ -505,13 +504,13 @@ ftl_restore_pad_band(struct ftl_restore_band *rband) /* Check if some chunks are not closed */ if (ftl_pad_chunk_pad_finish(rband, false)) { - /* If we're here, end meta wasn't recognized, but the whole band is written */ - /* Assume the band was padded and ignore it */ + /* + * If we're here, end meta wasn't recognized, but the whole band is written + * Assume the band was padded and ignore it + */ return; } - /* The LBA map was assigned from restore pool */ - band->lba_map.map = NULL; band->state = FTL_BAND_STATE_OPEN; rc = ftl_band_set_direct_access(band, true); if (rc) { @@ -591,6 +590,13 @@ ftl_restore_tail_md_cb(struct ftl_io *io, void *ctx, int status) return; } + /* + * The LBA map for bands is assigned from ftl_restore->lba_map and needs to be set to NULL + * before successful restore, otherwise ftl_band_alloc_lba_map will fail after + * initialization finalizes. + */ + rband->band->lba_map.map = NULL; + rband = ftl_restore_next_band(restore); if (!rband) { if (!STAILQ_EMPTY(&restore->pad_bands)) {