Signed-off-by: Chunyan Liu <cyliu(a)suse.com>
---
src/lxc/lxc_conf.h | 4 ----
src/lxc/lxc_driver.c | 17 +++++++++--------
src/lxc/lxc_hostdev.c | 49 ++++++++++++++++++++++++++++++++-----------------
3 files changed, 41 insertions(+), 29 deletions(-)
diff --git a/src/lxc/lxc_conf.h b/src/lxc/lxc_conf.h
index e04dcdd..5be159b 100644
--- a/src/lxc/lxc_conf.h
+++ b/src/lxc/lxc_conf.h
@@ -93,10 +93,6 @@ struct _virLXCDriver {
/* Immutable pointer, self-locking APIs */
virDomainObjListPtr domains;
- /* Immutable pointer. Requires lock to be held before
- * calling APIs. */
- virUSBDeviceListPtr activeUsbHostdevs;
-
/* Immutable pointer, self-locking APIs */
virObjectEventStatePtr domainEventState;
diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c
index 10e0fbb..f67a236 100644
--- a/src/lxc/lxc_driver.c
+++ b/src/lxc/lxc_driver.c
@@ -71,6 +71,7 @@
#include "virstring.h"
#include "viraccessapicheck.h"
#include "viraccessapichecklxc.h"
+#include "virhostdev.h"
#define VIR_FROM_THIS VIR_FROM_LXC
@@ -1557,9 +1558,6 @@ static int lxcStateInitialize(bool privileged,
if (!(lxc_driver->securityManager = lxcSecurityInit(cfg)))
goto cleanup;
- if ((lxc_driver->activeUsbHostdevs = virUSBDeviceListNew()) == NULL)
- goto cleanup;
-
if ((virLXCDriverGetCapabilities(lxc_driver, true)) == NULL)
goto cleanup;
@@ -1674,7 +1672,6 @@ static int lxcStateCleanup(void)
virSysinfoDefFree(lxc_driver->hostsysinfo);
- virObjectUnref(lxc_driver->activeUsbHostdevs);
virObjectUnref(lxc_driver->caps);
virObjectUnref(lxc_driver->securityManager);
virObjectUnref(lxc_driver->xmlopt);
@@ -4688,7 +4685,7 @@ cleanup:
static int
-lxcDomainDetachDeviceHostdevUSBLive(virLXCDriverPtr driver,
+lxcDomainDetachDeviceHostdevUSBLive(virLXCDriverPtr driver ATTRIBUTE_UNUSED,
virDomainObjPtr vm,
virDomainDeviceDefPtr dev)
{
@@ -4697,6 +4694,7 @@ lxcDomainDetachDeviceHostdevUSBLive(virLXCDriverPtr driver,
int idx, ret = -1;
char *dst = NULL;
virUSBDevicePtr usb = NULL;
+ virHostdevManagerPtr hostdev_mgr;
if ((idx = virDomainHostdevFind(vm->def,
dev->data.hostdev,
@@ -4733,9 +4731,12 @@ lxcDomainDetachDeviceHostdevUSBLive(virLXCDriverPtr driver,
VIR_WARN("cannot deny device %s for domain %s",
dst, vm->def->name);
- virObjectLock(driver->activeUsbHostdevs);
- virUSBDeviceListDel(driver->activeUsbHostdevs, usb);
- virObjectUnlock(driver->activeUsbHostdevs);
+ hostdev_mgr = virHostdevManagerGetDefault();
+ if (hostdev_mgr == NULL)
+ goto cleanup;
+ virObjectLock(hostdev_mgr->activeUsbHostdevs);
+ virUSBDeviceListDel(hostdev_mgr->activeUsbHostdevs, usb);
+ virObjectUnlock(hostdev_mgr->activeUsbHostdevs);
virDomainHostdevRemove(vm->def, idx);
virDomainHostdevDefFree(def);
diff --git a/src/lxc/lxc_hostdev.c b/src/lxc/lxc_hostdev.c
index b7248df..8398646 100644
--- a/src/lxc/lxc_hostdev.c
+++ b/src/lxc/lxc_hostdev.c
@@ -27,19 +27,25 @@
#include "viralloc.h"
#include "virlog.h"
#include "virerror.h"
+#include "virhostdev.h"
#define VIR_FROM_THIS VIR_FROM_LXC
int
-virLXCUpdateActiveUsbHostdevs(virLXCDriverPtr driver,
+virLXCUpdateActiveUsbHostdevs(virLXCDriverPtr driver ATTRIBUTE_UNUSED,
virDomainDefPtr def)
{
virDomainHostdevDefPtr hostdev = NULL;
size_t i;
+ virHostdevManagerPtr hostdev_mgr;
if (!def->nhostdevs)
return 0;
+ hostdev_mgr = virHostdevManagerGetDefault();
+ if (hostdev_mgr == NULL)
+ return -1;
+
for (i = 0; i < def->nhostdevs; i++) {
virUSBDevicePtr usb = NULL;
hostdev = def->hostdevs[i];
@@ -62,13 +68,13 @@ virLXCUpdateActiveUsbHostdevs(virLXCDriverPtr driver,
virUSBDeviceSetUsedBy(usb, LXC_DRIVER_NAME, def->name);
- virObjectLock(driver->activeUsbHostdevs);
- if (virUSBDeviceListAdd(driver->activeUsbHostdevs, usb) < 0) {
- virObjectUnlock(driver->activeUsbHostdevs);
+ virObjectLock(hostdev_mgr->activeUsbHostdevs);
+ if (virUSBDeviceListAdd(hostdev_mgr->activeUsbHostdevs, usb) < 0) {
+ virObjectUnlock(hostdev_mgr->activeUsbHostdevs);
virUSBDeviceFree(usb);
return -1;
}
- virObjectUnlock(driver->activeUsbHostdevs);
+ virObjectUnlock(hostdev_mgr->activeUsbHostdevs);
}
return 0;
@@ -76,20 +82,24 @@ virLXCUpdateActiveUsbHostdevs(virLXCDriverPtr driver,
int
-virLXCPrepareHostdevUSBDevices(virLXCDriverPtr driver,
+virLXCPrepareHostdevUSBDevices(virLXCDriverPtr driver ATTRIBUTE_UNUSED,
const char *name,
virUSBDeviceList *list)
{
size_t i, j;
unsigned int count;
virUSBDevicePtr tmp;
+ virHostdevManagerPtr hostdev_mgr;
count = virUSBDeviceListCount(list);
- virObjectLock(driver->activeUsbHostdevs);
+ hostdev_mgr = virHostdevManagerGetDefault();
+ if (hostdev_mgr == NULL)
+ return -1;
+ virObjectLock(hostdev_mgr->activeUsbHostdevs);
for (i = 0; i < count; i++) {
virUSBDevicePtr usb = virUSBDeviceListGet(list, i);
- if ((tmp = virUSBDeviceListFind(driver->activeUsbHostdevs, usb))) {
+ if ((tmp = virUSBDeviceListFind(hostdev_mgr->activeUsbHostdevs, usb))) {
const char *other_drvname;
const char *other_domname;
@@ -115,18 +125,18 @@ virLXCPrepareHostdevUSBDevices(virLXCDriverPtr driver,
* from the virUSBDeviceList that passed in on success,
* perform rollback on failure.
*/
- if (virUSBDeviceListAdd(driver->activeUsbHostdevs, usb) < 0)
+ if (virUSBDeviceListAdd(hostdev_mgr->activeUsbHostdevs, usb) < 0)
goto error;
}
- virObjectUnlock(driver->activeUsbHostdevs);
+ virObjectUnlock(hostdev_mgr->activeUsbHostdevs);
return 0;
error:
for (j = 0; j < i; j++) {
tmp = virUSBDeviceListGet(list, i);
- virUSBDeviceListSteal(driver->activeUsbHostdevs, tmp);
+ virUSBDeviceListSteal(hostdev_mgr->activeUsbHostdevs, tmp);
}
- virObjectUnlock(driver->activeUsbHostdevs);
+ virObjectUnlock(hostdev_mgr->activeUsbHostdevs);
return -1;
}
@@ -344,14 +354,19 @@ int virLXCPrepareHostDevices(virLXCDriverPtr driver,
static void
-virLXCDomainReAttachHostUsbDevices(virLXCDriverPtr driver,
+virLXCDomainReAttachHostUsbDevices(virLXCDriverPtr driver ATTRIBUTE_UNUSED,
const char *name,
virDomainHostdevDefPtr *hostdevs,
int nhostdevs)
{
size_t i;
+ virHostdevManagerPtr hostdev_mgr;
+
+ hostdev_mgr = virHostdevManagerGetDefault();
+ if (hostdev_mgr == NULL)
+ return;
- virObjectLock(driver->activeUsbHostdevs);
+ virObjectLock(hostdev_mgr->activeUsbHostdevs);
for (i = 0; i < nhostdevs; i++) {
virDomainHostdevDefPtr hostdev = hostdevs[i];
virUSBDevicePtr usb, tmp;
@@ -383,7 +398,7 @@ virLXCDomainReAttachHostUsbDevices(virLXCDriverPtr driver,
* Therefore we want to steal only those devices from
* the list which were taken by @name */
- tmp = virUSBDeviceListFind(driver->activeUsbHostdevs, usb);
+ tmp = virUSBDeviceListFind(hostdev_mgr->activeUsbHostdevs, usb);
virUSBDeviceFree(usb);
if (!tmp) {
@@ -402,10 +417,10 @@ virLXCDomainReAttachHostUsbDevices(virLXCDriverPtr driver,
hostdev->source.subsys.u.usb.device,
name);
- virUSBDeviceListDel(driver->activeUsbHostdevs, tmp);
+ virUSBDeviceListDel(hostdev_mgr->activeUsbHostdevs, tmp);
}
}
- virObjectUnlock(driver->activeUsbHostdevs);
+ virObjectUnlock(hostdev_mgr->activeUsbHostdevs);
}
void virLXCDomainReAttachHostDevices(virLXCDriverPtr driver,
--
1.6.0.2