Red Hat Bugzilla – Bug 1120053
Option shareable does not take effect after injecting a cdrom to guest by attach-disk
Last modified: 2016-11-03 14:09:47 EDT
Description of problem: Tried to injecting a cdrom to guest by attach-disk passing option shareable. However, libvirt didnot write the element <shareable/> into guest xml Version-Release number of selected component (if applicable): libvirt-1.1.1-29.el7.x86_64 How reproducible: 100% Steps: 1. Prepare a running guest with the following xml ................. <disk type='file' device='disk'> <driver name='qemu' type='qcow2' cache='none'/> <source file='/var/lib/libvirt/images/test2.img'/> <target dev='vda' bus='virtio'/> <alias name='virtio-disk0'/> <address type='pci' domain='0x0000' bus='0x00' slot='0x06' function='0x0'/> </disk> <disk type='block' device='cdrom'> <driver name='qemu' type='raw'/> <target dev='hda' bus='ide'/> <readonly/> </disk> ................. 2. Connect a device to cdrom # virsh attach-disk test /var/lib/libvirt/images/test.iso hda --type cdrom --shareable Disk attached successfully 3. check the dumpxml Expected Results: In step 3, the element <shareable/> should exist in xml. <disk type='file' device='cdrom'> <driver name='qemu' type='raw'/> <source file='/var/lib/libvirt/images/test.iso'/> <target dev='hda' bus='ide'/> <readonly/> <shareable/> <alias name='ide0-0-0'/> <address type='drive' controller='0' bus='0' target='0' unit='0'/> </disk> Actual Results: In step 3, the element <shareable/> was not found <disk type='file' device='cdrom'> <driver name='qemu' type='raw'/> <source file='/var/lib/libvirt/images/test.iso'/> <target dev='hda' bus='ide'/> <readonly/> <alias name='ide0-0-0'/> <address type='drive' controller='0' bus='0' target='0' unit='0'/> </disk> Additional info: The issue was also hit when injecting a cdrom to guest by attach-disk passing option --mode shareable. # virsh attach-disk test /var/lib/libvirt/images/test.iso hda --type cdrom --mode shareable
quick glance at the code reveals that "attach-disk" on an existing cdrom device just updates the media in the drive and cdrom device hotplug isn't supported at all. The problem lies in just changing the media and ignoring the rest of the XML. Additionally the media change function is flawed as it doesn't handle remote storage.
This was fixed by: commit 1f39218e4fdca901f7adca442e6ed6957b6eadef Author: Peter Krempa <pkrempa@redhat.com> Date: Tue Aug 5 13:43:57 2014 +0200 qemu: hotplug: Change arguments for qemuDomainChangeEjectableMedia Pass the source of the changed media instead of a complete disk definition. Note that the @disk argument now contains what @olddisk would contain. The new source is passed as a virStorageSource struct. ... and possibly few following patches. v1.2.7-170-g1f39218
Verified on libvirt-2.0.0-6.el7.x86_64 and passed 1. #virsh edit vm ... <disk type='block' device='cdrom'> <driver name='qemu' type='raw'/> <target dev='hda' bus='ide'/> <readonly/> </disk> ... 2. #virsh start vm 3. #touch /var/lib/libvirt/images/test.iso 4. #virsh attach-disk vm /var/lib/libvirt/images/test.iso hda --type cdrom --shareable 5. # virsh dumpxml vm | grep disk -A10 ... <disk type='file' device='cdrom'> <driver name='qemu' type='raw'/> <source file='/var/lib/libvirt/images/test.iso'/> <backingStore/> <target dev='hda' bus='ide'/> <readonly/> <shareable/> <====== exists <alias name='ide0-0-0'/> <address type='drive' controller='0' bus='0' target='0' unit='0'/> </disk> 6. #virsh destroy vm; virsh start vm 7. # virsh attach-disk vm /var/lib/libvirt/images/test.iso hda --type cdrom --mode shareable 8. # virsh dumpxml vm | grep disk -A10 ... <disk type='file' device='cdrom'> <driver name='qemu' type='raw'/> <source file='/var/lib/libvirt/images/test.iso'/> <backingStore/> <target dev='hda' bus='ide'/> <readonly/> <shareable/> <====== exists <alias name='ide0-0-0'/> <address type='drive' controller='0' bus='0' target='0' unit='0'/> </disk>
Since the problem described in this bug report should be resolved in a recent advisory, it has been closed with a resolution of ERRATA. For information on the advisory, and where to find the updated files, follow the link below. If the solution does not work for you, open a new bug report. https://rhn.redhat.com/errata/RHSA-2016-2577.html