qemu-block
[Top][All Lists]
Advanced

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

Re: Questions about how block devices use snapshots


From: Kevin Wolf
Subject: Re: Questions about how block devices use snapshots
Date: Tue, 21 Feb 2023 16:58:44 +0100

Am 21.02.2023 um 14:27 hat Zhiyong Ye geschrieben:
> 
> Hi Kevin,
> 
> Sorry to bother you again.
> 
> I intend to use this approach for snapshots of block devices, which, as you
> say, requires a lot of disk space to store snapshot data. So, to save disk
> space, after each successful external snapshot creation, I want to shrink
> the block device that stores the backing_file image to the size that qcow2
> data actually occupies, since it has become read-only. But there is no way
> to get the actual size of qcow2 when it is stored in a block device.
> 
> Qemu-img info can easily get the actual size of qcow2 when it is stored in a
> file using the fstat function, but this will fail and return 0 for block
> devices. Therefore, it is necessary to implement the method of getting data
> occupancy inside qcow2. I think there may be two possible ways to do this:
> 
> - Add a cluster count field @nb_clusters in the BDRVQcow2State for each new
> cluster allocated and the actual size occupied by qcow2 is: nb_clusters *
> cluster_size.
> - Iterate through the refcount block to find the value with the largest host
> offset, and this is the actual size occupied by qcow2.
> 
> Since I'm not very familiar with qcow2, may I ask if you have any advice on
> getting the actual size when using qcow2?

I think what you need is the 'image-end-offset' field from 'qemu-img
check --output=json'.

Kevin




reply via email to

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