[libvirt] [PATCH v2 7/8] Move the detach of PCI device to the beginnging of live hotplug

Shivaprasad G Bhat shivaprasadbhat at gmail.com
Wed May 18 21:35:01 UTC 2016


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 funtions first before
attempting to hotplug any.

We need not move the detach for net devices using SRIOV as
all SRIOV devices are single function devices.

Signed-off-by: Shivaprasad G Bhat <sbhat at linux.vnet.ibm.com>
---
 src/qemu/qemu_driver.c  |   13 ++++++++++++-
 src/qemu/qemu_hotplug.c |   18 +++++++++---------
 2 files changed, 21 insertions(+), 10 deletions(-)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 37d970e..9cff397 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -8273,8 +8273,13 @@ static int qemuDomainAttachDeviceFlags(virDomainPtr dom, const char *xml,
                                          VIR_DOMAIN_DEVICE_ACTION_ATTACH) < 0)
             goto endjob;
 
-        if ((ret = qemuDomainAttachDeviceLive(vm, dev_copy, dom)) < 0)
+        if (dev_copy->type == VIR_DOMAIN_DEVICE_HOSTDEV &&
+            dev_copy->data.hostdev->source.subsys.type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI &&
+            qemuDomainAttachPCIHostDevicePrepare(driver,vm->def, dev_copy->data.hostdev, qemuCaps) < 0)
             goto endjob;
+
+        if ((ret = qemuDomainAttachDeviceLive(vm, dev_copy, dom)) < 0)
+            goto undoprepare;
         /*
          * update domain status forcibly because the domain status may be
          * changed even if we failed to attach the device. For example,
@@ -8309,6 +8314,12 @@ static int qemuDomainAttachDeviceFlags(virDomainPtr dom, const char *xml,
     virObjectUnref(cfg);
     virNWFilterUnlockFilterUpdates();
     return ret;
+
+  undoprepare:
+    if (dev_copy->type == VIR_DOMAIN_DEVICE_HOSTDEV &&
+        dev_copy->data.hostdev->source.subsys.type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI)
+        qemuHostdevReAttachPCIDevices(driver, vm->def->name, &dev_copy->data.hostdev, 1);
+    goto endjob;
 }
 
 static int qemuDomainAttachDevice(virDomainPtr dom, const char *xml)
diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
index a2bcd89..bdfbafe 100644
--- a/src/qemu/qemu_hotplug.c
+++ b/src/qemu/qemu_hotplug.c
@@ -899,6 +899,7 @@ qemuDomainAttachNetDevice(virQEMUDriverPtr driver,
     actualType = virDomainNetGetActualType(net);
 
     if (actualType == VIR_DOMAIN_NET_TYPE_HOSTDEV) {
+        virDomainHostdevDefPtr hostdev = virDomainNetGetActualHostdev(net);
         /* This is really a "smart hostdev", so it should be attached
          * as a hostdev (the hostdev code will reach over into the
          * netdev-specific code as appropriate), then also added to
@@ -907,8 +908,14 @@ qemuDomainAttachNetDevice(virQEMUDriverPtr driver,
          * qemuDomainAttachHostDevice uses a connection to resolve
          * a SCSI hostdev secret, which is not this case, so pass NULL.
          */
-        ret = qemuDomainAttachHostDevice(NULL, driver, vm,
-                                         virDomainNetGetActualHostdev(net));
+        if (qemuDomainAttachPCIHostDevicePrepare(driver, vm->def,
+                                                 hostdev, priv->qemuCaps) < 0)
+            goto cleanup;
+
+        ret = qemuDomainAttachHostDevice(NULL, driver, vm, hostdev);
+        if (!ret)
+            qemuHostdevReAttachPCIDevices(driver, vm->def->name, &hostdev, 1);
+
         goto cleanup;
     }
 
@@ -1248,10 +1255,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;
-
     backend = hostdev->source.subsys.u.pci.backend;
 
     /* Temporarily add the hostdev to the domain definition. This is needed
@@ -1330,13 +1333,10 @@ qemuDomainAttachHostPCIDevice(virQEMUDriverPtr driver,
     if (releaseaddr)
         qemuDomainReleaseDeviceAddress(vm, hostdev->info, NULL);
 
-    qemuHostdevReAttachPCIDevices(driver, vm->def->name, &hostdev, 1);
-
     VIR_FREE(devstr);
     VIR_FREE(configfd_name);
     VIR_FORCE_CLOSE(configfd);
 
- cleanup:
     return -1;
 }
 




More information about the libvir-list mailing list