]> git.proxmox.com Git - mirror_lxc.git/blame - src/lxc/lxc.h
licensing: Add missing headers and FSF address
[mirror_lxc.git] / src / lxc / lxc.h
CommitLineData
0ad19a3f 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>
0ad19a3f 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
0ad19a3f 22 */
23#ifndef __lxc_h
24#define __lxc_h
25
26#ifdef __cplusplus
27extern "C" {
28#endif
29
ad3ac5e0 30#include <stddef.h>
2b89a9c1 31#include <sys/select.h>
8d06bd13 32#include <sys/types.h>
ad3ac5e0
MN
33#include <lxc/state.h>
34
35struct lxc_msg;
fae349da 36struct lxc_conf;
0ae4f887 37struct lxc_arguments;
ad3ac5e0 38
0ad19a3f 39/**
40 Following code is for liblxc.
41
2aa79ee7 42 lxc/lxc.h will contain exports of liblxc
0ad19a3f 43 **/
44
0ad19a3f 45/*
0ae4f887 46 * Start the specified command inside a system container
0ad19a3f 47 * @name : the name of the container
0ad19a3f 48 * @argv : an array of char * corresponding to the commande line
91480a0f 49 * @conf : configuration
0ad19a3f 50 * Returns 0 on sucess, < 0 otherwise
51 */
13f5be62
SH
52extern int lxc_start(const char *name, char *const argv[], struct lxc_conf *conf,
53 const char *lxcpath);
0ad19a3f 54
0ae4f887
GK
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 */
63extern int lxc_execute(const char *name, char *const argv[], int quiet,
13f5be62 64 struct lxc_conf *conf, const char *lxcpath);
0ae4f887 65
0ad19a3f 66/*
67 * Open the monitoring mechanism for a specific container
68 * The function will return an fd corresponding to the events
0ad19a3f 69 * Returns a file descriptor on success, < 0 otherwise
70 */
9123e471 71extern int lxc_monitor_open(const char *lxcpath);
0ad19a3f 72
73/*
8d06bd13
DE
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
0ad19a3f 77 * Returns 0 if the monitored container has exited, > 0 if
8d06bd13 78 * data was read, < 0 otherwise
0ad19a3f 79 */
eae6543d 80extern int lxc_monitor_read(int fd, struct lxc_msg *msg);
8d06bd13
DE
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 */
72d0e1cb 90extern int lxc_monitor_read_timeout(int fd, struct lxc_msg *msg, int timeout);
0ad19a3f 91
8d06bd13
DE
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 */
102extern int lxc_monitor_read_fdset(fd_set *rfds, int nfds, struct lxc_msg *msg, int timeout);
103
0ad19a3f 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 */
109extern int lxc_monitor_close(int fd);
110
0ad19a3f 111/*
112 * Freeze all the tasks running inside the container <name>
113 * @name : the container name
114 * Returns 0 on success, < 0 otherwise
115 */
9123e471 116extern int lxc_freeze(const char *name, const char *lxcpath);
0ad19a3f 117
118/*
119 * Unfreeze all previously frozen tasks.
120 * @name : the name of the container
121 * Return 0 on sucess, < 0 otherwise
122 */
9123e471 123extern int lxc_unfreeze(const char *name, const char *lxcpath);
0ad19a3f 124
ae5c8b8e
SH
125/*
126 * Unfreeze all previously frozen tasks.
127 * This is the function to use from inside the monitor
128 * @name : the name of the container
129 * Return 0 on sucess, < 0 otherwise
130 */
131extern int lxc_unfreeze_bypath(const char *cgpath);
132
0ad19a3f 133/*
134 * Retrieve the container state
135 * @name : the name of the container
136 * Returns the state of the container on success, < 0 otherwise
137 */
13f5be62 138extern lxc_state_t lxc_state(const char *name, const char *lxcpath);
0ad19a3f 139
b98f7d6e 140struct lxc_handler;
ae5c8b8e
SH
141/*
142 * Set a specified value for a specified subsystem. The specified
143 * subsystem must be fully specified, eg. "cpu.shares"
b98f7d6e 144 * @d : the cgroup descriptor for the container
ae5c8b8e
SH
145 * @filename : the cgroup attribute filename
146 * @value : the value to be set
147 * Returns 0 on success, < 0 otherwise
148 */
b98f7d6e
SH
149extern int lxc_cgroup_set_value(struct lxc_handler *hander, const char *filename,
150 const char *value);
ae5c8b8e 151
0ad19a3f 152/*
576f946d 153 * Set a specified value for a specified subsystem. The specified
154 * subsystem must be fully specified, eg. "cpu.shares"
155 * @name : the name of the container
ae5c8b8e 156 * @filename : the cgroup attribute filename
576f946d 157 * @value : the value to be set
ae5c8b8e 158 * @lxcpath : lxc config path for container
0ad19a3f 159 * Returns 0 on success, < 0 otherwise
160 */
ae5c8b8e 161extern int lxc_cgroup_set(const char *name, const char *filename, const char *value, const char *lxcpath);
0ad19a3f 162
163/*
576f946d 164 * Get a specified value for a specified subsystem. The specified
165 * subsystem must be fully specified, eg. "cpu.shares"
166 * @name : the name of the container
ae5c8b8e 167 * @filename : the cgroup attribute filename
576f946d 168 * @value : the value to be set
169 * @len : the len of the value variable
ae5c8b8e 170 * @lxcpath : lxc config path for container
70f7755e 171 * Returns the number of bytes read, < 0 on error
0ad19a3f 172 */
bcbd102c 173extern int lxc_cgroup_get(const char *name, const char *filename,
ae5c8b8e 174 char *value, size_t len, const char *lxcpath);
0ad19a3f 175
58412580 176/*
177 * Retrieve the error string associated with the error returned by
178 * the function.
179 * @error : the value of the error
180 * Returns a string on success or NULL otherwise.
181 */
3cf586a2 182extern const char *lxc_strerror(int error);
58412580 183
925aaa31 184/*
ad3ac5e0 185 * Checkpoint a container
925aaa31 186 * @name : the name of the container being checkpointed
9b8e796c 187 * @sfd: fd on which the container is checkpointed
ad3ac5e0 188 * @flags : checkpoint flags (an ORed value)
925aaa31 189 * Returns 0 on success, < 0 otherwise
190 */
9b8e796c 191extern int lxc_checkpoint(const char *name, int sfd, int flags);
ad3ac5e0
MN
192#define LXC_FLAG_PAUSE 1
193#define LXC_FLAG_HALT 2
925aaa31 194
195/*
ad3ac5e0 196 * Restart a container
925aaa31 197 * @name : the name of the container being restarted
9b8e796c 198 * @sfd: fd from which the container is restarted
267d974e 199 * @conf: lxc_conf structure.
ad3ac5e0 200 * @flags : restart flags (an ORed value)
67e571de 201 * @lxcpath: container path
925aaa31 202 * Returns 0 on success, < 0 otherwise
203 */
67e571de 204extern int lxc_restart(const char *, int, struct lxc_conf *, int, const char *);
925aaa31 205
72d0e1cb
SG
206/*
207 * Create and return a new lxccontainer struct.
208 */
afeecbba 209extern struct lxc_container *lxc_container_new(const char *name, const char *configpath);
72d0e1cb
SG
210
211/*
212 * Returns 1 on success, 0 on failure.
213 */
214extern int lxc_container_get(struct lxc_container *c);
215
216/*
217 * Put a lxccontainer struct reference.
218 * Return -1 on error.
219 * Return 0 if this was not the last reference.
220 * If it is the last reference, free the lxccontainer and return 1.
221 */
222extern int lxc_container_put(struct lxc_container *c);
223
224/*
225 * Get a list of valid wait states.
226 * If states is NULL, simply return the number of states
227 */
4a7c7daa 228extern int lxc_get_wait_states(const char **states);
72d0e1cb 229
dfb31b25
SH
230/*
231 * Add a dependency to a container
232 */
233extern int add_rdepend(struct lxc_conf *lxc_conf, char *rdepend);
234
0ad19a3f 235#ifdef __cplusplus
236}
237#endif
238
239#endif