Currently the LXC driver chooses between systemd machined and direct cgroups usage. This wires up support for the new backend choice introduced by the earlier commits, allowing apps to override the default logic in the driver. This reverts commit c32a7de7d8f81384b17dbe529c6d3b3ac13c631d. --- src/lxc/lxc_cgroup.c | 37 ++++++++++++++++++++++++++++++------- src/lxc/lxc_cgroup.h | 3 +++ src/lxc/lxc_process.c | 6 ++++-- 3 files changed, 37 insertions(+), 9 deletions(-) diff --git a/src/lxc/lxc_cgroup.c b/src/lxc/lxc_cgroup.c index 629f9eca1c..1cfa831f2b 100644 --- a/src/lxc/lxc_cgroup.c +++ b/src/lxc/lxc_cgroup.c @@ -380,6 +380,33 @@ static int virLXCCgroupSetupDeviceACL(virDomainDefPtr def, return 0; } +int virLXCCgroupMode(virDomainResourceBackend backend, + virCgroupRegister *cgreg) +{ + switch (backend) { + case VIR_DOMAIN_RESOURCE_BACKEND_NONE: + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("Resource backend '%s' not available"), + virDomainResourceBackendTypeToString(backend)); + return -1; + case VIR_DOMAIN_RESOURCE_BACKEND_DEFAULT: + *cgreg = VIR_CGROUP_REGISTER_DEFAULT; + break; + case VIR_DOMAIN_RESOURCE_BACKEND_MACHINED: + *cgreg = VIR_CGROUP_REGISTER_MACHINED; + break; + case VIR_DOMAIN_RESOURCE_BACKEND_CGROUPFS: + *cgreg = VIR_CGROUP_REGISTER_DIRECT; + break; + case VIR_DOMAIN_RESOURCE_BACKEND_LAST: + default: + virReportEnumRangeError(virDomainResourceBackend, backend); + return -1; + } + + return 0; +} + virCgroupPtr virLXCCgroupCreate(virDomainDefPtr def, pid_t initpid, @@ -387,18 +414,14 @@ virCgroupPtr virLXCCgroupCreate(virDomainDefPtr def, int *nicindexes) { virCgroupPtr cgroup = NULL; + virCgroupRegister reg; char *machineName = virLXCDomainGetMachineName(def, 0); if (!machineName) goto cleanup; - if (def->resource->backend != VIR_DOMAIN_RESOURCE_BACKEND_DEFAULT) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("Resource backend '%s' not available"), - virDomainResourceBackendTypeToString( - def->resource->backend)); + if (virLXCCgroupMode(def->resource->backend, ®) < 0) goto cleanup; - } if (def->resource->partition[0] != '/') { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, @@ -414,7 +437,7 @@ virCgroupPtr virLXCCgroupCreate(virDomainDefPtr def, initpid, true, nnicindexes, nicindexes, - VIR_CGROUP_REGISTER_DEFAULT, + ®, def->resource->partition, -1, 0, diff --git a/src/lxc/lxc_cgroup.h b/src/lxc/lxc_cgroup.h index 63e9e837b0..df799b2720 100644 --- a/src/lxc/lxc_cgroup.h +++ b/src/lxc/lxc_cgroup.h @@ -26,6 +26,9 @@ #include "lxc_fuse.h" #include "virusb.h" +int virLXCCgroupMode(virDomainResourceBackend backend, + virCgroupRegister *cgreg); + virCgroupPtr virLXCCgroupCreate(virDomainDefPtr def, pid_t initpid, size_t nnicindexes, diff --git a/src/lxc/lxc_process.c b/src/lxc/lxc_process.c index 4ec3cc5619..ead27c17c0 100644 --- a/src/lxc/lxc_process.c +++ b/src/lxc/lxc_process.c @@ -1261,11 +1261,13 @@ int virLXCProcessStart(virConnectPtr conn, goto cleanup; res->backend = VIR_DOMAIN_RESOURCE_BACKEND_DEFAULT; - res->partition = g_strdup("/machine"); - vm->def->resource = res; } + if (vm->def->resource->backend != VIR_DOMAIN_RESOURCE_BACKEND_NONE && + !vm->def->resource->partition) + vm->def->resource->partition = g_strdup("/machine"); + logfile = g_strdup_printf("%s/%s.log", cfg->logDir, vm->def->name); if (!(pidfile = virPidFileBuildPath(cfg->stateDir, vm->def->name))) -- 2.24.1