bdev/null: Pack constructor parameters into a structure

Null bdev constructor parameters are packed into a single structure to
simplify future extensions.

Signed-off-by: Evgeniy Kochetov <evgeniik@mellanox.com>
Signed-off-by: Sasha Kotchubievsky <sashakot@mellanox.com>
Signed-off-by: Alexey Marchuk <alexeymar@mellanox.com>
Change-Id: I2c542c159d21703147c3a5b910fcc853bb5db890
Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/464776
Reviewed-by: Broadcom SPDK FC-NVMe CI <spdk-ci.pdl@broadcom.com>
Reviewed-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Reviewed-by: Ben Walker <benjamin.walker@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
This commit is contained in:
Evgeniy Kochetov 2019-08-02 08:53:42 +00:00 committed by Jim Harris
parent e06e34be1d
commit 42dec8ffa2
3 changed files with 37 additions and 18 deletions

View File

@ -172,18 +172,22 @@ static const struct spdk_bdev_fn_table null_fn_table = {
}; };
int int
create_null_bdev(struct spdk_bdev **bdev, const char *name, const struct spdk_uuid *uuid, create_null_bdev(struct spdk_bdev **bdev, const struct spdk_null_bdev_opts *opts)
uint64_t num_blocks, uint32_t block_size)
{ {
struct null_bdev *null_disk; struct null_bdev *null_disk;
int rc; int rc;
if (block_size % 512 != 0) { if (!opts) {
SPDK_ERRLOG("Block size %u is not a multiple of 512.\n", block_size); SPDK_ERRLOG("No options provided for Null bdev.\n");
return -EINVAL; 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"); SPDK_ERRLOG("Disk must be more than 0 blocks\n");
return -EINVAL; return -EINVAL;
} }
@ -194,7 +198,7 @@ create_null_bdev(struct spdk_bdev **bdev, const char *name, const struct spdk_uu
return -ENOMEM; return -ENOMEM;
} }
null_disk->bdev.name = strdup(name); null_disk->bdev.name = strdup(opts->name);
if (!null_disk->bdev.name) { if (!null_disk->bdev.name) {
free(null_disk); free(null_disk);
return -ENOMEM; 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.product_name = "Null disk";
null_disk->bdev.write_cache = 0; null_disk->bdev.write_cache = 0;
null_disk->bdev.blocklen = block_size; null_disk->bdev.blocklen = opts->block_size;
null_disk->bdev.blockcnt = num_blocks; null_disk->bdev.blockcnt = opts->num_blocks;
if (uuid) { if (opts->uuid) {
null_disk->bdev.uuid = *uuid; null_disk->bdev.uuid = *opts->uuid;
} else { } else {
spdk_uuid_generate(&null_disk->bdev.uuid); spdk_uuid_generate(&null_disk->bdev.uuid);
} }
@ -295,6 +299,7 @@ bdev_null_initialize(void)
int block_size, i, rc = 0; int block_size, i, rc = 0;
struct spdk_bdev *bdev; struct spdk_bdev *bdev;
const char *name, *val; const char *name, *val;
struct spdk_null_bdev_opts opts = {};
TAILQ_INIT(&g_null_bdev_head); TAILQ_INIT(&g_null_bdev_head);
@ -356,7 +361,10 @@ bdev_null_initialize(void)
num_blocks = size_in_mb * (1024 * 1024) / block_size; 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) { if (rc) {
SPDK_ERRLOG("Could not create null bdev\n"); SPDK_ERRLOG("Could not create null bdev\n");
goto end; goto end;

View File

@ -1,8 +1,8 @@
/*- /*-
* BSD LICENSE * BSD LICENSE
* *
* Copyright (c) Intel Corporation. * Copyright (c) Intel Corporation. All rights reserved.
* All rights reserved. * Copyright (c) 2019 Mellanox Technologies LTD. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions * 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_bdev;
struct spdk_uuid; struct spdk_uuid;
int create_null_bdev(struct spdk_bdev **bdev, const char *name, const struct spdk_uuid *uuid, struct spdk_null_bdev_opts {
uint64_t num_blocks, uint32_t block_size); 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. * Delete null bdev.

View File

@ -1,8 +1,8 @@
/*- /*-
* BSD LICENSE * BSD LICENSE
* *
* Copyright (c) Intel Corporation. * Copyright (c) Intel Corporation. All rights reserved.
* All rights reserved. * Copyright (c) 2019 Mellanox Technologies LTD. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions * 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 *uuid = NULL;
struct spdk_uuid decoded_uuid; struct spdk_uuid decoded_uuid;
struct spdk_bdev *bdev; struct spdk_bdev *bdev;
struct spdk_null_bdev_opts opts = {};
int rc = 0; int rc = 0;
if (spdk_json_decode_object(params, rpc_construct_null_decoders, 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; 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) { if (rc) {
spdk_jsonrpc_send_error_response(request, rc, spdk_strerror(-rc)); spdk_jsonrpc_send_error_response(request, rc, spdk_strerror(-rc));
goto cleanup; goto cleanup;