Signed-off-by: Chunyan Liu <cyliu(a)suse.com>
---
src/lxc/lxc_conf.h | 5 ++---
src/lxc/lxc_driver.c | 12 +++++++-----
src/lxc/lxc_hostdev.c | 32 ++++++++++++++++++--------------
3 files changed, 27 insertions(+), 22 deletions(-)
diff --git a/src/lxc/lxc_conf.h b/src/lxc/lxc_conf.h
index e04dcdd..8340b1f 100644
--- a/src/lxc/lxc_conf.h
+++ b/src/lxc/lxc_conf.h
@@ -37,6 +37,7 @@
# include "virsysinfo.h"
# include "virusb.h"
# include "virclosecallbacks.h"
+# include "virhostdev.h"
# define LXC_DRIVER_NAME "LXC"
@@ -93,9 +94,7 @@ struct _virLXCDriver {
/* Immutable pointer, self-locking APIs */
virDomainObjListPtr domains;
- /* Immutable pointer. Requires lock to be held before
- * calling APIs. */
- virUSBDeviceListPtr activeUsbHostdevs;
+ virHostdevManagerPtr hostdevMgr;
/* Immutable pointer, self-locking APIs */
virObjectEventStatePtr domainEventState;
diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c
index 10e0fbb..e1d9ad4 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,7 +1558,7 @@ static int lxcStateInitialize(bool privileged,
if (!(lxc_driver->securityManager = lxcSecurityInit(cfg)))
goto cleanup;
- if ((lxc_driver->activeUsbHostdevs = virUSBDeviceListNew()) == NULL)
+ if (!(lxc_driver->hostdevMgr = virHostdevManagerGetDefault()))
goto cleanup;
if ((virLXCDriverGetCapabilities(lxc_driver, true)) == NULL)
@@ -1674,7 +1675,7 @@ static int lxcStateCleanup(void)
virSysinfoDefFree(lxc_driver->hostsysinfo);
- virObjectUnref(lxc_driver->activeUsbHostdevs);
+ virObjectUnref(lxc_driver->hostdevMgr);
virObjectUnref(lxc_driver->caps);
virObjectUnref(lxc_driver->securityManager);
virObjectUnref(lxc_driver->xmlopt);
@@ -4697,6 +4698,7 @@ lxcDomainDetachDeviceHostdevUSBLive(virLXCDriverPtr driver,
int idx, ret = -1;
char *dst = NULL;
virUSBDevicePtr usb = NULL;
+ virHostdevManagerPtr hostdev_mgr = driver->hostdevMgr;
if ((idx = virDomainHostdevFind(vm->def,
dev->data.hostdev,
@@ -4733,9 +4735,9 @@ 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);
+ 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..635f2e5 100644
--- a/src/lxc/lxc_hostdev.c
+++ b/src/lxc/lxc_hostdev.c
@@ -27,6 +27,7 @@
#include "viralloc.h"
#include "virlog.h"
#include "virerror.h"
+#include "virhostdev.h"
#define VIR_FROM_THIS VIR_FROM_LXC
@@ -36,6 +37,7 @@ virLXCUpdateActiveUsbHostdevs(virLXCDriverPtr driver,
{
virDomainHostdevDefPtr hostdev = NULL;
size_t i;
+ virHostdevManagerPtr hostdev_mgr = driver->hostdevMgr;
if (!def->nhostdevs)
return 0;
@@ -62,13 +64,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;
@@ -83,13 +85,14 @@ virLXCPrepareHostdevUSBDevices(virLXCDriverPtr driver,
size_t i, j;
unsigned int count;
virUSBDevicePtr tmp;
+ virHostdevManagerPtr hostdev_mgr = driver->hostdevMgr;
count = virUSBDeviceListCount(list);
- virObjectLock(driver->activeUsbHostdevs);
+ 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 +118,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;
}
@@ -350,8 +353,9 @@ virLXCDomainReAttachHostUsbDevices(virLXCDriverPtr driver,
int nhostdevs)
{
size_t i;
+ virHostdevManagerPtr hostdev_mgr = driver->hostdevMgr;
- virObjectLock(driver->activeUsbHostdevs);
+ virObjectLock(hostdev_mgr->activeUsbHostdevs);
for (i = 0; i < nhostdevs; i++) {
virDomainHostdevDefPtr hostdev = hostdevs[i];
virUSBDevicePtr usb, tmp;
@@ -383,7 +387,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 +406,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.9.0