mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-08 10:13:56 -06:00
raw-posix: add Linux native AIO support
Now that do have a nicer interface to work against we can add Linux native AIO support. It's an extremly thing layer just setting up an iocb for the io_submit system call in the submission path, and registering an eventfd with the qemu poll handler to do complete the iocbs directly from there. This started out based on Anthony's earlier AIO patch, but after estimated 42,000 rewrites and just as many build system changes there's not much left of it. To enable native kernel aio use the aio=native sub-command on the drive command line. I have also added an option to qemu-io to test the aio support without needing a guest. Signed-off-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
This commit is contained in:
parent
9ef91a6771
commit
5c6c3a6c54
11 changed files with 305 additions and 8 deletions
|
@ -33,4 +33,10 @@ BlockDriverAIOCB *paio_ioctl(BlockDriverState *bs, int fd,
|
|||
unsigned long int req, void *buf,
|
||||
BlockDriverCompletionFunc *cb, void *opaque);
|
||||
|
||||
/* linux-aio.c - Linux native implementation */
|
||||
void *laio_init(void);
|
||||
BlockDriverAIOCB *laio_submit(BlockDriverState *bs, void *aio_ctx, int fd,
|
||||
int64_t sector_num, QEMUIOVector *qiov, int nb_sectors,
|
||||
BlockDriverCompletionFunc *cb, void *opaque, int type);
|
||||
|
||||
#endif /* QEMU_RAW_POSIX_AIO_H */
|
||||
|
|
|
@ -115,6 +115,7 @@ typedef struct BDRVRawState {
|
|||
int fd_got_error;
|
||||
int fd_media_changed;
|
||||
#endif
|
||||
int use_aio;
|
||||
uint8_t* aligned_buf;
|
||||
} BDRVRawState;
|
||||
|
||||
|
@ -159,6 +160,7 @@ static int raw_open_common(BlockDriverState *bs, const char *filename,
|
|||
}
|
||||
s->fd = fd;
|
||||
s->aligned_buf = NULL;
|
||||
|
||||
if ((bdrv_flags & BDRV_O_NOCACHE)) {
|
||||
s->aligned_buf = qemu_blockalign(bs, ALIGNED_BUFFER_SIZE);
|
||||
if (s->aligned_buf == NULL) {
|
||||
|
@ -166,9 +168,22 @@ static int raw_open_common(BlockDriverState *bs, const char *filename,
|
|||
}
|
||||
}
|
||||
|
||||
s->aio_ctx = paio_init();
|
||||
if (!s->aio_ctx) {
|
||||
goto out_free_buf;
|
||||
#ifdef CONFIG_LINUX_AIO
|
||||
if ((bdrv_flags & (BDRV_O_NOCACHE|BDRV_O_NATIVE_AIO)) ==
|
||||
(BDRV_O_NOCACHE|BDRV_O_NATIVE_AIO)) {
|
||||
s->aio_ctx = laio_init();
|
||||
if (!s->aio_ctx) {
|
||||
goto out_free_buf;
|
||||
}
|
||||
s->use_aio = 1;
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
s->aio_ctx = paio_init();
|
||||
if (!s->aio_ctx) {
|
||||
goto out_free_buf;
|
||||
}
|
||||
s->use_aio = 0;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
@ -524,8 +539,13 @@ static BlockDriverAIOCB *raw_aio_submit(BlockDriverState *bs,
|
|||
* boundary. Check if this is the case or telll the low-level
|
||||
* driver that it needs to copy the buffer.
|
||||
*/
|
||||
if (s->aligned_buf && !qiov_is_aligned(qiov)) {
|
||||
type |= QEMU_AIO_MISALIGNED;
|
||||
if (s->aligned_buf) {
|
||||
if (!qiov_is_aligned(qiov)) {
|
||||
type |= QEMU_AIO_MISALIGNED;
|
||||
} else if (s->use_aio) {
|
||||
return laio_submit(bs, s->aio_ctx, s->fd, sector_num, qiov,
|
||||
nb_sectors, cb, opaque, type);
|
||||
}
|
||||
}
|
||||
|
||||
return paio_submit(bs, s->aio_ctx, s->fd, sector_num, qiov, nb_sectors,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue