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 <stefa...@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 <ebl...@redhat.com> -- Eric Blake, Principal Software Engineer Red Hat, Inc. Virtualization: qemu.org | libguestfs.org