[PATCHv2] qemu: Validate address type when attaching a disk device.

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

 



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

Attach-device can hotplug a virtio disk device with any address type now,
it need to validate the address type before the attachment.

Coldplug a scsi disk device without checking the address type in current
version, this patch also fix the scsi disk problem.
---
 src/qemu/qemu_driver.c  |  8 ++++++++
 src/qemu/qemu_hotplug.c | 18 ++++++++++++++++++
 2 files changed, 26 insertions(+)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 91eb661..af926fc 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -8050,6 +8050,14 @@ qemuDomainAttachDeviceConfig(virQEMUCapsPtr qemuCaps,
         if (disk->bus != VIR_DOMAIN_DISK_BUS_VIRTIO)
             if (virDomainDefAddImplicitControllers(vmdef) < 0)
                 return -1;
+        /* scsi disk should have an address type of driver */
+        if (disk->bus == VIR_DOMAIN_DISK_BUS_SCSI &&
+            (disk->info.type != VIR_DOMAIN_DEVICE_ADDRESS_TYPE_DRIVE)) {
+                virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+                               _("scsi disk cannot have an address of type '%s'"),
+                               virDomainDeviceAddressTypeToString(disk->info.type));
+            return -1;
+        }
         if (qemuDomainAssignAddresses(vmdef, qemuCaps, NULL) < 0)
             return -1;
         break;
diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
index 63fafa6..4226650 100644
--- a/src/qemu/qemu_hotplug.c
+++ b/src/qemu/qemu_hotplug.c
@@ -335,6 +335,24 @@ qemuDomainAttachVirtioDiskDevice(virConnectPtr conn,
         if (!qemuCheckCCWS390AddressSupport(vm->def, disk->info, priv->qemuCaps,
                                             disk->dst))
             goto cleanup;
+
+        /* virtio device should either have a ccw or pci address */
+        if (qemuDomainMachineIsS390CCW(vm->def) &&
+            virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_VIRTIO_CCW)) {
+            if (!virDomainDeviceAddressIsValid(&disk->info,
+                                               VIR_DOMAIN_DEVICE_ADDRESS_TYPE_CCW)) {
+                virReportError(VIR_ERR_OPERATION_FAILED, "%s",
+                               _("device cannot be attached without a valid CCW address"));
+                goto cleanup;
+            }
+        } else {
+            if (!virDomainDeviceAddressIsValid(&disk->info,
+                                               VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI)) {
+                virReportError(VIR_ERR_OPERATION_FAILED, "%s",
+                               _("device cannot be attached without a valid PCI address"));
+                goto cleaup;
+            }
+        }
     }
 
     for (i = 0; i < vm->def->ndisks; i++) {
-- 
2.4.3

--
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]