mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-02-04 02:45:22 +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 "virsysinfo.h"
|
||||||
# include "virusb.h"
|
# include "virusb.h"
|
||||||
# include "virclosecallbacks.h"
|
# include "virclosecallbacks.h"
|
||||||
|
# include "virhostdev.h"
|
||||||
|
|
||||||
# define LXC_DRIVER_NAME "LXC"
|
# define LXC_DRIVER_NAME "LXC"
|
||||||
|
|
||||||
@ -93,9 +94,7 @@ struct _virLXCDriver {
|
|||||||
/* Immutable pointer, self-locking APIs */
|
/* Immutable pointer, self-locking APIs */
|
||||||
virDomainObjListPtr domains;
|
virDomainObjListPtr domains;
|
||||||
|
|
||||||
/* Immutable pointer. Requires lock to be held before
|
virHostdevManagerPtr hostdevMgr;
|
||||||
* calling APIs. */
|
|
||||||
virUSBDeviceListPtr activeUsbHostdevs;
|
|
||||||
|
|
||||||
/* Immutable pointer, self-locking APIs */
|
/* Immutable pointer, self-locking APIs */
|
||||||
virObjectEventStatePtr domainEventState;
|
virObjectEventStatePtr domainEventState;
|
||||||
|
@ -71,6 +71,7 @@
|
|||||||
#include "virstring.h"
|
#include "virstring.h"
|
||||||
#include "viraccessapicheck.h"
|
#include "viraccessapicheck.h"
|
||||||
#include "viraccessapichecklxc.h"
|
#include "viraccessapichecklxc.h"
|
||||||
|
#include "virhostdev.h"
|
||||||
|
|
||||||
#define VIR_FROM_THIS VIR_FROM_LXC
|
#define VIR_FROM_THIS VIR_FROM_LXC
|
||||||
|
|
||||||
@ -1557,7 +1558,7 @@ static int lxcStateInitialize(bool privileged,
|
|||||||
if (!(lxc_driver->securityManager = lxcSecurityInit(cfg)))
|
if (!(lxc_driver->securityManager = lxcSecurityInit(cfg)))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if ((lxc_driver->activeUsbHostdevs = virUSBDeviceListNew()) == NULL)
|
if (!(lxc_driver->hostdevMgr = virHostdevManagerGetDefault()))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if ((virLXCDriverGetCapabilities(lxc_driver, true)) == NULL)
|
if ((virLXCDriverGetCapabilities(lxc_driver, true)) == NULL)
|
||||||
@ -1674,7 +1675,7 @@ static int lxcStateCleanup(void)
|
|||||||
|
|
||||||
virSysinfoDefFree(lxc_driver->hostsysinfo);
|
virSysinfoDefFree(lxc_driver->hostsysinfo);
|
||||||
|
|
||||||
virObjectUnref(lxc_driver->activeUsbHostdevs);
|
virObjectUnref(lxc_driver->hostdevMgr);
|
||||||
virObjectUnref(lxc_driver->caps);
|
virObjectUnref(lxc_driver->caps);
|
||||||
virObjectUnref(lxc_driver->securityManager);
|
virObjectUnref(lxc_driver->securityManager);
|
||||||
virObjectUnref(lxc_driver->xmlopt);
|
virObjectUnref(lxc_driver->xmlopt);
|
||||||
@ -4697,6 +4698,7 @@ lxcDomainDetachDeviceHostdevUSBLive(virLXCDriverPtr driver,
|
|||||||
int idx, ret = -1;
|
int idx, ret = -1;
|
||||||
char *dst = NULL;
|
char *dst = NULL;
|
||||||
virUSBDevicePtr usb = NULL;
|
virUSBDevicePtr usb = NULL;
|
||||||
|
virHostdevManagerPtr hostdev_mgr = driver->hostdevMgr;
|
||||||
|
|
||||||
if ((idx = virDomainHostdevFind(vm->def,
|
if ((idx = virDomainHostdevFind(vm->def,
|
||||||
dev->data.hostdev,
|
dev->data.hostdev,
|
||||||
@ -4733,9 +4735,9 @@ lxcDomainDetachDeviceHostdevUSBLive(virLXCDriverPtr driver,
|
|||||||
VIR_WARN("cannot deny device %s for domain %s",
|
VIR_WARN("cannot deny device %s for domain %s",
|
||||||
dst, vm->def->name);
|
dst, vm->def->name);
|
||||||
|
|
||||||
virObjectLock(driver->activeUsbHostdevs);
|
virObjectLock(hostdev_mgr->activeUsbHostdevs);
|
||||||
virUSBDeviceListDel(driver->activeUsbHostdevs, usb);
|
virUSBDeviceListDel(hostdev_mgr->activeUsbHostdevs, usb);
|
||||||
virObjectUnlock(driver->activeUsbHostdevs);
|
virObjectUnlock(hostdev_mgr->activeUsbHostdevs);
|
||||||
|
|
||||||
virDomainHostdevRemove(vm->def, idx);
|
virDomainHostdevRemove(vm->def, idx);
|
||||||
virDomainHostdevDefFree(def);
|
virDomainHostdevDefFree(def);
|
||||||
|
@ -27,6 +27,7 @@
|
|||||||
#include "viralloc.h"
|
#include "viralloc.h"
|
||||||
#include "virlog.h"
|
#include "virlog.h"
|
||||||
#include "virerror.h"
|
#include "virerror.h"
|
||||||
|
#include "virhostdev.h"
|
||||||
|
|
||||||
#define VIR_FROM_THIS VIR_FROM_LXC
|
#define VIR_FROM_THIS VIR_FROM_LXC
|
||||||
|
|
||||||
@ -36,6 +37,7 @@ virLXCUpdateActiveUsbHostdevs(virLXCDriverPtr driver,
|
|||||||
{
|
{
|
||||||
virDomainHostdevDefPtr hostdev = NULL;
|
virDomainHostdevDefPtr hostdev = NULL;
|
||||||
size_t i;
|
size_t i;
|
||||||
|
virHostdevManagerPtr hostdev_mgr = driver->hostdevMgr;
|
||||||
|
|
||||||
if (!def->nhostdevs)
|
if (!def->nhostdevs)
|
||||||
return 0;
|
return 0;
|
||||||
@ -62,13 +64,13 @@ virLXCUpdateActiveUsbHostdevs(virLXCDriverPtr driver,
|
|||||||
|
|
||||||
virUSBDeviceSetUsedBy(usb, LXC_DRIVER_NAME, def->name);
|
virUSBDeviceSetUsedBy(usb, LXC_DRIVER_NAME, def->name);
|
||||||
|
|
||||||
virObjectLock(driver->activeUsbHostdevs);
|
virObjectLock(hostdev_mgr->activeUsbHostdevs);
|
||||||
if (virUSBDeviceListAdd(driver->activeUsbHostdevs, usb) < 0) {
|
if (virUSBDeviceListAdd(hostdev_mgr->activeUsbHostdevs, usb) < 0) {
|
||||||
virObjectUnlock(driver->activeUsbHostdevs);
|
virObjectUnlock(hostdev_mgr->activeUsbHostdevs);
|
||||||
virUSBDeviceFree(usb);
|
virUSBDeviceFree(usb);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
virObjectUnlock(driver->activeUsbHostdevs);
|
virObjectUnlock(hostdev_mgr->activeUsbHostdevs);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@ -83,13 +85,14 @@ virLXCPrepareHostdevUSBDevices(virLXCDriverPtr driver,
|
|||||||
size_t i, j;
|
size_t i, j;
|
||||||
unsigned int count;
|
unsigned int count;
|
||||||
virUSBDevicePtr tmp;
|
virUSBDevicePtr tmp;
|
||||||
|
virHostdevManagerPtr hostdev_mgr = driver->hostdevMgr;
|
||||||
|
|
||||||
count = virUSBDeviceListCount(list);
|
count = virUSBDeviceListCount(list);
|
||||||
|
|
||||||
virObjectLock(driver->activeUsbHostdevs);
|
virObjectLock(hostdev_mgr->activeUsbHostdevs);
|
||||||
for (i = 0; i < count; i++) {
|
for (i = 0; i < count; i++) {
|
||||||
virUSBDevicePtr usb = virUSBDeviceListGet(list, 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_drvname;
|
||||||
const char *other_domname;
|
const char *other_domname;
|
||||||
|
|
||||||
@ -115,18 +118,18 @@ virLXCPrepareHostdevUSBDevices(virLXCDriverPtr driver,
|
|||||||
* from the virUSBDeviceList that passed in on success,
|
* from the virUSBDeviceList that passed in on success,
|
||||||
* perform rollback on failure.
|
* perform rollback on failure.
|
||||||
*/
|
*/
|
||||||
if (virUSBDeviceListAdd(driver->activeUsbHostdevs, usb) < 0)
|
if (virUSBDeviceListAdd(hostdev_mgr->activeUsbHostdevs, usb) < 0)
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
virObjectUnlock(driver->activeUsbHostdevs);
|
virObjectUnlock(hostdev_mgr->activeUsbHostdevs);
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
error:
|
error:
|
||||||
for (j = 0; j < i; j++) {
|
for (j = 0; j < i; j++) {
|
||||||
tmp = virUSBDeviceListGet(list, i);
|
tmp = virUSBDeviceListGet(list, i);
|
||||||
virUSBDeviceListSteal(driver->activeUsbHostdevs, tmp);
|
virUSBDeviceListSteal(hostdev_mgr->activeUsbHostdevs, tmp);
|
||||||
}
|
}
|
||||||
virObjectUnlock(driver->activeUsbHostdevs);
|
virObjectUnlock(hostdev_mgr->activeUsbHostdevs);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -350,8 +353,9 @@ virLXCDomainReAttachHostUsbDevices(virLXCDriverPtr driver,
|
|||||||
int nhostdevs)
|
int nhostdevs)
|
||||||
{
|
{
|
||||||
size_t i;
|
size_t i;
|
||||||
|
virHostdevManagerPtr hostdev_mgr = driver->hostdevMgr;
|
||||||
|
|
||||||
virObjectLock(driver->activeUsbHostdevs);
|
virObjectLock(hostdev_mgr->activeUsbHostdevs);
|
||||||
for (i = 0; i < nhostdevs; i++) {
|
for (i = 0; i < nhostdevs; i++) {
|
||||||
virDomainHostdevDefPtr hostdev = hostdevs[i];
|
virDomainHostdevDefPtr hostdev = hostdevs[i];
|
||||||
virUSBDevicePtr usb, tmp;
|
virUSBDevicePtr usb, tmp;
|
||||||
@ -383,7 +387,7 @@ virLXCDomainReAttachHostUsbDevices(virLXCDriverPtr driver,
|
|||||||
* Therefore we want to steal only those devices from
|
* Therefore we want to steal only those devices from
|
||||||
* the list which were taken by @name */
|
* the list which were taken by @name */
|
||||||
|
|
||||||
tmp = virUSBDeviceListFind(driver->activeUsbHostdevs, usb);
|
tmp = virUSBDeviceListFind(hostdev_mgr->activeUsbHostdevs, usb);
|
||||||
virUSBDeviceFree(usb);
|
virUSBDeviceFree(usb);
|
||||||
|
|
||||||
if (!tmp) {
|
if (!tmp) {
|
||||||
@ -402,10 +406,10 @@ virLXCDomainReAttachHostUsbDevices(virLXCDriverPtr driver,
|
|||||||
hostdev->source.subsys.u.usb.device,
|
hostdev->source.subsys.u.usb.device,
|
||||||
name);
|
name);
|
||||||
|
|
||||||
virUSBDeviceListDel(driver->activeUsbHostdevs, tmp);
|
virUSBDeviceListDel(hostdev_mgr->activeUsbHostdevs, tmp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
virObjectUnlock(driver->activeUsbHostdevs);
|
virObjectUnlock(hostdev_mgr->activeUsbHostdevs);
|
||||||
}
|
}
|
||||||
|
|
||||||
void virLXCDomainReAttachHostDevices(virLXCDriverPtr driver,
|
void virLXCDomainReAttachHostDevices(virLXCDriverPtr driver,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user