mirror of
https://github.com/qemu/qemu.git
synced 2026-02-04 05:35:39 +00:00
AioContext has its own io_uring instance for file descriptor monitoring. The disk I/O io_uring code was developed separately. Originally I thought the characteristics of file descriptor monitoring and disk I/O were too different, requiring separate io_uring instances. Now it has become clear to me that it's feasible to share a single io_uring instance for file descriptor monitoring and disk I/O. We're not using io_uring's IOPOLL feature or anything else that would require a separate instance. Unify block/io_uring.c and util/fdmon-io_uring.c using the new aio_add_sqe() API that allows user-defined io_uring sqe submission. Now block/io_uring.c just needs to submit readv/writev/fsync and most of the io_uring-specific logic is handled by fdmon-io_uring.c. There are two immediate advantages: 1. Fewer system calls. There is no need to monitor the disk I/O io_uring ring fd from the file descriptor monitoring io_uring instance. Disk I/O completions are now picked up directly. Also, sqes are accumulated in the sq ring until the end of the event loop iteration and there are fewer io_uring_enter(2) syscalls. 2. Less code duplication. Note that error_setg() messages are not supposed to end with punctuation, so I removed a '.' for the non-io_uring build error message. Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com> Message-ID: <20251104022933.618123-15-stefanha@redhat.com> Reviewed-by: Kevin Wolf <kwolf@redhat.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
105 lines
3.3 KiB
C
105 lines
3.3 KiB
C
/*
|
|
* Declarations for AIO in the raw protocol
|
|
*
|
|
* Copyright IBM, Corp. 2008
|
|
*
|
|
* Authors:
|
|
* Anthony Liguori <aliguori@us.ibm.com>
|
|
*
|
|
* This work is licensed under the terms of the GNU GPL, version 2. See
|
|
* the COPYING file in the top-level directory.
|
|
*
|
|
* Contributions after 2012-01-13 are licensed under the terms of the
|
|
* GNU GPL, version 2 or (at your option) any later version.
|
|
*/
|
|
|
|
#ifndef QEMU_RAW_AIO_H
|
|
#define QEMU_RAW_AIO_H
|
|
|
|
#include "block/aio.h"
|
|
#include "block/block-common.h"
|
|
#include "qemu/iov.h"
|
|
|
|
/* AIO request types */
|
|
#define QEMU_AIO_READ 0x0001
|
|
#define QEMU_AIO_WRITE 0x0002
|
|
#define QEMU_AIO_IOCTL 0x0004
|
|
#define QEMU_AIO_FLUSH 0x0008
|
|
#define QEMU_AIO_DISCARD 0x0010
|
|
#define QEMU_AIO_WRITE_ZEROES 0x0020
|
|
#define QEMU_AIO_COPY_RANGE 0x0040
|
|
#define QEMU_AIO_TRUNCATE 0x0080
|
|
#define QEMU_AIO_ZONE_REPORT 0x0100
|
|
#define QEMU_AIO_ZONE_MGMT 0x0200
|
|
#define QEMU_AIO_ZONE_APPEND 0x0400
|
|
#define QEMU_AIO_TYPE_MASK \
|
|
(QEMU_AIO_READ | \
|
|
QEMU_AIO_WRITE | \
|
|
QEMU_AIO_IOCTL | \
|
|
QEMU_AIO_FLUSH | \
|
|
QEMU_AIO_DISCARD | \
|
|
QEMU_AIO_WRITE_ZEROES | \
|
|
QEMU_AIO_COPY_RANGE | \
|
|
QEMU_AIO_TRUNCATE | \
|
|
QEMU_AIO_ZONE_REPORT | \
|
|
QEMU_AIO_ZONE_MGMT | \
|
|
QEMU_AIO_ZONE_APPEND)
|
|
|
|
/* AIO flags */
|
|
#define QEMU_AIO_MISALIGNED 0x1000
|
|
#define QEMU_AIO_BLKDEV 0x2000
|
|
#define QEMU_AIO_NO_FALLBACK 0x4000
|
|
|
|
|
|
/* linux-aio.c - Linux native implementation */
|
|
#ifdef CONFIG_LINUX_AIO
|
|
typedef struct LinuxAioState LinuxAioState;
|
|
LinuxAioState *laio_init(Error **errp);
|
|
void laio_cleanup(LinuxAioState *s);
|
|
|
|
/* laio_co_submit: submit I/O requests in the thread's current AioContext. */
|
|
int coroutine_fn laio_co_submit(int fd, uint64_t offset, QEMUIOVector *qiov,
|
|
int type, BdrvRequestFlags flags,
|
|
uint64_t dev_max_batch);
|
|
|
|
bool laio_has_fdsync(int);
|
|
bool laio_has_fua(void);
|
|
void laio_detach_aio_context(LinuxAioState *s, AioContext *old_context);
|
|
void laio_attach_aio_context(LinuxAioState *s, AioContext *new_context);
|
|
#else
|
|
static inline bool laio_has_fua(void)
|
|
{
|
|
return false;
|
|
}
|
|
#endif
|
|
/* io_uring.c - Linux io_uring implementation */
|
|
#ifdef CONFIG_LINUX_IO_URING
|
|
/* luring_co_submit: submit I/O requests in the thread's current AioContext. */
|
|
int coroutine_fn luring_co_submit(BlockDriverState *bs, int fd, uint64_t offset,
|
|
QEMUIOVector *qiov, int type,
|
|
BdrvRequestFlags flags);
|
|
bool luring_has_fua(void);
|
|
#else
|
|
static inline bool luring_has_fua(void)
|
|
{
|
|
return false;
|
|
}
|
|
#endif
|
|
|
|
#ifdef _WIN32
|
|
typedef struct QEMUWin32AIOState QEMUWin32AIOState;
|
|
QEMUWin32AIOState *win32_aio_init(void);
|
|
void win32_aio_cleanup(QEMUWin32AIOState *aio);
|
|
int win32_aio_attach(QEMUWin32AIOState *aio, HANDLE hfile);
|
|
BlockAIOCB *win32_aio_submit(BlockDriverState *bs,
|
|
QEMUWin32AIOState *aio, HANDLE hfile,
|
|
uint64_t offset, uint64_t bytes, QEMUIOVector *qiov,
|
|
BlockCompletionFunc *cb, void *opaque, int type);
|
|
void win32_aio_detach_aio_context(QEMUWin32AIOState *aio,
|
|
AioContext *old_context);
|
|
void win32_aio_attach_aio_context(QEMUWin32AIOState *aio,
|
|
AioContext *new_context);
|
|
#endif
|
|
|
|
#endif /* QEMU_RAW_AIO_H */
|