vircgroup.h 10.5 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 23 24
 *
 * Authors:
 *  Dan Smith <danms@us.ibm.com>
 */

25 26
#ifndef __VIR_CGROUP_H__
# define __VIR_CGROUP_H__
27

H
Hu Tao 已提交
28 29
# include "virutil.h"

30 31 32
struct virCgroup;
typedef struct virCgroup *virCgroupPtr;

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

    VIR_CGROUP_CONTROLLER_LAST
};

VIR_ENUM_DECL(virCgroupController);
49 50 51 52 53
/* 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));
54

55 56 57 58 59 60 61 62
typedef enum {
    VIR_CGROUP_THREAD_VCPU = 0,
    VIR_CGROUP_THREAD_EMULATOR,
    VIR_CGROUP_THREAD_IOTHREAD,

    VIR_CGROUP_THREAD_LAST
} virCgroupThreadName;

63 64
bool virCgroupAvailable(void);

65 66 67 68 69 70
int virCgroupNewPartition(const char *path,
                          bool create,
                          int controllers,
                          virCgroupPtr *group)
    ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(4);

71 72
int virCgroupNewSelf(virCgroupPtr *group)
    ATTRIBUTE_NONNULL(1);
G
Gao feng 已提交
73

74 75 76 77 78
int virCgroupNewDomainPartition(virCgroupPtr partition,
                                const char *driver,
                                const char *name,
                                bool create,
                                virCgroupPtr *group)
79
    ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(5);
80

81 82 83 84 85 86 87
int virCgroupNewThread(virCgroupPtr domain,
                       virCgroupThreadName nameval,
                       int id,
                       bool create,
                       virCgroupPtr *group)
    ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(5);

88
int virCgroupNewDetect(pid_t pid,
89
                       int controllers,
90 91
                       virCgroupPtr *group);

92 93 94
int virCgroupNewDetectMachine(const char *name,
                              const char *drivername,
                              pid_t pid,
95
                              const char *partition,
96
                              int controllers,
97 98
                              virCgroupPtr *group);

99 100 101 102 103 104 105
int virCgroupNewMachine(const char *name,
                        const char *drivername,
                        bool privileged,
                        const unsigned char *uuid,
                        const char *rootdir,
                        pid_t pidleader,
                        bool isContainer,
106 107
                        size_t nnicindexes,
                        int *nicindexes,
108 109 110 111 112 113
                        const char *partition,
                        int controllers,
                        virCgroupPtr *group)
    ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2)
    ATTRIBUTE_NONNULL(4);

114 115 116 117 118
int virCgroupTerminateMachine(const char *name,
                              const char *drivername,
                              bool privileged)
    ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);

119 120
bool virCgroupNewIgnoreError(void);

E
Eric Blake 已提交
121 122 123
void virCgroupFree(virCgroupPtr *group);

bool virCgroupHasController(virCgroupPtr cgroup, int controller);
124 125 126 127 128
int virCgroupPathOfController(virCgroupPtr group,
                              int controller,
                              const char *key,
                              char **path);

129 130
int virCgroupAddTask(virCgroupPtr group, pid_t pid);

131 132 133 134 135
int virCgroupAddTaskController(virCgroupPtr group,
                               pid_t pid,
                               int controller);

int virCgroupMoveTask(virCgroupPtr src_group,
136
                      virCgroupPtr dest_group);
137

138 139 140
int virCgroupSetBlkioWeight(virCgroupPtr group, unsigned int weight);
int virCgroupGetBlkioWeight(virCgroupPtr group, unsigned int *weight);

141 142 143 144 145 146 147 148 149 150 151 152
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);

153 154 155 156
int virCgroupSetBlkioDeviceWeight(virCgroupPtr group,
                                  const char *path,
                                  unsigned int weight);

157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172
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);

173
int virCgroupSetMemory(virCgroupPtr group, unsigned long long kb);
R
Ryota Ozaki 已提交
174
int virCgroupGetMemoryUsage(virCgroupPtr group, unsigned long *kb);
175

176 177 178 179
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);
180 181
int virCgroupSetMemSwapHardLimit(virCgroupPtr group, unsigned long long kb);
int virCgroupGetMemSwapHardLimit(virCgroupPtr group, unsigned long long *kb);
G
Gao feng 已提交
182
int virCgroupGetMemSwapUsage(virCgroupPtr group, unsigned long long *kb);
183

184 185 186 187 188 189 190 191
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,
};

192 193
const char *virCgroupGetDevicePermsString(int perms);

194 195
int virCgroupDenyAllDevices(virCgroupPtr group);

196 197
int virCgroupAllowAllDevices(virCgroupPtr group, int perms);

198 199 200
int virCgroupAllowDevice(virCgroupPtr group,
                         char type,
                         int major,
201 202
                         int minor,
                         int perms);
203 204
int virCgroupAllowDeviceMajor(virCgroupPtr group,
                              char type,
205 206
                              int major,
                              int perms);
207
int virCgroupAllowDevicePath(virCgroupPtr group,
208 209
                             const char *path,
                             int perms);
210 211 212 213

int virCgroupDenyDevice(virCgroupPtr group,
                        char type,
                        int major,
214 215
                        int minor,
                        int perms);
216 217
int virCgroupDenyDeviceMajor(virCgroupPtr group,
                             char type,
218 219
                             int major,
                             int perms);
220
int virCgroupDenyDevicePath(virCgroupPtr group,
221 222
                            const char *path,
                            int perms);
223

224 225 226 227 228
int
virCgroupGetPercpuStats(virCgroupPtr group,
                        virTypedParameterPtr params,
                        unsigned int nparams,
                        int start_cpu,
229 230
                        unsigned int ncpus,
                        unsigned int nvcpupids);
231

232 233 234 235 236
int
virCgroupGetDomainTotalCpuStats(virCgroupPtr group,
                                virTypedParameterPtr params,
                                int nparams);

237 238
int virCgroupSetCpuShares(virCgroupPtr group, unsigned long long shares);
int virCgroupGetCpuShares(virCgroupPtr group, unsigned long long *shares);
239

240 241 242 243 244 245
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);

246
int virCgroupGetCpuacctUsage(virCgroupPtr group, unsigned long long *usage);
247
int virCgroupGetCpuacctPercpuUsage(virCgroupPtr group, char **usage);
248 249
int virCgroupGetCpuacctStat(virCgroupPtr group, unsigned long long *user,
                            unsigned long long *sys);
250

R
Ryota Ozaki 已提交
251 252 253
int virCgroupSetFreezerState(virCgroupPtr group, const char *state);
int virCgroupGetFreezerState(virCgroupPtr group, char **state);

254 255 256
int virCgroupSetCpusetMems(virCgroupPtr group, const char *mems);
int virCgroupGetCpusetMems(virCgroupPtr group, char **mems);

257 258 259
int virCgroupSetCpusetMemoryMigrate(virCgroupPtr group, bool migrate);
int virCgroupGetCpusetMemoryMigrate(virCgroupPtr group, bool *migrate);

260 261 262
int virCgroupSetCpusetCpus(virCgroupPtr group, const char *cpus);
int virCgroupGetCpusetCpus(virCgroupPtr group, char **cpus);

263
int virCgroupRemoveRecursively(char *grppath);
264 265
int virCgroupRemove(virCgroupPtr group);

266 267 268 269
int virCgroupKill(virCgroupPtr group, int signum);
int virCgroupKillRecursive(virCgroupPtr group, int signum);
int virCgroupKillPainfully(virCgroupPtr group);

270 271 272 273
int virCgroupIsolateMount(virCgroupPtr group,
                          const char *oldroot,
                          const char *mountopts);

274 275
bool virCgroupSupportsCpuBW(virCgroupPtr cgroup);

276 277 278 279 280
int virCgroupSetOwner(virCgroupPtr cgroup,
                      uid_t uid,
                      gid_t gid,
                      int controllers);

281 282
int virCgroupHasEmptyTasks(virCgroupPtr cgroup, int controller);

283
bool virCgroupControllerAvailable(int controller);
284
#endif /* __VIR_CGROUP_H__ */