diff --git a/lib/bdev/malloc/bdev_malloc.c b/lib/bdev/malloc/bdev_malloc.c index d0223fa4b..a43ba4143 100644 --- a/lib/bdev/malloc/bdev_malloc.c +++ b/lib/bdev/malloc/bdev_malloc.c @@ -346,7 +346,8 @@ static const struct spdk_bdev_fn_table malloc_fn_table = { .get_io_channel = bdev_malloc_get_io_channel, }; -struct spdk_bdev *create_malloc_disk(const char *name, uint64_t num_blocks, uint32_t block_size) +struct spdk_bdev *create_malloc_disk(const char *name, const struct spdk_uuid *uuid, + uint64_t num_blocks, uint32_t block_size) { struct malloc_disk *mdisk; int rc; @@ -396,7 +397,11 @@ struct spdk_bdev *create_malloc_disk(const char *name, uint64_t num_blocks, uint mdisk->disk.write_cache = 1; mdisk->disk.blocklen = block_size; mdisk->disk.blockcnt = num_blocks; - spdk_uuid_generate(&mdisk->disk.uuid); + if (uuid) { + mdisk->disk.uuid = *uuid; + } else { + spdk_uuid_generate(&mdisk->disk.uuid); + } mdisk->disk.ctxt = mdisk; mdisk->disk.fn_table = &malloc_fn_table; @@ -435,7 +440,7 @@ static int bdev_malloc_initialize(void) } size = (uint64_t)LunSizeInMB * 1024 * 1024; for (i = 0; i < NumberOfLuns; i++) { - bdev = create_malloc_disk(NULL, size / BlockSize, BlockSize); + bdev = create_malloc_disk(NULL, NULL, size / BlockSize, BlockSize); if (bdev == NULL) { SPDK_ERRLOG("Could not create malloc disk\n"); rc = EINVAL; diff --git a/lib/bdev/malloc/bdev_malloc.h b/lib/bdev/malloc/bdev_malloc.h index 0462bd148..494594739 100644 --- a/lib/bdev/malloc/bdev_malloc.h +++ b/lib/bdev/malloc/bdev_malloc.h @@ -38,6 +38,7 @@ #include "spdk/bdev.h" -struct spdk_bdev *create_malloc_disk(const char *name, uint64_t num_blocks, uint32_t block_size); +struct spdk_bdev *create_malloc_disk(const char *name, const struct spdk_uuid *uuid, + uint64_t num_blocks, uint32_t block_size); #endif /* SPDK_BDEV_MALLOC_H */ diff --git a/lib/bdev/malloc/bdev_malloc_rpc.c b/lib/bdev/malloc/bdev_malloc_rpc.c index 543e4cf4a..907ed08b2 100644 --- a/lib/bdev/malloc/bdev_malloc_rpc.c +++ b/lib/bdev/malloc/bdev_malloc_rpc.c @@ -34,11 +34,13 @@ #include "bdev_malloc.h" #include "spdk/rpc.h" #include "spdk/util.h" +#include "spdk/uuid.h" #include "spdk_internal/log.h" struct rpc_construct_malloc { char *name; + char *uuid; uint32_t num_blocks; uint32_t block_size; }; @@ -47,10 +49,12 @@ static void free_rpc_construct_malloc(struct rpc_construct_malloc *r) { free(r->name); + free(r->uuid); } static const struct spdk_json_object_decoder rpc_construct_malloc_decoders[] = { {"name", offsetof(struct rpc_construct_malloc, name), spdk_json_decode_string, true}, + {"uuid", offsetof(struct rpc_construct_malloc, uuid), spdk_json_decode_string, true}, {"num_blocks", offsetof(struct rpc_construct_malloc, num_blocks), spdk_json_decode_uint32}, {"block_size", offsetof(struct rpc_construct_malloc, block_size), spdk_json_decode_uint32}, }; @@ -61,6 +65,8 @@ spdk_rpc_construct_malloc_bdev(struct spdk_jsonrpc_request *request, { struct rpc_construct_malloc req = {NULL}; 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_malloc_decoders, @@ -70,7 +76,14 @@ spdk_rpc_construct_malloc_bdev(struct spdk_jsonrpc_request *request, goto invalid; } - bdev = create_malloc_disk(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_malloc_disk(req.name, uuid, req.num_blocks, req.block_size); if (bdev == NULL) { goto invalid; } diff --git a/scripts/rpc.py b/scripts/rpc.py index 597ec50bd..5547e629d 100755 --- a/scripts/rpc.py +++ b/scripts/rpc.py @@ -32,6 +32,7 @@ if __name__ == "__main__": p = subparsers.add_parser('construct_malloc_bdev', help='Add a bdev with malloc backend') p.add_argument('-b', '--name', help="Name of the bdev") + p.add_argument('-u', '--uuid', help="UUID of the bdev") p.add_argument( 'total_size', help='Size of malloc bdev in MB (int > 0)', type=int) p.add_argument('block_size', help='Block size for this bdev', type=int) diff --git a/scripts/rpc/bdev.py b/scripts/rpc/bdev.py index aa70fa3f3..2d8f050e6 100755 --- a/scripts/rpc/bdev.py +++ b/scripts/rpc/bdev.py @@ -6,6 +6,8 @@ def construct_malloc_bdev(args): params = {'num_blocks': num_blocks, 'block_size': args.block_size} if args.name: params['name'] = args.name + if args.uuid: + params['uuid'] = args.uuid print_array(args.client.call( 'construct_malloc_bdev', params))