Commit 84918cd9 authored by Daniel Verkamp's avatar Daniel Verkamp Committed by Jim Harris
Browse files

bdev/null: allow user to override UUID



Change-Id: I2fe5eb46d5e5b67451b472b82cde69e3606c6235
Signed-off-by: default avatarDaniel Verkamp <daniel.verkamp@intel.com>
Reviewed-on: https://review.gerrithub.io/403222


Reviewed-by: default avatarJim Harris <james.r.harris@intel.com>
Tested-by: default avatarSPDK Automated Test System <sys_sgsw@intel.com>
Reviewed-by: default avatarShuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
parent eca9ac03
Loading
Loading
Loading
Loading
+8 −3
Original line number Diff line number Diff line
@@ -127,7 +127,8 @@ static const struct spdk_bdev_fn_table null_fn_table = {
};

struct spdk_bdev *
create_null_bdev(const char *name, uint64_t num_blocks, uint32_t block_size)
create_null_bdev(const char *name, const struct spdk_uuid *uuid,
		 uint64_t num_blocks, uint32_t block_size)
{
	struct null_bdev *bdev;
	int rc;
@@ -158,7 +159,11 @@ create_null_bdev(const char *name, uint64_t num_blocks, uint32_t block_size)
	bdev->bdev.write_cache = 0;
	bdev->bdev.blocklen = block_size;
	bdev->bdev.blockcnt = num_blocks;
	if (uuid) {
		bdev->bdev.uuid = *uuid;
	} else {
		spdk_uuid_generate(&bdev->bdev.uuid);
	}

	bdev->bdev.ctxt = bdev;
	bdev->bdev.fn_table = &null_fn_table;
@@ -281,7 +286,7 @@ bdev_null_initialize(void)

		num_blocks = size_in_mb * (1024 * 1024) / block_size;

		bdev = create_null_bdev(name, num_blocks, block_size);
		bdev = create_null_bdev(name, NULL, num_blocks, block_size);
		if (bdev == NULL) {
			SPDK_ERRLOG("Could not create null bdev\n");
			rc = EINVAL;
+3 −1
Original line number Diff line number Diff line
@@ -37,7 +37,9 @@
#include "spdk/stdinc.h"

struct spdk_bdev;
struct spdk_uuid;

struct spdk_bdev *create_null_bdev(const char *name, uint64_t num_blocks, uint32_t block_size);
struct spdk_bdev *create_null_bdev(const char *name, const struct spdk_uuid *uuid,
				   uint64_t num_blocks, uint32_t block_size);

#endif /* SPDK_BDEV_NULL_H */
+12 −1
Original line number Diff line number Diff line
@@ -41,12 +41,14 @@

struct rpc_construct_null {
	char *name;
	char *uuid;
	uint32_t num_blocks;
	uint32_t block_size;
};

static const struct spdk_json_object_decoder rpc_construct_null_decoders[] = {
	{"name", offsetof(struct rpc_construct_null, name), spdk_json_decode_string},
	{"uuid", offsetof(struct rpc_construct_null, uuid), spdk_json_decode_string, true},
	{"num_blocks", offsetof(struct rpc_construct_null, num_blocks), spdk_json_decode_uint32},
	{"block_size", offsetof(struct rpc_construct_null, block_size), spdk_json_decode_uint32},
};
@@ -57,6 +59,8 @@ spdk_rpc_construct_null_bdev(struct spdk_jsonrpc_request *request,
{
	struct rpc_construct_null req = {};
	struct spdk_json_write_ctx *w;
	struct spdk_uuid *uuid = NULL;
	struct spdk_uuid decoded_uuid;
	struct spdk_bdev *bdev;

	if (spdk_json_decode_object(params, rpc_construct_null_decoders,
@@ -66,7 +70,14 @@ spdk_rpc_construct_null_bdev(struct spdk_jsonrpc_request *request,
		goto invalid;
	}

	bdev = create_null_bdev(req.name, req.num_blocks, req.block_size);
	if (req.uuid) {
		if (spdk_uuid_parse(&decoded_uuid, req.uuid)) {
			goto invalid;
		}
		uuid = &decoded_uuid;
	}

	bdev = create_null_bdev(req.name, uuid, req.num_blocks, req.block_size);
	if (bdev == NULL) {
		goto invalid;
	}
+1 −0
Original line number Diff line number Diff line
@@ -41,6 +41,7 @@ if __name__ == "__main__":
    p = subparsers.add_parser('construct_null_bdev',
                              help='Add a bdev with null backend')
    p.add_argument('name', help='Block device name')
    p.add_argument('-u', '--uuid', help='UUID of the bdev')
    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)
+2 −0
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@ def construct_null_bdev(args):
    num_blocks = (args.total_size * 1024 * 1024) / args.block_size
    params = {'name': args.name, 'num_blocks': num_blocks,
              'block_size': args.block_size}
    if args.uuid:
        params['uuid'] = args.uuid
    print_array(args.client.call(
        'construct_null_bdev', params))