Commit a9837c70 authored by Changpeng Liu's avatar Changpeng Liu Committed by Tomasz Zawadzki
Browse files

bdev/null: use the same way as Malloc to create device with metadata



When creating device with metadata, `block_size` means data block
size without including metadata size, this is the same as Malloc
device.  Also check the input metadata size.

Fix #3191.

Change-Id: I8b64e0605de2e42ee053e749720f74706b623835
Signed-off-by: default avatarChangpeng Liu <changpeng.liu@intel.com>
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/20643


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>
Community-CI: Mellanox Build Bot
Reviewed-by: default avatarKarol Latecki <karol.latecki@intel.com>
parent 9f6d41db
Loading
Loading
Loading
Loading
+13 −0
Original line number Diff line number Diff line
@@ -232,6 +232,19 @@ bdev_null_create(struct spdk_bdev **bdev, const struct spdk_null_bdev_opts *opts
		return -EINVAL;
	}

	switch (opts->md_size) {
	case 0:
	case 8:
	case 16:
	case 32:
	case 64:
	case 128:
		break;
	default:
		SPDK_ERRLOG("metadata size %u is not supported\n", opts->md_size);
		return -EINVAL;
	}

	if (opts->md_interleave) {
		if (opts->block_size < opts->md_size) {
			SPDK_ERRLOG("Interleaved metadata size can not be greater than block size.\n");
+3 −4
Original line number Diff line number Diff line
@@ -47,7 +47,6 @@ rpc_bdev_null_create(struct spdk_jsonrpc_request *request,
	struct spdk_json_write_ctx *w;
	struct spdk_bdev *bdev;
	struct spdk_null_bdev_opts opts = {};
	uint32_t data_block_size;
	int rc = 0;

	if (spdk_json_decode_object(params, rpc_construct_null_decoders,
@@ -64,8 +63,8 @@ rpc_bdev_null_create(struct spdk_jsonrpc_request *request,
						     "Interleaved metadata size can not be greater than block size");
		goto cleanup;
	}
	data_block_size = req.block_size - req.md_size;
	if (data_block_size % 512 != 0) {

	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;
@@ -96,7 +95,7 @@ rpc_bdev_null_create(struct spdk_jsonrpc_request *request,
	opts.name = req.name;
	opts.uuid = &req.uuid;
	opts.num_blocks = req.num_blocks;
	opts.block_size = req.block_size;
	opts.block_size = req.block_size + req.md_size;
	opts.physical_block_size = req.physical_block_size;
	opts.md_size = req.md_size;
	opts.md_interleave = true;
+1 −1
Original line number Diff line number Diff line
@@ -1235,7 +1235,7 @@ class SPDKTarget(Target):
        self.log.info("Adding null block bdevices to config via RPC")
        for i in range(null_block_count):
            self.log.info("Setting bdev protection to :%s" % self.null_block_dif_type)
            rpc.bdev.bdev_null_create(self.client, 102400, block_size + md_size, "Nvme{}n1".format(i),
            rpc.bdev.bdev_null_create(self.client, 102400, block_size, "Nvme{}n1".format(i),
                                      dif_type=self.null_block_dif_type, md_size=md_size)
        self.log.info("SPDK Bdevs configuration:")
        rpc_client.print_dict(rpc.bdev.bdev_get_bdevs(self.client))
+1 −2
Original line number Diff line number Diff line
@@ -444,8 +444,7 @@ if __name__ == "__main__":
    p.add_argument('name', help='Block device name')
    p.add_argument('-u', '--uuid', help='UUID of the bdev')
    p.add_argument('total_size', help='Size of null bdev in MB (int > 0). Includes only data blocks.', type=int)
    p.add_argument('block_size', help='Block size for this bdev.'
                                      'Should be a sum of block size and metadata size if --md-size is used.', type=int)
    p.add_argument('block_size', help='Data block size for this bdev.', type=int)
    p.add_argument('-p', '--physical-block-size', help='Physical block size for this bdev.', type=int)
    p.add_argument('-m', '--md-size', type=int,
                   help='Metadata size for this bdev. Default=0.')
+1 −1
Original line number Diff line number Diff line
@@ -12,7 +12,7 @@ set -- "--transport=tcp" "--iso" "$@"
source "$rootdir/test/common/autotest_common.sh"
source "$rootdir/test/nvmf/common.sh"

NULL_META=16 NULL_BLOCK_SIZE=$((512 + NULL_META)) NULL_SIZE=64 NULL_DIF=1
NULL_META=16 NULL_BLOCK_SIZE=512 NULL_SIZE=64 NULL_DIF=1

create_subsystem() {
	local sub_id=${1:-0}