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 10:15:29 +00:00
|
|
|
* Copyright (C) 2011-2015 Red Hat, Inc.
|
2008-10-03 17:58:02 +00:00
|
|
|
* Copyright IBM Corp. 2008
|
|
|
|
*
|
2012-07-27 09:39:53 +00: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 22:30:55 +00:00
|
|
|
* License along with this library. If not, see
|
2012-07-27 09:39:53 +00:00
|
|
|
* <http://www.gnu.org/licenses/>.
|
2008-10-03 17:58:02 +00:00
|
|
|
*/
|
|
|
|
|
2019-06-18 16:12:54 +00:00
|
|
|
#pragma once
|
2008-10-03 17:58:02 +00:00
|
|
|
|
2019-06-18 16:12:54 +00:00
|
|
|
#include "virutil.h"
|
|
|
|
#include "virbitmap.h"
|
|
|
|
#include "virenum.h"
|
2013-01-16 02:53:04 +00:00
|
|
|
|
2018-06-12 11:46:04 +00:00
|
|
|
struct _virCgroup;
|
2018-06-12 11:47:10 +00:00
|
|
|
typedef struct _virCgroup virCgroup;
|
|
|
|
typedef virCgroup *virCgroupPtr;
|
2008-10-03 17:58:02 +00:00
|
|
|
|
2009-07-22 15:08:04 +00: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 14:31:22 +00:00
|
|
|
VIR_CGROUP_CONTROLLER_FREEZER,
|
2011-02-08 17:41:17 +00:00
|
|
|
VIR_CGROUP_CONTROLLER_BLKIO,
|
2013-04-15 14:17:33 +00:00
|
|
|
VIR_CGROUP_CONTROLLER_NET_CLS,
|
|
|
|
VIR_CGROUP_CONTROLLER_PERF_EVENT,
|
2013-07-25 18:13:44 +00:00
|
|
|
VIR_CGROUP_CONTROLLER_SYSTEMD,
|
2009-07-22 15:08:04 +00:00
|
|
|
|
|
|
|
VIR_CGROUP_CONTROLLER_LAST
|
|
|
|
};
|
|
|
|
|
|
|
|
VIR_ENUM_DECL(virCgroupController);
|
2015-03-27 12:45:33 +00: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 */
|
|
|
|
verify(VIR_CGROUP_CONTROLLER_LAST < 8 * sizeof(int));
|
2009-07-22 15:08:04 +00:00
|
|
|
|
2015-04-07 12:28:05 +00:00
|
|
|
typedef enum {
|
|
|
|
VIR_CGROUP_THREAD_VCPU = 0,
|
|
|
|
VIR_CGROUP_THREAD_EMULATOR,
|
|
|
|
VIR_CGROUP_THREAD_IOTHREAD,
|
|
|
|
|
|
|
|
VIR_CGROUP_THREAD_LAST
|
|
|
|
} virCgroupThreadName;
|
|
|
|
|
2013-07-04 15:49:24 +00:00
|
|
|
bool virCgroupAvailable(void);
|
|
|
|
|
2013-03-28 16:33:22 +00:00
|
|
|
int virCgroupNewSelf(virCgroupPtr *group)
|
|
|
|
ATTRIBUTE_NONNULL(1);
|
2012-11-12 07:02:26 +00:00
|
|
|
|
2015-04-07 12:28:05 +00:00
|
|
|
int virCgroupNewThread(virCgroupPtr domain,
|
|
|
|
virCgroupThreadName nameval,
|
|
|
|
int id,
|
|
|
|
bool create,
|
|
|
|
virCgroupPtr *group)
|
|
|
|
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(5);
|
|
|
|
|
2016-08-04 21:36:38 +00:00
|
|
|
int virCgroupDelThread(virCgroupPtr cgroup,
|
|
|
|
virCgroupThreadName nameval,
|
|
|
|
int idx);
|
|
|
|
|
2013-07-19 10:13:05 +00:00
|
|
|
int virCgroupNewDetect(pid_t pid,
|
2013-07-24 16:31:25 +00:00
|
|
|
int controllers,
|
2013-07-19 10:13:05 +00:00
|
|
|
virCgroupPtr *group);
|
|
|
|
|
2017-07-21 13:51:03 +00:00
|
|
|
int
|
|
|
|
virCgroupNewDetectMachine(const char *name,
|
|
|
|
const char *drivername,
|
|
|
|
pid_t pid,
|
|
|
|
int controllers,
|
|
|
|
char *machinename,
|
|
|
|
virCgroupPtr *group)
|
2016-02-01 15:50:54 +00:00
|
|
|
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
|
2013-07-24 16:36:42 +00:00
|
|
|
|
2013-07-18 15:55:37 +00: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 15:55:37 +00:00
|
|
|
const char *partition,
|
|
|
|
int controllers,
|
2019-05-22 23:12:14 +00:00
|
|
|
unsigned int maxthreads,
|
2013-07-18 15:55:37 +00:00
|
|
|
virCgroupPtr *group)
|
|
|
|
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2)
|
2016-02-06 11:45:46 +00:00
|
|
|
ATTRIBUTE_NONNULL(3);
|
2013-07-18 15:55:37 +00:00
|
|
|
|
2016-02-01 15:50:54 +00:00
|
|
|
int virCgroupTerminateMachine(const char *name)
|
|
|
|
ATTRIBUTE_NONNULL(1);
|
2014-09-25 11:32:58 +00:00
|
|
|
|
2013-07-04 15:49:24 +00:00
|
|
|
bool virCgroupNewIgnoreError(void);
|
|
|
|
|
2018-07-30 09:06:31 +00:00
|
|
|
void virCgroupFree(virCgroupPtr *group);
|
2013-08-12 21:20:59 +00:00
|
|
|
|
|
|
|
bool virCgroupHasController(virCgroupPtr cgroup, int controller);
|
2011-03-07 23:41:40 +00:00
|
|
|
int virCgroupPathOfController(virCgroupPtr group,
|
2018-08-15 15:21:47 +00:00
|
|
|
unsigned int controller,
|
2011-03-07 23:41:40 +00:00
|
|
|
const char *key,
|
|
|
|
char **path);
|
|
|
|
|
2018-09-11 13:03:22 +00:00
|
|
|
int virCgroupAddProcess(virCgroupPtr group, pid_t pid);
|
|
|
|
int virCgroupAddMachineProcess(virCgroupPtr group, pid_t pid);
|
2018-09-24 22:54:04 +00:00
|
|
|
int virCgroupAddThread(virCgroupPtr group, pid_t pid);
|
2008-10-03 17:58:02 +00:00
|
|
|
|
2011-02-08 06:56:39 +00:00
|
|
|
int virCgroupSetBlkioWeight(virCgroupPtr group, unsigned int weight);
|
|
|
|
int virCgroupGetBlkioWeight(virCgroupPtr group, unsigned int *weight);
|
|
|
|
|
2014-02-14 17:48:59 +00: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 11:00:34 +00:00
|
|
|
int virCgroupSetBlkioDeviceWeight(virCgroupPtr group,
|
|
|
|
const char *path,
|
|
|
|
unsigned int weight);
|
|
|
|
|
2013-12-11 08:29:50 +00: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 13:10:20 +00: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 09:18:11 +00:00
|
|
|
int virCgroupSetMemory(virCgroupPtr group, unsigned long long kb);
|
2018-07-20 12:47:11 +00: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 13:26:23 +00:00
|
|
|
int virCgroupGetMemoryUsage(virCgroupPtr group, unsigned long *kb);
|
2008-10-03 17:58:02 +00:00
|
|
|
|
2011-01-13 09:18:11 +00:00
|
|
|
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 05:07:12 +00:00
|
|
|
int virCgroupSetMemSwapHardLimit(virCgroupPtr group, unsigned long long kb);
|
|
|
|
int virCgroupGetMemSwapHardLimit(virCgroupPtr group, unsigned long long *kb);
|
2012-11-12 07:02:25 +00:00
|
|
|
int virCgroupGetMemSwapUsage(virCgroupPtr group, unsigned long long *kb);
|
2010-10-12 14:50:53 +00:00
|
|
|
|
2011-03-09 03:13:18 +00: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 11:33:16 +00:00
|
|
|
const char *virCgroupGetDevicePermsString(int perms);
|
|
|
|
|
2008-10-03 17:58:02 +00:00
|
|
|
int virCgroupDenyAllDevices(virCgroupPtr group);
|
|
|
|
|
2014-07-18 08:02:29 +00: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-09 03:13:18 +00:00
|
|
|
int minor,
|
|
|
|
int perms);
|
2009-07-09 13:11:49 +00:00
|
|
|
int virCgroupAllowDevicePath(virCgroupPtr group,
|
2011-03-09 03:13:18 +00:00
|
|
|
const char *path,
|
2016-02-16 13:43:41 +00:00
|
|
|
int perms,
|
|
|
|
bool ignoreEacces);
|
2009-07-09 13:11:49 +00:00
|
|
|
|
|
|
|
int virCgroupDenyDevice(virCgroupPtr group,
|
|
|
|
char type,
|
|
|
|
int major,
|
2011-03-09 03:13:18 +00:00
|
|
|
int minor,
|
|
|
|
int perms);
|
2009-07-09 13:11:49 +00:00
|
|
|
int virCgroupDenyDevicePath(virCgroupPtr group,
|
2011-03-09 03:13:18 +00:00
|
|
|
const char *path,
|
2016-02-16 13:43:41 +00:00
|
|
|
int perms,
|
|
|
|
bool ignoreEacces);
|
2008-10-03 17:58:02 +00:00
|
|
|
|
2014-02-14 17:49:02 +00:00
|
|
|
int
|
|
|
|
virCgroupGetPercpuStats(virCgroupPtr group,
|
|
|
|
virTypedParameterPtr params,
|
|
|
|
unsigned int nparams,
|
|
|
|
int start_cpu,
|
2014-04-03 15:53:43 +00:00
|
|
|
unsigned int ncpus,
|
2015-12-14 14:10:22 +00:00
|
|
|
virBitmapPtr guestvcpus);
|
2014-02-14 17:49:02 +00:00
|
|
|
|
2014-02-14 17:49:01 +00:00
|
|
|
int
|
|
|
|
virCgroupGetDomainTotalCpuStats(virCgroupPtr group,
|
|
|
|
virTypedParameterPtr params,
|
|
|
|
int nparams);
|
|
|
|
|
2009-07-09 13:11:21 +00: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 07:21:05 +00: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 02:54:23 +00:00
|
|
|
int virCgroupGetCpuacctPercpuUsage(virCgroupPtr group, char **usage);
|
2012-03-09 00:35:59 +00:00
|
|
|
int virCgroupGetCpuacctStat(virCgroupPtr group, unsigned long long *user,
|
|
|
|
unsigned long long *sys);
|
2009-03-06 14:44:04 +00:00
|
|
|
|
2009-09-21 14:31:22 +00:00
|
|
|
int virCgroupSetFreezerState(virCgroupPtr group, const char *state);
|
|
|
|
int virCgroupGetFreezerState(virCgroupPtr group, char **state);
|
|
|
|
|
2011-12-20 08:34:58 +00:00
|
|
|
int virCgroupSetCpusetMems(virCgroupPtr group, const char *mems);
|
|
|
|
int virCgroupGetCpusetMems(virCgroupPtr group, char **mems);
|
|
|
|
|
2015-03-11 10:15:29 +00:00
|
|
|
int virCgroupSetCpusetMemoryMigrate(virCgroupPtr group, bool migrate);
|
|
|
|
int virCgroupGetCpusetMemoryMigrate(virCgroupPtr group, bool *migrate);
|
|
|
|
|
2012-08-21 09:18:30 +00: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 11:48:47 +00:00
|
|
|
|
2013-09-13 14:03:14 +00: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 08:56:00 +00:00
|
|
|
int virCgroupHasEmptyTasks(virCgroupPtr cgroup, int controller);
|
|
|
|
|
2015-03-31 09:39:13 +00:00
|
|
|
bool virCgroupControllerAvailable(int controller);
|