]> git.proxmox.com Git - mirror_lxc.git/blob - src/lxc/lxccontainer.h
lxc api: fix some config_path oddities
[mirror_lxc.git] / src / lxc / lxccontainer.h
1 #include "lxclock.h"
2 #include <stdlib.h>
3 #include <malloc.h>
4
5 #include <stdbool.h>
6
7 struct lxc_container {
8 // private fields
9 char *name;
10 char *configfile;
11 sem_t *slock;
12 sem_t *privlock;
13 int numthreads; /* protected by privlock. */
14 struct lxc_conf *lxc_conf; // maybe we'll just want the whole lxc_handler?
15
16 // public fields
17 char *error_string;
18 int error_num;
19 int daemonize;
20
21 char *config_path;
22
23 bool (*is_defined)(struct lxc_container *c); // did /var/lib/lxc/$name/config exist
24 const char *(*state)(struct lxc_container *c);
25 bool (*is_running)(struct lxc_container *c); // true so long as defined and not stopped
26 bool (*freeze)(struct lxc_container *c);
27 bool (*unfreeze)(struct lxc_container *c);
28 pid_t (*init_pid)(struct lxc_container *c);
29 bool (*load_config)(struct lxc_container *c, const char *alt_file);
30 /* The '...' is the command line. If provided, it must be ended with a NULL */
31 bool (*start)(struct lxc_container *c, int useinit, char * const argv[]);
32 bool (*startl)(struct lxc_container *c, int useinit, ...);
33 bool (*stop)(struct lxc_container *c);
34 void (*want_daemonize)(struct lxc_container *c);
35 // Return current config file name. The result is strdup()d, so free the result.
36 char *(*config_file_name)(struct lxc_container *c);
37 // for wait, timeout == -1 means wait forever, timeout == 0 means don't wait.
38 // otherwise timeout is seconds to wait.
39 bool (*wait)(struct lxc_container *c, const char *state, int timeout);
40 bool (*set_config_item)(struct lxc_container *c, const char *key, const char *value);
41 bool (*destroy)(struct lxc_container *c);
42 bool (*save_config)(struct lxc_container *c, const char *alt_file);
43 bool (*create)(struct lxc_container *c, char *t, char *const argv[]);
44 bool (*createl)(struct lxc_container *c, char *t, ...);
45 /* send SIGPWR. if timeout is not 0 or -1, do a hard stop after timeout seconds */
46 bool (*shutdown)(struct lxc_container *c, int timeout);
47 /* clear all network or capability items in the in-memory configuration */
48 bool (*clear_config_item)(struct lxc_container *c, const char *key);
49 /* print a config item to a in-memory string allocated by the caller. Return
50 * the length which was our would be printed. */
51 int (*get_config_item)(struct lxc_container *c, const char *key, char *retv, int inlen);
52 int (*get_keys)(struct lxc_container *c, const char *key, char *retv, int inlen);
53 /*
54 * get_cgroup_item returns the number of bytes read, or an error (<0).
55 * If retv NULL or inlen 0 is passed in, then the length of the cgroup
56 * file will be returned. * Otherwise it will return the # of bytes read.
57 * If inlen is less than the number of bytes available, then the returned
58 * value will be inlen, not the full available size of the file.
59 */
60 int (*get_cgroup_item)(struct lxc_container *c, const char *subsys, char *retv, int inlen);
61 bool (*set_cgroup_item)(struct lxc_container *c, const char *subsys, const char *value);
62
63 /*
64 * Each container can have a custom configuration path. However
65 * by default it will be set to either the LXCPATH configure
66 * variable, or the lxcpath value in the LXC_GLOBAL_CONF configuration
67 * file (i.e. /etc/lxc/lxc.conf).
68 * You can change the value for a specific container with
69 * set_config_path(). Note there is no other way to specify this in
70 * general at the moment.
71 */
72 const char *(*get_config_path)(struct lxc_container *c);
73 bool (*set_config_path)(struct lxc_container *c, const char *path);
74
75 #if 0
76 bool (*commit_cgroups)(struct lxc_container *c);
77 bool (*reread_cgroups)(struct lxc_container *c);
78 // question with clone: how do we handle non-standard config file in orig?
79 struct lxc_container (*clone)(struct container *c);
80 int (*ns_attach)(struct lxc_container *c, int ns_mask);
81 // we'll need some plumbing to support lxc-console
82 #endif
83 };
84
85 struct lxc_container *lxc_container_new(const char *name, const char *configpath);
86 int lxc_container_get(struct lxc_container *c);
87 int lxc_container_put(struct lxc_container *c);
88 int lxc_get_wait_states(const char **states);
89
90 #if 0
91 char ** lxc_get_valid_keys();
92 char ** lxc_get_valid_values(char *key);
93 #endif