Commit 8031dfe2 authored by Evgeniy Kochetov's avatar Evgeniy Kochetov Committed by Ben Walker
Browse files

bdev/null: Add metadata size option to construct_null_bdev RPC method

parent f1209426
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -43,6 +43,10 @@ can only be deleted.

Metadata support has been added to Null bdev module.

### rpc

Added optional parameter '--md-size'to 'construct_null_bdev' RPC method.

## v19.07:

### ftl
+4 −2
Original line number Diff line number Diff line
@@ -1243,6 +1243,7 @@ name | Optional | string | Bdev name to use
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

### Result

@@ -1255,10 +1256,11 @@ Example request:
~~~
{
  "params": {
    "block_size": 4096,
    "block_size": 4104,
    "num_blocks": 16384,
    "name": "Null0",
    "uuid": "2b6601ba-eada-44fb-9a83-a20eb9eb9e90"
    "uuid": "2b6601ba-eada-44fb-9a83-a20eb9eb9e90",
    "md_size": 8
  },
  "jsonrpc": "2.0",
  "method": "construct_null_bdev",
+1 −0
Original line number Diff line number Diff line
@@ -156,6 +156,7 @@ bdev_null_write_config_json(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, "md_size", bdev->md_len);
	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);
+13 −2
Original line number Diff line number Diff line
@@ -44,6 +44,7 @@ struct rpc_construct_null {
	char *uuid;
	uint64_t num_blocks;
	uint32_t block_size;
	uint32_t md_size;
};

static void
@@ -58,6 +59,7 @@ static const struct spdk_json_object_decoder rpc_construct_null_decoders[] = {
	{"uuid", offsetof(struct rpc_construct_null, uuid), spdk_json_decode_string, true},
	{"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},
};

static void
@@ -70,6 +72,7 @@ spdk_rpc_construct_null_bdev(struct spdk_jsonrpc_request *request,
	struct spdk_uuid decoded_uuid;
	struct spdk_bdev *bdev;
	struct spdk_null_bdev_opts opts = {};
	uint32_t data_block_size;
	int rc = 0;

	if (spdk_json_decode_object(params, rpc_construct_null_decoders,
@@ -81,9 +84,15 @@ spdk_rpc_construct_null_bdev(struct spdk_jsonrpc_request *request,
		goto cleanup;
	}

	if (req.block_size % 512 != 0) {
	if (req.block_size < req.md_size) {
		spdk_jsonrpc_send_error_response_fmt(request, -EINVAL,
						     "Block size %u is not a multiple of 512", req.block_size);
						     "Interleaved metadata size can not be greater than block size");
		goto cleanup;
	}
	data_block_size = req.block_size - req.md_size;
	if (data_block_size % 512 != 0) {
		spdk_jsonrpc_send_error_response_fmt(request, -EINVAL,
						     "Data block size %u is not a multiple of 512", req.block_size);
		goto cleanup;
	}

@@ -106,6 +115,8 @@ spdk_rpc_construct_null_bdev(struct spdk_jsonrpc_request *request,
	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;
	rc = create_null_bdev(&bdev, &opts);
	if (rc) {
		spdk_jsonrpc_send_error_response(request, rc, spdk_strerror(-rc));
+4 −1
Original line number Diff line number Diff line
@@ -260,7 +260,8 @@ if __name__ == "__main__":
                                                num_blocks=num_blocks,
                                                block_size=args.block_size,
                                                name=args.name,
                                                uuid=args.uuid))
                                                uuid=args.uuid,
                                                md_size=args.md_size))

    p = subparsers.add_parser('construct_null_bdev',
                              help='Add a bdev with null backend')
@@ -269,6 +270,8 @@ if __name__ == "__main__":
    p.add_argument(
        'total_size', help='Size of null bdev in MB (int > 0)', type=int)
    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.set_defaults(func=construct_null_bdev)

    def delete_null_bdev(args):
Loading