malloc_bdev: Add physical block size optional argument

In the past, we didn't use the distinction between logical block size
and physical block size. Now it's possible to optionally set the
physical block size to be different then logical block size. It's useful
for NVMe 512e Advanced Format tests.

Change-Id: I1b596da471031ee90dafc6ba6276cebf769b5ea2
Signed-off-by: Panfil, Wojciech <wojciech.panfil@intel.com>
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/16793
Reviewed-by: Tomasz Zawadzki <tomasz.zawadzki@intel.com>
Reviewed-by: Jacek Kalwas <jacek.kalwas@intel.com>
Reviewed-by: Konrad Sztyber <konrad.sztyber@intel.com>
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
This commit is contained in:
Panfil, Wojciech 2023-02-14 09:12:08 -05:00 committed by Tomasz Zawadzki
parent 7f50da15bc
commit 1eb06bd600
5 changed files with 15 additions and 1 deletions

View File

@ -499,6 +499,7 @@ bdev_malloc_write_json_config(struct spdk_bdev *bdev, struct spdk_json_write_ctx
spdk_json_write_named_string(w, "name", bdev->name);
spdk_json_write_named_uint64(w, "num_blocks", bdev->blockcnt);
spdk_json_write_named_uint32(w, "block_size", bdev->blocklen);
spdk_json_write_named_uint32(w, "physical_block_size", bdev->phys_blocklen);
spdk_uuid_fmt_lower(uuid_str, sizeof(uuid_str), &bdev->uuid);
spdk_json_write_named_string(w, "uuid", uuid_str);
spdk_json_write_named_uint32(w, "optimal_io_boundary", bdev->optimal_io_boundary);
@ -576,6 +577,11 @@ create_malloc_disk(struct spdk_bdev **bdev, const struct malloc_bdev_opts *opts)
return -EINVAL;
}
if (opts->physical_block_size % 512) {
SPDK_ERRLOG("Physical block must be 512 bytes aligned\n");
return -EINVAL;
}
switch (opts->md_size) {
case 0:
case 8:
@ -650,6 +656,7 @@ create_malloc_disk(struct spdk_bdev **bdev, const struct malloc_bdev_opts *opts)
mdisk->disk.write_cache = 1;
mdisk->disk.blocklen = block_size;
mdisk->disk.phys_blocklen = opts->physical_block_size;
mdisk->disk.blockcnt = opts->num_blocks;
mdisk->disk.md_len = opts->md_size;
mdisk->disk.md_interleave = opts->md_interleave;

View File

@ -18,6 +18,7 @@ struct malloc_bdev_opts {
struct spdk_uuid uuid;
uint64_t num_blocks;
uint32_t block_size;
uint32_t physical_block_size;
uint32_t optimal_io_boundary;
uint32_t md_size;
bool md_interleave;

View File

@ -35,6 +35,7 @@ static const struct spdk_json_object_decoder rpc_construct_malloc_decoders[] = {
{"uuid", offsetof(struct malloc_bdev_opts, uuid), decode_mdisk_uuid, true},
{"num_blocks", offsetof(struct malloc_bdev_opts, num_blocks), spdk_json_decode_uint64},
{"block_size", offsetof(struct malloc_bdev_opts, block_size), spdk_json_decode_uint32},
{"physical_block_size", offsetof(struct malloc_bdev_opts, physical_block_size), spdk_json_decode_uint32, true},
{"optimal_io_boundary", offsetof(struct malloc_bdev_opts, optimal_io_boundary), spdk_json_decode_uint32, true},
{"md_size", offsetof(struct malloc_bdev_opts, md_size), spdk_json_decode_uint32, true},
{"md_interleave", offsetof(struct malloc_bdev_opts, md_interleave), spdk_json_decode_bool, true},

View File

@ -268,13 +268,14 @@ def bdev_ocf_flush_status(client, name):
return client.call('bdev_ocf_flush_status', params)
def bdev_malloc_create(client, num_blocks, block_size, name=None, uuid=None, optimal_io_boundary=None,
def bdev_malloc_create(client, num_blocks, block_size, physical_block_size=None, name=None, uuid=None, optimal_io_boundary=None,
md_size=None, md_interleave=None, dif_type=None, dif_is_head_of_md=None):
"""Construct a malloc block device.
Args:
num_blocks: size of block device in blocks
block_size: Data block size of device; must be a power of 2 and at least 512
physical_block_size: Physical block size of device; must be a power of 2 and at least 512 (optional)
name: name of block device (optional)
uuid: UUID of block device (optional)
optimal_io_boundary: Split on optimal IO boundary, in number of blocks, default 0 (disabled, optional)
@ -287,6 +288,8 @@ def bdev_malloc_create(client, num_blocks, block_size, name=None, uuid=None, opt
Name of created block device.
"""
params = {'num_blocks': num_blocks, 'block_size': block_size}
if physical_block_size:
params['physical_block_size'] = physical_block_size
if name:
params['name'] = name
if uuid:

View File

@ -379,6 +379,7 @@ if __name__ == "__main__":
print_json(rpc.bdev.bdev_malloc_create(args.client,
num_blocks=int(num_blocks),
block_size=args.block_size,
physical_block_size=args.physical_block_size,
name=args.name,
uuid=args.uuid,
optimal_io_boundary=args.optimal_io_boundary,
@ -392,6 +393,7 @@ if __name__ == "__main__":
p.add_argument(
'total_size', help='Size of malloc bdev in MB (float > 0)', type=float)
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('-o', '--optimal-io-boundary', help="""Split on optimal IO boundary, in number of
blocks, default 0 (disabled)""", type=int)
p.add_argument('-m', '--md-size', type=int,