#include <lxccontainer.h>
Data Fields | |
char * | error_string |
int | error_num |
bool | daemonize |
char * | config_path |
bool(* | is_defined )(struct lxc_container *c) |
Determine if /var/lib/lxc/$name/config exists. More... | |
const char *(* | state )(struct lxc_container *c) |
Determine state of container. More... | |
bool(* | is_running )(struct lxc_container *c) |
Determine if container is running. More... | |
bool(* | freeze )(struct lxc_container *c) |
Freeze running container. More... | |
bool(* | unfreeze )(struct lxc_container *c) |
Thaw a frozen container. More... | |
pid_t(* | init_pid )(struct lxc_container *c) |
Determine process ID of the containers init process. More... | |
bool(* | load_config )(struct lxc_container *c, const char *alt_file) |
Load the specified configuration for the container. More... | |
bool(* | start )(struct lxc_container *c, int useinit, char *const argv[]) |
Start the container. More... | |
bool(* | startl )(struct lxc_container *c, int useinit,...) |
Start the container (list variant). More... | |
bool(* | stop )(struct lxc_container *c) |
Stop the container. More... | |
bool(* | want_daemonize )(struct lxc_container *c, bool state) |
Change whether the container wants to run disconnected from the terminal. More... | |
bool(* | want_close_all_fds )(struct lxc_container *c, bool state) |
Change whether the container wishes all file descriptors to be closed on startup. More... | |
char *(* | config_file_name )(struct lxc_container *c) |
Return current config file name. More... | |
bool(* | wait )(struct lxc_container *c, const char *state, int timeout) |
Wait for container to reach a particular state. More... | |
bool(* | set_config_item )(struct lxc_container *c, const char *key, const char *value) |
Set a key/value configuration option. More... | |
bool(* | destroy )(struct lxc_container *c) |
Delete the container. More... | |
bool(* | save_config )(struct lxc_container *c, const char *alt_file) |
Save configuaration to a file. More... | |
bool(* | create )(struct lxc_container *c, const char *t, const char *bdevtype, struct bdev_specs *specs, int flags, char *const argv[]) |
Create a container. More... | |
bool(* | createl )(struct lxc_container *c, const char *t, const char *bdevtype, struct bdev_specs *specs, int flags,...) |
Create a container (list variant). More... | |
bool(* | rename )(struct lxc_container *c, const char *newname) |
Rename a container. More... | |
bool(* | reboot )(struct lxc_container *c) |
Request the container reboot by sending it SIGINT . More... | |
bool(* | shutdown )(struct lxc_container *c, int timeout) |
Request the container shutdown by sending it SIGPWR . More... | |
void(* | clear_config )(struct lxc_container *c) |
Completely clear the containers in-memory configuration. More... | |
bool(* | clear_config_item )(struct lxc_container *c, const char *key) |
Clear a configuration item. More... | |
int(* | get_config_item )(struct lxc_container *c, const char *key, char *retv, int inlen) |
Retrieve the value of a config item. More... | |
char *(* | get_running_config_item )(struct lxc_container *c, const char *key) |
Retrieve the value of a config item from running container. More... | |
int(* | get_keys )(struct lxc_container *c, const char *key, char *retv, int inlen) |
Retrieve a list of config item keys given a key prefix. More... | |
char **(* | get_interfaces )(struct lxc_container *c) |
Obtain a list of network interfaces. More... | |
char **(* | get_ips )(struct lxc_container *c, const char *interface, const char *family, int scope) |
Determine the list of container IP addresses. More... | |
int(* | get_cgroup_item )(struct lxc_container *c, const char *subsys, char *retv, int inlen) |
Retrieve the specified cgroup subsystem value for the container. More... | |
bool(* | set_cgroup_item )(struct lxc_container *c, const char *subsys, const char *value) |
Set the specified cgroup subsystem value for the container. More... | |
const char *(* | get_config_path )(struct lxc_container *c) |
Determine full path to the containers configuration file. Each container can have a custom configuration path. However by default it will be set to either the LXCPATH configure variable, or the lxcpath value in the LXC_GLOBAL_CONF configuration file (i.e. /etc/lxc/lxc .conf). The value for a specific container can be changed using set_config_path. There is no other way to specify this in general at the moment. More... | |
bool(* | set_config_path )(struct lxc_container *c, const char *path) |
Set the full path to the containers configuration file. More... | |
struct lxc_container *(* | clone )(struct lxc_container *c, const char *newname, const char *lxcpath, int flags, const char *bdevtype, const char *bdevdata, uint64_t newsize, char **hookargs) |
Copy a stopped container. More... | |
int(* | console_getfd )(struct lxc_container *c, int *ttynum, int *masterfd) |
Allocate a console tty for the container. More... | |
int(* | console )(struct lxc_container *c, int ttynum, int stdinfd, int stdoutfd, int stderrfd, int escape) |
Allocate and run a console tty. More... | |
int(* | attach )(struct lxc_container *c, lxc_attach_exec_t exec_function, void *exec_payload, lxc_attach_options_t *options, pid_t *attached_process) |
Create a sub-process attached to a container and run a function inside it. More... | |
int(* | attach_run_wait )(struct lxc_container *c, lxc_attach_options_t *options, const char *program, const char *const argv[]) |
Run a program inside a container and wait for it to exit. More... | |
int(* | attach_run_waitl )(struct lxc_container *c, lxc_attach_options_t *options, const char *program, const char *arg,...) |
Run a program inside a container and wait for it to exit (list variant). More... | |
int(* | snapshot )(struct lxc_container *c, const char *commentfile) |
Create a container snapshot. More... | |
int(* | snapshot_list )(struct lxc_container *c, struct lxc_snapshot **snapshots) |
Obtain a list of container snapshots. More... | |
bool(* | snapshot_restore )(struct lxc_container *c, const char *snapname, const char *newname) |
Create a new container based on a snapshot. More... | |
bool(* | snapshot_destroy )(struct lxc_container *c, const char *snapname) |
Destroy the specified snapshot. More... | |
bool(* | may_control )(struct lxc_container *c) |
Determine if the caller may control the container. More... | |
bool(* | add_device_node )(struct lxc_container *c, const char *src_path, const char *dest_path) |
Add specified device to the container. More... | |
bool(* | remove_device_node )(struct lxc_container *c, const char *src_path, const char *dest_path) |
Remove specified device from the container. More... | |
bool(* | attach_interface )(struct lxc_container *c, const char *dev, const char *dst_dev) |
Add specified netdev to the container. More... | |
bool(* | detach_interface )(struct lxc_container *c, const char *dev, const char *dst_dev) |
Remove specified netdev from the container. More... | |
bool(* | checkpoint )(struct lxc_container *c, char *directory, bool stop, bool verbose) |
Checkpoint a container. More... | |
bool(* | restore )(struct lxc_container *c, char *directory, bool verbose) |
Restore a container from a checkpoint. More... | |
bool(* | destroy_with_snapshots )(struct lxc_container *c) |
Delete the container and all its snapshots. More... | |
bool(* | snapshot_destroy_all )(struct lxc_container *c) |
Destroy all the container's snapshot. More... | |
int(* | migrate )(struct lxc_container *c, unsigned int cmd, struct migrate_opts *opts, unsigned int size) |
An API call to perform various migration operations. More... | |
An LXC container.
Note that changing the order of struct members is an API change, as callers will end up having the wrong offset when calling a function. So when making changes, whenever possible stick to simply appending new members.
bool(* lxc_container::add_device_node)(struct lxc_container *c, const char *src_path, const char *dest_path) |
Add specified device to the container.
c | Container. |
src_path | Full path of the device. |
dest_path | Alternate path in the container (or NULL to use src_path ). |
true
on success, else false
. int(* lxc_container::attach)(struct lxc_container *c, lxc_attach_exec_t exec_function, void *exec_payload, lxc_attach_options_t *options, pid_t *attached_process) |
Create a sub-process attached to a container and run a function inside it.
c | Container. | |
exec_function | Function to run. | |
exec_payload | Data to pass to exec_function . | |
options | lxc_attach_options_t. | |
[out] | attached_process | Process ID of process running inside container c that is running exec_function . |
0
on success, -1
on error. bool(* lxc_container::attach_interface)(struct lxc_container *c, const char *dev, const char *dst_dev) |
Add specified netdev to the container.
c | Container. |
dev | name of net device. |
true
on success, else false
. int(* lxc_container::attach_run_wait)(struct lxc_container *c, lxc_attach_options_t *options, const char *program, const char *const argv[]) |
Run a program inside a container and wait for it to exit.
c | Container. |
options | See attach options. |
program | Full path inside container of program to run. |
argv | Array of arguments to pass to program . |
waitpid(2)
status of exited process that ran program
, or -1
on error. int(* lxc_container::attach_run_waitl)(struct lxc_container *c, lxc_attach_options_t *options, const char *program, const char *arg,...) |
Run a program inside a container and wait for it to exit (list variant).
c | Container. |
options | See attach options. |
program | Full path inside container of program to run. |
... | Command-line to pass to program (must end in NULL ). |
waitpid(2)
status of exited process that ran program
, or -1
on error. bool(* lxc_container::checkpoint)(struct lxc_container *c, char *directory, bool stop, bool verbose) |
Checkpoint a container.
c | Container. |
directory | The directory to dump the container to. |
stop | Whether or not to stop the container after checkpointing. |
verbose | Enable criu's verbose logs. |
true
on success, else false
. present at compile time). void(* lxc_container::clear_config)(struct lxc_container *c) |
Completely clear the containers in-memory configuration.
c | Container. |
bool(* lxc_container::clear_config_item)(struct lxc_container *c, const char *key) |
Clear a configuration item.
c | Container. |
key | Name of option to clear. |
true
on success, else false
.struct lxc_container*(* lxc_container::clone)(struct lxc_container *c, const char *newname, const char *lxcpath, int flags, const char *bdevtype, const char *bdevdata, uint64_t newsize, char **hookargs) |
Copy a stopped container.
c | Original container. |
newname | New name for the container. If NULL , the same name is used and a new lxcpath MUST be specified. |
lxcpath | lxcpath in which to create the new container. If NULL , the original container's lxcpath will be used. (XXX: should we use the default instead?) |
flags | Additional LXC_CLONE* flags to change the cloning behaviour:
|
bdevtype | Optionally force the cloned bdevtype to a specified plugin. By default the original is used (subject to snapshot requirements). |
bdevdata | Information about how to create the new storage (i.e. fstype and fsdata). |
newsize | In case of a block device backing store, an optional size. If 0 , the original backing store's size will be used if possible. Note this only applies to the rootfs. For any other filesystems, the original size will be duplicated. |
hookargs | Additional arguments to pass to the clone hook script. |
c
, or NULL
on error.flags
contains LXC_CLONE_SNAPSHOT then use the native bdevtype
if possible, else use an overlayfs. char*(* lxc_container::config_file_name)(struct lxc_container *c) |
Return current config file name.
c | Container. |
NULL
on error.char* lxc_container::config_path |
Full path to configuration file
int(* lxc_container::console)(struct lxc_container *c, int ttynum, int stdinfd, int stdoutfd, int stderrfd, int escape) |
Allocate and run a console tty.
c | Container. |
ttynum | Terminal number to attempt to allocate, -1 to allocate the first available tty or 0 to allocate the console. |
stdinfd | File descriptor to read input from. |
stdoutfd | File descriptor to write output to. |
stderrfd | File descriptor to write error output to. |
escape | The escape character (1 == 'a', 2 == 'b', ...). |
0
on success, -1
on failure.int(* lxc_container::console_getfd)(struct lxc_container *c, int *ttynum, int *masterfd) |
Allocate a console tty for the container.
c | Container. | |
[in,out] | ttynum | Terminal number to attempt to allocate, or -1 to allocate the first available tty. |
[out] | masterfd | File descriptor referring to the master side of the pty. |
-1
on failure.ttynum
will contain the tty number that was allocated. bool(* lxc_container::create)(struct lxc_container *c, const char *t, const char *bdevtype, struct bdev_specs *specs, int flags, char *const argv[]) |
Create a container.
c | Container (with lxcpath, name and a starting configuration set). |
t | Template to execute to instantiate the root filesystem and adjust the configuration. |
bdevtype | Backing store type to use (if NULL , dir will be used). |
specs | Additional parameters for the backing store (for example LVM volume group to use). |
flags | LXC_CREATE_* options (currently only LXC_CREATE_QUIET is supported). |
argv | Arguments to pass to the template, terminated by NULL (if no arguments are required, just pass NULL ). |
true
on success, else false
. bool(* lxc_container::createl)(struct lxc_container *c, const char *t, const char *bdevtype, struct bdev_specs *specs, int flags,...) |
Create a container (list variant).
c | Container (with lxcpath, name and a starting configuration set). |
t | Template to execute to instantiate the root filesystem and adjust the configuration. |
bdevtype | Backing store type to use (if NULL , dir will be used). |
specs | Additional parameters for the backing store (for example LVM volume group to use). |
flags | LXC_CREATE_* options (currently only LXC_CREATE_QUIET is supported). |
... | Command-line to pass to init (must end in NULL ). |
true
on success, else false
.bool lxc_container::daemonize |
Whether container wishes to be daemonized
bool(* lxc_container::destroy)(struct lxc_container *c) |
Delete the container.
c | Container. |
true
on success, else false
.bool(* lxc_container::destroy_with_snapshots)(struct lxc_container *c) |
Delete the container and all its snapshots.
c | Container. |
true
on success, else false
.bool(* lxc_container::detach_interface)(struct lxc_container *c, const char *dev, const char *dst_dev) |
Remove specified netdev from the container.
c | Container. |
dev | name of net device. |
true
on success, else false
. int lxc_container::error_num |
Last error number
char* lxc_container::error_string |
Human-readable string representing last error
bool(* lxc_container::freeze)(struct lxc_container *c) |
Freeze running container.
c | Container. |
true
on success, else false
. int(* lxc_container::get_cgroup_item)(struct lxc_container *c, const char *subsys, char *retv, int inlen) |
Retrieve the specified cgroup subsystem value for the container.
c | Container. | |
subsys | cgroup subsystem to retrieve. | |
[out] | retv | Caller-allocated buffer to write value of subsys into (or NULL to determine length of value). |
inlen | length of retv (may be zero). |
subsys
value, or < 0 on error.retv
is NULL
, inlen
is ignored. inlen
is smaller than required, the value written to retv
will be truncated. int(* lxc_container::get_config_item)(struct lxc_container *c, const char *key, char *retv, int inlen) |
Retrieve the value of a config item.
c | Container. | |
key | Name of option to get. | |
[out] | retv | Caller-allocated buffer to write value of key into (or NULL to determine length of value). |
inlen | Length of retv (may be zero). |
retv
by initially passing its value as NULL
and considering the return value. This function can then be called again passing a newly-allocated suitably-sized buffer. retv
is NULL, inlen
is ignored. inlen
is smaller than required, nothing will be written to retv
and still return the length of config item value. const char*(* lxc_container::get_config_path)(struct lxc_container *c) |
Determine full path to the containers configuration file. Each container can have a custom configuration path. However by default it will be set to either the LXCPATH
configure variable, or the lxcpath value in the LXC_GLOBAL_CONF
configuration file (i.e. /etc/lxc/lxc
.conf). The value for a specific container can be changed using set_config_path. There is no other way to specify this in general at the moment.
c | Container. |
char**(* lxc_container::get_interfaces)(struct lxc_container *c) |
Obtain a list of network interfaces.
c | Container. |
NULL
on error.NULL
entry. char**(* lxc_container::get_ips)(struct lxc_container *c, const char *interface, const char *family, int scope) |
Determine the list of container IP addresses.
c | Container. |
interface | Network interface name to consider. |
family | Network family (for example "inet", "inet6"). |
scope | IPv6 scope id (ignored if family is not "inet6"). |
NULL
on error.NULL
entry. int(* lxc_container::get_keys)(struct lxc_container *c, const char *key, char *retv, int inlen) |
Retrieve a list of config item keys given a key prefix.
c | Container. | |
key | Name of option to get. | |
[out] | retv | Caller-allocated buffer to write list of keys to (or NULL to determine overall length of keys list). |
inlen | Length of retv (may be zero). |
retv
are separated by a newline character ('\n'). retv
by initially passing its value as NULL
and considering the return value. This function can then be called again passing a newly-allocated suitably-sized buffer. retv
is NULL, inlen
is ignored. inlen
is smaller than required, the value written to retv
will be truncated. char*(* lxc_container::get_running_config_item)(struct lxc_container *c, const char *key) |
Retrieve the value of a config item from running container.
c | Container. |
key | Name of option to get. |
pid_t(* lxc_container::init_pid)(struct lxc_container *c) |
Determine process ID of the containers init process.
c | Container. |
bool(* lxc_container::is_defined)(struct lxc_container *c) |
Determine if /var/lib/lxc/$name/config
exists.
c | Container. |
true
if container is defined, else false
. bool(* lxc_container::is_running)(struct lxc_container *c) |
Determine if container is running.
c | Container. |
true
on success, else false
. bool(* lxc_container::load_config)(struct lxc_container *c, const char *alt_file) |
Load the specified configuration for the container.
c | Container. |
alt_file | Full path to alternate configuration file, or NULL to use the default configuration file. |
true
on success, else false
. bool(* lxc_container::may_control)(struct lxc_container *c) |
Determine if the caller may control the container.
c | Container. |
false
if there is a control socket for the container monitor and the caller may not access it, otherwise returns true
. int(* lxc_container::migrate)(struct lxc_container *c, unsigned int cmd, struct migrate_opts *opts, unsigned int size) |
An API call to perform various migration operations.
cmd | One of the MIGRATE_ contstants. |
opts | A migrate_opts struct filled with relevant options. |
size | The size of the migrate_opts struct, i.e. sizeof(struct migrate_opts). |
0
on success, nonzero on failure. bool(* lxc_container::reboot)(struct lxc_container *c) |
Request the container reboot by sending it SIGINT
.
c | Container. |
true
if reboot request successful, else false
. bool(* lxc_container::remove_device_node)(struct lxc_container *c, const char *src_path, const char *dest_path) |
Remove specified device from the container.
c | Container. |
src_path | Full path of the device. |
dest_path | Alternate path in the container (or NULL to use src_path ). |
true
on success, else false
. bool(* lxc_container::rename)(struct lxc_container *c, const char *newname) |
Rename a container.
c | Container. |
newname | New name to be used for the container. |
true
on success, else false
. bool(* lxc_container::restore)(struct lxc_container *c, char *directory, bool verbose) |
Restore a container from a checkpoint.
c | Container. |
directory | The directory to restore the container from. |
verbose | Enable criu's verbose logs. |
true
on success, else false
. bool(* lxc_container::save_config)(struct lxc_container *c, const char *alt_file) |
Save configuaration to a file.
c | Container. |
alt_file | Full path to file to save configuration in. |
true
on success, else false
. bool(* lxc_container::set_cgroup_item)(struct lxc_container *c, const char *subsys, const char *value) |
Set the specified cgroup subsystem value for the container.
c | Container. |
subsys | cgroup subsystem to consider. |
value | Value to set for subsys . |
true
on success, else false
. bool(* lxc_container::set_config_item)(struct lxc_container *c, const char *key, const char *value) |
Set a key/value configuration option.
c | Container. |
key | Name of option to set. |
value | Value of name to set. |
true
on success, else false
. bool(* lxc_container::set_config_path)(struct lxc_container *c, const char *path) |
Set the full path to the containers configuration file.
c | Container. |
path | Full path to configuration file. |
true
on success, else false
. bool(* lxc_container::shutdown)(struct lxc_container *c, int timeout) |
Request the container shutdown by sending it SIGPWR
.
c | Container. |
timeout | Seconds to wait before returning false. (-1 to wait forever, 0 to avoid waiting). |
true
if the container was shutdown successfully, else false
. int(* lxc_container::snapshot)(struct lxc_container *c, const char *commentfile) |
Create a container snapshot.
Assuming default paths, snapshots will be created as /var/lib/lxc/<c>/snaps/snap<n>
where <c>
represents the container name and <n>
represents the zero-based snapshot number.
c | Container. |
commentfile | Full path to file containing a description of the snapshot. |
commentfile
may be NULL
but this is discouraged. bool(* lxc_container::snapshot_destroy)(struct lxc_container *c, const char *snapname) |
Destroy the specified snapshot.
c | Container. |
snapname | Name of snapshot. |
true
on success, else false
. bool(* lxc_container::snapshot_destroy_all)(struct lxc_container *c) |
Destroy all the container's snapshot.
c | Container. |
true
on success, else false
. int(* lxc_container::snapshot_list)(struct lxc_container *c, struct lxc_snapshot **snapshots) |
Obtain a list of container snapshots.
c | Container. | |
[out] | snapshots | Dynamically-allocated Array of lxc_snapshot's. |
snapshots
is allocated, so the caller must free it. snapshots
, call the snapshots free
function (see src/tests/snapshot.c
for an example). bool(* lxc_container::snapshot_restore)(struct lxc_container *c, const char *snapname, const char *newname) |
Create a new container based on a snapshot.
The restored container will be a copy (not snapshot) of the snapshot, and restored in the lxcpath of the original container.
c | Container. |
snapname | Name of snapshot. |
newname | Name to be used for the restored snapshot. |
true
on success, else false
. newname
is the same as the current container name, the container will be destroyed. However, this will fail if the snapshot is overlay-based, since the snapshots will pin the original container. /var/lib/lxc/c1
, snapname might be 'snap0'
(representing /var/lib/lxc/c1/snaps/snap0
). If newname
is c2
, then snap0
will be copied to /var/lib/lxc/c2
. bool(* lxc_container::start)(struct lxc_container *c, int useinit, char *const argv[]) |
Start the container.
c | Container. |
useinit | Use lxcinit rather than /sbin/init . |
argv | Array of arguments to pass to init. |
true
on success, else false
. bool(* lxc_container::startl)(struct lxc_container *c, int useinit,...) |
Start the container (list variant).
c | Container. |
useinit | Use lxcinit rather than /sbin/init . |
... | Command-line to pass to init (must end in NULL ). |
true
on success, else false
.const char*(* lxc_container::state)(struct lxc_container *c) |
Determine state of container.
c | Container. |
bool(* lxc_container::stop)(struct lxc_container *c) |
Stop the container.
c | Container. |
true
on success, else false
. bool(* lxc_container::unfreeze)(struct lxc_container *c) |
Thaw a frozen container.
c | Container. |
true
on success, else false
. bool(* lxc_container::wait)(struct lxc_container *c, const char *state, int timeout) |
Wait for container to reach a particular state.
c | Container. |
state | State to wait for. |
timeout | Timeout in seconds. |
true
if state reached within timeout
, else false
.timeout
of -1
means wait forever. A timeout
of 0
means do not wait. bool(* lxc_container::want_close_all_fds)(struct lxc_container *c, bool state) |
Change whether the container wishes all file descriptors to be closed on startup.
c | Container. |
state | Value for the close_all_fds bit (0 or 1). |
true
on success, else false
. bool(* lxc_container::want_daemonize)(struct lxc_container *c, bool state) |
Change whether the container wants to run disconnected from the terminal.
c | Container. |
state | Value for the daemonize bit (0 or 1). |
true
on success, else false
.