[PATCH 01/53] util: introduce cgroup v2 files

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxx>
---
 src/Makefile.am             |  1 +
 src/libvirt_private.syms    |  3 ++
 src/util/Makefile.inc.am    |  2 ++
 src/util/vircgroup.c        |  3 ++
 src/util/vircgroupbackend.c |  2 ++
 src/util/vircgroupbackend.h |  3 +-
 src/util/vircgrouppriv.h    |  9 ++++++
 src/util/vircgroupv2.c      | 63 +++++++++++++++++++++++++++++++++++++
 src/util/vircgroupv2.h      | 27 ++++++++++++++++
 9 files changed, 112 insertions(+), 1 deletion(-)
 create mode 100644 src/util/vircgroupv2.c
 create mode 100644 src/util/vircgroupv2.h

diff --git a/src/Makefile.am b/src/Makefile.am
index f515569fd5..33ff280d78 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -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 \
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 92363913e3..335210c31d 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -1583,6 +1583,9 @@ virCgroupBackendRegister;
 # util/vircgroupv1.h
 virCgroupV1Register;
 
+# util/vircgroupv2.h
+virCgroupV2Register;
+
 # util/virclosecallbacks.h
 virCloseCallbacksGet;
 virCloseCallbacksGetConn;
diff --git a/src/util/Makefile.inc.am b/src/util/Makefile.inc.am
index ad3be91867..cffbb357bc 100644
--- a/src/util/Makefile.inc.am
+++ b/src/util/Makefile.inc.am
@@ -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 \
diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c
index 548c873da8..1097b1f998 100644
--- a/src/util/vircgroup.c
+++ b/src/util/vircgroup.c
@@ -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);
 }
diff --git a/src/util/vircgroupbackend.c b/src/util/vircgroupbackend.c
index d854c9711d..79fe6cb73d 100644
--- a/src/util/vircgroupbackend.c
+++ b/src/util/vircgroupbackend.c
@@ -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;
diff --git a/src/util/vircgroupbackend.h b/src/util/vircgroupbackend.h
index 1c5744ef76..b1f19233e4 100644
--- a/src/util/vircgroupbackend.h
+++ b/src/util/vircgroupbackend.h
@@ -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;
 
diff --git a/src/util/vircgrouppriv.h b/src/util/vircgrouppriv.h
index c50a25f195..4a0d75ddbc 100644
--- a/src/util/vircgrouppriv.h
+++ b/src/util/vircgrouppriv.h
@@ -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
index 0000000000..23bf81dae2
--- /dev/null
+++ b/src/util/vircgroupv2.c
@@ -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
index 0000000000..a5d0bd0978
--- /dev/null
+++ b/src/util/vircgroupv2.h
@@ -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__ */
-- 
2.17.1

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux