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
00052 struct migrate_opts;
00053
00061 struct lxc_container {
00062
00067 char *name;
00068
00073 char *configfile;
00074
00079 char *pidfile;
00080
00085 struct lxc_lock *slock;
00086
00091 struct lxc_lock *privlock;
00092
00098 int numthreads;
00099
00106 struct lxc_conf *lxc_conf;
00107
00108
00110 char *error_string;
00111
00113 int error_num;
00114
00116 bool daemonize;
00117
00119 char *config_path;
00120
00128 bool (*is_defined)(struct lxc_container *c);
00129
00139 const char *(*state)(struct lxc_container *c);
00140
00148 bool (*is_running)(struct lxc_container *c);
00149
00157 bool (*freeze)(struct lxc_container *c);
00158
00166 bool (*unfreeze)(struct lxc_container *c);
00167
00176 pid_t (*init_pid)(struct lxc_container *c);
00177
00187 bool (*load_config)(struct lxc_container *c, const char *alt_file);
00188
00198 bool (*start)(struct lxc_container *c, int useinit, char * const argv[]);
00199
00213 bool (*startl)(struct lxc_container *c, int useinit, ...);
00214
00222 bool (*stop)(struct lxc_container *c);
00223
00233 bool (*want_daemonize)(struct lxc_container *c, bool state);
00234
00244 bool (*want_close_all_fds)(struct lxc_container *c, bool state);
00245
00255 char *(*config_file_name)(struct lxc_container *c);
00256
00269 bool (*wait)(struct lxc_container *c, const char *state, int timeout);
00270
00280 bool (*set_config_item)(struct lxc_container *c, const char *key, const char *value);
00281
00291 bool (*destroy)(struct lxc_container *c);
00292
00301 bool (*save_config)(struct lxc_container *c, const char *alt_file);
00302
00320 bool (*create)(struct lxc_container *c, const char *t, const char *bdevtype,
00321 struct bdev_specs *specs, int flags, char *const argv[]);
00322
00343 bool (*createl)(struct lxc_container *c, const char *t, const char *bdevtype,
00344 struct bdev_specs *specs, int flags, ...);
00345
00354 bool (*rename)(struct lxc_container *c, const char *newname);
00355
00363 bool (*reboot)(struct lxc_container *c);
00364
00375 bool (*shutdown)(struct lxc_container *c, int timeout);
00376
00382 void (*clear_config)(struct lxc_container *c);
00383
00394 bool (*clear_config_item)(struct lxc_container *c, const char *key);
00395
00414 int (*get_config_item)(struct lxc_container *c, const char *key, char *retv, int inlen);
00415
00416
00427 char* (*get_running_config_item)(struct lxc_container *c, const char *key);
00428
00450 int (*get_keys)(struct lxc_container *c, const char *key, char *retv, int inlen);
00451
00462 char** (*get_interfaces)(struct lxc_container *c);
00463
00478 char** (*get_ips)(struct lxc_container *c, const char* interface, const char* family, int scope);
00479
00495 int (*get_cgroup_item)(struct lxc_container *c, const char *subsys, char *retv, int inlen);
00496
00506 bool (*set_cgroup_item)(struct lxc_container *c, const char *subsys, const char *value);
00507
00524 const char *(*get_config_path)(struct lxc_container *c);
00525
00535 bool (*set_config_path)(struct lxc_container *c, const char *path);
00536
00567 struct lxc_container *(*clone)(struct lxc_container *c, const char *newname,
00568 const char *lxcpath, int flags, const char *bdevtype,
00569 const char *bdevdata, uint64_t newsize, char **hookargs);
00570
00589 int (*console_getfd)(struct lxc_container *c, int *ttynum, int *masterfd);
00590
00608 int (*console)(struct lxc_container *c, int ttynum,
00609 int stdinfd, int stdoutfd, int stderrfd, int escape);
00610
00624 int (*attach)(struct lxc_container *c, lxc_attach_exec_t exec_function,
00625 void *exec_payload, lxc_attach_options_t *options, pid_t *attached_process);
00626
00638 int (*attach_run_wait)(struct lxc_container *c, lxc_attach_options_t *options, const char *program, const char * const argv[]);
00639
00651 int (*attach_run_waitl)(struct lxc_container *c, lxc_attach_options_t *options, const char *program, const char *arg, ...);
00652
00669 int (*snapshot)(struct lxc_container *c, const char *commentfile);
00670
00683 int (*snapshot_list)(struct lxc_container *c, struct lxc_snapshot **snapshots);
00684
00702 bool (*snapshot_restore)(struct lxc_container *c, const char *snapname, const char *newname);
00703
00712 bool (*snapshot_destroy)(struct lxc_container *c, const char *snapname);
00713
00723 bool (*may_control)(struct lxc_container *c);
00724
00735 bool (*add_device_node)(struct lxc_container *c, const char *src_path, const char *dest_path);
00736
00747 bool (*remove_device_node)(struct lxc_container *c, const char *src_path, const char *dest_path);
00748
00749
00750
00759 bool (*attach_interface)(struct lxc_container *c, const char *dev, const char *dst_dev);
00760
00769 bool (*detach_interface)(struct lxc_container *c, const char *dev, const char *dst_dev);
00781 bool (*checkpoint)(struct lxc_container *c, char *directory, bool stop, bool verbose);
00782
00793 bool (*restore)(struct lxc_container *c, char *directory, bool verbose);
00794
00804 bool (*destroy_with_snapshots)(struct lxc_container *c);
00805
00813 bool (*snapshot_destroy_all)(struct lxc_container *c);
00814
00815
00825 int (*migrate)(struct lxc_container *c, unsigned int cmd, struct migrate_opts *opts, unsigned int size);
00826 };
00827
00831 struct lxc_snapshot {
00832 char *name;
00833 char *comment_pathname;
00834 char *timestamp;
00835 char *lxcpath;
00841 void (*free)(struct lxc_snapshot *s);
00842 };
00843
00844
00848 struct bdev_specs {
00849 char *fstype;
00850 uint64_t fssize;
00851 struct {
00852 char *zfsroot;
00853 } zfs;
00854 struct {
00855 char *vg;
00856 char *lv;
00857 char *thinpool;
00858 } lvm;
00859 char *dir;
00860 struct {
00861 char *rbdname;
00862 char *rbdpool;
00863 } rbd;
00864 };
00865
00869 enum {
00870 MIGRATE_PRE_DUMP,
00871 MIGRATE_DUMP,
00872 MIGRATE_RESTORE,
00873 };
00874
00878 struct migrate_opts {
00879
00880 char *directory;
00881 bool verbose;
00882
00883 bool stop;
00884 char *predump_dir;
00885 char *pageserver_address;
00886 char *pageserver_port;
00887
00888
00889
00890
00891
00892
00893 bool preserves_inodes;
00894
00895
00896
00897
00898 char *action_script;
00899
00900
00901
00902
00903
00904 bool disable_skip_in_flight;
00905
00906
00907
00908
00909
00910 uint64_t ghost_limit;
00911 };
00912
00921 struct lxc_container *lxc_container_new(const char *name, const char *configpath);
00922
00930 int lxc_container_get(struct lxc_container *c);
00931
00942 int lxc_container_put(struct lxc_container *c);
00943
00956 int lxc_get_wait_states(const char **states);
00957
00965 const char *lxc_get_global_config_item(const char *key);
00966
00973 const char *lxc_get_version(void);
00974
00986 int list_defined_containers(const char *lxcpath, char ***names, struct lxc_container ***cret);
00987
01002 int list_active_containers(const char *lxcpath, char ***names, struct lxc_container ***cret);
01003
01018 int list_all_containers(const char *lxcpath, char ***names, struct lxc_container ***cret);
01019
01023 void lxc_log_close(void);
01024
01025 #ifdef __cplusplus
01026 }
01027 #endif
01028
01029 #endif