Comment 12 for bug 953922

Revision history for this message
In , Tuomas (tuomas-redhat-bugs) wrote :

Created attachment 569802
Patches CloneDesign to generate the XML required for the <driver type='...'/> element

Description of problem:

Cloning of a VM doesn't duplicate the driver type of the disk images to be cloned.

Version-Release number of selected component (if applicable):

DistroRelease: Ubuntu 12.04
Package: virtinst 0.600.1-1ubuntu2
ProcVersionSignature: Ubuntu 3.2.0-18.29-generic 3.2.9
Uname: Linux 3.2.0-18-generic x86_64
Architecture: amd64
SourcePackage: virtinst

How reproducible:
Always

Steps to Reproduce:
1. Create a new QEMU/KVM VM called "foo" with a disk in qcow2 format like this

    <disk type='file' device='disk'>
      <driver name='qemu' type='qcow2'/>
      <source file='/var/lib/libvirt/images/foo.img'/>
      <target dev='vda' bus='virtio'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x0'/>
    </disk>

2. Clone the disk by running
       sudo virt-clone -o foo --auto-clone
   or using virt-manager GUI

Actual results:
The resulting VM foo-clone has the following disk configuration

    <disk type='file' device='disk'>
      <driver name='qemu' type='raw'/>
      <source file='/var/lib/libvirt/images/foo-clone.img'/>
      <target dev='vda' bus='virtio'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x0'/>
    </disk>

The type of the disk is raw, not qcow2 as in the original VM.

Expected results:

The configuration of the clone should define the disk as the same type as in the original VM, i.e. qcow2 in this case.

Additional info:
The file is properly cloned in the qcow2 format, though, so the issue only affects generation of the clone configuration.

About the patches:

virtinst-0.600.1-generate-cloned-disk-driver-type-xml.diff patches CloneDesign to generate the XML required for the <driver type='...'/> element. Only this patch is needed to fix the described malfunction with virt-manager. After applying this, cloned VMs created with virt-manager will have their configuration correctly cloned.

virtinst-0.600.1-hack-virt-clone-to-support-cloning-of-disk-driver-type.diff is a really ugly hack for virt-clone which makes it work around this problem. Also the previous patch is required so that correct XML is actually generated. This patch overrides the CloneDesign API by directly modifying the list of cloned drives in its CloneDesign object. The problem is that these drives are created in CloneDesign::set_cloned_devices using a fresh instance of VirtualDisk. No info about the original disk is available here, only the filename of the cloned image. Obviously, this isn't enough to supply the driver type to the constructor of VirtualDisk (driverType argument), so this info is effectively lost for the cloned disk. This code should be refactored so that the driver type from the original disk is somehow automatically preserved so the caller (e.g. virt-clone or virt-manager) doesn't have to do anything special. But since I'm not familiar with the code, I don't know where and how to start such refactoring.