]> git.proxmox.com Git - mirror_qemu.git/blob - softmmu/vl.c
qemu-options: New -compat to set policy for deprecated interfaces
[mirror_qemu.git] / softmmu / vl.c
1 /*
2 * QEMU System Emulator
3 *
4 * Copyright (c) 2003-2008 Fabrice Bellard
5 *
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.
23 */
24
25 #include "qemu/osdep.h"
26 #include "qemu-common.h"
27 #include "qemu/datadir.h"
28 #include "qemu/units.h"
29 #include "exec/cpu-common.h"
30 #include "hw/boards.h"
31 #include "hw/qdev-properties.h"
32 #include "qapi/compat-policy.h"
33 #include "qapi/error.h"
34 #include "qapi/qmp/qdict.h"
35 #include "qapi/qmp/qjson.h"
36 #include "qemu-version.h"
37 #include "qemu/cutils.h"
38 #include "qemu/help_option.h"
39 #include "qemu/uuid.h"
40 #include "sysemu/reset.h"
41 #include "sysemu/runstate.h"
42 #include "sysemu/runstate-action.h"
43 #include "sysemu/seccomp.h"
44 #include "sysemu/tcg.h"
45 #include "sysemu/xen.h"
46
47 #include "qemu/error-report.h"
48 #include "qemu/sockets.h"
49 #include "qemu/accel.h"
50 #include "hw/usb.h"
51 #include "hw/isa/isa.h"
52 #include "hw/scsi/scsi.h"
53 #include "hw/display/vga.h"
54 #include "sysemu/watchdog.h"
55 #include "hw/firmware/smbios.h"
56 #include "hw/acpi/acpi.h"
57 #include "hw/xen/xen.h"
58 #include "hw/loader.h"
59 #include "monitor/qdev.h"
60 #include "net/net.h"
61 #include "net/slirp.h"
62 #include "monitor/monitor.h"
63 #include "ui/console.h"
64 #include "ui/input.h"
65 #include "sysemu/sysemu.h"
66 #include "sysemu/numa.h"
67 #include "sysemu/hostmem.h"
68 #include "exec/gdbstub.h"
69 #include "qemu/timer.h"
70 #include "chardev/char.h"
71 #include "qemu/bitmap.h"
72 #include "qemu/log.h"
73 #include "sysemu/blockdev.h"
74 #include "hw/block/block.h"
75 #include "hw/i386/x86.h"
76 #include "hw/i386/pc.h"
77 #include "migration/misc.h"
78 #include "migration/snapshot.h"
79 #include "sysemu/tpm.h"
80 #include "sysemu/dma.h"
81 #include "hw/audio/soundhw.h"
82 #include "audio/audio.h"
83 #include "sysemu/cpus.h"
84 #include "sysemu/cpu-timers.h"
85 #include "migration/colo.h"
86 #include "migration/postcopy-ram.h"
87 #include "sysemu/kvm.h"
88 #include "sysemu/hax.h"
89 #include "qapi/qobject-input-visitor.h"
90 #include "qemu/option.h"
91 #include "qemu/config-file.h"
92 #include "qemu-options.h"
93 #include "qemu/main-loop.h"
94 #ifdef CONFIG_VIRTFS
95 #include "fsdev/qemu-fsdev.h"
96 #endif
97 #include "sysemu/qtest.h"
98
99 #include "disas/disas.h"
100
101 #include "trace.h"
102 #include "trace/control.h"
103 #include "qemu/plugin.h"
104 #include "qemu/queue.h"
105 #include "sysemu/arch_init.h"
106 #include "exec/confidential-guest-support.h"
107
108 #include "ui/qemu-spice.h"
109 #include "qapi/string-input-visitor.h"
110 #include "qapi/opts-visitor.h"
111 #include "qapi/clone-visitor.h"
112 #include "qom/object_interfaces.h"
113 #include "semihosting/semihost.h"
114 #include "crypto/init.h"
115 #include "sysemu/replay.h"
116 #include "qapi/qapi-events-run-state.h"
117 #include "qapi/qapi-visit-block-core.h"
118 #include "qapi/qapi-visit-compat.h"
119 #include "qapi/qapi-visit-ui.h"
120 #include "qapi/qapi-commands-block-core.h"
121 #include "qapi/qapi-commands-migration.h"
122 #include "qapi/qapi-commands-misc.h"
123 #include "qapi/qapi-visit-qom.h"
124 #include "qapi/qapi-commands-ui.h"
125 #include "qapi/qmp/qerror.h"
126 #include "sysemu/iothread.h"
127 #include "qemu/guest-random.h"
128
129 #define MAX_VIRTIO_CONSOLES 1
130
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
139 typedef struct ObjectOption {
140 ObjectOptions *opts;
141 QTAILQ_ENTRY(ObjectOption) next;
142 } ObjectOption;
143
144 static const char *cpu_option;
145 static const char *mem_path;
146 static const char *incoming;
147 static const char *loadvm;
148 static QTAILQ_HEAD(, ObjectOption) object_opts = QTAILQ_HEAD_INITIALIZER(object_opts);
149 static ram_addr_t maxram_size;
150 static uint64_t ram_slots;
151 static int display_remote;
152 static int snapshot;
153 static bool preconfig_requested;
154 static QemuPluginList plugin_list = QTAILQ_HEAD_INITIALIZER(plugin_list);
155 static BlockdevOptionsQueue bdo_queue = QSIMPLEQ_HEAD_INITIALIZER(bdo_queue);
156 static bool nographic = false;
157 static int mem_prealloc; /* force preallocation of physical target memory */
158 static ram_addr_t ram_size;
159 static const char *vga_model = NULL;
160 static DisplayOptions dpy;
161 static int num_serial_hds;
162 static Chardev **serial_hds;
163 static const char *log_mask;
164 static const char *log_file;
165 static bool list_data_dirs;
166 static const char *watchdog;
167 static const char *qtest_chrdev;
168 static const char *qtest_log;
169
170 static int has_defaults = 1;
171 static int default_serial = 1;
172 static int default_parallel = 1;
173 static int default_monitor = 1;
174 static int default_floppy = 1;
175 static int default_cdrom = 1;
176 static int default_sdcard = 1;
177 static int default_vga = 1;
178 static int default_net = 1;
179
180 static struct {
181 const char *driver;
182 int *flag;
183 } default_list[] = {
184 { .driver = "isa-serial", .flag = &default_serial },
185 { .driver = "isa-parallel", .flag = &default_parallel },
186 { .driver = "isa-fdc", .flag = &default_floppy },
187 { .driver = "floppy", .flag = &default_floppy },
188 { .driver = "ide-cd", .flag = &default_cdrom },
189 { .driver = "ide-hd", .flag = &default_cdrom },
190 { .driver = "scsi-cd", .flag = &default_cdrom },
191 { .driver = "scsi-hd", .flag = &default_cdrom },
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 },
198 { .driver = "virtio-vga", .flag = &default_vga },
199 { .driver = "ati-vga", .flag = &default_vga },
200 { .driver = "vhost-user-vga", .flag = &default_vga },
201 };
202
203 static QemuOptsList qemu_rtc_opts = {
204 .name = "rtc",
205 .head = QTAILQ_HEAD_INITIALIZER(qemu_rtc_opts.head),
206 .merge_lists = true,
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
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 = {
244 /*
245 * no elements => accept any
246 * sanity checking will happen later
247 * when setting machine properties
248 */
249 { }
250 },
251 };
252
253 static QemuOptsList qemu_accel_opts = {
254 .name = "accel",
255 .implied_opt_name = "accel",
256 .head = QTAILQ_HEAD_INITIALIZER(qemu_accel_opts.head),
257 .desc = {
258 /*
259 * no elements => accept any
260 * sanity checking will happen later
261 * when setting accelerator properties
262 */
263 { }
264 },
265 };
266
267 static QemuOptsList qemu_boot_opts = {
268 .name = "boot-opts",
269 .implied_opt_name = "order",
270 .merge_lists = true,
271 .head = QTAILQ_HEAD_INITIALIZER(qemu_boot_opts.head),
272 .desc = {
273 {
274 .name = "order",
275 .type = QEMU_OPT_STRING,
276 }, {
277 .name = "once",
278 .type = QEMU_OPT_STRING,
279 }, {
280 .name = "menu",
281 .type = QEMU_OPT_BOOL,
282 }, {
283 .name = "splash",
284 .type = QEMU_OPT_STRING,
285 }, {
286 .name = "splash-time",
287 .type = QEMU_OPT_NUMBER,
288 }, {
289 .name = "reboot-timeout",
290 .type = QEMU_OPT_NUMBER,
291 }, {
292 .name = "strict",
293 .type = QEMU_OPT_BOOL,
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
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 = {
334 /* options are defined in the TPM backends */
335 { /* end of list */ }
336 },
337 };
338
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
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 },
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 },
369 { /* end of list */ }
370 },
371 };
372
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",
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.",
395 },
396 { /* End of list */ }
397 },
398 };
399
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 },
410 {
411 .name = "slots",
412 .type = QEMU_OPT_NUMBER,
413 },
414 {
415 .name = "maxmem",
416 .type = QEMU_OPT_SIZE,
417 },
418 { /* end of list */ }
419 },
420 };
421
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,
431 }, {
432 .name = "align",
433 .type = QEMU_OPT_BOOL,
434 }, {
435 .name = "sleep",
436 .type = QEMU_OPT_BOOL,
437 }, {
438 .name = "rr",
439 .type = QEMU_OPT_STRING,
440 }, {
441 .name = "rrfile",
442 .type = QEMU_OPT_STRING,
443 }, {
444 .name = "rrsnapshot",
445 .type = QEMU_OPT_STRING,
446 },
447 { /* end of list */ }
448 },
449 };
450
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,
463 .help = "Sets the name of the file from which "
464 "the fw_cfg blob will be loaded",
465 }, {
466 .name = "string",
467 .type = QEMU_OPT_STRING,
468 .help = "Sets content of the blob to be inserted from a string",
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",
474 },
475 { /* end of list */ }
476 },
477 };
478
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,
490 },{
491 .name = "panic",
492 .type = QEMU_OPT_STRING,
493 },{
494 .name = "watchdog",
495 .type = QEMU_OPT_STRING,
496 },
497 { /* end of list */ }
498 },
499 };
500
501 /**
502 * Get machine options
503 *
504 * Returns: machine options (never null).
505 */
506 static QemuOpts *qemu_get_machine_opts(void)
507 {
508 return qemu_find_opts_singleton("machine");
509 }
510
511 const char *qemu_get_vm_name(void)
512 {
513 return qemu_name;
514 }
515
516 static int default_driver_check(void *opaque, QemuOpts *opts, Error **errp)
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
531 static int parse_name(void *opaque, QemuOpts *opts, Error **errp)
532 {
533 const char *proc_name;
534
535 if (qemu_opt_get(opts, "debug-threads")) {
536 qemu_thread_naming(qemu_opt_get_bool(opts, "debug-threads", false));
537 }
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 }
544
545 return 0;
546 }
547
548 bool defaults_enabled(void)
549 {
550 return has_defaults;
551 }
552
553 #ifndef _WIN32
554 static int parse_add_fd(void *opaque, QemuOpts *opts, Error **errp)
555 {
556 int fd, dupfd, flags;
557 int64_t fdset_id;
558 const char *fd_opaque = NULL;
559 AddfdInfo *fdinfo;
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) {
566 error_setg(errp, "fd option is required and must be non-negative");
567 return -1;
568 }
569
570 if (fd <= STDERR_FILENO) {
571 error_setg(errp, "fd cannot be a standard I/O stream");
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)) {
581 error_setg(errp, "fd is not valid or already in use");
582 return -1;
583 }
584
585 if (fdset_id < 0) {
586 error_setg(errp, "set option is required and must be non-negative");
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) {
599 error_setg(errp, "error duplicating fd: %s", strerror(errno));
600 return -1;
601 }
602
603 /* add the duplicate fd, and optionally the opaque string, to the fd set */
604 fdinfo = monitor_fdset_add_fd(dupfd, true, fdset_id, !!fd_opaque, fd_opaque,
605 &error_abort);
606 g_free(fdinfo);
607
608 return 0;
609 }
610
611 static int cleanup_add_fd(void *opaque, QemuOpts *opts, Error **errp)
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
622 /***********************************************************/
623 /* QEMU Block devices */
624
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 ""
631
632 static int drive_init_func(void *opaque, QemuOpts *opts, Error **errp)
633 {
634 BlockInterfaceType *block_default_type = opaque;
635
636 return drive_new(opts, *block_default_type, errp) == NULL;
637 }
638
639 static int drive_enable_snapshot(void *opaque, QemuOpts *opts, Error **errp)
640 {
641 if (qemu_opt_get(opts, "snapshot") == NULL) {
642 qemu_opt_set(opts, "snapshot", "on", &error_abort);
643 }
644 return 0;
645 }
646
647 static void default_drive(int enable, int snapshot, BlockInterfaceType type,
648 int index, const char *optstr)
649 {
650 QemuOpts *opts;
651 DriveInfo *dinfo;
652
653 if (!enable || drive_get_by_index(type, index)) {
654 return;
655 }
656
657 opts = drive_add(type, index, NULL, optstr);
658 if (snapshot) {
659 drive_enable_snapshot(NULL, opts, NULL);
660 }
661
662 dinfo = drive_new(opts, type, &error_abort);
663 dinfo->is_default = true;
664
665 }
666
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 }
691 if (snapshot) {
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
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,
720 }, {
721 .name = "dies",
722 .type = QEMU_OPT_NUMBER,
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
737 static void realtime_init(void)
738 {
739 if (enable_mlock) {
740 if (os_mlock() < 0) {
741 error_report("locking memory failed");
742 exit(1);
743 }
744 }
745 }
746
747
748 static void configure_msg(QemuOpts *opts)
749 {
750 message_with_timestamp = qemu_opt_get_bool(opts, "timestamp", false);
751 error_with_guestname = qemu_opt_get_bool(opts, "guest-name", false);
752 }
753
754
755 /***********************************************************/
756 /* USB devices */
757
758 static int usb_device_add(const char *devname)
759 {
760 USBDevice *dev = NULL;
761
762 if (!machine_usb(current_machine)) {
763 return -1;
764 }
765
766 dev = usbdevice_create(devname);
767 if (!dev)
768 return -1;
769
770 return 0;
771 }
772
773 static int usb_parse(const char *cmdline)
774 {
775 int r;
776 r = usb_device_add(cmdline);
777 if (r < 0) {
778 error_report("could not add USB device '%s'", cmdline);
779 }
780 return r;
781 }
782
783 /***********************************************************/
784 /* machine registration */
785
786 static MachineClass *find_machine(const char *name, GSList *machines)
787 {
788 GSList *el;
789
790 for (el = machines; el; el = el->next) {
791 MachineClass *mc = el->data;
792
793 if (!strcmp(mc->name, name) || !g_strcmp0(mc->alias, name)) {
794 return mc;
795 }
796 }
797
798 return NULL;
799 }
800
801 static MachineClass *find_default_machine(GSList *machines)
802 {
803 GSList *el;
804 MachineClass *default_machineclass = NULL;
805
806 for (el = machines; el; el = el->next) {
807 MachineClass *mc = el->data;
808
809 if (mc->is_default) {
810 assert(default_machineclass == NULL && "Multiple default machines");
811 default_machineclass = mc;
812 }
813 }
814
815 return default_machineclass;
816 }
817
818 static int machine_help_func(QemuOpts *opts, MachineState *machine)
819 {
820 ObjectProperty *prop;
821 ObjectPropertyIterator iter;
822
823 if (!qemu_opt_has_help_opt(opts)) {
824 return 0;
825 }
826
827 object_property_iter_init(&iter, OBJECT(machine));
828 while ((prop = object_property_iter_next(&iter))) {
829 if (!prop->set) {
830 continue;
831 }
832
833 printf("%s.%s=%s", MACHINE_GET_CLASS(machine)->name,
834 prop->name, prop->type);
835 if (prop->description) {
836 printf(" (%s)\n", prop->description);
837 } else {
838 printf("\n");
839 }
840 }
841
842 return 1;
843 }
844
845 static void version(void)
846 {
847 printf("QEMU emulator version " QEMU_FULL_VERSION "\n"
848 QEMU_COPYRIGHT "\n");
849 }
850
851 static void help(int exitcode)
852 {
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
858 #define QEMU_OPTIONS_GENERATE_HELP
859 #include "qemu-options-wrapper.h"
860
861 printf("\nDuring emulation, the following keys are useful:\n"
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"
866 "When using -nographic, press 'ctrl-a h' to get some help.\n"
867 "\n"
868 QEMU_HELP_BOTTOM "\n");
869
870 exit(exitcode);
871 }
872
873 #define HAS_ARG 0x0001
874
875 typedef struct QEMUOption {
876 const char *name;
877 int flags;
878 int index;
879 uint32_t arch_mask;
880 } QEMUOption;
881
882 static const QEMUOption qemu_options[] = {
883 { "h", 0, QEMU_OPTION_h, QEMU_ARCH_ALL },
884 #define QEMU_OPTIONS_GENERATE_OPTIONS
885 #include "qemu-options-wrapper.h"
886 { NULL },
887 };
888
889 typedef struct VGAInterfaceInfo {
890 const char *opt_name; /* option name */
891 const char *name; /* human-readable name */
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];
895 } VGAInterfaceInfo;
896
897 static const VGAInterfaceInfo vga_interfaces[VGA_TYPE_MAX] = {
898 [VGA_NONE] = {
899 .opt_name = "none",
900 .name = "no graphic card",
901 },
902 [VGA_STD] = {
903 .opt_name = "std",
904 .name = "standard VGA",
905 .class_names = { "VGA", "isa-vga" },
906 },
907 [VGA_CIRRUS] = {
908 .opt_name = "cirrus",
909 .name = "Cirrus VGA",
910 .class_names = { "cirrus-vga", "isa-cirrus-vga" },
911 },
912 [VGA_VMWARE] = {
913 .opt_name = "vmware",
914 .name = "VMWare SVGA",
915 .class_names = { "vmware-svga" },
916 },
917 [VGA_VIRTIO] = {
918 .opt_name = "virtio",
919 .name = "Virtio VGA",
920 .class_names = { "virtio-vga" },
921 },
922 [VGA_QXL] = {
923 .opt_name = "qxl",
924 .name = "QXL VGA",
925 .class_names = { "qxl-vga" },
926 },
927 [VGA_TCX] = {
928 .opt_name = "tcx",
929 .name = "TCX framebuffer",
930 .class_names = { "SUNW,tcx" },
931 },
932 [VGA_CG3] = {
933 .opt_name = "cg3",
934 .name = "CG3 framebuffer",
935 .class_names = { "cgthree" },
936 },
937 [VGA_XENFB] = {
938 .opt_name = "xenfb",
939 .name = "Xen paravirtualized framebuffer",
940 },
941 };
942
943 static bool vga_interface_available(VGAInterfaceType t)
944 {
945 const VGAInterfaceInfo *ti = &vga_interfaces[t];
946
947 assert(t < VGA_TYPE_MAX);
948 return !ti->class_names[0] ||
949 module_object_class_by_name(ti->class_names[0]) ||
950 module_object_class_by_name(ti->class_names[1]);
951 }
952
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)
968 {
969 const char *opts;
970 int t;
971
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
986 assert(vga_interface_type == VGA_NONE);
987 for (t = 0; t < VGA_TYPE_MAX; t++) {
988 const VGAInterfaceInfo *ti = &vga_interfaces[t];
989 if (ti->opt_name && strstart(p, ti->opt_name, &opts)) {
990 if (!vga_interface_available(t)) {
991 error_report("%s not available", ti->name);
992 exit(1);
993 }
994 vga_interface_type = t;
995 break;
996 }
997 }
998 if (t == VGA_TYPE_MAX) {
999 invalid_vga:
1000 error_report("unknown vga type: %s", p);
1001 exit(1);
1002 }
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 }
1016 }
1017
1018 static void parse_display_qapi(const char *optarg)
1019 {
1020 DisplayOptions *opts;
1021 Visitor *v;
1022
1023 v = qobject_input_visitor_new_str(optarg, "type", &error_fatal);
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
1032 DisplayOptions *qmp_query_display_options(Error **errp)
1033 {
1034 return QAPI_CLONE(DisplayOptions, &dpy);
1035 }
1036
1037 static void parse_display(const char *p)
1038 {
1039 const char *opts;
1040
1041 if (is_help_option(p)) {
1042 qemu_display_help();
1043 exit(0);
1044 }
1045
1046 if (strstart(p, "sdl", &opts)) {
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 */
1057 dpy.type = DISPLAY_TYPE_SDL;
1058 while (*opts) {
1059 const char *nextopt;
1060
1061 if (strstart(opts, ",alt_grab=", &nextopt)) {
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 {
1068 goto invalid_sdl_args;
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 {
1077 goto invalid_sdl_args;
1078 }
1079 } else if (strstart(opts, ",window_close=", &nextopt)) {
1080 opts = nextopt;
1081 dpy.has_window_close = true;
1082 if (strstart(opts, "on", &nextopt)) {
1083 dpy.window_close = true;
1084 } else if (strstart(opts, "off", &nextopt)) {
1085 dpy.window_close = false;
1086 } else {
1087 goto invalid_sdl_args;
1088 }
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 }
1099 } else if (strstart(opts, ",gl=", &nextopt)) {
1100 opts = nextopt;
1101 dpy.has_gl = true;
1102 if (strstart(opts, "on", &nextopt)) {
1103 dpy.gl = DISPLAYGL_MODE_ON;
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;
1108 } else if (strstart(opts, "off", &nextopt)) {
1109 dpy.gl = DISPLAYGL_MODE_OFF;
1110 } else {
1111 goto invalid_sdl_args;
1112 }
1113 } else {
1114 invalid_sdl_args:
1115 error_report("invalid SDL option string");
1116 exit(1);
1117 }
1118 opts = nextopt;
1119 }
1120 } else if (strstart(p, "vnc", &opts)) {
1121 /*
1122 * vnc isn't a (local) DisplayType but a protocol for remote
1123 * display access.
1124 */
1125 if (*opts == '=') {
1126 vnc_parse(opts + 1);
1127 } else {
1128 error_report("VNC requires a display argument vnc=<display>");
1129 exit(1);
1130 }
1131 } else {
1132 parse_display_qapi(p);
1133 }
1134 }
1135
1136 static inline bool nonempty_str(const char *str)
1137 {
1138 return str && *str;
1139 }
1140
1141 static int parse_fw_cfg(void *opaque, QemuOpts *opts, Error **errp)
1142 {
1143 gchar *buf;
1144 size_t size;
1145 const char *name, *file, *str, *gen_id;
1146 FWCfgState *fw_cfg = (FWCfgState *) opaque;
1147
1148 if (fw_cfg == NULL) {
1149 error_setg(errp, "fw_cfg device not available");
1150 return -1;
1151 }
1152 name = qemu_opt_get(opts, "name");
1153 file = qemu_opt_get(opts, "file");
1154 str = qemu_opt_get(opts, "string");
1155 gen_id = qemu_opt_get(opts, "gen_id");
1156
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");
1162 return -1;
1163 }
1164 if (strlen(name) > FW_CFG_MAX_FILE_PATH - 1) {
1165 error_setg(errp, "name too long (max. %d char)",
1166 FW_CFG_MAX_FILE_PATH - 1);
1167 return -1;
1168 }
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) {
1176 warn_report("externally provided fw_cfg item names "
1177 "should be prefixed with \"opt/\"");
1178 }
1179 if (nonempty_str(str)) {
1180 size = strlen(str); /* NUL terminator NOT included in fw_cfg blob */
1181 buf = g_memdup(str, size);
1182 } else if (nonempty_str(gen_id)) {
1183 if (!fw_cfg_add_from_generator(fw_cfg, name, gen_id, errp)) {
1184 return -1;
1185 }
1186 return 0;
1187 } else {
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);
1192 return -1;
1193 }
1194 }
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);
1199 return 0;
1200 }
1201
1202 static int device_help_func(void *opaque, QemuOpts *opts, Error **errp)
1203 {
1204 return qdev_device_help(opts);
1205 }
1206
1207 static int device_init_func(void *opaque, QemuOpts *opts, Error **errp)
1208 {
1209 DeviceState *dev;
1210
1211 dev = qdev_device_add(opts, errp);
1212 if (!dev && *errp) {
1213 error_report_err(*errp);
1214 return -1;
1215 } else if (dev) {
1216 object_unref(OBJECT(dev));
1217 }
1218 return 0;
1219 }
1220
1221 static int chardev_init_func(void *opaque, QemuOpts *opts, Error **errp)
1222 {
1223 Error *local_err = NULL;
1224
1225 if (!qemu_chr_new_from_opts(opts, NULL, &local_err)) {
1226 if (local_err) {
1227 error_propagate(errp, local_err);
1228 return -1;
1229 }
1230 exit(0);
1231 }
1232 return 0;
1233 }
1234
1235 #ifdef CONFIG_VIRTFS
1236 static int fsdev_init_func(void *opaque, QemuOpts *opts, Error **errp)
1237 {
1238 return qemu_fsdev_add(opts, errp);
1239 }
1240 #endif
1241
1242 static int mon_init_func(void *opaque, QemuOpts *opts, Error **errp)
1243 {
1244 return monitor_init_opts(opts, errp);
1245 }
1246
1247 static void monitor_parse(const char *optarg, const char *mode, bool pretty)
1248 {
1249 static int monitor_device_index = 0;
1250 QemuOpts *opts;
1251 const char *p;
1252 char label[32];
1253
1254 if (strstart(optarg, "chardev:", &p)) {
1255 snprintf(label, sizeof(label), "%s", p);
1256 } else {
1257 snprintf(label, sizeof(label), "compat_monitor%d",
1258 monitor_device_index);
1259 opts = qemu_chr_parse_compat(label, optarg, true);
1260 if (!opts) {
1261 error_report("parse error: %s", optarg);
1262 exit(1);
1263 }
1264 }
1265
1266 opts = qemu_opts_create(qemu_find_opts("mon"), label, 1, &error_fatal);
1267 qemu_opt_set(opts, "mode", mode, &error_abort);
1268 qemu_opt_set(opts, "chardev", label, &error_abort);
1269 if (!strcmp(mode, "control")) {
1270 qemu_opt_set_bool(opts, "pretty", pretty, &error_abort);
1271 } else {
1272 assert(pretty == false);
1273 }
1274 monitor_device_index++;
1275 }
1276
1277 struct device_config {
1278 enum {
1279 DEV_USB, /* -usbdevice */
1280 DEV_SERIAL, /* -serial */
1281 DEV_PARALLEL, /* -parallel */
1282 DEV_DEBUGCON, /* -debugcon */
1283 DEV_GDB, /* -gdb, -s */
1284 DEV_SCLP, /* s390 sclp */
1285 } type;
1286 const char *cmdline;
1287 Location loc;
1288 QTAILQ_ENTRY(device_config) next;
1289 };
1290
1291 static QTAILQ_HEAD(, device_config) device_configs =
1292 QTAILQ_HEAD_INITIALIZER(device_configs);
1293
1294 static void add_device_config(int type, const char *cmdline)
1295 {
1296 struct device_config *conf;
1297
1298 conf = g_malloc0(sizeof(*conf));
1299 conf->type = type;
1300 conf->cmdline = cmdline;
1301 loc_save(&conf->loc);
1302 QTAILQ_INSERT_TAIL(&device_configs, conf, next);
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
1310 QTAILQ_FOREACH(conf, &device_configs, next) {
1311 if (conf->type != type)
1312 continue;
1313 loc_push_restore(&conf->loc);
1314 rc = func(conf->cmdline);
1315 loc_pop(&conf->loc);
1316 if (rc) {
1317 return rc;
1318 }
1319 }
1320 return 0;
1321 }
1322
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)
1415 vnc_parse("localhost:0,to=99,id=default");
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
1432 static int serial_parse(const char *devname)
1433 {
1434 int index = num_serial_hds;
1435 char label[32];
1436
1437 if (strcmp(devname, "none") == 0)
1438 return 0;
1439 snprintf(label, sizeof(label), "serial%d", index);
1440 serial_hds = g_renew(Chardev *, serial_hds, index + 1);
1441
1442 serial_hds[index] = qemu_chr_new_mux_mon(label, devname, NULL);
1443 if (!serial_hds[index]) {
1444 error_report("could not connect serial device"
1445 " to character backend '%s'", devname);
1446 return -1;
1447 }
1448 num_serial_hds++;
1449 return 0;
1450 }
1451
1452 Chardev *serial_hd(int i)
1453 {
1454 assert(i >= 0);
1455 if (i < num_serial_hds) {
1456 return serial_hds[i];
1457 }
1458 return NULL;
1459 }
1460
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) {
1469 error_report("too many parallel ports");
1470 exit(1);
1471 }
1472 snprintf(label, sizeof(label), "parallel%d", index);
1473 parallel_hds[index] = qemu_chr_new_mux_mon(label, devname, NULL);
1474 if (!parallel_hds[index]) {
1475 error_report("could not connect parallel device"
1476 " to character backend '%s'", devname);
1477 return -1;
1478 }
1479 index++;
1480 return 0;
1481 }
1482
1483 static int debugcon_parse(const char *devname)
1484 {
1485 QemuOpts *opts;
1486
1487 if (!qemu_chr_new_mux_mon("debugcon", devname, NULL)) {
1488 error_report("invalid character backend '%s'", devname);
1489 exit(1);
1490 }
1491 opts = qemu_opts_create(qemu_find_opts("device"), "debugcon", 1, NULL);
1492 if (!opts) {
1493 error_report("already have a debugcon device");
1494 exit(1);
1495 }
1496 qemu_opt_set(opts, "driver", "isa-debugcon", &error_abort);
1497 qemu_opt_set(opts, "chardev", "debugcon", &error_abort);
1498 return 0;
1499 }
1500
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
1535 static MachineClass *machine_parse(const char *name, GSList *machines)
1536 {
1537 MachineClass *mc;
1538 GSList *el;
1539
1540 if (is_help_option(name)) {
1541 printf("Supported machines are:\n");
1542 machines = g_slist_sort(machines, machine_class_cmp);
1543 for (el = machines; el; el = el->next) {
1544 MachineClass *mc = el->data;
1545 if (mc->alias) {
1546 printf("%-20s %s (alias of %s)\n", mc->alias, mc->desc, mc->name);
1547 }
1548 printf("%-20s %s%s%s\n", mc->name, mc->desc,
1549 mc->is_default ? " (default)" : "",
1550 mc->deprecation_reason ? " (deprecated)" : "");
1551 }
1552 exit(0);
1553 }
1554
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;
1562 }
1563
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
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
1582 loc_set_cmdline(argv, optind, 1);
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) {
1590 error_report("invalid option");
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) {
1599 error_report("requires an argument");
1600 exit(1);
1601 }
1602 optarg = argv[optind++];
1603 loc_set_cmdline(argv, optind - 2, 2);
1604 } else {
1605 optarg = NULL;
1606 }
1607
1608 *poptarg = optarg;
1609 *poptind = optind;
1610
1611 return popt;
1612 }
1613
1614 static MachineClass *select_machine(void)
1615 {
1616 GSList *machines = object_class_get_list(TYPE_MACHINE, false);
1617 MachineClass *machine_class = find_default_machine(machines);
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) {
1629 machine_class = machine_parse(optarg, machines);
1630 }
1631
1632 if (!machine_class) {
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);
1639 g_slist_free(machines);
1640 return machine_class;
1641 }
1642
1643 static int object_parse_property_opt(Object *obj,
1644 const char *name, const char *value,
1645 const char *skip, Error **errp)
1646 {
1647 if (g_str_equal(name, skip)) {
1648 return 0;
1649 }
1650
1651 if (!object_property_parse(obj, name, value, errp)) {
1652 return -1;
1653 }
1654
1655 return 0;
1656 }
1657
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
1671 /* Legacy options do not correspond to MachineState properties. */
1672 if (g_str_equal(qom_name, "accel")) {
1673 return 0;
1674 }
1675 if (g_str_equal(qom_name, "igd-passthru")) {
1676 object_register_sugar_prop(ACCEL_CLASS_NAME("xen"), qom_name, value,
1677 false);
1678 return 0;
1679 }
1680 if (g_str_equal(qom_name, "kvm-shadow-mem")) {
1681 object_register_sugar_prop(ACCEL_CLASS_NAME("kvm"), qom_name, value,
1682 false);
1683 return 0;
1684 }
1685 if (g_str_equal(qom_name, "kernel-irqchip")) {
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);
1690 return 0;
1691 }
1692
1693 return object_parse_property_opt(opaque, name, value, "type", errp);
1694 }
1695
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
1718 if (optarg[0] == '{') {
1719 QObject *obj = qobject_from_json(optarg, &error_fatal);
1720
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);
1739 }
1740
1741 opt = g_new0(ObjectOption, 1);
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
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 */
1755 static bool object_create_early(const char *type)
1756 {
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" */
1763 if (g_str_equal(type, "rng-egd")) {
1764 return false;
1765 }
1766
1767 #if defined(CONFIG_VHOST_USER) && defined(CONFIG_LINUX)
1768 /* Reason: cryptodev-vhost-user property "chardev" */
1769 if (g_str_equal(type, "cryptodev-vhost-user")) {
1770 return false;
1771 }
1772 #endif
1773
1774 /* Reason: vhost-user-blk-server property "node-name" */
1775 if (g_str_equal(type, "vhost-user-blk-server")) {
1776 return false;
1777 }
1778 /*
1779 * Reason: filter-* property "netdev" etc.
1780 */
1781 if (g_str_equal(type, "filter-buffer") ||
1782 g_str_equal(type, "filter-dump") ||
1783 g_str_equal(type, "filter-mirror") ||
1784 g_str_equal(type, "filter-redirector") ||
1785 g_str_equal(type, "colo-compare") ||
1786 g_str_equal(type, "filter-rewriter") ||
1787 g_str_equal(type, "filter-replay")) {
1788 return false;
1789 }
1790
1791 /*
1792 * Allocation of large amounts of memory may delay
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
1801 return true;
1802 }
1803
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();
1808 const char *boot_order = NULL;
1809 const char *boot_once = NULL;
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;
1839 current_machine->boot_once = boot_once;
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 }
1847 }
1848
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
1875 object_option_foreach_add(object_create_early);
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
1899
1900 /*
1901 * The remainder of object creation happens after the
1902 * creation of chardev, fsdev, net clients and device data types.
1903 */
1904 static bool object_create_late(const char *type)
1905 {
1906 return !object_create_early(type);
1907 }
1908
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
1917 object_option_foreach_add(object_create_late);
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 }
1937
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
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
1980 static void set_memory_options(MachineClass *mc)
1981 {
1982 uint64_t sz;
1983 const char *mem_str;
1984 const ram_addr_t default_ram_size = mc->default_ram_size;
1985 QemuOpts *opts = qemu_find_opts_singleton("memory");
1986 Location loc;
1987
1988 loc_push_none(&loc);
1989 qemu_opts_loc_restore(opts);
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
2005 sz *= MiB;
2006 if (sz / MiB != overflow_check) {
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);
2019 if (mc->fixup_ram_size) {
2020 sz = mc->fixup_ram_size(sz);
2021 }
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 */
2029 qemu_opt_set_number(opts, "size", ram_size, &error_abort);
2030 maxram_size = ram_size;
2031
2032 if (qemu_opt_get(opts, "maxmem")) {
2033 uint64_t slots;
2034
2035 sz = qemu_opt_get_size(opts, "maxmem", 0);
2036 slots = qemu_opt_get_number(opts, "slots", 0);
2037 if (sz < ram_size) {
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);
2042 exit(EXIT_FAILURE);
2043 } else if (slots && sz == ram_size) {
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);
2048 exit(EXIT_FAILURE);
2049 }
2050
2051 maxram_size = sz;
2052 ram_slots = slots;
2053 } else if (qemu_opt_get(opts, "slots")) {
2054 error_report("invalid -m option value: missing 'maxmem' option");
2055 exit(EXIT_FAILURE);
2056 }
2057
2058 loc_pop(&loc);
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 }
2104 }
2105
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");
2114 qdev_prop_register_global(g);
2115 return 0;
2116 }
2117
2118 static void qemu_read_default_config_file(Error **errp)
2119 {
2120 ERRP_GUARD();
2121 int ret;
2122 g_autofree char *file = get_relocated_path(CONFIG_QEMU_CONFDIR "/qemu.conf");
2123
2124 ret = qemu_read_config_file(file, errp);
2125 if (ret < 0) {
2126 if (ret == -ENOENT) {
2127 error_free(*errp);
2128 *errp = NULL;
2129 }
2130 }
2131 }
2132
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
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
2172 static int do_configure_icount(void *opaque, QemuOpts *opts, Error **errp)
2173 {
2174 icount_configure(opts, errp);
2175 return 0;
2176 }
2177
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
2185 static int do_configure_accelerator(void *opaque, QemuOpts *opts, Error **errp)
2186 {
2187 bool *p_init_failed = opaque;
2188 const char *acc = qemu_opt_get(opts, "accel");
2189 AccelClass *ac = accel_find(acc);
2190 AccelState *accel;
2191 int ret;
2192 bool qtest_with_kvm;
2193
2194 qtest_with_kvm = g_str_equal(acc, "kvm") && qtest_chrdev != NULL;
2195
2196 if (!ac) {
2197 *p_init_failed = true;
2198 if (!qtest_with_kvm) {
2199 error_report("invalid accelerator %s", acc);
2200 }
2201 return 0;
2202 }
2203 accel = ACCEL(object_new_with_class(OBJECT_CLASS(ac)));
2204 object_apply_compat_props(OBJECT(accel));
2205 qemu_opt_foreach(opts, accelerator_set_property,
2206 accel,
2207 &error_fatal);
2208
2209 ret = accel_init_machine(accel, current_machine);
2210 if (ret < 0) {
2211 *p_init_failed = true;
2212 if (!qtest_with_kvm || ret != -ENOENT) {
2213 error_report("failed to initialize %s: %s", acc, strerror(-ret));
2214 }
2215 return 0;
2216 }
2217
2218 return 1;
2219 }
2220
2221 static void configure_accelerators(const char *progname)
2222 {
2223 const char *accelerators;
2224 bool init_failed = false;
2225
2226 qemu_opts_foreach(qemu_find_opts("icount"),
2227 do_configure_icount, NULL, &error_fatal);
2228
2229 accelerators = qemu_opt_get(qemu_get_machine_opts(), "accel");
2230 if (QTAILQ_EMPTY(&qemu_accel_opts.head)) {
2231 char **accel_list, **tmp;
2232
2233 if (accelerators == NULL) {
2234 /* Select the default accelerator */
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")) {
2240 /* If the program name ends with "kvm", we prefer KVM */
2241 accelerators = "kvm:tcg";
2242 } else {
2243 accelerators = "tcg:kvm";
2244 }
2245 } else if (have_kvm) {
2246 accelerators = "kvm";
2247 } else if (have_tcg) {
2248 accelerators = "tcg";
2249 } else {
2250 error_report("No accelerator selected and"
2251 " no default accelerator available");
2252 exit(1);
2253 }
2254 }
2255 accel_list = g_strsplit(accelerators, ":", 0);
2256
2257 for (tmp = accel_list; *tmp; tmp++) {
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);
2264 } else {
2265 init_failed = true;
2266 error_report("invalid accelerator %s", *tmp);
2267 }
2268 }
2269 g_strfreev(accel_list);
2270 } else {
2271 if (accelerators != NULL) {
2272 error_report("The -accel and \"-machine accel=\" options are incompatible");
2273 exit(1);
2274 }
2275 }
2276
2277 if (!qemu_opts_foreach(qemu_find_opts("accel"),
2278 do_configure_accelerator, &init_failed, &error_fatal)) {
2279 if (!init_failed) {
2280 error_report("no accelerator found");
2281 }
2282 exit(1);
2283 }
2284
2285 if (init_failed && !qtest_chrdev) {
2286 AccelClass *ac = ACCEL_GET_CLASS(current_accel());
2287 error_report("falling back to %s", ac->name);
2288 }
2289
2290 if (icount_enabled() && !tcg_enabled()) {
2291 error_report("-icount is not allowed with hardware virtualization");
2292 exit(1);
2293 }
2294 }
2295
2296 static void create_default_memdev(MachineState *ms, const char *path)
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) {
2303 object_property_set_str(obj, "mem-path", path, &error_fatal);
2304 }
2305 object_property_set_int(obj, "size", ms->ram_size, &error_fatal);
2306 object_property_add_child(object_get_objects_root(), mc->default_ram_id,
2307 obj);
2308 /* Ensure backend's memory region name is equal to mc->default_ram_id */
2309 object_property_set_bool(obj, "x-use-canonical-path-for-ramblock-id",
2310 false, &error_fatal);
2311 user_creatable_complete(USER_CREATABLE(obj), &error_fatal);
2312 object_unref(obj);
2313 object_property_set_str(OBJECT(ms), "memory-backend", mc->default_ram_id,
2314 &error_fatal);
2315 }
2316
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
2336 if (loadvm && preconfig_requested) {
2337 error_report("'preconfig' and 'loadvm' options are "
2338 "mutually exclusive");
2339 exit(EXIT_FAILURE);
2340 }
2341 if (incoming && preconfig_requested && strcmp(incoming, "defer") != 0) {
2342 error_report("'preconfig' supports '-incoming defer' only");
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
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));
2361 object_register_sugar_prop("memory-backend", "prealloc-threads", val,
2362 false);
2363 g_free(val);
2364 object_register_sugar_prop("memory-backend", "prealloc", "on", false);
2365 }
2366
2367 if (watchdog) {
2368 int i = select_watchdog(watchdog);
2369 if (i > 0)
2370 exit (i == 1 ? 1 : 0);
2371 }
2372 }
2373
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
2394 static void qemu_process_early_options(void)
2395 {
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
2406 if (qemu_opts_foreach(qemu_find_opts("action"),
2407 process_runstate_actions, NULL, &error_fatal)) {
2408 exit(1);
2409 }
2410
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
2419 /* Open the logfile at this point and set the log mask if necessary. */
2420 if (log_file) {
2421 qemu_set_log_filename(log_file, &error_fatal);
2422 }
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
2435 qemu_add_default_firmwarepath();
2436 }
2437
2438 static void qemu_process_help_options(void)
2439 {
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) {
2458 qemu_list_data_dirs();
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
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
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
2510 /* process plugin before CPUs are created, but once -smp has been parsed */
2511 qemu_plugin_load_list(&plugin_list, &error_fatal);
2512
2513 /* From here on we enter MACHINE_PHASE_INITIALIZED. */
2514 machine_run_board_init(current_machine);
2515
2516 /*
2517 * TODO To drop support for deprecated bogus if=..., move
2518 * drive_check_orphaned() here, replacing this call. Also drop
2519 * its deprecation warning, along with DriveInfo member
2520 * @claimed_by_board.
2521 */
2522 drive_mark_claimed_by_board();
2523
2524 realtime_init();
2525
2526 if (hax_enabled()) {
2527 /* FIXME: why isn't cpu_synchronize_all_post_init enough? */
2528 hax_sync_vcpus();
2529 }
2530 }
2531
2532 static void qemu_create_cli_devices(void)
2533 {
2534 soundhw_init();
2535
2536 qemu_opts_foreach(qemu_find_opts("fw_cfg"),
2537 parse_fw_cfg, fw_cfg_find(), &error_fatal);
2538
2539 /* init USB devices */
2540 if (machine_usb(current_machine)) {
2541 if (foreach_device_config(DEV_USB, usb_parse) < 0)
2542 exit(1);
2543 }
2544
2545 /* init generic devices */
2546 rom_set_order_override(FW_CFG_ORDER_OVERRIDE_DEVICE);
2547 qemu_opts_foreach(qemu_find_opts("device"),
2548 device_init_func, NULL, &error_fatal);
2549 rom_reset_order_override();
2550 }
2551
2552 static void qemu_machine_creation_done(void)
2553 {
2554 MachineState *machine = MACHINE(qdev_get_machine());
2555
2556 /* Did we create any drives that we failed to create a device for? */
2557 drive_check_orphaned();
2558
2559 /* Don't warn about the default network setup that you get if
2560 * no command line -net or -netdev options are specified. There
2561 * are two cases that we would otherwise complain about:
2562 * (1) board doesn't support a NIC but the implicit "-net nic"
2563 * requested one
2564 * (2) CONFIG_SLIRP not set, in which case the implicit "-net nic"
2565 * sets up a nic that isn't connected to anything.
2566 */
2567 if (!default_net && (!qtest_enabled() || has_defaults)) {
2568 net_check_clients();
2569 }
2570
2571 qdev_prop_check_globals();
2572
2573 qdev_machine_creation_done();
2574
2575 if (machine->cgs) {
2576 /*
2577 * Verify that Confidential Guest Support has actually been initialized
2578 */
2579 assert(machine->cgs->ready);
2580 }
2581
2582 if (foreach_device_config(DEV_GDB, gdbserver_start) < 0) {
2583 exit(1);
2584 }
2585 }
2586
2587 void qmp_x_exit_preconfig(Error **errp)
2588 {
2589 if (phase_check(PHASE_MACHINE_INITIALIZED)) {
2590 error_setg(errp, "The command is permitted only before machine initialization");
2591 return;
2592 }
2593
2594 qemu_init_board();
2595 qemu_create_cli_devices();
2596 qemu_machine_creation_done();
2597
2598 if (loadvm) {
2599 Error *local_err = NULL;
2600 if (!load_snapshot(loadvm, NULL, false, NULL, &local_err)) {
2601 error_report_err(local_err);
2602 autostart = 0;
2603 exit(1);
2604 }
2605 }
2606 if (replay_mode != REPLAY_MODE_NONE) {
2607 replay_vmstate_init();
2608 }
2609
2610 if (incoming) {
2611 Error *local_err = NULL;
2612 if (strcmp(incoming, "defer") != 0) {
2613 qmp_migrate_incoming(incoming, &local_err);
2614 if (local_err) {
2615 error_reportf_err(local_err, "-incoming %s: ", incoming);
2616 exit(1);
2617 }
2618 }
2619 } else if (autostart) {
2620 qmp_cont(NULL);
2621 }
2622 }
2623
2624 void qemu_init(int argc, char **argv, char **envp)
2625 {
2626 QemuOpts *opts;
2627 QemuOpts *icount_opts = NULL, *accel_opts = NULL;
2628 QemuOptsList *olist;
2629 int optind;
2630 const char *optarg;
2631 MachineClass *machine_class;
2632 bool userconfig = true;
2633 FILE *vmstate_dump_file = NULL;
2634
2635 qemu_add_opts(&qemu_drive_opts);
2636 qemu_add_drive_opts(&qemu_legacy_drive_opts);
2637 qemu_add_drive_opts(&qemu_common_drive_opts);
2638 qemu_add_drive_opts(&qemu_drive_opts);
2639 qemu_add_drive_opts(&bdrv_runtime_opts);
2640 qemu_add_opts(&qemu_chardev_opts);
2641 qemu_add_opts(&qemu_device_opts);
2642 qemu_add_opts(&qemu_netdev_opts);
2643 qemu_add_opts(&qemu_nic_opts);
2644 qemu_add_opts(&qemu_net_opts);
2645 qemu_add_opts(&qemu_rtc_opts);
2646 qemu_add_opts(&qemu_global_opts);
2647 qemu_add_opts(&qemu_mon_opts);
2648 qemu_add_opts(&qemu_trace_opts);
2649 qemu_plugin_add_opts();
2650 qemu_add_opts(&qemu_option_rom_opts);
2651 qemu_add_opts(&qemu_machine_opts);
2652 qemu_add_opts(&qemu_accel_opts);
2653 qemu_add_opts(&qemu_mem_opts);
2654 qemu_add_opts(&qemu_smp_opts);
2655 qemu_add_opts(&qemu_boot_opts);
2656 qemu_add_opts(&qemu_add_fd_opts);
2657 qemu_add_opts(&qemu_object_opts);
2658 qemu_add_opts(&qemu_tpmdev_opts);
2659 qemu_add_opts(&qemu_overcommit_opts);
2660 qemu_add_opts(&qemu_msg_opts);
2661 qemu_add_opts(&qemu_name_opts);
2662 qemu_add_opts(&qemu_numa_opts);
2663 qemu_add_opts(&qemu_icount_opts);
2664 qemu_add_opts(&qemu_semihosting_config_opts);
2665 qemu_add_opts(&qemu_fw_cfg_opts);
2666 qemu_add_opts(&qemu_action_opts);
2667 module_call_init(MODULE_INIT_OPTS);
2668
2669 error_init(argv[0]);
2670 qemu_init_exec_dir(argv[0]);
2671
2672 qemu_init_subsystems();
2673
2674 /* first pass of option parsing */
2675 optind = 1;
2676 while (optind < argc) {
2677 if (argv[optind][0] != '-') {
2678 /* disk image */
2679 optind++;
2680 } else {
2681 const QEMUOption *popt;
2682
2683 popt = lookup_opt(argc, argv, &optarg, &optind);
2684 switch (popt->index) {
2685 case QEMU_OPTION_nouserconfig:
2686 userconfig = false;
2687 break;
2688 }
2689 }
2690 }
2691
2692 if (userconfig) {
2693 qemu_read_default_config_file(&error_fatal);
2694 }
2695
2696 /* second pass of option parsing */
2697 optind = 1;
2698 for(;;) {
2699 if (optind >= argc)
2700 break;
2701 if (argv[optind][0] != '-') {
2702 loc_set_cmdline(argv, optind, 1);
2703 drive_add(IF_DEFAULT, 0, argv[optind++], HD_OPTS);
2704 } else {
2705 const QEMUOption *popt;
2706
2707 popt = lookup_opt(argc, argv, &optarg, &optind);
2708 if (!(popt->arch_mask & arch_type)) {
2709 error_report("Option not supported for this target");
2710 exit(1);
2711 }
2712 switch(popt->index) {
2713 case QEMU_OPTION_cpu:
2714 /* hw initialization will check this */
2715 cpu_option = optarg;
2716 break;
2717 case QEMU_OPTION_hda:
2718 case QEMU_OPTION_hdb:
2719 case QEMU_OPTION_hdc:
2720 case QEMU_OPTION_hdd:
2721 drive_add(IF_DEFAULT, popt->index - QEMU_OPTION_hda, optarg,
2722 HD_OPTS);
2723 break;
2724 case QEMU_OPTION_blockdev:
2725 {
2726 Visitor *v;
2727 BlockdevOptionsQueueEntry *bdo;
2728
2729 v = qobject_input_visitor_new_str(optarg, "driver",
2730 &error_fatal);
2731
2732 bdo = g_new(BlockdevOptionsQueueEntry, 1);
2733 visit_type_BlockdevOptions(v, NULL, &bdo->bdo,
2734 &error_fatal);
2735 visit_free(v);
2736 loc_save(&bdo->loc);
2737 QSIMPLEQ_INSERT_TAIL(&bdo_queue, bdo, entry);
2738 break;
2739 }
2740 case QEMU_OPTION_drive:
2741 if (drive_def(optarg) == NULL) {
2742 exit(1);
2743 }
2744 break;
2745 case QEMU_OPTION_set:
2746 if (qemu_set_option(optarg) != 0)
2747 exit(1);
2748 break;
2749 case QEMU_OPTION_global:
2750 if (qemu_global_option(optarg) != 0)
2751 exit(1);
2752 break;
2753 case QEMU_OPTION_mtdblock:
2754 drive_add(IF_MTD, -1, optarg, MTD_OPTS);
2755 break;
2756 case QEMU_OPTION_sd:
2757 drive_add(IF_SD, -1, optarg, SD_OPTS);
2758 break;
2759 case QEMU_OPTION_pflash:
2760 drive_add(IF_PFLASH, -1, optarg, PFLASH_OPTS);
2761 break;
2762 case QEMU_OPTION_snapshot:
2763 {
2764 Error *blocker = NULL;
2765 snapshot = 1;
2766 error_setg(&blocker, QERR_REPLAY_NOT_SUPPORTED,
2767 "-snapshot");
2768 replay_add_blocker(blocker);
2769 }
2770 break;
2771 case QEMU_OPTION_numa:
2772 opts = qemu_opts_parse_noisily(qemu_find_opts("numa"),
2773 optarg, true);
2774 if (!opts) {
2775 exit(1);
2776 }
2777 break;
2778 case QEMU_OPTION_display:
2779 parse_display(optarg);
2780 break;
2781 case QEMU_OPTION_nographic:
2782 olist = qemu_find_opts("machine");
2783 qemu_opts_parse_noisily(olist, "graphics=off", false);
2784 nographic = true;
2785 dpy.type = DISPLAY_TYPE_NONE;
2786 break;
2787 case QEMU_OPTION_curses:
2788 #ifdef CONFIG_CURSES
2789 dpy.type = DISPLAY_TYPE_CURSES;
2790 #else
2791 error_report("curses or iconv support is disabled");
2792 exit(1);
2793 #endif
2794 break;
2795 case QEMU_OPTION_portrait:
2796 graphic_rotate = 90;
2797 break;
2798 case QEMU_OPTION_rotate:
2799 graphic_rotate = strtol(optarg, (char **) &optarg, 10);
2800 if (graphic_rotate != 0 && graphic_rotate != 90 &&
2801 graphic_rotate != 180 && graphic_rotate != 270) {
2802 error_report("only 90, 180, 270 deg rotation is available");
2803 exit(1);
2804 }
2805 break;
2806 case QEMU_OPTION_kernel:
2807 qemu_opts_set(qemu_find_opts("machine"), "kernel", optarg, &error_abort);
2808 break;
2809 case QEMU_OPTION_initrd:
2810 qemu_opts_set(qemu_find_opts("machine"), "initrd", optarg, &error_abort);
2811 break;
2812 case QEMU_OPTION_append:
2813 qemu_opts_set(qemu_find_opts("machine"), "append", optarg, &error_abort);
2814 break;
2815 case QEMU_OPTION_dtb:
2816 qemu_opts_set(qemu_find_opts("machine"), "dtb", optarg, &error_abort);
2817 break;
2818 case QEMU_OPTION_cdrom:
2819 drive_add(IF_DEFAULT, 2, optarg, CDROM_OPTS);
2820 break;
2821 case QEMU_OPTION_boot:
2822 opts = qemu_opts_parse_noisily(qemu_find_opts("boot-opts"),
2823 optarg, true);
2824 if (!opts) {
2825 exit(1);
2826 }
2827 break;
2828 case QEMU_OPTION_fda:
2829 case QEMU_OPTION_fdb:
2830 drive_add(IF_FLOPPY, popt->index - QEMU_OPTION_fda,
2831 optarg, FD_OPTS);
2832 break;
2833 case QEMU_OPTION_no_fd_bootchk:
2834 fd_bootchk = 0;
2835 break;
2836 case QEMU_OPTION_netdev:
2837 default_net = 0;
2838 if (net_client_parse(qemu_find_opts("netdev"), optarg) == -1) {
2839 exit(1);
2840 }
2841 break;
2842 case QEMU_OPTION_nic:
2843 default_net = 0;
2844 if (net_client_parse(qemu_find_opts("nic"), optarg) == -1) {
2845 exit(1);
2846 }
2847 break;
2848 case QEMU_OPTION_net:
2849 default_net = 0;
2850 if (net_client_parse(qemu_find_opts("net"), optarg) == -1) {
2851 exit(1);
2852 }
2853 break;
2854 #ifdef CONFIG_LIBISCSI
2855 case QEMU_OPTION_iscsi:
2856 opts = qemu_opts_parse_noisily(qemu_find_opts("iscsi"),
2857 optarg, false);
2858 if (!opts) {
2859 exit(1);
2860 }
2861 break;
2862 #endif
2863 case QEMU_OPTION_audio_help:
2864 audio_legacy_help();
2865 exit (0);
2866 break;
2867 case QEMU_OPTION_audiodev:
2868 audio_parse_option(optarg);
2869 break;
2870 case QEMU_OPTION_soundhw:
2871 select_soundhw (optarg);
2872 break;
2873 case QEMU_OPTION_h:
2874 help(0);
2875 break;
2876 case QEMU_OPTION_version:
2877 version();
2878 exit(0);
2879 break;
2880 case QEMU_OPTION_m:
2881 opts = qemu_opts_parse_noisily(qemu_find_opts("memory"),
2882 optarg, true);
2883 if (!opts) {
2884 exit(EXIT_FAILURE);
2885 }
2886 break;
2887 #ifdef CONFIG_TPM
2888 case QEMU_OPTION_tpmdev:
2889 if (tpm_config_parse(qemu_find_opts("tpmdev"), optarg) < 0) {
2890 exit(1);
2891 }
2892 break;
2893 #endif
2894 case QEMU_OPTION_mempath:
2895 mem_path = optarg;
2896 break;
2897 case QEMU_OPTION_mem_prealloc:
2898 mem_prealloc = 1;
2899 break;
2900 case QEMU_OPTION_d:
2901 log_mask = optarg;
2902 break;
2903 case QEMU_OPTION_D:
2904 log_file = optarg;
2905 break;
2906 case QEMU_OPTION_DFILTER:
2907 qemu_set_dfilter_ranges(optarg, &error_fatal);
2908 break;
2909 case QEMU_OPTION_seed:
2910 qemu_guest_random_seed_main(optarg, &error_fatal);
2911 break;
2912 case QEMU_OPTION_s:
2913 add_device_config(DEV_GDB, "tcp::" DEFAULT_GDBSTUB_PORT);
2914 break;
2915 case QEMU_OPTION_gdb:
2916 add_device_config(DEV_GDB, optarg);
2917 break;
2918 case QEMU_OPTION_L:
2919 if (is_help_option(optarg)) {
2920 list_data_dirs = true;
2921 } else {
2922 qemu_add_data_dir(g_strdup(optarg));
2923 }
2924 break;
2925 case QEMU_OPTION_bios:
2926 qemu_opts_set(qemu_find_opts("machine"), "firmware", optarg, &error_abort);
2927 break;
2928 case QEMU_OPTION_singlestep:
2929 singlestep = 1;
2930 break;
2931 case QEMU_OPTION_S:
2932 autostart = 0;
2933 break;
2934 case QEMU_OPTION_k:
2935 keyboard_layout = optarg;
2936 break;
2937 case QEMU_OPTION_vga:
2938 vga_model = optarg;
2939 default_vga = 0;
2940 break;
2941 case QEMU_OPTION_g:
2942 {
2943 const char *p;
2944 int w, h, depth;
2945 p = optarg;
2946 w = strtol(p, (char **)&p, 10);
2947 if (w <= 0) {
2948 graphic_error:
2949 error_report("invalid resolution or depth");
2950 exit(1);
2951 }
2952 if (*p != 'x')
2953 goto graphic_error;
2954 p++;
2955 h = strtol(p, (char **)&p, 10);
2956 if (h <= 0)
2957 goto graphic_error;
2958 if (*p == 'x') {
2959 p++;
2960 depth = strtol(p, (char **)&p, 10);
2961 if (depth != 1 && depth != 2 && depth != 4 &&
2962 depth != 8 && depth != 15 && depth != 16 &&
2963 depth != 24 && depth != 32)
2964 goto graphic_error;
2965 } else if (*p == '\0') {
2966 depth = graphic_depth;
2967 } else {
2968 goto graphic_error;
2969 }
2970
2971 graphic_width = w;
2972 graphic_height = h;
2973 graphic_depth = depth;
2974 }
2975 break;
2976 case QEMU_OPTION_echr:
2977 {
2978 char *r;
2979 term_escape_char = strtol(optarg, &r, 0);
2980 if (r == optarg)
2981 printf("Bad argument to echr\n");
2982 break;
2983 }
2984 case QEMU_OPTION_monitor:
2985 default_monitor = 0;
2986 if (strncmp(optarg, "none", 4)) {
2987 monitor_parse(optarg, "readline", false);
2988 }
2989 break;
2990 case QEMU_OPTION_qmp:
2991 monitor_parse(optarg, "control", false);
2992 default_monitor = 0;
2993 break;
2994 case QEMU_OPTION_qmp_pretty:
2995 monitor_parse(optarg, "control", true);
2996 default_monitor = 0;
2997 break;
2998 case QEMU_OPTION_mon:
2999 opts = qemu_opts_parse_noisily(qemu_find_opts("mon"), optarg,
3000 true);
3001 if (!opts) {
3002 exit(1);
3003 }
3004 default_monitor = 0;
3005 break;
3006 case QEMU_OPTION_chardev:
3007 opts = qemu_opts_parse_noisily(qemu_find_opts("chardev"),
3008 optarg, true);
3009 if (!opts) {
3010 exit(1);
3011 }
3012 break;
3013 case QEMU_OPTION_fsdev:
3014 olist = qemu_find_opts("fsdev");
3015 if (!olist) {
3016 error_report("fsdev support is disabled");
3017 exit(1);
3018 }
3019 opts = qemu_opts_parse_noisily(olist, optarg, true);
3020 if (!opts) {
3021 exit(1);
3022 }
3023 break;
3024 case QEMU_OPTION_virtfs: {
3025 QemuOpts *fsdev;
3026 QemuOpts *device;
3027 const char *writeout, *sock_fd, *socket, *path, *security_model,
3028 *multidevs;
3029
3030 olist = qemu_find_opts("virtfs");
3031 if (!olist) {
3032 error_report("virtfs support is disabled");
3033 exit(1);
3034 }
3035 opts = qemu_opts_parse_noisily(olist, optarg, true);
3036 if (!opts) {
3037 exit(1);
3038 }
3039
3040 if (qemu_opt_get(opts, "fsdriver") == NULL ||
3041 qemu_opt_get(opts, "mount_tag") == NULL) {
3042 error_report("Usage: -virtfs fsdriver,mount_tag=tag");
3043 exit(1);
3044 }
3045 fsdev = qemu_opts_create(qemu_find_opts("fsdev"),
3046 qemu_opts_id(opts) ?:
3047 qemu_opt_get(opts, "mount_tag"),
3048 1, NULL);
3049 if (!fsdev) {
3050 error_report("duplicate or invalid fsdev id: %s",
3051 qemu_opt_get(opts, "mount_tag"));
3052 exit(1);
3053 }
3054
3055 writeout = qemu_opt_get(opts, "writeout");
3056 if (writeout) {
3057 #ifdef CONFIG_SYNC_FILE_RANGE
3058 qemu_opt_set(fsdev, "writeout", writeout, &error_abort);
3059 #else
3060 error_report("writeout=immediate not supported "
3061 "on this platform");
3062 exit(1);
3063 #endif
3064 }
3065 qemu_opt_set(fsdev, "fsdriver",
3066 qemu_opt_get(opts, "fsdriver"), &error_abort);
3067 path = qemu_opt_get(opts, "path");
3068 if (path) {
3069 qemu_opt_set(fsdev, "path", path, &error_abort);
3070 }
3071 security_model = qemu_opt_get(opts, "security_model");
3072 if (security_model) {
3073 qemu_opt_set(fsdev, "security_model", security_model,
3074 &error_abort);
3075 }
3076 socket = qemu_opt_get(opts, "socket");
3077 if (socket) {
3078 qemu_opt_set(fsdev, "socket", socket, &error_abort);
3079 }
3080 sock_fd = qemu_opt_get(opts, "sock_fd");
3081 if (sock_fd) {
3082 qemu_opt_set(fsdev, "sock_fd", sock_fd, &error_abort);
3083 }
3084
3085 qemu_opt_set_bool(fsdev, "readonly",
3086 qemu_opt_get_bool(opts, "readonly", 0),
3087 &error_abort);
3088 multidevs = qemu_opt_get(opts, "multidevs");
3089 if (multidevs) {
3090 qemu_opt_set(fsdev, "multidevs", multidevs, &error_abort);
3091 }
3092 device = qemu_opts_create(qemu_find_opts("device"), NULL, 0,
3093 &error_abort);
3094 qemu_opt_set(device, "driver", "virtio-9p-pci", &error_abort);
3095 qemu_opt_set(device, "fsdev",
3096 qemu_opts_id(fsdev), &error_abort);
3097 qemu_opt_set(device, "mount_tag",
3098 qemu_opt_get(opts, "mount_tag"), &error_abort);
3099 break;
3100 }
3101 case QEMU_OPTION_serial:
3102 add_device_config(DEV_SERIAL, optarg);
3103 default_serial = 0;
3104 if (strncmp(optarg, "mon:", 4) == 0) {
3105 default_monitor = 0;
3106 }
3107 break;
3108 case QEMU_OPTION_watchdog:
3109 if (watchdog) {
3110 error_report("only one watchdog option may be given");
3111 exit(1);
3112 }
3113 watchdog = optarg;
3114 break;
3115 case QEMU_OPTION_action:
3116 olist = qemu_find_opts("action");
3117 if (!qemu_opts_parse_noisily(olist, optarg, false)) {
3118 exit(1);
3119 }
3120 break;
3121 case QEMU_OPTION_watchdog_action:
3122 if (select_watchdog_action(optarg) == -1) {
3123 error_report("unknown -watchdog-action parameter");
3124 exit(1);
3125 }
3126 break;
3127 case QEMU_OPTION_parallel:
3128 add_device_config(DEV_PARALLEL, optarg);
3129 default_parallel = 0;
3130 if (strncmp(optarg, "mon:", 4) == 0) {
3131 default_monitor = 0;
3132 }
3133 break;
3134 case QEMU_OPTION_debugcon:
3135 add_device_config(DEV_DEBUGCON, optarg);
3136 break;
3137 case QEMU_OPTION_loadvm:
3138 loadvm = optarg;
3139 break;
3140 case QEMU_OPTION_full_screen:
3141 dpy.has_full_screen = true;
3142 dpy.full_screen = true;
3143 break;
3144 case QEMU_OPTION_alt_grab:
3145 alt_grab = 1;
3146 break;
3147 case QEMU_OPTION_ctrl_grab:
3148 ctrl_grab = 1;
3149 break;
3150 case QEMU_OPTION_no_quit:
3151 dpy.has_window_close = true;
3152 dpy.window_close = false;
3153 break;
3154 case QEMU_OPTION_sdl:
3155 #ifdef CONFIG_SDL
3156 dpy.type = DISPLAY_TYPE_SDL;
3157 break;
3158 #else
3159 error_report("SDL support is disabled");
3160 exit(1);
3161 #endif
3162 case QEMU_OPTION_pidfile:
3163 pid_file = optarg;
3164 break;
3165 case QEMU_OPTION_win2k_hack:
3166 win2k_install_hack = 1;
3167 break;
3168 case QEMU_OPTION_acpitable:
3169 opts = qemu_opts_parse_noisily(qemu_find_opts("acpi"),
3170 optarg, true);
3171 if (!opts) {
3172 exit(1);
3173 }
3174 acpi_table_add(opts, &error_fatal);
3175 break;
3176 case QEMU_OPTION_smbios:
3177 opts = qemu_opts_parse_noisily(qemu_find_opts("smbios"),
3178 optarg, false);
3179 if (!opts) {
3180 exit(1);
3181 }
3182 smbios_entry_add(opts, &error_fatal);
3183 break;
3184 case QEMU_OPTION_fwcfg:
3185 opts = qemu_opts_parse_noisily(qemu_find_opts("fw_cfg"),
3186 optarg, true);
3187 if (opts == NULL) {
3188 exit(1);
3189 }
3190 break;
3191 case QEMU_OPTION_preconfig:
3192 preconfig_requested = true;
3193 break;
3194 case QEMU_OPTION_enable_kvm:
3195 olist = qemu_find_opts("machine");
3196 qemu_opts_parse_noisily(olist, "accel=kvm", false);
3197 break;
3198 case QEMU_OPTION_M:
3199 case QEMU_OPTION_machine:
3200 olist = qemu_find_opts("machine");
3201 opts = qemu_opts_parse_noisily(olist, optarg, true);
3202 if (!opts) {
3203 exit(1);
3204 }
3205 break;
3206 case QEMU_OPTION_accel:
3207 accel_opts = qemu_opts_parse_noisily(qemu_find_opts("accel"),
3208 optarg, true);
3209 optarg = qemu_opt_get(accel_opts, "accel");
3210 if (!optarg || is_help_option(optarg)) {
3211 printf("Accelerators supported in QEMU binary:\n");
3212 GSList *el, *accel_list = object_class_get_list(TYPE_ACCEL,
3213 false);
3214 for (el = accel_list; el; el = el->next) {
3215 gchar *typename = g_strdup(object_class_get_name(
3216 OBJECT_CLASS(el->data)));
3217 /* omit qtest which is used for tests only */
3218 if (g_strcmp0(typename, ACCEL_CLASS_NAME("qtest")) &&
3219 g_str_has_suffix(typename, ACCEL_CLASS_SUFFIX)) {
3220 gchar **optname = g_strsplit(typename,
3221 ACCEL_CLASS_SUFFIX, 0);
3222 printf("%s\n", optname[0]);
3223 g_strfreev(optname);
3224 }
3225 g_free(typename);
3226 }
3227 g_slist_free(accel_list);
3228 exit(0);
3229 }
3230 break;
3231 case QEMU_OPTION_usb:
3232 olist = qemu_find_opts("machine");
3233 qemu_opts_parse_noisily(olist, "usb=on", false);
3234 break;
3235 case QEMU_OPTION_usbdevice:
3236 olist = qemu_find_opts("machine");
3237 qemu_opts_parse_noisily(olist, "usb=on", false);
3238 add_device_config(DEV_USB, optarg);
3239 break;
3240 case QEMU_OPTION_device:
3241 if (!qemu_opts_parse_noisily(qemu_find_opts("device"),
3242 optarg, true)) {
3243 exit(1);
3244 }
3245 break;
3246 case QEMU_OPTION_smp:
3247 if (!qemu_opts_parse_noisily(qemu_find_opts("smp-opts"),
3248 optarg, true)) {
3249 exit(1);
3250 }
3251 break;
3252 case QEMU_OPTION_vnc:
3253 vnc_parse(optarg);
3254 break;
3255 case QEMU_OPTION_no_acpi:
3256 olist = qemu_find_opts("machine");
3257 qemu_opts_parse_noisily(olist, "acpi=off", false);
3258 break;
3259 case QEMU_OPTION_no_hpet:
3260 olist = qemu_find_opts("machine");
3261 qemu_opts_parse_noisily(olist, "hpet=off", false);
3262 break;
3263 case QEMU_OPTION_no_reboot:
3264 olist = qemu_find_opts("action");
3265 qemu_opts_parse_noisily(olist, "reboot=shutdown", false);
3266 break;
3267 case QEMU_OPTION_no_shutdown:
3268 olist = qemu_find_opts("action");
3269 qemu_opts_parse_noisily(olist, "shutdown=pause", false);
3270 break;
3271 case QEMU_OPTION_uuid:
3272 if (qemu_uuid_parse(optarg, &qemu_uuid) < 0) {
3273 error_report("failed to parse UUID string: wrong format");
3274 exit(1);
3275 }
3276 qemu_uuid_set = true;
3277 break;
3278 case QEMU_OPTION_option_rom:
3279 if (nb_option_roms >= MAX_OPTION_ROMS) {
3280 error_report("too many option ROMs");
3281 exit(1);
3282 }
3283 opts = qemu_opts_parse_noisily(qemu_find_opts("option-rom"),
3284 optarg, true);
3285 if (!opts) {
3286 exit(1);
3287 }
3288 option_rom[nb_option_roms].name = qemu_opt_get(opts, "romfile");
3289 option_rom[nb_option_roms].bootindex =
3290 qemu_opt_get_number(opts, "bootindex", -1);
3291 if (!option_rom[nb_option_roms].name) {
3292 error_report("Option ROM file is not specified");
3293 exit(1);
3294 }
3295 nb_option_roms++;
3296 break;
3297 case QEMU_OPTION_semihosting:
3298 qemu_semihosting_enable();
3299 break;
3300 case QEMU_OPTION_semihosting_config:
3301 if (qemu_semihosting_config_options(optarg) != 0) {
3302 exit(1);
3303 }
3304 break;
3305 case QEMU_OPTION_name:
3306 opts = qemu_opts_parse_noisily(qemu_find_opts("name"),
3307 optarg, true);
3308 if (!opts) {
3309 exit(1);
3310 }
3311 /* Capture guest name if -msg guest-name is used later */
3312 error_guest_name = qemu_opt_get(opts, "guest");
3313 break;
3314 case QEMU_OPTION_prom_env:
3315 if (nb_prom_envs >= MAX_PROM_ENVS) {
3316 error_report("too many prom variables");
3317 exit(1);
3318 }
3319 prom_envs[nb_prom_envs] = optarg;
3320 nb_prom_envs++;
3321 break;
3322 case QEMU_OPTION_old_param:
3323 old_param = 1;
3324 break;
3325 case QEMU_OPTION_rtc:
3326 opts = qemu_opts_parse_noisily(qemu_find_opts("rtc"), optarg,
3327 false);
3328 if (!opts) {
3329 exit(1);
3330 }
3331 break;
3332 case QEMU_OPTION_icount:
3333 icount_opts = qemu_opts_parse_noisily(qemu_find_opts("icount"),
3334 optarg, true);
3335 if (!icount_opts) {
3336 exit(1);
3337 }
3338 break;
3339 case QEMU_OPTION_incoming:
3340 if (!incoming) {
3341 runstate_set(RUN_STATE_INMIGRATE);
3342 }
3343 incoming = optarg;
3344 break;
3345 case QEMU_OPTION_only_migratable:
3346 only_migratable = 1;
3347 break;
3348 case QEMU_OPTION_nodefaults:
3349 has_defaults = 0;
3350 break;
3351 case QEMU_OPTION_xen_domid:
3352 if (!(xen_available())) {
3353 error_report("Option not supported for this target");
3354 exit(1);
3355 }
3356 xen_domid = atoi(optarg);
3357 break;
3358 case QEMU_OPTION_xen_attach:
3359 if (!(xen_available())) {
3360 error_report("Option not supported for this target");
3361 exit(1);
3362 }
3363 xen_mode = XEN_ATTACH;
3364 break;
3365 case QEMU_OPTION_xen_domid_restrict:
3366 if (!(xen_available())) {
3367 error_report("Option not supported for this target");
3368 exit(1);
3369 }
3370 xen_domid_restrict = true;
3371 break;
3372 case QEMU_OPTION_trace:
3373 trace_opt_parse(optarg);
3374 break;
3375 case QEMU_OPTION_plugin:
3376 qemu_plugin_opt_parse(optarg, &plugin_list);
3377 break;
3378 case QEMU_OPTION_readconfig:
3379 qemu_read_config_file(optarg, &error_fatal);
3380 break;
3381 case QEMU_OPTION_spice:
3382 olist = qemu_find_opts_err("spice", NULL);
3383 if (!olist) {
3384 ui_module_load_one("spice-core");
3385 olist = qemu_find_opts("spice");
3386 }
3387 if (!olist) {
3388 error_report("spice support is disabled");
3389 exit(1);
3390 }
3391 opts = qemu_opts_parse_noisily(olist, optarg, false);
3392 if (!opts) {
3393 exit(1);
3394 }
3395 display_remote++;
3396 break;
3397 case QEMU_OPTION_writeconfig:
3398 {
3399 FILE *fp;
3400 warn_report("-writeconfig is deprecated and will go away without a replacement");
3401 if (strcmp(optarg, "-") == 0) {
3402 fp = stdout;
3403 } else {
3404 fp = fopen(optarg, "w");
3405 if (fp == NULL) {
3406 error_report("open %s: %s", optarg,
3407 strerror(errno));
3408 exit(1);
3409 }
3410 }
3411 qemu_config_write(fp);
3412 if (fp != stdout) {
3413 fclose(fp);
3414 }
3415 break;
3416 }
3417 case QEMU_OPTION_qtest:
3418 qtest_chrdev = optarg;
3419 break;
3420 case QEMU_OPTION_qtest_log:
3421 qtest_log = optarg;
3422 break;
3423 case QEMU_OPTION_sandbox:
3424 olist = qemu_find_opts("sandbox");
3425 if (!olist) {
3426 #ifndef CONFIG_SECCOMP
3427 error_report("-sandbox support is not enabled "
3428 "in this QEMU binary");
3429 #endif
3430 exit(1);
3431 }
3432
3433 opts = qemu_opts_parse_noisily(olist, optarg, true);
3434 if (!opts) {
3435 exit(1);
3436 }
3437 break;
3438 case QEMU_OPTION_add_fd:
3439 #ifndef _WIN32
3440 opts = qemu_opts_parse_noisily(qemu_find_opts("add-fd"),
3441 optarg, false);
3442 if (!opts) {
3443 exit(1);
3444 }
3445 #else
3446 error_report("File descriptor passing is disabled on this "
3447 "platform");
3448 exit(1);
3449 #endif
3450 break;
3451 case QEMU_OPTION_object:
3452 object_option_parse(optarg);
3453 break;
3454 case QEMU_OPTION_overcommit:
3455 opts = qemu_opts_parse_noisily(qemu_find_opts("overcommit"),
3456 optarg, false);
3457 if (!opts) {
3458 exit(1);
3459 }
3460 enable_mlock = qemu_opt_get_bool(opts, "mem-lock", false);
3461 enable_cpu_pm = qemu_opt_get_bool(opts, "cpu-pm", false);
3462 break;
3463 case QEMU_OPTION_compat:
3464 {
3465 CompatPolicy *opts;
3466 Visitor *v;
3467
3468 v = qobject_input_visitor_new_str(optarg, NULL,
3469 &error_fatal);
3470
3471 visit_type_CompatPolicy(v, NULL, &opts, &error_fatal);
3472 QAPI_CLONE_MEMBERS(CompatPolicy, &compat_policy, opts);
3473
3474 qapi_free_CompatPolicy(opts);
3475 visit_free(v);
3476 break;
3477 }
3478 case QEMU_OPTION_msg:
3479 opts = qemu_opts_parse_noisily(qemu_find_opts("msg"), optarg,
3480 false);
3481 if (!opts) {
3482 exit(1);
3483 }
3484 configure_msg(opts);
3485 break;
3486 case QEMU_OPTION_dump_vmstate:
3487 if (vmstate_dump_file) {
3488 error_report("only one '-dump-vmstate' "
3489 "option may be given");
3490 exit(1);
3491 }
3492 vmstate_dump_file = fopen(optarg, "w");
3493 if (vmstate_dump_file == NULL) {
3494 error_report("open %s: %s", optarg, strerror(errno));
3495 exit(1);
3496 }
3497 break;
3498 case QEMU_OPTION_enable_sync_profile:
3499 qsp_enable();
3500 break;
3501 case QEMU_OPTION_nouserconfig:
3502 /* Nothing to be parsed here. Especially, do not error out below. */
3503 break;
3504 default:
3505 if (os_parse_cmd_args(popt->index, optarg)) {
3506 error_report("Option not supported in this build");
3507 exit(1);
3508 }
3509 }
3510 }
3511 }
3512 /*
3513 * Clear error location left behind by the loop.
3514 * Best done right after the loop. Do not insert code here!
3515 */
3516 loc_set_none();
3517
3518 qemu_validate_options();
3519 qemu_process_sugar_options();
3520
3521 /*
3522 * These options affect everything else and should be processed
3523 * before daemonizing.
3524 */
3525 qemu_process_early_options();
3526
3527 qemu_process_help_options();
3528 qemu_maybe_daemonize(pid_file);
3529
3530 /*
3531 * The trace backend must be initialized after daemonizing.
3532 * trace_init_backends() will call st_init(), which will create the
3533 * trace thread in the parent, and also register st_flush_trace_buffer()
3534 * in atexit(). This function will force the parent to wait for the
3535 * writeout thread to finish, which will not occur, and the parent
3536 * process will be left in the host.
3537 */
3538 if (!trace_init_backends()) {
3539 exit(1);
3540 }
3541 trace_init_file();
3542
3543 qemu_init_main_loop(&error_fatal);
3544 cpu_timers_init();
3545
3546 user_register_global_props();
3547 replay_configure(icount_opts);
3548
3549 configure_rtc(qemu_find_opts_singleton("rtc"));
3550
3551 qemu_create_machine(select_machine());
3552
3553 suspend_mux_open();
3554
3555 qemu_disable_default_devices();
3556 qemu_create_default_devices();
3557 qemu_create_early_backends();
3558
3559 qemu_apply_machine_options();
3560 phase_advance(PHASE_MACHINE_CREATED);
3561
3562 /*
3563 * Note: uses machine properties such as kernel-irqchip, must run
3564 * after machine_set_property().
3565 */
3566 configure_accelerators(argv[0]);
3567 phase_advance(PHASE_ACCEL_CREATED);
3568
3569 /*
3570 * Beware, QOM objects created before this point miss global and
3571 * compat properties.
3572 *
3573 * Global properties get set up by qdev_prop_register_global(),
3574 * called from user_register_global_props(), and certain option
3575 * desugaring. Also in CPU feature desugaring (buried in
3576 * parse_cpu_option()), which happens below this point, but may
3577 * only target the CPU type, which can only be created after
3578 * parse_cpu_option() returned the type.
3579 *
3580 * Machine compat properties: object_set_machine_compat_props().
3581 * Accelerator compat props: object_set_accelerator_compat_props(),
3582 * called from do_configure_accelerator().
3583 */
3584
3585 machine_class = MACHINE_GET_CLASS(current_machine);
3586 if (!qtest_enabled() && machine_class->deprecation_reason) {
3587 error_report("Machine type '%s' is deprecated: %s",
3588 machine_class->name, machine_class->deprecation_reason);
3589 }
3590
3591 /*
3592 * Note: creates a QOM object, must run only after global and
3593 * compat properties have been set up.
3594 */
3595 migration_object_init();
3596
3597 qemu_create_late_backends();
3598
3599 /* parse features once if machine provides default cpu_type */
3600 current_machine->cpu_type = machine_class->default_cpu_type;
3601 if (cpu_option) {
3602 current_machine->cpu_type = parse_cpu_option(cpu_option);
3603 }
3604 /* NB: for machine none cpu_type could STILL be NULL here! */
3605 accel_init_interfaces(ACCEL_GET_CLASS(current_machine->accelerator));
3606
3607 qemu_resolve_machine_memdev();
3608 parse_numa_opts(current_machine);
3609
3610 if (vmstate_dump_file) {
3611 /* dump and exit */
3612 dump_vmstate_json_to_file(vmstate_dump_file);
3613 exit(0);
3614 }
3615
3616 if (!preconfig_requested) {
3617 qmp_x_exit_preconfig(&error_fatal);
3618 }
3619 qemu_init_displays();
3620 accel_setup_post(current_machine);
3621 os_setup_post();
3622 resume_mux_open();
3623 }