Commit 42dec8ff authored by Evgeniy Kochetov's avatar Evgeniy Kochetov Committed by Jim Harris
Browse files

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: default avatarEvgeniy Kochetov <evgeniik@mellanox.com>
Signed-off-by: default avatarSasha Kotchubievsky <sashakot@mellanox.com>
Signed-off-by: default avatarAlexey Marchuk <alexeymar@mellanox.com>
Change-Id: I2c542c159d21703147c3a5b910fcc853bb5db890
Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/464776


Reviewed-by: default avatarBroadcom SPDK FC-NVMe CI <spdk-ci.pdl@broadcom.com>
Reviewed-by: default avatarShuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Reviewed-by: default avatarBen Walker <benjamin.walker@intel.com>
Reviewed-by: default avatarJim Harris <james.r.harris@intel.com>
Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
parent e06e34be
Loading
Loading
Loading
Loading
+19 −11
Original line number Diff line number Diff line
@@ -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;
+10 −4
Original line number Diff line number Diff line
/*-
 *   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.
+8 −3
Original line number Diff line number Diff line
/*-
 *   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;