[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-block] [PULL 19/41] file-posix: Avoid aio_worker() for QEMU_AIO_DI
From: |
Kevin Wolf |
Subject: |
[Qemu-block] [PULL 19/41] file-posix: Avoid aio_worker() for QEMU_AIO_DISCARD |
Date: |
Wed, 12 Dec 2018 14:27:13 +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 16f2b202c6..88887108a7 100644
--- a/block/file-posix.c
+++ b/block/file-posix.c
@@ -1608,8 +1608,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;
@@ -1804,8 +1805,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:
@@ -2622,11 +2621,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
@@ -3154,15 +3172,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.2
- [Qemu-block] [PULL 09/41] qcow2: move decompression from qcow2-cluster.c to qcow2.c, (continued)
- [Qemu-block] [PULL 09/41] qcow2: move decompression from qcow2-cluster.c to qcow2.c, Kevin Wolf, 2018/12/12
- [Qemu-block] [PULL 10/41] qcow2: refactor decompress_buffer, Kevin Wolf, 2018/12/12
- [Qemu-block] [PULL 13/41] qcow2: do decompression in threads, Kevin Wolf, 2018/12/12
- [Qemu-block] [PULL 12/41] qcow2: aio support for compressed cluster read, Kevin Wolf, 2018/12/12
- [Qemu-block] [PULL 14/41] file-posix: Reorganise RawPosixAIOData, Kevin Wolf, 2018/12/12
- [Qemu-block] [PULL 15/41] file-posix: Factor out raw_thread_pool_submit(), Kevin Wolf, 2018/12/12
- [Qemu-block] [PULL 16/41] file-posix: Avoid aio_worker() for QEMU_AIO_TRUNCATE, Kevin Wolf, 2018/12/12
- [Qemu-block] [PULL 18/41] file-posix: Avoid aio_worker() for QEMU_AIO_WRITE_ZEROES, Kevin Wolf, 2018/12/12
- [Qemu-block] [PULL 17/41] file-posix: Avoid aio_worker() for QEMU_AIO_COPY_RANGE, Kevin Wolf, 2018/12/12
- [Qemu-block] [PULL 20/41] file-posix: Avoid aio_worker() for QEMU_AIO_FLUSH, Kevin Wolf, 2018/12/12
- [Qemu-block] [PULL 19/41] file-posix: Avoid aio_worker() for QEMU_AIO_DISCARD,
Kevin Wolf <=
- [Qemu-block] [PULL 21/41] file-posix: Move read/write operation logic out of aio_worker(), Kevin Wolf, 2018/12/12
- [Qemu-block] [PULL 22/41] file-posix: Avoid aio_worker() for QEMU_AIO_READ/WRITE, Kevin Wolf, 2018/12/12
- [Qemu-block] [PULL 24/41] file-posix: Switch to .bdrv_co_ioctl, Kevin Wolf, 2018/12/12
- [Qemu-block] [PULL 23/41] file-posix: Remove paio_submit_co(), Kevin Wolf, 2018/12/12
- [Qemu-block] [PULL 26/41] block: Add bdrv_reopen_set_read_only(), Kevin Wolf, 2018/12/12
- [Qemu-block] [PULL 25/41] file-posix: Avoid aio_worker() for QEMU_AIO_IOCTL, Kevin Wolf, 2018/12/12
- [Qemu-block] [PULL 27/41] block: Use bdrv_reopen_set_read_only() in bdrv_backing_update_filename(), Kevin Wolf, 2018/12/12
- [Qemu-block] [PULL 28/41] block: Use bdrv_reopen_set_read_only() in commit_start/complete(), Kevin Wolf, 2018/12/12
- [Qemu-block] [PULL 30/41] block: Use bdrv_reopen_set_read_only() in stream_start/complete(), Kevin Wolf, 2018/12/12
- [Qemu-block] [PULL 29/41] block: Use bdrv_reopen_set_read_only() in bdrv_commit(), Kevin Wolf, 2018/12/12