bdev/malloc: allow user to specify bdev name

The construct_malloc_bdev RPC method now takes an optional "name"
parameter to request a specific name for the created bdev, rather than
using the auto-generated Malloc%d-style name.

scripts/rpc.py is updated to add the new optional parameter, and it uses
-b/--name to match the corresponding parameter to construct_nvme_bdev.

Also update one of the test scripts to use the new parameter to get test
coverage.

Change-Id: I1f5bf76f406b8ea8a709d856f7624a38fbfa0d5f
Signed-off-by: Daniel Verkamp <daniel.verkamp@intel.com>
Reviewed-on: https://review.gerrithub.io/381728
Tested-by: SPDK Automated Test System <sys_sgsw@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
Reviewed-by: Changpeng Liu <changpeng.liu@intel.com>
This commit is contained in:
Daniel Verkamp 2017-10-06 15:00:28 -07:00 committed by Jim Harris
parent e35816b4be
commit 6f6645e2d8
5 changed files with 29 additions and 10 deletions

View File

@ -367,7 +367,7 @@ static const struct spdk_bdev_fn_table malloc_fn_table = {
.get_io_channel = bdev_malloc_get_io_channel,
};
struct spdk_bdev *create_malloc_disk(uint64_t num_blocks, uint32_t block_size)
struct spdk_bdev *create_malloc_disk(const char *name, uint64_t num_blocks, uint32_t block_size)
{
struct malloc_disk *mdisk;
@ -400,13 +400,18 @@ struct spdk_bdev *create_malloc_disk(uint64_t num_blocks, uint32_t block_size)
return NULL;
}
mdisk->disk.name = spdk_sprintf_alloc("Malloc%d", malloc_disk_count);
if (name) {
mdisk->disk.name = strdup(name);
} else {
/* Auto-generate a name */
mdisk->disk.name = spdk_sprintf_alloc("Malloc%d", malloc_disk_count);
malloc_disk_count++;
}
if (!mdisk->disk.name) {
malloc_disk_free(mdisk);
return NULL;
}
mdisk->disk.product_name = "Malloc disk";
malloc_disk_count++;
mdisk->disk.write_cache = 1;
mdisk->disk.blocklen = block_size;
@ -453,7 +458,7 @@ static int bdev_malloc_initialize(void)
}
size = (uint64_t)LunSizeInMB * 1024 * 1024;
for (i = 0; i < NumberOfLuns; i++) {
bdev = create_malloc_disk(size / BlockSize, BlockSize);
bdev = create_malloc_disk(NULL, size / BlockSize, BlockSize);
if (bdev == NULL) {
SPDK_ERRLOG("Could not create malloc disk\n");
rc = EINVAL;

View File

@ -38,6 +38,6 @@
#include "spdk/bdev.h"
struct spdk_bdev *create_malloc_disk(uint64_t num_blocks, uint32_t block_size);
struct spdk_bdev *create_malloc_disk(const char *name, uint64_t num_blocks, uint32_t block_size);
#endif /* SPDK_BDEV_MALLOC_H */

View File

@ -38,11 +38,19 @@
#include "spdk_internal/log.h"
struct rpc_construct_malloc {
char *name;
uint32_t num_blocks;
uint32_t block_size;
};
static void
free_rpc_construct_malloc(struct rpc_construct_malloc *r)
{
free(r->name);
}
static const struct spdk_json_object_decoder rpc_construct_malloc_decoders[] = {
{"name", offsetof(struct rpc_construct_malloc, name), spdk_json_decode_string, true},
{"num_blocks", offsetof(struct rpc_construct_malloc, num_blocks), spdk_json_decode_uint32},
{"block_size", offsetof(struct rpc_construct_malloc, block_size), spdk_json_decode_uint32},
};
@ -51,7 +59,7 @@ static void
spdk_rpc_construct_malloc_bdev(struct spdk_jsonrpc_request *request,
const struct spdk_json_val *params)
{
struct rpc_construct_malloc req = {};
struct rpc_construct_malloc req = {NULL};
struct spdk_json_write_ctx *w;
struct spdk_bdev *bdev;
@ -62,11 +70,13 @@ spdk_rpc_construct_malloc_bdev(struct spdk_jsonrpc_request *request,
goto invalid;
}
bdev = create_malloc_disk(req.num_blocks, req.block_size);
bdev = create_malloc_disk(req.name, req.num_blocks, req.block_size);
if (bdev == NULL) {
goto invalid;
}
free_rpc_construct_malloc(&req);
w = spdk_jsonrpc_begin_result(request);
if (w == NULL) {
return;
@ -79,6 +89,7 @@ spdk_rpc_construct_malloc_bdev(struct spdk_jsonrpc_request *request,
return;
invalid:
free_rpc_construct_malloc(&req);
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS, "Invalid parameters");
}
SPDK_RPC_REGISTER("construct_malloc_bdev", spdk_rpc_construct_malloc_bdev)

View File

@ -166,9 +166,12 @@ p.set_defaults(func=construct_target_node)
def construct_malloc_bdev(args):
num_blocks = (args.total_size * 1024 * 1024) / args.block_size
params = {'num_blocks': num_blocks, 'block_size': args.block_size}
if args.name:
params['name'] = args.name
print_array(jsonrpc_call('construct_malloc_bdev', params))
p = subparsers.add_parser('construct_malloc_bdev', help='Add a bdev with malloc backend')
p.add_argument('-b', '--name', help="Name of the bdev")
p.add_argument('total_size', help='Size of malloc bdev in MB (int > 0)', type=int)
p.add_argument('block_size', help='Block size for this bdev', type=int)
p.set_defaults(func=construct_malloc_bdev)

View File

@ -43,12 +43,12 @@ timing_exit start_iscsi_tgt
$rpc_py add_portal_group 1 $TARGET_IP:$PORT
$rpc_py add_initiator_group $INITIATOR_TAG $INITIATOR_NAME $NETMASK
$rpc_py construct_malloc_bdev $MALLOC_BDEV_SIZE $MALLOC_BLOCK_SIZE
# "Malloc0:0" ==> use Malloc0 blockdev for LUN0
$rpc_py construct_malloc_bdev -b MyBdev $MALLOC_BDEV_SIZE $MALLOC_BLOCK_SIZE
# "MyBdev:0" ==> use MyBdev blockdev for LUN0
# "1:2" ==> map PortalGroup1 to InitiatorGroup2
# "64" ==> iSCSI queue depth 64
# "0 0 0 1" ==> enable CHAP authentication using auth group 1
$rpc_py construct_target_node Target3 Target3_alias 'Malloc0:0' '1:2' 64 0 0 0 1
$rpc_py construct_target_node Target3 Target3_alias 'MyBdev:0' '1:2' 64 0 0 0 1
sleep 1
if [ "$1" ]; then