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
25 #include "qemu/osdep.h"
26 #include "qemu-common.h"
27 #include "qemu/units.h"
28 #include "hw/qdev-properties.h"
29 #include "qapi/error.h"
30 #include "qemu-version.h"
31 #include "qemu/cutils.h"
32 #include "qemu/help_option.h"
33 #include "qemu/uuid.h"
34 #include "sysemu/reset.h"
35 #include "sysemu/runstate.h"
36 #include "sysemu/seccomp.h"
37 #include "sysemu/tcg.h"
40 #if defined(__APPLE__) || defined(main)
41 #define SDL_MAIN_HANDLED
43 #if SDL_MAJOR_VERSION == 1
44 int qemu_main(int argc
, char **argv
);
45 int main(int argc
, char **argv
)
47 return qemu_main(argc
, argv
);
50 #define main qemu_main
51 #elif SDL_MAJOR_VERSION == 2
54 #error undefined SDL version
57 #endif /* CONFIG_SDL */
61 #define main qemu_main
62 #endif /* CONFIG_COCOA */
65 #include "qemu/error-report.h"
66 #include "qemu/sockets.h"
67 #include "sysemu/accel.h"
69 #include "hw/isa/isa.h"
70 #include "hw/scsi/scsi.h"
71 #include "hw/display/vga.h"
73 #include "sysemu/watchdog.h"
74 #include "hw/firmware/smbios.h"
75 #include "hw/acpi/acpi.h"
76 #include "hw/xen/xen.h"
77 #include "hw/loader.h"
78 #include "monitor/qdev.h"
79 #include "sysemu/bt.h"
81 #include "net/slirp.h"
82 #include "monitor/monitor.h"
83 #include "ui/console.h"
85 #include "sysemu/sysemu.h"
86 #include "sysemu/numa.h"
87 #include "exec/gdbstub.h"
88 #include "qemu/timer.h"
89 #include "chardev/char.h"
90 #include "qemu/bitmap.h"
92 #include "sysemu/blockdev.h"
93 #include "hw/block/block.h"
94 #include "migration/misc.h"
95 #include "migration/snapshot.h"
96 #include "migration/global_state.h"
97 #include "sysemu/tpm.h"
98 #include "sysemu/dma.h"
99 #include "hw/audio/soundhw.h"
100 #include "audio/audio.h"
101 #include "sysemu/cpus.h"
102 #include "migration/colo.h"
103 #include "migration/postcopy-ram.h"
104 #include "sysemu/kvm.h"
105 #include "sysemu/hax.h"
106 #include "qapi/qobject-input-visitor.h"
107 #include "qemu/option.h"
108 #include "qemu/config-file.h"
109 #include "qemu-options.h"
110 #include "qemu/main-loop.h"
112 #include "fsdev/qemu-fsdev.h"
114 #include "sysemu/qtest.h"
116 #include "disas/disas.h"
118 #include "trace-root.h"
119 #include "trace/control.h"
120 #include "qemu/plugin.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 "qapi/clone-visitor.h"
128 #include "qom/object_interfaces.h"
129 #include "hw/semihosting/semihost.h"
130 #include "crypto/init.h"
131 #include "sysemu/replay.h"
132 #include "qapi/qapi-events-run-state.h"
133 #include "qapi/qapi-visit-block-core.h"
134 #include "qapi/qapi-visit-ui.h"
135 #include "qapi/qapi-commands-block-core.h"
136 #include "qapi/qapi-commands-run-state.h"
137 #include "qapi/qapi-commands-ui.h"
138 #include "qapi/qmp/qerror.h"
139 #include "sysemu/iothread.h"
140 #include "qemu/guest-random.h"
142 #define MAX_VIRTIO_CONSOLES 1
144 static const char *data_dir
[16];
145 static int data_dir_idx
;
146 const char *bios_name
= NULL
;
147 enum vga_retrace_method vga_retrace_method
= VGA_RETRACE_DUMB
;
149 const char* keyboard_layout
= NULL
;
151 const char *mem_path
= NULL
;
152 int mem_prealloc
= 0; /* force preallocation of physical target memory */
153 bool enable_mlock
= false;
154 bool enable_cpu_pm
= false;
156 NICInfo nd_table
[MAX_NICS
];
162 } rtc_base_type
= RTC_BASE_UTC
;
163 static time_t rtc_ref_start_datetime
;
164 static int rtc_realtime_clock_offset
; /* used only with QEMU_CLOCK_REALTIME */
165 static int rtc_host_datetime_offset
= -1; /* valid & used only with
167 QEMUClockType rtc_clock
;
168 int vga_interface_type
= VGA_NONE
;
169 static DisplayOptions dpy
;
170 static int num_serial_hds
;
171 static Chardev
**serial_hds
;
172 Chardev
*parallel_hds
[MAX_PARALLEL_PORTS
];
173 int win2k_install_hack
= 0;
175 int acpi_enabled
= 1;
178 static int no_reboot
;
181 int graphic_rotate
= 0;
182 const char *watchdog
;
183 QEMUOptionRom option_rom
[MAX_OPTION_ROMS
];
186 const char *qemu_name
;
189 unsigned int nb_prom_envs
= 0;
190 const char *prom_envs
[MAX_PROM_ENVS
];
193 uint8_t *boot_splash_filedata
;
194 int only_migratable
; /* turn it off unless user states otherwise */
195 bool wakeup_suspend_enabled
;
197 int icount_align_option
;
199 /* The bytes in qemu_uuid are in the order specified by RFC4122, _not_ in the
200 * little-endian "wire format" described in the SMBIOS 2.6 specification.
205 /* Trace unassigned memory or i/o accesses. */
206 bool trace_unassigned
;
208 static NotifierList exit_notifiers
=
209 NOTIFIER_LIST_INITIALIZER(exit_notifiers
);
211 static NotifierList machine_init_done_notifiers
=
212 NOTIFIER_LIST_INITIALIZER(machine_init_done_notifiers
);
216 enum xen_mode xen_mode
= XEN_EMULATE
;
217 bool xen_domid_restrict
;
219 static int has_defaults
= 1;
220 static int default_serial
= 1;
221 static int default_parallel
= 1;
222 static int default_monitor
= 1;
223 static int default_floppy
= 1;
224 static int default_cdrom
= 1;
225 static int default_sdcard
= 1;
226 static int default_vga
= 1;
227 static int default_net
= 1;
233 { .driver
= "isa-serial", .flag
= &default_serial
},
234 { .driver
= "isa-parallel", .flag
= &default_parallel
},
235 { .driver
= "isa-fdc", .flag
= &default_floppy
},
236 { .driver
= "floppy", .flag
= &default_floppy
},
237 { .driver
= "ide-cd", .flag
= &default_cdrom
},
238 { .driver
= "ide-hd", .flag
= &default_cdrom
},
239 { .driver
= "ide-drive", .flag
= &default_cdrom
},
240 { .driver
= "scsi-cd", .flag
= &default_cdrom
},
241 { .driver
= "scsi-hd", .flag
= &default_cdrom
},
242 { .driver
= "VGA", .flag
= &default_vga
},
243 { .driver
= "isa-vga", .flag
= &default_vga
},
244 { .driver
= "cirrus-vga", .flag
= &default_vga
},
245 { .driver
= "isa-cirrus-vga", .flag
= &default_vga
},
246 { .driver
= "vmware-svga", .flag
= &default_vga
},
247 { .driver
= "qxl-vga", .flag
= &default_vga
},
248 { .driver
= "virtio-vga", .flag
= &default_vga
},
249 { .driver
= "ati-vga", .flag
= &default_vga
},
250 { .driver
= "vhost-user-vga", .flag
= &default_vga
},
253 static QemuOptsList qemu_rtc_opts
= {
255 .head
= QTAILQ_HEAD_INITIALIZER(qemu_rtc_opts
.head
),
260 .type
= QEMU_OPT_STRING
,
263 .type
= QEMU_OPT_STRING
,
266 .type
= QEMU_OPT_STRING
,
268 { /* end of list */ }
272 static QemuOptsList qemu_option_rom_opts
= {
273 .name
= "option-rom",
274 .implied_opt_name
= "romfile",
275 .head
= QTAILQ_HEAD_INITIALIZER(qemu_option_rom_opts
.head
),
279 .type
= QEMU_OPT_NUMBER
,
282 .type
= QEMU_OPT_STRING
,
284 { /* end of list */ }
288 static QemuOptsList qemu_machine_opts
= {
290 .implied_opt_name
= "type",
292 .head
= QTAILQ_HEAD_INITIALIZER(qemu_machine_opts
.head
),
295 * no elements => accept any
296 * sanity checking will happen later
297 * when setting machine properties
303 static QemuOptsList qemu_accel_opts
= {
305 .implied_opt_name
= "accel",
306 .head
= QTAILQ_HEAD_INITIALIZER(qemu_accel_opts
.head
),
311 .type
= QEMU_OPT_STRING
,
312 .help
= "Select the type of accelerator",
316 .type
= QEMU_OPT_STRING
,
317 .help
= "Enable/disable multi-threaded TCG",
319 { /* end of list */ }
323 static QemuOptsList qemu_boot_opts
= {
325 .implied_opt_name
= "order",
327 .head
= QTAILQ_HEAD_INITIALIZER(qemu_boot_opts
.head
),
331 .type
= QEMU_OPT_STRING
,
334 .type
= QEMU_OPT_STRING
,
337 .type
= QEMU_OPT_BOOL
,
340 .type
= QEMU_OPT_STRING
,
342 .name
= "splash-time",
343 .type
= QEMU_OPT_NUMBER
,
345 .name
= "reboot-timeout",
346 .type
= QEMU_OPT_NUMBER
,
349 .type
= QEMU_OPT_BOOL
,
355 static QemuOptsList qemu_add_fd_opts
= {
357 .head
= QTAILQ_HEAD_INITIALIZER(qemu_add_fd_opts
.head
),
361 .type
= QEMU_OPT_NUMBER
,
362 .help
= "file descriptor of which a duplicate is added to fd set",
365 .type
= QEMU_OPT_NUMBER
,
366 .help
= "ID of the fd set to add fd to",
369 .type
= QEMU_OPT_STRING
,
370 .help
= "free-form string used to describe fd",
372 { /* end of list */ }
376 static QemuOptsList qemu_object_opts
= {
378 .implied_opt_name
= "qom-type",
379 .head
= QTAILQ_HEAD_INITIALIZER(qemu_object_opts
.head
),
385 static QemuOptsList qemu_tpmdev_opts
= {
387 .implied_opt_name
= "type",
388 .head
= QTAILQ_HEAD_INITIALIZER(qemu_tpmdev_opts
.head
),
390 /* options are defined in the TPM backends */
391 { /* end of list */ }
395 static QemuOptsList qemu_realtime_opts
= {
397 .head
= QTAILQ_HEAD_INITIALIZER(qemu_realtime_opts
.head
),
401 .type
= QEMU_OPT_BOOL
,
403 { /* end of list */ }
407 static QemuOptsList qemu_overcommit_opts
= {
408 .name
= "overcommit",
409 .head
= QTAILQ_HEAD_INITIALIZER(qemu_overcommit_opts
.head
),
413 .type
= QEMU_OPT_BOOL
,
417 .type
= QEMU_OPT_BOOL
,
419 { /* end of list */ }
423 static QemuOptsList qemu_msg_opts
= {
425 .head
= QTAILQ_HEAD_INITIALIZER(qemu_msg_opts
.head
),
429 .type
= QEMU_OPT_BOOL
,
431 { /* end of list */ }
435 static QemuOptsList qemu_name_opts
= {
437 .implied_opt_name
= "guest",
439 .head
= QTAILQ_HEAD_INITIALIZER(qemu_name_opts
.head
),
443 .type
= QEMU_OPT_STRING
,
444 .help
= "Sets the name of the guest.\n"
445 "This name will be displayed in the SDL window caption.\n"
446 "The name will also be used for the VNC server",
449 .type
= QEMU_OPT_STRING
,
450 .help
= "Sets the name of the QEMU process, as shown in top etc",
452 .name
= "debug-threads",
453 .type
= QEMU_OPT_BOOL
,
454 .help
= "When enabled, name the individual threads; defaults off.\n"
455 "NOTE: The thread names are for debugging and not a\n"
458 { /* End of list */ }
462 static QemuOptsList qemu_mem_opts
= {
464 .implied_opt_name
= "size",
465 .head
= QTAILQ_HEAD_INITIALIZER(qemu_mem_opts
.head
),
470 .type
= QEMU_OPT_SIZE
,
474 .type
= QEMU_OPT_NUMBER
,
478 .type
= QEMU_OPT_SIZE
,
480 { /* end of list */ }
484 static QemuOptsList qemu_icount_opts
= {
486 .implied_opt_name
= "shift",
488 .head
= QTAILQ_HEAD_INITIALIZER(qemu_icount_opts
.head
),
492 .type
= QEMU_OPT_STRING
,
495 .type
= QEMU_OPT_BOOL
,
498 .type
= QEMU_OPT_BOOL
,
501 .type
= QEMU_OPT_STRING
,
504 .type
= QEMU_OPT_STRING
,
506 .name
= "rrsnapshot",
507 .type
= QEMU_OPT_STRING
,
509 { /* end of list */ }
513 static QemuOptsList qemu_fw_cfg_opts
= {
515 .implied_opt_name
= "name",
516 .head
= QTAILQ_HEAD_INITIALIZER(qemu_fw_cfg_opts
.head
),
520 .type
= QEMU_OPT_STRING
,
521 .help
= "Sets the fw_cfg name of the blob to be inserted",
524 .type
= QEMU_OPT_STRING
,
525 .help
= "Sets the name of the file from which "
526 "the fw_cfg blob will be loaded",
529 .type
= QEMU_OPT_STRING
,
530 .help
= "Sets content of the blob to be inserted from a string",
532 { /* end of list */ }
537 * Get machine options
539 * Returns: machine options (never null).
541 QemuOpts
*qemu_get_machine_opts(void)
543 return qemu_find_opts_singleton("machine");
546 const char *qemu_get_vm_name(void)
551 static void res_free(void)
553 g_free(boot_splash_filedata
);
554 boot_splash_filedata
= NULL
;
557 static int default_driver_check(void *opaque
, QemuOpts
*opts
, Error
**errp
)
559 const char *driver
= qemu_opt_get(opts
, "driver");
564 for (i
= 0; i
< ARRAY_SIZE(default_list
); i
++) {
565 if (strcmp(default_list
[i
].driver
, driver
) != 0)
567 *(default_list
[i
].flag
) = 0;
572 /***********************************************************/
575 static RunState current_run_state
= RUN_STATE_PRECONFIG
;
577 /* We use RUN_STATE__MAX but any invalid value will do */
578 static RunState vmstop_requested
= RUN_STATE__MAX
;
579 static QemuMutex vmstop_lock
;
584 } RunStateTransition
;
586 static const RunStateTransition runstate_transitions_def
[] = {
588 { RUN_STATE_PRECONFIG
, RUN_STATE_PRELAUNCH
},
589 /* Early switch to inmigrate state to allow -incoming CLI option work
590 * as it used to. TODO: delay actual switching to inmigrate state to
591 * the point after machine is built and remove this hack.
593 { RUN_STATE_PRECONFIG
, RUN_STATE_INMIGRATE
},
595 { RUN_STATE_DEBUG
, RUN_STATE_RUNNING
},
596 { RUN_STATE_DEBUG
, RUN_STATE_FINISH_MIGRATE
},
597 { RUN_STATE_DEBUG
, RUN_STATE_PRELAUNCH
},
599 { RUN_STATE_INMIGRATE
, RUN_STATE_INTERNAL_ERROR
},
600 { RUN_STATE_INMIGRATE
, RUN_STATE_IO_ERROR
},
601 { RUN_STATE_INMIGRATE
, RUN_STATE_PAUSED
},
602 { RUN_STATE_INMIGRATE
, RUN_STATE_RUNNING
},
603 { RUN_STATE_INMIGRATE
, RUN_STATE_SHUTDOWN
},
604 { RUN_STATE_INMIGRATE
, RUN_STATE_SUSPENDED
},
605 { RUN_STATE_INMIGRATE
, RUN_STATE_WATCHDOG
},
606 { RUN_STATE_INMIGRATE
, RUN_STATE_GUEST_PANICKED
},
607 { RUN_STATE_INMIGRATE
, RUN_STATE_FINISH_MIGRATE
},
608 { RUN_STATE_INMIGRATE
, RUN_STATE_PRELAUNCH
},
609 { RUN_STATE_INMIGRATE
, RUN_STATE_POSTMIGRATE
},
610 { RUN_STATE_INMIGRATE
, RUN_STATE_COLO
},
612 { RUN_STATE_INTERNAL_ERROR
, RUN_STATE_PAUSED
},
613 { RUN_STATE_INTERNAL_ERROR
, RUN_STATE_FINISH_MIGRATE
},
614 { RUN_STATE_INTERNAL_ERROR
, RUN_STATE_PRELAUNCH
},
616 { RUN_STATE_IO_ERROR
, RUN_STATE_RUNNING
},
617 { RUN_STATE_IO_ERROR
, RUN_STATE_FINISH_MIGRATE
},
618 { RUN_STATE_IO_ERROR
, RUN_STATE_PRELAUNCH
},
620 { RUN_STATE_PAUSED
, RUN_STATE_RUNNING
},
621 { RUN_STATE_PAUSED
, RUN_STATE_FINISH_MIGRATE
},
622 { RUN_STATE_PAUSED
, RUN_STATE_POSTMIGRATE
},
623 { RUN_STATE_PAUSED
, RUN_STATE_PRELAUNCH
},
624 { RUN_STATE_PAUSED
, RUN_STATE_COLO
},
626 { RUN_STATE_POSTMIGRATE
, RUN_STATE_RUNNING
},
627 { RUN_STATE_POSTMIGRATE
, RUN_STATE_FINISH_MIGRATE
},
628 { RUN_STATE_POSTMIGRATE
, RUN_STATE_PRELAUNCH
},
630 { RUN_STATE_PRELAUNCH
, RUN_STATE_RUNNING
},
631 { RUN_STATE_PRELAUNCH
, RUN_STATE_FINISH_MIGRATE
},
632 { RUN_STATE_PRELAUNCH
, RUN_STATE_INMIGRATE
},
634 { RUN_STATE_FINISH_MIGRATE
, RUN_STATE_RUNNING
},
635 { RUN_STATE_FINISH_MIGRATE
, RUN_STATE_PAUSED
},
636 { RUN_STATE_FINISH_MIGRATE
, RUN_STATE_POSTMIGRATE
},
637 { RUN_STATE_FINISH_MIGRATE
, RUN_STATE_PRELAUNCH
},
638 { RUN_STATE_FINISH_MIGRATE
, RUN_STATE_COLO
},
640 { RUN_STATE_RESTORE_VM
, RUN_STATE_RUNNING
},
641 { RUN_STATE_RESTORE_VM
, RUN_STATE_PRELAUNCH
},
643 { RUN_STATE_COLO
, RUN_STATE_RUNNING
},
645 { RUN_STATE_RUNNING
, RUN_STATE_DEBUG
},
646 { RUN_STATE_RUNNING
, RUN_STATE_INTERNAL_ERROR
},
647 { RUN_STATE_RUNNING
, RUN_STATE_IO_ERROR
},
648 { RUN_STATE_RUNNING
, RUN_STATE_PAUSED
},
649 { RUN_STATE_RUNNING
, RUN_STATE_FINISH_MIGRATE
},
650 { RUN_STATE_RUNNING
, RUN_STATE_RESTORE_VM
},
651 { RUN_STATE_RUNNING
, RUN_STATE_SAVE_VM
},
652 { RUN_STATE_RUNNING
, RUN_STATE_SHUTDOWN
},
653 { RUN_STATE_RUNNING
, RUN_STATE_WATCHDOG
},
654 { RUN_STATE_RUNNING
, RUN_STATE_GUEST_PANICKED
},
655 { RUN_STATE_RUNNING
, RUN_STATE_COLO
},
657 { RUN_STATE_SAVE_VM
, RUN_STATE_RUNNING
},
659 { RUN_STATE_SHUTDOWN
, RUN_STATE_PAUSED
},
660 { RUN_STATE_SHUTDOWN
, RUN_STATE_FINISH_MIGRATE
},
661 { RUN_STATE_SHUTDOWN
, RUN_STATE_PRELAUNCH
},
663 { RUN_STATE_DEBUG
, RUN_STATE_SUSPENDED
},
664 { RUN_STATE_RUNNING
, RUN_STATE_SUSPENDED
},
665 { RUN_STATE_SUSPENDED
, RUN_STATE_RUNNING
},
666 { RUN_STATE_SUSPENDED
, RUN_STATE_FINISH_MIGRATE
},
667 { RUN_STATE_SUSPENDED
, RUN_STATE_PRELAUNCH
},
668 { RUN_STATE_SUSPENDED
, RUN_STATE_COLO
},
670 { RUN_STATE_WATCHDOG
, RUN_STATE_RUNNING
},
671 { RUN_STATE_WATCHDOG
, RUN_STATE_FINISH_MIGRATE
},
672 { RUN_STATE_WATCHDOG
, RUN_STATE_PRELAUNCH
},
673 { RUN_STATE_WATCHDOG
, RUN_STATE_COLO
},
675 { RUN_STATE_GUEST_PANICKED
, RUN_STATE_RUNNING
},
676 { RUN_STATE_GUEST_PANICKED
, RUN_STATE_FINISH_MIGRATE
},
677 { RUN_STATE_GUEST_PANICKED
, RUN_STATE_PRELAUNCH
},
679 { RUN_STATE__MAX
, RUN_STATE__MAX
},
682 static bool runstate_valid_transitions
[RUN_STATE__MAX
][RUN_STATE__MAX
];
684 bool runstate_check(RunState state
)
686 return current_run_state
== state
;
689 bool runstate_store(char *str
, size_t size
)
691 const char *state
= RunState_str(current_run_state
);
692 size_t len
= strlen(state
) + 1;
697 memcpy(str
, state
, len
);
701 static void runstate_init(void)
703 const RunStateTransition
*p
;
705 memset(&runstate_valid_transitions
, 0, sizeof(runstate_valid_transitions
));
706 for (p
= &runstate_transitions_def
[0]; p
->from
!= RUN_STATE__MAX
; p
++) {
707 runstate_valid_transitions
[p
->from
][p
->to
] = true;
710 qemu_mutex_init(&vmstop_lock
);
713 /* This function will abort() on invalid state transitions */
714 void runstate_set(RunState new_state
)
716 assert(new_state
< RUN_STATE__MAX
);
718 trace_runstate_set(current_run_state
, RunState_str(current_run_state
),
719 new_state
, RunState_str(new_state
));
721 if (current_run_state
== new_state
) {
725 if (!runstate_valid_transitions
[current_run_state
][new_state
]) {
726 error_report("invalid runstate transition: '%s' -> '%s'",
727 RunState_str(current_run_state
),
728 RunState_str(new_state
));
732 current_run_state
= new_state
;
735 int runstate_is_running(void)
737 return runstate_check(RUN_STATE_RUNNING
);
740 bool runstate_needs_reset(void)
742 return runstate_check(RUN_STATE_INTERNAL_ERROR
) ||
743 runstate_check(RUN_STATE_SHUTDOWN
);
746 StatusInfo
*qmp_query_status(Error
**errp
)
748 StatusInfo
*info
= g_malloc0(sizeof(*info
));
750 info
->running
= runstate_is_running();
751 info
->singlestep
= singlestep
;
752 info
->status
= current_run_state
;
757 bool qemu_vmstop_requested(RunState
*r
)
759 qemu_mutex_lock(&vmstop_lock
);
760 *r
= vmstop_requested
;
761 vmstop_requested
= RUN_STATE__MAX
;
762 qemu_mutex_unlock(&vmstop_lock
);
763 return *r
< RUN_STATE__MAX
;
766 void qemu_system_vmstop_request_prepare(void)
768 qemu_mutex_lock(&vmstop_lock
);
771 void qemu_system_vmstop_request(RunState state
)
773 vmstop_requested
= state
;
774 qemu_mutex_unlock(&vmstop_lock
);
778 /***********************************************************/
779 /* RTC reference time/date access */
780 static time_t qemu_ref_timedate(QEMUClockType clock
)
782 time_t value
= qemu_clock_get_ms(clock
) / 1000;
784 case QEMU_CLOCK_REALTIME
:
785 value
-= rtc_realtime_clock_offset
;
787 case QEMU_CLOCK_VIRTUAL
:
788 value
+= rtc_ref_start_datetime
;
790 case QEMU_CLOCK_HOST
:
791 if (rtc_base_type
== RTC_BASE_DATETIME
) {
792 value
-= rtc_host_datetime_offset
;
801 void qemu_get_timedate(struct tm
*tm
, int offset
)
803 time_t ti
= qemu_ref_timedate(rtc_clock
);
807 switch (rtc_base_type
) {
808 case RTC_BASE_DATETIME
:
812 case RTC_BASE_LOCALTIME
:
813 localtime_r(&ti
, tm
);
818 int qemu_timedate_diff(struct tm
*tm
)
822 switch (rtc_base_type
) {
823 case RTC_BASE_DATETIME
:
825 seconds
= mktimegm(tm
);
827 case RTC_BASE_LOCALTIME
:
830 tmp
.tm_isdst
= -1; /* use timezone to figure it out */
831 seconds
= mktime(&tmp
);
838 return seconds
- qemu_ref_timedate(QEMU_CLOCK_HOST
);
841 static void configure_rtc_base_datetime(const char *startdate
)
843 time_t rtc_start_datetime
;
846 if (sscanf(startdate
, "%d-%d-%dT%d:%d:%d", &tm
.tm_year
, &tm
.tm_mon
,
847 &tm
.tm_mday
, &tm
.tm_hour
, &tm
.tm_min
, &tm
.tm_sec
) == 6) {
849 } else if (sscanf(startdate
, "%d-%d-%d",
850 &tm
.tm_year
, &tm
.tm_mon
, &tm
.tm_mday
) == 3) {
859 rtc_start_datetime
= mktimegm(&tm
);
860 if (rtc_start_datetime
== -1) {
862 error_report("invalid datetime format");
863 error_printf("valid formats: "
864 "'2006-06-17T16:01:21' or '2006-06-17'\n");
867 rtc_host_datetime_offset
= rtc_ref_start_datetime
- rtc_start_datetime
;
868 rtc_ref_start_datetime
= rtc_start_datetime
;
871 static void configure_rtc(QemuOpts
*opts
)
876 rtc_clock
= QEMU_CLOCK_HOST
;
877 rtc_ref_start_datetime
= qemu_clock_get_ms(QEMU_CLOCK_HOST
) / 1000;
878 rtc_realtime_clock_offset
= qemu_clock_get_ms(QEMU_CLOCK_REALTIME
) / 1000;
880 value
= qemu_opt_get(opts
, "base");
882 if (!strcmp(value
, "utc")) {
883 rtc_base_type
= RTC_BASE_UTC
;
884 } else if (!strcmp(value
, "localtime")) {
885 Error
*blocker
= NULL
;
886 rtc_base_type
= RTC_BASE_LOCALTIME
;
887 error_setg(&blocker
, QERR_REPLAY_NOT_SUPPORTED
,
888 "-rtc base=localtime");
889 replay_add_blocker(blocker
);
891 rtc_base_type
= RTC_BASE_DATETIME
;
892 configure_rtc_base_datetime(value
);
895 value
= qemu_opt_get(opts
, "clock");
897 if (!strcmp(value
, "host")) {
898 rtc_clock
= QEMU_CLOCK_HOST
;
899 } else if (!strcmp(value
, "rt")) {
900 rtc_clock
= QEMU_CLOCK_REALTIME
;
901 } else if (!strcmp(value
, "vm")) {
902 rtc_clock
= QEMU_CLOCK_VIRTUAL
;
904 error_report("invalid option value '%s'", value
);
908 value
= qemu_opt_get(opts
, "driftfix");
910 if (!strcmp(value
, "slew")) {
911 static GlobalProperty slew_lost_ticks
= {
912 .driver
= "mc146818rtc",
913 .property
= "lost_tick_policy",
917 qdev_prop_register_global(&slew_lost_ticks
);
918 } else if (!strcmp(value
, "none")) {
919 /* discard is default */
921 error_report("invalid option value '%s'", value
);
927 /***********************************************************/
928 /* Bluetooth support */
931 static struct HCIInfo
*hci_table
[MAX_NICS
];
933 struct HCIInfo
*qemu_next_hci(void)
935 if (cur_hci
== nb_hcis
)
938 return hci_table
[cur_hci
++];
941 static int bt_hci_parse(const char *str
)
946 if (nb_hcis
>= MAX_NICS
) {
947 error_report("too many bluetooth HCIs (max %i)", MAX_NICS
);
960 bdaddr
.b
[5] = 0x56 + nb_hcis
;
961 hci
->bdaddr_set(hci
, bdaddr
.b
);
963 hci_table
[nb_hcis
++] = hci
;
968 static void bt_vhci_add(int vlan_id
)
970 struct bt_scatternet_s
*vlan
= qemu_find_bt_vlan(vlan_id
);
973 warn_report("adding a VHCI to an empty scatternet %i",
976 bt_vhci_init(bt_new_hci(vlan
));
979 static struct bt_device_s
*bt_device_add(const char *opt
)
981 struct bt_scatternet_s
*vlan
;
983 char *endp
= strstr(opt
, ",vlan=");
984 int len
= (endp
? endp
- opt
: strlen(opt
)) + 1;
987 pstrcpy(devname
, MIN(sizeof(devname
), len
), opt
);
990 vlan_id
= strtol(endp
+ 6, &endp
, 0);
992 error_report("unrecognised bluetooth vlan Id");
997 vlan
= qemu_find_bt_vlan(vlan_id
);
1000 warn_report("adding a slave device to an empty scatternet %i",
1003 if (!strcmp(devname
, "keyboard"))
1004 return bt_keyboard_init(vlan
);
1006 error_report("unsupported bluetooth device '%s'", devname
);
1010 static int bt_parse(const char *opt
)
1012 const char *endp
, *p
;
1015 if (strstart(opt
, "hci", &endp
)) {
1016 if (!*endp
|| *endp
== ',') {
1018 if (!strstart(endp
, ",vlan=", 0))
1021 return bt_hci_parse(opt
);
1023 } else if (strstart(opt
, "vhci", &endp
)) {
1024 if (!*endp
|| *endp
== ',') {
1026 if (strstart(endp
, ",vlan=", &p
)) {
1027 vlan
= strtol(p
, (char **) &endp
, 0);
1029 error_report("bad scatternet '%s'", p
);
1033 error_report("bad parameter '%s'", endp
+ 1);
1042 } else if (strstart(opt
, "device:", &endp
))
1043 return !bt_device_add(endp
);
1045 error_report("bad bluetooth parameter '%s'", opt
);
1049 static int parse_name(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1051 const char *proc_name
;
1053 if (qemu_opt_get(opts
, "debug-threads")) {
1054 qemu_thread_naming(qemu_opt_get_bool(opts
, "debug-threads", false));
1056 qemu_name
= qemu_opt_get(opts
, "guest");
1058 proc_name
= qemu_opt_get(opts
, "process");
1060 os_set_proc_name(proc_name
);
1066 bool defaults_enabled(void)
1068 return has_defaults
;
1072 static int parse_add_fd(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1074 int fd
, dupfd
, flags
;
1076 const char *fd_opaque
= NULL
;
1079 fd
= qemu_opt_get_number(opts
, "fd", -1);
1080 fdset_id
= qemu_opt_get_number(opts
, "set", -1);
1081 fd_opaque
= qemu_opt_get(opts
, "opaque");
1084 error_setg(errp
, "fd option is required and must be non-negative");
1088 if (fd
<= STDERR_FILENO
) {
1089 error_setg(errp
, "fd cannot be a standard I/O stream");
1094 * All fds inherited across exec() necessarily have FD_CLOEXEC
1095 * clear, while qemu sets FD_CLOEXEC on all other fds used internally.
1097 flags
= fcntl(fd
, F_GETFD
);
1098 if (flags
== -1 || (flags
& FD_CLOEXEC
)) {
1099 error_setg(errp
, "fd is not valid or already in use");
1104 error_setg(errp
, "set option is required and must be non-negative");
1108 #ifdef F_DUPFD_CLOEXEC
1109 dupfd
= fcntl(fd
, F_DUPFD_CLOEXEC
, 0);
1113 qemu_set_cloexec(dupfd
);
1117 error_setg(errp
, "error duplicating fd: %s", strerror(errno
));
1121 /* add the duplicate fd, and optionally the opaque string, to the fd set */
1122 fdinfo
= monitor_fdset_add_fd(dupfd
, true, fdset_id
, !!fd_opaque
, fd_opaque
,
1129 static int cleanup_add_fd(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1133 fd
= qemu_opt_get_number(opts
, "fd", -1);
1140 /***********************************************************/
1141 /* QEMU Block devices */
1143 #define HD_OPTS "media=disk"
1144 #define CDROM_OPTS "media=cdrom"
1146 #define PFLASH_OPTS ""
1150 static int drive_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1152 BlockInterfaceType
*block_default_type
= opaque
;
1154 return drive_new(opts
, *block_default_type
, errp
) == NULL
;
1157 static int drive_enable_snapshot(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1159 if (qemu_opt_get(opts
, "snapshot") == NULL
) {
1160 qemu_opt_set(opts
, "snapshot", "on", &error_abort
);
1165 static void default_drive(int enable
, int snapshot
, BlockInterfaceType type
,
1166 int index
, const char *optstr
)
1171 if (!enable
|| drive_get_by_index(type
, index
)) {
1175 opts
= drive_add(type
, index
, NULL
, optstr
);
1177 drive_enable_snapshot(NULL
, opts
, NULL
);
1180 dinfo
= drive_new(opts
, type
, &error_abort
);
1181 dinfo
->is_default
= true;
1185 typedef struct BlockdevOptionsQueueEntry
{
1186 BlockdevOptions
*bdo
;
1188 QSIMPLEQ_ENTRY(BlockdevOptionsQueueEntry
) entry
;
1189 } BlockdevOptionsQueueEntry
;
1191 typedef QSIMPLEQ_HEAD(, BlockdevOptionsQueueEntry
) BlockdevOptionsQueue
;
1193 static void configure_blockdev(BlockdevOptionsQueue
*bdo_queue
,
1194 MachineClass
*machine_class
, int snapshot
)
1197 * If the currently selected machine wishes to override the
1198 * units-per-bus property of its default HBA interface type, do so
1201 if (machine_class
->units_per_default_bus
) {
1202 override_max_devs(machine_class
->block_default_type
,
1203 machine_class
->units_per_default_bus
);
1206 /* open the virtual block devices */
1207 while (!QSIMPLEQ_EMPTY(bdo_queue
)) {
1208 BlockdevOptionsQueueEntry
*bdo
= QSIMPLEQ_FIRST(bdo_queue
);
1210 QSIMPLEQ_REMOVE_HEAD(bdo_queue
, entry
);
1211 loc_push_restore(&bdo
->loc
);
1212 qmp_blockdev_add(bdo
->bdo
, &error_fatal
);
1214 qapi_free_BlockdevOptions(bdo
->bdo
);
1218 qemu_opts_foreach(qemu_find_opts("drive"), drive_enable_snapshot
,
1221 if (qemu_opts_foreach(qemu_find_opts("drive"), drive_init_func
,
1222 &machine_class
->block_default_type
, &error_fatal
)) {
1223 /* We printed help */
1227 default_drive(default_cdrom
, snapshot
, machine_class
->block_default_type
, 2,
1229 default_drive(default_floppy
, snapshot
, IF_FLOPPY
, 0, FD_OPTS
);
1230 default_drive(default_sdcard
, snapshot
, IF_SD
, 0, SD_OPTS
);
1234 static QemuOptsList qemu_smp_opts
= {
1236 .implied_opt_name
= "cpus",
1237 .merge_lists
= true,
1238 .head
= QTAILQ_HEAD_INITIALIZER(qemu_smp_opts
.head
),
1242 .type
= QEMU_OPT_NUMBER
,
1245 .type
= QEMU_OPT_NUMBER
,
1248 .type
= QEMU_OPT_NUMBER
,
1251 .type
= QEMU_OPT_NUMBER
,
1254 .type
= QEMU_OPT_NUMBER
,
1257 .type
= QEMU_OPT_NUMBER
,
1259 { /*End of list */ }
1263 static void realtime_init(void)
1266 if (os_mlock() < 0) {
1267 error_report("locking memory failed");
1274 static void configure_msg(QemuOpts
*opts
)
1276 enable_timestamp_msg
= qemu_opt_get_bool(opts
, "timestamp", true);
1280 /* Now we still need this for compatibility with XEN. */
1281 bool has_igd_gfx_passthru
;
1282 static void igd_gfx_passthru(void)
1284 has_igd_gfx_passthru
= current_machine
->igd_gfx_passthru
;
1287 /***********************************************************/
1290 static int usb_device_add(const char *devname
)
1292 USBDevice
*dev
= NULL
;
1294 if (!machine_usb(current_machine
)) {
1298 dev
= usbdevice_create(devname
);
1305 static int usb_parse(const char *cmdline
)
1308 r
= usb_device_add(cmdline
);
1310 error_report("could not add USB device '%s'", cmdline
);
1315 /***********************************************************/
1316 /* machine registration */
1318 MachineState
*current_machine
;
1320 static MachineClass
*find_machine(const char *name
, GSList
*machines
)
1324 for (el
= machines
; el
; el
= el
->next
) {
1325 MachineClass
*mc
= el
->data
;
1327 if (!strcmp(mc
->name
, name
) || !g_strcmp0(mc
->alias
, name
)) {
1335 static MachineClass
*find_default_machine(GSList
*machines
)
1339 for (el
= machines
; el
; el
= el
->next
) {
1340 MachineClass
*mc
= el
->data
;
1342 if (mc
->is_default
) {
1350 static int machine_help_func(QemuOpts
*opts
, MachineState
*machine
)
1352 ObjectProperty
*prop
;
1353 ObjectPropertyIterator iter
;
1355 if (!qemu_opt_has_help_opt(opts
)) {
1359 object_property_iter_init(&iter
, OBJECT(machine
));
1360 while ((prop
= object_property_iter_next(&iter
))) {
1365 printf("%s.%s=%s", MACHINE_GET_CLASS(machine
)->name
,
1366 prop
->name
, prop
->type
);
1367 if (prop
->description
) {
1368 printf(" (%s)\n", prop
->description
);
1377 struct VMChangeStateEntry
{
1378 VMChangeStateHandler
*cb
;
1380 QTAILQ_ENTRY(VMChangeStateEntry
) entries
;
1384 static QTAILQ_HEAD(, VMChangeStateEntry
) vm_change_state_head
;
1387 * qemu_add_vm_change_state_handler_prio:
1388 * @cb: the callback to invoke
1389 * @opaque: user data passed to the callback
1390 * @priority: low priorities execute first when the vm runs and the reverse is
1391 * true when the vm stops
1393 * Register a callback function that is invoked when the vm starts or stops
1396 * Returns: an entry to be freed using qemu_del_vm_change_state_handler()
1398 VMChangeStateEntry
*qemu_add_vm_change_state_handler_prio(
1399 VMChangeStateHandler
*cb
, void *opaque
, int priority
)
1401 VMChangeStateEntry
*e
;
1402 VMChangeStateEntry
*other
;
1404 e
= g_malloc0(sizeof(*e
));
1407 e
->priority
= priority
;
1409 /* Keep list sorted in ascending priority order */
1410 QTAILQ_FOREACH(other
, &vm_change_state_head
, entries
) {
1411 if (priority
< other
->priority
) {
1412 QTAILQ_INSERT_BEFORE(other
, e
, entries
);
1417 QTAILQ_INSERT_TAIL(&vm_change_state_head
, e
, entries
);
1421 VMChangeStateEntry
*qemu_add_vm_change_state_handler(VMChangeStateHandler
*cb
,
1424 return qemu_add_vm_change_state_handler_prio(cb
, opaque
, 0);
1427 void qemu_del_vm_change_state_handler(VMChangeStateEntry
*e
)
1429 QTAILQ_REMOVE(&vm_change_state_head
, e
, entries
);
1433 void vm_state_notify(int running
, RunState state
)
1435 VMChangeStateEntry
*e
, *next
;
1437 trace_vm_state_notify(running
, state
, RunState_str(state
));
1440 QTAILQ_FOREACH_SAFE(e
, &vm_change_state_head
, entries
, next
) {
1441 e
->cb(e
->opaque
, running
, state
);
1444 QTAILQ_FOREACH_REVERSE_SAFE(e
, &vm_change_state_head
, entries
, next
) {
1445 e
->cb(e
->opaque
, running
, state
);
1450 static ShutdownCause reset_requested
;
1451 static ShutdownCause shutdown_requested
;
1452 static int shutdown_signal
;
1453 static pid_t shutdown_pid
;
1454 static int powerdown_requested
;
1455 static int debug_requested
;
1456 static int suspend_requested
;
1457 static bool preconfig_exit_requested
= true;
1458 static WakeupReason wakeup_reason
;
1459 static NotifierList powerdown_notifiers
=
1460 NOTIFIER_LIST_INITIALIZER(powerdown_notifiers
);
1461 static NotifierList suspend_notifiers
=
1462 NOTIFIER_LIST_INITIALIZER(suspend_notifiers
);
1463 static NotifierList wakeup_notifiers
=
1464 NOTIFIER_LIST_INITIALIZER(wakeup_notifiers
);
1465 static NotifierList shutdown_notifiers
=
1466 NOTIFIER_LIST_INITIALIZER(shutdown_notifiers
);
1467 static uint32_t wakeup_reason_mask
= ~(1 << QEMU_WAKEUP_REASON_NONE
);
1469 ShutdownCause
qemu_shutdown_requested_get(void)
1471 return shutdown_requested
;
1474 ShutdownCause
qemu_reset_requested_get(void)
1476 return reset_requested
;
1479 static int qemu_shutdown_requested(void)
1481 return atomic_xchg(&shutdown_requested
, SHUTDOWN_CAUSE_NONE
);
1484 static void qemu_kill_report(void)
1486 if (!qtest_driver() && shutdown_signal
) {
1487 if (shutdown_pid
== 0) {
1488 /* This happens for eg ^C at the terminal, so it's worth
1489 * avoiding printing an odd message in that case.
1491 error_report("terminating on signal %d", shutdown_signal
);
1493 char *shutdown_cmd
= qemu_get_pid_name(shutdown_pid
);
1495 error_report("terminating on signal %d from pid " FMT_pid
" (%s)",
1496 shutdown_signal
, shutdown_pid
,
1497 shutdown_cmd
? shutdown_cmd
: "<unknown process>");
1498 g_free(shutdown_cmd
);
1500 shutdown_signal
= 0;
1504 static ShutdownCause
qemu_reset_requested(void)
1506 ShutdownCause r
= reset_requested
;
1508 if (r
&& replay_checkpoint(CHECKPOINT_RESET_REQUESTED
)) {
1509 reset_requested
= SHUTDOWN_CAUSE_NONE
;
1512 return SHUTDOWN_CAUSE_NONE
;
1515 static int qemu_suspend_requested(void)
1517 int r
= suspend_requested
;
1518 if (r
&& replay_checkpoint(CHECKPOINT_SUSPEND_REQUESTED
)) {
1519 suspend_requested
= 0;
1525 static WakeupReason
qemu_wakeup_requested(void)
1527 return wakeup_reason
;
1530 static int qemu_powerdown_requested(void)
1532 int r
= powerdown_requested
;
1533 powerdown_requested
= 0;
1537 static int qemu_debug_requested(void)
1539 int r
= debug_requested
;
1540 debug_requested
= 0;
1544 void qemu_exit_preconfig_request(void)
1546 preconfig_exit_requested
= true;
1550 * Reset the VM. Issue an event unless @reason is SHUTDOWN_CAUSE_NONE.
1552 void qemu_system_reset(ShutdownCause reason
)
1556 mc
= current_machine
? MACHINE_GET_CLASS(current_machine
) : NULL
;
1558 cpu_synchronize_all_states();
1560 if (mc
&& mc
->reset
) {
1561 mc
->reset(current_machine
);
1563 qemu_devices_reset();
1565 if (reason
&& reason
!= SHUTDOWN_CAUSE_SUBSYSTEM_RESET
) {
1566 qapi_event_send_reset(shutdown_caused_by_guest(reason
), reason
);
1568 cpu_synchronize_all_post_reset();
1572 * Wake the VM after suspend.
1574 static void qemu_system_wakeup(void)
1578 mc
= current_machine
? MACHINE_GET_CLASS(current_machine
) : NULL
;
1580 if (mc
&& mc
->wakeup
) {
1581 mc
->wakeup(current_machine
);
1585 void qemu_system_guest_panicked(GuestPanicInformation
*info
)
1587 qemu_log_mask(LOG_GUEST_ERROR
, "Guest crashed");
1590 current_cpu
->crash_occurred
= true;
1592 qapi_event_send_guest_panicked(GUEST_PANIC_ACTION_PAUSE
,
1594 vm_stop(RUN_STATE_GUEST_PANICKED
);
1596 qapi_event_send_guest_panicked(GUEST_PANIC_ACTION_POWEROFF
,
1598 qemu_system_shutdown_request(SHUTDOWN_CAUSE_GUEST_PANIC
);
1602 if (info
->type
== GUEST_PANIC_INFORMATION_TYPE_HYPER_V
) {
1603 qemu_log_mask(LOG_GUEST_ERROR
, "\nHV crash parameters: (%#"PRIx64
1604 " %#"PRIx64
" %#"PRIx64
" %#"PRIx64
" %#"PRIx64
")\n",
1605 info
->u
.hyper_v
.arg1
,
1606 info
->u
.hyper_v
.arg2
,
1607 info
->u
.hyper_v
.arg3
,
1608 info
->u
.hyper_v
.arg4
,
1609 info
->u
.hyper_v
.arg5
);
1610 } else if (info
->type
== GUEST_PANIC_INFORMATION_TYPE_S390
) {
1611 qemu_log_mask(LOG_GUEST_ERROR
, " on cpu %d: %s\n"
1612 "PSW: 0x%016" PRIx64
" 0x%016" PRIx64
"\n",
1614 S390CrashReason_str(info
->u
.s390
.reason
),
1615 info
->u
.s390
.psw_mask
,
1616 info
->u
.s390
.psw_addr
);
1618 qapi_free_GuestPanicInformation(info
);
1622 void qemu_system_reset_request(ShutdownCause reason
)
1624 if (no_reboot
&& reason
!= SHUTDOWN_CAUSE_SUBSYSTEM_RESET
) {
1625 shutdown_requested
= reason
;
1627 reset_requested
= reason
;
1630 qemu_notify_event();
1633 static void qemu_system_suspend(void)
1636 notifier_list_notify(&suspend_notifiers
, NULL
);
1637 runstate_set(RUN_STATE_SUSPENDED
);
1638 qapi_event_send_suspend();
1641 void qemu_system_suspend_request(void)
1643 if (runstate_check(RUN_STATE_SUSPENDED
)) {
1646 suspend_requested
= 1;
1648 qemu_notify_event();
1651 void qemu_register_suspend_notifier(Notifier
*notifier
)
1653 notifier_list_add(&suspend_notifiers
, notifier
);
1656 void qemu_system_wakeup_request(WakeupReason reason
, Error
**errp
)
1658 trace_system_wakeup_request(reason
);
1660 if (!runstate_check(RUN_STATE_SUSPENDED
)) {
1662 "Unable to wake up: guest is not in suspended state");
1665 if (!(wakeup_reason_mask
& (1 << reason
))) {
1668 runstate_set(RUN_STATE_RUNNING
);
1669 wakeup_reason
= reason
;
1670 qemu_notify_event();
1673 void qemu_system_wakeup_enable(WakeupReason reason
, bool enabled
)
1676 wakeup_reason_mask
|= (1 << reason
);
1678 wakeup_reason_mask
&= ~(1 << reason
);
1682 void qemu_register_wakeup_notifier(Notifier
*notifier
)
1684 notifier_list_add(&wakeup_notifiers
, notifier
);
1687 void qemu_register_wakeup_support(void)
1689 wakeup_suspend_enabled
= true;
1692 bool qemu_wakeup_suspend_enabled(void)
1694 return wakeup_suspend_enabled
;
1697 void qemu_system_killed(int signal
, pid_t pid
)
1699 shutdown_signal
= signal
;
1703 /* Cannot call qemu_system_shutdown_request directly because
1704 * we are in a signal handler.
1706 shutdown_requested
= SHUTDOWN_CAUSE_HOST_SIGNAL
;
1707 qemu_notify_event();
1710 void qemu_system_shutdown_request(ShutdownCause reason
)
1712 trace_qemu_system_shutdown_request(reason
);
1713 replay_shutdown_request(reason
);
1714 shutdown_requested
= reason
;
1715 qemu_notify_event();
1718 static void qemu_system_powerdown(void)
1720 qapi_event_send_powerdown();
1721 notifier_list_notify(&powerdown_notifiers
, NULL
);
1724 static void qemu_system_shutdown(ShutdownCause cause
)
1726 qapi_event_send_shutdown(shutdown_caused_by_guest(cause
), cause
);
1727 notifier_list_notify(&shutdown_notifiers
, &cause
);
1730 void qemu_system_powerdown_request(void)
1732 trace_qemu_system_powerdown_request();
1733 powerdown_requested
= 1;
1734 qemu_notify_event();
1737 void qemu_register_powerdown_notifier(Notifier
*notifier
)
1739 notifier_list_add(&powerdown_notifiers
, notifier
);
1742 void qemu_register_shutdown_notifier(Notifier
*notifier
)
1744 notifier_list_add(&shutdown_notifiers
, notifier
);
1747 void qemu_system_debug_request(void)
1749 debug_requested
= 1;
1750 qemu_notify_event();
1753 static bool main_loop_should_exit(void)
1756 ShutdownCause request
;
1758 if (runstate_check(RUN_STATE_FINISH_MIGRATE
)) {
1761 if (preconfig_exit_requested
) {
1762 if (runstate_check(RUN_STATE_PRECONFIG
)) {
1763 runstate_set(RUN_STATE_PRELAUNCH
);
1765 preconfig_exit_requested
= false;
1768 if (qemu_debug_requested()) {
1769 vm_stop(RUN_STATE_DEBUG
);
1771 if (qemu_suspend_requested()) {
1772 qemu_system_suspend();
1774 request
= qemu_shutdown_requested();
1777 qemu_system_shutdown(request
);
1779 vm_stop(RUN_STATE_SHUTDOWN
);
1784 request
= qemu_reset_requested();
1787 qemu_system_reset(request
);
1789 if (!runstate_check(RUN_STATE_RUNNING
) &&
1790 !runstate_check(RUN_STATE_INMIGRATE
)) {
1791 runstate_set(RUN_STATE_PRELAUNCH
);
1794 if (qemu_wakeup_requested()) {
1796 qemu_system_wakeup();
1797 notifier_list_notify(&wakeup_notifiers
, &wakeup_reason
);
1798 wakeup_reason
= QEMU_WAKEUP_REASON_NONE
;
1800 qapi_event_send_wakeup();
1802 if (qemu_powerdown_requested()) {
1803 qemu_system_powerdown();
1805 if (qemu_vmstop_requested(&r
)) {
1811 static void main_loop(void)
1813 #ifdef CONFIG_PROFILER
1816 while (!main_loop_should_exit()) {
1817 #ifdef CONFIG_PROFILER
1818 ti
= profile_getclock();
1820 main_loop_wait(false);
1821 #ifdef CONFIG_PROFILER
1822 dev_time
+= profile_getclock() - ti
;
1827 static void version(void)
1829 printf("QEMU emulator version " QEMU_FULL_VERSION
"\n"
1830 QEMU_COPYRIGHT
"\n");
1833 static void QEMU_NORETURN
help(int exitcode
)
1836 printf("usage: %s [options] [disk_image]\n\n"
1837 "'disk_image' is a raw hard disk image for IDE hard disk 0\n\n",
1838 error_get_progname());
1840 #define QEMU_OPTIONS_GENERATE_HELP
1841 #include "qemu-options-wrapper.h"
1843 printf("\nDuring emulation, the following keys are useful:\n"
1844 "ctrl-alt-f toggle full screen\n"
1845 "ctrl-alt-n switch to virtual console 'n'\n"
1846 "ctrl-alt toggle mouse and keyboard grab\n"
1848 "When using -nographic, press 'ctrl-a h' to get some help.\n"
1850 QEMU_HELP_BOTTOM
"\n");
1855 #define HAS_ARG 0x0001
1857 typedef struct QEMUOption
{
1864 static const QEMUOption qemu_options
[] = {
1865 { "h", 0, QEMU_OPTION_h
, QEMU_ARCH_ALL
},
1866 #define QEMU_OPTIONS_GENERATE_OPTIONS
1867 #include "qemu-options-wrapper.h"
1871 typedef struct VGAInterfaceInfo
{
1872 const char *opt_name
; /* option name */
1873 const char *name
; /* human-readable name */
1874 /* Class names indicating that support is available.
1875 * If no class is specified, the interface is always available */
1876 const char *class_names
[2];
1879 static const VGAInterfaceInfo vga_interfaces
[VGA_TYPE_MAX
] = {
1882 .name
= "no graphic card",
1886 .name
= "standard VGA",
1887 .class_names
= { "VGA", "isa-vga" },
1890 .opt_name
= "cirrus",
1891 .name
= "Cirrus VGA",
1892 .class_names
= { "cirrus-vga", "isa-cirrus-vga" },
1895 .opt_name
= "vmware",
1896 .name
= "VMWare SVGA",
1897 .class_names
= { "vmware-svga" },
1900 .opt_name
= "virtio",
1901 .name
= "Virtio VGA",
1902 .class_names
= { "virtio-vga" },
1907 .class_names
= { "qxl-vga" },
1911 .name
= "TCX framebuffer",
1912 .class_names
= { "SUNW,tcx" },
1916 .name
= "CG3 framebuffer",
1917 .class_names
= { "cgthree" },
1920 .opt_name
= "xenfb",
1921 .name
= "Xen paravirtualized framebuffer",
1925 static bool vga_interface_available(VGAInterfaceType t
)
1927 const VGAInterfaceInfo
*ti
= &vga_interfaces
[t
];
1929 assert(t
< VGA_TYPE_MAX
);
1930 return !ti
->class_names
[0] ||
1931 object_class_by_name(ti
->class_names
[0]) ||
1932 object_class_by_name(ti
->class_names
[1]);
1936 get_default_vga_model(const MachineClass
*machine_class
)
1938 if (machine_class
->default_display
) {
1939 return machine_class
->default_display
;
1940 } else if (vga_interface_available(VGA_CIRRUS
)) {
1942 } else if (vga_interface_available(VGA_STD
)) {
1949 static void select_vgahw(const MachineClass
*machine_class
, const char *p
)
1954 if (g_str_equal(p
, "help")) {
1955 const char *def
= get_default_vga_model(machine_class
);
1957 for (t
= 0; t
< VGA_TYPE_MAX
; t
++) {
1958 const VGAInterfaceInfo
*ti
= &vga_interfaces
[t
];
1960 if (vga_interface_available(t
) && ti
->opt_name
) {
1961 printf("%-20s %s%s\n", ti
->opt_name
, ti
->name
?: "",
1962 g_str_equal(ti
->opt_name
, def
) ? " (default)" : "");
1968 assert(vga_interface_type
== VGA_NONE
);
1969 for (t
= 0; t
< VGA_TYPE_MAX
; t
++) {
1970 const VGAInterfaceInfo
*ti
= &vga_interfaces
[t
];
1971 if (ti
->opt_name
&& strstart(p
, ti
->opt_name
, &opts
)) {
1972 if (!vga_interface_available(t
)) {
1973 error_report("%s not available", ti
->name
);
1976 vga_interface_type
= t
;
1980 if (t
== VGA_TYPE_MAX
) {
1982 error_report("unknown vga type: %s", p
);
1986 const char *nextopt
;
1988 if (strstart(opts
, ",retrace=", &nextopt
)) {
1990 if (strstart(opts
, "dumb", &nextopt
))
1991 vga_retrace_method
= VGA_RETRACE_DUMB
;
1992 else if (strstart(opts
, "precise", &nextopt
))
1993 vga_retrace_method
= VGA_RETRACE_PRECISE
;
1994 else goto invalid_vga
;
1995 } else goto invalid_vga
;
2000 static void parse_display_qapi(const char *optarg
)
2002 DisplayOptions
*opts
;
2005 v
= qobject_input_visitor_new_str(optarg
, "type", &error_fatal
);
2007 visit_type_DisplayOptions(v
, NULL
, &opts
, &error_fatal
);
2008 QAPI_CLONE_MEMBERS(DisplayOptions
, &dpy
, opts
);
2010 qapi_free_DisplayOptions(opts
);
2014 DisplayOptions
*qmp_query_display_options(Error
**errp
)
2016 return QAPI_CLONE(DisplayOptions
, &dpy
);
2019 static void parse_display(const char *p
)
2023 if (strstart(p
, "sdl", &opts
)) {
2025 * sdl DisplayType needs hand-crafted parser instead of
2026 * parse_display_qapi() due to some options not in
2027 * DisplayOptions, specifically:
2029 * Already deprecated.
2030 * - ctrl_grab + alt_grab
2031 * Not clear yet what happens to them long-term. Should
2032 * replaced by something better or deprecated and dropped.
2034 dpy
.type
= DISPLAY_TYPE_SDL
;
2036 const char *nextopt
;
2038 if (strstart(opts
, ",alt_grab=", &nextopt
)) {
2040 if (strstart(opts
, "on", &nextopt
)) {
2042 } else if (strstart(opts
, "off", &nextopt
)) {
2045 goto invalid_sdl_args
;
2047 } else if (strstart(opts
, ",ctrl_grab=", &nextopt
)) {
2049 if (strstart(opts
, "on", &nextopt
)) {
2051 } else if (strstart(opts
, "off", &nextopt
)) {
2054 goto invalid_sdl_args
;
2056 } else if (strstart(opts
, ",window_close=", &nextopt
)) {
2058 dpy
.has_window_close
= true;
2059 if (strstart(opts
, "on", &nextopt
)) {
2060 dpy
.window_close
= true;
2061 } else if (strstart(opts
, "off", &nextopt
)) {
2062 dpy
.window_close
= false;
2064 goto invalid_sdl_args
;
2066 } else if (strstart(opts
, ",gl=", &nextopt
)) {
2069 if (strstart(opts
, "on", &nextopt
)) {
2070 dpy
.gl
= DISPLAYGL_MODE_ON
;
2071 } else if (strstart(opts
, "core", &nextopt
)) {
2072 dpy
.gl
= DISPLAYGL_MODE_CORE
;
2073 } else if (strstart(opts
, "es", &nextopt
)) {
2074 dpy
.gl
= DISPLAYGL_MODE_ES
;
2075 } else if (strstart(opts
, "off", &nextopt
)) {
2076 dpy
.gl
= DISPLAYGL_MODE_OFF
;
2078 goto invalid_sdl_args
;
2082 error_report("invalid SDL option string");
2087 } else if (strstart(p
, "vnc", &opts
)) {
2089 * vnc isn't a (local) DisplayType but a protocol for remote
2093 vnc_parse(opts
+ 1, &error_fatal
);
2095 error_report("VNC requires a display argument vnc=<display>");
2099 parse_display_qapi(p
);
2103 char *qemu_find_file(int type
, const char *name
)
2109 /* Try the name as a straight path first */
2110 if (access(name
, R_OK
) == 0) {
2111 trace_load_file(name
, name
);
2112 return g_strdup(name
);
2116 case QEMU_FILE_TYPE_BIOS
:
2119 case QEMU_FILE_TYPE_KEYMAP
:
2120 subdir
= "keymaps/";
2126 for (i
= 0; i
< data_dir_idx
; i
++) {
2127 buf
= g_strdup_printf("%s/%s%s", data_dir
[i
], subdir
, name
);
2128 if (access(buf
, R_OK
) == 0) {
2129 trace_load_file(name
, buf
);
2137 static void qemu_add_data_dir(const char *path
)
2144 if (data_dir_idx
== ARRAY_SIZE(data_dir
)) {
2147 for (i
= 0; i
< data_dir_idx
; i
++) {
2148 if (strcmp(data_dir
[i
], path
) == 0) {
2149 return; /* duplicate */
2152 data_dir
[data_dir_idx
++] = g_strdup(path
);
2155 static inline bool nonempty_str(const char *str
)
2160 static int parse_fw_cfg(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2164 const char *name
, *file
, *str
;
2165 FWCfgState
*fw_cfg
= (FWCfgState
*) opaque
;
2167 if (fw_cfg
== NULL
) {
2168 error_setg(errp
, "fw_cfg device not available");
2171 name
= qemu_opt_get(opts
, "name");
2172 file
= qemu_opt_get(opts
, "file");
2173 str
= qemu_opt_get(opts
, "string");
2175 /* we need name and either a file or the content string */
2176 if (!(nonempty_str(name
) && (nonempty_str(file
) || nonempty_str(str
)))) {
2177 error_setg(errp
, "invalid argument(s)");
2180 if (nonempty_str(file
) && nonempty_str(str
)) {
2181 error_setg(errp
, "file and string are mutually exclusive");
2184 if (strlen(name
) > FW_CFG_MAX_FILE_PATH
- 1) {
2185 error_setg(errp
, "name too long (max. %d char)",
2186 FW_CFG_MAX_FILE_PATH
- 1);
2189 if (strncmp(name
, "opt/", 4) != 0) {
2190 warn_report("externally provided fw_cfg item names "
2191 "should be prefixed with \"opt/\"");
2193 if (nonempty_str(str
)) {
2194 size
= strlen(str
); /* NUL terminator NOT included in fw_cfg blob */
2195 buf
= g_memdup(str
, size
);
2198 if (!g_file_get_contents(file
, &buf
, &size
, &err
)) {
2199 error_setg(errp
, "can't load %s: %s", file
, err
->message
);
2204 /* For legacy, keep user files in a specific global order. */
2205 fw_cfg_set_order_override(fw_cfg
, FW_CFG_ORDER_OVERRIDE_USER
);
2206 fw_cfg_add_file(fw_cfg
, name
, buf
, size
);
2207 fw_cfg_reset_order_override(fw_cfg
);
2211 static int device_help_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2213 return qdev_device_help(opts
);
2216 static int device_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2220 dev
= qdev_device_add(opts
, errp
);
2221 if (!dev
&& *errp
) {
2222 error_report_err(*errp
);
2225 object_unref(OBJECT(dev
));
2230 static int chardev_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2232 Error
*local_err
= NULL
;
2234 if (!qemu_chr_new_from_opts(opts
, NULL
, &local_err
)) {
2236 error_propagate(errp
, local_err
);
2244 #ifdef CONFIG_VIRTFS
2245 static int fsdev_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2247 return qemu_fsdev_add(opts
, errp
);
2251 static int mon_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2255 bool pretty
= false;
2256 const char *chardev
;
2259 mode
= qemu_opt_get(opts
, "mode");
2263 if (strcmp(mode
, "readline") == 0) {
2265 } else if (strcmp(mode
, "control") == 0) {
2268 error_setg(errp
, "unknown monitor mode \"%s\"", mode
);
2272 if (!qmp
&& qemu_opt_get(opts
, "pretty")) {
2273 warn_report("'pretty' is deprecated for HMP monitors, it has no effect "
2274 "and will be removed in future versions");
2276 if (qemu_opt_get_bool(opts
, "pretty", 0)) {
2280 chardev
= qemu_opt_get(opts
, "chardev");
2282 error_report("chardev is required");
2285 chr
= qemu_chr_find(chardev
);
2287 error_setg(errp
, "chardev \"%s\" not found", chardev
);
2292 monitor_init_qmp(chr
, pretty
);
2294 monitor_init_hmp(chr
, true);
2299 static void monitor_parse(const char *optarg
, const char *mode
, bool pretty
)
2301 static int monitor_device_index
= 0;
2306 if (strstart(optarg
, "chardev:", &p
)) {
2307 snprintf(label
, sizeof(label
), "%s", p
);
2309 snprintf(label
, sizeof(label
), "compat_monitor%d",
2310 monitor_device_index
);
2311 opts
= qemu_chr_parse_compat(label
, optarg
, true);
2313 error_report("parse error: %s", optarg
);
2318 opts
= qemu_opts_create(qemu_find_opts("mon"), label
, 1, &error_fatal
);
2319 qemu_opt_set(opts
, "mode", mode
, &error_abort
);
2320 qemu_opt_set(opts
, "chardev", label
, &error_abort
);
2321 if (!strcmp(mode
, "control")) {
2322 qemu_opt_set_bool(opts
, "pretty", pretty
, &error_abort
);
2324 assert(pretty
== false);
2326 monitor_device_index
++;
2329 struct device_config
{
2331 DEV_USB
, /* -usbdevice */
2333 DEV_SERIAL
, /* -serial */
2334 DEV_PARALLEL
, /* -parallel */
2335 DEV_DEBUGCON
, /* -debugcon */
2336 DEV_GDB
, /* -gdb, -s */
2337 DEV_SCLP
, /* s390 sclp */
2339 const char *cmdline
;
2341 QTAILQ_ENTRY(device_config
) next
;
2344 static QTAILQ_HEAD(, device_config
) device_configs
=
2345 QTAILQ_HEAD_INITIALIZER(device_configs
);
2347 static void add_device_config(int type
, const char *cmdline
)
2349 struct device_config
*conf
;
2351 conf
= g_malloc0(sizeof(*conf
));
2353 conf
->cmdline
= cmdline
;
2354 loc_save(&conf
->loc
);
2355 QTAILQ_INSERT_TAIL(&device_configs
, conf
, next
);
2358 static int foreach_device_config(int type
, int (*func
)(const char *cmdline
))
2360 struct device_config
*conf
;
2363 QTAILQ_FOREACH(conf
, &device_configs
, next
) {
2364 if (conf
->type
!= type
)
2366 loc_push_restore(&conf
->loc
);
2367 rc
= func(conf
->cmdline
);
2368 loc_pop(&conf
->loc
);
2376 static int serial_parse(const char *devname
)
2378 int index
= num_serial_hds
;
2381 if (strcmp(devname
, "none") == 0)
2383 snprintf(label
, sizeof(label
), "serial%d", index
);
2384 serial_hds
= g_renew(Chardev
*, serial_hds
, index
+ 1);
2386 serial_hds
[index
] = qemu_chr_new_mux_mon(label
, devname
, NULL
);
2387 if (!serial_hds
[index
]) {
2388 error_report("could not connect serial device"
2389 " to character backend '%s'", devname
);
2396 Chardev
*serial_hd(int i
)
2399 if (i
< num_serial_hds
) {
2400 return serial_hds
[i
];
2405 int serial_max_hds(void)
2407 return num_serial_hds
;
2410 static int parallel_parse(const char *devname
)
2412 static int index
= 0;
2415 if (strcmp(devname
, "none") == 0)
2417 if (index
== MAX_PARALLEL_PORTS
) {
2418 error_report("too many parallel ports");
2421 snprintf(label
, sizeof(label
), "parallel%d", index
);
2422 parallel_hds
[index
] = qemu_chr_new_mux_mon(label
, devname
, NULL
);
2423 if (!parallel_hds
[index
]) {
2424 error_report("could not connect parallel device"
2425 " to character backend '%s'", devname
);
2432 static int debugcon_parse(const char *devname
)
2436 if (!qemu_chr_new_mux_mon("debugcon", devname
, NULL
)) {
2437 error_report("invalid character backend '%s'", devname
);
2440 opts
= qemu_opts_create(qemu_find_opts("device"), "debugcon", 1, NULL
);
2442 error_report("already have a debugcon device");
2445 qemu_opt_set(opts
, "driver", "isa-debugcon", &error_abort
);
2446 qemu_opt_set(opts
, "chardev", "debugcon", &error_abort
);
2450 static gint
machine_class_cmp(gconstpointer a
, gconstpointer b
)
2452 const MachineClass
*mc1
= a
, *mc2
= b
;
2455 if (mc1
->family
== NULL
) {
2456 if (mc2
->family
== NULL
) {
2457 /* Compare standalone machine types against each other; they sort
2458 * in increasing order.
2460 return strcmp(object_class_get_name(OBJECT_CLASS(mc1
)),
2461 object_class_get_name(OBJECT_CLASS(mc2
)));
2464 /* Standalone machine types sort after families. */
2468 if (mc2
->family
== NULL
) {
2469 /* Families sort before standalone machine types. */
2473 /* Families sort between each other alphabetically increasingly. */
2474 res
= strcmp(mc1
->family
, mc2
->family
);
2479 /* Within the same family, machine types sort in decreasing order. */
2480 return strcmp(object_class_get_name(OBJECT_CLASS(mc2
)),
2481 object_class_get_name(OBJECT_CLASS(mc1
)));
2484 static MachineClass
*machine_parse(const char *name
, GSList
*machines
)
2489 if (is_help_option(name
)) {
2490 printf("Supported machines are:\n");
2491 machines
= g_slist_sort(machines
, machine_class_cmp
);
2492 for (el
= machines
; el
; el
= el
->next
) {
2493 MachineClass
*mc
= el
->data
;
2495 printf("%-20s %s (alias of %s)\n", mc
->alias
, mc
->desc
, mc
->name
);
2497 printf("%-20s %s%s%s\n", mc
->name
, mc
->desc
,
2498 mc
->is_default
? " (default)" : "",
2499 mc
->deprecation_reason
? " (deprecated)" : "");
2504 mc
= find_machine(name
, machines
);
2506 error_report("unsupported machine type");
2507 error_printf("Use -machine help to list supported machines\n");
2513 void qemu_add_exit_notifier(Notifier
*notify
)
2515 notifier_list_add(&exit_notifiers
, notify
);
2518 void qemu_remove_exit_notifier(Notifier
*notify
)
2520 notifier_remove(notify
);
2523 static void qemu_run_exit_notifiers(void)
2525 notifier_list_notify(&exit_notifiers
, NULL
);
2528 static const char *pid_file
;
2529 static Notifier qemu_unlink_pidfile_notifier
;
2531 static void qemu_unlink_pidfile(Notifier
*n
, void *data
)
2538 bool machine_init_done
;
2540 void qemu_add_machine_init_done_notifier(Notifier
*notify
)
2542 notifier_list_add(&machine_init_done_notifiers
, notify
);
2543 if (machine_init_done
) {
2544 notify
->notify(notify
, NULL
);
2548 void qemu_remove_machine_init_done_notifier(Notifier
*notify
)
2550 notifier_remove(notify
);
2553 static void qemu_run_machine_init_done_notifiers(void)
2555 machine_init_done
= true;
2556 notifier_list_notify(&machine_init_done_notifiers
, NULL
);
2559 static const QEMUOption
*lookup_opt(int argc
, char **argv
,
2560 const char **poptarg
, int *poptind
)
2562 const QEMUOption
*popt
;
2563 int optind
= *poptind
;
2564 char *r
= argv
[optind
];
2567 loc_set_cmdline(argv
, optind
, 1);
2569 /* Treat --foo the same as -foo. */
2572 popt
= qemu_options
;
2575 error_report("invalid option");
2578 if (!strcmp(popt
->name
, r
+ 1))
2582 if (popt
->flags
& HAS_ARG
) {
2583 if (optind
>= argc
) {
2584 error_report("requires an argument");
2587 optarg
= argv
[optind
++];
2588 loc_set_cmdline(argv
, optind
- 2, 2);
2599 static MachineClass
*select_machine(void)
2601 GSList
*machines
= object_class_get_list(TYPE_MACHINE
, false);
2602 MachineClass
*machine_class
= find_default_machine(machines
);
2607 loc_push_none(&loc
);
2609 opts
= qemu_get_machine_opts();
2610 qemu_opts_loc_restore(opts
);
2612 optarg
= qemu_opt_get(opts
, "type");
2614 machine_class
= machine_parse(optarg
, machines
);
2617 if (!machine_class
) {
2618 error_report("No machine specified, and there is no default");
2619 error_printf("Use -machine help to list supported machines\n");
2624 g_slist_free(machines
);
2625 return machine_class
;
2628 static int machine_set_property(void *opaque
,
2629 const char *name
, const char *value
,
2632 Object
*obj
= OBJECT(opaque
);
2633 Error
*local_err
= NULL
;
2636 if (strcmp(name
, "type") == 0) {
2640 qom_name
= g_strdup(name
);
2641 for (p
= qom_name
; *p
; p
++) {
2647 object_property_parse(obj
, value
, qom_name
, &local_err
);
2651 error_propagate(errp
, local_err
);
2660 * Initial object creation happens before all other
2661 * QEMU data types are created. The majority of objects
2662 * can be created at this point. The rng-egd object
2663 * cannot be created here, as it depends on the chardev
2666 static bool object_create_initial(const char *type
, QemuOpts
*opts
)
2668 if (user_creatable_print_help(type
, opts
)) {
2673 * Objects should not be made "delayed" without a reason. If you
2674 * add one, state the reason in a comment!
2677 /* Reason: rng-egd property "chardev" */
2678 if (g_str_equal(type
, "rng-egd")) {
2682 #if defined(CONFIG_VHOST_USER) && defined(CONFIG_LINUX)
2683 /* Reason: cryptodev-vhost-user property "chardev" */
2684 if (g_str_equal(type
, "cryptodev-vhost-user")) {
2690 * Reason: filter-* property "netdev" etc.
2692 if (g_str_equal(type
, "filter-buffer") ||
2693 g_str_equal(type
, "filter-dump") ||
2694 g_str_equal(type
, "filter-mirror") ||
2695 g_str_equal(type
, "filter-redirector") ||
2696 g_str_equal(type
, "colo-compare") ||
2697 g_str_equal(type
, "filter-rewriter") ||
2698 g_str_equal(type
, "filter-replay")) {
2702 /* Memory allocation by backends needs to be done
2703 * after configure_accelerator() (due to the tcg_enabled()
2704 * checks at memory_region_init_*()).
2706 * Also, allocation of large amounts of memory may delay
2707 * chardev initialization for too long, and trigger timeouts
2708 * on software that waits for a monitor socket to be created
2711 if (g_str_has_prefix(type
, "memory-backend-")) {
2720 * The remainder of object creation happens after the
2721 * creation of chardev, fsdev, net clients and device data types.
2723 static bool object_create_delayed(const char *type
, QemuOpts
*opts
)
2725 return !object_create_initial(type
, opts
);
2729 static void set_memory_options(uint64_t *ram_slots
, ram_addr_t
*maxram_size
,
2733 const char *mem_str
;
2734 const ram_addr_t default_ram_size
= mc
->default_ram_size
;
2735 QemuOpts
*opts
= qemu_find_opts_singleton("memory");
2738 loc_push_none(&loc
);
2739 qemu_opts_loc_restore(opts
);
2742 mem_str
= qemu_opt_get(opts
, "size");
2745 error_report("missing 'size' option value");
2749 sz
= qemu_opt_get_size(opts
, "size", ram_size
);
2751 /* Fix up legacy suffix-less format */
2752 if (g_ascii_isdigit(mem_str
[strlen(mem_str
) - 1])) {
2753 uint64_t overflow_check
= sz
;
2756 if (sz
/ MiB
!= overflow_check
) {
2757 error_report("too large 'size' option value");
2763 /* backward compatibility behaviour for case "-m 0" */
2765 sz
= default_ram_size
;
2768 sz
= QEMU_ALIGN_UP(sz
, 8192);
2770 if (ram_size
!= sz
) {
2771 error_report("ram size too large");
2775 /* store value for the future use */
2776 qemu_opt_set_number(opts
, "size", ram_size
, &error_abort
);
2777 *maxram_size
= ram_size
;
2779 if (qemu_opt_get(opts
, "maxmem")) {
2782 sz
= qemu_opt_get_size(opts
, "maxmem", 0);
2783 slots
= qemu_opt_get_number(opts
, "slots", 0);
2784 if (sz
< ram_size
) {
2785 error_report("invalid value of -m option maxmem: "
2786 "maximum memory size (0x%" PRIx64
") must be at least "
2787 "the initial memory size (0x" RAM_ADDR_FMT
")",
2790 } else if (slots
&& sz
== ram_size
) {
2791 error_report("invalid value of -m option maxmem: "
2792 "memory slots were specified but maximum memory size "
2793 "(0x%" PRIx64
") is equal to the initial memory size "
2794 "(0x" RAM_ADDR_FMT
")", sz
, ram_size
);
2800 } else if (qemu_opt_get(opts
, "slots")) {
2801 error_report("invalid -m option value: missing 'maxmem' option");
2808 static int global_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2812 g
= g_malloc0(sizeof(*g
));
2813 g
->driver
= qemu_opt_get(opts
, "driver");
2814 g
->property
= qemu_opt_get(opts
, "property");
2815 g
->value
= qemu_opt_get(opts
, "value");
2816 qdev_prop_register_global(g
);
2820 static int qemu_read_default_config_file(void)
2824 ret
= qemu_read_config_file(CONFIG_QEMU_CONFDIR
"/qemu.conf");
2825 if (ret
< 0 && ret
!= -ENOENT
) {
2832 static void user_register_global_props(void)
2834 qemu_opts_foreach(qemu_find_opts("global"),
2835 global_init_func
, NULL
, NULL
);
2838 int main(int argc
, char **argv
)
2841 int snapshot
, linux_boot
;
2842 const char *initrd_filename
;
2843 const char *kernel_filename
, *kernel_cmdline
;
2844 const char *boot_order
= NULL
;
2845 const char *boot_once
= NULL
;
2847 QemuOpts
*opts
, *machine_opts
;
2848 QemuOpts
*icount_opts
= NULL
, *accel_opts
= NULL
;
2849 QemuOptsList
*olist
;
2852 const char *loadvm
= NULL
;
2853 MachineClass
*machine_class
;
2854 const char *cpu_option
;
2855 const char *vga_model
= NULL
;
2856 const char *qtest_chrdev
= NULL
;
2857 const char *qtest_log
= NULL
;
2858 const char *incoming
= NULL
;
2859 bool userconfig
= true;
2860 bool nographic
= false;
2861 int display_remote
= 0;
2862 const char *log_mask
= NULL
;
2863 const char *log_file
= NULL
;
2864 char *trace_file
= NULL
;
2865 ram_addr_t maxram_size
;
2866 uint64_t ram_slots
= 0;
2867 FILE *vmstate_dump_file
= NULL
;
2868 Error
*main_loop_err
= NULL
;
2870 bool list_data_dirs
= false;
2872 BlockdevOptionsQueue bdo_queue
= QSIMPLEQ_HEAD_INITIALIZER(bdo_queue
);
2873 QemuPluginList plugin_list
= QTAILQ_HEAD_INITIALIZER(plugin_list
);
2875 os_set_line_buffering();
2877 error_init(argv
[0]);
2878 module_call_init(MODULE_INIT_TRACE
);
2880 qemu_init_cpu_list();
2881 qemu_init_cpu_loop();
2883 qemu_mutex_lock_iothread();
2885 atexit(qemu_run_exit_notifiers
);
2886 qemu_init_exec_dir(argv
[0]);
2888 module_call_init(MODULE_INIT_QOM
);
2890 qemu_add_opts(&qemu_drive_opts
);
2891 qemu_add_drive_opts(&qemu_legacy_drive_opts
);
2892 qemu_add_drive_opts(&qemu_common_drive_opts
);
2893 qemu_add_drive_opts(&qemu_drive_opts
);
2894 qemu_add_drive_opts(&bdrv_runtime_opts
);
2895 qemu_add_opts(&qemu_chardev_opts
);
2896 qemu_add_opts(&qemu_device_opts
);
2897 qemu_add_opts(&qemu_netdev_opts
);
2898 qemu_add_opts(&qemu_nic_opts
);
2899 qemu_add_opts(&qemu_net_opts
);
2900 qemu_add_opts(&qemu_rtc_opts
);
2901 qemu_add_opts(&qemu_global_opts
);
2902 qemu_add_opts(&qemu_mon_opts
);
2903 qemu_add_opts(&qemu_trace_opts
);
2904 qemu_plugin_add_opts();
2905 qemu_add_opts(&qemu_option_rom_opts
);
2906 qemu_add_opts(&qemu_machine_opts
);
2907 qemu_add_opts(&qemu_accel_opts
);
2908 qemu_add_opts(&qemu_mem_opts
);
2909 qemu_add_opts(&qemu_smp_opts
);
2910 qemu_add_opts(&qemu_boot_opts
);
2911 qemu_add_opts(&qemu_add_fd_opts
);
2912 qemu_add_opts(&qemu_object_opts
);
2913 qemu_add_opts(&qemu_tpmdev_opts
);
2914 qemu_add_opts(&qemu_realtime_opts
);
2915 qemu_add_opts(&qemu_overcommit_opts
);
2916 qemu_add_opts(&qemu_msg_opts
);
2917 qemu_add_opts(&qemu_name_opts
);
2918 qemu_add_opts(&qemu_numa_opts
);
2919 qemu_add_opts(&qemu_icount_opts
);
2920 qemu_add_opts(&qemu_semihosting_config_opts
);
2921 qemu_add_opts(&qemu_fw_cfg_opts
);
2922 module_call_init(MODULE_INIT_OPTS
);
2925 precopy_infrastructure_init();
2926 postcopy_infrastructure_init();
2927 monitor_init_globals();
2929 if (qcrypto_init(&err
) < 0) {
2930 error_reportf_err(err
, "cannot initialize crypto: ");
2934 QTAILQ_INIT(&vm_change_state_head
);
2935 os_setup_early_signal_handling();
2942 bdrv_init_with_whitelist();
2946 /* first pass of option parsing */
2948 while (optind
< argc
) {
2949 if (argv
[optind
][0] != '-') {
2953 const QEMUOption
*popt
;
2955 popt
= lookup_opt(argc
, argv
, &optarg
, &optind
);
2956 switch (popt
->index
) {
2957 case QEMU_OPTION_nouserconfig
:
2965 if (qemu_read_default_config_file() < 0) {
2970 /* second pass of option parsing */
2975 if (argv
[optind
][0] != '-') {
2976 loc_set_cmdline(argv
, optind
, 1);
2977 drive_add(IF_DEFAULT
, 0, argv
[optind
++], HD_OPTS
);
2979 const QEMUOption
*popt
;
2981 popt
= lookup_opt(argc
, argv
, &optarg
, &optind
);
2982 if (!(popt
->arch_mask
& arch_type
)) {
2983 error_report("Option not supported for this target");
2986 switch(popt
->index
) {
2987 case QEMU_OPTION_cpu
:
2988 /* hw initialization will check this */
2989 cpu_option
= optarg
;
2991 case QEMU_OPTION_hda
:
2992 case QEMU_OPTION_hdb
:
2993 case QEMU_OPTION_hdc
:
2994 case QEMU_OPTION_hdd
:
2995 drive_add(IF_DEFAULT
, popt
->index
- QEMU_OPTION_hda
, optarg
,
2998 case QEMU_OPTION_blockdev
:
3001 BlockdevOptionsQueueEntry
*bdo
;
3003 v
= qobject_input_visitor_new_str(optarg
, "driver",
3006 bdo
= g_new(BlockdevOptionsQueueEntry
, 1);
3007 visit_type_BlockdevOptions(v
, NULL
, &bdo
->bdo
,
3010 loc_save(&bdo
->loc
);
3011 QSIMPLEQ_INSERT_TAIL(&bdo_queue
, bdo
, entry
);
3014 case QEMU_OPTION_drive
:
3015 if (drive_def(optarg
) == NULL
) {
3019 case QEMU_OPTION_set
:
3020 if (qemu_set_option(optarg
) != 0)
3023 case QEMU_OPTION_global
:
3024 if (qemu_global_option(optarg
) != 0)
3027 case QEMU_OPTION_mtdblock
:
3028 drive_add(IF_MTD
, -1, optarg
, MTD_OPTS
);
3030 case QEMU_OPTION_sd
:
3031 drive_add(IF_SD
, -1, optarg
, SD_OPTS
);
3033 case QEMU_OPTION_pflash
:
3034 drive_add(IF_PFLASH
, -1, optarg
, PFLASH_OPTS
);
3036 case QEMU_OPTION_snapshot
:
3038 Error
*blocker
= NULL
;
3040 error_setg(&blocker
, QERR_REPLAY_NOT_SUPPORTED
,
3042 replay_add_blocker(blocker
);
3045 case QEMU_OPTION_numa
:
3046 opts
= qemu_opts_parse_noisily(qemu_find_opts("numa"),
3052 case QEMU_OPTION_display
:
3053 parse_display(optarg
);
3055 case QEMU_OPTION_nographic
:
3056 olist
= qemu_find_opts("machine");
3057 qemu_opts_parse_noisily(olist
, "graphics=off", false);
3059 dpy
.type
= DISPLAY_TYPE_NONE
;
3061 case QEMU_OPTION_curses
:
3062 #ifdef CONFIG_CURSES
3063 dpy
.type
= DISPLAY_TYPE_CURSES
;
3065 error_report("curses or iconv support is disabled");
3069 case QEMU_OPTION_portrait
:
3070 graphic_rotate
= 90;
3072 case QEMU_OPTION_rotate
:
3073 graphic_rotate
= strtol(optarg
, (char **) &optarg
, 10);
3074 if (graphic_rotate
!= 0 && graphic_rotate
!= 90 &&
3075 graphic_rotate
!= 180 && graphic_rotate
!= 270) {
3076 error_report("only 90, 180, 270 deg rotation is available");
3080 case QEMU_OPTION_kernel
:
3081 qemu_opts_set(qemu_find_opts("machine"), 0, "kernel", optarg
,
3084 case QEMU_OPTION_initrd
:
3085 qemu_opts_set(qemu_find_opts("machine"), 0, "initrd", optarg
,
3088 case QEMU_OPTION_append
:
3089 qemu_opts_set(qemu_find_opts("machine"), 0, "append", optarg
,
3092 case QEMU_OPTION_dtb
:
3093 qemu_opts_set(qemu_find_opts("machine"), 0, "dtb", optarg
,
3096 case QEMU_OPTION_cdrom
:
3097 drive_add(IF_DEFAULT
, 2, optarg
, CDROM_OPTS
);
3099 case QEMU_OPTION_boot
:
3100 opts
= qemu_opts_parse_noisily(qemu_find_opts("boot-opts"),
3106 case QEMU_OPTION_fda
:
3107 case QEMU_OPTION_fdb
:
3108 drive_add(IF_FLOPPY
, popt
->index
- QEMU_OPTION_fda
,
3111 case QEMU_OPTION_no_fd_bootchk
:
3114 case QEMU_OPTION_netdev
:
3116 if (net_client_parse(qemu_find_opts("netdev"), optarg
) == -1) {
3120 case QEMU_OPTION_nic
:
3122 if (net_client_parse(qemu_find_opts("nic"), optarg
) == -1) {
3126 case QEMU_OPTION_net
:
3128 if (net_client_parse(qemu_find_opts("net"), optarg
) == -1) {
3132 #ifdef CONFIG_LIBISCSI
3133 case QEMU_OPTION_iscsi
:
3134 opts
= qemu_opts_parse_noisily(qemu_find_opts("iscsi"),
3141 case QEMU_OPTION_bt
:
3142 warn_report("The bluetooth subsystem is deprecated and will "
3143 "be removed soon. If the bluetooth subsystem is "
3144 "still useful for you, please send a mail to "
3145 "qemu-devel@nongnu.org with your usecase.");
3146 add_device_config(DEV_BT
, optarg
);
3148 case QEMU_OPTION_audio_help
:
3149 audio_legacy_help();
3152 case QEMU_OPTION_audiodev
:
3153 audio_parse_option(optarg
);
3155 case QEMU_OPTION_soundhw
:
3156 select_soundhw (optarg
);
3161 case QEMU_OPTION_version
:
3166 opts
= qemu_opts_parse_noisily(qemu_find_opts("memory"),
3173 case QEMU_OPTION_tpmdev
:
3174 if (tpm_config_parse(qemu_find_opts("tpmdev"), optarg
) < 0) {
3179 case QEMU_OPTION_mempath
:
3182 case QEMU_OPTION_mem_prealloc
:
3191 case QEMU_OPTION_DFILTER
:
3192 qemu_set_dfilter_ranges(optarg
, &error_fatal
);
3194 case QEMU_OPTION_seed
:
3195 qemu_guest_random_seed_main(optarg
, &error_fatal
);
3198 add_device_config(DEV_GDB
, "tcp::" DEFAULT_GDBSTUB_PORT
);
3200 case QEMU_OPTION_gdb
:
3201 add_device_config(DEV_GDB
, optarg
);
3204 if (is_help_option(optarg
)) {
3205 list_data_dirs
= true;
3207 qemu_add_data_dir(optarg
);
3210 case QEMU_OPTION_bios
:
3211 qemu_opts_set(qemu_find_opts("machine"), 0, "firmware", optarg
,
3214 case QEMU_OPTION_singlestep
:
3221 keyboard_layout
= optarg
;
3223 case QEMU_OPTION_vga
:
3232 w
= strtol(p
, (char **)&p
, 10);
3235 error_report("invalid resolution or depth");
3241 h
= strtol(p
, (char **)&p
, 10);
3246 depth
= strtol(p
, (char **)&p
, 10);
3247 if (depth
!= 1 && depth
!= 2 && depth
!= 4 &&
3248 depth
!= 8 && depth
!= 15 && depth
!= 16 &&
3249 depth
!= 24 && depth
!= 32)
3251 } else if (*p
== '\0') {
3252 depth
= graphic_depth
;
3259 graphic_depth
= depth
;
3262 case QEMU_OPTION_echr
:
3265 term_escape_char
= strtol(optarg
, &r
, 0);
3267 printf("Bad argument to echr\n");
3270 case QEMU_OPTION_monitor
:
3271 default_monitor
= 0;
3272 if (strncmp(optarg
, "none", 4)) {
3273 monitor_parse(optarg
, "readline", false);
3276 case QEMU_OPTION_qmp
:
3277 monitor_parse(optarg
, "control", false);
3278 default_monitor
= 0;
3280 case QEMU_OPTION_qmp_pretty
:
3281 monitor_parse(optarg
, "control", true);
3282 default_monitor
= 0;
3284 case QEMU_OPTION_mon
:
3285 opts
= qemu_opts_parse_noisily(qemu_find_opts("mon"), optarg
,
3290 default_monitor
= 0;
3292 case QEMU_OPTION_chardev
:
3293 opts
= qemu_opts_parse_noisily(qemu_find_opts("chardev"),
3299 case QEMU_OPTION_fsdev
:
3300 olist
= qemu_find_opts("fsdev");
3302 error_report("fsdev support is disabled");
3305 opts
= qemu_opts_parse_noisily(olist
, optarg
, true);
3310 case QEMU_OPTION_virtfs
: {
3313 const char *writeout
, *sock_fd
, *socket
, *path
, *security_model
,
3316 olist
= qemu_find_opts("virtfs");
3318 error_report("virtfs support is disabled");
3321 opts
= qemu_opts_parse_noisily(olist
, optarg
, true);
3326 if (qemu_opt_get(opts
, "fsdriver") == NULL
||
3327 qemu_opt_get(opts
, "mount_tag") == NULL
) {
3328 error_report("Usage: -virtfs fsdriver,mount_tag=tag");
3331 fsdev
= qemu_opts_create(qemu_find_opts("fsdev"),
3332 qemu_opts_id(opts
) ?:
3333 qemu_opt_get(opts
, "mount_tag"),
3336 error_report("duplicate or invalid fsdev id: %s",
3337 qemu_opt_get(opts
, "mount_tag"));
3341 writeout
= qemu_opt_get(opts
, "writeout");
3343 #ifdef CONFIG_SYNC_FILE_RANGE
3344 qemu_opt_set(fsdev
, "writeout", writeout
, &error_abort
);
3346 error_report("writeout=immediate not supported "
3347 "on this platform");
3351 qemu_opt_set(fsdev
, "fsdriver",
3352 qemu_opt_get(opts
, "fsdriver"), &error_abort
);
3353 path
= qemu_opt_get(opts
, "path");
3355 qemu_opt_set(fsdev
, "path", path
, &error_abort
);
3357 security_model
= qemu_opt_get(opts
, "security_model");
3358 if (security_model
) {
3359 qemu_opt_set(fsdev
, "security_model", security_model
,
3362 socket
= qemu_opt_get(opts
, "socket");
3364 qemu_opt_set(fsdev
, "socket", socket
, &error_abort
);
3366 sock_fd
= qemu_opt_get(opts
, "sock_fd");
3368 qemu_opt_set(fsdev
, "sock_fd", sock_fd
, &error_abort
);
3371 qemu_opt_set_bool(fsdev
, "readonly",
3372 qemu_opt_get_bool(opts
, "readonly", 0),
3374 multidevs
= qemu_opt_get(opts
, "multidevs");
3376 qemu_opt_set(fsdev
, "multidevs", multidevs
, &error_abort
);
3378 device
= qemu_opts_create(qemu_find_opts("device"), NULL
, 0,
3380 qemu_opt_set(device
, "driver", "virtio-9p-pci", &error_abort
);
3381 qemu_opt_set(device
, "fsdev",
3382 qemu_opts_id(fsdev
), &error_abort
);
3383 qemu_opt_set(device
, "mount_tag",
3384 qemu_opt_get(opts
, "mount_tag"), &error_abort
);
3387 case QEMU_OPTION_virtfs_synth
: {
3391 warn_report("'-virtfs_synth' is deprecated, please use "
3392 "'-fsdev synth' and '-device virtio-9p-...' "
3395 fsdev
= qemu_opts_create(qemu_find_opts("fsdev"), "v_synth",
3398 error_report("duplicate option: %s", "virtfs_synth");
3401 qemu_opt_set(fsdev
, "fsdriver", "synth", &error_abort
);
3403 device
= qemu_opts_create(qemu_find_opts("device"), NULL
, 0,
3405 qemu_opt_set(device
, "driver", "virtio-9p-pci", &error_abort
);
3406 qemu_opt_set(device
, "fsdev", "v_synth", &error_abort
);
3407 qemu_opt_set(device
, "mount_tag", "v_synth", &error_abort
);
3410 case QEMU_OPTION_serial
:
3411 add_device_config(DEV_SERIAL
, optarg
);
3413 if (strncmp(optarg
, "mon:", 4) == 0) {
3414 default_monitor
= 0;
3417 case QEMU_OPTION_watchdog
:
3419 error_report("only one watchdog option may be given");
3424 case QEMU_OPTION_watchdog_action
:
3425 if (select_watchdog_action(optarg
) == -1) {
3426 error_report("unknown -watchdog-action parameter");
3430 case QEMU_OPTION_parallel
:
3431 add_device_config(DEV_PARALLEL
, optarg
);
3432 default_parallel
= 0;
3433 if (strncmp(optarg
, "mon:", 4) == 0) {
3434 default_monitor
= 0;
3437 case QEMU_OPTION_debugcon
:
3438 add_device_config(DEV_DEBUGCON
, optarg
);
3440 case QEMU_OPTION_loadvm
:
3443 case QEMU_OPTION_full_screen
:
3444 dpy
.has_full_screen
= true;
3445 dpy
.full_screen
= true;
3447 case QEMU_OPTION_alt_grab
:
3450 case QEMU_OPTION_ctrl_grab
:
3453 case QEMU_OPTION_no_quit
:
3454 dpy
.has_window_close
= true;
3455 dpy
.window_close
= false;
3457 case QEMU_OPTION_sdl
:
3459 dpy
.type
= DISPLAY_TYPE_SDL
;
3462 error_report("SDL support is disabled");
3465 case QEMU_OPTION_pidfile
:
3468 case QEMU_OPTION_win2k_hack
:
3469 win2k_install_hack
= 1;
3471 case QEMU_OPTION_acpitable
:
3472 opts
= qemu_opts_parse_noisily(qemu_find_opts("acpi"),
3477 acpi_table_add(opts
, &error_fatal
);
3479 case QEMU_OPTION_smbios
:
3480 opts
= qemu_opts_parse_noisily(qemu_find_opts("smbios"),
3485 smbios_entry_add(opts
, &error_fatal
);
3487 case QEMU_OPTION_fwcfg
:
3488 opts
= qemu_opts_parse_noisily(qemu_find_opts("fw_cfg"),
3494 case QEMU_OPTION_preconfig
:
3495 preconfig_exit_requested
= false;
3497 case QEMU_OPTION_enable_kvm
:
3498 olist
= qemu_find_opts("machine");
3499 qemu_opts_parse_noisily(olist
, "accel=kvm", false);
3502 case QEMU_OPTION_machine
:
3503 olist
= qemu_find_opts("machine");
3504 opts
= qemu_opts_parse_noisily(olist
, optarg
, true);
3509 case QEMU_OPTION_no_kvm
:
3510 olist
= qemu_find_opts("machine");
3511 qemu_opts_parse_noisily(olist
, "accel=tcg", false);
3513 case QEMU_OPTION_accel
:
3514 accel_opts
= qemu_opts_parse_noisily(qemu_find_opts("accel"),
3516 optarg
= qemu_opt_get(accel_opts
, "accel");
3517 if (!optarg
|| is_help_option(optarg
)) {
3518 printf("Accelerators supported in QEMU binary:\n");
3519 GSList
*el
, *accel_list
= object_class_get_list(TYPE_ACCEL
,
3521 for (el
= accel_list
; el
; el
= el
->next
) {
3522 gchar
*typename
= g_strdup(object_class_get_name(
3523 OBJECT_CLASS(el
->data
)));
3524 /* omit qtest which is used for tests only */
3525 if (g_strcmp0(typename
, ACCEL_CLASS_NAME("qtest")) &&
3526 g_str_has_suffix(typename
, ACCEL_CLASS_SUFFIX
)) {
3527 gchar
**optname
= g_strsplit(typename
,
3528 ACCEL_CLASS_SUFFIX
, 0);
3529 printf("%s\n", optname
[0]);
3534 g_slist_free(accel_list
);
3537 if (optarg
&& strchr(optarg
, ':')) {
3538 error_report("Don't use ':' with -accel, "
3539 "use -M accel=... for now instead");
3542 opts
= qemu_opts_create(qemu_find_opts("machine"), NULL
,
3543 false, &error_abort
);
3544 qemu_opt_set(opts
, "accel", optarg
, &error_abort
);
3546 case QEMU_OPTION_usb
:
3547 olist
= qemu_find_opts("machine");
3548 qemu_opts_parse_noisily(olist
, "usb=on", false);
3550 case QEMU_OPTION_usbdevice
:
3551 error_report("'-usbdevice' is deprecated, please use "
3552 "'-device usb-...' instead");
3553 olist
= qemu_find_opts("machine");
3554 qemu_opts_parse_noisily(olist
, "usb=on", false);
3555 add_device_config(DEV_USB
, optarg
);
3557 case QEMU_OPTION_device
:
3558 if (!qemu_opts_parse_noisily(qemu_find_opts("device"),
3563 case QEMU_OPTION_smp
:
3564 if (!qemu_opts_parse_noisily(qemu_find_opts("smp-opts"),
3569 case QEMU_OPTION_vnc
:
3570 vnc_parse(optarg
, &error_fatal
);
3572 case QEMU_OPTION_no_acpi
:
3575 case QEMU_OPTION_no_hpet
:
3578 case QEMU_OPTION_no_reboot
:
3581 case QEMU_OPTION_no_shutdown
:
3584 case QEMU_OPTION_show_cursor
:
3587 case QEMU_OPTION_uuid
:
3588 if (qemu_uuid_parse(optarg
, &qemu_uuid
) < 0) {
3589 error_report("failed to parse UUID string: wrong format");
3592 qemu_uuid_set
= true;
3594 case QEMU_OPTION_option_rom
:
3595 if (nb_option_roms
>= MAX_OPTION_ROMS
) {
3596 error_report("too many option ROMs");
3599 opts
= qemu_opts_parse_noisily(qemu_find_opts("option-rom"),
3604 option_rom
[nb_option_roms
].name
= qemu_opt_get(opts
, "romfile");
3605 option_rom
[nb_option_roms
].bootindex
=
3606 qemu_opt_get_number(opts
, "bootindex", -1);
3607 if (!option_rom
[nb_option_roms
].name
) {
3608 error_report("Option ROM file is not specified");
3613 case QEMU_OPTION_semihosting
:
3614 qemu_semihosting_enable();
3616 case QEMU_OPTION_semihosting_config
:
3617 if (qemu_semihosting_config_options(optarg
) != 0) {
3621 case QEMU_OPTION_name
:
3622 opts
= qemu_opts_parse_noisily(qemu_find_opts("name"),
3628 case QEMU_OPTION_prom_env
:
3629 if (nb_prom_envs
>= MAX_PROM_ENVS
) {
3630 error_report("too many prom variables");
3633 prom_envs
[nb_prom_envs
] = optarg
;
3636 case QEMU_OPTION_old_param
:
3639 case QEMU_OPTION_rtc
:
3640 opts
= qemu_opts_parse_noisily(qemu_find_opts("rtc"), optarg
,
3646 case QEMU_OPTION_tb_size
:
3648 error_report("TCG is disabled");
3651 if (qemu_strtoul(optarg
, NULL
, 0, &tcg_tb_size
) < 0) {
3652 error_report("Invalid argument to -tb-size");
3656 case QEMU_OPTION_icount
:
3657 icount_opts
= qemu_opts_parse_noisily(qemu_find_opts("icount"),
3663 case QEMU_OPTION_incoming
:
3665 runstate_set(RUN_STATE_INMIGRATE
);
3669 case QEMU_OPTION_only_migratable
:
3670 only_migratable
= 1;
3672 case QEMU_OPTION_nodefaults
:
3675 case QEMU_OPTION_xen_domid
:
3676 if (!(xen_available())) {
3677 error_report("Option not supported for this target");
3680 xen_domid
= atoi(optarg
);
3682 case QEMU_OPTION_xen_attach
:
3683 if (!(xen_available())) {
3684 error_report("Option not supported for this target");
3687 xen_mode
= XEN_ATTACH
;
3689 case QEMU_OPTION_xen_domid_restrict
:
3690 if (!(xen_available())) {
3691 error_report("Option not supported for this target");
3694 xen_domid_restrict
= true;
3696 case QEMU_OPTION_trace
:
3698 trace_file
= trace_opt_parse(optarg
);
3700 case QEMU_OPTION_trace_unassigned
:
3701 trace_unassigned
= true;
3703 case QEMU_OPTION_plugin
:
3704 qemu_plugin_opt_parse(optarg
, &plugin_list
);
3706 case QEMU_OPTION_readconfig
:
3708 int ret
= qemu_read_config_file(optarg
);
3710 error_report("read config %s: %s", optarg
,
3716 case QEMU_OPTION_spice
:
3717 olist
= qemu_find_opts("spice");
3719 error_report("spice support is disabled");
3722 opts
= qemu_opts_parse_noisily(olist
, optarg
, false);
3728 case QEMU_OPTION_writeconfig
:
3731 if (strcmp(optarg
, "-") == 0) {
3734 fp
= fopen(optarg
, "w");
3736 error_report("open %s: %s", optarg
,
3741 qemu_config_write(fp
);
3747 case QEMU_OPTION_qtest
:
3748 qtest_chrdev
= optarg
;
3750 case QEMU_OPTION_qtest_log
:
3753 case QEMU_OPTION_sandbox
:
3754 olist
= qemu_find_opts("sandbox");
3756 #ifndef CONFIG_SECCOMP
3757 error_report("-sandbox support is not enabled "
3758 "in this QEMU binary");
3763 opts
= qemu_opts_parse_noisily(olist
, optarg
, true);
3768 case QEMU_OPTION_add_fd
:
3770 opts
= qemu_opts_parse_noisily(qemu_find_opts("add-fd"),
3776 error_report("File descriptor passing is disabled on this "
3781 case QEMU_OPTION_object
:
3782 opts
= qemu_opts_parse_noisily(qemu_find_opts("object"),
3788 case QEMU_OPTION_realtime
:
3789 warn_report("'-realtime mlock=...' is deprecated, please use "
3790 "'-overcommit mem-lock=...' instead");
3791 opts
= qemu_opts_parse_noisily(qemu_find_opts("realtime"),
3796 /* Don't override the -overcommit option if set */
3797 enable_mlock
= enable_mlock
||
3798 qemu_opt_get_bool(opts
, "mlock", true);
3800 case QEMU_OPTION_overcommit
:
3801 opts
= qemu_opts_parse_noisily(qemu_find_opts("overcommit"),
3806 /* Don't override the -realtime option if set */
3807 enable_mlock
= enable_mlock
||
3808 qemu_opt_get_bool(opts
, "mem-lock", false);
3809 enable_cpu_pm
= qemu_opt_get_bool(opts
, "cpu-pm", false);
3811 case QEMU_OPTION_msg
:
3812 opts
= qemu_opts_parse_noisily(qemu_find_opts("msg"), optarg
,
3817 configure_msg(opts
);
3819 case QEMU_OPTION_dump_vmstate
:
3820 if (vmstate_dump_file
) {
3821 error_report("only one '-dump-vmstate' "
3822 "option may be given");
3825 vmstate_dump_file
= fopen(optarg
, "w");
3826 if (vmstate_dump_file
== NULL
) {
3827 error_report("open %s: %s", optarg
, strerror(errno
));
3831 case QEMU_OPTION_enable_sync_profile
:
3834 case QEMU_OPTION_nouserconfig
:
3835 /* Nothing to be parsed here. Especially, do not error out below. */
3838 if (os_parse_cmd_args(popt
->index
, optarg
)) {
3839 error_report("Option not supported in this build");
3846 * Clear error location left behind by the loop.
3847 * Best done right after the loop. Do not insert code here!
3851 user_register_global_props();
3853 replay_configure(icount_opts
);
3855 if (incoming
&& !preconfig_exit_requested
) {
3856 error_report("'preconfig' and 'incoming' options are "
3857 "mutually exclusive");
3861 configure_rtc(qemu_find_opts_singleton("rtc"));
3863 machine_class
= select_machine();
3864 object_set_machine_compat_props(machine_class
->compat_props
);
3866 set_memory_options(&ram_slots
, &maxram_size
, machine_class
);
3869 rcu_disable_atfork();
3871 if (pid_file
&& !qemu_write_pidfile(pid_file
, &err
)) {
3872 error_reportf_err(err
, "cannot create PID file: ");
3876 qemu_unlink_pidfile_notifier
.notify
= qemu_unlink_pidfile
;
3877 qemu_add_exit_notifier(&qemu_unlink_pidfile_notifier
);
3879 if (qemu_init_main_loop(&main_loop_err
)) {
3880 error_report_err(main_loop_err
);
3884 #ifdef CONFIG_SECCOMP
3885 olist
= qemu_find_opts_err("sandbox", NULL
);
3887 qemu_opts_foreach(olist
, parse_sandbox
, NULL
, &error_fatal
);
3891 qemu_opts_foreach(qemu_find_opts("name"),
3892 parse_name
, NULL
, &error_fatal
);
3895 qemu_opts_foreach(qemu_find_opts("add-fd"),
3896 parse_add_fd
, NULL
, &error_fatal
);
3898 qemu_opts_foreach(qemu_find_opts("add-fd"),
3899 cleanup_add_fd
, NULL
, &error_fatal
);
3902 current_machine
= MACHINE(object_new(object_class_get_name(
3903 OBJECT_CLASS(machine_class
))));
3904 if (machine_help_func(qemu_get_machine_opts(), current_machine
)) {
3907 object_property_add_child(object_get_root(), "machine",
3908 OBJECT(current_machine
), &error_abort
);
3909 object_property_add_child(container_get(OBJECT(current_machine
),
3911 "sysbus", OBJECT(sysbus_get_default()),
3914 if (machine_class
->minimum_page_bits
) {
3915 if (!set_preferred_target_page_bits(machine_class
->minimum_page_bits
)) {
3916 /* This would be a board error: specifying a minimum smaller than
3917 * a target's compile-time fixed setting.
3919 g_assert_not_reached();
3923 cpu_exec_init_all();
3925 if (machine_class
->hw_version
) {
3926 qemu_set_hw_version(machine_class
->hw_version
);
3929 if (cpu_option
&& is_help_option(cpu_option
)) {
3930 list_cpus(cpu_option
);
3934 if (!trace_init_backends()) {
3937 trace_init_file(trace_file
);
3939 /* Open the logfile at this point and set the log mask if necessary.
3942 qemu_set_log_filename(log_file
, &error_fatal
);
3947 mask
= qemu_str_to_log_mask(log_mask
);
3949 qemu_print_log_usage(stdout
);
3957 /* add configured firmware directories */
3958 dirs
= g_strsplit(CONFIG_QEMU_FIRMWAREPATH
, G_SEARCHPATH_SEPARATOR_S
, 0);
3959 for (i
= 0; dirs
[i
] != NULL
; i
++) {
3960 qemu_add_data_dir(dirs
[i
]);
3964 /* try to find datadir relative to the executable path */
3965 dir
= os_find_datadir();
3966 qemu_add_data_dir(dir
);
3969 /* add the datadir specified when building */
3970 qemu_add_data_dir(CONFIG_QEMU_DATADIR
);
3972 /* -L help lists the data directories and exits. */
3973 if (list_data_dirs
) {
3974 for (i
= 0; i
< data_dir_idx
; i
++) {
3975 printf("%s\n", data_dir
[i
]);
3980 /* machine_class: default to UP */
3981 machine_class
->max_cpus
= machine_class
->max_cpus
?: 1;
3982 machine_class
->min_cpus
= machine_class
->min_cpus
?: 1;
3983 machine_class
->default_cpus
= machine_class
->default_cpus
?: 1;
3985 /* default to machine_class->default_cpus */
3986 current_machine
->smp
.cpus
= machine_class
->default_cpus
;
3987 current_machine
->smp
.max_cpus
= machine_class
->default_cpus
;
3988 current_machine
->smp
.cores
= 1;
3989 current_machine
->smp
.threads
= 1;
3991 machine_class
->smp_parse(current_machine
,
3992 qemu_opts_find(qemu_find_opts("smp-opts"), NULL
));
3994 /* sanity-check smp_cpus and max_cpus against machine_class */
3995 if (current_machine
->smp
.cpus
< machine_class
->min_cpus
) {
3996 error_report("Invalid SMP CPUs %d. The min CPUs "
3997 "supported by machine '%s' is %d",
3998 current_machine
->smp
.cpus
,
3999 machine_class
->name
, machine_class
->min_cpus
);
4002 if (current_machine
->smp
.max_cpus
> machine_class
->max_cpus
) {
4003 error_report("Invalid SMP CPUs %d. The max CPUs "
4004 "supported by machine '%s' is %d",
4005 current_machine
->smp
.max_cpus
,
4006 machine_class
->name
, machine_class
->max_cpus
);
4011 * Get the default machine options from the machine if it is not already
4012 * specified either by the configuration file or by the command line.
4014 if (machine_class
->default_machine_opts
) {
4015 qemu_opts_set_defaults(qemu_find_opts("machine"),
4016 machine_class
->default_machine_opts
, 0);
4019 /* process plugin before CPUs are created, but once -smp has been parsed */
4020 if (qemu_plugin_load_list(&plugin_list
)) {
4024 qemu_opts_foreach(qemu_find_opts("device"),
4025 default_driver_check
, NULL
, NULL
);
4026 qemu_opts_foreach(qemu_find_opts("global"),
4027 default_driver_check
, NULL
, NULL
);
4029 if (!vga_model
&& !default_vga
) {
4030 vga_interface_type
= VGA_DEVICE
;
4032 if (!has_defaults
|| machine_class
->no_serial
) {
4035 if (!has_defaults
|| machine_class
->no_parallel
) {
4036 default_parallel
= 0;
4038 if (!has_defaults
|| machine_class
->no_floppy
) {
4041 if (!has_defaults
|| machine_class
->no_cdrom
) {
4044 if (!has_defaults
|| machine_class
->no_sdcard
) {
4047 if (!has_defaults
) {
4048 default_monitor
= 0;
4053 if (is_daemonized()) {
4054 if (!preconfig_exit_requested
) {
4055 error_report("'preconfig' and 'daemonize' options are "
4056 "mutually exclusive");
4060 /* According to documentation and historically, -nographic redirects
4061 * serial port, parallel port and monitor to stdio, which does not work
4062 * with -daemonize. We can redirect these to null instead, but since
4063 * -nographic is legacy, let's just error out.
4064 * We disallow -nographic only if all other ports are not redirected
4065 * explicitly, to not break existing legacy setups which uses
4066 * -nographic _and_ redirects all ports explicitly - this is valid
4067 * usage, -nographic is just a no-op in this case.
4070 && (default_parallel
|| default_serial
|| default_monitor
)) {
4071 error_report("-nographic cannot be used with -daemonize");
4074 #ifdef CONFIG_CURSES
4075 if (dpy
.type
== DISPLAY_TYPE_CURSES
) {
4076 error_report("curses display cannot be used with -daemonize");
4083 if (default_parallel
)
4084 add_device_config(DEV_PARALLEL
, "null");
4085 if (default_serial
&& default_monitor
) {
4086 add_device_config(DEV_SERIAL
, "mon:stdio");
4089 add_device_config(DEV_SERIAL
, "stdio");
4090 if (default_monitor
)
4091 monitor_parse("stdio", "readline", false);
4095 add_device_config(DEV_SERIAL
, "vc:80Cx24C");
4096 if (default_parallel
)
4097 add_device_config(DEV_PARALLEL
, "vc:80Cx24C");
4098 if (default_monitor
)
4099 monitor_parse("vc:80Cx24C", "readline", false);
4102 #if defined(CONFIG_VNC)
4103 if (!QTAILQ_EMPTY(&(qemu_find_opts("vnc")->head
))) {
4107 if (dpy
.type
== DISPLAY_TYPE_DEFAULT
&& !display_remote
) {
4108 if (!qemu_display_find_default(&dpy
)) {
4109 dpy
.type
= DISPLAY_TYPE_NONE
;
4110 #if defined(CONFIG_VNC)
4111 vnc_parse("localhost:0,to=99,id=default", &error_abort
);
4115 if (dpy
.type
== DISPLAY_TYPE_DEFAULT
) {
4116 dpy
.type
= DISPLAY_TYPE_NONE
;
4119 if ((alt_grab
|| ctrl_grab
) && dpy
.type
!= DISPLAY_TYPE_SDL
) {
4120 error_report("-alt-grab and -ctrl-grab are only valid "
4121 "for SDL, ignoring option");
4123 if (dpy
.has_window_close
&&
4124 (dpy
.type
!= DISPLAY_TYPE_GTK
&& dpy
.type
!= DISPLAY_TYPE_SDL
)) {
4125 error_report("-no-quit is only valid for GTK and SDL, "
4129 qemu_display_early_init(&dpy
);
4130 qemu_console_early_init();
4132 if (dpy
.has_gl
&& dpy
.gl
!= DISPLAYGL_MODE_OFF
&& display_opengl
== 0) {
4133 #if defined(CONFIG_OPENGL)
4134 error_report("OpenGL is not supported by the display");
4136 error_report("OpenGL support is disabled");
4144 qemu_opts_foreach(qemu_find_opts("object"),
4145 user_creatable_add_opts_foreach
,
4146 object_create_initial
, &error_fatal
);
4148 qemu_opts_foreach(qemu_find_opts("chardev"),
4149 chardev_init_func
, NULL
, &error_fatal
);
4150 /* now chardevs have been created we may have semihosting to connect */
4151 qemu_semihosting_connect_chardevs();
4153 #ifdef CONFIG_VIRTFS
4154 qemu_opts_foreach(qemu_find_opts("fsdev"),
4155 fsdev_init_func
, NULL
, &error_fatal
);
4158 if (qemu_opts_foreach(qemu_find_opts("device"),
4159 device_help_func
, NULL
, NULL
)) {
4164 * Note: we need to create block backends before
4165 * machine_set_property(), so machine properties can refer to
4168 configure_blockdev(&bdo_queue
, machine_class
, snapshot
);
4170 machine_opts
= qemu_get_machine_opts();
4171 qemu_opt_foreach(machine_opts
, machine_set_property
, current_machine
,
4173 current_machine
->ram_size
= ram_size
;
4174 current_machine
->maxram_size
= maxram_size
;
4175 current_machine
->ram_slots
= ram_slots
;
4178 * Note: uses machine properties such as kernel-irqchip, must run
4179 * after machine_set_property().
4181 configure_accelerator(current_machine
, argv
[0]);
4184 * Beware, QOM objects created before this point miss global and
4185 * compat properties.
4187 * Global properties get set up by qdev_prop_register_global(),
4188 * called from user_register_global_props(), and certain option
4189 * desugaring. Also in CPU feature desugaring (buried in
4190 * parse_cpu_option()), which happens below this point, but may
4191 * only target the CPU type, which can only be created after
4192 * parse_cpu_option() returned the type.
4194 * Machine compat properties: object_set_machine_compat_props().
4195 * Accelerator compat props: object_set_accelerator_compat_props(),
4196 * called from configure_accelerator().
4199 if (!qtest_enabled() && machine_class
->deprecation_reason
) {
4200 error_report("Machine type '%s' is deprecated: %s",
4201 machine_class
->name
, machine_class
->deprecation_reason
);
4205 * Note: creates a QOM object, must run only after global and
4206 * compat properties have been set up.
4208 migration_object_init();
4211 qtest_server_init(qtest_chrdev
, qtest_log
, &error_fatal
);
4214 machine_opts
= qemu_get_machine_opts();
4215 kernel_filename
= qemu_opt_get(machine_opts
, "kernel");
4216 initrd_filename
= qemu_opt_get(machine_opts
, "initrd");
4217 kernel_cmdline
= qemu_opt_get(machine_opts
, "append");
4218 bios_name
= qemu_opt_get(machine_opts
, "firmware");
4220 opts
= qemu_opts_find(qemu_find_opts("boot-opts"), NULL
);
4222 boot_order
= qemu_opt_get(opts
, "order");
4224 validate_bootdevices(boot_order
, &error_fatal
);
4227 boot_once
= qemu_opt_get(opts
, "once");
4229 validate_bootdevices(boot_once
, &error_fatal
);
4232 boot_menu
= qemu_opt_get_bool(opts
, "menu", boot_menu
);
4233 boot_strict
= qemu_opt_get_bool(opts
, "strict", false);
4237 boot_order
= machine_class
->default_boot_order
;
4240 if (!kernel_cmdline
) {
4241 kernel_cmdline
= "";
4242 current_machine
->kernel_cmdline
= (char *)kernel_cmdline
;
4245 linux_boot
= (kernel_filename
!= NULL
);
4247 if (!linux_boot
&& *kernel_cmdline
!= '\0') {
4248 error_report("-append only allowed with -kernel option");
4252 if (!linux_boot
&& initrd_filename
!= NULL
) {
4253 error_report("-initrd only allowed with -kernel option");
4257 if (semihosting_enabled() && !semihosting_get_argc() && kernel_filename
) {
4258 /* fall back to the -kernel/-append */
4259 semihosting_arg_fallback(kernel_filename
, kernel_cmdline
);
4262 /* spice needs the timers to be initialized by this point */
4267 if (!tcg_enabled()) {
4268 error_report("-icount is not allowed with hardware virtualization");
4271 configure_icount(icount_opts
, &error_abort
);
4272 qemu_opts_del(icount_opts
);
4275 if (tcg_enabled()) {
4276 qemu_tcg_configure(accel_opts
, &error_fatal
);
4280 QemuOptsList
*net
= qemu_find_opts("net");
4281 qemu_opts_set(net
, NULL
, "type", "nic", &error_abort
);
4283 qemu_opts_set(net
, NULL
, "type", "user", &error_abort
);
4287 if (net_init_clients(&err
) < 0) {
4288 error_report_err(err
);
4292 qemu_opts_foreach(qemu_find_opts("object"),
4293 user_creatable_add_opts_foreach
,
4294 object_create_delayed
, &error_fatal
);
4298 /* init the bluetooth world */
4299 if (foreach_device_config(DEV_BT
, bt_parse
))
4302 if (!xen_enabled()) {
4303 /* On 32-bit hosts, QEMU is limited by virtual address space */
4304 if (ram_size
> (2047 << 20) && HOST_LONG_BITS
== 32) {
4305 error_report("at most 2047 MB RAM can be simulated");
4312 dirty_bitmap_mig_init();
4314 qemu_opts_foreach(qemu_find_opts("mon"),
4315 mon_init_func
, NULL
, &error_fatal
);
4317 if (foreach_device_config(DEV_SERIAL
, serial_parse
) < 0)
4319 if (foreach_device_config(DEV_PARALLEL
, parallel_parse
) < 0)
4321 if (foreach_device_config(DEV_DEBUGCON
, debugcon_parse
) < 0)
4324 /* If no default VGA is requested, the default is "none". */
4326 vga_model
= get_default_vga_model(machine_class
);
4329 select_vgahw(machine_class
, vga_model
);
4333 i
= select_watchdog(watchdog
);
4335 exit (i
== 1 ? 1 : 0);
4338 /* This checkpoint is required by replay to separate prior clock
4339 reading from the other reads, because timer polling functions query
4340 clock values from the log. */
4341 replay_checkpoint(CHECKPOINT_INIT
);
4342 qdev_machine_init();
4344 current_machine
->boot_order
= boot_order
;
4346 /* parse features once if machine provides default cpu_type */
4347 current_machine
->cpu_type
= machine_class
->default_cpu_type
;
4349 current_machine
->cpu_type
= parse_cpu_option(cpu_option
);
4351 parse_numa_opts(current_machine
);
4353 /* do monitor/qmp handling at preconfig state if requested */
4356 audio_init_audiodevs();
4358 /* from here on runstate is RUN_STATE_PRELAUNCH */
4359 machine_run_board_init(current_machine
);
4365 if (hax_enabled()) {
4369 qemu_opts_foreach(qemu_find_opts("fw_cfg"),
4370 parse_fw_cfg
, fw_cfg_find(), &error_fatal
);
4372 /* init USB devices */
4373 if (machine_usb(current_machine
)) {
4374 if (foreach_device_config(DEV_USB
, usb_parse
) < 0)
4378 /* Check if IGD GFX passthrough. */
4381 /* init generic devices */
4382 rom_set_order_override(FW_CFG_ORDER_OVERRIDE_DEVICE
);
4383 qemu_opts_foreach(qemu_find_opts("device"),
4384 device_init_func
, NULL
, &error_fatal
);
4386 cpu_synchronize_all_post_init();
4388 rom_reset_order_override();
4390 /* Did we create any drives that we failed to create a device for? */
4391 drive_check_orphaned();
4393 /* Don't warn about the default network setup that you get if
4394 * no command line -net or -netdev options are specified. There
4395 * are two cases that we would otherwise complain about:
4396 * (1) board doesn't support a NIC but the implicit "-net nic"
4398 * (2) CONFIG_SLIRP not set, in which case the implicit "-net nic"
4399 * sets up a nic that isn't connected to anything.
4401 if (!default_net
&& (!qtest_enabled() || has_defaults
)) {
4402 net_check_clients();
4406 qemu_boot_set(boot_once
, &error_fatal
);
4407 qemu_register_reset(restore_boot_order
, g_strdup(boot_order
));
4410 /* init local displays */
4411 ds
= init_displaystate();
4412 qemu_display_init(ds
, &dpy
);
4414 /* must be after terminal init, SDL library changes signal handlers */
4415 os_setup_signal_handling();
4417 /* init remote displays */
4419 qemu_opts_foreach(qemu_find_opts("vnc"),
4420 vnc_init_func
, NULL
, &error_fatal
);
4424 qemu_spice_display_init();
4427 if (foreach_device_config(DEV_GDB
, gdbserver_start
) < 0) {
4431 qdev_machine_creation_done();
4433 /* TODO: once all bus devices are qdevified, this should be done
4434 * when bus is created by qdev.c */
4435 qemu_register_reset(qbus_reset_all_fn
, sysbus_get_default());
4436 qemu_run_machine_init_done_notifiers();
4438 if (rom_check_and_register_reset() != 0) {
4439 error_report("rom check and register reset failed");
4445 /* This checkpoint is required by replay to separate prior clock
4446 reading from the other reads, because timer polling functions query
4447 clock values from the log. */
4448 replay_checkpoint(CHECKPOINT_RESET
);
4449 qemu_system_reset(SHUTDOWN_CAUSE_NONE
);
4450 register_global_state();
4452 Error
*local_err
= NULL
;
4453 if (load_snapshot(loadvm
, &local_err
) < 0) {
4454 error_report_err(local_err
);
4459 if (replay_mode
!= REPLAY_MODE_NONE
) {
4460 replay_vmstate_init();
4463 qdev_prop_check_globals();
4464 if (vmstate_dump_file
) {
4466 dump_vmstate_json_to_file(vmstate_dump_file
);
4471 Error
*local_err
= NULL
;
4472 qemu_start_incoming_migration(incoming
, &local_err
);
4474 error_reportf_err(local_err
, "-incoming %s: ", incoming
);
4477 } else if (autostart
) {
4481 accel_setup_post(current_machine
);
4486 gdbserver_cleanup();
4489 * cleaning up the migration object cancels any existing migration
4490 * try to do this early so that it also stops using devices.
4492 migration_shutdown();
4495 * We must cancel all block jobs while the block layer is drained,
4496 * or cancelling will be affected by throttling and thus may block
4497 * for an extended period of time.
4498 * vm_shutdown() will bdrv_drain_all(), so we may as well include
4499 * it in the drained section.
4500 * We do not need to end this section, because we do not want any
4501 * requests happening from here on anyway.
4503 bdrv_drain_all_begin();
4505 /* No more vcpu or device emulation activity beyond this point */
4509 job_cancel_sync_all();
4514 /* vhost-user must be cleaned up before chardevs. */
4520 user_creatable_cleanup();
4521 /* TODO: unref root container, check all devices are ok */