bdev/aio: Add support for blockdev_aio_get_spdk_running_config().

Change-Id: I7458a89c89b0605e5806768c03ef519fc222bce5
Signed-off-by: Chunyang Hui <Chunyang.hui@intel.com>
Reviewed-on: https://review.gerrithub.io/375256
Tested-by: SPDK Automated Test System <sys_sgsw@intel.com>
Reviewed-by: GangCao <gang.cao@intel.com>
Reviewed-by: Changpeng Liu <changpeng.liu@intel.com>
Reviewed-by: Daniel Verkamp <daniel.verkamp@intel.com>
This commit is contained in:
Chunyang Hui 2017-08-22 13:37:57 +08:00 committed by Daniel Verkamp
parent 3860fa7ef6
commit 116c494fc8
2 changed files with 43 additions and 1 deletions

View File

@ -47,6 +47,8 @@
static int bdev_aio_initialize(void);
static void aio_free_disk(struct file_disk *fdisk);
static void bdev_aio_get_spdk_running_config(FILE *fp);
static TAILQ_HEAD(, file_disk) g_aio_disk_head;
#define SPDK_AIO_QUEUE_DEPTH 128
@ -56,7 +58,8 @@ bdev_aio_get_ctx_size(void)
return sizeof(struct bdev_aio_task);
}
SPDK_BDEV_MODULE_REGISTER(aio, bdev_aio_initialize, NULL, NULL, bdev_aio_get_ctx_size, NULL)
SPDK_BDEV_MODULE_REGISTER(aio, bdev_aio_initialize, NULL, bdev_aio_get_spdk_running_config,
bdev_aio_get_ctx_size, NULL)
static int
bdev_aio_open(struct file_disk *disk)
@ -167,6 +170,7 @@ bdev_aio_destruct(void *ctx)
struct file_disk *fdisk = ctx;
int rc = 0;
TAILQ_REMOVE(&g_aio_disk_head, fdisk, link);
rc = bdev_aio_close(fdisk);
if (rc < 0) {
SPDK_ERRLOG("bdev_aio_close() failed\n");
@ -397,6 +401,7 @@ create_aio_disk(const char *name, const char *filename, uint32_t block_size)
SPDK_ERRLOG("Block size could not be auto-detected\n");
goto error_return;
}
fdisk->block_size_override = false;
block_size = detected_block_size;
} else {
if (block_size < detected_block_size) {
@ -409,6 +414,7 @@ create_aio_disk(const char *name, const char *filename, uint32_t block_size)
"auto-detected block size %" PRIu32 "\n",
block_size, detected_block_size);
}
fdisk->block_size_override = true;
}
if (block_size < 512) {
@ -437,6 +443,8 @@ create_aio_disk(const char *name, const char *filename, uint32_t block_size)
spdk_io_device_register(&fdisk->fd, bdev_aio_create_cb, bdev_aio_destroy_cb,
sizeof(struct bdev_aio_io_channel));
spdk_bdev_register(&fdisk->disk);
TAILQ_INSERT_TAIL(&g_aio_disk_head, fdisk, link);
return &fdisk->disk;
error_return:
@ -452,6 +460,7 @@ bdev_aio_initialize(void)
struct spdk_conf_section *sp;
struct spdk_bdev *bdev;
TAILQ_INIT(&g_aio_disk_head);
sp = spdk_conf_find_section(NULL, "AIO");
if (!sp) {
return 0;
@ -494,4 +503,35 @@ bdev_aio_initialize(void)
return 0;
}
static void
bdev_aio_get_spdk_running_config(FILE *fp)
{
char *file;
char *name;
uint32_t block_size;
struct file_disk *fdisk;
fprintf(fp,
"\n"
"# Users must change this section to match the /dev/sdX devices to be\n"
"# exported as iSCSI LUNs. The devices are accessed using Linux AIO.\n"
"# The format is:\n"
"# AIO <file name> <bdev name> [<block size>]\n"
"# The file name is the backing device\n"
"# The bdev name can be referenced from elsewhere in the configuration file.\n"
"# Block size may be omitted to automatically detect the block size of a disk.\n"
"[AIO]\n");
TAILQ_FOREACH(fdisk, &g_aio_disk_head, link) {
file = fdisk->filename;
name = fdisk->disk.name;
block_size = fdisk->disk.blocklen;
fprintf(fp, " AIO %s %s ", file, name);
if (fdisk->block_size_override)
fprintf(fp, "%d", block_size);
fprintf(fp, "\n");
}
fprintf(fp, "\n");
}
SPDK_LOG_REGISTER_TRACE_FLAG("aio", SPDK_TRACE_AIO)

View File

@ -58,6 +58,8 @@ struct file_disk {
struct spdk_bdev disk;
char *filename;
int fd;
TAILQ_ENTRY(file_disk) link;
bool block_size_override;
};
struct spdk_bdev *create_aio_disk(const char *name, const char *filename, uint32_t block_size);