LXC
lxccontainer.h
Go to the documentation of this file.
1 
23 #ifndef __LXC_CONTAINER_H
24 #define __LXC_CONTAINER_H
25 #include <malloc.h>
26 #include <semaphore.h>
27 #include <stdbool.h>
28 #include <stdlib.h>
29 #include <stdint.h>
30 
31 #include <lxc/attach_options.h>
32 
33 #ifdef __cplusplus
34 extern "C" {
35 #endif
36 
37 #define LXC_CLONE_KEEPNAME (1 << 0)
38 #define LXC_CLONE_KEEPMACADDR (1 << 1)
39 #define LXC_CLONE_SNAPSHOT (1 << 2)
40 #define LXC_CLONE_KEEPBDEVTYPE (1 << 3)
41 #define LXC_CLONE_MAYBE_SNAPSHOT (1 << 4)
42 #define LXC_CLONE_MAXFLAGS (1 << 5)
43 #define LXC_CREATE_QUIET (1 << 0)
44 #define LXC_CREATE_MAXFLAGS (1 << 1)
45 #define LXC_MOUNT_API_V1 1
46 
47 struct bdev_specs;
48 
49 struct lxc_snapshot;
50 
51 struct lxc_lock;
52 
53 struct migrate_opts;
54 
55 struct lxc_console_log;
56 
57 struct lxc_mount {
58  int version;
59 };
60 
68 struct lxc_container {
69  /* private fields */
74  char *name;
75 
80  char *configfile;
81 
86  char *pidfile;
87 
92  struct lxc_lock *slock;
93 
98  struct lxc_lock *privlock;
99 
105  int numthreads;
106 
113  struct lxc_conf *lxc_conf;
114 
115  /* public fields */
118 
121 
123  bool daemonize;
124 
126  char *config_path;
127 
135  bool (*is_defined)(struct lxc_container *c);
136 
146  const char *(*state)(struct lxc_container *c);
147 
155  bool (*is_running)(struct lxc_container *c);
156 
164  bool (*freeze)(struct lxc_container *c);
165 
173  bool (*unfreeze)(struct lxc_container *c);
174 
183  pid_t (*init_pid)(struct lxc_container *c);
184 
194  bool (*load_config)(struct lxc_container *c, const char *alt_file);
195 
205  bool (*start)(struct lxc_container *c, int useinit, char * const argv[]);
206 
220  bool (*startl)(struct lxc_container *c, int useinit, ...);
221 
229  bool (*stop)(struct lxc_container *c);
230 
240  bool (*want_daemonize)(struct lxc_container *c, bool state);
241 
251  bool (*want_close_all_fds)(struct lxc_container *c, bool state);
252 
262  char *(*config_file_name)(struct lxc_container *c);
263 
276  bool (*wait)(struct lxc_container *c, const char *state, int timeout);
277 
287  bool (*set_config_item)(struct lxc_container *c, const char *key, const char *value);
288 
298  bool (*destroy)(struct lxc_container *c);
299 
308  bool (*save_config)(struct lxc_container *c, const char *alt_file);
309 
327  bool (*create)(struct lxc_container *c, const char *t, const char *bdevtype,
328  struct bdev_specs *specs, int flags, char *const argv[]);
329 
350  bool (*createl)(struct lxc_container *c, const char *t, const char *bdevtype,
351  struct bdev_specs *specs, int flags, ...);
352 
361  bool (*rename)(struct lxc_container *c, const char *newname);
362 
370  bool (*reboot)(struct lxc_container *c);
371 
382  bool (*shutdown)(struct lxc_container *c, int timeout);
383 
389  void (*clear_config)(struct lxc_container *c);
390 
401  bool (*clear_config_item)(struct lxc_container *c, const char *key);
402 
421  int (*get_config_item)(struct lxc_container *c, const char *key, char *retv, int inlen);
422 
423 
434  char* (*get_running_config_item)(struct lxc_container *c, const char *key);
435 
457  int (*get_keys)(struct lxc_container *c, const char *key, char *retv, int inlen);
458 
469  char** (*get_interfaces)(struct lxc_container *c);
470 
485  char** (*get_ips)(struct lxc_container *c, const char* interface, const char* family, int scope);
486 
502  int (*get_cgroup_item)(struct lxc_container *c, const char *subsys, char *retv, int inlen);
503 
513  bool (*set_cgroup_item)(struct lxc_container *c, const char *subsys, const char *value);
514 
531  const char *(*get_config_path)(struct lxc_container *c);
532 
542  bool (*set_config_path)(struct lxc_container *c, const char *path);
543 
574  struct lxc_container *(*clone)(struct lxc_container *c, const char *newname,
575  const char *lxcpath, int flags, const char *bdevtype,
576  const char *bdevdata, uint64_t newsize, char **hookargs);
577 
596  int (*console_getfd)(struct lxc_container *c, int *ttynum, int *masterfd);
597 
615  int (*console)(struct lxc_container *c, int ttynum,
616  int stdinfd, int stdoutfd, int stderrfd, int escape);
617 
631  int (*attach)(struct lxc_container *c, lxc_attach_exec_t exec_function,
632  void *exec_payload, lxc_attach_options_t *options, pid_t *attached_process);
633 
645  int (*attach_run_wait)(struct lxc_container *c, lxc_attach_options_t *options, const char *program, const char * const argv[]);
646 
658  int (*attach_run_waitl)(struct lxc_container *c, lxc_attach_options_t *options, const char *program, const char *arg, ...);
659 
676  int (*snapshot)(struct lxc_container *c, const char *commentfile);
677 
690  int (*snapshot_list)(struct lxc_container *c, struct lxc_snapshot **snapshots);
691 
709  bool (*snapshot_restore)(struct lxc_container *c, const char *snapname, const char *newname);
710 
719  bool (*snapshot_destroy)(struct lxc_container *c, const char *snapname);
720 
730  bool (*may_control)(struct lxc_container *c);
731 
742  bool (*add_device_node)(struct lxc_container *c, const char *src_path, const char *dest_path);
743 
754  bool (*remove_device_node)(struct lxc_container *c, const char *src_path, const char *dest_path);
755 
756  /* Post LXC-1.0 additions */
757 
766  bool (*attach_interface)(struct lxc_container *c, const char *dev, const char *dst_dev);
767 
776  bool (*detach_interface)(struct lxc_container *c, const char *dev, const char *dst_dev);
788  bool (*checkpoint)(struct lxc_container *c, char *directory, bool stop, bool verbose);
789 
800  bool (*restore)(struct lxc_container *c, char *directory, bool verbose);
801 
812 
821 
822  /* Post LXC-1.1 additions */
832  int (*migrate)(struct lxc_container *c, unsigned int cmd, struct migrate_opts *opts, unsigned int size);
833 
842  int (*console_log)(struct lxc_container *c, struct lxc_console_log *log);
843 
853  bool (*reboot2)(struct lxc_container *c, int timeout);
854 
858  int (*mount)(struct lxc_container *c, const char *source,
859  const char *target, const char *filesystemtype,
860  unsigned long mountflags, const void *data,
861  struct lxc_mount *mnt);
862 
866  int (*umount)(struct lxc_container *c, const char *target,
867  unsigned long mountflags, struct lxc_mount *mnt);
868 };
869 
873 struct lxc_snapshot {
874  char *name;
876  char *timestamp;
877  char *lxcpath;
883  void (*free)(struct lxc_snapshot *s);
884 };
885 
886 
890 struct bdev_specs {
891  char *fstype;
892  uint64_t fssize;
893  struct {
894  char *zfsroot;
895  } zfs;
896  struct {
897  char *vg;
898  char *lv;
899  char *thinpool;
900  } lvm;
901  char *dir;
902  struct {
903  char *rbdname;
904  char *rbdpool;
905  } rbd;
906 };
907 
911 enum {
912  MIGRATE_PRE_DUMP,
913  MIGRATE_DUMP,
914  MIGRATE_RESTORE,
915  MIGRATE_FEATURE_CHECK,
916 };
917 
921 #define FEATURE_MEM_TRACK (1ULL << 0)
922 #define FEATURE_LAZY_PAGES (1ULL << 1)
923 
927 struct migrate_opts {
928  /* new members should be added at the end */
929  char *directory;
930  bool verbose;
931 
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;
936 
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.
941  */
942  bool preserves_inodes;
943 
944  /* Path to an executable script that will be registered as a criu
945  * "action script"
946  */
947  char *action_script;
948 
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;
954 
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.
958  */
959  uint64_t ghost_limit;
960 
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.
965  */
966  uint64_t features_to_check;
967 };
968 
970  /* Clear the console log. */
971  bool clear;
972 
973  /* Retrieve the console log. */
974  bool read;
975 
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
981  * the ringbuffer.
982  */
983  uint64_t *read_max;
984 
985  /* Data that was read from the ringbuffer. If "read_max" is 0 on return
986  * "data" is invalid.
987  */
988  char *data;
989 };
990 
999 struct lxc_container *lxc_container_new(const char *name, const char *configpath);
1000 
1008 int lxc_container_get(struct lxc_container *c);
1009 
1020 int lxc_container_put(struct lxc_container *c);
1021 
1034 int lxc_get_wait_states(const char **states);
1035 
1043 const char *lxc_get_global_config_item(const char *key);
1044 
1051 const char *lxc_get_version(void);
1052 
1064 int list_defined_containers(const char *lxcpath, char ***names, struct lxc_container ***cret);
1065 
1080 int list_active_containers(const char *lxcpath, char ***names, struct lxc_container ***cret);
1081 
1096 int list_all_containers(const char *lxcpath, char ***names, struct lxc_container ***cret);
1097 
1098 struct lxc_log {
1099  const char *name;
1100  const char *lxcpath;
1101  const char *file;
1102  const char *level;
1103  const char *prefix;
1104  bool quiet;
1105 };
1106 
1112 int lxc_log_init(struct lxc_log *log);
1113 
1117 void lxc_log_close(void);
1118 
1124 bool lxc_config_item_is_supported(const char *key);
1125 
1126 #ifdef __cplusplus
1127 }
1128 #endif
1129 
1130 #endif
bool(* start)(struct lxc_container *c, int useinit, char *const argv[])
Start the container.
Definition: lxccontainer.h:205
Definition: lxccontainer.h:68
bool daemonize
Definition: lxccontainer.h:123
int lxc_log_init(struct lxc_log *log)
Initialize the log.
bool(* unfreeze)(struct lxc_container *c)
Thaw a frozen container.
Definition: lxccontainer.h:173
int(* console_getfd)(struct lxc_container *c, int *ttynum, int *masterfd)
Allocate a console tty for the container.
Definition: lxccontainer.h:596
bool(* attach_interface)(struct lxc_container *c, const char *dev, const char *dst_dev)
Add specified netdev to the container.
Definition: lxccontainer.h:766
int lxc_get_wait_states(const char **states)
Obtain a list of all container states.
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:502
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:754
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:615
bool(* snapshot_destroy_all)(struct lxc_container *c)
Destroy all the container&#39;s snapshot.
Definition: lxccontainer.h:820
char * error_string
Definition: lxccontainer.h:117
pid_t(* init_pid)(struct lxc_container *c)
Determine process ID of the containers init process.
Definition: lxccontainer.h:183
const char * lxc_get_global_config_item(const char *key)
Get the value for a global config key.
bool(* destroy_with_snapshots)(struct lxc_container *c)
Delete the container and all its snapshots.
Definition: lxccontainer.h:811
char * vg
Definition: lxccontainer.h:897
bool(* detach_interface)(struct lxc_container *c, const char *dev, const char *dst_dev)
Remove specified netdev from the container.
Definition: lxccontainer.h:776
Specifications for how to create a new backing store.
Definition: lxccontainer.h:890
bool(* shutdown)(struct lxc_container *c, int timeout)
Request the container shutdown by sending it SIGPWR.
Definition: lxccontainer.h:382
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:421
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:327
bool(* clear_config_item)(struct lxc_container *c, const char *key)
Clear a configuration item.
Definition: lxccontainer.h:401
uint64_t fssize
Definition: lxccontainer.h:892
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:742
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:832
char * zfsroot
Definition: lxccontainer.h:894
char * timestamp
Definition: lxccontainer.h:876
bool lxc_config_item_is_supported(const char *key)
Check if the configuration item is supported by this LXC instance.
bool(* checkpoint)(struct lxc_container *c, char *directory, bool stop, bool verbose)
Checkpoint a container.
Definition: lxccontainer.h:788
int list_defined_containers(const char *lxcpath, char ***names, struct lxc_container ***cret)
Get a list of defined containers in a lxcpath.
char * name
Definition: lxccontainer.h:874
int lxc_container_put(struct lxc_container *c)
Drop a reference to the specified container.
void lxc_log_close(void)
Close log file.
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:658
int error_num
Definition: lxccontainer.h:120
void(* clear_config)(struct lxc_container *c)
Completely clear the containers in-memory configuration.
Definition: lxccontainer.h:389
bool(* restore)(struct lxc_container *c, char *directory, bool verbose)
Restore a container from a checkpoint.
Definition: lxccontainer.h:800
char * rbdpool
Definition: lxccontainer.h:904
char * thinpool
Definition: lxccontainer.h:899
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&#39;s path source onto the container&#39;s path target.
Definition: lxccontainer.h:858
bool(* reboot)(struct lxc_container *c)
Request the container reboot by sending it SIGINT.
Definition: lxccontainer.h:370
An LXC container snapshot.
Definition: lxccontainer.h:873
bool(* may_control)(struct lxc_container *c)
Determine if the caller may control the container.
Definition: lxccontainer.h:730
char * lxcpath
Definition: lxccontainer.h:877
int(* lxc_attach_exec_t)(void *payload)
Definition: attach_options.h:74
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:645
char * rbdname
Definition: lxccontainer.h:903
bool(* wait)(struct lxc_container *c, const char *state, int timeout)
Wait for container to reach a particular state.
Definition: lxccontainer.h:276
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:631
Definition: lxccontainer.h:57
bool(* load_config)(struct lxc_container *c, const char *alt_file)
Load the specified configuration for the container.
Definition: lxccontainer.h:194
int lxc_container_get(struct lxc_container *c)
Add a reference to the specified container.
bool(* snapshot_destroy)(struct lxc_container *c, const char *snapname)
Destroy the specified snapshot.
Definition: lxccontainer.h:719
int list_all_containers(const char *lxcpath, char ***names, struct lxc_container ***cret)
Get a complete list of all containers for a given lxcpath.
bool(* want_close_all_fds)(struct lxc_container *c, bool state)
Change whether the container wishes all file descriptors to be closed on startup. ...
Definition: lxccontainer.h:251
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:513
bool(* set_config_path)(struct lxc_container *c, const char *path)
Set the full path to the containers configuration file.
Definition: lxccontainer.h:542
Definition: lxccontainer.h:1098
bool(* stop)(struct lxc_container *c)
Stop the container.
Definition: lxccontainer.h:229
bool(* is_running)(struct lxc_container *c)
Determine if container is running.
Definition: lxccontainer.h:155
bool(* set_config_item)(struct lxc_container *c, const char *key, const char *value)
Set a key/value configuration option.
Definition: lxccontainer.h:287
char * lv
Definition: lxccontainer.h:898
struct lxc_container * lxc_container_new(const char *name, const char *configpath)
Create a new container.
Definition: lxclock.h:53
Definition: attach_options.h:79
bool(* freeze)(struct lxc_container *c)
Freeze running container.
Definition: lxccontainer.h:164
const char *(* state)(struct lxc_container *c)
Determine state of 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:690
int list_active_containers(const char *lxcpath, char ***names, struct lxc_container ***cret)
Get a list of active containers for a given lxcpath.
char * fstype
Definition: lxccontainer.h:891
char * comment_pathname
Definition: lxccontainer.h:875
const char * lxc_get_version(void)
Determine version of LXC.
Definition: lxccontainer.h:969
bool(* startl)(struct lxc_container *c, int useinit,...)
Start the container (list variant).
Definition: lxccontainer.h:220
char * config_path
Definition: lxccontainer.h:126
bool(* save_config)(struct lxc_container *c, const char *alt_file)
Save configuaration to a file.
Definition: lxccontainer.h:308
bool(* destroy)(struct lxc_container *c)
Delete the container.
Definition: lxccontainer.h:298
Options for the migrate API call.
Definition: lxccontainer.h:927
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:457
bool(* want_daemonize)(struct lxc_container *c, bool state)
Change whether the container wants to run disconnected from the terminal.
Definition: lxccontainer.h:240
char * dir
Definition: lxccontainer.h:901
int(* snapshot)(struct lxc_container *c, const char *commentfile)
Create a container snapshot.
Definition: lxccontainer.h:676