vircgroup.h 10.4 KB
Newer Older
1
/*
2
 * vircgroup.h: methods for managing control cgroups
3
 *
4
 * Copyright (C) 2011-2015 Red Hat, Inc.
5 6
 * Copyright IBM Corp. 2008
 *
O
Osier Yang 已提交
7 8 9 10 11 12 13 14 15 16 17
 * 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
18
 * License along with this library.  If not, see
O
Osier Yang 已提交
19
 * <http://www.gnu.org/licenses/>.
20 21
 */

22
#pragma once
23

24 25
#include "virbitmap.h"
#include "virenum.h"
H
Hu Tao 已提交
26

27
struct _virCgroup;
28 29
typedef struct _virCgroup virCgroup;
typedef virCgroup *virCgroupPtr;
30

31 32 33 34 35 36
enum {
    VIR_CGROUP_CONTROLLER_CPU,
    VIR_CGROUP_CONTROLLER_CPUACCT,
    VIR_CGROUP_CONTROLLER_CPUSET,
    VIR_CGROUP_CONTROLLER_MEMORY,
    VIR_CGROUP_CONTROLLER_DEVICES,
R
Ryota Ozaki 已提交
37
    VIR_CGROUP_CONTROLLER_FREEZER,
38
    VIR_CGROUP_CONTROLLER_BLKIO,
39 40
    VIR_CGROUP_CONTROLLER_NET_CLS,
    VIR_CGROUP_CONTROLLER_PERF_EVENT,
41
    VIR_CGROUP_CONTROLLER_SYSTEMD,
42 43 44 45 46

    VIR_CGROUP_CONTROLLER_LAST
};

VIR_ENUM_DECL(virCgroupController);
47 48 49 50
/* 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 */
51
G_STATIC_ASSERT(VIR_CGROUP_CONTROLLER_LAST < 8 * sizeof(int));
52

53 54 55 56 57 58 59 60
typedef enum {
    VIR_CGROUP_THREAD_VCPU = 0,
    VIR_CGROUP_THREAD_EMULATOR,
    VIR_CGROUP_THREAD_IOTHREAD,

    VIR_CGROUP_THREAD_LAST
} virCgroupThreadName;

61 62
bool virCgroupAvailable(void);

63 64
int virCgroupNewSelf(virCgroupPtr *group)
    ATTRIBUTE_NONNULL(1);
G
Gao feng 已提交
65

66 67 68 69 70 71 72
int virCgroupNewThread(virCgroupPtr domain,
                       virCgroupThreadName nameval,
                       int id,
                       bool create,
                       virCgroupPtr *group)
    ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(5);

73 74 75 76
int virCgroupDelThread(virCgroupPtr cgroup,
                       virCgroupThreadName nameval,
                       int idx);

77
int virCgroupNewDetect(pid_t pid,
78
                       int controllers,
79 80
                       virCgroupPtr *group);

81 82 83 84 85 86 87
int
virCgroupNewDetectMachine(const char *name,
                          const char *drivername,
                          pid_t pid,
                          int controllers,
                          char *machinename,
                          virCgroupPtr *group)
88
    ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
89

90 91 92 93 94 95
int virCgroupNewMachine(const char *name,
                        const char *drivername,
                        const unsigned char *uuid,
                        const char *rootdir,
                        pid_t pidleader,
                        bool isContainer,
96 97
                        size_t nnicindexes,
                        int *nicindexes,
98 99
                        const char *partition,
                        int controllers,
100
                        unsigned int maxthreads,
101 102
                        virCgroupPtr *group)
    ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2)
103
    ATTRIBUTE_NONNULL(3);
104

105 106
int virCgroupTerminateMachine(const char *name)
    ATTRIBUTE_NONNULL(1);
107

108 109
bool virCgroupNewIgnoreError(void);

110
void virCgroupFree(virCgroupPtr *group);
E
Eric Blake 已提交
111 112

bool virCgroupHasController(virCgroupPtr cgroup, int controller);
113
int virCgroupPathOfController(virCgroupPtr group,
114
                              unsigned int controller,
115 116 117
                              const char *key,
                              char **path);

118 119
int virCgroupAddProcess(virCgroupPtr group, pid_t pid);
int virCgroupAddMachineProcess(virCgroupPtr group, pid_t pid);
120
int virCgroupAddThread(virCgroupPtr group, pid_t pid);
121

122 123 124
int virCgroupSetBlkioWeight(virCgroupPtr group, unsigned int weight);
int virCgroupGetBlkioWeight(virCgroupPtr group, unsigned int *weight);

125 126 127 128 129 130 131 132 133 134 135 136
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);

137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156
int virCgroupSetupBlkioDeviceWeight(virCgroupPtr cgroup,
                                    const char *path,
                                    unsigned int *weight);

int virCgroupSetupBlkioDeviceReadIops(virCgroupPtr cgroup,
                                      const char *path,
                                      unsigned int *riops);

int virCgroupSetupBlkioDeviceWriteIops(virCgroupPtr cgroup,
                                       const char *path,
                                       unsigned int *wiops);

int virCgroupSetupBlkioDeviceReadBps(virCgroupPtr cgroup,
                                     const char *path,
                                     unsigned long long *rbps);

int virCgroupSetupBlkioDeviceWriteBps(virCgroupPtr cgroup,
                                      const char *path,
                                      unsigned long long *wbps);

157
int virCgroupSetMemory(virCgroupPtr group, unsigned long long kb);
158 159 160 161 162 163 164
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);
R
Ryota Ozaki 已提交
165
int virCgroupGetMemoryUsage(virCgroupPtr group, unsigned long *kb);
166

167 168 169 170
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);
171 172
int virCgroupSetMemSwapHardLimit(virCgroupPtr group, unsigned long long kb);
int virCgroupGetMemSwapHardLimit(virCgroupPtr group, unsigned long long *kb);
G
Gao feng 已提交
173
int virCgroupGetMemSwapUsage(virCgroupPtr group, unsigned long long *kb);
174

175 176 177 178 179 180 181 182
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,
};

183 184
const char *virCgroupGetDevicePermsString(int perms);

185 186
int virCgroupDenyAllDevices(virCgroupPtr group);

187 188
int virCgroupAllowAllDevices(virCgroupPtr group, int perms);

189 190 191
int virCgroupAllowDevice(virCgroupPtr group,
                         char type,
                         int major,
192 193
                         int minor,
                         int perms);
194
int virCgroupAllowDevicePath(virCgroupPtr group,
195
                             const char *path,
196 197
                             int perms,
                             bool ignoreEacces);
198 199 200 201

int virCgroupDenyDevice(virCgroupPtr group,
                        char type,
                        int major,
202 203
                        int minor,
                        int perms);
204
int virCgroupDenyDevicePath(virCgroupPtr group,
205
                            const char *path,
206 207
                            int perms,
                            bool ignoreEacces);
208

209 210 211 212 213
int
virCgroupGetPercpuStats(virCgroupPtr group,
                        virTypedParameterPtr params,
                        unsigned int nparams,
                        int start_cpu,
214
                        unsigned int ncpus,
215
                        virBitmapPtr guestvcpus);
216

217 218 219 220 221
int
virCgroupGetDomainTotalCpuStats(virCgroupPtr group,
                                virTypedParameterPtr params,
                                int nparams);

222 223
int virCgroupSetCpuShares(virCgroupPtr group, unsigned long long shares);
int virCgroupGetCpuShares(virCgroupPtr group, unsigned long long *shares);
224 225
int virCgroupSetupCpuShares(virCgroupPtr cgroup, unsigned long long shares,
                            unsigned long long *realValue);
226

227 228
int virCgroupSetCpuCfsPeriod(virCgroupPtr group, unsigned long long cfs_period);
int virCgroupGetCpuCfsPeriod(virCgroupPtr group, unsigned long long *cfs_period);
229 230
int virCgroupGetCpuPeriodQuota(virCgroupPtr cgroup, unsigned long long *period,
                               long long *quota);
231 232
int virCgroupSetupCpuPeriodQuota(virCgroupPtr cgroup, unsigned long long period,
                                 long long quota);
233 234 235 236

int virCgroupSetCpuCfsQuota(virCgroupPtr group, long long cfs_quota);
int virCgroupGetCpuCfsQuota(virCgroupPtr group, long long *cfs_quota);

237
int virCgroupGetCpuacctUsage(virCgroupPtr group, unsigned long long *usage);
238
int virCgroupGetCpuacctPercpuUsage(virCgroupPtr group, char **usage);
239 240
int virCgroupGetCpuacctStat(virCgroupPtr group, unsigned long long *user,
                            unsigned long long *sys);
241

R
Ryota Ozaki 已提交
242 243 244
int virCgroupSetFreezerState(virCgroupPtr group, const char *state);
int virCgroupGetFreezerState(virCgroupPtr group, char **state);

245 246 247
int virCgroupSetCpusetMems(virCgroupPtr group, const char *mems);
int virCgroupGetCpusetMems(virCgroupPtr group, char **mems);

248 249 250
int virCgroupSetCpusetMemoryMigrate(virCgroupPtr group, bool migrate);
int virCgroupGetCpusetMemoryMigrate(virCgroupPtr group, bool *migrate);

251 252
int virCgroupSetCpusetCpus(virCgroupPtr group, const char *cpus);
int virCgroupGetCpusetCpus(virCgroupPtr group, char **cpus);
253
int virCgroupSetupCpusetCpus(virCgroupPtr cgroup, virBitmapPtr cpumask);
254

255 256
int virCgroupRemove(virCgroupPtr group);

257 258 259
int virCgroupKillRecursive(virCgroupPtr group, int signum);
int virCgroupKillPainfully(virCgroupPtr group);

260 261 262
int virCgroupBindMount(virCgroupPtr group,
                       const char *oldroot,
                       const char *mountopts);
263

264 265
bool virCgroupSupportsCpuBW(virCgroupPtr cgroup);

266 267 268 269 270
int virCgroupSetOwner(virCgroupPtr cgroup,
                      uid_t uid,
                      gid_t gid,
                      int controllers);

271 272
int virCgroupHasEmptyTasks(virCgroupPtr cgroup, int controller);

273
bool virCgroupControllerAvailable(int controller);