render / rpms / libvirt

Forked from rpms/libvirt 9 months ago
Clone
c480ed
From 04bdbfa106768447822f3e8eeb2946e1f7bfb2b5 Mon Sep 17 00:00:00 2001
c480ed
Message-Id: <04bdbfa106768447822f3e8eeb2946e1f7bfb2b5@dist-git>
c480ed
From: Pavel Hrdina <phrdina@redhat.com>
c480ed
Date: Mon, 1 Jul 2019 17:07:12 +0200
c480ed
Subject: [PATCH] util: introduce cgroup v2 files
c480ed
MIME-Version: 1.0
c480ed
Content-Type: text/plain; charset=UTF-8
c480ed
Content-Transfer-Encoding: 8bit
c480ed
c480ed
Place cgroup v2 backend type before cgroup v1 to make it obvious
c480ed
that cgroup v2 is preferred implementation.
c480ed
c480ed
Following patches will introduce support for hybrid configuration
c480ed
which will allow us to use both at the same time, but we should
c480ed
prefer cgroup v2 regardless.
c480ed
c480ed
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
c480ed
(cherry picked from commit b4ddf5ae62ee3a50c7ead1e00914a141e5798096)
c480ed
c480ed
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1689297
c480ed
c480ed
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
c480ed
Message-Id: <fcbffeda541380f2e11e42f192b80276153bc84f.1561993100.git.phrdina@redhat.com>
c480ed
Reviewed-by: Ján Tomko <jtomko@redhat.com>
c480ed
---
c480ed
 src/Makefile.am             |  1 +
c480ed
 src/libvirt_private.syms    |  3 ++
c480ed
 src/util/Makefile.inc.am    |  2 ++
c480ed
 src/util/vircgroup.c        |  3 ++
c480ed
 src/util/vircgroupbackend.c |  2 ++
c480ed
 src/util/vircgroupbackend.h |  3 +-
c480ed
 src/util/vircgrouppriv.h    |  9 ++++++
c480ed
 src/util/vircgroupv2.c      | 63 +++++++++++++++++++++++++++++++++++++
c480ed
 src/util/vircgroupv2.h      | 27 ++++++++++++++++
c480ed
 9 files changed, 112 insertions(+), 1 deletion(-)
c480ed
 create mode 100644 src/util/vircgroupv2.c
c480ed
 create mode 100644 src/util/vircgroupv2.h
c480ed
c480ed
diff --git a/src/Makefile.am b/src/Makefile.am
c480ed
index 0def0a3b19..cc8e29a45a 100644
c480ed
--- a/src/Makefile.am
c480ed
+++ b/src/Makefile.am
c480ed
@@ -680,6 +680,7 @@ libvirt_setuid_rpc_client_la_SOURCES = \
c480ed
 		util/vircgroup.c \
c480ed
 		util/vircgroupbackend.c \
c480ed
 		util/vircgroupv1.c \
c480ed
+		util/vircgroupv2.c \
c480ed
 		util/vircommand.c \
c480ed
 		util/virconf.c \
c480ed
 		util/virdbus.c \
c480ed
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
c480ed
index b144955154..8132f9664b 100644
c480ed
--- a/src/libvirt_private.syms
c480ed
+++ b/src/libvirt_private.syms
c480ed
@@ -1598,6 +1598,9 @@ virCgroupBackendRegister;
c480ed
 # util/vircgroupv1.h
c480ed
 virCgroupV1Register;
c480ed
 
c480ed
+# util/vircgroupv2.h
c480ed
+virCgroupV2Register;
c480ed
+
c480ed
 # util/virclosecallbacks.h
c480ed
 virCloseCallbacksGet;
c480ed
 virCloseCallbacksGetConn;
c480ed
diff --git a/src/util/Makefile.inc.am b/src/util/Makefile.inc.am
c480ed
index 725ece98e9..24a98632a3 100644
c480ed
--- a/src/util/Makefile.inc.am
c480ed
+++ b/src/util/Makefile.inc.am
c480ed
@@ -27,6 +27,8 @@ UTIL_SOURCES = \
c480ed
 	util/vircgroupbackend.h \
c480ed
 	util/vircgroupv1.c \
c480ed
 	util/vircgroupv1.h \
c480ed
+	util/vircgroupv2.c \
c480ed
+	util/vircgroupv2.h \
c480ed
 	util/virclosecallbacks.c \
c480ed
 	util/virclosecallbacks.h \
c480ed
 	util/vircommand.c \
c480ed
diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c
c480ed
index 7ec1399bc6..42930582db 100644
c480ed
--- a/src/util/vircgroup.c
c480ed
+++ b/src/util/vircgroup.c
c480ed
@@ -1240,6 +1240,9 @@ virCgroupFree(virCgroupPtr *group)
c480ed
         VIR_FREE((*group)->legacy[i].placement);
c480ed
     }
c480ed
 
c480ed
+    VIR_FREE((*group)->unified.mountPoint);
c480ed
+    VIR_FREE((*group)->unified.placement);
c480ed
+
c480ed
     VIR_FREE((*group)->path);
c480ed
     VIR_FREE(*group);
c480ed
 }
c480ed
diff --git a/src/util/vircgroupbackend.c b/src/util/vircgroupbackend.c
c480ed
index d854c9711d..79fe6cb73d 100644
c480ed
--- a/src/util/vircgroupbackend.c
c480ed
+++ b/src/util/vircgroupbackend.c
c480ed
@@ -21,6 +21,7 @@
c480ed
 
c480ed
 #include "vircgroupbackend.h"
c480ed
 #include "vircgroupv1.h"
c480ed
+#include "vircgroupv2.h"
c480ed
 #include "virerror.h"
c480ed
 #include "virthread.h"
c480ed
 
c480ed
@@ -28,6 +29,7 @@
c480ed
 
c480ed
 VIR_ENUM_DECL(virCgroupBackend);
c480ed
 VIR_ENUM_IMPL(virCgroupBackend, VIR_CGROUP_BACKEND_TYPE_LAST,
c480ed
+              "cgroup V2",
c480ed
               "cgroup V1");
c480ed
 
c480ed
 static virOnceControl virCgroupBackendOnce = VIR_ONCE_CONTROL_INITIALIZER;
c480ed
diff --git a/src/util/vircgroupbackend.h b/src/util/vircgroupbackend.h
c480ed
index 1c5744ef76..b1f19233e4 100644
c480ed
--- a/src/util/vircgroupbackend.h
c480ed
+++ b/src/util/vircgroupbackend.h
c480ed
@@ -50,7 +50,8 @@ typedef enum {
c480ed
 } virCgroupBackendTaskFlags;
c480ed
 
c480ed
 typedef enum {
c480ed
-    VIR_CGROUP_BACKEND_TYPE_V1 = 0,
c480ed
+    VIR_CGROUP_BACKEND_TYPE_V2 = 0,
c480ed
+    VIR_CGROUP_BACKEND_TYPE_V1,
c480ed
     VIR_CGROUP_BACKEND_TYPE_LAST,
c480ed
 } virCgroupBackendType;
c480ed
 
c480ed
diff --git a/src/util/vircgrouppriv.h b/src/util/vircgrouppriv.h
c480ed
index c50a25f195..4a0d75ddbc 100644
c480ed
--- a/src/util/vircgrouppriv.h
c480ed
+++ b/src/util/vircgrouppriv.h
c480ed
@@ -45,12 +45,21 @@ struct _virCgroupV1Controller {
c480ed
 typedef struct _virCgroupV1Controller virCgroupV1Controller;
c480ed
 typedef virCgroupV1Controller *virCgroupV1ControllerPtr;
c480ed
 
c480ed
+struct _virCgroupV2Controller {
c480ed
+    int controllers;
c480ed
+    char *mountPoint;
c480ed
+    char *placement;
c480ed
+};
c480ed
+typedef struct _virCgroupV2Controller virCgroupV2Controller;
c480ed
+typedef virCgroupV2Controller *virCgroupV2ControllerPtr;
c480ed
+
c480ed
 struct _virCgroup {
c480ed
     char *path;
c480ed
 
c480ed
     virCgroupBackendPtr backend;
c480ed
 
c480ed
     virCgroupV1Controller legacy[VIR_CGROUP_CONTROLLER_LAST];
c480ed
+    virCgroupV2Controller unified;
c480ed
 };
c480ed
 
c480ed
 int virCgroupSetValueStr(virCgroupPtr group,
c480ed
diff --git a/src/util/vircgroupv2.c b/src/util/vircgroupv2.c
c480ed
new file mode 100644
c480ed
index 0000000000..23bf81dae2
c480ed
--- /dev/null
c480ed
+++ b/src/util/vircgroupv2.c
c480ed
@@ -0,0 +1,63 @@
c480ed
+/*
c480ed
+ * vircgroupv2.c: methods for cgroups v2 backend
c480ed
+ *
c480ed
+ * Copyright (C) 2018 Red Hat, Inc.
c480ed
+ *
c480ed
+ * This library is free software; you can redistribute it and/or
c480ed
+ * modify it under the terms of the GNU Lesser General Public
c480ed
+ * License as published by the Free Software Foundation; either
c480ed
+ * version 2.1 of the License, or (at your option) any later version.
c480ed
+ *
c480ed
+ * This library is distributed in the hope that it will be useful,
c480ed
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
c480ed
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
c480ed
+ * Lesser General Public License for more details.
c480ed
+ *
c480ed
+ * You should have received a copy of the GNU Lesser General Public
c480ed
+ * License along with this library.  If not, see
c480ed
+ * <http://www.gnu.org/licenses/>.
c480ed
+ */
c480ed
+#include <config.h>
c480ed
+
c480ed
+#include "internal.h"
c480ed
+
c480ed
+#define __VIR_CGROUP_ALLOW_INCLUDE_PRIV_H__
c480ed
+#include "vircgrouppriv.h"
c480ed
+#undef __VIR_CGROUP_ALLOW_INCLUDE_PRIV_H__
c480ed
+
c480ed
+#include "vircgroup.h"
c480ed
+#include "vircgroupbackend.h"
c480ed
+#include "vircgroupv2.h"
c480ed
+#include "virlog.h"
c480ed
+
c480ed
+VIR_LOG_INIT("util.cgroup");
c480ed
+
c480ed
+#define VIR_FROM_THIS VIR_FROM_CGROUP
c480ed
+
c480ed
+VIR_ENUM_DECL(virCgroupV2Controller);
c480ed
+VIR_ENUM_IMPL(virCgroupV2Controller, VIR_CGROUP_CONTROLLER_LAST,
c480ed
+              "cpu", "cpuacct", "cpuset", "memory", "devices",
c480ed
+              "freezer", "io", "net_cls", "perf_event", "name=systemd");
c480ed
+
c480ed
+#ifdef __linux__
c480ed
+
c480ed
+virCgroupBackend virCgroupV2Backend = {
c480ed
+    .type = VIR_CGROUP_BACKEND_TYPE_V2,
c480ed
+};
c480ed
+
c480ed
+
c480ed
+void
c480ed
+virCgroupV2Register(void)
c480ed
+{
c480ed
+    virCgroupBackendRegister(&virCgroupV2Backend);
c480ed
+}
c480ed
+
c480ed
+#else /* !__linux__ */
c480ed
+
c480ed
+void
c480ed
+virCgroupV2Register(void)
c480ed
+{
c480ed
+    VIR_INFO("Control groups not supported on this platform");
c480ed
+}
c480ed
+
c480ed
+#endif /* !__linux__ */
c480ed
diff --git a/src/util/vircgroupv2.h b/src/util/vircgroupv2.h
c480ed
new file mode 100644
c480ed
index 0000000000..a5d0bd0978
c480ed
--- /dev/null
c480ed
+++ b/src/util/vircgroupv2.h
c480ed
@@ -0,0 +1,27 @@
c480ed
+/*
c480ed
+ * vircgroupv2.h: methods for cgroups v2 backend
c480ed
+ *
c480ed
+ * Copyright (C) 2018 Red Hat, Inc.
c480ed
+ *
c480ed
+ * This library is free software; you can redistribute it and/or
c480ed
+ * modify it under the terms of the GNU Lesser General Public
c480ed
+ * License as published by the Free Software Foundation; either
c480ed
+ * version 2.1 of the License, or (at your option) any later version.
c480ed
+ *
c480ed
+ * This library is distributed in the hope that it will be useful,
c480ed
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
c480ed
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
c480ed
+ * Lesser General Public License for more details.
c480ed
+ *
c480ed
+ * You should have received a copy of the GNU Lesser General Public
c480ed
+ * License along with this library.  If not, see
c480ed
+ * <http://www.gnu.org/licenses/>.
c480ed
+ */
c480ed
+
c480ed
+#ifndef __VIR_CGROUP_V2_H__
c480ed
+# define __VIR_CGROUP_V2_H__
c480ed
+
c480ed
+void
c480ed
+virCgroupV2Register(void);
c480ed
+
c480ed
+#endif /* __VIR_CGROUP_V2_H__ */
c480ed
-- 
c480ed
2.22.0
c480ed