When cloning a VM with qcow2 disk, the cloned VM will have its disk defined as raw format in its config

Bug #953922 reported by Tuomas Jormola on 2012-03-13
42
This bug affects 7 people
Affects Status Importance Assigned to Milestone
virtinst
Won't Fix
Medium
virtinst (Ubuntu)
Undecided
Unassigned
Precise
Medium
Marc Deslauriers
Quantal
Undecided
Unassigned

Bug Description

SRU:

[Impact]
Precise users aren't able to use the virt-clone command, or the clone functionnality in virt-manager to create successful clones of VMs using qcow2 images, as the disk image format is not being transferred properly to the clone.

[Test Case]
1- Create VM with qcow2 disks
2- Clone VM with virt-manager
3- Inspect clone xml file to make sure qcow2 image format is set correctly

[Regression Potential]
This change is limited to the clone code path. If something breaks, it will be VM cloning.

I tried the cloning feature of virt-manager. First I created a VM with qcow2 disk and installed Ubuntu on it. Then I shutdown the VM and created a clone of it. The clone was successfully created, but the configuration of the disk is invalid. The disk type in the cloned VM is raw, not qcow2. The actual format of the cloned disk image is qcow2, only the config is wrong. After changing the type of the disk back to qcow2, the cloned VM can see the disk just fine.

Here's the libvirt XML config snippet for the disk on the VM to be cloned:
<disk type='file' device='disk'>
  <driver name='qemu' type='qcow2'/>
  <source file='/var/lib/libvirt/images/test.img'/>
  <target dev='vda' bus='virtio'/>
  <address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x0'/>
</disk>

And the same config for the clone VM before fixing the type manually:
<disk type='file' device='disk'>
  <driver name='qemu' type='raw'/>
  <source file='/var/lib/libvirt/images/test-clone.img'/>
  <target dev='vda' bus='virtio'/>
  <address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x0'/>
</disk>

ProblemType: Bug
DistroRelease: Ubuntu 12.04
Package: virt-manager 0.9.1-1ubuntu2
ProcVersionSignature: Ubuntu 3.2.0-18.29-generic 3.2.9
Uname: Linux 3.2.0-18-generic x86_64
NonfreeKernelModules: nvidia
ApportVersion: 1.94.1-0ubuntu2
Architecture: amd64
Date: Tue Mar 13 12:54:01 2012
PackageArchitecture: all
ProcEnviron:
 TERM=xterm
 LANG=en_US.UTF-8
 SHELL=/bin/bash
SourcePackage: virt-manager
UpgradeStatus: No upgrade log present (probably fresh install)

Tuomas Jormola (tjormola) 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.

Created attachment 569803
Hack for virt-clone to work around this problem

Tuomas Jormola (tjormola) wrote :

Further investigated this issue and reported my findings and possible fixes to upstream.
https://bugzilla.redhat.com/show_bug.cgi?id=803087

Applying the patch https://bugzilla.redhat.com/attachment.cgi?id=569802 would fix this problem for virt-manager as reported in this bug entry.

My initial bug report for Ubuntu regarding this issue
https://bugs.launchpad.net/ubuntu/+source/virt-manager/+bug/953922

Thanks for the report. This has actually been fixed independently upstream:

http://git.fedorahosted.org/git?p=python-virtinst.git;a=commit;h=f0195e95d57deda83daed5231582ca86bde519ae
http://git.fedorahosted.org/git?p=python-virtinst.git;a=commit;h=c9ae2ac4668213c03614842d92327737a25cf9ec

Unfortunately those probably won't backport cleanly, in which case I think your hack is sufficient for a distro backport. Closing as UPSTREAM

affects: virt-manager (Ubuntu) → virtinst (Ubuntu)
affects: virt-manager → virtinst
Launchpad Janitor (janitor) wrote :

Status changed to 'Confirmed' because the bug affects multiple users.

Changed in virtinst (Ubuntu):
status: New → Confirmed
Marc Deslauriers (mdeslaur) wrote :
Sebastien Douche (sdouche) wrote :

Hello everyone,
Can you make a new release out with the small patch already integrated upstream?

Thanks.

Changed in virtinst (Ubuntu Quantal):
status: Confirmed → Fix Released
Changed in virtinst (Ubuntu Precise):
status: New → Confirmed
importance: Undecided → Medium
assignee: nobody → Marc Deslauriers (mdeslaur)
Marc Deslauriers (mdeslaur) wrote :

Package uploaded to -proposed, awaiting SRU team approval.

description: updated

Hello Tuomas, or anyone else affected,

Accepted virtinst into precise-proposed. The package will build now and be available at http://launchpad.net/ubuntu/+source/virtinst/0.600.1-1ubuntu3.2 in a few hours, and then in the -proposed repository.

Please help us by testing this new package. See https://wiki.ubuntu.com/Testing/EnableProposed for documentation how to enable and use -proposed. Your feedback will aid us getting this update out to other Ubuntu users.

If this package fixes the bug for you, please change the bug tag from verification-needed to verification-done. If it does not, change the tag to verification-failed. In either case, details of your testing will help us make a better decision.

Further information regarding the verification process can be found at https://wiki.ubuntu.com/QATeam/PerformingSRUVerification . Thank you in advance!

Changed in virtinst (Ubuntu Precise):
status: Confirmed → Fix Committed
tags: added: verification-needed
Tuomas Jormola (tjormola) wrote :

Tested the version 0.600.1-1ubuntu3.2 and verified that cloning now works as supposed. Thanks!

tags: added: verification-done
removed: verification-needed

The verification of this Stable Release Update has completed successfully and the package has now been released to -updates. Subsequently, the Ubuntu Stable Release Updates Team is being unsubscribed and will not receive messages about this bug report. In the event that you encounter a regression using the package from -updates please report a new bug using ubuntu-bug and tag the bug report regression-update so we can easily find any regresssions.

Launchpad Janitor (janitor) wrote :

This bug was fixed in the package virtinst - 0.600.1-1ubuntu3.2

---------------
virtinst (0.600.1-1ubuntu3.2) precise-proposed; urgency=low

  * debian/patches/9006-fix-disk-cloning.patch: Also clone disk type when
    cloning a VM. (LP: #953922)
 -- Marc Deslauriers <email address hidden> Fri, 27 Jul 2012 11:13:04 -0400

Changed in virtinst (Ubuntu Precise):
status: Fix Committed → Fix Released
Alain Vernat (alain-vernat) wrote :
Download full text (11.2 KiB)

Upgrade to virtinst0.600.1-1ubuntu3.2 doesn't solve the problem.

# virt-clone -o ubuntu-1204-10G -n omcsvctst01d -f /data/instances/omcsvctst01d.img -d
[Fri, 09 Aug 2013 10:53:33 virt-clone 8084] DEBUG (cli:220) Launched with command line:
/usr/bin/virt-clone -o ubuntu-1204-10G -n omcsvctst01d -f /data/instances/omcsvctst01d.img -d
[Fri, 09 Aug 2013 10:53:33 virt-clone 8084] DEBUG (cli:326) Requesting libvirt URI default
[Fri, 09 Aug 2013 10:53:33 virt-clone 8084] DEBUG (cli:328) Received libvirt URI qemu:///system
[Fri, 09 Aug 2013 10:53:34 virt-clone 8084] DEBUG (CloneManager:399) Validating original guest parameters
[Fri, 09 Aug 2013 10:53:34 virt-clone 8084] DEBUG (CloneManager:408) Original XML:
<domain type='kvm'>
  <name>ubuntu-1204-10G</name>
  <uuid>28538012-f2b4-1fa2-acfc-99c0a35c6a78</uuid>
  <memory>1048576</memory>
  <currentMemory>1048576</currentMemory>
  <memoryBacking>
    <hugepages/>
  </memoryBacking>
  <vcpu>2</vcpu>
  <os>
    <type arch='x86_64' machine='pc-1.0'>hvm</type>
    <boot dev='hd'/>
  </os>
  <features>
    <acpi/>
    <apic/>
    <pae/>
  </features>
  <clock offset='utc'/>
  <on_poweroff>destroy</on_poweroff>
  <on_reboot>restart</on_reboot>
  <on_crash>restart</on_crash>
  <devices>
    <emulator>/usr/bin/kvm</emulator>
    <disk type='file' device='disk'>
      <driver name='qemu' type='qcow2'/>
      <source file='/data/templates/ubuntu-1204-10G.img'/>
      <target dev='vda' bus='virtio'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/>
    </disk>
    <disk type='file' device='cdrom'>
      <driver name='qemu' type='raw'/>
      <target dev='hdc' bus='ide'/>
      <readonly/>
      <address type='drive' controller='0' bus='1' unit='0'/>
    </disk>
    <controller type='ide' index='0'>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x1'/>
    </controller>
    <interface type='bridge'>
      <mac address='52:54:00:04:c0:4a'/>
      <source bridge='br-828'/>
      <model type='virtio'/>
      <driver name='vhost' txmode='iothread' ioeventfd='on' event_idx='off'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
    </interface>
    <serial type='pty'>
      <target port='0'/>
    </serial>
    <console type='pty'>
      <target type='serial' port='0'/>
    </console>
    <input type='mouse' bus='ps2'/>
    <graphics type='vnc' port='-1' autoport='yes'/>
    <video>
      <model type='cirrus' vram='9216' heads='1'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/>
    </video>
    <memballoon model='virtio'>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x0'/>
    </memballoon>
  </devices>
</domain>

[Fri, 09 Aug 2013 10:53:36 virt-clone 8084] DEBUG (CloneManager:416) Original paths: ['/data/templates/ubuntu-1204-10G.img']
[Fri, 09 Aug 2013 10:53:36 virt-clone 8084] DEBUG (CloneManager:417) Original sizes: [10.0]
[Fri, 09 Aug 2013 10:53:38 virt-clone 8084] DEBUG (VirtualDisk:240) Path '/data/instances' is target for pool 'default'. Creating volume 'omcsvctst01d.img'.
[Fri, 09 Aug 2013 10:53:39 virt-clone 8084] DEBUG (VirtualDisk:240) Path '/data/i...

Changed in virtinst:
importance: Unknown → Medium
status: Unknown → Won't Fix
To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Duplicates of this bug

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.