diff --git a/src/Makefile.am b/src/Makefile.am
index f515569fd544d9b196233ac143e5b6b60afbded8..33ff280d78fd861632f461f6ccefc35328d1ba2c 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 92363913e3574e36f522205c9824fee32253a69d..335210c31d1156f213a3a0874e25fb0787d62b2d 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 ad3be918679d478a341a156108a58a087d1b849f..cffbb357bc480c6fed270964dc4fde515724d5c4 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 548c873da8ac8e14a5bfa18b86b62ba7d457accc..1097b1f998c65bd4f83b6d3378c235067c6f86a6 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 d854c9711d869858fd51621fb75d26dc76b36f40..79fe6cb73d91557dce512550ea9a0855f46f10c3 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 1c5744ef76b97d342a87f5873dd86e6e4554fe5a..b1f19233e4835897a22bc4ac6969153b6b962772 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 c50a25f1955d040b5d20564ae02b8e3f1f875db9..4a0d75ddbca2fb9a0e7a0914e03df427ffd6ef5b 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 0000000000000000000000000000000000000000..23bf81dae2b6ac84508a7ecae3109ecd79a8dfba
--- /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
+ * .
+ */
+#include
+
+#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 0000000000000000000000000000000000000000..a5d0bd09789d1e013ce32e45b490c517791994c4
--- /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
+ * .
+ */
+
+#ifndef __VIR_CGROUP_V2_H__
+# define __VIR_CGROUP_V2_H__
+
+void
+virCgroupV2Register(void);
+
+#endif /* __VIR_CGROUP_V2_H__ */