]>
Commit | Line | Data |
---|---|---|
576f946d | 1 | /* |
2 | * lxc: linux Container library | |
3 | * | |
4 | * (C) Copyright IBM Corp. 2007, 2008 | |
5 | * | |
6 | * Authors: | |
9afe19d6 | 7 | * Daniel Lezcano <daniel.lezcano at free.fr> |
576f946d | 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 | |
250b1eec | 21 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
576f946d | 22 | */ |
33ad9f1a CS |
23 | #ifndef _ncgroup_h |
24 | #define _ncgroup_h | |
283678ed | 25 | #include <stdbool.h> |
33ad9f1a CS |
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 | }; | |
576f946d | 68 | |
b98f7d6e | 69 | /* |
33ad9f1a CS |
70 | * cgroup_process_info: describes the membership of a |
71 | * process to the different cgroup | |
72 | * hierarchies | |
b98f7d6e | 73 | */ |
33ad9f1a CS |
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; | |
b98f7d6e SH |
84 | }; |
85 | ||
33ad9f1a CS |
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 */ | |
692ba18f | 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, int pid); |
33ad9f1a CS |
117 | |
118 | /* get the cgroup membership of a given container */ | |
119 | extern struct cgroup_process_info *lxc_cgroup_get_container_info(const char *name, const char *lxcpath, struct cgroup_meta_data *meta_data); | |
120 | ||
121 | /* move a processs to the cgroups specified by the membership */ | |
122 | extern int lxc_cgroup_enter(struct cgroup_process_info *info, pid_t pid, bool enter_sub); | |
123 | ||
124 | /* free process membership information */ | |
125 | extern void lxc_cgroup_process_info_free(struct cgroup_process_info *info); | |
126 | extern void lxc_cgroup_process_info_free_and_remove(struct cgroup_process_info *info); | |
127 | ||
758437c5 | 128 | struct lxc_handler; |
33ad9f1a CS |
129 | extern char *lxc_cgroup_get_hierarchy_path_handler(const char *subsystem, struct lxc_handler *handler); |
130 | extern char *lxc_cgroup_get_hierarchy_path(const char *subsystem, const char *name, const char *lxcpath); | |
131 | extern char *lxc_cgroup_get_hierarchy_abs_path_handler(const char *subsystem, struct lxc_handler *handler); | |
132 | extern char *lxc_cgroup_get_hierarchy_abs_path(const char *subsystem, const char *name, const char *lxcpath); | |
133 | extern int lxc_cgroup_set_handler(const char *filename, const char *value, struct lxc_handler *handler); | |
134 | extern int lxc_cgroup_get_handler(const char *filename, char *value, size_t len, struct lxc_handler *handler); | |
135 | extern int lxc_cgroup_set(const char *filename, const char *value, const char *name, const char *lxcpath); | |
136 | extern int lxc_cgroup_get(const char *filename, char *value, size_t len, const char *name, const char *lxcpath); | |
137 | ||
b98f7d6e | 138 | /* |
33ad9f1a CS |
139 | * lxc_cgroup_path_get: Get the absolute pathname for a cgroup |
140 | * file for a running container. | |
141 | * | |
142 | * @filename : the file of interest (e.g. "freezer.state") or | |
143 | * the subsystem name (e.g. "freezer") in which case | |
144 | * the directory where the cgroup may be modified | |
145 | * will be returned | |
146 | * @name : name of container to connect to | |
147 | * @lxcpath : the lxcpath in which the container is running | |
148 | * | |
149 | * This is the exported function, which determines cgpath from the | |
150 | * lxc-start of the @name container running in @lxcpath. | |
151 | * | |
152 | * Returns path on success, NULL on error. The caller must free() | |
153 | * the returned path. | |
b98f7d6e | 154 | */ |
33ad9f1a CS |
155 | extern char *lxc_cgroup_path_get(const char *subsystem, const char *name, |
156 | const char *lxcpath); | |
157 | ||
b98f7d6e | 158 | struct lxc_list; |
33ad9f1a CS |
159 | extern int lxc_setup_cgroup_without_devices(struct lxc_handler *h, struct lxc_list *cgroup_settings); |
160 | extern int lxc_setup_cgroup_devices(struct lxc_handler *h, struct lxc_list *cgroup_settings); | |
161 | ||
162 | extern int lxc_cgroup_nrtasks_handler(struct lxc_handler *handler); | |
163 | ||
576f946d | 164 | #endif |