]>
git.proxmox.com Git - mirror_lxc.git/blob - src/lxc/cgroup.h
2 * lxc: linux Container library
4 * (C) Copyright IBM Corp. 2007, 2008
7 * Daniel Lezcano <daniel.lezcano at free.fr>
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.
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.
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
29 struct cgroup_hierarchy
;
30 struct cgroup_meta_data
;
31 struct cgroup_mount_point
;
34 * cgroup_meta_data: the metadata about the cgroup infrastructure on this
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
;
45 * cgroup_hierarchy: describes a single cgroup hierarchy
46 * (may have multiple mount points)
48 struct cgroup_hierarchy
{
50 bool used
; /* false if the hierarchy should be ignored by lxc */
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
;
59 * cgroup_mount_point: a mount point to where a hierarchy
62 struct cgroup_mount_point
{
63 struct cgroup_hierarchy
*hierarchy
;
70 * cgroup_process_info: describes the membership of a
71 * process to the different cgroup
74 struct cgroup_process_info
{
75 struct cgroup_process_info
*next
;
76 struct cgroup_meta_data
*meta_ref
;
77 struct cgroup_hierarchy
*hierarchy
;
79 char *cgroup_path_sub
;
81 size_t created_paths_capacity
;
82 size_t created_paths_count
;
83 struct cgroup_mount_point
*designated_mount_point
;
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
91 * lxc_cgroup_get_meta increments the refcount of a meta data
93 * lxc_cgroup_put_meta decrements the refcount of a meta data
94 * object, potentially destroying it
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
);
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
);
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
);
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
);
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
);
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
);
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
);
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
);
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
);
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
);
140 * lxc_cgroup_path_get: Get the absolute pathname for a cgroup
141 * file for a running container.
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
147 * @name : name of container to connect to
148 * @lxcpath : the lxcpath in which the container is running
150 * This is the exported function, which determines cgpath from the
151 * lxc-start of the @name container running in @lxcpath.
153 * Returns path on success, NULL on error. The caller must free()
156 extern char *lxc_cgroup_path_get(const char *subsystem
, const char *name
,
157 const char *lxcpath
);
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
);
163 extern int lxc_setup_mount_cgroup(const char *root
, struct cgroup_process_info
*base_info
);
165 extern int lxc_cgroup_nrtasks_handler(struct lxc_handler
*handler
);