[PATCH 15/18] qemuDomainAttachHostSCSIDevice: Use new infrastructure

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

 



Similarly to command line creation, use the blockdev helpers when
hotplugging an (i)SCSI hostdev.

Signed-off-by: Peter Krempa <pkrempa@xxxxxxxxxx>
---
 src/qemu/qemu_hotplug.c | 45 +++++++----------------------------------
 1 file changed, 7 insertions(+), 38 deletions(-)

diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
index fbbd6a533c..06b3b94ff2 100644
--- a/src/qemu/qemu_hotplug.c
+++ b/src/qemu/qemu_hotplug.c
@@ -2566,17 +2566,12 @@ qemuDomainAttachHostSCSIDevice(virQEMUDriverPtr driver,
     int ret = -1;
     qemuDomainObjPrivatePtr priv = vm->privateData;
     virErrorPtr orig_err;
+    g_autoptr(qemuBlockStorageSourceAttachData) data = NULL;
+    const char *backendalias = NULL;
     g_autofree char *devstr = NULL;
-    g_autofree char *drvstr = NULL;
-    g_autofree char *drivealias = NULL;
-    g_autofree char *secobjAlias = NULL;
     bool teardowncgroup = false;
     bool teardownlabel = false;
     bool teardowndevice = false;
-    bool driveAdded = false;
-    virJSONValuePtr secobjProps = NULL;
-    virDomainHostdevSubsysSCSIPtr scsisrc = &hostdev->source.subsys.u.scsi;
-    qemuDomainSecretInfoPtr secinfo = NULL;

     /* Let's make sure the disk has a controller defined and loaded before
      * trying to add it. The controller used by the disk must exist before a
@@ -2611,25 +2606,11 @@ qemuDomainAttachHostSCSIDevice(virQEMUDriverPtr driver,
     if (qemuDomainSecretHostdevPrepare(priv, hostdev) < 0)
         goto cleanup;

-    if (scsisrc->protocol == VIR_DOMAIN_HOSTDEV_SCSI_PROTOCOL_TYPE_ISCSI) {
-        qemuDomainStorageSourcePrivatePtr srcPriv =
-            QEMU_DOMAIN_STORAGE_SOURCE_PRIVATE(scsisrc->u.iscsi.src);
-        if (srcPriv)
-            secinfo = srcPriv->secinfo;
-    }
-
-    if (secinfo && secinfo->type == VIR_DOMAIN_SECRET_INFO_TYPE_AES) {
-        if (qemuBuildSecretInfoProps(secinfo, &secobjProps) < 0)
-            goto cleanup;
-    }
-
-    if (!(drvstr = qemuBuildSCSIHostdevDrvStr(hostdev, priv->qemuCaps)))
-        goto cleanup;
-
-    if (!(drivealias = qemuAliasFromHostdev(hostdev)))
+    if (!(data = qemuBuildHostdevSCSIAttachPrepare(hostdev, &backendalias,
+                                                   priv->qemuCaps)))
         goto cleanup;

-    if (!(devstr = qemuBuildSCSIHostdevDevStr(vm->def, hostdev, drivealias)))
+    if (!(devstr = qemuBuildSCSIHostdevDevStr(vm->def, hostdev, backendalias)))
         goto cleanup;

     if (VIR_REALLOC_N(vm->def->hostdevs, vm->def->nhostdevs + 1) < 0)
@@ -2637,14 +2618,9 @@ qemuDomainAttachHostSCSIDevice(virQEMUDriverPtr driver,

     qemuDomainObjEnterMonitor(driver, vm);

-    if (secobjProps &&
-        qemuMonitorAddObject(priv->mon, &secobjProps, &secobjAlias) < 0)
+    if (qemuBlockStorageSourceAttachApply(priv->mon, data) < 0)
         goto exit_monitor;

-    if (qemuMonitorAddDrive(priv->mon, drvstr) < 0)
-        goto exit_monitor;
-    driveAdded = true;
-
     if (qemuMonitorAddDevice(priv->mon, devstr) < 0)
         goto exit_monitor;

@@ -2670,18 +2646,11 @@ qemuDomainAttachHostSCSIDevice(virQEMUDriverPtr driver,
             VIR_WARN("Unable to remove host device from /dev");
     }
     qemuDomainSecretHostdevDestroy(hostdev);
-    virJSONValueFree(secobjProps);
     return ret;

  exit_monitor:
     virErrorPreserveLast(&orig_err);
-    if (driveAdded && qemuMonitorDriveDel(priv->mon, drivealias) < 0) {
-        VIR_WARN("Unable to remove drive %s (%s) after failed "
-                 "qemuMonitorAddDevice",
-                 drvstr, devstr);
-    }
-    if (secobjAlias)
-        ignore_value(qemuMonitorDelObject(priv->mon, secobjAlias, false));
+    qemuBlockStorageSourceAttachRollback(priv->mon, data);
     ignore_value(qemuDomainObjExitMonitor(driver, vm));
     virErrorRestore(&orig_err);

-- 
2.26.2




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

  Powered by Linux