qemu-devel
[Top][All Lists]
Advanced

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

Re: [Qemu-devel] [PATCHv3 1/2] qemu-img: find the highest offset in use


From: Eric Blake
Subject: Re: [Qemu-devel] [PATCHv3 1/2] qemu-img: find the highest offset in use during check
Date: Mon, 21 Jan 2013 09:27:45 -0700
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130110 Thunderbird/17.0.2

On 01/21/2013 07:25 AM, Federico Simoncelli wrote:
> This patch adds the support for reporting the highest offset in use by
> an image. This is particularly useful after a conversion (or a rebase)
> where the destination is a block device in order to find the actual
> amount of space in use.
> 
> Signed-off-by: Federico Simoncelli <address@hidden>
> ---
>  block/qcow2-refcount.c       |   10 ++++++++--
>  include/block/block.h        |    1 +
>  qemu-img.c                   |    4 ++++
>  tests/qemu-iotests/026       |    6 +++---
>  tests/qemu-iotests/036       |    3 ++-
>  tests/qemu-iotests/039       |    2 +-
>  tests/qemu-iotests/044.out   |    1 +
>  tests/qemu-iotests/common.rc |    5 +++--
>  8 files changed, 23 insertions(+), 9 deletions(-)
> 

> @@ -1231,6 +1236,7 @@ int qcow2_check_refcounts(BlockDriverState *bs, 
> BdrvCheckResult *res,
>          }
>      }
>  
> +    res->highest_offset = (highest_cluster + 1) * s->cluster_size;

That's actually one byte larger than the actual highest offset in use.
That is, if I have a file with exactly 4096 bytes, this computation
would return 4096 (the file size) rather than 4095 (the last offset in use).

> +++ b/qemu-img.c
> @@ -475,6 +475,10 @@ static int img_check(int argc, char **argv)
>          result.bfi.fragmented_clusters * 100.0 / 
> result.bfi.allocated_clusters);
>      }
>  
> +    if (result.highest_offset > 0) {
> +        printf("Highest offset in use: %" PRId64 "\n", 
> result.highest_offset);

This output message feels off by one.  Either you need to subtract 1
from res->highest_offset to get the address of the last used byte, or
you need to document it as the first unused byte, or instead of calling
it 'highest offset', you should call it 'used bytes' (except that with
sparse files, it's hard to argue that all earlier bytes were 'used').

Overall, though, I like the idea of this patch.

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

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