00001
00023 #ifndef __LXC_CONTAINER_H
00024 #define __LXC_CONTAINER_H
00025 #include <malloc.h>
00026 #include <semaphore.h>
00027 #include <stdbool.h>
00028 #include <stdlib.h>
00029 #include <stdint.h>
00030
00031 #include <lxc/attach_options.h>
00032
00033 #ifdef __cplusplus
00034 extern "C" {
00035 #endif
00036
00037 #define LXC_CLONE_KEEPNAME (1 << 0)
00038 #define LXC_CLONE_KEEPMACADDR (1 << 1)
00039 #define LXC_CLONE_SNAPSHOT (1 << 2)
00040 #define LXC_CLONE_KEEPBDEVTYPE (1 << 3)
00041 #define LXC_CLONE_MAYBE_SNAPSHOT (1 << 4)
00042 #define LXC_CLONE_MAXFLAGS (1 << 5)
00043 #define LXC_CREATE_QUIET (1 << 0)
00044 #define LXC_CREATE_MAXFLAGS (1 << 1)
00046 struct bdev_specs;
00047
00048 struct lxc_snapshot;
00049
00050 struct lxc_lock;
00051
00055 struct lxc_container {
00056
00061 char *name;
00062
00067 char *configfile;
00068
00073 char *pidfile;
00074
00079 struct lxc_lock *slock;
00080
00085 struct lxc_lock *privlock;
00086
00092 int numthreads;
00093
00100 struct lxc_conf *lxc_conf;
00101
00102
00104 char *error_string;
00105
00107 int error_num;
00108
00110 bool daemonize;
00111
00113 char *config_path;
00114
00122 bool (*is_defined)(struct lxc_container *c);
00123
00133 const char *(*state)(struct lxc_container *c);
00134
00142 bool (*is_running)(struct lxc_container *c);
00143
00151 bool (*freeze)(struct lxc_container *c);
00152
00160 bool (*unfreeze)(struct lxc_container *c);
00161
00170 pid_t (*init_pid)(struct lxc_container *c);
00171
00181 bool (*load_config)(struct lxc_container *c, const char *alt_file);
00182
00192 bool (*start)(struct lxc_container *c, int useinit, char * const argv[]);
00193
00207 bool (*startl)(struct lxc_container *c, int useinit, ...);
00208
00216 bool (*stop)(struct lxc_container *c);
00217
00227 bool (*want_daemonize)(struct lxc_container *c, bool state);
00228
00239 bool (*want_close_all_fds)(struct lxc_container *c, bool state);
00240
00250 char *(*config_file_name)(struct lxc_container *c);
00251
00264 bool (*wait)(struct lxc_container *c, const char *state, int timeout);
00265
00275 bool (*set_config_item)(struct lxc_container *c, const char *key, const char *value);
00276
00286 bool (*destroy)(struct lxc_container *c);
00287
00297 bool (*destroy_with_snapshots)(struct lxc_container *c);
00298
00307 bool (*save_config)(struct lxc_container *c, const char *alt_file);
00308
00326 bool (*create)(struct lxc_container *c, const char *t, const char *bdevtype,
00327 struct bdev_specs *specs, int flags, char *const argv[]);
00328
00349 bool (*createl)(struct lxc_container *c, const char *t, const char *bdevtype,
00350 struct bdev_specs *specs, int flags, ...);
00351
00360 bool (*rename)(struct lxc_container *c, const char *newname);
00361
00369 bool (*reboot)(struct lxc_container *c);
00370
00381 bool (*shutdown)(struct lxc_container *c, int timeout);
00382
00388 void (*clear_config)(struct lxc_container *c);
00389
00400 bool (*clear_config_item)(struct lxc_container *c, const char *key);
00401
00420 int (*get_config_item)(struct lxc_container *c, const char *key, char *retv, int inlen);
00421
00422
00433 char* (*get_running_config_item)(struct lxc_container *c, const char *key);
00434
00456 int (*get_keys)(struct lxc_container *c, const char *key, char *retv, int inlen);
00457
00468 char** (*get_interfaces)(struct lxc_container *c);
00469
00484 char** (*get_ips)(struct lxc_container *c, const char* interface, const char* family, int scope);
00485
00501 int (*get_cgroup_item)(struct lxc_container *c, const char *subsys, char *retv, int inlen);
00502
00512 bool (*set_cgroup_item)(struct lxc_container *c, const char *subsys, const char *value);
00513
00530 const char *(*get_config_path)(struct lxc_container *c);
00531
00541 bool (*set_config_path)(struct lxc_container *c, const char *path);
00542
00573 struct lxc_container *(*clone)(struct lxc_container *c, const char *newname,
00574 const char *lxcpath, int flags, const char *bdevtype,
00575 const char *bdevdata, uint64_t newsize, char **hookargs);
00576
00595 int (*console_getfd)(struct lxc_container *c, int *ttynum, int *masterfd);
00596
00614 int (*console)(struct lxc_container *c, int ttynum,
00615 int stdinfd, int stdoutfd, int stderrfd, int escape);
00616
00630 int (*attach)(struct lxc_container *c, lxc_attach_exec_t exec_function,
00631 void *exec_payload, lxc_attach_options_t *options, pid_t *attached_process);
00632
00644 int (*attach_run_wait)(struct lxc_container *c, lxc_attach_options_t *options, const char *program, const char * const argv[]);
00645
00657 int (*attach_run_waitl)(struct lxc_container *c, lxc_attach_options_t *options, const char *program, const char *arg, ...);
00658
00675 int (*snapshot)(struct lxc_container *c, const char *commentfile);
00676
00689 int (*snapshot_list)(struct lxc_container *c, struct lxc_snapshot **snapshots);
00690
00708 bool (*snapshot_restore)(struct lxc_container *c, const char *snapname, const char *newname);
00709
00718 bool (*snapshot_destroy)(struct lxc_container *c, const char *snapname);
00719
00727 bool (*snapshot_destroy_all)(struct lxc_container *c);
00728
00738 bool (*may_control)(struct lxc_container *c);
00739
00750 bool (*add_device_node)(struct lxc_container *c, const char *src_path, const char *dest_path);
00751
00762 bool (*remove_device_node)(struct lxc_container *c, const char *src_path, const char *dest_path);
00763
00772 bool (*attach_interface)(struct lxc_container *c, const char *dev, const char *dst_dev);
00773
00782 bool (*detach_interface)(struct lxc_container *c, const char *dev, const char *dst_dev);
00794 bool (*checkpoint)(struct lxc_container *c, char *directory, bool stop, bool verbose);
00795
00806 bool (*restore)(struct lxc_container *c, char *directory, bool verbose);
00807 };
00808
00812 struct lxc_snapshot {
00813 char *name;
00814 char *comment_pathname;
00815 char *timestamp;
00816 char *lxcpath;
00822 void (*free)(struct lxc_snapshot *s);
00823 };
00824
00825
00829 struct bdev_specs {
00830 char *fstype;
00831 uint64_t fssize;
00832 struct {
00833 char *zfsroot;
00834 } zfs;
00835 struct {
00836 char *vg;
00837 char *lv;
00838 char *thinpool;
00839 } lvm;
00840 char *dir;
00841 };
00842
00851 struct lxc_container *lxc_container_new(const char *name, const char *configpath);
00852
00860 int lxc_container_get(struct lxc_container *c);
00861
00872 int lxc_container_put(struct lxc_container *c);
00873
00886 int lxc_get_wait_states(const char **states);
00887
00895 const char *lxc_get_global_config_item(const char *key);
00896
00903 const char *lxc_get_version(void);
00904
00916 int list_defined_containers(const char *lxcpath, char ***names, struct lxc_container ***cret);
00917
00932 int list_active_containers(const char *lxcpath, char ***names, struct lxc_container ***cret);
00933
00948 int list_all_containers(const char *lxcpath, char ***names, struct lxc_container ***cret);
00949
00953 void lxc_log_close(void);
00954
00955 #ifdef __cplusplus
00956 }
00957 #endif
00958
00959 #endif