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

raid: alloc sb buffer when configuring the raid bdev



Move the allocation to a later point, when the block size is known. This
will be needed for upcoming patches for interleaved metadata.

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


Community-CI: Mellanox Build Bot
Reviewed-by: default avatarKonrad Sztyber <konrad.sztyber@intel.com>
Reviewed-by: default avatarJim Harris <jim.harris@samsung.com>
Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
parent 3bb8256a
Loading
Loading
Loading
Loading
+18 −20
Original line number Diff line number Diff line
@@ -364,7 +364,7 @@ raid_bdev_cleanup(struct raid_bdev *raid_bdev)
static void
raid_bdev_free(struct raid_bdev *raid_bdev)
{
	spdk_dma_free(raid_bdev->sb);
	raid_bdev_free_superblock(raid_bdev);
	spdk_spin_destroy(&raid_bdev->base_bdev_lock);
	free(raid_bdev->base_bdev_info);
	free(raid_bdev->bdev.name);
@@ -1451,15 +1451,6 @@ _raid_bdev_create(const char *name, uint32_t strip_size, uint8_t num_base_bdevs,
	raid_bdev->min_base_bdevs_operational = min_operational;
	raid_bdev->superblock_enabled = superblock_enabled;

	if (superblock_enabled) {
		raid_bdev->sb = spdk_dma_zmalloc(RAID_BDEV_SB_MAX_LENGTH, 0x1000, NULL);
		if (!raid_bdev->sb) {
			SPDK_ERRLOG("Failed to allocate raid bdev sb buffer\n");
			raid_bdev_free(raid_bdev);
			return -ENOMEM;
		}
	}

	raid_bdev_gen = &raid_bdev->bdev;

	raid_bdev_gen->name = strdup(name);
@@ -1703,11 +1694,11 @@ raid_bdev_configure(struct raid_bdev *raid_bdev)
	}

	if (raid_bdev->superblock_enabled) {
		if (spdk_uuid_is_null(&raid_bdev->sb->uuid)) {
			/* NULL UUID is not valid in the sb so it means that we are creating a new
			 * raid bdev and should initialize the superblock.
			 */
		if (raid_bdev->sb == NULL) {
			rc = raid_bdev_alloc_superblock(raid_bdev, data_block_size);
			if (rc == 0) {
				raid_bdev_init_superblock(raid_bdev);
			}
		} else {
			assert(spdk_uuid_compare(&raid_bdev->sb->uuid, &raid_bdev->bdev.uuid) == 0);
			if (raid_bdev->sb->block_size != data_block_size) {
@@ -1718,13 +1709,14 @@ raid_bdev_configure(struct raid_bdev *raid_bdev)
				SPDK_ERRLOG("blockcnt does not match value in superblock\n");
				rc = -EINVAL;
			}
		}

		if (rc != 0) {
			if (raid_bdev->module->stop != NULL) {
				raid_bdev->module->stop(raid_bdev);
			}
			return rc;
		}
		}

		raid_bdev_write_superblock(raid_bdev, raid_bdev_configure_write_sb_cb, NULL);
	} else {
@@ -3197,6 +3189,12 @@ raid_bdev_create_from_sb(const struct raid_bdev_superblock *sb, struct raid_bdev
		return rc;
	}

	rc = raid_bdev_alloc_superblock(raid_bdev, sb->block_size);
	if (rc != 0) {
		raid_bdev_free(raid_bdev);
		return rc;
	}

	assert(sb->length <= RAID_BDEV_SB_MAX_LENGTH);
	memcpy(raid_bdev->sb, sb, sb->length);

+2 −0
Original line number Diff line number Diff line
@@ -496,6 +496,8 @@ SPDK_STATIC_ASSERT(RAID_BDEV_SB_MAX_LENGTH < RAID_BDEV_MIN_DATA_OFFSET_SIZE,
typedef void (*raid_bdev_write_sb_cb)(int status, struct raid_bdev *raid_bdev, void *ctx);
typedef void (*raid_bdev_load_sb_cb)(const struct raid_bdev_superblock *sb, int status, void *ctx);

int raid_bdev_alloc_superblock(struct raid_bdev *raid_bdev, uint32_t block_size);
void raid_bdev_free_superblock(struct raid_bdev *raid_bdev);
void raid_bdev_init_superblock(struct raid_bdev *raid_bdev);
void raid_bdev_write_superblock(struct raid_bdev *raid_bdev, raid_bdev_write_sb_cb cb,
				void *cb_ctx);
+23 −2
Original line number Diff line number Diff line
@@ -38,6 +38,29 @@ align_ceil(uint64_t val, uint64_t align)
	return spdk_divide_round_up(val, align) * align;
}

int
raid_bdev_alloc_superblock(struct raid_bdev *raid_bdev, uint32_t block_size)
{
	struct raid_bdev_superblock *sb;

	sb = spdk_dma_zmalloc(SPDK_ALIGN_CEIL(RAID_BDEV_SB_MAX_LENGTH, block_size), 0x1000, NULL);
	if (!sb) {
		SPDK_ERRLOG("Failed to allocate raid bdev sb buffer\n");
		return -ENOMEM;
	}

	raid_bdev->sb = sb;

	return 0;
}

void
raid_bdev_free_superblock(struct raid_bdev *raid_bdev)
{
	spdk_dma_free(raid_bdev->sb);
	raid_bdev->sb = NULL;
}

void
raid_bdev_init_superblock(struct raid_bdev *raid_bdev)
{
@@ -45,8 +68,6 @@ raid_bdev_init_superblock(struct raid_bdev *raid_bdev)
	struct raid_base_bdev_info *base_info;
	struct raid_bdev_sb_base_bdev *sb_base_bdev;

	memset(sb, 0, RAID_BDEV_SB_MAX_LENGTH);

	memcpy(&sb->signature, RAID_BDEV_SB_SIG, sizeof(sb->signature));
	sb->version.major = RAID_BDEV_SB_VERSION_MAJOR;
	sb->version.minor = RAID_BDEV_SB_VERSION_MINOR;
+2 −0
Original line number Diff line number Diff line
@@ -128,6 +128,8 @@ DEFINE_STUB(spdk_bdev_get_dif_type, enum spdk_dif_type, (const struct spdk_bdev
DEFINE_STUB(spdk_bdev_is_dif_head_of_md, bool, (const struct spdk_bdev *bdev), false);
DEFINE_STUB(spdk_bdev_notify_blockcnt_change, int, (struct spdk_bdev *bdev, uint64_t size), 0);
DEFINE_STUB_V(raid_bdev_init_superblock, (struct raid_bdev *raid_bdev));
DEFINE_STUB(raid_bdev_alloc_superblock, int, (struct raid_bdev *raid_bdev, uint32_t block_size), 0);
DEFINE_STUB_V(raid_bdev_free_superblock, (struct raid_bdev *raid_bdev));

uint32_t
spdk_bdev_get_data_block_size(const struct spdk_bdev *bdev)