]> git.proxmox.com Git - mirror_lxc.git/blob - src/lxc/cgroup.h
Remove trailing whitespaces
[mirror_lxc.git] / src / lxc / cgroup.h
1 /*
2 * lxc: linux Container library
3 *
4 * (C) Copyright IBM Corp. 2007, 2008
5 *
6 * Authors:
7 * Daniel Lezcano <daniel.lezcano at free.fr>
8 *
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
13 *
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
18 *
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 */
23 #ifndef _ncgroup_h
24 #define _ncgroup_h
25 #include <stdbool.h>
26 #include <stdint.h>
27 #include <stddef.h>
28
29 struct cgroup_hierarchy;
30 struct cgroup_meta_data;
31 struct cgroup_mount_point;
32
33 /*
34 * cgroup_meta_data: the metadata about the cgroup infrastructure on this
35 * host
36 */
37 struct cgroup_meta_data {
38 ptrdiff_t ref; /* simple refcount */
39 struct cgroup_hierarchy **hierarchies;
40 struct cgroup_mount_point **mount_points;
41 int maximum_hierarchy;
42 };
43
44 /*
45 * cgroup_hierarchy: describes a single cgroup hierarchy
46 * (may have multiple mount points)
47 */
48 struct cgroup_hierarchy {
49 int index;
50 bool used; /* false if the hierarchy should be ignored by lxc */
51 char **subsystems;
52 struct cgroup_mount_point *rw_absolute_mount_point;
53 struct cgroup_mount_point *ro_absolute_mount_point;
54 struct cgroup_mount_point **all_mount_points;
55 size_t all_mount_point_capacity;
56 };
57
58 /*
59 * cgroup_mount_point: a mount point to where a hierarchy
60 * is mounted to
61 */
62 struct cgroup_mount_point {
63 struct cgroup_hierarchy *hierarchy;
64 char *mount_point;
65 char *mount_prefix;
66 bool read_only;
67 };
68
69 /*
70 * cgroup_process_info: describes the membership of a
71 * process to the different cgroup
72 * hierarchies
73 */
74 struct cgroup_process_info {
75 struct cgroup_process_info *next;
76 struct cgroup_meta_data *meta_ref;
77 struct cgroup_hierarchy *hierarchy;
78 char *cgroup_path;
79 char *cgroup_path_sub;
80 char **created_paths;
81 size_t created_paths_capacity;
82 size_t created_paths_count;
83 struct cgroup_mount_point *designated_mount_point;
84 };
85
86 /* meta data management:
87 * lxc_cgroup_load_meta loads the meta data (using subsystem
88 * whitelist from main lxc configuration)
89 * lxc_cgroup_load_meta2 does the same, but allows one to specify
90 * a custom whitelist
91 * lxc_cgroup_get_meta increments the refcount of a meta data
92 * object
93 * lxc_cgroup_put_meta decrements the refcount of a meta data
94 * object, potentially destroying it
95 */
96 extern struct cgroup_meta_data *lxc_cgroup_load_meta();
97 extern struct cgroup_meta_data *lxc_cgroup_load_meta2(const char **subsystem_whitelist);
98 extern struct cgroup_meta_data *lxc_cgroup_get_meta(struct cgroup_meta_data *meta_data);
99 extern struct cgroup_meta_data *lxc_cgroup_put_meta(struct cgroup_meta_data *meta_data);
100
101 /* find the hierarchy corresponding to a given subsystem */
102 extern struct cgroup_hierarchy *lxc_cgroup_find_hierarchy(struct cgroup_meta_data *meta_data, const char *subsystem);
103
104 /* find a mount point for a given hierarchy that has access to the cgroup in 'cgroup' and (if wanted) is writable */
105 extern struct cgroup_mount_point *lxc_cgroup_find_mount_point(struct cgroup_hierarchy *hierarchy, const char *group, bool should_be_writable);
106
107 /* all-in-one: find a mount point for a given hierarchy that has access to the cgroup and return the correct path within */
108 extern char *lxc_cgroup_find_abs_path(const char *subsystem, const char *group, bool should_be_writable, const char *suffix);
109
110 /* determine the cgroup membership of a given process */
111 extern struct cgroup_process_info *lxc_cgroup_process_info_get(pid_t pid, struct cgroup_meta_data *meta);
112 extern struct cgroup_process_info *lxc_cgroup_process_info_get_init(struct cgroup_meta_data *meta);
113 extern struct cgroup_process_info *lxc_cgroup_process_info_get_self(struct cgroup_meta_data *meta);
114
115 /* create a new cgroup */
116 extern struct cgroup_process_info *lxc_cgroup_create(const char *name, const char *path_pattern, struct cgroup_meta_data *meta_data, const char *sub_pattern);
117 extern int lxc_cgroup_create_legacy(struct cgroup_process_info *base_info, const char *name, pid_t pid);
118
119 /* get the cgroup membership of a given container */
120 extern struct cgroup_process_info *lxc_cgroup_get_container_info(const char *name, const char *lxcpath, struct cgroup_meta_data *meta_data);
121
122 /* move a processs to the cgroups specified by the membership */
123 extern int lxc_cgroup_enter(struct cgroup_process_info *info, pid_t pid, bool enter_sub);
124
125 /* free process membership information */
126 extern void lxc_cgroup_process_info_free(struct cgroup_process_info *info);
127 extern void lxc_cgroup_process_info_free_and_remove(struct cgroup_process_info *info);
128
129 struct lxc_handler;
130 extern char *lxc_cgroup_get_hierarchy_path_handler(const char *subsystem, struct lxc_handler *handler);
131 extern char *lxc_cgroup_get_hierarchy_path(const char *subsystem, const char *name, const char *lxcpath);
132 extern char *lxc_cgroup_get_hierarchy_abs_path_handler(const char *subsystem, struct lxc_handler *handler);
133 extern char *lxc_cgroup_get_hierarchy_abs_path(const char *subsystem, const char *name, const char *lxcpath);
134 extern int lxc_cgroup_set_handler(const char *filename, const char *value, struct lxc_handler *handler);
135 extern int lxc_cgroup_get_handler(const char *filename, char *value, size_t len, struct lxc_handler *handler);
136 extern int lxc_cgroup_set(const char *filename, const char *value, const char *name, const char *lxcpath);
137 extern int lxc_cgroup_get(const char *filename, char *value, size_t len, const char *name, const char *lxcpath);
138
139 /*
140 * lxc_cgroup_path_get: Get the absolute pathname for a cgroup
141 * file for a running container.
142 *
143 * @filename : the file of interest (e.g. "freezer.state") or
144 * the subsystem name (e.g. "freezer") in which case
145 * the directory where the cgroup may be modified
146 * will be returned
147 * @name : name of container to connect to
148 * @lxcpath : the lxcpath in which the container is running
149 *
150 * This is the exported function, which determines cgpath from the
151 * lxc-start of the @name container running in @lxcpath.
152 *
153 * Returns path on success, NULL on error. The caller must free()
154 * the returned path.
155 */
156 extern char *lxc_cgroup_path_get(const char *subsystem, const char *name,
157 const char *lxcpath);
158
159 struct lxc_list;
160 extern int lxc_setup_cgroup_without_devices(struct lxc_handler *h, struct lxc_list *cgroup_settings);
161 extern int lxc_setup_cgroup_devices(struct lxc_handler *h, struct lxc_list *cgroup_settings);
162
163 extern int lxc_setup_mount_cgroup(const char *root, struct cgroup_process_info *base_info);
164
165 extern int lxc_cgroup_nrtasks_handler(struct lxc_handler *handler);
166
167 #endif