]>
git.proxmox.com Git - mirror_lxc.git/blob - src/lxc/lxc.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
31 #include <sys/select.h>
32 #include <sys/types.h>
40 Following code is for liblxc.
42 lxc/lxc.h will contain exports of liblxc
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
52 extern int lxc_start(const char *name
, char *const argv
[], struct lxc_conf
*conf
,
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
63 extern int lxc_execute(const char *name
, char *const argv
[], int quiet
,
64 struct lxc_conf
*conf
, const char *lxcpath
);
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
71 extern int lxc_monitor_open(const char *lxcpath
);
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
80 extern int lxc_monitor_read(int fd
, struct lxc_msg
*msg
);
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
90 extern int lxc_monitor_read_timeout(int fd
, struct lxc_msg
*msg
, int timeout
);
93 * Blocking read from multiple monitors for the next container state
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
102 extern int lxc_monitor_read_fdset(fd_set
*rfds
, int nfds
, struct lxc_msg
*msg
, int timeout
);
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
109 extern int lxc_monitor_close(int fd
);
112 * Freeze all the tasks running inside the container <name>
113 * @name : the container name
114 * Returns 0 on success, < 0 otherwise
116 extern int lxc_freeze(const char *name
, const char *lxcpath
);
119 * Unfreeze all previously frozen tasks.
120 * @name : the name of the container
121 * Return 0 on sucess, < 0 otherwise
123 extern int lxc_unfreeze(const char *name
, const char *lxcpath
);
126 * Retrieve the container state
127 * @name : the name of the container
128 * Returns the state of the container on success, < 0 otherwise
130 extern lxc_state_t
lxc_state(const char *name
, const char *lxcpath
);
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
141 extern int lxc_cgroup_set_handler(const char *filename
, const char *value
, struct lxc_handler
*handler
);
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
152 extern int lxc_cgroup_set(const char *filename
, const char *value
, const char *name
, const char *lxcpath
);
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
164 extern int lxc_cgroup_get(const char *filename
, char *value
, size_t len
, const char *name
, const char *lxcpath
);
167 * Retrieve the error string associated with the error returned by
169 * @error : the value of the error
170 * Returns a string on success or NULL otherwise.
172 extern const char *lxc_strerror(int error
);
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
181 extern int lxc_checkpoint(const char *name
, int sfd
, int flags
);
182 #define LXC_FLAG_PAUSE 1
183 #define LXC_FLAG_HALT 2
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
194 extern int lxc_restart(const char *, int, struct lxc_conf
*, int, const char *);
197 * Create and return a new lxccontainer struct.
199 extern struct lxc_container
*lxc_container_new(const char *name
, const char *configpath
);
202 * Returns 1 on success, 0 on failure.
204 extern int lxc_container_get(struct lxc_container
*c
);
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.
212 extern int lxc_container_put(struct lxc_container
*c
);
215 * Get a list of valid wait states.
216 * If states is NULL, simply return the number of states
218 extern int lxc_get_wait_states(const char **states
);
221 * Add a dependency to a container
223 extern int add_rdepend(struct lxc_conf
*lxc_conf
, char *rdepend
);