|
|
c313de |
From 81bf1dade08ee40a9ecc32f5d384fdf35e3edbf3 Mon Sep 17 00:00:00 2001
|
|
|
c313de |
Message-Id: <81bf1dade08ee40a9ecc32f5d384fdf35e3edbf3@dist-git>
|
|
|
c313de |
From: Pavel Hrdina <phrdina@redhat.com>
|
|
|
c313de |
Date: Mon, 1 Jul 2019 17:06:24 +0200
|
|
|
c313de |
Subject: [PATCH] vircgroup: detect available backend for cgroup
|
|
|
c313de |
MIME-Version: 1.0
|
|
|
c313de |
Content-Type: text/plain; charset=UTF-8
|
|
|
c313de |
Content-Transfer-Encoding: 8bit
|
|
|
c313de |
|
|
|
c313de |
We need to update one test-case because now new cgroup object will be
|
|
|
c313de |
created only if there is any cgroup backend available.
|
|
|
c313de |
|
|
|
c313de |
Reviewed-by: Ján Tomko <jtomko@redhat.com>
|
|
|
c313de |
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
|
|
|
c313de |
(cherry picked from commit f60af21594801088fff217aebf33b58825bd8a80)
|
|
|
c313de |
|
|
|
c313de |
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1689297
|
|
|
c313de |
|
|
|
c313de |
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
|
|
|
c313de |
Message-Id: <2815d54d5cffdef81bf9a41136b2d6a7e1d75b55.1561993100.git.phrdina@redhat.com>
|
|
|
c313de |
Reviewed-by: Ján Tomko <jtomko@redhat.com>
|
|
|
c313de |
---
|
|
|
c313de |
src/util/vircgroup.c | 18 ++++++++++++++++++
|
|
|
c313de |
src/util/vircgrouppriv.h | 3 +++
|
|
|
c313de |
tests/vircgrouptest.c | 38 +++-----------------------------------
|
|
|
c313de |
3 files changed, 24 insertions(+), 35 deletions(-)
|
|
|
c313de |
|
|
|
c313de |
diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c
|
|
|
c313de |
index 47a3b9ed58..15d0cb65ac 100644
|
|
|
c313de |
--- a/src/util/vircgroup.c
|
|
|
c313de |
+++ b/src/util/vircgroup.c
|
|
|
c313de |
@@ -711,10 +711,28 @@ virCgroupDetect(virCgroupPtr group,
|
|
|
c313de |
virCgroupPtr parent)
|
|
|
c313de |
{
|
|
|
c313de |
int rc;
|
|
|
c313de |
+ size_t i;
|
|
|
c313de |
+ virCgroupBackendPtr *backends = virCgroupBackendGetAll();
|
|
|
c313de |
|
|
|
c313de |
VIR_DEBUG("group=%p controllers=%d path=%s parent=%p",
|
|
|
c313de |
group, controllers, path, parent);
|
|
|
c313de |
|
|
|
c313de |
+ if (!backends)
|
|
|
c313de |
+ return -1;
|
|
|
c313de |
+
|
|
|
c313de |
+ for (i = 0; i < VIR_CGROUP_BACKEND_TYPE_LAST; i++) {
|
|
|
c313de |
+ if (backends[i] && backends[i]->available()) {
|
|
|
c313de |
+ group->backend = backends[i];
|
|
|
c313de |
+ break;
|
|
|
c313de |
+ }
|
|
|
c313de |
+ }
|
|
|
c313de |
+
|
|
|
c313de |
+ if (!group->backend) {
|
|
|
c313de |
+ virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
c313de |
+ _("no cgroup backend available"));
|
|
|
c313de |
+ return -1;
|
|
|
c313de |
+ }
|
|
|
c313de |
+
|
|
|
c313de |
if (parent) {
|
|
|
c313de |
if (virCgroupCopyMounts(group, parent) < 0)
|
|
|
c313de |
return -1;
|
|
|
c313de |
diff --git a/src/util/vircgrouppriv.h b/src/util/vircgrouppriv.h
|
|
|
c313de |
index 046c96c52c..2caa966fee 100644
|
|
|
c313de |
--- a/src/util/vircgrouppriv.h
|
|
|
c313de |
+++ b/src/util/vircgrouppriv.h
|
|
|
c313de |
@@ -30,6 +30,7 @@
|
|
|
c313de |
# define __VIR_CGROUP_PRIV_H__
|
|
|
c313de |
|
|
|
c313de |
# include "vircgroup.h"
|
|
|
c313de |
+# include "vircgroupbackend.h"
|
|
|
c313de |
|
|
|
c313de |
struct _virCgroupController {
|
|
|
c313de |
int type;
|
|
|
c313de |
@@ -47,6 +48,8 @@ typedef virCgroupController *virCgroupControllerPtr;
|
|
|
c313de |
struct _virCgroup {
|
|
|
c313de |
char *path;
|
|
|
c313de |
|
|
|
c313de |
+ virCgroupBackendPtr backend;
|
|
|
c313de |
+
|
|
|
c313de |
virCgroupController controllers[VIR_CGROUP_CONTROLLER_LAST];
|
|
|
c313de |
};
|
|
|
c313de |
|
|
|
c313de |
diff --git a/tests/vircgrouptest.c b/tests/vircgrouptest.c
|
|
|
c313de |
index 5031a2973d..588a6e824d 100644
|
|
|
c313de |
--- a/tests/vircgrouptest.c
|
|
|
c313de |
+++ b/tests/vircgrouptest.c
|
|
|
c313de |
@@ -114,16 +114,6 @@ const char *mountsAllInOne[VIR_CGROUP_CONTROLLER_LAST] = {
|
|
|
c313de |
[VIR_CGROUP_CONTROLLER_BLKIO] = "/not/really/sys/fs/cgroup",
|
|
|
c313de |
[VIR_CGROUP_CONTROLLER_SYSTEMD] = NULL,
|
|
|
c313de |
};
|
|
|
c313de |
-const char *mountsLogind[VIR_CGROUP_CONTROLLER_LAST] = {
|
|
|
c313de |
- [VIR_CGROUP_CONTROLLER_CPU] = NULL,
|
|
|
c313de |
- [VIR_CGROUP_CONTROLLER_CPUACCT] = NULL,
|
|
|
c313de |
- [VIR_CGROUP_CONTROLLER_CPUSET] = NULL,
|
|
|
c313de |
- [VIR_CGROUP_CONTROLLER_MEMORY] = NULL,
|
|
|
c313de |
- [VIR_CGROUP_CONTROLLER_DEVICES] = NULL,
|
|
|
c313de |
- [VIR_CGROUP_CONTROLLER_FREEZER] = NULL,
|
|
|
c313de |
- [VIR_CGROUP_CONTROLLER_BLKIO] = NULL,
|
|
|
c313de |
- [VIR_CGROUP_CONTROLLER_SYSTEMD] = "/not/really/sys/fs/cgroup/systemd",
|
|
|
c313de |
-};
|
|
|
c313de |
|
|
|
c313de |
const char *links[VIR_CGROUP_CONTROLLER_LAST] = {
|
|
|
c313de |
[VIR_CGROUP_CONTROLLER_CPU] = "/not/really/sys/fs/cgroup/cpu",
|
|
|
c313de |
@@ -147,17 +137,6 @@ const char *linksAllInOne[VIR_CGROUP_CONTROLLER_LAST] = {
|
|
|
c313de |
[VIR_CGROUP_CONTROLLER_SYSTEMD] = NULL,
|
|
|
c313de |
};
|
|
|
c313de |
|
|
|
c313de |
-const char *linksLogind[VIR_CGROUP_CONTROLLER_LAST] = {
|
|
|
c313de |
- [VIR_CGROUP_CONTROLLER_CPU] = NULL,
|
|
|
c313de |
- [VIR_CGROUP_CONTROLLER_CPUACCT] = NULL,
|
|
|
c313de |
- [VIR_CGROUP_CONTROLLER_CPUSET] = NULL,
|
|
|
c313de |
- [VIR_CGROUP_CONTROLLER_MEMORY] = NULL,
|
|
|
c313de |
- [VIR_CGROUP_CONTROLLER_DEVICES] = NULL,
|
|
|
c313de |
- [VIR_CGROUP_CONTROLLER_FREEZER] = NULL,
|
|
|
c313de |
- [VIR_CGROUP_CONTROLLER_BLKIO] = NULL,
|
|
|
c313de |
- [VIR_CGROUP_CONTROLLER_SYSTEMD] = NULL,
|
|
|
c313de |
-};
|
|
|
c313de |
-
|
|
|
c313de |
|
|
|
c313de |
struct _detectMountsData {
|
|
|
c313de |
const char *file;
|
|
|
c313de |
@@ -555,24 +534,13 @@ static int testCgroupNewForSelfLogind(const void *args ATTRIBUTE_UNUSED)
|
|
|
c313de |
{
|
|
|
c313de |
virCgroupPtr cgroup = NULL;
|
|
|
c313de |
int ret = -1;
|
|
|
c313de |
- const char *placement[VIR_CGROUP_CONTROLLER_LAST] = {
|
|
|
c313de |
- [VIR_CGROUP_CONTROLLER_CPU] = NULL,
|
|
|
c313de |
- [VIR_CGROUP_CONTROLLER_CPUACCT] = NULL,
|
|
|
c313de |
- [VIR_CGROUP_CONTROLLER_CPUSET] = NULL,
|
|
|
c313de |
- [VIR_CGROUP_CONTROLLER_MEMORY] = NULL,
|
|
|
c313de |
- [VIR_CGROUP_CONTROLLER_DEVICES] = NULL,
|
|
|
c313de |
- [VIR_CGROUP_CONTROLLER_FREEZER] = NULL,
|
|
|
c313de |
- [VIR_CGROUP_CONTROLLER_BLKIO] = NULL,
|
|
|
c313de |
- [VIR_CGROUP_CONTROLLER_SYSTEMD] = "/",
|
|
|
c313de |
- };
|
|
|
c313de |
|
|
|
c313de |
- if (virCgroupNewSelf(&cgroup) < 0) {
|
|
|
c313de |
- fprintf(stderr, "Cannot create cgroup for self\n");
|
|
|
c313de |
+ if (virCgroupNewSelf(&cgroup) == 0) {
|
|
|
c313de |
+ fprintf(stderr, "Expected cgroup creation to fail.\n");
|
|
|
c313de |
goto cleanup;
|
|
|
c313de |
}
|
|
|
c313de |
|
|
|
c313de |
- ret = validateCgroup(cgroup, "", mountsLogind, linksLogind, placement);
|
|
|
c313de |
-
|
|
|
c313de |
+ ret = 0;
|
|
|
c313de |
cleanup:
|
|
|
c313de |
virCgroupFree(&cgroup);
|
|
|
c313de |
return ret;
|
|
|
c313de |
--
|
|
|
c313de |
2.22.0
|
|
|
c313de |
|