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
00059 struct lxc_container {
00060
00065 char *name;
00066
00071 char *configfile;
00072
00077 char *pidfile;
00078
00083 struct lxc_lock *slock;
00084
00089 struct lxc_lock *privlock;
00090
00096 int numthreads;
00097
00104 struct lxc_conf *lxc_conf;
00105
00106
00108 char *error_string;
00109
00111 int error_num;
00112
00114 bool daemonize;
00115
00117 char *config_path;
00118
00126 bool (*is_defined)(struct lxc_container *c);
00127
00137 const char *(*state)(struct lxc_container *c);
00138
00146 bool (*is_running)(struct lxc_container *c);
00147
00155 bool (*freeze)(struct lxc_container *c);
00156
00164 bool (*unfreeze)(struct lxc_container *c);
00165
00174 pid_t (*init_pid)(struct lxc_container *c);
00175
00185 bool (*load_config)(struct lxc_container *c, const char *alt_file);
00186
00196 bool (*start)(struct lxc_container *c, int useinit, char * const argv[]);
00197
00211 bool (*startl)(struct lxc_container *c, int useinit, ...);
00212
00220 bool (*stop)(struct lxc_container *c);
00221
00231 bool (*want_daemonize)(struct lxc_container *c, bool state);
00232
00242 bool (*want_close_all_fds)(struct lxc_container *c, bool state);
00243
00253 char *(*config_file_name)(struct lxc_container *c);
00254
00267 bool (*wait)(struct lxc_container *c, const char *state, int timeout);
00268
00278 bool (*set_config_item)(struct lxc_container *c, const char *key, const char *value);
00279
00289 bool (*destroy)(struct lxc_container *c);
00290
00299 bool (*save_config)(struct lxc_container *c, const char *alt_file);
00300
00318 bool (*create)(struct lxc_container *c, const char *t, const char *bdevtype,
00319 struct bdev_specs *specs, int flags, char *const argv[]);
00320
00341 bool (*createl)(struct lxc_container *c, const char *t, const char *bdevtype,
00342 struct bdev_specs *specs, int flags, ...);
00343
00352 bool (*rename)(struct lxc_container *c, const char *newname);
00353
00361 bool (*reboot)(struct lxc_container *c);
00362
00373 bool (*shutdown)(struct lxc_container *c, int timeout);
00374
00380 void (*clear_config)(struct lxc_container *c);
00381
00392 bool (*clear_config_item)(struct lxc_container *c, const char *key);
00393
00412 int (*get_config_item)(struct lxc_container *c, const char *key, char *retv, int inlen);
00413
00414
00425 char* (*get_running_config_item)(struct lxc_container *c, const char *key);
00426
00448 int (*get_keys)(struct lxc_container *c, const char *key, char *retv, int inlen);
00449
00460 char** (*get_interfaces)(struct lxc_container *c);
00461
00476 char** (*get_ips)(struct lxc_container *c, const char* interface, const char* family, int scope);
00477
00493 int (*get_cgroup_item)(struct lxc_container *c, const char *subsys, char *retv, int inlen);
00494
00504 bool (*set_cgroup_item)(struct lxc_container *c, const char *subsys, const char *value);
00505
00522 const char *(*get_config_path)(struct lxc_container *c);
00523
00533 bool (*set_config_path)(struct lxc_container *c, const char *path);
00534
00565 struct lxc_container *(*clone)(struct lxc_container *c, const char *newname,
00566 const char *lxcpath, int flags, const char *bdevtype,
00567 const char *bdevdata, uint64_t newsize, char **hookargs);
00568
00587 int (*console_getfd)(struct lxc_container *c, int *ttynum, int *masterfd);
00588
00606 int (*console)(struct lxc_container *c, int ttynum,
00607 int stdinfd, int stdoutfd, int stderrfd, int escape);
00608
00622 int (*attach)(struct lxc_container *c, lxc_attach_exec_t exec_function,
00623 void *exec_payload, lxc_attach_options_t *options, pid_t *attached_process);
00624
00636 int (*attach_run_wait)(struct lxc_container *c, lxc_attach_options_t *options, const char *program, const char * const argv[]);
00637
00649 int (*attach_run_waitl)(struct lxc_container *c, lxc_attach_options_t *options, const char *program, const char *arg, ...);
00650
00667 int (*snapshot)(struct lxc_container *c, const char *commentfile);
00668
00681 int (*snapshot_list)(struct lxc_container *c, struct lxc_snapshot **snapshots);
00682
00700 bool (*snapshot_restore)(struct lxc_container *c, const char *snapname, const char *newname);
00701
00710 bool (*snapshot_destroy)(struct lxc_container *c, const char *snapname);
00711
00721 bool (*may_control)(struct lxc_container *c);
00722
00733 bool (*add_device_node)(struct lxc_container *c, const char *src_path, const char *dest_path);
00734
00745 bool (*remove_device_node)(struct lxc_container *c, const char *src_path, const char *dest_path);
00746 };
00747
00751 struct lxc_snapshot {
00752 char *name;
00753 char *comment_pathname;
00754 char *timestamp;
00755 char *lxcpath;
00761 void (*free)(struct lxc_snapshot *s);
00762 };
00763
00764
00768 struct bdev_specs {
00769 char *fstype;
00770 uint64_t fssize;
00771 struct {
00772 char *zfsroot;
00773 } zfs;
00774 struct {
00775 char *vg;
00776 char *lv;
00777 char *thinpool;
00778 } lvm;
00779 char *dir;
00780 };
00781
00790 struct lxc_container *lxc_container_new(const char *name, const char *configpath);
00791
00799 int lxc_container_get(struct lxc_container *c);
00800
00811 int lxc_container_put(struct lxc_container *c);
00812
00825 int lxc_get_wait_states(const char **states);
00826
00834 const char *lxc_get_global_config_item(const char *key);
00835
00842 const char *lxc_get_version(void);
00843
00855 int list_defined_containers(const char *lxcpath, char ***names, struct lxc_container ***cret);
00856
00871 int list_active_containers(const char *lxcpath, char ***names, struct lxc_container ***cret);
00872
00887 int list_all_containers(const char *lxcpath, char ***names, struct lxc_container ***cret);
00888
00892 void lxc_log_close(void);
00893
00894 #ifdef __cplusplus
00895 }
00896 #endif
00897
00898 #endif