]> git.proxmox.com Git - mirror_lxc.git/blob - src/lxc/lxccontainer.h
api: add set_cgroup_item and get_cgroup_item (to c api)
[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 bool (*is_defined)(struct lxc_container *c); // did /var/lib/lxc/$name/config exist
22 const char *(*state)(struct lxc_container *c);
23 bool (*is_running)(struct lxc_container *c); // true so long as defined and not stopped
24 bool (*freeze)(struct lxc_container *c);
25 bool (*unfreeze)(struct lxc_container *c);
26 pid_t (*init_pid)(struct lxc_container *c);
27 bool (*load_config)(struct lxc_container *c, const char *alt_file);
28 /* The '...' is the command line. If provided, it must be ended with a NULL */
29 bool (*start)(struct lxc_container *c, int useinit, char * const argv[]);
30 bool (*startl)(struct lxc_container *c, int useinit, ...);
31 bool (*stop)(struct lxc_container *c);
32 void (*want_daemonize)(struct lxc_container *c);
33 // Return current config file name. The result is strdup()d, so free the result.
34 char *(*config_file_name)(struct lxc_container *c);
35 // for wait, timeout == -1 means wait forever, timeout == 0 means don't wait.
36 // otherwise timeout is seconds to wait.
37 bool (*wait)(struct lxc_container *c, const char *state, int timeout);
38 bool (*set_config_item)(struct lxc_container *c, const char *key, const char *value);
39 bool (*destroy)(struct lxc_container *c);
40 bool (*save_config)(struct lxc_container *c, const char *alt_file);
41 bool (*create)(struct lxc_container *c, char *t, char *const argv[]);
42 bool (*createl)(struct lxc_container *c, char *t, ...);
43 /* send SIGPWR. if timeout is not 0 or -1, do a hard stop after timeout seconds */
44 bool (*shutdown)(struct lxc_container *c, int timeout);
45 /* clear all network or capability items in the in-memory configuration */
46 bool (*clear_config_item)(struct lxc_container *c, const char *key);
47 /* print a config item to a in-memory string allocated by the caller. Return
48 * the length which was our would be printed. */
49 int (*get_config_item)(struct lxc_container *c, const char *key, char *retv, int inlen);
50 int (*get_keys)(struct lxc_container *c, const char *key, char *retv, int inlen);
51 /*
52 * get_cgroup_item returns the number of bytes read, or an error (<0).
53 * If retv NULL or inlen 0 is passed in, then the length of the cgroup
54 * file will be returned. * Otherwise it will return the # of bytes read.
55 * If inlen is less than the number of bytes available, then the returned
56 * value will be inlen, not the full available size of the file.
57 */
58 int (*get_cgroup_item)(struct lxc_container *c, const char *subsys, char *retv, int inlen);
59 bool (*set_cgroup_item)(struct lxc_container *c, const char *subsys, const char *value);
60
61 #if 0
62 bool (*commit_cgroups)(struct lxc_container *c);
63 bool (*reread_cgroups)(struct lxc_container *c);
64 // question with clone: how do we handle non-standard config file in orig?
65 struct lxc_container (*clone)(struct container *c);
66 int (*ns_attach)(struct lxc_container *c, int ns_mask);
67 // we'll need some plumbing to support lxc-console
68 #endif
69 };
70
71 struct lxc_container *lxc_container_new(const char *name);
72 int lxc_container_get(struct lxc_container *c);
73 int lxc_container_put(struct lxc_container *c);
74 int lxc_get_wait_states(const char **states);
75
76 #if 0
77 char ** lxc_get_valid_keys();
78 char ** lxc_get_valid_values(char *key);
79 #endif