This is being implemented in qemu-img, as requested by the RHV team. It might be useful in OpenStack as well.
+++ This bug was initially created as a clone of Bug #1433670 +++
Description of problem:
I was wondering if that will be possible to provide a new API that estimates the size of qcow2 image converted from a raw image.
We could use this new API to allocate the size more precisely before the convert operation.
The operation that we are trying to do is to convert a raw sparse image from NFS or from block device to qcow2 image on thin provisioned block device
In ovirt thin provisioned block device is a regular lv, and we like
to allocate only the required size for the the qcow file.
Our current (stupid) solution is to allocate the entire LV using the
size of the raw image.
Here is an example flow:
$ truncate -s 10G test.raw
We don't know what will be the size of the qcow on the block storage,
so we allocate the entire LV:
$ lvcreate --size 10G vg/lv
Then we convert the file to the new LV:
$ qemu-img convert -f raw -O qcow2 test.raw /dev/vg/lv
After the copy we can check the actual size:
$ qemu-img check /dev/vg/lv
And reduce the LV:
$ lvreduce -L128m vg/lv
But we like to avoid the allocation, and allocate only the needed size
before we convert the image.
We think that the best way to solve this issue is to return this info
from qemu-img, maybe as a flag to qemu-img convert that will
calculate the size of the converted image without doing any writes.
Version-Release number of selected component (if applicable):
--- Additional comment from Stefan Hajnoczi on 2017-07-14 06:01:00 BRT ---
The following commits are now in qemu.git/master and will be included in the next qemu-kvm-rhev rebase:
32a1681 iotests: add test 178 for qemu-img measure
217a068 qemu-iotests: support per-format golden output files
fd03c2b qemu-img: add measure subcommand
c501c35 qcow2: add bdrv_measure() support
0eb4a8c qcow2: extract image creation option parsing
7c5bcc4 qcow2: make refcount size calculation conservative
95c67e3 qcow2: extract preallocation calculation function
a843a22 raw-format: add bdrv_measure() support
90880ff block: add bdrv_measure() API