bdev/aio: The user now provides the names of AIO bdevs

The user now must choose the name for each AIO bdev. This
provides consistency for names across restarts.

Change-Id: I13ced1d02bb28c51d314512d60f739499b0c7d8d
Signed-off-by: Ben Walker <benjamin.walker@intel.com>
This commit is contained in:
Ben Walker 2017-03-01 16:50:29 -07:00
parent 39ad6c3151
commit 6d7b6e882c
8 changed files with 61 additions and 51 deletions

View File

@ -62,9 +62,10 @@ Configuration file syntax:
~~~
[AIO]
# normal file or block device
AIO /dev/sdb
AIO /dev/sdc
# AIO <file name> <bdev name>
# The file name is the backing device
# The bdev name can be referenced from elsewhere in the configuration file.
AIO /dev/sdb AIO0
~~~
This exports 2 aio block devices, named AIO0 and AIO1.

View File

@ -130,10 +130,14 @@
Whitelist 00:04.1
# Users must change this section to match the /dev/sdX devices to be
# exported as iSCSI LUNs. The devices are accessed using Linux AIO.
# exported as iSCSI LUNs. The devices are accessed using Linux AIO.
# The format is:
# AIO <file name> <bdev name>
# The file name is the backing device
# The bdev name can be referenced from elsewhere in the configuration file.
[AIO]
AIO /dev/sdb
AIO /dev/sdc
AIO /dev/sdb AIO0
AIO /dev/sdc AIO1
# The Split virtual block device slices block devices into multiple smaller bdevs.
[Split]

View File

@ -43,11 +43,15 @@
NumberOfLuns 8
LunSizeInMB 64
# Users must change this section to match the /dev/sdX devices to be virtual
# NVMe devices. The devices are accessed using Linux AIO.
# Users must change this section to match the /dev/sdX devices to be
# exported as iSCSI LUNs. The devices are accessed using Linux AIO.
# The format is:
# AIO <file name> <bdev name>
# The file name is the backing device
# The bdev name can be referenced from elsewhere in the configuration file.
[AIO]
AIO /dev/sdb
AIO /dev/sdc
AIO /dev/sdb AIO0
AIO /dev/sdc AIO1
# Define NVMf protocol global options
[Nvmf]

View File

@ -48,8 +48,6 @@
#include "spdk_internal/log.h"
static int g_blockdev_count = 0;
static int blockdev_aio_initialize(void);
static void aio_free_disk(struct file_disk *fdisk);
@ -341,7 +339,7 @@ static void aio_free_disk(struct file_disk *fdisk)
}
struct spdk_bdev *
create_aio_disk(char *fname)
create_aio_disk(const char *name, const char *fname)
{
struct file_disk *fdisk;
@ -360,8 +358,7 @@ create_aio_disk(char *fname)
fdisk->size = spdk_fd_get_size(fdisk->fd);
TAILQ_INIT(&fdisk->sync_completion_list);
snprintf(fdisk->disk.name, SPDK_BDEV_MAX_NAME_LENGTH, "AIO%d",
g_blockdev_count);
snprintf(fdisk->disk.name, SPDK_BDEV_MAX_NAME_LENGTH, "%s", name);
snprintf(fdisk->disk.product_name, SPDK_BDEV_MAX_PRODUCT_NAME_LENGTH, "AIO disk");
fdisk->disk.need_aligned_buffer = 1;
@ -371,7 +368,6 @@ create_aio_disk(char *fname)
fdisk->disk.ctxt = fdisk;
fdisk->disk.fn_table = &aio_fn_table;
g_blockdev_count++;
spdk_io_device_register(&fdisk->disk, blockdev_aio_create_cb, blockdev_aio_destroy_cb,
sizeof(struct blockdev_aio_io_channel));
@ -386,38 +382,42 @@ error_return:
static int blockdev_aio_initialize(void)
{
size_t i;
struct spdk_conf_section *sp;
struct spdk_bdev *bdev;
int i;
const char *val = NULL;
char *file;
struct spdk_conf_section *sp = spdk_conf_find_section(NULL, "AIO");
bool skip_missing = false;
if (sp != NULL) {
val = spdk_conf_section_get_val(sp, "SkipMissingFiles");
}
if (val != NULL && !strcmp(val, "Yes")) {
skip_missing = true;
sp = spdk_conf_find_section(NULL, "AIO");
if (!sp) {
return 0;
}
if (sp != NULL) {
for (i = 0; ; i++) {
val = spdk_conf_section_get_nval(sp, "AIO", i);
if (val == NULL)
break;
file = spdk_conf_section_get_nmval(sp, "AIO", i, 0);
if (file == NULL) {
SPDK_ERRLOG("AIO%d: format error\n", i);
return -1;
}
i = 0;
while (true) {
const char *file;
const char *name;
bdev = create_aio_disk(file);
if (bdev == NULL && !skip_missing) {
return -1;
}
file = spdk_conf_section_get_nmval(sp, "AIO", i, 0);
if (!file) {
break;
}
name = spdk_conf_section_get_nmval(sp, "AIO", i, 1);
if (!name) {
SPDK_ERRLOG("No name provided for AIO disk with file %s\n", file);
i++;
continue;
}
bdev = create_aio_disk(name, file);
if (!bdev) {
SPDK_ERRLOG("Unable to create AIO bdev from file %s\n", file);
i++;
continue;
}
i++;
}
return 0;
}

View File

@ -57,7 +57,7 @@ struct blockdev_aio_io_channel {
struct file_disk {
struct spdk_bdev disk; /* this must be first element */
char *file;
const char *file;
int fd;
char disk_name[SPDK_BDEV_MAX_NAME_LENGTH];
uint64_t size;
@ -69,6 +69,6 @@ struct file_disk {
TAILQ_HEAD(, blockdev_aio_task) sync_completion_list;
};
struct spdk_bdev *create_aio_disk(char *fname);
struct spdk_bdev *create_aio_disk(const char *name, const char *fname);
#endif // SPDK_BLOCKDEV_AIO_H

View File

@ -38,16 +38,19 @@
#include "spdk_internal/log.h"
struct rpc_construct_aio {
char *name;
char *fname;
};
static void
free_rpc_construct_aio(struct rpc_construct_aio *req)
{
free(req->name);
free(req->fname);
}
static const struct spdk_json_object_decoder rpc_construct_aio_decoders[] = {
{"name", offsetof(struct rpc_construct_aio, name), spdk_json_decode_string},
{"fname", offsetof(struct rpc_construct_aio, fname), spdk_json_decode_string},
};
@ -67,7 +70,7 @@ spdk_rpc_construct_aio_bdev(struct spdk_jsonrpc_server_conn *conn,
goto invalid;
}
bdev = create_aio_disk(req.fname);
bdev = create_aio_disk(req.name, req.fname);
if (bdev == NULL) {
goto invalid;
}

View File

@ -165,11 +165,14 @@ p.set_defaults(func=construct_malloc_bdev)
def construct_aio_bdev(args):
params = {'fname': args.fname}
params = {'name': args.name,
'fname': args.fname}
print_array(jsonrpc_call('construct_aio_bdev', params))
p = subparsers.add_parser('construct_aio_bdev', help='Add a bdev with aio backend')
p.add_argument('fname', help='Path to device or file (ex: /dev/sda)')
p.add_argument('name', help='Block device name')
p.set_defaults(func=construct_aio_bdev)
def construct_nvme_bdev(args):

View File

@ -14,9 +14,4 @@
Split Malloc2 8 1
[AIO]
# skip these blockdevs if the /dev/ramX nodes do not exist
# so that the blockdev tests can still run on systems that
# do not have /dev/ramX nodes configured
SkipMissingFiles Yes
# Linux AIO backend
AIO /dev/ram0
AIO /dev/ram0 AIO0