mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-10-30 01:43:23 +00:00
lxc: use general virhostdev lists instead of its own
This commit is contained in:
parent
e640e98fa4
commit
0d4efed02b
@ -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;
|
||||
|
@ -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);
|
||||
|
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user