]>
git.proxmox.com Git - mirror_lxc.git/blob - src/lxc/lxc.h
2 * lxc: linux Container library
4 * (C) Copyright IBM Corp. 2007, 2008
7 * Daniel Lezcano <dlezcano at fr.ibm.com>
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
31 #include <lxc/state.h>
38 Following code is for liblxc.
40 lxc/lxc.h will contain exports of liblxc
44 * Start the specified command inside a system container
45 * @name : the name of the container
46 * @argv : an array of char * corresponding to the commande line
47 * @conf : configuration
48 * Returns 0 on sucess, < 0 otherwise
50 extern int lxc_start(const char *name
, char *const argv
[], struct lxc_conf
*conf
,
54 * Stop the container previously started with lxc_start, all
55 * the processes running inside this container will be killed.
56 * @name : the name of the container
57 * Returns 0 on success, < 0 otherwise
59 extern int lxc_stop(const char *name
, const char *lxcpath
);
62 * Start the specified command inside an application container
63 * @name : the name of the container
64 * @argv : an array of char * corresponding to the commande line
65 * @quiet : if != 0 then lxc-init won't produce any output
66 * @conf : configuration
67 * Returns 0 on sucess, < 0 otherwise
69 extern int lxc_execute(const char *name
, char *const argv
[], int quiet
,
70 struct lxc_conf
*conf
, const char *lxcpath
);
73 * Open the monitoring mechanism for a specific container
74 * The function will return an fd corresponding to the events
75 * Returns a file descriptor on success, < 0 otherwise
77 extern int lxc_monitor_open(const char *lxcpath
);
80 * Read the state of the container if this one has changed
81 * The function will block until there is an event available
82 * @fd : the file descriptor provided by lxc_monitor_open
83 * @state : the variable which will be filled with the state
84 * Returns 0 if the monitored container has exited, > 0 if
85 * data was readen, < 0 otherwise
87 extern int lxc_monitor_read(int fd
, struct lxc_msg
*msg
);
88 extern int lxc_monitor_read_timeout(int fd
, struct lxc_msg
*msg
, int timeout
);
91 * Close the fd associated with the monitoring
92 * @fd : the file descriptor provided by lxc_monitor_open
93 * Returns 0 on success, < 0 otherwise
95 extern int lxc_monitor_close(int fd
);
98 * Show the console of the container.
99 * @name : the name of container
100 * @tty : the tty number
101 * @fd : a pointer to a tty file descriptor
102 * Returns 0 on sucess, < 0 otherwise
104 extern int lxc_console(const char *name
, int ttynum
, int *fd
, const char *lxcpath
);
107 * Freeze all the tasks running inside the container <name>
108 * @name : the container name
109 * Returns 0 on success, < 0 otherwise
111 extern int lxc_freeze(const char *name
, const char *lxcpath
);
114 * Unfreeze all previously frozen tasks.
115 * @name : the name of the container
116 * Return 0 on sucess, < 0 otherwise
118 extern int lxc_unfreeze(const char *name
, const char *lxcpath
);
121 * Unfreeze all previously frozen tasks.
122 * This is the function to use from inside the monitor
123 * @name : the name of the container
124 * Return 0 on sucess, < 0 otherwise
126 extern int lxc_unfreeze_bypath(const char *cgpath
);
129 * Retrieve the container state
130 * @name : the name of the container
131 * Returns the state of the container on success, < 0 otherwise
133 extern lxc_state_t
lxc_state(const char *name
, const char *lxcpath
);
136 * Set a specified value for a specified subsystem. The specified
137 * subsystem must be fully specified, eg. "cpu.shares"
138 * @cgpath : the cgroup path of the container
139 * @filename : the cgroup attribute filename
140 * @value : the value to be set
141 * Returns 0 on success, < 0 otherwise
143 extern int lxc_cgroup_set_bypath(const char *cgpath
, const char *filename
, const char *value
);
146 * Set a specified value for a specified subsystem. The specified
147 * subsystem must be fully specified, eg. "cpu.shares"
148 * @name : the name of the container
149 * @filename : the cgroup attribute filename
150 * @value : the value to be set
151 * @lxcpath : lxc config path for container
152 * Returns 0 on success, < 0 otherwise
154 extern int lxc_cgroup_set(const char *name
, const char *filename
, const char *value
, const char *lxcpath
);
157 * Get a specified value for a specified subsystem. The specified
158 * subsystem must be fully specified, eg. "cpu.shares"
159 * @name : the name of the container
160 * @filename : the cgroup attribute filename
161 * @value : the value to be set
162 * @len : the len of the value variable
163 * @lxcpath : lxc config path for container
164 * Returns the number of bytes read, < 0 on error
166 extern int lxc_cgroup_get(const char *name
, const char *filename
,
167 char *value
, size_t len
, const char *lxcpath
);
170 * Retrieve the error string associated with the error returned by
172 * @error : the value of the error
173 * Returns a string on success or NULL otherwise.
175 extern const char *lxc_strerror(int error
);
178 * Checkpoint a container
179 * @name : the name of the container being checkpointed
180 * @sfd: fd on which the container is checkpointed
181 * @flags : checkpoint flags (an ORed value)
182 * Returns 0 on success, < 0 otherwise
184 extern int lxc_checkpoint(const char *name
, int sfd
, int flags
);
185 #define LXC_FLAG_PAUSE 1
186 #define LXC_FLAG_HALT 2
189 * Restart a container
190 * @name : the name of the container being restarted
191 * @sfd: fd from which the container is restarted
192 * @conf: lxc_conf structure.
193 * @flags : restart flags (an ORed value)
194 * @lxcpath: container path
195 * Returns 0 on success, < 0 otherwise
197 extern int lxc_restart(const char *, int, struct lxc_conf
*, int, const char *);
200 * Create and return a new lxccontainer struct.
202 extern struct lxc_container
*lxc_container_new(const char *name
, const char *configpath
);
205 * Returns 1 on success, 0 on failure.
207 extern int lxc_container_get(struct lxc_container
*c
);
210 * Put a lxccontainer struct reference.
211 * Return -1 on error.
212 * Return 0 if this was not the last reference.
213 * If it is the last reference, free the lxccontainer and return 1.
215 extern int lxc_container_put(struct lxc_container
*c
);
218 * Get a list of valid wait states.
219 * If states is NULL, simply return the number of states
221 extern int lxc_get_wait_states(const char **states
);