From: Osier Yang Date: Wed, 14 Mar 2012 15:26:48 +0000 (+0800) Subject: qemu: Do not start with source for removable disks if tray is open X-Git-Tag: v0.9.11-rc1~19 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ad7db4391306916e57b3cb147c49ba77dcb24f70;p=thirdparty%2Flibvirt.git qemu: Do not start with source for removable disks if tray is open This is similiar with physical world, one will be surprised if the box starts with medium exists while the tray is open. New tests are added, tests disk-{cdrom,floppy}-tray are for the qemu supports "-device" flag, and disk-{cdrom,floppy}-no-device-cap are for old qemu, i.e. which doesn't support "-device" flag. --- diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 3b9eec81c4..ed390c17d5 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -1908,8 +1908,12 @@ qemuBuildDriveStr(virConnectPtr conn ATTRIBUTE_UNUSED, } /* disk->src is NULL when we use nbd disks */ - if (disk->src || (disk->type == VIR_DOMAIN_DISK_TYPE_NETWORK && - disk->protocol == VIR_DOMAIN_DISK_PROTOCOL_NBD)) { + if ((disk->src || + (disk->type == VIR_DOMAIN_DISK_TYPE_NETWORK && + disk->protocol == VIR_DOMAIN_DISK_PROTOCOL_NBD)) && + !((disk->device == VIR_DOMAIN_DISK_DEVICE_FLOPPY || + disk->device == VIR_DOMAIN_DISK_DEVICE_CDROM) && + disk->tray_status == VIR_DOMAIN_DISK_TRAY_OPEN)) { if (disk->type == VIR_DOMAIN_DISK_TYPE_DIR) { /* QEMU only supports magic FAT format for now */ if (disk->driverType && @@ -4736,7 +4740,13 @@ qemuBuildCommandLine(virConnectPtr conn, } } - virCommandAddArgList(cmd, dev, file, NULL); + /* Don't start with source if the tray is open for + * CDROM and Floppy device. + */ + if (!((disk->device == VIR_DOMAIN_DISK_DEVICE_FLOPPY || + disk->device == VIR_DOMAIN_DISK_DEVICE_CDROM) && + disk->tray_status == VIR_DOMAIN_DISK_TRAY_OPEN)) + virCommandAddArgList(cmd, dev, file, NULL); VIR_FREE(file); } } diff --git a/tests/qemuxml2argvdata/qemuxml2argv-disk-cdrom-tray-no-device-cap.args b/tests/qemuxml2argvdata/qemuxml2argv-disk-cdrom-tray-no-device-cap.args new file mode 100644 index 0000000000..5cd000e874 --- /dev/null +++ b/tests/qemuxml2argvdata/qemuxml2argv-disk-cdrom-tray-no-device-cap.args @@ -0,0 +1,4 @@ +LC_ALL=C PATH=/bin HOME=/home/test USER=test LOGNAME=test /usr/bin/qemu -S -M \ +pc -m 214 -smp 1 -nographic -monitor unix:/tmp/test-monitor,server,nowait \ +-no-acpi -boot c -hda /dev/HostVG/QEMUGuest1 -net none \ +-serial none -parallel none -usb diff --git a/tests/qemuxml2argvdata/qemuxml2argv-disk-cdrom-tray-no-device-cap.xml b/tests/qemuxml2argvdata/qemuxml2argv-disk-cdrom-tray-no-device-cap.xml new file mode 100644 index 0000000000..9f891c7a55 --- /dev/null +++ b/tests/qemuxml2argvdata/qemuxml2argv-disk-cdrom-tray-no-device-cap.xml @@ -0,0 +1,32 @@ + + QEMUGuest1 + c7a5fdbd-edaf-9455-926a-d65c16db1809 + 219100 + 219100 + 1 + + hvm + + + + destroy + restart + destroy + + /usr/bin/qemu + + + +
+ + + + + +
+ + + + + + diff --git a/tests/qemuxml2argvdata/qemuxml2argv-disk-cdrom-tray.args b/tests/qemuxml2argvdata/qemuxml2argv-disk-cdrom-tray.args new file mode 100644 index 0000000000..dfa0006282 --- /dev/null +++ b/tests/qemuxml2argvdata/qemuxml2argv-disk-cdrom-tray.args @@ -0,0 +1,10 @@ +LC_ALL=C PATH=/bin HOME=/home/test USER=test LOGNAME=test \ +/usr/bin/qemu -S -M pc-0.13 -m 1024 -smp 1 -nographic -nodefaults \ +-monitor unix:/tmp/test-monitor,server,nowait -no-acpi -boot dc \ +-drive file=/var/lib/libvirt/images/f14.img,if=none,id=drive-virtio-disk0 \ +-device virtio-blk-pci,bus=pci.0,addr=0x4,drive=drive-virtio-disk0,id=virtio-disk0 \ +-drive file=/var/lib/libvirt/Fedora-14-x86_64-Live-KDE.iso,if=none,media=cdrom,id=drive-ide0-1-0 \ +-device ide-drive,bus=ide.1,unit=0,drive=drive-ide0-1-0,id=ide0-1-0 \ +-drive if=none,media=cdrom,id=drive-ide0-1-1 \ +-device ide-drive,bus=ide.1,unit=1,drive=drive-ide0-1-1,id=ide0-1-1 \ +-usb -device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x3 diff --git a/tests/qemuxml2argvdata/qemuxml2argv-disk-cdrom-tray.xml b/tests/qemuxml2argvdata/qemuxml2argv-disk-cdrom-tray.xml new file mode 100644 index 0000000000..419f8f6086 --- /dev/null +++ b/tests/qemuxml2argvdata/qemuxml2argv-disk-cdrom-tray.xml @@ -0,0 +1,43 @@ + + test + 3fa02811-7832-34bd-004d-1ff56a9286ff + 1048576 + 1048576 + 1 + + hvm + + + + + + destroy + restart + restart + + /usr/bin/qemu + + + + +
+ + + + + + +
+ + + + + + +
+ + + + + + diff --git a/tests/qemuxml2argvdata/qemuxml2argv-disk-floppy-tray-no-device-cap.args b/tests/qemuxml2argvdata/qemuxml2argv-disk-floppy-tray-no-device-cap.args new file mode 100644 index 0000000000..a0aed99cfe --- /dev/null +++ b/tests/qemuxml2argvdata/qemuxml2argv-disk-floppy-tray-no-device-cap.args @@ -0,0 +1,4 @@ +LC_ALL=C PATH=/bin HOME=/home/test USER=test LOGNAME=test /usr/bin/qemu -S -M \ +pc -m 214 -smp 1 -nographic -monitor unix:/tmp/test-monitor,server,nowait \ +-no-acpi -boot c -hda /dev/HostVG/QEMUGuest1 -fda /dev/fd0 \ +-net none -serial none -parallel none -usb diff --git a/tests/qemuxml2argvdata/qemuxml2argv-disk-floppy-tray-no-device-cap.xml b/tests/qemuxml2argvdata/qemuxml2argv-disk-floppy-tray-no-device-cap.xml new file mode 100644 index 0000000000..1f4dd7f7c8 --- /dev/null +++ b/tests/qemuxml2argvdata/qemuxml2argv-disk-floppy-tray-no-device-cap.xml @@ -0,0 +1,37 @@ + + QEMUGuest1 + c7a5fdbd-edaf-9455-926a-d65c16db1809 + 219136 + 219136 + 1 + + hvm + + + + destroy + restart + destroy + + /usr/bin/qemu + + + +
+ + + + +
+ + + + +
+ + + + + + + diff --git a/tests/qemuxml2argvdata/qemuxml2argv-disk-floppy-tray.args b/tests/qemuxml2argvdata/qemuxml2argv-disk-floppy-tray.args new file mode 100644 index 0000000000..1a61ea5f78 --- /dev/null +++ b/tests/qemuxml2argvdata/qemuxml2argv-disk-floppy-tray.args @@ -0,0 +1,10 @@ +LC_ALL=C PATH=/bin HOME=/home/test USER=test LOGNAME=test \ +/usr/bin/qemu -S -M pc -m 214 -smp 1 -nographic -nodefaults \ +-monitor unix:/tmp/test-monitor,server,nowait -no-acpi -boot c \ +-drive file=/dev/HostVG/QEMUGuest1,if=none,id=drive-ide0-0-0 \ +-device ide-drive,bus=ide.0,unit=0,drive=drive-ide0-0-0,id=ide0-0-0 \ +-drive file=/dev/fd0,if=none,id=drive-fdc0-0-0 \ +-global isa-fdc.driveA=drive-fdc0-0-0 \ +-drive if=none,id=drive-fdc0-0-1 \ +-global isa-fdc.driveB=drive-fdc0-0-1 \ +-usb -device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x3 diff --git a/tests/qemuxml2argvdata/qemuxml2argv-disk-floppy-tray.xml b/tests/qemuxml2argvdata/qemuxml2argv-disk-floppy-tray.xml new file mode 100644 index 0000000000..1f4dd7f7c8 --- /dev/null +++ b/tests/qemuxml2argvdata/qemuxml2argv-disk-floppy-tray.xml @@ -0,0 +1,37 @@ + + QEMUGuest1 + c7a5fdbd-edaf-9455-926a-d65c16db1809 + 219136 + 219136 + 1 + + hvm + + + + destroy + restart + destroy + + /usr/bin/qemu + + + +
+ + + + +
+ + + + +
+ + + + + + + diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c index d0affc79b6..a69b1b8ecf 100644 --- a/tests/qemuxml2argvtest.c +++ b/tests/qemuxml2argvtest.c @@ -392,7 +392,13 @@ mymain(void) DO_TEST("hugepages", false, QEMU_CAPS_MEM_PATH); DO_TEST("disk-cdrom", false, NONE); DO_TEST("disk-cdrom-empty", false, QEMU_CAPS_DRIVE); + DO_TEST("disk-cdrom-tray", false, + QEMU_CAPS_DRIVE, QEMU_CAPS_DEVICE, QEMU_CAPS_VIRTIO_TX_ALG); + DO_TEST("disk-cdrom-tray-no-device-cap", false, NONE); DO_TEST("disk-floppy", false, NONE); + DO_TEST("disk-floppy-tray-no-device-cap", false, NONE); + DO_TEST("disk-floppy-tray", false, + QEMU_CAPS_DRIVE, QEMU_CAPS_DEVICE); DO_TEST("disk-many", false, NONE); DO_TEST("disk-virtio", false, QEMU_CAPS_DRIVE, QEMU_CAPS_DRIVE_BOOT); DO_TEST("disk-order", false,