debuggers.hg

view tools/libxl/xl_cmdtable.c @ 22855:1d1eec7e1fb4

xl: Perform minimal validation of virtual disk file while parsing config file

This patch performs some very basic validation on the virtual disk
file passed through the config file. This validation ensures that we
don't go too far with the initialization like spawn qemu and more
while there could be some potentially fundamental issues.

[ Patch fixed up to work with PHYSTYPE_EMPTY 22808:6ec61438713a -iwj ]

Signed-off-by: Kamala Narasimhan <kamala.narasimhan@citrix.com>
Acked-by: Ian Jackson <ian.jackson@eu.citrix.com>
Signed-off-by: Ian Jackson <ian.jackson@eu.citrix.com>
Committed-by: Ian Jackson <ian.jackson@eu.citrix.com>
author Kamala Narasimhan <kamala.narasimhan@gmail.com>
date Tue Jan 25 18:09:49 2011 +0000 (2011-01-25)
parents 26d58b44cd27
children aab67c1c6b87
line source
1 /*
2 * Author Yang Hongyang <yanghy@cn.fujitsu.com>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published
6 * by the Free Software Foundation; version 2.1 only. with the special
7 * exception on linking described in file LICENSE.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU Lesser General Public License for more details.
13 */
15 #include <string.h>
17 #include "libxl.h"
18 #include "xl.h"
20 struct cmd_spec cmd_table[] = {
21 { "create",
22 &main_create,
23 "Create a domain from config file <filename>",
24 "<ConfigFile> [options] [vars]",
25 "-h Print this help.\n"
26 "-p Leave the domain paused after it is created.\n"
27 "-c Connect to the console after the domain is created.\n"
28 "-f=FILE, --defconfig=FILE\n Use the given configuration file.\n"
29 "-q, --quiet Quiet.\n"
30 "-n, --dryrun Dry run - prints the resulting configuration.\n"
31 "-d Enable debug messages.\n"
32 "-e Do not wait in the background for the death of the domain."
33 },
34 { "list",
35 &main_list,
36 "List information about all/some domains",
37 "[options] [Domain]\n",
38 "-l, --long Output all VM details\n"
39 "-v, --verbose Prints out UUIDs",
40 },
41 { "destroy",
42 &main_destroy,
43 "Terminate a domain immediately",
44 "<Domain>",
45 },
46 { "shutdown",
47 &main_shutdown,
48 "Issue a shutdown signal to a domain",
49 "<Domain>",
50 },
51 { "reboot",
52 &main_reboot,
53 "Issue a reboot signal to a domain",
54 "<Domain>",
55 },
56 { "pci-attach",
57 &main_pciattach,
58 "Insert a new pass-through pci device",
59 "<Domain> <BDF> [Virtual Slot]",
60 },
61 { "pci-detach",
62 &main_pcidetach,
63 "Remove a domain's pass-through pci device",
64 "<Domain> <BDF>",
65 },
66 { "pci-list",
67 &main_pcilist,
68 "List pass-through pci devices for a domain",
69 "<Domain>",
70 },
71 { "pci-list-assignable-devices",
72 &main_pcilist_assignable,
73 "List all the assignable pci devices",
74 "",
75 },
76 { "pause",
77 &main_pause,
78 "Pause execution of a domain",
79 "<Domain>",
80 },
81 { "unpause",
82 &main_unpause,
83 "Unpause a paused domain",
84 "<Domain>",
85 },
86 { "console",
87 &main_console,
88 "Attach to domain's console",
89 "[options] <Domain>\n"
90 "-t <type> console type, pv or serial\n"
91 "-n <number> console number"
92 },
93 { "vncviewer",
94 &main_vncviewer,
95 "Attach to domain's VNC server.",
96 "[options] <Domain>\n"
97 "--autopass Pass VNC password to viewer via stdin and\n"
98 " -autopass\n"
99 "--vncviewer-autopass (consistency alias for --autopass)"
100 },
101 { "save",
102 &main_save,
103 "Save a domain state to restore later",
104 "[options] <Domain> <CheckpointFile> [<ConfigFile>]",
105 "-h Print this help.\n"
106 "-c Leave domain running after creating the snapshot."
107 },
108 { "migrate",
109 &main_migrate,
110 "Save a domain state to restore later",
111 "[options] <Domain> <host>",
112 "-h Print this help.\n"
113 "-C <config> Send <config> instead of config file from creation.\n"
114 "-s <sshcommand> Use <sshcommand> instead of ssh. String will be passed\n"
115 " to sh. If empty, run <host> instead of ssh <host> xl\n"
116 " migrate-receive [-d -e]\n"
117 "-e Do not wait in the background (on <host>) for the death\n"
118 " of the domain."
119 },
120 { "dump-core",
121 &main_dump_core,
122 "Core dump a domain",
123 "<Domain> <filename>"
124 },
125 { "restore",
126 &main_restore,
127 "Restore a domain from a saved state",
128 "[options] [<ConfigFile>] <CheckpointFile>",
129 "-h Print this help.\n"
130 "-p Do not unpause domain after restoring it.\n"
131 "-e Do not wait in the background for the death of the domain.\n"
132 "-d Enable debug messages."
133 },
134 { "migrate-receive",
135 &main_migrate_receive,
136 "Restore a domain from a saved state",
137 "- for internal use only",
138 },
139 { "cd-insert",
140 &main_cd_insert,
141 "Insert a cdrom into a guest's cd drive",
142 "<Domain> <VirtualDevice> <type:path>",
143 },
144 { "cd-eject",
145 &main_cd_eject,
146 "Eject a cdrom from a guest's cd drive",
147 "<Domain> <VirtualDevice>",
148 },
149 { "mem-max",
150 &main_memmax,
151 "Set the maximum amount reservation for a domain",
152 "<Domain> <MemMB['b'[bytes]|'k'[KB]|'m'[MB]|'g'[GB]|'t'[TB]]>",
153 },
154 { "mem-set",
155 &main_memset,
156 "Set the current memory usage for a domain",
157 "<Domain> <MemMB['b'[bytes]|'k'[KB]|'m'[MB]|'g'[GB]|'t'[TB]]>",
158 },
159 { "button-press",
160 &main_button_press,
161 "Indicate an ACPI button press to the domain",
162 "<Domain> <Button>",
163 "<Button> may be 'power' or 'sleep'."
164 },
165 { "vcpu-list",
166 &main_vcpulist,
167 "List the VCPUs for all/some domains",
168 "[Domain, ...]",
169 },
170 { "vcpu-pin",
171 &main_vcpupin,
172 "Set which CPUs a VCPU can use",
173 "<Domain> <VCPU|all> <CPUs|all>",
174 },
175 { "vcpu-set",
176 &main_vcpuset,
177 "Set the number of active VCPUs allowed for the domain",
178 "<Domain> <vCPUs>",
179 },
180 { "list-vm",
181 &main_list_vm,
182 "List the VMs,without DOM0",
183 "",
184 },
185 { "info",
186 &main_info,
187 "Get information about Xen host",
188 "-n, --numa List host NUMA topology information",
189 },
190 { "sched-credit",
191 &main_sched_credit,
192 "Get/set credit scheduler parameters",
193 "[-d <Domain> [-w[=WEIGHT]|-c[=CAP]]]",
194 "-d DOMAIN, --domain=DOMAIN Domain to modify\n"
195 "-w WEIGHT, --weight=WEIGHT Weight (int)\n"
196 "-c CAP, --cap=CAP Cap (int)"
197 },
198 { "domid",
199 &main_domid,
200 "Convert a domain name to domain id",
201 "<DomainName>",
202 },
203 { "domname",
204 &main_domname,
205 "Convert a domain id to domain name",
206 "<DomainId>",
207 },
208 { "rename",
209 &main_rename,
210 "Rename a domain",
211 "<Domain> <NewDomainName>",
212 },
213 { "trigger",
214 &main_trigger,
215 "Send a trigger to a domain",
216 "<Domain> <nmi|reset|init|power|sleep> [<VCPU>]",
217 },
218 { "sysrq",
219 &main_sysrq,
220 "Send a sysrq to a domain",
221 "<Domain> <letter>",
222 },
223 { "debug-keys",
224 &main_debug_keys,
225 "Send debug keys to Xen",
226 "<Keys>",
227 },
228 { "dmesg",
229 &main_dmesg,
230 "Read and/or clear dmesg buffer",
231 "[-c]",
232 " -c Clear dmesg buffer as well as printing it",
233 },
234 { "top",
235 &main_top,
236 "Monitor a host and the domains in real time",
237 "",
238 },
239 { "network-attach",
240 &main_networkattach,
241 "Create a new virtual network device",
242 "<Domain> [type=<type>] [mac=<mac>] [bridge=<bridge>] "
243 "[ip=<ip>] [script=<script>] [backend=<BackDomain>] [vifname=<name>] "
244 "[rate=<rate>] [model=<model>] [accel=<accel>]",
245 },
246 { "network-list",
247 &main_networklist,
248 "List virtual network interfaces for a domain",
249 "<Domain(s)>",
250 },
251 { "network-detach",
252 &main_networkdetach,
253 "Destroy a domain's virtual network device",
254 "<Domain> <DevId|mac>",
255 },
256 { "block-attach",
257 &main_blockattach,
258 "Create a new virtual block device",
259 "<Domain> <BackDev> <FrontDev> [<Mode>] [BackDomain]",
260 },
261 { "block-list",
262 &main_blocklist,
263 "List virtual block devices for a domain",
264 "<Domain(s)>",
265 },
266 { "block-detach",
267 &main_blockdetach,
268 "Destroy a domain's virtual block device",
269 "<Domain> <DevId>",
270 },
271 { "uptime",
272 &main_uptime,
273 "Print uptime for all/some domains",
274 "[-s] [Domain]",
275 },
276 { "tmem-list",
277 &main_tmem_list,
278 "List tmem pools",
279 "[-l] [<Domain>|-a]",
280 " -l List tmem stats",
281 },
282 { "tmem-freeze",
283 &main_tmem_freeze,
284 "Freeze tmem pools",
285 "[<Domain>|-a]",
286 " -a Freeze all tmem",
287 },
288 { "tmem-destroy",
289 &main_tmem_destroy,
290 "Destroy tmem pools",
291 "[<Domain>|-a]",
292 " -a Destroy all tmem",
293 },
294 { "tmem-thaw",
295 &main_tmem_thaw,
296 "Thaw tmem pools",
297 "[<Domain>|-a]",
298 " -a Thaw all tmem",
299 },
300 { "tmem-set",
301 &main_tmem_set,
302 "Change tmem settings",
303 "[<Domain>|-a] [-w[=WEIGHT]|-c[=CAP]|-p[=COMPRESS]]",
304 " -a Operate on all tmem\n"
305 " -w WEIGHT Weight (int)\n"
306 " -c CAP Cap (int)\n"
307 " -p COMPRESS Compress (int)",
308 },
309 { "tmem-shared-auth",
310 &main_tmem_shared_auth,
311 "De/authenticate shared tmem pool",
312 "[<Domain>|-a] [-u[=UUID] [-A[=AUTH]",
313 " -a Authenticate for all tmem pools\n"
314 " -u UUID Specify uuid\n"
315 " (abcdef01-2345-6789-1234-567890abcdef)\n"
316 " -A AUTH 0=auth,1=deauth",
317 },
318 { "tmem-freeable",
319 &main_tmem_freeable,
320 "Get information about how much freeable memory (MB) is in-use by tmem",
321 "",
322 },
323 { "network2-attach",
324 &main_network2attach,
325 "Create a new version 2 virtual network device",
326 "<Domain> [front_mac=<mac>] [back_mac=<mac>] [backend=<BackDomain>]"
327 " [trusted=<0|1>] [back_trusted=<0|1>] [bridge=<bridge>]"
328 " [filter_mac=<0|1>] [front_filter_mac=<0|1>] [pdev=<PDEV>]"
329 " [max_bypasses=n]",
330 },
331 { "network2-list",
332 &main_network2list,
333 "list version 2 virtual network interfaces for a domain",
334 "<Domain(s)>",
335 },
336 { "network2-detach",
337 &main_network2detach,
338 "destroy a domain's version 2 virtual network device",
339 "<Domain> <DevId>",
340 },
341 { "cpupool-create",
342 &main_cpupoolcreate,
343 "Create a CPU pool based an ConfigFile",
344 "[options] <ConfigFile> [vars]",
345 "-h, --help Print this help.\n"
346 "-f=FILE, --defconfig=FILE Use the given configuration file.\n"
347 "-n, --dryrun Dry run - prints the resulting configuration."
348 },
349 { "cpupool-list",
350 &main_cpupoollist,
351 "List CPU pools on host",
352 "[-l|--long] [-c|--cpus] [<CPU Pool>]",
353 "-l, --long Output all CPU pool details.\n"
354 "-c, --cpus Output list of CPUs used by a pool"
355 },
356 { "cpupool-destroy",
357 &main_cpupooldestroy,
358 "Deactivates a CPU pool",
359 "<CPU Pool>",
360 },
361 { "cpupool-rename",
362 &main_cpupoolrename,
363 "Renames a CPU pool",
364 "<CPU Pool> <new name>",
365 },
366 { "cpupool-cpu-add",
367 &main_cpupoolcpuadd,
368 "Adds a CPU to a CPU pool",
369 "<CPU Pool> <CPU nr>|node:<node nr>",
370 },
371 { "cpupool-cpu-remove",
372 &main_cpupoolcpuremove,
373 "Removes a CPU from a CPU pool",
374 "<CPU Pool> <CPU nr>|node:<node nr>",
375 },
376 { "cpupool-migrate",
377 &main_cpupoolmigrate,
378 "Moves a domain into a CPU pool",
379 "<Domain> <CPU Pool>",
380 },
381 { "cpupool-numa-split",
382 &main_cpupoolnumasplit,
383 "Splits up the machine into one CPU pool per NUMA node",
384 "",
385 },
386 };
388 int cmdtable_len = sizeof(cmd_table)/sizeof(struct cmd_spec);
390 /* Look up a command in the table, allowing unambiguous truncation */
391 struct cmd_spec *cmdtable_lookup(const char *s)
392 {
393 struct cmd_spec *cmd = NULL;
394 size_t len;
395 int i, count = 0;
397 if (!s)
398 return NULL;
399 len = strlen(s);
400 for (i = 0; i < cmdtable_len; i++) {
401 if (!strncmp(s, cmd_table[i].cmd_name, len)) {
402 cmd = &cmd_table[i];
403 /* Take an exact match, even if it also prefixes another command */
404 if (len == strlen(cmd->cmd_name))
405 return cmd;
406 count++;
407 }
408 }
409 return (count == 1) ? cmd : NULL;
410 }