
Unfortunately my backing store file is not in a volume. So I guess I cannot use that method. On 8/11/14 3:45 PM, "Eric Blake" <eblake@redhat.com> wrote:
On 08/11/2014 02:35 PM, Jianfeng Tang wrote:
I am using backing store when I create my volume. However, the backing store file is from another team, which can be either in raw or in qcow2 format.
Is there a libvirt API to detect image format by given an image file? Or I have to run qemu-img?
virStorageVolGetXMLDesc() in the C code ('virsh vol-dumpxml' from the command line), if your volume resides within a storage pool. Furthermore, if there is ANY possibility that the file might be raw but that the volume has been in use by a possibly malicious guest, you CANNOT blindly trust a file probe that says qcow2, because a guest can write header information into a raw disk in order to make probes return qcow2. So take the output with a grain of salt (it is safe to blindly trust a claim of 'raw', but blindly trusting a claim of 'qcow2' is risky if you don't know the history behind the image).
-- Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org