int virLXCCgroupGetMeminfo(virLXCMeminfoPtr meminfo)
{
- int ret = -1;
- virCgroupPtr cgroup;
+ g_autoptr(virCgroup) cgroup = NULL;
if (virCgroupNewSelf(&cgroup) < 0)
return -1;
if (virLXCCgroupGetMemStat(cgroup, meminfo) < 0)
- goto cleanup;
+ return -1;
if (virLXCCgroupGetMemTotal(cgroup, meminfo) < 0)
- goto cleanup;
+ return -1;
if (virLXCCgroupGetMemUsage(cgroup, meminfo) < 0)
- goto cleanup;
+ return -1;
if (virLXCCgroupGetMemSwapTotal(cgroup, meminfo) < 0)
- goto cleanup;
+ return -1;
if (virLXCCgroupGetMemSwapUsage(cgroup, meminfo) < 0)
- goto cleanup;
+ return -1;
- ret = 0;
- cleanup:
- virCgroupFree(cgroup);
- return ret;
+ return 0;
}
size_t nttyPaths,
virSecurityManagerPtr securityDriver)
{
- virCgroupPtr cgroup = NULL;
- int ret = -1;
+ g_autoptr(virCgroup) cgroup = NULL;
g_autofree char *sec_mount_options = NULL;
g_autofree char *stateDir = NULL;
/* Before pivoting we need to identify any
* cgroups controllers that are mounted */
if (virCgroupNewSelf(&cgroup) < 0)
- goto cleanup;
+ return -1;
if (virFileResolveAllLinks(LXC_STATE_DIR, &stateDir) < 0)
- goto cleanup;
+ return -1;
/* Ensure the root filesystem is mounted */
if (lxcContainerPrepareRoot(vmDef, root, sec_mount_options) < 0)
- goto cleanup;
+ return -1;
/* Gives us a private root, leaving all parent OS mounts on /.oldroot */
if (lxcContainerPivotRoot(root) < 0)
- goto cleanup;
+ return -1;
/* FIXME: we should find a way to unmount these mounts for container
* even user namespace is enabled. */
if (STREQ(root->src->path, "/") && (!vmDef->idmap.nuidmap) &&
lxcContainerUnmountForSharedRoot(stateDir, vmDef->name) < 0)
- goto cleanup;
+ return -1;
/* Mounts the core /proc, /sys, etc filesystems */
if (lxcContainerMountBasicFS(vmDef->idmap.nuidmap,
!lxcNeedNetworkNamespace(vmDef)) < 0)
- goto cleanup;
+ return -1;
/* Ensure entire root filesystem (except /.oldroot) is readonly */
if (root->readonly &&
lxcContainerSetReadOnly() < 0)
- goto cleanup;
+ return -1;
/* Mounts /proc/meminfo etc sysinfo */
if (lxcContainerMountProcFuse(vmDef, stateDir) < 0)
- goto cleanup;
+ return -1;
/* Now we can re-mount the cgroups controllers in the
* same configuration as before */
if (virCgroupBindMount(cgroup, "/.oldroot/", sec_mount_options) < 0)
- goto cleanup;
+ return -1;
/* Mounts /dev */
if (lxcContainerMountFSDev(vmDef, stateDir) < 0)
- goto cleanup;
+ return -1;
/* Mounts /dev/pts */
if (lxcContainerMountFSDevPTS(vmDef, stateDir) < 0)
- goto cleanup;
+ return -1;
/* Setup device nodes in /dev/ */
if (lxcContainerSetupDevices(ttyPaths, nttyPaths) < 0)
- goto cleanup;
+ return -1;
/* Sets up any non-root mounts from guest config */
if (lxcContainerMountAllFS(vmDef, sec_mount_options) < 0)
- goto cleanup;
+ return -1;
/* Gets rid of all remaining mounts from host OS, including /.oldroot itself */
if (lxcContainerUnmountSubtree("/.oldroot", true) < 0)
- goto cleanup;
-
- ret = 0;
+ return -1;
- cleanup:
- virCgroupFree(cgroup);
- return ret;
+ return 0;
}
static int lxcContainerResolveAllSymlinks(virDomainDefPtr vmDef)
virCapsPtr caps = NULL;
virErrorPtr err = NULL;
virLXCDriverConfigPtr cfg = virLXCDriverGetConfig(driver);
- virCgroupPtr selfcgroup;
+ g_autoptr(virCgroup) selfcgroup = NULL;
int status;
g_autofree char *pidfile = NULL;
if (!virCgroupHasController(selfcgroup,
VIR_CGROUP_CONTROLLER_CPUACCT)) {
- virCgroupFree(selfcgroup);
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("Unable to find 'cpuacct' cgroups controller mount"));
return -1;
}
if (!virCgroupHasController(selfcgroup,
VIR_CGROUP_CONTROLLER_DEVICES)) {
- virCgroupFree(selfcgroup);
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("Unable to find 'devices' cgroups controller mount"));
return -1;
}
if (!virCgroupHasController(selfcgroup,
VIR_CGROUP_CONTROLLER_MEMORY)) {
- virCgroupFree(selfcgroup);
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("Unable to find 'memory' cgroups controller mount"));
return -1;
}
- virCgroupFree(selfcgroup);
if (vm->def->nconsoles == 0) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",