]> git.proxmox.com Git - mirror_lxc.git/blame - src/lxc/lxc.h
split cgroup handling into discrete backends
[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>
f2363e38 33#include "state.h"
ad3ac5e0
MN
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
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 */
13f5be62 130extern lxc_state_t lxc_state(const char *name, const char *lxcpath);
0ad19a3f 131
0ad19a3f 132/*
576f946d 133 * Set a specified value for a specified subsystem. The specified
134 * subsystem must be fully specified, eg. "cpu.shares"
ae5c8b8e 135 * @filename : the cgroup attribute filename
576f946d 136 * @value : the value to be set
33ad9f1a 137 * @name : the name of the container
ae5c8b8e 138 * @lxcpath : lxc config path for container
0ad19a3f 139 * Returns 0 on success, < 0 otherwise
140 */
33ad9f1a 141extern int lxc_cgroup_set(const char *filename, const char *value, const char *name, const char *lxcpath);
0ad19a3f 142
143/*
576f946d 144 * Get a specified value for a specified subsystem. The specified
145 * subsystem must be fully specified, eg. "cpu.shares"
ae5c8b8e 146 * @filename : the cgroup attribute filename
576f946d 147 * @value : the value to be set
148 * @len : the len of the value variable
33ad9f1a 149 * @name : the name of the container
ae5c8b8e 150 * @lxcpath : lxc config path for container
70f7755e 151 * Returns the number of bytes read, < 0 on error
0ad19a3f 152 */
33ad9f1a 153extern int lxc_cgroup_get(const char *filename, char *value, size_t len, const char *name, const char *lxcpath);
0ad19a3f 154
58412580 155/*
156 * Retrieve the error string associated with the error returned by
157 * the function.
158 * @error : the value of the error
159 * Returns a string on success or NULL otherwise.
160 */
3cf586a2 161extern const char *lxc_strerror(int error);
58412580 162
72d0e1cb
SG
163/*
164 * Create and return a new lxccontainer struct.
165 */
afeecbba 166extern struct lxc_container *lxc_container_new(const char *name, const char *configpath);
72d0e1cb
SG
167
168/*
169 * Returns 1 on success, 0 on failure.
170 */
171extern int lxc_container_get(struct lxc_container *c);
172
173/*
174 * Put a lxccontainer struct reference.
175 * Return -1 on error.
176 * Return 0 if this was not the last reference.
177 * If it is the last reference, free the lxccontainer and return 1.
178 */
179extern int lxc_container_put(struct lxc_container *c);
180
181/*
182 * Get a list of valid wait states.
183 * If states is NULL, simply return the number of states
184 */
4a7c7daa 185extern int lxc_get_wait_states(const char **states);
72d0e1cb 186
dfb31b25
SH
187/*
188 * Add a dependency to a container
189 */
190extern int add_rdepend(struct lxc_conf *lxc_conf, char *rdepend);
191
0ad19a3f 192#ifdef __cplusplus
193}
194#endif
195
196#endif