mirror of
https://github.com/libvirt/libvirt.git
synced 2025-02-25 18:55:26 -06:00
Auto-detect existing cgroup placement
Use the new virCgroupNewDetect function to determine cgroup placement of existing running VMs. This will allow the legacy cgroups creation APIs to be removed entirely Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
This commit is contained in:
parent
e638778eb3
commit
87b2e6fa84
@ -429,12 +429,12 @@ cleanup:
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
virCgroupPtr virLXCCgroupCreate(virDomainDefPtr def, bool startup)
|
virCgroupPtr virLXCCgroupCreate(virDomainDefPtr def)
|
||||||
{
|
{
|
||||||
virCgroupPtr parent = NULL;
|
virCgroupPtr parent = NULL;
|
||||||
virCgroupPtr cgroup = NULL;
|
virCgroupPtr cgroup = NULL;
|
||||||
|
|
||||||
if (!def->resource && startup) {
|
if (!def->resource) {
|
||||||
virDomainResourceDefPtr res;
|
virDomainResourceDefPtr res;
|
||||||
|
|
||||||
if (VIR_ALLOC(res) < 0)
|
if (VIR_ALLOC(res) < 0)
|
||||||
@ -448,41 +448,26 @@ virCgroupPtr virLXCCgroupCreate(virDomainDefPtr def, bool startup)
|
|||||||
def->resource = res;
|
def->resource = res;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (def->resource &&
|
if (def->resource->partition[0] != '/') {
|
||||||
def->resource->partition) {
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
||||||
if (def->resource->partition[0] != '/') {
|
_("Resource partition '%s' must start with '/'"),
|
||||||
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
def->resource->partition);
|
||||||
_("Resource partition '%s' must start with '/'"),
|
goto cleanup;
|
||||||
def->resource->partition);
|
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
/* We only auto-create the default partition. In other
|
|
||||||
* cases we expec the sysadmin/app to have done so */
|
|
||||||
if (virCgroupNewPartition(def->resource->partition,
|
|
||||||
STREQ(def->resource->partition, "/machine"),
|
|
||||||
-1,
|
|
||||||
&parent) < 0)
|
|
||||||
goto cleanup;
|
|
||||||
|
|
||||||
if (virCgroupNewDomainPartition(parent,
|
|
||||||
"lxc",
|
|
||||||
def->name,
|
|
||||||
true,
|
|
||||||
&cgroup) < 0)
|
|
||||||
goto cleanup;
|
|
||||||
} else {
|
|
||||||
if (virCgroupNewDriver("lxc",
|
|
||||||
true,
|
|
||||||
-1,
|
|
||||||
&parent) < 0)
|
|
||||||
goto cleanup;
|
|
||||||
|
|
||||||
if (virCgroupNewDomainDriver(parent,
|
|
||||||
def->name,
|
|
||||||
true,
|
|
||||||
&cgroup) < 0)
|
|
||||||
goto cleanup;
|
|
||||||
}
|
}
|
||||||
|
/* We only auto-create the default partition. In other
|
||||||
|
* cases we expect the sysadmin/app to have done so */
|
||||||
|
if (virCgroupNewPartition(def->resource->partition,
|
||||||
|
STREQ(def->resource->partition, "/machine"),
|
||||||
|
-1,
|
||||||
|
&parent) < 0)
|
||||||
|
goto cleanup;
|
||||||
|
|
||||||
|
if (virCgroupNewDomainPartition(parent,
|
||||||
|
"lxc",
|
||||||
|
def->name,
|
||||||
|
true,
|
||||||
|
&cgroup) < 0)
|
||||||
|
goto cleanup;
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
virCgroupFree(&parent);
|
virCgroupFree(&parent);
|
||||||
@ -495,7 +480,7 @@ virCgroupPtr virLXCCgroupJoin(virDomainDefPtr def)
|
|||||||
virCgroupPtr cgroup = NULL;
|
virCgroupPtr cgroup = NULL;
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
|
|
||||||
if (!(cgroup = virLXCCgroupCreate(def, true)))
|
if (!(cgroup = virLXCCgroupCreate(def)))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if (virCgroupAddTask(cgroup, getpid()) < 0)
|
if (virCgroupAddTask(cgroup, getpid()) < 0)
|
||||||
|
@ -27,7 +27,7 @@
|
|||||||
# include "lxc_fuse.h"
|
# include "lxc_fuse.h"
|
||||||
# include "virusb.h"
|
# include "virusb.h"
|
||||||
|
|
||||||
virCgroupPtr virLXCCgroupCreate(virDomainDefPtr def, bool startup);
|
virCgroupPtr virLXCCgroupCreate(virDomainDefPtr def);
|
||||||
virCgroupPtr virLXCCgroupJoin(virDomainDefPtr def);
|
virCgroupPtr virLXCCgroupJoin(virDomainDefPtr def);
|
||||||
int virLXCCgroupSetup(virDomainDefPtr def,
|
int virLXCCgroupSetup(virDomainDefPtr def,
|
||||||
virCgroupPtr cgroup,
|
virCgroupPtr cgroup,
|
||||||
|
@ -974,7 +974,7 @@ int virLXCProcessStart(virConnectPtr conn,
|
|||||||
|
|
||||||
virCgroupFree(&priv->cgroup);
|
virCgroupFree(&priv->cgroup);
|
||||||
|
|
||||||
if (!(priv->cgroup = virLXCCgroupCreate(vm->def, true)))
|
if (!(priv->cgroup = virLXCCgroupCreate(vm->def)))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (!virCgroupHasController(priv->cgroup,
|
if (!virCgroupHasController(priv->cgroup,
|
||||||
@ -1385,9 +1385,19 @@ virLXCProcessReconnectDomain(virDomainObjPtr vm,
|
|||||||
if (!(priv->monitor = virLXCProcessConnectMonitor(driver, vm)))
|
if (!(priv->monitor = virLXCProcessConnectMonitor(driver, vm)))
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
if (!(priv->cgroup = virLXCCgroupCreate(vm->def, false)))
|
if (virCgroupNewDetect(vm->pid, &priv->cgroup) < 0)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
|
if (!virCgroupIsValidMachineGroup(priv->cgroup,
|
||||||
|
vm->def->name,
|
||||||
|
"lxc")) {
|
||||||
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||||
|
_("Cgroup name is not valid for machine %s"),
|
||||||
|
vm->def->name);
|
||||||
|
virCgroupFree(&priv->cgroup);
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
|
||||||
if (virLXCUpdateActiveUsbHostdevs(driver, vm->def) < 0)
|
if (virLXCUpdateActiveUsbHostdevs(driver, vm->def) < 0)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
|
@ -627,10 +627,9 @@ qemuSetupCpuCgroup(virDomainObjPtr vm)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int
|
static int
|
||||||
qemuInitCgroup(virQEMUDriverPtr driver,
|
qemuInitCgroup(virQEMUDriverPtr driver,
|
||||||
virDomainObjPtr vm,
|
virDomainObjPtr vm)
|
||||||
bool startup)
|
|
||||||
{
|
{
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
qemuDomainObjPrivatePtr priv = vm->privateData;
|
qemuDomainObjPrivatePtr priv = vm->privateData;
|
||||||
@ -645,7 +644,7 @@ qemuInitCgroup(virQEMUDriverPtr driver,
|
|||||||
|
|
||||||
virCgroupFree(&priv->cgroup);
|
virCgroupFree(&priv->cgroup);
|
||||||
|
|
||||||
if (!vm->def->resource && startup) {
|
if (!vm->def->resource) {
|
||||||
virDomainResourceDefPtr res;
|
virDomainResourceDefPtr res;
|
||||||
|
|
||||||
if (VIR_ALLOC(res) < 0)
|
if (VIR_ALLOC(res) < 0)
|
||||||
@ -659,49 +658,30 @@ qemuInitCgroup(virQEMUDriverPtr driver,
|
|||||||
vm->def->resource = res;
|
vm->def->resource = res;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (vm->def->resource &&
|
if (vm->def->resource->partition[0] != '/') {
|
||||||
vm->def->resource->partition) {
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
||||||
if (vm->def->resource->partition[0] != '/') {
|
_("Resource partition '%s' must start with '/'"),
|
||||||
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
vm->def->resource->partition);
|
||||||
_("Resource partition '%s' must start with '/'"),
|
goto cleanup;
|
||||||
vm->def->resource->partition);
|
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
/* We only auto-create the default partition. In other
|
|
||||||
* cases we expec the sysadmin/app to have done so */
|
|
||||||
if (virCgroupNewPartition(vm->def->resource->partition,
|
|
||||||
STREQ(vm->def->resource->partition, "/machine"),
|
|
||||||
cfg->cgroupControllers,
|
|
||||||
&parent) < 0) {
|
|
||||||
if (virCgroupNewIgnoreError())
|
|
||||||
goto done;
|
|
||||||
|
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (virCgroupNewDomainPartition(parent,
|
|
||||||
"qemu",
|
|
||||||
vm->def->name,
|
|
||||||
true,
|
|
||||||
&priv->cgroup) < 0)
|
|
||||||
goto cleanup;
|
|
||||||
} else {
|
|
||||||
if (virCgroupNewDriver("qemu",
|
|
||||||
true,
|
|
||||||
cfg->cgroupControllers,
|
|
||||||
&parent) < 0) {
|
|
||||||
if (virCgroupNewIgnoreError())
|
|
||||||
goto done;
|
|
||||||
|
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (virCgroupNewDomainDriver(parent,
|
|
||||||
vm->def->name,
|
|
||||||
true,
|
|
||||||
&priv->cgroup) < 0)
|
|
||||||
goto cleanup;
|
|
||||||
}
|
}
|
||||||
|
/* We only auto-create the default partition. In other
|
||||||
|
* cases we expect the sysadmin/app to have done so */
|
||||||
|
if (virCgroupNewPartition(vm->def->resource->partition,
|
||||||
|
STREQ(vm->def->resource->partition, "/machine"),
|
||||||
|
cfg->cgroupControllers,
|
||||||
|
&parent) < 0) {
|
||||||
|
if (virCgroupNewIgnoreError())
|
||||||
|
goto done;
|
||||||
|
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (virCgroupNewDomainPartition(parent,
|
||||||
|
"qemu",
|
||||||
|
vm->def->name,
|
||||||
|
true,
|
||||||
|
&priv->cgroup) < 0)
|
||||||
|
goto cleanup;
|
||||||
|
|
||||||
done:
|
done:
|
||||||
ret = 0;
|
ret = 0;
|
||||||
@ -712,6 +692,43 @@ cleanup:
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int
|
||||||
|
qemuConnectCgroup(virQEMUDriverPtr driver,
|
||||||
|
virDomainObjPtr vm)
|
||||||
|
{
|
||||||
|
virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
|
||||||
|
qemuDomainObjPrivatePtr priv = vm->privateData;
|
||||||
|
int ret = -1;
|
||||||
|
|
||||||
|
if (!cfg->privileged)
|
||||||
|
goto done;
|
||||||
|
|
||||||
|
if (!virCgroupAvailable())
|
||||||
|
goto done;
|
||||||
|
|
||||||
|
virCgroupFree(&priv->cgroup);
|
||||||
|
|
||||||
|
if (virCgroupNewDetect(vm->pid, &priv->cgroup) < 0) {
|
||||||
|
if (virCgroupNewIgnoreError())
|
||||||
|
goto done;
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!virCgroupIsValidMachineGroup(priv->cgroup,
|
||||||
|
vm->def->name,
|
||||||
|
"qemu")) {
|
||||||
|
VIR_DEBUG("Cgroup name is not valid for machine");
|
||||||
|
virCgroupFree(&priv->cgroup);
|
||||||
|
goto done;
|
||||||
|
}
|
||||||
|
|
||||||
|
done:
|
||||||
|
ret = 0;
|
||||||
|
cleanup:
|
||||||
|
virObjectUnref(cfg);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
qemuSetupCgroup(virQEMUDriverPtr driver,
|
qemuSetupCgroup(virQEMUDriverPtr driver,
|
||||||
virDomainObjPtr vm,
|
virDomainObjPtr vm,
|
||||||
@ -721,7 +738,7 @@ qemuSetupCgroup(virQEMUDriverPtr driver,
|
|||||||
virCapsPtr caps = NULL;
|
virCapsPtr caps = NULL;
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
|
|
||||||
if (qemuInitCgroup(driver, vm, true) < 0)
|
if (qemuInitCgroup(driver, vm) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (!priv->cgroup)
|
if (!priv->cgroup)
|
||||||
|
@ -39,9 +39,8 @@ int qemuSetupHostdevCGroup(virDomainObjPtr vm,
|
|||||||
int qemuTeardownHostdevCgroup(virDomainObjPtr vm,
|
int qemuTeardownHostdevCgroup(virDomainObjPtr vm,
|
||||||
virDomainHostdevDefPtr dev)
|
virDomainHostdevDefPtr dev)
|
||||||
ATTRIBUTE_RETURN_CHECK;
|
ATTRIBUTE_RETURN_CHECK;
|
||||||
int qemuInitCgroup(virQEMUDriverPtr driver,
|
int qemuConnectCgroup(virQEMUDriverPtr driver,
|
||||||
virDomainObjPtr vm,
|
virDomainObjPtr vm);
|
||||||
bool startup);
|
|
||||||
int qemuSetupCgroup(virQEMUDriverPtr driver,
|
int qemuSetupCgroup(virQEMUDriverPtr driver,
|
||||||
virDomainObjPtr vm,
|
virDomainObjPtr vm,
|
||||||
virBitmapPtr nodemask);
|
virBitmapPtr nodemask);
|
||||||
|
@ -3070,7 +3070,7 @@ qemuProcessReconnect(void *opaque)
|
|||||||
if (qemuUpdateActiveScsiHostdevs(driver, obj->def) < 0)
|
if (qemuUpdateActiveScsiHostdevs(driver, obj->def) < 0)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
if (qemuInitCgroup(driver, obj, false) < 0)
|
if (qemuConnectCgroup(driver, obj) < 0)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
/* XXX: Need to change as long as lock is introduced for
|
/* XXX: Need to change as long as lock is introduced for
|
||||||
|
Loading…
Reference in New Issue
Block a user