bdev/raid: Factor out configure/deconfigure raid bdev
Change-Id: I92719adee7f4c6256a753de7128ece1bab858638 Signed-off-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com> Reviewed-on: https://review.gerrithub.io/421197 Reviewed-by: Dariusz Stojaczyk <dariuszx.stojaczyk@intel.com> Reviewed-by: Jim Harris <james.r.harris@intel.com> Reviewed-by: Kunal Sablok <kunal.sablok@intel.com> Reviewed-by: Ben Walker <benjamin.walker@intel.com> Tested-by: SPDK CI Jenkins <sys_sgci@intel.com> Chandler-Test-Pool: SPDK Automated Test System <sys_sgsw@intel.com>
This commit is contained in:
parent
15bd396f30
commit
ff3cd4315e
@ -1242,132 +1242,22 @@ raid_bdev_alloc_base_bdev_resource(struct raid_bdev *raid_bdev, struct spdk_bdev
|
||||
|
||||
/*
|
||||
* brief:
|
||||
* raid_bdev_remove_base_bdev function is called by below layers when base_bdev
|
||||
* is removed. This function checks if this base bdev is part of any raid bdev
|
||||
* or not. If yes, it takes necessary action on that particular raid bdev.
|
||||
* If raid bdev config is complete, then only register the raid bdev to
|
||||
* bdev layer and remove this raid bdev from configuring list and
|
||||
* insert the raid bdev to configured list
|
||||
* params:
|
||||
* ctx - pointer to base bdev pointer which got removed
|
||||
* returns:
|
||||
* none
|
||||
*/
|
||||
void
|
||||
raid_bdev_remove_base_bdev(void *ctx)
|
||||
{
|
||||
struct spdk_bdev *base_bdev = ctx;
|
||||
struct raid_bdev *raid_bdev;
|
||||
struct raid_bdev *next_raid_bdev;
|
||||
uint16_t i;
|
||||
bool found = false;
|
||||
|
||||
SPDK_DEBUGLOG(SPDK_LOG_BDEV_RAID, "raid_bdev_remove_base_bdev\n");
|
||||
|
||||
/* Find the raid_bdev which has claimed this base_bdev */
|
||||
TAILQ_FOREACH_SAFE(raid_bdev, &g_spdk_raid_bdev_list, link_global_list, next_raid_bdev) {
|
||||
for (i = 0; i < raid_bdev->num_base_bdevs; i++) {
|
||||
if (raid_bdev->base_bdev_info[i].base_bdev == base_bdev) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (found == true) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (found == false) {
|
||||
SPDK_ERRLOG("bdev to remove '%s' not found\n", base_bdev->name);
|
||||
return;
|
||||
}
|
||||
|
||||
assert(raid_bdev != NULL);
|
||||
assert(raid_bdev->base_bdev_info[i].base_bdev);
|
||||
assert(raid_bdev->base_bdev_info[i].base_bdev_desc);
|
||||
raid_bdev->base_bdev_info[i].base_bdev_remove_scheduled = true;
|
||||
|
||||
if (raid_bdev->destruct_called == true && raid_bdev->base_bdev_info[i].base_bdev != NULL) {
|
||||
/* As raid bdev is 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) {
|
||||
/* Since there is no base bdev for this raid, so free the raid device */
|
||||
raid_bdev_cleanup(raid_bdev);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (raid_bdev->state == RAID_BDEV_STATE_ONLINE) {
|
||||
/*
|
||||
* If raid bdev is online and registered, change the bdev state to
|
||||
* configuring and unregister this raid device. Queue this raid device
|
||||
* in configuring list
|
||||
*/
|
||||
assert(raid_bdev->num_base_bdevs == raid_bdev->num_base_bdevs_discovered);
|
||||
TAILQ_REMOVE(&g_spdk_raid_bdev_configured_list, raid_bdev, link_specific_list);
|
||||
raid_bdev->state = RAID_BDEV_STATE_OFFLINE;
|
||||
assert(raid_bdev->num_base_bdevs_discovered);
|
||||
TAILQ_INSERT_TAIL(&g_spdk_raid_bdev_offline_list, raid_bdev, link_specific_list);
|
||||
SPDK_DEBUGLOG(SPDK_LOG_BDEV_RAID, "raid bdev state chaning from online to offline\n");
|
||||
spdk_io_device_unregister(raid_bdev, NULL);
|
||||
spdk_bdev_unregister(&raid_bdev->bdev, NULL, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* brief:
|
||||
* raid_bdev_add_base_device function is the actual function which either adds
|
||||
* the nvme base device to existing raid bdev or create a new raid bdev. It also claims
|
||||
* the base device and keep the open descriptor.
|
||||
* params:
|
||||
* bdev - pointer to base bdev
|
||||
* raid_bdev - pointer to raid bdev
|
||||
* returns:
|
||||
* 0 - success
|
||||
* non zero - failure
|
||||
*/
|
||||
int
|
||||
raid_bdev_add_base_device(struct spdk_bdev *bdev)
|
||||
static int
|
||||
raid_bdev_configure(struct raid_bdev *raid_bdev)
|
||||
{
|
||||
struct raid_bdev_config *raid_bdev_config = NULL;
|
||||
struct raid_bdev *raid_bdev;
|
||||
struct spdk_bdev *raid_bdev_gen;
|
||||
uint32_t blocklen;
|
||||
uint64_t min_blockcnt;
|
||||
uint32_t base_bdev_slot;
|
||||
bool can_claim;
|
||||
int rc;
|
||||
struct spdk_bdev *raid_bdev_gen;
|
||||
|
||||
SPDK_DEBUGLOG(SPDK_LOG_BDEV_RAID, "raid_bdev_examine %p\n", bdev);
|
||||
|
||||
can_claim = raid_bdev_can_claim_bdev(bdev->name, &raid_bdev_config, &base_bdev_slot);
|
||||
|
||||
if (!can_claim) {
|
||||
SPDK_DEBUGLOG(SPDK_LOG_BDEV_RAID, "bdev %s can't be claimed\n", bdev->name);
|
||||
return -1;
|
||||
}
|
||||
assert(raid_bdev_config);
|
||||
|
||||
raid_bdev = raid_bdev_config->raid_bdev;
|
||||
if (!raid_bdev) {
|
||||
rc = raid_bdev_create(raid_bdev_config, &raid_bdev);
|
||||
if (rc != 0) {
|
||||
SPDK_ERRLOG("Failed to create raid bdev for bdev '%s'\n", bdev->name);
|
||||
return -1;
|
||||
}
|
||||
raid_bdev_config->raid_bdev = raid_bdev;
|
||||
}
|
||||
|
||||
rc = raid_bdev_alloc_base_bdev_resource(raid_bdev, bdev, base_bdev_slot);
|
||||
if (rc != 0) {
|
||||
SPDK_ERRLOG("Failed to allocate resource for bdev '%s'\n", bdev->name);
|
||||
raid_bdev_cleanup(raid_bdev);
|
||||
return -1;
|
||||
}
|
||||
|
||||
assert(raid_bdev->num_base_bdevs_discovered <= raid_bdev->num_base_bdevs);
|
||||
|
||||
if (raid_bdev->num_base_bdevs_discovered == raid_bdev->num_base_bdevs) {
|
||||
/* If raid bdev config is complete, then only register the raid bdev to
|
||||
* bdev layer and remove this raid bdev from configuring list and
|
||||
* insert the raid bdev to configured list
|
||||
*/
|
||||
blocklen = raid_bdev->base_bdev_info[0].base_bdev->blocklen;
|
||||
min_blockcnt = raid_bdev->base_bdev_info[0].base_bdev->blockcnt;
|
||||
for (uint32_t i = 1; i < raid_bdev->num_base_bdevs; i++) {
|
||||
@ -1389,8 +1279,9 @@ raid_bdev_add_base_device(struct spdk_bdev *bdev)
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
raid_bdev_gen = &raid_bdev->bdev;
|
||||
raid_bdev_gen->name = strdup(raid_bdev_config->name);
|
||||
raid_bdev_gen->name = strdup(raid_bdev->raid_bdev_config->name);
|
||||
if (!raid_bdev_gen->name) {
|
||||
SPDK_ERRLOG("Unable to allocate name for raid\n");
|
||||
raid_bdev->state = RAID_BDEV_STATE_OFFLINE;
|
||||
@ -1444,6 +1335,150 @@ raid_bdev_add_base_device(struct spdk_bdev *bdev)
|
||||
SPDK_DEBUGLOG(SPDK_LOG_BDEV_RAID, "raid bdev is created with name %s, raid_bdev %p\n",
|
||||
raid_bdev_gen->name, raid_bdev);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* brief:
|
||||
* If raid bdev is online and registered, change the bdev state to
|
||||
* configuring and unregister this raid device. Queue this raid device
|
||||
* in configuring list
|
||||
* params:
|
||||
* raid_bdev - pointer to raid bdev
|
||||
* returns:
|
||||
* none
|
||||
*/
|
||||
static void
|
||||
raid_bdev_deconfigure(struct raid_bdev *raid_bdev)
|
||||
{
|
||||
if (raid_bdev->state != RAID_BDEV_STATE_ONLINE) {
|
||||
return;
|
||||
}
|
||||
|
||||
assert(raid_bdev->num_base_bdevs == raid_bdev->num_base_bdevs_discovered);
|
||||
TAILQ_REMOVE(&g_spdk_raid_bdev_configured_list, raid_bdev, link_specific_list);
|
||||
raid_bdev->state = RAID_BDEV_STATE_OFFLINE;
|
||||
assert(raid_bdev->num_base_bdevs_discovered);
|
||||
TAILQ_INSERT_TAIL(&g_spdk_raid_bdev_offline_list, raid_bdev, link_specific_list);
|
||||
SPDK_DEBUGLOG(SPDK_LOG_BDEV_RAID, "raid bdev state chaning from online to offline\n");
|
||||
|
||||
spdk_io_device_unregister(raid_bdev, NULL);
|
||||
spdk_bdev_unregister(&raid_bdev->bdev, NULL, NULL);
|
||||
}
|
||||
|
||||
/*
|
||||
* brief:
|
||||
* raid_bdev_remove_base_bdev function is called by below layers when base_bdev
|
||||
* is removed. This function checks if this base bdev is part of any raid bdev
|
||||
* or not. If yes, it takes necessary action on that particular raid bdev.
|
||||
* params:
|
||||
* ctx - pointer to base bdev pointer which got removed
|
||||
* returns:
|
||||
* none
|
||||
*/
|
||||
void
|
||||
raid_bdev_remove_base_bdev(void *ctx)
|
||||
{
|
||||
struct spdk_bdev *base_bdev = ctx;
|
||||
struct raid_bdev *raid_bdev;
|
||||
struct raid_bdev *next_raid_bdev;
|
||||
uint16_t i;
|
||||
bool found = false;
|
||||
|
||||
SPDK_DEBUGLOG(SPDK_LOG_BDEV_RAID, "raid_bdev_remove_base_bdev\n");
|
||||
|
||||
/* Find the raid_bdev which has claimed this base_bdev */
|
||||
TAILQ_FOREACH_SAFE(raid_bdev, &g_spdk_raid_bdev_list, link_global_list, next_raid_bdev) {
|
||||
for (i = 0; i < raid_bdev->num_base_bdevs; i++) {
|
||||
if (raid_bdev->base_bdev_info[i].base_bdev == base_bdev) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (found == true) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (found == false) {
|
||||
SPDK_ERRLOG("bdev to remove '%s' not found\n", base_bdev->name);
|
||||
return;
|
||||
}
|
||||
|
||||
assert(raid_bdev != NULL);
|
||||
assert(raid_bdev->base_bdev_info[i].base_bdev);
|
||||
assert(raid_bdev->base_bdev_info[i].base_bdev_desc);
|
||||
raid_bdev->base_bdev_info[i].base_bdev_remove_scheduled = true;
|
||||
|
||||
if (raid_bdev->destruct_called == true && raid_bdev->base_bdev_info[i].base_bdev != NULL) {
|
||||
/* As raid bdev is 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) {
|
||||
/* Since there is no base bdev for this raid, so free the raid device */
|
||||
raid_bdev_cleanup(raid_bdev);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
raid_bdev_deconfigure(raid_bdev);
|
||||
}
|
||||
|
||||
/*
|
||||
* brief:
|
||||
* raid_bdev_add_base_device function is the actual function which either adds
|
||||
* the nvme base device to existing raid bdev or create a new raid bdev. It also claims
|
||||
* the base device and keep the open descriptor.
|
||||
* params:
|
||||
* bdev - pointer to base bdev
|
||||
* returns:
|
||||
* 0 - success
|
||||
* non zero - failure
|
||||
*/
|
||||
int
|
||||
raid_bdev_add_base_device(struct spdk_bdev *bdev)
|
||||
{
|
||||
struct raid_bdev_config *raid_bdev_config = NULL;
|
||||
struct raid_bdev *raid_bdev;
|
||||
uint32_t base_bdev_slot;
|
||||
bool can_claim;
|
||||
int rc;
|
||||
|
||||
SPDK_DEBUGLOG(SPDK_LOG_BDEV_RAID, "raid_bdev_examine %p\n", bdev);
|
||||
|
||||
can_claim = raid_bdev_can_claim_bdev(bdev->name, &raid_bdev_config, &base_bdev_slot);
|
||||
|
||||
if (!can_claim) {
|
||||
SPDK_DEBUGLOG(SPDK_LOG_BDEV_RAID, "bdev %s can't be claimed\n", bdev->name);
|
||||
return -1;
|
||||
}
|
||||
assert(raid_bdev_config);
|
||||
|
||||
raid_bdev = raid_bdev_config->raid_bdev;
|
||||
if (!raid_bdev) {
|
||||
rc = raid_bdev_create(raid_bdev_config, &raid_bdev);
|
||||
if (rc != 0) {
|
||||
SPDK_ERRLOG("Failed to create raid bdev for bdev '%s'\n", bdev->name);
|
||||
return -1;
|
||||
}
|
||||
raid_bdev_config->raid_bdev = raid_bdev;
|
||||
}
|
||||
|
||||
rc = raid_bdev_alloc_base_bdev_resource(raid_bdev, bdev, base_bdev_slot);
|
||||
if (rc != 0) {
|
||||
SPDK_ERRLOG("Failed to allocate resource for bdev '%s'\n", bdev->name);
|
||||
raid_bdev_cleanup(raid_bdev);
|
||||
return -1;
|
||||
}
|
||||
|
||||
assert(raid_bdev->num_base_bdevs_discovered <= raid_bdev->num_base_bdevs);
|
||||
|
||||
if (raid_bdev->num_base_bdevs_discovered == raid_bdev->num_base_bdevs) {
|
||||
rc = raid_bdev_configure(raid_bdev);
|
||||
if (rc != 0) {
|
||||
SPDK_ERRLOG("Failed to configure raid bdev\n");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
Loading…
Reference in New Issue
Block a user