[PATCH v2 08/21] qemu: hotplug: Move the detach of PCI device to the beginning of live hotplug

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

 



From: Shivaprasad G Bhat <sbhat@xxxxxxxxxxxxxxxxxx>

The hostdevices are the only devices which have dependencies
outside of themselves such that, other functions of the PCI
card should also have been detached from host driver before
attempting the hotplug.

This patch moves the detach to the beginning of the hotplug
so that the following patch can detach all functions first before
attempting to hotplug any.

We don't need to move the detach for net devices using SRIOV as
all SRIOV devices are single function devices and can be independently
detached as usual.

Signed-off-by: Shivaprasad G Bhat <sbhat@xxxxxxxxxxxxxxxxxx>
Signed-off-by: Daniel Henrique Barboza <danielhb413@xxxxxxxxx>
---
 src/qemu/qemu_hotplug.c | 32 ++++++++++++++++++++++----------
 1 file changed, 22 insertions(+), 10 deletions(-)

diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
index 8e5625fb8d..688171c7b2 100644
--- a/src/qemu/qemu_hotplug.c
+++ b/src/qemu/qemu_hotplug.c
@@ -1205,6 +1205,7 @@ qemuDomainAttachNetDevice(virQEMUDriverPtr driver,
     g_autofree char *netdev_name = NULL;
     g_autoptr(virConnect) conn = NULL;
     virErrorPtr save_err = NULL;
+    virDomainHostdevDefPtr hostdev = NULL;
 
     /* preallocate new slot for device */
     if (VIR_REALLOC_N(vm->def->nets, vm->def->nnets + 1) < 0)
@@ -1235,9 +1236,18 @@ qemuDomainAttachNetDevice(virQEMUDriverPtr driver,
          * as a hostdev (the hostdev code will reach over into the
          * netdev-specific code as appropriate), then also added to
          * the nets list (see cleanup:) if successful.
+         *
+         * qemuDomainAttachHostDevice uses a connection to resolve
+         * a SCSI hostdev secret, which is not this case, so pass NULL.
          */
-        ret = qemuDomainAttachHostDevice(driver, vm,
-                                         virDomainNetGetActualHostdev(net));
+        hostdev = virDomainNetGetActualHostdev(net);
+        if (qemuDomainAttachPCIHostDevicePrepare(driver, vm->def,
+                                                 hostdev, priv->qemuCaps) < 0)
+            goto cleanup;
+
+        if ((ret = qemuDomainAttachHostDevice(driver, vm, hostdev)) < 0)
+            qemuHostdevReAttachPCIDevices(driver, vm->def->name, &hostdev, 1);
+
         goto cleanup;
     }
 
@@ -1593,10 +1603,6 @@ qemuDomainAttachHostPCIDevice(virQEMUDriverPtr driver,
     if (VIR_REALLOC_N(vm->def->hostdevs, vm->def->nhostdevs + 1) < 0)
         return -1;
 
-    if (qemuDomainAttachPCIHostDevicePrepare(driver, vm->def,
-                                             hostdev, priv->qemuCaps) < 0)
-        return -1;
-
     /* this could have been changed by qemuHostdevPreparePCIDevices */
     backend = hostdev->source.subsys.u.pci.backend;
 
@@ -1674,8 +1680,6 @@ qemuDomainAttachHostPCIDevice(virQEMUDriverPtr driver,
     if (releaseaddr)
         qemuDomainReleaseDeviceAddress(vm, info);
 
-    qemuHostdevReAttachPCIDevices(driver, vm->def->name, &hostdev, 1);
-
     return -1;
 }
 
@@ -2905,6 +2909,8 @@ qemuDomainAttachHostDevice(virQEMUDriverPtr driver,
                            virDomainObjPtr vm,
                            virDomainHostdevDefPtr hostdev)
 {
+    qemuDomainObjPrivatePtr priv = vm->privateData;
+
     if (hostdev->mode != VIR_DOMAIN_HOSTDEV_MODE_SUBSYS) {
         virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
                        _("hotplug is not supported for hostdev mode '%s'"),
@@ -2914,9 +2920,15 @@ qemuDomainAttachHostDevice(virQEMUDriverPtr driver,
 
     switch (hostdev->source.subsys.type) {
     case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI:
-        if (qemuDomainAttachHostPCIDevice(driver, vm,
-                                          hostdev) < 0)
+        if (qemuDomainAttachPCIHostDevicePrepare(driver, vm->def,
+                                                 hostdev, priv->qemuCaps) < 0)
             return -1;
+
+        if (qemuDomainAttachHostPCIDevice(driver, vm, hostdev) < 0) {
+            qemuHostdevReAttachPCIDevices(driver, vm->def->name, &hostdev, 1);
+            return -1;
+        }
+
         break;
 
     case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB:
-- 
2.24.1






[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