]>
Commit | Line | Data |
---|---|---|
0824d6fc | 1 | /* |
80cabfad | 2 | * QEMU System Emulator |
5fafdf24 | 3 | * |
68d0f70e | 4 | * Copyright (c) 2003-2008 Fabrice Bellard |
5fafdf24 | 5 | * |
1df912cf FB |
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
7 | * of this software and associated documentation files (the "Software"), to deal | |
8 | * in the Software without restriction, including without limitation the rights | |
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
10 | * copies of the Software, and to permit persons to whom the Software is | |
11 | * furnished to do so, subject to the following conditions: | |
12 | * | |
13 | * The above copyright notice and this permission notice shall be included in | |
14 | * all copies or substantial portions of the Software. | |
15 | * | |
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | |
19 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | |
22 | * THE SOFTWARE. | |
0824d6fc | 23 | */ |
e688df6b | 24 | |
d38ea87a | 25 | #include "qemu/osdep.h" |
a8d25326 | 26 | #include "qemu-common.h" |
2c65db5e | 27 | #include "qemu/datadir.h" |
3dc54b0e | 28 | #include "qemu/units.h" |
c5e3c918 | 29 | #include "exec/cpu-common.h" |
fe48442f | 30 | #include "hw/boards.h" |
a27bd6c7 | 31 | #include "hw/qdev-properties.h" |
6dd75472 | 32 | #include "qapi/compat-policy.h" |
e688df6b | 33 | #include "qapi/error.h" |
2a5ad60b | 34 | #include "qapi/qmp/qdict.h" |
009ff893 | 35 | #include "qapi/qmp/qjson.h" |
67a1de0d | 36 | #include "qemu-version.h" |
f348b6d1 VB |
37 | #include "qemu/cutils.h" |
38 | #include "qemu/help_option.h" | |
cea25275 | 39 | #include "qemu/uuid.h" |
71e8a915 | 40 | #include "sysemu/reset.h" |
54d31236 | 41 | #include "sysemu/runstate.h" |
e6dba048 | 42 | #include "sysemu/runstate-action.h" |
9c17d615 | 43 | #include "sysemu/seccomp.h" |
14a48c1d | 44 | #include "sysemu/tcg.h" |
da278d58 | 45 | #include "sysemu/xen.h" |
452dfbef | 46 | |
d49b6836 | 47 | #include "qemu/error-report.h" |
c8897e8e | 48 | #include "qemu/sockets.h" |
940e43aa | 49 | #include "qemu/accel.h" |
511d2b14 | 50 | #include "hw/usb.h" |
0d09e41a | 51 | #include "hw/isa/isa.h" |
fb8b660e | 52 | #include "hw/scsi/scsi.h" |
866e2b37 | 53 | #include "hw/display/vga.h" |
0d09e41a | 54 | #include "sysemu/watchdog.h" |
a2eb5c0c | 55 | #include "hw/firmware/smbios.h" |
9f57061c | 56 | #include "hw/acpi/acpi.h" |
0d09e41a | 57 | #include "hw/xen/xen.h" |
45a50b16 | 58 | #include "hw/loader.h" |
b4a42f81 | 59 | #include "monitor/qdev.h" |
1422e32d | 60 | #include "net/net.h" |
68ac40d2 | 61 | #include "net/slirp.h" |
83c9089e | 62 | #include "monitor/monitor.h" |
28ecbaee | 63 | #include "ui/console.h" |
e0d2bd51 | 64 | #include "ui/input.h" |
9c17d615 | 65 | #include "sysemu/sysemu.h" |
e35704ba | 66 | #include "sysemu/numa.h" |
900c0ba3 | 67 | #include "sysemu/hostmem.h" |
022c62cb | 68 | #include "exec/gdbstub.h" |
1de7afc9 | 69 | #include "qemu/timer.h" |
8228e353 | 70 | #include "chardev/char.h" |
b33276a7 | 71 | #include "qemu/bitmap.h" |
03dd024f | 72 | #include "qemu/log.h" |
9c17d615 | 73 | #include "sysemu/blockdev.h" |
0d09e41a | 74 | #include "hw/block/block.h" |
c5e3c918 PB |
75 | #include "hw/i386/x86.h" |
76 | #include "hw/i386/pc.h" | |
7b1e1a22 | 77 | #include "migration/misc.h" |
5e22479a | 78 | #include "migration/snapshot.h" |
bdee56f5 | 79 | #include "sysemu/tpm.h" |
9c17d615 | 80 | #include "sysemu/dma.h" |
8a824e4d | 81 | #include "hw/audio/soundhw.h" |
511d2b14 | 82 | #include "audio/audio.h" |
4b4629d9 | 83 | #include "sysemu/cpus.h" |
740b1759 | 84 | #include "sysemu/cpu-timers.h" |
5821ebf9 | 85 | #include "migration/colo.h" |
1693c64c | 86 | #include "migration/postcopy-ram.h" |
9c17d615 | 87 | #include "sysemu/kvm.h" |
b0cb0a66 | 88 | #include "sysemu/hax.h" |
42e5f393 | 89 | #include "qapi/qobject-input-visitor.h" |
1de7afc9 PB |
90 | #include "qemu/option.h" |
91 | #include "qemu/config-file.h" | |
59a5264b | 92 | #include "qemu-options.h" |
1de7afc9 | 93 | #include "qemu/main-loop.h" |
758e8e38 | 94 | #ifdef CONFIG_VIRTFS |
74db920c GS |
95 | #include "fsdev/qemu-fsdev.h" |
96 | #endif | |
9c17d615 | 97 | #include "sysemu/qtest.h" |
511d2b14 | 98 | |
76cad711 | 99 | #include "disas/disas.h" |
fc01f7e7 | 100 | |
8b7a5507 | 101 | #include "trace.h" |
e4858974 | 102 | #include "trace/control.h" |
42229a75 | 103 | #include "qemu/plugin.h" |
1de7afc9 | 104 | #include "qemu/queue.h" |
9c17d615 | 105 | #include "sysemu/arch_init.h" |
abc27d42 | 106 | #include "exec/confidential-guest-support.h" |
72cf2d4f | 107 | |
29b0040b | 108 | #include "ui/qemu-spice.h" |
68d98d3e | 109 | #include "qapi/string-input-visitor.h" |
c4090f8e | 110 | #include "qapi/opts-visitor.h" |
776d1344 | 111 | #include "qapi/clone-visitor.h" |
84321831 | 112 | #include "qom/object_interfaces.h" |
6b5fe137 | 113 | #include "semihosting/semihost.h" |
ddbb0d09 | 114 | #include "crypto/init.h" |
b60c48a7 | 115 | #include "sysemu/replay.h" |
9af23989 MA |
116 | #include "qapi/qapi-events-run-state.h" |
117 | #include "qapi/qapi-visit-block-core.h" | |
6dd75472 | 118 | #include "qapi/qapi-visit-compat.h" |
776d1344 | 119 | #include "qapi/qapi-visit-ui.h" |
112ed241 | 120 | #include "qapi/qapi-commands-block-core.h" |
e69d50d6 | 121 | #include "qapi/qapi-commands-migration.h" |
ee55686e | 122 | #include "qapi/qapi-commands-misc.h" |
bc2f4fcb | 123 | #include "qapi/qapi-visit-qom.h" |
e1ca8f7e | 124 | #include "qapi/qapi-commands-ui.h" |
0194749a | 125 | #include "qapi/qmp/qerror.h" |
dce8921b | 126 | #include "sysemu/iothread.h" |
9c09a251 | 127 | #include "qemu/guest-random.h" |
29b0040b | 128 | |
98b19252 AS |
129 | #define MAX_VIRTIO_CONSOLES 1 |
130 | ||
64418657 PB |
131 | typedef struct BlockdevOptionsQueueEntry { |
132 | BlockdevOptions *bdo; | |
133 | Location loc; | |
134 | QSIMPLEQ_ENTRY(BlockdevOptionsQueueEntry) entry; | |
135 | } BlockdevOptionsQueueEntry; | |
136 | ||
137 | typedef QSIMPLEQ_HEAD(, BlockdevOptionsQueueEntry) BlockdevOptionsQueue; | |
138 | ||
bc2f4fcb PB |
139 | typedef struct ObjectOption { |
140 | ObjectOptions *opts; | |
141 | QTAILQ_ENTRY(ObjectOption) next; | |
142 | } ObjectOption; | |
143 | ||
0546c060 | 144 | static const char *cpu_option; |
d8e4de41 | 145 | static const char *mem_path; |
58c91595 | 146 | static const char *incoming; |
90285ec8 | 147 | static const char *loadvm; |
bc2f4fcb | 148 | static QTAILQ_HEAD(, ObjectOption) object_opts = QTAILQ_HEAD_INITIALIZER(object_opts); |
f5c9fcb8 PB |
149 | static ram_addr_t maxram_size; |
150 | static uint64_t ram_slots; | |
f650266b | 151 | static int display_remote; |
64418657 | 152 | static int snapshot; |
7691bdef | 153 | static bool preconfig_requested; |
8a745974 | 154 | static QemuPluginList plugin_list = QTAILQ_HEAD_INITIALIZER(plugin_list); |
64418657 | 155 | static BlockdevOptionsQueue bdo_queue = QSIMPLEQ_HEAD_INITIALIZER(bdo_queue); |
f650266b | 156 | static bool nographic = false; |
4d2c17b0 | 157 | static int mem_prealloc; /* force preallocation of physical target memory */ |
b326b6ea | 158 | static ram_addr_t ram_size; |
f650266b | 159 | static const char *vga_model = NULL; |
0c8d7065 | 160 | static DisplayOptions dpy; |
b8d880ba PM |
161 | static int num_serial_hds; |
162 | static Chardev **serial_hds; | |
0546c060 PB |
163 | static const char *log_mask; |
164 | static const char *log_file; | |
165 | static bool list_data_dirs; | |
4d2c17b0 | 166 | static const char *watchdog; |
eaf65114 TH |
167 | static const char *qtest_chrdev; |
168 | static const char *qtest_log; | |
1ca4d09a | 169 | |
d44229c5 | 170 | static int has_defaults = 1; |
998bbd74 | 171 | static int default_serial = 1; |
6a5e8b0e | 172 | static int default_parallel = 1; |
abdeed06 | 173 | static int default_monitor = 1; |
ac33f8fa GH |
174 | static int default_floppy = 1; |
175 | static int default_cdrom = 1; | |
176 | static int default_sdcard = 1; | |
7f1b17f2 | 177 | static int default_vga = 1; |
d30300f7 | 178 | static int default_net = 1; |
998bbd74 GH |
179 | |
180 | static struct { | |
181 | const char *driver; | |
182 | int *flag; | |
183 | } default_list[] = { | |
6a5e8b0e GH |
184 | { .driver = "isa-serial", .flag = &default_serial }, |
185 | { .driver = "isa-parallel", .flag = &default_parallel }, | |
d8bcbabf | 186 | { .driver = "isa-fdc", .flag = &default_floppy }, |
a92bd191 | 187 | { .driver = "floppy", .flag = &default_floppy }, |
af6bf132 MA |
188 | { .driver = "ide-cd", .flag = &default_cdrom }, |
189 | { .driver = "ide-hd", .flag = &default_cdrom }, | |
af6bf132 | 190 | { .driver = "scsi-cd", .flag = &default_cdrom }, |
f6f99b48 | 191 | { .driver = "scsi-hd", .flag = &default_cdrom }, |
7f1b17f2 PB |
192 | { .driver = "VGA", .flag = &default_vga }, |
193 | { .driver = "isa-vga", .flag = &default_vga }, | |
194 | { .driver = "cirrus-vga", .flag = &default_vga }, | |
195 | { .driver = "isa-cirrus-vga", .flag = &default_vga }, | |
196 | { .driver = "vmware-svga", .flag = &default_vga }, | |
197 | { .driver = "qxl-vga", .flag = &default_vga }, | |
a94f0c5c | 198 | { .driver = "virtio-vga", .flag = &default_vga }, |
862b4a29 | 199 | { .driver = "ati-vga", .flag = &default_vga }, |
267f6646 | 200 | { .driver = "vhost-user-vga", .flag = &default_vga }, |
998bbd74 GH |
201 | }; |
202 | ||
4d454574 PB |
203 | static QemuOptsList qemu_rtc_opts = { |
204 | .name = "rtc", | |
205 | .head = QTAILQ_HEAD_INITIALIZER(qemu_rtc_opts.head), | |
eb6a5209 | 206 | .merge_lists = true, |
4d454574 PB |
207 | .desc = { |
208 | { | |
209 | .name = "base", | |
210 | .type = QEMU_OPT_STRING, | |
211 | },{ | |
212 | .name = "clock", | |
213 | .type = QEMU_OPT_STRING, | |
214 | },{ | |
215 | .name = "driftfix", | |
216 | .type = QEMU_OPT_STRING, | |
217 | }, | |
218 | { /* end of list */ } | |
219 | }, | |
220 | }; | |
221 | ||
4d454574 PB |
222 | static QemuOptsList qemu_option_rom_opts = { |
223 | .name = "option-rom", | |
224 | .implied_opt_name = "romfile", | |
225 | .head = QTAILQ_HEAD_INITIALIZER(qemu_option_rom_opts.head), | |
226 | .desc = { | |
227 | { | |
228 | .name = "bootindex", | |
229 | .type = QEMU_OPT_NUMBER, | |
230 | }, { | |
231 | .name = "romfile", | |
232 | .type = QEMU_OPT_STRING, | |
233 | }, | |
234 | { /* end of list */ } | |
235 | }, | |
236 | }; | |
237 | ||
238 | static QemuOptsList qemu_machine_opts = { | |
239 | .name = "machine", | |
240 | .implied_opt_name = "type", | |
241 | .merge_lists = true, | |
242 | .head = QTAILQ_HEAD_INITIALIZER(qemu_machine_opts.head), | |
243 | .desc = { | |
49d2e648 MA |
244 | /* |
245 | * no elements => accept any | |
246 | * sanity checking will happen later | |
247 | * when setting machine properties | |
248 | */ | |
249 | { } | |
4d454574 PB |
250 | }, |
251 | }; | |
252 | ||
8d4e9146 FK |
253 | static QemuOptsList qemu_accel_opts = { |
254 | .name = "accel", | |
255 | .implied_opt_name = "accel", | |
256 | .head = QTAILQ_HEAD_INITIALIZER(qemu_accel_opts.head), | |
8d4e9146 | 257 | .desc = { |
12ceaef6 PB |
258 | /* |
259 | * no elements => accept any | |
260 | * sanity checking will happen later | |
261 | * when setting accelerator properties | |
262 | */ | |
263 | { } | |
8d4e9146 FK |
264 | }, |
265 | }; | |
266 | ||
4d454574 PB |
267 | static QemuOptsList qemu_boot_opts = { |
268 | .name = "boot-opts", | |
6ef4716c MA |
269 | .implied_opt_name = "order", |
270 | .merge_lists = true, | |
4d454574 PB |
271 | .head = QTAILQ_HEAD_INITIALIZER(qemu_boot_opts.head), |
272 | .desc = { | |
4d454574 PB |
273 | { |
274 | .name = "order", | |
275 | .type = QEMU_OPT_STRING, | |
276 | }, { | |
277 | .name = "once", | |
278 | .type = QEMU_OPT_STRING, | |
279 | }, { | |
280 | .name = "menu", | |
6ef4716c | 281 | .type = QEMU_OPT_BOOL, |
4d454574 PB |
282 | }, { |
283 | .name = "splash", | |
284 | .type = QEMU_OPT_STRING, | |
285 | }, { | |
286 | .name = "splash-time", | |
6912bb0b | 287 | .type = QEMU_OPT_NUMBER, |
4d454574 PB |
288 | }, { |
289 | .name = "reboot-timeout", | |
ee5d0f89 | 290 | .type = QEMU_OPT_NUMBER, |
c8a6ae8b AK |
291 | }, { |
292 | .name = "strict", | |
e5187b56 | 293 | .type = QEMU_OPT_BOOL, |
4d454574 PB |
294 | }, |
295 | { /*End of list */ } | |
296 | }, | |
297 | }; | |
298 | ||
299 | static QemuOptsList qemu_add_fd_opts = { | |
300 | .name = "add-fd", | |
301 | .head = QTAILQ_HEAD_INITIALIZER(qemu_add_fd_opts.head), | |
302 | .desc = { | |
303 | { | |
304 | .name = "fd", | |
305 | .type = QEMU_OPT_NUMBER, | |
306 | .help = "file descriptor of which a duplicate is added to fd set", | |
307 | },{ | |
308 | .name = "set", | |
309 | .type = QEMU_OPT_NUMBER, | |
310 | .help = "ID of the fd set to add fd to", | |
311 | },{ | |
312 | .name = "opaque", | |
313 | .type = QEMU_OPT_STRING, | |
314 | .help = "free-form string used to describe fd", | |
315 | }, | |
316 | { /* end of list */ } | |
317 | }, | |
318 | }; | |
319 | ||
320 | static QemuOptsList qemu_object_opts = { | |
321 | .name = "object", | |
322 | .implied_opt_name = "qom-type", | |
323 | .head = QTAILQ_HEAD_INITIALIZER(qemu_object_opts.head), | |
324 | .desc = { | |
325 | { } | |
326 | }, | |
327 | }; | |
328 | ||
d1a0cf73 SB |
329 | static QemuOptsList qemu_tpmdev_opts = { |
330 | .name = "tpmdev", | |
331 | .implied_opt_name = "type", | |
332 | .head = QTAILQ_HEAD_INITIALIZER(qemu_tpmdev_opts.head), | |
333 | .desc = { | |
bb716238 | 334 | /* options are defined in the TPM backends */ |
d1a0cf73 SB |
335 | { /* end of list */ } |
336 | }, | |
337 | }; | |
338 | ||
6f131f13 MT |
339 | static QemuOptsList qemu_overcommit_opts = { |
340 | .name = "overcommit", | |
341 | .head = QTAILQ_HEAD_INITIALIZER(qemu_overcommit_opts.head), | |
342 | .desc = { | |
343 | { | |
344 | .name = "mem-lock", | |
345 | .type = QEMU_OPT_BOOL, | |
346 | }, | |
347 | { | |
348 | .name = "cpu-pm", | |
349 | .type = QEMU_OPT_BOOL, | |
350 | }, | |
351 | { /* end of list */ } | |
352 | }, | |
353 | }; | |
354 | ||
5e2ac519 SA |
355 | static QemuOptsList qemu_msg_opts = { |
356 | .name = "msg", | |
357 | .head = QTAILQ_HEAD_INITIALIZER(qemu_msg_opts.head), | |
358 | .desc = { | |
359 | { | |
360 | .name = "timestamp", | |
361 | .type = QEMU_OPT_BOOL, | |
362 | }, | |
2880ffb0 MS |
363 | { |
364 | .name = "guest-name", | |
365 | .type = QEMU_OPT_BOOL, | |
366 | .help = "Prepends guest name for error messages but only if " | |
367 | "-name guest is set otherwise option is ignored\n", | |
368 | }, | |
5e2ac519 SA |
369 | { /* end of list */ } |
370 | }, | |
371 | }; | |
372 | ||
5d12f961 DDAG |
373 | static QemuOptsList qemu_name_opts = { |
374 | .name = "name", | |
375 | .implied_opt_name = "guest", | |
376 | .merge_lists = true, | |
377 | .head = QTAILQ_HEAD_INITIALIZER(qemu_name_opts.head), | |
378 | .desc = { | |
379 | { | |
380 | .name = "guest", | |
381 | .type = QEMU_OPT_STRING, | |
382 | .help = "Sets the name of the guest.\n" | |
383 | "This name will be displayed in the SDL window caption.\n" | |
384 | "The name will also be used for the VNC server", | |
385 | }, { | |
386 | .name = "process", | |
387 | .type = QEMU_OPT_STRING, | |
388 | .help = "Sets the name of the QEMU process, as shown in top etc", | |
8f480de0 DDAG |
389 | }, { |
390 | .name = "debug-threads", | |
391 | .type = QEMU_OPT_BOOL, | |
392 | .help = "When enabled, name the individual threads; defaults off.\n" | |
393 | "NOTE: The thread names are for debugging and not a\n" | |
394 | "stable API.", | |
5d12f961 DDAG |
395 | }, |
396 | { /* End of list */ } | |
397 | }, | |
398 | }; | |
399 | ||
6e1d3c1c IM |
400 | static QemuOptsList qemu_mem_opts = { |
401 | .name = "memory", | |
402 | .implied_opt_name = "size", | |
403 | .head = QTAILQ_HEAD_INITIALIZER(qemu_mem_opts.head), | |
404 | .merge_lists = true, | |
405 | .desc = { | |
406 | { | |
407 | .name = "size", | |
408 | .type = QEMU_OPT_SIZE, | |
409 | }, | |
c270fb9e IM |
410 | { |
411 | .name = "slots", | |
412 | .type = QEMU_OPT_NUMBER, | |
413 | }, | |
414 | { | |
415 | .name = "maxmem", | |
416 | .type = QEMU_OPT_SIZE, | |
417 | }, | |
6e1d3c1c IM |
418 | { /* end of list */ } |
419 | }, | |
420 | }; | |
421 | ||
1ad9580b ST |
422 | static QemuOptsList qemu_icount_opts = { |
423 | .name = "icount", | |
424 | .implied_opt_name = "shift", | |
425 | .merge_lists = true, | |
426 | .head = QTAILQ_HEAD_INITIALIZER(qemu_icount_opts.head), | |
427 | .desc = { | |
428 | { | |
429 | .name = "shift", | |
430 | .type = QEMU_OPT_STRING, | |
a8bfac37 ST |
431 | }, { |
432 | .name = "align", | |
433 | .type = QEMU_OPT_BOOL, | |
f1f4b57e VC |
434 | }, { |
435 | .name = "sleep", | |
436 | .type = QEMU_OPT_BOOL, | |
4c27b859 PD |
437 | }, { |
438 | .name = "rr", | |
439 | .type = QEMU_OPT_STRING, | |
440 | }, { | |
441 | .name = "rrfile", | |
442 | .type = QEMU_OPT_STRING, | |
9c2037d0 PD |
443 | }, { |
444 | .name = "rrsnapshot", | |
445 | .type = QEMU_OPT_STRING, | |
1ad9580b ST |
446 | }, |
447 | { /* end of list */ } | |
448 | }, | |
449 | }; | |
450 | ||
81b2b810 GS |
451 | static QemuOptsList qemu_fw_cfg_opts = { |
452 | .name = "fw_cfg", | |
453 | .implied_opt_name = "name", | |
454 | .head = QTAILQ_HEAD_INITIALIZER(qemu_fw_cfg_opts.head), | |
455 | .desc = { | |
456 | { | |
457 | .name = "name", | |
458 | .type = QEMU_OPT_STRING, | |
459 | .help = "Sets the fw_cfg name of the blob to be inserted", | |
460 | }, { | |
461 | .name = "file", | |
462 | .type = QEMU_OPT_STRING, | |
679be303 | 463 | .help = "Sets the name of the file from which " |
81b2b810 | 464 | "the fw_cfg blob will be loaded", |
6407d76e GS |
465 | }, { |
466 | .name = "string", | |
467 | .type = QEMU_OPT_STRING, | |
468 | .help = "Sets content of the blob to be inserted from a string", | |
6552d87c PMD |
469 | }, { |
470 | .name = "gen_id", | |
471 | .type = QEMU_OPT_STRING, | |
472 | .help = "Sets id of the object generating the fw_cfg blob " | |
473 | "to be inserted", | |
81b2b810 GS |
474 | }, |
475 | { /* end of list */ } | |
476 | }, | |
477 | }; | |
478 | ||
2a5ad60b AJ |
479 | static QemuOptsList qemu_action_opts = { |
480 | .name = "action", | |
481 | .merge_lists = true, | |
482 | .head = QTAILQ_HEAD_INITIALIZER(qemu_action_opts.head), | |
483 | .desc = { | |
484 | { | |
485 | .name = "shutdown", | |
486 | .type = QEMU_OPT_STRING, | |
487 | },{ | |
488 | .name = "reboot", | |
489 | .type = QEMU_OPT_STRING, | |
c753e8e7 AJ |
490 | },{ |
491 | .name = "panic", | |
492 | .type = QEMU_OPT_STRING, | |
2a5ad60b AJ |
493 | },{ |
494 | .name = "watchdog", | |
495 | .type = QEMU_OPT_STRING, | |
496 | }, | |
497 | { /* end of list */ } | |
498 | }, | |
499 | }; | |
500 | ||
7f9d6e54 MA |
501 | /** |
502 | * Get machine options | |
503 | * | |
504 | * Returns: machine options (never null). | |
505 | */ | |
f2ce39b4 | 506 | static QemuOpts *qemu_get_machine_opts(void) |
7f9d6e54 | 507 | { |
e96e5ae8 | 508 | return qemu_find_opts_singleton("machine"); |
7f9d6e54 MA |
509 | } |
510 | ||
31459f46 RS |
511 | const char *qemu_get_vm_name(void) |
512 | { | |
513 | return qemu_name; | |
514 | } | |
515 | ||
28d0de7a | 516 | static int default_driver_check(void *opaque, QemuOpts *opts, Error **errp) |
998bbd74 GH |
517 | { |
518 | const char *driver = qemu_opt_get(opts, "driver"); | |
519 | int i; | |
520 | ||
521 | if (!driver) | |
522 | return 0; | |
523 | for (i = 0; i < ARRAY_SIZE(default_list); i++) { | |
524 | if (strcmp(default_list[i].driver, driver) != 0) | |
525 | continue; | |
526 | *(default_list[i].flag) = 0; | |
527 | } | |
528 | return 0; | |
529 | } | |
530 | ||
28d0de7a | 531 | static int parse_name(void *opaque, QemuOpts *opts, Error **errp) |
5d12f961 DDAG |
532 | { |
533 | const char *proc_name; | |
534 | ||
8f480de0 DDAG |
535 | if (qemu_opt_get(opts, "debug-threads")) { |
536 | qemu_thread_naming(qemu_opt_get_bool(opts, "debug-threads", false)); | |
537 | } | |
5d12f961 DDAG |
538 | qemu_name = qemu_opt_get(opts, "guest"); |
539 | ||
540 | proc_name = qemu_opt_get(opts, "process"); | |
541 | if (proc_name) { | |
542 | os_set_proc_name(proc_name); | |
543 | } | |
5b9d313e DDAG |
544 | |
545 | return 0; | |
5d12f961 DDAG |
546 | } |
547 | ||
f8b6f8ed MA |
548 | bool defaults_enabled(void) |
549 | { | |
550 | return has_defaults; | |
551 | } | |
552 | ||
587ed6be | 553 | #ifndef _WIN32 |
28d0de7a | 554 | static int parse_add_fd(void *opaque, QemuOpts *opts, Error **errp) |
587ed6be CB |
555 | { |
556 | int fd, dupfd, flags; | |
557 | int64_t fdset_id; | |
558 | const char *fd_opaque = NULL; | |
636a30a8 | 559 | AddfdInfo *fdinfo; |
587ed6be CB |
560 | |
561 | fd = qemu_opt_get_number(opts, "fd", -1); | |
562 | fdset_id = qemu_opt_get_number(opts, "set", -1); | |
563 | fd_opaque = qemu_opt_get(opts, "opaque"); | |
564 | ||
565 | if (fd < 0) { | |
6353218b | 566 | error_setg(errp, "fd option is required and must be non-negative"); |
587ed6be CB |
567 | return -1; |
568 | } | |
569 | ||
570 | if (fd <= STDERR_FILENO) { | |
6353218b | 571 | error_setg(errp, "fd cannot be a standard I/O stream"); |
587ed6be CB |
572 | return -1; |
573 | } | |
574 | ||
575 | /* | |
576 | * All fds inherited across exec() necessarily have FD_CLOEXEC | |
577 | * clear, while qemu sets FD_CLOEXEC on all other fds used internally. | |
578 | */ | |
579 | flags = fcntl(fd, F_GETFD); | |
580 | if (flags == -1 || (flags & FD_CLOEXEC)) { | |
6353218b | 581 | error_setg(errp, "fd is not valid or already in use"); |
587ed6be CB |
582 | return -1; |
583 | } | |
584 | ||
585 | if (fdset_id < 0) { | |
6353218b | 586 | error_setg(errp, "set option is required and must be non-negative"); |
587ed6be CB |
587 | return -1; |
588 | } | |
589 | ||
590 | #ifdef F_DUPFD_CLOEXEC | |
591 | dupfd = fcntl(fd, F_DUPFD_CLOEXEC, 0); | |
592 | #else | |
593 | dupfd = dup(fd); | |
594 | if (dupfd != -1) { | |
595 | qemu_set_cloexec(dupfd); | |
596 | } | |
597 | #endif | |
598 | if (dupfd == -1) { | |
6353218b | 599 | error_setg(errp, "error duplicating fd: %s", strerror(errno)); |
587ed6be CB |
600 | return -1; |
601 | } | |
602 | ||
603 | /* add the duplicate fd, and optionally the opaque string, to the fd set */ | |
636a30a8 PB |
604 | fdinfo = monitor_fdset_add_fd(dupfd, true, fdset_id, !!fd_opaque, fd_opaque, |
605 | &error_abort); | |
606 | g_free(fdinfo); | |
587ed6be CB |
607 | |
608 | return 0; | |
609 | } | |
610 | ||
28d0de7a | 611 | static int cleanup_add_fd(void *opaque, QemuOpts *opts, Error **errp) |
587ed6be CB |
612 | { |
613 | int fd; | |
614 | ||
615 | fd = qemu_opt_get_number(opts, "fd", -1); | |
616 | close(fd); | |
617 | ||
618 | return 0; | |
619 | } | |
620 | #endif | |
621 | ||
1ae26a18 AZ |
622 | /***********************************************************/ |
623 | /* QEMU Block devices */ | |
624 | ||
2292ddae MA |
625 | #define HD_OPTS "media=disk" |
626 | #define CDROM_OPTS "media=cdrom" | |
627 | #define FD_OPTS "" | |
628 | #define PFLASH_OPTS "" | |
629 | #define MTD_OPTS "" | |
630 | #define SD_OPTS "" | |
e4bcb14c | 631 | |
28d0de7a | 632 | static int drive_init_func(void *opaque, QemuOpts *opts, Error **errp) |
9dfd7c7a | 633 | { |
2d0d2837 | 634 | BlockInterfaceType *block_default_type = opaque; |
9dfd7c7a | 635 | |
c4f26c9f | 636 | return drive_new(opts, *block_default_type, errp) == NULL; |
9dfd7c7a GH |
637 | } |
638 | ||
28d0de7a | 639 | static int drive_enable_snapshot(void *opaque, QemuOpts *opts, Error **errp) |
9dfd7c7a | 640 | { |
28de2f88 | 641 | if (qemu_opt_get(opts, "snapshot") == NULL) { |
f43e47db | 642 | qemu_opt_set(opts, "snapshot", "on", &error_abort); |
9dfd7c7a GH |
643 | } |
644 | return 0; | |
645 | } | |
646 | ||
3c42ea66 CB |
647 | static void default_drive(int enable, int snapshot, BlockInterfaceType type, |
648 | int index, const char *optstr) | |
4e5d9b57 MA |
649 | { |
650 | QemuOpts *opts; | |
a66c9dc7 | 651 | DriveInfo *dinfo; |
4e5d9b57 | 652 | |
4e5d9b57 MA |
653 | if (!enable || drive_get_by_index(type, index)) { |
654 | return; | |
655 | } | |
656 | ||
657 | opts = drive_add(type, index, NULL, optstr); | |
658 | if (snapshot) { | |
28d0de7a | 659 | drive_enable_snapshot(NULL, opts, NULL); |
4e5d9b57 | 660 | } |
a66c9dc7 | 661 | |
c4f26c9f | 662 | dinfo = drive_new(opts, type, &error_abort); |
a66c9dc7 JS |
663 | dinfo->is_default = true; |
664 | ||
4e5d9b57 MA |
665 | } |
666 | ||
d11bf9bf MA |
667 | static void configure_blockdev(BlockdevOptionsQueue *bdo_queue, |
668 | MachineClass *machine_class, int snapshot) | |
669 | { | |
670 | /* | |
671 | * If the currently selected machine wishes to override the | |
672 | * units-per-bus property of its default HBA interface type, do so | |
673 | * now. | |
674 | */ | |
675 | if (machine_class->units_per_default_bus) { | |
676 | override_max_devs(machine_class->block_default_type, | |
677 | machine_class->units_per_default_bus); | |
678 | } | |
679 | ||
680 | /* open the virtual block devices */ | |
681 | while (!QSIMPLEQ_EMPTY(bdo_queue)) { | |
682 | BlockdevOptionsQueueEntry *bdo = QSIMPLEQ_FIRST(bdo_queue); | |
683 | ||
684 | QSIMPLEQ_REMOVE_HEAD(bdo_queue, entry); | |
685 | loc_push_restore(&bdo->loc); | |
686 | qmp_blockdev_add(bdo->bdo, &error_fatal); | |
687 | loc_pop(&bdo->loc); | |
688 | qapi_free_BlockdevOptions(bdo->bdo); | |
689 | g_free(bdo); | |
690 | } | |
25863975 | 691 | if (snapshot) { |
d11bf9bf MA |
692 | qemu_opts_foreach(qemu_find_opts("drive"), drive_enable_snapshot, |
693 | NULL, NULL); | |
694 | } | |
695 | if (qemu_opts_foreach(qemu_find_opts("drive"), drive_init_func, | |
696 | &machine_class->block_default_type, &error_fatal)) { | |
697 | /* We printed help */ | |
698 | exit(0); | |
699 | } | |
700 | ||
701 | default_drive(default_cdrom, snapshot, machine_class->block_default_type, 2, | |
702 | CDROM_OPTS); | |
703 | default_drive(default_floppy, snapshot, IF_FLOPPY, 0, FD_OPTS); | |
704 | default_drive(default_sdcard, snapshot, IF_SD, 0, SD_OPTS); | |
705 | ||
706 | } | |
707 | ||
12b7f57e MT |
708 | static QemuOptsList qemu_smp_opts = { |
709 | .name = "smp-opts", | |
710 | .implied_opt_name = "cpus", | |
711 | .merge_lists = true, | |
712 | .head = QTAILQ_HEAD_INITIALIZER(qemu_smp_opts.head), | |
713 | .desc = { | |
714 | { | |
715 | .name = "cpus", | |
716 | .type = QEMU_OPT_NUMBER, | |
717 | }, { | |
718 | .name = "sockets", | |
719 | .type = QEMU_OPT_NUMBER, | |
1b458422 LX |
720 | }, { |
721 | .name = "dies", | |
722 | .type = QEMU_OPT_NUMBER, | |
12b7f57e MT |
723 | }, { |
724 | .name = "cores", | |
725 | .type = QEMU_OPT_NUMBER, | |
726 | }, { | |
727 | .name = "threads", | |
728 | .type = QEMU_OPT_NUMBER, | |
729 | }, { | |
730 | .name = "maxcpus", | |
731 | .type = QEMU_OPT_NUMBER, | |
732 | }, | |
733 | { /*End of list */ } | |
734 | }, | |
735 | }; | |
736 | ||
28d16f38 | 737 | static void realtime_init(void) |
888a6bc6 | 738 | { |
888a6bc6 SM |
739 | if (enable_mlock) { |
740 | if (os_mlock() < 0) { | |
f61eddcb | 741 | error_report("locking memory failed"); |
888a6bc6 SM |
742 | exit(1); |
743 | } | |
744 | } | |
745 | } | |
746 | ||
5e2ac519 SA |
747 | |
748 | static void configure_msg(QemuOpts *opts) | |
749 | { | |
651d588f | 750 | message_with_timestamp = qemu_opt_get_bool(opts, "timestamp", false); |
2880ffb0 | 751 | error_with_guestname = qemu_opt_get_bool(opts, "guest-name", false); |
5e2ac519 SA |
752 | } |
753 | ||
a59d31a1 | 754 | |
a594cfbf FB |
755 | /***********************************************************/ |
756 | /* USB devices */ | |
757 | ||
fb08000c | 758 | static int usb_device_add(const char *devname) |
a594cfbf | 759 | { |
a5d2f727 | 760 | USBDevice *dev = NULL; |
a594cfbf | 761 | |
4bcbe0b6 | 762 | if (!machine_usb(current_machine)) { |
a594cfbf | 763 | return -1; |
094b287f | 764 | } |
a594cfbf | 765 | |
0958b4cc | 766 | dev = usbdevice_create(devname); |
0d92ed30 PB |
767 | if (!dev) |
768 | return -1; | |
769 | ||
a594cfbf FB |
770 | return 0; |
771 | } | |
772 | ||
bd3c948d GH |
773 | static int usb_parse(const char *cmdline) |
774 | { | |
59d1c1c2 | 775 | int r; |
fb08000c | 776 | r = usb_device_add(cmdline); |
59d1c1c2 | 777 | if (r < 0) { |
f61eddcb | 778 | error_report("could not add USB device '%s'", cmdline); |
59d1c1c2 ST |
779 | } |
780 | return r; | |
bd3c948d GH |
781 | } |
782 | ||
cc1daa40 FB |
783 | /***********************************************************/ |
784 | /* machine registration */ | |
785 | ||
c516cd1b | 786 | static MachineClass *find_machine(const char *name, GSList *machines) |
cc1daa40 | 787 | { |
c516cd1b | 788 | GSList *el; |
cc1daa40 | 789 | |
261747f1 | 790 | for (el = machines; el; el = el->next) { |
f2c93021 | 791 | MachineClass *mc = el->data; |
261747f1 | 792 | |
f2c93021 MA |
793 | if (!strcmp(mc->name, name) || !g_strcmp0(mc->alias, name)) { |
794 | return mc; | |
261747f1 | 795 | } |
cc1daa40 | 796 | } |
261747f1 | 797 | |
f2c93021 | 798 | return NULL; |
cc1daa40 FB |
799 | } |
800 | ||
c516cd1b | 801 | static MachineClass *find_default_machine(GSList *machines) |
0c257437 | 802 | { |
c516cd1b | 803 | GSList *el; |
6db1857e | 804 | MachineClass *default_machineclass = NULL; |
0c257437 | 805 | |
261747f1 | 806 | for (el = machines; el; el = el->next) { |
f2c93021 | 807 | MachineClass *mc = el->data; |
261747f1 | 808 | |
f2c93021 | 809 | if (mc->is_default) { |
6db1857e PMD |
810 | assert(default_machineclass == NULL && "Multiple default machines"); |
811 | default_machineclass = mc; | |
0c257437 AL |
812 | } |
813 | } | |
261747f1 | 814 | |
6db1857e | 815 | return default_machineclass; |
0c257437 AL |
816 | } |
817 | ||
52eb3dfd MA |
818 | static int machine_help_func(QemuOpts *opts, MachineState *machine) |
819 | { | |
820 | ObjectProperty *prop; | |
7746abd8 | 821 | ObjectPropertyIterator iter; |
52eb3dfd MA |
822 | |
823 | if (!qemu_opt_has_help_opt(opts)) { | |
824 | return 0; | |
825 | } | |
826 | ||
7746abd8 DB |
827 | object_property_iter_init(&iter, OBJECT(machine)); |
828 | while ((prop = object_property_iter_next(&iter))) { | |
52eb3dfd MA |
829 | if (!prop->set) { |
830 | continue; | |
831 | } | |
832 | ||
26eaf2cd MA |
833 | printf("%s.%s=%s", MACHINE_GET_CLASS(machine)->name, |
834 | prop->name, prop->type); | |
52eb3dfd | 835 | if (prop->description) { |
26eaf2cd | 836 | printf(" (%s)\n", prop->description); |
52eb3dfd | 837 | } else { |
26eaf2cd | 838 | printf("\n"); |
52eb3dfd MA |
839 | } |
840 | } | |
841 | ||
842 | return 1; | |
843 | } | |
844 | ||
9bd7e6d9 PB |
845 | static void version(void) |
846 | { | |
7e563bfb | 847 | printf("QEMU emulator version " QEMU_FULL_VERSION "\n" |
d915b7bb | 848 | QEMU_COPYRIGHT "\n"); |
9bd7e6d9 PB |
849 | } |
850 | ||
15f82208 | 851 | static void help(int exitcode) |
0824d6fc | 852 | { |
a3adb7ad ME |
853 | version(); |
854 | printf("usage: %s [options] [disk_image]\n\n" | |
855 | "'disk_image' is a raw hard disk image for IDE hard disk 0\n\n", | |
856 | error_get_progname()); | |
857 | ||
77bd1119 ME |
858 | #define QEMU_OPTIONS_GENERATE_HELP |
859 | #include "qemu-options-wrapper.h" | |
a3adb7ad ME |
860 | |
861 | printf("\nDuring emulation, the following keys are useful:\n" | |
3f020d70 | 862 | "ctrl-alt-f toggle full screen\n" |
863 | "ctrl-alt-n switch to virtual console 'n'\n" | |
864 | "ctrl-alt toggle mouse and keyboard grab\n" | |
865 | "\n" | |
f5048cb7 EB |
866 | "When using -nographic, press 'ctrl-a h' to get some help.\n" |
867 | "\n" | |
868 | QEMU_HELP_BOTTOM "\n"); | |
a3adb7ad | 869 | |
15f82208 | 870 | exit(exitcode); |
0824d6fc FB |
871 | } |
872 | ||
cd6f1169 FB |
873 | #define HAS_ARG 0x0001 |
874 | ||
cd6f1169 FB |
875 | typedef struct QEMUOption { |
876 | const char *name; | |
877 | int flags; | |
878 | int index; | |
ad96090a | 879 | uint32_t arch_mask; |
cd6f1169 FB |
880 | } QEMUOption; |
881 | ||
dbed7e40 | 882 | static const QEMUOption qemu_options[] = { |
ad96090a | 883 | { "h", 0, QEMU_OPTION_h, QEMU_ARCH_ALL }, |
77bd1119 ME |
884 | #define QEMU_OPTIONS_GENERATE_OPTIONS |
885 | #include "qemu-options-wrapper.h" | |
cd6f1169 | 886 | { NULL }, |
fc01f7e7 | 887 | }; |
a369da5f | 888 | |
8c9a2b71 EH |
889 | typedef struct VGAInterfaceInfo { |
890 | const char *opt_name; /* option name */ | |
891 | const char *name; /* human-readable name */ | |
c2c7b22d EH |
892 | /* Class names indicating that support is available. |
893 | * If no class is specified, the interface is always available */ | |
894 | const char *class_names[2]; | |
8c9a2b71 EH |
895 | } VGAInterfaceInfo; |
896 | ||
53b93511 | 897 | static const VGAInterfaceInfo vga_interfaces[VGA_TYPE_MAX] = { |
8c9a2b71 EH |
898 | [VGA_NONE] = { |
899 | .opt_name = "none", | |
d2fa65cd | 900 | .name = "no graphic card", |
8c9a2b71 EH |
901 | }, |
902 | [VGA_STD] = { | |
903 | .opt_name = "std", | |
904 | .name = "standard VGA", | |
c2c7b22d | 905 | .class_names = { "VGA", "isa-vga" }, |
8c9a2b71 EH |
906 | }, |
907 | [VGA_CIRRUS] = { | |
908 | .opt_name = "cirrus", | |
909 | .name = "Cirrus VGA", | |
c2c7b22d | 910 | .class_names = { "cirrus-vga", "isa-cirrus-vga" }, |
8c9a2b71 EH |
911 | }, |
912 | [VGA_VMWARE] = { | |
913 | .opt_name = "vmware", | |
914 | .name = "VMWare SVGA", | |
c2c7b22d | 915 | .class_names = { "vmware-svga" }, |
8c9a2b71 EH |
916 | }, |
917 | [VGA_VIRTIO] = { | |
918 | .opt_name = "virtio", | |
919 | .name = "Virtio VGA", | |
c2c7b22d | 920 | .class_names = { "virtio-vga" }, |
8c9a2b71 EH |
921 | }, |
922 | [VGA_QXL] = { | |
923 | .opt_name = "qxl", | |
924 | .name = "QXL VGA", | |
c2c7b22d | 925 | .class_names = { "qxl-vga" }, |
8c9a2b71 EH |
926 | }, |
927 | [VGA_TCX] = { | |
928 | .opt_name = "tcx", | |
929 | .name = "TCX framebuffer", | |
e178113f | 930 | .class_names = { "sun-tcx" }, |
8c9a2b71 EH |
931 | }, |
932 | [VGA_CG3] = { | |
933 | .opt_name = "cg3", | |
934 | .name = "CG3 framebuffer", | |
c2c7b22d | 935 | .class_names = { "cgthree" }, |
8c9a2b71 EH |
936 | }, |
937 | [VGA_XENFB] = { | |
938 | .opt_name = "xenfb", | |
d2fa65cd | 939 | .name = "Xen paravirtualized framebuffer", |
8c9a2b71 EH |
940 | }, |
941 | }; | |
942 | ||
c2c7b22d EH |
943 | static bool vga_interface_available(VGAInterfaceType t) |
944 | { | |
53b93511 | 945 | const VGAInterfaceInfo *ti = &vga_interfaces[t]; |
c2c7b22d EH |
946 | |
947 | assert(t < VGA_TYPE_MAX); | |
948 | return !ti->class_names[0] || | |
7ab6e7fc GH |
949 | module_object_class_by_name(ti->class_names[0]) || |
950 | module_object_class_by_name(ti->class_names[1]); | |
c2c7b22d EH |
951 | } |
952 | ||
dceb8852 MAL |
953 | static const char * |
954 | get_default_vga_model(const MachineClass *machine_class) | |
955 | { | |
956 | if (machine_class->default_display) { | |
957 | return machine_class->default_display; | |
958 | } else if (vga_interface_available(VGA_CIRRUS)) { | |
959 | return "cirrus"; | |
960 | } else if (vga_interface_available(VGA_STD)) { | |
961 | return "std"; | |
962 | } | |
963 | ||
964 | return NULL; | |
965 | } | |
966 | ||
967 | static void select_vgahw(const MachineClass *machine_class, const char *p) | |
3893c124 | 968 | { |
969 | const char *opts; | |
8c9a2b71 | 970 | int t; |
3893c124 | 971 | |
dceb8852 MAL |
972 | if (g_str_equal(p, "help")) { |
973 | const char *def = get_default_vga_model(machine_class); | |
974 | ||
975 | for (t = 0; t < VGA_TYPE_MAX; t++) { | |
976 | const VGAInterfaceInfo *ti = &vga_interfaces[t]; | |
977 | ||
978 | if (vga_interface_available(t) && ti->opt_name) { | |
979 | printf("%-20s %s%s\n", ti->opt_name, ti->name ?: "", | |
980 | g_str_equal(ti->opt_name, def) ? " (default)" : ""); | |
981 | } | |
982 | } | |
983 | exit(0); | |
984 | } | |
985 | ||
d44229c5 | 986 | assert(vga_interface_type == VGA_NONE); |
8c9a2b71 | 987 | for (t = 0; t < VGA_TYPE_MAX; t++) { |
53b93511 | 988 | const VGAInterfaceInfo *ti = &vga_interfaces[t]; |
8c9a2b71 | 989 | if (ti->opt_name && strstart(p, ti->opt_name, &opts)) { |
c2c7b22d | 990 | if (!vga_interface_available(t)) { |
8c9a2b71 EH |
991 | error_report("%s not available", ti->name); |
992 | exit(1); | |
993 | } | |
994 | vga_interface_type = t; | |
995 | break; | |
af87bf29 | 996 | } |
8c9a2b71 EH |
997 | } |
998 | if (t == VGA_TYPE_MAX) { | |
3893c124 | 999 | invalid_vga: |
3e515373 | 1000 | error_report("unknown vga type: %s", p); |
3893c124 | 1001 | exit(1); |
1002 | } | |
cb5a7aa8 | 1003 | while (*opts) { |
1004 | const char *nextopt; | |
1005 | ||
1006 | if (strstart(opts, ",retrace=", &nextopt)) { | |
1007 | opts = nextopt; | |
1008 | if (strstart(opts, "dumb", &nextopt)) | |
1009 | vga_retrace_method = VGA_RETRACE_DUMB; | |
1010 | else if (strstart(opts, "precise", &nextopt)) | |
1011 | vga_retrace_method = VGA_RETRACE_PRECISE; | |
1012 | else goto invalid_vga; | |
1013 | } else goto invalid_vga; | |
1014 | opts = nextopt; | |
1015 | } | |
3893c124 | 1016 | } |
1017 | ||
776d1344 GH |
1018 | static void parse_display_qapi(const char *optarg) |
1019 | { | |
776d1344 GH |
1020 | DisplayOptions *opts; |
1021 | Visitor *v; | |
1022 | ||
50beeb68 | 1023 | v = qobject_input_visitor_new_str(optarg, "type", &error_fatal); |
776d1344 GH |
1024 | |
1025 | visit_type_DisplayOptions(v, NULL, &opts, &error_fatal); | |
1026 | QAPI_CLONE_MEMBERS(DisplayOptions, &dpy, opts); | |
1027 | ||
1028 | qapi_free_DisplayOptions(opts); | |
1029 | visit_free(v); | |
1030 | } | |
1031 | ||
e1ca8f7e GH |
1032 | DisplayOptions *qmp_query_display_options(Error **errp) |
1033 | { | |
1034 | return QAPI_CLONE(DisplayOptions, &dpy); | |
1035 | } | |
1036 | ||
e3af9f9a | 1037 | static void parse_display(const char *p) |
1472a95b JS |
1038 | { |
1039 | const char *opts; | |
1472a95b | 1040 | |
c388f408 TH |
1041 | if (is_help_option(p)) { |
1042 | qemu_display_help(); | |
1043 | exit(0); | |
1044 | } | |
1045 | ||
1472a95b | 1046 | if (strstart(p, "sdl", &opts)) { |
7a61f438 GH |
1047 | /* |
1048 | * sdl DisplayType needs hand-crafted parser instead of | |
1049 | * parse_display_qapi() due to some options not in | |
1050 | * DisplayOptions, specifically: | |
1051 | * - frame | |
1052 | * Already deprecated. | |
1053 | * - ctrl_grab + alt_grab | |
1054 | * Not clear yet what happens to them long-term. Should | |
1055 | * replaced by something better or deprecated and dropped. | |
1056 | */ | |
fe91f36a | 1057 | dpy.type = DISPLAY_TYPE_SDL; |
1472a95b JS |
1058 | while (*opts) { |
1059 | const char *nextopt; | |
1060 | ||
09bd7ba9 | 1061 | if (strstart(opts, ",alt_grab=", &nextopt)) { |
1472a95b JS |
1062 | opts = nextopt; |
1063 | if (strstart(opts, "on", &nextopt)) { | |
1064 | alt_grab = 1; | |
1065 | } else if (strstart(opts, "off", &nextopt)) { | |
1066 | alt_grab = 0; | |
1067 | } else { | |
05175535 | 1068 | goto invalid_sdl_args; |
1472a95b JS |
1069 | } |
1070 | } else if (strstart(opts, ",ctrl_grab=", &nextopt)) { | |
1071 | opts = nextopt; | |
1072 | if (strstart(opts, "on", &nextopt)) { | |
1073 | ctrl_grab = 1; | |
1074 | } else if (strstart(opts, "off", &nextopt)) { | |
1075 | ctrl_grab = 0; | |
1076 | } else { | |
05175535 | 1077 | goto invalid_sdl_args; |
1472a95b JS |
1078 | } |
1079 | } else if (strstart(opts, ",window_close=", &nextopt)) { | |
1080 | opts = nextopt; | |
fe91f36a | 1081 | dpy.has_window_close = true; |
1472a95b | 1082 | if (strstart(opts, "on", &nextopt)) { |
fe91f36a | 1083 | dpy.window_close = true; |
1472a95b | 1084 | } else if (strstart(opts, "off", &nextopt)) { |
fe91f36a | 1085 | dpy.window_close = false; |
1472a95b | 1086 | } else { |
05175535 | 1087 | goto invalid_sdl_args; |
1472a95b | 1088 | } |
86a088e6 GH |
1089 | } else if (strstart(opts, ",show-cursor=", &nextopt)) { |
1090 | opts = nextopt; | |
1091 | dpy.has_show_cursor = true; | |
1092 | if (strstart(opts, "on", &nextopt)) { | |
1093 | dpy.show_cursor = true; | |
1094 | } else if (strstart(opts, "off", &nextopt)) { | |
1095 | dpy.show_cursor = false; | |
1096 | } else { | |
1097 | goto invalid_sdl_args; | |
1098 | } | |
0b71a5d5 GH |
1099 | } else if (strstart(opts, ",gl=", &nextopt)) { |
1100 | opts = nextopt; | |
fe91f36a | 1101 | dpy.has_gl = true; |
0b71a5d5 | 1102 | if (strstart(opts, "on", &nextopt)) { |
62f27922 | 1103 | dpy.gl = DISPLAYGL_MODE_ON; |
4867e47c ET |
1104 | } else if (strstart(opts, "core", &nextopt)) { |
1105 | dpy.gl = DISPLAYGL_MODE_CORE; | |
1106 | } else if (strstart(opts, "es", &nextopt)) { | |
1107 | dpy.gl = DISPLAYGL_MODE_ES; | |
0b71a5d5 | 1108 | } else if (strstart(opts, "off", &nextopt)) { |
62f27922 | 1109 | dpy.gl = DISPLAYGL_MODE_OFF; |
0b71a5d5 GH |
1110 | } else { |
1111 | goto invalid_sdl_args; | |
1112 | } | |
1472a95b | 1113 | } else { |
05175535 | 1114 | invalid_sdl_args: |
3e515373 | 1115 | error_report("invalid SDL option string"); |
05175535 | 1116 | exit(1); |
1472a95b JS |
1117 | } |
1118 | opts = nextopt; | |
1119 | } | |
3264ff12 | 1120 | } else if (strstart(p, "vnc", &opts)) { |
7a61f438 GH |
1121 | /* |
1122 | * vnc isn't a (local) DisplayType but a protocol for remote | |
1123 | * display access. | |
1124 | */ | |
4db14629 | 1125 | if (*opts == '=') { |
653c9747 | 1126 | vnc_parse(opts + 1); |
4db14629 | 1127 | } else { |
c6bf0f7f | 1128 | error_report("VNC requires a display argument vnc=<display>"); |
3264ff12 JS |
1129 | exit(1); |
1130 | } | |
1472a95b | 1131 | } else { |
776d1344 | 1132 | parse_display_qapi(p); |
1472a95b | 1133 | } |
1472a95b JS |
1134 | } |
1135 | ||
6407d76e GS |
1136 | static inline bool nonempty_str(const char *str) |
1137 | { | |
1138 | return str && *str; | |
1139 | } | |
1140 | ||
81b2b810 GS |
1141 | static int parse_fw_cfg(void *opaque, QemuOpts *opts, Error **errp) |
1142 | { | |
1143 | gchar *buf; | |
1144 | size_t size; | |
6552d87c | 1145 | const char *name, *file, *str, *gen_id; |
bab47d9a | 1146 | FWCfgState *fw_cfg = (FWCfgState *) opaque; |
81b2b810 | 1147 | |
bab47d9a | 1148 | if (fw_cfg == NULL) { |
406b6367 | 1149 | error_setg(errp, "fw_cfg device not available"); |
81b2b810 GS |
1150 | return -1; |
1151 | } | |
1152 | name = qemu_opt_get(opts, "name"); | |
1153 | file = qemu_opt_get(opts, "file"); | |
6407d76e | 1154 | str = qemu_opt_get(opts, "string"); |
6552d87c | 1155 | gen_id = qemu_opt_get(opts, "gen_id"); |
6407d76e | 1156 | |
6552d87c PMD |
1157 | /* we need the name, and exactly one of: file, content string, gen_id */ |
1158 | if (!nonempty_str(name) || | |
1159 | nonempty_str(file) + nonempty_str(str) + nonempty_str(gen_id) != 1) { | |
1160 | error_setg(errp, "name, plus exactly one of file," | |
1161 | " string and gen_id, are needed"); | |
81b2b810 GS |
1162 | return -1; |
1163 | } | |
1164 | if (strlen(name) > FW_CFG_MAX_FILE_PATH - 1) { | |
406b6367 MA |
1165 | error_setg(errp, "name too long (max. %d char)", |
1166 | FW_CFG_MAX_FILE_PATH - 1); | |
81b2b810 GS |
1167 | return -1; |
1168 | } | |
f7d8afb1 PMD |
1169 | if (nonempty_str(gen_id)) { |
1170 | /* | |
1171 | * In this particular case where the content is populated | |
1172 | * internally, the "etc/" namespace protection is relaxed, | |
1173 | * so do not emit a warning. | |
1174 | */ | |
1175 | } else if (strncmp(name, "opt/", 4) != 0) { | |
3dc6f869 AF |
1176 | warn_report("externally provided fw_cfg item names " |
1177 | "should be prefixed with \"opt/\""); | |
81b2b810 | 1178 | } |
6407d76e GS |
1179 | if (nonempty_str(str)) { |
1180 | size = strlen(str); /* NUL terminator NOT included in fw_cfg blob */ | |
1181 | buf = g_memdup(str, size); | |
6552d87c | 1182 | } else if (nonempty_str(gen_id)) { |
07719518 | 1183 | if (!fw_cfg_add_from_generator(fw_cfg, name, gen_id, errp)) { |
6552d87c PMD |
1184 | return -1; |
1185 | } | |
1186 | return 0; | |
6407d76e | 1187 | } else { |
353c7d58 LQ |
1188 | GError *err = NULL; |
1189 | if (!g_file_get_contents(file, &buf, &size, &err)) { | |
1190 | error_setg(errp, "can't load %s: %s", file, err->message); | |
1191 | g_error_free(err); | |
6407d76e GS |
1192 | return -1; |
1193 | } | |
81b2b810 | 1194 | } |
bab47d9a GH |
1195 | /* For legacy, keep user files in a specific global order. */ |
1196 | fw_cfg_set_order_override(fw_cfg, FW_CFG_ORDER_OVERRIDE_USER); | |
1197 | fw_cfg_add_file(fw_cfg, name, buf, size); | |
1198 | fw_cfg_reset_order_override(fw_cfg); | |
81b2b810 GS |
1199 | return 0; |
1200 | } | |
1201 | ||
28d0de7a | 1202 | static int device_help_func(void *opaque, QemuOpts *opts, Error **errp) |
ff952ba2 MA |
1203 | { |
1204 | return qdev_device_help(opts); | |
1205 | } | |
1206 | ||
28d0de7a | 1207 | static int device_init_func(void *opaque, QemuOpts *opts, Error **errp) |
f31d07d1 GH |
1208 | { |
1209 | DeviceState *dev; | |
1210 | ||
cd65f349 | 1211 | dev = qdev_device_add(opts, errp); |
f3a85056 JF |
1212 | if (!dev && *errp) { |
1213 | error_report_err(*errp); | |
f31d07d1 | 1214 | return -1; |
f3a85056 JF |
1215 | } else if (dev) { |
1216 | object_unref(OBJECT(dev)); | |
f006cf7f | 1217 | } |
f31d07d1 GH |
1218 | return 0; |
1219 | } | |
1220 | ||
28d0de7a | 1221 | static int chardev_init_func(void *opaque, QemuOpts *opts, Error **errp) |
1a688d3b | 1222 | { |
bd2d80b2 | 1223 | Error *local_err = NULL; |
1a688d3b | 1224 | |
4ad6f6cb | 1225 | if (!qemu_chr_new_from_opts(opts, NULL, &local_err)) { |
0ec846bf | 1226 | if (local_err) { |
dd4af977 | 1227 | error_propagate(errp, local_err); |
0ec846bf AN |
1228 | return -1; |
1229 | } | |
1230 | exit(0); | |
bd2d80b2 | 1231 | } |
1a688d3b GH |
1232 | return 0; |
1233 | } | |
1234 | ||
758e8e38 | 1235 | #ifdef CONFIG_VIRTFS |
28d0de7a | 1236 | static int fsdev_init_func(void *opaque, QemuOpts *opts, Error **errp) |
74db920c | 1237 | { |
b836723d | 1238 | return qemu_fsdev_add(opts, errp); |
74db920c GS |
1239 | } |
1240 | #endif | |
1241 | ||
28d0de7a | 1242 | static int mon_init_func(void *opaque, QemuOpts *opts, Error **errp) |
88589343 | 1243 | { |
c3e95551 | 1244 | return monitor_init_opts(opts, errp); |
88589343 GH |
1245 | } |
1246 | ||
4821cd4c | 1247 | static void monitor_parse(const char *optarg, const char *mode, bool pretty) |
88589343 GH |
1248 | { |
1249 | static int monitor_device_index = 0; | |
1250 | QemuOpts *opts; | |
1251 | const char *p; | |
1252 | char label[32]; | |
88589343 GH |
1253 | |
1254 | if (strstart(optarg, "chardev:", &p)) { | |
1255 | snprintf(label, sizeof(label), "%s", p); | |
1256 | } else { | |
140e065d JK |
1257 | snprintf(label, sizeof(label), "compat_monitor%d", |
1258 | monitor_device_index); | |
95e30b2a | 1259 | opts = qemu_chr_parse_compat(label, optarg, true); |
88589343 | 1260 | if (!opts) { |
f61eddcb | 1261 | error_report("parse error: %s", optarg); |
88589343 GH |
1262 | exit(1); |
1263 | } | |
1264 | } | |
1265 | ||
822ac12d | 1266 | opts = qemu_opts_create(qemu_find_opts("mon"), label, 1, &error_fatal); |
f43e47db MA |
1267 | qemu_opt_set(opts, "mode", mode, &error_abort); |
1268 | qemu_opt_set(opts, "chardev", label, &error_abort); | |
3c45f625 KW |
1269 | if (!strcmp(mode, "control")) { |
1270 | qemu_opt_set_bool(opts, "pretty", pretty, &error_abort); | |
1271 | } else { | |
1272 | assert(pretty == false); | |
1273 | } | |
88589343 GH |
1274 | monitor_device_index++; |
1275 | } | |
1276 | ||
bd3c948d GH |
1277 | struct device_config { |
1278 | enum { | |
aee1b935 | 1279 | DEV_USB, /* -usbdevice */ |
aee1b935 GH |
1280 | DEV_SERIAL, /* -serial */ |
1281 | DEV_PARALLEL, /* -parallel */ | |
c9f398e5 | 1282 | DEV_DEBUGCON, /* -debugcon */ |
ef0c4a0d | 1283 | DEV_GDB, /* -gdb, -s */ |
3ef669e1 | 1284 | DEV_SCLP, /* s390 sclp */ |
bd3c948d GH |
1285 | } type; |
1286 | const char *cmdline; | |
d9a5954d | 1287 | Location loc; |
72cf2d4f | 1288 | QTAILQ_ENTRY(device_config) next; |
bd3c948d | 1289 | }; |
4fdcac0e BS |
1290 | |
1291 | static QTAILQ_HEAD(, device_config) device_configs = | |
1292 | QTAILQ_HEAD_INITIALIZER(device_configs); | |
bd3c948d GH |
1293 | |
1294 | static void add_device_config(int type, const char *cmdline) | |
1295 | { | |
1296 | struct device_config *conf; | |
1297 | ||
7267c094 | 1298 | conf = g_malloc0(sizeof(*conf)); |
bd3c948d GH |
1299 | conf->type = type; |
1300 | conf->cmdline = cmdline; | |
d9a5954d | 1301 | loc_save(&conf->loc); |
72cf2d4f | 1302 | QTAILQ_INSERT_TAIL(&device_configs, conf, next); |
bd3c948d GH |
1303 | } |
1304 | ||
1305 | static int foreach_device_config(int type, int (*func)(const char *cmdline)) | |
1306 | { | |
1307 | struct device_config *conf; | |
1308 | int rc; | |
1309 | ||
72cf2d4f | 1310 | QTAILQ_FOREACH(conf, &device_configs, next) { |
bd3c948d GH |
1311 | if (conf->type != type) |
1312 | continue; | |
d9a5954d | 1313 | loc_push_restore(&conf->loc); |
bd3c948d | 1314 | rc = func(conf->cmdline); |
d9a5954d | 1315 | loc_pop(&conf->loc); |
28de2f88 | 1316 | if (rc) { |
bd3c948d | 1317 | return rc; |
28de2f88 | 1318 | } |
bd3c948d GH |
1319 | } |
1320 | return 0; | |
1321 | } | |
1322 | ||
f650266b PB |
1323 | static void qemu_disable_default_devices(void) |
1324 | { | |
1325 | MachineClass *machine_class = MACHINE_GET_CLASS(current_machine); | |
1326 | ||
1327 | qemu_opts_foreach(qemu_find_opts("device"), | |
1328 | default_driver_check, NULL, NULL); | |
1329 | qemu_opts_foreach(qemu_find_opts("global"), | |
1330 | default_driver_check, NULL, NULL); | |
1331 | ||
1332 | if (!vga_model && !default_vga) { | |
1333 | vga_interface_type = VGA_DEVICE; | |
1334 | } | |
1335 | if (!has_defaults || machine_class->no_serial) { | |
1336 | default_serial = 0; | |
1337 | } | |
1338 | if (!has_defaults || machine_class->no_parallel) { | |
1339 | default_parallel = 0; | |
1340 | } | |
1341 | if (!has_defaults || machine_class->no_floppy) { | |
1342 | default_floppy = 0; | |
1343 | } | |
1344 | if (!has_defaults || machine_class->no_cdrom) { | |
1345 | default_cdrom = 0; | |
1346 | } | |
1347 | if (!has_defaults || machine_class->no_sdcard) { | |
1348 | default_sdcard = 0; | |
1349 | } | |
1350 | if (!has_defaults) { | |
1351 | default_monitor = 0; | |
1352 | default_net = 0; | |
1353 | default_vga = 0; | |
1354 | } | |
1355 | } | |
1356 | ||
1357 | static void qemu_create_default_devices(void) | |
1358 | { | |
1359 | MachineClass *machine_class = MACHINE_GET_CLASS(current_machine); | |
1360 | ||
1361 | if (is_daemonized()) { | |
1362 | /* According to documentation and historically, -nographic redirects | |
1363 | * serial port, parallel port and monitor to stdio, which does not work | |
1364 | * with -daemonize. We can redirect these to null instead, but since | |
1365 | * -nographic is legacy, let's just error out. | |
1366 | * We disallow -nographic only if all other ports are not redirected | |
1367 | * explicitly, to not break existing legacy setups which uses | |
1368 | * -nographic _and_ redirects all ports explicitly - this is valid | |
1369 | * usage, -nographic is just a no-op in this case. | |
1370 | */ | |
1371 | if (nographic | |
1372 | && (default_parallel || default_serial || default_monitor)) { | |
1373 | error_report("-nographic cannot be used with -daemonize"); | |
1374 | exit(1); | |
1375 | } | |
1376 | } | |
1377 | ||
1378 | if (nographic) { | |
1379 | if (default_parallel) | |
1380 | add_device_config(DEV_PARALLEL, "null"); | |
1381 | if (default_serial && default_monitor) { | |
1382 | add_device_config(DEV_SERIAL, "mon:stdio"); | |
1383 | } else { | |
1384 | if (default_serial) | |
1385 | add_device_config(DEV_SERIAL, "stdio"); | |
1386 | if (default_monitor) | |
1387 | monitor_parse("stdio", "readline", false); | |
1388 | } | |
1389 | } else { | |
1390 | if (default_serial) | |
1391 | add_device_config(DEV_SERIAL, "vc:80Cx24C"); | |
1392 | if (default_parallel) | |
1393 | add_device_config(DEV_PARALLEL, "vc:80Cx24C"); | |
1394 | if (default_monitor) | |
1395 | monitor_parse("vc:80Cx24C", "readline", false); | |
1396 | } | |
1397 | ||
1398 | if (default_net) { | |
1399 | QemuOptsList *net = qemu_find_opts("net"); | |
1400 | qemu_opts_parse(net, "nic", true, &error_abort); | |
1401 | #ifdef CONFIG_SLIRP | |
1402 | qemu_opts_parse(net, "user", true, &error_abort); | |
1403 | #endif | |
1404 | } | |
1405 | ||
1406 | #if defined(CONFIG_VNC) | |
1407 | if (!QTAILQ_EMPTY(&(qemu_find_opts("vnc")->head))) { | |
1408 | display_remote++; | |
1409 | } | |
1410 | #endif | |
1411 | if (dpy.type == DISPLAY_TYPE_DEFAULT && !display_remote) { | |
1412 | if (!qemu_display_find_default(&dpy)) { | |
1413 | dpy.type = DISPLAY_TYPE_NONE; | |
1414 | #if defined(CONFIG_VNC) | |
653c9747 | 1415 | vnc_parse("localhost:0,to=99,id=default"); |
f650266b PB |
1416 | #endif |
1417 | } | |
1418 | } | |
1419 | if (dpy.type == DISPLAY_TYPE_DEFAULT) { | |
1420 | dpy.type = DISPLAY_TYPE_NONE; | |
1421 | } | |
1422 | ||
1423 | /* If no default VGA is requested, the default is "none". */ | |
1424 | if (default_vga) { | |
1425 | vga_model = get_default_vga_model(machine_class); | |
1426 | } | |
1427 | if (vga_model) { | |
1428 | select_vgahw(machine_class, vga_model); | |
1429 | } | |
1430 | } | |
1431 | ||
998bbd74 GH |
1432 | static int serial_parse(const char *devname) |
1433 | { | |
6af2692e | 1434 | int index = num_serial_hds; |
998bbd74 GH |
1435 | char label[32]; |
1436 | ||
1437 | if (strcmp(devname, "none") == 0) | |
1438 | return 0; | |
998bbd74 | 1439 | snprintf(label, sizeof(label), "serial%d", index); |
6af2692e PM |
1440 | serial_hds = g_renew(Chardev *, serial_hds, index + 1); |
1441 | ||
4ad6f6cb | 1442 | serial_hds[index] = qemu_chr_new_mux_mon(label, devname, NULL); |
998bbd74 | 1443 | if (!serial_hds[index]) { |
f61eddcb EH |
1444 | error_report("could not connect serial device" |
1445 | " to character backend '%s'", devname); | |
998bbd74 GH |
1446 | return -1; |
1447 | } | |
6af2692e | 1448 | num_serial_hds++; |
998bbd74 GH |
1449 | return 0; |
1450 | } | |
1451 | ||
a8d78cd0 PM |
1452 | Chardev *serial_hd(int i) |
1453 | { | |
1454 | assert(i >= 0); | |
6af2692e | 1455 | if (i < num_serial_hds) { |
a8d78cd0 PM |
1456 | return serial_hds[i]; |
1457 | } | |
1458 | return NULL; | |
1459 | } | |
1460 | ||
6a5e8b0e GH |
1461 | static int parallel_parse(const char *devname) |
1462 | { | |
1463 | static int index = 0; | |
1464 | char label[32]; | |
1465 | ||
1466 | if (strcmp(devname, "none") == 0) | |
1467 | return 0; | |
1468 | if (index == MAX_PARALLEL_PORTS) { | |
f61eddcb | 1469 | error_report("too many parallel ports"); |
6a5e8b0e GH |
1470 | exit(1); |
1471 | } | |
1472 | snprintf(label, sizeof(label), "parallel%d", index); | |
4ad6f6cb | 1473 | parallel_hds[index] = qemu_chr_new_mux_mon(label, devname, NULL); |
6a5e8b0e | 1474 | if (!parallel_hds[index]) { |
f61eddcb EH |
1475 | error_report("could not connect parallel device" |
1476 | " to character backend '%s'", devname); | |
6a5e8b0e GH |
1477 | return -1; |
1478 | } | |
1479 | index++; | |
1480 | return 0; | |
1481 | } | |
1482 | ||
c9f398e5 | 1483 | static int debugcon_parse(const char *devname) |
4d8b3c63 | 1484 | { |
c9f398e5 PA |
1485 | QemuOpts *opts; |
1486 | ||
4ad6f6cb | 1487 | if (!qemu_chr_new_mux_mon("debugcon", devname, NULL)) { |
d7ecf712 | 1488 | error_report("invalid character backend '%s'", devname); |
c9f398e5 PA |
1489 | exit(1); |
1490 | } | |
8be7e7e4 | 1491 | opts = qemu_opts_create(qemu_find_opts("device"), "debugcon", 1, NULL); |
c9f398e5 | 1492 | if (!opts) { |
f61eddcb | 1493 | error_report("already have a debugcon device"); |
c9f398e5 PA |
1494 | exit(1); |
1495 | } | |
f43e47db MA |
1496 | qemu_opt_set(opts, "driver", "isa-debugcon", &error_abort); |
1497 | qemu_opt_set(opts, "chardev", "debugcon", &error_abort); | |
c9f398e5 PA |
1498 | return 0; |
1499 | } | |
1500 | ||
2709f263 LE |
1501 | static gint machine_class_cmp(gconstpointer a, gconstpointer b) |
1502 | { | |
1503 | const MachineClass *mc1 = a, *mc2 = b; | |
1504 | int res; | |
1505 | ||
1506 | if (mc1->family == NULL) { | |
1507 | if (mc2->family == NULL) { | |
1508 | /* Compare standalone machine types against each other; they sort | |
1509 | * in increasing order. | |
1510 | */ | |
1511 | return strcmp(object_class_get_name(OBJECT_CLASS(mc1)), | |
1512 | object_class_get_name(OBJECT_CLASS(mc2))); | |
1513 | } | |
1514 | ||
1515 | /* Standalone machine types sort after families. */ | |
1516 | return 1; | |
1517 | } | |
1518 | ||
1519 | if (mc2->family == NULL) { | |
1520 | /* Families sort before standalone machine types. */ | |
1521 | return -1; | |
1522 | } | |
1523 | ||
1524 | /* Families sort between each other alphabetically increasingly. */ | |
1525 | res = strcmp(mc1->family, mc2->family); | |
1526 | if (res != 0) { | |
1527 | return res; | |
1528 | } | |
1529 | ||
1530 | /* Within the same family, machine types sort in decreasing order. */ | |
1531 | return strcmp(object_class_get_name(OBJECT_CLASS(mc2)), | |
1532 | object_class_get_name(OBJECT_CLASS(mc1))); | |
1533 | } | |
1534 | ||
c516cd1b | 1535 | static MachineClass *machine_parse(const char *name, GSList *machines) |
9052ea6b | 1536 | { |
12cb82fd | 1537 | MachineClass *mc; |
c516cd1b | 1538 | GSList *el; |
9052ea6b | 1539 | |
12cb82fd | 1540 | if (is_help_option(name)) { |
025172d5 | 1541 | printf("Supported machines are:\n"); |
2709f263 | 1542 | machines = g_slist_sort(machines, machine_class_cmp); |
025172d5 MR |
1543 | for (el = machines; el; el = el->next) { |
1544 | MachineClass *mc = el->data; | |
958db90c MA |
1545 | if (mc->alias) { |
1546 | printf("%-20s %s (alias of %s)\n", mc->alias, mc->desc, mc->name); | |
025172d5 | 1547 | } |
08fe6824 TH |
1548 | printf("%-20s %s%s%s\n", mc->name, mc->desc, |
1549 | mc->is_default ? " (default)" : "", | |
1550 | mc->deprecation_reason ? " (deprecated)" : ""); | |
9052ea6b | 1551 | } |
12cb82fd | 1552 | exit(0); |
9052ea6b | 1553 | } |
261747f1 | 1554 | |
12cb82fd MA |
1555 | mc = find_machine(name, machines); |
1556 | if (!mc) { | |
1557 | error_report("unsupported machine type"); | |
1558 | error_printf("Use -machine help to list supported machines\n"); | |
1559 | exit(1); | |
1560 | } | |
1561 | return mc; | |
9052ea6b JK |
1562 | } |
1563 | ||
90a84d13 MAL |
1564 | static const char *pid_file; |
1565 | static Notifier qemu_unlink_pidfile_notifier; | |
1566 | ||
1567 | static void qemu_unlink_pidfile(Notifier *n, void *data) | |
1568 | { | |
1569 | if (pid_file) { | |
1570 | unlink(pid_file); | |
1571 | } | |
1572 | } | |
1573 | ||
6530a97b AL |
1574 | static const QEMUOption *lookup_opt(int argc, char **argv, |
1575 | const char **poptarg, int *poptind) | |
1576 | { | |
1577 | const QEMUOption *popt; | |
1578 | int optind = *poptind; | |
1579 | char *r = argv[optind]; | |
1580 | const char *optarg; | |
1581 | ||
0f0bc3f1 | 1582 | loc_set_cmdline(argv, optind, 1); |
6530a97b AL |
1583 | optind++; |
1584 | /* Treat --foo the same as -foo. */ | |
1585 | if (r[1] == '-') | |
1586 | r++; | |
1587 | popt = qemu_options; | |
1588 | for(;;) { | |
1589 | if (!popt->name) { | |
0f0bc3f1 | 1590 | error_report("invalid option"); |
6530a97b AL |
1591 | exit(1); |
1592 | } | |
1593 | if (!strcmp(popt->name, r + 1)) | |
1594 | break; | |
1595 | popt++; | |
1596 | } | |
1597 | if (popt->flags & HAS_ARG) { | |
1598 | if (optind >= argc) { | |
0f0bc3f1 | 1599 | error_report("requires an argument"); |
6530a97b AL |
1600 | exit(1); |
1601 | } | |
1602 | optarg = argv[optind++]; | |
0f0bc3f1 | 1603 | loc_set_cmdline(argv, optind - 2, 2); |
6530a97b AL |
1604 | } else { |
1605 | optarg = NULL; | |
1606 | } | |
1607 | ||
1608 | *poptarg = optarg; | |
1609 | *poptind = optind; | |
1610 | ||
1611 | return popt; | |
1612 | } | |
1613 | ||
7580f231 | 1614 | static MachineClass *select_machine(void) |
34f405ae | 1615 | { |
c516cd1b WY |
1616 | GSList *machines = object_class_get_list(TYPE_MACHINE, false); |
1617 | MachineClass *machine_class = find_default_machine(machines); | |
34f405ae MA |
1618 | const char *optarg; |
1619 | QemuOpts *opts; | |
1620 | Location loc; | |
1621 | ||
1622 | loc_push_none(&loc); | |
1623 | ||
1624 | opts = qemu_get_machine_opts(); | |
1625 | qemu_opts_loc_restore(opts); | |
1626 | ||
1627 | optarg = qemu_opt_get(opts, "type"); | |
1628 | if (optarg) { | |
c516cd1b | 1629 | machine_class = machine_parse(optarg, machines); |
34f405ae MA |
1630 | } |
1631 | ||
7580f231 | 1632 | if (!machine_class) { |
34f405ae MA |
1633 | error_report("No machine specified, and there is no default"); |
1634 | error_printf("Use -machine help to list supported machines\n"); | |
1635 | exit(1); | |
1636 | } | |
1637 | ||
1638 | loc_pop(&loc); | |
c516cd1b | 1639 | g_slist_free(machines); |
7580f231 | 1640 | return machine_class; |
34f405ae MA |
1641 | } |
1642 | ||
e5db4bd8 PB |
1643 | static int object_parse_property_opt(Object *obj, |
1644 | const char *name, const char *value, | |
1645 | const char *skip, Error **errp) | |
68d98d3e | 1646 | { |
e5db4bd8 | 1647 | if (g_str_equal(name, skip)) { |
68d98d3e AL |
1648 | return 0; |
1649 | } | |
1650 | ||
668f62ec | 1651 | if (!object_property_parse(obj, name, value, errp)) { |
68d98d3e AL |
1652 | return -1; |
1653 | } | |
1654 | ||
1655 | return 0; | |
1656 | } | |
1657 | ||
e5db4bd8 PB |
1658 | static int machine_set_property(void *opaque, |
1659 | const char *name, const char *value, | |
1660 | Error **errp) | |
1661 | { | |
1662 | g_autofree char *qom_name = g_strdup(name); | |
1663 | char *p; | |
1664 | ||
1665 | for (p = qom_name; *p; p++) { | |
1666 | if (*p == '_') { | |
1667 | *p = '-'; | |
1668 | } | |
1669 | } | |
1670 | ||
6f6e1698 PB |
1671 | /* Legacy options do not correspond to MachineState properties. */ |
1672 | if (g_str_equal(qom_name, "accel")) { | |
1673 | return 0; | |
1674 | } | |
46472d82 | 1675 | if (g_str_equal(qom_name, "igd-passthru")) { |
a8dc82ce GK |
1676 | object_register_sugar_prop(ACCEL_CLASS_NAME("xen"), qom_name, value, |
1677 | false); | |
46472d82 PB |
1678 | return 0; |
1679 | } | |
faf20793 | 1680 | if (g_str_equal(qom_name, "kvm-shadow-mem")) { |
a8dc82ce GK |
1681 | object_register_sugar_prop(ACCEL_CLASS_NAME("kvm"), qom_name, value, |
1682 | false); | |
23b0898e PB |
1683 | return 0; |
1684 | } | |
faf20793 | 1685 | if (g_str_equal(qom_name, "kernel-irqchip")) { |
a8dc82ce GK |
1686 | object_register_sugar_prop(ACCEL_CLASS_NAME("kvm"), qom_name, value, |
1687 | false); | |
1688 | object_register_sugar_prop(ACCEL_CLASS_NAME("whpx"), qom_name, value, | |
1689 | false); | |
faf20793 SM |
1690 | return 0; |
1691 | } | |
6f6e1698 | 1692 | |
e5db4bd8 PB |
1693 | return object_parse_property_opt(opaque, name, value, "type", errp); |
1694 | } | |
f08f9271 | 1695 | |
bc2f4fcb PB |
1696 | static void object_option_foreach_add(bool (*type_opt_predicate)(const char *)) |
1697 | { | |
1698 | ObjectOption *opt, *next; | |
1699 | ||
1700 | QTAILQ_FOREACH_SAFE(opt, &object_opts, next, next) { | |
1701 | const char *type = ObjectType_str(opt->opts->qom_type); | |
1702 | if (type_opt_predicate(type)) { | |
1703 | user_creatable_add_qapi(opt->opts, &error_fatal); | |
1704 | qapi_free_ObjectOptions(opt->opts); | |
1705 | QTAILQ_REMOVE(&object_opts, opt, next); | |
1706 | g_free(opt); | |
1707 | } | |
1708 | } | |
1709 | } | |
1710 | ||
1711 | static void object_option_parse(const char *optarg) | |
1712 | { | |
1713 | ObjectOption *opt; | |
1714 | QemuOpts *opts; | |
1715 | const char *type; | |
1716 | Visitor *v; | |
1717 | ||
009ff893 PB |
1718 | if (optarg[0] == '{') { |
1719 | QObject *obj = qobject_from_json(optarg, &error_fatal); | |
bc2f4fcb | 1720 | |
009ff893 PB |
1721 | v = qobject_input_visitor_new(obj); |
1722 | qobject_unref(obj); | |
1723 | } else { | |
1724 | opts = qemu_opts_parse_noisily(qemu_find_opts("object"), | |
1725 | optarg, true); | |
1726 | if (!opts) { | |
1727 | exit(1); | |
1728 | } | |
1729 | ||
1730 | type = qemu_opt_get(opts, "qom-type"); | |
1731 | if (!type) { | |
1732 | error_setg(&error_fatal, QERR_MISSING_PARAMETER, "qom-type"); | |
1733 | } | |
1734 | if (user_creatable_print_help(type, opts)) { | |
1735 | exit(0); | |
1736 | } | |
1737 | ||
1738 | v = opts_visitor_new(opts); | |
bc2f4fcb PB |
1739 | } |
1740 | ||
1741 | opt = g_new0(ObjectOption, 1); | |
bc2f4fcb PB |
1742 | visit_type_ObjectOptions(v, NULL, &opt->opts, &error_fatal); |
1743 | visit_free(v); | |
1744 | ||
1745 | QTAILQ_INSERT_TAIL(&object_opts, opt, next); | |
1746 | } | |
1747 | ||
f08f9271 DB |
1748 | /* |
1749 | * Initial object creation happens before all other | |
1750 | * QEMU data types are created. The majority of objects | |
1751 | * can be created at this point. The rng-egd object | |
1752 | * cannot be created here, as it depends on the chardev | |
1753 | * already existing. | |
1754 | */ | |
bc2f4fcb | 1755 | static bool object_create_early(const char *type) |
f08f9271 | 1756 | { |
edfb4389 MA |
1757 | /* |
1758 | * Objects should not be made "delayed" without a reason. If you | |
1759 | * add one, state the reason in a comment! | |
1760 | */ | |
1761 | ||
1762 | /* Reason: rng-egd property "chardev" */ | |
9ea18ed2 | 1763 | if (g_str_equal(type, "rng-egd")) { |
f08f9271 DB |
1764 | return false; |
1765 | } | |
7dbb11c8 | 1766 | |
042cea27 | 1767 | #if defined(CONFIG_VHOST_USER) && defined(CONFIG_LINUX) |
edfb4389 | 1768 | /* Reason: cryptodev-vhost-user property "chardev" */ |
042cea27 GA |
1769 | if (g_str_equal(type, "cryptodev-vhost-user")) { |
1770 | return false; | |
1771 | } | |
1772 | #endif | |
1773 | ||
3578389b CX |
1774 | /* Reason: vhost-user-blk-server property "node-name" */ |
1775 | if (g_str_equal(type, "vhost-user-blk-server")) { | |
1776 | return false; | |
1777 | } | |
9d3e12e8 | 1778 | /* |
edfb4389 | 1779 | * Reason: filter-* property "netdev" etc. |
9d3e12e8 TH |
1780 | */ |
1781 | if (g_str_equal(type, "filter-buffer") || | |
f6d3afb5 | 1782 | g_str_equal(type, "filter-dump") || |
d46f75b2 | 1783 | g_str_equal(type, "filter-mirror") || |
7dce4e6f | 1784 | g_str_equal(type, "filter-redirector") || |
e6eee8ab | 1785 | g_str_equal(type, "colo-compare") || |
646c5478 PD |
1786 | g_str_equal(type, "filter-rewriter") || |
1787 | g_str_equal(type, "filter-replay")) { | |
7dbb11c8 YH |
1788 | return false; |
1789 | } | |
1790 | ||
b86f59c7 CF |
1791 | /* |
1792 | * Allocation of large amounts of memory may delay | |
6546d0db EH |
1793 | * chardev initialization for too long, and trigger timeouts |
1794 | * on software that waits for a monitor socket to be created | |
1795 | * (e.g. libvirt). | |
1796 | */ | |
1797 | if (g_str_has_prefix(type, "memory-backend-")) { | |
1798 | return false; | |
1799 | } | |
1800 | ||
f08f9271 DB |
1801 | return true; |
1802 | } | |
1803 | ||
7a84268d PB |
1804 | static void qemu_apply_machine_options(void) |
1805 | { | |
1806 | MachineClass *machine_class = MACHINE_GET_CLASS(current_machine); | |
1807 | QemuOpts *machine_opts = qemu_get_machine_opts(); | |
4b7acd2a PB |
1808 | const char *boot_order = NULL; |
1809 | const char *boot_once = NULL; | |
7a84268d PB |
1810 | QemuOpts *opts; |
1811 | ||
1812 | qemu_opt_foreach(machine_opts, machine_set_property, current_machine, | |
1813 | &error_fatal); | |
1814 | current_machine->ram_size = ram_size; | |
1815 | current_machine->maxram_size = maxram_size; | |
1816 | current_machine->ram_slots = ram_slots; | |
1817 | ||
1818 | opts = qemu_opts_find(qemu_find_opts("boot-opts"), NULL); | |
1819 | if (opts) { | |
1820 | boot_order = qemu_opt_get(opts, "order"); | |
1821 | if (boot_order) { | |
1822 | validate_bootdevices(boot_order, &error_fatal); | |
1823 | } | |
1824 | ||
1825 | boot_once = qemu_opt_get(opts, "once"); | |
1826 | if (boot_once) { | |
1827 | validate_bootdevices(boot_once, &error_fatal); | |
1828 | } | |
1829 | ||
1830 | boot_menu = qemu_opt_get_bool(opts, "menu", boot_menu); | |
1831 | boot_strict = qemu_opt_get_bool(opts, "strict", false); | |
1832 | } | |
1833 | ||
1834 | if (!boot_order) { | |
1835 | boot_order = machine_class->default_boot_order; | |
1836 | } | |
1837 | ||
1838 | current_machine->boot_order = boot_order; | |
4b7acd2a | 1839 | current_machine->boot_once = boot_once; |
7a84268d PB |
1840 | |
1841 | if (semihosting_enabled() && !semihosting_get_argc()) { | |
1842 | const char *kernel_filename = qemu_opt_get(machine_opts, "kernel"); | |
1843 | const char *kernel_cmdline = qemu_opt_get(machine_opts, "append") ?: ""; | |
1844 | /* fall back to the -kernel/-append */ | |
1845 | semihosting_arg_fallback(kernel_filename, kernel_cmdline); | |
1846 | } | |
7a84268d PB |
1847 | } |
1848 | ||
64418657 PB |
1849 | static void qemu_create_early_backends(void) |
1850 | { | |
1851 | MachineClass *machine_class = MACHINE_GET_CLASS(current_machine); | |
1852 | ||
1853 | if ((alt_grab || ctrl_grab) && dpy.type != DISPLAY_TYPE_SDL) { | |
1854 | error_report("-alt-grab and -ctrl-grab are only valid " | |
1855 | "for SDL, ignoring option"); | |
1856 | } | |
1857 | if (dpy.has_window_close && | |
1858 | (dpy.type != DISPLAY_TYPE_GTK && dpy.type != DISPLAY_TYPE_SDL)) { | |
1859 | error_report("-no-quit is only valid for GTK and SDL, " | |
1860 | "ignoring option"); | |
1861 | } | |
1862 | ||
1863 | qemu_display_early_init(&dpy); | |
1864 | qemu_console_early_init(); | |
1865 | ||
1866 | if (dpy.has_gl && dpy.gl != DISPLAYGL_MODE_OFF && display_opengl == 0) { | |
1867 | #if defined(CONFIG_OPENGL) | |
1868 | error_report("OpenGL is not supported by the display"); | |
1869 | #else | |
1870 | error_report("OpenGL support is disabled"); | |
1871 | #endif | |
1872 | exit(1); | |
1873 | } | |
1874 | ||
bc2f4fcb | 1875 | object_option_foreach_add(object_create_early); |
64418657 PB |
1876 | |
1877 | /* spice needs the timers to be initialized by this point */ | |
1878 | /* spice must initialize before audio as it changes the default auiodev */ | |
1879 | /* spice must initialize before chardevs (for spicevmc and spiceport) */ | |
1880 | qemu_spice.init(); | |
1881 | ||
1882 | qemu_opts_foreach(qemu_find_opts("chardev"), | |
1883 | chardev_init_func, NULL, &error_fatal); | |
1884 | ||
1885 | #ifdef CONFIG_VIRTFS | |
1886 | qemu_opts_foreach(qemu_find_opts("fsdev"), | |
1887 | fsdev_init_func, NULL, &error_fatal); | |
1888 | #endif | |
1889 | ||
1890 | /* | |
1891 | * Note: we need to create audio and block backends before | |
1892 | * machine_set_property(), so machine properties can refer to | |
1893 | * them. | |
1894 | */ | |
1895 | configure_blockdev(&bdo_queue, machine_class, snapshot); | |
1896 | audio_init_audiodevs(); | |
1897 | } | |
1898 | ||
f08f9271 DB |
1899 | |
1900 | /* | |
1901 | * The remainder of object creation happens after the | |
9abce56d | 1902 | * creation of chardev, fsdev, net clients and device data types. |
f08f9271 | 1903 | */ |
bc2f4fcb | 1904 | static bool object_create_late(const char *type) |
f08f9271 | 1905 | { |
bc2f4fcb | 1906 | return !object_create_early(type); |
f08f9271 DB |
1907 | } |
1908 | ||
07a91b1a PB |
1909 | static void qemu_create_late_backends(void) |
1910 | { | |
1911 | if (qtest_chrdev) { | |
1912 | qtest_server_init(qtest_chrdev, qtest_log, &error_fatal); | |
1913 | } | |
1914 | ||
1915 | net_init_clients(&error_fatal); | |
1916 | ||
bc2f4fcb | 1917 | object_option_foreach_add(object_create_late); |
07a91b1a PB |
1918 | |
1919 | if (tpm_init() < 0) { | |
1920 | exit(1); | |
1921 | } | |
1922 | ||
1923 | qemu_opts_foreach(qemu_find_opts("mon"), | |
1924 | mon_init_func, NULL, &error_fatal); | |
1925 | ||
1926 | if (foreach_device_config(DEV_SERIAL, serial_parse) < 0) | |
1927 | exit(1); | |
1928 | if (foreach_device_config(DEV_PARALLEL, parallel_parse) < 0) | |
1929 | exit(1); | |
1930 | if (foreach_device_config(DEV_DEBUGCON, debugcon_parse) < 0) | |
1931 | exit(1); | |
1932 | ||
1933 | /* now chardevs have been created we may have semihosting to connect */ | |
1934 | qemu_semihosting_connect_chardevs(); | |
1935 | qemu_semihosting_console_init(); | |
1936 | } | |
f08f9271 | 1937 | |
f5c9fcb8 PB |
1938 | static bool have_custom_ram_size(void) |
1939 | { | |
1940 | QemuOpts *opts = qemu_find_opts_singleton("memory"); | |
1941 | return !!qemu_opt_get_size(opts, "size", 0); | |
1942 | } | |
1943 | ||
b24986e7 PB |
1944 | static void qemu_resolve_machine_memdev(void) |
1945 | { | |
1946 | if (current_machine->ram_memdev_id) { | |
1947 | Object *backend; | |
1948 | ram_addr_t backend_size; | |
1949 | ||
1950 | backend = object_resolve_path_type(current_machine->ram_memdev_id, | |
1951 | TYPE_MEMORY_BACKEND, NULL); | |
1952 | if (!backend) { | |
1953 | error_report("Memory backend '%s' not found", | |
1954 | current_machine->ram_memdev_id); | |
1955 | exit(EXIT_FAILURE); | |
1956 | } | |
1957 | backend_size = object_property_get_uint(backend, "size", &error_abort); | |
1958 | if (have_custom_ram_size() && backend_size != ram_size) { | |
1959 | error_report("Size specified by -m option must match size of " | |
1960 | "explicitly specified 'memory-backend' property"); | |
1961 | exit(EXIT_FAILURE); | |
1962 | } | |
1963 | if (mem_path) { | |
1964 | error_report("'-mem-path' can't be used together with" | |
1965 | "'-machine memory-backend'"); | |
1966 | exit(EXIT_FAILURE); | |
1967 | } | |
1968 | ram_size = backend_size; | |
1969 | } | |
1970 | ||
1971 | if (!xen_enabled()) { | |
1972 | /* On 32-bit hosts, QEMU is limited by virtual address space */ | |
1973 | if (ram_size > (2047 << 20) && HOST_LONG_BITS == 32) { | |
1974 | error_report("at most 2047 MB RAM can be simulated"); | |
1975 | exit(1); | |
1976 | } | |
1977 | } | |
1978 | } | |
1979 | ||
f5c9fcb8 | 1980 | static void set_memory_options(MachineClass *mc) |
3b9985e9 MA |
1981 | { |
1982 | uint64_t sz; | |
1983 | const char *mem_str; | |
076b35b5 | 1984 | const ram_addr_t default_ram_size = mc->default_ram_size; |
3b9985e9 | 1985 | QemuOpts *opts = qemu_find_opts_singleton("memory"); |
bbe2d25c EH |
1986 | Location loc; |
1987 | ||
1988 | loc_push_none(&loc); | |
1989 | qemu_opts_loc_restore(opts); | |
3b9985e9 MA |
1990 | |
1991 | sz = 0; | |
1992 | mem_str = qemu_opt_get(opts, "size"); | |
1993 | if (mem_str) { | |
1994 | if (!*mem_str) { | |
1995 | error_report("missing 'size' option value"); | |
1996 | exit(EXIT_FAILURE); | |
1997 | } | |
1998 | ||
1999 | sz = qemu_opt_get_size(opts, "size", ram_size); | |
2000 | ||
2001 | /* Fix up legacy suffix-less format */ | |
2002 | if (g_ascii_isdigit(mem_str[strlen(mem_str) - 1])) { | |
2003 | uint64_t overflow_check = sz; | |
2004 | ||
3dc54b0e PMD |
2005 | sz *= MiB; |
2006 | if (sz / MiB != overflow_check) { | |
3b9985e9 MA |
2007 | error_report("too large 'size' option value"); |
2008 | exit(EXIT_FAILURE); | |
2009 | } | |
2010 | } | |
2011 | } | |
2012 | ||
2013 | /* backward compatibility behaviour for case "-m 0" */ | |
2014 | if (sz == 0) { | |
2015 | sz = default_ram_size; | |
2016 | } | |
2017 | ||
2018 | sz = QEMU_ALIGN_UP(sz, 8192); | |
5c30ef93 CB |
2019 | if (mc->fixup_ram_size) { |
2020 | sz = mc->fixup_ram_size(sz); | |
2021 | } | |
3b9985e9 MA |
2022 | ram_size = sz; |
2023 | if (ram_size != sz) { | |
2024 | error_report("ram size too large"); | |
2025 | exit(EXIT_FAILURE); | |
2026 | } | |
2027 | ||
2028 | /* store value for the future use */ | |
39101f25 | 2029 | qemu_opt_set_number(opts, "size", ram_size, &error_abort); |
f5c9fcb8 | 2030 | maxram_size = ram_size; |
3b9985e9 | 2031 | |
951f2269 | 2032 | if (qemu_opt_get(opts, "maxmem")) { |
3b9985e9 MA |
2033 | uint64_t slots; |
2034 | ||
2035 | sz = qemu_opt_get_size(opts, "maxmem", 0); | |
214224ad | 2036 | slots = qemu_opt_get_number(opts, "slots", 0); |
3b9985e9 | 2037 | if (sz < ram_size) { |
214224ad PK |
2038 | error_report("invalid value of -m option maxmem: " |
2039 | "maximum memory size (0x%" PRIx64 ") must be at least " | |
2040 | "the initial memory size (0x" RAM_ADDR_FMT ")", | |
2041 | sz, ram_size); | |
3b9985e9 | 2042 | exit(EXIT_FAILURE); |
951f2269 | 2043 | } else if (slots && sz == ram_size) { |
214224ad PK |
2044 | error_report("invalid value of -m option maxmem: " |
2045 | "memory slots were specified but maximum memory size " | |
2046 | "(0x%" PRIx64 ") is equal to the initial memory size " | |
2047 | "(0x" RAM_ADDR_FMT ")", sz, ram_size); | |
3b9985e9 MA |
2048 | exit(EXIT_FAILURE); |
2049 | } | |
2050 | ||
f5c9fcb8 PB |
2051 | maxram_size = sz; |
2052 | ram_slots = slots; | |
951f2269 DH |
2053 | } else if (qemu_opt_get(opts, "slots")) { |
2054 | error_report("invalid -m option value: missing 'maxmem' option"); | |
3b9985e9 MA |
2055 | exit(EXIT_FAILURE); |
2056 | } | |
bbe2d25c EH |
2057 | |
2058 | loc_pop(&loc); | |
f5c9fcb8 PB |
2059 | } |
2060 | ||
2061 | static void qemu_create_machine(MachineClass *machine_class) | |
2062 | { | |
2063 | object_set_machine_compat_props(machine_class->compat_props); | |
2064 | ||
2065 | set_memory_options(machine_class); | |
2066 | ||
2067 | current_machine = MACHINE(object_new_with_class(OBJECT_CLASS(machine_class))); | |
2068 | if (machine_help_func(qemu_get_machine_opts(), current_machine)) { | |
2069 | exit(0); | |
2070 | } | |
2071 | object_property_add_child(object_get_root(), "machine", | |
2072 | OBJECT(current_machine)); | |
2073 | object_property_add_child(container_get(OBJECT(current_machine), | |
2074 | "/unattached"), | |
2075 | "sysbus", OBJECT(sysbus_get_default())); | |
2076 | ||
2077 | if (machine_class->minimum_page_bits) { | |
2078 | if (!set_preferred_target_page_bits(machine_class->minimum_page_bits)) { | |
2079 | /* This would be a board error: specifying a minimum smaller than | |
2080 | * a target's compile-time fixed setting. | |
2081 | */ | |
2082 | g_assert_not_reached(); | |
2083 | } | |
2084 | } | |
2085 | ||
2086 | cpu_exec_init_all(); | |
2087 | page_size_init(); | |
2088 | ||
2089 | if (machine_class->hw_version) { | |
2090 | qemu_set_hw_version(machine_class->hw_version); | |
2091 | } | |
2092 | ||
2093 | machine_smp_parse(current_machine, | |
2094 | qemu_opts_find(qemu_find_opts("smp-opts"), NULL), &error_fatal); | |
2095 | ||
2096 | /* | |
2097 | * Get the default machine options from the machine if it is not already | |
2098 | * specified either by the configuration file or by the command line. | |
2099 | */ | |
2100 | if (machine_class->default_machine_opts) { | |
2101 | qemu_opts_set_defaults(qemu_find_opts("machine"), | |
2102 | machine_class->default_machine_opts, 0); | |
2103 | } | |
3b9985e9 MA |
2104 | } |
2105 | ||
8d76bfe8 EH |
2106 | static int global_init_func(void *opaque, QemuOpts *opts, Error **errp) |
2107 | { | |
2108 | GlobalProperty *g; | |
2109 | ||
2110 | g = g_malloc0(sizeof(*g)); | |
2111 | g->driver = qemu_opt_get(opts, "driver"); | |
2112 | g->property = qemu_opt_get(opts, "property"); | |
2113 | g->value = qemu_opt_get(opts, "value"); | |
8d76bfe8 EH |
2114 | qdev_prop_register_global(g); |
2115 | return 0; | |
2116 | } | |
2117 | ||
f7544edc | 2118 | static void qemu_read_default_config_file(Error **errp) |
726401be | 2119 | { |
f7544edc | 2120 | ERRP_GUARD(); |
726401be | 2121 | int ret; |
580e6ad6 | 2122 | g_autofree char *file = get_relocated_path(CONFIG_QEMU_CONFDIR "/qemu.conf"); |
726401be | 2123 | |
f7544edc PB |
2124 | ret = qemu_read_config_file(file, errp); |
2125 | if (ret < 0) { | |
2126 | if (ret == -ENOENT) { | |
2127 | error_free(*errp); | |
2128 | *errp = NULL; | |
2129 | } | |
726401be | 2130 | } |
726401be EH |
2131 | } |
2132 | ||
ed7fa564 PB |
2133 | static int qemu_set_option(const char *str) |
2134 | { | |
2135 | Error *local_err = NULL; | |
2136 | char group[64], id[64], arg[64]; | |
2137 | QemuOptsList *list; | |
2138 | QemuOpts *opts; | |
2139 | int rc, offset; | |
2140 | ||
2141 | rc = sscanf(str, "%63[^.].%63[^.].%63[^=]%n", group, id, arg, &offset); | |
2142 | if (rc < 3 || str[offset] != '=') { | |
2143 | error_report("can't parse: \"%s\"", str); | |
2144 | return -1; | |
2145 | } | |
2146 | ||
2147 | list = qemu_find_opts(group); | |
2148 | if (list == NULL) { | |
2149 | return -1; | |
2150 | } | |
2151 | ||
2152 | opts = qemu_opts_find(list, id); | |
2153 | if (!opts) { | |
2154 | error_report("there is no %s \"%s\" defined", | |
2155 | list->name, id); | |
2156 | return -1; | |
2157 | } | |
2158 | ||
2159 | if (!qemu_opt_set(opts, arg, str + offset + 1, &local_err)) { | |
2160 | error_report_err(local_err); | |
2161 | return -1; | |
2162 | } | |
2163 | return 0; | |
2164 | } | |
2165 | ||
a0660e0b PX |
2166 | static void user_register_global_props(void) |
2167 | { | |
2168 | qemu_opts_foreach(qemu_find_opts("global"), | |
2169 | global_init_func, NULL, NULL); | |
2170 | } | |
2171 | ||
7f8b6126 PB |
2172 | static int do_configure_icount(void *opaque, QemuOpts *opts, Error **errp) |
2173 | { | |
8191d368 | 2174 | icount_configure(opts, errp); |
7f8b6126 PB |
2175 | return 0; |
2176 | } | |
2177 | ||
12ceaef6 PB |
2178 | static int accelerator_set_property(void *opaque, |
2179 | const char *name, const char *value, | |
2180 | Error **errp) | |
2181 | { | |
2182 | return object_parse_property_opt(opaque, name, value, "accel", errp); | |
2183 | } | |
2184 | ||
deda73e8 PB |
2185 | static int do_configure_accelerator(void *opaque, QemuOpts *opts, Error **errp) |
2186 | { | |
6f6e1698 PB |
2187 | bool *p_init_failed = opaque; |
2188 | const char *acc = qemu_opt_get(opts, "accel"); | |
2189 | AccelClass *ac = accel_find(acc); | |
fc5cf826 | 2190 | AccelState *accel; |
6f6e1698 | 2191 | int ret; |
eaf65114 TH |
2192 | bool qtest_with_kvm; |
2193 | ||
2194 | qtest_with_kvm = g_str_equal(acc, "kvm") && qtest_chrdev != NULL; | |
6f6e1698 PB |
2195 | |
2196 | if (!ac) { | |
8b90f1c5 | 2197 | *p_init_failed = true; |
eaf65114 TH |
2198 | if (!qtest_with_kvm) { |
2199 | error_report("invalid accelerator %s", acc); | |
2200 | } | |
6f6e1698 PB |
2201 | return 0; |
2202 | } | |
fc5cf826 | 2203 | accel = ACCEL(object_new_with_class(OBJECT_CLASS(ac))); |
fe174132 | 2204 | object_apply_compat_props(OBJECT(accel)); |
12ceaef6 PB |
2205 | qemu_opt_foreach(opts, accelerator_set_property, |
2206 | accel, | |
2207 | &error_fatal); | |
2208 | ||
fc5cf826 | 2209 | ret = accel_init_machine(accel, current_machine); |
6f6e1698 PB |
2210 | if (ret < 0) { |
2211 | *p_init_failed = true; | |
eaf65114 TH |
2212 | if (!qtest_with_kvm || ret != -ENOENT) { |
2213 | error_report("failed to initialize %s: %s", acc, strerror(-ret)); | |
2214 | } | |
6f6e1698 PB |
2215 | return 0; |
2216 | } | |
fe174132 | 2217 | |
6f6e1698 | 2218 | return 1; |
deda73e8 PB |
2219 | } |
2220 | ||
28a09617 | 2221 | static void configure_accelerators(const char *progname) |
deda73e8 | 2222 | { |
7245ca74 | 2223 | const char *accelerators; |
28a09617 | 2224 | bool init_failed = false; |
28a09617 PB |
2225 | |
2226 | qemu_opts_foreach(qemu_find_opts("icount"), | |
2227 | do_configure_icount, NULL, &error_fatal); | |
2228 | ||
7245ca74 | 2229 | accelerators = qemu_opt_get(qemu_get_machine_opts(), "accel"); |
6f6e1698 | 2230 | if (QTAILQ_EMPTY(&qemu_accel_opts.head)) { |
60ee3552 RH |
2231 | char **accel_list, **tmp; |
2232 | ||
7245ca74 | 2233 | if (accelerators == NULL) { |
6f6e1698 | 2234 | /* Select the default accelerator */ |
755ee1f3 RH |
2235 | bool have_tcg = accel_find("tcg"); |
2236 | bool have_kvm = accel_find("kvm"); | |
2237 | ||
2238 | if (have_tcg && have_kvm) { | |
2239 | if (g_str_has_suffix(progname, "kvm")) { | |
6f6e1698 | 2240 | /* If the program name ends with "kvm", we prefer KVM */ |
7245ca74 | 2241 | accelerators = "kvm:tcg"; |
6f6e1698 | 2242 | } else { |
7245ca74 | 2243 | accelerators = "tcg:kvm"; |
6f6e1698 | 2244 | } |
755ee1f3 | 2245 | } else if (have_kvm) { |
7245ca74 | 2246 | accelerators = "kvm"; |
755ee1f3 | 2247 | } else if (have_tcg) { |
7245ca74 | 2248 | accelerators = "tcg"; |
755ee1f3 RH |
2249 | } else { |
2250 | error_report("No accelerator selected and" | |
2251 | " no default accelerator available"); | |
2252 | exit(1); | |
28a09617 PB |
2253 | } |
2254 | } | |
7245ca74 | 2255 | accel_list = g_strsplit(accelerators, ":", 0); |
28a09617 | 2256 | |
a024b090 | 2257 | for (tmp = accel_list; *tmp; tmp++) { |
6f6e1698 PB |
2258 | /* |
2259 | * Filter invalid accelerators here, to prevent obscenities | |
2260 | * such as "-machine accel=tcg,,thread=single". | |
2261 | */ | |
2262 | if (accel_find(*tmp)) { | |
2263 | qemu_opts_parse_noisily(qemu_find_opts("accel"), *tmp, true); | |
8b90f1c5 PB |
2264 | } else { |
2265 | init_failed = true; | |
2266 | error_report("invalid accelerator %s", *tmp); | |
6f6e1698 | 2267 | } |
28a09617 | 2268 | } |
adb464ff | 2269 | g_strfreev(accel_list); |
6f6e1698 | 2270 | } else { |
7245ca74 | 2271 | if (accelerators != NULL) { |
6f6e1698 PB |
2272 | error_report("The -accel and \"-machine accel=\" options are incompatible"); |
2273 | exit(1); | |
28a09617 PB |
2274 | } |
2275 | } | |
28a09617 | 2276 | |
6f6e1698 PB |
2277 | if (!qemu_opts_foreach(qemu_find_opts("accel"), |
2278 | do_configure_accelerator, &init_failed, &error_fatal)) { | |
28a09617 | 2279 | if (!init_failed) { |
6f6e1698 | 2280 | error_report("no accelerator found"); |
28a09617 PB |
2281 | } |
2282 | exit(1); | |
2283 | } | |
2284 | ||
eaf65114 | 2285 | if (init_failed && !qtest_chrdev) { |
4f7f5893 | 2286 | AccelClass *ac = ACCEL_GET_CLASS(current_accel()); |
8b90f1c5 | 2287 | error_report("falling back to %s", ac->name); |
28a09617 PB |
2288 | } |
2289 | ||
740b1759 | 2290 | if (icount_enabled() && !tcg_enabled()) { |
deda73e8 PB |
2291 | error_report("-icount is not allowed with hardware virtualization"); |
2292 | exit(1); | |
2293 | } | |
2294 | } | |
2295 | ||
ffac16fa | 2296 | static void create_default_memdev(MachineState *ms, const char *path) |
900c0ba3 IM |
2297 | { |
2298 | Object *obj; | |
2299 | MachineClass *mc = MACHINE_GET_CLASS(ms); | |
2300 | ||
2301 | obj = object_new(path ? TYPE_MEMORY_BACKEND_FILE : TYPE_MEMORY_BACKEND_RAM); | |
2302 | if (path) { | |
5325cc34 | 2303 | object_property_set_str(obj, "mem-path", path, &error_fatal); |
900c0ba3 | 2304 | } |
5325cc34 | 2305 | object_property_set_int(obj, "size", ms->ram_size, &error_fatal); |
900c0ba3 | 2306 | object_property_add_child(object_get_objects_root(), mc->default_ram_id, |
d2623129 | 2307 | obj); |
d96c4d5f | 2308 | /* Ensure backend's memory region name is equal to mc->default_ram_id */ |
5325cc34 MA |
2309 | object_property_set_bool(obj, "x-use-canonical-path-for-ramblock-id", |
2310 | false, &error_fatal); | |
900c0ba3 IM |
2311 | user_creatable_complete(USER_CREATABLE(obj), &error_fatal); |
2312 | object_unref(obj); | |
5325cc34 | 2313 | object_property_set_str(OBJECT(ms), "memory-backend", mc->default_ram_id, |
900c0ba3 IM |
2314 | &error_fatal); |
2315 | } | |
2316 | ||
58c91595 PB |
2317 | static void qemu_validate_options(void) |
2318 | { | |
2319 | QemuOpts *machine_opts = qemu_get_machine_opts(); | |
2320 | const char *kernel_filename = qemu_opt_get(machine_opts, "kernel"); | |
2321 | const char *initrd_filename = qemu_opt_get(machine_opts, "initrd"); | |
2322 | const char *kernel_cmdline = qemu_opt_get(machine_opts, "append"); | |
2323 | ||
2324 | if (kernel_filename == NULL) { | |
2325 | if (kernel_cmdline != NULL) { | |
2326 | error_report("-append only allowed with -kernel option"); | |
2327 | exit(1); | |
2328 | } | |
2329 | ||
2330 | if (initrd_filename != NULL) { | |
2331 | error_report("-initrd only allowed with -kernel option"); | |
2332 | exit(1); | |
2333 | } | |
2334 | } | |
2335 | ||
7691bdef | 2336 | if (loadvm && preconfig_requested) { |
90285ec8 PB |
2337 | error_report("'preconfig' and 'loadvm' options are " |
2338 | "mutually exclusive"); | |
2339 | exit(EXIT_FAILURE); | |
2340 | } | |
8fafaa04 PB |
2341 | if (incoming && preconfig_requested && strcmp(incoming, "defer") != 0) { |
2342 | error_report("'preconfig' supports '-incoming defer' only"); | |
58c91595 PB |
2343 | exit(EXIT_FAILURE); |
2344 | } | |
2345 | ||
2346 | #ifdef CONFIG_CURSES | |
2347 | if (is_daemonized() && dpy.type == DISPLAY_TYPE_CURSES) { | |
2348 | error_report("curses display cannot be used with -daemonize"); | |
2349 | exit(1); | |
2350 | } | |
2351 | #endif | |
2352 | } | |
2353 | ||
4d2c17b0 PB |
2354 | static void qemu_process_sugar_options(void) |
2355 | { | |
2356 | if (mem_prealloc) { | |
2357 | char *val; | |
2358 | ||
2359 | val = g_strdup_printf("%d", | |
2360 | (uint32_t) qemu_opt_get_number(qemu_find_opts_singleton("smp-opts"), "cpus", 1)); | |
a8dc82ce GK |
2361 | object_register_sugar_prop("memory-backend", "prealloc-threads", val, |
2362 | false); | |
4d2c17b0 | 2363 | g_free(val); |
a8dc82ce | 2364 | object_register_sugar_prop("memory-backend", "prealloc", "on", false); |
4d2c17b0 PB |
2365 | } |
2366 | ||
2367 | if (watchdog) { | |
2368 | int i = select_watchdog(watchdog); | |
2369 | if (i > 0) | |
2370 | exit (i == 1 ? 1 : 0); | |
2371 | } | |
2372 | } | |
2373 | ||
2a5ad60b AJ |
2374 | /* -action processing */ |
2375 | ||
2376 | /* | |
2377 | * Process all the -action parameters parsed from cmdline. | |
2378 | */ | |
2379 | static int process_runstate_actions(void *opaque, QemuOpts *opts, Error **errp) | |
2380 | { | |
2381 | Error *local_err = NULL; | |
2382 | QDict *qdict = qemu_opts_to_qdict(opts, NULL); | |
2383 | QObject *ret = NULL; | |
2384 | qmp_marshal_set_action(qdict, &ret, &local_err); | |
2385 | qobject_unref(ret); | |
2386 | qobject_unref(qdict); | |
2387 | if (local_err) { | |
2388 | error_propagate(errp, local_err); | |
2389 | return 1; | |
2390 | } | |
2391 | return 0; | |
2392 | } | |
2393 | ||
0546c060 PB |
2394 | static void qemu_process_early_options(void) |
2395 | { | |
0546c060 PB |
2396 | #ifdef CONFIG_SECCOMP |
2397 | QemuOptsList *olist = qemu_find_opts_err("sandbox", NULL); | |
2398 | if (olist) { | |
2399 | qemu_opts_foreach(olist, parse_sandbox, NULL, &error_fatal); | |
2400 | } | |
2401 | #endif | |
2402 | ||
2403 | qemu_opts_foreach(qemu_find_opts("name"), | |
2404 | parse_name, NULL, &error_fatal); | |
2405 | ||
2a5ad60b AJ |
2406 | if (qemu_opts_foreach(qemu_find_opts("action"), |
2407 | process_runstate_actions, NULL, &error_fatal)) { | |
2408 | exit(1); | |
2409 | } | |
2410 | ||
0546c060 PB |
2411 | #ifndef _WIN32 |
2412 | qemu_opts_foreach(qemu_find_opts("add-fd"), | |
2413 | parse_add_fd, NULL, &error_fatal); | |
2414 | ||
2415 | qemu_opts_foreach(qemu_find_opts("add-fd"), | |
2416 | cleanup_add_fd, NULL, &error_fatal); | |
2417 | #endif | |
2418 | ||
0546c060 | 2419 | /* Open the logfile at this point and set the log mask if necessary. */ |
7520c4f0 PB |
2420 | if (log_file) { |
2421 | qemu_set_log_filename(log_file, &error_fatal); | |
2422 | } | |
0546c060 PB |
2423 | if (log_mask) { |
2424 | int mask; | |
2425 | mask = qemu_str_to_log_mask(log_mask); | |
2426 | if (!mask) { | |
2427 | qemu_print_log_usage(stdout); | |
2428 | exit(1); | |
2429 | } | |
2430 | qemu_set_log(mask); | |
2431 | } else { | |
2432 | qemu_set_log(0); | |
2433 | } | |
2434 | ||
2c65db5e | 2435 | qemu_add_default_firmwarepath(); |
0546c060 PB |
2436 | } |
2437 | ||
2438 | static void qemu_process_help_options(void) | |
2439 | { | |
0546c060 PB |
2440 | /* |
2441 | * Check for -cpu help and -device help before we call select_machine(), | |
2442 | * which will return an error if the architecture has no default machine | |
2443 | * type and the user did not specify one, so that the user doesn't need | |
2444 | * to say '-cpu help -machine something'. | |
2445 | */ | |
2446 | if (cpu_option && is_help_option(cpu_option)) { | |
2447 | list_cpus(cpu_option); | |
2448 | exit(0); | |
2449 | } | |
2450 | ||
2451 | if (qemu_opts_foreach(qemu_find_opts("device"), | |
2452 | device_help_func, NULL, NULL)) { | |
2453 | exit(0); | |
2454 | } | |
2455 | ||
2456 | /* -L help lists the data directories and exits. */ | |
2457 | if (list_data_dirs) { | |
2c65db5e | 2458 | qemu_list_data_dirs(); |
0546c060 PB |
2459 | exit(0); |
2460 | } | |
2461 | } | |
2462 | ||
2463 | static void qemu_maybe_daemonize(const char *pid_file) | |
2464 | { | |
2465 | Error *err; | |
2466 | ||
2467 | os_daemonize(); | |
2468 | rcu_disable_atfork(); | |
2469 | ||
2470 | if (pid_file && !qemu_write_pidfile(pid_file, &err)) { | |
2471 | error_reportf_err(err, "cannot create PID file: "); | |
2472 | exit(1); | |
2473 | } | |
2474 | ||
2475 | qemu_unlink_pidfile_notifier.notify = qemu_unlink_pidfile; | |
2476 | qemu_add_exit_notifier(&qemu_unlink_pidfile_notifier); | |
2477 | } | |
2478 | ||
7691bdef PB |
2479 | static void qemu_init_displays(void) |
2480 | { | |
2481 | DisplayState *ds; | |
2482 | ||
2483 | /* init local displays */ | |
2484 | ds = init_displaystate(); | |
2485 | qemu_display_init(ds, &dpy); | |
2486 | ||
2487 | /* must be after terminal init, SDL library changes signal handlers */ | |
2488 | os_setup_signal_handling(); | |
2489 | ||
2490 | /* init remote displays */ | |
2491 | #ifdef CONFIG_VNC | |
2492 | qemu_opts_foreach(qemu_find_opts("vnc"), | |
2493 | vnc_init_func, NULL, &error_fatal); | |
2494 | #endif | |
2495 | ||
2496 | if (using_spice) { | |
2497 | qemu_spice.display_init(); | |
2498 | } | |
2499 | } | |
2500 | ||
d8e4de41 PB |
2501 | static void qemu_init_board(void) |
2502 | { | |
2503 | MachineClass *machine_class = MACHINE_GET_CLASS(current_machine); | |
2504 | ||
2505 | if (machine_class->default_ram_id && current_machine->ram_size && | |
2506 | numa_uses_legacy_mem() && !current_machine->ram_memdev_id) { | |
2507 | create_default_memdev(current_machine, mem_path); | |
2508 | } | |
2509 | ||
8a745974 | 2510 | /* process plugin before CPUs are created, but once -smp has been parsed */ |
0572f558 | 2511 | qemu_plugin_load_list(&plugin_list, &error_fatal); |
8a745974 | 2512 | |
2f181fbd | 2513 | /* From here on we enter MACHINE_PHASE_INITIALIZED. */ |
d8e4de41 PB |
2514 | machine_run_board_init(current_machine); |
2515 | ||
fe9f70a1 | 2516 | drive_check_orphaned(); |
d8e4de41 PB |
2517 | |
2518 | realtime_init(); | |
2519 | ||
2520 | if (hax_enabled()) { | |
2521 | /* FIXME: why isn't cpu_synchronize_all_post_init enough? */ | |
2522 | hax_sync_vcpus(); | |
2523 | } | |
2524 | } | |
2525 | ||
2526 | static void qemu_create_cli_devices(void) | |
2527 | { | |
2528 | soundhw_init(); | |
2529 | ||
2530 | qemu_opts_foreach(qemu_find_opts("fw_cfg"), | |
2531 | parse_fw_cfg, fw_cfg_find(), &error_fatal); | |
2532 | ||
2533 | /* init USB devices */ | |
2534 | if (machine_usb(current_machine)) { | |
2535 | if (foreach_device_config(DEV_USB, usb_parse) < 0) | |
2536 | exit(1); | |
2537 | } | |
2538 | ||
2539 | /* init generic devices */ | |
2540 | rom_set_order_override(FW_CFG_ORDER_OVERRIDE_DEVICE); | |
2541 | qemu_opts_foreach(qemu_find_opts("device"), | |
2542 | device_init_func, NULL, &error_fatal); | |
2543 | rom_reset_order_override(); | |
2544 | } | |
2545 | ||
2546 | static void qemu_machine_creation_done(void) | |
2547 | { | |
abc27d42 DG |
2548 | MachineState *machine = MACHINE(qdev_get_machine()); |
2549 | ||
d8e4de41 PB |
2550 | /* Did we create any drives that we failed to create a device for? */ |
2551 | drive_check_orphaned(); | |
2552 | ||
2553 | /* Don't warn about the default network setup that you get if | |
2554 | * no command line -net or -netdev options are specified. There | |
2555 | * are two cases that we would otherwise complain about: | |
2556 | * (1) board doesn't support a NIC but the implicit "-net nic" | |
2557 | * requested one | |
2558 | * (2) CONFIG_SLIRP not set, in which case the implicit "-net nic" | |
2559 | * sets up a nic that isn't connected to anything. | |
2560 | */ | |
2561 | if (!default_net && (!qtest_enabled() || has_defaults)) { | |
2562 | net_check_clients(); | |
2563 | } | |
2564 | ||
cca686b4 PB |
2565 | qdev_prop_check_globals(); |
2566 | ||
d8e4de41 PB |
2567 | qdev_machine_creation_done(); |
2568 | ||
abc27d42 DG |
2569 | if (machine->cgs) { |
2570 | /* | |
2571 | * Verify that Confidential Guest Support has actually been initialized | |
2572 | */ | |
2573 | assert(machine->cgs->ready); | |
2574 | } | |
2575 | ||
f66dc873 | 2576 | if (foreach_device_config(DEV_GDB, gdbserver_start) < 0) { |
d8e4de41 PB |
2577 | exit(1); |
2578 | } | |
d8e4de41 PB |
2579 | } |
2580 | ||
b4e1a342 PB |
2581 | void qmp_x_exit_preconfig(Error **errp) |
2582 | { | |
2f181fbd | 2583 | if (phase_check(PHASE_MACHINE_INITIALIZED)) { |
b4e1a342 PB |
2584 | error_setg(errp, "The command is permitted only before machine initialization"); |
2585 | return; | |
2586 | } | |
2587 | ||
2588 | qemu_init_board(); | |
2589 | qemu_create_cli_devices(); | |
2590 | qemu_machine_creation_done(); | |
2591 | ||
2592 | if (loadvm) { | |
2593 | Error *local_err = NULL; | |
f1a9fcdd | 2594 | if (!load_snapshot(loadvm, NULL, false, NULL, &local_err)) { |
b4e1a342 PB |
2595 | error_report_err(local_err); |
2596 | autostart = 0; | |
2597 | exit(1); | |
2598 | } | |
2599 | } | |
2600 | if (replay_mode != REPLAY_MODE_NONE) { | |
2601 | replay_vmstate_init(); | |
2602 | } | |
2603 | ||
2604 | if (incoming) { | |
2605 | Error *local_err = NULL; | |
2606 | if (strcmp(incoming, "defer") != 0) { | |
2607 | qmp_migrate_incoming(incoming, &local_err); | |
2608 | if (local_err) { | |
2609 | error_reportf_err(local_err, "-incoming %s: ", incoming); | |
2610 | exit(1); | |
2611 | } | |
2612 | } | |
2613 | } else if (autostart) { | |
2614 | qmp_cont(NULL); | |
2615 | } | |
2616 | } | |
2617 | ||
7b733862 | 2618 | void qemu_init(int argc, char **argv, char **envp) |
0824d6fc | 2619 | { |
7a84268d | 2620 | QemuOpts *opts; |
d1cdd92e | 2621 | QemuOpts *icount_opts = NULL, *accel_opts = NULL; |
03b0ba70 | 2622 | QemuOptsList *olist; |
cd6f1169 | 2623 | int optind; |
6530a97b | 2624 | const char *optarg; |
0056ae24 | 2625 | MachineClass *machine_class; |
f29a5614 | 2626 | bool userconfig = true; |
abfd9ce3 | 2627 | FILE *vmstate_dump_file = NULL; |
0b5538c3 | 2628 | |
4d454574 | 2629 | qemu_add_opts(&qemu_drive_opts); |
968854c8 AK |
2630 | qemu_add_drive_opts(&qemu_legacy_drive_opts); |
2631 | qemu_add_drive_opts(&qemu_common_drive_opts); | |
2632 | qemu_add_drive_opts(&qemu_drive_opts); | |
c5f3014b | 2633 | qemu_add_drive_opts(&bdrv_runtime_opts); |
4d454574 PB |
2634 | qemu_add_opts(&qemu_chardev_opts); |
2635 | qemu_add_opts(&qemu_device_opts); | |
2636 | qemu_add_opts(&qemu_netdev_opts); | |
78cd6f7b | 2637 | qemu_add_opts(&qemu_nic_opts); |
4d454574 PB |
2638 | qemu_add_opts(&qemu_net_opts); |
2639 | qemu_add_opts(&qemu_rtc_opts); | |
2640 | qemu_add_opts(&qemu_global_opts); | |
2641 | qemu_add_opts(&qemu_mon_opts); | |
2642 | qemu_add_opts(&qemu_trace_opts); | |
42229a75 | 2643 | qemu_plugin_add_opts(); |
4d454574 PB |
2644 | qemu_add_opts(&qemu_option_rom_opts); |
2645 | qemu_add_opts(&qemu_machine_opts); | |
8d4e9146 | 2646 | qemu_add_opts(&qemu_accel_opts); |
6e1d3c1c | 2647 | qemu_add_opts(&qemu_mem_opts); |
12b7f57e | 2648 | qemu_add_opts(&qemu_smp_opts); |
4d454574 | 2649 | qemu_add_opts(&qemu_boot_opts); |
4d454574 PB |
2650 | qemu_add_opts(&qemu_add_fd_opts); |
2651 | qemu_add_opts(&qemu_object_opts); | |
d1a0cf73 | 2652 | qemu_add_opts(&qemu_tpmdev_opts); |
1fdd4748 | 2653 | qemu_add_opts(&qemu_overcommit_opts); |
5e2ac519 | 2654 | qemu_add_opts(&qemu_msg_opts); |
5d12f961 | 2655 | qemu_add_opts(&qemu_name_opts); |
0042109a | 2656 | qemu_add_opts(&qemu_numa_opts); |
1ad9580b | 2657 | qemu_add_opts(&qemu_icount_opts); |
a38bb079 | 2658 | qemu_add_opts(&qemu_semihosting_config_opts); |
81b2b810 | 2659 | qemu_add_opts(&qemu_fw_cfg_opts); |
2a5ad60b | 2660 | qemu_add_opts(&qemu_action_opts); |
34294e2f | 2661 | module_call_init(MODULE_INIT_OPTS); |
4d454574 | 2662 | |
efd7ab22 PB |
2663 | error_init(argv[0]); |
2664 | qemu_init_exec_dir(argv[0]); | |
142c6b1a | 2665 | |
efd7ab22 | 2666 | qemu_init_subsystems(); |
41bd639b | 2667 | |
292444cb AL |
2668 | /* first pass of option parsing */ |
2669 | optind = 1; | |
2670 | while (optind < argc) { | |
2671 | if (argv[optind][0] != '-') { | |
2672 | /* disk image */ | |
28e68d68 | 2673 | optind++; |
292444cb AL |
2674 | } else { |
2675 | const QEMUOption *popt; | |
2676 | ||
2677 | popt = lookup_opt(argc, argv, &optarg, &optind); | |
2678 | switch (popt->index) { | |
f29a5614 EH |
2679 | case QEMU_OPTION_nouserconfig: |
2680 | userconfig = false; | |
2681 | break; | |
292444cb AL |
2682 | } |
2683 | } | |
2684 | } | |
2685 | ||
1ea06c39 | 2686 | if (userconfig) { |
f7544edc | 2687 | qemu_read_default_config_file(&error_fatal); |
292444cb AL |
2688 | } |
2689 | ||
2690 | /* second pass of option parsing */ | |
cd6f1169 | 2691 | optind = 1; |
0824d6fc | 2692 | for(;;) { |
cd6f1169 | 2693 | if (optind >= argc) |
0824d6fc | 2694 | break; |
6530a97b | 2695 | if (argv[optind][0] != '-') { |
17f30eae | 2696 | loc_set_cmdline(argv, optind, 1); |
d1cdd92e | 2697 | drive_add(IF_DEFAULT, 0, argv[optind++], HD_OPTS); |
cd6f1169 FB |
2698 | } else { |
2699 | const QEMUOption *popt; | |
2700 | ||
6530a97b | 2701 | popt = lookup_opt(argc, argv, &optarg, &optind); |
ad96090a | 2702 | if (!(popt->arch_mask & arch_type)) { |
da002526 | 2703 | error_report("Option not supported for this target"); |
ad96090a BS |
2704 | exit(1); |
2705 | } | |
cd6f1169 | 2706 | switch(popt->index) { |
94fc95cd JM |
2707 | case QEMU_OPTION_cpu: |
2708 | /* hw initialization will check this */ | |
c1c8cfe5 | 2709 | cpu_option = optarg; |
94fc95cd | 2710 | break; |
cd6f1169 | 2711 | case QEMU_OPTION_hda: |
cd6f1169 | 2712 | case QEMU_OPTION_hdb: |
cc1daa40 FB |
2713 | case QEMU_OPTION_hdc: |
2714 | case QEMU_OPTION_hdd: | |
2292ddae MA |
2715 | drive_add(IF_DEFAULT, popt->index - QEMU_OPTION_hda, optarg, |
2716 | HD_OPTS); | |
fc01f7e7 | 2717 | break; |
42e5f393 MA |
2718 | case QEMU_OPTION_blockdev: |
2719 | { | |
2720 | Visitor *v; | |
651af51c | 2721 | BlockdevOptionsQueueEntry *bdo; |
42e5f393 | 2722 | |
92917cd2 MA |
2723 | v = qobject_input_visitor_new_str(optarg, "driver", |
2724 | &error_fatal); | |
42e5f393 | 2725 | |
651af51c | 2726 | bdo = g_new(BlockdevOptionsQueueEntry, 1); |
42e5f393 MA |
2727 | visit_type_BlockdevOptions(v, NULL, &bdo->bdo, |
2728 | &error_fatal); | |
2729 | visit_free(v); | |
2730 | loc_save(&bdo->loc); | |
2731 | QSIMPLEQ_INSERT_TAIL(&bdo_queue, bdo, entry); | |
2732 | break; | |
2733 | } | |
e4bcb14c | 2734 | case QEMU_OPTION_drive: |
e2982c3a MT |
2735 | if (drive_def(optarg) == NULL) { |
2736 | exit(1); | |
2737 | } | |
99efa84d | 2738 | break; |
d058fe03 GH |
2739 | case QEMU_OPTION_set: |
2740 | if (qemu_set_option(optarg) != 0) | |
2741 | exit(1); | |
99efa84d | 2742 | break; |
d0fef6fb GH |
2743 | case QEMU_OPTION_global: |
2744 | if (qemu_global_option(optarg) != 0) | |
2745 | exit(1); | |
99efa84d | 2746 | break; |
3e3d5815 | 2747 | case QEMU_OPTION_mtdblock: |
2292ddae | 2748 | drive_add(IF_MTD, -1, optarg, MTD_OPTS); |
3e3d5815 | 2749 | break; |
a1bb27b1 | 2750 | case QEMU_OPTION_sd: |
80f4d9fc | 2751 | drive_add(IF_SD, -1, optarg, SD_OPTS); |
a1bb27b1 | 2752 | break; |
86f55663 | 2753 | case QEMU_OPTION_pflash: |
2292ddae | 2754 | drive_add(IF_PFLASH, -1, optarg, PFLASH_OPTS); |
86f55663 | 2755 | break; |
cd6f1169 | 2756 | case QEMU_OPTION_snapshot: |
25863975 PD |
2757 | { |
2758 | Error *blocker = NULL; | |
2759 | snapshot = 1; | |
2760 | error_setg(&blocker, QERR_REPLAY_NOT_SUPPORTED, | |
2761 | "-snapshot"); | |
2762 | replay_add_blocker(blocker); | |
2763 | } | |
33e3963e | 2764 | break; |
268a362c | 2765 | case QEMU_OPTION_numa: |
70b94331 MA |
2766 | opts = qemu_opts_parse_noisily(qemu_find_opts("numa"), |
2767 | optarg, true); | |
0042109a WG |
2768 | if (!opts) { |
2769 | exit(1); | |
2770 | } | |
268a362c | 2771 | break; |
1472a95b | 2772 | case QEMU_OPTION_display: |
e3af9f9a | 2773 | parse_display(optarg); |
1472a95b | 2774 | break; |
cd6f1169 | 2775 | case QEMU_OPTION_nographic: |
cfc58cf3 EH |
2776 | olist = qemu_find_opts("machine"); |
2777 | qemu_opts_parse_noisily(olist, "graphics=off", false); | |
2778 | nographic = true; | |
0c8d7065 | 2779 | dpy.type = DISPLAY_TYPE_NONE; |
a20dd508 | 2780 | break; |
4d3b6f6e | 2781 | case QEMU_OPTION_curses: |
47b05369 | 2782 | #ifdef CONFIG_CURSES |
14f130fa | 2783 | dpy.type = DISPLAY_TYPE_CURSES; |
47b05369 | 2784 | #else |
e08bb301 | 2785 | error_report("curses or iconv support is disabled"); |
47b05369 | 2786 | exit(1); |
4d3b6f6e | 2787 | #endif |
47b05369 | 2788 | break; |
a171fe39 | 2789 | case QEMU_OPTION_portrait: |
9312805d VK |
2790 | graphic_rotate = 90; |
2791 | break; | |
2792 | case QEMU_OPTION_rotate: | |
2793 | graphic_rotate = strtol(optarg, (char **) &optarg, 10); | |
2794 | if (graphic_rotate != 0 && graphic_rotate != 90 && | |
2795 | graphic_rotate != 180 && graphic_rotate != 270) { | |
f61eddcb | 2796 | error_report("only 90, 180, 270 deg rotation is available"); |
9312805d VK |
2797 | exit(1); |
2798 | } | |
a171fe39 | 2799 | break; |
cd6f1169 | 2800 | case QEMU_OPTION_kernel: |
32c02fdd | 2801 | qemu_opts_set(qemu_find_opts("machine"), "kernel", optarg, &error_abort); |
a0abe474 PM |
2802 | break; |
2803 | case QEMU_OPTION_initrd: | |
32c02fdd | 2804 | qemu_opts_set(qemu_find_opts("machine"), "initrd", optarg, &error_abort); |
a20dd508 | 2805 | break; |
cd6f1169 | 2806 | case QEMU_OPTION_append: |
32c02fdd | 2807 | qemu_opts_set(qemu_find_opts("machine"), "append", optarg, &error_abort); |
313aa567 | 2808 | break; |
412beee6 | 2809 | case QEMU_OPTION_dtb: |
32c02fdd | 2810 | qemu_opts_set(qemu_find_opts("machine"), "dtb", optarg, &error_abort); |
412beee6 | 2811 | break; |
cd6f1169 | 2812 | case QEMU_OPTION_cdrom: |
2292ddae | 2813 | drive_add(IF_DEFAULT, 2, optarg, CDROM_OPTS); |
36b486bb | 2814 | break; |
cd6f1169 | 2815 | case QEMU_OPTION_boot: |
70b94331 MA |
2816 | opts = qemu_opts_parse_noisily(qemu_find_opts("boot-opts"), |
2817 | optarg, true); | |
8281abd5 MA |
2818 | if (!opts) { |
2819 | exit(1); | |
36b486bb FB |
2820 | } |
2821 | break; | |
cd6f1169 | 2822 | case QEMU_OPTION_fda: |
cd6f1169 | 2823 | case QEMU_OPTION_fdb: |
2292ddae MA |
2824 | drive_add(IF_FLOPPY, popt->index - QEMU_OPTION_fda, |
2825 | optarg, FD_OPTS); | |
c45886db | 2826 | break; |
52ca8d6a FB |
2827 | case QEMU_OPTION_no_fd_bootchk: |
2828 | fd_bootchk = 0; | |
2829 | break; | |
a1ea458f | 2830 | case QEMU_OPTION_netdev: |
d30300f7 | 2831 | default_net = 0; |
3329f07b | 2832 | if (net_client_parse(qemu_find_opts("netdev"), optarg) == -1) { |
a1ea458f MM |
2833 | exit(1); |
2834 | } | |
2835 | break; | |
78cd6f7b TH |
2836 | case QEMU_OPTION_nic: |
2837 | default_net = 0; | |
2838 | if (net_client_parse(qemu_find_opts("nic"), optarg) == -1) { | |
2839 | exit(1); | |
2840 | } | |
2841 | break; | |
7c9d8e07 | 2842 | case QEMU_OPTION_net: |
d30300f7 | 2843 | default_net = 0; |
3329f07b | 2844 | if (net_client_parse(qemu_find_opts("net"), optarg) == -1) { |
c4b1fcc0 FB |
2845 | exit(1); |
2846 | } | |
702c651c | 2847 | break; |
f9dadc98 RS |
2848 | #ifdef CONFIG_LIBISCSI |
2849 | case QEMU_OPTION_iscsi: | |
70b94331 MA |
2850 | opts = qemu_opts_parse_noisily(qemu_find_opts("iscsi"), |
2851 | optarg, false); | |
f9dadc98 RS |
2852 | if (!opts) { |
2853 | exit(1); | |
2854 | } | |
2855 | break; | |
c7f74643 | 2856 | #endif |
1d14ffa9 | 2857 | case QEMU_OPTION_audio_help: |
71830221 | 2858 | audio_legacy_help(); |
1d14ffa9 FB |
2859 | exit (0); |
2860 | break; | |
71830221 KZ |
2861 | case QEMU_OPTION_audiodev: |
2862 | audio_parse_option(optarg); | |
2863 | break; | |
1d14ffa9 FB |
2864 | case QEMU_OPTION_soundhw: |
2865 | select_soundhw (optarg); | |
2866 | break; | |
cd6f1169 | 2867 | case QEMU_OPTION_h: |
15f82208 | 2868 | help(0); |
cd6f1169 | 2869 | break; |
9bd7e6d9 PB |
2870 | case QEMU_OPTION_version: |
2871 | version(); | |
2872 | exit(0); | |
2873 | break; | |
3b9985e9 | 2874 | case QEMU_OPTION_m: |
70b94331 MA |
2875 | opts = qemu_opts_parse_noisily(qemu_find_opts("memory"), |
2876 | optarg, true); | |
6e1d3c1c IM |
2877 | if (!opts) { |
2878 | exit(EXIT_FAILURE); | |
2879 | } | |
cd6f1169 | 2880 | break; |
d1a0cf73 SB |
2881 | #ifdef CONFIG_TPM |
2882 | case QEMU_OPTION_tpmdev: | |
2883 | if (tpm_config_parse(qemu_find_opts("tpmdev"), optarg) < 0) { | |
2884 | exit(1); | |
2885 | } | |
2886 | break; | |
2887 | #endif | |
c902760f MT |
2888 | case QEMU_OPTION_mempath: |
2889 | mem_path = optarg; | |
2890 | break; | |
c902760f MT |
2891 | case QEMU_OPTION_mem_prealloc: |
2892 | mem_prealloc = 1; | |
2893 | break; | |
cd6f1169 | 2894 | case QEMU_OPTION_d: |
c235d738 MF |
2895 | log_mask = optarg; |
2896 | break; | |
2897 | case QEMU_OPTION_D: | |
2898 | log_file = optarg; | |
cd6f1169 | 2899 | break; |
3514552e | 2900 | case QEMU_OPTION_DFILTER: |
bd6fee9f | 2901 | qemu_set_dfilter_ranges(optarg, &error_fatal); |
3514552e | 2902 | break; |
9c09a251 RH |
2903 | case QEMU_OPTION_seed: |
2904 | qemu_guest_random_seed_main(optarg, &error_fatal); | |
2905 | break; | |
cd6f1169 | 2906 | case QEMU_OPTION_s: |
ef0c4a0d | 2907 | add_device_config(DEV_GDB, "tcp::" DEFAULT_GDBSTUB_PORT); |
cd6f1169 | 2908 | break; |
59030a8c | 2909 | case QEMU_OPTION_gdb: |
ef0c4a0d | 2910 | add_device_config(DEV_GDB, optarg); |
cd6f1169 | 2911 | break; |
cd6f1169 | 2912 | case QEMU_OPTION_L: |
37146e7e RJ |
2913 | if (is_help_option(optarg)) { |
2914 | list_data_dirs = true; | |
2a1cce90 | 2915 | } else { |
ea1edcd7 | 2916 | qemu_add_data_dir(g_strdup(optarg)); |
4524051c | 2917 | } |
cd6f1169 | 2918 | break; |
1192dad8 | 2919 | case QEMU_OPTION_bios: |
32c02fdd | 2920 | qemu_opts_set(qemu_find_opts("machine"), "firmware", optarg, &error_abort); |
1192dad8 | 2921 | break; |
1b530a6d AJ |
2922 | case QEMU_OPTION_singlestep: |
2923 | singlestep = 1; | |
2924 | break; | |
cd6f1169 | 2925 | case QEMU_OPTION_S: |
3c07f8e8 | 2926 | autostart = 0; |
cd6f1169 | 2927 | break; |
99efa84d MA |
2928 | case QEMU_OPTION_k: |
2929 | keyboard_layout = optarg; | |
2930 | break; | |
3893c124 | 2931 | case QEMU_OPTION_vga: |
a369da5f | 2932 | vga_model = optarg; |
7f1b17f2 | 2933 | default_vga = 0; |
1bfe856e | 2934 | break; |
e9b137c2 FB |
2935 | case QEMU_OPTION_g: |
2936 | { | |
2937 | const char *p; | |
2938 | int w, h, depth; | |
2939 | p = optarg; | |
2940 | w = strtol(p, (char **)&p, 10); | |
2941 | if (w <= 0) { | |
2942 | graphic_error: | |
f61eddcb | 2943 | error_report("invalid resolution or depth"); |
e9b137c2 FB |
2944 | exit(1); |
2945 | } | |
2946 | if (*p != 'x') | |
2947 | goto graphic_error; | |
2948 | p++; | |
2949 | h = strtol(p, (char **)&p, 10); | |
2950 | if (h <= 0) | |
2951 | goto graphic_error; | |
2952 | if (*p == 'x') { | |
2953 | p++; | |
2954 | depth = strtol(p, (char **)&p, 10); | |
8ac919a0 LV |
2955 | if (depth != 1 && depth != 2 && depth != 4 && |
2956 | depth != 8 && depth != 15 && depth != 16 && | |
e9b137c2 FB |
2957 | depth != 24 && depth != 32) |
2958 | goto graphic_error; | |
2959 | } else if (*p == '\0') { | |
2960 | depth = graphic_depth; | |
2961 | } else { | |
2962 | goto graphic_error; | |
2963 | } | |
3b46e624 | 2964 | |
e9b137c2 FB |
2965 | graphic_width = w; |
2966 | graphic_height = h; | |
2967 | graphic_depth = depth; | |
2968 | } | |
2969 | break; | |
20d8a3ed TS |
2970 | case QEMU_OPTION_echr: |
2971 | { | |
2972 | char *r; | |
2973 | term_escape_char = strtol(optarg, &r, 0); | |
2974 | if (r == optarg) | |
2975 | printf("Bad argument to echr\n"); | |
2976 | break; | |
2977 | } | |
82c643ff | 2978 | case QEMU_OPTION_monitor: |
6ca5582d | 2979 | default_monitor = 0; |
70e098af | 2980 | if (strncmp(optarg, "none", 4)) { |
4821cd4c | 2981 | monitor_parse(optarg, "readline", false); |
70e098af | 2982 | } |
6ca5582d GH |
2983 | break; |
2984 | case QEMU_OPTION_qmp: | |
4821cd4c HR |
2985 | monitor_parse(optarg, "control", false); |
2986 | default_monitor = 0; | |
2987 | break; | |
2988 | case QEMU_OPTION_qmp_pretty: | |
2989 | monitor_parse(optarg, "control", true); | |
2d114dc1 | 2990 | default_monitor = 0; |
82c643ff | 2991 | break; |
22a0e04b | 2992 | case QEMU_OPTION_mon: |
70b94331 MA |
2993 | opts = qemu_opts_parse_noisily(qemu_find_opts("mon"), optarg, |
2994 | true); | |
22a0e04b | 2995 | if (!opts) { |
22a0e04b GH |
2996 | exit(1); |
2997 | } | |
2d114dc1 | 2998 | default_monitor = 0; |
22a0e04b | 2999 | break; |
191bc01b | 3000 | case QEMU_OPTION_chardev: |
70b94331 MA |
3001 | opts = qemu_opts_parse_noisily(qemu_find_opts("chardev"), |
3002 | optarg, true); | |
191bc01b | 3003 | if (!opts) { |
191bc01b GH |
3004 | exit(1); |
3005 | } | |
191bc01b | 3006 | break; |
74db920c | 3007 | case QEMU_OPTION_fsdev: |
03b0ba70 GH |
3008 | olist = qemu_find_opts("fsdev"); |
3009 | if (!olist) { | |
5dfdae81 | 3010 | error_report("fsdev support is disabled"); |
03b0ba70 GH |
3011 | exit(1); |
3012 | } | |
70b94331 | 3013 | opts = qemu_opts_parse_noisily(olist, optarg, true); |
74db920c | 3014 | if (!opts) { |
74db920c GS |
3015 | exit(1); |
3016 | } | |
3017 | break; | |
3d54abc7 | 3018 | case QEMU_OPTION_virtfs: { |
e14ea479 SH |
3019 | QemuOpts *fsdev; |
3020 | QemuOpts *device; | |
1a6ed33c AM |
3021 | const char *writeout, *sock_fd, *socket, *path, *security_model, |
3022 | *multidevs; | |
3d54abc7 | 3023 | |
03b0ba70 GH |
3024 | olist = qemu_find_opts("virtfs"); |
3025 | if (!olist) { | |
5dfdae81 | 3026 | error_report("virtfs support is disabled"); |
03b0ba70 GH |
3027 | exit(1); |
3028 | } | |
70b94331 | 3029 | opts = qemu_opts_parse_noisily(olist, optarg, true); |
3d54abc7 | 3030 | if (!opts) { |
3d54abc7 GS |
3031 | exit(1); |
3032 | } | |
3033 | ||
fbcbf101 | 3034 | if (qemu_opt_get(opts, "fsdriver") == NULL || |
99519f0a | 3035 | qemu_opt_get(opts, "mount_tag") == NULL) { |
8afb9000 | 3036 | error_report("Usage: -virtfs fsdriver,mount_tag=tag"); |
9ce56db6 VJ |
3037 | exit(1); |
3038 | } | |
e14ea479 | 3039 | fsdev = qemu_opts_create(qemu_find_opts("fsdev"), |
3baa0a6a | 3040 | qemu_opts_id(opts) ?: |
8be7e7e4 LC |
3041 | qemu_opt_get(opts, "mount_tag"), |
3042 | 1, NULL); | |
e14ea479 | 3043 | if (!fsdev) { |
3baa0a6a | 3044 | error_report("duplicate or invalid fsdev id: %s", |
f61eddcb | 3045 | qemu_opt_get(opts, "mount_tag")); |
3d54abc7 GS |
3046 | exit(1); |
3047 | } | |
d3ab98e6 AK |
3048 | |
3049 | writeout = qemu_opt_get(opts, "writeout"); | |
3050 | if (writeout) { | |
3051 | #ifdef CONFIG_SYNC_FILE_RANGE | |
f43e47db | 3052 | qemu_opt_set(fsdev, "writeout", writeout, &error_abort); |
d3ab98e6 | 3053 | #else |
f61eddcb EH |
3054 | error_report("writeout=immediate not supported " |
3055 | "on this platform"); | |
d3ab98e6 AK |
3056 | exit(1); |
3057 | #endif | |
3058 | } | |
f43e47db MA |
3059 | qemu_opt_set(fsdev, "fsdriver", |
3060 | qemu_opt_get(opts, "fsdriver"), &error_abort); | |
32b69436 GK |
3061 | path = qemu_opt_get(opts, "path"); |
3062 | if (path) { | |
3063 | qemu_opt_set(fsdev, "path", path, &error_abort); | |
3064 | } | |
3065 | security_model = qemu_opt_get(opts, "security_model"); | |
3066 | if (security_model) { | |
3067 | qemu_opt_set(fsdev, "security_model", security_model, | |
3068 | &error_abort); | |
3069 | } | |
84a87cc4 MK |
3070 | socket = qemu_opt_get(opts, "socket"); |
3071 | if (socket) { | |
f43e47db | 3072 | qemu_opt_set(fsdev, "socket", socket, &error_abort); |
84a87cc4 | 3073 | } |
4c793dda MK |
3074 | sock_fd = qemu_opt_get(opts, "sock_fd"); |
3075 | if (sock_fd) { | |
f43e47db | 3076 | qemu_opt_set(fsdev, "sock_fd", sock_fd, &error_abort); |
4c793dda | 3077 | } |
e14ea479 | 3078 | |
2c74c2cb | 3079 | qemu_opt_set_bool(fsdev, "readonly", |
cccb7967 MA |
3080 | qemu_opt_get_bool(opts, "readonly", 0), |
3081 | &error_abort); | |
1a6ed33c AM |
3082 | multidevs = qemu_opt_get(opts, "multidevs"); |
3083 | if (multidevs) { | |
3084 | qemu_opt_set(fsdev, "multidevs", multidevs, &error_abort); | |
3085 | } | |
87ea75d5 PC |
3086 | device = qemu_opts_create(qemu_find_opts("device"), NULL, 0, |
3087 | &error_abort); | |
f43e47db | 3088 | qemu_opt_set(device, "driver", "virtio-9p-pci", &error_abort); |
e14ea479 | 3089 | qemu_opt_set(device, "fsdev", |
3baa0a6a | 3090 | qemu_opts_id(fsdev), &error_abort); |
e14ea479 | 3091 | qemu_opt_set(device, "mount_tag", |
f43e47db | 3092 | qemu_opt_get(opts, "mount_tag"), &error_abort); |
3d54abc7 GS |
3093 | break; |
3094 | } | |
82c643ff | 3095 | case QEMU_OPTION_serial: |
998bbd74 GH |
3096 | add_device_config(DEV_SERIAL, optarg); |
3097 | default_serial = 0; | |
18141ed6 JK |
3098 | if (strncmp(optarg, "mon:", 4) == 0) { |
3099 | default_monitor = 0; | |
3100 | } | |
82c643ff | 3101 | break; |
9dd986cc | 3102 | case QEMU_OPTION_watchdog: |
09aaa160 | 3103 | if (watchdog) { |
f61eddcb | 3104 | error_report("only one watchdog option may be given"); |
7b733862 | 3105 | exit(1); |
09aaa160 MA |
3106 | } |
3107 | watchdog = optarg; | |
9dd986cc | 3108 | break; |
2a5ad60b AJ |
3109 | case QEMU_OPTION_action: |
3110 | olist = qemu_find_opts("action"); | |
3111 | if (!qemu_opts_parse_noisily(olist, optarg, false)) { | |
3112 | exit(1); | |
3113 | } | |
3114 | break; | |
9dd986cc RJ |
3115 | case QEMU_OPTION_watchdog_action: |
3116 | if (select_watchdog_action(optarg) == -1) { | |
3e515373 | 3117 | error_report("unknown -watchdog-action parameter"); |
9dd986cc RJ |
3118 | exit(1); |
3119 | } | |
3120 | break; | |
6508fe59 | 3121 | case QEMU_OPTION_parallel: |
6a5e8b0e GH |
3122 | add_device_config(DEV_PARALLEL, optarg); |
3123 | default_parallel = 0; | |
18141ed6 JK |
3124 | if (strncmp(optarg, "mon:", 4) == 0) { |
3125 | default_monitor = 0; | |
3126 | } | |
6508fe59 | 3127 | break; |
c9f398e5 PA |
3128 | case QEMU_OPTION_debugcon: |
3129 | add_device_config(DEV_DEBUGCON, optarg); | |
3130 | break; | |
99efa84d MA |
3131 | case QEMU_OPTION_loadvm: |
3132 | loadvm = optarg; | |
3133 | break; | |
d63d307f | 3134 | case QEMU_OPTION_full_screen: |
0c8d7065 GH |
3135 | dpy.has_full_screen = true; |
3136 | dpy.full_screen = true; | |
d63d307f | 3137 | break; |
3780e197 TS |
3138 | case QEMU_OPTION_alt_grab: |
3139 | alt_grab = 1; | |
3140 | break; | |
0ca9f8a4 DK |
3141 | case QEMU_OPTION_ctrl_grab: |
3142 | ctrl_grab = 1; | |
3143 | break; | |
667accab | 3144 | case QEMU_OPTION_no_quit: |
0c8d7065 GH |
3145 | dpy.has_window_close = true; |
3146 | dpy.window_close = false; | |
667accab | 3147 | break; |
7d957bd8 | 3148 | case QEMU_OPTION_sdl: |
24f6ff86 | 3149 | #ifdef CONFIG_SDL |
fe91f36a | 3150 | dpy.type = DISPLAY_TYPE_SDL; |
7d957bd8 | 3151 | break; |
58fc096c | 3152 | #else |
f61eddcb | 3153 | error_report("SDL support is disabled"); |
58fc096c | 3154 | exit(1); |
667accab | 3155 | #endif |
f7cce898 | 3156 | case QEMU_OPTION_pidfile: |
93815bc2 | 3157 | pid_file = optarg; |
f7cce898 | 3158 | break; |
a09db21f FB |
3159 | case QEMU_OPTION_win2k_hack: |
3160 | win2k_install_hack = 1; | |
3161 | break; | |
8a92ea2f | 3162 | case QEMU_OPTION_acpitable: |
70b94331 MA |
3163 | opts = qemu_opts_parse_noisily(qemu_find_opts("acpi"), |
3164 | optarg, true); | |
f46e720a LE |
3165 | if (!opts) { |
3166 | exit(1); | |
3167 | } | |
9f57061c | 3168 | acpi_table_add(opts, &error_fatal); |
8a92ea2f | 3169 | break; |
b6f6e3d3 | 3170 | case QEMU_OPTION_smbios: |
70b94331 MA |
3171 | opts = qemu_opts_parse_noisily(qemu_find_opts("smbios"), |
3172 | optarg, false); | |
f46e720a LE |
3173 | if (!opts) { |
3174 | exit(1); | |
3175 | } | |
1007a37e | 3176 | smbios_entry_add(opts, &error_fatal); |
b6f6e3d3 | 3177 | break; |
81b2b810 | 3178 | case QEMU_OPTION_fwcfg: |
70b94331 MA |
3179 | opts = qemu_opts_parse_noisily(qemu_find_opts("fw_cfg"), |
3180 | optarg, true); | |
81b2b810 GS |
3181 | if (opts == NULL) { |
3182 | exit(1); | |
3183 | } | |
3184 | break; | |
047f7038 | 3185 | case QEMU_OPTION_preconfig: |
7691bdef | 3186 | preconfig_requested = true; |
047f7038 | 3187 | break; |
7ba1e619 | 3188 | case QEMU_OPTION_enable_kvm: |
303d4e86 | 3189 | olist = qemu_find_opts("machine"); |
70b94331 | 3190 | qemu_opts_parse_noisily(olist, "accel=kvm", false); |
303d4e86 | 3191 | break; |
364c3e6b | 3192 | case QEMU_OPTION_M: |
303d4e86 AP |
3193 | case QEMU_OPTION_machine: |
3194 | olist = qemu_find_opts("machine"); | |
70b94331 | 3195 | opts = qemu_opts_parse_noisily(olist, optarg, true); |
303d4e86 | 3196 | if (!opts) { |
303d4e86 AP |
3197 | exit(1); |
3198 | } | |
7ba1e619 | 3199 | break; |
a20fa79f | 3200 | case QEMU_OPTION_accel: |
8d4e9146 FK |
3201 | accel_opts = qemu_opts_parse_noisily(qemu_find_opts("accel"), |
3202 | optarg, true); | |
3203 | optarg = qemu_opt_get(accel_opts, "accel"); | |
bde4d920 | 3204 | if (!optarg || is_help_option(optarg)) { |
cbe6d636 WSM |
3205 | printf("Accelerators supported in QEMU binary:\n"); |
3206 | GSList *el, *accel_list = object_class_get_list(TYPE_ACCEL, | |
3207 | false); | |
3208 | for (el = accel_list; el; el = el->next) { | |
3209 | gchar *typename = g_strdup(object_class_get_name( | |
3210 | OBJECT_CLASS(el->data))); | |
3211 | /* omit qtest which is used for tests only */ | |
3212 | if (g_strcmp0(typename, ACCEL_CLASS_NAME("qtest")) && | |
3213 | g_str_has_suffix(typename, ACCEL_CLASS_SUFFIX)) { | |
3214 | gchar **optname = g_strsplit(typename, | |
3215 | ACCEL_CLASS_SUFFIX, 0); | |
3216 | printf("%s\n", optname[0]); | |
4903602e | 3217 | g_strfreev(optname); |
cbe6d636 WSM |
3218 | } |
3219 | g_free(typename); | |
3220 | } | |
3221 | g_slist_free(accel_list); | |
a20fa79f | 3222 | exit(0); |
8d4e9146 FK |
3223 | } |
3224 | break; | |
bb36d470 | 3225 | case QEMU_OPTION_usb: |
fa5358c6 | 3226 | olist = qemu_find_opts("machine"); |
70b94331 | 3227 | qemu_opts_parse_noisily(olist, "usb=on", false); |
bb36d470 | 3228 | break; |
a594cfbf | 3229 | case QEMU_OPTION_usbdevice: |
fa5358c6 | 3230 | olist = qemu_find_opts("machine"); |
70b94331 | 3231 | qemu_opts_parse_noisily(olist, "usb=on", false); |
bd3c948d GH |
3232 | add_device_config(DEV_USB, optarg); |
3233 | break; | |
3234 | case QEMU_OPTION_device: | |
70b94331 MA |
3235 | if (!qemu_opts_parse_noisily(qemu_find_opts("device"), |
3236 | optarg, true)) { | |
f31d07d1 GH |
3237 | exit(1); |
3238 | } | |
a594cfbf | 3239 | break; |
6a00d601 | 3240 | case QEMU_OPTION_smp: |
70b94331 MA |
3241 | if (!qemu_opts_parse_noisily(qemu_find_opts("smp-opts"), |
3242 | optarg, true)) { | |
6be68d7e JS |
3243 | exit(1); |
3244 | } | |
6a00d601 | 3245 | break; |
99efa84d | 3246 | case QEMU_OPTION_vnc: |
653c9747 | 3247 | vnc_parse(optarg); |
821601ea | 3248 | break; |
6515b203 | 3249 | case QEMU_OPTION_no_acpi: |
17e89077 GH |
3250 | olist = qemu_find_opts("machine"); |
3251 | qemu_opts_parse_noisily(olist, "acpi=off", false); | |
6515b203 | 3252 | break; |
16b29ae1 | 3253 | case QEMU_OPTION_no_hpet: |
0259c78c EH |
3254 | olist = qemu_find_opts("machine"); |
3255 | qemu_opts_parse_noisily(olist, "hpet=off", false); | |
16b29ae1 | 3256 | break; |
d1beab82 | 3257 | case QEMU_OPTION_no_reboot: |
2a5ad60b AJ |
3258 | olist = qemu_find_opts("action"); |
3259 | qemu_opts_parse_noisily(olist, "reboot=shutdown", false); | |
d1beab82 | 3260 | break; |
b2f76161 | 3261 | case QEMU_OPTION_no_shutdown: |
2a5ad60b | 3262 | olist = qemu_find_opts("action"); |
c27025e0 | 3263 | qemu_opts_parse_noisily(olist, "shutdown=pause", false); |
b2f76161 | 3264 | break; |
8fcb1b90 | 3265 | case QEMU_OPTION_uuid: |
9c5ce8db | 3266 | if (qemu_uuid_parse(optarg, &qemu_uuid) < 0) { |
4cd70f34 | 3267 | error_report("failed to parse UUID string: wrong format"); |
8fcb1b90 BS |
3268 | exit(1); |
3269 | } | |
fc3b3295 | 3270 | qemu_uuid_set = true; |
8fcb1b90 | 3271 | break; |
99efa84d MA |
3272 | case QEMU_OPTION_option_rom: |
3273 | if (nb_option_roms >= MAX_OPTION_ROMS) { | |
3e515373 | 3274 | error_report("too many option ROMs"); |
99efa84d MA |
3275 | exit(1); |
3276 | } | |
70b94331 MA |
3277 | opts = qemu_opts_parse_noisily(qemu_find_opts("option-rom"), |
3278 | optarg, true); | |
49295ebc MA |
3279 | if (!opts) { |
3280 | exit(1); | |
3281 | } | |
2e55e842 GN |
3282 | option_rom[nb_option_roms].name = qemu_opt_get(opts, "romfile"); |
3283 | option_rom[nb_option_roms].bootindex = | |
3284 | qemu_opt_get_number(opts, "bootindex", -1); | |
3285 | if (!option_rom[nb_option_roms].name) { | |
f61eddcb | 3286 | error_report("Option ROM file is not specified"); |
2e55e842 GN |
3287 | exit(1); |
3288 | } | |
99efa84d MA |
3289 | nb_option_roms++; |
3290 | break; | |
8e71621f | 3291 | case QEMU_OPTION_semihosting: |
f1672e6f | 3292 | qemu_semihosting_enable(); |
a38bb079 LI |
3293 | break; |
3294 | case QEMU_OPTION_semihosting_config: | |
f1672e6f | 3295 | if (qemu_semihosting_config_options(optarg) != 0) { |
a38bb079 LI |
3296 | exit(1); |
3297 | } | |
8e71621f | 3298 | break; |
c35734b2 | 3299 | case QEMU_OPTION_name: |
70b94331 MA |
3300 | opts = qemu_opts_parse_noisily(qemu_find_opts("name"), |
3301 | optarg, true); | |
5d12f961 DDAG |
3302 | if (!opts) { |
3303 | exit(1); | |
3304 | } | |
2880ffb0 MS |
3305 | /* Capture guest name if -msg guest-name is used later */ |
3306 | error_guest_name = qemu_opt_get(opts, "guest"); | |
c35734b2 | 3307 | break; |
66508601 BS |
3308 | case QEMU_OPTION_prom_env: |
3309 | if (nb_prom_envs >= MAX_PROM_ENVS) { | |
3e515373 | 3310 | error_report("too many prom variables"); |
66508601 BS |
3311 | exit(1); |
3312 | } | |
3313 | prom_envs[nb_prom_envs] = optarg; | |
3314 | nb_prom_envs++; | |
3315 | break; | |
2b8f2d41 AZ |
3316 | case QEMU_OPTION_old_param: |
3317 | old_param = 1; | |
05ebd537 | 3318 | break; |
1ed2fc1f | 3319 | case QEMU_OPTION_rtc: |
70b94331 MA |
3320 | opts = qemu_opts_parse_noisily(qemu_find_opts("rtc"), optarg, |
3321 | false); | |
1ed2fc1f | 3322 | if (!opts) { |
1ed2fc1f | 3323 | exit(1); |
7e0af5d0 FB |
3324 | } |
3325 | break; | |
2e70f6ef | 3326 | case QEMU_OPTION_icount: |
70b94331 MA |
3327 | icount_opts = qemu_opts_parse_noisily(qemu_find_opts("icount"), |
3328 | optarg, true); | |
1ad9580b ST |
3329 | if (!icount_opts) { |
3330 | exit(1); | |
3331 | } | |
2e70f6ef | 3332 | break; |
5bb7910a | 3333 | case QEMU_OPTION_incoming: |
7c76235a DDAG |
3334 | if (!incoming) { |
3335 | runstate_set(RUN_STATE_INMIGRATE); | |
3336 | } | |
5bb7910a AL |
3337 | incoming = optarg; |
3338 | break; | |
d15c05fc | 3339 | case QEMU_OPTION_only_migratable: |
811f8652 | 3340 | only_migratable = 1; |
d15c05fc | 3341 | break; |
d8c208dd | 3342 | case QEMU_OPTION_nodefaults: |
d44229c5 | 3343 | has_defaults = 0; |
d8c208dd | 3344 | break; |
e37630ca | 3345 | case QEMU_OPTION_xen_domid: |
ad96090a | 3346 | if (!(xen_available())) { |
da002526 | 3347 | error_report("Option not supported for this target"); |
ad96090a BS |
3348 | exit(1); |
3349 | } | |
e37630ca AL |
3350 | xen_domid = atoi(optarg); |
3351 | break; | |
e37630ca | 3352 | case QEMU_OPTION_xen_attach: |
ad96090a | 3353 | if (!(xen_available())) { |
da002526 | 3354 | error_report("Option not supported for this target"); |
ad96090a BS |
3355 | exit(1); |
3356 | } | |
e37630ca AL |
3357 | xen_mode = XEN_ATTACH; |
3358 | break; | |
1c599472 PD |
3359 | case QEMU_OPTION_xen_domid_restrict: |
3360 | if (!(xen_available())) { | |
3361 | error_report("Option not supported for this target"); | |
3362 | exit(1); | |
3363 | } | |
3364 | xen_domid_restrict = true; | |
3365 | break; | |
ab6540d5 | 3366 | case QEMU_OPTION_trace: |
92eecfff | 3367 | trace_opt_parse(optarg); |
ab6540d5 | 3368 | break; |
42229a75 LV |
3369 | case QEMU_OPTION_plugin: |
3370 | qemu_plugin_opt_parse(optarg, &plugin_list); | |
3371 | break; | |
715a664a | 3372 | case QEMU_OPTION_readconfig: |
f7544edc PB |
3373 | qemu_read_config_file(optarg, &error_fatal); |
3374 | break; | |
29b0040b | 3375 | case QEMU_OPTION_spice: |
9ed345a1 GH |
3376 | olist = qemu_find_opts_err("spice", NULL); |
3377 | if (!olist) { | |
3378 | ui_module_load_one("spice-core"); | |
3379 | olist = qemu_find_opts("spice"); | |
3380 | } | |
29b0040b | 3381 | if (!olist) { |
5dfdae81 | 3382 | error_report("spice support is disabled"); |
29b0040b GH |
3383 | exit(1); |
3384 | } | |
70b94331 | 3385 | opts = qemu_opts_parse_noisily(olist, optarg, false); |
29b0040b | 3386 | if (!opts) { |
29b0040b GH |
3387 | exit(1); |
3388 | } | |
f963e4d0 | 3389 | display_remote++; |
29b0040b | 3390 | break; |
715a664a GH |
3391 | case QEMU_OPTION_writeconfig: |
3392 | { | |
3393 | FILE *fp; | |
b979c931 | 3394 | warn_report("-writeconfig is deprecated and will go away without a replacement"); |
715a664a GH |
3395 | if (strcmp(optarg, "-") == 0) { |
3396 | fp = stdout; | |
3397 | } else { | |
3398 | fp = fopen(optarg, "w"); | |
3399 | if (fp == NULL) { | |
f61eddcb EH |
3400 | error_report("open %s: %s", optarg, |
3401 | strerror(errno)); | |
715a664a GH |
3402 | exit(1); |
3403 | } | |
3404 | } | |
3405 | qemu_config_write(fp); | |
7fb8b5d9 CG |
3406 | if (fp != stdout) { |
3407 | fclose(fp); | |
3408 | } | |
715a664a GH |
3409 | break; |
3410 | } | |
c7f0f3b1 AL |
3411 | case QEMU_OPTION_qtest: |
3412 | qtest_chrdev = optarg; | |
3413 | break; | |
3414 | case QEMU_OPTION_qtest_log: | |
3415 | qtest_log = optarg; | |
3416 | break; | |
7d76ad4f | 3417 | case QEMU_OPTION_sandbox: |
2bb814a4 MAL |
3418 | olist = qemu_find_opts("sandbox"); |
3419 | if (!olist) { | |
3420 | #ifndef CONFIG_SECCOMP | |
3421 | error_report("-sandbox support is not enabled " | |
3422 | "in this QEMU binary"); | |
3423 | #endif | |
3424 | exit(1); | |
3425 | } | |
3426 | ||
3427 | opts = qemu_opts_parse_noisily(olist, optarg, true); | |
7d76ad4f | 3428 | if (!opts) { |
49295ebc | 3429 | exit(1); |
7d76ad4f EO |
3430 | } |
3431 | break; | |
587ed6be CB |
3432 | case QEMU_OPTION_add_fd: |
3433 | #ifndef _WIN32 | |
70b94331 MA |
3434 | opts = qemu_opts_parse_noisily(qemu_find_opts("add-fd"), |
3435 | optarg, false); | |
587ed6be | 3436 | if (!opts) { |
49295ebc | 3437 | exit(1); |
587ed6be CB |
3438 | } |
3439 | #else | |
3440 | error_report("File descriptor passing is disabled on this " | |
3441 | "platform"); | |
3442 | exit(1); | |
3443 | #endif | |
3444 | break; | |
68d98d3e | 3445 | case QEMU_OPTION_object: |
bc2f4fcb | 3446 | object_option_parse(optarg); |
68d98d3e | 3447 | break; |
6f131f13 MT |
3448 | case QEMU_OPTION_overcommit: |
3449 | opts = qemu_opts_parse_noisily(qemu_find_opts("overcommit"), | |
3450 | optarg, false); | |
3451 | if (!opts) { | |
3452 | exit(1); | |
3453 | } | |
c8c9dc42 | 3454 | enable_mlock = qemu_opt_get_bool(opts, "mem-lock", false); |
6f131f13 | 3455 | enable_cpu_pm = qemu_opt_get_bool(opts, "cpu-pm", false); |
888a6bc6 | 3456 | break; |
6dd75472 MA |
3457 | case QEMU_OPTION_compat: |
3458 | { | |
3459 | CompatPolicy *opts; | |
3460 | Visitor *v; | |
3461 | ||
3462 | v = qobject_input_visitor_new_str(optarg, NULL, | |
3463 | &error_fatal); | |
3464 | ||
3465 | visit_type_CompatPolicy(v, NULL, &opts, &error_fatal); | |
3466 | QAPI_CLONE_MEMBERS(CompatPolicy, &compat_policy, opts); | |
3467 | ||
3468 | qapi_free_CompatPolicy(opts); | |
3469 | visit_free(v); | |
3470 | break; | |
3471 | } | |
5e2ac519 | 3472 | case QEMU_OPTION_msg: |
70b94331 MA |
3473 | opts = qemu_opts_parse_noisily(qemu_find_opts("msg"), optarg, |
3474 | false); | |
5e2ac519 SA |
3475 | if (!opts) { |
3476 | exit(1); | |
3477 | } | |
3478 | configure_msg(opts); | |
3479 | break; | |
abfd9ce3 | 3480 | case QEMU_OPTION_dump_vmstate: |
522abf69 | 3481 | if (vmstate_dump_file) { |
f61eddcb EH |
3482 | error_report("only one '-dump-vmstate' " |
3483 | "option may be given"); | |
522abf69 GA |
3484 | exit(1); |
3485 | } | |
abfd9ce3 AS |
3486 | vmstate_dump_file = fopen(optarg, "w"); |
3487 | if (vmstate_dump_file == NULL) { | |
f61eddcb | 3488 | error_report("open %s: %s", optarg, strerror(errno)); |
abfd9ce3 AS |
3489 | exit(1); |
3490 | } | |
12df189d EC |
3491 | break; |
3492 | case QEMU_OPTION_enable_sync_profile: | |
3493 | qsp_enable(); | |
abfd9ce3 | 3494 | break; |
aec0d0e1 MP |
3495 | case QEMU_OPTION_nouserconfig: |
3496 | /* Nothing to be parsed here. Especially, do not error out below. */ | |
3497 | break; | |
59a5264b | 3498 | default: |
1217d6ca TH |
3499 | if (os_parse_cmd_args(popt->index, optarg)) { |
3500 | error_report("Option not supported in this build"); | |
3501 | exit(1); | |
3502 | } | |
cd6f1169 | 3503 | } |
0824d6fc FB |
3504 | } |
3505 | } | |
43fa1e0b EH |
3506 | /* |
3507 | * Clear error location left behind by the loop. | |
3508 | * Best done right after the loop. Do not insert code here! | |
3509 | */ | |
3510 | loc_set_none(); | |
364c3e6b | 3511 | |
58c91595 | 3512 | qemu_validate_options(); |
4d2c17b0 | 3513 | qemu_process_sugar_options(); |
58c91595 | 3514 | |
3df261b6 | 3515 | /* |
0546c060 PB |
3516 | * These options affect everything else and should be processed |
3517 | * before daemonizing. | |
3df261b6 | 3518 | */ |
0546c060 | 3519 | qemu_process_early_options(); |
3df261b6 | 3520 | |
0546c060 PB |
3521 | qemu_process_help_options(); |
3522 | qemu_maybe_daemonize(pid_file); | |
3523 | ||
10b6ee16 DHB |
3524 | /* |
3525 | * The trace backend must be initialized after daemonizing. | |
3526 | * trace_init_backends() will call st_init(), which will create the | |
3527 | * trace thread in the parent, and also register st_flush_trace_buffer() | |
3528 | * in atexit(). This function will force the parent to wait for the | |
3529 | * writeout thread to finish, which will not occur, and the parent | |
3530 | * process will be left in the host. | |
3531 | */ | |
3532 | if (!trace_init_backends()) { | |
3533 | exit(1); | |
3534 | } | |
3535 | trace_init_file(); | |
3536 | ||
efd7ab22 PB |
3537 | qemu_init_main_loop(&error_fatal); |
3538 | cpu_timers_init(); | |
3df261b6 | 3539 | |
fc4a4734 | 3540 | user_register_global_props(); |
4c27b859 PD |
3541 | replay_configure(icount_opts); |
3542 | ||
eb6a5209 AP |
3543 | configure_rtc(qemu_find_opts_singleton("rtc")); |
3544 | ||
f5c9fcb8 | 3545 | qemu_create_machine(select_machine()); |
67b724e6 | 3546 | |
5a1ee607 PB |
3547 | suspend_mux_open(); |
3548 | ||
f650266b PB |
3549 | qemu_disable_default_devices(); |
3550 | qemu_create_default_devices(); | |
64418657 | 3551 | qemu_create_early_backends(); |
cda4aa9a | 3552 | |
7a84268d | 3553 | qemu_apply_machine_options(); |
2f181fbd | 3554 | phase_advance(PHASE_MACHINE_CREATED); |
6b1b1440 | 3555 | |
0427b625 MA |
3556 | /* |
3557 | * Note: uses machine properties such as kernel-irqchip, must run | |
3558 | * after machine_set_property(). | |
3559 | */ | |
28a09617 | 3560 | configure_accelerators(argv[0]); |
2f181fbd | 3561 | phase_advance(PHASE_ACCEL_CREATED); |
214910a7 | 3562 | |
0427b625 MA |
3563 | /* |
3564 | * Beware, QOM objects created before this point miss global and | |
3565 | * compat properties. | |
3566 | * | |
3567 | * Global properties get set up by qdev_prop_register_global(), | |
3568 | * called from user_register_global_props(), and certain option | |
3569 | * desugaring. Also in CPU feature desugaring (buried in | |
c1c8cfe5 | 3570 | * parse_cpu_option()), which happens below this point, but may |
0427b625 | 3571 | * only target the CPU type, which can only be created after |
c1c8cfe5 | 3572 | * parse_cpu_option() returned the type. |
0427b625 MA |
3573 | * |
3574 | * Machine compat properties: object_set_machine_compat_props(). | |
3575 | * Accelerator compat props: object_set_accelerator_compat_props(), | |
b86f59c7 | 3576 | * called from do_configure_accelerator(). |
0427b625 MA |
3577 | */ |
3578 | ||
f5c9fcb8 | 3579 | machine_class = MACHINE_GET_CLASS(current_machine); |
08fe6824 TH |
3580 | if (!qtest_enabled() && machine_class->deprecation_reason) { |
3581 | error_report("Machine type '%s' is deprecated: %s", | |
3582 | machine_class->name, machine_class->deprecation_reason); | |
3583 | } | |
3584 | ||
2fa23277 | 3585 | /* |
0427b625 MA |
3586 | * Note: creates a QOM object, must run only after global and |
3587 | * compat properties have been set up. | |
2fa23277 MA |
3588 | */ |
3589 | migration_object_init(); | |
3590 | ||
07a91b1a | 3591 | qemu_create_late_backends(); |
619985e9 | 3592 | |
6063d4c0 | 3593 | /* parse features once if machine provides default cpu_type */ |
2278b939 | 3594 | current_machine->cpu_type = machine_class->default_cpu_type; |
c1c8cfe5 EH |
3595 | if (cpu_option) { |
3596 | current_machine->cpu_type = parse_cpu_option(cpu_option); | |
6063d4c0 | 3597 | } |
b86f59c7 CF |
3598 | /* NB: for machine none cpu_type could STILL be NULL here! */ |
3599 | accel_init_interfaces(ACCEL_GET_CLASS(current_machine->accelerator)); | |
a1b18df9 | 3600 | |
b24986e7 | 3601 | qemu_resolve_machine_memdev(); |
d342eb76 | 3602 | parse_numa_opts(current_machine); |
6063d4c0 | 3603 | |
abfd9ce3 AS |
3604 | if (vmstate_dump_file) { |
3605 | /* dump and exit */ | |
3606 | dump_vmstate_json_to_file(vmstate_dump_file); | |
7b733862 | 3607 | exit(0); |
abfd9ce3 | 3608 | } |
ffd843bc | 3609 | |
b4e1a342 PB |
3610 | if (!preconfig_requested) { |
3611 | qmp_x_exit_preconfig(&error_fatal); | |
3612 | } | |
facf7c60 | 3613 | qemu_init_displays(); |
7a64c17f | 3614 | accel_setup_post(current_machine); |
eb505be1 | 3615 | os_setup_post(); |
5a1ee607 | 3616 | resume_mux_open(); |
7b733862 | 3617 | } |