[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 19/24] linux-aio: Allow reads beyond the end of grow
From: |
Kevin Wolf |
Subject: |
[Qemu-devel] [PATCH 19/24] linux-aio: Allow reads beyond the end of growable images |
Date: |
Fri, 14 Oct 2011 18:49:14 +0200 |
This is the linux-aio version of commits 22afa7b5 (raw-posix, synchronous) and
ba1d1afd (posix-aio-compat). Reads now produce zeros after the end of file
instead of failing or resulting in short reads, making linux-aio compatible
with the behaviour of synchronous raw-posix requests and posix-aio-compat.
The problem can be reproduced like this:
dd if=/dev/zero of=/tmp/test.raw bs=1 count=1234
./qemu-io -k -n -g -c 'read -p 1024 512' /tmp/test.raw
Previously, the result of this was 'read failed: Invalid argument', now the
read completes successfully.
Signed-off-by: Kevin Wolf <address@hidden>
Reviewed-by: Stefan Hajnoczi <address@hidden>
---
linux-aio.c | 17 ++++++++++++++---
1 files changed, 14 insertions(+), 3 deletions(-)
diff --git a/linux-aio.c b/linux-aio.c
index 50da75d..1c635ef 100644
--- a/linux-aio.c
+++ b/linux-aio.c
@@ -31,6 +31,8 @@ struct qemu_laiocb {
struct iocb iocb;
ssize_t ret;
size_t nbytes;
+ QEMUIOVector *qiov;
+ bool is_read;
QLIST_ENTRY(qemu_laiocb) node;
};
@@ -57,10 +59,17 @@ static void qemu_laio_process_completion(struct
qemu_laio_state *s,
ret = laiocb->ret;
if (ret != -ECANCELED) {
- if (ret == laiocb->nbytes)
+ if (ret == laiocb->nbytes) {
ret = 0;
- else if (ret >= 0)
- ret = -EINVAL;
+ } else if (ret >= 0) {
+ /* Short reads mean EOF, pad with zeros. */
+ if (laiocb->is_read) {
+ qemu_iovec_memset_skip(laiocb->qiov, 0,
+ laiocb->qiov->size - ret, ret);
+ } else {
+ ret = -EINVAL;
+ }
+ }
laiocb->common.cb(laiocb->common.opaque, ret);
}
@@ -162,6 +171,8 @@ BlockDriverAIOCB *laio_submit(BlockDriverState *bs, void
*aio_ctx, int fd,
laiocb->nbytes = nb_sectors * 512;
laiocb->ctx = s;
laiocb->ret = -EINPROGRESS;
+ laiocb->is_read = (type == QEMU_AIO_READ);
+ laiocb->qiov = qiov;
iocbs = &laiocb->iocb;
--
1.7.6.4
- [Qemu-devel] [PATCH 13/24] block: directly invoke .bdrv_* from emulation functions, (continued)
- [Qemu-devel] [PATCH 13/24] block: directly invoke .bdrv_* from emulation functions, Kevin Wolf, 2011/10/14
- [Qemu-devel] [PATCH 11/24] vvfat: Fix potential buffer overflow, Kevin Wolf, 2011/10/14
- [Qemu-devel] [PATCH 10/24] block/vvfat: Remove unused code, Kevin Wolf, 2011/10/14
- [Qemu-devel] [PATCH 12/24] block: directly invoke .bdrv_aio_*() in bdrv_co_io_em(), Kevin Wolf, 2011/10/14
- [Qemu-devel] [PATCH 14/24] block: split out bdrv_co_do_readv() and bdrv_co_do_writev(), Kevin Wolf, 2011/10/14
- [Qemu-devel] [PATCH 15/24] block: switch bdrv_read()/bdrv_write() to coroutines, Kevin Wolf, 2011/10/14
- [Qemu-devel] [PATCH 17/24] block: mark blocks dirty on coroutine write completion, Kevin Wolf, 2011/10/14
- [Qemu-devel] [PATCH 16/24] block: switch bdrv_aio_readv() to coroutines, Kevin Wolf, 2011/10/14
- [Qemu-devel] [PATCH 18/24] block: switch bdrv_aio_writev() to coroutines, Kevin Wolf, 2011/10/14
- [Qemu-devel] [PATCH 19/24] linux-aio: Allow reads beyond the end of growable images,
Kevin Wolf <=
- [Qemu-devel] [PATCH 20/24] block: drop emulation functions that use coroutines, Kevin Wolf, 2011/10/14
- [Qemu-devel] [PATCH 23/24] block: drop .bdrv_read()/.bdrv_write() emulation, Kevin Wolf, 2011/10/14
- [Qemu-devel] [PATCH 22/24] block: use coroutine interface for raw format, Kevin Wolf, 2011/10/14
- [Qemu-devel] [PATCH 24/24] block: drop bdrv_has_async_rw(), Kevin Wolf, 2011/10/14
- [Qemu-devel] [PATCH 21/24] raw-posix: remove bdrv_read()/bdrv_write(), Kevin Wolf, 2011/10/14
- Re: [Qemu-devel] [PULL 00/24] Block patches, Anthony Liguori, 2011/10/14