diff --git a/lib/bdev/null/bdev_null.c b/lib/bdev/null/bdev_null.c index b13749348..4d9670252 100644 --- a/lib/bdev/null/bdev_null.c +++ b/lib/bdev/null/bdev_null.c @@ -172,18 +172,22 @@ static const struct spdk_bdev_fn_table null_fn_table = { }; int -create_null_bdev(struct spdk_bdev **bdev, const char *name, const struct spdk_uuid *uuid, - uint64_t num_blocks, uint32_t block_size) +create_null_bdev(struct spdk_bdev **bdev, const struct spdk_null_bdev_opts *opts) { struct null_bdev *null_disk; int rc; - if (block_size % 512 != 0) { - SPDK_ERRLOG("Block size %u is not a multiple of 512.\n", block_size); + if (!opts) { + SPDK_ERRLOG("No options provided for Null bdev.\n"); return -EINVAL; } - if (num_blocks == 0) { + if (opts->block_size % 512 != 0) { + SPDK_ERRLOG("Block size %u is not a multiple of 512.\n", opts->block_size); + return -EINVAL; + } + + if (opts->num_blocks == 0) { SPDK_ERRLOG("Disk must be more than 0 blocks\n"); return -EINVAL; } @@ -194,7 +198,7 @@ create_null_bdev(struct spdk_bdev **bdev, const char *name, const struct spdk_uu return -ENOMEM; } - null_disk->bdev.name = strdup(name); + null_disk->bdev.name = strdup(opts->name); if (!null_disk->bdev.name) { free(null_disk); return -ENOMEM; @@ -202,10 +206,10 @@ create_null_bdev(struct spdk_bdev **bdev, const char *name, const struct spdk_uu null_disk->bdev.product_name = "Null disk"; null_disk->bdev.write_cache = 0; - null_disk->bdev.blocklen = block_size; - null_disk->bdev.blockcnt = num_blocks; - if (uuid) { - null_disk->bdev.uuid = *uuid; + null_disk->bdev.blocklen = opts->block_size; + null_disk->bdev.blockcnt = opts->num_blocks; + if (opts->uuid) { + null_disk->bdev.uuid = *opts->uuid; } else { spdk_uuid_generate(&null_disk->bdev.uuid); } @@ -295,6 +299,7 @@ bdev_null_initialize(void) int block_size, i, rc = 0; struct spdk_bdev *bdev; const char *name, *val; + struct spdk_null_bdev_opts opts = {}; TAILQ_INIT(&g_null_bdev_head); @@ -356,7 +361,10 @@ bdev_null_initialize(void) num_blocks = size_in_mb * (1024 * 1024) / block_size; - rc = create_null_bdev(&bdev, name, NULL, num_blocks, block_size); + opts.name = name; + opts.num_blocks = num_blocks; + opts.block_size = block_size; + rc = create_null_bdev(&bdev, &opts); if (rc) { SPDK_ERRLOG("Could not create null bdev\n"); goto end; diff --git a/lib/bdev/null/bdev_null.h b/lib/bdev/null/bdev_null.h index c9293fb65..c771eda14 100644 --- a/lib/bdev/null/bdev_null.h +++ b/lib/bdev/null/bdev_null.h @@ -1,8 +1,8 @@ /*- * BSD LICENSE * - * Copyright (c) Intel Corporation. - * All rights reserved. + * Copyright (c) Intel Corporation. All rights reserved. + * Copyright (c) 2019 Mellanox Technologies LTD. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -41,8 +41,14 @@ typedef void (*spdk_delete_null_complete)(void *cb_arg, int bdeverrno); struct spdk_bdev; struct spdk_uuid; -int create_null_bdev(struct spdk_bdev **bdev, const char *name, const struct spdk_uuid *uuid, - uint64_t num_blocks, uint32_t block_size); +struct spdk_null_bdev_opts { + const char *name; + const struct spdk_uuid *uuid; + uint64_t num_blocks; + uint32_t block_size; +}; + +int create_null_bdev(struct spdk_bdev **bdev, const struct spdk_null_bdev_opts *opts); /** * Delete null bdev. diff --git a/lib/bdev/null/bdev_null_rpc.c b/lib/bdev/null/bdev_null_rpc.c index 65cc70bc7..46cc39589 100644 --- a/lib/bdev/null/bdev_null_rpc.c +++ b/lib/bdev/null/bdev_null_rpc.c @@ -1,8 +1,8 @@ /*- * BSD LICENSE * - * Copyright (c) Intel Corporation. - * All rights reserved. + * Copyright (c) Intel Corporation. All rights reserved. + * Copyright (c) 2019 Mellanox Technologies LTD. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -69,6 +69,7 @@ spdk_rpc_construct_null_bdev(struct spdk_jsonrpc_request *request, struct spdk_uuid *uuid = NULL; struct spdk_uuid decoded_uuid; struct spdk_bdev *bdev; + struct spdk_null_bdev_opts opts = {}; int rc = 0; if (spdk_json_decode_object(params, rpc_construct_null_decoders, @@ -101,7 +102,11 @@ spdk_rpc_construct_null_bdev(struct spdk_jsonrpc_request *request, uuid = &decoded_uuid; } - rc = create_null_bdev(&bdev, req.name, uuid, req.num_blocks, req.block_size); + opts.name = req.name; + opts.uuid = uuid; + opts.num_blocks = req.num_blocks; + opts.block_size = req.block_size; + rc = create_null_bdev(&bdev, &opts); if (rc) { spdk_jsonrpc_send_error_response(request, rc, spdk_strerror(-rc)); goto cleanup;