Patchwork [for-1.2] stream: complete early if end of backing file is reached

login
register
mail settings
Submitter Stefan Hajnoczi
Date Aug. 28, 2012, 1:58 p.m.
Message ID <1346162283-29761-1-git-send-email-stefanha@linux.vnet.ibm.com>
Download mbox | patch
Permalink /patch/180497/
State New
Headers show

Comments

Stefan Hajnoczi - Aug. 28, 2012, 1:58 p.m.
It is possible to create an image that is larger than its backing file.
Reading beyond the end of the backing file produces zeroes if no writes
have been made to those sectors in the image file.

This patch finishes streaming early when the end of the backing file is
reached.  Without this patch the block job hangs and continually tries
to stream the first sectors beyond the end of the backing file.

To reproduce the hung block job bug:

  $ qemu-img create -f qcow2 backing.qcow2 128M
  $ qemu-img create -f qcow2 -o backing_file=backing.qcow2 image.qcow2 6G
  $ qemu -drive if=virtio,cache=none,file=image.qcow2
  (qemu) block_stream virtio0
  (qemu) info block-jobs

The qemu-iotests 030 streaming test still passes.

Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
---
 block/stream.c |    7 +++++++
 1 file changed, 7 insertions(+)
Stefan Hajnoczi - Aug. 28, 2012, 2:16 p.m.
On Tue, Aug 28, 2012 at 2:58 PM, Stefan Hajnoczi
<stefanha@linux.vnet.ibm.com> wrote:
> It is possible to create an image that is larger than its backing file.
> Reading beyond the end of the backing file produces zeroes if no writes
> have been made to those sectors in the image file.
>
> This patch finishes streaming early when the end of the backing file is
> reached.  Without this patch the block job hangs and continually tries
> to stream the first sectors beyond the end of the backing file.
>
> To reproduce the hung block job bug:
>
>   $ qemu-img create -f qcow2 backing.qcow2 128M
>   $ qemu-img create -f qcow2 -o backing_file=backing.qcow2 image.qcow2 6G
>   $ qemu -drive if=virtio,cache=none,file=image.qcow2
>   (qemu) block_stream virtio0
>   (qemu) info block-jobs
>
> The qemu-iotests 030 streaming test still passes.
>
> Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
> ---
>  block/stream.c |    7 +++++++
>  1 file changed, 7 insertions(+)

I will resend this along with a test case.

Stefan

Patch

diff --git a/block/stream.c b/block/stream.c
index 37c4652..331ba21 100644
--- a/block/stream.c
+++ b/block/stream.c
@@ -122,6 +122,13 @@  wait:
              * known-unallocated area [sector_num, sector_num+n).  */
             ret = bdrv_co_is_allocated_above(bs->backing_hd, base,
                                              sector_num, n, &n);
+
+            /* Finish early if end of backing file has been reached */
+            if (ret == 0 && n == 0) {
+                sector_num = end;
+                break;
+            }
+
             copy = (ret == 1);
         }
         trace_stream_one_iteration(s, sector_num, n, ret);