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

[libvirt] [PATCH 5/7] qemu: implement virNodeDeviceDetachFlags backend



The differences from virNodeDeviceDettach are very minor:

1) Check that the flags are 0.

2) Set the virPCIDevice's stubDriver according to the driverName that
   is passed in.

3) Call virPCIDeviceDetach with a NULL stubDriver, indicating it
   should get the name of the stub driver from the virPCIDevice
   object.
---
 src/qemu/qemu_driver.c | 25 +++++++++++++++++++++++--
 1 file changed, 23 insertions(+), 2 deletions(-)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index ba5600d..237d4de 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -9741,7 +9741,9 @@ out:
 }
 
 static int
-qemuNodeDeviceDettach(virNodeDevicePtr dev)
+qemuNodeDeviceDetachFlags(virNodeDevicePtr dev,
+                          const char *driverName,
+                          unsigned int flags)
 {
     virQEMUDriverPtr driver = dev->conn->privateData;
     virPCIDevicePtr pci;
@@ -9749,6 +9751,8 @@ qemuNodeDeviceDettach(virNodeDevicePtr dev)
     int ret = -1;
     bool in_inactive_list = false;
 
+    virCheckFlags(0, -1);
+
     if (qemuNodeDeviceGetPciInfo(dev, &domain, &bus, &slot, &function) < 0)
         return -1;
 
@@ -9756,12 +9760,22 @@ qemuNodeDeviceDettach(virNodeDevicePtr dev)
     if (!pci)
         return -1;
 
+    if (!driverName || STREQ(driverName, "kvm")) {
+        virPCIDeviceSetStubDriver(pci, "pci-stub");
+    } else if (STREQ(driverName, "vfio")) {
+        virPCIDeviceSetStubDriver(pci, "vfio-pci");
+    } else {
+        virReportError(VIR_ERR_INVALID_ARG,
+                       _("unknown driver name '%s'"), driverName);
+        goto out;
+    }
+
     virObjectLock(driver->activePciHostdevs);
     virObjectLock(driver->inactivePciHostdevs);
     in_inactive_list = virPCIDeviceListFind(driver->inactivePciHostdevs, pci);
 
     if (virPCIDeviceDetach(pci, driver->activePciHostdevs,
-                           driver->inactivePciHostdevs, "pci-stub") < 0)
+                           driver->inactivePciHostdevs, NULL) < 0)
         goto out;
 
     ret = 0;
@@ -9774,6 +9788,12 @@ out:
 }
 
 static int
+qemuNodeDeviceDettach(virNodeDevicePtr dev)
+{
+    return qemuNodeDeviceDetachFlags(dev, NULL, 0);
+}
+
+static int
 qemuNodeDeviceReAttach(virNodeDevicePtr dev)
 {
     virQEMUDriverPtr driver = dev->conn->privateData;
@@ -14725,6 +14745,7 @@ static virDriver qemuDriver = {
     .domainMigratePrepare2 = qemuDomainMigratePrepare2, /* 0.5.0 */
     .domainMigrateFinish2 = qemuDomainMigrateFinish2, /* 0.5.0 */
     .nodeDeviceDettach = qemuNodeDeviceDettach, /* 0.6.1 */
+    .nodeDeviceDetachFlags = qemuNodeDeviceDetachFlags, /* 1.0.5 */
     .nodeDeviceReAttach = qemuNodeDeviceReAttach, /* 0.6.1 */
     .nodeDeviceReset = qemuNodeDeviceReset, /* 0.6.1 */
     .domainMigratePrepareTunnel = qemuDomainMigratePrepareTunnel, /* 0.7.2 */
-- 
1.7.11.7


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