]> git.proxmox.com Git - mirror_lxc.git/blame - src/lxc/lxccontainer.h
ubuntu: iproute is now called iproute2
[mirror_lxc.git] / src / lxc / lxccontainer.h
CommitLineData
9be53773
SH
1#ifndef __LXC_CONTAINER_H
2#define __LXC_CONTAINER_H
72d0e1cb 3#include "lxclock.h"
a0e93eeb 4#include "attach_options.h"
72d0e1cb
SG
5#include <stdlib.h>
6#include <malloc.h>
7
8#include <stdbool.h>
9
9be53773
SH
10#define LXC_CLONE_KEEPNAME (1 << 0)
11#define LXC_CLONE_COPYHOOKS (1 << 1)
12#define LXC_CLONE_KEEPMACADDR (1 << 2)
13#define LXC_CLONE_SNAPSHOT (1 << 3)
14#define LXC_CLONE_MAXFLAGS (1 << 4)
15
dc23c1c8
SH
16#define LXC_CREATE_QUIET (1 << 0)
17#define LXC_CREATE_MAXFLAGS (1 << 1)
18
1897e3bc
SH
19struct bdev_specs;
20
72d0e1cb
SG
21struct lxc_container {
22 // private fields
23 char *name;
24 char *configfile;
df271a59
SH
25 struct lxc_lock *slock;
26 struct lxc_lock *privlock;
72d0e1cb
SG
27 int numthreads; /* protected by privlock. */
28 struct lxc_conf *lxc_conf; // maybe we'll just want the whole lxc_handler?
29
30 // public fields
31 char *error_string;
32 int error_num;
33 int daemonize;
34
2a59a681
SH
35 char *config_path;
36
72d0e1cb
SG
37 bool (*is_defined)(struct lxc_container *c); // did /var/lib/lxc/$name/config exist
38 const char *(*state)(struct lxc_container *c);
39 bool (*is_running)(struct lxc_container *c); // true so long as defined and not stopped
40 bool (*freeze)(struct lxc_container *c);
41 bool (*unfreeze)(struct lxc_container *c);
42 pid_t (*init_pid)(struct lxc_container *c);
12a50cc6 43 bool (*load_config)(struct lxc_container *c, const char *alt_file);
72d0e1cb 44 /* The '...' is the command line. If provided, it must be ended with a NULL */
12a50cc6 45 bool (*start)(struct lxc_container *c, int useinit, char * const argv[]);
72d0e1cb
SG
46 bool (*startl)(struct lxc_container *c, int useinit, ...);
47 bool (*stop)(struct lxc_container *c);
48 void (*want_daemonize)(struct lxc_container *c);
49 // Return current config file name. The result is strdup()d, so free the result.
50 char *(*config_file_name)(struct lxc_container *c);
51 // for wait, timeout == -1 means wait forever, timeout == 0 means don't wait.
52 // otherwise timeout is seconds to wait.
12a50cc6
DE
53 bool (*wait)(struct lxc_container *c, const char *state, int timeout);
54 bool (*set_config_item)(struct lxc_container *c, const char *key, const char *value);
72d0e1cb 55 bool (*destroy)(struct lxc_container *c);
12a50cc6 56 bool (*save_config)(struct lxc_container *c, const char *alt_file);
1897e3bc 57 bool (*create)(struct lxc_container *c, const char *t, const char *bdevtype,
dc23c1c8 58 struct bdev_specs *specs, int flags, char *const argv[]);
1897e3bc 59 bool (*createl)(struct lxc_container *c, const char *t, const char *bdevtype,
dc23c1c8 60 struct bdev_specs *specs, int flags, ...);
3e625e2d
SH
61 /* send SIGINT to ask container to reboot */
62 bool (*reboot)(struct lxc_container *c);
72d0e1cb
SG
63 /* send SIGPWR. if timeout is not 0 or -1, do a hard stop after timeout seconds */
64 bool (*shutdown)(struct lxc_container *c, int timeout);
65 /* clear all network or capability items in the in-memory configuration */
12a50cc6 66 bool (*clear_config_item)(struct lxc_container *c, const char *key);
72d0e1cb
SG
67 /* print a config item to a in-memory string allocated by the caller. Return
68 * the length which was our would be printed. */
12a50cc6
DE
69 int (*get_config_item)(struct lxc_container *c, const char *key, char *retv, int inlen);
70 int (*get_keys)(struct lxc_container *c, const char *key, char *retv, int inlen);
9c83a661 71 char** (*get_ips)(struct lxc_container *c, char* interface, char* family, int scope);
794dd120
SH
72 /*
73 * get_cgroup_item returns the number of bytes read, or an error (<0).
74 * If retv NULL or inlen 0 is passed in, then the length of the cgroup
75 * file will be returned. * Otherwise it will return the # of bytes read.
76 * If inlen is less than the number of bytes available, then the returned
77 * value will be inlen, not the full available size of the file.
78 */
79 int (*get_cgroup_item)(struct lxc_container *c, const char *subsys, char *retv, int inlen);
80 bool (*set_cgroup_item)(struct lxc_container *c, const char *subsys, const char *value);
72d0e1cb 81
2a59a681
SH
82 /*
83 * Each container can have a custom configuration path. However
84 * by default it will be set to either the LXCPATH configure
85 * variable, or the lxcpath value in the LXC_GLOBAL_CONF configuration
86 * file (i.e. /etc/lxc/lxc.conf).
87 * You can change the value for a specific container with
88 * set_config_path(). Note there is no other way to specify this in
89 * general at the moment.
90 */
91 const char *(*get_config_path)(struct lxc_container *c);
92 bool (*set_config_path)(struct lxc_container *c, const char *path);
93
9be53773
SH
94 /*
95 * @c: the original container
96 * @newname: new name for the container. If NULL, the same name is used, and
97 * a new lxcpath MUST be specified.
98 * @lxcpath: lxcpath in which to create the new container. If NULL, then the
99 * original container's lxcpath will be used. (Shoudl we use the default
100 * instead?)
101 * @flags: additional flags to modify cloning behavior.
102 * LXC_CLONE_KEEPNAME: don't edit the rootfs to change the hostname.
103 * LXC_CLONE_COPYHOOKS: copy all hooks into the container dir
104 * LXC_CLONE_KEEPMACADDR: don't change the mac address on network interfaces.
105 * LXC_CLONE_SNAPSHOT: snapshot the original filesystem(s). If @devtype was not
106 * specified, then do so with the native bdevtype if possible, else use an
107 * overlayfs.
108 * @bdevtype: optionally force the cloned bdevtype to a specified plugin. By
109 * default the original is used (subject to snapshot requirements).
110 * @bdevdata: information about how to create the new storage (i.e. fstype and
111 * fsdata)
112 * @newsize: in case of a block device backing store, an optional size. If 0,
113 * then the original backing store's size will be used if possible. Note this
114 * only applies to the rootfs. For any other filesystems, the original size
115 * will be duplicated.
481624b3 116 * @hookargs: additional arguments to pass to the clone hook script
9be53773
SH
117 */
118 struct lxc_container *(*clone)(struct lxc_container *c, const char *newname,
119 const char *lxcpath, int flags, const char *bdevtype,
148e91f5 120 const char *bdevdata, unsigned long newsize, char **hookargs);
9be53773 121
b5159817 122 /* lxcapi_console_getfd: allocate a console tty from container @c
0115f8fd
DE
123 *
124 * @c : the running container
125 * @ttynum : in : tty number to attempt to allocate or -1 to
126 * allocate the first available tty
127 * out: the tty number that was allocated
128 * @masterfd : out: fd refering to the master side of pty
129 *
130 * Returns "ttyfd" on success, -1 on failure. The returned "ttyfd" is
131 * used to keep the tty allocated. The caller should close "ttyfd" to
132 * indicate that it is done with the allocated console so that it can
133 * be allocated by another caller.
134 */
b5159817
DE
135 int (*console_getfd)(struct lxc_container *c, int *ttynum, int *masterfd);
136
137 /* lxcapi_console: allocate and run a console tty from container @c
138 *
139 * @c : the running container
140 * @ttynum : tty number to attempt to allocate, -1 to
141 * allocate the first available tty, or 0 to allocate
142 * the console
143 * @stdinfd : fd to read input from
144 * @stdoutfd : fd to write output to
145 * @stderrfd : fd to write error output to
146 * @escape : the escape character (1 == 'a', 2 == 'b', ...)
147 *
148 * Returns 0 on success, -1 on failure. This function will not return
149 * until the console has been exited by the user.
150 */
151 int (*console)(struct lxc_container *c, int ttynum,
152 int stdinfd, int stdoutfd, int stderrfd, int escape);
0115f8fd 153
a0e93eeb
CS
154 /* create subprocess and attach it to the container, run exec_function inside */
155 int (*attach)(struct lxc_container *c, lxc_attach_exec_t exec_function, void *exec_payload, lxc_attach_options_t *options, pid_t *attached_process);
156
157 /* run program in container, wait for it to exit */
158 int (*attach_run_wait)(struct lxc_container *c, lxc_attach_options_t *options, const char *program, const char * const argv[]);
159 int (*attach_run_waitl)(struct lxc_container *c, lxc_attach_options_t *options, const char *program, const char *arg, ...);
72d0e1cb
SG
160};
161
afeecbba 162struct lxc_container *lxc_container_new(const char *name, const char *configpath);
72d0e1cb
SG
163int lxc_container_get(struct lxc_container *c);
164int lxc_container_put(struct lxc_container *c);
4a7c7daa 165int lxc_get_wait_states(const char **states);
67e571de 166const char *lxc_get_default_config_path(void);
a8428dfa
SH
167const char *lxc_get_default_lvm_vg(void);
168const char *lxc_get_default_zfs_root(void);
b6b918a1 169const char *lxc_get_version(void);
72d0e1cb
SG
170
171#if 0
172char ** lxc_get_valid_keys();
173char ** lxc_get_valid_values(char *key);
174#endif
9be53773 175#endif