[PATCH v12 08/11] change qemu driver to use hostdev common library

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

 



Change qemu driver to use hostdev common library instead of APIs in
qemu_hostdev.[ch] Improve some test files.

Signed-off-by: Chunyan Liu <cyliu@xxxxxxxx>
---
 po/POTFILES.in          |    1 -
 src/Makefile.am         |    1 -
 src/qemu/qemu_command.c |    1 -
 src/qemu/qemu_conf.h    |    9 +---
 src/qemu/qemu_domain.c  |    4 +-
 src/qemu/qemu_driver.c  |   81 ++++++-------------------------
 src/qemu/qemu_hostdev.h |    5 --
 src/qemu/qemu_hotplug.c |  119 +++++++++++++++++++---------------------------
 src/qemu/qemu_process.c |   31 ++++++++----
 9 files changed, 89 insertions(+), 163 deletions(-)

diff --git a/po/POTFILES.in b/po/POTFILES.in
index 60c226a..9e71db3 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -99,7 +99,6 @@ src/qemu/qemu_command.c
 src/qemu/qemu_conf.c
 src/qemu/qemu_domain.c
 src/qemu/qemu_driver.c
-src/qemu/qemu_hostdev.c
 src/qemu/qemu_hotplug.c
 src/qemu/qemu_migration.c
 src/qemu/qemu_monitor.c
diff --git a/src/Makefile.am b/src/Makefile.am
index 04ea01b..5712055 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -673,7 +673,6 @@ QEMU_DRIVER_SOURCES =							\
 		qemu/qemu_command.c qemu/qemu_command.h			\
 		qemu/qemu_domain.c qemu/qemu_domain.h			\
 		qemu/qemu_cgroup.c qemu/qemu_cgroup.h			\
-		qemu/qemu_hostdev.c qemu/qemu_hostdev.h			\
 		qemu/qemu_hotplug.c qemu/qemu_hotplug.h			\
 		qemu/qemu_hotplugpriv.h					\
 		qemu/qemu_conf.c qemu/qemu_conf.h			\
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index e499d54..ccdd50f 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -24,7 +24,6 @@
 #include <config.h>
 
 #include "qemu_command.h"
-#include "qemu_hostdev.h"
 #include "qemu_capabilities.h"
 #include "qemu_bridge_filter.h"
 #include "cpu/cpu.h"
diff --git a/src/qemu/qemu_conf.h b/src/qemu/qemu_conf.h
index 158cc1a..3512589 100644
--- a/src/qemu/qemu_conf.h
+++ b/src/qemu/qemu_conf.h
@@ -55,6 +55,7 @@
 
 # define QEMU_DRIVER_NAME "QEMU"
 
+# define QEMU_DRIVER_NAME "QEMU"
 typedef struct _virQEMUDriver virQEMUDriver;
 typedef virQEMUDriver *virQEMUDriverPtr;
 
@@ -215,14 +216,6 @@ struct _virQEMUDriver {
     /* Immutable pointer. self-locking APIs */
     virSecurityManagerPtr securityManager;
 
-    /* Immutable pointers. Requires locks to be held before
-     * calling APIs. activePciHostdevs must be locked before
-     * inactivePciHostdevs */
-    virPCIDeviceListPtr activePciHostdevs;
-    virPCIDeviceListPtr inactivePciHostdevs;
-    virUSBDeviceListPtr activeUsbHostdevs;
-    virSCSIDeviceListPtr activeScsiHostdevs;
-
     /* Immutable pointer. Unsafe APIs. XXX */
     virHashTablePtr sharedDevices;
 
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index 55e707e..c9586e5 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -38,7 +38,7 @@
 #include "virtime.h"
 #include "virstoragefile.h"
 #include "virstring.h"
-#include "qemu_hostdev.h"
+#include "virhostdev.h"
 
 #include <sys/time.h>
 #include <fcntl.h>
@@ -909,7 +909,7 @@ qemuDomainDeviceDefPostParse(virDomainDeviceDefPtr dev,
 
             hostdev->source.subsys.u.pci.backend = VIR_DOMAIN_HOSTDEV_PCI_BACKEND_KVM;
             if (driver && driver->qemuCapsCache) {
-                bool supportsPassthroughVFIO = qemuHostdevHostSupportsPassthroughVFIO();
+                bool supportsPassthroughVFIO = virHostdevHostSupportsPassthroughVFIO();
                 qemuCaps = virQEMUCapsCacheLookupCopy(driver->qemuCapsCache,
                                                       def->emulator);
                 if (supportsPassthroughVFIO && qemuCaps &&
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 1fe8992..a812e47 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -50,7 +50,6 @@
 #include "qemu_capabilities.h"
 #include "qemu_command.h"
 #include "qemu_cgroup.h"
-#include "qemu_hostdev.h"
 #include "qemu_hotplug.h"
 #include "qemu_monitor.h"
 #include "qemu_bridge_filter.h"
@@ -94,6 +93,7 @@
 #include "virstring.h"
 #include "viraccessapicheck.h"
 #include "viraccessapicheckqemu.h"
+#include "virhostdev.h"
 
 #define VIR_FROM_THIS VIR_FROM_QEMU
 
@@ -695,18 +695,6 @@ qemuStateInitialize(bool privileged,
     if (qemuSecurityInit(qemu_driver) < 0)
         goto error;
 
-    if ((qemu_driver->activePciHostdevs = virPCIDeviceListNew()) == NULL)
-        goto error;
-
-    if ((qemu_driver->activeUsbHostdevs = virUSBDeviceListNew()) == NULL)
-        goto error;
-
-    if ((qemu_driver->inactivePciHostdevs = virPCIDeviceListNew()) == NULL)
-        goto error;
-
-    if ((qemu_driver->activeScsiHostdevs = virSCSIDeviceListNew()) == NULL)
-        goto error;
-
     if (!(qemu_driver->sharedDevices = virHashCreate(30, qemuSharedDeviceEntryFree)))
         goto error;
 
@@ -983,10 +971,6 @@ qemuStateCleanup(void) {
 
     virNWFilterUnRegisterCallbackDriver(&qemuCallbackDriver);
     virObjectUnref(qemu_driver->config);
-    virObjectUnref(qemu_driver->activePciHostdevs);
-    virObjectUnref(qemu_driver->inactivePciHostdevs);
-    virObjectUnref(qemu_driver->activeUsbHostdevs);
-    virObjectUnref(qemu_driver->activeScsiHostdevs);
     virHashFree(qemu_driver->sharedDevices);
     virObjectUnref(qemu_driver->caps);
     virQEMUCapsCacheFree(qemu_driver->qemuCapsCache);
@@ -11199,14 +11183,14 @@ qemuNodeDeviceDetachFlags(virNodeDevicePtr dev,
                           const char *driverName,
                           unsigned int flags)
 {
-    virQEMUDriverPtr driver = dev->conn->privateData;
     virPCIDevicePtr pci = NULL;
     unsigned domain = 0, bus = 0, slot = 0, function = 0;
     int ret = -1;
     virNodeDeviceDefPtr def = NULL;
     char *xml = NULL;
-    bool legacy = qemuHostdevHostSupportsPassthroughLegacy();
-    bool vfio = qemuHostdevHostSupportsPassthroughVFIO();
+    bool legacy = virHostdevHostSupportsPassthroughKVM();
+    bool vfio = virHostdevHostSupportsPassthroughVFIO();
+    virHostdevManagerPtr hostdev_mgr;
 
     virCheckFlags(0, -1);
 
@@ -11265,18 +11249,12 @@ qemuNodeDeviceDetachFlags(virNodeDevicePtr dev,
         goto cleanup;
     }
 
-    virObjectLock(driver->activePciHostdevs);
-    virObjectLock(driver->inactivePciHostdevs);
-
-    if (virPCIDeviceDetach(pci, driver->activePciHostdevs,
-                           driver->inactivePciHostdevs) < 0) {
-        goto out;
-    }
+    hostdev_mgr = virHostdevManagerGetDefault();
+    if (hostdev_mgr == NULL ||
+        virHostdevPciNodeDeviceDetach(hostdev_mgr, pci) < 0)
+        goto cleanup;
 
     ret = 0;
-out:
-    virObjectUnlock(driver->inactivePciHostdevs);
-    virObjectUnlock(driver->activePciHostdevs);
 cleanup:
     virPCIDeviceFree(pci);
     virNodeDeviceDefFree(def);
@@ -11293,13 +11271,12 @@ qemuNodeDeviceDettach(virNodeDevicePtr dev)
 static int
 qemuNodeDeviceReAttach(virNodeDevicePtr dev)
 {
-    virQEMUDriverPtr driver = dev->conn->privateData;
     virPCIDevicePtr pci = NULL;
-    virPCIDevicePtr other;
     unsigned domain = 0, bus = 0, slot = 0, function = 0;
     int ret = -1;
     virNodeDeviceDefPtr def = NULL;
     char *xml = NULL;
+    virHostdevManagerPtr hostdev_mgr;
 
     xml = virNodeDeviceGetXMLDesc(dev, 0);
     if (!xml)
@@ -11319,35 +11296,13 @@ qemuNodeDeviceReAttach(virNodeDevicePtr dev)
     if (!pci)
         goto cleanup;
 
-    virObjectLock(driver->activePciHostdevs);
-    virObjectLock(driver->inactivePciHostdevs);
-    other = virPCIDeviceListFind(driver->activePciHostdevs, pci);
-    if (other) {
-        const char *other_name = NULL;
-        const char *other_drvname = NULL;
-        virPCIDeviceGetUsedBy(other, &other_drvname, &other_name);
-
-        if (other_name)
-            virReportError(VIR_ERR_OPERATION_INVALID,
-                           _("PCI device %s is still in use by domain %s"),
-                           virPCIDeviceGetName(pci), other_name);
-        else
-            virReportError(VIR_ERR_OPERATION_INVALID,
-                           _("PCI device %s is still in use"),
-                           virPCIDeviceGetName(pci));
-        goto out;
-    }
-
-    virPCIDeviceReattachInit(pci);
-
-    if (virPCIDeviceReattach(pci, driver->activePciHostdevs,
-                             driver->inactivePciHostdevs) < 0)
+    hostdev_mgr = virHostdevManagerGetDefault();
+    if (hostdev_mgr == NULL ||
+        virHostdevPciNodeDeviceReAttach(hostdev_mgr, pci) < 0)
         goto out;
 
     ret = 0;
 out:
-    virObjectUnlock(driver->inactivePciHostdevs);
-    virObjectUnlock(driver->activePciHostdevs);
     virPCIDeviceFree(pci);
 cleanup:
     virNodeDeviceDefFree(def);
@@ -11358,12 +11313,12 @@ cleanup:
 static int
 qemuNodeDeviceReset(virNodeDevicePtr dev)
 {
-    virQEMUDriverPtr driver = dev->conn->privateData;
     virPCIDevicePtr pci;
     unsigned domain = 0, bus = 0, slot = 0, function = 0;
     int ret = -1;
     virNodeDeviceDefPtr def = NULL;
     char *xml = NULL;
+    virHostdevManagerPtr hostdev_mgr;
 
     xml = virNodeDeviceGetXMLDesc(dev, 0);
     if (!xml)
@@ -11383,17 +11338,13 @@ qemuNodeDeviceReset(virNodeDevicePtr dev)
     if (!pci)
         goto cleanup;
 
-    virObjectLock(driver->activePciHostdevs);
-    virObjectLock(driver->inactivePciHostdevs);
-
-    if (virPCIDeviceReset(pci, driver->activePciHostdevs,
-                          driver->inactivePciHostdevs) < 0)
+    hostdev_mgr = virHostdevManagerGetDefault();
+    if (hostdev_mgr == NULL ||
+        virHostdevPciNodeDeviceReset(hostdev_mgr, pci) < 0)
         goto out;
 
     ret = 0;
 out:
-    virObjectUnlock(driver->inactivePciHostdevs);
-    virObjectUnlock(driver->activePciHostdevs);
     virPCIDeviceFree(pci);
 cleanup:
     virNodeDeviceDefFree(def);
diff --git a/src/qemu/qemu_hostdev.h b/src/qemu/qemu_hostdev.h
index 128032d..c4a9226 100644
--- a/src/qemu/qemu_hostdev.h
+++ b/src/qemu/qemu_hostdev.h
@@ -27,11 +27,6 @@
 # include "qemu_conf.h"
 # include "domain_conf.h"
 
-typedef enum {
-     VIR_STRICT_ACS_CHECK     = (1 << 0), /* strict acs check */
-     VIR_COLD_BOOT                   = (1 << 1), /* cold boot */
-} qemuHostdevFlag;
-
 int qemuUpdateActivePciHostdevs(virQEMUDriverPtr driver,
                                 virDomainDefPtr def);
 int qemuUpdateActiveUsbHostdevs(virQEMUDriverPtr driver,
diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
index afa92da..bb9b3ff 100644
--- a/src/qemu/qemu_hotplug.c
+++ b/src/qemu/qemu_hotplug.c
@@ -30,7 +30,6 @@
 #include "qemu_domain.h"
 #include "qemu_command.h"
 #include "qemu_bridge_filter.h"
-#include "qemu_hostdev.h"
 #include "domain_audit.h"
 #include "domain_nwfilter.h"
 #include "virlog.h"
@@ -50,6 +49,7 @@
 #include "virstoragefile.h"
 #include "virstring.h"
 #include "virtime.h"
+#include "virhostdev.h"
 
 #define VIR_FROM_THIS VIR_FROM_QEMU
 #define CHANGE_MEDIA_RETRIES 10
@@ -1156,13 +1156,17 @@ qemuDomainAttachHostPciDevice(virQEMUDriverPtr driver,
     unsigned long long memKB;
     virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
     unsigned int flags = 0;
+    virHostdevManagerPtr hostdev_mgr;
 
     if (VIR_REALLOC_N(vm->def->hostdevs, vm->def->nhostdevs + 1) < 0)
         return -1;
 
     if (!cfg->relaxedACS)
         flags |= VIR_STRICT_ACS_CHECK;
-    if (qemuPrepareHostdevPCIDevices(driver, vm->def->name, vm->def->uuid,
+    hostdev_mgr = virHostdevManagerGetDefault();
+    if (hostdev_mgr == NULL ||
+        virHostdevPreparePciHostdevs(hostdev_mgr, QEMU_DRIVER_NAME,
+                                     vm->def->name, vm->def->uuid,
                                      &hostdev, 1, flags) < 0)
         return -1;
 
@@ -1273,7 +1277,8 @@ error:
     if (releaseaddr)
         qemuDomainReleaseDeviceAddress(vm, hostdev->info, NULL);
 
-    qemuDomainReAttachHostdevDevices(driver, vm->def->name, &hostdev, 1);
+    virHostdevReAttachPciHostdevs(hostdev_mgr, QEMU_DRIVER_NAME,
+                                  vm->def->name, &hostdev, 1);
 
     VIR_FREE(devstr);
     VIR_FREE(configfd_name);
@@ -1459,28 +1464,23 @@ qemuDomainAttachHostUsbDevice(virQEMUDriverPtr driver,
                               virDomainHostdevDefPtr hostdev)
 {
     qemuDomainObjPrivatePtr priv = vm->privateData;
-    virUSBDeviceList *list = NULL;
-    virUSBDevicePtr usb = NULL;
     char *devstr = NULL;
     bool added = false;
     bool teardowncgroup = false;
     bool teardownlabel = false;
     int ret = -1;
-
-    if (qemuFindHostdevUSBDevice(hostdev, true, &usb) < 0)
+    virHostdevManagerPtr hostdev_mgr;
+
+    hostdev_mgr = virHostdevManagerGetDefault();
+    if (hostdev_mgr == NULL ||
+        virHostdevPrepareUsbHostdevs(hostdev_mgr,
+                                     QEMU_DRIVER_NAME,
+                                     vm->def->name,
+                                     &hostdev,
+                                     1, 0) < 0)
         return -1;
 
-    if (!(list = virUSBDeviceListNew()))
-        goto cleanup;
-
-    if (virUSBDeviceListAdd(list, usb) < 0)
-        goto cleanup;
-
-    if (qemuPrepareHostdevUSBDevices(driver, vm->def->name, list) < 0)
-        goto cleanup;
-
     added = true;
-    virUSBDeviceListSteal(list, usb);
 
     if (qemuSetupHostdevCGroup(vm, hostdev) < 0)
         goto cleanup;
@@ -1525,13 +1525,9 @@ cleanup:
                                                   vm->def, hostdev, NULL) < 0)
             VIR_WARN("Unable to restore host device labelling on hotplug fail");
         if (added)
-            virUSBDeviceListSteal(driver->activeUsbHostdevs, usb);
+            virHostdevReAttachUsbHostdevs(hostdev_mgr, QEMU_DRIVER_NAME,
+                                          vm->def->name, &hostdev, 1);
     }
-    if (list && usb &&
-        !virUSBDeviceListFind(list, usb) &&
-        !virUSBDeviceListFind(driver->activeUsbHostdevs, usb))
-        virUSBDeviceFree(usb);
-    virObjectUnref(list);
     VIR_FREE(devstr);
     return ret;
 }
@@ -1549,6 +1545,7 @@ qemuDomainAttachHostScsiDevice(virQEMUDriverPtr driver,
     bool teardowncgroup = false;
     bool teardownlabel = false;
     virDomainDeviceDef dev;
+    virHostdevManagerPtr hostdev_mgr;
 
     if (!virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_DRIVE) ||
         !virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_DEVICE) ||
@@ -1568,8 +1565,12 @@ qemuDomainAttachHostScsiDevice(virQEMUDriverPtr driver,
     if (qemuAddSharedDevice(driver, &dev, vm->def->name) < 0)
          return -1;
 
-    if (qemuPrepareHostdevSCSIDevices(driver, vm->def->name,
-                                      &hostdev, 1)) {
+    hostdev_mgr = virHostdevManagerGetDefault();
+    if (hostdev_mgr == NULL ||
+        virHostdevPrepareScsiHostdevs(hostdev_mgr,
+                                      QEMU_DRIVER_NAME,
+                                      vm->def->name,
+                                      &hostdev, 1) < 0) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        _("Unable to prepare scsi hostdev: %s:%d:%d:%d"),
                        hostdev->source.subsys.u.scsi.adapter,
@@ -1627,7 +1628,8 @@ qemuDomainAttachHostScsiDevice(virQEMUDriverPtr driver,
 cleanup:
     if (ret < 0) {
         ignore_value(qemuRemoveSharedDevice(driver, &dev, vm->def->name));
-        qemuDomainReAttachHostScsiDevices(driver, vm->def->name, &hostdev, 1);
+        virHostdevReAttachScsiHostdevs(hostdev_mgr, QEMU_DRIVER_NAME,
+                                       vm->def->name, &hostdev, 1);
         if (teardowncgroup && qemuTeardownHostdevCgroup(vm, hostdev) < 0)
             VIR_WARN("Unable to remove host device cgroup ACL on hotplug fail");
         if (teardownlabel &&
@@ -2540,54 +2542,29 @@ qemuDomainRemoveControllerDevice(virQEMUDriverPtr driver,
 
 
 static void
-qemuDomainRemovePCIHostDevice(virQEMUDriverPtr driver,
-                              virDomainObjPtr vm,
+qemuDomainRemovePCIHostDevice(virDomainObjPtr vm,
                               virDomainHostdevDefPtr hostdev)
 {
-    virDomainHostdevSubsysPtr subsys = &hostdev->source.subsys;
-    virPCIDevicePtr pci;
-    virPCIDevicePtr activePci;
-
-    virObjectLock(driver->activePciHostdevs);
-    virObjectLock(driver->inactivePciHostdevs);
-    pci = virPCIDeviceNew(subsys->u.pci.addr.domain, subsys->u.pci.addr.bus,
-                          subsys->u.pci.addr.slot, subsys->u.pci.addr.function);
-    if (pci) {
-        activePci = virPCIDeviceListSteal(driver->activePciHostdevs, pci);
-        if (activePci &&
-            virPCIDeviceReset(activePci, driver->activePciHostdevs,
-                              driver->inactivePciHostdevs) == 0) {
-            qemuReattachPciDevice(activePci, driver);
-        } else {
-            /* reset of the device failed, treat it as if it was returned */
-            virPCIDeviceFree(activePci);
-        }
-        virPCIDeviceFree(pci);
-    }
-    virObjectUnlock(driver->activePciHostdevs);
-    virObjectUnlock(driver->inactivePciHostdevs);
+    virHostdevManagerPtr hostdev_mgr;
+
+    hostdev_mgr = virHostdevManagerGetDefault();
+    if (hostdev_mgr != NULL)
+        virHostdevReAttachPciHostdevs(hostdev_mgr, QEMU_DRIVER_NAME,
+                                      vm->def->name, &hostdev, 1);
 
     qemuDomainReleaseDeviceAddress(vm, hostdev->info, NULL);
 }
 
 static void
-qemuDomainRemoveUSBHostDevice(virQEMUDriverPtr driver,
-                              virDomainObjPtr vm ATTRIBUTE_UNUSED,
+qemuDomainRemoveUSBHostDevice(virDomainObjPtr vm,
                               virDomainHostdevDefPtr hostdev)
 {
-    virDomainHostdevSubsysPtr subsys = &hostdev->source.subsys;
-    virUSBDevicePtr usb;
-
-    usb = virUSBDeviceNew(subsys->u.usb.bus, subsys->u.usb.device, NULL);
-    if (usb) {
-        virObjectLock(driver->activeUsbHostdevs);
-        virUSBDeviceListDel(driver->activeUsbHostdevs, usb);
-        virObjectUnlock(driver->activeUsbHostdevs);
-        virUSBDeviceFree(usb);
-    } else {
-        VIR_WARN("Unable to find device %03d.%03d in list of used USB devices",
-                 subsys->u.usb.bus, subsys->u.usb.device);
-    }
+    virHostdevManagerPtr hostdev_mgr;
+
+    hostdev_mgr = virHostdevManagerGetDefault();
+    if (hostdev_mgr != NULL)
+        virHostdevReAttachUsbHostdevs(hostdev_mgr, QEMU_DRIVER_NAME,
+                                      vm->def->name, &hostdev, 1);
 }
 
 static void
@@ -2595,13 +2572,17 @@ qemuDomainRemoveSCSIHostDevice(virQEMUDriverPtr driver,
                                virDomainObjPtr vm,
                                virDomainHostdevDefPtr hostdev)
 {
+    virHostdevManagerPtr hostdev_mgr;
     virDomainDeviceDef dev;
 
     dev.type = VIR_DOMAIN_DEVICE_HOSTDEV;
     dev.data.hostdev = hostdev;
 
     ignore_value(qemuRemoveSharedDevice(driver, &dev, vm->def->name));
-    qemuDomainReAttachHostScsiDevices(driver, vm->def->name, &hostdev, 1);
+    hostdev_mgr = virHostdevManagerGetDefault();
+    if (hostdev_mgr != NULL)
+        virHostdevReAttachScsiHostdevs(hostdev_mgr, QEMU_DRIVER_NAME,
+                                       vm->def->name, &hostdev, 1);
 }
 
 static void
@@ -2641,14 +2622,12 @@ qemuDomainRemoveHostDevice(virQEMUDriverPtr driver,
 
     virDomainAuditHostdev(vm, hostdev, "detach", true);
 
-    qemuDomainHostdevNetConfigRestore(hostdev, cfg->stateDir);
-
     switch ((enum virDomainHostdevSubsysType) hostdev->source.subsys.type) {
     case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI:
-        qemuDomainRemovePCIHostDevice(driver, vm, hostdev);
+        qemuDomainRemovePCIHostDevice(vm, hostdev);
         break;
     case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB:
-        qemuDomainRemoveUSBHostDevice(driver, vm, hostdev);
+        qemuDomainRemoveUSBHostDevice(vm, hostdev);
         break;
     case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI:
         qemuDomainRemoveSCSIHostDevice(driver, vm, hostdev);
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index 5ea42c7..8cabb39 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -39,7 +39,6 @@
 #include "qemu_capabilities.h"
 #include "qemu_monitor.h"
 #include "qemu_command.h"
-#include "qemu_hostdev.h"
 #include "qemu_hotplug.h"
 #include "qemu_bridge_filter.h"
 #include "qemu_migration.h"
@@ -66,6 +65,7 @@
 #include "viratomic.h"
 #include "virnuma.h"
 #include "virstring.h"
+#include "virhostdev.h"
 
 #define VIR_FROM_THIS VIR_FROM_QEMU
 
@@ -3124,6 +3124,8 @@ qemuProcessReconnect(void *opaque)
     virQEMUDriverConfigPtr cfg;
     size_t i;
     int ret;
+    virHostdevManagerPtr hostdev_mgr;
+    unsigned int flags;
 
     memcpy(&oldjob, &data->oldjob, sizeof(oldjob));
 
@@ -3168,14 +3170,12 @@ qemuProcessReconnect(void *opaque)
             goto error;
     }
 
-    if (qemuUpdateActivePciHostdevs(driver, obj->def) < 0) {
-        goto error;
-    }
 
-    if (qemuUpdateActiveUsbHostdevs(driver, obj->def) < 0)
-        goto error;
-
-    if (qemuUpdateActiveScsiHostdevs(driver, obj->def) < 0)
+    hostdev_mgr = virHostdevManagerGetDefault();
+    flags = VIR_SP_PCI_HOSTDEV | VIR_SP_USB_HOSTDEV | VIR_SP_SCSI_HOSTDEV;
+    if (hostdev_mgr == NULL ||
+        virHostdevUpdateActiveHostdevs(hostdev_mgr, QEMU_DRIVER_NAME,
+                                       obj->def, flags) < 0)
         goto error;
 
     if (qemuConnectCgroup(driver, obj) < 0)
@@ -3607,6 +3607,7 @@ int qemuProcessStart(virConnectPtr conn,
     virQEMUDriverConfigPtr cfg;
     virCapsPtr caps = NULL;
     unsigned int hostdev_flags = 0;
+    virHostdevManagerPtr hostdev_mgr;
 
     VIR_DEBUG("vm=%p name=%s id=%d pid=%llu",
               vm, vm->def->name, vm->def->id,
@@ -3709,7 +3710,11 @@ int qemuProcessStart(virConnectPtr conn,
         hostdev_flags |= VIR_STRICT_ACS_CHECK;
     if (!migrateFrom)
         hostdev_flags |= VIR_COLD_BOOT;
-    if (qemuPrepareHostDevices(driver, vm->def, hostdev_flags) < 0)
+    hostdev_flags |= VIR_SP_PCI_HOSTDEV | VIR_SP_USB_HOSTDEV | VIR_SP_SCSI_HOSTDEV;
+    hostdev_mgr = virHostdevManagerGetDefault();
+    if (!hostdev_mgr ||
+        virHostdevPrepareDomainHostdevs(hostdev_mgr, QEMU_DRIVER_NAME,
+                                        vm->def, hostdev_flags) < 0)
         goto cleanup;
 
     VIR_DEBUG("Preparing chr devices");
@@ -4248,6 +4253,8 @@ void qemuProcessStop(virQEMUDriverPtr driver,
     char *timestamp;
     char ebuf[1024];
     virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
+    unsigned int hostdev_flags = 0;
+    virHostdevManagerPtr hostdev_mgr;
 
     VIR_DEBUG("Shutting down vm=%p name=%s id=%d pid=%llu flags=%x",
               vm, vm->def->name, vm->def->id,
@@ -4400,7 +4407,11 @@ void qemuProcessStop(virQEMUDriverPtr driver,
         ignore_value(qemuRemoveSharedDevice(driver, &dev, vm->def->name));
     }
 
-    qemuDomainReAttachHostDevices(driver, vm->def);
+    hostdev_mgr = virHostdevManagerGetDefault();
+    hostdev_flags |= VIR_SP_PCI_HOSTDEV | VIR_SP_USB_HOSTDEV | VIR_SP_SCSI_HOSTDEV;
+    if (hostdev_mgr != NULL)
+        virHostdevReAttachDomainHostdevs(hostdev_mgr, QEMU_DRIVER_NAME,
+                                         vm->def, hostdev_flags);
 
     def = vm->def;
     for (i = 0; i < def->nnets; i++) {
-- 
1.6.0.2

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