Received: from eggs.gnu.org ([2001:4830:134:3::10]:40787) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VHy9X-0005i5-UG for qemu-devel@nongnu.org; Fri, 06 Sep 2013 11:41:01 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VHy9R-0005gA-9n for qemu-devel@nongnu.org; Fri, 06 Sep 2013 11:40:55 -0400 Received: from mx1.redhat.com ([209.132.183.28]:16709) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VHy9Q-0005fu-S7 for qemu-devel@nongnu.org; Fri, 06 Sep 2013 11:40:49 -0400 From: Stefan Hajnoczi Date: Fri, 6 Sep 2013 17:39:03 +0200 Message-Id: <1378481953-23099-33-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> Subject: [Qemu-devel] [PULL 32/42] 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: Paolo Bonzini , Stefan Hajnoczi , Anthony Liguori From: Paolo Bonzini Alternatively, this could use a "discard zeroes data" flag returned by bdrv_get_info. Reviewed-by: Eric Blake Signed-off-by: Paolo Bonzini Signed-off-by: Stefan Hajnoczi --- block.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/block.c b/block.c index 97406ec..aa9ec83 100644 --- a/block.c +++ b/block.c @@ -3075,6 +3075,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) { @@ -3096,7 +3097,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