Received: from eggs.gnu.org ([208.118.235.92]:36323) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1T6MJ9-0003hc-OI for qemu-devel@nongnu.org; Tue, 28 Aug 2012 09:58:29 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1T6MJ3-0005nc-Tf for qemu-devel@nongnu.org; Tue, 28 Aug 2012 09:58:19 -0400 Received: from e06smtp10.uk.ibm.com ([195.75.94.106]:37720) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1T6MJ3-0005nP-Hr for qemu-devel@nongnu.org; Tue, 28 Aug 2012 09:58:13 -0400 Received: from /spool/local by e06smtp10.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 28 Aug 2012 14:58:11 +0100 Received: from d06av01.portsmouth.uk.ibm.com (d06av01.portsmouth.uk.ibm.com [9.149.37.212]) by b06cxnps4074.portsmouth.uk.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id q7SDw2VK28573878 for ; Tue, 28 Aug 2012 13:58:02 GMT Received: from d06av01.portsmouth.uk.ibm.com (loopback [127.0.0.1]) by d06av01.portsmouth.uk.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id q7SDw8u4010452 for ; Tue, 28 Aug 2012 07:58:08 -0600 From: Stefan Hajnoczi Date: Tue, 28 Aug 2012 14:58:03 +0100 Message-Id: <1346162283-29761-1-git-send-email-stefanha@linux.vnet.ibm.com> Subject: [Qemu-devel] [PATCH for-1.2] stream: complete early if end of backing file is reached List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Kevin Wolf , Paolo Bonzini , Anthony Liguori , Stefan Hajnoczi 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 --- block/stream.c | 7 +++++++ 1 file changed, 7 insertions(+) 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); -- 1.7.10.4