From patchwork Tue Aug 28 14:26:48 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Hajnoczi X-Patchwork-Id: 180507 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 4F4E42C015E for ; Wed, 29 Aug 2012 00:27:39 +1000 (EST) Received: from localhost ([::1]:56375 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1T6MlV-00031R-BF for incoming@patchwork.ozlabs.org; Tue, 28 Aug 2012 10:27:37 -0400 Received: from eggs.gnu.org ([208.118.235.92]:51351) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1T6Ml4-00022c-Di for qemu-devel@nongnu.org; Tue, 28 Aug 2012 10:27:16 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1T6Mkt-0006aL-Ef for qemu-devel@nongnu.org; Tue, 28 Aug 2012 10:27:10 -0400 Received: from e06smtp15.uk.ibm.com ([195.75.94.111]:35143) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1T6Mkt-0006aE-4v for qemu-devel@nongnu.org; Tue, 28 Aug 2012 10:26:59 -0400 Received: from /spool/local by e06smtp15.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 28 Aug 2012 15:26:58 +0100 Received: from b06cxnps3075.portsmouth.uk.ibm.com (9.149.109.195) by e06smtp15.uk.ibm.com (192.168.101.145) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Tue, 28 Aug 2012 15:26:56 +0100 Received: from d06av01.portsmouth.uk.ibm.com (d06av01.portsmouth.uk.ibm.com [9.149.37.212]) by b06cxnps3075.portsmouth.uk.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id q7SEQnZr21889188 for ; Tue, 28 Aug 2012 14:26:49 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 q7SEQt5A008726 for ; Tue, 28 Aug 2012 08:26:55 -0600 Received: from localhost (stefanha-thinkpad.manchester-maybrook.uk.ibm.com [9.174.219.145]) by d06av01.portsmouth.uk.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id q7SEQs9V008715; Tue, 28 Aug 2012 08:26:55 -0600 From: Stefan Hajnoczi To: Date: Tue, 28 Aug 2012 15:26:48 +0100 Message-Id: <1346164009-30648-2-git-send-email-stefanha@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1346164009-30648-1-git-send-email-stefanha@linux.vnet.ibm.com> References: <1346164009-30648-1-git-send-email-stefanha@linux.vnet.ibm.com> x-cbid: 12082814-0342-0000-0000-000002AFF859 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 195.75.94.111 Cc: Kevin Wolf , Paolo Bonzini , Anthony Liguori , Stefan Hajnoczi Subject: [Qemu-devel] [PATCH v2 for-1.2 1/2] stream: complete early if end of backing file is reached X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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 Reviewed-by: Paolo Bonzini --- block/stream.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/block/stream.c b/block/stream.c index 37c4652..c4f87dd 100644 --- a/block/stream.c +++ b/block/stream.c @@ -122,6 +122,12 @@ 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) { + n = end - sector_num; + } + copy = (ret == 1); } trace_stream_one_iteration(s, sector_num, n, ret);