LXC
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros
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 
55 struct lxc_container {
56  // private fields
61  char *name;
62 
67  char *configfile;
68 
73  char *pidfile;
74 
79  struct lxc_lock *slock;
80 
85  struct lxc_lock *privlock;
86 
92  int numthreads;
93 
100  struct lxc_conf *lxc_conf;
101 
102  // public fields
105 
108 
110  bool daemonize;
111 
113  char *config_path;
114 
122  bool (*is_defined)(struct lxc_container *c);
123 
133  const char *(*state)(struct lxc_container *c);
134 
142  bool (*is_running)(struct lxc_container *c);
143 
151  bool (*freeze)(struct lxc_container *c);
152 
160  bool (*unfreeze)(struct lxc_container *c);
161 
170  pid_t (*init_pid)(struct lxc_container *c);
171 
181  bool (*load_config)(struct lxc_container *c, const char *alt_file);
182 
192  bool (*start)(struct lxc_container *c, int useinit, char * const argv[]);
193 
207  bool (*startl)(struct lxc_container *c, int useinit, ...);
208 
216  bool (*stop)(struct lxc_container *c);
217 
227  bool (*want_daemonize)(struct lxc_container *c, bool state);
228 
239  bool (*want_close_all_fds)(struct lxc_container *c, bool state);
240 
250  char *(*config_file_name)(struct lxc_container *c);
251 
264  bool (*wait)(struct lxc_container *c, const char *state, int timeout);
265 
275  bool (*set_config_item)(struct lxc_container *c, const char *key, const char *value);
276 
286  bool (*destroy)(struct lxc_container *c);
287 
298 
307  bool (*save_config)(struct lxc_container *c, const char *alt_file);
308 
326  bool (*create)(struct lxc_container *c, const char *t, const char *bdevtype,
327  struct bdev_specs *specs, int flags, char *const argv[]);
328 
349  bool (*createl)(struct lxc_container *c, const char *t, const char *bdevtype,
350  struct bdev_specs *specs, int flags, ...);
351 
360  bool (*rename)(struct lxc_container *c, const char *newname);
361 
369  bool (*reboot)(struct lxc_container *c);
370 
381  bool (*shutdown)(struct lxc_container *c, int timeout);
382 
388  void (*clear_config)(struct lxc_container *c);
389 
400  bool (*clear_config_item)(struct lxc_container *c, const char *key);
401 
420  int (*get_config_item)(struct lxc_container *c, const char *key, char *retv, int inlen);
421 
422 
433  char* (*get_running_config_item)(struct lxc_container *c, const char *key);
434 
456  int (*get_keys)(struct lxc_container *c, const char *key, char *retv, int inlen);
457 
468  char** (*get_interfaces)(struct lxc_container *c);
469 
484  char** (*get_ips)(struct lxc_container *c, const char* interface, const char* family, int scope);
485 
501  int (*get_cgroup_item)(struct lxc_container *c, const char *subsys, char *retv, int inlen);
502 
512  bool (*set_cgroup_item)(struct lxc_container *c, const char *subsys, const char *value);
513 
530  const char *(*get_config_path)(struct lxc_container *c);
531 
541  bool (*set_config_path)(struct lxc_container *c, const char *path);
542 
573  struct lxc_container *(*clone)(struct lxc_container *c, const char *newname,
574  const char *lxcpath, int flags, const char *bdevtype,
575  const char *bdevdata, uint64_t newsize, char **hookargs);
576 
595  int (*console_getfd)(struct lxc_container *c, int *ttynum, int *masterfd);
596 
614  int (*console)(struct lxc_container *c, int ttynum,
615  int stdinfd, int stdoutfd, int stderrfd, int escape);
616 
630  int (*attach)(struct lxc_container *c, lxc_attach_exec_t exec_function,
631  void *exec_payload, lxc_attach_options_t *options, pid_t *attached_process);
632 
644  int (*attach_run_wait)(struct lxc_container *c, lxc_attach_options_t *options, const char *program, const char * const argv[]);
645 
657  int (*attach_run_waitl)(struct lxc_container *c, lxc_attach_options_t *options, const char *program, const char *arg, ...);
658 
675  int (*snapshot)(struct lxc_container *c, const char *commentfile);
676 
689  int (*snapshot_list)(struct lxc_container *c, struct lxc_snapshot **snapshots);
690 
708  bool (*snapshot_restore)(struct lxc_container *c, const char *snapname, const char *newname);
709 
718  bool (*snapshot_destroy)(struct lxc_container *c, const char *snapname);
719 
728 
738  bool (*may_control)(struct lxc_container *c);
739 
750  bool (*add_device_node)(struct lxc_container *c, const char *src_path, const char *dest_path);
751 
762  bool (*remove_device_node)(struct lxc_container *c, const char *src_path, const char *dest_path);
763 
772  bool (*attach_interface)(struct lxc_container *c, const char *dev, const char *dst_dev);
773 
782  bool (*detach_interface)(struct lxc_container *c, const char *dev, const char *dst_dev);
794  bool (*checkpoint)(struct lxc_container *c, char *directory, bool stop, bool verbose);
795 
806  bool (*restore)(struct lxc_container *c, char *directory, bool verbose);
807 };
808 
812 struct lxc_snapshot {
813  char *name;
815  char *timestamp;
816  char *lxcpath;
822  void (*free)(struct lxc_snapshot *s);
823 };
824 
825 
829 struct bdev_specs {
830  char *fstype;
831  uint64_t fssize;
832  struct {
833  char *zfsroot;
834  } zfs;
835  struct {
836  char *vg;
837  char *lv;
838  char *thinpool;
839  } lvm;
840  char *dir;
841 };
842 
851 struct lxc_container *lxc_container_new(const char *name, const char *configpath);
852 
860 int lxc_container_get(struct lxc_container *c);
861 
872 int lxc_container_put(struct lxc_container *c);
873 
886 int lxc_get_wait_states(const char **states);
887 
895 const char *lxc_get_global_config_item(const char *key);
896 
903 const char *lxc_get_version(void);
904 
916 int list_defined_containers(const char *lxcpath, char ***names, struct lxc_container ***cret);
917 
932 int list_active_containers(const char *lxcpath, char ***names, struct lxc_container ***cret);
933 
948 int list_all_containers(const char *lxcpath, char ***names, struct lxc_container ***cret);
949 
953 void lxc_log_close(void);
954 
955 #ifdef __cplusplus
956 }
957 #endif
958 
959 #endif
void(* free)(struct lxc_snapshot *s)
De-allocate the snapshot.
Definition: lxccontainer.h:822
int(* lxc_attach_exec_t)(void *payload)
Definition: attach_options.h:72
Definition: lxccontainer.h:55
bool daemonize
Definition: lxccontainer.h:110
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:456
bool(* save_config)(struct lxc_container *c, const char *alt_file)
Save configuaration to a file.
Definition: lxccontainer.h:307
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:614
bool(* attach_interface)(struct lxc_container *c, const char *dev, const char *dst_dev)
Add specified netdev to the container.
Definition: lxccontainer.h:772
bool(* want_daemonize)(struct lxc_container *c, bool state)
Determine if the container wants to run disconnected from the terminal.
Definition: lxccontainer.h:227
int lxc_get_wait_states(const char **states)
Obtain a list of all container states.
bool(* snapshot_restore)(struct lxc_container *c, const char *snapname, const char *newname)
Create a new container based on a snapshot.
Definition: lxccontainer.h:708
bool(* wait)(struct lxc_container *c, const char *state, int timeout)
Wait for container to reach a particular state.
Definition: lxccontainer.h:264
char * error_string
Definition: lxccontainer.h:104
const char * lxc_get_global_config_item(const char *key)
Get the value for a global config key.
char * vg
Definition: lxccontainer.h:836
const char *(* state)(struct lxc_container *c)
Determine state of container.
Definition: lxccontainer.h:133
Specifications for how to create a new backing store.
Definition: lxccontainer.h:829
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:630
bool(* stop)(struct lxc_container *c)
Stop the container.
Definition: lxccontainer.h:216
int(* console_getfd)(struct lxc_container *c, int *ttynum, int *masterfd)
Allocate a console tty for the container.
Definition: lxccontainer.h:595
uint64_t fssize
Definition: lxccontainer.h:831
bool(* destroy_with_snapshots)(struct lxc_container *c)
Delete the container and all its snapshots.
Definition: lxccontainer.h:297
bool(* set_config_path)(struct lxc_container *c, const char *path)
Set the full path to the containers configuration file.
Definition: lxccontainer.h:541
bool(* unfreeze)(struct lxc_container *c)
Thaw a frozen container.
Definition: lxccontainer.h:160
pid_t(* init_pid)(struct lxc_container *c)
Determine process ID of the containers init process.
Definition: lxccontainer.h:170
char * zfsroot
Definition: lxccontainer.h:833
char * timestamp
Definition: lxccontainer.h:815
int list_defined_containers(const char *lxcpath, char ***names, struct lxc_container ***cret)
Get a list of defined containers in a lxcpath.
bool(* destroy)(struct lxc_container *c)
Delete the container.
Definition: lxccontainer.h:286
char * name
Definition: lxccontainer.h:813
int(* snapshot_list)(struct lxc_container *c, struct lxc_snapshot **snapshots)
Obtain a list of container snapshots.
Definition: lxccontainer.h:689
int lxc_container_put(struct lxc_container *c)
Drop a reference to the specified container.
void lxc_log_close(void)
Close log file.
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:512
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:657
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:501
bool(* is_running)(struct lxc_container *c)
Determine if container is running.
Definition: lxccontainer.h:142
bool(* checkpoint)(struct lxc_container *c, char *directory, bool stop, bool verbose)
Checkpoint a container.
Definition: lxccontainer.h:794
bool(* may_control)(struct lxc_container *c)
Determine if the caller may control the container.
Definition: lxccontainer.h:738
bool(* load_config)(struct lxc_container *c, const char *alt_file)
Load the specified configuration for the container.
Definition: lxccontainer.h:181
int error_num
Definition: lxccontainer.h:107
bool(* start)(struct lxc_container *c, int useinit, char *const argv[])
Start the container.
Definition: lxccontainer.h:192
char * thinpool
Definition: lxccontainer.h:838
bool(* snapshot_destroy_all)(struct lxc_container *c)
Destroy all the container&#39;s snapshot.
Definition: lxccontainer.h:727
An LXC container snapshot.
Definition: lxccontainer.h:812
bool(* restore)(struct lxc_container *c, char *directory, bool verbose)
Restore a container from a checkpoint.
Definition: lxccontainer.h:806
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:750
char * lxcpath
Definition: lxccontainer.h:816
void(* clear_config)(struct lxc_container *c)
Completely clear the containers in-memory configuration.
Definition: lxccontainer.h:388
int lxc_container_get(struct lxc_container *c)
Add a reference to the specified container.
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(* set_config_item)(struct lxc_container *c, const char *key, const char *value)
Set a key/value configuration option.
Definition: lxccontainer.h:275
bool(* want_close_all_fds)(struct lxc_container *c, bool state)
Determine whether container wishes all file descriptors to be closed on startup.
Definition: lxccontainer.h:239
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:644
bool(* detach_interface)(struct lxc_container *c, const char *dev, const char *dst_dev)
Remove specified netdev from the container.
Definition: lxccontainer.h:782
char * lv
Definition: lxccontainer.h:837
int(* snapshot)(struct lxc_container *c, const char *commentfile)
Create a container snapshot.
Definition: lxccontainer.h:675
bool(* is_defined)(struct lxc_container *c)
Determine if /var/lib/lxc/$name/config exists.
Definition: lxccontainer.h:122
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
int list_active_containers(const char *lxcpath, char ***names, struct lxc_container ***cret)
Get a list of active containers for a given lxcpath.
bool(* startl)(struct lxc_container *c, int useinit,...)
Start the container (list variant).
Definition: lxccontainer.h:207
char * fstype
Definition: lxccontainer.h:830
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:349
char * comment_pathname
Definition: lxccontainer.h:814
const char * lxc_get_version(void)
Determine version of LXC.
bool(* reboot)(struct lxc_container *c)
Request the container reboot by sending it SIGINT.
Definition: lxccontainer.h:369
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:420
bool(* clear_config_item)(struct lxc_container *c, const char *key)
Clear a configuration item.
Definition: lxccontainer.h:400
bool(* rename)(struct lxc_container *c, const char *newname)
Rename a container.
Definition: lxccontainer.h:360
char * config_path
Definition: lxccontainer.h:113
bool(* snapshot_destroy)(struct lxc_container *c, const char *snapname)
Destroy the specified snapshot.
Definition: lxccontainer.h:718
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:326
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:762
bool(* shutdown)(struct lxc_container *c, int timeout)
Request the container shutdown by sending it SIGPWR.
Definition: lxccontainer.h:381
bool(* freeze)(struct lxc_container *c)
Freeze running container.
Definition: lxccontainer.h:151
char * dir
Definition: lxccontainer.h:840