bdev/raid: Factor out finding raid bdev from base bdev into a function
This patch tries to clarify the logic of the operation to deconfigure the corresponding raid bdev when a base bdev is removed. Change-Id: Id601049dfa59cd919321d833c2867f40c3ba031b Signed-off-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com> Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/450566 Tested-by: SPDK CI Jenkins <sys_sgci@intel.com> Reviewed-by: Changpeng Liu <changpeng.liu@intel.com> Reviewed-by: Darek Stojaczyk <dariusz.stojaczyk@intel.com>
This commit is contained in:
parent
00b13a7207
commit
e1c9791225
@ -1736,6 +1736,38 @@ raid_bdev_deconfigure(struct raid_bdev *raid_bdev)
|
|||||||
spdk_bdev_unregister(&raid_bdev->bdev, NULL, NULL);
|
spdk_bdev_unregister(&raid_bdev->bdev, NULL, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* brief:
|
||||||
|
* raid_bdev_find_by_base_bdev function finds the raid bdev which has
|
||||||
|
* claimed the base bdev.
|
||||||
|
* params:
|
||||||
|
* base_bdev - pointer to base bdev pointer
|
||||||
|
* _raid_bdev - Referenct to pointer to raid bdev
|
||||||
|
* _base_bdev_slot - Reference to the slot of the base bdev.
|
||||||
|
* returns:
|
||||||
|
* true - if the raid bdev is found.
|
||||||
|
* false - if the raid bdev is not found.
|
||||||
|
*/
|
||||||
|
static bool
|
||||||
|
raid_bdev_find_by_base_bdev(struct spdk_bdev *base_bdev, struct raid_bdev **_raid_bdev,
|
||||||
|
uint16_t *_base_bdev_slot)
|
||||||
|
{
|
||||||
|
struct raid_bdev *raid_bdev;
|
||||||
|
uint16_t i;
|
||||||
|
|
||||||
|
TAILQ_FOREACH(raid_bdev, &g_raid_bdev_list, global_link) {
|
||||||
|
for (i = 0; i < raid_bdev->num_base_bdevs; i++) {
|
||||||
|
if (raid_bdev->base_bdev_info[i].bdev == base_bdev) {
|
||||||
|
*_raid_bdev = raid_bdev;
|
||||||
|
*_base_bdev_slot = i;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* brief:
|
* brief:
|
||||||
* raid_bdev_remove_base_bdev function is called by below layers when base_bdev
|
* raid_bdev_remove_base_bdev function is called by below layers when base_bdev
|
||||||
@ -1750,40 +1782,35 @@ void
|
|||||||
raid_bdev_remove_base_bdev(void *ctx)
|
raid_bdev_remove_base_bdev(void *ctx)
|
||||||
{
|
{
|
||||||
struct spdk_bdev *base_bdev = ctx;
|
struct spdk_bdev *base_bdev = ctx;
|
||||||
struct raid_bdev *raid_bdev;
|
struct raid_bdev *raid_bdev = NULL;
|
||||||
uint16_t i;
|
uint16_t base_bdev_slot = 0;
|
||||||
|
|
||||||
SPDK_DEBUGLOG(SPDK_LOG_BDEV_RAID, "raid_bdev_remove_base_bdev\n");
|
SPDK_DEBUGLOG(SPDK_LOG_BDEV_RAID, "raid_bdev_remove_base_bdev\n");
|
||||||
|
|
||||||
/* Find the raid_bdev which has claimed this base_bdev */
|
/* Find the raid_bdev which has claimed this base_bdev */
|
||||||
TAILQ_FOREACH(raid_bdev, &g_raid_bdev_list, global_link) {
|
if (!raid_bdev_find_by_base_bdev(base_bdev, &raid_bdev, &base_bdev_slot)) {
|
||||||
for (i = 0; i < raid_bdev->num_base_bdevs; i++) {
|
SPDK_ERRLOG("bdev to remove '%s' not found\n", base_bdev->name);
|
||||||
if (raid_bdev->base_bdev_info[i].bdev == base_bdev) {
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
assert(raid_bdev->base_bdev_info[i].desc);
|
assert(raid_bdev->base_bdev_info[base_bdev_slot].desc);
|
||||||
raid_bdev->base_bdev_info[i].remove_scheduled = true;
|
raid_bdev->base_bdev_info[base_bdev_slot].remove_scheduled = true;
|
||||||
|
|
||||||
if (raid_bdev->destruct_called == true ||
|
if (raid_bdev->destruct_called == true ||
|
||||||
raid_bdev->state == RAID_BDEV_STATE_CONFIGURING) {
|
raid_bdev->state == RAID_BDEV_STATE_CONFIGURING) {
|
||||||
/*
|
/*
|
||||||
* As raid bdev is not registered yet or already unregistered,
|
* As raid bdev is not registered yet or already unregistered,
|
||||||
* so cleanup should be done here itself.
|
* so cleanup should be done here itself.
|
||||||
*/
|
*/
|
||||||
raid_bdev_free_base_bdev_resource(raid_bdev, i);
|
raid_bdev_free_base_bdev_resource(raid_bdev, base_bdev_slot);
|
||||||
if (raid_bdev->num_base_bdevs_discovered == 0) {
|
if (raid_bdev->num_base_bdevs_discovered == 0) {
|
||||||
/* There is no base bdev for this raid, so free the raid device. */
|
/* There is no base bdev for this raid, so free the raid device. */
|
||||||
raid_bdev_cleanup(raid_bdev);
|
raid_bdev_cleanup(raid_bdev);
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
raid_bdev_deconfigure(raid_bdev);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SPDK_ERRLOG("bdev to remove '%s' not found\n", base_bdev->name);
|
raid_bdev_deconfigure(raid_bdev);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
Loading…
Reference in New Issue
Block a user