util: introduce cgroup v2 files

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>
This commit is contained in:
Pavel Hrdina 2018-09-18 17:48:33 +02:00
parent 87f71398fe
commit b4ddf5ae62
9 changed files with 112 additions and 1 deletions

View 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 \

View File

@ -1583,6 +1583,9 @@ virCgroupBackendRegister;
# util/vircgroupv1.h
virCgroupV1Register;
# util/vircgroupv2.h
virCgroupV2Register;
# util/virclosecallbacks.h
virCloseCallbacksGet;
virCloseCallbacksGetConn;

View 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 \

View 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);
}

View 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;

View 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;

View 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,

63
src/util/vircgroupv2.c Normal file
View File

@ -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__ */

27
src/util/vircgroupv2.h Normal file
View File

@ -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__ */