[libvirt] [PATCH] qemu: check hostdev address type

Ján Tomko jtomko at redhat.com
Wed Jun 17 16:00:14 UTC 2015


For USB and SCSI hostdevs, we passed the invalid address to QEMU.
Report an error earlier.

PCI hostdevs check the address type when parsing the XML.

https://bugzilla.redhat.com/show_bug.cgi?id=1225339
---
 src/qemu/qemu_command.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 3886b4f..a4853ab 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -10572,7 +10572,12 @@ qemuBuildCommandLine(virConnectPtr conn,
         /* USB */
         if (hostdev->mode == VIR_DOMAIN_HOSTDEV_MODE_SUBSYS &&
             hostdev->source.subsys.type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB) {
-
+            if (hostdev->info->type != VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE &&
+                hostdev->info->type != VIR_DOMAIN_DEVICE_ADDRESS_TYPE_USB) {
+                virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+                               _("USB host devices must use 'usb' address type"));
+                goto error;
+            }
             if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE)) {
                 virCommandAddArg(cmd, "-device");
                 if (!(devstr = qemuBuildUSBHostdevDevStr(def, hostdev, qemuCaps)))
@@ -10644,6 +10649,12 @@ qemuBuildCommandLine(virConnectPtr conn,
         /* SCSI */
         if (hostdev->mode == VIR_DOMAIN_HOSTDEV_MODE_SUBSYS &&
             hostdev->source.subsys.type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI) {
+            if (hostdev->info->type != VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE &&
+                hostdev->info->type != VIR_DOMAIN_DEVICE_ADDRESS_TYPE_DRIVE) {
+                virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+                               _("SCSI host devices must use 'drive' address type"));
+                goto error;
+            }
             if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_DRIVE) &&
                 virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE) &&
                 virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_SCSI_GENERIC)) {
-- 
2.3.6




More information about the libvir-list mailing list