From 20aeec560b78d480a81d2ab5b19d80432a82285e Mon Sep 17 00:00:00 2001 From: Evgeniy Kochetov Date: Thu, 1 Aug 2019 08:58:16 +0000 Subject: [PATCH] bdev/null: Add data protection options to construct_null_bdev RPC method Signed-off-by: Evgeniy Kochetov Signed-off-by: Sasha Kotchubievsky Signed-off-by: Alexey Marchuk Change-Id: I9ba8370685630668a577f4ea79334f148d03b37f Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/464781 Reviewed-by: Jim Harris Reviewed-by: Shuhei Matsumoto Reviewed-by: Broadcom SPDK FC-NVMe CI Tested-by: SPDK CI Jenkins --- CHANGELOG.md | 3 +++ doc/jsonrpc.md | 6 +++++- module/bdev/null/bdev_null.c | 2 ++ module/bdev/null/bdev_null_rpc.c | 11 +++++++++++ scripts/rpc.py | 8 +++++++- scripts/rpc/bdev.py | 9 ++++++++- 6 files changed, 36 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1be4df117..3ab02a18f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/doc/jsonrpc.md b/doc/jsonrpc.md index 5d2447e86..8236ee0d8 100644 --- a/doc/jsonrpc.md +++ b/doc/jsonrpc.md @@ -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", diff --git a/module/bdev/null/bdev_null.c b/module/bdev/null/bdev_null.c index 96003be6b..2fedafb4b 100644 --- a/module/bdev/null/bdev_null.c +++ b/module/bdev/null/bdev_null.c @@ -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); diff --git a/module/bdev/null/bdev_null_rpc.c b/module/bdev/null/bdev_null_rpc.c index 44583bfb0..3a6835671 100644 --- a/module/bdev/null/bdev_null_rpc.c +++ b/module/bdev/null/bdev_null_rpc.c @@ -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)); diff --git a/scripts/rpc.py b/scripts/rpc.py index 3057b8e47..114aba620 100755 --- a/scripts/rpc.py +++ b/scripts/rpc.py @@ -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): diff --git a/scripts/rpc/bdev.py b/scripts/rpc/bdev.py index ce769222d..ef327c56d 100644 --- a/scripts/rpc/bdev.py +++ b/scripts/rpc/bdev.py @@ -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)