From b39b6024b5d81e345e8f62c784a1f64f9bf3bc4d Mon Sep 17 00:00:00 2001 From: Shuhei Matsumoto Date: Tue, 21 Aug 2018 11:05:24 +0900 Subject: [PATCH] bdev/raid: Refactor helper function check_and_remove_raid_bdev() Other helper functions raid_bdev_free_base_bdev_resource() and raid_bdev_cleanup() can be used in check_and_remove_raid_bdev(). Change-Id: I24ce02371f5bb29c3b6111da4475a9ad08e65c21 Signed-off-by: Shuhei Matsumoto Reviewed-on: https://review.gerrithub.io/422794 Tested-by: SPDK CI Jenkins Chandler-Test-Pool: SPDK Automated Test System Reviewed-by: Kunal Sablok Reviewed-by: Ben Walker Reviewed-by: Jim Harris --- lib/bdev/raid/bdev_raid.c | 4 ++-- lib/bdev/raid/bdev_raid.h | 2 ++ lib/bdev/raid/bdev_raid_rpc.c | 15 ++------------- 3 files changed, 6 insertions(+), 15 deletions(-) diff --git a/lib/bdev/raid/bdev_raid.c b/lib/bdev/raid/bdev_raid.c index 09229312a..6efa84dc0 100644 --- a/lib/bdev/raid/bdev_raid.c +++ b/lib/bdev/raid/bdev_raid.c @@ -159,7 +159,7 @@ raid_bdev_destroy_cb(void *io_device, void *ctx_buf) * returns: * none */ -static void +void raid_bdev_cleanup(struct raid_bdev *raid_bdev) { SPDK_DEBUGLOG(SPDK_LOG_BDEV_RAID, "raid_bdev_cleanup, %p name %s, state %u, config %p\n", @@ -194,7 +194,7 @@ raid_bdev_cleanup(struct raid_bdev *raid_bdev) * 0 - success * non zero - failure */ -static void +void raid_bdev_free_base_bdev_resource(struct raid_bdev *raid_bdev, uint32_t base_bdev_slot) { struct raid_base_bdev_info *info; diff --git a/lib/bdev/raid/bdev_raid.h b/lib/bdev/raid/bdev_raid.h index 4652fb07a..322a5b39e 100644 --- a/lib/bdev/raid/bdev_raid.h +++ b/lib/bdev/raid/bdev_raid.h @@ -217,6 +217,8 @@ extern struct raid_config g_spdk_raid_config; void raid_bdev_remove_base_bdev(void *ctx); int raid_bdev_add_base_device(struct spdk_bdev *bdev); +void raid_bdev_free_base_bdev_resource(struct raid_bdev *raid_bdev, uint32_t slot); +void raid_bdev_cleanup(struct raid_bdev *raid_bdev); int raid_bdev_config_add(const char *raid_name, int strip_size, int num_base_bdevs, int raid_level, struct raid_bdev_config **_raid_cfg); int raid_bdev_config_add_base_bdev(struct raid_bdev_config *raid_cfg, diff --git a/lib/bdev/raid/bdev_raid_rpc.c b/lib/bdev/raid/bdev_raid_rpc.c index f9d0a25ad..8f4c570dd 100644 --- a/lib/bdev/raid/bdev_raid_rpc.c +++ b/lib/bdev/raid/bdev_raid_rpc.c @@ -267,22 +267,11 @@ check_and_remove_raid_bdev(struct raid_bdev_config *raid_cfg) for (uint32_t i = 0; i < raid_bdev->num_base_bdevs; i++) { assert(raid_bdev->base_bdev_info != NULL); if (raid_bdev->base_bdev_info[i].bdev) { - /* Release base bdev related resources */ - spdk_bdev_module_release_bdev(raid_bdev->base_bdev_info[i].bdev); - spdk_bdev_close(raid_bdev->base_bdev_info[i].desc); - raid_bdev->base_bdev_info[i].desc = NULL; - raid_bdev->base_bdev_info[i].bdev = NULL; - assert(raid_bdev->num_base_bdevs_discovered); - raid_bdev->num_base_bdevs_discovered--; + raid_bdev_free_base_bdev_resource(raid_bdev, i); } } - /* Free raid */ assert(raid_bdev->num_base_bdevs_discovered == 0); - TAILQ_REMOVE(&g_spdk_raid_bdev_configuring_list, raid_bdev, link_specific_list); - TAILQ_REMOVE(&g_spdk_raid_bdev_list, raid_bdev, link_global_list); - free(raid_bdev->base_bdev_info); - free(raid_bdev); - raid_cfg->raid_bdev = NULL; + raid_bdev_cleanup(raid_bdev); } /*