bdev/null: allow user to override UUID
Change-Id: I2fe5eb46d5e5b67451b472b82cde69e3606c6235 Signed-off-by: Daniel Verkamp <daniel.verkamp@intel.com> Reviewed-on: https://review.gerrithub.io/403222 Reviewed-by: Jim Harris <james.r.harris@intel.com> Tested-by: SPDK Automated Test System <sys_sgsw@intel.com> Reviewed-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
This commit is contained in:
parent
eca9ac03e4
commit
84918cd9fa
@ -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;
|
||||
|
@ -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 */
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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)
|
||||
|
@ -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))
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user