[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-block] [PATCH 06/12] file-posix: Avoid aio_worker() for QEMU_AIO_D
From: |
Kevin Wolf |
Subject: |
[Qemu-block] [PATCH 06/12] file-posix: Avoid aio_worker() for QEMU_AIO_DISCARD |
Date: |
Wed, 31 Oct 2018 22:56:16 +0100 |
aio_worker() doesn't add anything interesting, it's only a useless
indirection. Call the handler function directly instead.
As we know that this handler function is only called from coroutine
context and the coroutine stays around until the worker thread finishes,
we can keep RawPosixAIOData on the stack.
Signed-off-by: Kevin Wolf <address@hidden>
---
block/file-posix.c | 32 ++++++++++++++++++++++++--------
1 file changed, 24 insertions(+), 8 deletions(-)
diff --git a/block/file-posix.c b/block/file-posix.c
index 3d3bddd511..291ffaeded 100644
--- a/block/file-posix.c
+++ b/block/file-posix.c
@@ -1587,8 +1587,9 @@ static int handle_aiocb_copy_range(void *opaque)
return 0;
}
-static ssize_t handle_aiocb_discard(RawPosixAIOData *aiocb)
+static int handle_aiocb_discard(void *opaque)
{
+ RawPosixAIOData *aiocb = opaque;
int ret = -EOPNOTSUPP;
BDRVRawState *s = aiocb->bs->opaque;
@@ -1783,8 +1784,6 @@ static int aio_worker(void *arg)
ret = handle_aiocb_ioctl(aiocb);
break;
case QEMU_AIO_DISCARD:
- ret = handle_aiocb_discard(aiocb);
- break;
case QEMU_AIO_WRITE_ZEROES:
case QEMU_AIO_WRITE_ZEROES | QEMU_AIO_DISCARD:
case QEMU_AIO_COPY_RANGE:
@@ -2605,11 +2604,30 @@ static void coroutine_fn
raw_co_invalidate_cache(BlockDriverState *bs,
}
static coroutine_fn int
-raw_co_pdiscard(BlockDriverState *bs, int64_t offset, int bytes)
+raw_do_pdiscard(BlockDriverState *bs, int64_t offset, int bytes, bool blkdev)
{
BDRVRawState *s = bs->opaque;
+ RawPosixAIOData acb;
+
+ acb = (RawPosixAIOData) {
+ .bs = bs,
+ .aio_fildes = s->fd,
+ .aio_type = QEMU_AIO_DISCARD,
+ .aio_offset = offset,
+ .aio_nbytes = bytes,
+ };
- return paio_submit_co(bs, s->fd, offset, NULL, bytes, QEMU_AIO_DISCARD);
+ if (blkdev) {
+ acb.aio_type |= QEMU_AIO_BLKDEV;
+ }
+
+ return raw_thread_pool_submit(bs, handle_aiocb_discard, &acb);
+}
+
+static coroutine_fn int
+raw_co_pdiscard(BlockDriverState *bs, int64_t offset, int bytes)
+{
+ return raw_do_pdiscard(bs, offset, bytes, false);
}
static int coroutine_fn
@@ -3137,15 +3155,13 @@ static int fd_open(BlockDriverState *bs)
static coroutine_fn int
hdev_co_pdiscard(BlockDriverState *bs, int64_t offset, int bytes)
{
- BDRVRawState *s = bs->opaque;
int ret;
ret = fd_open(bs);
if (ret < 0) {
return ret;
}
- return paio_submit_co(bs, s->fd, offset, NULL, bytes,
- QEMU_AIO_DISCARD | QEMU_AIO_BLKDEV);
+ return raw_do_pdiscard(bs, offset, bytes, true);
}
static coroutine_fn int hdev_co_pwrite_zeroes(BlockDriverState *bs,
--
2.19.1
- [Qemu-block] [PATCH 00/12] file-posix: Simplify delegation to worker thread, Kevin Wolf, 2018/10/31
- [Qemu-block] [PATCH 04/12] file-posix: Avoid aio_worker() for QEMU_AIO_COPY_RANGE, Kevin Wolf, 2018/10/31
- [Qemu-block] [PATCH 06/12] file-posix: Avoid aio_worker() for QEMU_AIO_DISCARD,
Kevin Wolf <=
- [Qemu-block] [PATCH 07/12] file-posix: Avoid aio_worker() for QEMU_AIO_FLUSH, Kevin Wolf, 2018/10/31
- [Qemu-block] [PATCH 02/12] file-posix: Factor out raw_thread_pool_submit(), Kevin Wolf, 2018/10/31
- [Qemu-block] [PATCH 03/12] file-posix: Avoid aio_worker() for QEMU_AIO_TRUNCATE, Kevin Wolf, 2018/10/31
- [Qemu-block] [PATCH 05/12] file-posix: Avoid aio_worker() for QEMU_AIO_WRITE_ZEROES, Kevin Wolf, 2018/10/31
- [Qemu-block] [PATCH 01/12] file-posix: Reorganise RawPosixAIOData, Kevin Wolf, 2018/10/31
- [Qemu-block] [PATCH 10/12] file-posix: Remove paio_submit_co(), Kevin Wolf, 2018/10/31
- [Qemu-block] [PATCH 09/12] file-posix: Avoid aio_worker() for QEMU_AIO_READ/WRITE, Kevin Wolf, 2018/10/31
- [Qemu-block] [PATCH 11/12] file-posix: Switch to .bdrv_co_ioctl, Kevin Wolf, 2018/10/31
- [Qemu-block] [PATCH 08/12] file-posix: Move read/write operation logic out of aio_worker(), Kevin Wolf, 2018/10/31
- [Qemu-block] [PATCH 12/12] file-posix: Avoid aio_worker() for QEMU_AIO_IOCTL, Kevin Wolf, 2018/10/31