mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-22 04:25:18 +00:00
vircgroup: detect available backend for cgroup
We need to update one test-case because now new cgroup object will be created only if there is any cgroup backend available. Reviewed-by: Ján Tomko <jtomko@redhat.com> Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
This commit is contained in:
parent
57d35b72c9
commit
f60af21594
@ -707,10 +707,28 @@ virCgroupDetect(virCgroupPtr group,
|
|||||||
virCgroupPtr parent)
|
virCgroupPtr parent)
|
||||||
{
|
{
|
||||||
int rc;
|
int rc;
|
||||||
|
size_t i;
|
||||||
|
virCgroupBackendPtr *backends = virCgroupBackendGetAll();
|
||||||
|
|
||||||
VIR_DEBUG("group=%p controllers=%d path=%s parent=%p",
|
VIR_DEBUG("group=%p controllers=%d path=%s parent=%p",
|
||||||
group, controllers, path, parent);
|
group, controllers, path, parent);
|
||||||
|
|
||||||
|
if (!backends)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
for (i = 0; i < VIR_CGROUP_BACKEND_TYPE_LAST; i++) {
|
||||||
|
if (backends[i] && backends[i]->available()) {
|
||||||
|
group->backend = backends[i];
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!group->backend) {
|
||||||
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||||
|
_("no cgroup backend available"));
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
if (parent) {
|
if (parent) {
|
||||||
if (virCgroupCopyMounts(group, parent) < 0)
|
if (virCgroupCopyMounts(group, parent) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -30,6 +30,7 @@
|
|||||||
# define __VIR_CGROUP_PRIV_H__
|
# define __VIR_CGROUP_PRIV_H__
|
||||||
|
|
||||||
# include "vircgroup.h"
|
# include "vircgroup.h"
|
||||||
|
# include "vircgroupbackend.h"
|
||||||
|
|
||||||
struct _virCgroupController {
|
struct _virCgroupController {
|
||||||
int type;
|
int type;
|
||||||
@ -47,6 +48,8 @@ typedef virCgroupController *virCgroupControllerPtr;
|
|||||||
struct _virCgroup {
|
struct _virCgroup {
|
||||||
char *path;
|
char *path;
|
||||||
|
|
||||||
|
virCgroupBackendPtr backend;
|
||||||
|
|
||||||
virCgroupController controllers[VIR_CGROUP_CONTROLLER_LAST];
|
virCgroupController controllers[VIR_CGROUP_CONTROLLER_LAST];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -113,16 +113,6 @@ const char *mountsAllInOne[VIR_CGROUP_CONTROLLER_LAST] = {
|
|||||||
[VIR_CGROUP_CONTROLLER_BLKIO] = "/not/really/sys/fs/cgroup",
|
[VIR_CGROUP_CONTROLLER_BLKIO] = "/not/really/sys/fs/cgroup",
|
||||||
[VIR_CGROUP_CONTROLLER_SYSTEMD] = NULL,
|
[VIR_CGROUP_CONTROLLER_SYSTEMD] = NULL,
|
||||||
};
|
};
|
||||||
const char *mountsLogind[VIR_CGROUP_CONTROLLER_LAST] = {
|
|
||||||
[VIR_CGROUP_CONTROLLER_CPU] = NULL,
|
|
||||||
[VIR_CGROUP_CONTROLLER_CPUACCT] = NULL,
|
|
||||||
[VIR_CGROUP_CONTROLLER_CPUSET] = NULL,
|
|
||||||
[VIR_CGROUP_CONTROLLER_MEMORY] = NULL,
|
|
||||||
[VIR_CGROUP_CONTROLLER_DEVICES] = NULL,
|
|
||||||
[VIR_CGROUP_CONTROLLER_FREEZER] = NULL,
|
|
||||||
[VIR_CGROUP_CONTROLLER_BLKIO] = NULL,
|
|
||||||
[VIR_CGROUP_CONTROLLER_SYSTEMD] = "/not/really/sys/fs/cgroup/systemd",
|
|
||||||
};
|
|
||||||
|
|
||||||
const char *links[VIR_CGROUP_CONTROLLER_LAST] = {
|
const char *links[VIR_CGROUP_CONTROLLER_LAST] = {
|
||||||
[VIR_CGROUP_CONTROLLER_CPU] = "/not/really/sys/fs/cgroup/cpu",
|
[VIR_CGROUP_CONTROLLER_CPU] = "/not/really/sys/fs/cgroup/cpu",
|
||||||
@ -146,17 +136,6 @@ const char *linksAllInOne[VIR_CGROUP_CONTROLLER_LAST] = {
|
|||||||
[VIR_CGROUP_CONTROLLER_SYSTEMD] = NULL,
|
[VIR_CGROUP_CONTROLLER_SYSTEMD] = NULL,
|
||||||
};
|
};
|
||||||
|
|
||||||
const char *linksLogind[VIR_CGROUP_CONTROLLER_LAST] = {
|
|
||||||
[VIR_CGROUP_CONTROLLER_CPU] = NULL,
|
|
||||||
[VIR_CGROUP_CONTROLLER_CPUACCT] = NULL,
|
|
||||||
[VIR_CGROUP_CONTROLLER_CPUSET] = NULL,
|
|
||||||
[VIR_CGROUP_CONTROLLER_MEMORY] = NULL,
|
|
||||||
[VIR_CGROUP_CONTROLLER_DEVICES] = NULL,
|
|
||||||
[VIR_CGROUP_CONTROLLER_FREEZER] = NULL,
|
|
||||||
[VIR_CGROUP_CONTROLLER_BLKIO] = NULL,
|
|
||||||
[VIR_CGROUP_CONTROLLER_SYSTEMD] = NULL,
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
struct _detectMountsData {
|
struct _detectMountsData {
|
||||||
const char *file;
|
const char *file;
|
||||||
@ -554,24 +533,13 @@ static int testCgroupNewForSelfLogind(const void *args ATTRIBUTE_UNUSED)
|
|||||||
{
|
{
|
||||||
virCgroupPtr cgroup = NULL;
|
virCgroupPtr cgroup = NULL;
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
const char *placement[VIR_CGROUP_CONTROLLER_LAST] = {
|
|
||||||
[VIR_CGROUP_CONTROLLER_CPU] = NULL,
|
|
||||||
[VIR_CGROUP_CONTROLLER_CPUACCT] = NULL,
|
|
||||||
[VIR_CGROUP_CONTROLLER_CPUSET] = NULL,
|
|
||||||
[VIR_CGROUP_CONTROLLER_MEMORY] = NULL,
|
|
||||||
[VIR_CGROUP_CONTROLLER_DEVICES] = NULL,
|
|
||||||
[VIR_CGROUP_CONTROLLER_FREEZER] = NULL,
|
|
||||||
[VIR_CGROUP_CONTROLLER_BLKIO] = NULL,
|
|
||||||
[VIR_CGROUP_CONTROLLER_SYSTEMD] = "/",
|
|
||||||
};
|
|
||||||
|
|
||||||
if (virCgroupNewSelf(&cgroup) < 0) {
|
if (virCgroupNewSelf(&cgroup) == 0) {
|
||||||
fprintf(stderr, "Cannot create cgroup for self\n");
|
fprintf(stderr, "Expected cgroup creation to fail.\n");
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = validateCgroup(cgroup, "", mountsLogind, linksLogind, placement);
|
ret = 0;
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
virCgroupFree(&cgroup);
|
virCgroupFree(&cgroup);
|
||||||
return ret;
|
return ret;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user