Jianfeng Tang
2014-Aug-11 20:35 UTC
[libvirt-users] Does libvirt have API to detect image format
>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?>
Eric Blake
2014-Aug-11 20:45 UTC
Re: [libvirt-users] Does libvirt have API to detect image format
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
Jianfeng Tang
2014-Aug-11 20:59 UTC
Re: [libvirt-users] Does libvirt have API to detect image format
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 >
Richard W.M. Jones
2014-Aug-13 14:10 UTC
Re: [libvirt-users] Does libvirt have API to detect image format
On Mon, Aug 11, 2014 at 08:35:46PM +0000, 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?Nothing wrong with running `qemu-img info' IMHO. Libguestfs has some disk detection features, including format, backing file, virtual size. And of course it can go a lot deeper into the disk content itself using libguestfs inspection. Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com Fedora Windows cross-compiler. Compile Windows programs, test, and build Windows installers. Over 100 libraries supported. http://fedoraproject.org/wiki/MinGW
Possibly Parallel Threads
- Re: Does libvirt have API to detect image format
- Does libvirt have API to detect image format
- Re: how to disable vnet_hdr through libvirt
- Re: Ubuntu Trusty: failed to create VM due to permission denied
- Re: Can I move the disk image of the guest while it is running?