]> git.proxmox.com Git - mirror_lxc.git/blob - src/lxc/lxc.h
Initial support for cgmanager
[mirror_lxc.git] / src / lxc / lxc.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 __lxc_h
24 #define __lxc_h
25
26 #ifdef __cplusplus
27 extern "C" {
28 #endif
29
30 #include <stddef.h>
31 #include <sys/select.h>
32 #include <sys/types.h>
33 #include "state.h"
34
35 struct lxc_msg;
36 struct lxc_conf;
37 struct lxc_arguments;
38
39 /**
40 Following code is for liblxc.
41
42 lxc/lxc.h will contain exports of liblxc
43 **/
44
45 /*
46 * Start the specified command inside a system container
47 * @name : the name of the container
48 * @argv : an array of char * corresponding to the commande line
49 * @conf : configuration
50 * Returns 0 on sucess, < 0 otherwise
51 */
52 extern int lxc_start(const char *name, char *const argv[], struct lxc_conf *conf,
53 const char *lxcpath);
54
55 /*
56 * Start the specified command inside an application container
57 * @name : the name of the container
58 * @argv : an array of char * corresponding to the commande line
59 * @quiet : if != 0 then lxc-init won't produce any output
60 * @conf : configuration
61 * Returns 0 on sucess, < 0 otherwise
62 */
63 extern int lxc_execute(const char *name, char *const argv[], int quiet,
64 struct lxc_conf *conf, const char *lxcpath);
65
66 /*
67 * Open the monitoring mechanism for a specific container
68 * The function will return an fd corresponding to the events
69 * Returns a file descriptor on success, < 0 otherwise
70 */
71 extern int lxc_monitor_open(const char *lxcpath);
72
73 /*
74 * Blocking read for the next container state change
75 * @fd : the file descriptor provided by lxc_monitor_open
76 * @msg : the variable which will be filled with the state
77 * Returns 0 if the monitored container has exited, > 0 if
78 * data was read, < 0 otherwise
79 */
80 extern int lxc_monitor_read(int fd, struct lxc_msg *msg);
81
82 /*
83 * Blocking read for the next container state change with timeout
84 * @fd : the file descriptor provided by lxc_monitor_open
85 * @msg : the variable which will be filled with the state
86 * @timeout : the timeout in seconds to wait for a state change
87 * Returns 0 if the monitored container has exited, > 0 if
88 * data was read, < 0 otherwise
89 */
90 extern int lxc_monitor_read_timeout(int fd, struct lxc_msg *msg, int timeout);
91
92 /*
93 * Blocking read from multiple monitors for the next container state
94 * change with timeout
95 * @rfds : an fd_set of file descriptors provided by lxc_monitor_open
96 * @nfds : the maximum fd number in rfds + 1
97 * @msg : the variable which will be filled with the state
98 * @timeout : the timeout in seconds to wait for a state change
99 * Returns 0 if the monitored container has exited, > 0 if
100 * data was read, < 0 otherwise
101 */
102 extern int lxc_monitor_read_fdset(fd_set *rfds, int nfds, struct lxc_msg *msg, int timeout);
103
104 /*
105 * Close the fd associated with the monitoring
106 * @fd : the file descriptor provided by lxc_monitor_open
107 * Returns 0 on success, < 0 otherwise
108 */
109 extern int lxc_monitor_close(int fd);
110
111 /*
112 * Freeze all the tasks running inside the container <name>
113 * @name : the container name
114 * Returns 0 on success, < 0 otherwise
115 */
116 extern int lxc_freeze(const char *name, const char *lxcpath);
117
118 /*
119 * Unfreeze all previously frozen tasks.
120 * @name : the name of the container
121 * Return 0 on sucess, < 0 otherwise
122 */
123 extern int lxc_unfreeze(const char *name, const char *lxcpath);
124
125 /*
126 * Retrieve the container state
127 * @name : the name of the container
128 * Returns the state of the container on success, < 0 otherwise
129 */
130 extern lxc_state_t lxc_state(const char *name, const char *lxcpath);
131
132 struct lxc_handler;
133 /*
134 * Set a specified value for a specified subsystem. The specified
135 * subsystem must be fully specified, eg. "cpu.shares"
136 * @filename : the cgroup attribute filename
137 * @value : the value to be set
138 * @handler : the lxc_handler structure of the container
139 * Returns 0 on success, < 0 otherwise
140 */
141 extern int lxc_cgroup_set_handler(const char *filename, const char *value, struct lxc_handler *handler);
142
143 /*
144 * Set a specified value for a specified subsystem. The specified
145 * subsystem must be fully specified, eg. "cpu.shares"
146 * @filename : the cgroup attribute filename
147 * @value : the value to be set
148 * @name : the name of the container
149 * @lxcpath : lxc config path for container
150 * Returns 0 on success, < 0 otherwise
151 */
152 extern int lxc_cgroup_set(const char *filename, const char *value, const char *name, const char *lxcpath);
153
154 /*
155 * Get a specified value for a specified subsystem. The specified
156 * subsystem must be fully specified, eg. "cpu.shares"
157 * @filename : the cgroup attribute filename
158 * @value : the value to be set
159 * @len : the len of the value variable
160 * @name : the name of the container
161 * @lxcpath : lxc config path for container
162 * Returns the number of bytes read, < 0 on error
163 */
164 extern int lxc_cgroup_get(const char *filename, char *value, size_t len, const char *name, const char *lxcpath);
165
166 /*
167 * Retrieve the error string associated with the error returned by
168 * the function.
169 * @error : the value of the error
170 * Returns a string on success or NULL otherwise.
171 */
172 extern const char *lxc_strerror(int error);
173
174 /*
175 * Checkpoint a container
176 * @name : the name of the container being checkpointed
177 * @sfd: fd on which the container is checkpointed
178 * @flags : checkpoint flags (an ORed value)
179 * Returns 0 on success, < 0 otherwise
180 */
181 extern int lxc_checkpoint(const char *name, int sfd, int flags);
182 #define LXC_FLAG_PAUSE 1
183 #define LXC_FLAG_HALT 2
184
185 /*
186 * Restart a container
187 * @name : the name of the container being restarted
188 * @sfd: fd from which the container is restarted
189 * @conf: lxc_conf structure.
190 * @flags : restart flags (an ORed value)
191 * @lxcpath: container path
192 * Returns 0 on success, < 0 otherwise
193 */
194 extern int lxc_restart(const char *, int, struct lxc_conf *, int, const char *);
195
196 /*
197 * Create and return a new lxccontainer struct.
198 */
199 extern struct lxc_container *lxc_container_new(const char *name, const char *configpath);
200
201 /*
202 * Returns 1 on success, 0 on failure.
203 */
204 extern int lxc_container_get(struct lxc_container *c);
205
206 /*
207 * Put a lxccontainer struct reference.
208 * Return -1 on error.
209 * Return 0 if this was not the last reference.
210 * If it is the last reference, free the lxccontainer and return 1.
211 */
212 extern int lxc_container_put(struct lxc_container *c);
213
214 /*
215 * Get a list of valid wait states.
216 * If states is NULL, simply return the number of states
217 */
218 extern int lxc_get_wait_states(const char **states);
219
220 /*
221 * Add a dependency to a container
222 */
223 extern int add_rdepend(struct lxc_conf *lxc_conf, char *rdepend);
224
225 #ifdef __cplusplus
226 }
227 #endif
228
229 #endif