bdev/null: Add data protection options to construct_null_bdev RPC method

Signed-off-by: Evgeniy Kochetov <evgeniik@mellanox.com>
Signed-off-by: Sasha Kotchubievsky <sashakot@mellanox.com>
Signed-off-by: Alexey Marchuk <alexeymar@mellanox.com>
Change-Id: I9ba8370685630668a577f4ea79334f148d03b37f
Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/464781
Reviewed-by: Jim Harris <james.r.harris@intel.com>
Reviewed-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Reviewed-by: Broadcom SPDK FC-NVMe CI <spdk-ci.pdl@broadcom.com>
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
This commit is contained in:
Evgeniy Kochetov 2019-08-01 08:58:16 +00:00 committed by Jim Harris
parent 65848d0ca2
commit 20aeec560b
6 changed files with 36 additions and 3 deletions

View File

@ -57,6 +57,9 @@ Protection information support has been added to Null bdev module.
Added optional parameter '--md-size'to 'construct_null_bdev' RPC method.
Added optional parameters '--dif-type' and '--dif-is-head-of-md' to 'construct_null_bdev'
RPC method.
## v19.07:
### ftl

View File

@ -1244,6 +1244,8 @@ block_size | Required | number | Block size in bytes
num_blocks | Required | number | Number of blocks
uuid | Optional | string | UUID of new bdev
md_size | Optional | number | Metadata size in bytes
dif_type | Optional | number | Protection information type (0, 1, 2 or 3). Default: 0 - no protection.
dif_is_head_of_md | Optional | boolean | Protection information is in the first 8 bytes of MD. Default: in the last 8 bytes.
### Result
@ -1260,7 +1262,9 @@ Example request:
"num_blocks": 16384,
"name": "Null0",
"uuid": "2b6601ba-eada-44fb-9a83-a20eb9eb9e90",
"md_size": 8
"md_size": 8,
"dif_type": 1,
"dif_is_head_of_md": true
},
"jsonrpc": "2.0",
"method": "construct_null_bdev",

View File

@ -209,6 +209,8 @@ bdev_null_write_config_json(struct spdk_bdev *bdev, struct spdk_json_write_ctx *
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, "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_uuid_fmt_lower(uuid_str, sizeof(uuid_str), &bdev->uuid);
spdk_json_write_named_string(w, "uuid", uuid_str);
spdk_json_write_object_end(w);

View File

@ -45,6 +45,8 @@ struct rpc_construct_null {
uint64_t num_blocks;
uint32_t block_size;
uint32_t md_size;
int32_t dif_type;
bool dif_is_head_of_md;
};
static void
@ -60,6 +62,8 @@ static const struct spdk_json_object_decoder rpc_construct_null_decoders[] = {
{"num_blocks", offsetof(struct rpc_construct_null, num_blocks), spdk_json_decode_uint64},
{"block_size", offsetof(struct rpc_construct_null, block_size), spdk_json_decode_uint32},
{"md_size", offsetof(struct rpc_construct_null, md_size), spdk_json_decode_uint32, true},
{"dif_type", offsetof(struct rpc_construct_null, dif_type), spdk_json_decode_int32, true},
{"dif_is_head_of_md", offsetof(struct rpc_construct_null, dif_is_head_of_md), spdk_json_decode_bool, true},
};
static void
@ -111,12 +115,19 @@ spdk_rpc_construct_null_bdev(struct spdk_jsonrpc_request *request,
uuid = &decoded_uuid;
}
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;
}
opts.name = req.name;
opts.uuid = uuid;
opts.num_blocks = req.num_blocks;
opts.block_size = req.block_size;
opts.md_size = req.md_size;
opts.md_interleave = true;
opts.dif_type = req.dif_type;
opts.dif_is_head_of_md = req.dif_is_head_of_md;
rc = create_null_bdev(&bdev, &opts);
if (rc) {
spdk_jsonrpc_send_error_response(request, rc, spdk_strerror(-rc));

View File

@ -261,7 +261,9 @@ if __name__ == "__main__":
block_size=args.block_size,
name=args.name,
uuid=args.uuid,
md_size=args.md_size))
md_size=args.md_size,
dif_type=args.dif_type,
dif_is_head_of_md=args.dif_is_head_of_md))
p = subparsers.add_parser('construct_null_bdev',
help='Add a bdev with null backend')
@ -272,6 +274,10 @@ if __name__ == "__main__":
p.add_argument('block_size', help='Block size for this bdev', type=int)
p.add_argument('-m', '--md-size', type=int,
help='Metadata size for this bdev. Default 0')
p.add_argument('-t', '--dif-type', type=int, choices=[0, 1, 2, 3],
help='Protection information 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: in the last 8 bytes')
p.set_defaults(func=construct_null_bdev)
def delete_null_bdev(args):

View File

@ -189,7 +189,8 @@ def delete_malloc_bdev(client, name):
return client.call('delete_malloc_bdev', params)
def construct_null_bdev(client, num_blocks, block_size, name, uuid=None, md_size=None):
def construct_null_bdev(client, num_blocks, block_size, name, uuid=None, md_size=None,
dif_type=None, dif_is_head_of_md=None):
"""Construct a null block device.
Args:
@ -198,6 +199,8 @@ def construct_null_bdev(client, num_blocks, block_size, name, uuid=None, md_size
name: name of block device
uuid: UUID of block device (optional)
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)
Returns:
Name of created block device.
@ -208,6 +211,10 @@ def construct_null_bdev(client, num_blocks, block_size, name, uuid=None, md_size
params['uuid'] = uuid
if md_size:
params['md_size'] = md_size
if dif_type:
params['dif_type'] = dif_type
if dif_is_head_of_md:
params['dif_is_head_of_md'] = dif_is_head_of_md
return client.call('construct_null_bdev', params)