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?