bdev/malloc: allow user to override UUID

This can be used to force specific UUIDs for testing.

Change-Id: I40c403fd00c142552d632dd5f0fbe1ea9a6c9962
Signed-off-by: Daniel Verkamp <daniel.verkamp@intel.com>
Reviewed-on: https://review.gerrithub.io/403221
Tested-by: SPDK Automated Test System <sys_sgsw@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
Reviewed-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
This commit is contained in:
Daniel Verkamp 2018-03-08 14:35:44 -07:00 committed by Jim Harris
parent f09b9c2ed1
commit eca9ac03e4
5 changed files with 27 additions and 5 deletions

View File

@ -346,7 +346,8 @@ static const struct spdk_bdev_fn_table malloc_fn_table = {
.get_io_channel = bdev_malloc_get_io_channel, .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; struct malloc_disk *mdisk;
int rc; 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.write_cache = 1;
mdisk->disk.blocklen = block_size; mdisk->disk.blocklen = block_size;
mdisk->disk.blockcnt = num_blocks; 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.ctxt = mdisk;
mdisk->disk.fn_table = &malloc_fn_table; mdisk->disk.fn_table = &malloc_fn_table;
@ -435,7 +440,7 @@ static int bdev_malloc_initialize(void)
} }
size = (uint64_t)LunSizeInMB * 1024 * 1024; size = (uint64_t)LunSizeInMB * 1024 * 1024;
for (i = 0; i < NumberOfLuns; i++) { 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) { if (bdev == NULL) {
SPDK_ERRLOG("Could not create malloc disk\n"); SPDK_ERRLOG("Could not create malloc disk\n");
rc = EINVAL; rc = EINVAL;

View File

@ -38,6 +38,7 @@
#include "spdk/bdev.h" #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 */ #endif /* SPDK_BDEV_MALLOC_H */

View File

@ -34,11 +34,13 @@
#include "bdev_malloc.h" #include "bdev_malloc.h"
#include "spdk/rpc.h" #include "spdk/rpc.h"
#include "spdk/util.h" #include "spdk/util.h"
#include "spdk/uuid.h"
#include "spdk_internal/log.h" #include "spdk_internal/log.h"
struct rpc_construct_malloc { struct rpc_construct_malloc {
char *name; char *name;
char *uuid;
uint32_t num_blocks; uint32_t num_blocks;
uint32_t block_size; uint32_t block_size;
}; };
@ -47,10 +49,12 @@ static void
free_rpc_construct_malloc(struct rpc_construct_malloc *r) free_rpc_construct_malloc(struct rpc_construct_malloc *r)
{ {
free(r->name); free(r->name);
free(r->uuid);
} }
static const struct spdk_json_object_decoder rpc_construct_malloc_decoders[] = { static const struct spdk_json_object_decoder rpc_construct_malloc_decoders[] = {
{"name", offsetof(struct rpc_construct_malloc, name), spdk_json_decode_string, true}, {"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}, {"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}, {"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 rpc_construct_malloc req = {NULL};
struct spdk_json_write_ctx *w; struct spdk_json_write_ctx *w;
struct spdk_uuid *uuid = NULL;
struct spdk_uuid decoded_uuid;
struct spdk_bdev *bdev; struct spdk_bdev *bdev;
if (spdk_json_decode_object(params, rpc_construct_malloc_decoders, 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; 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) { if (bdev == NULL) {
goto invalid; goto invalid;
} }

View File

@ -32,6 +32,7 @@ if __name__ == "__main__":
p = subparsers.add_parser('construct_malloc_bdev', p = subparsers.add_parser('construct_malloc_bdev',
help='Add a bdev with malloc backend') help='Add a bdev with malloc backend')
p.add_argument('-b', '--name', help="Name of the bdev") p.add_argument('-b', '--name', help="Name of the bdev")
p.add_argument('-u', '--uuid', help="UUID of the bdev")
p.add_argument( p.add_argument(
'total_size', help='Size of malloc bdev in MB (int > 0)', type=int) '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) p.add_argument('block_size', help='Block size for this bdev', type=int)

View File

@ -6,6 +6,8 @@ def construct_malloc_bdev(args):
params = {'num_blocks': num_blocks, 'block_size': args.block_size} params = {'num_blocks': num_blocks, 'block_size': args.block_size}
if args.name: if args.name:
params['name'] = args.name params['name'] = args.name
if args.uuid:
params['uuid'] = args.uuid
print_array(args.client.call( print_array(args.client.call(
'construct_malloc_bdev', params)) 'construct_malloc_bdev', params))