]> git.proxmox.com Git - mirror_lxc.git/blob - src/lxc/commands.h
storage: rename files "bdev" -> "storage"
[mirror_lxc.git] / src / lxc / commands.h
1 /*
2 * lxc: linux Container library
3 *
4 * (C) Copyright IBM Corp. 2007, 2009
5 *
6 * Authors:
7 * Daniel Lezcano <daniel.lezcano at free.fr>
8 *
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.
13 *
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.
18 *
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 */
23
24 #ifndef __LXC_COMMANDS_H
25 #define __LXC_COMMANDS_H
26
27 #include <stdio.h>
28 #include <unistd.h>
29 #include <sys/types.h>
30
31 #include "state.h"
32
33 #define LXC_CMD_DATA_MAX (MAXPATHLEN * 2)
34
35 /* https://developer.gnome.org/glib/2.28/glib-Type-Conversion-Macros.html */
36 #define INT_TO_PTR(n) ((void *)(long)(n))
37 #define PTR_TO_INT(p) ((int)(long)(p))
38
39 typedef enum {
40 LXC_CMD_CONSOLE,
41 LXC_CMD_CONSOLE_WINCH,
42 LXC_CMD_STOP,
43 LXC_CMD_GET_STATE,
44 LXC_CMD_GET_INIT_PID,
45 LXC_CMD_GET_CLONE_FLAGS,
46 LXC_CMD_GET_CGROUP,
47 LXC_CMD_GET_CONFIG_ITEM,
48 LXC_CMD_GET_NAME,
49 LXC_CMD_GET_LXCPATH,
50 LXC_CMD_ADD_STATE_CLIENT,
51 LXC_CMD_MAX,
52 } lxc_cmd_t;
53
54 struct lxc_cmd_req {
55 lxc_cmd_t cmd;
56 int datalen;
57 const void *data;
58 };
59
60 struct lxc_cmd_rsp {
61 int ret; /* 0 on success, -errno on failure */
62 int datalen;
63 void *data;
64 };
65
66 struct lxc_cmd_rr {
67 struct lxc_cmd_req req;
68 struct lxc_cmd_rsp rsp;
69 };
70
71 struct lxc_cmd_console_rsp_data {
72 int masterfd;
73 int ttynum;
74 };
75
76 extern int lxc_cmd_console_winch(const char *name, const char *lxcpath);
77 extern int lxc_cmd_console(const char *name, int *ttynum, int *fd,
78 const char *lxcpath);
79 /*
80 * Get the 'real' cgroup path (as seen in /proc/self/cgroup) for a container
81 * for a particular subsystem
82 */
83 extern char *lxc_cmd_get_cgroup_path(const char *name, const char *lxcpath,
84 const char *subsystem);
85 extern int lxc_cmd_get_clone_flags(const char *name, const char *lxcpath);
86 extern char *lxc_cmd_get_config_item(const char *name, const char *item, const char *lxcpath);
87 extern char *lxc_cmd_get_name(const char *hashed_sock);
88 extern char *lxc_cmd_get_lxcpath(const char *hashed_sock);
89 extern pid_t lxc_cmd_get_init_pid(const char *name, const char *lxcpath);
90 extern int lxc_cmd_get_state(const char *name, const char *lxcpath);
91 extern int lxc_cmd_stop(const char *name, const char *lxcpath);
92
93 /* lxc_cmd_add_state_client Register a new state client fd in the container's
94 * in-memory handler.
95 *
96 * @param[in] name Name of container to connect to.
97 * @param[in] lxcpath The lxcpath in which the container is running.
98 * @param[in] states The states to wait for.
99 * @param[out] state_client_fd The state client fd from which the state can be
100 * received.
101 * @return Return < 0 on error
102 * == MAX_STATE when state needs to retrieved
103 * via socket fd
104 * < MAX_STATE current container state
105 */
106 extern int lxc_cmd_add_state_client(const char *name, const char *lxcpath,
107 lxc_state_t states[MAX_STATE],
108 int *state_client_fd);
109
110 struct lxc_epoll_descr;
111 struct lxc_handler;
112
113 extern int lxc_cmd_init(const char *name, struct lxc_handler *handler,
114 const char *lxcpath);
115 extern int lxc_cmd_mainloop_add(const char *name, struct lxc_epoll_descr *descr,
116 struct lxc_handler *handler);
117 extern int lxc_try_cmd(const char *name, const char *lxcpath);
118
119 #endif /* __commands_h */