Received: from eggs.gnu.org ([2001:4830:134:3::10]:54099) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VF2me-00074i-10 for qemu-devel@nongnu.org; Thu, 29 Aug 2013 10:01:20 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VF2mV-0008Ar-Ju for qemu-devel@nongnu.org; Thu, 29 Aug 2013 10:01:11 -0400 Received: from mail-ee0-x22e.google.com ([2a00:1450:4013:c00::22e]:34273) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VF2mV-0008Ae-Dy for qemu-devel@nongnu.org; Thu, 29 Aug 2013 10:01:03 -0400 Received: by mail-ee0-f46.google.com with SMTP id c13so268440eek.33 for ; Thu, 29 Aug 2013 07:01:02 -0700 (PDT) Sender: Paolo Bonzini From: Paolo Bonzini Date: Thu, 29 Aug 2013 16:00:14 +0200 Message-Id: <1377784821-29561-15-git-send-email-pbonzini@redhat.com> In-Reply-To: <1377784821-29561-1-git-send-email-pbonzini@redhat.com> References: <1377784821-29561-1-git-send-email-pbonzini@redhat.com> Subject: [Qemu-devel] [PATCH v4 14/21] block: use bdrv_has_zero_init to return BDRV_BLOCK_ZERO List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: kwolf@redhat.com, stefanha@redhat.com Alternatively, this could use a "discard zeroes data" flag returned by bdrv_get_info. Reviewed-by: Eric Blake Signed-off-by: Paolo Bonzini --- block.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/block.c b/block.c index c9756f5..ecae287 100644 --- a/block.c +++ b/block.c @@ -3001,6 +3001,7 @@ static int64_t coroutine_fn bdrv_co_get_block_status(BlockDriverState *bs, { int64_t length; int64_t n; + int64_t ret; length = bdrv_getlength(bs); if (length < 0) { @@ -3022,7 +3023,15 @@ static int64_t coroutine_fn bdrv_co_get_block_status(BlockDriverState *bs, return BDRV_BLOCK_DATA; } - return bs->drv->bdrv_co_get_block_status(bs, sector_num, nb_sectors, pnum); + ret = bs->drv->bdrv_co_get_block_status(bs, sector_num, nb_sectors, pnum); + if (ret < 0) { + return ret; + } + + if (!(ret & BDRV_BLOCK_DATA) && bdrv_has_zero_init(bs)) { + ret |= BDRV_BLOCK_ZERO; + } + return ret; } /* Coroutine wrapper for bdrv_get_block_status() */ -- 1.8.3.1