Commit 20aeec56 authored by Evgeniy Kochetov's avatar Evgeniy Kochetov Committed by Jim Harris
Browse files

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

parent 65848d0c
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -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
+5 −1
Original line number Diff line number Diff line
@@ -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",
+2 −0
Original line number Diff line number Diff line
@@ -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);
+11 −0
Original line number Diff line number Diff line
@@ -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));
+7 −1
Original line number Diff line number Diff line
@@ -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):
Loading