From 0f1f40deaf152cdf1a5fdf11a37be97be2c0f7d4 Mon Sep 17 00:00:00 2001 From: Maciej Szwed Date: Fri, 24 Nov 2017 14:23:45 +0100 Subject: [PATCH] lvol: add vbdev_get_lvs_bdev_by_bdev() function Signed-off-by: Maciej Szwed Change-Id: Ie7a6513d45652d4a6420ac52b5ded39581d688c6 Reviewed-on: https://review.gerrithub.io/388944 Tested-by: SPDK Automated Test System Reviewed-by: Tomasz Zawadzki Reviewed-by: Jim Harris --- lib/bdev/lvol/vbdev_lvol.c | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/lib/bdev/lvol/vbdev_lvol.c b/lib/bdev/lvol/vbdev_lvol.c index 7e982463d7..63c778c6a0 100644 --- a/lib/bdev/lvol/vbdev_lvol.c +++ b/lib/bdev/lvol/vbdev_lvol.c @@ -62,6 +62,22 @@ vbdev_get_lvs_bdev_by_lvs(struct spdk_lvol_store *lvs_orig) } lvs_bdev = vbdev_lvol_store_next(lvs_bdev); } + + return NULL; +} + +static struct lvol_store_bdev * +vbdev_get_lvs_bdev_by_bdev(struct spdk_bdev *bdev_orig) +{ + struct lvol_store_bdev *lvs_bdev = vbdev_lvol_store_first(); + + while (lvs_bdev != NULL) { + if (lvs_bdev->bdev == bdev_orig) { + return lvs_bdev; + } + lvs_bdev = vbdev_lvol_store_next(lvs_bdev); + } + return NULL; } @@ -69,14 +85,11 @@ static void vbdev_lvs_hotremove_cb(void *ctx) { struct spdk_bdev *bdev = ctx; - struct lvol_store_bdev *lvs_bdev, *tmp; + struct lvol_store_bdev *lvs_bdev; - TAILQ_FOREACH_SAFE(lvs_bdev, &g_spdk_lvol_pairs, lvol_stores, tmp) { - if (lvs_bdev) { - if (lvs_bdev->bdev == bdev) { - vbdev_lvs_unload(lvs_bdev->lvs, NULL, NULL); - } - } + lvs_bdev = vbdev_get_lvs_bdev_by_bdev(bdev); + if (lvs_bdev != NULL) { + vbdev_lvs_unload(lvs_bdev->lvs, NULL, NULL); } }