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