From 264667078184117dfc265fa525276356d0f69f9a Mon Sep 17 00:00:00 2001 From: Wojciech Malikowski Date: Wed, 24 Apr 2019 08:24:39 -0400 Subject: [PATCH] lib/ftl: Added assert checks to ftl_band_set_state() Change-Id: I142ea5be2e5d03b29dc17896fe590a1af798b11f Signed-off-by: Wojciech Malikowski Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/451873 Tested-by: SPDK CI Jenkins Reviewed-by: Darek Stojaczyk Reviewed-by: Shuhei Matsumoto Reviewed-by: Konrad Sztyber --- lib/ftl/ftl_band.c | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/lib/ftl/ftl_band.c b/lib/ftl/ftl_band.c index 23b85bec1..81e0a2a0a 100644 --- a/lib/ftl/ftl_band.c +++ b/lib/ftl/ftl_band.c @@ -185,9 +185,6 @@ _ftl_band_set_free(struct ftl_band *band) struct spdk_ftl_dev *dev = band->dev; struct ftl_band *lband, *prev; - /* Verify band's previous state */ - assert(band->state == FTL_BAND_STATE_CLOSED); - if (band == dev->df_band) { dev->df_band = NULL; } @@ -231,8 +228,6 @@ _ftl_band_set_preparing(struct ftl_band *band) struct spdk_ftl_dev *dev = band->dev; struct ftl_md *md = &band->md; - /* Verify band's previous state */ - assert(band->state == FTL_BAND_STATE_FREE); /* Remove band from free list */ LIST_REMOVE(band, list_entry); @@ -250,11 +245,6 @@ _ftl_band_set_closed(struct ftl_band *band) struct spdk_ftl_dev *dev = band->dev; struct ftl_chunk *chunk; - /* TODO: add this kind of check in band_set_state() */ - if (band->state == FTL_BAND_STATE_CLOSED) { - return; - } - /* Set the state as free_md() checks for that */ band->state = FTL_BAND_STATE_CLOSED; @@ -460,15 +450,20 @@ ftl_band_set_state(struct ftl_band *band, enum ftl_band_state state) { switch (state) { case FTL_BAND_STATE_FREE: + assert(band->state == FTL_BAND_STATE_CLOSED); _ftl_band_set_free(band); break; case FTL_BAND_STATE_PREP: + assert(band->state == FTL_BAND_STATE_FREE); _ftl_band_set_preparing(band); break; case FTL_BAND_STATE_CLOSED: - _ftl_band_set_closed(band); + if (band->state != FTL_BAND_STATE_CLOSED) { + assert(band->state == FTL_BAND_STATE_CLOSING); + _ftl_band_set_closed(band); + } break; default: