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

bdev/null: Make DIF PI format configurable at bdev creation



Make bdev's PI format configurable via the bdev_null_create RPC.
Add the same check as the NVMe specification, for example, metadata
size should not be less than 16 bytes if format is 16/32b Guard PI.

Additionally, add dif_pi_format into write_json_config().

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


Community-CI: Mellanox Build Bot
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>
parent d2407f06
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -221,6 +221,7 @@ bdev_null_write_config_json(struct spdk_bdev *bdev, struct spdk_json_write_ctx *
	spdk_json_write_named_uint32(w, "md_size", bdev->md_len);
	spdk_json_write_named_uint32(w, "dif_type", bdev->dif_type);
	spdk_json_write_named_bool(w, "dif_is_head_of_md", bdev->dif_is_head_of_md);
	spdk_json_write_named_uint32(w, "dif_pi_format", bdev->dif_pi_format);
	spdk_json_write_named_uuid(w, "uuid", &bdev->uuid);
	spdk_json_write_object_end(w);

@@ -338,7 +339,7 @@ bdev_null_create(struct spdk_bdev **bdev, const struct null_bdev_opts *opts)
	case SPDK_DIF_DISABLE:
		break;
	}
	null_disk->bdev.dif_pi_format = SPDK_DIF_PI_FORMAT_16;
	null_disk->bdev.dif_pi_format = opts->dif_pi_format;

	if (opts->dif_type != SPDK_DIF_DISABLE) {
		rc = _bdev_validate_dif_config(&null_disk->bdev);
+1 −0
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ struct null_bdev_opts {
	uint32_t md_size;
	enum spdk_dif_type dif_type;
	bool dif_is_head_of_md;
	enum spdk_dif_pi_format dif_pi_format;
};

int bdev_null_create(struct spdk_bdev **bdev, const struct null_bdev_opts *opts);
+1 −0
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@ static const struct spdk_json_object_decoder rpc_construct_null_decoders[] = {
	{"md_size", offsetof(struct null_bdev_opts, md_size), spdk_json_decode_uint32, true},
	{"dif_type", offsetof(struct null_bdev_opts, dif_type), spdk_json_decode_int32, true},
	{"dif_is_head_of_md", offsetof(struct null_bdev_opts, dif_is_head_of_md), spdk_json_decode_bool, true},
	{"dif_pi_format", offsetof(struct null_bdev_opts, dif_pi_format), spdk_json_decode_uint32, true},
};

static void
+4 −1
Original line number Diff line number Diff line
@@ -301,7 +301,7 @@ def bdev_malloc_delete(client, name):


def bdev_null_create(client, num_blocks, block_size, name, physical_block_size=None, uuid=None, md_size=None,
                     dif_type=None, dif_is_head_of_md=None):
                     dif_type=None, dif_is_head_of_md=None, dif_pi_format=None):
    """Construct a null block device.
    Args:
        num_blocks: size of block device in blocks
@@ -312,6 +312,7 @@ def bdev_null_create(client, num_blocks, block_size, name, physical_block_size=N
        md_size: metadata size of device (optional)
        dif_type: protection information type (optional)
        dif_is_head_of_md: protection information is in the first 8 bytes of metadata (optional)
        dif_pi_format: protection information format (optional)
    Returns:
        Name of created block device.
    """
@@ -329,6 +330,8 @@ def bdev_null_create(client, num_blocks, block_size, name, physical_block_size=N
        params['dif_type'] = dif_type
    if dif_is_head_of_md is not None:
        params['dif_is_head_of_md'] = dif_is_head_of_md
    if dif_pi_format is not None:
        params['dif_pi_format'] = dif_pi_format
    return client.call('bdev_null_create', params)


+5 −1
Original line number Diff line number Diff line
@@ -448,7 +448,8 @@ if __name__ == "__main__":
                                             uuid=args.uuid,
                                             md_size=args.md_size,
                                             dif_type=args.dif_type,
                                             dif_is_head_of_md=args.dif_is_head_of_md))
                                             dif_is_head_of_md=args.dif_is_head_of_md,
                                             dif_pi_format=args.dif_pi_format))

    p = subparsers.add_parser('bdev_null_create', help='Add a bdev with null backend')
    p.add_argument('name', help='Block device name')
@@ -463,6 +464,9 @@ if __name__ == "__main__":
                        'to be set along --dif-type. Default=0 - no protection.')
    p.add_argument('-d', '--dif-is-head-of-md', action='store_true',
                   help='Protection information is in the first 8 bytes of metadata. Default=false.')
    p.add_argument('-f', '--dif-pi-format', type=int, choices=[0, 1, 2],
                   help='Protection infromation format. Parameter --dif-type needs to be set together.'
                        '0=16b Guard PI, 1=32b Guard PI, 2=64b Guard PI. Default=0.')
    p.set_defaults(func=bdev_null_create)

    def bdev_null_delete(args):