]>
git.proxmox.com Git - mirror_lxc.git/blob - src/lxc/lxccontainer.h
1 #ifndef __LXC_CONTAINER_H
2 #define __LXC_CONTAINER_H
9 #define LXC_CLONE_KEEPNAME (1 << 0)
10 #define LXC_CLONE_COPYHOOKS (1 << 1)
11 #define LXC_CLONE_KEEPMACADDR (1 << 2)
12 #define LXC_CLONE_SNAPSHOT (1 << 3)
13 #define LXC_CLONE_MAXFLAGS (1 << 4)
17 struct lxc_container
{
21 struct lxc_lock
*slock
;
22 struct lxc_lock
*privlock
;
23 int numthreads
; /* protected by privlock. */
24 struct lxc_conf
*lxc_conf
; // maybe we'll just want the whole lxc_handler?
33 bool (*is_defined
)(struct lxc_container
*c
); // did /var/lib/lxc/$name/config exist
34 const char *(*state
)(struct lxc_container
*c
);
35 bool (*is_running
)(struct lxc_container
*c
); // true so long as defined and not stopped
36 bool (*freeze
)(struct lxc_container
*c
);
37 bool (*unfreeze
)(struct lxc_container
*c
);
38 pid_t (*init_pid
)(struct lxc_container
*c
);
39 bool (*load_config
)(struct lxc_container
*c
, const char *alt_file
);
40 /* The '...' is the command line. If provided, it must be ended with a NULL */
41 bool (*start
)(struct lxc_container
*c
, int useinit
, char * const argv
[]);
42 bool (*startl
)(struct lxc_container
*c
, int useinit
, ...);
43 bool (*stop
)(struct lxc_container
*c
);
44 void (*want_daemonize
)(struct lxc_container
*c
);
45 // Return current config file name. The result is strdup()d, so free the result.
46 char *(*config_file_name
)(struct lxc_container
*c
);
47 // for wait, timeout == -1 means wait forever, timeout == 0 means don't wait.
48 // otherwise timeout is seconds to wait.
49 bool (*wait
)(struct lxc_container
*c
, const char *state
, int timeout
);
50 bool (*set_config_item
)(struct lxc_container
*c
, const char *key
, const char *value
);
51 bool (*destroy
)(struct lxc_container
*c
);
52 bool (*save_config
)(struct lxc_container
*c
, const char *alt_file
);
53 bool (*create
)(struct lxc_container
*c
, const char *t
, const char *bdevtype
,
54 struct bdev_specs
*specs
, char *const argv
[]);
55 bool (*createl
)(struct lxc_container
*c
, const char *t
, const char *bdevtype
,
56 struct bdev_specs
*specs
, ...);
57 /* send SIGINT to ask container to reboot */
58 bool (*reboot
)(struct lxc_container
*c
);
59 /* send SIGPWR. if timeout is not 0 or -1, do a hard stop after timeout seconds */
60 bool (*shutdown
)(struct lxc_container
*c
, int timeout
);
61 /* clear all network or capability items in the in-memory configuration */
62 bool (*clear_config_item
)(struct lxc_container
*c
, const char *key
);
63 /* print a config item to a in-memory string allocated by the caller. Return
64 * the length which was our would be printed. */
65 int (*get_config_item
)(struct lxc_container
*c
, const char *key
, char *retv
, int inlen
);
66 int (*get_keys
)(struct lxc_container
*c
, const char *key
, char *retv
, int inlen
);
67 char** (*get_ips
)(struct lxc_container
*c
, char* interface
, char* family
, int scope
);
69 * get_cgroup_item returns the number of bytes read, or an error (<0).
70 * If retv NULL or inlen 0 is passed in, then the length of the cgroup
71 * file will be returned. * Otherwise it will return the # of bytes read.
72 * If inlen is less than the number of bytes available, then the returned
73 * value will be inlen, not the full available size of the file.
75 int (*get_cgroup_item
)(struct lxc_container
*c
, const char *subsys
, char *retv
, int inlen
);
76 bool (*set_cgroup_item
)(struct lxc_container
*c
, const char *subsys
, const char *value
);
79 * Each container can have a custom configuration path. However
80 * by default it will be set to either the LXCPATH configure
81 * variable, or the lxcpath value in the LXC_GLOBAL_CONF configuration
82 * file (i.e. /etc/lxc/lxc.conf).
83 * You can change the value for a specific container with
84 * set_config_path(). Note there is no other way to specify this in
85 * general at the moment.
87 const char *(*get_config_path
)(struct lxc_container
*c
);
88 bool (*set_config_path
)(struct lxc_container
*c
, const char *path
);
91 * @c: the original container
92 * @newname: new name for the container. If NULL, the same name is used, and
93 * a new lxcpath MUST be specified.
94 * @lxcpath: lxcpath in which to create the new container. If NULL, then the
95 * original container's lxcpath will be used. (Shoudl we use the default
97 * @flags: additional flags to modify cloning behavior.
98 * LXC_CLONE_KEEPNAME: don't edit the rootfs to change the hostname.
99 * LXC_CLONE_COPYHOOKS: copy all hooks into the container dir
100 * LXC_CLONE_KEEPMACADDR: don't change the mac address on network interfaces.
101 * LXC_CLONE_SNAPSHOT: snapshot the original filesystem(s). If @devtype was not
102 * specified, then do so with the native bdevtype if possible, else use an
104 * @bdevtype: optionally force the cloned bdevtype to a specified plugin. By
105 * default the original is used (subject to snapshot requirements).
106 * @bdevdata: information about how to create the new storage (i.e. fstype and
108 * @newsize: in case of a block device backing store, an optional size. If 0,
109 * then the original backing store's size will be used if possible. Note this
110 * only applies to the rootfs. For any other filesystems, the original size
111 * will be duplicated.
112 * @hookargs: additional arguments to pass to the clone hook script
114 struct lxc_container
*(*clone
)(struct lxc_container
*c
, const char *newname
,
115 const char *lxcpath
, int flags
, const char *bdevtype
,
116 const char *bdevdata
, unsigned long newsize
, char **hookargs
);
118 /* lxcapi_console_getfd: allocate a console tty from container @c
120 * @c : the running container
121 * @ttynum : in : tty number to attempt to allocate or -1 to
122 * allocate the first available tty
123 * out: the tty number that was allocated
124 * @masterfd : out: fd refering to the master side of pty
126 * Returns "ttyfd" on success, -1 on failure. The returned "ttyfd" is
127 * used to keep the tty allocated. The caller should close "ttyfd" to
128 * indicate that it is done with the allocated console so that it can
129 * be allocated by another caller.
131 int (*console_getfd
)(struct lxc_container
*c
, int *ttynum
, int *masterfd
);
133 /* lxcapi_console: allocate and run a console tty from container @c
135 * @c : the running container
136 * @ttynum : tty number to attempt to allocate, -1 to
137 * allocate the first available tty, or 0 to allocate
139 * @stdinfd : fd to read input from
140 * @stdoutfd : fd to write output to
141 * @stderrfd : fd to write error output to
142 * @escape : the escape character (1 == 'a', 2 == 'b', ...)
144 * Returns 0 on success, -1 on failure. This function will not return
145 * until the console has been exited by the user.
147 int (*console
)(struct lxc_container
*c
, int ttynum
,
148 int stdinfd
, int stdoutfd
, int stderrfd
, int escape
);
151 bool (*commit_cgroups
)(struct lxc_container
*c
);
152 bool (*reread_cgroups
)(struct lxc_container
*c
);
153 // question with clone: how do we handle non-standard config file in orig?
154 struct lxc_container (*clone
)(struct container
*c
);
155 int (*ns_attach
)(struct lxc_container
*c
, int ns_mask
);
156 // we'll need some plumbing to support lxc-console
160 struct lxc_container
*lxc_container_new(const char *name
, const char *configpath
);
161 int lxc_container_get(struct lxc_container
*c
);
162 int lxc_container_put(struct lxc_container
*c
);
163 int lxc_get_wait_states(const char **states
);
164 const char *lxc_get_default_config_path(void);
165 const char *lxc_get_default_lvm_vg(void);
166 const char *lxc_get_default_zfs_root(void);
167 const char *lxc_get_version(void);
170 char ** lxc_get_valid_keys();
171 char ** lxc_get_valid_values(char *key
);