]> xenbits.xensource.com Git - people/liuw/libxenctrl-split/libvirt.git/commitdiff
qemu: Check address type for USB disks
authorJiri Denemark <jdenemar@redhat.com>
Thu, 30 Apr 2015 12:16:40 +0000 (14:16 +0200)
committerJiri Denemark <jdenemar@redhat.com>
Thu, 30 Apr 2015 13:34:57 +0000 (15:34 +0200)
Only USB addresses are allowed for USB disks. Report an error if another
address is configured.

https://bugzilla.redhat.com/show_bug.cgi?id=1043436

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
src/qemu/qemu_command.c
tests/qemuxml2argvdata/qemuxml2argv-disk-usb-pci.xml [new file with mode: 0644]
tests/qemuxml2argvtest.c

index e62833fb5998143b5d0d75c6b8eb55e061a18d89..0dc8628b9821ba163e61769d68130763d9301a86 100644 (file)
@@ -4057,6 +4057,7 @@ qemuBuildDriveDevStr(virDomainDefPtr def,
                           disk->info.addr.drive.bus,
                           disk->info.addr.drive.unit);
         break;
+
     case VIR_DOMAIN_DISK_BUS_SCSI:
         if (disk->device == VIR_DOMAIN_DISK_DEVICE_LUN) {
             if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_SCSI_BLOCK)) {
@@ -4155,6 +4156,7 @@ qemuBuildDriveDevStr(virDomainDefPtr def,
                               disk->info.addr.drive.unit);
         }
         break;
+
     case VIR_DOMAIN_DISK_BUS_SATA:
         if (disk->info.addr.drive.bus != 0) {
             virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
@@ -4194,6 +4196,7 @@ qemuBuildDriveDevStr(virDomainDefPtr def,
                               disk->info.addr.drive.unit);
         }
         break;
+
     case VIR_DOMAIN_DISK_BUS_VIRTIO:
         if (disk->info.type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_CCW) {
             virBufferAddLit(&opt, "virtio-blk-ccw");
@@ -4227,7 +4230,14 @@ qemuBuildDriveDevStr(virDomainDefPtr def,
         if (qemuBuildDeviceAddressStr(&opt, def, &disk->info, qemuCaps) < 0)
             goto error;
         break;
+
     case VIR_DOMAIN_DISK_BUS_USB:
+        if (disk->info.type != VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE &&
+            disk->info.type != VIR_DOMAIN_DEVICE_ADDRESS_TYPE_USB) {
+            virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+                           _("unexpected address type for usb disk"));
+            goto error;
+        }
         if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_USB_STORAGE)) {
             virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
                            _("This QEMU doesn't support '-device "
@@ -4240,11 +4250,13 @@ qemuBuildDriveDevStr(virDomainDefPtr def,
         if (qemuBuildDeviceAddressStr(&opt, def, &disk->info, qemuCaps) < 0)
             goto error;
         break;
+
     default:
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        _("unsupported disk bus '%s' with device setup"), bus);
         goto error;
     }
+
     virBufferAsprintf(&opt, ",drive=%s%s", QEMU_DRIVE_HOST_PREFIX, disk->info.alias);
     virBufferAsprintf(&opt, ",id=%s", disk->info.alias);
     if (bootindex && virQEMUCapsGet(qemuCaps, QEMU_CAPS_BOOTINDEX))
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-disk-usb-pci.xml b/tests/qemuxml2argvdata/qemuxml2argv-disk-usb-pci.xml
new file mode 100644 (file)
index 0000000..ad96559
--- /dev/null
@@ -0,0 +1,34 @@
+<domain type='qemu'>
+  <name>QEMUGuest1</name>
+  <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>
+  <memory unit='KiB'>219136</memory>
+  <currentMemory unit='KiB'>219136</currentMemory>
+  <vcpu placement='static'>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'>
+      <driver name='qemu' type='raw'/>
+      <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='disk'>
+      <driver name='qemu' type='raw'/>
+      <source file='/tmp/usbdisk.img'/>
+      <target dev='sda' bus='usb'/>
+      <address type='pci' domain='0x0000' bus='0x00' slot='0x06' function='0x0'/>
+    </disk>
+    <controller type='usb' index='0'/>
+    <controller type='ide' index='0'/>
+    <controller type='pci' index='0' model='pci-root'/>
+    <memballoon model='none'/>
+  </devices>
+</domain>
index 670465e309030750a982f984830abb0a99c240f7..4acaa11b88675a8c0689ee605456380d713aa4f0 100644 (file)
@@ -812,6 +812,9 @@ mymain(void)
     DO_TEST("disk-usb-device-removable",
             QEMU_CAPS_DRIVE, QEMU_CAPS_DEVICE, QEMU_CAPS_DEVICE_USB_STORAGE,
             QEMU_CAPS_USB_STORAGE_REMOVABLE, QEMU_CAPS_NODEFCONFIG);
+    DO_TEST_FAILURE("disk-usb-pci",
+                    QEMU_CAPS_DRIVE, QEMU_CAPS_DEVICE,
+                    QEMU_CAPS_DEVICE_USB_STORAGE, QEMU_CAPS_NODEFCONFIG);
     DO_TEST("disk-scsi-device",
             QEMU_CAPS_DRIVE, QEMU_CAPS_DEVICE, QEMU_CAPS_NODEFCONFIG,
             QEMU_CAPS_SCSI_LSI);