提交 e640e98f 编写于 作者: C Chunyan Liu 提交者: Daniel P. Berrange

qemu: use general virhostdev lists instead of its own

上级 b5d5eb9b
...@@ -44,6 +44,7 @@ ...@@ -44,6 +44,7 @@
# include "locking/lock_manager.h" # include "locking/lock_manager.h"
# include "qemu_capabilities.h" # include "qemu_capabilities.h"
# include "virclosecallbacks.h" # include "virclosecallbacks.h"
# include "virhostdev.h"
# ifdef CPU_SETSIZE /* Linux */ # ifdef CPU_SETSIZE /* Linux */
# define QEMUD_CPUMASK_LEN CPU_SETSIZE # define QEMUD_CPUMASK_LEN CPU_SETSIZE
...@@ -215,13 +216,7 @@ struct _virQEMUDriver { ...@@ -215,13 +216,7 @@ struct _virQEMUDriver {
/* Immutable pointer. self-locking APIs */ /* Immutable pointer. self-locking APIs */
virSecurityManagerPtr securityManager; virSecurityManagerPtr securityManager;
/* Immutable pointers. Requires locks to be held before virHostdevManagerPtr hostdevMgr;
* calling APIs. activePciHostdevs must be locked before
* inactivePciHostdevs */
virPCIDeviceListPtr activePciHostdevs;
virPCIDeviceListPtr inactivePciHostdevs;
virUSBDeviceListPtr activeUsbHostdevs;
virSCSIDeviceListPtr activeScsiHostdevs;
/* Immutable pointer. Unsafe APIs. XXX */ /* Immutable pointer. Unsafe APIs. XXX */
virHashTablePtr sharedDevices; virHashTablePtr sharedDevices;
......
...@@ -94,6 +94,7 @@ ...@@ -94,6 +94,7 @@
#include "viraccessapicheck.h" #include "viraccessapicheck.h"
#include "viraccessapicheckqemu.h" #include "viraccessapicheckqemu.h"
#include "storage/storage_driver.h" #include "storage/storage_driver.h"
#include "virhostdev.h"
#define VIR_FROM_THIS VIR_FROM_QEMU #define VIR_FROM_THIS VIR_FROM_QEMU
...@@ -690,16 +691,7 @@ qemuStateInitialize(bool privileged, ...@@ -690,16 +691,7 @@ qemuStateInitialize(bool privileged,
if (qemuSecurityInit(qemu_driver) < 0) if (qemuSecurityInit(qemu_driver) < 0)
goto error; goto error;
if ((qemu_driver->activePciHostdevs = virPCIDeviceListNew()) == NULL) if (!(qemu_driver->hostdevMgr = virHostdevManagerGetDefault()))
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; goto error;
if (!(qemu_driver->sharedDevices = virHashCreate(30, qemuSharedDeviceEntryFree))) if (!(qemu_driver->sharedDevices = virHashCreate(30, qemuSharedDeviceEntryFree)))
...@@ -979,10 +971,7 @@ qemuStateCleanup(void) { ...@@ -979,10 +971,7 @@ qemuStateCleanup(void) {
virNWFilterUnRegisterCallbackDriver(&qemuCallbackDriver); virNWFilterUnRegisterCallbackDriver(&qemuCallbackDriver);
virObjectUnref(qemu_driver->config); virObjectUnref(qemu_driver->config);
virObjectUnref(qemu_driver->activePciHostdevs); virObjectUnref(qemu_driver->hostdevMgr);
virObjectUnref(qemu_driver->inactivePciHostdevs);
virObjectUnref(qemu_driver->activeUsbHostdevs);
virObjectUnref(qemu_driver->activeScsiHostdevs);
virHashFree(qemu_driver->sharedDevices); virHashFree(qemu_driver->sharedDevices);
virObjectUnref(qemu_driver->caps); virObjectUnref(qemu_driver->caps);
virQEMUCapsCacheFree(qemu_driver->qemuCapsCache); virQEMUCapsCacheFree(qemu_driver->qemuCapsCache);
...@@ -11288,6 +11277,7 @@ qemuNodeDeviceDetachFlags(virNodeDevicePtr dev, ...@@ -11288,6 +11277,7 @@ qemuNodeDeviceDetachFlags(virNodeDevicePtr dev,
char *xml = NULL; char *xml = NULL;
bool legacy = qemuHostdevHostSupportsPassthroughLegacy(); bool legacy = qemuHostdevHostSupportsPassthroughLegacy();
bool vfio = qemuHostdevHostSupportsPassthroughVFIO(); bool vfio = qemuHostdevHostSupportsPassthroughVFIO();
virHostdevManagerPtr hostdev_mgr = driver->hostdevMgr;
virCheckFlags(0, -1); virCheckFlags(0, -1);
...@@ -11346,18 +11336,18 @@ qemuNodeDeviceDetachFlags(virNodeDevicePtr dev, ...@@ -11346,18 +11336,18 @@ qemuNodeDeviceDetachFlags(virNodeDevicePtr dev,
goto cleanup; goto cleanup;
} }
virObjectLock(driver->activePciHostdevs); virObjectLock(hostdev_mgr->activePciHostdevs);
virObjectLock(driver->inactivePciHostdevs); virObjectLock(hostdev_mgr->inactivePciHostdevs);
if (virPCIDeviceDetach(pci, driver->activePciHostdevs, if (virPCIDeviceDetach(pci, hostdev_mgr->activePciHostdevs,
driver->inactivePciHostdevs) < 0) { hostdev_mgr->inactivePciHostdevs) < 0) {
goto out; goto out;
} }
ret = 0; ret = 0;
out: out:
virObjectUnlock(driver->inactivePciHostdevs); virObjectUnlock(hostdev_mgr->inactivePciHostdevs);
virObjectUnlock(driver->activePciHostdevs); virObjectUnlock(hostdev_mgr->activePciHostdevs);
cleanup: cleanup:
virPCIDeviceFree(pci); virPCIDeviceFree(pci);
virNodeDeviceDefFree(def); virNodeDeviceDefFree(def);
...@@ -11381,6 +11371,7 @@ qemuNodeDeviceReAttach(virNodeDevicePtr dev) ...@@ -11381,6 +11371,7 @@ qemuNodeDeviceReAttach(virNodeDevicePtr dev)
int ret = -1; int ret = -1;
virNodeDeviceDefPtr def = NULL; virNodeDeviceDefPtr def = NULL;
char *xml = NULL; char *xml = NULL;
virHostdevManagerPtr hostdev_mgr = driver->hostdevMgr;
xml = virNodeDeviceGetXMLDesc(dev, 0); xml = virNodeDeviceGetXMLDesc(dev, 0);
if (!xml) if (!xml)
...@@ -11400,9 +11391,9 @@ qemuNodeDeviceReAttach(virNodeDevicePtr dev) ...@@ -11400,9 +11391,9 @@ qemuNodeDeviceReAttach(virNodeDevicePtr dev)
if (!pci) if (!pci)
goto cleanup; goto cleanup;
virObjectLock(driver->activePciHostdevs); virObjectLock(hostdev_mgr->activePciHostdevs);
virObjectLock(driver->inactivePciHostdevs); virObjectLock(hostdev_mgr->inactivePciHostdevs);
other = virPCIDeviceListFind(driver->activePciHostdevs, pci); other = virPCIDeviceListFind(hostdev_mgr->activePciHostdevs, pci);
if (other) { if (other) {
const char *other_drvname = NULL; const char *other_drvname = NULL;
const char *other_domname = NULL; const char *other_domname = NULL;
...@@ -11423,14 +11414,14 @@ qemuNodeDeviceReAttach(virNodeDevicePtr dev) ...@@ -11423,14 +11414,14 @@ qemuNodeDeviceReAttach(virNodeDevicePtr dev)
virPCIDeviceReattachInit(pci); virPCIDeviceReattachInit(pci);
if (virPCIDeviceReattach(pci, driver->activePciHostdevs, if (virPCIDeviceReattach(pci, hostdev_mgr->activePciHostdevs,
driver->inactivePciHostdevs) < 0) hostdev_mgr->inactivePciHostdevs) < 0)
goto out; goto out;
ret = 0; ret = 0;
out: out:
virObjectUnlock(driver->inactivePciHostdevs); virObjectUnlock(hostdev_mgr->inactivePciHostdevs);
virObjectUnlock(driver->activePciHostdevs); virObjectUnlock(hostdev_mgr->activePciHostdevs);
virPCIDeviceFree(pci); virPCIDeviceFree(pci);
cleanup: cleanup:
virNodeDeviceDefFree(def); virNodeDeviceDefFree(def);
...@@ -11447,6 +11438,7 @@ qemuNodeDeviceReset(virNodeDevicePtr dev) ...@@ -11447,6 +11438,7 @@ qemuNodeDeviceReset(virNodeDevicePtr dev)
int ret = -1; int ret = -1;
virNodeDeviceDefPtr def = NULL; virNodeDeviceDefPtr def = NULL;
char *xml = NULL; char *xml = NULL;
virHostdevManagerPtr hostdev_mgr = driver->hostdevMgr;
xml = virNodeDeviceGetXMLDesc(dev, 0); xml = virNodeDeviceGetXMLDesc(dev, 0);
if (!xml) if (!xml)
...@@ -11466,17 +11458,16 @@ qemuNodeDeviceReset(virNodeDevicePtr dev) ...@@ -11466,17 +11458,16 @@ qemuNodeDeviceReset(virNodeDevicePtr dev)
if (!pci) if (!pci)
goto cleanup; goto cleanup;
virObjectLock(driver->activePciHostdevs); virObjectLock(hostdev_mgr->activePciHostdevs);
virObjectLock(driver->inactivePciHostdevs); virObjectLock(hostdev_mgr->inactivePciHostdevs);
if (virPCIDeviceReset(pci, hostdev_mgr->activePciHostdevs,
if (virPCIDeviceReset(pci, driver->activePciHostdevs, hostdev_mgr->inactivePciHostdevs) < 0)
driver->inactivePciHostdevs) < 0)
goto out; goto out;
ret = 0; ret = 0;
out: out:
virObjectUnlock(driver->inactivePciHostdevs); virObjectUnlock(hostdev_mgr->inactivePciHostdevs);
virObjectUnlock(driver->activePciHostdevs); virObjectUnlock(hostdev_mgr->activePciHostdevs);
virPCIDeviceFree(pci); virPCIDeviceFree(pci);
cleanup: cleanup:
virNodeDeviceDefFree(def); virNodeDeviceDefFree(def);
......
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册