Commit ca34df98 authored by Shuhei Matsumoto's avatar Shuhei Matsumoto Committed by Jim Harris
Browse files

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: default avatarShuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/450568


Reviewed-by: default avatarChangpeng Liu <changpeng.liu@intel.com>
Reviewed-by: default avatarJim Harris <james.r.harris@intel.com>
Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
parent 2cccea55
Loading
Loading
Loading
Loading
+31 −8
Original line number Diff line number Diff line
@@ -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;
	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);
	}
}