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

bdev: Add spdk_dif_ctx and spdk_dif_error into spdk_bdev_io



If the generic bdev layer and the underlying bdev module use T10 DIF APIs
of the accel framework for T10 DIF, DIF context and DIF error structures
must be persistent while executing the APIs.

As a preparation, embed spdk_dif_ctx structure and spdk_dif_error
structure into spdk_bdev_io structure, and initialize both at the start
of the I/O submission if the DIF type of the bdev is not disabled or
no_metadata option is enabled.

These embedded data structure will be able to use for other purposes
too.

Signed-off-by: default avatarShuhei Matsumoto <smatsumoto@nvidia.com>
Change-Id: I4e61222034bb33d4dd862692a878bd283b5d32d4
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/23741


Community-CI: Community CI Samsung <spdk.community.ci.samsung@gmail.com>
Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Community-CI: Broadcom CI <spdk-ci.pdl@broadcom.com>
Reviewed-by: default avatarJim Harris <jim.harris@nvidia.com>
Reviewed-by: default avatarAleksey Marchuk <alexeymar@nvidia.com>
Community-CI: Mellanox Build Bot
parent fb1630bf
Loading
Loading
Loading
Loading
+7 −1
Original line number Diff line number Diff line
@@ -875,6 +875,12 @@ struct spdk_bdev_io_block_params {
		/** Starting source offset (in blocks) of the bdev for copy I/O. */
		uint64_t src_offset_blocks;
	} copy;

	/** DIF context */
	struct spdk_dif_ctx dif_ctx;

	/** DIF error information */
	struct spdk_dif_error dif_err;
};

struct spdk_bdev_io_reset_params {
@@ -1110,7 +1116,7 @@ struct spdk_bdev_io {
		struct spdk_bdev_io_zone_mgmt_params zone_mgmt;
	} u;

	uint64_t reserved3;
	uint8_t reserved3[40];

	/**
	 *  Fields that are used internally by the bdev subsystem.  Bdev modules
+38 −0
Original line number Diff line number Diff line
@@ -1060,6 +1060,12 @@ _are_iovs_aligned(struct iovec *iovs, int iovcnt, uint32_t alignment)
	return true;
}

static inline bool
bdev_io_needs_metadata(struct spdk_bdev_desc *desc, struct spdk_bdev_io *bdev_io)
{
	return desc->opts.hide_metadata && bdev_io->bdev->md_len != 0;
}

static inline bool
bdev_io_needs_sequence_exec(struct spdk_bdev_desc *desc, struct spdk_bdev_io *bdev_io)
{
@@ -3689,6 +3695,28 @@ bdev_io_submit(struct spdk_bdev_io *bdev_io)
	_bdev_io_submit(bdev_io);
}

static inline int
bdev_io_init_dif_ctx(struct spdk_bdev_io *bdev_io)
{
	struct spdk_bdev *bdev = bdev_io->bdev;
	struct spdk_dif_ctx_init_ext_opts dif_opts;

	memset(&bdev_io->u.bdev.dif_err, 0, sizeof(struct spdk_dif_error));

	dif_opts.size = SPDK_SIZEOF(&dif_opts, dif_pi_format);
	dif_opts.dif_pi_format = bdev->dif_pi_format;

	return spdk_dif_ctx_init(&bdev_io->u.bdev.dif_ctx,
				 bdev->blocklen,
				 bdev->md_len,
				 bdev->md_interleave,
				 bdev->dif_is_head_of_md,
				 bdev->dif_type,
				 bdev_io->u.bdev.dif_check_flags,
				 bdev_io->u.bdev.offset_blocks & 0xFFFFFFFF,
				 0xFFFF, 0, 0, 0, &dif_opts);
}

static inline void
_bdev_io_ext_use_bounce_buffer(struct spdk_bdev_io *bdev_io)
{
@@ -3710,6 +3738,7 @@ _bdev_io_submit_ext(struct spdk_bdev_desc *desc, struct spdk_bdev_io *bdev_io)
{
	struct spdk_bdev_channel *ch = bdev_io->internal.ch;
	bool needs_exec = bdev_io_needs_sequence_exec(desc, bdev_io);
	int rc;

	if (spdk_unlikely(ch->flags & BDEV_CH_RESET_IN_PROGRESS)) {
		bdev_io->internal.status = SPDK_BDEV_IO_STATUS_ABORTED;
@@ -3717,6 +3746,15 @@ _bdev_io_submit_ext(struct spdk_bdev_desc *desc, struct spdk_bdev_io *bdev_io)
		return;
	}

	if (bdev_io_needs_metadata(desc, bdev_io)) {
		rc = bdev_io_init_dif_ctx(bdev_io);
		if (spdk_unlikely(rc != 0)) {
			bdev_io->internal.status = SPDK_BDEV_IO_STATUS_FAILED;
			bdev_io_complete_unsubmitted(bdev_io);
			return;
		}
	}

	/* We need to allocate bounce buffer if bdev doesn't support memory domains, or if it does
	 * support them, but we need to execute an accel sequence and the data buffer is from accel
	 * memory domain (to avoid doing a push/pull from that domain).
+32 −0
Original line number Diff line number Diff line
@@ -7740,6 +7740,37 @@ open_ext_v2_test(void)
	free_bdev(bdev);
}

static void
bdev_io_init_dif_ctx_test(void)
{
	struct spdk_bdev *bdev;
	struct spdk_bdev_io bdev_io;
	int rc;

	bdev = allocate_bdev("bdev0");

	/* This is invalid because md_len should be larger than PI size. */
	bdev->dif_pi_format = SPDK_DIF_PI_FORMAT_32;
	bdev->blocklen = 4096 + 8;
	bdev->md_len = 8;
	bdev->md_interleave = true;

	bdev_io.bdev = bdev;

	/* Check if initialization detects error. */
	rc = bdev_io_init_dif_ctx(&bdev_io);
	CU_ASSERT(rc != 0);

	/* Increase md_len to pass initialization check. */
	bdev->blocklen = 4096 + 16;
	bdev->md_len = 16;

	rc = bdev_io_init_dif_ctx(&bdev_io);
	CU_ASSERT(rc == 0);

	free_bdev(bdev);
}

int
main(int argc, char **argv)
{
@@ -7813,6 +7844,7 @@ main(int argc, char **argv)
	CU_ADD_TEST(suite, get_numa_id);
	CU_ADD_TEST(suite, get_device_stat_with_reset);
	CU_ADD_TEST(suite, open_ext_v2_test);
	CU_ADD_TEST(suite, bdev_io_init_dif_ctx_test);

	allocate_cores(1);
	allocate_threads(1);