LXC
Loading...
Searching...
No Matches
lxccontainer.h
1/* SPDX-License-Identifier: LGPL-2.1+ */
2
3#ifndef __LXC_CONTAINER_H
4#define __LXC_CONTAINER_H
5
6#include <malloc.h>
7#include <semaphore.h>
8#include <stdbool.h>
9#include <stdint.h>
10#include <stdlib.h>
11
12#include <lxc/attach_options.h>
13
14#ifdef __cplusplus
15extern "C" {
16#endif
17
18#define LXC_CLONE_KEEPNAME (1 << 0)
19#define LXC_CLONE_KEEPMACADDR (1 << 1)
20#define LXC_CLONE_SNAPSHOT (1 << 2)
21#define LXC_CLONE_KEEPBDEVTYPE (1 << 3)
22#define LXC_CLONE_MAYBE_SNAPSHOT (1 << 4)
23#define LXC_CLONE_MAXFLAGS (1 << 5)
24#define LXC_CLONE_ALLOW_RUNNING (1 << 6)
25#define LXC_CREATE_QUIET (1 << 0)
26#define LXC_CREATE_MAXFLAGS (1 << 1)
27#define LXC_MOUNT_API_V1 1
28
29struct bdev_specs;
30
31struct lxc_snapshot;
32
33struct lxc_lock;
34
35struct migrate_opts;
36
37struct lxc_console_log;
38
39struct lxc_mount {
40 int version;
41};
42
51 /* private fields */
56 char *name;
57
62 char *configfile;
63
68 char *pidfile;
69
74 struct lxc_lock *slock;
75
80 struct lxc_lock *privlock;
81
87 int numthreads;
88
95 struct lxc_conf *lxc_conf;
96
97 /* public fields */
100
103
106
109
117 bool (*is_defined)(struct lxc_container *c);
118
128 const char *(*state)(struct lxc_container *c);
129
137 bool (*is_running)(struct lxc_container *c);
138
146 bool (*freeze)(struct lxc_container *c);
147
155 bool (*unfreeze)(struct lxc_container *c);
156
165 pid_t (*init_pid)(struct lxc_container *c);
166
176 bool (*load_config)(struct lxc_container *c, const char *alt_file);
177
187 bool (*start)(struct lxc_container *c, int useinit, char * const argv[]);
188
202 bool (*startl)(struct lxc_container *c, int useinit, ...);
203
211 bool (*stop)(struct lxc_container *c);
212
222 bool (*want_daemonize)(struct lxc_container *c, bool state);
223
234 bool (*want_close_all_fds)(struct lxc_container *c, bool state);
235
245 char *(*config_file_name)(struct lxc_container *c);
246
259 bool (*wait)(struct lxc_container *c, const char *state, int timeout);
260
270 bool (*set_config_item)(struct lxc_container *c, const char *key, const char *value);
271
281 bool (*destroy)(struct lxc_container *c);
282
291 bool (*save_config)(struct lxc_container *c, const char *alt_file);
292
310 bool (*create)(struct lxc_container *c, const char *t, const char *bdevtype,
311 struct bdev_specs *specs, int flags, char *const argv[]);
312
333 bool (*createl)(struct lxc_container *c, const char *t, const char *bdevtype,
334 struct bdev_specs *specs, int flags, ...);
335
344 bool (*rename)(struct lxc_container *c, const char *newname);
345
353 bool (*reboot)(struct lxc_container *c);
354
365 bool (*shutdown)(struct lxc_container *c, int timeout);
366
372 void (*clear_config)(struct lxc_container *c);
373
384 bool (*clear_config_item)(struct lxc_container *c, const char *key);
385
404 int (*get_config_item)(struct lxc_container *c, const char *key, char *retv, int inlen);
405
406
417 char* (*get_running_config_item)(struct lxc_container *c, const char *key);
418
440 int (*get_keys)(struct lxc_container *c, const char *key, char *retv, int inlen);
441
452 char** (*get_interfaces)(struct lxc_container *c);
453
468 char** (*get_ips)(struct lxc_container *c, const char* interface, const char* family, int scope);
469
485 int (*get_cgroup_item)(struct lxc_container *c, const char *subsys, char *retv, int inlen);
486
496 bool (*set_cgroup_item)(struct lxc_container *c, const char *subsys, const char *value);
497
513 const char *(*get_config_path)(struct lxc_container *c);
514
523 bool (*set_config_path)(struct lxc_container *c, const char *path);
524
555 struct lxc_container *(*clone)(struct lxc_container *c, const char *newname,
556 const char *lxcpath, int flags, const char *bdevtype,
557 const char *bdevdata, uint64_t newsize, char **hookargs);
558
577 int (*console_getfd)(struct lxc_container *c, int *ttynum, int *ptxfd);
578
596 int (*console)(struct lxc_container *c, int ttynum,
597 int stdinfd, int stdoutfd, int stderrfd, int escape);
598
612 int (*attach)(struct lxc_container *c, lxc_attach_exec_t exec_function,
613 void *exec_payload, lxc_attach_options_t *options, pid_t *attached_process);
614
626 int (*attach_run_wait)(struct lxc_container *c, lxc_attach_options_t *options, const char *program, const char * const argv[]);
627
639 int (*attach_run_waitl)(struct lxc_container *c, lxc_attach_options_t *options, const char *program, const char *arg, ...);
640
657 int (*snapshot)(struct lxc_container *c, const char *commentfile);
658
671 int (*snapshot_list)(struct lxc_container *c, struct lxc_snapshot **snapshots);
672
690 bool (*snapshot_restore)(struct lxc_container *c, const char *snapname, const char *newname);
691
700 bool (*snapshot_destroy)(struct lxc_container *c, const char *snapname);
701
711 bool (*may_control)(struct lxc_container *c);
712
723 bool (*add_device_node)(struct lxc_container *c, const char *src_path, const char *dest_path);
724
735 bool (*remove_device_node)(struct lxc_container *c, const char *src_path, const char *dest_path);
736
737 /* Post LXC-1.0 additions */
738
747 bool (*attach_interface)(struct lxc_container *c, const char *dev, const char *dst_dev);
748
757 bool (*detach_interface)(struct lxc_container *c, const char *dev, const char *dst_dev);
769 bool (*checkpoint)(struct lxc_container *c, char *directory, bool stop, bool verbose);
770
781 bool (*restore)(struct lxc_container *c, char *directory, bool verbose);
782
793
802
803 /* Post LXC-1.1 additions */
813 int (*migrate)(struct lxc_container *c, unsigned int cmd, struct migrate_opts *opts, unsigned int size);
814
823 int (*console_log)(struct lxc_container *c, struct lxc_console_log *log);
824
834 bool (*reboot2)(struct lxc_container *c, int timeout);
835
839 int (*mount)(struct lxc_container *c, const char *source,
840 const char *target, const char *filesystemtype,
841 unsigned long mountflags, const void *data,
842 struct lxc_mount *mnt);
843
847 int (*umount)(struct lxc_container *c, const char *target,
848 unsigned long mountflags, struct lxc_mount *mnt);
849
858
867
875 int (*init_pidfd)(struct lxc_container *c);
876
884 int (*devpts_fd)(struct lxc_container *c);
885
890 int rcv_timeout;
891
901 bool (*set_timeout)(struct lxc_container *c, int timeout);
902};
903
908 char *name;
910 char *timestamp;
911 char *lxcpath;
917 void (*free)(struct lxc_snapshot *s);
918};
919
920
925 char *fstype;
926 uint64_t fssize;
927 struct {
928 char *zfsroot;
929 } zfs;
930 struct {
931 char *vg;
932 char *lv;
933 char *thinpool;
934 } lvm;
935 char *dir;
936 struct {
937 char *rbdname;
938 char *rbdpool;
939 } rbd;
940};
941
945enum {
946 MIGRATE_PRE_DUMP,
947 MIGRATE_DUMP,
948 MIGRATE_RESTORE,
949 MIGRATE_FEATURE_CHECK,
950};
951
955#define FEATURE_MEM_TRACK (1ULL << 0)
956#define FEATURE_LAZY_PAGES (1ULL << 1)
957
962 /* new members should be added at the end */
963 char *directory;
964 bool verbose;
965
966 bool stop; /* stop the container after dump? */
967 char *predump_dir; /* relative to directory above */
968 char *pageserver_address; /* where should memory pages be send? */
969 char *pageserver_port;
970
971 /* This flag indicates whether or not the container's rootfs will have
972 * the same inodes on checkpoint and restore. In the case of e.g. zfs
973 * send or btrfs send, or an LVM snapshot, this will be true, but it
974 * won't if e.g. you rsync the filesystems between two machines.
975 */
976 bool preserves_inodes;
977
978 /* Path to an executable script that will be registered as a criu
979 * "action script"
980 */
981 char *action_script;
982
983 /* If CRIU >= 2.4 is detected the option to skip in-flight connections
984 * will be enabled by default. The flag 'disable_skip_in_flight' will
985 * unconditionally disable this feature. In-flight connections are
986 * not fully established TCP connections: SYN, SYN-ACK */
987 bool disable_skip_in_flight;
988
989 /* This is the maximum file size for deleted files (which CRIU calls
990 * "ghost" files) that will be handled. 0 indicates the CRIU default,
991 * which at this time is 1MB.
992 */
993 uint64_t ghost_limit;
994
995 /* Some features cannot be checked by comparing the CRIU version.
996 * Features like dirty page tracking or userfaultfd depend on
997 * the architecture/kernel/criu combination. This is a bitmask
998 * in which the desired feature checks can be encoded.
999 */
1000 uint64_t features_to_check;
1001};
1002
1004 /* Clear the console log. */
1005 bool clear;
1006
1007 /* Retrieve the console log. */
1008 bool read;
1009
1010 /* This specifies the maximum size to read from the ringbuffer. Setting
1011 * it to 0 means that the a read can be as big as the whole ringbuffer.
1012 * On return callers can check how many bytes were actually read.
1013 * If "read" and "clear" are set to false and a non-zero value is
1014 * specified then up to "read_max" bytes of data will be discarded from
1015 * the ringbuffer.
1016 */
1017 uint64_t *read_max;
1018
1019 /* Data that was read from the ringbuffer. If "read_max" is 0 on return
1020 * "data" is invalid.
1021 */
1022 char *data;
1023};
1024
1033struct lxc_container *lxc_container_new(const char *name, const char *configpath);
1034
1042int lxc_container_get(struct lxc_container *c);
1043
1054int lxc_container_put(struct lxc_container *c);
1055
1068int lxc_get_wait_states(const char **states);
1069
1077const char *lxc_get_global_config_item(const char *key);
1078
1085const char *lxc_get_version(void);
1086
1098int list_defined_containers(const char *lxcpath, char ***names, struct lxc_container ***cret);
1099
1114int list_active_containers(const char *lxcpath, char ***names, struct lxc_container ***cret);
1115
1130int list_all_containers(const char *lxcpath, char ***names, struct lxc_container ***cret);
1131
1132struct lxc_log {
1133 const char *name;
1134 const char *lxcpath;
1135 const char *file;
1136 const char *level;
1137 const char *prefix;
1138 bool quiet;
1139};
1140
1146int lxc_log_init(struct lxc_log *log);
1147
1151void lxc_log_close(void);
1152
1158bool lxc_config_item_is_supported(const char *key);
1159
1165bool lxc_has_api_extension(const char *extension);
1166
1167#ifdef __cplusplus
1168}
1169#endif
1170
1171#endif
Specifications for how to create a new backing store.
Definition lxccontainer.h:924
char * zfsroot
Definition lxccontainer.h:928
char * vg
Definition lxccontainer.h:931
char * fstype
Definition lxccontainer.h:925
char * dir
Definition lxccontainer.h:935
char * lv
Definition lxccontainer.h:932
char * rbdname
Definition lxccontainer.h:937
uint64_t fssize
Definition lxccontainer.h:926
char * rbdpool
Definition lxccontainer.h:938
char * thinpool
Definition lxccontainer.h:933
Definition attach_options.h:90
Definition lxccontainer.h:1003
Definition lxccontainer.h:50
int(* seccomp_notify_fd_active)(struct lxc_container *c)
Retrieve a file descriptor for the running container's seccomp filter.
Definition lxccontainer.h:866
bool(* checkpoint)(struct lxc_container *c, char *directory, bool stop, bool verbose)
Checkpoint a container.
Definition lxccontainer.h:769
bool(* wait)(struct lxc_container *c, const char *state, int timeout)
Wait for container to reach a particular state.
Definition lxccontainer.h:259
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
bool(* load_config)(struct lxc_container *c, const char *alt_file)
Load the specified configuration for the container.
Definition lxccontainer.h:176
bool(* snapshot_destroy_all)(struct lxc_container *c)
Destroy all the container's snapshot.
Definition lxccontainer.h:801
int(* console_log)(struct lxc_container *c, struct lxc_console_log *log)
Query the console log of a container.
Definition lxccontainer.h:823
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
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
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
bool(* destroy)(struct lxc_container *c)
Delete the container.
Definition lxccontainer.h:281
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
void(* clear_config)(struct lxc_container *c)
Completely clear the containers in-memory configuration.
Definition lxccontainer.h:372
char * error_string
Definition lxccontainer.h:99
bool(* attach_interface)(struct lxc_container *c, const char *dev, const char *dst_dev)
Add specified netdev to the container.
Definition lxccontainer.h:747
bool(* set_config_item)(struct lxc_container *c, const char *key, const char *value)
Set a key/value configuration option.
Definition lxccontainer.h:270
bool(* rename)(struct lxc_container *c, const char *newname)
Rename a container.
Definition lxccontainer.h:344
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
const char *(* state)(struct lxc_container *c)
Determine state of container.
Definition lxccontainer.h:128
bool(* clear_config_item)(struct lxc_container *c, const char *key)
Clear a configuration item.
Definition lxccontainer.h:384
bool(* startl)(struct lxc_container *c, int useinit,...)
Start the container (list variant).
Definition lxccontainer.h:202
bool(* set_timeout)(struct lxc_container *c, int timeout)
Set response receive timeout for LXC commands.
Definition lxccontainer.h:901
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
bool(* start)(struct lxc_container *c, int useinit, char *const argv[])
Start the container.
Definition lxccontainer.h:187
bool(* reboot2)(struct lxc_container *c, int timeout)
Request the container reboot by sending it SIGINT.
Definition lxccontainer.h:834
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
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
int(* console_getfd)(struct lxc_container *c, int *ttynum, int *ptxfd)
Allocate a console tty for the container.
Definition lxccontainer.h:577
bool(* stop)(struct lxc_container *c)
Stop the container.
Definition lxccontainer.h:211
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
char * config_path
Definition lxccontainer.h:108
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
bool(* may_control)(struct lxc_container *c)
Determine if the caller may control the container.
Definition lxccontainer.h:711
bool(* snapshot_destroy)(struct lxc_container *c, const char *snapname)
Destroy the specified snapshot.
Definition lxccontainer.h:700
bool(* is_defined)(struct lxc_container *c)
Determine if /var/lib/lxc/$name/config exists.
Definition lxccontainer.h:117
int(* devpts_fd)(struct lxc_container *c)
Retrieve a mount fd for the container's devpts instance.
Definition lxccontainer.h:884
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
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
int(* init_pidfd)(struct lxc_container *c)
Retrieve a pidfd for the container's init process.
Definition lxccontainer.h:875
pid_t(* init_pid)(struct lxc_container *c)
Determine process ID of the containers init process.
Definition lxccontainer.h:165
bool(* want_daemonize)(struct lxc_container *c, bool state)
Change whether the container wants to run disconnected from the terminal.
Definition lxccontainer.h:222
bool(* shutdown)(struct lxc_container *c, int timeout)
Request the container shutdown by sending it SIGPWR.
Definition lxccontainer.h:365
int(* seccomp_notify_fd)(struct lxc_container *c)
Retrieve a file descriptor for the container's seccomp filter.
Definition lxccontainer.h:857
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
int error_num
Definition lxccontainer.h:102
bool daemonize
Definition lxccontainer.h:105
bool(* is_running)(struct lxc_container *c)
Determine if container is running.
Definition lxccontainer.h:137
int(* snapshot)(struct lxc_container *c, const char *commentfile)
Create a container snapshot.
Definition lxccontainer.h:657
bool(* freeze)(struct lxc_container *c)
Freeze running container.
Definition lxccontainer.h:146
int(* snapshot_list)(struct lxc_container *c, struct lxc_snapshot **snapshots)
Obtain a list of container snapshots.
Definition lxccontainer.h:671
bool(* save_config)(struct lxc_container *c, const char *alt_file)
Save configuration to a file.
Definition lxccontainer.h:291
bool(* detach_interface)(struct lxc_container *c, const char *dev, const char *dst_dev)
Remove specified netdev from the container.
Definition lxccontainer.h:757
bool(* unfreeze)(struct lxc_container *c)
Thaw a frozen container.
Definition lxccontainer.h:155
bool(* restore)(struct lxc_container *c, char *directory, bool verbose)
Restore a container from a checkpoint.
Definition lxccontainer.h:781
bool(* reboot)(struct lxc_container *c)
Request the container reboot by sending it SIGINT.
Definition lxccontainer.h:353
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
bool(* set_config_path)(struct lxc_container *c, const char *path)
Set the full path to the containers configuration directory.
Definition lxccontainer.h:523
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
bool(* destroy_with_snapshots)(struct lxc_container *c)
Delete the container and all its snapshots.
Definition lxccontainer.h:792
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
Definition lxclock.h:37
Definition lxccontainer.h:1132
Definition lxccontainer.h:39
An LXC container snapshot.
Definition lxccontainer.h:907
void(* free)(struct lxc_snapshot *s)
De-allocate the snapshot.
Definition lxccontainer.h:917
char * name
Definition lxccontainer.h:908
char * lxcpath
Definition lxccontainer.h:911
char * timestamp
Definition lxccontainer.h:910
char * comment_pathname
Definition lxccontainer.h:909
Options for the migrate API call.
Definition lxccontainer.h:961