From: Chunyan Liu <cyliu(a)suse.com>
Change lxc driver to use hostdev common library instead of its own APIs in
lxc_hostdev.[ch]
Signed-off-by: Chunyan Liu <cyliu(a)suse.com>
---
po/POTFILES.in | 1 -
src/Makefile.am | 1 -
src/lxc/lxc_conf.h | 4 -
src/lxc/lxc_driver.c | 45 +++---
src/lxc/lxc_hostdev.c | 413 -------------------------------------------------
src/lxc/lxc_hostdev.h | 43 -----
src/lxc/lxc_process.c | 21 ++-
7 files changed, 43 insertions(+), 485 deletions(-)
delete mode 100644 src/lxc/lxc_hostdev.c
delete mode 100644 src/lxc/lxc_hostdev.h
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 1124311..7186457 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -61,7 +61,6 @@ src/locking/lock_manager.c
src/locking/sanlock_helper.c
src/lxc/lxc_cgroup.c
src/lxc/lxc_fuse.c
-src/lxc/lxc_hostdev.c
src/lxc/lxc_container.c
src/lxc/lxc_conf.c
src/lxc/lxc_controller.c
diff --git a/src/Makefile.am b/src/Makefile.am
index 20fa84e..2509db3 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -578,7 +578,6 @@ LXC_DRIVER_SOURCES = \
lxc/lxc_container.c lxc/lxc_container.h \
lxc/lxc_cgroup.c lxc/lxc_cgroup.h \
lxc/lxc_domain.c lxc/lxc_domain.h \
- lxc/lxc_hostdev.c lxc/lxc_hostdev.h \
lxc/lxc_monitor.c lxc/lxc_monitor.h \
lxc/lxc_process.c lxc/lxc_process.h \
lxc/lxc_fuse.c lxc/lxc_fuse.h \
diff --git a/src/lxc/lxc_conf.h b/src/lxc/lxc_conf.h
index a6208a2..05f2a80 100644
--- a/src/lxc/lxc_conf.h
+++ b/src/lxc/lxc_conf.h
@@ -92,10 +92,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 */
virDomainEventStatePtr domainEventState;
diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c
index 9cb95ff..4f37619 100644
--- a/src/lxc/lxc_driver.c
+++ b/src/lxc/lxc_driver.c
@@ -70,6 +70,7 @@
#include "virstring.h"
#include "viraccessapicheck.h"
#include "viraccessapichecklxc.h"
+#include "virhostdev.h"
#define VIR_FROM_THIS VIR_FROM_LXC
@@ -1418,9 +1419,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;
@@ -1535,7 +1533,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);
@@ -3214,6 +3211,7 @@ lxcDomainAttachDeviceHostdevSubsysUSBLive(virLXCDriverPtr driver,
mode_t mode;
bool created = false;
virUSBDevicePtr usb = NULL;
+ virHostdevManagerPtr hostdev_mgr;
if (virDomainHostdevFind(vm->def, def, NULL) >= 0) {
virReportError(VIR_ERR_OPERATION_FAILED, "%s",
@@ -3221,6 +3219,13 @@ lxcDomainAttachDeviceHostdevSubsysUSBLive(virLXCDriverPtr driver,
return -1;
}
+ hostdev_mgr = virHostdevManagerGetDefault();
+ if (virHostdevPrepareUsbHostdevs(hostdev_mgr,
+ LXC_DRIVER_NAME,
+ vm->def->name,
+ &def, 1, 0) < 0)
+ goto cleanup;
+
if (virAsprintf(&vroot, "/proc/%llu/root",
(unsigned long long)priv->initpid) < 0)
goto cleanup;
@@ -3296,6 +3301,11 @@ lxcDomainAttachDeviceHostdevSubsysUSBLive(virLXCDriverPtr driver,
ret = 0;
cleanup:
+ virHostdevReAttachUsbHostdevs(hostdev_mgr,
+ LXC_DRIVER_NAME,
+ vm->def->name,
+ &def,
+ 1);
virDomainAuditHostdev(vm, def, "attach", ret == 0);
if (ret < 0 && created)
unlink(dstfile);
@@ -3758,8 +3768,7 @@ cleanup:
static int
-lxcDomainDetachDeviceHostdevUSBLive(virLXCDriverPtr driver,
- virDomainObjPtr vm,
+lxcDomainDetachDeviceHostdevUSBLive(virDomainObjPtr vm,
virDomainDeviceDefPtr dev)
{
virLXCDomainObjPrivatePtr priv = vm->privateData;
@@ -3768,6 +3777,7 @@ lxcDomainDetachDeviceHostdevUSBLive(virLXCDriverPtr driver,
char *dst = NULL;
char *vroot;
virUSBDevicePtr usb = NULL;
+ virHostdevManagerPtr hostdev_mgr;
if ((idx = virDomainHostdevFind(vm->def,
dev->data.hostdev,
@@ -3812,9 +3822,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);
+ hostdev_mgr = virHostdevManagerGetDefault();
+ virHostdevReAttachPciHostdevs(hostdev_mgr, LXC_DRIVER_NAME,
+ vm->def->name, &def, 1);
virDomainHostdevRemove(vm->def, idx);
virDomainHostdevDefFree(def);
@@ -3947,13 +3957,12 @@ cleanup:
static int
-lxcDomainDetachDeviceHostdevSubsysLive(virLXCDriverPtr driver,
- virDomainObjPtr vm,
+lxcDomainDetachDeviceHostdevSubsysLive(virDomainObjPtr vm,
virDomainDeviceDefPtr dev)
{
switch (dev->data.hostdev->source.subsys.type) {
case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB:
- return lxcDomainDetachDeviceHostdevUSBLive(driver, vm, dev);
+ return lxcDomainDetachDeviceHostdevUSBLive(vm, dev);
default:
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
@@ -3985,8 +3994,7 @@ lxcDomainDetachDeviceHostdevCapsLive(virDomainObjPtr vm,
static int
-lxcDomainDetachDeviceHostdevLive(virLXCDriverPtr driver,
- virDomainObjPtr vm,
+lxcDomainDetachDeviceHostdevLive(virDomainObjPtr vm,
virDomainDeviceDefPtr dev)
{
virLXCDomainObjPrivatePtr priv = vm->privateData;
@@ -3999,7 +4007,7 @@ lxcDomainDetachDeviceHostdevLive(virLXCDriverPtr driver,
switch (dev->data.hostdev->mode) {
case VIR_DOMAIN_HOSTDEV_MODE_SUBSYS:
- return lxcDomainDetachDeviceHostdevSubsysLive(driver, vm, dev);
+ return lxcDomainDetachDeviceHostdevSubsysLive(vm, dev);
case VIR_DOMAIN_HOSTDEV_MODE_CAPABILITIES:
return lxcDomainDetachDeviceHostdevCapsLive(vm, dev);
@@ -4014,8 +4022,7 @@ lxcDomainDetachDeviceHostdevLive(virLXCDriverPtr driver,
static int
-lxcDomainDetachDeviceLive(virLXCDriverPtr driver,
- virDomainObjPtr vm,
+lxcDomainDetachDeviceLive(virDomainObjPtr vm,
virDomainDeviceDefPtr dev)
{
int ret = -1;
@@ -4030,7 +4037,7 @@ lxcDomainDetachDeviceLive(virLXCDriverPtr driver,
break;
case VIR_DOMAIN_DEVICE_HOSTDEV:
- ret = lxcDomainDetachDeviceHostdevLive(driver, vm, dev);
+ ret = lxcDomainDetachDeviceHostdevLive(vm, dev);
break;
default:
@@ -4363,7 +4370,7 @@ static int lxcDomainDetachDeviceFlags(virDomainPtr dom,
if (virDomainDefCompatibleDevice(vm->def, dev_copy) < 0)
goto cleanup;
- if ((ret = lxcDomainDetachDeviceLive(driver, vm, dev_copy)) < 0)
+ if ((ret = lxcDomainDetachDeviceLive(vm, dev_copy)) < 0)
goto cleanup;
/*
* update domain status forcibly because the domain status may be
diff --git a/src/lxc/lxc_hostdev.c b/src/lxc/lxc_hostdev.c
deleted file mode 100644
index 3b371fc..0000000
--- a/src/lxc/lxc_hostdev.c
+++ /dev/null
@@ -1,413 +0,0 @@
-/*
- * virLXC_hostdev.c: VIRLXC hostdev management
- *
- * Copyright (C) 2006-2007, 2009-2012 Red Hat, Inc.
- * Copyright (C) 2006 Daniel P. Berrange
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library. If not, see
- * <
http://www.gnu.org/licenses/>.
- *
- * Author: Daniel P. Berrange <berrange(a)redhat.com>
- */
-
-#include <config.h>
-
-#include "lxc_hostdev.h"
-#include "viralloc.h"
-#include "virlog.h"
-#include "virerror.h"
-
-#define VIR_FROM_THIS VIR_FROM_LXC
-
-int
-virLXCUpdateActiveUsbHostdevs(virLXCDriverPtr driver,
- virDomainDefPtr def)
-{
- virDomainHostdevDefPtr hostdev = NULL;
- size_t i;
-
- if (!def->nhostdevs)
- return 0;
-
- for (i = 0; i < def->nhostdevs; i++) {
- virUSBDevicePtr usb = NULL;
- hostdev = def->hostdevs[i];
-
- if (hostdev->mode != VIR_DOMAIN_HOSTDEV_MODE_SUBSYS)
- continue;
- if (hostdev->source.subsys.type != VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB)
- continue;
-
- usb = virUSBDeviceNew(hostdev->source.subsys.u.usb.bus,
- hostdev->source.subsys.u.usb.device,
- NULL);
- if (!usb) {
- VIR_WARN("Unable to reattach USB device %03d.%03d on domain %s",
- hostdev->source.subsys.u.usb.bus,
- hostdev->source.subsys.u.usb.device,
- def->name);
- continue;
- }
-
- virUSBDeviceSetUsedBy(usb, def->name);
-
- virObjectLock(driver->activeUsbHostdevs);
- if (virUSBDeviceListAdd(driver->activeUsbHostdevs, usb) < 0) {
- virObjectUnlock(driver->activeUsbHostdevs);
- virUSBDeviceFree(usb);
- return -1;
- }
- virObjectUnlock(driver->activeUsbHostdevs);
- }
-
- return 0;
-}
-
-
-int
-virLXCPrepareHostdevUSBDevices(virLXCDriverPtr driver,
- const char *name,
- virUSBDeviceList *list)
-{
- size_t i, j;
- unsigned int count;
- virUSBDevicePtr tmp;
-
- count = virUSBDeviceListCount(list);
-
- virObjectLock(driver->activeUsbHostdevs);
- for (i = 0; i < count; i++) {
- virUSBDevicePtr usb = virUSBDeviceListGet(list, i);
- if ((tmp = virUSBDeviceListFind(driver->activeUsbHostdevs, usb))) {
- const char *other_name = virUSBDeviceGetUsedBy(tmp);
-
- if (other_name)
- virReportError(VIR_ERR_OPERATION_INVALID,
- _("USB device %s is in use by domain %s"),
- virUSBDeviceGetName(tmp), other_name);
- else
- virReportError(VIR_ERR_OPERATION_INVALID,
- _("USB device %s is already in use"),
- virUSBDeviceGetName(tmp));
- goto error;
- }
-
- virUSBDeviceSetUsedBy(usb, name);
- VIR_DEBUG("Adding %03d.%03d dom=%s to activeUsbHostdevs",
- virUSBDeviceGetBus(usb), virUSBDeviceGetDevno(usb), name);
- /*
- * The caller is responsible to steal these usb devices
- * from the virUSBDeviceList that passed in on success,
- * perform rollback on failure.
- */
- if (virUSBDeviceListAdd(driver->activeUsbHostdevs, usb) < 0)
- goto error;
- }
- virObjectUnlock(driver->activeUsbHostdevs);
- return 0;
-
-error:
- for (j = 0; j < i; j++) {
- tmp = virUSBDeviceListGet(list, i);
- virUSBDeviceListSteal(driver->activeUsbHostdevs, tmp);
- }
- virObjectUnlock(driver->activeUsbHostdevs);
- return -1;
-}
-
-int
-virLXCFindHostdevUSBDevice(virDomainHostdevDefPtr hostdev,
- bool mandatory,
- virUSBDevicePtr *usb)
-{
- unsigned vendor = hostdev->source.subsys.u.usb.vendor;
- unsigned product = hostdev->source.subsys.u.usb.product;
- unsigned bus = hostdev->source.subsys.u.usb.bus;
- unsigned device = hostdev->source.subsys.u.usb.device;
- bool autoAddress = hostdev->source.subsys.u.usb.autoAddress;
- int rc;
-
- *usb = NULL;
-
- if (vendor && bus) {
- rc = virUSBDeviceFind(vendor, product, bus, device,
- NULL,
- autoAddress ? false : mandatory,
- usb);
- if (rc < 0) {
- return -1;
- } else if (!autoAddress) {
- goto out;
- } else {
- VIR_INFO("USB device %x:%x could not be found at previous"
- " address (bus:%u device:%u)",
- vendor, product, bus, device);
- }
- }
-
- /* When vendor is specified, its USB address is either unspecified or the
- * device could not be found at the USB device where it had been
- * automatically found before.
- */
- if (vendor) {
- virUSBDeviceList *devs;
-
- rc = virUSBDeviceFindByVendor(vendor, product,
- NULL,
- mandatory, &devs);
- if (rc < 0)
- return -1;
-
- if (rc == 1) {
- *usb = virUSBDeviceListGet(devs, 0);
- virUSBDeviceListSteal(devs, *usb);
- }
- virObjectUnref(devs);
-
- if (rc == 0) {
- goto out;
- } else if (rc > 1) {
- if (autoAddress) {
- virReportError(VIR_ERR_OPERATION_FAILED,
- _("Multiple USB devices for %x:%x were found,"
- " but none of them is at bus:%u device:%u"),
- vendor, product, bus, device);
- } else {
- virReportError(VIR_ERR_OPERATION_FAILED,
- _("Multiple USB devices for %x:%x, "
- "use <address> to specify one"),
- vendor, product);
- }
- return -1;
- }
-
- hostdev->source.subsys.u.usb.bus = virUSBDeviceGetBus(*usb);
- hostdev->source.subsys.u.usb.device = virUSBDeviceGetDevno(*usb);
- hostdev->source.subsys.u.usb.autoAddress = true;
-
- if (autoAddress) {
- VIR_INFO("USB device %x:%x found at bus:%u device:%u (moved"
- " from bus:%u device:%u)",
- vendor, product,
- hostdev->source.subsys.u.usb.bus,
- hostdev->source.subsys.u.usb.device,
- bus, device);
- }
- } else if (!vendor && bus) {
- if (virUSBDeviceFindByBus(bus, device,
- NULL,
- mandatory, usb) < 0)
- return -1;
- }
-
-out:
- if (!*usb)
- hostdev->missing = true;
- return 0;
-}
-
-static int
-virLXCPrepareHostUSBDevices(virLXCDriverPtr driver,
- virDomainDefPtr def)
-{
- size_t i;
- int ret = -1;
- virUSBDeviceList *list;
- virUSBDevicePtr tmp;
- virDomainHostdevDefPtr *hostdevs = def->hostdevs;
- int nhostdevs = def->nhostdevs;
-
- /* To prevent situation where USB device is assigned to two domains
- * we need to keep a list of currently assigned USB devices.
- * This is done in several loops which cannot be joined into one big
- * loop. See virLXCPrepareHostdevPCIDevices()
- */
- if (!(list = virUSBDeviceListNew()))
- goto cleanup;
-
- /* Loop 1: build temporary list
- */
- for (i = 0; i < nhostdevs; i++) {
- virDomainHostdevDefPtr hostdev = hostdevs[i];
- bool required = true;
- virUSBDevicePtr usb;
-
- if (hostdev->mode != VIR_DOMAIN_HOSTDEV_MODE_SUBSYS)
- continue;
- if (hostdev->source.subsys.type != VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB)
- continue;
-
- if (hostdev->startupPolicy == VIR_DOMAIN_STARTUP_POLICY_OPTIONAL)
- required = false;
-
- if (virLXCFindHostdevUSBDevice(hostdev, required, &usb) < 0)
- goto cleanup;
-
- if (usb && virUSBDeviceListAdd(list, usb) < 0) {
- virUSBDeviceFree(usb);
- goto cleanup;
- }
- }
-
- /* Mark devices in temporary list as used by @name
- * and add them do driver list. However, if something goes
- * wrong, perform rollback.
- */
- if (virLXCPrepareHostdevUSBDevices(driver, def->name, list) < 0)
- goto cleanup;
-
- /* Loop 2: Temporary list was successfully merged with
- * driver list, so steal all items to avoid freeing them
- * in cleanup label.
- */
- while (virUSBDeviceListCount(list) > 0) {
- tmp = virUSBDeviceListGet(list, 0);
- virUSBDeviceListSteal(list, tmp);
- }
-
- ret = 0;
-
-cleanup:
- virObjectUnref(list);
- return ret;
-}
-
-
-int virLXCPrepareHostDevices(virLXCDriverPtr driver,
- virDomainDefPtr def)
-{
- size_t i;
-
- if (!def->nhostdevs)
- return 0;
-
- /* Sanity check for supported configurations only */
- for (i = 0; i < def->nhostdevs; i++) {
- virDomainHostdevDefPtr dev = def->hostdevs[i];
-
- switch (dev->mode) {
- case VIR_DOMAIN_HOSTDEV_MODE_SUBSYS:
- switch (dev->source.subsys.type) {
- case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB:
- break;
- default:
- virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
- _("Unsupported hostdev type %s"),
-
virDomainHostdevSubsysTypeToString(dev->source.subsys.type));
- return -1;
- }
- break;
-
- case VIR_DOMAIN_HOSTDEV_MODE_CAPABILITIES:
- switch (dev->source.subsys.type) {
- case VIR_DOMAIN_HOSTDEV_CAPS_TYPE_STORAGE:
- case VIR_DOMAIN_HOSTDEV_CAPS_TYPE_MISC:
- case VIR_DOMAIN_HOSTDEV_CAPS_TYPE_NET:
- break;
- default:
- virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
- _("Unsupported hostdev type %s"),
-
virDomainHostdevSubsysTypeToString(dev->source.subsys.type));
- return -1;
- }
- break;
-
-
- default:
- virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
- _("Unsupported hostdev mode %s"),
- virDomainHostdevModeTypeToString(dev->mode));
- return -1;
- }
- }
-
- if (virLXCPrepareHostUSBDevices(driver, def) < 0)
- return -1;
-
- return 0;
-}
-
-
-static void
-virLXCDomainReAttachHostUsbDevices(virLXCDriverPtr driver,
- const char *name,
- virDomainHostdevDefPtr *hostdevs,
- int nhostdevs)
-{
- size_t i;
-
- virObjectLock(driver->activeUsbHostdevs);
- for (i = 0; i < nhostdevs; i++) {
- virDomainHostdevDefPtr hostdev = hostdevs[i];
- virUSBDevicePtr usb, tmp;
- const char *used_by = NULL;
-
- if (hostdev->mode != VIR_DOMAIN_HOSTDEV_MODE_SUBSYS)
- continue;
- if (hostdev->source.subsys.type != VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB)
- continue;
- if (hostdev->missing)
- continue;
-
- usb = virUSBDeviceNew(hostdev->source.subsys.u.usb.bus,
- hostdev->source.subsys.u.usb.device,
- NULL);
-
- if (!usb) {
- VIR_WARN("Unable to reattach USB device %03d.%03d on domain %s",
- hostdev->source.subsys.u.usb.bus,
- hostdev->source.subsys.u.usb.device,
- name);
- continue;
- }
-
- /* Delete only those USB devices which belongs
- * to domain @name because virLXCProcessStart() might
- * have failed because USB device is already taken.
- * Therefore we want to steal only those devices from
- * the list which were taken by @name */
-
- tmp = virUSBDeviceListFind(driver->activeUsbHostdevs, usb);
- virUSBDeviceFree(usb);
-
- if (!tmp) {
- VIR_WARN("Unable to find device %03d.%03d "
- "in list of active USB devices",
- hostdev->source.subsys.u.usb.bus,
- hostdev->source.subsys.u.usb.device);
- continue;
- }
-
- used_by = virUSBDeviceGetUsedBy(tmp);
- if (STREQ_NULLABLE(used_by, name)) {
- VIR_DEBUG("Removing %03d.%03d dom=%s from activeUsbHostdevs",
- hostdev->source.subsys.u.usb.bus,
- hostdev->source.subsys.u.usb.device,
- name);
-
- virUSBDeviceListDel(driver->activeUsbHostdevs, tmp);
- }
- }
- virObjectUnlock(driver->activeUsbHostdevs);
-}
-
-void virLXCDomainReAttachHostDevices(virLXCDriverPtr driver,
- virDomainDefPtr def)
-{
- if (!def->nhostdevs)
- return;
-
- virLXCDomainReAttachHostUsbDevices(driver, def->name, def->hostdevs,
- def->nhostdevs);
-}
diff --git a/src/lxc/lxc_hostdev.h b/src/lxc/lxc_hostdev.h
deleted file mode 100644
index 41bb178..0000000
--- a/src/lxc/lxc_hostdev.h
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * virLXC_hostdev.h: VIRLXC hostdev management
- *
- * Copyright (C) 2006-2007, 2009-2010 Red Hat, Inc.
- * Copyright (C) 2006 Daniel P. Berrange
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library. If not, see
- * <
http://www.gnu.org/licenses/>.
- *
- * Author: Daniel P. Berrange <berrange(a)redhat.com>
- */
-
-#ifndef __LXC_HOSTDEV_H__
-# define __LXC_HOSTDEV_H__
-
-# include "lxc_conf.h"
-# include "domain_conf.h"
-
-int virLXCUpdateActiveUsbHostdevs(virLXCDriverPtr driver,
- virDomainDefPtr def);
-int virLXCFindHostdevUSBDevice(virDomainHostdevDefPtr hostdev,
- bool mandatory,
- virUSBDevicePtr *usb);
-int virLXCPrepareHostdevUSBDevices(virLXCDriverPtr driver,
- const char *name,
- virUSBDeviceListPtr list);
-int virLXCPrepareHostDevices(virLXCDriverPtr driver,
- virDomainDefPtr def);
-void virLXCDomainReAttachHostDevices(virLXCDriverPtr driver,
- virDomainDefPtr def);
-
-#endif /* __LXC_HOSTDEV_H__ */
diff --git a/src/lxc/lxc_process.c b/src/lxc/lxc_process.c
index 247e516..02509d9 100644
--- a/src/lxc/lxc_process.c
+++ b/src/lxc/lxc_process.c
@@ -45,11 +45,11 @@
#include "virerror.h"
#include "virlog.h"
#include "vircommand.h"
-#include "lxc_hostdev.h"
#include "virhook.h"
#include "virstring.h"
#include "viratomic.h"
#include "virprocess.h"
+#include "virhostdev.h"
#define VIR_FROM_THIS VIR_FROM_LXC
@@ -151,6 +151,7 @@ static void virLXCProcessCleanup(virLXCDriverPtr driver,
virLXCDomainObjPrivatePtr priv = vm->privateData;
virNetDevVPortProfilePtr vport = NULL;
virLXCDriverConfigPtr cfg = virLXCDriverGetConfig(driver);
+ virHostdevManagerPtr hostdev_mgr;
VIR_DEBUG("Stopping VM name=%s pid=%d reason=%d",
vm->def->name, (int)vm->pid, (int)reason);
@@ -186,7 +187,11 @@ static void virLXCProcessCleanup(virLXCDriverPtr driver,
if (virAtomicIntDecAndTest(&driver->nactive) &&
driver->inhibitCallback)
driver->inhibitCallback(false, driver->inhibitOpaque);
- virLXCDomainReAttachHostDevices(driver, vm->def);
+ hostdev_mgr = virHostdevManagerGetDefault();
+ virHostdevReAttachDomainHostdevs(hostdev_mgr,
+ LXC_DRIVER_NAME,
+ vm->def,
+ VIR_SP_USB_HOSTDEV);
for (i = 0; i < vm->def->nnets; i++) {
virDomainNetDefPtr iface = vm->def->nets[i];
@@ -973,6 +978,7 @@ int virLXCProcessStart(virConnectPtr conn,
virErrorPtr err = NULL;
virLXCDriverConfigPtr cfg = virLXCDriverGetConfig(driver);
virCgroupPtr selfcgroup;
+ virHostdevManagerPtr hostdev_mgr;
if (virCgroupNewSelf(&selfcgroup) < 0)
return -1;
@@ -1058,7 +1064,11 @@ int virLXCProcessStart(virConnectPtr conn,
/* Must be run before security labelling */
VIR_DEBUG("Preparing host devices");
- if (virLXCPrepareHostDevices(driver, vm->def) < 0)
+ hostdev_mgr = virHostdevManagerGetDefault();
+ if (virHostdevPrepareDomainHostdevs(hostdev_mgr,
+ LXC_DRIVER_NAME,
+ vm->def,
+ VIR_SP_USB_HOSTDEV) < 0)
goto cleanup;
/* Here we open all the PTYs we need on the host OS side.
@@ -1393,6 +1403,7 @@ virLXCProcessReconnectDomain(virDomainObjPtr vm,
{
virLXCDriverPtr driver = opaque;
virLXCDomainObjPrivatePtr priv;
+ virHostdevManagerPtr hostdev_mgr;
int ret = -1;
virObjectLock(vm);
@@ -1422,7 +1433,9 @@ virLXCProcessReconnectDomain(virDomainObjPtr vm,
goto error;
}
- if (virLXCUpdateActiveUsbHostdevs(driver, vm->def) < 0)
+ hostdev_mgr = virHostdevManagerGetDefault();
+ if (virHostdevPrepareDomainHostdevs(hostdev_mgr, LXC_DRIVER_NAME,
+ vm->def, VIR_SP_USB_HOSTDEV) < 0)
Parameter alignment.
This patch looks rather straight-forward and similar to the changes you
made in the QEMU driver, but would be good to have another set of
libvirt dev eyes review it.
Regards,
Jim
goto error;
if (virSecurityManagerReserveLabel(driver->securityManager,