[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH 1/4] block/file-posix: set up Linux AIO and io_uring in the c
From: |
Eric Blake |
Subject: |
Re: [PATCH 1/4] block/file-posix: set up Linux AIO and io_uring in the current thread |
Date: |
Thu, 14 Sep 2023 10:47:38 -0500 |
User-agent: |
NeoMutt/20230517 |
On Thu, Sep 14, 2023 at 10:00:58AM -0400, Stefan Hajnoczi wrote:
> The file-posix block driver currently only sets up Linux AIO and
> io_uring in the BDS's AioContext. In the multi-queue block layer we must
> be able to submit I/O requests in AioContexts that do not have Linux AIO
> and io_uring set up yet since any thread can call into the block driver.
>
> Set up Linux AIO and io_uring for the current AioContext during request
> submission. We lose the ability to return an error from
> .bdrv_file_open() when Linux AIO and io_uring setup fails (e.g. due to
> resource limits). Instead the user only gets warnings and we fall back
> to aio=threads. This is still better than a fatal error after startup.
>
> Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
> ---
> block/file-posix.c | 99 ++++++++++++++++++++++------------------------
> 1 file changed, 47 insertions(+), 52 deletions(-)
>
> diff --git a/block/file-posix.c b/block/file-posix.c
> index 4757914ac0..e9dbb87c57 100644
> --- a/block/file-posix.c
> +++ b/block/file-posix.c
> @@ -713,17 +713,11 @@ static int raw_open_common(BlockDriverState *bs, QDict
> *options,
>
> #ifdef CONFIG_LINUX_AIO
> /* Currently Linux does AIO only for files opened with O_DIRECT */
> - if (s->use_linux_aio) {
> - if (!(s->open_flags & O_DIRECT)) {
> - error_setg(errp, "aio=native was specified, but it requires "
> - "cache.direct=on, which was not specified.");
> - ret = -EINVAL;
> - goto fail;
> - }
> - if (!aio_setup_linux_aio(bdrv_get_aio_context(bs), errp)) {
We were previously doing setup only once during open...
> +static inline bool raw_check_linux_io_uring(BDRVRawState *s)
> +{
> + Error *local_err = NULL;
> + AioContext *ctx;
> +
> + if (!s->use_linux_io_uring) {
> + return false;
> + }
> +
> + ctx = qemu_get_current_aio_context();
> + if (unlikely(!aio_setup_linux_io_uring(ctx, &local_err))) {
...now you're doing it on ever I/O request. I had to check that setup
is idempotent; thankfully it is (once ctx has an associated linux_aio
or io_uring, setup is a no-op for subsequent calls).
Reviewed-by: Eric Blake <eblake@redhat.com>
--
Eric Blake, Principal Software Engineer
Red Hat, Inc.
Virtualization: qemu.org | libguestfs.org
- [PATCH 0/4] virtio-blk: prepare for the multi-queue block layer, Stefan Hajnoczi, 2023/09/14
- [PATCH 4/4] virtio-blk: don't lock AioContext in the submission code path, Stefan Hajnoczi, 2023/09/14
- [PATCH 2/4] virtio-blk: add lock to protect s->rq, Stefan Hajnoczi, 2023/09/14
- [PATCH 3/4] virtio-blk: don't lock AioContext in the completion code path, Stefan Hajnoczi, 2023/09/14
- [PATCH 1/4] block/file-posix: set up Linux AIO and io_uring in the current thread, Stefan Hajnoczi, 2023/09/14
- Re: [PATCH 1/4] block/file-posix: set up Linux AIO and io_uring in the current thread,
Eric Blake <=
- Re: [PATCH 0/4] virtio-blk: prepare for the multi-queue block layer, Michael S. Tsirkin, 2023/09/15