Commit 36943038 authored by Shuhei Matsumoto's avatar Shuhei Matsumoto Committed by Tomasz Zawadzki
Browse files

bdev/null: bdev_null_create RPC uses bdev_null_opts directly



The bdev_null_create RPC set rpc_construct_null structure and copied
it to null_bdev_opts structure. However, this was not efficient or
clean.

The difference of rpc_construct_null structure and null_bdev_opts
structure were:
1. null_bdev_opts::block_size was block size,
   rpc_construct_null::block_size was data block size
2. null_bdev_opts::uuid was pointer, rpc_construct_null::uuid was
   instance

For #1, as we do for malloc bdev, we can use null_bdev_opts::block_size
as data block size. If null_bdev_opts::block_size is data block size,
we do not have to compare opts::block_size and opts::md_size.

For #2, as we do for malloc bdev, null_bdev_opts::uuid can be instance
and we can copy null_bdev_opts::uuid to spdk_bdev::uuid.

Additionally, spdk_null_bdev_opts is not a public data structure. Hence,
it should not have "spdk_" prefix.

Signed-off-by: default avatarShuhei Matsumoto <smatsumoto@nvidia.com>
Change-Id: If53702071cf02fe23d03f464a63c2495c70e1f12
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/24109


Reviewed-by: default avatarJim Harris <jim.harris@samsung.com>
Reviewed-by: default avatarAleksey Marchuk <alexeymar@nvidia.com>
Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Community-CI: Mellanox Build Bot
parent ccc88995
Loading
Loading
Loading
Loading
+10 −11
Original line number Diff line number Diff line
@@ -236,10 +236,10 @@ static const struct spdk_bdev_fn_table null_fn_table = {
};

int
bdev_null_create(struct spdk_bdev **bdev, const struct spdk_null_bdev_opts *opts)
bdev_null_create(struct spdk_bdev **bdev, const struct null_bdev_opts *opts)
{
	struct null_bdev *null_disk;
	uint32_t data_block_size;
	uint32_t block_size;
	int rc;

	if (!opts) {
@@ -260,17 +260,13 @@ bdev_null_create(struct spdk_bdev **bdev, const struct spdk_null_bdev_opts *opts
		return -EINVAL;
	}

	if (opts->block_size < opts->md_size) {
		SPDK_ERRLOG("Interleaved metadata size can not be greater than block size.\n");
		return -EINVAL;
	}
	data_block_size = opts->block_size - opts->md_size;

	if (data_block_size % 512 != 0) {
	if (opts->block_size % 512 != 0) {
		SPDK_ERRLOG("Data block size %u is not a multiple of 512.\n", opts->block_size);
		return -EINVAL;
	}

	block_size = opts->block_size + opts->md_size;

	if (opts->num_blocks == 0) {
		SPDK_ERRLOG("Disk must be more than 0 blocks\n");
		return -EINVAL;
@@ -290,7 +286,7 @@ bdev_null_create(struct spdk_bdev **bdev, const struct spdk_null_bdev_opts *opts
	null_disk->bdev.product_name = "Null disk";

	null_disk->bdev.write_cache = 0;
	null_disk->bdev.blocklen = opts->block_size;
	null_disk->bdev.blocklen = block_size;
	null_disk->bdev.phys_blocklen = opts->physical_block_size;
	null_disk->bdev.blockcnt = opts->num_blocks;
	null_disk->bdev.md_len = opts->md_size;
@@ -315,7 +311,10 @@ bdev_null_create(struct spdk_bdev **bdev, const struct spdk_null_bdev_opts *opts
	}
	null_disk->bdev.dif_pi_format = SPDK_DIF_PI_FORMAT_16;

	null_disk->bdev.uuid = *opts->uuid;
	if (!spdk_uuid_is_null(&opts->uuid)) {
		spdk_uuid_copy(&null_disk->bdev.uuid, &opts->uuid);
	}

	null_disk->bdev.ctxt = null_disk;
	null_disk->bdev.fn_table = &null_fn_table;
	null_disk->bdev.module = &null_if;
+4 −4
Original line number Diff line number Diff line
@@ -13,9 +13,9 @@ typedef void (*spdk_delete_null_complete)(void *cb_arg, int bdeverrno);
struct spdk_bdev;
struct spdk_uuid;

struct spdk_null_bdev_opts {
	const char *name;
	const struct spdk_uuid *uuid;
struct null_bdev_opts {
	char *name;
	struct spdk_uuid uuid;
	uint64_t num_blocks;
	uint32_t block_size;
	uint32_t physical_block_size;
@@ -24,7 +24,7 @@ struct spdk_null_bdev_opts {
	bool dif_is_head_of_md;
};

int bdev_null_create(struct spdk_bdev **bdev, const struct spdk_null_bdev_opts *opts);
int bdev_null_create(struct spdk_bdev **bdev, const struct null_bdev_opts *opts);

/**
 * Delete null bdev.
+11 −31
Original line number Diff line number Diff line
@@ -11,42 +11,30 @@

#include "bdev_null.h"

struct rpc_construct_null {
	char *name;
	struct spdk_uuid uuid;
	uint64_t num_blocks;
	uint32_t block_size;
	uint32_t physical_block_size;
	uint32_t md_size;
	int32_t dif_type;
	bool dif_is_head_of_md;
};

static void
free_rpc_construct_null(struct rpc_construct_null *req)
free_rpc_construct_null(struct null_bdev_opts *req)
{
	free(req->name);
}

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_uuid, true},
	{"num_blocks", offsetof(struct rpc_construct_null, num_blocks), spdk_json_decode_uint64},
	{"block_size", offsetof(struct rpc_construct_null, block_size), spdk_json_decode_uint32},
	{"physical_block_size", offsetof(struct rpc_construct_null, physical_block_size), spdk_json_decode_uint32, true},
	{"md_size", offsetof(struct rpc_construct_null, md_size), spdk_json_decode_uint32, true},
	{"dif_type", offsetof(struct rpc_construct_null, dif_type), spdk_json_decode_int32, true},
	{"dif_is_head_of_md", offsetof(struct rpc_construct_null, dif_is_head_of_md), spdk_json_decode_bool, true},
	{"name", offsetof(struct null_bdev_opts, name), spdk_json_decode_string},
	{"uuid", offsetof(struct null_bdev_opts, uuid), spdk_json_decode_uuid, true},
	{"num_blocks", offsetof(struct null_bdev_opts, num_blocks), spdk_json_decode_uint64},
	{"block_size", offsetof(struct null_bdev_opts, block_size), spdk_json_decode_uint32},
	{"physical_block_size", offsetof(struct null_bdev_opts, physical_block_size), spdk_json_decode_uint32, true},
	{"md_size", offsetof(struct null_bdev_opts, md_size), spdk_json_decode_uint32, true},
	{"dif_type", offsetof(struct null_bdev_opts, dif_type), spdk_json_decode_int32, true},
	{"dif_is_head_of_md", offsetof(struct null_bdev_opts, dif_is_head_of_md), spdk_json_decode_bool, true},
};

static void
rpc_bdev_null_create(struct spdk_jsonrpc_request *request,
		     const struct spdk_json_val *params)
{
	struct rpc_construct_null req = {};
	struct null_bdev_opts req = {};
	struct spdk_json_write_ctx *w;
	struct spdk_bdev *bdev;
	struct spdk_null_bdev_opts opts = {};
	int rc = 0;

	if (spdk_json_decode_object(params, rpc_construct_null_decoders,
@@ -92,15 +80,7 @@ rpc_bdev_null_create(struct spdk_jsonrpc_request *request,
		goto cleanup;
	}

	opts.name = req.name;
	opts.uuid = &req.uuid;
	opts.num_blocks = req.num_blocks;
	opts.block_size = req.block_size + req.md_size;
	opts.physical_block_size = req.physical_block_size;
	opts.md_size = req.md_size;
	opts.dif_type = req.dif_type;
	opts.dif_is_head_of_md = req.dif_is_head_of_md;
	rc = bdev_null_create(&bdev, &opts);
	rc = bdev_null_create(&bdev, &req);
	if (rc) {
		spdk_jsonrpc_send_error_response(request, rc, spdk_strerror(-rc));
		goto cleanup;