Re: [PATCH 4/9] qemu: Do not start with source for removable disks if tray is open

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, Mar 05, 2012 at 06:25:42PM +0800, Osier Yang wrote:
> 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.
> ---
>  src/qemu/qemu_command.c                            |   16 ++++++-
>  ...qemuxml2argv-disk-cdrom-tray-no-device-cap.args |    4 ++
>  .../qemuxml2argv-disk-cdrom-tray-no-device-cap.xml |   32 +++++++++++++++
>  .../qemuxml2argv-disk-cdrom-tray.args              |   10 +++++
>  .../qemuxml2argv-disk-cdrom-tray.xml               |   43 ++++++++++++++++++++
>  ...emuxml2argv-disk-floppy-tray-no-device-cap.args |    4 ++
>  ...qemuxml2argv-disk-floppy-tray-no-device-cap.xml |   37 +++++++++++++++++
>  .../qemuxml2argv-disk-floppy-tray.args             |   10 +++++
>  .../qemuxml2argv-disk-floppy-tray.xml              |   37 +++++++++++++++++
>  tests/qemuxml2argvtest.c                           |    6 +++
>  10 files changed, 196 insertions(+), 3 deletions(-)
>  create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-disk-cdrom-tray-no-device-cap.args
>  create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-disk-cdrom-tray-no-device-cap.xml
>  create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-disk-cdrom-tray.args
>  create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-disk-cdrom-tray.xml
>  create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-disk-floppy-tray-no-device-cap.args
>  create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-disk-floppy-tray-no-device-cap.xml
>  create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-disk-floppy-tray.args
>  create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-disk-floppy-tray.xml
> 
> diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
> index cddd6aa..60c3d16 100644
> --- a/src/qemu/qemu_command.c
> +++ b/src/qemu/qemu_command.c
> @@ -1885,8 +1885,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 &&
> @@ -4694,7 +4698,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 0000000..5cd000e
> --- /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 0000000..9f891c7
> --- /dev/null
> +++ b/tests/qemuxml2argvdata/qemuxml2argv-disk-cdrom-tray-no-device-cap.xml
> @@ -0,0 +1,32 @@
> +<domain type='qemu'>
> +  <name>QEMUGuest1</name>
> +  <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>
> +  <memory>219100</memory>
> +  <currentMemory>219100</currentMemory>
> +  <vcpu>1</vcpu>
> +  <os>
> +    <type arch='i686' machine='pc'>hvm</type>
> +    <boot dev='hd'/>
> +  </os>
> +  <clock offset='utc'/>
> +  <on_poweroff>destroy</on_poweroff>
> +  <on_reboot>restart</on_reboot>
> +  <on_crash>destroy</on_crash>
> +  <devices>
> +    <emulator>/usr/bin/qemu</emulator>
> +    <disk type='block' device='disk'>
> +      <source dev='/dev/HostVG/QEMUGuest1'/>
> +      <target dev='hda' bus='ide'/>
> +      <address type='drive' controller='0' bus='0' target='0' unit='0'/>
> +    </disk>
> +    <disk type='file' device='cdrom'>
> +      <source file='/root/boot.iso'/>
> +      <target dev='hdc' bus='ide' tray='open'/>
> +      <readonly/>
> +      <address type='drive' controller='0' bus='1' target='0' unit='0'/>
> +    </disk>
> +    <controller type='usb' index='0'/>
> +    <controller type='ide' index='0'/>
> +    <memballoon model='virtio'/>
> +  </devices>
> +</domain>
> diff --git a/tests/qemuxml2argvdata/qemuxml2argv-disk-cdrom-tray.args b/tests/qemuxml2argvdata/qemuxml2argv-disk-cdrom-tray.args
> new file mode 100644
> index 0000000..dfa0006
> --- /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 0000000..419f8f6
> --- /dev/null
> +++ b/tests/qemuxml2argvdata/qemuxml2argv-disk-cdrom-tray.xml
> @@ -0,0 +1,43 @@
> +<domain type='qemu'>
> +  <name>test</name>
> +  <uuid>3fa02811-7832-34bd-004d-1ff56a9286ff</uuid>
> +  <memory>1048576</memory>
> +  <currentMemory>1048576</currentMemory>
> +  <vcpu>1</vcpu>
> +  <os>
> +    <type arch='x86_64' machine='pc-0.13'>hvm</type>
> +    <boot dev='cdrom'/>
> +    <boot dev='hd'/>
> +    <bootmenu enable='yes'/>
> +  </os>
> +  <clock offset='utc'/>
> +  <on_poweroff>destroy</on_poweroff>
> +  <on_reboot>restart</on_reboot>
> +  <on_crash>restart</on_crash>
> +  <devices>
> +    <emulator>/usr/bin/qemu</emulator>
> +    <disk type='file' device='disk'>
> +      <driver name='qemu' type='qcow2'/>
> +      <source file='/var/lib/libvirt/images/f14.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'/>
> +      <source file='/var/lib/libvirt/Fedora-14-x86_64-Live-KDE.iso'/>
> +      <target dev='hdc' bus='ide' tray='closed'/>
> +      <readonly/>
> +      <address type='drive' controller='0' bus='1' target='0' unit='0'/>
> +    </disk>
> +    <disk type='file' device='cdrom'>
> +      <driver name='qemu' type='raw'/>
> +      <source file='/tmp/cdrom.img'/>
> +      <target dev='hdd' bus='ide' tray='open'/>
> +      <readonly/>
> +      <address type='drive' controller='0' bus='1' target='0' unit='1'/>
> +    </disk>
> +    <controller type='usb' index='0'/>
> +    <controller type='ide' index='0'/>
> +    <memballoon model='virtio'/>
> +  </devices>
> +</domain>
> 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 0000000..a0aed99
> --- /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 0000000..1f4dd7f
> --- /dev/null
> +++ b/tests/qemuxml2argvdata/qemuxml2argv-disk-floppy-tray-no-device-cap.xml
> @@ -0,0 +1,37 @@
> +<domain type='qemu'>
> +  <name>QEMUGuest1</name>
> +  <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>
> +  <memory>219136</memory>
> +  <currentMemory>219136</currentMemory>
> +  <vcpu>1</vcpu>
> +  <os>
> +    <type arch='i686' machine='pc'>hvm</type>
> +    <boot dev='hd'/>
> +  </os>
> +  <clock offset='utc'/>
> +  <on_poweroff>destroy</on_poweroff>
> +  <on_reboot>restart</on_reboot>
> +  <on_crash>destroy</on_crash>
> +  <devices>
> +    <emulator>/usr/bin/qemu</emulator>
> +    <disk type='block' device='disk'>
> +      <source dev='/dev/HostVG/QEMUGuest1'/>
> +      <target dev='hda' bus='ide'/>
> +      <address type='drive' controller='0' bus='0' target='0' unit='0'/>
> +    </disk>
> +    <disk type='block' device='floppy'>
> +      <source dev='/dev/fd0'/>
> +      <target dev='fda' bus='fdc' tray='closed'/>
> +      <address type='drive' controller='0' bus='0' target='0' unit='0'/>
> +    </disk>
> +    <disk type='file' device='floppy'>
> +      <source file='/tmp/firmware.img'/>
> +      <target dev='fdb' bus='fdc' tray='open'/>
> +      <address type='drive' controller='0' bus='0' target='0' unit='1'/>
> +    </disk>
> +    <controller type='usb' index='0'/>
> +    <controller type='fdc' index='0'/>
> +    <controller type='ide' index='0'/>
> +    <memballoon model='virtio'/>
> +  </devices>
> +</domain>
> diff --git a/tests/qemuxml2argvdata/qemuxml2argv-disk-floppy-tray.args b/tests/qemuxml2argvdata/qemuxml2argv-disk-floppy-tray.args
> new file mode 100644
> index 0000000..1a61ea5
> --- /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 0000000..1f4dd7f
> --- /dev/null
> +++ b/tests/qemuxml2argvdata/qemuxml2argv-disk-floppy-tray.xml
> @@ -0,0 +1,37 @@
> +<domain type='qemu'>
> +  <name>QEMUGuest1</name>
> +  <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>
> +  <memory>219136</memory>
> +  <currentMemory>219136</currentMemory>
> +  <vcpu>1</vcpu>
> +  <os>
> +    <type arch='i686' machine='pc'>hvm</type>
> +    <boot dev='hd'/>
> +  </os>
> +  <clock offset='utc'/>
> +  <on_poweroff>destroy</on_poweroff>
> +  <on_reboot>restart</on_reboot>
> +  <on_crash>destroy</on_crash>
> +  <devices>
> +    <emulator>/usr/bin/qemu</emulator>
> +    <disk type='block' device='disk'>
> +      <source dev='/dev/HostVG/QEMUGuest1'/>
> +      <target dev='hda' bus='ide'/>
> +      <address type='drive' controller='0' bus='0' target='0' unit='0'/>
> +    </disk>
> +    <disk type='block' device='floppy'>
> +      <source dev='/dev/fd0'/>
> +      <target dev='fda' bus='fdc' tray='closed'/>
> +      <address type='drive' controller='0' bus='0' target='0' unit='0'/>
> +    </disk>
> +    <disk type='file' device='floppy'>
> +      <source file='/tmp/firmware.img'/>
> +      <target dev='fdb' bus='fdc' tray='open'/>
> +      <address type='drive' controller='0' bus='0' target='0' unit='1'/>
> +    </disk>
> +    <controller type='usb' index='0'/>
> +    <controller type='fdc' index='0'/>
> +    <controller type='ide' index='0'/>
> +    <memballoon model='virtio'/>
> +  </devices>
> +</domain>
> diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c
> index fcffc27..e304318 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,

  ACK

Daniel

-- 
Daniel Veillard      | libxml Gnome XML XSLT toolkit  http://xmlsoft.org/
daniel@xxxxxxxxxxxx  | Rpmfind RPM search engine http://rpmfind.net/
http://veillard.com/ | virtualization library  http://libvirt.org/

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list


[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]