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_POSTMIGRATE },
625 { RUN_STATE_PAUSED, RUN_STATE_PRELAUNCH },
626 { RUN_STATE_PAUSED, RUN_STATE_COLO},
628 { RUN_STATE_POSTMIGRATE, RUN_STATE_RUNNING },
629 { RUN_STATE_POSTMIGRATE, RUN_STATE_FINISH_MIGRATE },
630 { RUN_STATE_POSTMIGRATE, RUN_STATE_PRELAUNCH },
632 { RUN_STATE_PRELAUNCH, RUN_STATE_RUNNING },
633 { RUN_STATE_PRELAUNCH, RUN_STATE_FINISH_MIGRATE },
634 { RUN_STATE_PRELAUNCH, RUN_STATE_INMIGRATE },
636 { RUN_STATE_FINISH_MIGRATE, RUN_STATE_RUNNING },
637 { RUN_STATE_FINISH_MIGRATE, RUN_STATE_PAUSED },
638 { RUN_STATE_FINISH_MIGRATE, RUN_STATE_POSTMIGRATE },
639 { RUN_STATE_FINISH_MIGRATE, RUN_STATE_PRELAUNCH },
640 { RUN_STATE_FINISH_MIGRATE, RUN_STATE_COLO},
642 { RUN_STATE_RESTORE_VM, RUN_STATE_RUNNING },
643 { RUN_STATE_RESTORE_VM, RUN_STATE_PRELAUNCH },
645 { RUN_STATE_COLO, RUN_STATE_RUNNING },
647 { RUN_STATE_RUNNING, RUN_STATE_DEBUG },
648 { RUN_STATE_RUNNING, RUN_STATE_INTERNAL_ERROR },
649 { RUN_STATE_RUNNING, RUN_STATE_IO_ERROR },
650 { RUN_STATE_RUNNING, RUN_STATE_PAUSED },
651 { RUN_STATE_RUNNING, RUN_STATE_FINISH_MIGRATE },
652 { RUN_STATE_RUNNING, RUN_STATE_RESTORE_VM },
653 { RUN_STATE_RUNNING, RUN_STATE_SAVE_VM },
654 { RUN_STATE_RUNNING, RUN_STATE_SHUTDOWN },
655 { RUN_STATE_RUNNING, RUN_STATE_WATCHDOG },
656 { RUN_STATE_RUNNING, RUN_STATE_GUEST_PANICKED },
657 { RUN_STATE_RUNNING, RUN_STATE_COLO},
659 { RUN_STATE_SAVE_VM, RUN_STATE_RUNNING },
661 { RUN_STATE_SHUTDOWN, RUN_STATE_PAUSED },
662 { RUN_STATE_SHUTDOWN, RUN_STATE_FINISH_MIGRATE },
663 { RUN_STATE_SHUTDOWN, RUN_STATE_PRELAUNCH },
665 { RUN_STATE_DEBUG, RUN_STATE_SUSPENDED },
666 { RUN_STATE_RUNNING, RUN_STATE_SUSPENDED },
667 { RUN_STATE_SUSPENDED, RUN_STATE_RUNNING },
668 { RUN_STATE_SUSPENDED, RUN_STATE_FINISH_MIGRATE },
669 { RUN_STATE_SUSPENDED, RUN_STATE_PRELAUNCH },
670 { RUN_STATE_SUSPENDED, RUN_STATE_COLO},
672 { RUN_STATE_WATCHDOG, RUN_STATE_RUNNING },
673 { RUN_STATE_WATCHDOG, RUN_STATE_FINISH_MIGRATE },
674 { RUN_STATE_WATCHDOG, RUN_STATE_PRELAUNCH },
675 { RUN_STATE_WATCHDOG, RUN_STATE_COLO},
677 { RUN_STATE_GUEST_PANICKED, RUN_STATE_RUNNING },
678 { RUN_STATE_GUEST_PANICKED, RUN_STATE_FINISH_MIGRATE },
679 { RUN_STATE_GUEST_PANICKED, RUN_STATE_PRELAUNCH },
681 { RUN_STATE__MAX, RUN_STATE__MAX },
684 static bool runstate_valid_transitions[RUN_STATE__MAX][RUN_STATE__MAX];
686 bool runstate_check(RunState state)
688 return current_run_state == state;
691 bool runstate_store(char *str, size_t size)
693 const char *state = RunState_str(current_run_state);
694 size_t len = strlen(state) + 1;
699 memcpy(str, state, len);
703 static void runstate_init(void)
705 const RunStateTransition *p;
707 memset(&runstate_valid_transitions, 0, sizeof(runstate_valid_transitions));
708 for (p = &runstate_transitions_def[0]; p->from != RUN_STATE__MAX; p++) {
709 runstate_valid_transitions[p->from][p->to] = true;
712 qemu_mutex_init(&vmstop_lock);
715 /* This function will abort() on invalid state transitions */
716 void runstate_set(RunState new_state)
718 assert(new_state < RUN_STATE__MAX);
720 if (current_run_state == new_state) {
724 if (!runstate_valid_transitions[current_run_state][new_state]) {
725 error_report("invalid runstate transition: '%s' -> '%s'",
726 RunState_str(current_run_state),
727 RunState_str(new_state));
730 trace_runstate_set(new_state);
731 current_run_state = new_state;
734 int runstate_is_running(void)
736 return runstate_check(RUN_STATE_RUNNING);
739 bool runstate_needs_reset(void)
741 return runstate_check(RUN_STATE_INTERNAL_ERROR) ||
742 runstate_check(RUN_STATE_SHUTDOWN);
745 StatusInfo *qmp_query_status(Error **errp)
747 StatusInfo *info = g_malloc0(sizeof(*info));
749 info->running = runstate_is_running();
750 info->singlestep = singlestep;
751 info->status = current_run_state;
756 bool qemu_vmstop_requested(RunState *r)
758 qemu_mutex_lock(&vmstop_lock);
759 *r = vmstop_requested;
760 vmstop_requested = RUN_STATE__MAX;
761 qemu_mutex_unlock(&vmstop_lock);
762 return *r < RUN_STATE__MAX;
765 void qemu_system_vmstop_request_prepare(void)
767 qemu_mutex_lock(&vmstop_lock);
770 void qemu_system_vmstop_request(RunState state)
772 vmstop_requested = state;
773 qemu_mutex_unlock(&vmstop_lock);
777 /***********************************************************/
778 /* real time host monotonic timer */
780 static time_t qemu_time(void)
782 return qemu_clock_get_ms(QEMU_CLOCK_HOST) / 1000;
785 /***********************************************************/
786 /* host time/date access */
787 void qemu_get_timedate(struct tm *tm, int offset)
789 time_t ti = qemu_time();
792 if (rtc_date_offset == -1) {
796 localtime_r(&ti, tm);
798 ti -= rtc_date_offset;
803 int qemu_timedate_diff(struct tm *tm)
807 if (rtc_date_offset == -1)
809 seconds = mktimegm(tm);
812 tmp.tm_isdst = -1; /* use timezone to figure it out */
813 seconds = mktime(&tmp);
816 seconds = mktimegm(tm) + rtc_date_offset;
818 return seconds - qemu_time();
821 static void configure_rtc_date_offset(const char *startdate, int legacy)
823 time_t rtc_start_date;
826 if (!strcmp(startdate, "now") && legacy) {
827 rtc_date_offset = -1;
829 if (sscanf(startdate, "%d-%d-%dT%d:%d:%d",
837 } else if (sscanf(startdate, "%d-%d-%d",
849 rtc_start_date = mktimegm(&tm);
850 if (rtc_start_date == -1) {
852 error_report("invalid date format");
853 error_printf("valid formats: "
854 "'2006-06-17T16:01:21' or '2006-06-17'\n");
857 rtc_date_offset = qemu_time() - rtc_start_date;
861 static void configure_rtc(QemuOpts *opts)
865 value = qemu_opt_get(opts, "base");
867 if (!strcmp(value, "utc")) {
869 } else if (!strcmp(value, "localtime")) {
870 Error *blocker = NULL;
872 error_setg(&blocker, QERR_REPLAY_NOT_SUPPORTED,
873 "-rtc base=localtime");
874 replay_add_blocker(blocker);
876 configure_rtc_date_offset(value, 0);
879 value = qemu_opt_get(opts, "clock");
881 if (!strcmp(value, "host")) {
882 rtc_clock = QEMU_CLOCK_HOST;
883 } else if (!strcmp(value, "rt")) {
884 rtc_clock = QEMU_CLOCK_REALTIME;
885 } else if (!strcmp(value, "vm")) {
886 rtc_clock = QEMU_CLOCK_VIRTUAL;
888 error_report("invalid option value '%s'", value);
892 value = qemu_opt_get(opts, "driftfix");
894 if (!strcmp(value, "slew")) {
895 static GlobalProperty slew_lost_ticks = {
896 .driver = "mc146818rtc",
897 .property = "lost_tick_policy",
901 qdev_prop_register_global(&slew_lost_ticks);
902 } else if (!strcmp(value, "none")) {
903 /* discard is default */
905 error_report("invalid option value '%s'", value);
911 /***********************************************************/
912 /* Bluetooth support */
915 static struct HCIInfo *hci_table[MAX_NICS];
917 struct HCIInfo *qemu_next_hci(void)
919 if (cur_hci == nb_hcis)
922 return hci_table[cur_hci++];
925 static int bt_hci_parse(const char *str)
930 if (nb_hcis >= MAX_NICS) {
931 error_report("too many bluetooth HCIs (max %i)", MAX_NICS);
944 bdaddr.b[5] = 0x56 + nb_hcis;
945 hci->bdaddr_set(hci, bdaddr.b);
947 hci_table[nb_hcis++] = hci;
952 static void bt_vhci_add(int vlan_id)
954 struct bt_scatternet_s *vlan = qemu_find_bt_vlan(vlan_id);
957 warn_report("adding a VHCI to an empty scatternet %i",
960 bt_vhci_init(bt_new_hci(vlan));
963 static struct bt_device_s *bt_device_add(const char *opt)
965 struct bt_scatternet_s *vlan;
967 char *endp = strstr(opt, ",vlan=");
968 int len = (endp ? endp - opt : strlen(opt)) + 1;
971 pstrcpy(devname, MIN(sizeof(devname), len), opt);
974 vlan_id = strtol(endp + 6, &endp, 0);
976 error_report("unrecognised bluetooth vlan Id");
981 vlan = qemu_find_bt_vlan(vlan_id);
984 warn_report("adding a slave device to an empty scatternet %i",
987 if (!strcmp(devname, "keyboard"))
988 return bt_keyboard_init(vlan);
990 error_report("unsupported bluetooth device '%s'", devname);
994 static int bt_parse(const char *opt)
996 const char *endp, *p;
999 if (strstart(opt, "hci", &endp)) {
1000 if (!*endp || *endp == ',') {
1002 if (!strstart(endp, ",vlan=", 0))
1005 return bt_hci_parse(opt);
1007 } else if (strstart(opt, "vhci", &endp)) {
1008 if (!*endp || *endp == ',') {
1010 if (strstart(endp, ",vlan=", &p)) {
1011 vlan = strtol(p, (char **) &endp, 0);
1013 error_report("bad scatternet '%s'", p);
1017 error_report("bad parameter '%s'", endp + 1);
1026 } else if (strstart(opt, "device:", &endp))
1027 return !bt_device_add(endp);
1029 error_report("bad bluetooth parameter '%s'", opt);
1033 static int parse_sandbox(void *opaque, QemuOpts *opts, Error **errp)
1035 /* FIXME: change this to true for 1.3 */
1036 if (qemu_opt_get_bool(opts, "enable", false)) {
1037 #ifdef CONFIG_SECCOMP
1038 if (seccomp_start() < 0) {
1039 error_report("failed to install seccomp syscall filter "
1044 error_report("seccomp support is disabled");
1052 static int parse_name(void *opaque, QemuOpts *opts, Error **errp)
1054 const char *proc_name;
1056 if (qemu_opt_get(opts, "debug-threads")) {
1057 qemu_thread_naming(qemu_opt_get_bool(opts, "debug-threads", false));
1059 qemu_name = qemu_opt_get(opts, "guest");
1061 proc_name = qemu_opt_get(opts, "process");
1063 os_set_proc_name(proc_name);
1069 bool defaults_enabled(void)
1071 return has_defaults;
1075 static int parse_add_fd(void *opaque, QemuOpts *opts, Error **errp)
1077 int fd, dupfd, flags;
1079 const char *fd_opaque = NULL;
1082 fd = qemu_opt_get_number(opts, "fd", -1);
1083 fdset_id = qemu_opt_get_number(opts, "set", -1);
1084 fd_opaque = qemu_opt_get(opts, "opaque");
1087 error_report("fd option is required and must be non-negative");
1091 if (fd <= STDERR_FILENO) {
1092 error_report("fd cannot be a standard I/O stream");
1097 * All fds inherited across exec() necessarily have FD_CLOEXEC
1098 * clear, while qemu sets FD_CLOEXEC on all other fds used internally.
1100 flags = fcntl(fd, F_GETFD);
1101 if (flags == -1 || (flags & FD_CLOEXEC)) {
1102 error_report("fd is not valid or already in use");
1107 error_report("set option is required and must be non-negative");
1111 #ifdef F_DUPFD_CLOEXEC
1112 dupfd = fcntl(fd, F_DUPFD_CLOEXEC, 0);
1116 qemu_set_cloexec(dupfd);
1120 error_report("error duplicating fd: %s", strerror(errno));
1124 /* add the duplicate fd, and optionally the opaque string, to the fd set */
1125 fdinfo = monitor_fdset_add_fd(dupfd, true, fdset_id, !!fd_opaque, fd_opaque,
1132 static int cleanup_add_fd(void *opaque, QemuOpts *opts, Error **errp)
1136 fd = qemu_opt_get_number(opts, "fd", -1);
1143 /***********************************************************/
1144 /* QEMU Block devices */
1146 #define HD_OPTS "media=disk"
1147 #define CDROM_OPTS "media=cdrom"
1149 #define PFLASH_OPTS ""
1153 static int drive_init_func(void *opaque, QemuOpts *opts, Error **errp)
1155 BlockInterfaceType *block_default_type = opaque;
1157 return drive_new(opts, *block_default_type) == NULL;
1160 static int drive_enable_snapshot(void *opaque, QemuOpts *opts, Error **errp)
1162 if (qemu_opt_get(opts, "snapshot") == NULL) {
1163 qemu_opt_set(opts, "snapshot", "on", &error_abort);
1168 static void default_drive(int enable, int snapshot, BlockInterfaceType type,
1169 int index, const char *optstr)
1174 if (!enable || drive_get_by_index(type, index)) {
1178 opts = drive_add(type, index, NULL, optstr);
1180 drive_enable_snapshot(NULL, opts, NULL);
1183 dinfo = drive_new(opts, type);
1187 dinfo->is_default = true;
1191 static QemuOptsList qemu_smp_opts = {
1193 .implied_opt_name = "cpus",
1194 .merge_lists = true,
1195 .head = QTAILQ_HEAD_INITIALIZER(qemu_smp_opts.head),
1199 .type = QEMU_OPT_NUMBER,
1202 .type = QEMU_OPT_NUMBER,
1205 .type = QEMU_OPT_NUMBER,
1208 .type = QEMU_OPT_NUMBER,
1211 .type = QEMU_OPT_NUMBER,
1213 { /*End of list */ }
1217 static void smp_parse(QemuOpts *opts)
1220 unsigned cpus = qemu_opt_get_number(opts, "cpus", 0);
1221 unsigned sockets = qemu_opt_get_number(opts, "sockets", 0);
1222 unsigned cores = qemu_opt_get_number(opts, "cores", 0);
1223 unsigned threads = qemu_opt_get_number(opts, "threads", 0);
1225 /* compute missing values, prefer sockets over cores over threads */
1226 if (cpus == 0 || sockets == 0) {
1227 sockets = sockets > 0 ? sockets : 1;
1228 cores = cores > 0 ? cores : 1;
1229 threads = threads > 0 ? threads : 1;
1231 cpus = cores * threads * sockets;
1233 } else if (cores == 0) {
1234 threads = threads > 0 ? threads : 1;
1235 cores = cpus / (sockets * threads);
1236 cores = cores > 0 ? cores : 1;
1237 } else if (threads == 0) {
1238 threads = cpus / (cores * sockets);
1239 threads = threads > 0 ? threads : 1;
1240 } else if (sockets * cores * threads < cpus) {
1241 error_report("cpu topology: "
1242 "sockets (%u) * cores (%u) * threads (%u) < "
1244 sockets, cores, threads, cpus);
1248 max_cpus = qemu_opt_get_number(opts, "maxcpus", cpus);
1250 if (max_cpus < cpus) {
1251 error_report("maxcpus must be equal to or greater than smp");
1255 if (sockets * cores * threads > max_cpus) {
1256 error_report("cpu topology: "
1257 "sockets (%u) * cores (%u) * threads (%u) > "
1259 sockets, cores, threads, max_cpus);
1265 smp_threads = threads;
1269 Error *blocker = NULL;
1270 error_setg(&blocker, QERR_REPLAY_NOT_SUPPORTED, "smp");
1271 replay_add_blocker(blocker);
1275 static void realtime_init(void)
1278 if (os_mlock() < 0) {
1279 error_report("locking memory failed");
1286 static void configure_msg(QemuOpts *opts)
1288 enable_timestamp_msg = qemu_opt_get_bool(opts, "timestamp", true);
1291 /***********************************************************/
1294 typedef struct SemihostingConfig {
1296 SemihostingTarget target;
1299 const char *cmdline; /* concatenated argv */
1300 } SemihostingConfig;
1302 static SemihostingConfig semihosting;
1304 bool semihosting_enabled(void)
1306 return semihosting.enabled;
1309 SemihostingTarget semihosting_get_target(void)
1311 return semihosting.target;
1314 const char *semihosting_get_arg(int i)
1316 if (i >= semihosting.argc) {
1319 return semihosting.argv[i];
1322 int semihosting_get_argc(void)
1324 return semihosting.argc;
1327 const char *semihosting_get_cmdline(void)
1329 if (semihosting.cmdline == NULL && semihosting.argc > 0) {
1330 semihosting.cmdline = g_strjoinv(" ", (gchar **)semihosting.argv);
1332 return semihosting.cmdline;
1335 static int add_semihosting_arg(void *opaque,
1336 const char *name, const char *val,
1339 SemihostingConfig *s = opaque;
1340 if (strcmp(name, "arg") == 0) {
1342 /* one extra element as g_strjoinv() expects NULL-terminated array */
1343 s->argv = g_realloc(s->argv, (s->argc + 1) * sizeof(void *));
1344 s->argv[s->argc - 1] = val;
1345 s->argv[s->argc] = NULL;
1350 /* Use strings passed via -kernel/-append to initialize semihosting.argv[] */
1351 static inline void semihosting_arg_fallback(const char *file, const char *cmd)
1356 add_semihosting_arg(&semihosting, "arg", file, NULL);
1358 /* split -append and initialize argv[1..n] */
1359 cmd_token = strtok(g_strdup(cmd), " ");
1361 add_semihosting_arg(&semihosting, "arg", cmd_token, NULL);
1362 cmd_token = strtok(NULL, " ");
1366 /* Now we still need this for compatibility with XEN. */
1367 bool has_igd_gfx_passthru;
1368 static void igd_gfx_passthru(void)
1370 has_igd_gfx_passthru = current_machine->igd_gfx_passthru;
1373 /***********************************************************/
1376 static int usb_device_add(const char *devname)
1378 USBDevice *dev = NULL;
1379 #ifndef CONFIG_LINUX
1383 if (!machine_usb(current_machine)) {
1387 /* drivers with .usbdevice_name entry in USBDeviceInfo */
1388 dev = usbdevice_create(devname);
1392 /* the other ones */
1393 #ifndef CONFIG_LINUX
1394 /* only the linux version is qdev-ified, usb-bsd still needs this */
1395 if (strstart(devname, "host:", &p)) {
1396 dev = usb_host_device_open(usb_bus_find(-1), p);
1406 static int usb_device_del(const char *devname)
1411 if (strstart(devname, "host:", &p)) {
1415 if (!machine_usb(current_machine)) {
1419 p = strchr(devname, '.');
1422 bus_num = strtoul(devname, NULL, 0);
1423 addr = strtoul(p + 1, NULL, 0);
1425 return usb_device_delete_addr(bus_num, addr);
1428 static int usb_parse(const char *cmdline)
1431 r = usb_device_add(cmdline);
1433 error_report("could not add USB device '%s'", cmdline);
1438 void hmp_usb_add(Monitor *mon, const QDict *qdict)
1440 const char *devname = qdict_get_str(qdict, "devname");
1442 error_report("usb_add is deprecated, please use device_add instead");
1444 if (usb_device_add(devname) < 0) {
1445 error_report("could not add USB device '%s'", devname);
1449 void hmp_usb_del(Monitor *mon, const QDict *qdict)
1451 const char *devname = qdict_get_str(qdict, "devname");
1453 error_report("usb_del is deprecated, please use device_del instead");
1455 if (usb_device_del(devname) < 0) {
1456 error_report("could not delete USB device '%s'", devname);
1460 /***********************************************************/
1461 /* machine registration */
1463 MachineState *current_machine;
1465 static MachineClass *find_machine(const char *name)
1467 GSList *el, *machines = object_class_get_list(TYPE_MACHINE, false);
1468 MachineClass *mc = NULL;
1470 for (el = machines; el; el = el->next) {
1471 MachineClass *temp = el->data;
1473 if (!strcmp(temp->name, name)) {
1478 !strcmp(temp->alias, name)) {
1484 g_slist_free(machines);
1488 MachineClass *find_default_machine(void)
1490 GSList *el, *machines = object_class_get_list(TYPE_MACHINE, false);
1491 MachineClass *mc = NULL;
1493 for (el = machines; el; el = el->next) {
1494 MachineClass *temp = el->data;
1496 if (temp->is_default) {
1502 g_slist_free(machines);
1506 MachineInfoList *qmp_query_machines(Error **errp)
1508 GSList *el, *machines = object_class_get_list(TYPE_MACHINE, false);
1509 MachineInfoList *mach_list = NULL;
1511 for (el = machines; el; el = el->next) {
1512 MachineClass *mc = el->data;
1513 MachineInfoList *entry;
1516 info = g_malloc0(sizeof(*info));
1517 if (mc->is_default) {
1518 info->has_is_default = true;
1519 info->is_default = true;
1523 info->has_alias = true;
1524 info->alias = g_strdup(mc->alias);
1527 info->name = g_strdup(mc->name);
1528 info->cpu_max = !mc->max_cpus ? 1 : mc->max_cpus;
1529 info->hotpluggable_cpus = mc->has_hotpluggable_cpus;
1531 entry = g_malloc0(sizeof(*entry));
1532 entry->value = info;
1533 entry->next = mach_list;
1537 g_slist_free(machines);
1541 static int machine_help_func(QemuOpts *opts, MachineState *machine)
1543 ObjectProperty *prop;
1544 ObjectPropertyIterator iter;
1546 if (!qemu_opt_has_help_opt(opts)) {
1550 object_property_iter_init(&iter, OBJECT(machine));
1551 while ((prop = object_property_iter_next(&iter))) {
1556 error_printf("%s.%s=%s", MACHINE_GET_CLASS(machine)->name,
1557 prop->name, prop->type);
1558 if (prop->description) {
1559 error_printf(" (%s)\n", prop->description);
1568 /***********************************************************/
1569 /* main execution loop */
1571 struct vm_change_state_entry {
1572 VMChangeStateHandler *cb;
1574 QLIST_ENTRY (vm_change_state_entry) entries;
1577 static QLIST_HEAD(vm_change_state_head, vm_change_state_entry) vm_change_state_head;
1579 VMChangeStateEntry *qemu_add_vm_change_state_handler(VMChangeStateHandler *cb,
1582 VMChangeStateEntry *e;
1584 e = g_malloc0(sizeof (*e));
1588 QLIST_INSERT_HEAD(&vm_change_state_head, e, entries);
1592 void qemu_del_vm_change_state_handler(VMChangeStateEntry *e)
1594 QLIST_REMOVE (e, entries);
1598 void vm_state_notify(int running, RunState state)
1600 VMChangeStateEntry *e, *next;
1602 trace_vm_state_notify(running, state);
1604 QLIST_FOREACH_SAFE(e, &vm_change_state_head, entries, next) {
1605 e->cb(e->opaque, running, state);
1609 static ShutdownCause reset_requested;
1610 static ShutdownCause shutdown_requested;
1611 static int shutdown_signal;
1612 static pid_t shutdown_pid;
1613 static int powerdown_requested;
1614 static int debug_requested;
1615 static int suspend_requested;
1616 static WakeupReason wakeup_reason;
1617 static NotifierList powerdown_notifiers =
1618 NOTIFIER_LIST_INITIALIZER(powerdown_notifiers);
1619 static NotifierList suspend_notifiers =
1620 NOTIFIER_LIST_INITIALIZER(suspend_notifiers);
1621 static NotifierList wakeup_notifiers =
1622 NOTIFIER_LIST_INITIALIZER(wakeup_notifiers);
1623 static uint32_t wakeup_reason_mask = ~(1 << QEMU_WAKEUP_REASON_NONE);
1625 ShutdownCause qemu_shutdown_requested_get(void)
1627 return shutdown_requested;
1630 ShutdownCause qemu_reset_requested_get(void)
1632 return reset_requested;
1635 static int qemu_shutdown_requested(void)
1637 return atomic_xchg(&shutdown_requested, SHUTDOWN_CAUSE_NONE);
1640 static void qemu_kill_report(void)
1642 if (!qtest_driver() && shutdown_signal) {
1643 if (shutdown_pid == 0) {
1644 /* This happens for eg ^C at the terminal, so it's worth
1645 * avoiding printing an odd message in that case.
1647 error_report("terminating on signal %d", shutdown_signal);
1649 char *shutdown_cmd = qemu_get_pid_name(shutdown_pid);
1651 error_report("terminating on signal %d from pid " FMT_pid " (%s)",
1652 shutdown_signal, shutdown_pid,
1653 shutdown_cmd ? shutdown_cmd : "<unknown process>");
1654 g_free(shutdown_cmd);
1656 shutdown_signal = 0;
1660 static ShutdownCause qemu_reset_requested(void)
1662 ShutdownCause r = reset_requested;
1664 if (r && replay_checkpoint(CHECKPOINT_RESET_REQUESTED)) {
1665 reset_requested = SHUTDOWN_CAUSE_NONE;
1668 return SHUTDOWN_CAUSE_NONE;
1671 static int qemu_suspend_requested(void)
1673 int r = suspend_requested;
1674 if (r && replay_checkpoint(CHECKPOINT_SUSPEND_REQUESTED)) {
1675 suspend_requested = 0;
1681 static WakeupReason qemu_wakeup_requested(void)
1683 return wakeup_reason;
1686 static int qemu_powerdown_requested(void)
1688 int r = powerdown_requested;
1689 powerdown_requested = 0;
1693 static int qemu_debug_requested(void)
1695 int r = debug_requested;
1696 debug_requested = 0;
1701 * Reset the VM. Issue an event unless @reason is SHUTDOWN_CAUSE_NONE.
1703 void qemu_system_reset(ShutdownCause reason)
1707 mc = current_machine ? MACHINE_GET_CLASS(current_machine) : NULL;
1709 cpu_synchronize_all_states();
1711 if (mc && mc->reset) {
1714 qemu_devices_reset();
1717 qapi_event_send_reset(shutdown_caused_by_guest(reason),
1720 cpu_synchronize_all_post_reset();
1723 void qemu_system_guest_panicked(GuestPanicInformation *info)
1725 qemu_log_mask(LOG_GUEST_ERROR, "Guest crashed\n");
1728 current_cpu->crash_occurred = true;
1730 qapi_event_send_guest_panicked(GUEST_PANIC_ACTION_PAUSE,
1731 !!info, info, &error_abort);
1732 vm_stop(RUN_STATE_GUEST_PANICKED);
1734 qapi_event_send_guest_panicked(GUEST_PANIC_ACTION_POWEROFF,
1735 !!info, info, &error_abort);
1736 qemu_system_shutdown_request(SHUTDOWN_CAUSE_GUEST_PANIC);
1740 if (info->type == GUEST_PANIC_INFORMATION_TYPE_HYPER_V) {
1741 qemu_log_mask(LOG_GUEST_ERROR, "HV crash parameters: (%#"PRIx64
1742 " %#"PRIx64" %#"PRIx64" %#"PRIx64" %#"PRIx64")\n",
1743 info->u.hyper_v.arg1,
1744 info->u.hyper_v.arg2,
1745 info->u.hyper_v.arg3,
1746 info->u.hyper_v.arg4,
1747 info->u.hyper_v.arg5);
1749 qapi_free_GuestPanicInformation(info);
1753 void qemu_system_reset_request(ShutdownCause reason)
1756 shutdown_requested = reason;
1758 reset_requested = reason;
1761 qemu_notify_event();
1764 static void qemu_system_suspend(void)
1767 notifier_list_notify(&suspend_notifiers, NULL);
1768 runstate_set(RUN_STATE_SUSPENDED);
1769 qapi_event_send_suspend(&error_abort);
1772 void qemu_system_suspend_request(void)
1774 if (runstate_check(RUN_STATE_SUSPENDED)) {
1777 suspend_requested = 1;
1779 qemu_notify_event();
1782 void qemu_register_suspend_notifier(Notifier *notifier)
1784 notifier_list_add(&suspend_notifiers, notifier);
1787 void qemu_system_wakeup_request(WakeupReason reason)
1789 trace_system_wakeup_request(reason);
1791 if (!runstate_check(RUN_STATE_SUSPENDED)) {
1794 if (!(wakeup_reason_mask & (1 << reason))) {
1797 runstate_set(RUN_STATE_RUNNING);
1798 wakeup_reason = reason;
1799 qemu_notify_event();
1802 void qemu_system_wakeup_enable(WakeupReason reason, bool enabled)
1805 wakeup_reason_mask |= (1 << reason);
1807 wakeup_reason_mask &= ~(1 << reason);
1811 void qemu_register_wakeup_notifier(Notifier *notifier)
1813 notifier_list_add(&wakeup_notifiers, notifier);
1816 void qemu_system_killed(int signal, pid_t pid)
1818 shutdown_signal = signal;
1822 /* Cannot call qemu_system_shutdown_request directly because
1823 * we are in a signal handler.
1825 shutdown_requested = SHUTDOWN_CAUSE_HOST_SIGNAL;
1826 qemu_notify_event();
1829 void qemu_system_shutdown_request(ShutdownCause reason)
1831 trace_qemu_system_shutdown_request(reason);
1832 replay_shutdown_request(reason);
1833 shutdown_requested = reason;
1834 qemu_notify_event();
1837 static void qemu_system_powerdown(void)
1839 qapi_event_send_powerdown(&error_abort);
1840 notifier_list_notify(&powerdown_notifiers, NULL);
1843 void qemu_system_powerdown_request(void)
1845 trace_qemu_system_powerdown_request();
1846 powerdown_requested = 1;
1847 qemu_notify_event();
1850 void qemu_register_powerdown_notifier(Notifier *notifier)
1852 notifier_list_add(&powerdown_notifiers, notifier);
1855 void qemu_system_debug_request(void)
1857 debug_requested = 1;
1858 qemu_notify_event();
1861 static bool main_loop_should_exit(void)
1864 ShutdownCause request;
1866 if (qemu_debug_requested()) {
1867 vm_stop(RUN_STATE_DEBUG);
1869 if (qemu_suspend_requested()) {
1870 qemu_system_suspend();
1872 request = qemu_shutdown_requested();
1875 qapi_event_send_shutdown(shutdown_caused_by_guest(request),
1878 vm_stop(RUN_STATE_SHUTDOWN);
1883 request = qemu_reset_requested();
1886 qemu_system_reset(request);
1888 if (!runstate_check(RUN_STATE_RUNNING) &&
1889 !runstate_check(RUN_STATE_INMIGRATE)) {
1890 runstate_set(RUN_STATE_PRELAUNCH);
1893 if (qemu_wakeup_requested()) {
1895 qemu_system_reset(SHUTDOWN_CAUSE_NONE);
1896 notifier_list_notify(&wakeup_notifiers, &wakeup_reason);
1897 wakeup_reason = QEMU_WAKEUP_REASON_NONE;
1899 qapi_event_send_wakeup(&error_abort);
1901 if (qemu_powerdown_requested()) {
1902 qemu_system_powerdown();
1904 if (qemu_vmstop_requested(&r)) {
1910 static void main_loop(void)
1912 #ifdef CONFIG_PROFILER
1916 #ifdef CONFIG_PROFILER
1917 ti = profile_getclock();
1919 main_loop_wait(false);
1920 #ifdef CONFIG_PROFILER
1921 dev_time += profile_getclock() - ti;
1923 } while (!main_loop_should_exit());
1926 static void version(void)
1928 printf("QEMU emulator version " QEMU_VERSION QEMU_PKGVERSION "\n"
1929 QEMU_COPYRIGHT "\n");
1932 static void help(int exitcode)
1935 printf("usage: %s [options] [disk_image]\n\n"
1936 "'disk_image' is a raw hard disk image for IDE hard disk 0\n\n",
1937 error_get_progname());
1939 #define QEMU_OPTIONS_GENERATE_HELP
1940 #include "qemu-options-wrapper.h"
1942 printf("\nDuring emulation, the following keys are useful:\n"
1943 "ctrl-alt-f toggle full screen\n"
1944 "ctrl-alt-n switch to virtual console 'n'\n"
1945 "ctrl-alt toggle mouse and keyboard grab\n"
1947 "When using -nographic, press 'ctrl-a h' to get some help.\n"
1949 QEMU_HELP_BOTTOM "\n");
1954 #define HAS_ARG 0x0001
1956 typedef struct QEMUOption {
1963 static const QEMUOption qemu_options[] = {
1964 { "h", 0, QEMU_OPTION_h, QEMU_ARCH_ALL },
1965 #define QEMU_OPTIONS_GENERATE_OPTIONS
1966 #include "qemu-options-wrapper.h"
1970 typedef struct VGAInterfaceInfo {
1971 const char *opt_name; /* option name */
1972 const char *name; /* human-readable name */
1973 /* Class names indicating that support is available.
1974 * If no class is specified, the interface is always available */
1975 const char *class_names[2];
1978 static VGAInterfaceInfo vga_interfaces[VGA_TYPE_MAX] = {
1984 .name = "standard VGA",
1985 .class_names = { "VGA", "isa-vga" },
1988 .opt_name = "cirrus",
1989 .name = "Cirrus VGA",
1990 .class_names = { "cirrus-vga", "isa-cirrus-vga" },
1993 .opt_name = "vmware",
1994 .name = "VMWare SVGA",
1995 .class_names = { "vmware-svga" },
1998 .opt_name = "virtio",
1999 .name = "Virtio VGA",
2000 .class_names = { "virtio-vga" },
2005 .class_names = { "qxl-vga" },
2009 .name = "TCX framebuffer",
2010 .class_names = { "SUNW,tcx" },
2014 .name = "CG3 framebuffer",
2015 .class_names = { "cgthree" },
2018 .opt_name = "xenfb",
2022 static bool vga_interface_available(VGAInterfaceType t)
2024 VGAInterfaceInfo *ti = &vga_interfaces[t];
2026 assert(t < VGA_TYPE_MAX);
2027 return !ti->class_names[0] ||
2028 object_class_by_name(ti->class_names[0]) ||
2029 object_class_by_name(ti->class_names[1]);
2032 static void select_vgahw(const char *p)
2037 assert(vga_interface_type == VGA_NONE);
2038 for (t = 0; t < VGA_TYPE_MAX; t++) {
2039 VGAInterfaceInfo *ti = &vga_interfaces[t];
2040 if (ti->opt_name && strstart(p, ti->opt_name, &opts)) {
2041 if (!vga_interface_available(t)) {
2042 error_report("%s not available", ti->name);
2045 vga_interface_type = t;
2049 if (t == VGA_TYPE_MAX) {
2051 error_report("unknown vga type: %s", p);
2055 const char *nextopt;
2057 if (strstart(opts, ",retrace=", &nextopt)) {
2059 if (strstart(opts, "dumb", &nextopt))
2060 vga_retrace_method = VGA_RETRACE_DUMB;
2061 else if (strstart(opts, "precise", &nextopt))
2062 vga_retrace_method = VGA_RETRACE_PRECISE;
2063 else goto invalid_vga;
2064 } else goto invalid_vga;
2069 typedef enum DisplayType {
2079 static DisplayType select_display(const char *p)
2082 DisplayType display = DT_DEFAULT;
2084 if (strstart(p, "sdl", &opts)) {
2088 const char *nextopt;
2090 if (strstart(opts, ",frame=", &nextopt)) {
2092 if (strstart(opts, "on", &nextopt)) {
2094 } else if (strstart(opts, "off", &nextopt)) {
2097 goto invalid_sdl_args;
2099 } else if (strstart(opts, ",alt_grab=", &nextopt)) {
2101 if (strstart(opts, "on", &nextopt)) {
2103 } else if (strstart(opts, "off", &nextopt)) {
2106 goto invalid_sdl_args;
2108 } else if (strstart(opts, ",ctrl_grab=", &nextopt)) {
2110 if (strstart(opts, "on", &nextopt)) {
2112 } else if (strstart(opts, "off", &nextopt)) {
2115 goto invalid_sdl_args;
2117 } else if (strstart(opts, ",window_close=", &nextopt)) {
2119 if (strstart(opts, "on", &nextopt)) {
2121 } else if (strstart(opts, "off", &nextopt)) {
2124 goto invalid_sdl_args;
2126 } else if (strstart(opts, ",gl=", &nextopt)) {
2128 if (strstart(opts, "on", &nextopt)) {
2130 } else if (strstart(opts, "off", &nextopt)) {
2133 goto invalid_sdl_args;
2137 error_report("invalid SDL option string");
2143 error_report("SDL support is disabled");
2146 } else if (strstart(p, "vnc", &opts)) {
2148 vnc_parse(opts + 1, &error_fatal);
2150 error_report("VNC requires a display argument vnc=<display>");
2153 } else if (strstart(p, "egl-headless", &opts)) {
2154 #ifdef CONFIG_OPENGL_DMABUF
2159 fprintf(stderr, "egl support is disabled\n");
2162 } else if (strstart(p, "curses", &opts)) {
2163 #ifdef CONFIG_CURSES
2164 display = DT_CURSES;
2166 error_report("curses support is disabled");
2169 } else if (strstart(p, "gtk", &opts)) {
2173 const char *nextopt;
2175 if (strstart(opts, ",grab_on_hover=", &nextopt)) {
2177 if (strstart(opts, "on", &nextopt)) {
2178 grab_on_hover = true;
2179 } else if (strstart(opts, "off", &nextopt)) {
2180 grab_on_hover = false;
2182 goto invalid_gtk_args;
2184 } else if (strstart(opts, ",gl=", &nextopt)) {
2186 if (strstart(opts, "on", &nextopt)) {
2188 } else if (strstart(opts, "off", &nextopt)) {
2191 goto invalid_gtk_args;
2195 error_report("invalid GTK option string");
2201 error_report("GTK support is disabled");
2204 } else if (strstart(p, "none", &opts)) {
2207 error_report("unknown display type");
2214 static int balloon_parse(const char *arg)
2218 if (strcmp(arg, "none") == 0) {
2222 if (!strncmp(arg, "virtio", 6)) {
2223 if (arg[6] == ',') {
2224 /* have params -> parse them */
2225 opts = qemu_opts_parse_noisily(qemu_find_opts("device"), arg + 7,
2230 /* create empty opts */
2231 opts = qemu_opts_create(qemu_find_opts("device"), NULL, 0,
2234 qemu_opt_set(opts, "driver", "virtio-balloon", &error_abort);
2241 char *qemu_find_file(int type, const char *name)
2247 /* Try the name as a straight path first */
2248 if (access(name, R_OK) == 0) {
2249 trace_load_file(name, name);
2250 return g_strdup(name);
2254 case QEMU_FILE_TYPE_BIOS:
2257 case QEMU_FILE_TYPE_KEYMAP:
2258 subdir = "keymaps/";
2264 for (i = 0; i < data_dir_idx; i++) {
2265 buf = g_strdup_printf("%s/%s%s", data_dir[i], subdir, name);
2266 if (access(buf, R_OK) == 0) {
2267 trace_load_file(name, buf);
2275 static inline bool nonempty_str(const char *str)
2280 static int parse_fw_cfg(void *opaque, QemuOpts *opts, Error **errp)
2284 const char *name, *file, *str;
2285 FWCfgState *fw_cfg = (FWCfgState *) opaque;
2287 if (fw_cfg == NULL) {
2288 error_report("fw_cfg device not available");
2291 name = qemu_opt_get(opts, "name");
2292 file = qemu_opt_get(opts, "file");
2293 str = qemu_opt_get(opts, "string");
2295 /* we need name and either a file or the content string */
2296 if (!(nonempty_str(name) && (nonempty_str(file) || nonempty_str(str)))) {
2297 error_report("invalid argument(s)");
2300 if (nonempty_str(file) && nonempty_str(str)) {
2301 error_report("file and string are mutually exclusive");
2304 if (strlen(name) > FW_CFG_MAX_FILE_PATH - 1) {
2305 error_report("name too long (max. %d char)", FW_CFG_MAX_FILE_PATH - 1);
2308 if (strncmp(name, "opt/", 4) != 0) {
2309 warn_report("externally provided fw_cfg item names "
2310 "should be prefixed with \"opt/\"");
2312 if (nonempty_str(str)) {
2313 size = strlen(str); /* NUL terminator NOT included in fw_cfg blob */
2314 buf = g_memdup(str, size);
2316 if (!g_file_get_contents(file, &buf, &size, NULL)) {
2317 error_report("can't load %s", file);
2321 /* For legacy, keep user files in a specific global order. */
2322 fw_cfg_set_order_override(fw_cfg, FW_CFG_ORDER_OVERRIDE_USER);
2323 fw_cfg_add_file(fw_cfg, name, buf, size);
2324 fw_cfg_reset_order_override(fw_cfg);
2328 static int device_help_func(void *opaque, QemuOpts *opts, Error **errp)
2330 return qdev_device_help(opts);
2333 static int device_init_func(void *opaque, QemuOpts *opts, Error **errp)
2338 dev = qdev_device_add(opts, &err);
2340 error_report_err(err);
2343 object_unref(OBJECT(dev));
2347 static int chardev_init_func(void *opaque, QemuOpts *opts, Error **errp)
2349 Error *local_err = NULL;
2351 if (!qemu_chr_new_from_opts(opts, &local_err)) {
2353 error_report_err(local_err);
2361 #ifdef CONFIG_VIRTFS
2362 static int fsdev_init_func(void *opaque, QemuOpts *opts, Error **errp)
2364 return qemu_fsdev_add(opts);
2368 static int mon_init_func(void *opaque, QemuOpts *opts, Error **errp)
2371 const char *chardev;
2375 mode = qemu_opt_get(opts, "mode");
2379 if (strcmp(mode, "readline") == 0) {
2380 flags = MONITOR_USE_READLINE;
2381 } else if (strcmp(mode, "control") == 0) {
2382 flags = MONITOR_USE_CONTROL;
2384 error_report("unknown monitor mode \"%s\"", mode);
2388 if (qemu_opt_get_bool(opts, "pretty", 0))
2389 flags |= MONITOR_USE_PRETTY;
2391 if (qemu_opt_get_bool(opts, "default", 0)) {
2392 error_report("option 'default' does nothing and is deprecated");
2395 chardev = qemu_opt_get(opts, "chardev");
2396 chr = qemu_chr_find(chardev);
2398 error_report("chardev \"%s\" not found", chardev);
2402 monitor_init(chr, flags);
2406 static void monitor_parse(const char *optarg, const char *mode, bool pretty)
2408 static int monitor_device_index = 0;
2413 if (strstart(optarg, "chardev:", &p)) {
2414 snprintf(label, sizeof(label), "%s", p);
2416 snprintf(label, sizeof(label), "compat_monitor%d",
2417 monitor_device_index);
2418 opts = qemu_chr_parse_compat(label, optarg);
2420 error_report("parse error: %s", optarg);
2425 opts = qemu_opts_create(qemu_find_opts("mon"), label, 1, &error_fatal);
2426 qemu_opt_set(opts, "mode", mode, &error_abort);
2427 qemu_opt_set(opts, "chardev", label, &error_abort);
2428 qemu_opt_set_bool(opts, "pretty", pretty, &error_abort);
2429 monitor_device_index++;
2432 struct device_config {
2434 DEV_USB, /* -usbdevice */
2436 DEV_SERIAL, /* -serial */
2437 DEV_PARALLEL, /* -parallel */
2438 DEV_VIRTCON, /* -virtioconsole */
2439 DEV_DEBUGCON, /* -debugcon */
2440 DEV_GDB, /* -gdb, -s */
2441 DEV_SCLP, /* s390 sclp */
2443 const char *cmdline;
2445 QTAILQ_ENTRY(device_config) next;
2448 static QTAILQ_HEAD(, device_config) device_configs =
2449 QTAILQ_HEAD_INITIALIZER(device_configs);
2451 static void add_device_config(int type, const char *cmdline)
2453 struct device_config *conf;
2455 conf = g_malloc0(sizeof(*conf));
2457 conf->cmdline = cmdline;
2458 loc_save(&conf->loc);
2459 QTAILQ_INSERT_TAIL(&device_configs, conf, next);
2462 static int foreach_device_config(int type, int (*func)(const char *cmdline))
2464 struct device_config *conf;
2467 QTAILQ_FOREACH(conf, &device_configs, next) {
2468 if (conf->type != type)
2470 loc_push_restore(&conf->loc);
2471 rc = func(conf->cmdline);
2472 loc_pop(&conf->loc);
2480 static int serial_parse(const char *devname)
2482 static int index = 0;
2485 if (strcmp(devname, "none") == 0)
2487 if (index == MAX_SERIAL_PORTS) {
2488 error_report("too many serial ports");
2491 snprintf(label, sizeof(label), "serial%d", index);
2492 serial_hds[index] = qemu_chr_new(label, devname);
2493 if (!serial_hds[index]) {
2494 error_report("could not connect serial device"
2495 " to character backend '%s'", devname);
2502 static int parallel_parse(const char *devname)
2504 static int index = 0;
2507 if (strcmp(devname, "none") == 0)
2509 if (index == MAX_PARALLEL_PORTS) {
2510 error_report("too many parallel ports");
2513 snprintf(label, sizeof(label), "parallel%d", index);
2514 parallel_hds[index] = qemu_chr_new(label, devname);
2515 if (!parallel_hds[index]) {
2516 error_report("could not connect parallel device"
2517 " to character backend '%s'", devname);
2524 static int virtcon_parse(const char *devname)
2526 QemuOptsList *device = qemu_find_opts("device");
2527 static int index = 0;
2529 QemuOpts *bus_opts, *dev_opts;
2531 if (strcmp(devname, "none") == 0)
2533 if (index == MAX_VIRTIO_CONSOLES) {
2534 error_report("too many virtio consoles");
2538 bus_opts = qemu_opts_create(device, NULL, 0, &error_abort);
2539 qemu_opt_set(bus_opts, "driver", "virtio-serial", &error_abort);
2541 dev_opts = qemu_opts_create(device, NULL, 0, &error_abort);
2542 qemu_opt_set(dev_opts, "driver", "virtconsole", &error_abort);
2544 snprintf(label, sizeof(label), "virtcon%d", index);
2545 virtcon_hds[index] = qemu_chr_new(label, devname);
2546 if (!virtcon_hds[index]) {
2547 error_report("could not connect virtio console"
2548 " to character backend '%s'", devname);
2551 qemu_opt_set(dev_opts, "chardev", label, &error_abort);
2557 static int sclp_parse(const char *devname)
2559 QemuOptsList *device = qemu_find_opts("device");
2560 static int index = 0;
2564 if (strcmp(devname, "none") == 0) {
2567 if (index == MAX_SCLP_CONSOLES) {
2568 error_report("too many sclp consoles");
2572 assert(arch_type == QEMU_ARCH_S390X);
2574 dev_opts = qemu_opts_create(device, NULL, 0, NULL);
2575 qemu_opt_set(dev_opts, "driver", "sclpconsole", &error_abort);
2577 snprintf(label, sizeof(label), "sclpcon%d", index);
2578 sclp_hds[index] = qemu_chr_new(label, devname);
2579 if (!sclp_hds[index]) {
2580 error_report("could not connect sclp console"
2581 " to character backend '%s'", devname);
2584 qemu_opt_set(dev_opts, "chardev", label, &error_abort);
2590 static int debugcon_parse(const char *devname)
2594 if (!qemu_chr_new("debugcon", devname)) {
2597 opts = qemu_opts_create(qemu_find_opts("device"), "debugcon", 1, NULL);
2599 error_report("already have a debugcon device");
2602 qemu_opt_set(opts, "driver", "isa-debugcon", &error_abort);
2603 qemu_opt_set(opts, "chardev", "debugcon", &error_abort);
2607 static gint machine_class_cmp(gconstpointer a, gconstpointer b)
2609 const MachineClass *mc1 = a, *mc2 = b;
2612 if (mc1->family == NULL) {
2613 if (mc2->family == NULL) {
2614 /* Compare standalone machine types against each other; they sort
2615 * in increasing order.
2617 return strcmp(object_class_get_name(OBJECT_CLASS(mc1)),
2618 object_class_get_name(OBJECT_CLASS(mc2)));
2621 /* Standalone machine types sort after families. */
2625 if (mc2->family == NULL) {
2626 /* Families sort before standalone machine types. */
2630 /* Families sort between each other alphabetically increasingly. */
2631 res = strcmp(mc1->family, mc2->family);
2636 /* Within the same family, machine types sort in decreasing order. */
2637 return strcmp(object_class_get_name(OBJECT_CLASS(mc2)),
2638 object_class_get_name(OBJECT_CLASS(mc1)));
2641 static MachineClass *machine_parse(const char *name)
2643 MachineClass *mc = NULL;
2644 GSList *el, *machines = object_class_get_list(TYPE_MACHINE, false);
2647 mc = find_machine(name);
2650 g_slist_free(machines);
2653 if (name && !is_help_option(name)) {
2654 error_report("unsupported machine type");
2655 error_printf("Use -machine help to list supported machines\n");
2657 printf("Supported machines are:\n");
2658 machines = g_slist_sort(machines, machine_class_cmp);
2659 for (el = machines; el; el = el->next) {
2660 MachineClass *mc = el->data;
2662 printf("%-20s %s (alias of %s)\n", mc->alias, mc->desc, mc->name);
2664 printf("%-20s %s%s\n", mc->name, mc->desc,
2665 mc->is_default ? " (default)" : "");
2669 g_slist_free(machines);
2670 exit(!name || !is_help_option(name));
2673 void qemu_add_exit_notifier(Notifier *notify)
2675 notifier_list_add(&exit_notifiers, notify);
2678 void qemu_remove_exit_notifier(Notifier *notify)
2680 notifier_remove(notify);
2683 static void qemu_run_exit_notifiers(void)
2685 notifier_list_notify(&exit_notifiers, NULL);
2688 static bool machine_init_done;
2690 void qemu_add_machine_init_done_notifier(Notifier *notify)
2692 notifier_list_add(&machine_init_done_notifiers, notify);
2693 if (machine_init_done) {
2694 notify->notify(notify, NULL);
2698 void qemu_remove_machine_init_done_notifier(Notifier *notify)
2700 notifier_remove(notify);
2703 static void qemu_run_machine_init_done_notifiers(void)
2705 notifier_list_notify(&machine_init_done_notifiers, NULL);
2706 machine_init_done = true;
2709 static const QEMUOption *lookup_opt(int argc, char **argv,
2710 const char **poptarg, int *poptind)
2712 const QEMUOption *popt;
2713 int optind = *poptind;
2714 char *r = argv[optind];
2717 loc_set_cmdline(argv, optind, 1);
2719 /* Treat --foo the same as -foo. */
2722 popt = qemu_options;
2725 error_report("invalid option");
2728 if (!strcmp(popt->name, r + 1))
2732 if (popt->flags & HAS_ARG) {
2733 if (optind >= argc) {
2734 error_report("requires an argument");
2737 optarg = argv[optind++];
2738 loc_set_cmdline(argv, optind - 2, 2);
2749 static MachineClass *select_machine(void)
2751 MachineClass *machine_class = find_default_machine();
2756 loc_push_none(&loc);
2758 opts = qemu_get_machine_opts();
2759 qemu_opts_loc_restore(opts);
2761 optarg = qemu_opt_get(opts, "type");
2763 machine_class = machine_parse(optarg);
2766 if (!machine_class) {
2767 error_report("No machine specified, and there is no default");
2768 error_printf("Use -machine help to list supported machines\n");
2773 return machine_class;
2776 static int machine_set_property(void *opaque,
2777 const char *name, const char *value,
2780 Object *obj = OBJECT(opaque);
2781 Error *local_err = NULL;
2784 if (strcmp(name, "type") == 0) {
2788 qom_name = g_strdup(name);
2789 for (p = qom_name; *p; p++) {
2795 object_property_parse(obj, value, qom_name, &local_err);
2799 error_report_err(local_err);
2808 * Initial object creation happens before all other
2809 * QEMU data types are created. The majority of objects
2810 * can be created at this point. The rng-egd object
2811 * cannot be created here, as it depends on the chardev
2814 static bool object_create_initial(const char *type)
2816 if (g_str_equal(type, "rng-egd")) {
2821 * return false for concrete netfilters since
2822 * they depend on netdevs already existing
2824 if (g_str_equal(type, "filter-buffer") ||
2825 g_str_equal(type, "filter-dump") ||
2826 g_str_equal(type, "filter-mirror") ||
2827 g_str_equal(type, "filter-redirector") ||
2828 g_str_equal(type, "colo-compare") ||
2829 g_str_equal(type, "filter-rewriter") ||
2830 g_str_equal(type, "filter-replay")) {
2834 /* Memory allocation by backends needs to be done
2835 * after configure_accelerator() (due to the tcg_enabled()
2836 * checks at memory_region_init_*()).
2838 * Also, allocation of large amounts of memory may delay
2839 * chardev initialization for too long, and trigger timeouts
2840 * on software that waits for a monitor socket to be created
2843 if (g_str_has_prefix(type, "memory-backend-")) {
2852 * The remainder of object creation happens after the
2853 * creation of chardev, fsdev, net clients and device data types.
2855 static bool object_create_delayed(const char *type)
2857 return !object_create_initial(type);
2861 static void set_memory_options(uint64_t *ram_slots, ram_addr_t *maxram_size,
2865 const char *mem_str;
2866 const char *maxmem_str, *slots_str;
2867 const ram_addr_t default_ram_size = mc->default_ram_size;
2868 QemuOpts *opts = qemu_find_opts_singleton("memory");
2871 loc_push_none(&loc);
2872 qemu_opts_loc_restore(opts);
2875 mem_str = qemu_opt_get(opts, "size");
2878 error_report("missing 'size' option value");
2882 sz = qemu_opt_get_size(opts, "size", ram_size);
2884 /* Fix up legacy suffix-less format */
2885 if (g_ascii_isdigit(mem_str[strlen(mem_str) - 1])) {
2886 uint64_t overflow_check = sz;
2889 if ((sz >> 20) != overflow_check) {
2890 error_report("too large 'size' option value");
2896 /* backward compatibility behaviour for case "-m 0" */
2898 sz = default_ram_size;
2901 sz = QEMU_ALIGN_UP(sz, 8192);
2903 if (ram_size != sz) {
2904 error_report("ram size too large");
2908 /* store value for the future use */
2909 qemu_opt_set_number(opts, "size", ram_size, &error_abort);
2910 *maxram_size = ram_size;
2912 maxmem_str = qemu_opt_get(opts, "maxmem");
2913 slots_str = qemu_opt_get(opts, "slots");
2914 if (maxmem_str && slots_str) {
2917 sz = qemu_opt_get_size(opts, "maxmem", 0);
2918 slots = qemu_opt_get_number(opts, "slots", 0);
2919 if (sz < ram_size) {
2920 error_report("invalid value of -m option maxmem: "
2921 "maximum memory size (0x%" PRIx64 ") must be at least "
2922 "the initial memory size (0x" RAM_ADDR_FMT ")",
2925 } else if (sz > ram_size) {
2927 error_report("invalid value of -m option: maxmem was "
2928 "specified, but no hotplug slots were specified");
2932 error_report("invalid value of -m option maxmem: "
2933 "memory slots were specified but maximum memory size "
2934 "(0x%" PRIx64 ") is equal to the initial memory size "
2935 "(0x" RAM_ADDR_FMT ")", sz, ram_size);
2941 } else if ((!maxmem_str && slots_str) ||
2942 (maxmem_str && !slots_str)) {
2943 error_report("invalid -m option value: missing "
2944 "'%s' option", slots_str ? "maxmem" : "slots");
2951 static int global_init_func(void *opaque, QemuOpts *opts, Error **errp)
2955 g = g_malloc0(sizeof(*g));
2956 g->driver = qemu_opt_get(opts, "driver");
2957 g->property = qemu_opt_get(opts, "property");
2958 g->value = qemu_opt_get(opts, "value");
2959 g->user_provided = true;
2960 g->errp = &error_fatal;
2961 qdev_prop_register_global(g);
2965 static int qemu_read_default_config_file(void)
2969 ret = qemu_read_config_file(CONFIG_QEMU_CONFDIR "/qemu.conf");
2970 if (ret < 0 && ret != -ENOENT) {
2977 static void user_register_global_props(void)
2979 qemu_opts_foreach(qemu_find_opts("global"),
2980 global_init_func, NULL, NULL);
2984 * Note: we should see that these properties are actually having a
2985 * priority: accel < machine < user. This means e.g. when user
2986 * specifies something in "-global", it'll always be used with highest
2987 * priority than either machine/accelerator compat properties.
2989 static void register_global_properties(MachineState *ms)
2991 accel_register_compat_props(ms->accelerator);
2992 machine_register_compat_props(ms);
2993 user_register_global_props();
2996 int main(int argc, char **argv, char **envp)
2999 int snapshot, linux_boot;
3000 const char *initrd_filename;
3001 const char *kernel_filename, *kernel_cmdline;
3002 const char *boot_order = NULL;
3003 const char *boot_once = NULL;
3005 int cyls, heads, secs, translation;
3006 QemuOpts *opts, *machine_opts;
3007 QemuOpts *hda_opts = NULL, *icount_opts = NULL, *accel_opts = NULL;
3008 QemuOptsList *olist;
3011 const char *loadvm = NULL;
3012 MachineClass *machine_class;
3013 const char *cpu_model;
3014 const char *vga_model = NULL;
3015 const char *qtest_chrdev = NULL;
3016 const char *qtest_log = NULL;
3017 const char *pid_file = NULL;
3018 const char *incoming = NULL;
3019 bool defconfig = true;
3020 bool userconfig = true;
3021 bool nographic = false;
3022 DisplayType display_type = DT_DEFAULT;
3023 int display_remote = 0;
3024 const char *log_mask = NULL;
3025 const char *log_file = NULL;
3026 char *trace_file = NULL;
3027 ram_addr_t maxram_size;
3028 uint64_t ram_slots = 0;
3029 FILE *vmstate_dump_file = NULL;
3030 Error *main_loop_err = NULL;
3032 bool list_data_dirs = false;
3033 typedef struct BlockdevOptions_queue {
3034 BlockdevOptions *bdo;
3036 QSIMPLEQ_ENTRY(BlockdevOptions_queue) entry;
3037 } BlockdevOptions_queue;
3038 QSIMPLEQ_HEAD(, BlockdevOptions_queue) bdo_queue
3039 = QSIMPLEQ_HEAD_INITIALIZER(bdo_queue);
3041 module_call_init(MODULE_INIT_TRACE);
3043 qemu_init_cpu_list();
3044 qemu_init_cpu_loop();
3045 qemu_mutex_lock_iothread();
3047 atexit(qemu_run_exit_notifiers);
3048 error_set_progname(argv[0]);
3049 qemu_init_exec_dir(argv[0]);
3051 module_call_init(MODULE_INIT_QOM);
3052 monitor_init_qmp_commands();
3054 qemu_add_opts(&qemu_drive_opts);
3055 qemu_add_drive_opts(&qemu_legacy_drive_opts);
3056 qemu_add_drive_opts(&qemu_common_drive_opts);
3057 qemu_add_drive_opts(&qemu_drive_opts);
3058 qemu_add_drive_opts(&bdrv_runtime_opts);
3059 qemu_add_opts(&qemu_chardev_opts);
3060 qemu_add_opts(&qemu_device_opts);
3061 qemu_add_opts(&qemu_netdev_opts);
3062 qemu_add_opts(&qemu_net_opts);
3063 qemu_add_opts(&qemu_rtc_opts);
3064 qemu_add_opts(&qemu_global_opts);
3065 qemu_add_opts(&qemu_mon_opts);
3066 qemu_add_opts(&qemu_trace_opts);
3067 qemu_add_opts(&qemu_option_rom_opts);
3068 qemu_add_opts(&qemu_machine_opts);
3069 qemu_add_opts(&qemu_accel_opts);
3070 qemu_add_opts(&qemu_mem_opts);
3071 qemu_add_opts(&qemu_smp_opts);
3072 qemu_add_opts(&qemu_boot_opts);
3073 qemu_add_opts(&qemu_sandbox_opts);
3074 qemu_add_opts(&qemu_add_fd_opts);
3075 qemu_add_opts(&qemu_object_opts);
3076 qemu_add_opts(&qemu_tpmdev_opts);
3077 qemu_add_opts(&qemu_realtime_opts);
3078 qemu_add_opts(&qemu_msg_opts);
3079 qemu_add_opts(&qemu_name_opts);
3080 qemu_add_opts(&qemu_numa_opts);
3081 qemu_add_opts(&qemu_icount_opts);
3082 qemu_add_opts(&qemu_semihosting_config_opts);
3083 qemu_add_opts(&qemu_fw_cfg_opts);
3084 module_call_init(MODULE_INIT_OPTS);
3088 if (qcrypto_init(&err) < 0) {
3089 error_reportf_err(err, "cannot initialize crypto: ");
3092 rtc_clock = QEMU_CLOCK_HOST;
3094 QLIST_INIT (&vm_change_state_head);
3095 os_setup_early_signal_handling();
3099 cyls = heads = secs = 0;
3100 translation = BIOS_ATA_TRANSLATION_AUTO;
3104 bdrv_init_with_whitelist();
3108 /* first pass of option parsing */
3110 while (optind < argc) {
3111 if (argv[optind][0] != '-') {
3115 const QEMUOption *popt;
3117 popt = lookup_opt(argc, argv, &optarg, &optind);
3118 switch (popt->index) {
3119 case QEMU_OPTION_nodefconfig:
3122 case QEMU_OPTION_nouserconfig:
3129 if (defconfig && userconfig) {
3130 if (qemu_read_default_config_file() < 0) {
3135 /* second pass of option parsing */
3140 if (argv[optind][0] != '-') {
3141 hda_opts = drive_add(IF_DEFAULT, 0, argv[optind++], HD_OPTS);
3143 const QEMUOption *popt;
3145 popt = lookup_opt(argc, argv, &optarg, &optind);
3146 if (!(popt->arch_mask & arch_type)) {
3147 error_report("Option not supported for this target");
3150 switch(popt->index) {
3151 case QEMU_OPTION_no_kvm_irqchip: {
3152 olist = qemu_find_opts("machine");
3153 qemu_opts_parse_noisily(olist, "kernel_irqchip=off", false);
3156 case QEMU_OPTION_cpu:
3157 /* hw initialization will check this */
3160 case QEMU_OPTION_hda:
3164 snprintf(buf, sizeof(buf), "%s", HD_OPTS);
3166 snprintf(buf, sizeof(buf),
3167 "%s,cyls=%d,heads=%d,secs=%d%s",
3168 HD_OPTS , cyls, heads, secs,
3169 translation == BIOS_ATA_TRANSLATION_LBA ?
3171 translation == BIOS_ATA_TRANSLATION_NONE ?
3172 ",trans=none" : "");
3173 drive_add(IF_DEFAULT, 0, optarg, buf);
3176 case QEMU_OPTION_hdb:
3177 case QEMU_OPTION_hdc:
3178 case QEMU_OPTION_hdd:
3179 drive_add(IF_DEFAULT, popt->index - QEMU_OPTION_hda, optarg,
3182 case QEMU_OPTION_blockdev:
3185 BlockdevOptions_queue *bdo;
3187 v = qobject_input_visitor_new_str(optarg, "driver", &err);
3189 error_report_err(err);
3193 bdo = g_new(BlockdevOptions_queue, 1);
3194 visit_type_BlockdevOptions(v, NULL, &bdo->bdo,
3197 loc_save(&bdo->loc);
3198 QSIMPLEQ_INSERT_TAIL(&bdo_queue, bdo, entry);
3201 case QEMU_OPTION_drive:
3202 if (drive_def(optarg) == NULL) {
3206 case QEMU_OPTION_set:
3207 if (qemu_set_option(optarg) != 0)
3210 case QEMU_OPTION_global:
3211 if (qemu_global_option(optarg) != 0)
3214 case QEMU_OPTION_mtdblock:
3215 drive_add(IF_MTD, -1, optarg, MTD_OPTS);
3217 case QEMU_OPTION_sd:
3218 drive_add(IF_SD, -1, optarg, SD_OPTS);
3220 case QEMU_OPTION_pflash:
3221 drive_add(IF_PFLASH, -1, optarg, PFLASH_OPTS);
3223 case QEMU_OPTION_snapshot:
3226 case QEMU_OPTION_hdachs:
3230 cyls = strtol(p, (char **)&p, 0);
3231 if (cyls < 1 || cyls > 16383)
3236 heads = strtol(p, (char **)&p, 0);
3237 if (heads < 1 || heads > 16)
3242 secs = strtol(p, (char **)&p, 0);
3243 if (secs < 1 || secs > 63)
3247 if (!strcmp(p, "large")) {
3248 translation = BIOS_ATA_TRANSLATION_LARGE;
3249 } else if (!strcmp(p, "rechs")) {
3250 translation = BIOS_ATA_TRANSLATION_RECHS;
3251 } else if (!strcmp(p, "none")) {
3252 translation = BIOS_ATA_TRANSLATION_NONE;
3253 } else if (!strcmp(p, "lba")) {
3254 translation = BIOS_ATA_TRANSLATION_LBA;
3255 } else if (!strcmp(p, "auto")) {
3256 translation = BIOS_ATA_TRANSLATION_AUTO;
3260 } else if (*p != '\0') {
3262 error_report("invalid physical CHS format");
3265 if (hda_opts != NULL) {
3266 qemu_opt_set_number(hda_opts, "cyls", cyls,
3268 qemu_opt_set_number(hda_opts, "heads", heads,
3270 qemu_opt_set_number(hda_opts, "secs", secs,
3272 if (translation == BIOS_ATA_TRANSLATION_LARGE) {
3273 qemu_opt_set(hda_opts, "trans", "large",
3275 } else if (translation == BIOS_ATA_TRANSLATION_RECHS) {
3276 qemu_opt_set(hda_opts, "trans", "rechs",
3278 } else if (translation == BIOS_ATA_TRANSLATION_LBA) {
3279 qemu_opt_set(hda_opts, "trans", "lba",
3281 } else if (translation == BIOS_ATA_TRANSLATION_NONE) {
3282 qemu_opt_set(hda_opts, "trans", "none",
3287 error_report("'-hdachs' is deprecated, please use '-device"
3288 " ide-hd,cyls=c,heads=h,secs=s,...' instead");
3290 case QEMU_OPTION_numa:
3291 opts = qemu_opts_parse_noisily(qemu_find_opts("numa"),
3297 case QEMU_OPTION_display:
3298 display_type = select_display(optarg);
3300 case QEMU_OPTION_nographic:
3301 olist = qemu_find_opts("machine");
3302 qemu_opts_parse_noisily(olist, "graphics=off", false);
3304 display_type = DT_NONE;
3306 case QEMU_OPTION_curses:
3307 #ifdef CONFIG_CURSES
3308 display_type = DT_CURSES;
3310 error_report("curses support is disabled");
3314 case QEMU_OPTION_portrait:
3315 graphic_rotate = 90;
3317 case QEMU_OPTION_rotate:
3318 graphic_rotate = strtol(optarg, (char **) &optarg, 10);
3319 if (graphic_rotate != 0 && graphic_rotate != 90 &&
3320 graphic_rotate != 180 && graphic_rotate != 270) {
3321 error_report("only 90, 180, 270 deg rotation is available");
3325 case QEMU_OPTION_kernel:
3326 qemu_opts_set(qemu_find_opts("machine"), 0, "kernel", optarg,
3329 case QEMU_OPTION_initrd:
3330 qemu_opts_set(qemu_find_opts("machine"), 0, "initrd", optarg,
3333 case QEMU_OPTION_append:
3334 qemu_opts_set(qemu_find_opts("machine"), 0, "append", optarg,
3337 case QEMU_OPTION_dtb:
3338 qemu_opts_set(qemu_find_opts("machine"), 0, "dtb", optarg,
3341 case QEMU_OPTION_cdrom:
3342 drive_add(IF_DEFAULT, 2, optarg, CDROM_OPTS);
3344 case QEMU_OPTION_boot:
3345 opts = qemu_opts_parse_noisily(qemu_find_opts("boot-opts"),
3351 case QEMU_OPTION_fda:
3352 case QEMU_OPTION_fdb:
3353 drive_add(IF_FLOPPY, popt->index - QEMU_OPTION_fda,
3356 case QEMU_OPTION_no_fd_bootchk:
3359 case QEMU_OPTION_netdev:
3361 if (net_client_parse(qemu_find_opts("netdev"), optarg) == -1) {
3365 case QEMU_OPTION_net:
3367 if (net_client_parse(qemu_find_opts("net"), optarg) == -1) {
3371 #ifdef CONFIG_LIBISCSI
3372 case QEMU_OPTION_iscsi:
3373 opts = qemu_opts_parse_noisily(qemu_find_opts("iscsi"),
3381 case QEMU_OPTION_tftp:
3382 error_report("The -tftp option is deprecated. "
3383 "Please use '-netdev user,tftp=...' instead.");
3384 legacy_tftp_prefix = optarg;
3386 case QEMU_OPTION_bootp:
3387 error_report("The -bootp option is deprecated. "
3388 "Please use '-netdev user,bootfile=...' instead.");
3389 legacy_bootp_filename = optarg;
3391 case QEMU_OPTION_redir:
3392 error_report("The -redir option is deprecated. "
3393 "Please use '-netdev user,hostfwd=...' instead.");
3394 if (net_slirp_redir(optarg) < 0)
3398 case QEMU_OPTION_bt:
3399 add_device_config(DEV_BT, optarg);
3401 case QEMU_OPTION_audio_help:
3405 case QEMU_OPTION_soundhw:
3406 select_soundhw (optarg);
3411 case QEMU_OPTION_version:
3416 opts = qemu_opts_parse_noisily(qemu_find_opts("memory"),
3423 case QEMU_OPTION_tpmdev:
3424 if (tpm_config_parse(qemu_find_opts("tpmdev"), optarg) < 0) {
3429 case QEMU_OPTION_mempath:
3432 case QEMU_OPTION_mem_prealloc:
3441 case QEMU_OPTION_DFILTER:
3442 qemu_set_dfilter_ranges(optarg, &error_fatal);
3445 add_device_config(DEV_GDB, "tcp::" DEFAULT_GDBSTUB_PORT);
3447 case QEMU_OPTION_gdb:
3448 add_device_config(DEV_GDB, optarg);
3451 if (is_help_option(optarg)) {
3452 list_data_dirs = true;
3453 } else if (data_dir_idx < ARRAY_SIZE(data_dir)) {
3454 data_dir[data_dir_idx++] = optarg;
3457 case QEMU_OPTION_bios:
3458 qemu_opts_set(qemu_find_opts("machine"), 0, "firmware", optarg,
3461 case QEMU_OPTION_singlestep:
3468 keyboard_layout = optarg;
3470 case QEMU_OPTION_localtime:
3473 case QEMU_OPTION_vga:
3482 w = strtol(p, (char **)&p, 10);
3485 error_report("invalid resolution or depth");
3491 h = strtol(p, (char **)&p, 10);
3496 depth = strtol(p, (char **)&p, 10);
3497 if (depth != 8 && depth != 15 && depth != 16 &&
3498 depth != 24 && depth != 32)
3500 } else if (*p == '\0') {
3501 depth = graphic_depth;
3508 graphic_depth = depth;
3511 case QEMU_OPTION_echr:
3514 term_escape_char = strtol(optarg, &r, 0);
3516 printf("Bad argument to echr\n");
3519 case QEMU_OPTION_monitor:
3520 default_monitor = 0;
3521 if (strncmp(optarg, "none", 4)) {
3522 monitor_parse(optarg, "readline", false);
3525 case QEMU_OPTION_qmp:
3526 monitor_parse(optarg, "control", false);
3527 default_monitor = 0;
3529 case QEMU_OPTION_qmp_pretty:
3530 monitor_parse(optarg, "control", true);
3531 default_monitor = 0;
3533 case QEMU_OPTION_mon:
3534 opts = qemu_opts_parse_noisily(qemu_find_opts("mon"), optarg,
3539 default_monitor = 0;
3541 case QEMU_OPTION_chardev:
3542 opts = qemu_opts_parse_noisily(qemu_find_opts("chardev"),
3548 case QEMU_OPTION_fsdev:
3549 olist = qemu_find_opts("fsdev");
3551 error_report("fsdev support is disabled");
3554 opts = qemu_opts_parse_noisily(olist, optarg, true);
3559 case QEMU_OPTION_virtfs: {
3562 const char *writeout, *sock_fd, *socket, *path, *security_model;
3564 olist = qemu_find_opts("virtfs");
3566 error_report("virtfs support is disabled");
3569 opts = qemu_opts_parse_noisily(olist, optarg, true);
3574 if (qemu_opt_get(opts, "fsdriver") == NULL ||
3575 qemu_opt_get(opts, "mount_tag") == NULL) {
3576 error_report("Usage: -virtfs fsdriver,mount_tag=tag");
3579 fsdev = qemu_opts_create(qemu_find_opts("fsdev"),
3580 qemu_opts_id(opts) ?:
3581 qemu_opt_get(opts, "mount_tag"),
3584 error_report("duplicate or invalid fsdev id: %s",
3585 qemu_opt_get(opts, "mount_tag"));
3589 writeout = qemu_opt_get(opts, "writeout");
3591 #ifdef CONFIG_SYNC_FILE_RANGE
3592 qemu_opt_set(fsdev, "writeout", writeout, &error_abort);
3594 error_report("writeout=immediate not supported "
3595 "on this platform");
3599 qemu_opt_set(fsdev, "fsdriver",
3600 qemu_opt_get(opts, "fsdriver"), &error_abort);
3601 path = qemu_opt_get(opts, "path");
3603 qemu_opt_set(fsdev, "path", path, &error_abort);
3605 security_model = qemu_opt_get(opts, "security_model");
3606 if (security_model) {
3607 qemu_opt_set(fsdev, "security_model", security_model,
3610 socket = qemu_opt_get(opts, "socket");
3612 qemu_opt_set(fsdev, "socket", socket, &error_abort);
3614 sock_fd = qemu_opt_get(opts, "sock_fd");
3616 qemu_opt_set(fsdev, "sock_fd", sock_fd, &error_abort);
3619 qemu_opt_set_bool(fsdev, "readonly",
3620 qemu_opt_get_bool(opts, "readonly", 0),
3622 device = qemu_opts_create(qemu_find_opts("device"), NULL, 0,
3624 qemu_opt_set(device, "driver", "virtio-9p-pci", &error_abort);
3625 qemu_opt_set(device, "fsdev",
3626 qemu_opts_id(fsdev), &error_abort);
3627 qemu_opt_set(device, "mount_tag",
3628 qemu_opt_get(opts, "mount_tag"), &error_abort);
3631 case QEMU_OPTION_virtfs_synth: {
3635 fsdev = qemu_opts_create(qemu_find_opts("fsdev"), "v_synth",
3638 error_report("duplicate option: %s", "virtfs_synth");
3641 qemu_opt_set(fsdev, "fsdriver", "synth", &error_abort);
3643 device = qemu_opts_create(qemu_find_opts("device"), NULL, 0,
3645 qemu_opt_set(device, "driver", "virtio-9p-pci", &error_abort);
3646 qemu_opt_set(device, "fsdev", "v_synth", &error_abort);
3647 qemu_opt_set(device, "mount_tag", "v_synth", &error_abort);
3650 case QEMU_OPTION_serial:
3651 add_device_config(DEV_SERIAL, optarg);
3653 if (strncmp(optarg, "mon:", 4) == 0) {
3654 default_monitor = 0;
3657 case QEMU_OPTION_watchdog:
3659 error_report("only one watchdog option may be given");
3664 case QEMU_OPTION_watchdog_action:
3665 if (select_watchdog_action(optarg) == -1) {
3666 error_report("unknown -watchdog-action parameter");
3670 case QEMU_OPTION_virtiocon:
3671 add_device_config(DEV_VIRTCON, optarg);
3672 default_virtcon = 0;
3673 if (strncmp(optarg, "mon:", 4) == 0) {
3674 default_monitor = 0;
3677 case QEMU_OPTION_parallel:
3678 add_device_config(DEV_PARALLEL, optarg);
3679 default_parallel = 0;
3680 if (strncmp(optarg, "mon:", 4) == 0) {
3681 default_monitor = 0;
3684 case QEMU_OPTION_debugcon:
3685 add_device_config(DEV_DEBUGCON, optarg);
3687 case QEMU_OPTION_loadvm:
3690 case QEMU_OPTION_full_screen:
3693 case QEMU_OPTION_no_frame:
3696 case QEMU_OPTION_alt_grab:
3699 case QEMU_OPTION_ctrl_grab:
3702 case QEMU_OPTION_no_quit:
3705 case QEMU_OPTION_sdl:
3707 display_type = DT_SDL;
3710 error_report("SDL support is disabled");
3713 case QEMU_OPTION_pidfile:
3716 case QEMU_OPTION_win2k_hack:
3717 win2k_install_hack = 1;
3719 case QEMU_OPTION_rtc_td_hack: {
3720 static GlobalProperty slew_lost_ticks = {
3721 .driver = "mc146818rtc",
3722 .property = "lost_tick_policy",
3726 qdev_prop_register_global(&slew_lost_ticks);
3729 case QEMU_OPTION_acpitable:
3730 opts = qemu_opts_parse_noisily(qemu_find_opts("acpi"),
3735 acpi_table_add(opts, &error_fatal);
3737 case QEMU_OPTION_smbios:
3738 opts = qemu_opts_parse_noisily(qemu_find_opts("smbios"),
3743 smbios_entry_add(opts, &error_fatal);
3745 case QEMU_OPTION_fwcfg:
3746 opts = qemu_opts_parse_noisily(qemu_find_opts("fw_cfg"),
3752 case QEMU_OPTION_enable_kvm:
3753 olist = qemu_find_opts("machine");
3754 qemu_opts_parse_noisily(olist, "accel=kvm", false);
3756 case QEMU_OPTION_enable_hax:
3757 olist = qemu_find_opts("machine");
3758 qemu_opts_parse_noisily(olist, "accel=hax", false);
3761 case QEMU_OPTION_machine:
3762 olist = qemu_find_opts("machine");
3763 opts = qemu_opts_parse_noisily(olist, optarg, true);
3768 case QEMU_OPTION_no_kvm:
3769 olist = qemu_find_opts("machine");
3770 qemu_opts_parse_noisily(olist, "accel=tcg", false);
3772 case QEMU_OPTION_no_kvm_pit: {
3773 warn_report("ignoring deprecated option");
3776 case QEMU_OPTION_no_kvm_pit_reinjection: {
3777 static GlobalProperty kvm_pit_lost_tick_policy = {
3778 .driver = "kvm-pit",
3779 .property = "lost_tick_policy",
3783 warn_report("deprecated, replaced by "
3784 "-global kvm-pit.lost_tick_policy=discard");
3785 qdev_prop_register_global(&kvm_pit_lost_tick_policy);
3788 case QEMU_OPTION_accel:
3789 accel_opts = qemu_opts_parse_noisily(qemu_find_opts("accel"),
3791 optarg = qemu_opt_get(accel_opts, "accel");
3792 if (!optarg || is_help_option(optarg)) {
3793 error_printf("Possible accelerators: kvm, xen, hax, tcg\n");
3796 opts = qemu_opts_create(qemu_find_opts("machine"), NULL,
3797 false, &error_abort);
3798 qemu_opt_set(opts, "accel", optarg, &error_abort);
3800 case QEMU_OPTION_usb:
3801 olist = qemu_find_opts("machine");
3802 qemu_opts_parse_noisily(olist, "usb=on", false);
3804 case QEMU_OPTION_usbdevice:
3805 error_report("'-usbdevice' is deprecated, please use "
3806 "'-device usb-...' instead");
3807 olist = qemu_find_opts("machine");
3808 qemu_opts_parse_noisily(olist, "usb=on", false);
3809 add_device_config(DEV_USB, optarg);
3811 case QEMU_OPTION_device:
3812 if (!qemu_opts_parse_noisily(qemu_find_opts("device"),
3817 case QEMU_OPTION_smp:
3818 if (!qemu_opts_parse_noisily(qemu_find_opts("smp-opts"),
3823 case QEMU_OPTION_vnc:
3824 vnc_parse(optarg, &error_fatal);
3826 case QEMU_OPTION_no_acpi:
3829 case QEMU_OPTION_no_hpet:
3832 case QEMU_OPTION_balloon:
3833 if (balloon_parse(optarg) < 0) {
3834 error_report("unknown -balloon argument %s", optarg);
3838 case QEMU_OPTION_no_reboot:
3841 case QEMU_OPTION_no_shutdown:
3844 case QEMU_OPTION_show_cursor:
3847 case QEMU_OPTION_uuid:
3848 if (qemu_uuid_parse(optarg, &qemu_uuid) < 0) {
3849 error_report("failed to parse UUID string: wrong format");
3852 qemu_uuid_set = true;
3854 case QEMU_OPTION_option_rom:
3855 if (nb_option_roms >= MAX_OPTION_ROMS) {
3856 error_report("too many option ROMs");
3859 opts = qemu_opts_parse_noisily(qemu_find_opts("option-rom"),
3864 option_rom[nb_option_roms].name = qemu_opt_get(opts, "romfile");
3865 option_rom[nb_option_roms].bootindex =
3866 qemu_opt_get_number(opts, "bootindex", -1);
3867 if (!option_rom[nb_option_roms].name) {
3868 error_report("Option ROM file is not specified");
3873 case QEMU_OPTION_semihosting:
3874 semihosting.enabled = true;
3875 semihosting.target = SEMIHOSTING_TARGET_AUTO;
3877 case QEMU_OPTION_semihosting_config:
3878 semihosting.enabled = true;
3879 opts = qemu_opts_parse_noisily(qemu_find_opts("semihosting-config"),
3882 semihosting.enabled = qemu_opt_get_bool(opts, "enable",
3884 const char *target = qemu_opt_get(opts, "target");
3885 if (target != NULL) {
3886 if (strcmp("native", target) == 0) {
3887 semihosting.target = SEMIHOSTING_TARGET_NATIVE;
3888 } else if (strcmp("gdb", target) == 0) {
3889 semihosting.target = SEMIHOSTING_TARGET_GDB;
3890 } else if (strcmp("auto", target) == 0) {
3891 semihosting.target = SEMIHOSTING_TARGET_AUTO;
3893 error_report("unsupported semihosting-config %s",
3898 semihosting.target = SEMIHOSTING_TARGET_AUTO;
3900 /* Set semihosting argument count and vector */
3901 qemu_opt_foreach(opts, add_semihosting_arg,
3902 &semihosting, NULL);
3904 error_report("unsupported semihosting-config %s", optarg);
3908 case QEMU_OPTION_tdf:
3909 warn_report("ignoring deprecated option");
3911 case QEMU_OPTION_name:
3912 opts = qemu_opts_parse_noisily(qemu_find_opts("name"),
3918 case QEMU_OPTION_prom_env:
3919 if (nb_prom_envs >= MAX_PROM_ENVS) {
3920 error_report("too many prom variables");
3923 prom_envs[nb_prom_envs] = optarg;
3926 case QEMU_OPTION_old_param:
3929 case QEMU_OPTION_clock:
3930 /* Clock options no longer exist. Keep this option for
3931 * backward compatibility.
3934 case QEMU_OPTION_startdate:
3935 configure_rtc_date_offset(optarg, 1);
3937 case QEMU_OPTION_rtc:
3938 opts = qemu_opts_parse_noisily(qemu_find_opts("rtc"), optarg,
3943 configure_rtc(opts);
3945 case QEMU_OPTION_tb_size:
3947 error_report("TCG is disabled");
3950 if (qemu_strtoul(optarg, NULL, 0, &tcg_tb_size) < 0) {
3951 error_report("Invalid argument to -tb-size");
3955 case QEMU_OPTION_icount:
3956 icount_opts = qemu_opts_parse_noisily(qemu_find_opts("icount"),
3962 case QEMU_OPTION_incoming:
3964 runstate_set(RUN_STATE_INMIGRATE);
3968 case QEMU_OPTION_only_migratable:
3970 * TODO: we can remove this option one day, and we
3973 * "-global migration.only-migratable=true"
3975 qemu_global_option("migration.only-migratable=true");
3977 case QEMU_OPTION_nodefaults:
3980 case QEMU_OPTION_xen_domid:
3981 if (!(xen_available())) {
3982 error_report("Option not supported for this target");
3985 xen_domid = atoi(optarg);
3987 case QEMU_OPTION_xen_create:
3988 if (!(xen_available())) {
3989 error_report("Option not supported for this target");
3992 xen_mode = XEN_CREATE;
3994 case QEMU_OPTION_xen_attach:
3995 if (!(xen_available())) {
3996 error_report("Option not supported for this target");
3999 xen_mode = XEN_ATTACH;
4001 case QEMU_OPTION_xen_domid_restrict:
4002 if (!(xen_available())) {
4003 error_report("Option not supported for this target");
4006 xen_domid_restrict = true;
4008 case QEMU_OPTION_trace:
4010 trace_file = trace_opt_parse(optarg);
4012 case QEMU_OPTION_readconfig:
4014 int ret = qemu_read_config_file(optarg);
4016 error_report("read config %s: %s", optarg,
4022 case QEMU_OPTION_spice:
4023 olist = qemu_find_opts("spice");
4025 error_report("spice support is disabled");
4028 opts = qemu_opts_parse_noisily(olist, optarg, false);
4034 case QEMU_OPTION_writeconfig:
4037 if (strcmp(optarg, "-") == 0) {
4040 fp = fopen(optarg, "w");
4042 error_report("open %s: %s", optarg,
4047 qemu_config_write(fp);
4053 case QEMU_OPTION_qtest:
4054 qtest_chrdev = optarg;
4056 case QEMU_OPTION_qtest_log:
4059 case QEMU_OPTION_sandbox:
4060 opts = qemu_opts_parse_noisily(qemu_find_opts("sandbox"),
4066 case QEMU_OPTION_add_fd:
4068 opts = qemu_opts_parse_noisily(qemu_find_opts("add-fd"),
4074 error_report("File descriptor passing is disabled on this "
4079 case QEMU_OPTION_object:
4080 opts = qemu_opts_parse_noisily(qemu_find_opts("object"),
4086 case QEMU_OPTION_realtime:
4087 opts = qemu_opts_parse_noisily(qemu_find_opts("realtime"),
4092 enable_mlock = qemu_opt_get_bool(opts, "mlock", true);
4094 case QEMU_OPTION_msg:
4095 opts = qemu_opts_parse_noisily(qemu_find_opts("msg"), optarg,
4100 configure_msg(opts);
4102 case QEMU_OPTION_dump_vmstate:
4103 if (vmstate_dump_file) {
4104 error_report("only one '-dump-vmstate' "
4105 "option may be given");
4108 vmstate_dump_file = fopen(optarg, "w");
4109 if (vmstate_dump_file == NULL) {
4110 error_report("open %s: %s", optarg, strerror(errno));
4115 os_parse_cmd_args(popt->index, optarg);
4120 * Clear error location left behind by the loop.
4121 * Best done right after the loop. Do not insert code here!
4125 replay_configure(icount_opts);
4127 machine_class = select_machine();
4129 set_memory_options(&ram_slots, &maxram_size, machine_class);
4132 rcu_disable_atfork();
4134 if (pid_file && qemu_create_pidfile(pid_file) != 0) {
4135 error_report("could not acquire pid file: %s", strerror(errno));
4139 if (qemu_init_main_loop(&main_loop_err)) {
4140 error_report_err(main_loop_err);
4144 if (qemu_opts_foreach(qemu_find_opts("sandbox"),
4145 parse_sandbox, NULL, NULL)) {
4149 if (qemu_opts_foreach(qemu_find_opts("name"),
4150 parse_name, NULL, NULL)) {
4155 if (qemu_opts_foreach(qemu_find_opts("add-fd"),
4156 parse_add_fd, NULL, NULL)) {
4160 if (qemu_opts_foreach(qemu_find_opts("add-fd"),
4161 cleanup_add_fd, NULL, NULL)) {
4166 current_machine = MACHINE(object_new(object_class_get_name(
4167 OBJECT_CLASS(machine_class))));
4168 if (machine_help_func(qemu_get_machine_opts(), current_machine)) {
4171 object_property_add_child(object_get_root(), "machine",
4172 OBJECT(current_machine), &error_abort);
4174 if (machine_class->minimum_page_bits) {
4175 if (!set_preferred_target_page_bits(machine_class->minimum_page_bits)) {
4176 /* This would be a board error: specifying a minimum smaller than
4177 * a target's compile-time fixed setting.
4179 g_assert_not_reached();
4183 cpu_exec_init_all();
4185 if (machine_class->hw_version) {
4186 qemu_set_hw_version(machine_class->hw_version);
4189 if (cpu_model && is_help_option(cpu_model)) {
4190 list_cpus(stdout, &fprintf, cpu_model);
4194 if (!trace_init_backends()) {
4197 trace_init_file(trace_file);
4199 /* Open the logfile at this point and set the log mask if necessary.
4202 qemu_set_log_filename(log_file, &error_fatal);
4207 mask = qemu_str_to_log_mask(log_mask);
4209 qemu_print_log_usage(stdout);
4217 /* If no data_dir is specified then try to find it relative to the
4219 if (data_dir_idx < ARRAY_SIZE(data_dir)) {
4220 data_dir[data_dir_idx] = os_find_datadir();
4221 if (data_dir[data_dir_idx] != NULL) {
4225 /* If all else fails use the install path specified when building. */
4226 if (data_dir_idx < ARRAY_SIZE(data_dir)) {
4227 data_dir[data_dir_idx++] = CONFIG_QEMU_DATADIR;
4230 /* -L help lists the data directories and exits. */
4231 if (list_data_dirs) {
4232 for (i = 0; i < data_dir_idx; i++) {
4233 printf("%s\n", data_dir[i]);
4238 smp_parse(qemu_opts_find(qemu_find_opts("smp-opts"), NULL));
4240 machine_class->max_cpus = machine_class->max_cpus ?: 1; /* Default to UP */
4241 if (max_cpus > machine_class->max_cpus) {
4242 error_report("Number of SMP CPUs requested (%d) exceeds max CPUs "
4243 "supported by machine '%s' (%d)", max_cpus,
4244 machine_class->name, machine_class->max_cpus);
4249 * Get the default machine options from the machine if it is not already
4250 * specified either by the configuration file or by the command line.
4252 if (machine_class->default_machine_opts) {
4253 qemu_opts_set_defaults(qemu_find_opts("machine"),
4254 machine_class->default_machine_opts, 0);
4257 qemu_opts_foreach(qemu_find_opts("device"),
4258 default_driver_check, NULL, NULL);
4259 qemu_opts_foreach(qemu_find_opts("global"),
4260 default_driver_check, NULL, NULL);
4262 if (!vga_model && !default_vga) {
4263 vga_interface_type = VGA_DEVICE;
4265 if (!has_defaults || machine_class->no_serial) {
4268 if (!has_defaults || machine_class->no_parallel) {
4269 default_parallel = 0;
4271 if (!has_defaults || !machine_class->use_virtcon) {
4272 default_virtcon = 0;
4274 if (!has_defaults || !machine_class->use_sclp) {
4277 if (!has_defaults || machine_class->no_floppy) {
4280 if (!has_defaults || machine_class->no_cdrom) {
4283 if (!has_defaults || machine_class->no_sdcard) {
4286 if (!has_defaults) {
4287 default_monitor = 0;
4292 if (is_daemonized()) {
4293 /* According to documentation and historically, -nographic redirects
4294 * serial port, parallel port and monitor to stdio, which does not work
4295 * with -daemonize. We can redirect these to null instead, but since
4296 * -nographic is legacy, let's just error out.
4297 * We disallow -nographic only if all other ports are not redirected
4298 * explicitly, to not break existing legacy setups which uses
4299 * -nographic _and_ redirects all ports explicitly - this is valid
4300 * usage, -nographic is just a no-op in this case.
4303 && (default_parallel || default_serial
4304 || default_monitor || default_virtcon)) {
4305 error_report("-nographic cannot be used with -daemonize");
4308 #ifdef CONFIG_CURSES
4309 if (display_type == DT_CURSES) {
4310 error_report("curses display cannot be used with -daemonize");
4317 if (default_parallel)
4318 add_device_config(DEV_PARALLEL, "null");
4319 if (default_serial && default_monitor) {
4320 add_device_config(DEV_SERIAL, "mon:stdio");
4321 } else if (default_virtcon && default_monitor) {
4322 add_device_config(DEV_VIRTCON, "mon:stdio");
4323 } else if (default_sclp && default_monitor) {
4324 add_device_config(DEV_SCLP, "mon:stdio");
4327 add_device_config(DEV_SERIAL, "stdio");
4328 if (default_virtcon)
4329 add_device_config(DEV_VIRTCON, "stdio");
4331 add_device_config(DEV_SCLP, "stdio");
4333 if (default_monitor)
4334 monitor_parse("stdio", "readline", false);
4338 add_device_config(DEV_SERIAL, "vc:80Cx24C");
4339 if (default_parallel)
4340 add_device_config(DEV_PARALLEL, "vc:80Cx24C");
4341 if (default_monitor)
4342 monitor_parse("vc:80Cx24C", "readline", false);
4343 if (default_virtcon)
4344 add_device_config(DEV_VIRTCON, "vc:80Cx24C");
4346 add_device_config(DEV_SCLP, "vc:80Cx24C");
4350 #if defined(CONFIG_VNC)
4351 if (!QTAILQ_EMPTY(&(qemu_find_opts("vnc")->head))) {
4355 if (display_type == DT_DEFAULT && !display_remote) {
4356 #if defined(CONFIG_GTK)
4357 display_type = DT_GTK;
4358 #elif defined(CONFIG_SDL)
4359 display_type = DT_SDL;
4360 #elif defined(CONFIG_COCOA)
4361 display_type = DT_COCOA;
4362 #elif defined(CONFIG_VNC)
4363 vnc_parse("localhost:0,to=99,id=default", &error_abort);
4365 display_type = DT_NONE;
4369 if ((no_frame || alt_grab || ctrl_grab) && display_type != DT_SDL) {
4370 error_report("-no-frame, -alt-grab and -ctrl-grab are only valid "
4371 "for SDL, ignoring option");
4373 if (no_quit && (display_type != DT_GTK && display_type != DT_SDL)) {
4374 error_report("-no-quit is only valid for GTK and SDL, "
4378 if (display_type == DT_GTK) {
4379 early_gtk_display_init(request_opengl);
4382 if (display_type == DT_SDL) {
4383 sdl_display_early_init(request_opengl);
4386 qemu_console_early_init();
4388 if (request_opengl == 1 && display_opengl == 0) {
4389 #if defined(CONFIG_OPENGL)
4390 error_report("OpenGL is not supported by the display");
4392 error_report("OpenGL support is disabled");
4400 if (qemu_opts_foreach(qemu_find_opts("object"),
4401 user_creatable_add_opts_foreach,
4402 object_create_initial, NULL)) {
4406 if (qemu_opts_foreach(qemu_find_opts("chardev"),
4407 chardev_init_func, NULL, NULL)) {
4411 #ifdef CONFIG_VIRTFS
4412 if (qemu_opts_foreach(qemu_find_opts("fsdev"),
4413 fsdev_init_func, NULL, NULL)) {
4418 if (qemu_opts_foreach(qemu_find_opts("device"),
4419 device_help_func, NULL, NULL)) {
4423 machine_opts = qemu_get_machine_opts();
4424 if (qemu_opt_foreach(machine_opts, machine_set_property, current_machine,
4426 object_unref(OBJECT(current_machine));
4430 configure_accelerator(current_machine);
4433 * Register all the global properties, including accel properties,
4434 * machine properties, and user-specified ones.
4436 register_global_properties(current_machine);
4439 * Migration object can only be created after global properties
4440 * are applied correctly.
4442 migration_object_init();
4445 qtest_init(qtest_chrdev, qtest_log, &error_fatal);
4448 machine_opts = qemu_get_machine_opts();
4449 kernel_filename = qemu_opt_get(machine_opts, "kernel");
4450 initrd_filename = qemu_opt_get(machine_opts, "initrd");
4451 kernel_cmdline = qemu_opt_get(machine_opts, "append");
4452 bios_name = qemu_opt_get(machine_opts, "firmware");
4454 opts = qemu_opts_find(qemu_find_opts("boot-opts"), NULL);
4456 boot_order = qemu_opt_get(opts, "order");
4458 validate_bootdevices(boot_order, &error_fatal);
4461 boot_once = qemu_opt_get(opts, "once");
4463 validate_bootdevices(boot_once, &error_fatal);
4466 boot_menu = qemu_opt_get_bool(opts, "menu", boot_menu);
4467 boot_strict = qemu_opt_get_bool(opts, "strict", false);
4471 boot_order = machine_class->default_boot_order;
4474 if (!kernel_cmdline) {
4475 kernel_cmdline = "";
4476 current_machine->kernel_cmdline = (char *)kernel_cmdline;
4479 linux_boot = (kernel_filename != NULL);
4481 if (!linux_boot && *kernel_cmdline != '\0') {
4482 error_report("-append only allowed with -kernel option");
4486 if (!linux_boot && initrd_filename != NULL) {
4487 error_report("-initrd only allowed with -kernel option");
4491 if (semihosting_enabled() && !semihosting_get_argc() && kernel_filename) {
4492 /* fall back to the -kernel/-append */
4493 semihosting_arg_fallback(kernel_filename, kernel_cmdline);
4496 os_set_line_buffering();
4498 /* spice needs the timers to be initialized by this point */
4503 if (!tcg_enabled()) {
4504 error_report("-icount is not allowed with hardware virtualization");
4507 configure_icount(icount_opts, &error_abort);
4508 qemu_opts_del(icount_opts);
4511 if (tcg_enabled()) {
4512 qemu_tcg_configure(accel_opts, &error_fatal);
4516 QemuOptsList *net = qemu_find_opts("net");
4517 qemu_opts_set(net, NULL, "type", "nic", &error_abort);
4519 qemu_opts_set(net, NULL, "type", "user", &error_abort);
4525 if (net_init_clients() < 0) {
4529 if (qemu_opts_foreach(qemu_find_opts("object"),
4530 user_creatable_add_opts_foreach,
4531 object_create_delayed, NULL)) {
4536 if (tpm_init() < 0) {
4541 /* init the bluetooth world */
4542 if (foreach_device_config(DEV_BT, bt_parse))
4545 if (!xen_enabled()) {
4546 /* On 32-bit hosts, QEMU is limited by virtual address space */
4547 if (ram_size > (2047 << 20) && HOST_LONG_BITS == 32) {
4548 error_report("at most 2047 MB RAM can be simulated");
4556 /* If the currently selected machine wishes to override the units-per-bus
4557 * property of its default HBA interface type, do so now. */
4558 if (machine_class->units_per_default_bus) {
4559 override_max_devs(machine_class->block_default_type,
4560 machine_class->units_per_default_bus);
4563 /* open the virtual block devices */
4564 while (!QSIMPLEQ_EMPTY(&bdo_queue)) {
4565 BlockdevOptions_queue *bdo = QSIMPLEQ_FIRST(&bdo_queue);
4567 QSIMPLEQ_REMOVE_HEAD(&bdo_queue, entry);
4568 loc_push_restore(&bdo->loc);
4569 qmp_blockdev_add(bdo->bdo, &error_fatal);
4571 qapi_free_BlockdevOptions(bdo->bdo);
4574 if (snapshot || replay_mode != REPLAY_MODE_NONE) {
4575 qemu_opts_foreach(qemu_find_opts("drive"), drive_enable_snapshot,
4578 if (qemu_opts_foreach(qemu_find_opts("drive"), drive_init_func,
4579 &machine_class->block_default_type, NULL)) {
4583 default_drive(default_cdrom, snapshot, machine_class->block_default_type, 2,
4585 default_drive(default_floppy, snapshot, IF_FLOPPY, 0, FD_OPTS);
4586 default_drive(default_sdcard, snapshot, IF_SD, 0, SD_OPTS);
4588 parse_numa_opts(current_machine);
4590 if (qemu_opts_foreach(qemu_find_opts("mon"),
4591 mon_init_func, NULL, NULL)) {
4595 if (foreach_device_config(DEV_SERIAL, serial_parse) < 0)
4597 if (foreach_device_config(DEV_PARALLEL, parallel_parse) < 0)
4599 if (foreach_device_config(DEV_VIRTCON, virtcon_parse) < 0)
4601 if (foreach_device_config(DEV_SCLP, sclp_parse) < 0) {
4604 if (foreach_device_config(DEV_DEBUGCON, debugcon_parse) < 0)
4607 /* If no default VGA is requested, the default is "none". */
4609 if (machine_class->default_display) {
4610 vga_model = machine_class->default_display;
4611 } else if (vga_interface_available(VGA_CIRRUS)) {
4612 vga_model = "cirrus";
4613 } else if (vga_interface_available(VGA_STD)) {
4618 select_vgahw(vga_model);
4622 i = select_watchdog(watchdog);
4624 exit (i == 1 ? 1 : 0);
4627 /* This checkpoint is required by replay to separate prior clock
4628 reading from the other reads, because timer polling functions query
4629 clock values from the log. */
4630 replay_checkpoint(CHECKPOINT_INIT);
4631 qdev_machine_init();
4633 current_machine->ram_size = ram_size;
4634 current_machine->maxram_size = maxram_size;
4635 current_machine->ram_slots = ram_slots;
4636 current_machine->boot_order = boot_order;
4637 current_machine->cpu_model = cpu_model;
4639 machine_run_board_init(current_machine);
4645 if (hax_enabled()) {
4649 if (qemu_opts_foreach(qemu_find_opts("fw_cfg"),
4650 parse_fw_cfg, fw_cfg_find(), NULL) != 0) {
4654 /* init USB devices */
4655 if (machine_usb(current_machine)) {
4656 if (foreach_device_config(DEV_USB, usb_parse) < 0)
4660 /* Check if IGD GFX passthrough. */
4663 /* init generic devices */
4664 rom_set_order_override(FW_CFG_ORDER_OVERRIDE_DEVICE);
4665 if (qemu_opts_foreach(qemu_find_opts("device"),
4666 device_init_func, NULL, NULL)) {
4670 cpu_synchronize_all_post_init();
4672 rom_reset_order_override();
4675 * Create frontends for -drive if=scsi leftovers.
4676 * Normally, frontends for -drive get created by machine
4677 * initialization for onboard SCSI HBAs. However, we create a few
4678 * more ever since SCSI qdevification, but this is pretty much an
4679 * implementation accident, and deprecated.
4681 scsi_legacy_handle_cmdline();
4683 /* Did we create any drives that we failed to create a device for? */
4684 drive_check_orphaned();
4686 /* Don't warn about the default network setup that you get if
4687 * no command line -net or -netdev options are specified. There
4688 * are two cases that we would otherwise complain about:
4689 * (1) board doesn't support a NIC but the implicit "-net nic"
4691 * (2) CONFIG_SLIRP not set, in which case the implicit "-net nic"
4692 * sets up a nic that isn't connected to anything.
4695 net_check_clients();
4700 qemu_boot_set(boot_once, &error_fatal);
4701 qemu_register_reset(restore_boot_order, g_strdup(boot_order));
4704 ds = init_displaystate();
4706 /* init local displays */
4707 switch (display_type) {
4709 curses_display_init(ds, full_screen);
4712 sdl_display_init(ds, full_screen, no_frame);
4715 cocoa_display_init(ds, full_screen);
4718 gtk_display_init(ds, full_screen, grab_on_hover);
4724 /* must be after terminal init, SDL library changes signal handlers */
4725 os_setup_signal_handling();
4727 /* init remote displays */
4729 qemu_opts_foreach(qemu_find_opts("vnc"),
4730 vnc_init_func, NULL, NULL);
4734 qemu_spice_display_init();
4737 #ifdef CONFIG_OPENGL_DMABUF
4738 if (display_type == DT_EGL) {
4739 egl_headless_init();
4743 if (foreach_device_config(DEV_GDB, gdbserver_start) < 0) {
4747 qdev_machine_creation_done();
4749 /* TODO: once all bus devices are qdevified, this should be done
4750 * when bus is created by qdev.c */
4751 qemu_register_reset(qbus_reset_all_fn, sysbus_get_default());
4752 qemu_run_machine_init_done_notifiers();
4754 if (rom_check_and_register_reset() != 0) {
4755 error_report("rom check and register reset failed");
4761 /* This checkpoint is required by replay to separate prior clock
4762 reading from the other reads, because timer polling functions query
4763 clock values from the log. */
4764 replay_checkpoint(CHECKPOINT_RESET);
4765 qemu_system_reset(SHUTDOWN_CAUSE_NONE);
4766 register_global_state();
4767 if (replay_mode != REPLAY_MODE_NONE) {
4768 replay_vmstate_init();
4769 } else if (loadvm) {
4770 Error *local_err = NULL;
4771 if (load_snapshot(loadvm, &local_err) < 0) {
4772 error_report_err(local_err);
4777 qdev_prop_check_globals();
4778 if (vmstate_dump_file) {
4780 dump_vmstate_json_to_file(vmstate_dump_file);
4785 Error *local_err = NULL;
4786 qemu_start_incoming_migration(incoming, &local_err);
4788 error_reportf_err(local_err, "-incoming %s: ", incoming);
4791 } else if (autostart) {
4798 replay_disable_events();
4799 iothread_stop_all();
4805 /* vhost-user must be cleaned up before chardevs. */
4810 /* TODO: unref root container, check all devices are ok */