On 02/05/2013 11:54 AM, Stefan Hajnoczi wrote:
> The qemu-img check command can display fragmentation statistics:
>  * Total number of clusters in virtual disk
>  * Number of allocated clusters
>  * Number of fragmented clusters
> 
> This patch adds fragmentation statistics support to qcow2.
> 
> Compressed and normal clusters count as allocated.  Zero clusters are
> not counted as allocated unless their L2 entry has a non-zero offset
> (e.g. preallocation).
> 
> Only the current L1 table counts towards the statistics - snapshots are
> ignored.
> 
> Signed-off-by: Stefan Hajnoczi <stefa...@redhat.com>
> ---
>  block/qcow2-refcount.c | 25 ++++++++++++++++++++++++-
>  1 file changed, 24 insertions(+), 1 deletion(-)

Reviewed-by: Eric Blake <ebl...@redhat.com>

> @@ -963,6 +965,17 @@ static int check_refcounts_l2(BlockDriverState *bs, 
> BdrvCheckResult *res,
>              l2_entry &= s->cluster_offset_mask;
>              inc_refcounts(bs, res, refcount_table, refcount_table_size,
>                  l2_entry & ~511, nb_csectors * 512);
> +
> +            if (flags & CHECK_FRAG_INFO) {
> +                res->bfi.allocated_clusters++;
> +                if (next_contiguous_offset &&
> +                    (l2_entry & ~511) != next_contiguous_offset) {
> +                    res->bfi.fragmented_clusters++;
> +                }
> +                /* Round down again, see nb_sectors above */
> +                next_contiguous_offset = (l2_entry & ~511) +

That's a lot of repetition of (l2_entry & ~511), which feels somewhat
magic; is it worth a dedicated temporary variable better named to
explain why l2_entry is being rounded down to a 512-byte boundary?

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

Attachment: signature.asc
Description: OpenPGP digital signature

Reply via email to