]>
Commit | Line | Data |
---|---|---|
953e611c JH |
1 | /*! \file |
2 | * | |
3 | * liblxcapi | |
250b1eec SG |
4 | * |
5 | * Copyright © 2012 Serge Hallyn <serge.hallyn@ubuntu.com>. | |
6 | * Copyright © 2012 Canonical Ltd. | |
7 | * | |
8 | * This library is free software; you can redistribute it and/or | |
9 | * modify it under the terms of the GNU Lesser General Public | |
10 | * License as published by the Free Software Foundation; either | |
11 | * version 2.1 of the License, or (at your option) any later version. | |
12 | ||
13 | * This library is distributed in the hope that it will be useful, | |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
16 | * Lesser General Public License for more details. | |
17 | ||
18 | * You should have received a copy of the GNU Lesser General Public | |
19 | * License along with this library; if not, write to the Free Software | |
20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | |
21 | */ | |
22 | ||
9be53773 SH |
23 | #ifndef __LXC_CONTAINER_H |
24 | #define __LXC_CONTAINER_H | |
d38dd64a | 25 | |
72d0e1cb | 26 | #include <malloc.h> |
95ee490b | 27 | #include <semaphore.h> |
72d0e1cb | 28 | #include <stdbool.h> |
d659597e | 29 | #include <stdint.h> |
d38dd64a | 30 | #include <stdlib.h> |
72d0e1cb | 31 | |
f2363e38 ÇO |
32 | #include <lxc/attach_options.h> |
33 | ||
579e783e AM |
34 | #ifdef __cplusplus |
35 | extern "C" { | |
36 | #endif | |
37 | ||
953e611c | 38 | #define LXC_CLONE_KEEPNAME (1 << 0) /*!< Do not edit the rootfs to change the hostname */ |
619256b5 ÇO |
39 | #define LXC_CLONE_KEEPMACADDR (1 << 1) /*!< Do not change the MAC address on network interfaces */ |
40 | #define LXC_CLONE_SNAPSHOT (1 << 2) /*!< Snapshot the original filesystem(s) */ | |
0a83cbbb SH |
41 | #define LXC_CLONE_KEEPBDEVTYPE (1 << 3) /*!< Use the same bdev type */ |
42 | #define LXC_CLONE_MAYBE_SNAPSHOT (1 << 4) /*!< Snapshot only if bdev supports it, else copy */ | |
43 | #define LXC_CLONE_MAXFLAGS (1 << 5) /*!< Number of \c LXC_CLONE_* flags */ | |
754076f5 | 44 | #define LXC_CLONE_ALLOW_RUNNING (1 << 6) /*!< allow snapshot creation even if source container is running */ |
953e611c JH |
45 | #define LXC_CREATE_QUIET (1 << 0) /*!< Redirect \c stdin to \c /dev/zero and \c stdout and \c stderr to \c /dev/null */ |
46 | #define LXC_CREATE_MAXFLAGS (1 << 1) /*!< Number of \c LXC_CREATE* flags */ | |
29df56cd | 47 | #define LXC_MOUNT_API_V1 1 |
dc23c1c8 | 48 | |
1897e3bc SH |
49 | struct bdev_specs; |
50 | ||
f5dd1d53 SH |
51 | struct lxc_snapshot; |
52 | ||
95ee490b SG |
53 | struct lxc_lock; |
54 | ||
aef3d51e TA |
55 | struct migrate_opts; |
56 | ||
191d43cc CB |
57 | struct lxc_console_log; |
58 | ||
29df56cd LT |
59 | struct lxc_mount { |
60 | int version; | |
61 | }; | |
62 | ||
953e611c JH |
63 | /*! |
64 | * An LXC container. | |
e2ae7f6d SH |
65 | * |
66 | * Note that changing the order of struct members is an API change, as callers | |
67 | * will end up having the wrong offset when calling a function. So when making | |
68 | * changes, whenever possible stick to simply appending new members. | |
953e611c | 69 | */ |
72d0e1cb | 70 | struct lxc_container { |
1a0e70ac | 71 | /* private fields */ |
953e611c JH |
72 | /*! |
73 | * \private | |
74 | * Name of container. | |
75 | */ | |
72d0e1cb | 76 | char *name; |
953e611c JH |
77 | |
78 | /*! | |
79 | * \private | |
80 | * Full path to configuration file. | |
81 | */ | |
72d0e1cb | 82 | char *configfile; |
953e611c | 83 | |
72cf75fa QH |
84 | /*! |
85 | * \private | |
86 | * File to store pid. | |
87 | */ | |
88 | char *pidfile; | |
89 | ||
953e611c JH |
90 | /*! |
91 | * \private | |
92 | * Container semaphore lock. | |
93 | */ | |
df271a59 | 94 | struct lxc_lock *slock; |
953e611c JH |
95 | |
96 | /*! | |
97 | * \private | |
98 | * Container private lock. | |
99 | */ | |
df271a59 | 100 | struct lxc_lock *privlock; |
953e611c JH |
101 | |
102 | /*! | |
103 | * \private | |
104 | * Number of references to this container. | |
105 | * \note protected by privlock. | |
106 | */ | |
107 | int numthreads; | |
108 | ||
109 | /*! | |
110 | * \private | |
111 | * Container configuration. | |
112 | * | |
113 | * \internal FIXME: do we want the whole lxc_handler? | |
114 | */ | |
115 | struct lxc_conf *lxc_conf; | |
72d0e1cb | 116 | |
1a0e70ac | 117 | /* public fields */ |
953e611c | 118 | /*! Human-readable string representing last error */ |
72d0e1cb | 119 | char *error_string; |
953e611c JH |
120 | |
121 | /*! Last error number */ | |
72d0e1cb | 122 | int error_num; |
953e611c JH |
123 | |
124 | /*! Whether container wishes to be daemonized */ | |
540f932a | 125 | bool daemonize; |
72d0e1cb | 126 | |
953e611c | 127 | /*! Full path to configuration file */ |
2a59a681 SH |
128 | char *config_path; |
129 | ||
953e611c JH |
130 | /*! |
131 | * \brief Determine if \c /var/lib/lxc/$name/config exists. | |
132 | * | |
133 | * \param c Container. | |
134 | * | |
135 | * \return \c true if container is defined, else \c false. | |
136 | */ | |
137 | bool (*is_defined)(struct lxc_container *c); | |
138 | ||
139 | /*! | |
140 | * \brief Determine state of container. | |
141 | * | |
142 | * \param c Container. | |
143 | * | |
144 | * \return Static upper-case string representing state of container. | |
145 | * | |
146 | * \note Returned string must not be freed. | |
147 | */ | |
72d0e1cb | 148 | const char *(*state)(struct lxc_container *c); |
953e611c JH |
149 | |
150 | /*! | |
151 | * \brief Determine if container is running. | |
152 | * | |
153 | * \param c Container. | |
154 | * | |
155 | * \return \c true on success, else \c false. | |
156 | */ | |
157 | bool (*is_running)(struct lxc_container *c); | |
158 | ||
159 | /*! | |
160 | * \brief Freeze running container. | |
161 | * | |
162 | * \param c Container. | |
163 | * | |
164 | * \return \c true on success, else \c false. | |
165 | */ | |
72d0e1cb | 166 | bool (*freeze)(struct lxc_container *c); |
953e611c JH |
167 | |
168 | /*! | |
169 | * \brief Thaw a frozen container. | |
170 | * | |
171 | * \param c Container. | |
172 | * | |
173 | * \return \c true on success, else \c false. | |
174 | */ | |
72d0e1cb | 175 | bool (*unfreeze)(struct lxc_container *c); |
953e611c JH |
176 | |
177 | /*! | |
178 | * \brief Determine process ID of the containers init process. | |
179 | * | |
180 | * \param c Container. | |
f7f1ba77 | 181 | * |
953e611c JH |
182 | * \return pid of init process as seen from outside the |
183 | * container. | |
184 | */ | |
72d0e1cb | 185 | pid_t (*init_pid)(struct lxc_container *c); |
953e611c JH |
186 | |
187 | /*! | |
188 | * \brief Load the specified configuration for the container. | |
189 | * | |
190 | * \param c Container. | |
191 | * \param alt_file Full path to alternate configuration file, or | |
192 | * \c NULL to use the default configuration file. | |
193 | * | |
194 | * \return \c true on success, else \c false. | |
195 | */ | |
12a50cc6 | 196 | bool (*load_config)(struct lxc_container *c, const char *alt_file); |
953e611c JH |
197 | |
198 | /*! | |
199 | * \brief Start the container. | |
200 | * | |
201 | * \param c Container. | |
202 | * \param useinit Use lxcinit rather than \c /sbin/init. | |
203 | * \param argv Array of arguments to pass to init. | |
204 | * | |
205 | * \return \c true on success, else \c false. | |
206 | */ | |
12a50cc6 | 207 | bool (*start)(struct lxc_container *c, int useinit, char * const argv[]); |
953e611c JH |
208 | |
209 | /*! | |
210 | * \brief Start the container (list variant). | |
211 | * | |
212 | * \param c Container. | |
213 | * \param useinit Use lxcinit rather than \c /sbin/init. | |
214 | * \param ... Command-line to pass to init (must end in \c NULL). | |
215 | * | |
216 | * \return \c true on success, else \c false. | |
217 | * | |
218 | * \note Identical to \ref start except that that the init | |
219 | * arguments are specified via a list rather than an array of | |
220 | * pointers. | |
221 | */ | |
72d0e1cb | 222 | bool (*startl)(struct lxc_container *c, int useinit, ...); |
953e611c JH |
223 | |
224 | /*! | |
225 | * \brief Stop the container. | |
226 | * | |
227 | * \param c Container. | |
228 | * | |
229 | * \return \c true on success, else \c false. | |
230 | */ | |
72d0e1cb | 231 | bool (*stop)(struct lxc_container *c); |
953e611c JH |
232 | |
233 | /*! | |
289cdc73 | 234 | * \brief Change whether the container wants to run disconnected |
953e611c JH |
235 | * from the terminal. |
236 | * | |
237 | * \param c Container. | |
c9d845b5 | 238 | * \param state Value for the daemonize bit (0 or 1). |
953e611c | 239 | * |
289cdc73 | 240 | * \return \c true on success, else \c false. |
953e611c | 241 | */ |
540f932a | 242 | bool (*want_daemonize)(struct lxc_container *c, bool state); |
953e611c JH |
243 | |
244 | /*! | |
289cdc73 | 245 | * \brief Change whether the container wishes all file descriptors |
953e611c JH |
246 | * to be closed on startup. |
247 | * | |
248 | * \param c Container. | |
c9d845b5 | 249 | * \param state Value for the close_all_fds bit (0 or 1). |
953e611c | 250 | * |
289cdc73 | 251 | * \return \c true on success, else \c false. |
953e611c | 252 | */ |
540f932a | 253 | bool (*want_close_all_fds)(struct lxc_container *c, bool state); |
953e611c JH |
254 | |
255 | /*! | |
256 | * \brief Return current config file name. | |
257 | * | |
258 | * \param c Container. | |
259 | * | |
260 | * \return config file name, or \c NULL on error. | |
261 | * | |
262 | * \note The result is allocated, so the caller must free the result. | |
263 | */ | |
72d0e1cb | 264 | char *(*config_file_name)(struct lxc_container *c); |
953e611c JH |
265 | |
266 | /*! | |
267 | * \brief Wait for container to reach a particular state. | |
268 | * | |
269 | * \param c Container. | |
270 | * \param state State to wait for. | |
271 | * \param timeout Timeout in seconds. | |
272 | * | |
273 | * \return \c true if state reached within \p timeout, else \c false. | |
274 | * | |
275 | * \note A \p timeout of \c -1 means wait forever. A \p timeout | |
276 | * of \c 0 means do not wait. | |
277 | */ | |
12a50cc6 | 278 | bool (*wait)(struct lxc_container *c, const char *state, int timeout); |
953e611c JH |
279 | |
280 | /*! | |
281 | * \brief Set a key/value configuration option. | |
282 | * | |
283 | * \param c Container. | |
284 | * \param key Name of option to set. | |
285 | * \param value Value of \p name to set. | |
286 | * | |
287 | * \return \c true on success, else \c false. | |
288 | */ | |
12a50cc6 | 289 | bool (*set_config_item)(struct lxc_container *c, const char *key, const char *value); |
953e611c JH |
290 | |
291 | /*! | |
292 | * \brief Delete the container. | |
293 | * | |
294 | * \param c Container. | |
295 | * | |
296 | * \return \c true on success, else \c false. | |
297 | * | |
298 | * \note Container must be stopped and have no dependent snapshots. | |
299 | */ | |
72d0e1cb | 300 | bool (*destroy)(struct lxc_container *c); |
953e611c JH |
301 | |
302 | /*! | |
056da80e | 303 | * \brief Save configuration to a file. |
953e611c JH |
304 | * |
305 | * \param c Container. | |
306 | * \param alt_file Full path to file to save configuration in. | |
307 | * | |
308 | * \return \c true on success, else \c false. | |
309 | */ | |
12a50cc6 | 310 | bool (*save_config)(struct lxc_container *c, const char *alt_file); |
953e611c JH |
311 | |
312 | /*! | |
313 | * \brief Create a container. | |
314 | * | |
315 | * \param c Container (with lxcpath, name and a starting | |
316 | * configuration set). | |
317 | * \param t Template to execute to instantiate the root | |
318 | * filesystem and adjust the configuration. | |
319 | * \param bdevtype Backing store type to use (if \c NULL, \c dir will be used). | |
320 | * \param specs Additional parameters for the backing store (for | |
321 | * example LVM volume group to use). | |
322 | * \param flags \c LXC_CREATE_* options (currently only \ref | |
323 | * LXC_CREATE_QUIET is supported). | |
324 | * \param argv Arguments to pass to the template, terminated by \c NULL (if no | |
325 | * arguments are required, just pass \c NULL). | |
326 | * | |
327 | * \return \c true on success, else \c false. | |
328 | */ | |
1897e3bc | 329 | bool (*create)(struct lxc_container *c, const char *t, const char *bdevtype, |
dc23c1c8 | 330 | struct bdev_specs *specs, int flags, char *const argv[]); |
953e611c JH |
331 | |
332 | /*! | |
333 | * \brief Create a container (list variant). | |
334 | * | |
335 | * \param c Container (with lxcpath, name and a starting | |
336 | * configuration set). | |
337 | * \param t Template to execute to instantiate the root | |
338 | * filesystem and adjust the configuration. | |
339 | * \param bdevtype Backing store type to use (if \c NULL, \c dir will be used). | |
340 | * \param specs Additional parameters for the backing store (for | |
341 | * example LVM volume group to use). | |
342 | * \param flags \c LXC_CREATE_* options (currently only \ref | |
343 | * LXC_CREATE_QUIET is supported). | |
344 | * \param ... Command-line to pass to init (must end in \c NULL). | |
345 | * | |
346 | * \return \c true on success, else \c false. | |
347 | * | |
348 | * \note Identical to \ref create except that the template | |
349 | * arguments are specified as a list rather than an array of | |
350 | * pointers. | |
351 | */ | |
1897e3bc | 352 | bool (*createl)(struct lxc_container *c, const char *t, const char *bdevtype, |
dc23c1c8 | 353 | struct bdev_specs *specs, int flags, ...); |
953e611c | 354 | |
06e5650e ÇO |
355 | /*! |
356 | * \brief Rename a container | |
357 | * | |
358 | * \param c Container. | |
359 | * \param newname New name to be used for the container. | |
360 | * | |
361 | * \return \c true on success, else \c false. | |
362 | */ | |
363 | bool (*rename)(struct lxc_container *c, const char *newname); | |
364 | ||
953e611c JH |
365 | /*! |
366 | * \brief Request the container reboot by sending it \c SIGINT. | |
367 | * | |
368 | * \param c Container. | |
369 | * | |
370 | * \return \c true if reboot request successful, else \c false. | |
371 | */ | |
3e625e2d | 372 | bool (*reboot)(struct lxc_container *c); |
953e611c JH |
373 | |
374 | /*! | |
375 | * \brief Request the container shutdown by sending it \c | |
376 | * SIGPWR. | |
377 | * | |
378 | * \param c Container. | |
0464b881 SG |
379 | * \param timeout Seconds to wait before returning false. |
380 | * (-1 to wait forever, 0 to avoid waiting). | |
953e611c | 381 | * |
0464b881 | 382 | * \return \c true if the container was shutdown successfully, else \c false. |
953e611c | 383 | */ |
72d0e1cb | 384 | bool (*shutdown)(struct lxc_container *c, int timeout); |
953e611c JH |
385 | |
386 | /*! | |
387 | * \brief Completely clear the containers in-memory configuration. | |
388 | * | |
389 | * \param c Container. | |
390 | */ | |
4df7f012 | 391 | void (*clear_config)(struct lxc_container *c); |
953e611c JH |
392 | |
393 | /*! | |
394 | * \brief Clear a configuration item. | |
395 | * | |
396 | * \param c Container. | |
397 | * \param key Name of option to clear. | |
398 | * | |
399 | * \return \c true on success, else \c false. | |
400 | * | |
401 | * \note Analog of \ref set_config_item. | |
402 | */ | |
12a50cc6 | 403 | bool (*clear_config_item)(struct lxc_container *c, const char *key); |
953e611c JH |
404 | |
405 | /*! | |
406 | * \brief Retrieve the value of a config item. | |
407 | * | |
408 | * \param c Container. | |
409 | * \param key Name of option to get. | |
410 | * \param[out] retv Caller-allocated buffer to write value of \p key | |
411 | * into (or \c NULL to determine length of value). | |
412 | * \param inlen Length of \p retv (may be zero). | |
413 | * | |
414 | * \return Length of config items value, or < 0 on error. | |
415 | * | |
416 | * \note The caller can (and should) determine how large a buffer to allocate for | |
417 | * \p retv by initially passing its value as \c NULL and considering the return value. | |
418 | * This function can then be called again passing a newly-allocated suitably-sized buffer. | |
419 | * \note If \p retv is NULL, \p inlen is ignored. | |
13a4215b | 420 | * \note If \p inlen is smaller than required, nothing will be written to \p retv and still return |
421 | * the length of config item value. | |
953e611c | 422 | */ |
12a50cc6 | 423 | int (*get_config_item)(struct lxc_container *c, const char *key, char *retv, int inlen); |
953e611c | 424 | |
8ac18377 ÇO |
425 | |
426 | /*! | |
427 | * \brief Retrieve the value of a config item from running container. | |
428 | * | |
429 | * \param c Container. | |
430 | * \param key Name of option to get. | |
431 | * | |
432 | * \return the item or NULL on error. | |
433 | * | |
434 | * \note Returned string must be freed by the caller. | |
435 | */ | |
436 | char* (*get_running_config_item)(struct lxc_container *c, const char *key); | |
437 | ||
953e611c JH |
438 | /*! |
439 | * \brief Retrieve a list of config item keys given a key | |
440 | * prefix. | |
441 | * | |
442 | * \param c Container. | |
443 | * \param key Name of option to get. | |
444 | * \param[out] retv Caller-allocated buffer to write list of keys to | |
445 | * (or \c NULL to determine overall length of keys list). | |
446 | * \param inlen Length of \p retv (may be zero). | |
447 | * | |
448 | * \return Length of keys list, or < 0 on error. | |
449 | * | |
450 | * \note The list values written to \p retv are separated by | |
451 | * a newline character ('\\n'). | |
452 | * \note The caller can (and should) determine how large a buffer to allocate for | |
453 | * \p retv by initially passing its value as \c NULL and considering the return value. | |
454 | * This function can then be called again passing a newly-allocated suitably-sized buffer. | |
455 | * \note If \p retv is NULL, \p inlen is ignored. | |
456 | * \note If \p inlen is smaller than required, the value written | |
457 | * to \p retv will be truncated. | |
458 | */ | |
12a50cc6 | 459 | int (*get_keys)(struct lxc_container *c, const char *key, char *retv, int inlen); |
953e611c JH |
460 | |
461 | /*! | |
462 | * \brief Obtain a list of network interfaces. | |
463 | * \param c Container. | |
464 | * | |
465 | * \return Newly-allocated array of network interfaces, or \c | |
466 | * NULL on error. | |
467 | * | |
468 | * \note The returned array is allocated, so the caller must free it. | |
469 | * \note The returned array is terminated with a \c NULL entry. | |
470 | */ | |
799f29ab | 471 | char** (*get_interfaces)(struct lxc_container *c); |
953e611c JH |
472 | |
473 | /*! | |
474 | * \brief Determine the list of container IP addresses. | |
475 | * | |
476 | * \param c Container. | |
477 | * \param interface Network interface name to consider. | |
478 | * \param family Network family (for example "inet", "inet6"). | |
479 | * \param scope IPv6 scope id (ignored if \p family is not "inet6"). | |
480 | * | |
481 | * \return Newly-allocated array of network interfaces, or \c | |
482 | * NULL on error. | |
483 | * | |
484 | * \note The returned array is allocated, so the caller must free it. | |
485 | * \note The returned array is terminated with a \c NULL entry. | |
486 | */ | |
f0ca2726 | 487 | char** (*get_ips)(struct lxc_container *c, const char* interface, const char* family, int scope); |
953e611c JH |
488 | |
489 | /*! | |
490 | * \brief Retrieve the specified cgroup subsystem value for the container. | |
491 | * | |
492 | * \param c Container. | |
493 | * \param subsys cgroup subsystem to retrieve. | |
494 | * \param[out] retv Caller-allocated buffer to write value of \p | |
495 | * subsys into (or \c NULL to determine length of value). | |
496 | * \param inlen length of \p retv (may be zero). | |
497 | * | |
498 | * \return Length of \p subsys value, or < 0 on error. | |
499 | * | |
500 | * \note If \p retv is \c NULL, \p inlen is ignored. | |
501 | * \note If \p inlen is smaller than required, the value written | |
502 | * to \p retv will be truncated. | |
794dd120 SH |
503 | */ |
504 | int (*get_cgroup_item)(struct lxc_container *c, const char *subsys, char *retv, int inlen); | |
953e611c JH |
505 | |
506 | /*! | |
507 | * \brief Set the specified cgroup subsystem value for the container. | |
508 | * | |
509 | * \param c Container. | |
510 | * \param subsys cgroup subsystem to consider. | |
511 | * \param value Value to set for \p subsys. | |
512 | * | |
513 | * \return \c true on success, else \c false. | |
514 | */ | |
794dd120 | 515 | bool (*set_cgroup_item)(struct lxc_container *c, const char *subsys, const char *value); |
72d0e1cb | 516 | |
953e611c JH |
517 | /*! |
518 | * \brief Determine full path to the containers configuration file. | |
519 | * Each container can have a custom configuration path. However | |
520 | * by default it will be set to either the \c LXCPATH configure | |
521 | * variable, or the lxcpath value in the \c LXC_GLOBAL_CONF configuration | |
522 | * file (i.e. \c /etc/lxc/lxc.conf). | |
523 | * The value for a specific container can be changed using | |
524 | * \ref set_config_path. There is no other way to specify this in general at the moment. | |
525 | * | |
526 | * \param c Container. | |
527 | * | |
528 | * \return Static string representing full path to configuration | |
529 | * file. | |
530 | * | |
531 | * \note Returned string must not be freed. | |
2a59a681 SH |
532 | */ |
533 | const char *(*get_config_path)(struct lxc_container *c); | |
953e611c JH |
534 | |
535 | /*! | |
536 | * \brief Set the full path to the containers configuration | |
537 | * file. | |
538 | * | |
539 | * \param c Container. | |
540 | * \param path Full path to configuration file. | |
541 | * | |
542 | * \return \c true on success, else \c false. | |
543 | */ | |
2a59a681 SH |
544 | bool (*set_config_path)(struct lxc_container *c, const char *path); |
545 | ||
953e611c JH |
546 | /*! |
547 | * \brief Copy a stopped container. | |
548 | * | |
549 | * \param c Original container. | |
550 | * \param newname New name for the container. If \c NULL, the same | |
551 | * name is used and a new lxcpath MUST be specified. | |
552 | * \param lxcpath lxcpath in which to create the new container. If | |
553 | * \c NULL, the original container's lxcpath will be used. | |
554 | * (XXX: should we use the default instead?) | |
555 | * \param flags Additional \c LXC_CLONE* flags to change the cloning behaviour: | |
556 | * - \ref LXC_CLONE_KEEPNAME | |
953e611c JH |
557 | * - \ref LXC_CLONE_KEEPMACADDR |
558 | * - \ref LXC_CLONE_SNAPSHOT | |
559 | * \param bdevtype Optionally force the cloned bdevtype to a specified plugin. | |
560 | * By default the original is used (subject to snapshot requirements). | |
561 | * \param bdevdata Information about how to create the new storage | |
562 | * (i.e. fstype and fsdata). | |
cf642e10 | 563 | * \param newsize In case of a block device backing store, an |
953e611c JH |
564 | * optional size. If \c 0, the original backing store's size will |
565 | * be used if possible. Note this only applies to the rootfs. For | |
566 | * any other filesystems, the original size will be duplicated. | |
567 | * \param hookargs Additional arguments to pass to the clone hook script. | |
568 | * | |
569 | * \return Newly-allocated copy of container \p c, or \p NULL on | |
570 | * error. | |
571 | * | |
572 | * \note If devtype was not specified, and \p flags contains \ref | |
573 | * LXC_CLONE_SNAPSHOT then use the native \p bdevtype if possible, | |
574 | * else use an overlayfs. | |
9be53773 SH |
575 | */ |
576 | struct lxc_container *(*clone)(struct lxc_container *c, const char *newname, | |
953e611c | 577 | const char *lxcpath, int flags, const char *bdevtype, |
d659597e | 578 | const char *bdevdata, uint64_t newsize, char **hookargs); |
9be53773 | 579 | |
953e611c JH |
580 | /*! |
581 | * \brief Allocate a console tty for the container. | |
0115f8fd | 582 | * |
953e611c JH |
583 | * \param c Container. |
584 | * \param[in,out] ttynum Terminal number to attempt to allocate, | |
585 | * or \c -1 to allocate the first available tty. | |
ec64264d | 586 | * \param[out] masterfd File descriptor referring to the master side of the pty. |
0115f8fd | 587 | * |
953e611c JH |
588 | * \return tty file descriptor number on success, or \c -1 on |
589 | * failure. | |
590 | * | |
591 | * \note On successful return, \p ttynum will contain the tty number | |
592 | * that was allocated. | |
593 | * \note The returned file descriptor is used to keep the tty | |
594 | * allocated. The caller should call close(2) on the returned file | |
595 | * descriptor when no longer required so that it may be allocated | |
596 | * by another caller. | |
0115f8fd | 597 | */ |
b5159817 DE |
598 | int (*console_getfd)(struct lxc_container *c, int *ttynum, int *masterfd); |
599 | ||
953e611c JH |
600 | /*! |
601 | * \brief Allocate and run a console tty. | |
602 | * | |
603 | * \param c Container. | |
604 | * \param ttynum Terminal number to attempt to allocate, \c -1 to | |
605 | * allocate the first available tty or \c 0 to allocate the | |
606 | * console. | |
607 | * \param stdinfd File descriptor to read input from. | |
608 | * \param stdoutfd File descriptor to write output to. | |
609 | * \param stderrfd File descriptor to write error output to. | |
610 | * \param escape The escape character (1 == 'a', 2 == 'b', ...). | |
b5159817 | 611 | * |
953e611c | 612 | * \return \c 0 on success, \c -1 on failure. |
b5159817 | 613 | * |
953e611c JH |
614 | * \note This function will not return until the console has been |
615 | * exited by the user. | |
b5159817 DE |
616 | */ |
617 | int (*console)(struct lxc_container *c, int ttynum, | |
953e611c | 618 | int stdinfd, int stdoutfd, int stderrfd, int escape); |
0115f8fd | 619 | |
953e611c JH |
620 | /*! |
621 | * \brief Create a sub-process attached to a container and run | |
622 | * a function inside it. | |
623 | * | |
624 | * \param c Container. | |
625 | * \param exec_function Function to run. | |
626 | * \param exec_payload Data to pass to \p exec_function. | |
627 | * \param options \ref lxc_attach_options_t. | |
628 | * \param[out] attached_process Process ID of process running inside | |
629 | * container \p c that is running \p exec_function. | |
630 | * | |
631 | * \return \c 0 on success, \c -1 on error. | |
632 | */ | |
633 | int (*attach)(struct lxc_container *c, lxc_attach_exec_t exec_function, | |
634 | void *exec_payload, lxc_attach_options_t *options, pid_t *attached_process); | |
a0e93eeb | 635 | |
953e611c JH |
636 | /*! |
637 | * \brief Run a program inside a container and wait for it to exit. | |
638 | * | |
639 | * \param c Container. | |
640 | * \param options See \ref attach options. | |
641 | * \param program Full path inside container of program to run. | |
642 | * \param argv Array of arguments to pass to \p program. | |
643 | * | |
644 | * \return \c waitpid(2) status of exited process that ran \p | |
645 | * program, or \c -1 on error. | |
646 | */ | |
a0e93eeb | 647 | int (*attach_run_wait)(struct lxc_container *c, lxc_attach_options_t *options, const char *program, const char * const argv[]); |
f5dd1d53 | 648 | |
953e611c JH |
649 | /*! |
650 | * \brief Run a program inside a container and wait for it to exit (list variant). | |
651 | * | |
652 | * \param c Container. | |
653 | * \param options See \ref attach options. | |
654 | * \param program Full path inside container of program to run. | |
655 | * \param ... Command-line to pass to \p program (must end in \c NULL). | |
656 | * | |
657 | * \return \c waitpid(2) status of exited process that ran \p | |
658 | * program, or \c -1 on error. | |
659 | */ | |
660 | int (*attach_run_waitl)(struct lxc_container *c, lxc_attach_options_t *options, const char *program, const char *arg, ...); | |
f5dd1d53 | 661 | |
953e611c JH |
662 | /*! |
663 | * \brief Create a container snapshot. | |
664 | * | |
665 | * Assuming default paths, snapshots will be created as | |
18aa217b | 666 | * \c /var/lib/lxc/\<c\>/snaps/snap\<n\> |
953e611c JH |
667 | * where \c \<c\> represents the container name and \c \<n\> |
668 | * represents the zero-based snapshot number. | |
669 | * | |
670 | * \param c Container. | |
671 | * \param commentfile Full path to file containing a description | |
672 | * of the snapshot. | |
673 | * | |
674 | * \return -1 on error, or zero-based snapshot number. | |
f5dd1d53 | 675 | * |
953e611c | 676 | * \note \p commentfile may be \c NULL but this is discouraged. |
f5dd1d53 | 677 | */ |
f0ca2726 | 678 | int (*snapshot)(struct lxc_container *c, const char *commentfile); |
f5dd1d53 | 679 | |
953e611c JH |
680 | /*! |
681 | * \brief Obtain a list of container snapshots. | |
682 | * | |
683 | * \param c Container. | |
684 | * \param[out] snapshots Dynamically-allocated Array of lxc_snapshot's. | |
f5dd1d53 | 685 | * |
953e611c | 686 | * \return Number of snapshots. |
f5dd1d53 | 687 | * |
953e611c JH |
688 | * \note The array returned in \p snapshots is allocated, so the caller must free it. |
689 | * \note To free an individual snapshot as returned in \p | |
690 | * snapshots, call the snapshots \c free function (see \c src/tests/snapshot.c for an example). | |
691 | */ | |
692 | int (*snapshot_list)(struct lxc_container *c, struct lxc_snapshot **snapshots); | |
693 | ||
694 | /*! | |
695 | * \brief Create a new container based on a snapshot. | |
f5dd1d53 | 696 | * |
953e611c JH |
697 | * The restored container will be a copy (not snapshot) of the snapshot, |
698 | * and restored in the lxcpath of the original container. | |
699 | * \param c Container. | |
700 | * \param snapname Name of snapshot. | |
701 | * \param newname Name to be used for the restored snapshot. | |
702 | * \return \c true on success, else \c false. | |
703 | * \warning If \p newname is the same as the current container | |
704 | * name, the container will be destroyed. However, this will | |
1f92162d | 705 | * fail if the snapshot is overlay-based, since the snapshots |
953e611c JH |
706 | * will pin the original container. |
707 | * \note As an example, if the container exists as \c /var/lib/lxc/c1, snapname might be \c 'snap0' | |
18aa217b | 708 | * (representing \c /var/lib/lxc/c1/snaps/snap0). If \p newname is \p c2, |
953e611c | 709 | * then \c snap0 will be copied to \c /var/lib/lxc/c2. |
f5dd1d53 | 710 | */ |
f0ca2726 | 711 | bool (*snapshot_restore)(struct lxc_container *c, const char *snapname, const char *newname); |
b494d2dd | 712 | |
953e611c JH |
713 | /*! |
714 | * \brief Destroy the specified snapshot. | |
771d96b3 | 715 | * |
953e611c JH |
716 | * \param c Container. |
717 | * \param snapname Name of snapshot. | |
718 | * | |
719 | * \return \c true on success, else \c false. | |
771d96b3 | 720 | */ |
f0ca2726 | 721 | bool (*snapshot_destroy)(struct lxc_container *c, const char *snapname); |
771d96b3 | 722 | |
953e611c JH |
723 | /*! |
724 | * \brief Determine if the caller may control the container. | |
725 | * | |
726 | * \param c Container. | |
727 | * | |
728 | * \return \c false if there is a control socket for the | |
729 | * container monitor and the caller may not access it, otherwise | |
730 | * returns \c true. | |
b494d2dd SH |
731 | */ |
732 | bool (*may_control)(struct lxc_container *c); | |
a9a0ed90 | 733 | |
953e611c JH |
734 | /*! |
735 | * \brief Add specified device to the container. | |
a9a0ed90 | 736 | * |
953e611c JH |
737 | * \param c Container. |
738 | * \param src_path Full path of the device. | |
739 | * \param dest_path Alternate path in the container (or \p NULL | |
740 | * to use \p src_path). | |
741 | * | |
742 | * \return \c true on success, else \c false. | |
a9a0ed90 | 743 | */ |
f0ca2726 | 744 | bool (*add_device_node)(struct lxc_container *c, const char *src_path, const char *dest_path); |
953e611c JH |
745 | |
746 | /*! | |
747 | * \brief Remove specified device from the container. | |
a9a0ed90 | 748 | * |
953e611c JH |
749 | * \param c Container. |
750 | * \param src_path Full path of the device. | |
751 | * \param dest_path Alternate path in the container (or \p NULL | |
752 | * to use \p src_path). | |
753 | * | |
754 | * \return \c true on success, else \c false. | |
a9a0ed90 | 755 | */ |
f0ca2726 | 756 | bool (*remove_device_node)(struct lxc_container *c, const char *src_path, const char *dest_path); |
735f2c6e | 757 | |
d24095e4 SG |
758 | /* Post LXC-1.0 additions */ |
759 | ||
51d0854c DY |
760 | /*! |
761 | * \brief Add specified netdev to the container. | |
762 | * | |
763 | * \param c Container. | |
764 | * \param dev name of net device. | |
765 | * | |
766 | * \return \c true on success, else \c false. | |
767 | */ | |
768 | bool (*attach_interface)(struct lxc_container *c, const char *dev, const char *dst_dev); | |
769 | ||
770 | /*! | |
771 | * \brief Remove specified netdev from the container. | |
772 | * | |
773 | * \param c Container. | |
774 | * \param dev name of net device. | |
775 | * | |
776 | * \return \c true on success, else \c false. | |
777 | */ | |
778 | bool (*detach_interface)(struct lxc_container *c, const char *dev, const char *dst_dev); | |
735f2c6e TA |
779 | /*! |
780 | * \brief Checkpoint a container. | |
781 | * | |
782 | * \param c Container. | |
783 | * \param directory The directory to dump the container to. | |
784 | * \param stop Whether or not to stop the container after checkpointing. | |
785 | * \param verbose Enable criu's verbose logs. | |
786 | * | |
787 | * \return \c true on success, else \c false. | |
788 | * present at compile time). | |
789 | */ | |
790 | bool (*checkpoint)(struct lxc_container *c, char *directory, bool stop, bool verbose); | |
791 | ||
792 | /*! | |
793 | * \brief Restore a container from a checkpoint. | |
794 | * | |
795 | * \param c Container. | |
796 | * \param directory The directory to restore the container from. | |
797 | * \param verbose Enable criu's verbose logs. | |
798 | * | |
799 | * \return \c true on success, else \c false. | |
800 | * | |
801 | */ | |
802 | bool (*restore)(struct lxc_container *c, char *directory, bool verbose); | |
d24095e4 SG |
803 | |
804 | /*! | |
805 | * \brief Delete the container and all its snapshots. | |
806 | * | |
807 | * \param c Container. | |
808 | * | |
809 | * \return \c true on success, else \c false. | |
810 | * | |
811 | * \note Container must be stopped. | |
812 | */ | |
813 | bool (*destroy_with_snapshots)(struct lxc_container *c); | |
814 | ||
815 | /*! | |
816 | * \brief Destroy all the container's snapshot. | |
817 | * | |
818 | * \param c Container. | |
819 | * | |
820 | * \return \c true on success, else \c false. | |
821 | */ | |
822 | bool (*snapshot_destroy_all)(struct lxc_container *c); | |
823 | ||
824 | /* Post LXC-1.1 additions */ | |
aef3d51e TA |
825 | /*! |
826 | * \brief An API call to perform various migration operations | |
827 | * | |
c0125e79 | 828 | * \param cmd One of the MIGRATE_ constants. |
aef3d51e TA |
829 | * \param opts A migrate_opts struct filled with relevant options. |
830 | * \param size The size of the migrate_opts struct, i.e. sizeof(struct migrate_opts). | |
831 | * | |
832 | * \return \c 0 on success, nonzero on failure. | |
833 | */ | |
834 | int (*migrate)(struct lxc_container *c, unsigned int cmd, struct migrate_opts *opts, unsigned int size); | |
dcf33b94 | 835 | |
191d43cc CB |
836 | /*! |
837 | * \brief Query the console log of a container. | |
838 | * | |
839 | * \param c Container. | |
840 | * \param opts A lxc_console_log struct filled with relevant options. | |
841 | * | |
842 | * \return \c 0 on success, nonzero on failure. | |
843 | */ | |
844 | int (*console_log)(struct lxc_container *c, struct lxc_console_log *log); | |
d39b10eb CB |
845 | |
846 | /*! | |
847 | * \brief Request the container reboot by sending it \c SIGINT. | |
848 | * | |
849 | * \param c Container. | |
850 | * \param timeout Seconds to wait before returning false. | |
851 | * (-1 to wait forever, 0 to avoid waiting). | |
852 | * | |
853 | * \return \c true if the container was rebooted successfully, else \c false. | |
854 | */ | |
855 | bool (*reboot2)(struct lxc_container *c, int timeout); | |
29df56cd LT |
856 | |
857 | /*! | |
858 | * \brief Mount the host's path `source` onto the container's path `target`. | |
859 | */ | |
095b5c7d CB |
860 | int (*mount)(struct lxc_container *c, const char *source, |
861 | const char *target, const char *filesystemtype, | |
862 | unsigned long mountflags, const void *data, | |
863 | struct lxc_mount *mnt); | |
d83da817 LT |
864 | |
865 | /*! | |
866 | * \brief Unmount the container's path `target`. | |
867 | */ | |
868 | int (*umount)(struct lxc_container *c, const char *target, | |
095b5c7d | 869 | unsigned long mountflags, struct lxc_mount *mnt); |
f5dd1d53 SH |
870 | }; |
871 | ||
953e611c JH |
872 | /*! |
873 | * \brief An LXC container snapshot. | |
874 | */ | |
f5dd1d53 | 875 | struct lxc_snapshot { |
953e611c JH |
876 | char *name; /*!< Name of snapshot */ |
877 | char *comment_pathname; /*!< Full path to snapshots comment file (may be \c NULL) */ | |
878 | char *timestamp; /*!< Time snapshot was created */ | |
879 | char *lxcpath; /*!< Full path to LXCPATH for snapshot */ | |
880 | ||
881 | /*! | |
882 | * \brief De-allocate the snapshot. | |
883 | * \param s snapshot. | |
884 | */ | |
885 | void (*free)(struct lxc_snapshot *s); | |
72d0e1cb SG |
886 | }; |
887 | ||
f49ad558 ÇO |
888 | |
889 | /*! | |
890 | * \brief Specifications for how to create a new backing store | |
891 | */ | |
892 | struct bdev_specs { | |
d028235d SG |
893 | char *fstype; /*!< Filesystem type */ |
894 | uint64_t fssize; /*!< Filesystem size in bytes */ | |
895 | struct { | |
896 | char *zfsroot; /*!< ZFS root path */ | |
897 | } zfs; | |
898 | struct { | |
899 | char *vg; /*!< LVM Volume Group name */ | |
900 | char *lv; /*!< LVM Logical Volume name */ | |
901 | char *thinpool; /*!< LVM thin pool to use, if any */ | |
902 | } lvm; | |
7ed52ec6 | 903 | char *dir; /*!< Directory path */ |
7da812df LB |
904 | struct { |
905 | char *rbdname; /*!< RBD image name */ | |
906 | char *rbdpool; /*!< Ceph pool name */ | |
907 | } rbd; | |
f49ad558 ÇO |
908 | }; |
909 | ||
aef3d51e TA |
910 | /*! |
911 | * \brief Commands for the migrate API call. | |
912 | */ | |
913 | enum { | |
914 | MIGRATE_PRE_DUMP, | |
915 | MIGRATE_DUMP, | |
916 | MIGRATE_RESTORE, | |
b5b12b9e | 917 | MIGRATE_FEATURE_CHECK, |
aef3d51e TA |
918 | }; |
919 | ||
b5b12b9e AR |
920 | /*! |
921 | * \brief Available feature checks. | |
922 | */ | |
923 | #define FEATURE_MEM_TRACK (1ULL << 0) | |
924 | #define FEATURE_LAZY_PAGES (1ULL << 1) | |
925 | ||
aef3d51e TA |
926 | /*! |
927 | * \brief Options for the migrate API call. | |
928 | */ | |
929 | struct migrate_opts { | |
930 | /* new members should be added at the end */ | |
931 | char *directory; | |
932 | bool verbose; | |
933 | ||
934 | bool stop; /* stop the container after dump? */ | |
935 | char *predump_dir; /* relative to directory above */ | |
74eb576c NE |
936 | char *pageserver_address; /* where should memory pages be send? */ |
937 | char *pageserver_port; | |
19d1509c TA |
938 | |
939 | /* This flag indicates whether or not the container's rootfs will have | |
940 | * the same inodes on checkpoint and restore. In the case of e.g. zfs | |
941 | * send or btrfs send, or an LVM snapshot, this will be true, but it | |
942 | * won't if e.g. you rsync the filesystems between two machines. | |
943 | */ | |
944 | bool preserves_inodes; | |
b9ee6643 TA |
945 | |
946 | /* Path to an executable script that will be registered as a criu | |
947 | * "action script" | |
948 | */ | |
949 | char *action_script; | |
f1954503 AR |
950 | |
951 | /* If CRIU >= 2.4 is detected the option to skip in-flight connections | |
952 | * will be enabled by default. The flag 'disable_skip_in_flight' will | |
953 | * unconditionally disable this feature. In-flight connections are | |
954 | * not fully established TCP connections: SYN, SYN-ACK */ | |
955 | bool disable_skip_in_flight; | |
b2b7b0d2 TA |
956 | |
957 | /* This is the maximum file size for deleted files (which CRIU calls | |
958 | * "ghost" files) that will be handled. 0 indicates the CRIU default, | |
959 | * which at this time is 1MB. | |
960 | */ | |
961 | uint64_t ghost_limit; | |
b5b12b9e AR |
962 | |
963 | /* Some features cannot be checked by comparing the CRIU version. | |
964 | * Features like dirty page tracking or userfaultfd depend on | |
965 | * the architecture/kernel/criu combination. This is a bitmask | |
966 | * in which the desired feature checks can be encoded. | |
967 | */ | |
968 | uint64_t features_to_check; | |
aef3d51e TA |
969 | }; |
970 | ||
191d43cc CB |
971 | struct lxc_console_log { |
972 | /* Clear the console log. */ | |
973 | bool clear; | |
974 | ||
975 | /* Retrieve the console log. */ | |
976 | bool read; | |
977 | ||
978 | /* This specifies the maximum size to read from the ringbuffer. Setting | |
979 | * it to 0 means that the a read can be as big as the whole ringbuffer. | |
980 | * On return callers can check how many bytes were actually read. | |
981 | * If "read" and "clear" are set to false and a non-zero value is | |
982 | * specified then up to "read_max" bytes of data will be discarded from | |
983 | * the ringbuffer. | |
984 | */ | |
985 | uint64_t *read_max; | |
986 | ||
987 | /* Data that was read from the ringbuffer. If "read_max" is 0 on return | |
988 | * "data" is invalid. | |
989 | */ | |
990 | char *data; | |
991 | }; | |
992 | ||
953e611c JH |
993 | /*! |
994 | * \brief Create a new container. | |
995 | * | |
996 | * \param name Name to use for container. | |
997 | * \param configpath Full path to configuration file to use. | |
998 | * | |
999 | * \return Newly-allocated container, or \c NULL on error. | |
1000 | */ | |
afeecbba | 1001 | struct lxc_container *lxc_container_new(const char *name, const char *configpath); |
953e611c JH |
1002 | |
1003 | /*! | |
1004 | * \brief Add a reference to the specified container. | |
1005 | * | |
1006 | * \param c Container. | |
1007 | * | |
1008 | * \return \c true on success, \c false on error. | |
1009 | */ | |
72d0e1cb | 1010 | int lxc_container_get(struct lxc_container *c); |
953e611c JH |
1011 | |
1012 | /*! | |
1013 | * \brief Drop a reference to the specified container. | |
1014 | * | |
1015 | * \param c Container. | |
1016 | * | |
1017 | * \return \c 0 on success, \c 1 if reference was successfully dropped | |
1018 | * and container has been freed, and \c -1 on error. | |
1019 | * | |
1020 | * \warning If \c 1 is returned, \p c is no longer valid. | |
1021 | */ | |
72d0e1cb | 1022 | int lxc_container_put(struct lxc_container *c); |
953e611c JH |
1023 | |
1024 | /*! | |
1025 | * \brief Obtain a list of all container states. | |
1026 | * \param[out] states Caller-allocated array to hold all states (may be \c NULL). | |
1027 | * | |
1028 | * \return Number of container states. | |
1029 | * | |
1030 | * \note Passing \c NULL for \p states allows the caller to first | |
1031 | * calculate how many states there are before calling the function again, the second time | |
1032 | * providing a suitably-sized array to store the static string pointers | |
1033 | * in. | |
1034 | * \note The \p states array should be freed by the caller, but not the strings the elements point to. | |
1035 | */ | |
4a7c7daa | 1036 | int lxc_get_wait_states(const char **states); |
953e611c | 1037 | |
dbfa7128 | 1038 | /*! |
593e8478 | 1039 | * \brief Get the value for a global config key |
953e611c | 1040 | * |
593e8478 | 1041 | * \param key The name of the config key |
953e611c | 1042 | * |
593e8478 | 1043 | * \return String representing the current value for the key. |
953e611c | 1044 | */ |
593e8478 | 1045 | const char *lxc_get_global_config_item(const char *key); |
953e611c JH |
1046 | |
1047 | /*! | |
1048 | * \brief Determine version of LXC. | |
1049 | * \return Static string representing version of LXC in use. | |
1050 | * | |
1051 | * \note Returned string must not be freed. | |
1052 | */ | |
b6b918a1 | 1053 | const char *lxc_get_version(void); |
72d0e1cb | 1054 | |
953e611c JH |
1055 | /*! |
1056 | * \brief Get a list of defined containers in a lxcpath. | |
a41f104b | 1057 | * |
953e611c JH |
1058 | * \param lxcpath lxcpath under which to look. |
1059 | * \param names If not \c NULL, then a list of container names will be returned here. | |
1060 | * \param cret If not \c NULL, then a list of lxc_containers will be returned here. | |
1061 | * | |
1062 | * \return Number of containers found, or \c -1 on error. | |
1063 | * | |
1064 | * \note Values returned in \p cret are sorted by container name. | |
a41f104b SH |
1065 | */ |
1066 | int list_defined_containers(const char *lxcpath, char ***names, struct lxc_container ***cret); | |
1067 | ||
953e611c JH |
1068 | /*! |
1069 | * \brief Get a list of active containers for a given lxcpath. | |
1070 | * | |
1071 | * \param lxcpath Full \c LXCPATH path to consider. | |
1072 | * \param[out] names Dynamically-allocated array of container names. | |
1073 | * \param[out] cret Dynamically-allocated list of containers. | |
1074 | * | |
1075 | * \return Number of containers found, or -1 on error. | |
a41f104b | 1076 | * |
953e611c JH |
1077 | * \note Some of the containers may not be "defined". |
1078 | * \note Values returned in \p cret are sorted by container name. | |
1079 | * \note \p names and \p cret may both (or either) be specified as \c NULL. | |
1080 | * \note \p names and \p cret must be freed by the caller. | |
a41f104b SH |
1081 | */ |
1082 | int list_active_containers(const char *lxcpath, char ***names, struct lxc_container ***cret); | |
1083 | ||
953e611c JH |
1084 | /*! |
1085 | * \brief Get a complete list of all containers for a given lxcpath. | |
2871830a | 1086 | * |
953e611c JH |
1087 | * \param lxcpath Full \c LXCPATH path to consider. |
1088 | * \param[out] names Dynamically-allocated array of container name. | |
1089 | * \param[out] cret Dynamically-allocated list of containers. | |
1090 | * | |
1091 | * \return Number of containers, or -1 on error. | |
1092 | * | |
1093 | * \note Some of the containers may not be "defined". | |
1094 | * \note Values returned in \p cret are sorted by container name. | |
1095 | * \note \p names and \p cret may both (or either) be specified as \c NULL. | |
1096 | * \note \p names and \p cret must be freed by the caller. | |
2871830a DE |
1097 | */ |
1098 | int list_all_containers(const char *lxcpath, char ***names, struct lxc_container ***cret); | |
1099 | ||
73b910a3 | 1100 | struct lxc_log { |
1101 | const char *name; | |
1102 | const char *lxcpath; | |
1103 | const char *file; | |
4b73005c | 1104 | const char *level; |
73b910a3 | 1105 | const char *prefix; |
1106 | bool quiet; | |
1107 | }; | |
1108 | ||
1109 | /*! | |
1110 | *\brief Initialize the log | |
1111 | * | |
1112 | *\param log lxc log configuration. | |
1113 | */ | |
1114 | int lxc_log_init(struct lxc_log *log); | |
1115 | ||
36eaa694 DE |
1116 | /*! |
1117 | * \brief Close log file. | |
1118 | */ | |
1119 | void lxc_log_close(void); | |
1120 | ||
12461428 CB |
1121 | /*! |
1122 | * \brief Check if the configuration item is supported by this LXC instance. | |
1123 | * | |
1124 | * \param key Configuration item to check for. | |
1125 | */ | |
1126 | bool lxc_config_item_is_supported(const char *key); | |
1127 | ||
aafa5f96 CB |
1128 | /*! |
1129 | * \brief Check if an API extension is supported by this LXC instance. | |
1130 | * | |
1131 | * \param extension API extension to check for. | |
1132 | */ | |
1133 | bool lxc_has_api_extension(const char *extension); | |
1134 | ||
579e783e AM |
1135 | #ifdef __cplusplus |
1136 | } | |
1137 | #endif | |
1138 | ||
9be53773 | 1139 | #endif |