qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] linux-aio: Allow reads beyond the end of growable images
@ 2011-10-13 13:49 Kevin Wolf
  2011-10-13 14:55 ` Stefan Hajnoczi
  2011-10-14  7:51 ` Christoph Hellwig
  0 siblings, 2 replies; 3+ messages in thread
From: Kevin Wolf @ 2011-10-13 13:49 UTC (permalink / raw)
  To: qemu-devel; +Cc: kwolf, stefanha

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 <kwolf@redhat.com>
---
 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

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [Qemu-devel] [PATCH] linux-aio: Allow reads beyond the end of growable images
  2011-10-13 13:49 [Qemu-devel] [PATCH] linux-aio: Allow reads beyond the end of growable images Kevin Wolf
@ 2011-10-13 14:55 ` Stefan Hajnoczi
  2011-10-14  7:51 ` Christoph Hellwig
  1 sibling, 0 replies; 3+ messages in thread
From: Stefan Hajnoczi @ 2011-10-13 14:55 UTC (permalink / raw)
  To: Kevin Wolf; +Cc: qemu-devel

On Thu, Oct 13, 2011 at 2:49 PM, Kevin Wolf <kwolf@redhat.com> wrote:
> 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 <kwolf@redhat.com>
> ---
>  linux-aio.c |   17 ++++++++++++++---
>  1 files changed, 14 insertions(+), 3 deletions(-)

Reviewed-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Qemu-devel] [PATCH] linux-aio: Allow reads beyond the end of growable images
  2011-10-13 13:49 [Qemu-devel] [PATCH] linux-aio: Allow reads beyond the end of growable images Kevin Wolf
  2011-10-13 14:55 ` Stefan Hajnoczi
@ 2011-10-14  7:51 ` Christoph Hellwig
  1 sibling, 0 replies; 3+ messages in thread
From: Christoph Hellwig @ 2011-10-14  7:51 UTC (permalink / raw)
  To: Kevin Wolf; +Cc: stefanha, qemu-devel

On Thu, Oct 13, 2011 at 03:49:39PM +0200, Kevin Wolf wrote:
> 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

Can you send a patch doing this for qemu-iotests?

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2011-10-14  7:51 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-10-13 13:49 [Qemu-devel] [PATCH] linux-aio: Allow reads beyond the end of growable images Kevin Wolf
2011-10-13 14:55 ` Stefan Hajnoczi
2011-10-14  7:51 ` Christoph Hellwig

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).