1 /* SPDX-License-Identifier: LGPL-2.1+ */
3 #ifndef __LXC_CONTAINER_H
4 #define __LXC_CONTAINER_H
12 #include <lxc/attach_options.h>
18 #define LXC_CLONE_KEEPNAME (1 << 0) /*!< Do not edit the rootfs to change the hostname */
19 #define LXC_CLONE_KEEPMACADDR (1 << 1) /*!< Do not change the MAC address on network interfaces */
20 #define LXC_CLONE_SNAPSHOT (1 << 2) /*!< Snapshot the original filesystem(s) */
21 #define LXC_CLONE_KEEPBDEVTYPE (1 << 3) /*!< Use the same bdev type */
22 #define LXC_CLONE_MAYBE_SNAPSHOT (1 << 4) /*!< Snapshot only if bdev supports it, else copy */
23 #define LXC_CLONE_MAXFLAGS (1 << 5) /*!< Number of \c LXC_CLONE_* flags */
24 #define LXC_CLONE_ALLOW_RUNNING (1 << 6) /*!< allow snapshot creation even if source container is running */
25 #define LXC_CREATE_QUIET (1 << 0) /*!< Redirect \c stdin to \c /dev/zero and \c stdout and \c stderr to \c /dev/null */
26 #define LXC_CREATE_MAXFLAGS (1 << 1) /*!< Number of \c LXC_CREATE* flags */
27 #define LXC_MOUNT_API_V1 1
37 struct lxc_console_log
;
46 * Note that changing the order of struct members is an API change, as callers
47 * will end up having the wrong offset when calling a function. So when making
48 * changes, whenever possible stick to simply appending new members.
50 struct lxc_container
{
60 * Full path to configuration file.
72 * Container semaphore lock.
74 struct lxc_lock
*slock
;
78 * Container private lock.
80 struct lxc_lock
*privlock
;
84 * Number of references to this container.
85 * \note protected by privlock.
91 * Container configuration.
93 * \internal TODO: do we want the whole lxc_handler?
95 struct lxc_conf
*lxc_conf
;
98 /*! Human-readable string representing last error */
101 /*! Last error number */
104 /*! Whether container wishes to be daemonized */
107 /*! Full path to configuration file */
111 * \brief Determine if \c /var/lib/lxc/$name/config exists.
113 * \param c Container.
115 * \return \c true if container is defined, else \c false.
117 bool (*is_defined
)(struct lxc_container
*c
);
120 * \brief Determine state of container.
122 * \param c Container.
124 * \return Static upper-case string representing state of container.
126 * \note Returned string must not be freed.
128 const char *(*state
)(struct lxc_container
*c
);
131 * \brief Determine if container is running.
133 * \param c Container.
135 * \return \c true on success, else \c false.
137 bool (*is_running
)(struct lxc_container
*c
);
140 * \brief Freeze running container.
142 * \param c Container.
144 * \return \c true on success, else \c false.
146 bool (*freeze
)(struct lxc_container
*c
);
149 * \brief Thaw a frozen container.
151 * \param c Container.
153 * \return \c true on success, else \c false.
155 bool (*unfreeze
)(struct lxc_container
*c
);
158 * \brief Determine process ID of the containers init process.
160 * \param c Container.
162 * \return pid of init process as seen from outside the
165 pid_t (*init_pid
)(struct lxc_container
*c
);
168 * \brief Load the specified configuration for the container.
170 * \param c Container.
171 * \param alt_file Full path to alternate configuration file, or
172 * \c NULL to use the default configuration file.
174 * \return \c true on success, else \c false.
176 bool (*load_config
)(struct lxc_container
*c
, const char *alt_file
);
179 * \brief Start the container.
181 * \param c Container.
182 * \param useinit Use lxcinit rather than \c /sbin/init.
183 * \param argv Array of arguments to pass to init.
185 * \return \c true on success, else \c false.
187 bool (*start
)(struct lxc_container
*c
, int useinit
, char * const argv
[]);
190 * \brief Start the container (list variant).
192 * \param c Container.
193 * \param useinit Use lxcinit rather than \c /sbin/init.
194 * \param ... Command-line to pass to init (must end in \c NULL).
196 * \return \c true on success, else \c false.
198 * \note Identical to \ref start except that that the init
199 * arguments are specified via a list rather than an array of
202 bool (*startl
)(struct lxc_container
*c
, int useinit
, ...);
205 * \brief Stop the container.
207 * \param c Container.
209 * \return \c true on success, else \c false.
211 bool (*stop
)(struct lxc_container
*c
);
214 * \brief Change whether the container wants to run disconnected
217 * \param c Container.
218 * \param state Value for the daemonize bit (0 or 1).
220 * \return \c true on success, else \c false.
222 bool (*want_daemonize
)(struct lxc_container
*c
, bool state
);
225 * \brief Change whether the container wishes all file descriptors
226 * to be closed on startup.
228 * \param c Container.
229 * \param state Value for the close_all_fds bit (0 or 1).
231 * \return \c true on success, else \c false.
233 bool (*want_close_all_fds
)(struct lxc_container
*c
, bool state
);
236 * \brief Return current config file name.
238 * \param c Container.
240 * \return config file name, or \c NULL on error.
242 * \note The result is allocated, so the caller must free the result.
244 char *(*config_file_name
)(struct lxc_container
*c
);
247 * \brief Wait for container to reach a particular state.
249 * \param c Container.
250 * \param state State to wait for.
251 * \param timeout Timeout in seconds.
253 * \return \c true if state reached within \p timeout, else \c false.
255 * \note A \p timeout of \c -1 means wait forever. A \p timeout
256 * of \c 0 means do not wait.
258 bool (*wait
)(struct lxc_container
*c
, const char *state
, int timeout
);
261 * \brief Set a key/value configuration option.
263 * \param c Container.
264 * \param key Name of option to set.
265 * \param value Value of \p name to set.
267 * \return \c true on success, else \c false.
269 bool (*set_config_item
)(struct lxc_container
*c
, const char *key
, const char *value
);
272 * \brief Delete the container.
274 * \param c Container.
276 * \return \c true on success, else \c false.
278 * \note Container must be stopped and have no dependent snapshots.
280 bool (*destroy
)(struct lxc_container
*c
);
283 * \brief Save configuration to a file.
285 * \param c Container.
286 * \param alt_file Full path to file to save configuration in.
288 * \return \c true on success, else \c false.
290 bool (*save_config
)(struct lxc_container
*c
, const char *alt_file
);
293 * \brief Create a container.
295 * \param c Container (with lxcpath, name and a starting
296 * configuration set).
297 * \param t Template to execute to instantiate the root
298 * filesystem and adjust the configuration.
299 * \param bdevtype Backing store type to use (if \c NULL, \c dir will be used).
300 * \param specs Additional parameters for the backing store (for
301 * example LVM volume group to use).
302 * \param flags \c LXC_CREATE_* options (currently only \ref
303 * LXC_CREATE_QUIET is supported).
304 * \param argv Arguments to pass to the template, terminated by \c NULL (if no
305 * arguments are required, just pass \c NULL).
307 * \return \c true on success, else \c false.
309 bool (*create
)(struct lxc_container
*c
, const char *t
, const char *bdevtype
,
310 struct bdev_specs
*specs
, int flags
, char *const argv
[]);
313 * \brief Create a container (list variant).
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 ... Command-line to pass to init (must end in \c NULL).
326 * \return \c true on success, else \c false.
328 * \note Identical to \ref create except that the template
329 * arguments are specified as a list rather than an array of
332 bool (*createl
)(struct lxc_container
*c
, const char *t
, const char *bdevtype
,
333 struct bdev_specs
*specs
, int flags
, ...);
336 * \brief Rename a container
338 * \param c Container.
339 * \param newname New name to be used for the container.
341 * \return \c true on success, else \c false.
343 bool (*rename
)(struct lxc_container
*c
, const char *newname
);
346 * \brief Request the container reboot by sending it \c SIGINT.
348 * \param c Container.
350 * \return \c true if reboot request successful, else \c false.
352 bool (*reboot
)(struct lxc_container
*c
);
355 * \brief Request the container shutdown by sending it \c
358 * \param c Container.
359 * \param timeout Seconds to wait before returning false.
360 * (-1 to wait forever, 0 to avoid waiting).
362 * \return \c true if the container was shutdown successfully, else \c false.
364 bool (*shutdown
)(struct lxc_container
*c
, int timeout
);
367 * \brief Completely clear the containers in-memory configuration.
369 * \param c Container.
371 void (*clear_config
)(struct lxc_container
*c
);
374 * \brief Clear a configuration item.
376 * \param c Container.
377 * \param key Name of option to clear.
379 * \return \c true on success, else \c false.
381 * \note Analog of \ref set_config_item.
383 bool (*clear_config_item
)(struct lxc_container
*c
, const char *key
);
386 * \brief Retrieve the value of a config item.
388 * \param c Container.
389 * \param key Name of option to get.
390 * \param[out] retv Caller-allocated buffer to write value of \p key
391 * into (or \c NULL to determine length of value).
392 * \param inlen Length of \p retv (may be zero).
394 * \return Length of config items value, or < 0 on error.
396 * \note The caller can (and should) determine how large a buffer to allocate for
397 * \p retv by initially passing its value as \c NULL and considering the return value.
398 * This function can then be called again passing a newly-allocated suitably-sized buffer.
399 * \note If \p retv is NULL, \p inlen is ignored.
400 * \note If \p inlen is smaller than required, nothing will be written to \p retv and still return
401 * the length of config item value.
403 int (*get_config_item
)(struct lxc_container
*c
, const char *key
, char *retv
, int inlen
);
407 * \brief Retrieve the value of a config item from running container.
409 * \param c Container.
410 * \param key Name of option to get.
412 * \return the item or NULL on error.
414 * \note Returned string must be freed by the caller.
416 char* (*get_running_config_item
)(struct lxc_container
*c
, const char *key
);
419 * \brief Retrieve a list of config item keys given a key
422 * \param c Container.
423 * \param key Name of option to get.
424 * \param[out] retv Caller-allocated buffer to write list of keys to
425 * (or \c NULL to determine overall length of keys list).
426 * \param inlen Length of \p retv (may be zero).
428 * \return Length of keys list, or < 0 on error.
430 * \note The list values written to \p retv are separated by
431 * a newline character ('\\n').
432 * \note The caller can (and should) determine how large a buffer to allocate for
433 * \p retv by initially passing its value as \c NULL and considering the return value.
434 * This function can then be called again passing a newly-allocated suitably-sized buffer.
435 * \note If \p retv is NULL, \p inlen is ignored.
436 * \note If \p inlen is smaller than required, the value written
437 * to \p retv will be truncated.
439 int (*get_keys
)(struct lxc_container
*c
, const char *key
, char *retv
, int inlen
);
442 * \brief Obtain a list of network interfaces.
443 * \param c Container.
445 * \return Newly-allocated array of network interfaces, or \c
448 * \note The returned array is allocated, so the caller must free it.
449 * \note The returned array is terminated with a \c NULL entry.
451 char** (*get_interfaces
)(struct lxc_container
*c
);
454 * \brief Determine the list of container IP addresses.
456 * \param c Container.
457 * \param interface Network interface name to consider.
458 * \param family Network family (for example "inet", "inet6").
459 * \param scope IPv6 scope id (ignored if \p family is not "inet6").
461 * \return Newly-allocated array of network interfaces, or \c
464 * \note The returned array is allocated, so the caller must free it.
465 * \note The returned array is terminated with a \c NULL entry.
467 char** (*get_ips
)(struct lxc_container
*c
, const char* interface
, const char* family
, int scope
);
470 * \brief Retrieve the specified cgroup subsystem value for the container.
472 * \param c Container.
473 * \param subsys cgroup subsystem to retrieve.
474 * \param[out] retv Caller-allocated buffer to write value of \p
475 * subsys into (or \c NULL to determine length of value).
476 * \param inlen length of \p retv (may be zero).
478 * \return Length of \p subsys value, or < 0 on error.
480 * \note If \p retv is \c NULL, \p inlen is ignored.
481 * \note If \p inlen is smaller than required, the value written
482 * to \p retv will be truncated.
484 int (*get_cgroup_item
)(struct lxc_container
*c
, const char *subsys
, char *retv
, int inlen
);
487 * \brief Set the specified cgroup subsystem value for the container.
489 * \param c Container.
490 * \param subsys cgroup subsystem to consider.
491 * \param value Value to set for \p subsys.
493 * \return \c true on success, else \c false.
495 bool (*set_cgroup_item
)(struct lxc_container
*c
, const char *subsys
, const char *value
);
498 * \brief Determine full path to the containers configuration file.
499 * Each container can have a custom configuration path. However
500 * by default it will be set to either the \c LXCPATH configure
501 * variable, or the lxcpath value in the \c LXC_GLOBAL_CONF configuration
502 * file (i.e. \c /etc/lxc/lxc.conf).
503 * The value for a specific container can be changed using
504 * \ref set_config_path. There is no other way to specify this in general at the moment.
506 * \param c Container.
508 * \return Static string representing full path to configuration
511 * \note Returned string must not be freed.
513 const char *(*get_config_path
)(struct lxc_container
*c
);
516 * \brief Set the full path to the containers configuration
519 * \param c Container.
520 * \param path Full path to configuration file.
522 * \return \c true on success, else \c false.
524 bool (*set_config_path
)(struct lxc_container
*c
, const char *path
);
527 * \brief Copy a stopped container.
529 * \param c Original container.
530 * \param newname New name for the container. If \c NULL, the same
531 * name is used and a new lxcpath MUST be specified.
532 * \param lxcpath lxcpath in which to create the new container. If
533 * \c NULL, the original container's lxcpath will be used.
534 * (XXX: should we use the default instead?)
535 * \param flags Additional \c LXC_CLONE* flags to change the cloning behaviour:
536 * - \ref LXC_CLONE_KEEPNAME
537 * - \ref LXC_CLONE_KEEPMACADDR
538 * - \ref LXC_CLONE_SNAPSHOT
539 * \param bdevtype Optionally force the cloned bdevtype to a specified plugin.
540 * By default the original is used (subject to snapshot requirements).
541 * \param bdevdata Information about how to create the new storage
542 * (i.e. fstype and fsdata).
543 * \param newsize In case of a block device backing store, an
544 * optional size. If \c 0, the original backing store's size will
545 * be used if possible. Note this only applies to the rootfs. For
546 * any other filesystems, the original size will be duplicated.
547 * \param hookargs Additional arguments to pass to the clone hook script.
549 * \return Newly-allocated copy of container \p c, or \p NULL on
552 * \note If devtype was not specified, and \p flags contains \ref
553 * LXC_CLONE_SNAPSHOT then use the native \p bdevtype if possible,
554 * else use an overlayfs.
556 struct lxc_container
*(*clone
)(struct lxc_container
*c
, const char *newname
,
557 const char *lxcpath
, int flags
, const char *bdevtype
,
558 const char *bdevdata
, uint64_t newsize
, char **hookargs
);
561 * \brief Allocate a console tty for the container.
563 * \param c Container.
564 * \param[in,out] ttynum Terminal number to attempt to allocate,
565 * or \c -1 to allocate the first available tty.
566 * \param[out] ptxfd File descriptor referring to the ptx side of the pty.
568 * \return tty file descriptor number on success, or \c -1 on
571 * \note On successful return, \p ttynum will contain the tty number
572 * that was allocated.
573 * \note The returned file descriptor is used to keep the tty
574 * allocated. The caller should call close(2) on the returned file
575 * descriptor when no longer required so that it may be allocated
578 int (*console_getfd
)(struct lxc_container
*c
, int *ttynum
, int *ptxfd
);
581 * \brief Allocate and run a console tty.
583 * \param c Container.
584 * \param ttynum Terminal number to attempt to allocate, \c -1 to
585 * allocate the first available tty or \c 0 to allocate the
587 * \param stdinfd File descriptor to read input from.
588 * \param stdoutfd File descriptor to write output to.
589 * \param stderrfd File descriptor to write error output to.
590 * \param escape The escape character (1 == 'a', 2 == 'b', ...).
592 * \return \c 0 on success, \c -1 on failure.
594 * \note This function will not return until the console has been
595 * exited by the user.
597 int (*console
)(struct lxc_container
*c
, int ttynum
,
598 int stdinfd
, int stdoutfd
, int stderrfd
, int escape
);
601 * \brief Create a sub-process attached to a container and run
602 * a function inside it.
604 * \param c Container.
605 * \param exec_function Function to run.
606 * \param exec_payload Data to pass to \p exec_function.
607 * \param options \ref lxc_attach_options_t.
608 * \param[out] attached_process Process ID of process running inside
609 * container \p c that is running \p exec_function.
611 * \return \c 0 on success, \c -1 on error.
613 int (*attach
)(struct lxc_container
*c
, lxc_attach_exec_t exec_function
,
614 void *exec_payload
, lxc_attach_options_t
*options
, pid_t
*attached_process
);
617 * \brief Run a program inside a container and wait for it to exit.
619 * \param c Container.
620 * \param options See \ref attach options.
621 * \param program Full path inside container of program to run.
622 * \param argv Array of arguments to pass to \p program.
624 * \return \c waitpid(2) status of exited process that ran \p
625 * program, or \c -1 on error.
627 int (*attach_run_wait
)(struct lxc_container
*c
, lxc_attach_options_t
*options
, const char *program
, const char * const argv
[]);
630 * \brief Run a program inside a container and wait for it to exit (list variant).
632 * \param c Container.
633 * \param options See \ref attach options.
634 * \param program Full path inside container of program to run.
635 * \param ... Command-line to pass to \p program (must end in \c NULL).
637 * \return \c waitpid(2) status of exited process that ran \p
638 * program, or \c -1 on error.
640 int (*attach_run_waitl
)(struct lxc_container
*c
, lxc_attach_options_t
*options
, const char *program
, const char *arg
, ...);
643 * \brief Create a container snapshot.
645 * Assuming default paths, snapshots will be created as
646 * \c /var/lib/lxc/\<c\>/snaps/snap\<n\>
647 * where \c \<c\> represents the container name and \c \<n\>
648 * represents the zero-based snapshot number.
650 * \param c Container.
651 * \param commentfile Full path to file containing a description
654 * \return -1 on error, or zero-based snapshot number.
656 * \note \p commentfile may be \c NULL but this is discouraged.
658 int (*snapshot
)(struct lxc_container
*c
, const char *commentfile
);
661 * \brief Obtain a list of container snapshots.
663 * \param c Container.
664 * \param[out] snapshots Dynamically-allocated Array of lxc_snapshot's.
666 * \return Number of snapshots.
668 * \note The array returned in \p snapshots is allocated, so the caller must free it.
669 * \note To free an individual snapshot as returned in \p
670 * snapshots, call the snapshots \c free function (see \c src/tests/snapshot.c for an example).
672 int (*snapshot_list
)(struct lxc_container
*c
, struct lxc_snapshot
**snapshots
);
675 * \brief Create a new container based on a snapshot.
677 * The restored container will be a copy (not snapshot) of the snapshot,
678 * and restored in the lxcpath of the original container.
679 * \param c Container.
680 * \param snapname Name of snapshot.
681 * \param newname Name to be used for the restored snapshot.
682 * \return \c true on success, else \c false.
683 * \warning If \p newname is the same as the current container
684 * name, the container will be destroyed. However, this will
685 * fail if the snapshot is overlay-based, since the snapshots
686 * will pin the original container.
687 * \note As an example, if the container exists as \c /var/lib/lxc/c1, snapname might be \c 'snap0'
688 * (representing \c /var/lib/lxc/c1/snaps/snap0). If \p newname is \p c2,
689 * then \c snap0 will be copied to \c /var/lib/lxc/c2.
691 bool (*snapshot_restore
)(struct lxc_container
*c
, const char *snapname
, const char *newname
);
694 * \brief Destroy the specified snapshot.
696 * \param c Container.
697 * \param snapname Name of snapshot.
699 * \return \c true on success, else \c false.
701 bool (*snapshot_destroy
)(struct lxc_container
*c
, const char *snapname
);
704 * \brief Determine if the caller may control the container.
706 * \param c Container.
708 * \return \c false if there is a control socket for the
709 * container monitor and the caller may not access it, otherwise
712 bool (*may_control
)(struct lxc_container
*c
);
715 * \brief Add specified device to the container.
717 * \param c Container.
718 * \param src_path Full path of the device.
719 * \param dest_path Alternate path in the container (or \p NULL
720 * to use \p src_path).
722 * \return \c true on success, else \c false.
724 bool (*add_device_node
)(struct lxc_container
*c
, const char *src_path
, const char *dest_path
);
727 * \brief Remove specified device from the container.
729 * \param c Container.
730 * \param src_path Full path of the device.
731 * \param dest_path Alternate path in the container (or \p NULL
732 * to use \p src_path).
734 * \return \c true on success, else \c false.
736 bool (*remove_device_node
)(struct lxc_container
*c
, const char *src_path
, const char *dest_path
);
738 /* Post LXC-1.0 additions */
741 * \brief Add specified netdev to the container.
743 * \param c Container.
744 * \param dev name of net device.
746 * \return \c true on success, else \c false.
748 bool (*attach_interface
)(struct lxc_container
*c
, const char *dev
, const char *dst_dev
);
751 * \brief Remove specified netdev from the container.
753 * \param c Container.
754 * \param dev name of net device.
756 * \return \c true on success, else \c false.
758 bool (*detach_interface
)(struct lxc_container
*c
, const char *dev
, const char *dst_dev
);
760 * \brief Checkpoint a container.
762 * \param c Container.
763 * \param directory The directory to dump the container to.
764 * \param stop Whether or not to stop the container after checkpointing.
765 * \param verbose Enable criu's verbose logs.
767 * \return \c true on success, else \c false.
768 * present at compile time).
770 bool (*checkpoint
)(struct lxc_container
*c
, char *directory
, bool stop
, bool verbose
);
773 * \brief Restore a container from a checkpoint.
775 * \param c Container.
776 * \param directory The directory to restore the container from.
777 * \param verbose Enable criu's verbose logs.
779 * \return \c true on success, else \c false.
782 bool (*restore
)(struct lxc_container
*c
, char *directory
, bool verbose
);
785 * \brief Delete the container and all its snapshots.
787 * \param c Container.
789 * \return \c true on success, else \c false.
791 * \note Container must be stopped.
793 bool (*destroy_with_snapshots
)(struct lxc_container
*c
);
796 * \brief Destroy all the container's snapshot.
798 * \param c Container.
800 * \return \c true on success, else \c false.
802 bool (*snapshot_destroy_all
)(struct lxc_container
*c
);
804 /* Post LXC-1.1 additions */
806 * \brief An API call to perform various migration operations
808 * \param cmd One of the MIGRATE_ constants.
809 * \param opts A migrate_opts struct filled with relevant options.
810 * \param size The size of the migrate_opts struct, i.e. sizeof(struct migrate_opts).
812 * \return \c 0 on success, nonzero on failure.
814 int (*migrate
)(struct lxc_container
*c
, unsigned int cmd
, struct migrate_opts
*opts
, unsigned int size
);
817 * \brief Query the console log of a container.
819 * \param c Container.
820 * \param opts A lxc_console_log struct filled with relevant options.
822 * \return \c 0 on success, nonzero on failure.
824 int (*console_log
)(struct lxc_container
*c
, struct lxc_console_log
*log
);
827 * \brief Request the container reboot by sending it \c SIGINT.
829 * \param c Container.
830 * \param timeout Seconds to wait before returning false.
831 * (-1 to wait forever, 0 to avoid waiting).
833 * \return \c true if the container was rebooted successfully, else \c false.
835 bool (*reboot2
)(struct lxc_container
*c
, int timeout
);
838 * \brief Mount the host's path `source` onto the container's path `target`.
840 int (*mount
)(struct lxc_container
*c
, const char *source
,
841 const char *target
, const char *filesystemtype
,
842 unsigned long mountflags
, const void *data
,
843 struct lxc_mount
*mnt
);
846 * \brief Unmount the container's path `target`.
848 int (*umount
)(struct lxc_container
*c
, const char *target
,
849 unsigned long mountflags
, struct lxc_mount
*mnt
);
852 * \brief Retrieve a file descriptor for the container's seccomp filter.
856 * \return file descriptor for container's seccomp filter
858 int (*seccomp_notify_fd
)(struct lxc_container
*c
);
861 * \brief Retrieve a pidfd for the container's init process.
863 * \param c Container.
865 * \return pidfd of init process of the container.
867 int (*init_pidfd
)(struct lxc_container
*c
);
871 * \brief An LXC container snapshot.
873 struct lxc_snapshot
{
874 char *name
; /*!< Name of snapshot */
875 char *comment_pathname
; /*!< Full path to snapshots comment file (may be \c NULL) */
876 char *timestamp
; /*!< Time snapshot was created */
877 char *lxcpath
; /*!< Full path to LXCPATH for snapshot */
880 * \brief De-allocate the snapshot.
883 void (*free
)(struct lxc_snapshot
*s
);
888 * \brief Specifications for how to create a new backing store
891 char *fstype
; /*!< Filesystem type */
892 uint64_t fssize
; /*!< Filesystem size in bytes */
894 char *zfsroot
; /*!< ZFS root path */
897 char *vg
; /*!< LVM Volume Group name */
898 char *lv
; /*!< LVM Logical Volume name */
899 char *thinpool
; /*!< LVM thin pool to use, if any */
901 char *dir
; /*!< Directory path */
903 char *rbdname
; /*!< RBD image name */
904 char *rbdpool
; /*!< Ceph pool name */
909 * \brief Commands for the migrate API call.
915 MIGRATE_FEATURE_CHECK
,
919 * \brief Available feature checks.
921 #define FEATURE_MEM_TRACK (1ULL << 0)
922 #define FEATURE_LAZY_PAGES (1ULL << 1)
925 * \brief Options for the migrate API call.
927 struct migrate_opts
{
928 /* new members should be added at the end */
932 bool stop
; /* stop the container after dump? */
933 char *predump_dir
; /* relative to directory above */
934 char *pageserver_address
; /* where should memory pages be send? */
935 char *pageserver_port
;
937 /* This flag indicates whether or not the container's rootfs will have
938 * the same inodes on checkpoint and restore. In the case of e.g. zfs
939 * send or btrfs send, or an LVM snapshot, this will be true, but it
940 * won't if e.g. you rsync the filesystems between two machines.
942 bool preserves_inodes
;
944 /* Path to an executable script that will be registered as a criu
949 /* If CRIU >= 2.4 is detected the option to skip in-flight connections
950 * will be enabled by default. The flag 'disable_skip_in_flight' will
951 * unconditionally disable this feature. In-flight connections are
952 * not fully established TCP connections: SYN, SYN-ACK */
953 bool disable_skip_in_flight
;
955 /* This is the maximum file size for deleted files (which CRIU calls
956 * "ghost" files) that will be handled. 0 indicates the CRIU default,
957 * which at this time is 1MB.
959 uint64_t ghost_limit
;
961 /* Some features cannot be checked by comparing the CRIU version.
962 * Features like dirty page tracking or userfaultfd depend on
963 * the architecture/kernel/criu combination. This is a bitmask
964 * in which the desired feature checks can be encoded.
966 uint64_t features_to_check
;
969 struct lxc_console_log
{
970 /* Clear the console log. */
973 /* Retrieve the console log. */
976 /* This specifies the maximum size to read from the ringbuffer. Setting
977 * it to 0 means that the a read can be as big as the whole ringbuffer.
978 * On return callers can check how many bytes were actually read.
979 * If "read" and "clear" are set to false and a non-zero value is
980 * specified then up to "read_max" bytes of data will be discarded from
985 /* Data that was read from the ringbuffer. If "read_max" is 0 on return
992 * \brief Create a new container.
994 * \param name Name to use for container.
995 * \param configpath Full path to configuration file to use.
997 * \return Newly-allocated container, or \c NULL on error.
999 struct lxc_container
*lxc_container_new(const char *name
, const char *configpath
);
1002 * \brief Add a reference to the specified container.
1004 * \param c Container.
1006 * \return \c true on success, \c false on error.
1008 int lxc_container_get(struct lxc_container
*c
);
1011 * \brief Drop a reference to the specified container.
1013 * \param c Container.
1015 * \return \c 0 on success, \c 1 if reference was successfully dropped
1016 * and container has been freed, and \c -1 on error.
1018 * \warning If \c 1 is returned, \p c is no longer valid.
1020 int lxc_container_put(struct lxc_container
*c
);
1023 * \brief Obtain a list of all container states.
1024 * \param[out] states Caller-allocated array to hold all states (may be \c NULL).
1026 * \return Number of container states.
1028 * \note Passing \c NULL for \p states allows the caller to first
1029 * calculate how many states there are before calling the function again, the second time
1030 * providing a suitably-sized array to store the static string pointers
1032 * \note The \p states array should be freed by the caller, but not the strings the elements point to.
1034 int lxc_get_wait_states(const char **states
);
1037 * \brief Get the value for a global config key
1039 * \param key The name of the config key
1041 * \return String representing the current value for the key.
1043 const char *lxc_get_global_config_item(const char *key
);
1046 * \brief Determine version of LXC.
1047 * \return Static string representing version of LXC in use.
1049 * \note Returned string must not be freed.
1051 const char *lxc_get_version(void);
1054 * \brief Get a list of defined containers in a lxcpath.
1056 * \param lxcpath lxcpath under which to look.
1057 * \param names If not \c NULL, then a list of container names will be returned here.
1058 * \param cret If not \c NULL, then a list of lxc_containers will be returned here.
1060 * \return Number of containers found, or \c -1 on error.
1062 * \note Values returned in \p cret are sorted by container name.
1064 int list_defined_containers(const char *lxcpath
, char ***names
, struct lxc_container
***cret
);
1067 * \brief Get a list of active containers for a given lxcpath.
1069 * \param lxcpath Full \c LXCPATH path to consider.
1070 * \param[out] names Dynamically-allocated array of container names.
1071 * \param[out] cret Dynamically-allocated list of containers.
1073 * \return Number of containers found, or -1 on error.
1075 * \note Some of the containers may not be "defined".
1076 * \note Values returned in \p cret are sorted by container name.
1077 * \note \p names and \p cret may both (or either) be specified as \c NULL.
1078 * \note \p names and \p cret must be freed by the caller.
1080 int list_active_containers(const char *lxcpath
, char ***names
, struct lxc_container
***cret
);
1083 * \brief Get a complete list of all containers for a given lxcpath.
1085 * \param lxcpath Full \c LXCPATH path to consider.
1086 * \param[out] names Dynamically-allocated array of container name.
1087 * \param[out] cret Dynamically-allocated list of containers.
1089 * \return Number of containers, or -1 on error.
1091 * \note Some of the containers may not be "defined".
1092 * \note Values returned in \p cret are sorted by container name.
1093 * \note \p names and \p cret may both (or either) be specified as \c NULL.
1094 * \note \p names and \p cret must be freed by the caller.
1096 int list_all_containers(const char *lxcpath
, char ***names
, struct lxc_container
***cret
);
1100 const char *lxcpath
;
1108 *\brief Initialize the log
1110 *\param log lxc log configuration.
1112 int lxc_log_init(struct lxc_log
*log
);
1115 * \brief Close log file.
1117 void lxc_log_close(void);
1120 * \brief Check if the configuration item is supported by this LXC instance.
1122 * \param key Configuration item to check for.
1124 bool lxc_config_item_is_supported(const char *key
);
1127 * \brief Check if an API extension is supported by this LXC instance.
1129 * \param extension API extension to check for.
1131 bool lxc_has_api_extension(const char *extension
);