2008-10-03 17:58:02 +00:00
|
|
|
/*
|
2012-12-03 15:03:47 +00:00
|
|
|
* vircgroup.h: methods for managing control cgroups
|
2008-10-03 17:58:02 +00:00
|
|
|
*
|
2015-03-11 11:15:29 +01:00
|
|
|
* Copyright (C) 2011-2015 Red Hat, Inc.
|
2008-10-03 17:58:02 +00:00
|
|
|
* Copyright IBM Corp. 2008
|
|
|
|
*
|
2012-07-27 17:39:53 +08:00
|
|
|
* 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
|
2012-09-20 16:30:55 -06:00
|
|
|
* License along with this library. If not, see
|
2012-07-27 17:39:53 +08:00
|
|
|
* <http://www.gnu.org/licenses/>.
|
2008-10-03 17:58:02 +00:00
|
|
|
*/
|
|
|
|
|
2019-06-18 11:12:54 -05:00
|
|
|
#pragma once
|
2008-10-03 17:58:02 +00:00
|
|
|
|
2019-06-18 11:12:54 -05:00
|
|
|
#include "virutil.h"
|
|
|
|
#include "virbitmap.h"
|
|
|
|
#include "virenum.h"
|
2013-01-16 10:53:04 +08:00
|
|
|
|
2018-06-12 13:46:04 +02:00
|
|
|
struct _virCgroup;
|
2018-06-12 13:47:10 +02:00
|
|
|
typedef struct _virCgroup virCgroup;
|
|
|
|
typedef virCgroup *virCgroupPtr;
|
2008-10-03 17:58:02 +00:00
|
|
|
|
2009-07-22 16:08:04 +01:00
|
|
|
enum {
|
|
|
|
VIR_CGROUP_CONTROLLER_CPU,
|
|
|
|
VIR_CGROUP_CONTROLLER_CPUACCT,
|
|
|
|
VIR_CGROUP_CONTROLLER_CPUSET,
|
|
|
|
VIR_CGROUP_CONTROLLER_MEMORY,
|
|
|
|
VIR_CGROUP_CONTROLLER_DEVICES,
|
2009-09-21 23:31:22 +09:00
|
|
|
VIR_CGROUP_CONTROLLER_FREEZER,
|
2011-02-08 10:41:17 -07:00
|
|
|
VIR_CGROUP_CONTROLLER_BLKIO,
|
2013-04-15 15:17:33 +01:00
|
|
|
VIR_CGROUP_CONTROLLER_NET_CLS,
|
|
|
|
VIR_CGROUP_CONTROLLER_PERF_EVENT,
|
2013-07-25 19:13:44 +01:00
|
|
|
VIR_CGROUP_CONTROLLER_SYSTEMD,
|
2009-07-22 16:08:04 +01:00
|
|
|
|
|
|
|
VIR_CGROUP_CONTROLLER_LAST
|
|
|
|
};
|
|
|
|
|
|
|
|
VIR_ENUM_DECL(virCgroupController);
|
2015-03-27 13:45:33 +01:00
|
|
|
/* Items of this enum are used later in virCgroupNew to create
|
|
|
|
* bit array stored in int. Like this:
|
|
|
|
* 1 << VIR_CGROUP_CONTROLLER_CPU
|
|
|
|
* Make sure we will not overflow */
|
2020-01-09 10:39:55 +00:00
|
|
|
G_STATIC_ASSERT(VIR_CGROUP_CONTROLLER_LAST < 8 * sizeof(int));
|
2009-07-22 16:08:04 +01:00
|
|
|
|
2015-04-07 08:28:05 -04:00
|
|
|
typedef enum {
|
|
|
|
VIR_CGROUP_THREAD_VCPU = 0,
|
|
|
|
VIR_CGROUP_THREAD_EMULATOR,
|
|
|
|
VIR_CGROUP_THREAD_IOTHREAD,
|
|
|
|
|
|
|
|
VIR_CGROUP_THREAD_LAST
|
|
|
|
} virCgroupThreadName;
|
|
|
|
|
2013-07-04 16:49:24 +01:00
|
|
|
bool virCgroupAvailable(void);
|
|
|
|
|
2013-03-28 16:33:22 +00:00
|
|
|
int virCgroupNewSelf(virCgroupPtr *group)
|
|
|
|
ATTRIBUTE_NONNULL(1);
|
2012-11-12 15:02:26 +08:00
|
|
|
|
2015-04-07 08:28:05 -04:00
|
|
|
int virCgroupNewThread(virCgroupPtr domain,
|
|
|
|
virCgroupThreadName nameval,
|
|
|
|
int id,
|
|
|
|
bool create,
|
|
|
|
virCgroupPtr *group)
|
|
|
|
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(5);
|
|
|
|
|
2016-08-04 23:36:38 +02:00
|
|
|
int virCgroupDelThread(virCgroupPtr cgroup,
|
|
|
|
virCgroupThreadName nameval,
|
|
|
|
int idx);
|
|
|
|
|
2013-07-19 11:13:05 +01:00
|
|
|
int virCgroupNewDetect(pid_t pid,
|
2013-07-24 17:31:25 +01:00
|
|
|
int controllers,
|
2013-07-19 11:13:05 +01:00
|
|
|
virCgroupPtr *group);
|
|
|
|
|
2017-07-21 15:51:03 +02:00
|
|
|
int
|
|
|
|
virCgroupNewDetectMachine(const char *name,
|
|
|
|
const char *drivername,
|
|
|
|
pid_t pid,
|
|
|
|
int controllers,
|
|
|
|
char *machinename,
|
|
|
|
virCgroupPtr *group)
|
2016-02-01 16:50:54 +01:00
|
|
|
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
|
2013-07-24 17:36:42 +01:00
|
|
|
|
2013-07-18 16:55:37 +01:00
|
|
|
int virCgroupNewMachine(const char *name,
|
|
|
|
const char *drivername,
|
|
|
|
const unsigned char *uuid,
|
|
|
|
const char *rootdir,
|
|
|
|
pid_t pidleader,
|
|
|
|
bool isContainer,
|
2014-11-11 17:38:43 +00:00
|
|
|
size_t nnicindexes,
|
|
|
|
int *nicindexes,
|
2013-07-18 16:55:37 +01:00
|
|
|
const char *partition,
|
|
|
|
int controllers,
|
2019-05-22 17:12:14 -06:00
|
|
|
unsigned int maxthreads,
|
2013-07-18 16:55:37 +01:00
|
|
|
virCgroupPtr *group)
|
|
|
|
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2)
|
2016-02-06 06:45:46 -05:00
|
|
|
ATTRIBUTE_NONNULL(3);
|
2013-07-18 16:55:37 +01:00
|
|
|
|
2016-02-01 16:50:54 +01:00
|
|
|
int virCgroupTerminateMachine(const char *name)
|
|
|
|
ATTRIBUTE_NONNULL(1);
|
2014-09-25 13:32:58 +02:00
|
|
|
|
2013-07-04 16:49:24 +01:00
|
|
|
bool virCgroupNewIgnoreError(void);
|
|
|
|
|
2018-07-30 11:06:31 +02:00
|
|
|
void virCgroupFree(virCgroupPtr *group);
|
2013-08-12 15:20:59 -06:00
|
|
|
|
|
|
|
bool virCgroupHasController(virCgroupPtr cgroup, int controller);
|
2011-03-07 16:41:40 -07:00
|
|
|
int virCgroupPathOfController(virCgroupPtr group,
|
2018-08-15 17:21:47 +02:00
|
|
|
unsigned int controller,
|
2011-03-07 16:41:40 -07:00
|
|
|
const char *key,
|
|
|
|
char **path);
|
|
|
|
|
2018-09-11 15:03:22 +02:00
|
|
|
int virCgroupAddProcess(virCgroupPtr group, pid_t pid);
|
|
|
|
int virCgroupAddMachineProcess(virCgroupPtr group, pid_t pid);
|
2018-09-25 00:54:04 +02:00
|
|
|
int virCgroupAddThread(virCgroupPtr group, pid_t pid);
|
2008-10-03 17:58:02 +00:00
|
|
|
|
2011-02-08 14:56:39 +08:00
|
|
|
int virCgroupSetBlkioWeight(virCgroupPtr group, unsigned int weight);
|
|
|
|
int virCgroupGetBlkioWeight(virCgroupPtr group, unsigned int *weight);
|
|
|
|
|
2014-02-14 18:48:59 +01:00
|
|
|
int virCgroupGetBlkioIoServiced(virCgroupPtr group,
|
|
|
|
long long *bytes_read,
|
|
|
|
long long *bytes_write,
|
|
|
|
long long *requests_read,
|
|
|
|
long long *requests_write);
|
|
|
|
int virCgroupGetBlkioIoDeviceServiced(virCgroupPtr group,
|
|
|
|
const char *path,
|
|
|
|
long long *bytes_read,
|
|
|
|
long long *bytes_write,
|
|
|
|
long long *requests_read,
|
|
|
|
long long *requests_write);
|
|
|
|
|
2011-11-08 19:00:34 +08:00
|
|
|
int virCgroupSetBlkioDeviceWeight(virCgroupPtr group,
|
|
|
|
const char *path,
|
|
|
|
unsigned int weight);
|
|
|
|
|
2013-12-11 16:29:50 +08:00
|
|
|
int virCgroupSetBlkioDeviceReadIops(virCgroupPtr group,
|
|
|
|
const char *path,
|
|
|
|
unsigned int riops);
|
|
|
|
|
|
|
|
int virCgroupSetBlkioDeviceWriteIops(virCgroupPtr group,
|
|
|
|
const char *path,
|
|
|
|
unsigned int wiops);
|
|
|
|
|
|
|
|
int virCgroupSetBlkioDeviceReadBps(virCgroupPtr group,
|
|
|
|
const char *path,
|
|
|
|
unsigned long long rbps);
|
|
|
|
|
|
|
|
int virCgroupSetBlkioDeviceWriteBps(virCgroupPtr group,
|
|
|
|
const char *path,
|
|
|
|
unsigned long long wbps);
|
|
|
|
|
2015-08-03 15:10:20 +02:00
|
|
|
int virCgroupGetBlkioDeviceWeight(virCgroupPtr group,
|
|
|
|
const char *path,
|
|
|
|
unsigned int *weight);
|
|
|
|
|
|
|
|
int virCgroupGetBlkioDeviceReadIops(virCgroupPtr group,
|
|
|
|
const char *path,
|
|
|
|
unsigned int *riops);
|
|
|
|
|
|
|
|
int virCgroupGetBlkioDeviceWriteIops(virCgroupPtr group,
|
|
|
|
const char *path,
|
|
|
|
unsigned int *wiops);
|
|
|
|
|
|
|
|
int virCgroupGetBlkioDeviceReadBps(virCgroupPtr group,
|
|
|
|
const char *path,
|
|
|
|
unsigned long long *rbps);
|
|
|
|
|
|
|
|
int virCgroupGetBlkioDeviceWriteBps(virCgroupPtr group,
|
|
|
|
const char *path,
|
|
|
|
unsigned long long *wbps);
|
|
|
|
|
2011-01-13 14:48:11 +05:30
|
|
|
int virCgroupSetMemory(virCgroupPtr group, unsigned long long kb);
|
2018-07-20 14:47:11 +02:00
|
|
|
int virCgroupGetMemoryStat(virCgroupPtr group,
|
|
|
|
unsigned long long *cache,
|
|
|
|
unsigned long long *activeAnon,
|
|
|
|
unsigned long long *inactiveAnon,
|
|
|
|
unsigned long long *activeFile,
|
|
|
|
unsigned long long *inactiveFile,
|
|
|
|
unsigned long long *unevictable);
|
2009-10-07 15:26:23 +02:00
|
|
|
int virCgroupGetMemoryUsage(virCgroupPtr group, unsigned long *kb);
|
2008-10-03 17:58:02 +00:00
|
|
|
|
2011-01-13 14:48:11 +05:30
|
|
|
int virCgroupSetMemoryHardLimit(virCgroupPtr group, unsigned long long kb);
|
|
|
|
int virCgroupGetMemoryHardLimit(virCgroupPtr group, unsigned long long *kb);
|
|
|
|
int virCgroupSetMemorySoftLimit(virCgroupPtr group, unsigned long long kb);
|
|
|
|
int virCgroupGetMemorySoftLimit(virCgroupPtr group, unsigned long long *kb);
|
2011-03-16 10:37:12 +05:30
|
|
|
int virCgroupSetMemSwapHardLimit(virCgroupPtr group, unsigned long long kb);
|
|
|
|
int virCgroupGetMemSwapHardLimit(virCgroupPtr group, unsigned long long *kb);
|
2012-11-12 15:02:25 +08:00
|
|
|
int virCgroupGetMemSwapUsage(virCgroupPtr group, unsigned long long *kb);
|
2010-10-12 16:50:53 +02:00
|
|
|
|
2011-03-08 20:13:18 -07:00
|
|
|
enum {
|
|
|
|
VIR_CGROUP_DEVICE_READ = 1,
|
|
|
|
VIR_CGROUP_DEVICE_WRITE = 2,
|
|
|
|
VIR_CGROUP_DEVICE_MKNOD = 4,
|
|
|
|
VIR_CGROUP_DEVICE_RW = VIR_CGROUP_DEVICE_READ | VIR_CGROUP_DEVICE_WRITE,
|
|
|
|
VIR_CGROUP_DEVICE_RWM = VIR_CGROUP_DEVICE_RW | VIR_CGROUP_DEVICE_MKNOD,
|
|
|
|
};
|
|
|
|
|
2014-06-20 13:33:16 +02:00
|
|
|
const char *virCgroupGetDevicePermsString(int perms);
|
|
|
|
|
2008-10-03 17:58:02 +00:00
|
|
|
int virCgroupDenyAllDevices(virCgroupPtr group);
|
|
|
|
|
2014-07-18 10:02:29 +02:00
|
|
|
int virCgroupAllowAllDevices(virCgroupPtr group, int perms);
|
|
|
|
|
2008-10-03 17:58:02 +00:00
|
|
|
int virCgroupAllowDevice(virCgroupPtr group,
|
|
|
|
char type,
|
|
|
|
int major,
|
2011-03-08 20:13:18 -07:00
|
|
|
int minor,
|
|
|
|
int perms);
|
2009-07-09 14:11:49 +01:00
|
|
|
int virCgroupAllowDevicePath(virCgroupPtr group,
|
2011-03-08 20:13:18 -07:00
|
|
|
const char *path,
|
2016-02-16 14:43:41 +01:00
|
|
|
int perms,
|
|
|
|
bool ignoreEacces);
|
2009-07-09 14:11:49 +01:00
|
|
|
|
|
|
|
int virCgroupDenyDevice(virCgroupPtr group,
|
|
|
|
char type,
|
|
|
|
int major,
|
2011-03-08 20:13:18 -07:00
|
|
|
int minor,
|
|
|
|
int perms);
|
2009-07-09 14:11:49 +01:00
|
|
|
int virCgroupDenyDevicePath(virCgroupPtr group,
|
2011-03-08 20:13:18 -07:00
|
|
|
const char *path,
|
2016-02-16 14:43:41 +01:00
|
|
|
int perms,
|
|
|
|
bool ignoreEacces);
|
2008-10-03 17:58:02 +00:00
|
|
|
|
2014-02-14 18:49:02 +01:00
|
|
|
int
|
|
|
|
virCgroupGetPercpuStats(virCgroupPtr group,
|
|
|
|
virTypedParameterPtr params,
|
|
|
|
unsigned int nparams,
|
|
|
|
int start_cpu,
|
2014-04-03 17:53:43 +02:00
|
|
|
unsigned int ncpus,
|
2015-12-14 15:10:22 +01:00
|
|
|
virBitmapPtr guestvcpus);
|
2014-02-14 18:49:02 +01:00
|
|
|
|
2014-02-14 18:49:01 +01:00
|
|
|
int
|
|
|
|
virCgroupGetDomainTotalCpuStats(virCgroupPtr group,
|
|
|
|
virTypedParameterPtr params,
|
|
|
|
int nparams);
|
|
|
|
|
2009-07-09 14:11:21 +01:00
|
|
|
int virCgroupSetCpuShares(virCgroupPtr group, unsigned long long shares);
|
|
|
|
int virCgroupGetCpuShares(virCgroupPtr group, unsigned long long *shares);
|
2008-10-08 16:28:48 +00:00
|
|
|
|
2011-07-21 15:21:05 +08:00
|
|
|
int virCgroupSetCpuCfsPeriod(virCgroupPtr group, unsigned long long cfs_period);
|
|
|
|
int virCgroupGetCpuCfsPeriod(virCgroupPtr group, unsigned long long *cfs_period);
|
|
|
|
|
|
|
|
int virCgroupSetCpuCfsQuota(virCgroupPtr group, long long cfs_quota);
|
|
|
|
int virCgroupGetCpuCfsQuota(virCgroupPtr group, long long *cfs_quota);
|
|
|
|
|
2009-03-06 14:44:04 +00:00
|
|
|
int virCgroupGetCpuacctUsage(virCgroupPtr group, unsigned long long *usage);
|
2012-03-02 10:54:23 +08:00
|
|
|
int virCgroupGetCpuacctPercpuUsage(virCgroupPtr group, char **usage);
|
2012-03-08 17:35:59 -07:00
|
|
|
int virCgroupGetCpuacctStat(virCgroupPtr group, unsigned long long *user,
|
|
|
|
unsigned long long *sys);
|
2009-03-06 14:44:04 +00:00
|
|
|
|
2009-09-21 23:31:22 +09:00
|
|
|
int virCgroupSetFreezerState(virCgroupPtr group, const char *state);
|
|
|
|
int virCgroupGetFreezerState(virCgroupPtr group, char **state);
|
|
|
|
|
2011-12-20 16:34:58 +08:00
|
|
|
int virCgroupSetCpusetMems(virCgroupPtr group, const char *mems);
|
|
|
|
int virCgroupGetCpusetMems(virCgroupPtr group, char **mems);
|
|
|
|
|
2015-03-11 11:15:29 +01:00
|
|
|
int virCgroupSetCpusetMemoryMigrate(virCgroupPtr group, bool migrate);
|
|
|
|
int virCgroupGetCpusetMemoryMigrate(virCgroupPtr group, bool *migrate);
|
|
|
|
|
2012-08-21 17:18:30 +08:00
|
|
|
int virCgroupSetCpusetCpus(virCgroupPtr group, const char *cpus);
|
|
|
|
int virCgroupGetCpusetCpus(virCgroupPtr group, char **cpus);
|
|
|
|
|
2008-10-03 17:58:02 +00:00
|
|
|
int virCgroupRemove(virCgroupPtr group);
|
|
|
|
|
2011-02-22 17:33:59 +00:00
|
|
|
int virCgroupKillRecursive(virCgroupPtr group, int signum);
|
|
|
|
int virCgroupKillPainfully(virCgroupPtr group);
|
|
|
|
|
2016-01-22 16:07:18 +00:00
|
|
|
int virCgroupBindMount(virCgroupPtr group,
|
|
|
|
const char *oldroot,
|
|
|
|
const char *mountopts);
|
2013-04-05 12:48:47 +01:00
|
|
|
|
2013-09-13 16:03:14 +02:00
|
|
|
bool virCgroupSupportsCpuBW(virCgroupPtr cgroup);
|
|
|
|
|
2014-02-24 12:23:33 +00:00
|
|
|
int virCgroupSetOwner(virCgroupPtr cgroup,
|
|
|
|
uid_t uid,
|
|
|
|
gid_t gid,
|
|
|
|
int controllers);
|
|
|
|
|
2014-12-13 09:56:00 +01:00
|
|
|
int virCgroupHasEmptyTasks(virCgroupPtr cgroup, int controller);
|
|
|
|
|
2015-03-31 11:39:13 +02:00
|
|
|
bool virCgroupControllerAvailable(int controller);
|