5 * Copyright © 2012 Serge Hallyn <serge.hallyn@ubuntu.com>.
6 * Copyright © 2012 Canonical Ltd.
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.
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.
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
23 #ifndef __LXC_CONTAINER_H
24 #define __LXC_CONTAINER_H
26 #include <semaphore.h>
31 #include <lxc/attach_options.h>
37 #define LXC_CLONE_KEEPNAME (1 << 0) /*!< Do not edit the rootfs to change the hostname */
38 #define LXC_CLONE_KEEPMACADDR (1 << 1) /*!< Do not change the MAC address on network interfaces */
39 #define LXC_CLONE_SNAPSHOT (1 << 2) /*!< Snapshot the original filesystem(s) */
40 #define LXC_CLONE_KEEPBDEVTYPE (1 << 3) /*!< Use the same bdev type */
41 #define LXC_CLONE_MAYBE_SNAPSHOT (1 << 4) /*!< Snapshot only if bdev supports it, else copy */
42 #define LXC_CLONE_MAXFLAGS (1 << 5) /*!< Number of \c LXC_CLONE_* flags */
43 #define LXC_CREATE_QUIET (1 << 0) /*!< Redirect \c stdin to \c /dev/zero and \c stdout and \c stderr to \c /dev/null */
44 #define LXC_CREATE_MAXFLAGS (1 << 1) /*!< Number of \c LXC_CREATE* flags */
57 * Note that changing the order of struct members is an API change, as callers
58 * will end up having the wrong offset when calling a function. So when making
59 * changes, whenever possible stick to simply appending new members.
61 struct lxc_container
{
71 * Full path to configuration file.
83 * Container semaphore lock.
85 struct lxc_lock
*slock
;
89 * Container private lock.
91 struct lxc_lock
*privlock
;
95 * Number of references to this container.
96 * \note protected by privlock.
102 * Container configuration.
104 * \internal FIXME: do we want the whole lxc_handler?
106 struct lxc_conf
*lxc_conf
;
109 /*! Human-readable string representing last error */
112 /*! Last error number */
115 /*! Whether container wishes to be daemonized */
118 /*! Full path to configuration file */
122 * \brief Determine if \c /var/lib/lxc/$name/config exists.
124 * \param c Container.
126 * \return \c true if container is defined, else \c false.
128 bool (*is_defined
)(struct lxc_container
*c
);
131 * \brief Determine state of container.
133 * \param c Container.
135 * \return Static upper-case string representing state of container.
137 * \note Returned string must not be freed.
139 const char *(*state
)(struct lxc_container
*c
);
142 * \brief Determine if container is running.
144 * \param c Container.
146 * \return \c true on success, else \c false.
148 bool (*is_running
)(struct lxc_container
*c
);
151 * \brief Freeze running container.
153 * \param c Container.
155 * \return \c true on success, else \c false.
157 bool (*freeze
)(struct lxc_container
*c
);
160 * \brief Thaw a frozen container.
162 * \param c Container.
164 * \return \c true on success, else \c false.
166 bool (*unfreeze
)(struct lxc_container
*c
);
169 * \brief Determine process ID of the containers init process.
171 * \param c Container.
173 * \return pid of init process as seen from outside the
176 pid_t (*init_pid
)(struct lxc_container
*c
);
179 * \brief Load the specified configuration for the container.
181 * \param c Container.
182 * \param alt_file Full path to alternate configuration file, or
183 * \c NULL to use the default configuration file.
185 * \return \c true on success, else \c false.
187 bool (*load_config
)(struct lxc_container
*c
, const char *alt_file
);
190 * \brief Start the container.
192 * \param c Container.
193 * \param useinit Use lxcinit rather than \c /sbin/init.
194 * \param argv Array of arguments to pass to init.
196 * \return \c true on success, else \c false.
198 bool (*start
)(struct lxc_container
*c
, int useinit
, char * const argv
[]);
201 * \brief Start the container (list variant).
203 * \param c Container.
204 * \param useinit Use lxcinit rather than \c /sbin/init.
205 * \param ... Command-line to pass to init (must end in \c NULL).
207 * \return \c true on success, else \c false.
209 * \note Identical to \ref start except that that the init
210 * arguments are specified via a list rather than an array of
213 bool (*startl
)(struct lxc_container
*c
, int useinit
, ...);
216 * \brief Stop the container.
218 * \param c Container.
220 * \return \c true on success, else \c false.
222 bool (*stop
)(struct lxc_container
*c
);
225 * \brief Change whether the container wants to run disconnected
228 * \param c Container.
229 * \param state Value for the daemonize bit (0 or 1).
231 * \return \c true on success, else \c false.
233 bool (*want_daemonize
)(struct lxc_container
*c
, bool state
);
236 * \brief Change whether the container wishes all file descriptors
237 * to be closed on startup.
239 * \param c Container.
240 * \param state Value for the close_all_fds bit (0 or 1).
242 * \return \c true on success, else \c false.
244 bool (*want_close_all_fds
)(struct lxc_container
*c
, bool state
);
247 * \brief Return current config file name.
249 * \param c Container.
251 * \return config file name, or \c NULL on error.
253 * \note The result is allocated, so the caller must free the result.
255 char *(*config_file_name
)(struct lxc_container
*c
);
258 * \brief Wait for container to reach a particular state.
260 * \param c Container.
261 * \param state State to wait for.
262 * \param timeout Timeout in seconds.
264 * \return \c true if state reached within \p timeout, else \c false.
266 * \note A \p timeout of \c -1 means wait forever. A \p timeout
267 * of \c 0 means do not wait.
269 bool (*wait
)(struct lxc_container
*c
, const char *state
, int timeout
);
272 * \brief Set a key/value configuration option.
274 * \param c Container.
275 * \param key Name of option to set.
276 * \param value Value of \p name to set.
278 * \return \c true on success, else \c false.
280 bool (*set_config_item
)(struct lxc_container
*c
, const char *key
, const char *value
);
283 * \brief Delete the container.
285 * \param c Container.
287 * \return \c true on success, else \c false.
289 * \note Container must be stopped and have no dependent snapshots.
291 bool (*destroy
)(struct lxc_container
*c
);
294 * \brief Save configuaration to a file.
296 * \param c Container.
297 * \param alt_file Full path to file to save configuration in.
299 * \return \c true on success, else \c false.
301 bool (*save_config
)(struct lxc_container
*c
, const char *alt_file
);
304 * \brief Create a container.
306 * \param c Container (with lxcpath, name and a starting
307 * configuration set).
308 * \param t Template to execute to instantiate the root
309 * filesystem and adjust the configuration.
310 * \param bdevtype Backing store type to use (if \c NULL, \c dir will be used).
311 * \param specs Additional parameters for the backing store (for
312 * example LVM volume group to use).
313 * \param flags \c LXC_CREATE_* options (currently only \ref
314 * LXC_CREATE_QUIET is supported).
315 * \param argv Arguments to pass to the template, terminated by \c NULL (if no
316 * arguments are required, just pass \c NULL).
318 * \return \c true on success, else \c false.
320 bool (*create
)(struct lxc_container
*c
, const char *t
, const char *bdevtype
,
321 struct bdev_specs
*specs
, int flags
, char *const argv
[]);
324 * \brief Create a container (list variant).
326 * \param c Container (with lxcpath, name and a starting
327 * configuration set).
328 * \param t Template to execute to instantiate the root
329 * filesystem and adjust the configuration.
330 * \param bdevtype Backing store type to use (if \c NULL, \c dir will be used).
331 * \param specs Additional parameters for the backing store (for
332 * example LVM volume group to use).
333 * \param flags \c LXC_CREATE_* options (currently only \ref
334 * LXC_CREATE_QUIET is supported).
335 * \param ... Command-line to pass to init (must end in \c NULL).
337 * \return \c true on success, else \c false.
339 * \note Identical to \ref create except that the template
340 * arguments are specified as a list rather than an array of
343 bool (*createl
)(struct lxc_container
*c
, const char *t
, const char *bdevtype
,
344 struct bdev_specs
*specs
, int flags
, ...);
347 * \brief Rename a container
349 * \param c Container.
350 * \param newname New name to be used for the container.
352 * \return \c true on success, else \c false.
354 bool (*rename
)(struct lxc_container
*c
, const char *newname
);
357 * \brief Request the container reboot by sending it \c SIGINT.
359 * \param c Container.
361 * \return \c true if reboot request successful, else \c false.
363 bool (*reboot
)(struct lxc_container
*c
);
366 * \brief Request the container shutdown by sending it \c
369 * \param c Container.
370 * \param timeout Seconds to wait before returning false.
371 * (-1 to wait forever, 0 to avoid waiting).
373 * \return \c true if the container was shutdown successfully, else \c false.
375 bool (*shutdown
)(struct lxc_container
*c
, int timeout
);
378 * \brief Completely clear the containers in-memory configuration.
380 * \param c Container.
382 void (*clear_config
)(struct lxc_container
*c
);
385 * \brief Clear a configuration item.
387 * \param c Container.
388 * \param key Name of option to clear.
390 * \return \c true on success, else \c false.
392 * \note Analog of \ref set_config_item.
394 bool (*clear_config_item
)(struct lxc_container
*c
, const char *key
);
397 * \brief Retrieve the value of a config item.
399 * \param c Container.
400 * \param key Name of option to get.
401 * \param[out] retv Caller-allocated buffer to write value of \p key
402 * into (or \c NULL to determine length of value).
403 * \param inlen Length of \p retv (may be zero).
405 * \return Length of config items value, or < 0 on error.
407 * \note The caller can (and should) determine how large a buffer to allocate for
408 * \p retv by initially passing its value as \c NULL and considering the return value.
409 * This function can then be called again passing a newly-allocated suitably-sized buffer.
410 * \note If \p retv is NULL, \p inlen is ignored.
411 * \note If \p inlen is smaller than required, nothing will be written to \p retv and still return
412 * the length of config item value.
414 int (*get_config_item
)(struct lxc_container
*c
, const char *key
, char *retv
, int inlen
);
418 * \brief Retrieve the value of a config item from running container.
420 * \param c Container.
421 * \param key Name of option to get.
423 * \return the item or NULL on error.
425 * \note Returned string must be freed by the caller.
427 char* (*get_running_config_item
)(struct lxc_container
*c
, const char *key
);
430 * \brief Retrieve a list of config item keys given a key
433 * \param c Container.
434 * \param key Name of option to get.
435 * \param[out] retv Caller-allocated buffer to write list of keys to
436 * (or \c NULL to determine overall length of keys list).
437 * \param inlen Length of \p retv (may be zero).
439 * \return Length of keys list, or < 0 on error.
441 * \note The list values written to \p retv are separated by
442 * a newline character ('\\n').
443 * \note The caller can (and should) determine how large a buffer to allocate for
444 * \p retv by initially passing its value as \c NULL and considering the return value.
445 * This function can then be called again passing a newly-allocated suitably-sized buffer.
446 * \note If \p retv is NULL, \p inlen is ignored.
447 * \note If \p inlen is smaller than required, the value written
448 * to \p retv will be truncated.
450 int (*get_keys
)(struct lxc_container
*c
, const char *key
, char *retv
, int inlen
);
453 * \brief Obtain a list of network interfaces.
454 * \param c Container.
456 * \return Newly-allocated array of network interfaces, or \c
459 * \note The returned array is allocated, so the caller must free it.
460 * \note The returned array is terminated with a \c NULL entry.
462 char** (*get_interfaces
)(struct lxc_container
*c
);
465 * \brief Determine the list of container IP addresses.
467 * \param c Container.
468 * \param interface Network interface name to consider.
469 * \param family Network family (for example "inet", "inet6").
470 * \param scope IPv6 scope id (ignored if \p family is not "inet6").
472 * \return Newly-allocated array of network interfaces, or \c
475 * \note The returned array is allocated, so the caller must free it.
476 * \note The returned array is terminated with a \c NULL entry.
478 char** (*get_ips
)(struct lxc_container
*c
, const char* interface
, const char* family
, int scope
);
481 * \brief Retrieve the specified cgroup subsystem value for the container.
483 * \param c Container.
484 * \param subsys cgroup subsystem to retrieve.
485 * \param[out] retv Caller-allocated buffer to write value of \p
486 * subsys into (or \c NULL to determine length of value).
487 * \param inlen length of \p retv (may be zero).
489 * \return Length of \p subsys value, or < 0 on error.
491 * \note If \p retv is \c NULL, \p inlen is ignored.
492 * \note If \p inlen is smaller than required, the value written
493 * to \p retv will be truncated.
495 int (*get_cgroup_item
)(struct lxc_container
*c
, const char *subsys
, char *retv
, int inlen
);
498 * \brief Set the specified cgroup subsystem value for the container.
500 * \param c Container.
501 * \param subsys cgroup subsystem to consider.
502 * \param value Value to set for \p subsys.
504 * \return \c true on success, else \c false.
506 bool (*set_cgroup_item
)(struct lxc_container
*c
, const char *subsys
, const char *value
);
509 * \brief Determine full path to the containers configuration file.
510 * Each container can have a custom configuration path. However
511 * by default it will be set to either the \c LXCPATH configure
512 * variable, or the lxcpath value in the \c LXC_GLOBAL_CONF configuration
513 * file (i.e. \c /etc/lxc/lxc.conf).
514 * The value for a specific container can be changed using
515 * \ref set_config_path. There is no other way to specify this in general at the moment.
517 * \param c Container.
519 * \return Static string representing full path to configuration
522 * \note Returned string must not be freed.
524 const char *(*get_config_path
)(struct lxc_container
*c
);
527 * \brief Set the full path to the containers configuration
530 * \param c Container.
531 * \param path Full path to configuration file.
533 * \return \c true on success, else \c false.
535 bool (*set_config_path
)(struct lxc_container
*c
, const char *path
);
538 * \brief Copy a stopped container.
540 * \param c Original container.
541 * \param newname New name for the container. If \c NULL, the same
542 * name is used and a new lxcpath MUST be specified.
543 * \param lxcpath lxcpath in which to create the new container. If
544 * \c NULL, the original container's lxcpath will be used.
545 * (XXX: should we use the default instead?)
546 * \param flags Additional \c LXC_CLONE* flags to change the cloning behaviour:
547 * - \ref LXC_CLONE_KEEPNAME
548 * - \ref LXC_CLONE_KEEPMACADDR
549 * - \ref LXC_CLONE_SNAPSHOT
550 * \param bdevtype Optionally force the cloned bdevtype to a specified plugin.
551 * By default the original is used (subject to snapshot requirements).
552 * \param bdevdata Information about how to create the new storage
553 * (i.e. fstype and fsdata).
554 * \param newsize In case of a block device backing store, an
555 * optional size. If \c 0, the original backing store's size will
556 * be used if possible. Note this only applies to the rootfs. For
557 * any other filesystems, the original size will be duplicated.
558 * \param hookargs Additional arguments to pass to the clone hook script.
560 * \return Newly-allocated copy of container \p c, or \p NULL on
563 * \note If devtype was not specified, and \p flags contains \ref
564 * LXC_CLONE_SNAPSHOT then use the native \p bdevtype if possible,
565 * else use an overlayfs.
567 struct lxc_container
*(*clone
)(struct lxc_container
*c
, const char *newname
,
568 const char *lxcpath
, int flags
, const char *bdevtype
,
569 const char *bdevdata
, uint64_t newsize
, char **hookargs
);
572 * \brief Allocate a console tty for the container.
574 * \param c Container.
575 * \param[in,out] ttynum Terminal number to attempt to allocate,
576 * or \c -1 to allocate the first available tty.
577 * \param[out] masterfd File descriptor referring to the master side of the pty.
579 * \return tty file descriptor number on success, or \c -1 on
582 * \note On successful return, \p ttynum will contain the tty number
583 * that was allocated.
584 * \note The returned file descriptor is used to keep the tty
585 * allocated. The caller should call close(2) on the returned file
586 * descriptor when no longer required so that it may be allocated
589 int (*console_getfd
)(struct lxc_container
*c
, int *ttynum
, int *masterfd
);
592 * \brief Allocate and run a console tty.
594 * \param c Container.
595 * \param ttynum Terminal number to attempt to allocate, \c -1 to
596 * allocate the first available tty or \c 0 to allocate the
598 * \param stdinfd File descriptor to read input from.
599 * \param stdoutfd File descriptor to write output to.
600 * \param stderrfd File descriptor to write error output to.
601 * \param escape The escape character (1 == 'a', 2 == 'b', ...).
603 * \return \c 0 on success, \c -1 on failure.
605 * \note This function will not return until the console has been
606 * exited by the user.
608 int (*console
)(struct lxc_container
*c
, int ttynum
,
609 int stdinfd
, int stdoutfd
, int stderrfd
, int escape
);
612 * \brief Create a sub-process attached to a container and run
613 * a function inside it.
615 * \param c Container.
616 * \param exec_function Function to run.
617 * \param exec_payload Data to pass to \p exec_function.
618 * \param options \ref lxc_attach_options_t.
619 * \param[out] attached_process Process ID of process running inside
620 * container \p c that is running \p exec_function.
622 * \return \c 0 on success, \c -1 on error.
624 int (*attach
)(struct lxc_container
*c
, lxc_attach_exec_t exec_function
,
625 void *exec_payload
, lxc_attach_options_t
*options
, pid_t
*attached_process
);
628 * \brief Run a program inside a container and wait for it to exit.
630 * \param c Container.
631 * \param options See \ref attach options.
632 * \param program Full path inside container of program to run.
633 * \param argv Array of arguments to pass to \p program.
635 * \return \c waitpid(2) status of exited process that ran \p
636 * program, or \c -1 on error.
638 int (*attach_run_wait
)(struct lxc_container
*c
, lxc_attach_options_t
*options
, const char *program
, const char * const argv
[]);
641 * \brief Run a program inside a container and wait for it to exit (list variant).
643 * \param c Container.
644 * \param options See \ref attach options.
645 * \param program Full path inside container of program to run.
646 * \param ... Command-line to pass to \p program (must end in \c NULL).
648 * \return \c waitpid(2) status of exited process that ran \p
649 * program, or \c -1 on error.
651 int (*attach_run_waitl
)(struct lxc_container
*c
, lxc_attach_options_t
*options
, const char *program
, const char *arg
, ...);
654 * \brief Create a container snapshot.
656 * Assuming default paths, snapshots will be created as
657 * \c /var/lib/lxc/\<c\>/snaps/snap\<n\>
658 * where \c \<c\> represents the container name and \c \<n\>
659 * represents the zero-based snapshot number.
661 * \param c Container.
662 * \param commentfile Full path to file containing a description
665 * \return -1 on error, or zero-based snapshot number.
667 * \note \p commentfile may be \c NULL but this is discouraged.
669 int (*snapshot
)(struct lxc_container
*c
, const char *commentfile
);
672 * \brief Obtain a list of container snapshots.
674 * \param c Container.
675 * \param[out] snapshots Dynamically-allocated Array of lxc_snapshot's.
677 * \return Number of snapshots.
679 * \note The array returned in \p snapshots is allocated, so the caller must free it.
680 * \note To free an individual snapshot as returned in \p
681 * snapshots, call the snapshots \c free function (see \c src/tests/snapshot.c for an example).
683 int (*snapshot_list
)(struct lxc_container
*c
, struct lxc_snapshot
**snapshots
);
686 * \brief Create a new container based on a snapshot.
688 * The restored container will be a copy (not snapshot) of the snapshot,
689 * and restored in the lxcpath of the original container.
690 * \param c Container.
691 * \param snapname Name of snapshot.
692 * \param newname Name to be used for the restored snapshot.
693 * \return \c true on success, else \c false.
694 * \warning If \p newname is the same as the current container
695 * name, the container will be destroyed. However, this will
696 * fail if the snapshot is overlay-based, since the snapshots
697 * will pin the original container.
698 * \note As an example, if the container exists as \c /var/lib/lxc/c1, snapname might be \c 'snap0'
699 * (representing \c /var/lib/lxc/c1/snaps/snap0). If \p newname is \p c2,
700 * then \c snap0 will be copied to \c /var/lib/lxc/c2.
702 bool (*snapshot_restore
)(struct lxc_container
*c
, const char *snapname
, const char *newname
);
705 * \brief Destroy the specified snapshot.
707 * \param c Container.
708 * \param snapname Name of snapshot.
710 * \return \c true on success, else \c false.
712 bool (*snapshot_destroy
)(struct lxc_container
*c
, const char *snapname
);
715 * \brief Determine if the caller may control the container.
717 * \param c Container.
719 * \return \c false if there is a control socket for the
720 * container monitor and the caller may not access it, otherwise
723 bool (*may_control
)(struct lxc_container
*c
);
726 * \brief Add specified device to the container.
728 * \param c Container.
729 * \param src_path Full path of the device.
730 * \param dest_path Alternate path in the container (or \p NULL
731 * to use \p src_path).
733 * \return \c true on success, else \c false.
735 bool (*add_device_node
)(struct lxc_container
*c
, const char *src_path
, const char *dest_path
);
738 * \brief Remove specified device from the container.
740 * \param c Container.
741 * \param src_path Full path of the device.
742 * \param dest_path Alternate path in the container (or \p NULL
743 * to use \p src_path).
745 * \return \c true on success, else \c false.
747 bool (*remove_device_node
)(struct lxc_container
*c
, const char *src_path
, const char *dest_path
);
749 /* Post LXC-1.0 additions */
752 * \brief Add specified netdev to the container.
754 * \param c Container.
755 * \param dev name of net device.
757 * \return \c true on success, else \c false.
759 bool (*attach_interface
)(struct lxc_container
*c
, const char *dev
, const char *dst_dev
);
762 * \brief Remove specified netdev from the container.
764 * \param c Container.
765 * \param dev name of net device.
767 * \return \c true on success, else \c false.
769 bool (*detach_interface
)(struct lxc_container
*c
, const char *dev
, const char *dst_dev
);
771 * \brief Checkpoint a container.
773 * \param c Container.
774 * \param directory The directory to dump the container to.
775 * \param stop Whether or not to stop the container after checkpointing.
776 * \param verbose Enable criu's verbose logs.
778 * \return \c true on success, else \c false.
779 * present at compile time).
781 bool (*checkpoint
)(struct lxc_container
*c
, char *directory
, bool stop
, bool verbose
);
784 * \brief Restore a container from a checkpoint.
786 * \param c Container.
787 * \param directory The directory to restore the container from.
788 * \param verbose Enable criu's verbose logs.
790 * \return \c true on success, else \c false.
793 bool (*restore
)(struct lxc_container
*c
, char *directory
, bool verbose
);
796 * \brief Delete the container and all its snapshots.
798 * \param c Container.
800 * \return \c true on success, else \c false.
802 * \note Container must be stopped.
804 bool (*destroy_with_snapshots
)(struct lxc_container
*c
);
807 * \brief Destroy all the container's snapshot.
809 * \param c Container.
811 * \return \c true on success, else \c false.
813 bool (*snapshot_destroy_all
)(struct lxc_container
*c
);
815 /* Post LXC-1.1 additions */
817 * \brief An API call to perform various migration operations
819 * \param cmd One of the MIGRATE_ contstants.
820 * \param opts A migrate_opts struct filled with relevant options.
821 * \param size The size of the migrate_opts struct, i.e. sizeof(struct migrate_opts).
823 * \return \c 0 on success, nonzero on failure.
825 int (*migrate
)(struct lxc_container
*c
, unsigned int cmd
, struct migrate_opts
*opts
, unsigned int size
);
829 * \brief An LXC container snapshot.
831 struct lxc_snapshot
{
832 char *name
; /*!< Name of snapshot */
833 char *comment_pathname
; /*!< Full path to snapshots comment file (may be \c NULL) */
834 char *timestamp
; /*!< Time snapshot was created */
835 char *lxcpath
; /*!< Full path to LXCPATH for snapshot */
838 * \brief De-allocate the snapshot.
841 void (*free
)(struct lxc_snapshot
*s
);
846 * \brief Specifications for how to create a new backing store
849 char *fstype
; /*!< Filesystem type */
850 uint64_t fssize
; /*!< Filesystem size in bytes */
852 char *zfsroot
; /*!< ZFS root path */
855 char *vg
; /*!< LVM Volume Group name */
856 char *lv
; /*!< LVM Logical Volume name */
857 char *thinpool
; /*!< LVM thin pool to use, if any */
859 char *dir
; /*!< Directory path */
861 char *rbdname
; /*!< RBD image name */
862 char *rbdpool
; /*!< Ceph pool name */
867 * \brief Commands for the migrate API call.
876 * \brief Options for the migrate API call.
878 struct migrate_opts
{
879 /* new members should be added at the end */
883 bool stop
; /* stop the container after dump? */
884 char *predump_dir
; /* relative to directory above */
885 char *pageserver_address
; /* where should memory pages be send? */
886 char *pageserver_port
;
888 /* This flag indicates whether or not the container's rootfs will have
889 * the same inodes on checkpoint and restore. In the case of e.g. zfs
890 * send or btrfs send, or an LVM snapshot, this will be true, but it
891 * won't if e.g. you rsync the filesystems between two machines.
893 bool preserves_inodes
;
895 /* Path to an executable script that will be registered as a criu
900 /* If CRIU >= 2.4 is detected the option to skip in-flight connections
901 * will be enabled by default. The flag 'disable_skip_in_flight' will
902 * unconditionally disable this feature. In-flight connections are
903 * not fully established TCP connections: SYN, SYN-ACK */
904 bool disable_skip_in_flight
;
906 /* This is the maximum file size for deleted files (which CRIU calls
907 * "ghost" files) that will be handled. 0 indicates the CRIU default,
908 * which at this time is 1MB.
910 uint64_t ghost_limit
;
914 * \brief Create a new container.
916 * \param name Name to use for container.
917 * \param configpath Full path to configuration file to use.
919 * \return Newly-allocated container, or \c NULL on error.
921 struct lxc_container
*lxc_container_new(const char *name
, const char *configpath
);
924 * \brief Add a reference to the specified container.
926 * \param c Container.
928 * \return \c true on success, \c false on error.
930 int lxc_container_get(struct lxc_container
*c
);
933 * \brief Drop a reference to the specified container.
935 * \param c Container.
937 * \return \c 0 on success, \c 1 if reference was successfully dropped
938 * and container has been freed, and \c -1 on error.
940 * \warning If \c 1 is returned, \p c is no longer valid.
942 int lxc_container_put(struct lxc_container
*c
);
945 * \brief Obtain a list of all container states.
946 * \param[out] states Caller-allocated array to hold all states (may be \c NULL).
948 * \return Number of container states.
950 * \note Passing \c NULL for \p states allows the caller to first
951 * calculate how many states there are before calling the function again, the second time
952 * providing a suitably-sized array to store the static string pointers
954 * \note The \p states array should be freed by the caller, but not the strings the elements point to.
956 int lxc_get_wait_states(const char **states
);
959 * \brief Get the value for a global config key
961 * \param key The name of the config key
963 * \return String representing the current value for the key.
965 const char *lxc_get_global_config_item(const char *key
);
968 * \brief Determine version of LXC.
969 * \return Static string representing version of LXC in use.
971 * \note Returned string must not be freed.
973 const char *lxc_get_version(void);
976 * \brief Get a list of defined containers in a lxcpath.
978 * \param lxcpath lxcpath under which to look.
979 * \param names If not \c NULL, then a list of container names will be returned here.
980 * \param cret If not \c NULL, then a list of lxc_containers will be returned here.
982 * \return Number of containers found, or \c -1 on error.
984 * \note Values returned in \p cret are sorted by container name.
986 int list_defined_containers(const char *lxcpath
, char ***names
, struct lxc_container
***cret
);
989 * \brief Get a list of active containers for a given lxcpath.
991 * \param lxcpath Full \c LXCPATH path to consider.
992 * \param[out] names Dynamically-allocated array of container names.
993 * \param[out] cret Dynamically-allocated list of containers.
995 * \return Number of containers found, or -1 on error.
997 * \note Some of the containers may not be "defined".
998 * \note Values returned in \p cret are sorted by container name.
999 * \note \p names and \p cret may both (or either) be specified as \c NULL.
1000 * \note \p names and \p cret must be freed by the caller.
1002 int list_active_containers(const char *lxcpath
, char ***names
, struct lxc_container
***cret
);
1005 * \brief Get a complete list of all containers for a given lxcpath.
1007 * \param lxcpath Full \c LXCPATH path to consider.
1008 * \param[out] names Dynamically-allocated array of container name.
1009 * \param[out] cret Dynamically-allocated list of containers.
1011 * \return Number of containers, or -1 on error.
1013 * \note Some of the containers may not be "defined".
1014 * \note Values returned in \p cret are sorted by container name.
1015 * \note \p names and \p cret may both (or either) be specified as \c NULL.
1016 * \note \p names and \p cret must be freed by the caller.
1018 int list_all_containers(const char *lxcpath
, char ***names
, struct lxc_container
***cret
);
1022 const char *lxcpath
;
1030 *\brief Initialize the log
1032 *\param log lxc log configuration.
1034 int lxc_log_init(struct lxc_log
*log
);
1037 * \brief Close log file.
1039 void lxc_log_close(void);
1042 * \brief Check if the configuration item is supported by this LXC instance.
1044 * \param key Configuration item to check for.
1046 bool lxc_config_item_is_supported(const char *key
);