]> git.proxmox.com Git - mirror_lxc.git/blob - src/lxc/tools/arguments.h
added allowrunning command line option for snapshotting alive containers
[mirror_lxc.git] / src / lxc / tools / arguments.h
1 /*
2 * lxc: linux Container library
3 *
4 * (C) Copyright IBM Corp. 2007, 2008
5 *
6 * Authors:
7 * Daniel Lezcano <daniel.lezcano at free.fr>
8 * Michel Normand <normand at fr.ibm.com>
9 *
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2.1 of the License, or (at your option) any later version.
14 *
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with this library; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23 */
24
25 #ifndef __LXC_ARGUMENTS_H
26 #define __LXC_ARGUMENTS_H
27
28 #include <getopt.h>
29 #include <stdbool.h>
30 #include <stdint.h>
31 #include <sys/param.h>
32 #include <sys/types.h>
33
34 #include <lxc/lxccontainer.h>
35
36 struct lxc_arguments;
37
38 typedef int (*lxc_arguments_parser_t)(struct lxc_arguments *, int, char *);
39 typedef int (*lxc_arguments_checker_t)(const struct lxc_arguments *);
40
41 struct lxc_arguments {
42 const char *help;
43 void (*helpfn)(const struct lxc_arguments *);
44 const char *progname;
45 const struct option *options;
46 lxc_arguments_parser_t parser;
47 lxc_arguments_checker_t checker;
48
49 const char *name;
50 char *log_file;
51 char *log_priority;
52 int quiet;
53 int daemonize;
54 const char *rcfile;
55 const char *console;
56 const char *console_log;
57 const char *pidfile;
58 const char **lxcpath;
59 int lxcpath_cnt;
60 /* set to 0 to accept only 1 lxcpath, -1 for unlimited */
61 int lxcpath_additional;
62
63 /* for lxc-start */
64 const char *share_ns[32]; /* size must be greater than LXC_NS_MAX */
65
66 /* for lxc-console */
67 unsigned int ttynum;
68 char escape;
69
70 /* for lxc-wait */
71 char *states;
72 long timeout;
73
74 /* for lxc-autostart */
75 int shutdown;
76
77 /* for lxc-stop */
78 int hardstop;
79 int nokill;
80 int nolock;
81 int nowait;
82 int reboot;
83
84 /* for lxc-destroy */
85 int force;
86
87 /* close fds from parent? */
88 bool close_all_fds;
89
90 /* lxc-create */
91 char *bdevtype, *configfile, *template;
92 char *fstype;
93 uint64_t fssize;
94 char *lvname, *vgname, *thinpool;
95 char *rbdname, *rbdpool;
96 char *zfsroot, *lowerdir, *dir;
97
98 /* lxc-execute and lxc-unshare */
99 uid_t uid;
100 gid_t gid;
101
102 /* auto-start */
103 int all;
104 int ignore_auto;
105 int list;
106 char *groups; /* also used by lxc-ls */
107
108 /* lxc-snapshot and lxc-copy */
109 enum task {
110 CLONE,
111 DESTROY,
112 LIST,
113 RESTORE,
114 SNAP,
115 RENAME,
116 } task;
117 int print_comments;
118 char *commentfile;
119 char *newname;
120 char *newpath;
121 char *snapname;
122 int keepdata;
123 int keepname;
124 int keepmac;
125 int allowrunning;
126
127 /* lxc-ls */
128 char *ls_fancy_format;
129 char *ls_filter;
130 unsigned int ls_nesting; /* maximum allowed nesting level */
131 bool ls_active;
132 bool ls_fancy;
133 bool ls_frozen;
134 bool ls_line;
135 bool ls_running;
136 bool ls_stopped;
137 bool ls_defined;
138
139 /* lxc-copy */
140 bool tmpfs;
141
142 /* lxc-unshare */
143 int flags;
144 int want_default_mounts;
145 const char *want_hostname;
146 bool setuid;
147
148 /* remaining arguments */
149 char *const *argv;
150 int argc;
151
152 /* private arguments */
153 void *data;
154 };
155
156 #define LXC_COMMON_OPTIONS \
157 { "name", required_argument, 0, 'n' }, \
158 { "help", no_argument, 0, 'h' }, \
159 { "usage", no_argument, 0, OPT_USAGE }, \
160 { "version", no_argument, 0, OPT_VERSION }, \
161 { "quiet", no_argument, 0, 'q' }, \
162 { "logfile", required_argument, 0, 'o' }, \
163 { "logpriority", required_argument, 0, 'l' }, \
164 { "lxcpath", required_argument, 0, 'P' }, \
165 { "rcfile", required_argument, 0, OPT_RCFILE }, \
166 { 0, 0, 0, 0 }
167
168 /* option keys for long only options */
169 #define OPT_USAGE 0x1000
170 #define OPT_VERSION OPT_USAGE - 1
171 #define OPT_RCFILE OPT_USAGE - 2
172 #define OPT_SHARE_NET OPT_USAGE - 3
173 #define OPT_SHARE_IPC OPT_USAGE - 4
174 #define OPT_SHARE_UTS OPT_USAGE - 5
175 #define OPT_SHARE_PID OPT_USAGE - 6
176
177 extern int lxc_arguments_parse(struct lxc_arguments *args, int argc,
178 char *const argv[]);
179
180 extern int lxc_arguments_str_to_int(struct lxc_arguments *args,
181 const char *str);
182
183 extern bool lxc_setup_shared_ns(struct lxc_arguments *args, struct lxc_container *c);
184
185 #define lxc_info(arg, fmt, args...) \
186 do { \
187 if (!(arg)->quiet) { \
188 fprintf(stdout, "%s: " fmt "\n", (arg)->progname, ##args); \
189 } \
190 } while (0)
191
192 #define lxc_error(arg, fmt, args...) \
193 do { \
194 if (!(arg)->quiet) { \
195 fprintf(stderr, "%s: " fmt "\n", (arg)->progname, ##args); \
196 } \
197 } while (0)
198
199 #define lxc_sys_error(arg, fmt, args...) \
200 do { \
201 if (!(arg)->quiet) { \
202 fprintf(stderr, "%s: " fmt "\n", (arg)->progname, ##args); \
203 } \
204 } while (0)
205
206 #endif /* __LXC_ARGUMENTS_H */