[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-block] [PULL 21/41] file-posix: Move read/write operation logic ou
From: |
Kevin Wolf |
Subject: |
[Qemu-block] [PULL 21/41] file-posix: Move read/write operation logic out of aio_worker() |
Date: |
Wed, 12 Dec 2018 14:27:15 +0100 |
aio_worker() for reads and writes isn't boring enough yet. It still does
some postprocessing for handling short reads and turning the result into
the right return value.
However, there is no reason why handle_aiocb_rw() couldn't do the same,
and even without duplicating code between the read and write path. So
move the code there.
Signed-off-by: Kevin Wolf <address@hidden>
---
block/file-posix.c | 40 ++++++++++++++++++++--------------------
1 file changed, 20 insertions(+), 20 deletions(-)
diff --git a/block/file-posix.c b/block/file-posix.c
index 4a94597b80..877c0700e1 100644
--- a/block/file-posix.c
+++ b/block/file-posix.c
@@ -1311,7 +1311,8 @@ static ssize_t handle_aiocb_rw(RawPosixAIOData *aiocb)
* we can just use plain pread/pwrite without any problems.
*/
if (aiocb->io.niov == 1) {
- return handle_aiocb_rw_linear(aiocb, aiocb->io.iov->iov_base);
+ nbytes = handle_aiocb_rw_linear(aiocb, aiocb->io.iov->iov_base);
+ goto out;
}
/*
* We have more than one iovec, and all are properly aligned.
@@ -1323,7 +1324,7 @@ static ssize_t handle_aiocb_rw(RawPosixAIOData *aiocb)
nbytes = handle_aiocb_rw_vector(aiocb);
if (nbytes == aiocb->aio_nbytes ||
(nbytes < 0 && nbytes != -ENOSYS)) {
- return nbytes;
+ goto out;
}
preadv_present = false;
}
@@ -1341,7 +1342,8 @@ static ssize_t handle_aiocb_rw(RawPosixAIOData *aiocb)
*/
buf = qemu_try_blockalign(aiocb->bs, aiocb->aio_nbytes);
if (buf == NULL) {
- return -ENOMEM;
+ nbytes = -ENOMEM;
+ goto out;
}
if (aiocb->aio_type & QEMU_AIO_WRITE) {
@@ -1375,7 +1377,21 @@ static ssize_t handle_aiocb_rw(RawPosixAIOData *aiocb)
}
qemu_vfree(buf);
- return nbytes;
+out:
+ if (nbytes == aiocb->aio_nbytes) {
+ return 0;
+ } else if (nbytes >= 0 && nbytes < aiocb->aio_nbytes) {
+ if (aiocb->aio_type & QEMU_AIO_WRITE) {
+ return -EINVAL;
+ } else {
+ iov_memset(aiocb->io.iov, aiocb->io.niov, nbytes,
+ 0, aiocb->aio_nbytes - nbytes);
+ return 0;
+ }
+ } else {
+ assert(nbytes < 0);
+ return nbytes;
+ }
}
#ifdef CONFIG_XFS
@@ -1779,25 +1795,9 @@ static int aio_worker(void *arg)
switch (aiocb->aio_type & QEMU_AIO_TYPE_MASK) {
case QEMU_AIO_READ:
ret = handle_aiocb_rw(aiocb);
- if (ret >= 0 && ret < aiocb->aio_nbytes) {
- iov_memset(aiocb->io.iov, aiocb->io.niov, ret,
- 0, aiocb->aio_nbytes - ret);
-
- ret = aiocb->aio_nbytes;
- }
- if (ret == aiocb->aio_nbytes) {
- ret = 0;
- } else if (ret >= 0 && ret < aiocb->aio_nbytes) {
- ret = -EINVAL;
- }
break;
case QEMU_AIO_WRITE:
ret = handle_aiocb_rw(aiocb);
- if (ret == aiocb->aio_nbytes) {
- ret = 0;
- } else if (ret >= 0 && ret < aiocb->aio_nbytes) {
- ret = -EINVAL;
- }
break;
case QEMU_AIO_IOCTL:
ret = handle_aiocb_ioctl(aiocb);
--
2.19.2
- [Qemu-block] [PULL 10/41] qcow2: refactor decompress_buffer, (continued)
- [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, 2018/12/12
- [Qemu-block] [PULL 21/41] file-posix: Move read/write operation logic out of aio_worker(),
Kevin Wolf <=
- [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
- [Qemu-block] [PULL 31/41] block: Use bdrv_reopen_set_read_only() in qmp_change_backing_file(), Kevin Wolf, 2018/12/12