From patchwork Fri Sep 6 15:39:04 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Hajnoczi X-Patchwork-Id: 273302 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 109F82C0115 for ; Sat, 7 Sep 2013 03:21:55 +1000 (EST) Received: from localhost ([::1]:38494 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VHyI1-0007My-EU for incoming@patchwork.ozlabs.org; Fri, 06 Sep 2013 11:49:41 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40810) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VHy9a-0005jB-3p for qemu-devel@nongnu.org; Fri, 06 Sep 2013 11:41:04 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VHy9T-0005h5-Rc for qemu-devel@nongnu.org; Fri, 06 Sep 2013 11:40:58 -0400 Received: from mx1.redhat.com ([209.132.183.28]:13399) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VHy9T-0005go-0m for qemu-devel@nongnu.org; Fri, 06 Sep 2013 11:40:51 -0400 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r86Fenxi004792 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 6 Sep 2013 11:40:49 -0400 Received: from localhost (ovpn-112-53.ams2.redhat.com [10.36.112.53]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id r86FemSl023774; Fri, 6 Sep 2013 11:40:48 -0400 From: Stefan Hajnoczi To: Date: Fri, 6 Sep 2013 17:39:04 +0200 Message-Id: <1378481953-23099-34-git-send-email-stefanha@redhat.com> In-Reply-To: <1378481953-23099-1-git-send-email-stefanha@redhat.com> References: <1378481953-23099-1-git-send-email-stefanha@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: Paolo Bonzini , Stefan Hajnoczi , Anthony Liguori Subject: [Qemu-devel] [PULL 33/42] block: return BDRV_BLOCK_ZERO past end of backing file 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 From: Paolo Bonzini If the sectors are unallocated and we are past the end of the backing file, they will read as zero. Signed-off-by: Paolo Bonzini Signed-off-by: Stefan Hajnoczi --- block.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/block.c b/block.c index aa9ec83..82bbd6c 100644 --- a/block.c +++ b/block.c @@ -3102,8 +3102,16 @@ static int64_t coroutine_fn bdrv_co_get_block_status(BlockDriverState *bs, return ret; } - if (!(ret & BDRV_BLOCK_DATA) && bdrv_has_zero_init(bs)) { - ret |= BDRV_BLOCK_ZERO; + if (!(ret & BDRV_BLOCK_DATA)) { + if (bdrv_has_zero_init(bs)) { + ret |= BDRV_BLOCK_ZERO; + } else { + BlockDriverState *bs2 = bs->backing_hd; + int64_t length2 = bdrv_getlength(bs2); + if (length2 >= 0 && sector_num >= (length2 >> BDRV_SECTOR_BITS)) { + ret |= BDRV_BLOCK_ZERO; + } + } } return ret; }