提交 cfed9ad4 编写于 作者: D Daniel P. Berrange

Store a virCgroupPtr instance in virLXCDomainObjPrivatePtr

Instead of calling virCgroupForDomain every time we need
the virCgrouPtr instance, just do it once at Vm startup
and cache a reference to the object in virLXCDomainObjPrivatePtr
until shutdown of the VM. Removing the virCgroupPtr from
the LXC driver state also means we don't have stale mount
info, if someone mounts the cgroups filesystem after libvirtd
has been started
Signed-off-by: NDaniel P. Berrange <berrange@redhat.com>
上级 632f78ca
......@@ -527,7 +527,6 @@ virCgroupPtr virLXCCgroupCreate(virDomainDefPtr def)
{
virCgroupPtr driver = NULL;
virCgroupPtr cgroup = NULL;
int ret = -1;
int rc;
rc = virCgroupForDriver("lxc", &driver, 1, 0, -1);
......@@ -545,6 +544,21 @@ virCgroupPtr virLXCCgroupCreate(virDomainDefPtr def)
goto cleanup;
}
cleanup:
virCgroupFree(&driver);
return cgroup;
}
virCgroupPtr virLXCCgroupJoin(virDomainDefPtr def)
{
virCgroupPtr cgroup = NULL;
int ret = -1;
int rc;
if (!(cgroup = virLXCCgroupCreate(def)))
return NULL;
rc = virCgroupAddTask(cgroup, getpid());
if (rc != 0) {
virReportSystemError(-rc,
......@@ -556,7 +570,6 @@ virCgroupPtr virLXCCgroupCreate(virDomainDefPtr def)
ret = 0;
cleanup:
virCgroupFree(&driver);
if (ret < 0) {
virCgroupFree(&cgroup);
return NULL;
......
......@@ -22,11 +22,13 @@
#ifndef __VIR_LXC_CGROUP_H__
# define __VIR_LXC_CGROUP_H__
# include "vircgroup.h"
# include "domain_conf.h"
# include "lxc_fuse.h"
# include "virusb.h"
virCgroupPtr virLXCCgroupCreate(virDomainDefPtr def);
virCgroupPtr virLXCCgroupJoin(virDomainDefPtr def);
int virLXCCgroupSetup(virDomainDefPtr def,
virCgroupPtr cgroup,
virBitmapPtr nodemask);
......
......@@ -32,9 +32,9 @@
# include "domain_event.h"
# include "capabilities.h"
# include "virthread.h"
# include "vircgroup.h"
# include "security/security_manager.h"
# include "configmake.h"
# include "vircgroup.h"
# include "virsysinfo.h"
# include "virusb.h"
......
......@@ -1434,7 +1434,7 @@ virLXCControllerRun(virLXCControllerPtr ctrl)
if (virLXCControllerSetupPrivateNS() < 0)
goto cleanup;
if (!(cgroup = virLXCCgroupCreate(ctrl->def)))
if (!(cgroup = virLXCCgroupJoin(ctrl->def)))
goto cleanup;
if (virLXCControllerSetupLoopDevices(ctrl) < 0)
......
......@@ -43,6 +43,8 @@ static void virLXCDomainObjPrivateFree(void *data)
{
virLXCDomainObjPrivatePtr priv = data;
virCgroupFree(&priv->cgroup);
VIR_FREE(priv);
}
......
......@@ -23,6 +23,7 @@
#ifndef __LXC_DOMAIN_H__
# define __LXC_DOMAIN_H__
# include "vircgroup.h"
# include "lxc_conf.h"
# include "lxc_monitor.h"
......@@ -36,6 +37,8 @@ struct _virLXCDomainObjPrivate {
bool wantReboot;
pid_t initpid;
virCgroupPtr cgroup;
};
extern virDomainXMLPrivateDataCallbacks virLXCDriverPrivateDataCallbacks;
......
此差异已折叠。
......@@ -29,6 +29,7 @@
#include "lxc_process.h"
#include "lxc_domain.h"
#include "lxc_container.h"
#include "lxc_cgroup.h"
#include "lxc_fuse.h"
#include "datatypes.h"
#include "virfile.h"
......@@ -219,7 +220,6 @@ static void virLXCProcessCleanup(virLXCDriverPtr driver,
virDomainObjPtr vm,
virDomainShutoffReason reason)
{
virCgroupPtr cgroup;
int i;
virLXCDomainObjPrivatePtr priv = vm->privateData;
virNetDevVPortProfilePtr vport = NULL;
......@@ -277,10 +277,9 @@ static void virLXCProcessCleanup(virLXCDriverPtr driver,
virDomainConfVMNWFilterTeardown(vm);
if (driver->cgroup &&
virCgroupForDomain(driver->cgroup, vm->def->name, &cgroup, 0) == 0) {
virCgroupRemove(cgroup);
virCgroupFree(&cgroup);
if (priv->cgroup) {
virCgroupRemove(priv->cgroup);
virCgroupFree(&priv->cgroup);
}
/* now that we know it's stopped call the hook if present */
......@@ -742,8 +741,8 @@ int virLXCProcessStop(virLXCDriverPtr driver,
virDomainObjPtr vm,
virDomainShutoffReason reason)
{
virCgroupPtr group = NULL;
int rc;
virLXCDomainObjPrivatePtr priv;
VIR_DEBUG("Stopping VM name=%s pid=%d reason=%d",
vm->def->name, (int)vm->pid, (int)reason);
......@@ -752,6 +751,8 @@ int virLXCProcessStop(virLXCDriverPtr driver,
return 0;
}
priv = vm->privateData;
if (vm->pid <= 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Invalid PID %d for container"), vm->pid);
......@@ -769,8 +770,8 @@ int virLXCProcessStop(virLXCDriverPtr driver,
VIR_FREE(vm->def->seclabels[0]->imagelabel);
}
if (virCgroupForDomain(driver->cgroup, vm->def->name, &group, 0) == 0) {
rc = virCgroupKillPainfully(group);
if (priv->cgroup) {
rc = virCgroupKillPainfully(priv->cgroup);
if (rc < 0) {
virReportSystemError(-rc, "%s",
_("Failed to kill container PIDs"));
......@@ -794,7 +795,6 @@ int virLXCProcessStop(virLXCDriverPtr driver,
rc = 0;
cleanup:
virCgroupFree(&group);
return rc;
}
......@@ -1047,26 +1047,28 @@ int virLXCProcessStart(virConnectPtr conn,
virLXCDomainObjPrivatePtr priv = vm->privateData;
virErrorPtr err = NULL;
if (!lxc_driver->cgroup) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("The 'cpuacct', 'devices' & 'memory' cgroups controllers must be mounted"));
virCgroupFree(&priv->cgroup);
if (!(priv->cgroup = virLXCCgroupCreate(vm->def)))
return -1;
}
if (!virCgroupHasController(lxc_driver->cgroup,
VIR_CGROUP_CONTROLLER_CPUACCT)) {
if (!virCgroupHasController(priv->cgroup,
VIR_CGROUP_CONTROLLER_CPUACCT)) {
virCgroupFree(&priv->cgroup);
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("Unable to find 'cpuacct' cgroups controller mount"));
return -1;
}
if (!virCgroupHasController(lxc_driver->cgroup,
if (!virCgroupHasController(priv->cgroup,
VIR_CGROUP_CONTROLLER_DEVICES)) {
virCgroupFree(&priv->cgroup);
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("Unable to find 'devices' cgroups controller mount"));
return -1;
}
if (!virCgroupHasController(lxc_driver->cgroup,
if (!virCgroupHasController(priv->cgroup,
VIR_CGROUP_CONTROLLER_MEMORY)) {
virCgroupFree(&priv->cgroup);
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("Unable to find 'memory' cgroups controller mount"));
return -1;
......@@ -1462,6 +1464,9 @@ virLXCProcessReconnectDomain(virDomainObjPtr vm,
if (!(priv->monitor = virLXCProcessConnectMonitor(driver, vm)))
goto error;
if (!(priv->cgroup = virLXCCgroupCreate(vm->def)))
goto error;
if (virLXCUpdateActiveUsbHostdevs(driver, vm->def) < 0)
goto error;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册