From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55161) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WhKLk-00044q-7R for qemu-devel@nongnu.org; Mon, 05 May 2014 10:58:42 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WhKLd-0003Id-UA for qemu-devel@nongnu.org; Mon, 05 May 2014 10:58:36 -0400 Received: from mx1.redhat.com ([209.132.183.28]:57087) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WhKLd-0003IN-Kj for qemu-devel@nongnu.org; Mon, 05 May 2014 10:58:29 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s45EwSIq023660 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Mon, 5 May 2014 10:58:28 -0400 Message-ID: <5367A711.607@redhat.com> Date: Mon, 05 May 2014 16:58:25 +0200 From: Paolo Bonzini MIME-Version: 1.0 References: <1378314038-15525-1-git-send-email-pbonzini@redhat.com> <1378314038-15525-13-git-send-email-pbonzini@redhat.com> <20140505143412.GE3317@noname.str.redhat.com> In-Reply-To: <20140505143412.GE3317@noname.str.redhat.com> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH v5 12/21] block: define get_block_status return value List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Kevin Wolf Cc: qemu-devel@nongnu.org, stefanha@redhat.com Il 05/05/2014 16:34, Kevin Wolf ha scritto: > I think we're missing the information whether the BDRV_BLOCK_ZERO flag > actually comes from bs itself or from the backing chain. Do we need > another flag or does someone have a better idea? Not sure if it is a better idea :) but we can duplicate the logic of bdrv_get_co_block_status in bdrv_is_allocated. The observation here is that bdrv_has_zero_init should have been changed to bdrv_unallocated_blocks_are_zero in commit c3d8688 (block/get_block_status: fix BDRV_BLOCK_ZERO for unallocated blocks, 2013-10-24); the logic in the commit message applies just as well to bdrv_is_allocated. Of course, instead of cut-and-paste we can wrap all this into a bdrv_unallocated_block_is_zero(bs, sector_num) function like this: if (bdrv_unallocated_blocks_are_zero(bs)) { return true; } if (bs->backing_hd) { BlockDriverState *bs2 = bs->backing_hd; int64_t length2 = bdrv_getlength(bs2); if (length2 >= 0 && sector_num >= (length2 >> BDRV_SECTOR_BITS)) { return true; } } return false; The function can then be used in bdrv_get_block_status to add a BDRV_BLOCK_ZERO, and in bdrv_is_allocated instead of bdrv_has_zero_init. (Bonus points for renaming bdrv_is_allocated to something like bdrv_has_content, and similarly for bdrv_is_allocated_above). Paolo