aboutsummaryrefslogtreecommitdiff
path: root/block
diff options
context:
space:
mode:
authorKevin Wolf <kwolf@redhat.com>2018-10-25 14:18:58 +0100
committerKevin Wolf <kwolf@redhat.com>2018-12-14 11:52:41 +0100
commit46ee0f462bfa1e374fa0f5df5834b061a632af6d (patch)
tree58e12510cde3e1cc1aeaac9f8823c3c814dbc833 /block
parent7154d8ae66c75c97b08c8f1c80dd6f46f0dbffca (diff)
file-posix: Avoid aio_worker() for QEMU_AIO_DISCARD
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 <kwolf@redhat.com>
Diffstat (limited to 'block')
-rw-r--r--block/file-posix.c32
1 files 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,