Hi,
I am experimenting with attaching and detaching of CDROM images in running VMs.
fails like this:
Mon Feb 6 11:39:21 2017 [Z0][VMM][D]: Message received: LOG I 69 Command execution fail: cat << EOT | /var/tmp/one/vmm/kvm/detach_disk ‘one-69’ ‘/var/lib/one//datastore /0/69/disk.0’ ‘hda’ ‘0’ 69 s001310a
Mon Feb 6 11:39:21 2017 [Z0][VMM][D]: Message received: LOG E 69 detach_disk: Command “virsh --connect qemu:///system detach-disk --domain one-69 --target hda” failed: error: Failed to detach disk
Mon Feb 6 11:39:21 2017 [Z0][VMM][D]: Message received: LOG I 69 error: Operation not supported: disk device type ‘cdrom’ cannot be detached
Mon Feb 6 11:39:21 2017 [Z0][VMM][D]: Message received: LOG E 69 Could not detach hda from one-69
Mon Feb 6 11:39:21 2017 [Z0][VMM][D]: Message received: LOG I 69 ExitCode: 1
Mon Feb 6 11:39:21 2017 [Z0][VMM][D]: Message received: LOG I 69 Failed to execute virtualization driver operation: detach_disk.
Mon Feb 6 11:39:21 2017 [Z0][VMM][D]: Message received: DETACHDISK FAILURE 69 Could not detach hda from one-69
also _a_ttaching a cdrom to running vm fails like this:
Mon Feb 6 12:02:55 2017 [Z0][VMM][D]: Message received: LOG E 69 attach_disk: Command "virsh --connect qemu:///system attach-device one-69 /var/lib/one//datastores/0/69/disk.3.attach" failed: error: Failed to attach device from /var/lib/one//datastores/0/69/disk.3.attach
Mon Feb 6 12:02:55 2017 [Z0][VMM][D]: Message received: LOG I 69 error: internal error: No device with bus 'ide' and target 'hda'. cdrom and floppy device hotplug isn't supported by libvirt
Mon Feb 6 12:02:55 2017 [Z0][VMM][D]: Message received: LOG E 69 Could not attach /var/lib/one//datastores/0/69/disk.3 (hda) to one-69
looks like it is libvirt’s fault.
ok, then for both, attaching and detaching of cdrom type images, is it just not supported by libvirt? or is there a way to achieve this with OpenNebula?
what i think is also odd is that for libvirt it doesn’t matter if you set the cdrom img to persistent, it still got the readonly tag:
so it is actually useless that opennebula supports having persistent and non persistent cdrom types.
and actually i dont really see a use case where you would need a cdrom of type persistent, you cant write into a cdroms filesystem anyway. maybe i am missing something here.
I know this issue has been discussed on this forum quite often already. I just want to set this straight: does libvirt really NOT support hotplug for cdroms?
I think it’s more of an issue with the bus type. IDE has never supported hotplugging devices, and the CDRoms default to IDE (hda/hdb/etc). I have had some success with cdrom images on the virtio and SCSI buses, though not 100%. I have yet to understand the intricacies of why it works sometimes and not others.
I think you will understand better if you read “Attach Drive” instead of “Attach Disk”. As @cro says the problem here is that you are attaching a cdrom drive in IDE bus and is not supported.You should read
Currently OpenNebula does not support changing media of CDRoms, that I think it’s what you are looking for:
# virsh change-media --help
NAME
change-media - Change media of CD or floppy drive
SYNOPSIS
change-media <domain> <path> [--source <string>] [--eject] [--insert] [--update] [--current] [--live] [--config] [--force] [--print-xml] [--block]
DESCRIPTION
Change media of CD or floppy drive.
OPTIONS
[--domain] <string> domain name, id or uuid
[--path] <string> Fully-qualified path or target of disk device
--source <string> source of the media
--eject Eject the media
--insert Insert the media
--update Update the media
--current can be either or both of --live and --config, depends on implementation hypervisor driver
--live alter live configuration of running domain
--config alter persistent configuration, effect observed on next boot
--force force media changing
--print-xml print XML document rather than change media
--block source media is a block device
There is a prefeconfigure action in KVM that uses change-media but it is only used to change the context after a new NIC is attached:
You are right that persistent CDROM makes no sense.
Hi C.R. and Javi,
thanks for your replies, appreciated
Ok, now that you mention it, when I think about how many times I properly hotplugged a IDE CDROM in hardware back in the day…no that was not very often
I tried to change my oned.conf to have scsi drives (sd) as a default for cdroms. From this message it seems to me that it doesn’t actually mean the scsi bus, but the device type CDROM that is not supported for detaching:
Tue Feb 7 17:04:14 2017 [Z0][VMM][D]: Message received: LOG I 156 Command execution fail: cat << EOT | /var/tmp/one/vmm/kvm/detach_disk ‘one-156’ ‘/var/lib/one//datastores/0/156/disk.0’ ‘sda’ ‘0’ 156 s001310a
Tue Feb 7 17:04:14 2017 [Z0][VMM][D]: Message received: LOG E 156 detach_disk: Command “virsh --connect qemu:///system detach-disk --domain one-156 --target sda” failed: error: Failed to detach disk
Tue Feb 7 17:04:14 2017 [Z0][VMM][D]: Message received: LOG I 156 error: Operation not supported: disk device type ‘cdrom’ cannot be detached
Tue Feb 7 17:04:14 2017 [Z0][VMM][D]: Message received: LOG E 156 Could not detach sda from one-156
Tue Feb 7 17:04:14 2017 [Z0][VMM][D]: Message received: LOG I 156 ExitCode: 1
Tue Feb 7 17:04:14 2017 [Z0][VMM][D]: Message received: LOG I 156 Failed to execute virtualization driver operation: detach_disk.
I am thinking about extending the script /var/lib/one/remotes/vmm/kvm/detach_disk, so it does the change-media command when it is definitely a CDROM device that is to be detached.
but does this script actually “know” that it is a cdrom?
looks like it’s getting this variables:
DOMAIN="$1"
SOURCE="$2"
TARGET="$3"
TARGET_INDEX="$4"
TARGET tells me only that it is a hd*, vd* or hd*, which does not say anything about the image-type. what is TARGET_INDEX Javi?
You should escape $DISK_SOURCE otherwise it will be always emty string.
But in case of cdrom it will remove the source entry and the check for $TARGET later in the code will detect the device and a failure will be reported to OpenNebula.
Thanks for the patch, one drawback I can see that even after the detach (eject), the cdrom still remain on the VM (no medium found), right? But anyway, could you open a PR in the one repository?