4 * Copyright (c) 2003-2008 Fabrice Bellard
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:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
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
24 #include "qemu/osdep.h"
25 #include "qemu-version.h"
26 #include "qemu/cutils.h"
27 #include "qemu/help_option.h"
28 #include "qemu/uuid.h"
31 #include "sysemu/seccomp.h"
34 #if defined(CONFIG_VDE)
35 #include <libvdeplug.h>
39 #if defined(__APPLE__) || defined(main)
41 int qemu_main(int argc, char **argv, char **envp);
42 int main(int argc, char **argv)
44 return qemu_main(argc, argv, NULL);
47 #define main qemu_main
49 #endif /* CONFIG_SDL */
53 #define main qemu_main
54 #endif /* CONFIG_COCOA */
57 #include "qemu/error-report.h"
58 #include "qemu/sockets.h"
60 #include "hw/boards.h"
61 #include "sysemu/accel.h"
63 #include "hw/i386/pc.h"
64 #include "hw/isa/isa.h"
65 #include "hw/scsi/scsi.h"
67 #include "sysemu/watchdog.h"
68 #include "hw/smbios/smbios.h"
69 #include "hw/acpi/acpi.h"
70 #include "hw/xen/xen.h"
72 #include "hw/loader.h"
73 #include "monitor/qdev.h"
74 #include "sysemu/bt.h"
76 #include "net/slirp.h"
77 #include "monitor/monitor.h"
78 #include "ui/console.h"
80 #include "sysemu/sysemu.h"
81 #include "sysemu/numa.h"
82 #include "exec/gdbstub.h"
83 #include "qemu/timer.h"
84 #include "chardev/char.h"
85 #include "qemu/bitmap.h"
87 #include "sysemu/blockdev.h"
88 #include "hw/block/block.h"
89 #include "migration/misc.h"
90 #include "migration/snapshot.h"
91 #include "migration/global_state.h"
92 #include "sysemu/tpm.h"
93 #include "sysemu/dma.h"
94 #include "hw/audio/soundhw.h"
95 #include "audio/audio.h"
96 #include "sysemu/cpus.h"
97 #include "migration/colo.h"
98 #include "sysemu/kvm.h"
99 #include "sysemu/hax.h"
100 #include "qapi/qobject-input-visitor.h"
101 #include "qapi/qobject-input-visitor.h"
102 #include "qapi-visit.h"
103 #include "qapi/qmp/qjson.h"
104 #include "qemu/option.h"
105 #include "qemu/config-file.h"
106 #include "qemu-options.h"
107 #include "qmp-commands.h"
108 #include "qemu/main-loop.h"
110 #include "fsdev/qemu-fsdev.h"
112 #include "sysemu/qtest.h"
114 #include "disas/disas.h"
117 #include "slirp/libslirp.h"
119 #include "trace-root.h"
120 #include "trace/control.h"
121 #include "qemu/queue.h"
122 #include "sysemu/arch_init.h"
124 #include "ui/qemu-spice.h"
125 #include "qapi/string-input-visitor.h"
126 #include "qapi/opts-visitor.h"
127 #include "qom/object_interfaces.h"
128 #include "qapi-event.h"
129 #include "exec/semihost.h"
130 #include "crypto/init.h"
131 #include "sysemu/replay.h"
132 #include "qapi/qmp/qerror.h"
133 #include "sysemu/iothread.h"
135 #define MAX_VIRTIO_CONSOLES 1
136 #define MAX_SCLP_CONSOLES 1
138 static const char *data_dir[16];
139 static int data_dir_idx;
140 const char *bios_name = NULL;
141 enum vga_retrace_method vga_retrace_method = VGA_RETRACE_DUMB;
142 int request_opengl = -1;
144 const char* keyboard_layout = NULL;
146 const char *mem_path = NULL;
147 int mem_prealloc = 0; /* force preallocation of physical target memory */
148 bool enable_mlock = false;
150 NICInfo nd_table[MAX_NICS];
152 static int rtc_utc = 1;
153 static int rtc_date_offset = -1; /* -1 means no change */
154 QEMUClockType rtc_clock;
155 int vga_interface_type = VGA_NONE;
156 static int full_screen = 0;
157 static int no_frame = 0;
159 static bool grab_on_hover;
160 Chardev *serial_hds[MAX_SERIAL_PORTS];
161 Chardev *parallel_hds[MAX_PARALLEL_PORTS];
162 Chardev *virtcon_hds[MAX_VIRTIO_CONSOLES];
163 Chardev *sclp_hds[MAX_SCLP_CONSOLES];
164 int win2k_install_hack = 0;
170 int acpi_enabled = 1;
173 static int no_reboot;
176 int graphic_rotate = 0;
177 const char *watchdog;
178 QEMUOptionRom option_rom[MAX_OPTION_ROMS];
181 const char *qemu_name;
184 unsigned int nb_prom_envs = 0;
185 const char *prom_envs[MAX_PROM_ENVS];
188 uint8_t *boot_splash_filedata;
189 size_t boot_splash_filedata_size;
190 uint8_t qemu_extra_params_fw[2];
192 int icount_align_option;
194 /* The bytes in qemu_uuid are in the order specified by RFC4122, _not_ in the
195 * little-endian "wire format" described in the SMBIOS 2.6 specification.
200 static NotifierList exit_notifiers =
201 NOTIFIER_LIST_INITIALIZER(exit_notifiers);
203 static NotifierList machine_init_done_notifiers =
204 NOTIFIER_LIST_INITIALIZER(machine_init_done_notifiers);
208 enum xen_mode xen_mode = XEN_EMULATE;
209 bool xen_domid_restrict;
211 static int has_defaults = 1;
212 static int default_serial = 1;
213 static int default_parallel = 1;
214 static int default_virtcon = 1;
215 static int default_sclp = 1;
216 static int default_monitor = 1;
217 static int default_floppy = 1;
218 static int default_cdrom = 1;
219 static int default_sdcard = 1;
220 static int default_vga = 1;
221 static int default_net = 1;
227 { .driver = "isa-serial", .flag = &default_serial },
228 { .driver = "isa-parallel", .flag = &default_parallel },
229 { .driver = "isa-fdc", .flag = &default_floppy },
230 { .driver = "floppy", .flag = &default_floppy },
231 { .driver = "ide-cd", .flag = &default_cdrom },
232 { .driver = "ide-hd", .flag = &default_cdrom },
233 { .driver = "ide-drive", .flag = &default_cdrom },
234 { .driver = "scsi-cd", .flag = &default_cdrom },
235 { .driver = "scsi-hd", .flag = &default_cdrom },
236 { .driver = "virtio-serial-pci", .flag = &default_virtcon },
237 { .driver = "virtio-serial", .flag = &default_virtcon },
238 { .driver = "VGA", .flag = &default_vga },
239 { .driver = "isa-vga", .flag = &default_vga },
240 { .driver = "cirrus-vga", .flag = &default_vga },
241 { .driver = "isa-cirrus-vga", .flag = &default_vga },
242 { .driver = "vmware-svga", .flag = &default_vga },
243 { .driver = "qxl-vga", .flag = &default_vga },
244 { .driver = "virtio-vga", .flag = &default_vga },
247 static QemuOptsList qemu_rtc_opts = {
249 .head = QTAILQ_HEAD_INITIALIZER(qemu_rtc_opts.head),
253 .type = QEMU_OPT_STRING,
256 .type = QEMU_OPT_STRING,
259 .type = QEMU_OPT_STRING,
261 { /* end of list */ }
265 static QemuOptsList qemu_sandbox_opts = {
267 .implied_opt_name = "enable",
268 .head = QTAILQ_HEAD_INITIALIZER(qemu_sandbox_opts.head),
272 .type = QEMU_OPT_BOOL,
274 { /* end of list */ }
278 static QemuOptsList qemu_option_rom_opts = {
279 .name = "option-rom",
280 .implied_opt_name = "romfile",
281 .head = QTAILQ_HEAD_INITIALIZER(qemu_option_rom_opts.head),
285 .type = QEMU_OPT_NUMBER,
288 .type = QEMU_OPT_STRING,
290 { /* end of list */ }
294 static QemuOptsList qemu_machine_opts = {
296 .implied_opt_name = "type",
298 .head = QTAILQ_HEAD_INITIALIZER(qemu_machine_opts.head),
301 * no elements => accept any
302 * sanity checking will happen later
303 * when setting machine properties
309 static QemuOptsList qemu_accel_opts = {
311 .implied_opt_name = "accel",
312 .head = QTAILQ_HEAD_INITIALIZER(qemu_accel_opts.head),
317 .type = QEMU_OPT_STRING,
318 .help = "Select the type of accelerator",
322 .type = QEMU_OPT_STRING,
323 .help = "Enable/disable multi-threaded TCG",
325 { /* end of list */ }
329 static QemuOptsList qemu_boot_opts = {
331 .implied_opt_name = "order",
333 .head = QTAILQ_HEAD_INITIALIZER(qemu_boot_opts.head),
337 .type = QEMU_OPT_STRING,
340 .type = QEMU_OPT_STRING,
343 .type = QEMU_OPT_BOOL,
346 .type = QEMU_OPT_STRING,
348 .name = "splash-time",
349 .type = QEMU_OPT_STRING,
351 .name = "reboot-timeout",
352 .type = QEMU_OPT_STRING,
355 .type = QEMU_OPT_BOOL,
361 static QemuOptsList qemu_add_fd_opts = {
363 .head = QTAILQ_HEAD_INITIALIZER(qemu_add_fd_opts.head),
367 .type = QEMU_OPT_NUMBER,
368 .help = "file descriptor of which a duplicate is added to fd set",
371 .type = QEMU_OPT_NUMBER,
372 .help = "ID of the fd set to add fd to",
375 .type = QEMU_OPT_STRING,
376 .help = "free-form string used to describe fd",
378 { /* end of list */ }
382 static QemuOptsList qemu_object_opts = {
384 .implied_opt_name = "qom-type",
385 .head = QTAILQ_HEAD_INITIALIZER(qemu_object_opts.head),
391 static QemuOptsList qemu_tpmdev_opts = {
393 .implied_opt_name = "type",
394 .head = QTAILQ_HEAD_INITIALIZER(qemu_tpmdev_opts.head),
396 /* options are defined in the TPM backends */
397 { /* end of list */ }
401 static QemuOptsList qemu_realtime_opts = {
403 .head = QTAILQ_HEAD_INITIALIZER(qemu_realtime_opts.head),
407 .type = QEMU_OPT_BOOL,
409 { /* end of list */ }
413 static QemuOptsList qemu_msg_opts = {
415 .head = QTAILQ_HEAD_INITIALIZER(qemu_msg_opts.head),
419 .type = QEMU_OPT_BOOL,
421 { /* end of list */ }
425 static QemuOptsList qemu_name_opts = {
427 .implied_opt_name = "guest",
429 .head = QTAILQ_HEAD_INITIALIZER(qemu_name_opts.head),
433 .type = QEMU_OPT_STRING,
434 .help = "Sets the name of the guest.\n"
435 "This name will be displayed in the SDL window caption.\n"
436 "The name will also be used for the VNC server",
439 .type = QEMU_OPT_STRING,
440 .help = "Sets the name of the QEMU process, as shown in top etc",
442 .name = "debug-threads",
443 .type = QEMU_OPT_BOOL,
444 .help = "When enabled, name the individual threads; defaults off.\n"
445 "NOTE: The thread names are for debugging and not a\n"
448 { /* End of list */ }
452 static QemuOptsList qemu_mem_opts = {
454 .implied_opt_name = "size",
455 .head = QTAILQ_HEAD_INITIALIZER(qemu_mem_opts.head),
460 .type = QEMU_OPT_SIZE,
464 .type = QEMU_OPT_NUMBER,
468 .type = QEMU_OPT_SIZE,
470 { /* end of list */ }
474 static QemuOptsList qemu_icount_opts = {
476 .implied_opt_name = "shift",
478 .head = QTAILQ_HEAD_INITIALIZER(qemu_icount_opts.head),
482 .type = QEMU_OPT_STRING,
485 .type = QEMU_OPT_BOOL,
488 .type = QEMU_OPT_BOOL,
491 .type = QEMU_OPT_STRING,
494 .type = QEMU_OPT_STRING,
496 .name = "rrsnapshot",
497 .type = QEMU_OPT_STRING,
499 { /* end of list */ }
503 static QemuOptsList qemu_semihosting_config_opts = {
504 .name = "semihosting-config",
505 .implied_opt_name = "enable",
506 .head = QTAILQ_HEAD_INITIALIZER(qemu_semihosting_config_opts.head),
510 .type = QEMU_OPT_BOOL,
513 .type = QEMU_OPT_STRING,
516 .type = QEMU_OPT_STRING,
518 { /* end of list */ }
522 static QemuOptsList qemu_fw_cfg_opts = {
524 .implied_opt_name = "name",
525 .head = QTAILQ_HEAD_INITIALIZER(qemu_fw_cfg_opts.head),
529 .type = QEMU_OPT_STRING,
530 .help = "Sets the fw_cfg name of the blob to be inserted",
533 .type = QEMU_OPT_STRING,
534 .help = "Sets the name of the file from which\n"
535 "the fw_cfg blob will be loaded",
538 .type = QEMU_OPT_STRING,
539 .help = "Sets content of the blob to be inserted from a string",
541 { /* end of list */ }
546 * Get machine options
548 * Returns: machine options (never null).
550 QemuOpts *qemu_get_machine_opts(void)
552 return qemu_find_opts_singleton("machine");
555 const char *qemu_get_vm_name(void)
560 static void res_free(void)
562 g_free(boot_splash_filedata);
563 boot_splash_filedata = NULL;
566 static int default_driver_check(void *opaque, QemuOpts *opts, Error **errp)
568 const char *driver = qemu_opt_get(opts, "driver");
573 for (i = 0; i < ARRAY_SIZE(default_list); i++) {
574 if (strcmp(default_list[i].driver, driver) != 0)
576 *(default_list[i].flag) = 0;
581 /***********************************************************/
584 static RunState current_run_state = RUN_STATE_PRELAUNCH;
586 /* We use RUN_STATE__MAX but any invalid value will do */
587 static RunState vmstop_requested = RUN_STATE__MAX;
588 static QemuMutex vmstop_lock;
593 } RunStateTransition;
595 static const RunStateTransition runstate_transitions_def[] = {
597 { RUN_STATE_DEBUG, RUN_STATE_RUNNING },
598 { RUN_STATE_DEBUG, RUN_STATE_FINISH_MIGRATE },
599 { RUN_STATE_DEBUG, RUN_STATE_PRELAUNCH },
601 { RUN_STATE_INMIGRATE, RUN_STATE_INTERNAL_ERROR },
602 { RUN_STATE_INMIGRATE, RUN_STATE_IO_ERROR },
603 { RUN_STATE_INMIGRATE, RUN_STATE_PAUSED },
604 { RUN_STATE_INMIGRATE, RUN_STATE_RUNNING },
605 { RUN_STATE_INMIGRATE, RUN_STATE_SHUTDOWN },
606 { RUN_STATE_INMIGRATE, RUN_STATE_SUSPENDED },
607 { RUN_STATE_INMIGRATE, RUN_STATE_WATCHDOG },
608 { RUN_STATE_INMIGRATE, RUN_STATE_GUEST_PANICKED },
609 { RUN_STATE_INMIGRATE, RUN_STATE_FINISH_MIGRATE },
610 { RUN_STATE_INMIGRATE, RUN_STATE_PRELAUNCH },
611 { RUN_STATE_INMIGRATE, RUN_STATE_POSTMIGRATE },
612 { RUN_STATE_INMIGRATE, RUN_STATE_COLO },
614 { RUN_STATE_INTERNAL_ERROR, RUN_STATE_PAUSED },
615 { RUN_STATE_INTERNAL_ERROR, RUN_STATE_FINISH_MIGRATE },
616 { RUN_STATE_INTERNAL_ERROR, RUN_STATE_PRELAUNCH },
618 { RUN_STATE_IO_ERROR, RUN_STATE_RUNNING },
619 { RUN_STATE_IO_ERROR, RUN_STATE_FINISH_MIGRATE },
620 { RUN_STATE_IO_ERROR, RUN_STATE_PRELAUNCH },
622 { RUN_STATE_PAUSED, RUN_STATE_RUNNING },
623 { RUN_STATE_PAUSED, RUN_STATE_FINISH_MIGRATE },
624 { RUN_STATE_PAUSED, RUN_STATE_PRELAUNCH },
625 { RUN_STATE_PAUSED, RUN_STATE_COLO},
627 { RUN_STATE_POSTMIGRATE, RUN_STATE_RUNNING },
628 { RUN_STATE_POSTMIGRATE, RUN_STATE_FINISH_MIGRATE },
629 { RUN_STATE_POSTMIGRATE, RUN_STATE_PRELAUNCH },
631 { RUN_STATE_PRELAUNCH, RUN_STATE_RUNNING },
632 { RUN_STATE_PRELAUNCH, RUN_STATE_FINISH_MIGRATE },
633 { RUN_STATE_PRELAUNCH, RUN_STATE_INMIGRATE },
635 { RUN_STATE_FINISH_MIGRATE, RUN_STATE_RUNNING },
636 { RUN_STATE_FINISH_MIGRATE, RUN_STATE_POSTMIGRATE },
637 { RUN_STATE_FINISH_MIGRATE, RUN_STATE_PRELAUNCH },
638 { RUN_STATE_FINISH_MIGRATE, RUN_STATE_COLO},
640 { RUN_STATE_RESTORE_VM, RUN_STATE_RUNNING },
641 { RUN_STATE_RESTORE_VM, RUN_STATE_PRELAUNCH },
643 { RUN_STATE_COLO, RUN_STATE_RUNNING },
645 { RUN_STATE_RUNNING, RUN_STATE_DEBUG },
646 { RUN_STATE_RUNNING, RUN_STATE_INTERNAL_ERROR },
647 { RUN_STATE_RUNNING, RUN_STATE_IO_ERROR },
648 { RUN_STATE_RUNNING, RUN_STATE_PAUSED },
649 { RUN_STATE_RUNNING, RUN_STATE_FINISH_MIGRATE },
650 { RUN_STATE_RUNNING, RUN_STATE_RESTORE_VM },
651 { RUN_STATE_RUNNING, RUN_STATE_SAVE_VM },
652 { RUN_STATE_RUNNING, RUN_STATE_SHUTDOWN },
653 { RUN_STATE_RUNNING, RUN_STATE_WATCHDOG },
654 { RUN_STATE_RUNNING, RUN_STATE_GUEST_PANICKED },
655 { RUN_STATE_RUNNING, RUN_STATE_COLO},
657 { RUN_STATE_SAVE_VM, RUN_STATE_RUNNING },
659 { RUN_STATE_SHUTDOWN, RUN_STATE_PAUSED },
660 { RUN_STATE_SHUTDOWN, RUN_STATE_FINISH_MIGRATE },
661 { RUN_STATE_SHUTDOWN, RUN_STATE_PRELAUNCH },
663 { RUN_STATE_DEBUG, RUN_STATE_SUSPENDED },
664 { RUN_STATE_RUNNING, RUN_STATE_SUSPENDED },
665 { RUN_STATE_SUSPENDED, RUN_STATE_RUNNING },
666 { RUN_STATE_SUSPENDED, RUN_STATE_FINISH_MIGRATE },
667 { RUN_STATE_SUSPENDED, RUN_STATE_PRELAUNCH },
668 { RUN_STATE_SUSPENDED, RUN_STATE_COLO},
670 { RUN_STATE_WATCHDOG, RUN_STATE_RUNNING },
671 { RUN_STATE_WATCHDOG, RUN_STATE_FINISH_MIGRATE },
672 { RUN_STATE_WATCHDOG, RUN_STATE_PRELAUNCH },
673 { RUN_STATE_WATCHDOG, RUN_STATE_COLO},
675 { RUN_STATE_GUEST_PANICKED, RUN_STATE_RUNNING },
676 { RUN_STATE_GUEST_PANICKED, RUN_STATE_FINISH_MIGRATE },
677 { RUN_STATE_GUEST_PANICKED, RUN_STATE_PRELAUNCH },
679 { RUN_STATE__MAX, RUN_STATE__MAX },
682 static bool runstate_valid_transitions[RUN_STATE__MAX][RUN_STATE__MAX];
684 bool runstate_check(RunState state)
686 return current_run_state == state;
689 bool runstate_store(char *str, size_t size)
691 const char *state = RunState_lookup[current_run_state];
692 size_t len = strlen(state) + 1;
697 memcpy(str, state, len);
701 static void runstate_init(void)
703 const RunStateTransition *p;
705 memset(&runstate_valid_transitions, 0, sizeof(runstate_valid_transitions));
706 for (p = &runstate_transitions_def[0]; p->from != RUN_STATE__MAX; p++) {
707 runstate_valid_transitions[p->from][p->to] = true;
710 qemu_mutex_init(&vmstop_lock);
713 /* This function will abort() on invalid state transitions */
714 void runstate_set(RunState new_state)
716 assert(new_state < RUN_STATE__MAX);
718 if (current_run_state == new_state) {
722 if (!runstate_valid_transitions[current_run_state][new_state]) {
723 error_report("invalid runstate transition: '%s' -> '%s'",
724 RunState_lookup[current_run_state],
725 RunState_lookup[new_state]);
728 trace_runstate_set(new_state);
729 current_run_state = new_state;
732 int runstate_is_running(void)
734 return runstate_check(RUN_STATE_RUNNING);
737 bool runstate_needs_reset(void)
739 return runstate_check(RUN_STATE_INTERNAL_ERROR) ||
740 runstate_check(RUN_STATE_SHUTDOWN);
743 StatusInfo *qmp_query_status(Error **errp)
745 StatusInfo *info = g_malloc0(sizeof(*info));
747 info->running = runstate_is_running();
748 info->singlestep = singlestep;
749 info->status = current_run_state;
754 bool qemu_vmstop_requested(RunState *r)
756 qemu_mutex_lock(&vmstop_lock);
757 *r = vmstop_requested;
758 vmstop_requested = RUN_STATE__MAX;
759 qemu_mutex_unlock(&vmstop_lock);
760 return *r < RUN_STATE__MAX;
763 void qemu_system_vmstop_request_prepare(void)
765 qemu_mutex_lock(&vmstop_lock);
768 void qemu_system_vmstop_request(RunState state)
770 vmstop_requested = state;
771 qemu_mutex_unlock(&vmstop_lock);
775 /***********************************************************/
776 /* real time host monotonic timer */
778 static time_t qemu_time(void)
780 return qemu_clock_get_ms(QEMU_CLOCK_HOST) / 1000;
783 /***********************************************************/
784 /* host time/date access */
785 void qemu_get_timedate(struct tm *tm, int offset)
787 time_t ti = qemu_time();
790 if (rtc_date_offset == -1) {
794 localtime_r(&ti, tm);
796 ti -= rtc_date_offset;
801 int qemu_timedate_diff(struct tm *tm)
805 if (rtc_date_offset == -1)
807 seconds = mktimegm(tm);
810 tmp.tm_isdst = -1; /* use timezone to figure it out */
811 seconds = mktime(&tmp);
814 seconds = mktimegm(tm) + rtc_date_offset;
816 return seconds - qemu_time();
819 static void configure_rtc_date_offset(const char *startdate, int legacy)
821 time_t rtc_start_date;
824 if (!strcmp(startdate, "now") && legacy) {
825 rtc_date_offset = -1;
827 if (sscanf(startdate, "%d-%d-%dT%d:%d:%d",
835 } else if (sscanf(startdate, "%d-%d-%d",
847 rtc_start_date = mktimegm(&tm);
848 if (rtc_start_date == -1) {
850 error_report("invalid date format");
851 error_printf("valid formats: "
852 "'2006-06-17T16:01:21' or '2006-06-17'\n");
855 rtc_date_offset = qemu_time() - rtc_start_date;
859 static void configure_rtc(QemuOpts *opts)
863 value = qemu_opt_get(opts, "base");
865 if (!strcmp(value, "utc")) {
867 } else if (!strcmp(value, "localtime")) {
868 Error *blocker = NULL;
870 error_setg(&blocker, QERR_REPLAY_NOT_SUPPORTED,
871 "-rtc base=localtime");
872 replay_add_blocker(blocker);
874 configure_rtc_date_offset(value, 0);
877 value = qemu_opt_get(opts, "clock");
879 if (!strcmp(value, "host")) {
880 rtc_clock = QEMU_CLOCK_HOST;
881 } else if (!strcmp(value, "rt")) {
882 rtc_clock = QEMU_CLOCK_REALTIME;
883 } else if (!strcmp(value, "vm")) {
884 rtc_clock = QEMU_CLOCK_VIRTUAL;
886 error_report("invalid option value '%s'", value);
890 value = qemu_opt_get(opts, "driftfix");
892 if (!strcmp(value, "slew")) {
893 static GlobalProperty slew_lost_ticks = {
894 .driver = "mc146818rtc",
895 .property = "lost_tick_policy",
899 qdev_prop_register_global(&slew_lost_ticks);
900 } else if (!strcmp(value, "none")) {
901 /* discard is default */
903 error_report("invalid option value '%s'", value);
909 /***********************************************************/
910 /* Bluetooth support */
913 static struct HCIInfo *hci_table[MAX_NICS];
915 struct HCIInfo *qemu_next_hci(void)
917 if (cur_hci == nb_hcis)
920 return hci_table[cur_hci++];
923 static int bt_hci_parse(const char *str)
928 if (nb_hcis >= MAX_NICS) {
929 error_report("too many bluetooth HCIs (max %i)", MAX_NICS);
942 bdaddr.b[5] = 0x56 + nb_hcis;
943 hci->bdaddr_set(hci, bdaddr.b);
945 hci_table[nb_hcis++] = hci;
950 static void bt_vhci_add(int vlan_id)
952 struct bt_scatternet_s *vlan = qemu_find_bt_vlan(vlan_id);
955 warn_report("adding a VHCI to an empty scatternet %i",
958 bt_vhci_init(bt_new_hci(vlan));
961 static struct bt_device_s *bt_device_add(const char *opt)
963 struct bt_scatternet_s *vlan;
965 char *endp = strstr(opt, ",vlan=");
966 int len = (endp ? endp - opt : strlen(opt)) + 1;
969 pstrcpy(devname, MIN(sizeof(devname), len), opt);
972 vlan_id = strtol(endp + 6, &endp, 0);
974 error_report("unrecognised bluetooth vlan Id");
979 vlan = qemu_find_bt_vlan(vlan_id);
982 warn_report("adding a slave device to an empty scatternet %i",
985 if (!strcmp(devname, "keyboard"))
986 return bt_keyboard_init(vlan);
988 error_report("unsupported bluetooth device '%s'", devname);
992 static int bt_parse(const char *opt)
994 const char *endp, *p;
997 if (strstart(opt, "hci", &endp)) {
998 if (!*endp || *endp == ',') {
1000 if (!strstart(endp, ",vlan=", 0))
1003 return bt_hci_parse(opt);
1005 } else if (strstart(opt, "vhci", &endp)) {
1006 if (!*endp || *endp == ',') {
1008 if (strstart(endp, ",vlan=", &p)) {
1009 vlan = strtol(p, (char **) &endp, 0);
1011 error_report("bad scatternet '%s'", p);
1015 error_report("bad parameter '%s'", endp + 1);
1024 } else if (strstart(opt, "device:", &endp))
1025 return !bt_device_add(endp);
1027 error_report("bad bluetooth parameter '%s'", opt);
1031 static int parse_sandbox(void *opaque, QemuOpts *opts, Error **errp)
1033 /* FIXME: change this to true for 1.3 */
1034 if (qemu_opt_get_bool(opts, "enable", false)) {
1035 #ifdef CONFIG_SECCOMP
1036 if (seccomp_start() < 0) {
1037 error_report("failed to install seccomp syscall filter "
1042 error_report("seccomp support is disabled");
1050 static int parse_name(void *opaque, QemuOpts *opts, Error **errp)
1052 const char *proc_name;
1054 if (qemu_opt_get(opts, "debug-threads")) {
1055 qemu_thread_naming(qemu_opt_get_bool(opts, "debug-threads", false));
1057 qemu_name = qemu_opt_get(opts, "guest");
1059 proc_name = qemu_opt_get(opts, "process");
1061 os_set_proc_name(proc_name);
1067 bool defaults_enabled(void)
1069 return has_defaults;
1073 static int parse_add_fd(void *opaque, QemuOpts *opts, Error **errp)
1075 int fd, dupfd, flags;
1077 const char *fd_opaque = NULL;
1080 fd = qemu_opt_get_number(opts, "fd", -1);
1081 fdset_id = qemu_opt_get_number(opts, "set", -1);
1082 fd_opaque = qemu_opt_get(opts, "opaque");
1085 error_report("fd option is required and must be non-negative");
1089 if (fd <= STDERR_FILENO) {
1090 error_report("fd cannot be a standard I/O stream");
1095 * All fds inherited across exec() necessarily have FD_CLOEXEC
1096 * clear, while qemu sets FD_CLOEXEC on all other fds used internally.
1098 flags = fcntl(fd, F_GETFD);
1099 if (flags == -1 || (flags & FD_CLOEXEC)) {
1100 error_report("fd is not valid or already in use");
1105 error_report("set option is required and must be non-negative");
1109 #ifdef F_DUPFD_CLOEXEC
1110 dupfd = fcntl(fd, F_DUPFD_CLOEXEC, 0);
1114 qemu_set_cloexec(dupfd);
1118 error_report("error duplicating fd: %s", strerror(errno));
1122 /* add the duplicate fd, and optionally the opaque string, to the fd set */
1123 fdinfo = monitor_fdset_add_fd(dupfd, true, fdset_id, !!fd_opaque, fd_opaque,
1130 static int cleanup_add_fd(void *opaque, QemuOpts *opts, Error **errp)
1134 fd = qemu_opt_get_number(opts, "fd", -1);
1141 /***********************************************************/
1142 /* QEMU Block devices */
1144 #define HD_OPTS "media=disk"
1145 #define CDROM_OPTS "media=cdrom"
1147 #define PFLASH_OPTS ""
1151 static int drive_init_func(void *opaque, QemuOpts *opts, Error **errp)
1153 BlockInterfaceType *block_default_type = opaque;
1155 return drive_new(opts, *block_default_type) == NULL;
1158 static int drive_enable_snapshot(void *opaque, QemuOpts *opts, Error **errp)
1160 if (qemu_opt_get(opts, "snapshot") == NULL) {
1161 qemu_opt_set(opts, "snapshot", "on", &error_abort);
1166 static void default_drive(int enable, int snapshot, BlockInterfaceType type,
1167 int index, const char *optstr)
1172 if (!enable || drive_get_by_index(type, index)) {
1176 opts = drive_add(type, index, NULL, optstr);
1178 drive_enable_snapshot(NULL, opts, NULL);
1181 dinfo = drive_new(opts, type);
1185 dinfo->is_default = true;
1189 static QemuOptsList qemu_smp_opts = {
1191 .implied_opt_name = "cpus",
1192 .merge_lists = true,
1193 .head = QTAILQ_HEAD_INITIALIZER(qemu_smp_opts.head),
1197 .type = QEMU_OPT_NUMBER,
1200 .type = QEMU_OPT_NUMBER,
1203 .type = QEMU_OPT_NUMBER,
1206 .type = QEMU_OPT_NUMBER,
1209 .type = QEMU_OPT_NUMBER,
1211 { /*End of list */ }
1215 static void smp_parse(QemuOpts *opts)
1218 unsigned cpus = qemu_opt_get_number(opts, "cpus", 0);
1219 unsigned sockets = qemu_opt_get_number(opts, "sockets", 0);
1220 unsigned cores = qemu_opt_get_number(opts, "cores", 0);
1221 unsigned threads = qemu_opt_get_number(opts, "threads", 0);
1223 /* compute missing values, prefer sockets over cores over threads */
1224 if (cpus == 0 || sockets == 0) {
1225 sockets = sockets > 0 ? sockets : 1;
1226 cores = cores > 0 ? cores : 1;
1227 threads = threads > 0 ? threads : 1;
1229 cpus = cores * threads * sockets;
1231 } else if (cores == 0) {
1232 threads = threads > 0 ? threads : 1;
1233 cores = cpus / (sockets * threads);
1234 cores = cores > 0 ? cores : 1;
1235 } else if (threads == 0) {
1236 threads = cpus / (cores * sockets);
1237 threads = threads > 0 ? threads : 1;
1238 } else if (sockets * cores * threads < cpus) {
1239 error_report("cpu topology: "
1240 "sockets (%u) * cores (%u) * threads (%u) < "
1242 sockets, cores, threads, cpus);
1246 max_cpus = qemu_opt_get_number(opts, "maxcpus", cpus);
1248 if (max_cpus < cpus) {
1249 error_report("maxcpus must be equal to or greater than smp");
1253 if (sockets * cores * threads > max_cpus) {
1254 error_report("cpu topology: "
1255 "sockets (%u) * cores (%u) * threads (%u) > "
1257 sockets, cores, threads, max_cpus);
1263 smp_threads = threads;
1267 Error *blocker = NULL;
1268 error_setg(&blocker, QERR_REPLAY_NOT_SUPPORTED, "smp");
1269 replay_add_blocker(blocker);
1273 static void realtime_init(void)
1276 if (os_mlock() < 0) {
1277 error_report("locking memory failed");
1284 static void configure_msg(QemuOpts *opts)
1286 enable_timestamp_msg = qemu_opt_get_bool(opts, "timestamp", true);
1289 /***********************************************************/
1292 typedef struct SemihostingConfig {
1294 SemihostingTarget target;
1297 const char *cmdline; /* concatenated argv */
1298 } SemihostingConfig;
1300 static SemihostingConfig semihosting;
1302 bool semihosting_enabled(void)
1304 return semihosting.enabled;
1307 SemihostingTarget semihosting_get_target(void)
1309 return semihosting.target;
1312 const char *semihosting_get_arg(int i)
1314 if (i >= semihosting.argc) {
1317 return semihosting.argv[i];
1320 int semihosting_get_argc(void)
1322 return semihosting.argc;
1325 const char *semihosting_get_cmdline(void)
1327 if (semihosting.cmdline == NULL && semihosting.argc > 0) {
1328 semihosting.cmdline = g_strjoinv(" ", (gchar **)semihosting.argv);
1330 return semihosting.cmdline;
1333 static int add_semihosting_arg(void *opaque,
1334 const char *name, const char *val,
1337 SemihostingConfig *s = opaque;
1338 if (strcmp(name, "arg") == 0) {
1340 /* one extra element as g_strjoinv() expects NULL-terminated array */
1341 s->argv = g_realloc(s->argv, (s->argc + 1) * sizeof(void *));
1342 s->argv[s->argc - 1] = val;
1343 s->argv[s->argc] = NULL;
1348 /* Use strings passed via -kernel/-append to initialize semihosting.argv[] */
1349 static inline void semihosting_arg_fallback(const char *file, const char *cmd)
1354 add_semihosting_arg(&semihosting, "arg", file, NULL);
1356 /* split -append and initialize argv[1..n] */
1357 cmd_token = strtok(g_strdup(cmd), " ");
1359 add_semihosting_arg(&semihosting, "arg", cmd_token, NULL);
1360 cmd_token = strtok(NULL, " ");
1364 /* Now we still need this for compatibility with XEN. */
1365 bool has_igd_gfx_passthru;
1366 static void igd_gfx_passthru(void)
1368 has_igd_gfx_passthru = current_machine->igd_gfx_passthru;
1371 /***********************************************************/
1374 static int usb_device_add(const char *devname)
1376 USBDevice *dev = NULL;
1377 #ifndef CONFIG_LINUX
1381 if (!machine_usb(current_machine)) {
1385 /* drivers with .usbdevice_name entry in USBDeviceInfo */
1386 dev = usbdevice_create(devname);
1390 /* the other ones */
1391 #ifndef CONFIG_LINUX
1392 /* only the linux version is qdev-ified, usb-bsd still needs this */
1393 if (strstart(devname, "host:", &p)) {
1394 dev = usb_host_device_open(usb_bus_find(-1), p);
1404 static int usb_device_del(const char *devname)
1409 if (strstart(devname, "host:", &p)) {
1413 if (!machine_usb(current_machine)) {
1417 p = strchr(devname, '.');
1420 bus_num = strtoul(devname, NULL, 0);
1421 addr = strtoul(p + 1, NULL, 0);
1423 return usb_device_delete_addr(bus_num, addr);
1426 static int usb_parse(const char *cmdline)
1429 r = usb_device_add(cmdline);
1431 error_report("could not add USB device '%s'", cmdline);
1436 void hmp_usb_add(Monitor *mon, const QDict *qdict)
1438 const char *devname = qdict_get_str(qdict, "devname");
1440 error_report("usb_add is deprecated, please use device_add instead");
1442 if (usb_device_add(devname) < 0) {
1443 error_report("could not add USB device '%s'", devname);
1447 void hmp_usb_del(Monitor *mon, const QDict *qdict)
1449 const char *devname = qdict_get_str(qdict, "devname");
1451 error_report("usb_del is deprecated, please use device_del instead");
1453 if (usb_device_del(devname) < 0) {
1454 error_report("could not delete USB device '%s'", devname);
1458 /***********************************************************/
1459 /* machine registration */
1461 MachineState *current_machine;
1463 static MachineClass *find_machine(const char *name)
1465 GSList *el, *machines = object_class_get_list(TYPE_MACHINE, false);
1466 MachineClass *mc = NULL;
1468 for (el = machines; el; el = el->next) {
1469 MachineClass *temp = el->data;
1471 if (!strcmp(temp->name, name)) {
1476 !strcmp(temp->alias, name)) {
1482 g_slist_free(machines);
1486 MachineClass *find_default_machine(void)
1488 GSList *el, *machines = object_class_get_list(TYPE_MACHINE, false);
1489 MachineClass *mc = NULL;
1491 for (el = machines; el; el = el->next) {
1492 MachineClass *temp = el->data;
1494 if (temp->is_default) {
1500 g_slist_free(machines);
1504 MachineInfoList *qmp_query_machines(Error **errp)
1506 GSList *el, *machines = object_class_get_list(TYPE_MACHINE, false);
1507 MachineInfoList *mach_list = NULL;
1509 for (el = machines; el; el = el->next) {
1510 MachineClass *mc = el->data;
1511 MachineInfoList *entry;
1514 info = g_malloc0(sizeof(*info));
1515 if (mc->is_default) {
1516 info->has_is_default = true;
1517 info->is_default = true;
1521 info->has_alias = true;
1522 info->alias = g_strdup(mc->alias);
1525 info->name = g_strdup(mc->name);
1526 info->cpu_max = !mc->max_cpus ? 1 : mc->max_cpus;
1527 info->hotpluggable_cpus = mc->has_hotpluggable_cpus;
1529 entry = g_malloc0(sizeof(*entry));
1530 entry->value = info;
1531 entry->next = mach_list;
1535 g_slist_free(machines);
1539 static int machine_help_func(QemuOpts *opts, MachineState *machine)
1541 ObjectProperty *prop;
1542 ObjectPropertyIterator iter;
1544 if (!qemu_opt_has_help_opt(opts)) {
1548 object_property_iter_init(&iter, OBJECT(machine));
1549 while ((prop = object_property_iter_next(&iter))) {
1554 error_printf("%s.%s=%s", MACHINE_GET_CLASS(machine)->name,
1555 prop->name, prop->type);
1556 if (prop->description) {
1557 error_printf(" (%s)\n", prop->description);
1566 /***********************************************************/
1567 /* main execution loop */
1569 struct vm_change_state_entry {
1570 VMChangeStateHandler *cb;
1572 QLIST_ENTRY (vm_change_state_entry) entries;
1575 static QLIST_HEAD(vm_change_state_head, vm_change_state_entry) vm_change_state_head;
1577 VMChangeStateEntry *qemu_add_vm_change_state_handler(VMChangeStateHandler *cb,
1580 VMChangeStateEntry *e;
1582 e = g_malloc0(sizeof (*e));
1586 QLIST_INSERT_HEAD(&vm_change_state_head, e, entries);
1590 void qemu_del_vm_change_state_handler(VMChangeStateEntry *e)
1592 QLIST_REMOVE (e, entries);
1596 void vm_state_notify(int running, RunState state)
1598 VMChangeStateEntry *e, *next;
1600 trace_vm_state_notify(running, state);
1602 QLIST_FOREACH_SAFE(e, &vm_change_state_head, entries, next) {
1603 e->cb(e->opaque, running, state);
1607 static ShutdownCause reset_requested;
1608 static ShutdownCause shutdown_requested;
1609 static int shutdown_signal;
1610 static pid_t shutdown_pid;
1611 static int powerdown_requested;
1612 static int debug_requested;
1613 static int suspend_requested;
1614 static WakeupReason wakeup_reason;
1615 static NotifierList powerdown_notifiers =
1616 NOTIFIER_LIST_INITIALIZER(powerdown_notifiers);
1617 static NotifierList suspend_notifiers =
1618 NOTIFIER_LIST_INITIALIZER(suspend_notifiers);
1619 static NotifierList wakeup_notifiers =
1620 NOTIFIER_LIST_INITIALIZER(wakeup_notifiers);
1621 static uint32_t wakeup_reason_mask = ~(1 << QEMU_WAKEUP_REASON_NONE);
1623 ShutdownCause qemu_shutdown_requested_get(void)
1625 return shutdown_requested;
1628 ShutdownCause qemu_reset_requested_get(void)
1630 return reset_requested;
1633 static int qemu_shutdown_requested(void)
1635 return atomic_xchg(&shutdown_requested, SHUTDOWN_CAUSE_NONE);
1638 static void qemu_kill_report(void)
1640 if (!qtest_driver() && shutdown_signal) {
1641 if (shutdown_pid == 0) {
1642 /* This happens for eg ^C at the terminal, so it's worth
1643 * avoiding printing an odd message in that case.
1645 error_report("terminating on signal %d", shutdown_signal);
1647 char *shutdown_cmd = qemu_get_pid_name(shutdown_pid);
1649 error_report("terminating on signal %d from pid " FMT_pid " (%s)",
1650 shutdown_signal, shutdown_pid,
1651 shutdown_cmd ? shutdown_cmd : "<unknown process>");
1652 g_free(shutdown_cmd);
1654 shutdown_signal = 0;
1658 static ShutdownCause qemu_reset_requested(void)
1660 ShutdownCause r = reset_requested;
1662 if (r && replay_checkpoint(CHECKPOINT_RESET_REQUESTED)) {
1663 reset_requested = SHUTDOWN_CAUSE_NONE;
1666 return SHUTDOWN_CAUSE_NONE;
1669 static int qemu_suspend_requested(void)
1671 int r = suspend_requested;
1672 if (r && replay_checkpoint(CHECKPOINT_SUSPEND_REQUESTED)) {
1673 suspend_requested = 0;
1679 static WakeupReason qemu_wakeup_requested(void)
1681 return wakeup_reason;
1684 static int qemu_powerdown_requested(void)
1686 int r = powerdown_requested;
1687 powerdown_requested = 0;
1691 static int qemu_debug_requested(void)
1693 int r = debug_requested;
1694 debug_requested = 0;
1699 * Reset the VM. Issue an event unless @reason is SHUTDOWN_CAUSE_NONE.
1701 void qemu_system_reset(ShutdownCause reason)
1705 mc = current_machine ? MACHINE_GET_CLASS(current_machine) : NULL;
1707 cpu_synchronize_all_states();
1709 if (mc && mc->reset) {
1712 qemu_devices_reset();
1715 qapi_event_send_reset(shutdown_caused_by_guest(reason),
1718 cpu_synchronize_all_post_reset();
1721 void qemu_system_guest_panicked(GuestPanicInformation *info)
1723 qemu_log_mask(LOG_GUEST_ERROR, "Guest crashed\n");
1726 current_cpu->crash_occurred = true;
1728 qapi_event_send_guest_panicked(GUEST_PANIC_ACTION_PAUSE,
1729 !!info, info, &error_abort);
1730 vm_stop(RUN_STATE_GUEST_PANICKED);
1732 qapi_event_send_guest_panicked(GUEST_PANIC_ACTION_POWEROFF,
1733 !!info, info, &error_abort);
1734 qemu_system_shutdown_request(SHUTDOWN_CAUSE_GUEST_PANIC);
1738 if (info->type == GUEST_PANIC_INFORMATION_TYPE_HYPER_V) {
1739 qemu_log_mask(LOG_GUEST_ERROR, "HV crash parameters: (%#"PRIx64
1740 " %#"PRIx64" %#"PRIx64" %#"PRIx64" %#"PRIx64")\n",
1741 info->u.hyper_v.arg1,
1742 info->u.hyper_v.arg2,
1743 info->u.hyper_v.arg3,
1744 info->u.hyper_v.arg4,
1745 info->u.hyper_v.arg5);
1747 qapi_free_GuestPanicInformation(info);
1751 void qemu_system_reset_request(ShutdownCause reason)
1754 shutdown_requested = reason;
1756 reset_requested = reason;
1759 qemu_notify_event();
1762 static void qemu_system_suspend(void)
1765 notifier_list_notify(&suspend_notifiers, NULL);
1766 runstate_set(RUN_STATE_SUSPENDED);
1767 qapi_event_send_suspend(&error_abort);
1770 void qemu_system_suspend_request(void)
1772 if (runstate_check(RUN_STATE_SUSPENDED)) {
1775 suspend_requested = 1;
1777 qemu_notify_event();
1780 void qemu_register_suspend_notifier(Notifier *notifier)
1782 notifier_list_add(&suspend_notifiers, notifier);
1785 void qemu_system_wakeup_request(WakeupReason reason)
1787 trace_system_wakeup_request(reason);
1789 if (!runstate_check(RUN_STATE_SUSPENDED)) {
1792 if (!(wakeup_reason_mask & (1 << reason))) {
1795 runstate_set(RUN_STATE_RUNNING);
1796 wakeup_reason = reason;
1797 qemu_notify_event();
1800 void qemu_system_wakeup_enable(WakeupReason reason, bool enabled)
1803 wakeup_reason_mask |= (1 << reason);
1805 wakeup_reason_mask &= ~(1 << reason);
1809 void qemu_register_wakeup_notifier(Notifier *notifier)
1811 notifier_list_add(&wakeup_notifiers, notifier);
1814 void qemu_system_killed(int signal, pid_t pid)
1816 shutdown_signal = signal;
1820 /* Cannot call qemu_system_shutdown_request directly because
1821 * we are in a signal handler.
1823 shutdown_requested = SHUTDOWN_CAUSE_HOST_SIGNAL;
1824 qemu_notify_event();
1827 void qemu_system_shutdown_request(ShutdownCause reason)
1829 trace_qemu_system_shutdown_request(reason);
1830 replay_shutdown_request(reason);
1831 shutdown_requested = reason;
1832 qemu_notify_event();
1835 static void qemu_system_powerdown(void)
1837 qapi_event_send_powerdown(&error_abort);
1838 notifier_list_notify(&powerdown_notifiers, NULL);
1841 void qemu_system_powerdown_request(void)
1843 trace_qemu_system_powerdown_request();
1844 powerdown_requested = 1;
1845 qemu_notify_event();
1848 void qemu_register_powerdown_notifier(Notifier *notifier)
1850 notifier_list_add(&powerdown_notifiers, notifier);
1853 void qemu_system_debug_request(void)
1855 debug_requested = 1;
1856 qemu_notify_event();
1859 static bool main_loop_should_exit(void)
1862 ShutdownCause request;
1864 if (qemu_debug_requested()) {
1865 vm_stop(RUN_STATE_DEBUG);
1867 if (qemu_suspend_requested()) {
1868 qemu_system_suspend();
1870 request = qemu_shutdown_requested();
1873 qapi_event_send_shutdown(shutdown_caused_by_guest(request),
1876 vm_stop(RUN_STATE_SHUTDOWN);
1881 request = qemu_reset_requested();
1884 qemu_system_reset(request);
1886 if (!runstate_check(RUN_STATE_RUNNING) &&
1887 !runstate_check(RUN_STATE_INMIGRATE)) {
1888 runstate_set(RUN_STATE_PRELAUNCH);
1891 if (qemu_wakeup_requested()) {
1893 qemu_system_reset(SHUTDOWN_CAUSE_NONE);
1894 notifier_list_notify(&wakeup_notifiers, &wakeup_reason);
1895 wakeup_reason = QEMU_WAKEUP_REASON_NONE;
1897 qapi_event_send_wakeup(&error_abort);
1899 if (qemu_powerdown_requested()) {
1900 qemu_system_powerdown();
1902 if (qemu_vmstop_requested(&r)) {
1908 static void main_loop(void)
1910 #ifdef CONFIG_PROFILER
1914 #ifdef CONFIG_PROFILER
1915 ti = profile_getclock();
1917 main_loop_wait(false);
1918 #ifdef CONFIG_PROFILER
1919 dev_time += profile_getclock() - ti;
1921 } while (!main_loop_should_exit());
1924 static void version(void)
1926 printf("QEMU emulator version " QEMU_VERSION QEMU_PKGVERSION "\n"
1927 QEMU_COPYRIGHT "\n");
1930 static void help(int exitcode)
1933 printf("usage: %s [options] [disk_image]\n\n"
1934 "'disk_image' is a raw hard disk image for IDE hard disk 0\n\n",
1935 error_get_progname());
1937 #define QEMU_OPTIONS_GENERATE_HELP
1938 #include "qemu-options-wrapper.h"
1940 printf("\nDuring emulation, the following keys are useful:\n"
1941 "ctrl-alt-f toggle full screen\n"
1942 "ctrl-alt-n switch to virtual console 'n'\n"
1943 "ctrl-alt toggle mouse and keyboard grab\n"
1945 "When using -nographic, press 'ctrl-a h' to get some help.\n");
1950 #define HAS_ARG 0x0001
1952 typedef struct QEMUOption {
1959 static const QEMUOption qemu_options[] = {
1960 { "h", 0, QEMU_OPTION_h, QEMU_ARCH_ALL },
1961 #define QEMU_OPTIONS_GENERATE_OPTIONS
1962 #include "qemu-options-wrapper.h"
1966 typedef struct VGAInterfaceInfo {
1967 const char *opt_name; /* option name */
1968 const char *name; /* human-readable name */
1969 /* Class names indicating that support is available.
1970 * If no class is specified, the interface is always available */
1971 const char *class_names[2];
1974 static VGAInterfaceInfo vga_interfaces[VGA_TYPE_MAX] = {
1980 .name = "standard VGA",
1981 .class_names = { "VGA", "isa-vga" },
1984 .opt_name = "cirrus",
1985 .name = "Cirrus VGA",
1986 .class_names = { "cirrus-vga", "isa-cirrus-vga" },
1989 .opt_name = "vmware",
1990 .name = "VMWare SVGA",
1991 .class_names = { "vmware-svga" },
1994 .opt_name = "virtio",
1995 .name = "Virtio VGA",
1996 .class_names = { "virtio-vga" },
2001 .class_names = { "qxl-vga" },
2005 .name = "TCX framebuffer",
2006 .class_names = { "SUNW,tcx" },
2010 .name = "CG3 framebuffer",
2011 .class_names = { "cgthree" },
2014 .opt_name = "xenfb",
2018 static bool vga_interface_available(VGAInterfaceType t)
2020 VGAInterfaceInfo *ti = &vga_interfaces[t];
2022 assert(t < VGA_TYPE_MAX);
2023 return !ti->class_names[0] ||
2024 object_class_by_name(ti->class_names[0]) ||
2025 object_class_by_name(ti->class_names[1]);
2028 static void select_vgahw(const char *p)
2033 assert(vga_interface_type == VGA_NONE);
2034 for (t = 0; t < VGA_TYPE_MAX; t++) {
2035 VGAInterfaceInfo *ti = &vga_interfaces[t];
2036 if (ti->opt_name && strstart(p, ti->opt_name, &opts)) {
2037 if (!vga_interface_available(t)) {
2038 error_report("%s not available", ti->name);
2041 vga_interface_type = t;
2045 if (t == VGA_TYPE_MAX) {
2047 error_report("unknown vga type: %s", p);
2051 const char *nextopt;
2053 if (strstart(opts, ",retrace=", &nextopt)) {
2055 if (strstart(opts, "dumb", &nextopt))
2056 vga_retrace_method = VGA_RETRACE_DUMB;
2057 else if (strstart(opts, "precise", &nextopt))
2058 vga_retrace_method = VGA_RETRACE_PRECISE;
2059 else goto invalid_vga;
2060 } else goto invalid_vga;
2065 typedef enum DisplayType {
2075 static DisplayType select_display(const char *p)
2078 DisplayType display = DT_DEFAULT;
2080 if (strstart(p, "sdl", &opts)) {
2084 const char *nextopt;
2086 if (strstart(opts, ",frame=", &nextopt)) {
2088 if (strstart(opts, "on", &nextopt)) {
2090 } else if (strstart(opts, "off", &nextopt)) {
2093 goto invalid_sdl_args;
2095 } else if (strstart(opts, ",alt_grab=", &nextopt)) {
2097 if (strstart(opts, "on", &nextopt)) {
2099 } else if (strstart(opts, "off", &nextopt)) {
2102 goto invalid_sdl_args;
2104 } else if (strstart(opts, ",ctrl_grab=", &nextopt)) {
2106 if (strstart(opts, "on", &nextopt)) {
2108 } else if (strstart(opts, "off", &nextopt)) {
2111 goto invalid_sdl_args;
2113 } else if (strstart(opts, ",window_close=", &nextopt)) {
2115 if (strstart(opts, "on", &nextopt)) {
2117 } else if (strstart(opts, "off", &nextopt)) {
2120 goto invalid_sdl_args;
2122 } else if (strstart(opts, ",gl=", &nextopt)) {
2124 if (strstart(opts, "on", &nextopt)) {
2126 } else if (strstart(opts, "off", &nextopt)) {
2129 goto invalid_sdl_args;
2133 error_report("invalid SDL option string");
2139 error_report("SDL support is disabled");
2142 } else if (strstart(p, "vnc", &opts)) {
2144 vnc_parse(opts + 1, &error_fatal);
2146 error_report("VNC requires a display argument vnc=<display>");
2149 } else if (strstart(p, "egl-headless", &opts)) {
2150 #ifdef CONFIG_OPENGL_DMABUF
2155 fprintf(stderr, "egl support is disabled\n");
2158 } else if (strstart(p, "curses", &opts)) {
2159 #ifdef CONFIG_CURSES
2160 display = DT_CURSES;
2162 error_report("curses support is disabled");
2165 } else if (strstart(p, "gtk", &opts)) {
2169 const char *nextopt;
2171 if (strstart(opts, ",grab_on_hover=", &nextopt)) {
2173 if (strstart(opts, "on", &nextopt)) {
2174 grab_on_hover = true;
2175 } else if (strstart(opts, "off", &nextopt)) {
2176 grab_on_hover = false;
2178 goto invalid_gtk_args;
2180 } else if (strstart(opts, ",gl=", &nextopt)) {
2182 if (strstart(opts, "on", &nextopt)) {
2184 } else if (strstart(opts, "off", &nextopt)) {
2187 goto invalid_gtk_args;
2191 error_report("invalid GTK option string");
2197 error_report("GTK support is disabled");
2200 } else if (strstart(p, "none", &opts)) {
2203 error_report("unknown display type");
2210 static int balloon_parse(const char *arg)
2214 if (strcmp(arg, "none") == 0) {
2218 if (!strncmp(arg, "virtio", 6)) {
2219 if (arg[6] == ',') {
2220 /* have params -> parse them */
2221 opts = qemu_opts_parse_noisily(qemu_find_opts("device"), arg + 7,
2226 /* create empty opts */
2227 opts = qemu_opts_create(qemu_find_opts("device"), NULL, 0,
2230 qemu_opt_set(opts, "driver", "virtio-balloon", &error_abort);
2237 char *qemu_find_file(int type, const char *name)
2243 /* Try the name as a straight path first */
2244 if (access(name, R_OK) == 0) {
2245 trace_load_file(name, name);
2246 return g_strdup(name);
2250 case QEMU_FILE_TYPE_BIOS:
2253 case QEMU_FILE_TYPE_KEYMAP:
2254 subdir = "keymaps/";
2260 for (i = 0; i < data_dir_idx; i++) {
2261 buf = g_strdup_printf("%s/%s%s", data_dir[i], subdir, name);
2262 if (access(buf, R_OK) == 0) {
2263 trace_load_file(name, buf);
2271 static inline bool nonempty_str(const char *str)
2276 static int parse_fw_cfg(void *opaque, QemuOpts *opts, Error **errp)
2280 const char *name, *file, *str;
2281 FWCfgState *fw_cfg = (FWCfgState *) opaque;
2283 if (fw_cfg == NULL) {
2284 error_report("fw_cfg device not available");
2287 name = qemu_opt_get(opts, "name");
2288 file = qemu_opt_get(opts, "file");
2289 str = qemu_opt_get(opts, "string");
2291 /* we need name and either a file or the content string */
2292 if (!(nonempty_str(name) && (nonempty_str(file) || nonempty_str(str)))) {
2293 error_report("invalid argument(s)");
2296 if (nonempty_str(file) && nonempty_str(str)) {
2297 error_report("file and string are mutually exclusive");
2300 if (strlen(name) > FW_CFG_MAX_FILE_PATH - 1) {
2301 error_report("name too long (max. %d char)", FW_CFG_MAX_FILE_PATH - 1);
2304 if (strncmp(name, "opt/", 4) != 0) {
2305 warn_report("externally provided fw_cfg item names "
2306 "should be prefixed with \"opt/\"");
2308 if (nonempty_str(str)) {
2309 size = strlen(str); /* NUL terminator NOT included in fw_cfg blob */
2310 buf = g_memdup(str, size);
2312 if (!g_file_get_contents(file, &buf, &size, NULL)) {
2313 error_report("can't load %s", file);
2317 /* For legacy, keep user files in a specific global order. */
2318 fw_cfg_set_order_override(fw_cfg, FW_CFG_ORDER_OVERRIDE_USER);
2319 fw_cfg_add_file(fw_cfg, name, buf, size);
2320 fw_cfg_reset_order_override(fw_cfg);
2324 static int device_help_func(void *opaque, QemuOpts *opts, Error **errp)
2326 return qdev_device_help(opts);
2329 static int device_init_func(void *opaque, QemuOpts *opts, Error **errp)
2334 dev = qdev_device_add(opts, &err);
2336 error_report_err(err);
2339 object_unref(OBJECT(dev));
2343 static int chardev_init_func(void *opaque, QemuOpts *opts, Error **errp)
2345 Error *local_err = NULL;
2347 if (!qemu_chr_new_from_opts(opts, &local_err)) {
2349 error_report_err(local_err);
2357 #ifdef CONFIG_VIRTFS
2358 static int fsdev_init_func(void *opaque, QemuOpts *opts, Error **errp)
2360 return qemu_fsdev_add(opts);
2364 static int mon_init_func(void *opaque, QemuOpts *opts, Error **errp)
2367 const char *chardev;
2371 mode = qemu_opt_get(opts, "mode");
2375 if (strcmp(mode, "readline") == 0) {
2376 flags = MONITOR_USE_READLINE;
2377 } else if (strcmp(mode, "control") == 0) {
2378 flags = MONITOR_USE_CONTROL;
2380 error_report("unknown monitor mode \"%s\"", mode);
2384 if (qemu_opt_get_bool(opts, "pretty", 0))
2385 flags |= MONITOR_USE_PRETTY;
2387 if (qemu_opt_get_bool(opts, "default", 0)) {
2388 error_report("option 'default' does nothing and is deprecated");
2391 chardev = qemu_opt_get(opts, "chardev");
2392 chr = qemu_chr_find(chardev);
2394 error_report("chardev \"%s\" not found", chardev);
2398 monitor_init(chr, flags);
2402 static void monitor_parse(const char *optarg, const char *mode, bool pretty)
2404 static int monitor_device_index = 0;
2409 if (strstart(optarg, "chardev:", &p)) {
2410 snprintf(label, sizeof(label), "%s", p);
2412 snprintf(label, sizeof(label), "compat_monitor%d",
2413 monitor_device_index);
2414 opts = qemu_chr_parse_compat(label, optarg);
2416 error_report("parse error: %s", optarg);
2421 opts = qemu_opts_create(qemu_find_opts("mon"), label, 1, &error_fatal);
2422 qemu_opt_set(opts, "mode", mode, &error_abort);
2423 qemu_opt_set(opts, "chardev", label, &error_abort);
2424 qemu_opt_set_bool(opts, "pretty", pretty, &error_abort);
2425 monitor_device_index++;
2428 struct device_config {
2430 DEV_USB, /* -usbdevice */
2432 DEV_SERIAL, /* -serial */
2433 DEV_PARALLEL, /* -parallel */
2434 DEV_VIRTCON, /* -virtioconsole */
2435 DEV_DEBUGCON, /* -debugcon */
2436 DEV_GDB, /* -gdb, -s */
2437 DEV_SCLP, /* s390 sclp */
2439 const char *cmdline;
2441 QTAILQ_ENTRY(device_config) next;
2444 static QTAILQ_HEAD(, device_config) device_configs =
2445 QTAILQ_HEAD_INITIALIZER(device_configs);
2447 static void add_device_config(int type, const char *cmdline)
2449 struct device_config *conf;
2451 conf = g_malloc0(sizeof(*conf));
2453 conf->cmdline = cmdline;
2454 loc_save(&conf->loc);
2455 QTAILQ_INSERT_TAIL(&device_configs, conf, next);
2458 static int foreach_device_config(int type, int (*func)(const char *cmdline))
2460 struct device_config *conf;
2463 QTAILQ_FOREACH(conf, &device_configs, next) {
2464 if (conf->type != type)
2466 loc_push_restore(&conf->loc);
2467 rc = func(conf->cmdline);
2468 loc_pop(&conf->loc);
2476 static int serial_parse(const char *devname)
2478 static int index = 0;
2481 if (strcmp(devname, "none") == 0)
2483 if (index == MAX_SERIAL_PORTS) {
2484 error_report("too many serial ports");
2487 snprintf(label, sizeof(label), "serial%d", index);
2488 serial_hds[index] = qemu_chr_new(label, devname);
2489 if (!serial_hds[index]) {
2490 error_report("could not connect serial device"
2491 " to character backend '%s'", devname);
2498 static int parallel_parse(const char *devname)
2500 static int index = 0;
2503 if (strcmp(devname, "none") == 0)
2505 if (index == MAX_PARALLEL_PORTS) {
2506 error_report("too many parallel ports");
2509 snprintf(label, sizeof(label), "parallel%d", index);
2510 parallel_hds[index] = qemu_chr_new(label, devname);
2511 if (!parallel_hds[index]) {
2512 error_report("could not connect parallel device"
2513 " to character backend '%s'", devname);
2520 static int virtcon_parse(const char *devname)
2522 QemuOptsList *device = qemu_find_opts("device");
2523 static int index = 0;
2525 QemuOpts *bus_opts, *dev_opts;
2527 if (strcmp(devname, "none") == 0)
2529 if (index == MAX_VIRTIO_CONSOLES) {
2530 error_report("too many virtio consoles");
2534 bus_opts = qemu_opts_create(device, NULL, 0, &error_abort);
2535 qemu_opt_set(bus_opts, "driver", "virtio-serial", &error_abort);
2537 dev_opts = qemu_opts_create(device, NULL, 0, &error_abort);
2538 qemu_opt_set(dev_opts, "driver", "virtconsole", &error_abort);
2540 snprintf(label, sizeof(label), "virtcon%d", index);
2541 virtcon_hds[index] = qemu_chr_new(label, devname);
2542 if (!virtcon_hds[index]) {
2543 error_report("could not connect virtio console"
2544 " to character backend '%s'", devname);
2547 qemu_opt_set(dev_opts, "chardev", label, &error_abort);
2553 static int sclp_parse(const char *devname)
2555 QemuOptsList *device = qemu_find_opts("device");
2556 static int index = 0;
2560 if (strcmp(devname, "none") == 0) {
2563 if (index == MAX_SCLP_CONSOLES) {
2564 error_report("too many sclp consoles");
2568 assert(arch_type == QEMU_ARCH_S390X);
2570 dev_opts = qemu_opts_create(device, NULL, 0, NULL);
2571 qemu_opt_set(dev_opts, "driver", "sclpconsole", &error_abort);
2573 snprintf(label, sizeof(label), "sclpcon%d", index);
2574 sclp_hds[index] = qemu_chr_new(label, devname);
2575 if (!sclp_hds[index]) {
2576 error_report("could not connect sclp console"
2577 " to character backend '%s'", devname);
2580 qemu_opt_set(dev_opts, "chardev", label, &error_abort);
2586 static int debugcon_parse(const char *devname)
2590 if (!qemu_chr_new("debugcon", devname)) {
2593 opts = qemu_opts_create(qemu_find_opts("device"), "debugcon", 1, NULL);
2595 error_report("already have a debugcon device");
2598 qemu_opt_set(opts, "driver", "isa-debugcon", &error_abort);
2599 qemu_opt_set(opts, "chardev", "debugcon", &error_abort);
2603 static gint machine_class_cmp(gconstpointer a, gconstpointer b)
2605 const MachineClass *mc1 = a, *mc2 = b;
2608 if (mc1->family == NULL) {
2609 if (mc2->family == NULL) {
2610 /* Compare standalone machine types against each other; they sort
2611 * in increasing order.
2613 return strcmp(object_class_get_name(OBJECT_CLASS(mc1)),
2614 object_class_get_name(OBJECT_CLASS(mc2)));
2617 /* Standalone machine types sort after families. */
2621 if (mc2->family == NULL) {
2622 /* Families sort before standalone machine types. */
2626 /* Families sort between each other alphabetically increasingly. */
2627 res = strcmp(mc1->family, mc2->family);
2632 /* Within the same family, machine types sort in decreasing order. */
2633 return strcmp(object_class_get_name(OBJECT_CLASS(mc2)),
2634 object_class_get_name(OBJECT_CLASS(mc1)));
2637 static MachineClass *machine_parse(const char *name)
2639 MachineClass *mc = NULL;
2640 GSList *el, *machines = object_class_get_list(TYPE_MACHINE, false);
2643 mc = find_machine(name);
2646 g_slist_free(machines);
2649 if (name && !is_help_option(name)) {
2650 error_report("unsupported machine type");
2651 error_printf("Use -machine help to list supported machines\n");
2653 printf("Supported machines are:\n");
2654 machines = g_slist_sort(machines, machine_class_cmp);
2655 for (el = machines; el; el = el->next) {
2656 MachineClass *mc = el->data;
2658 printf("%-20s %s (alias of %s)\n", mc->alias, mc->desc, mc->name);
2660 printf("%-20s %s%s\n", mc->name, mc->desc,
2661 mc->is_default ? " (default)" : "");
2665 g_slist_free(machines);
2666 exit(!name || !is_help_option(name));
2669 void qemu_add_exit_notifier(Notifier *notify)
2671 notifier_list_add(&exit_notifiers, notify);
2674 void qemu_remove_exit_notifier(Notifier *notify)
2676 notifier_remove(notify);
2679 static void qemu_run_exit_notifiers(void)
2681 notifier_list_notify(&exit_notifiers, NULL);
2684 static bool machine_init_done;
2686 void qemu_add_machine_init_done_notifier(Notifier *notify)
2688 notifier_list_add(&machine_init_done_notifiers, notify);
2689 if (machine_init_done) {
2690 notify->notify(notify, NULL);
2694 void qemu_remove_machine_init_done_notifier(Notifier *notify)
2696 notifier_remove(notify);
2699 static void qemu_run_machine_init_done_notifiers(void)
2701 notifier_list_notify(&machine_init_done_notifiers, NULL);
2702 machine_init_done = true;
2705 static const QEMUOption *lookup_opt(int argc, char **argv,
2706 const char **poptarg, int *poptind)
2708 const QEMUOption *popt;
2709 int optind = *poptind;
2710 char *r = argv[optind];
2713 loc_set_cmdline(argv, optind, 1);
2715 /* Treat --foo the same as -foo. */
2718 popt = qemu_options;
2721 error_report("invalid option");
2724 if (!strcmp(popt->name, r + 1))
2728 if (popt->flags & HAS_ARG) {
2729 if (optind >= argc) {
2730 error_report("requires an argument");
2733 optarg = argv[optind++];
2734 loc_set_cmdline(argv, optind - 2, 2);
2745 static MachineClass *select_machine(void)
2747 MachineClass *machine_class = find_default_machine();
2752 loc_push_none(&loc);
2754 opts = qemu_get_machine_opts();
2755 qemu_opts_loc_restore(opts);
2757 optarg = qemu_opt_get(opts, "type");
2759 machine_class = machine_parse(optarg);
2762 if (!machine_class) {
2763 error_report("No machine specified, and there is no default");
2764 error_printf("Use -machine help to list supported machines\n");
2769 return machine_class;
2772 static int machine_set_property(void *opaque,
2773 const char *name, const char *value,
2776 Object *obj = OBJECT(opaque);
2777 Error *local_err = NULL;
2780 if (strcmp(name, "type") == 0) {
2784 qom_name = g_strdup(name);
2785 for (p = qom_name; *p; p++) {
2791 object_property_parse(obj, value, qom_name, &local_err);
2795 error_report_err(local_err);
2804 * Initial object creation happens before all other
2805 * QEMU data types are created. The majority of objects
2806 * can be created at this point. The rng-egd object
2807 * cannot be created here, as it depends on the chardev
2810 static bool object_create_initial(const char *type)
2812 if (g_str_equal(type, "rng-egd")) {
2817 * return false for concrete netfilters since
2818 * they depend on netdevs already existing
2820 if (g_str_equal(type, "filter-buffer") ||
2821 g_str_equal(type, "filter-dump") ||
2822 g_str_equal(type, "filter-mirror") ||
2823 g_str_equal(type, "filter-redirector") ||
2824 g_str_equal(type, "colo-compare") ||
2825 g_str_equal(type, "filter-rewriter") ||
2826 g_str_equal(type, "filter-replay")) {
2830 /* Memory allocation by backends needs to be done
2831 * after configure_accelerator() (due to the tcg_enabled()
2832 * checks at memory_region_init_*()).
2834 * Also, allocation of large amounts of memory may delay
2835 * chardev initialization for too long, and trigger timeouts
2836 * on software that waits for a monitor socket to be created
2839 if (g_str_has_prefix(type, "memory-backend-")) {
2848 * The remainder of object creation happens after the
2849 * creation of chardev, fsdev, net clients and device data types.
2851 static bool object_create_delayed(const char *type)
2853 return !object_create_initial(type);
2857 static void set_memory_options(uint64_t *ram_slots, ram_addr_t *maxram_size,
2861 const char *mem_str;
2862 const char *maxmem_str, *slots_str;
2863 const ram_addr_t default_ram_size = mc->default_ram_size;
2864 QemuOpts *opts = qemu_find_opts_singleton("memory");
2867 loc_push_none(&loc);
2868 qemu_opts_loc_restore(opts);
2871 mem_str = qemu_opt_get(opts, "size");
2874 error_report("missing 'size' option value");
2878 sz = qemu_opt_get_size(opts, "size", ram_size);
2880 /* Fix up legacy suffix-less format */
2881 if (g_ascii_isdigit(mem_str[strlen(mem_str) - 1])) {
2882 uint64_t overflow_check = sz;
2885 if ((sz >> 20) != overflow_check) {
2886 error_report("too large 'size' option value");
2892 /* backward compatibility behaviour for case "-m 0" */
2894 sz = default_ram_size;
2897 sz = QEMU_ALIGN_UP(sz, 8192);
2899 if (ram_size != sz) {
2900 error_report("ram size too large");
2904 /* store value for the future use */
2905 qemu_opt_set_number(opts, "size", ram_size, &error_abort);
2906 *maxram_size = ram_size;
2908 maxmem_str = qemu_opt_get(opts, "maxmem");
2909 slots_str = qemu_opt_get(opts, "slots");
2910 if (maxmem_str && slots_str) {
2913 sz = qemu_opt_get_size(opts, "maxmem", 0);
2914 slots = qemu_opt_get_number(opts, "slots", 0);
2915 if (sz < ram_size) {
2916 error_report("invalid value of -m option maxmem: "
2917 "maximum memory size (0x%" PRIx64 ") must be at least "
2918 "the initial memory size (0x" RAM_ADDR_FMT ")",
2921 } else if (sz > ram_size) {
2923 error_report("invalid value of -m option: maxmem was "
2924 "specified, but no hotplug slots were specified");
2928 error_report("invalid value of -m option maxmem: "
2929 "memory slots were specified but maximum memory size "
2930 "(0x%" PRIx64 ") is equal to the initial memory size "
2931 "(0x" RAM_ADDR_FMT ")", sz, ram_size);
2937 } else if ((!maxmem_str && slots_str) ||
2938 (maxmem_str && !slots_str)) {
2939 error_report("invalid -m option value: missing "
2940 "'%s' option", slots_str ? "maxmem" : "slots");
2947 static int global_init_func(void *opaque, QemuOpts *opts, Error **errp)
2951 g = g_malloc0(sizeof(*g));
2952 g->driver = qemu_opt_get(opts, "driver");
2953 g->property = qemu_opt_get(opts, "property");
2954 g->value = qemu_opt_get(opts, "value");
2955 g->user_provided = true;
2956 g->errp = &error_fatal;
2957 qdev_prop_register_global(g);
2961 static int qemu_read_default_config_file(void)
2965 ret = qemu_read_config_file(CONFIG_QEMU_CONFDIR "/qemu.conf");
2966 if (ret < 0 && ret != -ENOENT) {
2973 static void user_register_global_props(void)
2975 qemu_opts_foreach(qemu_find_opts("global"),
2976 global_init_func, NULL, NULL);
2980 * Note: we should see that these properties are actually having a
2981 * priority: accel < machine < user. This means e.g. when user
2982 * specifies something in "-global", it'll always be used with highest
2983 * priority than either machine/accelerator compat properties.
2985 static void register_global_properties(MachineState *ms)
2987 accel_register_compat_props(ms->accelerator);
2988 machine_register_compat_props(ms);
2989 user_register_global_props();
2992 int main(int argc, char **argv, char **envp)
2995 int snapshot, linux_boot;
2996 const char *initrd_filename;
2997 const char *kernel_filename, *kernel_cmdline;
2998 const char *boot_order = NULL;
2999 const char *boot_once = NULL;
3001 int cyls, heads, secs, translation;
3002 QemuOpts *opts, *machine_opts;
3003 QemuOpts *hda_opts = NULL, *icount_opts = NULL, *accel_opts = NULL;
3004 QemuOptsList *olist;
3007 const char *loadvm = NULL;
3008 MachineClass *machine_class;
3009 const char *cpu_model;
3010 const char *vga_model = NULL;
3011 const char *qtest_chrdev = NULL;
3012 const char *qtest_log = NULL;
3013 const char *pid_file = NULL;
3014 const char *incoming = NULL;
3015 bool defconfig = true;
3016 bool userconfig = true;
3017 bool nographic = false;
3018 DisplayType display_type = DT_DEFAULT;
3019 int display_remote = 0;
3020 const char *log_mask = NULL;
3021 const char *log_file = NULL;
3022 char *trace_file = NULL;
3023 ram_addr_t maxram_size;
3024 uint64_t ram_slots = 0;
3025 FILE *vmstate_dump_file = NULL;
3026 Error *main_loop_err = NULL;
3028 bool list_data_dirs = false;
3029 typedef struct BlockdevOptions_queue {
3030 BlockdevOptions *bdo;
3032 QSIMPLEQ_ENTRY(BlockdevOptions_queue) entry;
3033 } BlockdevOptions_queue;
3034 QSIMPLEQ_HEAD(, BlockdevOptions_queue) bdo_queue
3035 = QSIMPLEQ_HEAD_INITIALIZER(bdo_queue);
3037 module_call_init(MODULE_INIT_TRACE);
3039 qemu_init_cpu_list();
3040 qemu_init_cpu_loop();
3041 qemu_mutex_lock_iothread();
3043 atexit(qemu_run_exit_notifiers);
3044 error_set_progname(argv[0]);
3045 qemu_init_exec_dir(argv[0]);
3047 module_call_init(MODULE_INIT_QOM);
3048 monitor_init_qmp_commands();
3050 qemu_add_opts(&qemu_drive_opts);
3051 qemu_add_drive_opts(&qemu_legacy_drive_opts);
3052 qemu_add_drive_opts(&qemu_common_drive_opts);
3053 qemu_add_drive_opts(&qemu_drive_opts);
3054 qemu_add_drive_opts(&bdrv_runtime_opts);
3055 qemu_add_opts(&qemu_chardev_opts);
3056 qemu_add_opts(&qemu_device_opts);
3057 qemu_add_opts(&qemu_netdev_opts);
3058 qemu_add_opts(&qemu_net_opts);
3059 qemu_add_opts(&qemu_rtc_opts);
3060 qemu_add_opts(&qemu_global_opts);
3061 qemu_add_opts(&qemu_mon_opts);
3062 qemu_add_opts(&qemu_trace_opts);
3063 qemu_add_opts(&qemu_option_rom_opts);
3064 qemu_add_opts(&qemu_machine_opts);
3065 qemu_add_opts(&qemu_accel_opts);
3066 qemu_add_opts(&qemu_mem_opts);
3067 qemu_add_opts(&qemu_smp_opts);
3068 qemu_add_opts(&qemu_boot_opts);
3069 qemu_add_opts(&qemu_sandbox_opts);
3070 qemu_add_opts(&qemu_add_fd_opts);
3071 qemu_add_opts(&qemu_object_opts);
3072 qemu_add_opts(&qemu_tpmdev_opts);
3073 qemu_add_opts(&qemu_realtime_opts);
3074 qemu_add_opts(&qemu_msg_opts);
3075 qemu_add_opts(&qemu_name_opts);
3076 qemu_add_opts(&qemu_numa_opts);
3077 qemu_add_opts(&qemu_icount_opts);
3078 qemu_add_opts(&qemu_semihosting_config_opts);
3079 qemu_add_opts(&qemu_fw_cfg_opts);
3080 module_call_init(MODULE_INIT_OPTS);
3084 if (qcrypto_init(&err) < 0) {
3085 error_reportf_err(err, "cannot initialize crypto: ");
3088 rtc_clock = QEMU_CLOCK_HOST;
3090 QLIST_INIT (&vm_change_state_head);
3091 os_setup_early_signal_handling();
3095 cyls = heads = secs = 0;
3096 translation = BIOS_ATA_TRANSLATION_AUTO;
3100 bdrv_init_with_whitelist();
3104 /* first pass of option parsing */
3106 while (optind < argc) {
3107 if (argv[optind][0] != '-') {
3111 const QEMUOption *popt;
3113 popt = lookup_opt(argc, argv, &optarg, &optind);
3114 switch (popt->index) {
3115 case QEMU_OPTION_nodefconfig:
3118 case QEMU_OPTION_nouserconfig:
3125 if (defconfig && userconfig) {
3126 if (qemu_read_default_config_file() < 0) {
3131 /* second pass of option parsing */
3136 if (argv[optind][0] != '-') {
3137 hda_opts = drive_add(IF_DEFAULT, 0, argv[optind++], HD_OPTS);
3139 const QEMUOption *popt;
3141 popt = lookup_opt(argc, argv, &optarg, &optind);
3142 if (!(popt->arch_mask & arch_type)) {
3143 error_report("Option not supported for this target");
3146 switch(popt->index) {
3147 case QEMU_OPTION_no_kvm_irqchip: {
3148 olist = qemu_find_opts("machine");
3149 qemu_opts_parse_noisily(olist, "kernel_irqchip=off", false);
3152 case QEMU_OPTION_cpu:
3153 /* hw initialization will check this */
3156 case QEMU_OPTION_hda:
3160 snprintf(buf, sizeof(buf), "%s", HD_OPTS);
3162 snprintf(buf, sizeof(buf),
3163 "%s,cyls=%d,heads=%d,secs=%d%s",
3164 HD_OPTS , cyls, heads, secs,
3165 translation == BIOS_ATA_TRANSLATION_LBA ?
3167 translation == BIOS_ATA_TRANSLATION_NONE ?
3168 ",trans=none" : "");
3169 drive_add(IF_DEFAULT, 0, optarg, buf);
3172 case QEMU_OPTION_hdb:
3173 case QEMU_OPTION_hdc:
3174 case QEMU_OPTION_hdd:
3175 drive_add(IF_DEFAULT, popt->index - QEMU_OPTION_hda, optarg,
3178 case QEMU_OPTION_blockdev:
3181 BlockdevOptions_queue *bdo;
3183 v = qobject_input_visitor_new_str(optarg, "driver", &err);
3185 error_report_err(err);
3189 bdo = g_new(BlockdevOptions_queue, 1);
3190 visit_type_BlockdevOptions(v, NULL, &bdo->bdo,
3193 loc_save(&bdo->loc);
3194 QSIMPLEQ_INSERT_TAIL(&bdo_queue, bdo, entry);
3197 case QEMU_OPTION_drive:
3198 if (drive_def(optarg) == NULL) {
3202 case QEMU_OPTION_set:
3203 if (qemu_set_option(optarg) != 0)
3206 case QEMU_OPTION_global:
3207 if (qemu_global_option(optarg) != 0)
3210 case QEMU_OPTION_mtdblock:
3211 drive_add(IF_MTD, -1, optarg, MTD_OPTS);
3213 case QEMU_OPTION_sd:
3214 drive_add(IF_SD, -1, optarg, SD_OPTS);
3216 case QEMU_OPTION_pflash:
3217 drive_add(IF_PFLASH, -1, optarg, PFLASH_OPTS);
3219 case QEMU_OPTION_snapshot:
3222 case QEMU_OPTION_hdachs:
3226 cyls = strtol(p, (char **)&p, 0);
3227 if (cyls < 1 || cyls > 16383)
3232 heads = strtol(p, (char **)&p, 0);
3233 if (heads < 1 || heads > 16)
3238 secs = strtol(p, (char **)&p, 0);
3239 if (secs < 1 || secs > 63)
3243 if (!strcmp(p, "large")) {
3244 translation = BIOS_ATA_TRANSLATION_LARGE;
3245 } else if (!strcmp(p, "rechs")) {
3246 translation = BIOS_ATA_TRANSLATION_RECHS;
3247 } else if (!strcmp(p, "none")) {
3248 translation = BIOS_ATA_TRANSLATION_NONE;
3249 } else if (!strcmp(p, "lba")) {
3250 translation = BIOS_ATA_TRANSLATION_LBA;
3251 } else if (!strcmp(p, "auto")) {
3252 translation = BIOS_ATA_TRANSLATION_AUTO;
3256 } else if (*p != '\0') {
3258 error_report("invalid physical CHS format");
3261 if (hda_opts != NULL) {
3262 qemu_opt_set_number(hda_opts, "cyls", cyls,
3264 qemu_opt_set_number(hda_opts, "heads", heads,
3266 qemu_opt_set_number(hda_opts, "secs", secs,
3268 if (translation == BIOS_ATA_TRANSLATION_LARGE) {
3269 qemu_opt_set(hda_opts, "trans", "large",
3271 } else if (translation == BIOS_ATA_TRANSLATION_RECHS) {
3272 qemu_opt_set(hda_opts, "trans", "rechs",
3274 } else if (translation == BIOS_ATA_TRANSLATION_LBA) {
3275 qemu_opt_set(hda_opts, "trans", "lba",
3277 } else if (translation == BIOS_ATA_TRANSLATION_NONE) {
3278 qemu_opt_set(hda_opts, "trans", "none",
3283 error_report("'-hdachs' is deprecated, please use '-device"
3284 " ide-hd,cyls=c,heads=h,secs=s,...' instead");
3286 case QEMU_OPTION_numa:
3287 opts = qemu_opts_parse_noisily(qemu_find_opts("numa"),
3293 case QEMU_OPTION_display:
3294 display_type = select_display(optarg);
3296 case QEMU_OPTION_nographic:
3297 olist = qemu_find_opts("machine");
3298 qemu_opts_parse_noisily(olist, "graphics=off", false);
3300 display_type = DT_NONE;
3302 case QEMU_OPTION_curses:
3303 #ifdef CONFIG_CURSES
3304 display_type = DT_CURSES;
3306 error_report("curses support is disabled");
3310 case QEMU_OPTION_portrait:
3311 graphic_rotate = 90;
3313 case QEMU_OPTION_rotate:
3314 graphic_rotate = strtol(optarg, (char **) &optarg, 10);
3315 if (graphic_rotate != 0 && graphic_rotate != 90 &&
3316 graphic_rotate != 180 && graphic_rotate != 270) {
3317 error_report("only 90, 180, 270 deg rotation is available");
3321 case QEMU_OPTION_kernel:
3322 qemu_opts_set(qemu_find_opts("machine"), 0, "kernel", optarg,
3325 case QEMU_OPTION_initrd:
3326 qemu_opts_set(qemu_find_opts("machine"), 0, "initrd", optarg,
3329 case QEMU_OPTION_append:
3330 qemu_opts_set(qemu_find_opts("machine"), 0, "append", optarg,
3333 case QEMU_OPTION_dtb:
3334 qemu_opts_set(qemu_find_opts("machine"), 0, "dtb", optarg,
3337 case QEMU_OPTION_cdrom:
3338 drive_add(IF_DEFAULT, 2, optarg, CDROM_OPTS);
3340 case QEMU_OPTION_boot:
3341 opts = qemu_opts_parse_noisily(qemu_find_opts("boot-opts"),
3347 case QEMU_OPTION_fda:
3348 case QEMU_OPTION_fdb:
3349 drive_add(IF_FLOPPY, popt->index - QEMU_OPTION_fda,
3352 case QEMU_OPTION_no_fd_bootchk:
3355 case QEMU_OPTION_netdev:
3357 if (net_client_parse(qemu_find_opts("netdev"), optarg) == -1) {
3361 case QEMU_OPTION_net:
3363 if (net_client_parse(qemu_find_opts("net"), optarg) == -1) {
3367 #ifdef CONFIG_LIBISCSI
3368 case QEMU_OPTION_iscsi:
3369 opts = qemu_opts_parse_noisily(qemu_find_opts("iscsi"),
3377 case QEMU_OPTION_tftp:
3378 error_report("The -tftp option is deprecated. "
3379 "Please use '-netdev user,tftp=...' instead.");
3380 legacy_tftp_prefix = optarg;
3382 case QEMU_OPTION_bootp:
3383 error_report("The -bootp option is deprecated. "
3384 "Please use '-netdev user,bootfile=...' instead.");
3385 legacy_bootp_filename = optarg;
3387 case QEMU_OPTION_redir:
3388 error_report("The -redir option is deprecated. "
3389 "Please use '-netdev user,hostfwd=...' instead.");
3390 if (net_slirp_redir(optarg) < 0)
3394 case QEMU_OPTION_bt:
3395 add_device_config(DEV_BT, optarg);
3397 case QEMU_OPTION_audio_help:
3401 case QEMU_OPTION_soundhw:
3402 select_soundhw (optarg);
3407 case QEMU_OPTION_version:
3412 opts = qemu_opts_parse_noisily(qemu_find_opts("memory"),
3419 case QEMU_OPTION_tpmdev:
3420 if (tpm_config_parse(qemu_find_opts("tpmdev"), optarg) < 0) {
3425 case QEMU_OPTION_mempath:
3428 case QEMU_OPTION_mem_prealloc:
3437 case QEMU_OPTION_DFILTER:
3438 qemu_set_dfilter_ranges(optarg, &error_fatal);
3441 add_device_config(DEV_GDB, "tcp::" DEFAULT_GDBSTUB_PORT);
3443 case QEMU_OPTION_gdb:
3444 add_device_config(DEV_GDB, optarg);
3447 if (is_help_option(optarg)) {
3448 list_data_dirs = true;
3449 } else if (data_dir_idx < ARRAY_SIZE(data_dir)) {
3450 data_dir[data_dir_idx++] = optarg;
3453 case QEMU_OPTION_bios:
3454 qemu_opts_set(qemu_find_opts("machine"), 0, "firmware", optarg,
3457 case QEMU_OPTION_singlestep:
3464 keyboard_layout = optarg;
3466 case QEMU_OPTION_localtime:
3469 case QEMU_OPTION_vga:
3478 w = strtol(p, (char **)&p, 10);
3481 error_report("invalid resolution or depth");
3487 h = strtol(p, (char **)&p, 10);
3492 depth = strtol(p, (char **)&p, 10);
3493 if (depth != 8 && depth != 15 && depth != 16 &&
3494 depth != 24 && depth != 32)
3496 } else if (*p == '\0') {
3497 depth = graphic_depth;
3504 graphic_depth = depth;
3507 case QEMU_OPTION_echr:
3510 term_escape_char = strtol(optarg, &r, 0);
3512 printf("Bad argument to echr\n");
3515 case QEMU_OPTION_monitor:
3516 default_monitor = 0;
3517 if (strncmp(optarg, "none", 4)) {
3518 monitor_parse(optarg, "readline", false);
3521 case QEMU_OPTION_qmp:
3522 monitor_parse(optarg, "control", false);
3523 default_monitor = 0;
3525 case QEMU_OPTION_qmp_pretty:
3526 monitor_parse(optarg, "control", true);
3527 default_monitor = 0;
3529 case QEMU_OPTION_mon:
3530 opts = qemu_opts_parse_noisily(qemu_find_opts("mon"), optarg,
3535 default_monitor = 0;
3537 case QEMU_OPTION_chardev:
3538 opts = qemu_opts_parse_noisily(qemu_find_opts("chardev"),
3544 case QEMU_OPTION_fsdev:
3545 olist = qemu_find_opts("fsdev");
3547 error_report("fsdev support is disabled");
3550 opts = qemu_opts_parse_noisily(olist, optarg, true);
3555 case QEMU_OPTION_virtfs: {
3558 const char *writeout, *sock_fd, *socket;
3560 olist = qemu_find_opts("virtfs");
3562 error_report("virtfs support is disabled");
3565 opts = qemu_opts_parse_noisily(olist, optarg, true);
3570 if (qemu_opt_get(opts, "fsdriver") == NULL ||
3571 qemu_opt_get(opts, "mount_tag") == NULL) {
3572 error_report("Usage: -virtfs fsdriver,mount_tag=tag");
3575 fsdev = qemu_opts_create(qemu_find_opts("fsdev"),
3576 qemu_opts_id(opts) ?:
3577 qemu_opt_get(opts, "mount_tag"),
3580 error_report("duplicate or invalid fsdev id: %s",
3581 qemu_opt_get(opts, "mount_tag"));
3585 writeout = qemu_opt_get(opts, "writeout");
3587 #ifdef CONFIG_SYNC_FILE_RANGE
3588 qemu_opt_set(fsdev, "writeout", writeout, &error_abort);
3590 error_report("writeout=immediate not supported "
3591 "on this platform");
3595 qemu_opt_set(fsdev, "fsdriver",
3596 qemu_opt_get(opts, "fsdriver"), &error_abort);
3597 qemu_opt_set(fsdev, "path", qemu_opt_get(opts, "path"),
3599 qemu_opt_set(fsdev, "security_model",
3600 qemu_opt_get(opts, "security_model"),
3602 socket = qemu_opt_get(opts, "socket");
3604 qemu_opt_set(fsdev, "socket", socket, &error_abort);
3606 sock_fd = qemu_opt_get(opts, "sock_fd");
3608 qemu_opt_set(fsdev, "sock_fd", sock_fd, &error_abort);
3611 qemu_opt_set_bool(fsdev, "readonly",
3612 qemu_opt_get_bool(opts, "readonly", 0),
3614 device = qemu_opts_create(qemu_find_opts("device"), NULL, 0,
3616 qemu_opt_set(device, "driver", "virtio-9p-pci", &error_abort);
3617 qemu_opt_set(device, "fsdev",
3618 qemu_opts_id(fsdev), &error_abort);
3619 qemu_opt_set(device, "mount_tag",
3620 qemu_opt_get(opts, "mount_tag"), &error_abort);
3623 case QEMU_OPTION_virtfs_synth: {
3627 fsdev = qemu_opts_create(qemu_find_opts("fsdev"), "v_synth",
3630 error_report("duplicate option: %s", "virtfs_synth");
3633 qemu_opt_set(fsdev, "fsdriver", "synth", &error_abort);
3635 device = qemu_opts_create(qemu_find_opts("device"), NULL, 0,
3637 qemu_opt_set(device, "driver", "virtio-9p-pci", &error_abort);
3638 qemu_opt_set(device, "fsdev", "v_synth", &error_abort);
3639 qemu_opt_set(device, "mount_tag", "v_synth", &error_abort);
3642 case QEMU_OPTION_serial:
3643 add_device_config(DEV_SERIAL, optarg);
3645 if (strncmp(optarg, "mon:", 4) == 0) {
3646 default_monitor = 0;
3649 case QEMU_OPTION_watchdog:
3651 error_report("only one watchdog option may be given");
3656 case QEMU_OPTION_watchdog_action:
3657 if (select_watchdog_action(optarg) == -1) {
3658 error_report("unknown -watchdog-action parameter");
3662 case QEMU_OPTION_virtiocon:
3663 add_device_config(DEV_VIRTCON, optarg);
3664 default_virtcon = 0;
3665 if (strncmp(optarg, "mon:", 4) == 0) {
3666 default_monitor = 0;
3669 case QEMU_OPTION_parallel:
3670 add_device_config(DEV_PARALLEL, optarg);
3671 default_parallel = 0;
3672 if (strncmp(optarg, "mon:", 4) == 0) {
3673 default_monitor = 0;
3676 case QEMU_OPTION_debugcon:
3677 add_device_config(DEV_DEBUGCON, optarg);
3679 case QEMU_OPTION_loadvm:
3682 case QEMU_OPTION_full_screen:
3685 case QEMU_OPTION_no_frame:
3688 case QEMU_OPTION_alt_grab:
3691 case QEMU_OPTION_ctrl_grab:
3694 case QEMU_OPTION_no_quit:
3697 case QEMU_OPTION_sdl:
3699 display_type = DT_SDL;
3702 error_report("SDL support is disabled");
3705 case QEMU_OPTION_pidfile:
3708 case QEMU_OPTION_win2k_hack:
3709 win2k_install_hack = 1;
3711 case QEMU_OPTION_rtc_td_hack: {
3712 static GlobalProperty slew_lost_ticks = {
3713 .driver = "mc146818rtc",
3714 .property = "lost_tick_policy",
3718 qdev_prop_register_global(&slew_lost_ticks);
3721 case QEMU_OPTION_acpitable:
3722 opts = qemu_opts_parse_noisily(qemu_find_opts("acpi"),
3727 acpi_table_add(opts, &error_fatal);
3729 case QEMU_OPTION_smbios:
3730 opts = qemu_opts_parse_noisily(qemu_find_opts("smbios"),
3735 smbios_entry_add(opts, &error_fatal);
3737 case QEMU_OPTION_fwcfg:
3738 opts = qemu_opts_parse_noisily(qemu_find_opts("fw_cfg"),
3744 case QEMU_OPTION_enable_kvm:
3745 olist = qemu_find_opts("machine");
3746 qemu_opts_parse_noisily(olist, "accel=kvm", false);
3748 case QEMU_OPTION_enable_hax:
3749 olist = qemu_find_opts("machine");
3750 qemu_opts_parse_noisily(olist, "accel=hax", false);
3753 case QEMU_OPTION_machine:
3754 olist = qemu_find_opts("machine");
3755 opts = qemu_opts_parse_noisily(olist, optarg, true);
3760 case QEMU_OPTION_no_kvm:
3761 olist = qemu_find_opts("machine");
3762 qemu_opts_parse_noisily(olist, "accel=tcg", false);
3764 case QEMU_OPTION_no_kvm_pit: {
3765 warn_report("ignoring deprecated option");
3768 case QEMU_OPTION_no_kvm_pit_reinjection: {
3769 static GlobalProperty kvm_pit_lost_tick_policy = {
3770 .driver = "kvm-pit",
3771 .property = "lost_tick_policy",
3775 warn_report("deprecated, replaced by "
3776 "-global kvm-pit.lost_tick_policy=discard");
3777 qdev_prop_register_global(&kvm_pit_lost_tick_policy);
3780 case QEMU_OPTION_accel:
3781 accel_opts = qemu_opts_parse_noisily(qemu_find_opts("accel"),
3783 optarg = qemu_opt_get(accel_opts, "accel");
3784 if (!optarg || is_help_option(optarg)) {
3785 error_printf("Possible accelerators: kvm, xen, hax, tcg\n");
3788 opts = qemu_opts_create(qemu_find_opts("machine"), NULL,
3789 false, &error_abort);
3790 qemu_opt_set(opts, "accel", optarg, &error_abort);
3792 case QEMU_OPTION_usb:
3793 olist = qemu_find_opts("machine");
3794 qemu_opts_parse_noisily(olist, "usb=on", false);
3796 case QEMU_OPTION_usbdevice:
3797 error_report("'-usbdevice' is deprecated, please use "
3798 "'-device usb-...' instead");
3799 olist = qemu_find_opts("machine");
3800 qemu_opts_parse_noisily(olist, "usb=on", false);
3801 add_device_config(DEV_USB, optarg);
3803 case QEMU_OPTION_device:
3804 if (!qemu_opts_parse_noisily(qemu_find_opts("device"),
3809 case QEMU_OPTION_smp:
3810 if (!qemu_opts_parse_noisily(qemu_find_opts("smp-opts"),
3815 case QEMU_OPTION_vnc:
3816 vnc_parse(optarg, &error_fatal);
3818 case QEMU_OPTION_no_acpi:
3821 case QEMU_OPTION_no_hpet:
3824 case QEMU_OPTION_balloon:
3825 if (balloon_parse(optarg) < 0) {
3826 error_report("unknown -balloon argument %s", optarg);
3830 case QEMU_OPTION_no_reboot:
3833 case QEMU_OPTION_no_shutdown:
3836 case QEMU_OPTION_show_cursor:
3839 case QEMU_OPTION_uuid:
3840 if (qemu_uuid_parse(optarg, &qemu_uuid) < 0) {
3841 error_report("failed to parse UUID string: wrong format");
3844 qemu_uuid_set = true;
3846 case QEMU_OPTION_option_rom:
3847 if (nb_option_roms >= MAX_OPTION_ROMS) {
3848 error_report("too many option ROMs");
3851 opts = qemu_opts_parse_noisily(qemu_find_opts("option-rom"),
3856 option_rom[nb_option_roms].name = qemu_opt_get(opts, "romfile");
3857 option_rom[nb_option_roms].bootindex =
3858 qemu_opt_get_number(opts, "bootindex", -1);
3859 if (!option_rom[nb_option_roms].name) {
3860 error_report("Option ROM file is not specified");
3865 case QEMU_OPTION_semihosting:
3866 semihosting.enabled = true;
3867 semihosting.target = SEMIHOSTING_TARGET_AUTO;
3869 case QEMU_OPTION_semihosting_config:
3870 semihosting.enabled = true;
3871 opts = qemu_opts_parse_noisily(qemu_find_opts("semihosting-config"),
3874 semihosting.enabled = qemu_opt_get_bool(opts, "enable",
3876 const char *target = qemu_opt_get(opts, "target");
3877 if (target != NULL) {
3878 if (strcmp("native", target) == 0) {
3879 semihosting.target = SEMIHOSTING_TARGET_NATIVE;
3880 } else if (strcmp("gdb", target) == 0) {
3881 semihosting.target = SEMIHOSTING_TARGET_GDB;
3882 } else if (strcmp("auto", target) == 0) {
3883 semihosting.target = SEMIHOSTING_TARGET_AUTO;
3885 error_report("unsupported semihosting-config %s",
3890 semihosting.target = SEMIHOSTING_TARGET_AUTO;
3892 /* Set semihosting argument count and vector */
3893 qemu_opt_foreach(opts, add_semihosting_arg,
3894 &semihosting, NULL);
3896 error_report("unsupported semihosting-config %s", optarg);
3900 case QEMU_OPTION_tdf:
3901 warn_report("ignoring deprecated option");
3903 case QEMU_OPTION_name:
3904 opts = qemu_opts_parse_noisily(qemu_find_opts("name"),
3910 case QEMU_OPTION_prom_env:
3911 if (nb_prom_envs >= MAX_PROM_ENVS) {
3912 error_report("too many prom variables");
3915 prom_envs[nb_prom_envs] = optarg;
3918 case QEMU_OPTION_old_param:
3921 case QEMU_OPTION_clock:
3922 /* Clock options no longer exist. Keep this option for
3923 * backward compatibility.
3926 case QEMU_OPTION_startdate:
3927 configure_rtc_date_offset(optarg, 1);
3929 case QEMU_OPTION_rtc:
3930 opts = qemu_opts_parse_noisily(qemu_find_opts("rtc"), optarg,
3935 configure_rtc(opts);
3937 case QEMU_OPTION_tb_size:
3939 error_report("TCG is disabled");
3942 if (qemu_strtoul(optarg, NULL, 0, &tcg_tb_size) < 0) {
3943 error_report("Invalid argument to -tb-size");
3947 case QEMU_OPTION_icount:
3948 icount_opts = qemu_opts_parse_noisily(qemu_find_opts("icount"),
3954 case QEMU_OPTION_incoming:
3956 runstate_set(RUN_STATE_INMIGRATE);
3960 case QEMU_OPTION_only_migratable:
3962 * TODO: we can remove this option one day, and we
3965 * "-global migration.only-migratable=true"
3967 qemu_global_option("migration.only-migratable=true");
3969 case QEMU_OPTION_nodefaults:
3972 case QEMU_OPTION_xen_domid:
3973 if (!(xen_available())) {
3974 error_report("Option not supported for this target");
3977 xen_domid = atoi(optarg);
3979 case QEMU_OPTION_xen_create:
3980 if (!(xen_available())) {
3981 error_report("Option not supported for this target");
3984 xen_mode = XEN_CREATE;
3986 case QEMU_OPTION_xen_attach:
3987 if (!(xen_available())) {
3988 error_report("Option not supported for this target");
3991 xen_mode = XEN_ATTACH;
3993 case QEMU_OPTION_xen_domid_restrict:
3994 if (!(xen_available())) {
3995 error_report("Option not supported for this target");
3998 xen_domid_restrict = true;
4000 case QEMU_OPTION_trace:
4002 trace_file = trace_opt_parse(optarg);
4004 case QEMU_OPTION_readconfig:
4006 int ret = qemu_read_config_file(optarg);
4008 error_report("read config %s: %s", optarg,
4014 case QEMU_OPTION_spice:
4015 olist = qemu_find_opts("spice");
4017 error_report("spice support is disabled");
4020 opts = qemu_opts_parse_noisily(olist, optarg, false);
4026 case QEMU_OPTION_writeconfig:
4029 if (strcmp(optarg, "-") == 0) {
4032 fp = fopen(optarg, "w");
4034 error_report("open %s: %s", optarg,
4039 qemu_config_write(fp);
4045 case QEMU_OPTION_qtest:
4046 qtest_chrdev = optarg;
4048 case QEMU_OPTION_qtest_log:
4051 case QEMU_OPTION_sandbox:
4052 opts = qemu_opts_parse_noisily(qemu_find_opts("sandbox"),
4058 case QEMU_OPTION_add_fd:
4060 opts = qemu_opts_parse_noisily(qemu_find_opts("add-fd"),
4066 error_report("File descriptor passing is disabled on this "
4071 case QEMU_OPTION_object:
4072 opts = qemu_opts_parse_noisily(qemu_find_opts("object"),
4078 case QEMU_OPTION_realtime:
4079 opts = qemu_opts_parse_noisily(qemu_find_opts("realtime"),
4084 enable_mlock = qemu_opt_get_bool(opts, "mlock", true);
4086 case QEMU_OPTION_msg:
4087 opts = qemu_opts_parse_noisily(qemu_find_opts("msg"), optarg,
4092 configure_msg(opts);
4094 case QEMU_OPTION_dump_vmstate:
4095 if (vmstate_dump_file) {
4096 error_report("only one '-dump-vmstate' "
4097 "option may be given");
4100 vmstate_dump_file = fopen(optarg, "w");
4101 if (vmstate_dump_file == NULL) {
4102 error_report("open %s: %s", optarg, strerror(errno));
4107 os_parse_cmd_args(popt->index, optarg);
4112 * Clear error location left behind by the loop.
4113 * Best done right after the loop. Do not insert code here!
4117 replay_configure(icount_opts);
4119 machine_class = select_machine();
4121 set_memory_options(&ram_slots, &maxram_size, machine_class);
4124 rcu_disable_atfork();
4126 if (pid_file && qemu_create_pidfile(pid_file) != 0) {
4127 error_report("could not acquire pid file: %s", strerror(errno));
4131 if (qemu_init_main_loop(&main_loop_err)) {
4132 error_report_err(main_loop_err);
4136 if (qemu_opts_foreach(qemu_find_opts("sandbox"),
4137 parse_sandbox, NULL, NULL)) {
4141 if (qemu_opts_foreach(qemu_find_opts("name"),
4142 parse_name, NULL, NULL)) {
4147 if (qemu_opts_foreach(qemu_find_opts("add-fd"),
4148 parse_add_fd, NULL, NULL)) {
4152 if (qemu_opts_foreach(qemu_find_opts("add-fd"),
4153 cleanup_add_fd, NULL, NULL)) {
4158 current_machine = MACHINE(object_new(object_class_get_name(
4159 OBJECT_CLASS(machine_class))));
4160 if (machine_help_func(qemu_get_machine_opts(), current_machine)) {
4163 object_property_add_child(object_get_root(), "machine",
4164 OBJECT(current_machine), &error_abort);
4166 if (machine_class->minimum_page_bits) {
4167 if (!set_preferred_target_page_bits(machine_class->minimum_page_bits)) {
4168 /* This would be a board error: specifying a minimum smaller than
4169 * a target's compile-time fixed setting.
4171 g_assert_not_reached();
4175 cpu_exec_init_all();
4177 if (machine_class->hw_version) {
4178 qemu_set_hw_version(machine_class->hw_version);
4181 if (cpu_model && is_help_option(cpu_model)) {
4182 list_cpus(stdout, &fprintf, cpu_model);
4186 if (!trace_init_backends()) {
4189 trace_init_file(trace_file);
4191 /* Open the logfile at this point and set the log mask if necessary.
4194 qemu_set_log_filename(log_file, &error_fatal);
4199 mask = qemu_str_to_log_mask(log_mask);
4201 qemu_print_log_usage(stdout);
4209 /* If no data_dir is specified then try to find it relative to the
4211 if (data_dir_idx < ARRAY_SIZE(data_dir)) {
4212 data_dir[data_dir_idx] = os_find_datadir();
4213 if (data_dir[data_dir_idx] != NULL) {
4217 /* If all else fails use the install path specified when building. */
4218 if (data_dir_idx < ARRAY_SIZE(data_dir)) {
4219 data_dir[data_dir_idx++] = CONFIG_QEMU_DATADIR;
4222 /* -L help lists the data directories and exits. */
4223 if (list_data_dirs) {
4224 for (i = 0; i < data_dir_idx; i++) {
4225 printf("%s\n", data_dir[i]);
4230 smp_parse(qemu_opts_find(qemu_find_opts("smp-opts"), NULL));
4232 machine_class->max_cpus = machine_class->max_cpus ?: 1; /* Default to UP */
4233 if (max_cpus > machine_class->max_cpus) {
4234 error_report("Number of SMP CPUs requested (%d) exceeds max CPUs "
4235 "supported by machine '%s' (%d)", max_cpus,
4236 machine_class->name, machine_class->max_cpus);
4241 * Get the default machine options from the machine if it is not already
4242 * specified either by the configuration file or by the command line.
4244 if (machine_class->default_machine_opts) {
4245 qemu_opts_set_defaults(qemu_find_opts("machine"),
4246 machine_class->default_machine_opts, 0);
4249 qemu_opts_foreach(qemu_find_opts("device"),
4250 default_driver_check, NULL, NULL);
4251 qemu_opts_foreach(qemu_find_opts("global"),
4252 default_driver_check, NULL, NULL);
4254 if (!vga_model && !default_vga) {
4255 vga_interface_type = VGA_DEVICE;
4257 if (!has_defaults || machine_class->no_serial) {
4260 if (!has_defaults || machine_class->no_parallel) {
4261 default_parallel = 0;
4263 if (!has_defaults || !machine_class->use_virtcon) {
4264 default_virtcon = 0;
4266 if (!has_defaults || !machine_class->use_sclp) {
4269 if (!has_defaults || machine_class->no_floppy) {
4272 if (!has_defaults || machine_class->no_cdrom) {
4275 if (!has_defaults || machine_class->no_sdcard) {
4278 if (!has_defaults) {
4279 default_monitor = 0;
4284 if (is_daemonized()) {
4285 /* According to documentation and historically, -nographic redirects
4286 * serial port, parallel port and monitor to stdio, which does not work
4287 * with -daemonize. We can redirect these to null instead, but since
4288 * -nographic is legacy, let's just error out.
4289 * We disallow -nographic only if all other ports are not redirected
4290 * explicitly, to not break existing legacy setups which uses
4291 * -nographic _and_ redirects all ports explicitly - this is valid
4292 * usage, -nographic is just a no-op in this case.
4295 && (default_parallel || default_serial
4296 || default_monitor || default_virtcon)) {
4297 error_report("-nographic cannot be used with -daemonize");
4300 #ifdef CONFIG_CURSES
4301 if (display_type == DT_CURSES) {
4302 error_report("curses display cannot be used with -daemonize");
4309 if (default_parallel)
4310 add_device_config(DEV_PARALLEL, "null");
4311 if (default_serial && default_monitor) {
4312 add_device_config(DEV_SERIAL, "mon:stdio");
4313 } else if (default_virtcon && default_monitor) {
4314 add_device_config(DEV_VIRTCON, "mon:stdio");
4315 } else if (default_sclp && default_monitor) {
4316 add_device_config(DEV_SCLP, "mon:stdio");
4319 add_device_config(DEV_SERIAL, "stdio");
4320 if (default_virtcon)
4321 add_device_config(DEV_VIRTCON, "stdio");
4323 add_device_config(DEV_SCLP, "stdio");
4325 if (default_monitor)
4326 monitor_parse("stdio", "readline", false);
4330 add_device_config(DEV_SERIAL, "vc:80Cx24C");
4331 if (default_parallel)
4332 add_device_config(DEV_PARALLEL, "vc:80Cx24C");
4333 if (default_monitor)
4334 monitor_parse("vc:80Cx24C", "readline", false);
4335 if (default_virtcon)
4336 add_device_config(DEV_VIRTCON, "vc:80Cx24C");
4338 add_device_config(DEV_SCLP, "vc:80Cx24C");
4342 #if defined(CONFIG_VNC)
4343 if (!QTAILQ_EMPTY(&(qemu_find_opts("vnc")->head))) {
4347 if (display_type == DT_DEFAULT && !display_remote) {
4348 #if defined(CONFIG_GTK)
4349 display_type = DT_GTK;
4350 #elif defined(CONFIG_SDL)
4351 display_type = DT_SDL;
4352 #elif defined(CONFIG_COCOA)
4353 display_type = DT_COCOA;
4354 #elif defined(CONFIG_VNC)
4355 vnc_parse("localhost:0,to=99,id=default", &error_abort);
4357 display_type = DT_NONE;
4361 if ((no_frame || alt_grab || ctrl_grab) && display_type != DT_SDL) {
4362 error_report("-no-frame, -alt-grab and -ctrl-grab are only valid "
4363 "for SDL, ignoring option");
4365 if (no_quit && (display_type != DT_GTK && display_type != DT_SDL)) {
4366 error_report("-no-quit is only valid for GTK and SDL, "
4370 if (display_type == DT_GTK) {
4371 early_gtk_display_init(request_opengl);
4374 if (display_type == DT_SDL) {
4375 sdl_display_early_init(request_opengl);
4378 qemu_console_early_init();
4380 if (request_opengl == 1 && display_opengl == 0) {
4381 #if defined(CONFIG_OPENGL)
4382 error_report("OpenGL is not supported by the display");
4384 error_report("OpenGL support is disabled");
4392 if (qemu_opts_foreach(qemu_find_opts("object"),
4393 user_creatable_add_opts_foreach,
4394 object_create_initial, NULL)) {
4398 if (qemu_opts_foreach(qemu_find_opts("chardev"),
4399 chardev_init_func, NULL, NULL)) {
4403 #ifdef CONFIG_VIRTFS
4404 if (qemu_opts_foreach(qemu_find_opts("fsdev"),
4405 fsdev_init_func, NULL, NULL)) {
4410 if (qemu_opts_foreach(qemu_find_opts("device"),
4411 device_help_func, NULL, NULL)) {
4415 machine_opts = qemu_get_machine_opts();
4416 if (qemu_opt_foreach(machine_opts, machine_set_property, current_machine,
4418 object_unref(OBJECT(current_machine));
4422 configure_accelerator(current_machine);
4425 * Register all the global properties, including accel properties,
4426 * machine properties, and user-specified ones.
4428 register_global_properties(current_machine);
4431 * Migration object can only be created after global properties
4432 * are applied correctly.
4434 migration_object_init();
4437 qtest_init(qtest_chrdev, qtest_log, &error_fatal);
4440 machine_opts = qemu_get_machine_opts();
4441 kernel_filename = qemu_opt_get(machine_opts, "kernel");
4442 initrd_filename = qemu_opt_get(machine_opts, "initrd");
4443 kernel_cmdline = qemu_opt_get(machine_opts, "append");
4444 bios_name = qemu_opt_get(machine_opts, "firmware");
4446 opts = qemu_opts_find(qemu_find_opts("boot-opts"), NULL);
4448 boot_order = qemu_opt_get(opts, "order");
4450 validate_bootdevices(boot_order, &error_fatal);
4453 boot_once = qemu_opt_get(opts, "once");
4455 validate_bootdevices(boot_once, &error_fatal);
4458 boot_menu = qemu_opt_get_bool(opts, "menu", boot_menu);
4459 boot_strict = qemu_opt_get_bool(opts, "strict", false);
4463 boot_order = machine_class->default_boot_order;
4466 if (!kernel_cmdline) {
4467 kernel_cmdline = "";
4468 current_machine->kernel_cmdline = (char *)kernel_cmdline;
4471 linux_boot = (kernel_filename != NULL);
4473 if (!linux_boot && *kernel_cmdline != '\0') {
4474 error_report("-append only allowed with -kernel option");
4478 if (!linux_boot && initrd_filename != NULL) {
4479 error_report("-initrd only allowed with -kernel option");
4483 if (semihosting_enabled() && !semihosting_get_argc() && kernel_filename) {
4484 /* fall back to the -kernel/-append */
4485 semihosting_arg_fallback(kernel_filename, kernel_cmdline);
4488 os_set_line_buffering();
4490 /* spice needs the timers to be initialized by this point */
4495 if (!tcg_enabled()) {
4496 error_report("-icount is not allowed with hardware virtualization");
4499 configure_icount(icount_opts, &error_abort);
4500 qemu_opts_del(icount_opts);
4503 if (tcg_enabled()) {
4504 qemu_tcg_configure(accel_opts, &error_fatal);
4508 QemuOptsList *net = qemu_find_opts("net");
4509 qemu_opts_set(net, NULL, "type", "nic", &error_abort);
4511 qemu_opts_set(net, NULL, "type", "user", &error_abort);
4517 if (net_init_clients() < 0) {
4521 if (qemu_opts_foreach(qemu_find_opts("object"),
4522 user_creatable_add_opts_foreach,
4523 object_create_delayed, NULL)) {
4528 if (tpm_init() < 0) {
4533 /* init the bluetooth world */
4534 if (foreach_device_config(DEV_BT, bt_parse))
4537 if (!xen_enabled()) {
4538 /* On 32-bit hosts, QEMU is limited by virtual address space */
4539 if (ram_size > (2047 << 20) && HOST_LONG_BITS == 32) {
4540 error_report("at most 2047 MB RAM can be simulated");
4548 /* If the currently selected machine wishes to override the units-per-bus
4549 * property of its default HBA interface type, do so now. */
4550 if (machine_class->units_per_default_bus) {
4551 override_max_devs(machine_class->block_default_type,
4552 machine_class->units_per_default_bus);
4555 /* open the virtual block devices */
4556 while (!QSIMPLEQ_EMPTY(&bdo_queue)) {
4557 BlockdevOptions_queue *bdo = QSIMPLEQ_FIRST(&bdo_queue);
4559 QSIMPLEQ_REMOVE_HEAD(&bdo_queue, entry);
4560 loc_push_restore(&bdo->loc);
4561 qmp_blockdev_add(bdo->bdo, &error_fatal);
4563 qapi_free_BlockdevOptions(bdo->bdo);
4566 if (snapshot || replay_mode != REPLAY_MODE_NONE) {
4567 qemu_opts_foreach(qemu_find_opts("drive"), drive_enable_snapshot,
4570 if (qemu_opts_foreach(qemu_find_opts("drive"), drive_init_func,
4571 &machine_class->block_default_type, NULL)) {
4575 default_drive(default_cdrom, snapshot, machine_class->block_default_type, 2,
4577 default_drive(default_floppy, snapshot, IF_FLOPPY, 0, FD_OPTS);
4578 default_drive(default_sdcard, snapshot, IF_SD, 0, SD_OPTS);
4580 parse_numa_opts(current_machine);
4582 if (qemu_opts_foreach(qemu_find_opts("mon"),
4583 mon_init_func, NULL, NULL)) {
4587 if (foreach_device_config(DEV_SERIAL, serial_parse) < 0)
4589 if (foreach_device_config(DEV_PARALLEL, parallel_parse) < 0)
4591 if (foreach_device_config(DEV_VIRTCON, virtcon_parse) < 0)
4593 if (foreach_device_config(DEV_SCLP, sclp_parse) < 0) {
4596 if (foreach_device_config(DEV_DEBUGCON, debugcon_parse) < 0)
4599 /* If no default VGA is requested, the default is "none". */
4601 if (machine_class->default_display) {
4602 vga_model = machine_class->default_display;
4603 } else if (vga_interface_available(VGA_CIRRUS)) {
4604 vga_model = "cirrus";
4605 } else if (vga_interface_available(VGA_STD)) {
4610 select_vgahw(vga_model);
4614 i = select_watchdog(watchdog);
4616 exit (i == 1 ? 1 : 0);
4619 /* This checkpoint is required by replay to separate prior clock
4620 reading from the other reads, because timer polling functions query
4621 clock values from the log. */
4622 replay_checkpoint(CHECKPOINT_INIT);
4623 qdev_machine_init();
4625 current_machine->ram_size = ram_size;
4626 current_machine->maxram_size = maxram_size;
4627 current_machine->ram_slots = ram_slots;
4628 current_machine->boot_order = boot_order;
4629 current_machine->cpu_model = cpu_model;
4631 machine_run_board_init(current_machine);
4637 if (hax_enabled()) {
4641 if (qemu_opts_foreach(qemu_find_opts("fw_cfg"),
4642 parse_fw_cfg, fw_cfg_find(), NULL) != 0) {
4646 /* init USB devices */
4647 if (machine_usb(current_machine)) {
4648 if (foreach_device_config(DEV_USB, usb_parse) < 0)
4652 /* Check if IGD GFX passthrough. */
4655 /* init generic devices */
4656 rom_set_order_override(FW_CFG_ORDER_OVERRIDE_DEVICE);
4657 if (qemu_opts_foreach(qemu_find_opts("device"),
4658 device_init_func, NULL, NULL)) {
4662 cpu_synchronize_all_post_init();
4664 rom_reset_order_override();
4667 * Create frontends for -drive if=scsi leftovers.
4668 * Normally, frontends for -drive get created by machine
4669 * initialization for onboard SCSI HBAs. However, we create a few
4670 * more ever since SCSI qdevification, but this is pretty much an
4671 * implementation accident, and deprecated.
4673 scsi_legacy_handle_cmdline();
4675 /* Did we create any drives that we failed to create a device for? */
4676 drive_check_orphaned();
4678 /* Don't warn about the default network setup that you get if
4679 * no command line -net or -netdev options are specified. There
4680 * are two cases that we would otherwise complain about:
4681 * (1) board doesn't support a NIC but the implicit "-net nic"
4683 * (2) CONFIG_SLIRP not set, in which case the implicit "-net nic"
4684 * sets up a nic that isn't connected to anything.
4687 net_check_clients();
4692 qemu_boot_set(boot_once, &error_fatal);
4693 qemu_register_reset(restore_boot_order, g_strdup(boot_order));
4696 ds = init_displaystate();
4698 /* init local displays */
4699 switch (display_type) {
4701 curses_display_init(ds, full_screen);
4704 sdl_display_init(ds, full_screen, no_frame);
4707 cocoa_display_init(ds, full_screen);
4710 gtk_display_init(ds, full_screen, grab_on_hover);
4716 /* must be after terminal init, SDL library changes signal handlers */
4717 os_setup_signal_handling();
4719 /* init remote displays */
4721 qemu_opts_foreach(qemu_find_opts("vnc"),
4722 vnc_init_func, NULL, NULL);
4726 qemu_spice_display_init();
4729 #ifdef CONFIG_OPENGL_DMABUF
4730 if (display_type == DT_EGL) {
4731 egl_headless_init();
4735 if (foreach_device_config(DEV_GDB, gdbserver_start) < 0) {
4739 qdev_machine_creation_done();
4741 /* TODO: once all bus devices are qdevified, this should be done
4742 * when bus is created by qdev.c */
4743 qemu_register_reset(qbus_reset_all_fn, sysbus_get_default());
4744 qemu_run_machine_init_done_notifiers();
4746 if (rom_check_and_register_reset() != 0) {
4747 error_report("rom check and register reset failed");
4753 /* This checkpoint is required by replay to separate prior clock
4754 reading from the other reads, because timer polling functions query
4755 clock values from the log. */
4756 replay_checkpoint(CHECKPOINT_RESET);
4757 qemu_system_reset(SHUTDOWN_CAUSE_NONE);
4758 register_global_state();
4759 if (replay_mode != REPLAY_MODE_NONE) {
4760 replay_vmstate_init();
4761 } else if (loadvm) {
4762 Error *local_err = NULL;
4763 if (load_snapshot(loadvm, &local_err) < 0) {
4764 error_report_err(local_err);
4769 qdev_prop_check_globals();
4770 if (vmstate_dump_file) {
4772 dump_vmstate_json_to_file(vmstate_dump_file);
4777 Error *local_err = NULL;
4778 qemu_start_incoming_migration(incoming, &local_err);
4780 error_reportf_err(local_err, "-incoming %s: ", incoming);
4783 } else if (autostart) {
4790 replay_disable_events();
4791 iothread_stop_all();
4797 /* vhost-user must be cleaned up before chardevs. */
4802 /* TODO: unref root container, check all devices are ok */