From ca34df98073c1ac120551ddf8b4cff38d9995c47 Mon Sep 17 00:00:00 2001 From: Shuhei Matsumoto Date: Tue, 9 Apr 2019 09:09:12 +0900 Subject: [PATCH] bdev/raid: Get base bdevs from its raid bdev simply in remove_base_devices() This is a preparation to add completion callback to the destroy_raid_bdev RPC. Getting raid bdev from its config and processing base bdevs by using it throughout is much more natural. Checking if base bdev is active can be done by checking if the pointer to the base bdev in base_bdev_info is not NULL. Change-Id: Idd43b13eb342d9cd21ba55943bdcd1f564b3760e Signed-off-by: Shuhei Matsumoto Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/450568 Reviewed-by: Changpeng Liu Reviewed-by: Jim Harris Tested-by: SPDK CI Jenkins --- lib/bdev/raid/bdev_raid.c | 39 +++++++++++++++++++++++++++++++-------- 1 file changed, 31 insertions(+), 8 deletions(-) diff --git a/lib/bdev/raid/bdev_raid.c b/lib/bdev/raid/bdev_raid.c index 5520b39ee..cd445bbc4 100644 --- a/lib/bdev/raid/bdev_raid.c +++ b/lib/bdev/raid/bdev_raid.c @@ -1823,20 +1823,43 @@ raid_bdev_remove_base_bdev(void *ctx) void raid_bdev_remove_base_devices(struct raid_bdev_config *raid_cfg) { - struct spdk_bdev *base_bdev; - uint8_t i; + struct raid_bdev *raid_bdev; + struct raid_base_bdev_info *info; + uint8_t i; SPDK_DEBUGLOG(SPDK_LOG_BDEV_RAID, "raid_bdev_remove_base_devices\n"); - for (i = 0; i < raid_cfg->num_base_bdevs; i++) { - base_bdev = spdk_bdev_get_by_name(raid_cfg->base_bdev[i].name); - if (base_bdev == NULL) { - SPDK_DEBUGLOG(SPDK_LOG_BDEV_RAID, "base bdev %s doesn't exist now\n", - raid_cfg->base_bdev[i].name); + raid_bdev = raid_cfg->raid_bdev; + if (raid_bdev == NULL) { + SPDK_DEBUGLOG(SPDK_LOG_BDEV_RAID, "raid bdev %s doesn't exist now\n", raid_cfg->name); + return; + } + + for (i = 0; i < raid_bdev->num_base_bdevs; i++) { + info = &raid_bdev->base_bdev_info[i]; + + if (info->bdev == NULL) { continue; } - raid_bdev_remove_base_bdev(base_bdev); + assert(info->desc); + info->remove_scheduled = true; + + if (raid_bdev->destruct_called == true || + raid_bdev->state == RAID_BDEV_STATE_CONFIGURING) { + /* + * As raid bdev is not registered yet or already unregistered, + * so cleanup should be done here itself. + */ + raid_bdev_free_base_bdev_resource(raid_bdev, i); + if (raid_bdev->num_base_bdevs_discovered == 0) { + /* There is no base bdev for this raid, so free the raid device. */ + raid_bdev_cleanup(raid_bdev); + return; + } + } + + raid_bdev_deconfigure(raid_bdev); } }