diff --git a/src/ch/ch_hostdev.c b/src/ch/ch_hostdev.c index c18137b661..641032de30 100644 --- a/src/ch/ch_hostdev.c +++ b/src/ch/ch_hostdev.c @@ -22,11 +22,31 @@ #include "ch_hostdev.h" #include "virlog.h" +#include "virerror.h" +#include "virhostdev.h" #define VIR_FROM_THIS VIR_FROM_CH VIR_LOG_INIT("ch.ch_hostdev"); +int +virCHHostdevPrepareDomainDevices(virCHDriver *driver, + virDomainDef *def, + unsigned int flags) + +{ + if (!def->nhostdevs) + return 0; + + if (virHostdevPreparePCIDevices(driver->hostdevMgr, CH_DRIVER_NAME, + def->name, def->uuid, + def->hostdevs, def->nhostdevs, + flags) < 0) + return -1; + + return 0; +} + static int virCHDomainPrepareHostdevPCI(virDomainHostdevDef *hostdev) { diff --git a/src/ch/ch_hostdev.h b/src/ch/ch_hostdev.h index f9ba40ab71..f949ecbe87 100644 --- a/src/ch/ch_hostdev.h +++ b/src/ch/ch_hostdev.h @@ -25,3 +25,8 @@ int virCHDomainPrepareHostdev(virDomainHostdevDef *hostdev); + +int +virCHHostdevPrepareDomainDevices(virCHDriver *driver, + virDomainDef *def, + unsigned int flags); diff --git a/src/ch/ch_process.c b/src/ch/ch_process.c index c5b5b6ebb2..ed0fa1fedb 100644 --- a/src/ch/ch_process.c +++ b/src/ch/ch_process.c @@ -824,6 +824,33 @@ virCHProcessPrepareDomainHostdevs(virDomainObj *vm) return 0; } +/** + * virCHProcessPrepareHost: + * @driver: ch driver + * @vm: domain object + * + * This function groups all code that modifies host system to prepare + * environment for a domain which is about to start. + * + * This function MUST be called only after virCHProcessPrepareDomain(). + */ +static int +virCHProcessPrepareHost(virCHDriver *driver, virDomainObj *vm) +{ + unsigned int hostdev_flags = 0; + virCHDomainObjPrivate *priv = vm->privateData; + g_autoptr(virCHDriverConfig) cfg = virCHDriverGetConfig(driver); + + if (virCHHostdevPrepareDomainDevices(driver, vm->def, hostdev_flags) < 0) + return -1; + + /* Ensure no historical cgroup for this VM is lying around */ + VIR_DEBUG("Ensuring no historical cgroup is lying around"); + virDomainCgroupRemoveCgroup(vm, priv->cgroup, priv->machineName); + + return 0; +} + /** * virCHProcessPrepareDomain: * @vm: domain object @@ -878,6 +905,9 @@ virCHProcessStart(virCHDriver *driver, return -1; } + if (virCHProcessPrepareHost(driver, vm) < 0) + return -1; + if (!priv->monitor) { /* And we can get the first monitor connection now too */ if (!(priv->monitor = virCHProcessConnectMonitor(driver, vm))) {