From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55942) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VHGSY-0003TB-8i for qemu-devel@nongnu.org; Wed, 04 Sep 2013 13:01:46 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VHGSO-0006Fo-T7 for qemu-devel@nongnu.org; Wed, 04 Sep 2013 13:01:38 -0400 Received: from mail-qa0-x235.google.com ([2607:f8b0:400d:c00::235]:53872) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VHGSO-0006Fd-PM for qemu-devel@nongnu.org; Wed, 04 Sep 2013 13:01:28 -0400 Received: by mail-qa0-f53.google.com with SMTP id i13so339271qae.12 for ; Wed, 04 Sep 2013 10:01:28 -0700 (PDT) Sender: Paolo Bonzini From: Paolo Bonzini Date: Wed, 4 Sep 2013 19:00:38 +0200 Message-Id: <1378314038-15525-22-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 21/21] block: look for zero blocks in bs->file List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: stefanha@redhat.com Reviewed-by: Eric Blake Signed-off-by: Paolo Bonzini --- block.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/block.c b/block.c index 18cdfe6..6e6f974 100644 --- a/block.c +++ b/block.c @@ -3055,7 +3055,7 @@ static int64_t coroutine_fn bdrv_co_get_block_status(BlockDriverState *bs, { int64_t length; int64_t n; - int64_t ret; + int64_t ret, ret2; length = bdrv_getlength(bs); if (length < 0) { @@ -3097,6 +3097,20 @@ static int64_t coroutine_fn bdrv_co_get_block_status(BlockDriverState *bs, } } } + + if (bs->file && + (ret & BDRV_BLOCK_DATA) && !(ret & BDRV_BLOCK_ZERO) && + (ret & BDRV_BLOCK_OFFSET_VALID)) { + ret2 = bdrv_co_get_block_status(bs->file, ret >> BDRV_SECTOR_BITS, + *pnum, pnum); + if (ret2 >= 0) { + /* Ignore errors. This is just providing extra information, it + * is useful but not necessary. + */ + ret |= (ret2 & BDRV_BLOCK_ZERO); + } + } + return ret; } -- 1.8.3.1