Commit d2407f06 authored by Shuhei Matsumoto's avatar Shuhei Matsumoto Committed by Tomasz Zawadzki
Browse files

bdev/null: Delegate or remove DIF config check of bdev_null_create RPC



NULL bdev module supports only interleaved metadata. opts->block_size is
data block size. Hence, comparing opts->block_size and opts->md_size was
a long check. Remove it.

Checking if opts->num_blocks is non-zero was duplicated.

As same as malloc bdev, we can move opts->physical_block_size check to
bdev_null_create().

We can delegate DIF type check to spdk_dif_ctx_init().

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


Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: default avatarJim Harris <jim.harris@samsung.com>
Reviewed-by: default avatarAleksey Marchuk <alexeymar@nvidia.com>
Community-CI: Mellanox Build Bot
parent 36943038
Loading
Loading
Loading
Loading
+38 −0
Original line number Diff line number Diff line
@@ -235,6 +235,30 @@ static const struct spdk_bdev_fn_table null_fn_table = {
	.write_config_json	= bdev_null_write_config_json,
};

/* Use a dummy DIF context to validate DIF configuration of the
 * craeted bdev.
 */
static int
_bdev_validate_dif_config(struct spdk_bdev *bdev)
{
	struct spdk_dif_ctx dif_ctx;
	struct spdk_dif_ctx_init_ext_opts dif_opts;

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

	return spdk_dif_ctx_init(&dif_ctx,
				 bdev->blocklen,
				 bdev->md_len,
				 true,
				 bdev->dif_is_head_of_md,
				 bdev->dif_type,
				 bdev->dif_check_flags,
				 SPDK_DIF_REFTAG_IGNORE,
				 0xFFFF, SPDK_DIF_APPTAG_IGNORE,
				 0, 0, &dif_opts);
}

int
bdev_null_create(struct spdk_bdev **bdev, const struct null_bdev_opts *opts)
{
@@ -265,6 +289,11 @@ bdev_null_create(struct spdk_bdev **bdev, const struct null_bdev_opts *opts)
		return -EINVAL;
	}

	if (opts->physical_block_size % 512 != 0) {
		SPDK_ERRLOG("Physical block must be 512 bytes aligned\n");
		return -EINVAL;
	}

	block_size = opts->block_size + opts->md_size;

	if (opts->num_blocks == 0) {
@@ -311,6 +340,15 @@ bdev_null_create(struct spdk_bdev **bdev, const struct null_bdev_opts *opts)
	}
	null_disk->bdev.dif_pi_format = SPDK_DIF_PI_FORMAT_16;

	if (opts->dif_type != SPDK_DIF_DISABLE) {
		rc = _bdev_validate_dif_config(&null_disk->bdev);
		if (rc != 0) {
			SPDK_ERRLOG("DIF configuration was wrong\n");
			free(null_disk);
			return -EINVAL;
		}
	}

	if (!spdk_uuid_is_null(&opts->uuid)) {
		spdk_uuid_copy(&null_disk->bdev.uuid, &opts->uuid);
	}
+0 −34
Original line number Diff line number Diff line
@@ -46,40 +46,6 @@ rpc_bdev_null_create(struct spdk_jsonrpc_request *request,
		goto cleanup;
	}

	if (req.block_size < req.md_size) {
		spdk_jsonrpc_send_error_response_fmt(request, -EINVAL,
						     "Interleaved metadata size can not be greater than block size");
		goto cleanup;
	}

	if (req.block_size % 512 != 0) {
		spdk_jsonrpc_send_error_response_fmt(request, -EINVAL,
						     "Data block size %u is not a multiple of 512", req.block_size);
		goto cleanup;
	}

	if (req.physical_block_size % 512 != 0) {
		spdk_jsonrpc_send_error_response_fmt(request, -EINVAL,
						     "Physical block size %u is not a multiple of 512", req.physical_block_size);
	}

	if (req.num_blocks == 0) {
		spdk_jsonrpc_send_error_response(request, -EINVAL,
						 "Disk num_blocks must be greater than 0");
		goto cleanup;
	}

	if (req.dif_type < SPDK_DIF_DISABLE || req.dif_type > SPDK_DIF_TYPE3) {
		spdk_jsonrpc_send_error_response(request, -EINVAL, "Invalid protection information type");
		goto cleanup;
	}

	if (req.dif_type != SPDK_DIF_DISABLE && !req.md_size) {
		spdk_jsonrpc_send_error_response(request, -EINVAL,
						 "Interleaved metadata size should be set for DIF");
		goto cleanup;
	}

	rc = bdev_null_create(&bdev, &req);
	if (rc) {
		spdk_jsonrpc_send_error_response(request, rc, spdk_strerror(-rc));