]>
Commit | Line | Data |
---|---|---|
7282a033 | 1 | #include "qemu-common.h" |
2f792016 | 2 | #include "qemu-error.h" |
7282a033 GH |
3 | #include "qemu-option.h" |
4 | #include "qemu-config.h" | |
d0fef6fb | 5 | #include "hw/qdev.h" |
2ac20613 | 6 | #include "error.h" |
7282a033 | 7 | |
3329f07b | 8 | static QemuOptsList qemu_drive_opts = { |
7282a033 | 9 | .name = "drive", |
72cf2d4f | 10 | .head = QTAILQ_HEAD_INITIALIZER(qemu_drive_opts.head), |
7282a033 GH |
11 | .desc = { |
12 | { | |
13 | .name = "bus", | |
14 | .type = QEMU_OPT_NUMBER, | |
15 | .help = "bus number", | |
16 | },{ | |
17 | .name = "unit", | |
18 | .type = QEMU_OPT_NUMBER, | |
19 | .help = "unit number (i.e. lun for scsi)", | |
20 | },{ | |
21 | .name = "if", | |
22 | .type = QEMU_OPT_STRING, | |
23 | .help = "interface (ide, scsi, sd, mtd, floppy, pflash, virtio)", | |
24 | },{ | |
25 | .name = "index", | |
26 | .type = QEMU_OPT_NUMBER, | |
69d7e218 | 27 | .help = "index number", |
7282a033 GH |
28 | },{ |
29 | .name = "cyls", | |
30 | .type = QEMU_OPT_NUMBER, | |
31 | .help = "number of cylinders (ide disk geometry)", | |
32 | },{ | |
33 | .name = "heads", | |
34 | .type = QEMU_OPT_NUMBER, | |
35 | .help = "number of heads (ide disk geometry)", | |
36 | },{ | |
37 | .name = "secs", | |
38 | .type = QEMU_OPT_NUMBER, | |
39 | .help = "number of sectors (ide disk geometry)", | |
40 | },{ | |
41 | .name = "trans", | |
42 | .type = QEMU_OPT_STRING, | |
43 | .help = "chs translation (auto, lba. none)", | |
44 | },{ | |
45 | .name = "media", | |
46 | .type = QEMU_OPT_STRING, | |
47 | .help = "media type (disk, cdrom)", | |
48 | },{ | |
49 | .name = "snapshot", | |
50 | .type = QEMU_OPT_BOOL, | |
69d7e218 | 51 | .help = "enable/disable snapshot mode", |
7282a033 GH |
52 | },{ |
53 | .name = "file", | |
54 | .type = QEMU_OPT_STRING, | |
55 | .help = "disk image", | |
56 | },{ | |
57 | .name = "cache", | |
58 | .type = QEMU_OPT_STRING, | |
92196b2f SH |
59 | .help = "host cache usage (none, writeback, writethrough, " |
60 | "directsync, unsafe)", | |
5c6c3a6c CH |
61 | },{ |
62 | .name = "aio", | |
63 | .type = QEMU_OPT_STRING, | |
64 | .help = "host AIO implementation (threads, native)", | |
7282a033 GH |
65 | },{ |
66 | .name = "format", | |
67 | .type = QEMU_OPT_STRING, | |
68 | .help = "disk format (raw, qcow2, ...)", | |
69 | },{ | |
70 | .name = "serial", | |
71 | .type = QEMU_OPT_STRING, | |
69d7e218 | 72 | .help = "disk serial number", |
e9b2e818 KW |
73 | },{ |
74 | .name = "rerror", | |
75 | .type = QEMU_OPT_STRING, | |
69d7e218 | 76 | .help = "read error action", |
7282a033 GH |
77 | },{ |
78 | .name = "werror", | |
79 | .type = QEMU_OPT_STRING, | |
69d7e218 | 80 | .help = "write error action", |
7282a033 GH |
81 | },{ |
82 | .name = "addr", | |
83 | .type = QEMU_OPT_STRING, | |
84 | .help = "pci address (virtio only)", | |
59f2689d NS |
85 | },{ |
86 | .name = "readonly", | |
87 | .type = QEMU_OPT_BOOL, | |
69d7e218 | 88 | .help = "open drive file as read-only", |
0563e191 ZYW |
89 | },{ |
90 | .name = "iops", | |
91 | .type = QEMU_OPT_NUMBER, | |
92 | .help = "limit total I/O operations per second", | |
93 | },{ | |
94 | .name = "iops_rd", | |
95 | .type = QEMU_OPT_NUMBER, | |
96 | .help = "limit read operations per second", | |
97 | },{ | |
98 | .name = "iops_wr", | |
99 | .type = QEMU_OPT_NUMBER, | |
100 | .help = "limit write operations per second", | |
101 | },{ | |
102 | .name = "bps", | |
103 | .type = QEMU_OPT_NUMBER, | |
104 | .help = "limit total bytes per second", | |
105 | },{ | |
106 | .name = "bps_rd", | |
107 | .type = QEMU_OPT_NUMBER, | |
108 | .help = "limit read bytes per second", | |
109 | },{ | |
110 | .name = "bps_wr", | |
111 | .type = QEMU_OPT_NUMBER, | |
112 | .help = "limit write bytes per second", | |
fb0490f6 SH |
113 | },{ |
114 | .name = "copy-on-read", | |
115 | .type = QEMU_OPT_BOOL, | |
116 | .help = "copy read data from backing file into image file", | |
0d92d17a JK |
117 | },{ |
118 | .name = "boot", | |
119 | .type = QEMU_OPT_BOOL, | |
120 | .help = "(deprecated, ignored)", | |
7282a033 | 121 | }, |
26056e0c | 122 | { /* end of list */ } |
7282a033 GH |
123 | }, |
124 | }; | |
125 | ||
f9dadc98 RS |
126 | static QemuOptsList qemu_iscsi_opts = { |
127 | .name = "iscsi", | |
128 | .head = QTAILQ_HEAD_INITIALIZER(qemu_iscsi_opts.head), | |
129 | .desc = { | |
130 | { | |
131 | .name = "user", | |
132 | .type = QEMU_OPT_STRING, | |
133 | .help = "username for CHAP authentication to target", | |
134 | },{ | |
135 | .name = "password", | |
136 | .type = QEMU_OPT_STRING, | |
137 | .help = "password for CHAP authentication to target", | |
138 | },{ | |
139 | .name = "header-digest", | |
140 | .type = QEMU_OPT_STRING, | |
141 | .help = "HeaderDigest setting. " | |
142 | "{CRC32C|CRC32C-NONE|NONE-CRC32C|NONE}", | |
143 | },{ | |
144 | .name = "initiator-name", | |
145 | .type = QEMU_OPT_STRING, | |
146 | .help = "Initiator iqn name to use when connecting", | |
147 | }, | |
148 | { /* end of list */ } | |
149 | }, | |
150 | }; | |
151 | ||
3329f07b | 152 | static QemuOptsList qemu_chardev_opts = { |
191bc01b | 153 | .name = "chardev", |
8212c64f | 154 | .implied_opt_name = "backend", |
72cf2d4f | 155 | .head = QTAILQ_HEAD_INITIALIZER(qemu_chardev_opts.head), |
191bc01b | 156 | .desc = { |
7d31544f GH |
157 | { |
158 | .name = "backend", | |
159 | .type = QEMU_OPT_STRING, | |
160 | },{ | |
161 | .name = "path", | |
162 | .type = QEMU_OPT_STRING, | |
aeb2c47a GH |
163 | },{ |
164 | .name = "host", | |
165 | .type = QEMU_OPT_STRING, | |
166 | },{ | |
167 | .name = "port", | |
168 | .type = QEMU_OPT_STRING, | |
7e1b35b4 GH |
169 | },{ |
170 | .name = "localaddr", | |
171 | .type = QEMU_OPT_STRING, | |
172 | },{ | |
173 | .name = "localport", | |
174 | .type = QEMU_OPT_STRING, | |
aeb2c47a GH |
175 | },{ |
176 | .name = "to", | |
177 | .type = QEMU_OPT_NUMBER, | |
178 | },{ | |
179 | .name = "ipv4", | |
180 | .type = QEMU_OPT_BOOL, | |
181 | },{ | |
182 | .name = "ipv6", | |
183 | .type = QEMU_OPT_BOOL, | |
184 | },{ | |
185 | .name = "wait", | |
186 | .type = QEMU_OPT_BOOL, | |
187 | },{ | |
188 | .name = "server", | |
189 | .type = QEMU_OPT_BOOL, | |
190 | },{ | |
191 | .name = "delay", | |
192 | .type = QEMU_OPT_BOOL, | |
193 | },{ | |
194 | .name = "telnet", | |
195 | .type = QEMU_OPT_BOOL, | |
6ea314d9 GH |
196 | },{ |
197 | .name = "width", | |
198 | .type = QEMU_OPT_NUMBER, | |
199 | },{ | |
200 | .name = "height", | |
201 | .type = QEMU_OPT_NUMBER, | |
202 | },{ | |
203 | .name = "cols", | |
204 | .type = QEMU_OPT_NUMBER, | |
205 | },{ | |
206 | .name = "rows", | |
207 | .type = QEMU_OPT_NUMBER, | |
c845f401 GH |
208 | },{ |
209 | .name = "mux", | |
210 | .type = QEMU_OPT_BOOL, | |
5989020b KK |
211 | },{ |
212 | .name = "signal", | |
213 | .type = QEMU_OPT_BOOL, | |
cbcc6336 AL |
214 | },{ |
215 | .name = "name", | |
216 | .type = QEMU_OPT_STRING, | |
217 | },{ | |
218 | .name = "debug", | |
219 | .type = QEMU_OPT_NUMBER, | |
7d31544f | 220 | }, |
26056e0c | 221 | { /* end of list */ } |
191bc01b GH |
222 | }, |
223 | }; | |
224 | ||
74db920c GS |
225 | QemuOptsList qemu_fsdev_opts = { |
226 | .name = "fsdev", | |
fbcbf101 | 227 | .implied_opt_name = "fsdriver", |
74db920c GS |
228 | .head = QTAILQ_HEAD_INITIALIZER(qemu_fsdev_opts.head), |
229 | .desc = { | |
230 | { | |
fbcbf101 | 231 | .name = "fsdriver", |
74db920c GS |
232 | .type = QEMU_OPT_STRING, |
233 | }, { | |
234 | .name = "path", | |
235 | .type = QEMU_OPT_STRING, | |
9ce56db6 VJ |
236 | }, { |
237 | .name = "security_model", | |
238 | .type = QEMU_OPT_STRING, | |
d3ab98e6 AK |
239 | }, { |
240 | .name = "writeout", | |
241 | .type = QEMU_OPT_STRING, | |
2c74c2cb MK |
242 | }, { |
243 | .name = "readonly", | |
244 | .type = QEMU_OPT_BOOL, | |
84a87cc4 MK |
245 | |
246 | }, { | |
247 | .name = "socket", | |
248 | .type = QEMU_OPT_STRING, | |
4c793dda MK |
249 | }, { |
250 | .name = "sock_fd", | |
251 | .type = QEMU_OPT_NUMBER, | |
74db920c | 252 | }, |
2c74c2cb | 253 | |
74db920c GS |
254 | { /*End of list */ } |
255 | }, | |
256 | }; | |
74db920c | 257 | |
3d54abc7 GS |
258 | QemuOptsList qemu_virtfs_opts = { |
259 | .name = "virtfs", | |
fbcbf101 | 260 | .implied_opt_name = "fsdriver", |
3d54abc7 GS |
261 | .head = QTAILQ_HEAD_INITIALIZER(qemu_virtfs_opts.head), |
262 | .desc = { | |
263 | { | |
fbcbf101 | 264 | .name = "fsdriver", |
3d54abc7 GS |
265 | .type = QEMU_OPT_STRING, |
266 | }, { | |
267 | .name = "path", | |
268 | .type = QEMU_OPT_STRING, | |
269 | }, { | |
270 | .name = "mount_tag", | |
271 | .type = QEMU_OPT_STRING, | |
9ce56db6 VJ |
272 | }, { |
273 | .name = "security_model", | |
274 | .type = QEMU_OPT_STRING, | |
d3ab98e6 AK |
275 | }, { |
276 | .name = "writeout", | |
277 | .type = QEMU_OPT_STRING, | |
2c74c2cb MK |
278 | }, { |
279 | .name = "readonly", | |
280 | .type = QEMU_OPT_BOOL, | |
84a87cc4 MK |
281 | }, { |
282 | .name = "socket", | |
283 | .type = QEMU_OPT_STRING, | |
4c793dda MK |
284 | }, { |
285 | .name = "sock_fd", | |
286 | .type = QEMU_OPT_NUMBER, | |
3d54abc7 GS |
287 | }, |
288 | ||
289 | { /*End of list */ } | |
290 | }, | |
291 | }; | |
3d54abc7 | 292 | |
3329f07b | 293 | static QemuOptsList qemu_device_opts = { |
f31d07d1 | 294 | .name = "device", |
8212c64f | 295 | .implied_opt_name = "driver", |
72cf2d4f | 296 | .head = QTAILQ_HEAD_INITIALIZER(qemu_device_opts.head), |
f31d07d1 GH |
297 | .desc = { |
298 | /* | |
299 | * no elements => accept any | |
300 | * sanity checking will happen later | |
301 | * when setting device properties | |
302 | */ | |
26056e0c | 303 | { /* end of list */ } |
f31d07d1 GH |
304 | }, |
305 | }; | |
306 | ||
3329f07b | 307 | static QemuOptsList qemu_netdev_opts = { |
a1ea458f | 308 | .name = "netdev", |
8212c64f | 309 | .implied_opt_name = "type", |
a1ea458f MM |
310 | .head = QTAILQ_HEAD_INITIALIZER(qemu_netdev_opts.head), |
311 | .desc = { | |
312 | /* | |
313 | * no elements => accept any params | |
314 | * validation will happen later | |
315 | */ | |
316 | { /* end of list */ } | |
317 | }, | |
318 | }; | |
319 | ||
3329f07b | 320 | static QemuOptsList qemu_net_opts = { |
8119b33d | 321 | .name = "net", |
8212c64f | 322 | .implied_opt_name = "type", |
8119b33d MM |
323 | .head = QTAILQ_HEAD_INITIALIZER(qemu_net_opts.head), |
324 | .desc = { | |
325 | /* | |
326 | * no elements => accept any params | |
327 | * validation will happen later | |
328 | */ | |
329 | { /* end of list */ } | |
330 | }, | |
331 | }; | |
332 | ||
3329f07b | 333 | static QemuOptsList qemu_rtc_opts = { |
1ed2fc1f JK |
334 | .name = "rtc", |
335 | .head = QTAILQ_HEAD_INITIALIZER(qemu_rtc_opts.head), | |
336 | .desc = { | |
337 | { | |
338 | .name = "base", | |
339 | .type = QEMU_OPT_STRING, | |
6875204c JK |
340 | },{ |
341 | .name = "clock", | |
342 | .type = QEMU_OPT_STRING, | |
1ed2fc1f JK |
343 | },{ |
344 | .name = "driftfix", | |
345 | .type = QEMU_OPT_STRING, | |
1ed2fc1f | 346 | }, |
26056e0c | 347 | { /* end of list */ } |
1ed2fc1f JK |
348 | }, |
349 | }; | |
350 | ||
3329f07b | 351 | static QemuOptsList qemu_global_opts = { |
d0fef6fb GH |
352 | .name = "global", |
353 | .head = QTAILQ_HEAD_INITIALIZER(qemu_global_opts.head), | |
354 | .desc = { | |
355 | { | |
356 | .name = "driver", | |
357 | .type = QEMU_OPT_STRING, | |
358 | },{ | |
359 | .name = "property", | |
360 | .type = QEMU_OPT_STRING, | |
361 | },{ | |
362 | .name = "value", | |
363 | .type = QEMU_OPT_STRING, | |
364 | }, | |
26056e0c | 365 | { /* end of list */ } |
d0fef6fb GH |
366 | }, |
367 | }; | |
368 | ||
7d76ad4f EO |
369 | QemuOptsList qemu_sandbox_opts = { |
370 | .name = "sandbox", | |
371 | .implied_opt_name = "enable", | |
372 | .head = QTAILQ_HEAD_INITIALIZER(qemu_sandbox_opts.head), | |
373 | .desc = { | |
374 | { | |
375 | .name = "enable", | |
376 | .type = QEMU_OPT_BOOL, | |
377 | }, | |
378 | { /* end of list */ } | |
379 | }, | |
380 | }; | |
381 | ||
3329f07b | 382 | static QemuOptsList qemu_mon_opts = { |
88589343 | 383 | .name = "mon", |
8212c64f | 384 | .implied_opt_name = "chardev", |
88589343 GH |
385 | .head = QTAILQ_HEAD_INITIALIZER(qemu_mon_opts.head), |
386 | .desc = { | |
387 | { | |
388 | .name = "mode", | |
389 | .type = QEMU_OPT_STRING, | |
390 | },{ | |
391 | .name = "chardev", | |
392 | .type = QEMU_OPT_STRING, | |
393 | },{ | |
394 | .name = "default", | |
395 | .type = QEMU_OPT_BOOL, | |
39eaab9a DB |
396 | },{ |
397 | .name = "pretty", | |
398 | .type = QEMU_OPT_BOOL, | |
88589343 | 399 | }, |
26056e0c | 400 | { /* end of list */ } |
88589343 GH |
401 | }, |
402 | }; | |
403 | ||
ab6540d5 PS |
404 | static QemuOptsList qemu_trace_opts = { |
405 | .name = "trace", | |
406 | .implied_opt_name = "trace", | |
407 | .head = QTAILQ_HEAD_INITIALIZER(qemu_trace_opts.head), | |
408 | .desc = { | |
409 | { | |
23d15e86 LV |
410 | .name = "events", |
411 | .type = QEMU_OPT_STRING, | |
412 | },{ | |
ab6540d5 PS |
413 | .name = "file", |
414 | .type = QEMU_OPT_STRING, | |
415 | }, | |
44bd6907 | 416 | { /* end of list */ } |
ab6540d5 PS |
417 | }, |
418 | }; | |
ab6540d5 | 419 | |
29b0040b GH |
420 | QemuOptsList qemu_spice_opts = { |
421 | .name = "spice", | |
422 | .head = QTAILQ_HEAD_INITIALIZER(qemu_spice_opts.head), | |
423 | .desc = { | |
424 | { | |
425 | .name = "port", | |
426 | .type = QEMU_OPT_NUMBER, | |
c448e855 GH |
427 | },{ |
428 | .name = "tls-port", | |
429 | .type = QEMU_OPT_NUMBER, | |
333b0eeb GH |
430 | },{ |
431 | .name = "addr", | |
432 | .type = QEMU_OPT_STRING, | |
433 | },{ | |
434 | .name = "ipv4", | |
435 | .type = QEMU_OPT_BOOL, | |
436 | },{ | |
437 | .name = "ipv6", | |
438 | .type = QEMU_OPT_BOOL, | |
29b0040b GH |
439 | },{ |
440 | .name = "password", | |
441 | .type = QEMU_OPT_STRING, | |
442 | },{ | |
443 | .name = "disable-ticketing", | |
444 | .type = QEMU_OPT_BOOL, | |
d4970b07 HG |
445 | },{ |
446 | .name = "disable-copy-paste", | |
447 | .type = QEMU_OPT_BOOL, | |
48b3ed0a MAL |
448 | },{ |
449 | .name = "sasl", | |
450 | .type = QEMU_OPT_BOOL, | |
c448e855 GH |
451 | },{ |
452 | .name = "x509-dir", | |
453 | .type = QEMU_OPT_STRING, | |
454 | },{ | |
455 | .name = "x509-key-file", | |
456 | .type = QEMU_OPT_STRING, | |
457 | },{ | |
458 | .name = "x509-key-password", | |
459 | .type = QEMU_OPT_STRING, | |
460 | },{ | |
461 | .name = "x509-cert-file", | |
462 | .type = QEMU_OPT_STRING, | |
463 | },{ | |
464 | .name = "x509-cacert-file", | |
465 | .type = QEMU_OPT_STRING, | |
466 | },{ | |
467 | .name = "x509-dh-key-file", | |
468 | .type = QEMU_OPT_STRING, | |
469 | },{ | |
470 | .name = "tls-ciphers", | |
471 | .type = QEMU_OPT_STRING, | |
17b6dea0 GH |
472 | },{ |
473 | .name = "tls-channel", | |
474 | .type = QEMU_OPT_STRING, | |
475 | },{ | |
476 | .name = "plaintext-channel", | |
477 | .type = QEMU_OPT_STRING, | |
9f04e09e YH |
478 | },{ |
479 | .name = "image-compression", | |
480 | .type = QEMU_OPT_STRING, | |
481 | },{ | |
482 | .name = "jpeg-wan-compression", | |
483 | .type = QEMU_OPT_STRING, | |
484 | },{ | |
485 | .name = "zlib-glz-wan-compression", | |
486 | .type = QEMU_OPT_STRING, | |
84a23f25 GH |
487 | },{ |
488 | .name = "streaming-video", | |
489 | .type = QEMU_OPT_STRING, | |
490 | },{ | |
491 | .name = "agent-mouse", | |
492 | .type = QEMU_OPT_BOOL, | |
493 | },{ | |
494 | .name = "playback-compression", | |
495 | .type = QEMU_OPT_BOOL, | |
8c957053 YH |
496 | }, { |
497 | .name = "seamless-migration", | |
498 | .type = QEMU_OPT_BOOL, | |
29b0040b | 499 | }, |
44bd6907 | 500 | { /* end of list */ } |
29b0040b GH |
501 | }, |
502 | }; | |
503 | ||
2e55e842 GN |
504 | QemuOptsList qemu_option_rom_opts = { |
505 | .name = "option-rom", | |
506 | .implied_opt_name = "romfile", | |
507 | .head = QTAILQ_HEAD_INITIALIZER(qemu_option_rom_opts.head), | |
508 | .desc = { | |
509 | { | |
510 | .name = "bootindex", | |
511 | .type = QEMU_OPT_NUMBER, | |
512 | }, { | |
513 | .name = "romfile", | |
514 | .type = QEMU_OPT_STRING, | |
515 | }, | |
44bd6907 | 516 | { /* end of list */ } |
2e55e842 GN |
517 | }, |
518 | }; | |
519 | ||
303d4e86 AP |
520 | static QemuOptsList qemu_machine_opts = { |
521 | .name = "machine", | |
9052ea6b | 522 | .implied_opt_name = "type", |
9de36b1a | 523 | .merge_lists = true, |
303d4e86 AP |
524 | .head = QTAILQ_HEAD_INITIALIZER(qemu_machine_opts.head), |
525 | .desc = { | |
526 | { | |
9052ea6b JK |
527 | .name = "type", |
528 | .type = QEMU_OPT_STRING, | |
529 | .help = "emulated machine" | |
530 | }, { | |
303d4e86 AP |
531 | .name = "accel", |
532 | .type = QEMU_OPT_STRING, | |
533 | .help = "accelerator list", | |
6a48ffaa JK |
534 | }, { |
535 | .name = "kernel_irqchip", | |
536 | .type = QEMU_OPT_BOOL, | |
537 | .help = "use KVM in-kernel irqchip", | |
39d6960a JK |
538 | }, { |
539 | .name = "kvm_shadow_mem", | |
540 | .type = QEMU_OPT_SIZE, | |
541 | .help = "KVM shadow MMU size", | |
a0abe474 PM |
542 | }, { |
543 | .name = "kernel", | |
544 | .type = QEMU_OPT_STRING, | |
545 | .help = "Linux kernel image file", | |
546 | }, { | |
547 | .name = "initrd", | |
548 | .type = QEMU_OPT_STRING, | |
549 | .help = "Linux initial ramdisk file", | |
550 | }, { | |
551 | .name = "append", | |
552 | .type = QEMU_OPT_STRING, | |
553 | .help = "Linux kernel command line", | |
412beee6 GL |
554 | }, { |
555 | .name = "dtb", | |
556 | .type = QEMU_OPT_STRING, | |
557 | .help = "Linux kernel device tree file", | |
25b42708 AG |
558 | }, { |
559 | .name = "dumpdtb", | |
560 | .type = QEMU_OPT_STRING, | |
561 | .help = "Dump current dtb to a file and quit", | |
4b1b1c89 AG |
562 | }, { |
563 | .name = "phandle_start", | |
564 | .type = QEMU_OPT_STRING, | |
565 | .help = "The first phandle ID we may generate dynamically", | |
caedc737 AG |
566 | }, { |
567 | .name = "dt_compatible", | |
568 | .type = QEMU_OPT_STRING, | |
569 | .help = "Overrides the \"compatible\" property of the dt root node", | |
ddb97f1d JB |
570 | }, { |
571 | .name = "dump-guest-core", | |
572 | .type = QEMU_OPT_BOOL, | |
573 | .help = "Include guest memory in a core dump", | |
8490fc78 LC |
574 | }, { |
575 | .name = "mem-merge", | |
576 | .type = QEMU_OPT_BOOL, | |
577 | .help = "enable/disable memory merge support", | |
094b287f LZ |
578 | },{ |
579 | .name = "usb", | |
580 | .type = QEMU_OPT_BOOL, | |
581 | .help = "Set on/off to enable/disable usb", | |
639e8102 DG |
582 | }, { |
583 | .name = "nvram", | |
584 | .type = QEMU_OPT_STRING, | |
585 | .help = "Drive backing persistent NVRAM", | |
303d4e86 AP |
586 | }, |
587 | { /* End of list */ } | |
588 | }, | |
589 | }; | |
590 | ||
3d3b8303 WX |
591 | QemuOptsList qemu_boot_opts = { |
592 | .name = "boot-opts", | |
593 | .head = QTAILQ_HEAD_INITIALIZER(qemu_boot_opts.head), | |
594 | .desc = { | |
595 | /* the three names below are not used now */ | |
596 | { | |
597 | .name = "order", | |
598 | .type = QEMU_OPT_STRING, | |
599 | }, { | |
600 | .name = "once", | |
601 | .type = QEMU_OPT_STRING, | |
602 | }, { | |
603 | .name = "menu", | |
604 | .type = QEMU_OPT_STRING, | |
605 | /* following are really used */ | |
606 | }, { | |
607 | .name = "splash", | |
608 | .type = QEMU_OPT_STRING, | |
609 | }, { | |
610 | .name = "splash-time", | |
611 | .type = QEMU_OPT_STRING, | |
ac05f349 AK |
612 | }, { |
613 | .name = "reboot-timeout", | |
614 | .type = QEMU_OPT_STRING, | |
3d3b8303 WX |
615 | }, |
616 | { /*End of list */ } | |
617 | }, | |
618 | }; | |
619 | ||
587ed6be CB |
620 | static QemuOptsList qemu_add_fd_opts = { |
621 | .name = "add-fd", | |
622 | .head = QTAILQ_HEAD_INITIALIZER(qemu_add_fd_opts.head), | |
623 | .desc = { | |
624 | { | |
625 | .name = "fd", | |
626 | .type = QEMU_OPT_NUMBER, | |
627 | .help = "file descriptor of which a duplicate is added to fd set", | |
628 | },{ | |
629 | .name = "set", | |
630 | .type = QEMU_OPT_NUMBER, | |
631 | .help = "ID of the fd set to add fd to", | |
632 | },{ | |
633 | .name = "opaque", | |
634 | .type = QEMU_OPT_STRING, | |
635 | .help = "free-form string used to describe fd", | |
636 | }, | |
637 | { /* end of list */ } | |
638 | }, | |
639 | }; | |
640 | ||
68d98d3e AL |
641 | static QemuOptsList qemu_object_opts = { |
642 | .name = "object", | |
643 | .implied_opt_name = "qom-type", | |
644 | .head = QTAILQ_HEAD_INITIALIZER(qemu_object_opts.head), | |
645 | .desc = { | |
646 | { } | |
647 | }, | |
648 | }; | |
649 | ||
dfe795e7 | 650 | static QemuOptsList *vm_config_groups[32] = { |
d058fe03 | 651 | &qemu_drive_opts, |
191bc01b | 652 | &qemu_chardev_opts, |
f31d07d1 | 653 | &qemu_device_opts, |
a1ea458f | 654 | &qemu_netdev_opts, |
8119b33d | 655 | &qemu_net_opts, |
5fdfbf7e | 656 | &qemu_rtc_opts, |
d0fef6fb | 657 | &qemu_global_opts, |
88589343 | 658 | &qemu_mon_opts, |
ab6540d5 | 659 | &qemu_trace_opts, |
2e55e842 | 660 | &qemu_option_rom_opts, |
303d4e86 | 661 | &qemu_machine_opts, |
3d3b8303 | 662 | &qemu_boot_opts, |
f9dadc98 | 663 | &qemu_iscsi_opts, |
7d76ad4f | 664 | &qemu_sandbox_opts, |
587ed6be | 665 | &qemu_add_fd_opts, |
68d98d3e | 666 | &qemu_object_opts, |
d058fe03 GH |
667 | NULL, |
668 | }; | |
669 | ||
2ac20613 LC |
670 | static QemuOptsList *find_list(QemuOptsList **lists, const char *group, |
671 | Error **errp) | |
ddc97855 GH |
672 | { |
673 | int i; | |
674 | ||
675 | for (i = 0; lists[i] != NULL; i++) { | |
676 | if (strcmp(lists[i]->name, group) == 0) | |
677 | break; | |
678 | } | |
679 | if (lists[i] == NULL) { | |
2ac20613 | 680 | error_set(errp, QERR_INVALID_OPTION_GROUP, group); |
ddc97855 GH |
681 | } |
682 | return lists[i]; | |
683 | } | |
684 | ||
490b648e KW |
685 | QemuOptsList *qemu_find_opts(const char *group) |
686 | { | |
2ac20613 LC |
687 | QemuOptsList *ret; |
688 | Error *local_err = NULL; | |
689 | ||
690 | ret = find_list(vm_config_groups, group, &local_err); | |
691 | if (error_is_set(&local_err)) { | |
692 | error_report("%s\n", error_get_pretty(local_err)); | |
693 | error_free(local_err); | |
694 | } | |
695 | ||
696 | return ret; | |
490b648e KW |
697 | } |
698 | ||
60d5666f LC |
699 | QemuOptsList *qemu_find_opts_err(const char *group, Error **errp) |
700 | { | |
701 | return find_list(vm_config_groups, group, errp); | |
702 | } | |
703 | ||
dfe795e7 GH |
704 | void qemu_add_opts(QemuOptsList *list) |
705 | { | |
706 | int entries, i; | |
707 | ||
708 | entries = ARRAY_SIZE(vm_config_groups); | |
709 | entries--; /* keep list NULL terminated */ | |
710 | for (i = 0; i < entries; i++) { | |
711 | if (vm_config_groups[i] == NULL) { | |
712 | vm_config_groups[i] = list; | |
713 | return; | |
714 | } | |
715 | } | |
716 | fprintf(stderr, "ran out of space in vm_config_groups"); | |
717 | abort(); | |
718 | } | |
719 | ||
d058fe03 GH |
720 | int qemu_set_option(const char *str) |
721 | { | |
722 | char group[64], id[64], arg[64]; | |
ddc97855 | 723 | QemuOptsList *list; |
d058fe03 | 724 | QemuOpts *opts; |
ddc97855 | 725 | int rc, offset; |
d058fe03 GH |
726 | |
727 | rc = sscanf(str, "%63[^.].%63[^.].%63[^=]%n", group, id, arg, &offset); | |
728 | if (rc < 3 || str[offset] != '=') { | |
1ecda02b | 729 | error_report("can't parse: \"%s\"", str); |
d058fe03 GH |
730 | return -1; |
731 | } | |
732 | ||
304329ee | 733 | list = qemu_find_opts(group); |
ddc97855 | 734 | if (list == NULL) { |
d058fe03 GH |
735 | return -1; |
736 | } | |
737 | ||
ddc97855 | 738 | opts = qemu_opts_find(list, id); |
d058fe03 | 739 | if (!opts) { |
1ecda02b MA |
740 | error_report("there is no %s \"%s\" defined", |
741 | list->name, id); | |
d058fe03 GH |
742 | return -1; |
743 | } | |
744 | ||
3df04ac3 | 745 | if (qemu_opt_set(opts, arg, str+offset+1) == -1) { |
d058fe03 GH |
746 | return -1; |
747 | } | |
748 | return 0; | |
749 | } | |
750 | ||
d0fef6fb GH |
751 | int qemu_global_option(const char *str) |
752 | { | |
753 | char driver[64], property[64]; | |
754 | QemuOpts *opts; | |
755 | int rc, offset; | |
756 | ||
757 | rc = sscanf(str, "%63[^.].%63[^=]%n", driver, property, &offset); | |
758 | if (rc < 2 || str[offset] != '=') { | |
1ecda02b | 759 | error_report("can't parse: \"%s\"", str); |
d0fef6fb GH |
760 | return -1; |
761 | } | |
762 | ||
e478b448 | 763 | opts = qemu_opts_create_nofail(&qemu_global_opts); |
d0fef6fb GH |
764 | qemu_opt_set(opts, "driver", driver); |
765 | qemu_opt_set(opts, "property", property); | |
766 | qemu_opt_set(opts, "value", str+offset+1); | |
767 | return 0; | |
768 | } | |
769 | ||
9d993394 GH |
770 | struct ConfigWriteData { |
771 | QemuOptsList *list; | |
772 | FILE *fp; | |
773 | }; | |
774 | ||
775 | static int config_write_opt(const char *name, const char *value, void *opaque) | |
776 | { | |
777 | struct ConfigWriteData *data = opaque; | |
778 | ||
779 | fprintf(data->fp, " %s = \"%s\"\n", name, value); | |
780 | return 0; | |
781 | } | |
782 | ||
783 | static int config_write_opts(QemuOpts *opts, void *opaque) | |
784 | { | |
785 | struct ConfigWriteData *data = opaque; | |
786 | const char *id = qemu_opts_id(opts); | |
787 | ||
788 | if (id) { | |
789 | fprintf(data->fp, "[%s \"%s\"]\n", data->list->name, id); | |
790 | } else { | |
791 | fprintf(data->fp, "[%s]\n", data->list->name); | |
792 | } | |
793 | qemu_opt_foreach(opts, config_write_opt, data, 0); | |
794 | fprintf(data->fp, "\n"); | |
795 | return 0; | |
796 | } | |
797 | ||
798 | void qemu_config_write(FILE *fp) | |
799 | { | |
800 | struct ConfigWriteData data = { .fp = fp }; | |
490b648e | 801 | QemuOptsList **lists = vm_config_groups; |
9d993394 GH |
802 | int i; |
803 | ||
804 | fprintf(fp, "# qemu config file\n\n"); | |
805 | for (i = 0; lists[i] != NULL; i++) { | |
806 | data.list = lists[i]; | |
807 | qemu_opts_foreach(data.list, config_write_opts, &data, 0); | |
808 | } | |
809 | } | |
42262ba8 | 810 | |
490b648e | 811 | int qemu_config_parse(FILE *fp, QemuOptsList **lists, const char *fname) |
42262ba8 GH |
812 | { |
813 | char line[1024], group[64], id[64], arg[64], value[1024]; | |
cf5a65aa | 814 | Location loc; |
42262ba8 | 815 | QemuOptsList *list = NULL; |
2ac20613 | 816 | Error *local_err = NULL; |
42262ba8 | 817 | QemuOpts *opts = NULL; |
cf5a65aa | 818 | int res = -1, lno = 0; |
42262ba8 | 819 | |
cf5a65aa | 820 | loc_push_none(&loc); |
42262ba8 | 821 | while (fgets(line, sizeof(line), fp) != NULL) { |
cf5a65aa | 822 | loc_set_file(fname, ++lno); |
42262ba8 GH |
823 | if (line[0] == '\n') { |
824 | /* skip empty lines */ | |
825 | continue; | |
826 | } | |
827 | if (line[0] == '#') { | |
828 | /* comment */ | |
829 | continue; | |
830 | } | |
831 | if (sscanf(line, "[%63s \"%63[^\"]\"]", group, id) == 2) { | |
832 | /* group with id */ | |
2ac20613 LC |
833 | list = find_list(lists, group, &local_err); |
834 | if (error_is_set(&local_err)) { | |
835 | error_report("%s\n", error_get_pretty(local_err)); | |
836 | error_free(local_err); | |
cf5a65aa | 837 | goto out; |
2ac20613 | 838 | } |
8be7e7e4 | 839 | opts = qemu_opts_create(list, id, 1, NULL); |
42262ba8 GH |
840 | continue; |
841 | } | |
842 | if (sscanf(line, "[%63[^]]]", group) == 1) { | |
843 | /* group without id */ | |
2ac20613 LC |
844 | list = find_list(lists, group, &local_err); |
845 | if (error_is_set(&local_err)) { | |
846 | error_report("%s\n", error_get_pretty(local_err)); | |
847 | error_free(local_err); | |
cf5a65aa | 848 | goto out; |
2ac20613 | 849 | } |
e478b448 | 850 | opts = qemu_opts_create_nofail(list); |
42262ba8 GH |
851 | continue; |
852 | } | |
853 | if (sscanf(line, " %63s = \"%1023[^\"]\"", arg, value) == 2) { | |
854 | /* arg = value */ | |
855 | if (opts == NULL) { | |
cf5a65aa MA |
856 | error_report("no group defined"); |
857 | goto out; | |
42262ba8 GH |
858 | } |
859 | if (qemu_opt_set(opts, arg, value) != 0) { | |
cf5a65aa | 860 | goto out; |
42262ba8 GH |
861 | } |
862 | continue; | |
863 | } | |
cf5a65aa MA |
864 | error_report("parse error"); |
865 | goto out; | |
42262ba8 | 866 | } |
ef82516d MA |
867 | if (ferror(fp)) { |
868 | error_report("error reading file"); | |
869 | goto out; | |
870 | } | |
cf5a65aa MA |
871 | res = 0; |
872 | out: | |
873 | loc_pop(&loc); | |
874 | return res; | |
42262ba8 | 875 | } |
dcfb0939 KW |
876 | |
877 | int qemu_read_config_file(const char *filename) | |
878 | { | |
879 | FILE *f = fopen(filename, "r"); | |
019e78ba KW |
880 | int ret; |
881 | ||
dcfb0939 KW |
882 | if (f == NULL) { |
883 | return -errno; | |
884 | } | |
885 | ||
019e78ba | 886 | ret = qemu_config_parse(f, vm_config_groups, filename); |
dcfb0939 KW |
887 | fclose(f); |
888 | ||
019e78ba KW |
889 | if (ret == 0) { |
890 | return 0; | |
891 | } else { | |
892 | return -EINVAL; | |
893 | } | |
dcfb0939 | 894 | } |