vircgroup.h 6.1 KB
Newer Older
1
/*
2
 * vircgroup.h: methods for managing control cgroups
3
 *
H
Hu Tao 已提交
4
 * Copyright (C) 2011-2013 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 43 44 45 46

    VIR_CGROUP_CONTROLLER_LAST
};

VIR_ENUM_DECL(virCgroupController);

47 48
int virCgroupForDriver(const char *name,
                       virCgroupPtr *group,
49
                       bool privileged,
50 51
                       bool create,
                       int controllers);
52

53
int virCgroupForSelf(virCgroupPtr *group);
G
Gao feng 已提交
54

55 56 57
int virCgroupForDomain(virCgroupPtr driver,
                       const char *name,
                       virCgroupPtr *group,
58
                       bool create);
59

60 61 62
int virCgroupForVcpu(virCgroupPtr driver,
                     int vcpuid,
                     virCgroupPtr *group,
63
                     bool create);
64

65 66
int virCgroupForEmulator(virCgroupPtr driver,
                         virCgroupPtr *group,
67
                         bool create);
68

69 70 71 72 73
int virCgroupPathOfController(virCgroupPtr group,
                              int controller,
                              const char *key,
                              char **path);

74 75
int virCgroupAddTask(virCgroupPtr group, pid_t pid);

76 77 78 79 80
int virCgroupAddTaskController(virCgroupPtr group,
                               pid_t pid,
                               int controller);

int virCgroupMoveTask(virCgroupPtr src_group,
81
                      virCgroupPtr dest_group);
82

83 84 85
int virCgroupSetBlkioWeight(virCgroupPtr group, unsigned int weight);
int virCgroupGetBlkioWeight(virCgroupPtr group, unsigned int *weight);

86 87 88 89
int virCgroupSetBlkioDeviceWeight(virCgroupPtr group,
                                  const char *path,
                                  unsigned int weight);

90
int virCgroupSetMemory(virCgroupPtr group, unsigned long long kb);
R
Ryota Ozaki 已提交
91
int virCgroupGetMemoryUsage(virCgroupPtr group, unsigned long *kb);
92

93 94 95 96
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);
97 98
int virCgroupSetMemSwapHardLimit(virCgroupPtr group, unsigned long long kb);
int virCgroupGetMemSwapHardLimit(virCgroupPtr group, unsigned long long *kb);
G
Gao feng 已提交
99
int virCgroupGetMemSwapUsage(virCgroupPtr group, unsigned long long *kb);
100

101 102 103 104 105 106 107 108
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,
};

109 110 111 112 113
int virCgroupDenyAllDevices(virCgroupPtr group);

int virCgroupAllowDevice(virCgroupPtr group,
                         char type,
                         int major,
114 115
                         int minor,
                         int perms);
116 117
int virCgroupAllowDeviceMajor(virCgroupPtr group,
                              char type,
118 119
                              int major,
                              int perms);
120
int virCgroupAllowDevicePath(virCgroupPtr group,
121 122
                             const char *path,
                             int perms);
123 124 125 126

int virCgroupDenyDevice(virCgroupPtr group,
                        char type,
                        int major,
127 128
                        int minor,
                        int perms);
129 130
int virCgroupDenyDeviceMajor(virCgroupPtr group,
                             char type,
131 132
                             int major,
                             int perms);
133
int virCgroupDenyDevicePath(virCgroupPtr group,
134 135
                            const char *path,
                            int perms);
136

137 138
int virCgroupSetCpuShares(virCgroupPtr group, unsigned long long shares);
int virCgroupGetCpuShares(virCgroupPtr group, unsigned long long *shares);
139

140 141 142 143 144 145
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);

146
int virCgroupGetCpuacctUsage(virCgroupPtr group, unsigned long long *usage);
147
int virCgroupGetCpuacctPercpuUsage(virCgroupPtr group, char **usage);
148 149
int virCgroupGetCpuacctStat(virCgroupPtr group, unsigned long long *user,
                            unsigned long long *sys);
150

R
Ryota Ozaki 已提交
151 152 153
int virCgroupSetFreezerState(virCgroupPtr group, const char *state);
int virCgroupGetFreezerState(virCgroupPtr group, char **state);

154 155 156
int virCgroupSetCpusetMems(virCgroupPtr group, const char *mems);
int virCgroupGetCpusetMems(virCgroupPtr group, char **mems);

157 158 159
int virCgroupSetCpusetCpus(virCgroupPtr group, const char *cpus);
int virCgroupGetCpusetCpus(virCgroupPtr group, char **cpus);

160
int virCgroupRemoveRecursively(char *grppath);
161 162 163
int virCgroupRemove(virCgroupPtr group);

void virCgroupFree(virCgroupPtr *group);
L
Lai Jiangshan 已提交
164
bool virCgroupMounted(virCgroupPtr cgroup, int controller);
165

166 167 168 169
int virCgroupKill(virCgroupPtr group, int signum);
int virCgroupKillRecursive(virCgroupPtr group, int signum);
int virCgroupKillPainfully(virCgroupPtr group);

170
#endif /* __VIR_CGROUP_H__ */