[PATCH 1/7] qemu: hotplug: Assume support for -device in qemuDomainAttachSCSIDisk

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

 



We've started to assume support for QEMU_CAPS_DEVICE. Doing so in the
SCSI disk hotplug code allows us to drop a lot of ugly legacy code.
---
 src/qemu/qemu_hotplug.c | 62 ++++++++++---------------------------------------
 1 file changed, 12 insertions(+), 50 deletions(-)

diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
index b580283..ac359da 100644
--- a/src/qemu/qemu_hotplug.c
+++ b/src/qemu/qemu_hotplug.c
@@ -564,7 +564,6 @@ qemuDomainAttachSCSIDisk(virConnectPtr conn,
 {
     size_t i;
     qemuDomainObjPrivatePtr priv = vm->privateData;
-    virDomainControllerDefPtr cont = NULL;
     char *drivestr = NULL;
     char *devstr = NULL;
     int ret = -1;
@@ -581,27 +580,11 @@ qemuDomainAttachSCSIDisk(virConnectPtr conn,
         goto error;
     }

-    /* Let's make sure our disk has a controller defined and loaded
-     * before trying add the disk. The controller the disk is going
-     * to use must exist before a qemu command line string is generated.
-     */
-    for (i = 0; i <= disk->info.addr.drive.controller; i++) {
-        cont = qemuDomainFindOrCreateSCSIDiskController(driver, vm, i);
-        if (!cont)
-            goto error;
-    }
-
-    /* Tell clang that "cont" is non-NULL.
-       This is because disk->info.addr.driver.controller is unsigned,
-       and hence the above loop must iterate at least once.  */
-    sa_assert(cont);
+    if (qemuAssignDeviceDiskAlias(vm->def, disk, priv->qemuCaps) < 0)
+        goto error;

-    if (virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_DEVICE)) {
-        if (qemuAssignDeviceDiskAlias(vm->def, disk, priv->qemuCaps) < 0)
-            goto error;
-        if (!(devstr = qemuBuildDriveDevStr(vm->def, disk, 0, priv->qemuCaps)))
-            goto error;
-    }
+    if (!(devstr = qemuBuildDriveDevStr(vm->def, disk, 0, priv->qemuCaps)))
+        goto error;

     if (!(drivestr = qemuBuildDriveStr(conn, disk, false, priv->qemuCaps)))
         goto error;
@@ -610,38 +593,17 @@ qemuDomainAttachSCSIDisk(virConnectPtr conn,
         goto error;

     qemuDomainObjEnterMonitor(driver, vm);
-    if (virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_DEVICE)) {
-        ret = qemuMonitorAddDrive(priv->mon, drivestr);
-        if (ret == 0) {
-            ret = qemuMonitorAddDevice(priv->mon, devstr);
-            if (ret < 0) {
-                VIR_WARN("qemuMonitorAddDevice failed on %s (%s)",
-                         drivestr, devstr);
-                /* XXX should call 'drive_del' on error but this does not
-                   exist yet */
-            }
-        }
-    } else {
-        if (cont->info.type != VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI) {
-            virReportError(VIR_ERR_INTERNAL_ERROR,
-                           _("SCSI controller %d was missing its PCI address"),
-                           cont->idx);
-            goto error;
-        }

-        virDomainDeviceDriveAddress driveAddr;
-        ret = qemuMonitorAttachDrive(priv->mon,
-                                     drivestr,
-                                     &cont->info.addr.pci,
-                                     &driveAddr);
-        if (ret == 0) {
-            /* XXX we should probably validate that the addr matches
-             * our existing defined addr instead of overwriting */
-            disk->info.type = VIR_DOMAIN_DEVICE_ADDRESS_TYPE_DRIVE;
-            disk->info.addr.drive.bus = driveAddr.bus;
-            disk->info.addr.drive.unit = driveAddr.unit;
+    ret = qemuMonitorAddDrive(priv->mon, drivestr);
+    if (ret == 0) {
+        ret = qemuMonitorAddDevice(priv->mon, devstr);
+        if (ret < 0) {
+            VIR_WARN("qemuMonitorAddDevice failed on %s (%s)",
+                     drivestr, devstr);
+            /* XXX should call 'drive_del' on error but this does not exist yet */
         }
     }
+
     if (qemuDomainObjExitMonitor(driver, vm) < 0) {
         ret = -1;
         goto error;
-- 
2.7.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]