[libvirt-users] Does libvirt have API to detect image format

Eric Blake eblake at redhat.com
Mon Aug 11 20:45:24 UTC 2014


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

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 539 bytes
Desc: OpenPGP digital signature
URL: <http://listman.redhat.com/archives/libvirt-users/attachments/20140811/1f756ca5/attachment.sig>


More information about the libvirt-users mailing list