From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54200) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V06je-0006uG-Ck for qemu-devel@nongnu.org; Fri, 19 Jul 2013 05:12:24 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1V06jd-0002RI-2P for qemu-devel@nongnu.org; Fri, 19 Jul 2013 05:12:22 -0400 Received: from mail-ee0-x22a.google.com ([2a00:1450:4013:c00::22a]:33702) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V06jc-0002R4-LX for qemu-devel@nongnu.org; Fri, 19 Jul 2013 05:12:20 -0400 Received: by mail-ee0-f42.google.com with SMTP id c4so2295672eek.1 for ; Fri, 19 Jul 2013 02:12:20 -0700 (PDT) Sender: Paolo Bonzini Message-ID: <51E902E5.8050503@redhat.com> Date: Fri, 19 Jul 2013 11:12:05 +0200 From: Paolo Bonzini MIME-Version: 1.0 References: <1373992168-26043-1-git-send-email-pbonzini@redhat.com> <1373992168-26043-11-git-send-email-pbonzini@redhat.com> <51E8E124.3050500@kamp.de> In-Reply-To: <51E8E124.3050500@kamp.de> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH v2 10/17] block: define get_block_status return value List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Peter Lieven Cc: famz@redhat.com, qemu-devel@nongnu.org, stefanha@redhat.com Il 19/07/2013 08:48, Peter Lieven ha scritto: >> @@ -3040,7 +3040,10 @@ int64_t bdrv_get_block_status(BlockDriverState >> *bs, int64_t sector_num, >> int coroutine_fn bdrv_is_allocated(BlockDriverState *bs, int64_t >> sector_num, >> int nb_sectors, int *pnum) >> { >> - return bdrv_get_block_status(bs, sector_num, nb_sectors, pnum); >> + int64_t ret = bdrv_get_block_status(bs, sector_num, nb_sectors, >> pnum); >> + return >> + (ret & BDRV_BLOCK_DATA) || >> + ((ret & BDRV_BLOCK_ZERO) && !bdrv_has_zero_init(bs)); > > i do also not understand the "((ret & BDRV_BLOCK_ZERO) && > !bdrv_has_zero_init(bs))"; > if a block is unallocated and reads as zero, but the device lacks zero > init, it is declared as allocated with this, isn't it? Perhaps bdrv_has_zero_init(bs) could be replaced by bs->backing_hd. I'd have to look at the code more closely. But I suggest that you try using get_block_status (the function in qemu-img.c) instead of bdrv_is_allocated in qemu-img.c. It will probably simplify your code _and_ make it more efficient. > for iscsi and host_device with lbprz==1 or discardzeroes respectively all > blocks would return as allocated. is this wanted? Paolo