]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
util: introduce cgroup v2 files
authorPavel Hrdina <phrdina@redhat.com>
Tue, 18 Sep 2018 15:48:33 +0000 (17:48 +0200)
committerPavel Hrdina <phrdina@redhat.com>
Fri, 5 Oct 2018 13:53:29 +0000 (15:53 +0200)
Place cgroup v2 backend type before cgroup v1 to make it obvious
that cgroup v2 is preferred implementation.

Following patches will introduce support for hybrid configuration
which will allow us to use both at the same time, but we should
prefer cgroup v2 regardless.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
src/Makefile.am
src/libvirt_private.syms
src/util/Makefile.inc.am
src/util/vircgroup.c
src/util/vircgroupbackend.c
src/util/vircgroupbackend.h
src/util/vircgrouppriv.h
src/util/vircgroupv2.c [new file with mode: 0644]
src/util/vircgroupv2.h [new file with mode: 0644]

index f515569fd544d9b196233ac143e5b6b60afbded8..33ff280d78fd861632f461f6ccefc35328d1ba2c 100644 (file)
@@ -675,6 +675,7 @@ libvirt_setuid_rpc_client_la_SOURCES = \
                util/vircgroup.c \
                util/vircgroupbackend.c \
                util/vircgroupv1.c \
+               util/vircgroupv2.c \
                util/vircommand.c \
                util/virconf.c \
                util/virdbus.c \
index 92363913e3574e36f522205c9824fee32253a69d..335210c31d1156f213a3a0874e25fb0787d62b2d 100644 (file)
@@ -1583,6 +1583,9 @@ virCgroupBackendRegister;
 # util/vircgroupv1.h
 virCgroupV1Register;
 
+# util/vircgroupv2.h
+virCgroupV2Register;
+
 # util/virclosecallbacks.h
 virCloseCallbacksGet;
 virCloseCallbacksGetConn;
index ad3be918679d478a341a156108a58a087d1b849f..cffbb357bc480c6fed270964dc4fde515724d5c4 100644 (file)
@@ -27,6 +27,8 @@ UTIL_SOURCES = \
        util/vircgroupbackend.h \
        util/vircgroupv1.c \
        util/vircgroupv1.h \
+       util/vircgroupv2.c \
+       util/vircgroupv2.h \
        util/virclosecallbacks.c \
        util/virclosecallbacks.h \
        util/vircommand.c \
index 548c873da8ac8e14a5bfa18b86b62ba7d457accc..1097b1f998c65bd4f83b6d3378c235067c6f86a6 100644 (file)
@@ -1236,6 +1236,9 @@ virCgroupFree(virCgroupPtr *group)
         VIR_FREE((*group)->legacy[i].placement);
     }
 
+    VIR_FREE((*group)->unified.mountPoint);
+    VIR_FREE((*group)->unified.placement);
+
     VIR_FREE((*group)->path);
     VIR_FREE(*group);
 }
index d854c9711d869858fd51621fb75d26dc76b36f40..79fe6cb73d91557dce512550ea9a0855f46f10c3 100644 (file)
@@ -21,6 +21,7 @@
 
 #include "vircgroupbackend.h"
 #include "vircgroupv1.h"
+#include "vircgroupv2.h"
 #include "virerror.h"
 #include "virthread.h"
 
@@ -28,6 +29,7 @@
 
 VIR_ENUM_DECL(virCgroupBackend);
 VIR_ENUM_IMPL(virCgroupBackend, VIR_CGROUP_BACKEND_TYPE_LAST,
+              "cgroup V2",
               "cgroup V1");
 
 static virOnceControl virCgroupBackendOnce = VIR_ONCE_CONTROL_INITIALIZER;
index 1c5744ef76b97d342a87f5873dd86e6e4554fe5a..b1f19233e4835897a22bc4ac6969153b6b962772 100644 (file)
@@ -50,7 +50,8 @@ typedef enum {
 } virCgroupBackendTaskFlags;
 
 typedef enum {
-    VIR_CGROUP_BACKEND_TYPE_V1 = 0,
+    VIR_CGROUP_BACKEND_TYPE_V2 = 0,
+    VIR_CGROUP_BACKEND_TYPE_V1,
     VIR_CGROUP_BACKEND_TYPE_LAST,
 } virCgroupBackendType;
 
index c50a25f1955d040b5d20564ae02b8e3f1f875db9..4a0d75ddbca2fb9a0e7a0914e03df427ffd6ef5b 100644 (file)
@@ -45,12 +45,21 @@ struct _virCgroupV1Controller {
 typedef struct _virCgroupV1Controller virCgroupV1Controller;
 typedef virCgroupV1Controller *virCgroupV1ControllerPtr;
 
+struct _virCgroupV2Controller {
+    int controllers;
+    char *mountPoint;
+    char *placement;
+};
+typedef struct _virCgroupV2Controller virCgroupV2Controller;
+typedef virCgroupV2Controller *virCgroupV2ControllerPtr;
+
 struct _virCgroup {
     char *path;
 
     virCgroupBackendPtr backend;
 
     virCgroupV1Controller legacy[VIR_CGROUP_CONTROLLER_LAST];
+    virCgroupV2Controller unified;
 };
 
 int virCgroupSetValueStr(virCgroupPtr group,
diff --git a/src/util/vircgroupv2.c b/src/util/vircgroupv2.c
new file mode 100644 (file)
index 0000000..23bf81d
--- /dev/null
@@ -0,0 +1,63 @@
+/*
+ * vircgroupv2.c: methods for cgroups v2 backend
+ *
+ * Copyright (C) 2018 Red Hat, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library.  If not, see
+ * <http://www.gnu.org/licenses/>.
+ */
+#include <config.h>
+
+#include "internal.h"
+
+#define __VIR_CGROUP_ALLOW_INCLUDE_PRIV_H__
+#include "vircgrouppriv.h"
+#undef __VIR_CGROUP_ALLOW_INCLUDE_PRIV_H__
+
+#include "vircgroup.h"
+#include "vircgroupbackend.h"
+#include "vircgroupv2.h"
+#include "virlog.h"
+
+VIR_LOG_INIT("util.cgroup");
+
+#define VIR_FROM_THIS VIR_FROM_CGROUP
+
+VIR_ENUM_DECL(virCgroupV2Controller);
+VIR_ENUM_IMPL(virCgroupV2Controller, VIR_CGROUP_CONTROLLER_LAST,
+              "cpu", "cpuacct", "cpuset", "memory", "devices",
+              "freezer", "io", "net_cls", "perf_event", "name=systemd");
+
+#ifdef __linux__
+
+virCgroupBackend virCgroupV2Backend = {
+    .type = VIR_CGROUP_BACKEND_TYPE_V2,
+};
+
+
+void
+virCgroupV2Register(void)
+{
+    virCgroupBackendRegister(&virCgroupV2Backend);
+}
+
+#else /* !__linux__ */
+
+void
+virCgroupV2Register(void)
+{
+    VIR_INFO("Control groups not supported on this platform");
+}
+
+#endif /* !__linux__ */
diff --git a/src/util/vircgroupv2.h b/src/util/vircgroupv2.h
new file mode 100644 (file)
index 0000000..a5d0bd0
--- /dev/null
@@ -0,0 +1,27 @@
+/*
+ * vircgroupv2.h: methods for cgroups v2 backend
+ *
+ * Copyright (C) 2018 Red Hat, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library.  If not, see
+ * <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __VIR_CGROUP_V2_H__
+# define __VIR_CGROUP_V2_H__
+
+void
+virCgroupV2Register(void);
+
+#endif /* __VIR_CGROUP_V2_H__ */