From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55846) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VHGSO-00039t-Go for qemu-devel@nongnu.org; Wed, 04 Sep 2013 13:01:36 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VHGSD-0006BE-AV for qemu-devel@nongnu.org; Wed, 04 Sep 2013 13:01:28 -0400 Received: from mail-qc0-x232.google.com ([2607:f8b0:400d:c01::232]:55663) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VHGSD-0006Az-7G for qemu-devel@nongnu.org; Wed, 04 Sep 2013 13:01:17 -0400 Received: by mail-qc0-f178.google.com with SMTP id r5so317438qcx.23 for ; Wed, 04 Sep 2013 10:01:16 -0700 (PDT) Sender: Paolo Bonzini From: Paolo Bonzini Date: Wed, 4 Sep 2013 19:00:32 +0200 Message-Id: <1378314038-15525-16-git-send-email-pbonzini@redhat.com> In-Reply-To: <1378314038-15525-1-git-send-email-pbonzini@redhat.com> References: <1378314038-15525-1-git-send-email-pbonzini@redhat.com> Subject: [Qemu-devel] [PATCH v5 15/21] block: return BDRV_BLOCK_ZERO past end of backing file List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: stefanha@redhat.com 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 --- block.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/block.c b/block.c index b6d380f..6df387c 100644 --- a/block.c +++ b/block.c @@ -3082,8 +3082,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; } -- 1.8.3.1