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)
46 struct bdev_specs;
47 
48 struct lxc_snapshot;
49 
50 struct lxc_lock;
51 
52 struct migrate_opts;
53 
61 struct lxc_container {
62  // private fields
67  char *name;
68 
73  char *configfile;
74 
79  char *pidfile;
80 
85  struct lxc_lock *slock;
86 
91  struct lxc_lock *privlock;
92 
98  int numthreads;
99 
106  struct lxc_conf *lxc_conf;
107 
108  // public fields
111 
114 
116  bool daemonize;
117 
119  char *config_path;
120 
128  bool (*is_defined)(struct lxc_container *c);
129 
139  const char *(*state)(struct lxc_container *c);
140 
148  bool (*is_running)(struct lxc_container *c);
149 
157  bool (*freeze)(struct lxc_container *c);
158 
166  bool (*unfreeze)(struct lxc_container *c);
167 
176  pid_t (*init_pid)(struct lxc_container *c);
177 
187  bool (*load_config)(struct lxc_container *c, const char *alt_file);
188 
198  bool (*start)(struct lxc_container *c, int useinit, char * const argv[]);
199 
213  bool (*startl)(struct lxc_container *c, int useinit, ...);
214 
222  bool (*stop)(struct lxc_container *c);
223 
233  bool (*want_daemonize)(struct lxc_container *c, bool state);
234 
244  bool (*want_close_all_fds)(struct lxc_container *c, bool state);
245 
255  char *(*config_file_name)(struct lxc_container *c);
256 
269  bool (*wait)(struct lxc_container *c, const char *state, int timeout);
270 
280  bool (*set_config_item)(struct lxc_container *c, const char *key, const char *value);
281 
291  bool (*destroy)(struct lxc_container *c);
292 
301  bool (*save_config)(struct lxc_container *c, const char *alt_file);
302 
320  bool (*create)(struct lxc_container *c, const char *t, const char *bdevtype,
321  struct bdev_specs *specs, int flags, char *const argv[]);
322 
343  bool (*createl)(struct lxc_container *c, const char *t, const char *bdevtype,
344  struct bdev_specs *specs, int flags, ...);
345 
354  bool (*rename)(struct lxc_container *c, const char *newname);
355 
363  bool (*reboot)(struct lxc_container *c);
364 
375  bool (*shutdown)(struct lxc_container *c, int timeout);
376 
382  void (*clear_config)(struct lxc_container *c);
383 
394  bool (*clear_config_item)(struct lxc_container *c, const char *key);
395 
414  int (*get_config_item)(struct lxc_container *c, const char *key, char *retv, int inlen);
415 
416 
427  char* (*get_running_config_item)(struct lxc_container *c, const char *key);
428 
450  int (*get_keys)(struct lxc_container *c, const char *key, char *retv, int inlen);
451 
462  char** (*get_interfaces)(struct lxc_container *c);
463 
478  char** (*get_ips)(struct lxc_container *c, const char* interface, const char* family, int scope);
479 
495  int (*get_cgroup_item)(struct lxc_container *c, const char *subsys, char *retv, int inlen);
496 
506  bool (*set_cgroup_item)(struct lxc_container *c, const char *subsys, const char *value);
507 
524  const char *(*get_config_path)(struct lxc_container *c);
525 
535  bool (*set_config_path)(struct lxc_container *c, const char *path);
536 
567  struct lxc_container *(*clone)(struct lxc_container *c, const char *newname,
568  const char *lxcpath, int flags, const char *bdevtype,
569  const char *bdevdata, uint64_t newsize, char **hookargs);
570 
589  int (*console_getfd)(struct lxc_container *c, int *ttynum, int *masterfd);
590 
608  int (*console)(struct lxc_container *c, int ttynum,
609  int stdinfd, int stdoutfd, int stderrfd, int escape);
610 
624  int (*attach)(struct lxc_container *c, lxc_attach_exec_t exec_function,
625  void *exec_payload, lxc_attach_options_t *options, pid_t *attached_process);
626 
638  int (*attach_run_wait)(struct lxc_container *c, lxc_attach_options_t *options, const char *program, const char * const argv[]);
639 
651  int (*attach_run_waitl)(struct lxc_container *c, lxc_attach_options_t *options, const char *program, const char *arg, ...);
652 
669  int (*snapshot)(struct lxc_container *c, const char *commentfile);
670 
683  int (*snapshot_list)(struct lxc_container *c, struct lxc_snapshot **snapshots);
684 
702  bool (*snapshot_restore)(struct lxc_container *c, const char *snapname, const char *newname);
703 
712  bool (*snapshot_destroy)(struct lxc_container *c, const char *snapname);
713 
723  bool (*may_control)(struct lxc_container *c);
724 
735  bool (*add_device_node)(struct lxc_container *c, const char *src_path, const char *dest_path);
736 
747  bool (*remove_device_node)(struct lxc_container *c, const char *src_path, const char *dest_path);
748 
749  /* Post LXC-1.0 additions */
750 
759  bool (*attach_interface)(struct lxc_container *c, const char *dev, const char *dst_dev);
760 
769  bool (*detach_interface)(struct lxc_container *c, const char *dev, const char *dst_dev);
781  bool (*checkpoint)(struct lxc_container *c, char *directory, bool stop, bool verbose);
782 
793  bool (*restore)(struct lxc_container *c, char *directory, bool verbose);
794 
805 
814 
815  /* Post LXC-1.1 additions */
825  int (*migrate)(struct lxc_container *c, unsigned int cmd, struct migrate_opts *opts, unsigned int size);
826 };
827 
831 struct lxc_snapshot {
832  char *name;
834  char *timestamp;
835  char *lxcpath;
841  void (*free)(struct lxc_snapshot *s);
842 };
843 
844 
848 struct bdev_specs {
849  char *fstype;
850  uint64_t fssize;
851  struct {
852  char *zfsroot;
853  } zfs;
854  struct {
855  char *vg;
856  char *lv;
857  char *thinpool;
858  } lvm;
859  char *dir;
860  struct {
861  char *rbdname;
862  char *rbdpool;
863  } rbd;
864 };
865 
869 enum {
870  MIGRATE_PRE_DUMP,
871  MIGRATE_DUMP,
872  MIGRATE_RESTORE,
873 };
874 
878 struct migrate_opts {
879  /* new members should be added at the end */
880  char *directory;
881  bool verbose;
882 
883  bool stop; /* stop the container after dump? */
884  char *predump_dir; /* relative to directory above */
885  char *pageserver_address; /* where should memory pages be send? */
886  char *pageserver_port;
887 
888  /* This flag indicates whether or not the container's rootfs will have
889  * the same inodes on checkpoint and restore. In the case of e.g. zfs
890  * send or btrfs send, or an LVM snapshot, this will be true, but it
891  * won't if e.g. you rsync the filesystems between two machines.
892  */
893  bool preserves_inodes;
894 
895  /* Path to an executable script that will be registered as a criu
896  * "action script"
897  */
898  char *action_script;
899 
900  /* If CRIU >= 2.4 is detected the option to skip in-flight connections
901  * will be enabled by default. The flag 'disable_skip_in_flight' will
902  * unconditionally disable this feature. In-flight connections are
903  * not fully established TCP connections: SYN, SYN-ACK */
904  bool disable_skip_in_flight;
905 
906  /* This is the maximum file size for deleted files (which CRIU calls
907  * "ghost" files) that will be handled. 0 indicates the CRIU default,
908  * which at this time is 1MB.
909  */
910  uint64_t ghost_limit;
911 };
912 
921 struct lxc_container *lxc_container_new(const char *name, const char *configpath);
922 
930 int lxc_container_get(struct lxc_container *c);
931 
942 int lxc_container_put(struct lxc_container *c);
943 
956 int lxc_get_wait_states(const char **states);
957 
965 const char *lxc_get_global_config_item(const char *key);
966 
973 const char *lxc_get_version(void);
974 
986 int list_defined_containers(const char *lxcpath, char ***names, struct lxc_container ***cret);
987 
1002 int list_active_containers(const char *lxcpath, char ***names, struct lxc_container ***cret);
1003 
1018 int list_all_containers(const char *lxcpath, char ***names, struct lxc_container ***cret);
1019 
1023 void lxc_log_close(void);
1024 
1025 #ifdef __cplusplus
1026 }
1027 #endif
1028 
1029 #endif
bool(* start)(struct lxc_container *c, int useinit, char *const argv[])
Start the container.
Definition: lxccontainer.h:198
Definition: lxccontainer.h:61
bool daemonize
Definition: lxccontainer.h:116
bool(* unfreeze)(struct lxc_container *c)
Thaw a frozen container.
Definition: lxccontainer.h:166
int(* console_getfd)(struct lxc_container *c, int *ttynum, int *masterfd)
Allocate a console tty for the container.
Definition: lxccontainer.h:589
bool(* attach_interface)(struct lxc_container *c, const char *dev, const char *dst_dev)
Add specified netdev to the container.
Definition: lxccontainer.h:759
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:495
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:747
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:608
bool(* snapshot_destroy_all)(struct lxc_container *c)
Destroy all the container&#39;s snapshot.
Definition: lxccontainer.h:813
char * error_string
Definition: lxccontainer.h:110
pid_t(* init_pid)(struct lxc_container *c)
Determine process ID of the containers init process.
Definition: lxccontainer.h:176
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:804
char * vg
Definition: lxccontainer.h:855
bool(* detach_interface)(struct lxc_container *c, const char *dev, const char *dst_dev)
Remove specified netdev from the container.
Definition: lxccontainer.h:769
Specifications for how to create a new backing store.
Definition: lxccontainer.h:848
bool(* shutdown)(struct lxc_container *c, int timeout)
Request the container shutdown by sending it SIGPWR.
Definition: lxccontainer.h:375
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:414
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:320
bool(* clear_config_item)(struct lxc_container *c, const char *key)
Clear a configuration item.
Definition: lxccontainer.h:394
uint64_t fssize
Definition: lxccontainer.h:850
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:735
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:825
char * zfsroot
Definition: lxccontainer.h:852
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:343
char * timestamp
Definition: lxccontainer.h:834
bool(* checkpoint)(struct lxc_container *c, char *directory, bool stop, bool verbose)
Checkpoint a container.
Definition: lxccontainer.h:781
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:832
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:651
int error_num
Definition: lxccontainer.h:113
void(* clear_config)(struct lxc_container *c)
Completely clear the containers in-memory configuration.
Definition: lxccontainer.h:382
bool(* restore)(struct lxc_container *c, char *directory, bool verbose)
Restore a container from a checkpoint.
Definition: lxccontainer.h:793
char * rbdpool
Definition: lxccontainer.h:862
char * thinpool
Definition: lxccontainer.h:857
bool(* reboot)(struct lxc_container *c)
Request the container reboot by sending it SIGINT.
Definition: lxccontainer.h:363
An LXC container snapshot.
Definition: lxccontainer.h:831
bool(* rename)(struct lxc_container *c, const char *newname)
Rename a container.
Definition: lxccontainer.h:354
bool(* may_control)(struct lxc_container *c)
Determine if the caller may control the container.
Definition: lxccontainer.h:723
char * lxcpath
Definition: lxccontainer.h:835
int(* lxc_attach_exec_t)(void *payload)
Definition: attach_options.h:72
bool(* is_defined)(struct lxc_container *c)
Determine if /var/lib/lxc/$name/config exists.
Definition: lxccontainer.h:128
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:638
char * rbdname
Definition: lxccontainer.h:861
bool(* wait)(struct lxc_container *c, const char *state, int timeout)
Wait for container to reach a particular state.
Definition: lxccontainer.h:269
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:624
bool(* load_config)(struct lxc_container *c, const char *alt_file)
Load the specified configuration for the container.
Definition: lxccontainer.h:187
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:712
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:244
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:506
bool(* set_config_path)(struct lxc_container *c, const char *path)
Set the full path to the containers configuration file.
Definition: lxccontainer.h:535
bool(* stop)(struct lxc_container *c)
Stop the container.
Definition: lxccontainer.h:222
bool(* is_running)(struct lxc_container *c)
Determine if container is running.
Definition: lxccontainer.h:148
bool(* set_config_item)(struct lxc_container *c, const char *key, const char *value)
Set a key/value configuration option.
Definition: lxccontainer.h:280
char * lv
Definition: lxccontainer.h:856
bool(* snapshot_restore)(struct lxc_container *c, const char *snapname, const char *newname)
Create a new container based on a snapshot.
Definition: lxccontainer.h:702
struct lxc_container * lxc_container_new(const char *name, const char *configpath)
Create a new container.
Definition: lxclock.h:40
Definition: attach_options.h:77
bool(* freeze)(struct lxc_container *c)
Freeze running container.
Definition: lxccontainer.h:157
const char *(* state)(struct lxc_container *c)
Determine state of container.
Definition: lxccontainer.h:139
int(* snapshot_list)(struct lxc_container *c, struct lxc_snapshot **snapshots)
Obtain a list of container snapshots.
Definition: lxccontainer.h:683
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:849
char * comment_pathname
Definition: lxccontainer.h:833
const char * lxc_get_version(void)
Determine version of LXC.
bool(* startl)(struct lxc_container *c, int useinit,...)
Start the container (list variant).
Definition: lxccontainer.h:213
char * config_path
Definition: lxccontainer.h:119
bool(* save_config)(struct lxc_container *c, const char *alt_file)
Save configuaration to a file.
Definition: lxccontainer.h:301
bool(* destroy)(struct lxc_container *c)
Delete the container.
Definition: lxccontainer.h:291
Options for the migrate API call.
Definition: lxccontainer.h:878
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:450
bool(* want_daemonize)(struct lxc_container *c, bool state)
Change whether the container wants to run disconnected from the terminal.
Definition: lxccontainer.h:233
char * dir
Definition: lxccontainer.h:859
int(* snapshot)(struct lxc_container *c, const char *commentfile)
Create a container snapshot.
Definition: lxccontainer.h:669