Loading...
Searching...
No Matches
lxccontainer.h
/* SPDX-License-Identifier: LGPL-2.1+ */
#ifndef __LXC_CONTAINER_H
#define __LXC_CONTAINER_H
#include <malloc.h>
#include <semaphore.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
#include <lxc/attach_options.h>
#ifdef __cplusplus
extern "C" {
#endif
#define LXC_CLONE_KEEPNAME (1 << 0)
#define LXC_CLONE_KEEPMACADDR (1 << 1)
#define LXC_CLONE_SNAPSHOT (1 << 2)
#define LXC_CLONE_KEEPBDEVTYPE (1 << 3)
#define LXC_CLONE_MAYBE_SNAPSHOT (1 << 4)
#define LXC_CLONE_MAXFLAGS (1 << 5)
#define LXC_CLONE_ALLOW_RUNNING (1 << 6)
#define LXC_CREATE_QUIET (1 << 0)
#define LXC_CREATE_MAXFLAGS (1 << 1)
#define LXC_MOUNT_API_V1 1
struct bdev_specs;
struct lxc_snapshot;
struct lxc_lock;
struct migrate_opts;
struct lxc_console_log;
struct lxc_mount {
int version;
};
struct lxc_container {
/* private fields */
char *name;
char *configfile;
char *pidfile;
struct lxc_lock *slock;
struct lxc_lock *privlock;
int numthreads;
struct lxc_conf *lxc_conf;
/* public fields */
char *error_string;
int error_num;
bool daemonize;
char *config_path;
bool (*is_defined)(struct lxc_container *c);
const char *(*state)(struct lxc_container *c);
bool (*is_running)(struct lxc_container *c);
bool (*freeze)(struct lxc_container *c);
bool (*unfreeze)(struct lxc_container *c);
pid_t (*init_pid)(struct lxc_container *c);
bool (*load_config)(struct lxc_container *c, const char *alt_file);
bool (*start)(struct lxc_container *c, int useinit, char * const argv[]);
bool (*startl)(struct lxc_container *c, int useinit, ...);
bool (*stop)(struct lxc_container *c);
bool (*want_daemonize)(struct lxc_container *c, bool state);
bool (*want_close_all_fds)(struct lxc_container *c, bool state);
char *(*config_file_name)(struct lxc_container *c);
bool (*wait)(struct lxc_container *c, const char *state, int timeout);
bool (*set_config_item)(struct lxc_container *c, const char *key, const char *value);
bool (*destroy)(struct lxc_container *c);
bool (*save_config)(struct lxc_container *c, const char *alt_file);
bool (*create)(struct lxc_container *c, const char *t, const char *bdevtype,
struct bdev_specs *specs, int flags, char *const argv[]);
bool (*createl)(struct lxc_container *c, const char *t, const char *bdevtype,
struct bdev_specs *specs, int flags, ...);
bool (*rename)(struct lxc_container *c, const char *newname);
bool (*reboot)(struct lxc_container *c);
bool (*shutdown)(struct lxc_container *c, int timeout);
void (*clear_config)(struct lxc_container *c);
bool (*clear_config_item)(struct lxc_container *c, const char *key);
int (*get_config_item)(struct lxc_container *c, const char *key, char *retv, int inlen);
char* (*get_running_config_item)(struct lxc_container *c, const char *key);
int (*get_keys)(struct lxc_container *c, const char *key, char *retv, int inlen);
char** (*get_interfaces)(struct lxc_container *c);
char** (*get_ips)(struct lxc_container *c, const char* interface, const char* family, int scope);
int (*get_cgroup_item)(struct lxc_container *c, const char *subsys, char *retv, int inlen);
bool (*set_cgroup_item)(struct lxc_container *c, const char *subsys, const char *value);
const char *(*get_config_path)(struct lxc_container *c);
bool (*set_config_path)(struct lxc_container *c, const char *path);
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);
int (*console_getfd)(struct lxc_container *c, int *ttynum, int *ptxfd);
int (*console)(struct lxc_container *c, int ttynum,
int stdinfd, int stdoutfd, int stderrfd, int escape);
int (*attach)(struct lxc_container *c, lxc_attach_exec_t exec_function,
void *exec_payload, lxc_attach_options_t *options, pid_t *attached_process);
int (*attach_run_wait)(struct lxc_container *c, lxc_attach_options_t *options, const char *program, const char * const argv[]);
int (*attach_run_waitl)(struct lxc_container *c, lxc_attach_options_t *options, const char *program, const char *arg, ...);
int (*snapshot)(struct lxc_container *c, const char *commentfile);
int (*snapshot_list)(struct lxc_container *c, struct lxc_snapshot **snapshots);
bool (*snapshot_restore)(struct lxc_container *c, const char *snapname, const char *newname);
bool (*snapshot_destroy)(struct lxc_container *c, const char *snapname);
bool (*may_control)(struct lxc_container *c);
bool (*add_device_node)(struct lxc_container *c, const char *src_path, const char *dest_path);
bool (*remove_device_node)(struct lxc_container *c, const char *src_path, const char *dest_path);
/* Post LXC-1.0 additions */
bool (*attach_interface)(struct lxc_container *c, const char *dev, const char *dst_dev);
bool (*detach_interface)(struct lxc_container *c, const char *dev, const char *dst_dev);
bool (*checkpoint)(struct lxc_container *c, char *directory, bool stop, bool verbose);
bool (*restore)(struct lxc_container *c, char *directory, bool verbose);
bool (*destroy_with_snapshots)(struct lxc_container *c);
bool (*snapshot_destroy_all)(struct lxc_container *c);
/* Post LXC-1.1 additions */
int (*migrate)(struct lxc_container *c, unsigned int cmd, struct migrate_opts *opts, unsigned int size);
int (*console_log)(struct lxc_container *c, struct lxc_console_log *log);
bool (*reboot2)(struct lxc_container *c, int timeout);
int (*mount)(struct lxc_container *c, const char *source,
const char *target, const char *filesystemtype,
unsigned long mountflags, const void *data,
struct lxc_mount *mnt);
int (*umount)(struct lxc_container *c, const char *target,
unsigned long mountflags, struct lxc_mount *mnt);
int (*seccomp_notify_fd)(struct lxc_container *c);
int (*seccomp_notify_fd_active)(struct lxc_container *c);
int (*init_pidfd)(struct lxc_container *c);
int (*devpts_fd)(struct lxc_container *c);
int rcv_timeout;
bool (*set_timeout)(struct lxc_container *c, int timeout);
};
struct lxc_snapshot {
char *name;
char *comment_pathname;
char *timestamp;
char *lxcpath;
void (*free)(struct lxc_snapshot *s);
};
struct bdev_specs {
char *fstype;
uint64_t fssize;
struct {
char *zfsroot;
} zfs;
struct {
char *vg;
char *lv;
char *thinpool;
} lvm;
char *dir;
struct {
char *rbdname;
char *rbdpool;
char *rbduser;
} rbd;
};
enum {
MIGRATE_PRE_DUMP,
MIGRATE_DUMP,
MIGRATE_RESTORE,
MIGRATE_FEATURE_CHECK,
};
#define FEATURE_MEM_TRACK (1ULL << 0)
#define FEATURE_LAZY_PAGES (1ULL << 1)
struct migrate_opts {
/* new members should be added at the end */
char *directory;
bool verbose;
bool stop; /* stop the container after dump? */
char *predump_dir; /* relative to directory above */
char *pageserver_address; /* where should memory pages be send? */
char *pageserver_port;
/* This flag indicates whether or not the container's rootfs will have
* the same inodes on checkpoint and restore. In the case of e.g. zfs
* send or btrfs send, or an LVM snapshot, this will be true, but it
* won't if e.g. you rsync the filesystems between two machines.
*/
bool preserves_inodes;
/* Path to an executable script that will be registered as a criu
* "action script"
*/
char *action_script;
/* If CRIU >= 2.4 is detected the option to skip in-flight connections
* will be enabled by default. The flag 'disable_skip_in_flight' will
* unconditionally disable this feature. In-flight connections are
* not fully established TCP connections: SYN, SYN-ACK */
bool disable_skip_in_flight;
/* This is the maximum file size for deleted files (which CRIU calls
* "ghost" files) that will be handled. 0 indicates the CRIU default,
* which at this time is 1MB.
*/
uint64_t ghost_limit;
/* Some features cannot be checked by comparing the CRIU version.
* Features like dirty page tracking or userfaultfd depend on
* the architecture/kernel/criu combination. This is a bitmask
* in which the desired feature checks can be encoded.
*/
uint64_t features_to_check;
};
struct lxc_console_log {
/* Clear the console log. */
bool clear;
/* Retrieve the console log. */
bool read;
/* This specifies the maximum size to read from the ringbuffer. Setting
* it to 0 means that the a read can be as big as the whole ringbuffer.
* On return callers can check how many bytes were actually read.
* If "read" and "clear" are set to false and a non-zero value is
* specified then up to "read_max" bytes of data will be discarded from
* the ringbuffer.
*/
uint64_t *read_max;
/* Data that was read from the ringbuffer. If "read_max" is 0 on return
* "data" is invalid.
*/
char *data;
};
struct lxc_container *lxc_container_new(const char *name, const char *configpath);
int lxc_container_get(struct lxc_container *c);
int lxc_container_put(struct lxc_container *c);
int lxc_get_wait_states(const char **states);
const char *lxc_get_global_config_item(const char *key);
const char *lxc_get_version(void);
int list_defined_containers(const char *lxcpath, char ***names, struct lxc_container ***cret);
int list_active_containers(const char *lxcpath, char ***names, struct lxc_container ***cret);
int list_all_containers(const char *lxcpath, char ***names, struct lxc_container ***cret);
struct lxc_log {
const char *name;
const char *lxcpath;
const char *file;
const char *level;
const char *prefix;
bool quiet;
};
int lxc_log_init(struct lxc_log *log);
void lxc_log_close(void);
bool lxc_config_item_is_supported(const char *key);
bool lxc_has_api_extension(const char *extension);
#ifdef __cplusplus
}
#endif
#endif
bdev_specs
Specifications for how to create a new backing store.
Definition lxccontainer.h:924
bdev_specs::zfsroot
char * zfsroot
Definition lxccontainer.h:928
bdev_specs::vg
char * vg
Definition lxccontainer.h:931
bdev_specs::fstype
char * fstype
Definition lxccontainer.h:925
bdev_specs::dir
char * dir
Definition lxccontainer.h:935
bdev_specs::lv
char * lv
Definition lxccontainer.h:932
bdev_specs::rbdname
char * rbdname
Definition lxccontainer.h:937
bdev_specs::fssize
uint64_t fssize
Definition lxccontainer.h:926
bdev_specs::rbdpool
char * rbdpool
Definition lxccontainer.h:938
bdev_specs::rbduser
char * rbduser
Definition lxccontainer.h:939
bdev_specs::thinpool
char * thinpool
Definition lxccontainer.h:933
lxc_attach_options_t
Definition attach_options.h:90
lxc_console_log
Definition lxccontainer.h:1004
lxc_container
Definition lxccontainer.h:50
lxc_container::seccomp_notify_fd_active
int(* seccomp_notify_fd_active)(struct lxc_container *c)
Retrieve a file descriptor for the running container's seccomp filter.
Definition lxccontainer.h:866
lxc_container::checkpoint
bool(* checkpoint)(struct lxc_container *c, char *directory, bool stop, bool verbose)
Checkpoint a container.
Definition lxccontainer.h:769
lxc_container::wait
bool(* wait)(struct lxc_container *c, const char *state, int timeout)
Wait for container to reach a particular state.
Definition lxccontainer.h:259
lxc_container::createl
bool(* createl)(struct lxc_container *c, const char *t, const char *bdevtype, struct bdev_specs *specs, int flags,...)
Create a container (list variant).
Definition lxccontainer.h:333
lxc_container::load_config
bool(* load_config)(struct lxc_container *c, const char *alt_file)
Load the specified configuration for the container.
Definition lxccontainer.h:176
lxc_container::snapshot_destroy_all
bool(* snapshot_destroy_all)(struct lxc_container *c)
Destroy all the container's snapshot.
Definition lxccontainer.h:801
lxc_container::console_log
int(* console_log)(struct lxc_container *c, struct lxc_console_log *log)
Query the console log of a container.
Definition lxccontainer.h:823
lxc_container::attach
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.
Definition lxccontainer.h:612
lxc_container::attach_run_waitl
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).
Definition lxccontainer.h:639
lxc_container::add_device_node
bool(* add_device_node)(struct lxc_container *c, const char *src_path, const char *dest_path)
Add specified device to the container.
Definition lxccontainer.h:723
lxc_container::destroy
bool(* destroy)(struct lxc_container *c)
Delete the container.
Definition lxccontainer.h:281
lxc_container::want_close_all_fds
bool(* want_close_all_fds)(struct lxc_container *c, bool state)
Change whether the container wishes all file descriptors to be closed on startup. The LISTEN_FDS envi...
Definition lxccontainer.h:234
lxc_container::clear_config
void(* clear_config)(struct lxc_container *c)
Completely clear the containers in-memory configuration.
Definition lxccontainer.h:372
lxc_container::error_string
char * error_string
Definition lxccontainer.h:99
lxc_container::attach_interface
bool(* attach_interface)(struct lxc_container *c, const char *dev, const char *dst_dev)
Add specified netdev to the container.
Definition lxccontainer.h:747
lxc_container::set_config_item
bool(* set_config_item)(struct lxc_container *c, const char *key, const char *value)
Set a key/value configuration option.
Definition lxccontainer.h:270
lxc_container::rename
bool(* rename)(struct lxc_container *c, const char *newname)
Rename a container.
Definition lxccontainer.h:344
lxc_container::remove_device_node
bool(* remove_device_node)(struct lxc_container *c, const char *src_path, const char *dest_path)
Remove specified device from the container.
Definition lxccontainer.h:735
lxc_container::state
const char *(* state)(struct lxc_container *c)
Determine state of container.
Definition lxccontainer.h:128
lxc_container::clear_config_item
bool(* clear_config_item)(struct lxc_container *c, const char *key)
Clear a configuration item.
Definition lxccontainer.h:384
lxc_container::startl
bool(* startl)(struct lxc_container *c, int useinit,...)
Start the container (list variant).
Definition lxccontainer.h:202
lxc_container::set_timeout
bool(* set_timeout)(struct lxc_container *c, int timeout)
Set response receive timeout for LXC commands.
Definition lxccontainer.h:901
lxc_container::umount
int(* umount)(struct lxc_container *c, const char *target, unsigned long mountflags, struct lxc_mount *mnt)
Unmount the container's path target.
Definition lxccontainer.h:847
lxc_container::start
bool(* start)(struct lxc_container *c, int useinit, char *const argv[])
Start the container.
Definition lxccontainer.h:187
lxc_container::reboot2
bool(* reboot2)(struct lxc_container *c, int timeout)
Request the container reboot by sending it SIGINT.
Definition lxccontainer.h:834
lxc_container::console
int(* console)(struct lxc_container *c, int ttynum, int stdinfd, int stdoutfd, int stderrfd, int escape)
Allocate and run a console tty.
Definition lxccontainer.h:596
lxc_container::get_cgroup_item
int(* get_cgroup_item)(struct lxc_container *c, const char *subsys, char *retv, int inlen)
Retrieve the specified cgroup subsystem value for the container.
Definition lxccontainer.h:485
lxc_container::console_getfd
int(* console_getfd)(struct lxc_container *c, int *ttynum, int *ptxfd)
Allocate a console tty for the container.
Definition lxccontainer.h:577
lxc_container::stop
bool(* stop)(struct lxc_container *c)
Stop the container.
Definition lxccontainer.h:211
lxc_container::mount
int(* mount)(struct lxc_container *c, const char *source, const char *target, const char *filesystemtype, unsigned long mountflags, const void *data, struct lxc_mount *mnt)
Mount the host's path source onto the container's path target.
Definition lxccontainer.h:839
lxc_container::config_path
char * config_path
Definition lxccontainer.h:108
lxc_container::get_config_item
int(* get_config_item)(struct lxc_container *c, const char *key, char *retv, int inlen)
Retrieve the value of a config item.
Definition lxccontainer.h:404
lxc_container::may_control
bool(* may_control)(struct lxc_container *c)
Determine if the caller may control the container.
Definition lxccontainer.h:711
lxc_container::snapshot_destroy
bool(* snapshot_destroy)(struct lxc_container *c, const char *snapname)
Destroy the specified snapshot.
Definition lxccontainer.h:700
lxc_container::is_defined
bool(* is_defined)(struct lxc_container *c)
Determine if /var/lib/lxc/$name/config exists.
Definition lxccontainer.h:117
lxc_container::devpts_fd
int(* devpts_fd)(struct lxc_container *c)
Retrieve a mount fd for the container's devpts instance.
Definition lxccontainer.h:884
lxc_container::get_keys
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.
Definition lxccontainer.h:440
lxc_container::attach_run_wait
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.
Definition lxccontainer.h:626
lxc_container::init_pidfd
int(* init_pidfd)(struct lxc_container *c)
Retrieve a pidfd for the container's init process.
Definition lxccontainer.h:875
lxc_container::init_pid
pid_t(* init_pid)(struct lxc_container *c)
Determine process ID of the containers init process.
Definition lxccontainer.h:165
lxc_container::want_daemonize
bool(* want_daemonize)(struct lxc_container *c, bool state)
Change whether the container wants to run disconnected from the terminal.
Definition lxccontainer.h:222
lxc_container::shutdown
bool(* shutdown)(struct lxc_container *c, int timeout)
Request the container shutdown by sending it SIGPWR.
Definition lxccontainer.h:365
lxc_container::seccomp_notify_fd
int(* seccomp_notify_fd)(struct lxc_container *c)
Retrieve a file descriptor for the container's seccomp filter.
Definition lxccontainer.h:857
lxc_container::migrate
int(* migrate)(struct lxc_container *c, unsigned int cmd, struct migrate_opts *opts, unsigned int size)
An API call to perform various migration operations.
Definition lxccontainer.h:813
lxc_container::error_num
int error_num
Definition lxccontainer.h:102
lxc_container::daemonize
bool daemonize
Definition lxccontainer.h:105
lxc_container::is_running
bool(* is_running)(struct lxc_container *c)
Determine if container is running.
Definition lxccontainer.h:137
lxc_container::snapshot
int(* snapshot)(struct lxc_container *c, const char *commentfile)
Create a container snapshot.
Definition lxccontainer.h:657
lxc_container::freeze
bool(* freeze)(struct lxc_container *c)
Freeze running container.
Definition lxccontainer.h:146
lxc_container::snapshot_list
int(* snapshot_list)(struct lxc_container *c, struct lxc_snapshot **snapshots)
Obtain a list of container snapshots.
Definition lxccontainer.h:671
lxc_container::save_config
bool(* save_config)(struct lxc_container *c, const char *alt_file)
Save configuration to a file.
Definition lxccontainer.h:291
lxc_container::detach_interface
bool(* detach_interface)(struct lxc_container *c, const char *dev, const char *dst_dev)
Remove specified netdev from the container.
Definition lxccontainer.h:757
lxc_container::unfreeze
bool(* unfreeze)(struct lxc_container *c)
Thaw a frozen container.
Definition lxccontainer.h:155
lxc_container::restore
bool(* restore)(struct lxc_container *c, char *directory, bool verbose)
Restore a container from a checkpoint.
Definition lxccontainer.h:781
lxc_container::reboot
bool(* reboot)(struct lxc_container *c)
Request the container reboot by sending it SIGINT.
Definition lxccontainer.h:353
lxc_container::snapshot_restore
bool(* snapshot_restore)(struct lxc_container *c, const char *snapname, const char *newname)
Create a new container based on a snapshot.
Definition lxccontainer.h:690
lxc_container::set_config_path
bool(* set_config_path)(struct lxc_container *c, const char *path)
Set the full path to the containers configuration directory.
Definition lxccontainer.h:523
lxc_container::create
bool(* create)(struct lxc_container *c, const char *t, const char *bdevtype, struct bdev_specs *specs, int flags, char *const argv[])
Create a container.
Definition lxccontainer.h:310
lxc_container::destroy_with_snapshots
bool(* destroy_with_snapshots)(struct lxc_container *c)
Delete the container and all its snapshots.
Definition lxccontainer.h:792
lxc_container::set_cgroup_item
bool(* set_cgroup_item)(struct lxc_container *c, const char *subsys, const char *value)
Set the specified cgroup subsystem value for the container.
Definition lxccontainer.h:496
lxc_lock
Definition lxclock.h:37
lxc_log
Definition lxccontainer.h:1133
lxc_mount
Definition lxccontainer.h:39
lxc_snapshot
An LXC container snapshot.
Definition lxccontainer.h:907
lxc_snapshot::free
void(* free)(struct lxc_snapshot *s)
De-allocate the snapshot.
Definition lxccontainer.h:917
lxc_snapshot::name
char * name
Definition lxccontainer.h:908
lxc_snapshot::lxcpath
char * lxcpath
Definition lxccontainer.h:911
lxc_snapshot::timestamp
char * timestamp
Definition lxccontainer.h:910
lxc_snapshot::comment_pathname
char * comment_pathname
Definition lxccontainer.h:909
migrate_opts
Options for the migrate API call.
Definition lxccontainer.h:962