[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH v5 12/21] block: define get_block_status return

From: Paolo Bonzini
Subject: Re: [Qemu-devel] [PATCH v5 12/21] block: define get_block_status return value
Date: Mon, 05 May 2014 16:58:25 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.4.0

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

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).


reply via email to

[Prev in Thread] Current Thread [Next in Thread]