Commit 5558f3f5 authored by Artur Paszkiewicz's avatar Artur Paszkiewicz Committed by Tomasz Zawadzki
Browse files

raid: complete bdev_raid_create after sb is written



If a raid_bdev is created with superblock, raid_bdev_configure() will
not complete synchronously because it issues sb writes. Add a callback
for raid_bdev_configure() and use it to defer the final base bdev
configure callback.

Fixes #3413

Signed-off-by: default avatarArtur Paszkiewicz <artur.paszkiewicz@intel.com>
Change-Id: Ic1e629e80447390656aa3d4c1ac3f120a409be70
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/24216


Community-CI: Mellanox Build Bot
Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: default avatarKonrad Sztyber <konrad.sztyber@intel.com>
Reviewed-by: default avatarTomasz Zawadzki <tomasz.zawadzki@intel.com>
parent d005e023
Loading
Loading
Loading
Loading
+28 −10
Original line number Diff line number Diff line
@@ -1727,7 +1727,7 @@ raid_bdev_configure_cont(struct raid_bdev *raid_bdev)
	if (rc != 0) {
		SPDK_ERRLOG("Failed to register raid bdev '%s': %s\n",
			    raid_bdev_gen->name, spdk_strerror(-rc));
		goto err;
		goto out;
	}

	/*
@@ -1744,14 +1744,14 @@ raid_bdev_configure_cont(struct raid_bdev *raid_bdev)
		SPDK_ERRLOG("Failed to open raid bdev '%s': %s\n",
			    raid_bdev_gen->name, spdk_strerror(-rc));
		spdk_bdev_unregister(raid_bdev_gen, NULL, NULL);
		goto err;
		goto out;
	}

	SPDK_DEBUGLOG(bdev_raid, "raid bdev generic %p\n", raid_bdev_gen);
	SPDK_DEBUGLOG(bdev_raid, "raid bdev is created with name %s, raid_bdev %p\n",
		      raid_bdev_gen->name, raid_bdev);
	return;
err:
out:
	if (rc != 0) {
		if (raid_bdev->module->stop != NULL) {
			raid_bdev->module->stop(raid_bdev);
		}
@@ -1759,6 +1759,12 @@ err:
		raid_bdev->state = RAID_BDEV_STATE_CONFIGURING;
	}

	if (raid_bdev->configure_cb != NULL) {
		raid_bdev->configure_cb(raid_bdev->configure_cb_ctx, rc);
		raid_bdev->configure_cb = NULL;
	}
}

static void
raid_bdev_configure_write_sb_cb(int status, struct raid_bdev *raid_bdev, void *ctx)
{
@@ -1770,6 +1776,10 @@ raid_bdev_configure_write_sb_cb(int status, struct raid_bdev *raid_bdev, void *c
		if (raid_bdev->module->stop != NULL) {
			raid_bdev->module->stop(raid_bdev);
		}
		if (raid_bdev->configure_cb != NULL) {
			raid_bdev->configure_cb(raid_bdev->configure_cb_ctx, status);
			raid_bdev->configure_cb = NULL;
		}
	}
}

@@ -1785,7 +1795,7 @@ raid_bdev_configure_write_sb_cb(int status, struct raid_bdev *raid_bdev, void *c
 * non zero - failure
 */
static int
raid_bdev_configure(struct raid_bdev *raid_bdev)
raid_bdev_configure(struct raid_bdev *raid_bdev, raid_bdev_configure_cb cb, void *cb_ctx)
{
	uint32_t data_block_size = spdk_bdev_get_data_block_size(&raid_bdev->bdev);
	int rc;
@@ -1810,6 +1820,10 @@ raid_bdev_configure(struct raid_bdev *raid_bdev)
		return rc;
	}

	assert(raid_bdev->configure_cb == NULL);
	raid_bdev->configure_cb = cb;
	raid_bdev->configure_cb_ctx = cb_ctx;

	if (raid_bdev->superblock_enabled) {
		if (raid_bdev->sb == NULL) {
			rc = raid_bdev_alloc_superblock(raid_bdev, data_block_size);
@@ -1829,6 +1843,7 @@ raid_bdev_configure(struct raid_bdev *raid_bdev)
		}

		if (rc != 0) {
			raid_bdev->configure_cb = NULL;
			if (raid_bdev->module->stop != NULL) {
				raid_bdev->module->stop(raid_bdev);
			}
@@ -3154,9 +3169,12 @@ raid_bdev_configure_base_bdev_cont(struct raid_base_bdev_info *base_info)
	 * degraded.
	 */
	if (raid_bdev->num_base_bdevs_discovered == raid_bdev->num_base_bdevs_operational) {
		rc = raid_bdev_configure(raid_bdev);
		rc = raid_bdev_configure(raid_bdev,
					 base_info->configure_cb, base_info->configure_cb_ctx);
		if (rc != 0) {
			SPDK_ERRLOG("Failed to configure raid bdev: %s\n", spdk_strerror(-rc));
		} else {
			base_info->configure_cb = NULL;
		}
	} else if (base_info->is_process_target) {
		raid_bdev->num_base_bdevs_operational++;
+6 −0
Original line number Diff line number Diff line
@@ -175,6 +175,8 @@ struct raid_bdev_process_request {
	TAILQ_ENTRY(raid_bdev_process_request) link;
};

typedef void (*raid_bdev_configure_cb)(void *cb_ctx, int rc);

/*
 * raid_bdev is the single entity structure which contains SPDK block device
 * and the information related to any raid bdev either configured or
@@ -242,6 +244,10 @@ struct raid_bdev {

	/* Raid bdev background process, e.g. rebuild */
	struct raid_bdev_process	*process;

	/* Callback and context for raid_bdev configuration */
	raid_bdev_configure_cb		configure_cb;
	void				*configure_cb_ctx;
};

#define RAID_FOR_EACH_BASE_BDEV(r, i) \