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/units.h"
27 #include "qapi/error.h"
28 #include "qemu-version.h"
29 #include "qemu/cutils.h"
30 #include "qemu/help_option.h"
31 #include "qemu/uuid.h"
32 #include "sysemu/seccomp.h"
33 #include "sysemu/tcg.h"
36 #if defined(__APPLE__) || defined(main)
38 int qemu_main(int argc
, char **argv
, char **envp
);
39 int main(int argc
, char **argv
)
41 return qemu_main(argc
, argv
, NULL
);
44 #define main qemu_main
46 #endif /* CONFIG_SDL */
50 #define main qemu_main
51 #endif /* CONFIG_COCOA */
54 #include "qemu/error-report.h"
55 #include "qemu/sockets.h"
57 #include "hw/boards.h"
58 #include "sysemu/accel.h"
60 #include "hw/isa/isa.h"
61 #include "hw/scsi/scsi.h"
62 #include "hw/display/vga.h"
64 #include "sysemu/watchdog.h"
65 #include "hw/firmware/smbios.h"
66 #include "hw/acpi/acpi.h"
67 #include "hw/xen/xen.h"
69 #include "hw/loader.h"
70 #include "monitor/qdev.h"
71 #include "sysemu/bt.h"
73 #include "net/slirp.h"
74 #include "monitor/monitor.h"
75 #include "ui/console.h"
77 #include "sysemu/sysemu.h"
78 #include "sysemu/numa.h"
79 #include "exec/gdbstub.h"
80 #include "qemu/timer.h"
81 #include "chardev/char.h"
82 #include "qemu/bitmap.h"
84 #include "sysemu/blockdev.h"
85 #include "hw/block/block.h"
86 #include "migration/misc.h"
87 #include "migration/snapshot.h"
88 #include "migration/global_state.h"
89 #include "sysemu/tpm.h"
90 #include "sysemu/dma.h"
91 #include "hw/audio/soundhw.h"
92 #include "audio/audio.h"
93 #include "sysemu/cpus.h"
94 #include "migration/colo.h"
95 #include "migration/postcopy-ram.h"
96 #include "sysemu/kvm.h"
97 #include "sysemu/hax.h"
98 #include "qapi/qobject-input-visitor.h"
99 #include "qemu/option.h"
100 #include "qemu/config-file.h"
101 #include "qemu-options.h"
102 #include "qemu/main-loop.h"
104 #include "fsdev/qemu-fsdev.h"
106 #include "sysemu/qtest.h"
108 #include "disas/disas.h"
110 #include "trace-root.h"
111 #include "trace/control.h"
112 #include "qemu/queue.h"
113 #include "sysemu/arch_init.h"
115 #include "ui/qemu-spice.h"
116 #include "qapi/string-input-visitor.h"
117 #include "qapi/opts-visitor.h"
118 #include "qapi/clone-visitor.h"
119 #include "qom/object_interfaces.h"
120 #include "hw/semihosting/semihost.h"
121 #include "crypto/init.h"
122 #include "sysemu/replay.h"
123 #include "qapi/qapi-events-run-state.h"
124 #include "qapi/qapi-visit-block-core.h"
125 #include "qapi/qapi-visit-ui.h"
126 #include "qapi/qapi-commands-block-core.h"
127 #include "qapi/qapi-commands-misc.h"
128 #include "qapi/qapi-commands-run-state.h"
129 #include "qapi/qapi-commands-ui.h"
130 #include "qapi/qmp/qerror.h"
131 #include "sysemu/iothread.h"
132 #include "qemu/guest-random.h"
134 #define MAX_VIRTIO_CONSOLES 1
136 static const char *data_dir
[16];
137 static int data_dir_idx
;
138 const char *bios_name
= NULL
;
139 enum vga_retrace_method vga_retrace_method
= VGA_RETRACE_DUMB
;
141 const char* keyboard_layout
= NULL
;
143 const char *mem_path
= NULL
;
144 int mem_prealloc
= 0; /* force preallocation of physical target memory */
145 bool enable_mlock
= false;
146 bool enable_cpu_pm
= false;
148 NICInfo nd_table
[MAX_NICS
];
154 } rtc_base_type
= RTC_BASE_UTC
;
155 static time_t rtc_ref_start_datetime
;
156 static int rtc_realtime_clock_offset
; /* used only with QEMU_CLOCK_REALTIME */
157 static int rtc_host_datetime_offset
= -1; /* valid & used only with
159 QEMUClockType rtc_clock
;
160 int vga_interface_type
= VGA_NONE
;
161 static DisplayOptions dpy
;
162 static int num_serial_hds
;
163 static Chardev
**serial_hds
;
164 Chardev
*parallel_hds
[MAX_PARALLEL_PORTS
];
165 int win2k_install_hack
= 0;
168 unsigned int max_cpus
;
171 int acpi_enabled
= 1;
174 static int no_reboot
;
177 int graphic_rotate
= 0;
178 const char *watchdog
;
179 QEMUOptionRom option_rom
[MAX_OPTION_ROMS
];
182 const char *qemu_name
;
185 unsigned int nb_prom_envs
= 0;
186 const char *prom_envs
[MAX_PROM_ENVS
];
189 uint8_t *boot_splash_filedata
;
190 int only_migratable
; /* turn it off unless user states otherwise */
191 bool wakeup_suspend_enabled
;
193 int icount_align_option
;
195 /* The bytes in qemu_uuid are in the order specified by RFC4122, _not_ in the
196 * little-endian "wire format" described in the SMBIOS 2.6 specification.
201 static NotifierList exit_notifiers
=
202 NOTIFIER_LIST_INITIALIZER(exit_notifiers
);
204 static NotifierList machine_init_done_notifiers
=
205 NOTIFIER_LIST_INITIALIZER(machine_init_done_notifiers
);
209 enum xen_mode xen_mode
= XEN_EMULATE
;
210 bool xen_domid_restrict
;
212 static int has_defaults
= 1;
213 static int default_serial
= 1;
214 static int default_parallel
= 1;
215 static int default_monitor
= 1;
216 static int default_floppy
= 1;
217 static int default_cdrom
= 1;
218 static int default_sdcard
= 1;
219 static int default_vga
= 1;
220 static int default_net
= 1;
226 { .driver
= "isa-serial", .flag
= &default_serial
},
227 { .driver
= "isa-parallel", .flag
= &default_parallel
},
228 { .driver
= "isa-fdc", .flag
= &default_floppy
},
229 { .driver
= "floppy", .flag
= &default_floppy
},
230 { .driver
= "ide-cd", .flag
= &default_cdrom
},
231 { .driver
= "ide-hd", .flag
= &default_cdrom
},
232 { .driver
= "ide-drive", .flag
= &default_cdrom
},
233 { .driver
= "scsi-cd", .flag
= &default_cdrom
},
234 { .driver
= "scsi-hd", .flag
= &default_cdrom
},
235 { .driver
= "VGA", .flag
= &default_vga
},
236 { .driver
= "isa-vga", .flag
= &default_vga
},
237 { .driver
= "cirrus-vga", .flag
= &default_vga
},
238 { .driver
= "isa-cirrus-vga", .flag
= &default_vga
},
239 { .driver
= "vmware-svga", .flag
= &default_vga
},
240 { .driver
= "qxl-vga", .flag
= &default_vga
},
241 { .driver
= "virtio-vga", .flag
= &default_vga
},
242 { .driver
= "ati-vga", .flag
= &default_vga
},
243 { .driver
= "vhost-user-vga", .flag
= &default_vga
},
246 static QemuOptsList qemu_rtc_opts
= {
248 .head
= QTAILQ_HEAD_INITIALIZER(qemu_rtc_opts
.head
),
253 .type
= QEMU_OPT_STRING
,
256 .type
= QEMU_OPT_STRING
,
259 .type
= QEMU_OPT_STRING
,
261 { /* end of list */ }
265 static QemuOptsList qemu_option_rom_opts
= {
266 .name
= "option-rom",
267 .implied_opt_name
= "romfile",
268 .head
= QTAILQ_HEAD_INITIALIZER(qemu_option_rom_opts
.head
),
272 .type
= QEMU_OPT_NUMBER
,
275 .type
= QEMU_OPT_STRING
,
277 { /* end of list */ }
281 static QemuOptsList qemu_machine_opts
= {
283 .implied_opt_name
= "type",
285 .head
= QTAILQ_HEAD_INITIALIZER(qemu_machine_opts
.head
),
288 * no elements => accept any
289 * sanity checking will happen later
290 * when setting machine properties
296 static QemuOptsList qemu_accel_opts
= {
298 .implied_opt_name
= "accel",
299 .head
= QTAILQ_HEAD_INITIALIZER(qemu_accel_opts
.head
),
304 .type
= QEMU_OPT_STRING
,
305 .help
= "Select the type of accelerator",
309 .type
= QEMU_OPT_STRING
,
310 .help
= "Enable/disable multi-threaded TCG",
312 { /* end of list */ }
316 static QemuOptsList qemu_boot_opts
= {
318 .implied_opt_name
= "order",
320 .head
= QTAILQ_HEAD_INITIALIZER(qemu_boot_opts
.head
),
324 .type
= QEMU_OPT_STRING
,
327 .type
= QEMU_OPT_STRING
,
330 .type
= QEMU_OPT_BOOL
,
333 .type
= QEMU_OPT_STRING
,
335 .name
= "splash-time",
336 .type
= QEMU_OPT_NUMBER
,
338 .name
= "reboot-timeout",
339 .type
= QEMU_OPT_NUMBER
,
342 .type
= QEMU_OPT_BOOL
,
348 static QemuOptsList qemu_add_fd_opts
= {
350 .head
= QTAILQ_HEAD_INITIALIZER(qemu_add_fd_opts
.head
),
354 .type
= QEMU_OPT_NUMBER
,
355 .help
= "file descriptor of which a duplicate is added to fd set",
358 .type
= QEMU_OPT_NUMBER
,
359 .help
= "ID of the fd set to add fd to",
362 .type
= QEMU_OPT_STRING
,
363 .help
= "free-form string used to describe fd",
365 { /* end of list */ }
369 static QemuOptsList qemu_object_opts
= {
371 .implied_opt_name
= "qom-type",
372 .head
= QTAILQ_HEAD_INITIALIZER(qemu_object_opts
.head
),
378 static QemuOptsList qemu_tpmdev_opts
= {
380 .implied_opt_name
= "type",
381 .head
= QTAILQ_HEAD_INITIALIZER(qemu_tpmdev_opts
.head
),
383 /* options are defined in the TPM backends */
384 { /* end of list */ }
388 static QemuOptsList qemu_realtime_opts
= {
390 .head
= QTAILQ_HEAD_INITIALIZER(qemu_realtime_opts
.head
),
394 .type
= QEMU_OPT_BOOL
,
396 { /* end of list */ }
400 static QemuOptsList qemu_overcommit_opts
= {
401 .name
= "overcommit",
402 .head
= QTAILQ_HEAD_INITIALIZER(qemu_overcommit_opts
.head
),
406 .type
= QEMU_OPT_BOOL
,
410 .type
= QEMU_OPT_BOOL
,
412 { /* end of list */ }
416 static QemuOptsList qemu_msg_opts
= {
418 .head
= QTAILQ_HEAD_INITIALIZER(qemu_msg_opts
.head
),
422 .type
= QEMU_OPT_BOOL
,
424 { /* end of list */ }
428 static QemuOptsList qemu_name_opts
= {
430 .implied_opt_name
= "guest",
432 .head
= QTAILQ_HEAD_INITIALIZER(qemu_name_opts
.head
),
436 .type
= QEMU_OPT_STRING
,
437 .help
= "Sets the name of the guest.\n"
438 "This name will be displayed in the SDL window caption.\n"
439 "The name will also be used for the VNC server",
442 .type
= QEMU_OPT_STRING
,
443 .help
= "Sets the name of the QEMU process, as shown in top etc",
445 .name
= "debug-threads",
446 .type
= QEMU_OPT_BOOL
,
447 .help
= "When enabled, name the individual threads; defaults off.\n"
448 "NOTE: The thread names are for debugging and not a\n"
451 { /* End of list */ }
455 static QemuOptsList qemu_mem_opts
= {
457 .implied_opt_name
= "size",
458 .head
= QTAILQ_HEAD_INITIALIZER(qemu_mem_opts
.head
),
463 .type
= QEMU_OPT_SIZE
,
467 .type
= QEMU_OPT_NUMBER
,
471 .type
= QEMU_OPT_SIZE
,
473 { /* end of list */ }
477 static QemuOptsList qemu_icount_opts
= {
479 .implied_opt_name
= "shift",
481 .head
= QTAILQ_HEAD_INITIALIZER(qemu_icount_opts
.head
),
485 .type
= QEMU_OPT_STRING
,
488 .type
= QEMU_OPT_BOOL
,
491 .type
= QEMU_OPT_BOOL
,
494 .type
= QEMU_OPT_STRING
,
497 .type
= QEMU_OPT_STRING
,
499 .name
= "rrsnapshot",
500 .type
= QEMU_OPT_STRING
,
502 { /* end of list */ }
506 static QemuOptsList qemu_fw_cfg_opts
= {
508 .implied_opt_name
= "name",
509 .head
= QTAILQ_HEAD_INITIALIZER(qemu_fw_cfg_opts
.head
),
513 .type
= QEMU_OPT_STRING
,
514 .help
= "Sets the fw_cfg name of the blob to be inserted",
517 .type
= QEMU_OPT_STRING
,
518 .help
= "Sets the name of the file from which "
519 "the fw_cfg blob will be loaded",
522 .type
= QEMU_OPT_STRING
,
523 .help
= "Sets content of the blob to be inserted from a string",
525 { /* end of list */ }
530 * Get machine options
532 * Returns: machine options (never null).
534 QemuOpts
*qemu_get_machine_opts(void)
536 return qemu_find_opts_singleton("machine");
539 const char *qemu_get_vm_name(void)
544 static void res_free(void)
546 g_free(boot_splash_filedata
);
547 boot_splash_filedata
= NULL
;
550 static int default_driver_check(void *opaque
, QemuOpts
*opts
, Error
**errp
)
552 const char *driver
= qemu_opt_get(opts
, "driver");
557 for (i
= 0; i
< ARRAY_SIZE(default_list
); i
++) {
558 if (strcmp(default_list
[i
].driver
, driver
) != 0)
560 *(default_list
[i
].flag
) = 0;
565 /***********************************************************/
568 static RunState current_run_state
= RUN_STATE_PRECONFIG
;
570 /* We use RUN_STATE__MAX but any invalid value will do */
571 static RunState vmstop_requested
= RUN_STATE__MAX
;
572 static QemuMutex vmstop_lock
;
577 } RunStateTransition
;
579 static const RunStateTransition runstate_transitions_def
[] = {
581 { RUN_STATE_PRECONFIG
, RUN_STATE_PRELAUNCH
},
582 /* Early switch to inmigrate state to allow -incoming CLI option work
583 * as it used to. TODO: delay actual switching to inmigrate state to
584 * the point after machine is built and remove this hack.
586 { RUN_STATE_PRECONFIG
, RUN_STATE_INMIGRATE
},
588 { RUN_STATE_DEBUG
, RUN_STATE_RUNNING
},
589 { RUN_STATE_DEBUG
, RUN_STATE_FINISH_MIGRATE
},
590 { RUN_STATE_DEBUG
, RUN_STATE_PRELAUNCH
},
592 { RUN_STATE_INMIGRATE
, RUN_STATE_INTERNAL_ERROR
},
593 { RUN_STATE_INMIGRATE
, RUN_STATE_IO_ERROR
},
594 { RUN_STATE_INMIGRATE
, RUN_STATE_PAUSED
},
595 { RUN_STATE_INMIGRATE
, RUN_STATE_RUNNING
},
596 { RUN_STATE_INMIGRATE
, RUN_STATE_SHUTDOWN
},
597 { RUN_STATE_INMIGRATE
, RUN_STATE_SUSPENDED
},
598 { RUN_STATE_INMIGRATE
, RUN_STATE_WATCHDOG
},
599 { RUN_STATE_INMIGRATE
, RUN_STATE_GUEST_PANICKED
},
600 { RUN_STATE_INMIGRATE
, RUN_STATE_FINISH_MIGRATE
},
601 { RUN_STATE_INMIGRATE
, RUN_STATE_PRELAUNCH
},
602 { RUN_STATE_INMIGRATE
, RUN_STATE_POSTMIGRATE
},
603 { RUN_STATE_INMIGRATE
, RUN_STATE_COLO
},
605 { RUN_STATE_INTERNAL_ERROR
, RUN_STATE_PAUSED
},
606 { RUN_STATE_INTERNAL_ERROR
, RUN_STATE_FINISH_MIGRATE
},
607 { RUN_STATE_INTERNAL_ERROR
, RUN_STATE_PRELAUNCH
},
609 { RUN_STATE_IO_ERROR
, RUN_STATE_RUNNING
},
610 { RUN_STATE_IO_ERROR
, RUN_STATE_FINISH_MIGRATE
},
611 { RUN_STATE_IO_ERROR
, RUN_STATE_PRELAUNCH
},
613 { RUN_STATE_PAUSED
, RUN_STATE_RUNNING
},
614 { RUN_STATE_PAUSED
, RUN_STATE_FINISH_MIGRATE
},
615 { RUN_STATE_PAUSED
, RUN_STATE_POSTMIGRATE
},
616 { RUN_STATE_PAUSED
, RUN_STATE_PRELAUNCH
},
617 { RUN_STATE_PAUSED
, RUN_STATE_COLO
},
619 { RUN_STATE_POSTMIGRATE
, RUN_STATE_RUNNING
},
620 { RUN_STATE_POSTMIGRATE
, RUN_STATE_FINISH_MIGRATE
},
621 { RUN_STATE_POSTMIGRATE
, RUN_STATE_PRELAUNCH
},
623 { RUN_STATE_PRELAUNCH
, RUN_STATE_RUNNING
},
624 { RUN_STATE_PRELAUNCH
, RUN_STATE_FINISH_MIGRATE
},
625 { RUN_STATE_PRELAUNCH
, RUN_STATE_INMIGRATE
},
627 { RUN_STATE_FINISH_MIGRATE
, RUN_STATE_RUNNING
},
628 { RUN_STATE_FINISH_MIGRATE
, RUN_STATE_PAUSED
},
629 { RUN_STATE_FINISH_MIGRATE
, RUN_STATE_POSTMIGRATE
},
630 { RUN_STATE_FINISH_MIGRATE
, RUN_STATE_PRELAUNCH
},
631 { RUN_STATE_FINISH_MIGRATE
, RUN_STATE_COLO
},
633 { RUN_STATE_RESTORE_VM
, RUN_STATE_RUNNING
},
634 { RUN_STATE_RESTORE_VM
, RUN_STATE_PRELAUNCH
},
636 { RUN_STATE_COLO
, RUN_STATE_RUNNING
},
638 { RUN_STATE_RUNNING
, RUN_STATE_DEBUG
},
639 { RUN_STATE_RUNNING
, RUN_STATE_INTERNAL_ERROR
},
640 { RUN_STATE_RUNNING
, RUN_STATE_IO_ERROR
},
641 { RUN_STATE_RUNNING
, RUN_STATE_PAUSED
},
642 { RUN_STATE_RUNNING
, RUN_STATE_FINISH_MIGRATE
},
643 { RUN_STATE_RUNNING
, RUN_STATE_RESTORE_VM
},
644 { RUN_STATE_RUNNING
, RUN_STATE_SAVE_VM
},
645 { RUN_STATE_RUNNING
, RUN_STATE_SHUTDOWN
},
646 { RUN_STATE_RUNNING
, RUN_STATE_WATCHDOG
},
647 { RUN_STATE_RUNNING
, RUN_STATE_GUEST_PANICKED
},
648 { RUN_STATE_RUNNING
, RUN_STATE_COLO
},
650 { RUN_STATE_SAVE_VM
, RUN_STATE_RUNNING
},
652 { RUN_STATE_SHUTDOWN
, RUN_STATE_PAUSED
},
653 { RUN_STATE_SHUTDOWN
, RUN_STATE_FINISH_MIGRATE
},
654 { RUN_STATE_SHUTDOWN
, RUN_STATE_PRELAUNCH
},
656 { RUN_STATE_DEBUG
, RUN_STATE_SUSPENDED
},
657 { RUN_STATE_RUNNING
, RUN_STATE_SUSPENDED
},
658 { RUN_STATE_SUSPENDED
, RUN_STATE_RUNNING
},
659 { RUN_STATE_SUSPENDED
, RUN_STATE_FINISH_MIGRATE
},
660 { RUN_STATE_SUSPENDED
, RUN_STATE_PRELAUNCH
},
661 { RUN_STATE_SUSPENDED
, RUN_STATE_COLO
},
663 { RUN_STATE_WATCHDOG
, RUN_STATE_RUNNING
},
664 { RUN_STATE_WATCHDOG
, RUN_STATE_FINISH_MIGRATE
},
665 { RUN_STATE_WATCHDOG
, RUN_STATE_PRELAUNCH
},
666 { RUN_STATE_WATCHDOG
, RUN_STATE_COLO
},
668 { RUN_STATE_GUEST_PANICKED
, RUN_STATE_RUNNING
},
669 { RUN_STATE_GUEST_PANICKED
, RUN_STATE_FINISH_MIGRATE
},
670 { RUN_STATE_GUEST_PANICKED
, RUN_STATE_PRELAUNCH
},
672 { RUN_STATE__MAX
, RUN_STATE__MAX
},
675 static bool runstate_valid_transitions
[RUN_STATE__MAX
][RUN_STATE__MAX
];
677 bool runstate_check(RunState state
)
679 return current_run_state
== state
;
682 bool runstate_store(char *str
, size_t size
)
684 const char *state
= RunState_str(current_run_state
);
685 size_t len
= strlen(state
) + 1;
690 memcpy(str
, state
, len
);
694 static void runstate_init(void)
696 const RunStateTransition
*p
;
698 memset(&runstate_valid_transitions
, 0, sizeof(runstate_valid_transitions
));
699 for (p
= &runstate_transitions_def
[0]; p
->from
!= RUN_STATE__MAX
; p
++) {
700 runstate_valid_transitions
[p
->from
][p
->to
] = true;
703 qemu_mutex_init(&vmstop_lock
);
706 /* This function will abort() on invalid state transitions */
707 void runstate_set(RunState new_state
)
709 assert(new_state
< RUN_STATE__MAX
);
711 trace_runstate_set(current_run_state
, RunState_str(current_run_state
),
712 new_state
, RunState_str(new_state
));
714 if (current_run_state
== new_state
) {
718 if (!runstate_valid_transitions
[current_run_state
][new_state
]) {
719 error_report("invalid runstate transition: '%s' -> '%s'",
720 RunState_str(current_run_state
),
721 RunState_str(new_state
));
725 current_run_state
= new_state
;
728 int runstate_is_running(void)
730 return runstate_check(RUN_STATE_RUNNING
);
733 bool runstate_needs_reset(void)
735 return runstate_check(RUN_STATE_INTERNAL_ERROR
) ||
736 runstate_check(RUN_STATE_SHUTDOWN
);
739 StatusInfo
*qmp_query_status(Error
**errp
)
741 StatusInfo
*info
= g_malloc0(sizeof(*info
));
743 info
->running
= runstate_is_running();
744 info
->singlestep
= singlestep
;
745 info
->status
= current_run_state
;
750 bool qemu_vmstop_requested(RunState
*r
)
752 qemu_mutex_lock(&vmstop_lock
);
753 *r
= vmstop_requested
;
754 vmstop_requested
= RUN_STATE__MAX
;
755 qemu_mutex_unlock(&vmstop_lock
);
756 return *r
< RUN_STATE__MAX
;
759 void qemu_system_vmstop_request_prepare(void)
761 qemu_mutex_lock(&vmstop_lock
);
764 void qemu_system_vmstop_request(RunState state
)
766 vmstop_requested
= state
;
767 qemu_mutex_unlock(&vmstop_lock
);
771 /***********************************************************/
772 /* RTC reference time/date access */
773 static time_t qemu_ref_timedate(QEMUClockType clock
)
775 time_t value
= qemu_clock_get_ms(clock
) / 1000;
777 case QEMU_CLOCK_REALTIME
:
778 value
-= rtc_realtime_clock_offset
;
780 case QEMU_CLOCK_VIRTUAL
:
781 value
+= rtc_ref_start_datetime
;
783 case QEMU_CLOCK_HOST
:
784 if (rtc_base_type
== RTC_BASE_DATETIME
) {
785 value
-= rtc_host_datetime_offset
;
794 void qemu_get_timedate(struct tm
*tm
, int offset
)
796 time_t ti
= qemu_ref_timedate(rtc_clock
);
800 switch (rtc_base_type
) {
801 case RTC_BASE_DATETIME
:
805 case RTC_BASE_LOCALTIME
:
806 localtime_r(&ti
, tm
);
811 int qemu_timedate_diff(struct tm
*tm
)
815 switch (rtc_base_type
) {
816 case RTC_BASE_DATETIME
:
818 seconds
= mktimegm(tm
);
820 case RTC_BASE_LOCALTIME
:
823 tmp
.tm_isdst
= -1; /* use timezone to figure it out */
824 seconds
= mktime(&tmp
);
831 return seconds
- qemu_ref_timedate(QEMU_CLOCK_HOST
);
834 static void configure_rtc_base_datetime(const char *startdate
)
836 time_t rtc_start_datetime
;
839 if (sscanf(startdate
, "%d-%d-%dT%d:%d:%d", &tm
.tm_year
, &tm
.tm_mon
,
840 &tm
.tm_mday
, &tm
.tm_hour
, &tm
.tm_min
, &tm
.tm_sec
) == 6) {
842 } else if (sscanf(startdate
, "%d-%d-%d",
843 &tm
.tm_year
, &tm
.tm_mon
, &tm
.tm_mday
) == 3) {
852 rtc_start_datetime
= mktimegm(&tm
);
853 if (rtc_start_datetime
== -1) {
855 error_report("invalid datetime format");
856 error_printf("valid formats: "
857 "'2006-06-17T16:01:21' or '2006-06-17'\n");
860 rtc_host_datetime_offset
= rtc_ref_start_datetime
- rtc_start_datetime
;
861 rtc_ref_start_datetime
= rtc_start_datetime
;
864 static void configure_rtc(QemuOpts
*opts
)
869 rtc_clock
= QEMU_CLOCK_HOST
;
870 rtc_ref_start_datetime
= qemu_clock_get_ms(QEMU_CLOCK_HOST
) / 1000;
871 rtc_realtime_clock_offset
= qemu_clock_get_ms(QEMU_CLOCK_REALTIME
) / 1000;
873 value
= qemu_opt_get(opts
, "base");
875 if (!strcmp(value
, "utc")) {
876 rtc_base_type
= RTC_BASE_UTC
;
877 } else if (!strcmp(value
, "localtime")) {
878 Error
*blocker
= NULL
;
879 rtc_base_type
= RTC_BASE_LOCALTIME
;
880 error_setg(&blocker
, QERR_REPLAY_NOT_SUPPORTED
,
881 "-rtc base=localtime");
882 replay_add_blocker(blocker
);
884 rtc_base_type
= RTC_BASE_DATETIME
;
885 configure_rtc_base_datetime(value
);
888 value
= qemu_opt_get(opts
, "clock");
890 if (!strcmp(value
, "host")) {
891 rtc_clock
= QEMU_CLOCK_HOST
;
892 } else if (!strcmp(value
, "rt")) {
893 rtc_clock
= QEMU_CLOCK_REALTIME
;
894 } else if (!strcmp(value
, "vm")) {
895 rtc_clock
= QEMU_CLOCK_VIRTUAL
;
897 error_report("invalid option value '%s'", value
);
901 value
= qemu_opt_get(opts
, "driftfix");
903 if (!strcmp(value
, "slew")) {
904 static GlobalProperty slew_lost_ticks
= {
905 .driver
= "mc146818rtc",
906 .property
= "lost_tick_policy",
910 qdev_prop_register_global(&slew_lost_ticks
);
911 } else if (!strcmp(value
, "none")) {
912 /* discard is default */
914 error_report("invalid option value '%s'", value
);
920 /***********************************************************/
921 /* Bluetooth support */
924 static struct HCIInfo
*hci_table
[MAX_NICS
];
926 struct HCIInfo
*qemu_next_hci(void)
928 if (cur_hci
== nb_hcis
)
931 return hci_table
[cur_hci
++];
934 static int bt_hci_parse(const char *str
)
939 if (nb_hcis
>= MAX_NICS
) {
940 error_report("too many bluetooth HCIs (max %i)", MAX_NICS
);
953 bdaddr
.b
[5] = 0x56 + nb_hcis
;
954 hci
->bdaddr_set(hci
, bdaddr
.b
);
956 hci_table
[nb_hcis
++] = hci
;
961 static void bt_vhci_add(int vlan_id
)
963 struct bt_scatternet_s
*vlan
= qemu_find_bt_vlan(vlan_id
);
966 warn_report("adding a VHCI to an empty scatternet %i",
969 bt_vhci_init(bt_new_hci(vlan
));
972 static struct bt_device_s
*bt_device_add(const char *opt
)
974 struct bt_scatternet_s
*vlan
;
976 char *endp
= strstr(opt
, ",vlan=");
977 int len
= (endp
? endp
- opt
: strlen(opt
)) + 1;
980 pstrcpy(devname
, MIN(sizeof(devname
), len
), opt
);
983 vlan_id
= strtol(endp
+ 6, &endp
, 0);
985 error_report("unrecognised bluetooth vlan Id");
990 vlan
= qemu_find_bt_vlan(vlan_id
);
993 warn_report("adding a slave device to an empty scatternet %i",
996 if (!strcmp(devname
, "keyboard"))
997 return bt_keyboard_init(vlan
);
999 error_report("unsupported bluetooth device '%s'", devname
);
1003 static int bt_parse(const char *opt
)
1005 const char *endp
, *p
;
1008 if (strstart(opt
, "hci", &endp
)) {
1009 if (!*endp
|| *endp
== ',') {
1011 if (!strstart(endp
, ",vlan=", 0))
1014 return bt_hci_parse(opt
);
1016 } else if (strstart(opt
, "vhci", &endp
)) {
1017 if (!*endp
|| *endp
== ',') {
1019 if (strstart(endp
, ",vlan=", &p
)) {
1020 vlan
= strtol(p
, (char **) &endp
, 0);
1022 error_report("bad scatternet '%s'", p
);
1026 error_report("bad parameter '%s'", endp
+ 1);
1035 } else if (strstart(opt
, "device:", &endp
))
1036 return !bt_device_add(endp
);
1038 error_report("bad bluetooth parameter '%s'", opt
);
1042 static int parse_name(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1044 const char *proc_name
;
1046 if (qemu_opt_get(opts
, "debug-threads")) {
1047 qemu_thread_naming(qemu_opt_get_bool(opts
, "debug-threads", false));
1049 qemu_name
= qemu_opt_get(opts
, "guest");
1051 proc_name
= qemu_opt_get(opts
, "process");
1053 os_set_proc_name(proc_name
);
1059 bool defaults_enabled(void)
1061 return has_defaults
;
1065 static int parse_add_fd(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1067 int fd
, dupfd
, flags
;
1069 const char *fd_opaque
= NULL
;
1072 fd
= qemu_opt_get_number(opts
, "fd", -1);
1073 fdset_id
= qemu_opt_get_number(opts
, "set", -1);
1074 fd_opaque
= qemu_opt_get(opts
, "opaque");
1077 error_setg(errp
, "fd option is required and must be non-negative");
1081 if (fd
<= STDERR_FILENO
) {
1082 error_setg(errp
, "fd cannot be a standard I/O stream");
1087 * All fds inherited across exec() necessarily have FD_CLOEXEC
1088 * clear, while qemu sets FD_CLOEXEC on all other fds used internally.
1090 flags
= fcntl(fd
, F_GETFD
);
1091 if (flags
== -1 || (flags
& FD_CLOEXEC
)) {
1092 error_setg(errp
, "fd is not valid or already in use");
1097 error_setg(errp
, "set option is required and must be non-negative");
1101 #ifdef F_DUPFD_CLOEXEC
1102 dupfd
= fcntl(fd
, F_DUPFD_CLOEXEC
, 0);
1106 qemu_set_cloexec(dupfd
);
1110 error_setg(errp
, "error duplicating fd: %s", strerror(errno
));
1114 /* add the duplicate fd, and optionally the opaque string, to the fd set */
1115 fdinfo
= monitor_fdset_add_fd(dupfd
, true, fdset_id
, !!fd_opaque
, fd_opaque
,
1122 static int cleanup_add_fd(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1126 fd
= qemu_opt_get_number(opts
, "fd", -1);
1133 /***********************************************************/
1134 /* QEMU Block devices */
1136 #define HD_OPTS "media=disk"
1137 #define CDROM_OPTS "media=cdrom"
1139 #define PFLASH_OPTS ""
1143 static int drive_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1145 BlockInterfaceType
*block_default_type
= opaque
;
1147 return drive_new(opts
, *block_default_type
, errp
) == NULL
;
1150 static int drive_enable_snapshot(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1152 if (qemu_opt_get(opts
, "snapshot") == NULL
) {
1153 qemu_opt_set(opts
, "snapshot", "on", &error_abort
);
1158 static void default_drive(int enable
, int snapshot
, BlockInterfaceType type
,
1159 int index
, const char *optstr
)
1164 if (!enable
|| drive_get_by_index(type
, index
)) {
1168 opts
= drive_add(type
, index
, NULL
, optstr
);
1170 drive_enable_snapshot(NULL
, opts
, NULL
);
1173 dinfo
= drive_new(opts
, type
, &error_abort
);
1174 dinfo
->is_default
= true;
1178 typedef struct BlockdevOptionsQueueEntry
{
1179 BlockdevOptions
*bdo
;
1181 QSIMPLEQ_ENTRY(BlockdevOptionsQueueEntry
) entry
;
1182 } BlockdevOptionsQueueEntry
;
1184 typedef QSIMPLEQ_HEAD(, BlockdevOptionsQueueEntry
) BlockdevOptionsQueue
;
1186 static void configure_blockdev(BlockdevOptionsQueue
*bdo_queue
,
1187 MachineClass
*machine_class
, int snapshot
)
1190 * If the currently selected machine wishes to override the
1191 * units-per-bus property of its default HBA interface type, do so
1194 if (machine_class
->units_per_default_bus
) {
1195 override_max_devs(machine_class
->block_default_type
,
1196 machine_class
->units_per_default_bus
);
1199 /* open the virtual block devices */
1200 while (!QSIMPLEQ_EMPTY(bdo_queue
)) {
1201 BlockdevOptionsQueueEntry
*bdo
= QSIMPLEQ_FIRST(bdo_queue
);
1203 QSIMPLEQ_REMOVE_HEAD(bdo_queue
, entry
);
1204 loc_push_restore(&bdo
->loc
);
1205 qmp_blockdev_add(bdo
->bdo
, &error_fatal
);
1207 qapi_free_BlockdevOptions(bdo
->bdo
);
1210 if (snapshot
|| replay_mode
!= REPLAY_MODE_NONE
) {
1211 qemu_opts_foreach(qemu_find_opts("drive"), drive_enable_snapshot
,
1214 if (qemu_opts_foreach(qemu_find_opts("drive"), drive_init_func
,
1215 &machine_class
->block_default_type
, &error_fatal
)) {
1216 /* We printed help */
1220 default_drive(default_cdrom
, snapshot
, machine_class
->block_default_type
, 2,
1222 default_drive(default_floppy
, snapshot
, IF_FLOPPY
, 0, FD_OPTS
);
1223 default_drive(default_sdcard
, snapshot
, IF_SD
, 0, SD_OPTS
);
1227 static QemuOptsList qemu_smp_opts
= {
1229 .implied_opt_name
= "cpus",
1230 .merge_lists
= true,
1231 .head
= QTAILQ_HEAD_INITIALIZER(qemu_smp_opts
.head
),
1235 .type
= QEMU_OPT_NUMBER
,
1238 .type
= QEMU_OPT_NUMBER
,
1241 .type
= QEMU_OPT_NUMBER
,
1244 .type
= QEMU_OPT_NUMBER
,
1247 .type
= QEMU_OPT_NUMBER
,
1249 { /*End of list */ }
1253 static void smp_parse(QemuOpts
*opts
)
1256 unsigned cpus
= qemu_opt_get_number(opts
, "cpus", 0);
1257 unsigned sockets
= qemu_opt_get_number(opts
, "sockets", 0);
1258 unsigned cores
= qemu_opt_get_number(opts
, "cores", 0);
1259 unsigned threads
= qemu_opt_get_number(opts
, "threads", 0);
1261 /* compute missing values, prefer sockets over cores over threads */
1262 if (cpus
== 0 || sockets
== 0) {
1263 cores
= cores
> 0 ? cores
: 1;
1264 threads
= threads
> 0 ? threads
: 1;
1266 sockets
= sockets
> 0 ? sockets
: 1;
1267 cpus
= cores
* threads
* sockets
;
1269 max_cpus
= qemu_opt_get_number(opts
, "maxcpus", cpus
);
1270 sockets
= max_cpus
/ (cores
* threads
);
1272 } else if (cores
== 0) {
1273 threads
= threads
> 0 ? threads
: 1;
1274 cores
= cpus
/ (sockets
* threads
);
1275 cores
= cores
> 0 ? cores
: 1;
1276 } else if (threads
== 0) {
1277 threads
= cpus
/ (cores
* sockets
);
1278 threads
= threads
> 0 ? threads
: 1;
1279 } else if (sockets
* cores
* threads
< cpus
) {
1280 error_report("cpu topology: "
1281 "sockets (%u) * cores (%u) * threads (%u) < "
1283 sockets
, cores
, threads
, cpus
);
1287 max_cpus
= qemu_opt_get_number(opts
, "maxcpus", cpus
);
1289 if (max_cpus
< cpus
) {
1290 error_report("maxcpus must be equal to or greater than smp");
1294 if (sockets
* cores
* threads
> max_cpus
) {
1295 error_report("cpu topology: "
1296 "sockets (%u) * cores (%u) * threads (%u) > "
1298 sockets
, cores
, threads
, max_cpus
);
1302 if (sockets
* cores
* threads
!= max_cpus
) {
1303 warn_report("Invalid CPU topology deprecated: "
1304 "sockets (%u) * cores (%u) * threads (%u) "
1306 sockets
, cores
, threads
, max_cpus
);
1311 smp_threads
= threads
;
1315 Error
*blocker
= NULL
;
1316 error_setg(&blocker
, QERR_REPLAY_NOT_SUPPORTED
, "smp");
1317 replay_add_blocker(blocker
);
1321 static void realtime_init(void)
1324 if (os_mlock() < 0) {
1325 error_report("locking memory failed");
1332 static void configure_msg(QemuOpts
*opts
)
1334 enable_timestamp_msg
= qemu_opt_get_bool(opts
, "timestamp", true);
1338 /* Now we still need this for compatibility with XEN. */
1339 bool has_igd_gfx_passthru
;
1340 static void igd_gfx_passthru(void)
1342 has_igd_gfx_passthru
= current_machine
->igd_gfx_passthru
;
1345 /***********************************************************/
1348 static int usb_device_add(const char *devname
)
1350 USBDevice
*dev
= NULL
;
1352 if (!machine_usb(current_machine
)) {
1356 dev
= usbdevice_create(devname
);
1363 static int usb_parse(const char *cmdline
)
1366 r
= usb_device_add(cmdline
);
1368 error_report("could not add USB device '%s'", cmdline
);
1373 /***********************************************************/
1374 /* machine registration */
1376 MachineState
*current_machine
;
1378 static MachineClass
*find_machine(const char *name
, GSList
*machines
)
1382 for (el
= machines
; el
; el
= el
->next
) {
1383 MachineClass
*mc
= el
->data
;
1385 if (!strcmp(mc
->name
, name
) || !g_strcmp0(mc
->alias
, name
)) {
1393 static MachineClass
*find_default_machine(GSList
*machines
)
1397 for (el
= machines
; el
; el
= el
->next
) {
1398 MachineClass
*mc
= el
->data
;
1400 if (mc
->is_default
) {
1408 MachineInfoList
*qmp_query_machines(Error
**errp
)
1410 GSList
*el
, *machines
= object_class_get_list(TYPE_MACHINE
, false);
1411 MachineInfoList
*mach_list
= NULL
;
1413 for (el
= machines
; el
; el
= el
->next
) {
1414 MachineClass
*mc
= el
->data
;
1415 MachineInfoList
*entry
;
1418 info
= g_malloc0(sizeof(*info
));
1419 if (mc
->is_default
) {
1420 info
->has_is_default
= true;
1421 info
->is_default
= true;
1425 info
->has_alias
= true;
1426 info
->alias
= g_strdup(mc
->alias
);
1429 info
->name
= g_strdup(mc
->name
);
1430 info
->cpu_max
= !mc
->max_cpus
? 1 : mc
->max_cpus
;
1431 info
->hotpluggable_cpus
= mc
->has_hotpluggable_cpus
;
1433 entry
= g_malloc0(sizeof(*entry
));
1434 entry
->value
= info
;
1435 entry
->next
= mach_list
;
1439 g_slist_free(machines
);
1443 static int machine_help_func(QemuOpts
*opts
, MachineState
*machine
)
1445 ObjectProperty
*prop
;
1446 ObjectPropertyIterator iter
;
1448 if (!qemu_opt_has_help_opt(opts
)) {
1452 object_property_iter_init(&iter
, OBJECT(machine
));
1453 while ((prop
= object_property_iter_next(&iter
))) {
1458 printf("%s.%s=%s", MACHINE_GET_CLASS(machine
)->name
,
1459 prop
->name
, prop
->type
);
1460 if (prop
->description
) {
1461 printf(" (%s)\n", prop
->description
);
1470 struct vm_change_state_entry
{
1471 VMChangeStateHandler
*cb
;
1473 QLIST_ENTRY (vm_change_state_entry
) entries
;
1476 static QLIST_HEAD(, vm_change_state_entry
) vm_change_state_head
;
1478 VMChangeStateEntry
*qemu_add_vm_change_state_handler(VMChangeStateHandler
*cb
,
1481 VMChangeStateEntry
*e
;
1483 e
= g_malloc0(sizeof (*e
));
1487 QLIST_INSERT_HEAD(&vm_change_state_head
, e
, entries
);
1491 void qemu_del_vm_change_state_handler(VMChangeStateEntry
*e
)
1493 QLIST_REMOVE (e
, entries
);
1497 void vm_state_notify(int running
, RunState state
)
1499 VMChangeStateEntry
*e
, *next
;
1501 trace_vm_state_notify(running
, state
, RunState_str(state
));
1503 QLIST_FOREACH_SAFE(e
, &vm_change_state_head
, entries
, next
) {
1504 e
->cb(e
->opaque
, running
, state
);
1508 static ShutdownCause reset_requested
;
1509 static ShutdownCause shutdown_requested
;
1510 static int shutdown_signal
;
1511 static pid_t shutdown_pid
;
1512 static int powerdown_requested
;
1513 static int debug_requested
;
1514 static int suspend_requested
;
1515 static bool preconfig_exit_requested
= true;
1516 static WakeupReason wakeup_reason
;
1517 static NotifierList powerdown_notifiers
=
1518 NOTIFIER_LIST_INITIALIZER(powerdown_notifiers
);
1519 static NotifierList suspend_notifiers
=
1520 NOTIFIER_LIST_INITIALIZER(suspend_notifiers
);
1521 static NotifierList wakeup_notifiers
=
1522 NOTIFIER_LIST_INITIALIZER(wakeup_notifiers
);
1523 static NotifierList shutdown_notifiers
=
1524 NOTIFIER_LIST_INITIALIZER(shutdown_notifiers
);
1525 static uint32_t wakeup_reason_mask
= ~(1 << QEMU_WAKEUP_REASON_NONE
);
1527 ShutdownCause
qemu_shutdown_requested_get(void)
1529 return shutdown_requested
;
1532 ShutdownCause
qemu_reset_requested_get(void)
1534 return reset_requested
;
1537 static int qemu_shutdown_requested(void)
1539 return atomic_xchg(&shutdown_requested
, SHUTDOWN_CAUSE_NONE
);
1542 static void qemu_kill_report(void)
1544 if (!qtest_driver() && shutdown_signal
) {
1545 if (shutdown_pid
== 0) {
1546 /* This happens for eg ^C at the terminal, so it's worth
1547 * avoiding printing an odd message in that case.
1549 error_report("terminating on signal %d", shutdown_signal
);
1551 char *shutdown_cmd
= qemu_get_pid_name(shutdown_pid
);
1553 error_report("terminating on signal %d from pid " FMT_pid
" (%s)",
1554 shutdown_signal
, shutdown_pid
,
1555 shutdown_cmd
? shutdown_cmd
: "<unknown process>");
1556 g_free(shutdown_cmd
);
1558 shutdown_signal
= 0;
1562 static ShutdownCause
qemu_reset_requested(void)
1564 ShutdownCause r
= reset_requested
;
1566 if (r
&& replay_checkpoint(CHECKPOINT_RESET_REQUESTED
)) {
1567 reset_requested
= SHUTDOWN_CAUSE_NONE
;
1570 return SHUTDOWN_CAUSE_NONE
;
1573 static int qemu_suspend_requested(void)
1575 int r
= suspend_requested
;
1576 if (r
&& replay_checkpoint(CHECKPOINT_SUSPEND_REQUESTED
)) {
1577 suspend_requested
= 0;
1583 static WakeupReason
qemu_wakeup_requested(void)
1585 return wakeup_reason
;
1588 static int qemu_powerdown_requested(void)
1590 int r
= powerdown_requested
;
1591 powerdown_requested
= 0;
1595 static int qemu_debug_requested(void)
1597 int r
= debug_requested
;
1598 debug_requested
= 0;
1602 void qemu_exit_preconfig_request(void)
1604 preconfig_exit_requested
= true;
1608 * Reset the VM. Issue an event unless @reason is SHUTDOWN_CAUSE_NONE.
1610 void qemu_system_reset(ShutdownCause reason
)
1614 mc
= current_machine
? MACHINE_GET_CLASS(current_machine
) : NULL
;
1616 cpu_synchronize_all_states();
1618 if (mc
&& mc
->reset
) {
1621 qemu_devices_reset();
1623 if (reason
!= SHUTDOWN_CAUSE_SUBSYSTEM_RESET
) {
1624 qapi_event_send_reset(shutdown_caused_by_guest(reason
), reason
);
1626 cpu_synchronize_all_post_reset();
1629 void qemu_system_guest_panicked(GuestPanicInformation
*info
)
1631 qemu_log_mask(LOG_GUEST_ERROR
, "Guest crashed");
1634 current_cpu
->crash_occurred
= true;
1636 qapi_event_send_guest_panicked(GUEST_PANIC_ACTION_PAUSE
,
1638 vm_stop(RUN_STATE_GUEST_PANICKED
);
1640 qapi_event_send_guest_panicked(GUEST_PANIC_ACTION_POWEROFF
,
1642 qemu_system_shutdown_request(SHUTDOWN_CAUSE_GUEST_PANIC
);
1646 if (info
->type
== GUEST_PANIC_INFORMATION_TYPE_HYPER_V
) {
1647 qemu_log_mask(LOG_GUEST_ERROR
, "\nHV crash parameters: (%#"PRIx64
1648 " %#"PRIx64
" %#"PRIx64
" %#"PRIx64
" %#"PRIx64
")\n",
1649 info
->u
.hyper_v
.arg1
,
1650 info
->u
.hyper_v
.arg2
,
1651 info
->u
.hyper_v
.arg3
,
1652 info
->u
.hyper_v
.arg4
,
1653 info
->u
.hyper_v
.arg5
);
1654 } else if (info
->type
== GUEST_PANIC_INFORMATION_TYPE_S390
) {
1655 qemu_log_mask(LOG_GUEST_ERROR
, " on cpu %d: %s\n"
1656 "PSW: 0x%016" PRIx64
" 0x%016" PRIx64
"\n",
1658 S390CrashReason_str(info
->u
.s390
.reason
),
1659 info
->u
.s390
.psw_mask
,
1660 info
->u
.s390
.psw_addr
);
1662 qapi_free_GuestPanicInformation(info
);
1666 void qemu_system_reset_request(ShutdownCause reason
)
1668 if (no_reboot
&& reason
!= SHUTDOWN_CAUSE_SUBSYSTEM_RESET
) {
1669 shutdown_requested
= reason
;
1671 reset_requested
= reason
;
1674 qemu_notify_event();
1677 static void qemu_system_suspend(void)
1680 notifier_list_notify(&suspend_notifiers
, NULL
);
1681 runstate_set(RUN_STATE_SUSPENDED
);
1682 qapi_event_send_suspend();
1685 void qemu_system_suspend_request(void)
1687 if (runstate_check(RUN_STATE_SUSPENDED
)) {
1690 suspend_requested
= 1;
1692 qemu_notify_event();
1695 void qemu_register_suspend_notifier(Notifier
*notifier
)
1697 notifier_list_add(&suspend_notifiers
, notifier
);
1700 void qemu_system_wakeup_request(WakeupReason reason
, Error
**errp
)
1702 trace_system_wakeup_request(reason
);
1704 if (!runstate_check(RUN_STATE_SUSPENDED
)) {
1706 "Unable to wake up: guest is not in suspended state");
1709 if (!(wakeup_reason_mask
& (1 << reason
))) {
1712 runstate_set(RUN_STATE_RUNNING
);
1713 wakeup_reason
= reason
;
1714 qemu_notify_event();
1717 void qemu_system_wakeup_enable(WakeupReason reason
, bool enabled
)
1720 wakeup_reason_mask
|= (1 << reason
);
1722 wakeup_reason_mask
&= ~(1 << reason
);
1726 void qemu_register_wakeup_notifier(Notifier
*notifier
)
1728 notifier_list_add(&wakeup_notifiers
, notifier
);
1731 void qemu_register_wakeup_support(void)
1733 wakeup_suspend_enabled
= true;
1736 bool qemu_wakeup_suspend_enabled(void)
1738 return wakeup_suspend_enabled
;
1741 CurrentMachineParams
*qmp_query_current_machine(Error
**errp
)
1743 CurrentMachineParams
*params
= g_malloc0(sizeof(*params
));
1744 params
->wakeup_suspend_support
= qemu_wakeup_suspend_enabled();
1749 void qemu_system_killed(int signal
, pid_t pid
)
1751 shutdown_signal
= signal
;
1755 /* Cannot call qemu_system_shutdown_request directly because
1756 * we are in a signal handler.
1758 shutdown_requested
= SHUTDOWN_CAUSE_HOST_SIGNAL
;
1759 qemu_notify_event();
1762 void qemu_system_shutdown_request(ShutdownCause reason
)
1764 trace_qemu_system_shutdown_request(reason
);
1765 replay_shutdown_request(reason
);
1766 shutdown_requested
= reason
;
1767 qemu_notify_event();
1770 static void qemu_system_powerdown(void)
1772 qapi_event_send_powerdown();
1773 notifier_list_notify(&powerdown_notifiers
, NULL
);
1776 static void qemu_system_shutdown(ShutdownCause cause
)
1778 qapi_event_send_shutdown(shutdown_caused_by_guest(cause
), cause
);
1779 notifier_list_notify(&shutdown_notifiers
, &cause
);
1782 void qemu_system_powerdown_request(void)
1784 trace_qemu_system_powerdown_request();
1785 powerdown_requested
= 1;
1786 qemu_notify_event();
1789 void qemu_register_powerdown_notifier(Notifier
*notifier
)
1791 notifier_list_add(&powerdown_notifiers
, notifier
);
1794 void qemu_register_shutdown_notifier(Notifier
*notifier
)
1796 notifier_list_add(&shutdown_notifiers
, notifier
);
1799 void qemu_system_debug_request(void)
1801 debug_requested
= 1;
1802 qemu_notify_event();
1805 static bool main_loop_should_exit(void)
1808 ShutdownCause request
;
1810 if (preconfig_exit_requested
) {
1811 if (runstate_check(RUN_STATE_PRECONFIG
)) {
1812 runstate_set(RUN_STATE_PRELAUNCH
);
1814 preconfig_exit_requested
= false;
1817 if (qemu_debug_requested()) {
1818 vm_stop(RUN_STATE_DEBUG
);
1820 if (qemu_suspend_requested()) {
1821 qemu_system_suspend();
1823 request
= qemu_shutdown_requested();
1826 qemu_system_shutdown(request
);
1828 vm_stop(RUN_STATE_SHUTDOWN
);
1833 request
= qemu_reset_requested();
1836 qemu_system_reset(request
);
1838 if (!runstate_check(RUN_STATE_RUNNING
) &&
1839 !runstate_check(RUN_STATE_INMIGRATE
)) {
1840 runstate_set(RUN_STATE_PRELAUNCH
);
1843 if (qemu_wakeup_requested()) {
1845 qemu_system_reset(SHUTDOWN_CAUSE_NONE
);
1846 notifier_list_notify(&wakeup_notifiers
, &wakeup_reason
);
1847 wakeup_reason
= QEMU_WAKEUP_REASON_NONE
;
1849 qapi_event_send_wakeup();
1851 if (qemu_powerdown_requested()) {
1852 qemu_system_powerdown();
1854 if (qemu_vmstop_requested(&r
)) {
1860 static void main_loop(void)
1862 #ifdef CONFIG_PROFILER
1865 while (!main_loop_should_exit()) {
1866 #ifdef CONFIG_PROFILER
1867 ti
= profile_getclock();
1869 main_loop_wait(false);
1870 #ifdef CONFIG_PROFILER
1871 dev_time
+= profile_getclock() - ti
;
1876 static void version(void)
1878 printf("QEMU emulator version " QEMU_FULL_VERSION
"\n"
1879 QEMU_COPYRIGHT
"\n");
1882 static void help(int exitcode
)
1885 printf("usage: %s [options] [disk_image]\n\n"
1886 "'disk_image' is a raw hard disk image for IDE hard disk 0\n\n",
1887 error_get_progname());
1889 #define QEMU_OPTIONS_GENERATE_HELP
1890 #include "qemu-options-wrapper.h"
1892 printf("\nDuring emulation, the following keys are useful:\n"
1893 "ctrl-alt-f toggle full screen\n"
1894 "ctrl-alt-n switch to virtual console 'n'\n"
1895 "ctrl-alt toggle mouse and keyboard grab\n"
1897 "When using -nographic, press 'ctrl-a h' to get some help.\n"
1899 QEMU_HELP_BOTTOM
"\n");
1904 #define HAS_ARG 0x0001
1906 typedef struct QEMUOption
{
1913 static const QEMUOption qemu_options
[] = {
1914 { "h", 0, QEMU_OPTION_h
, QEMU_ARCH_ALL
},
1915 #define QEMU_OPTIONS_GENERATE_OPTIONS
1916 #include "qemu-options-wrapper.h"
1920 typedef struct VGAInterfaceInfo
{
1921 const char *opt_name
; /* option name */
1922 const char *name
; /* human-readable name */
1923 /* Class names indicating that support is available.
1924 * If no class is specified, the interface is always available */
1925 const char *class_names
[2];
1928 static const VGAInterfaceInfo vga_interfaces
[VGA_TYPE_MAX
] = {
1931 .name
= "no graphic card",
1935 .name
= "standard VGA",
1936 .class_names
= { "VGA", "isa-vga" },
1939 .opt_name
= "cirrus",
1940 .name
= "Cirrus VGA",
1941 .class_names
= { "cirrus-vga", "isa-cirrus-vga" },
1944 .opt_name
= "vmware",
1945 .name
= "VMWare SVGA",
1946 .class_names
= { "vmware-svga" },
1949 .opt_name
= "virtio",
1950 .name
= "Virtio VGA",
1951 .class_names
= { "virtio-vga" },
1956 .class_names
= { "qxl-vga" },
1960 .name
= "TCX framebuffer",
1961 .class_names
= { "SUNW,tcx" },
1965 .name
= "CG3 framebuffer",
1966 .class_names
= { "cgthree" },
1969 .opt_name
= "xenfb",
1970 .name
= "Xen paravirtualized framebuffer",
1974 static bool vga_interface_available(VGAInterfaceType t
)
1976 const VGAInterfaceInfo
*ti
= &vga_interfaces
[t
];
1978 assert(t
< VGA_TYPE_MAX
);
1979 return !ti
->class_names
[0] ||
1980 object_class_by_name(ti
->class_names
[0]) ||
1981 object_class_by_name(ti
->class_names
[1]);
1985 get_default_vga_model(const MachineClass
*machine_class
)
1987 if (machine_class
->default_display
) {
1988 return machine_class
->default_display
;
1989 } else if (vga_interface_available(VGA_CIRRUS
)) {
1991 } else if (vga_interface_available(VGA_STD
)) {
1998 static void select_vgahw(const MachineClass
*machine_class
, const char *p
)
2003 if (g_str_equal(p
, "help")) {
2004 const char *def
= get_default_vga_model(machine_class
);
2006 for (t
= 0; t
< VGA_TYPE_MAX
; t
++) {
2007 const VGAInterfaceInfo
*ti
= &vga_interfaces
[t
];
2009 if (vga_interface_available(t
) && ti
->opt_name
) {
2010 printf("%-20s %s%s\n", ti
->opt_name
, ti
->name
?: "",
2011 g_str_equal(ti
->opt_name
, def
) ? " (default)" : "");
2017 assert(vga_interface_type
== VGA_NONE
);
2018 for (t
= 0; t
< VGA_TYPE_MAX
; t
++) {
2019 const VGAInterfaceInfo
*ti
= &vga_interfaces
[t
];
2020 if (ti
->opt_name
&& strstart(p
, ti
->opt_name
, &opts
)) {
2021 if (!vga_interface_available(t
)) {
2022 error_report("%s not available", ti
->name
);
2025 vga_interface_type
= t
;
2029 if (t
== VGA_TYPE_MAX
) {
2031 error_report("unknown vga type: %s", p
);
2035 const char *nextopt
;
2037 if (strstart(opts
, ",retrace=", &nextopt
)) {
2039 if (strstart(opts
, "dumb", &nextopt
))
2040 vga_retrace_method
= VGA_RETRACE_DUMB
;
2041 else if (strstart(opts
, "precise", &nextopt
))
2042 vga_retrace_method
= VGA_RETRACE_PRECISE
;
2043 else goto invalid_vga
;
2044 } else goto invalid_vga
;
2049 static void parse_display_qapi(const char *optarg
)
2051 DisplayOptions
*opts
;
2054 v
= qobject_input_visitor_new_str(optarg
, "type", &error_fatal
);
2056 visit_type_DisplayOptions(v
, NULL
, &opts
, &error_fatal
);
2057 QAPI_CLONE_MEMBERS(DisplayOptions
, &dpy
, opts
);
2059 qapi_free_DisplayOptions(opts
);
2063 DisplayOptions
*qmp_query_display_options(Error
**errp
)
2065 return QAPI_CLONE(DisplayOptions
, &dpy
);
2068 static void parse_display(const char *p
)
2072 if (strstart(p
, "sdl", &opts
)) {
2074 * sdl DisplayType needs hand-crafted parser instead of
2075 * parse_display_qapi() due to some options not in
2076 * DisplayOptions, specifically:
2078 * Already deprecated.
2079 * - ctrl_grab + alt_grab
2080 * Not clear yet what happens to them long-term. Should
2081 * replaced by something better or deprecated and dropped.
2083 dpy
.type
= DISPLAY_TYPE_SDL
;
2085 const char *nextopt
;
2087 if (strstart(opts
, ",alt_grab=", &nextopt
)) {
2089 if (strstart(opts
, "on", &nextopt
)) {
2091 } else if (strstart(opts
, "off", &nextopt
)) {
2094 goto invalid_sdl_args
;
2096 } else if (strstart(opts
, ",ctrl_grab=", &nextopt
)) {
2098 if (strstart(opts
, "on", &nextopt
)) {
2100 } else if (strstart(opts
, "off", &nextopt
)) {
2103 goto invalid_sdl_args
;
2105 } else if (strstart(opts
, ",window_close=", &nextopt
)) {
2107 dpy
.has_window_close
= true;
2108 if (strstart(opts
, "on", &nextopt
)) {
2109 dpy
.window_close
= true;
2110 } else if (strstart(opts
, "off", &nextopt
)) {
2111 dpy
.window_close
= false;
2113 goto invalid_sdl_args
;
2115 } else if (strstart(opts
, ",gl=", &nextopt
)) {
2118 if (strstart(opts
, "on", &nextopt
)) {
2119 dpy
.gl
= DISPLAYGL_MODE_ON
;
2120 } else if (strstart(opts
, "core", &nextopt
)) {
2121 dpy
.gl
= DISPLAYGL_MODE_CORE
;
2122 } else if (strstart(opts
, "es", &nextopt
)) {
2123 dpy
.gl
= DISPLAYGL_MODE_ES
;
2124 } else if (strstart(opts
, "off", &nextopt
)) {
2125 dpy
.gl
= DISPLAYGL_MODE_OFF
;
2127 goto invalid_sdl_args
;
2131 error_report("invalid SDL option string");
2136 } else if (strstart(p
, "vnc", &opts
)) {
2138 * vnc isn't a (local) DisplayType but a protocol for remote
2142 vnc_parse(opts
+ 1, &error_fatal
);
2144 error_report("VNC requires a display argument vnc=<display>");
2148 parse_display_qapi(p
);
2152 char *qemu_find_file(int type
, const char *name
)
2158 /* Try the name as a straight path first */
2159 if (access(name
, R_OK
) == 0) {
2160 trace_load_file(name
, name
);
2161 return g_strdup(name
);
2165 case QEMU_FILE_TYPE_BIOS
:
2168 case QEMU_FILE_TYPE_KEYMAP
:
2169 subdir
= "keymaps/";
2175 for (i
= 0; i
< data_dir_idx
; i
++) {
2176 buf
= g_strdup_printf("%s/%s%s", data_dir
[i
], subdir
, name
);
2177 if (access(buf
, R_OK
) == 0) {
2178 trace_load_file(name
, buf
);
2186 static void qemu_add_data_dir(const char *path
)
2193 if (data_dir_idx
== ARRAY_SIZE(data_dir
)) {
2196 for (i
= 0; i
< data_dir_idx
; i
++) {
2197 if (strcmp(data_dir
[i
], path
) == 0) {
2198 return; /* duplicate */
2201 data_dir
[data_dir_idx
++] = g_strdup(path
);
2204 static inline bool nonempty_str(const char *str
)
2209 static int parse_fw_cfg(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2213 const char *name
, *file
, *str
;
2214 FWCfgState
*fw_cfg
= (FWCfgState
*) opaque
;
2216 if (fw_cfg
== NULL
) {
2217 error_setg(errp
, "fw_cfg device not available");
2220 name
= qemu_opt_get(opts
, "name");
2221 file
= qemu_opt_get(opts
, "file");
2222 str
= qemu_opt_get(opts
, "string");
2224 /* we need name and either a file or the content string */
2225 if (!(nonempty_str(name
) && (nonempty_str(file
) || nonempty_str(str
)))) {
2226 error_setg(errp
, "invalid argument(s)");
2229 if (nonempty_str(file
) && nonempty_str(str
)) {
2230 error_setg(errp
, "file and string are mutually exclusive");
2233 if (strlen(name
) > FW_CFG_MAX_FILE_PATH
- 1) {
2234 error_setg(errp
, "name too long (max. %d char)",
2235 FW_CFG_MAX_FILE_PATH
- 1);
2238 if (strncmp(name
, "opt/", 4) != 0) {
2239 warn_report("externally provided fw_cfg item names "
2240 "should be prefixed with \"opt/\"");
2242 if (nonempty_str(str
)) {
2243 size
= strlen(str
); /* NUL terminator NOT included in fw_cfg blob */
2244 buf
= g_memdup(str
, size
);
2247 if (!g_file_get_contents(file
, &buf
, &size
, &err
)) {
2248 error_setg(errp
, "can't load %s: %s", file
, err
->message
);
2253 /* For legacy, keep user files in a specific global order. */
2254 fw_cfg_set_order_override(fw_cfg
, FW_CFG_ORDER_OVERRIDE_USER
);
2255 fw_cfg_add_file(fw_cfg
, name
, buf
, size
);
2256 fw_cfg_reset_order_override(fw_cfg
);
2260 static int device_help_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2262 return qdev_device_help(opts
);
2265 static int device_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2269 dev
= qdev_device_add(opts
, errp
);
2273 object_unref(OBJECT(dev
));
2277 static int chardev_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2279 Error
*local_err
= NULL
;
2281 if (!qemu_chr_new_from_opts(opts
, NULL
, &local_err
)) {
2283 error_propagate(errp
, local_err
);
2291 #ifdef CONFIG_VIRTFS
2292 static int fsdev_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2294 return qemu_fsdev_add(opts
, errp
);
2298 static int mon_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2301 const char *chardev
;
2305 mode
= qemu_opt_get(opts
, "mode");
2309 if (strcmp(mode
, "readline") == 0) {
2310 flags
= MONITOR_USE_READLINE
;
2311 } else if (strcmp(mode
, "control") == 0) {
2312 flags
= MONITOR_USE_CONTROL
;
2314 error_setg(errp
, "unknown monitor mode \"%s\"", mode
);
2318 if (qemu_opt_get_bool(opts
, "pretty", 0))
2319 flags
|= MONITOR_USE_PRETTY
;
2321 chardev
= qemu_opt_get(opts
, "chardev");
2323 error_report("chardev is required");
2326 chr
= qemu_chr_find(chardev
);
2328 error_setg(errp
, "chardev \"%s\" not found", chardev
);
2332 monitor_init(chr
, flags
);
2336 static void monitor_parse(const char *optarg
, const char *mode
, bool pretty
)
2338 static int monitor_device_index
= 0;
2343 if (strstart(optarg
, "chardev:", &p
)) {
2344 snprintf(label
, sizeof(label
), "%s", p
);
2346 snprintf(label
, sizeof(label
), "compat_monitor%d",
2347 monitor_device_index
);
2348 opts
= qemu_chr_parse_compat(label
, optarg
, true);
2350 error_report("parse error: %s", optarg
);
2355 opts
= qemu_opts_create(qemu_find_opts("mon"), label
, 1, &error_fatal
);
2356 qemu_opt_set(opts
, "mode", mode
, &error_abort
);
2357 qemu_opt_set(opts
, "chardev", label
, &error_abort
);
2358 qemu_opt_set_bool(opts
, "pretty", pretty
, &error_abort
);
2359 monitor_device_index
++;
2362 struct device_config
{
2364 DEV_USB
, /* -usbdevice */
2366 DEV_SERIAL
, /* -serial */
2367 DEV_PARALLEL
, /* -parallel */
2368 DEV_DEBUGCON
, /* -debugcon */
2369 DEV_GDB
, /* -gdb, -s */
2370 DEV_SCLP
, /* s390 sclp */
2372 const char *cmdline
;
2374 QTAILQ_ENTRY(device_config
) next
;
2377 static QTAILQ_HEAD(, device_config
) device_configs
=
2378 QTAILQ_HEAD_INITIALIZER(device_configs
);
2380 static void add_device_config(int type
, const char *cmdline
)
2382 struct device_config
*conf
;
2384 conf
= g_malloc0(sizeof(*conf
));
2386 conf
->cmdline
= cmdline
;
2387 loc_save(&conf
->loc
);
2388 QTAILQ_INSERT_TAIL(&device_configs
, conf
, next
);
2391 static int foreach_device_config(int type
, int (*func
)(const char *cmdline
))
2393 struct device_config
*conf
;
2396 QTAILQ_FOREACH(conf
, &device_configs
, next
) {
2397 if (conf
->type
!= type
)
2399 loc_push_restore(&conf
->loc
);
2400 rc
= func(conf
->cmdline
);
2401 loc_pop(&conf
->loc
);
2409 static int serial_parse(const char *devname
)
2411 int index
= num_serial_hds
;
2414 if (strcmp(devname
, "none") == 0)
2416 snprintf(label
, sizeof(label
), "serial%d", index
);
2417 serial_hds
= g_renew(Chardev
*, serial_hds
, index
+ 1);
2419 serial_hds
[index
] = qemu_chr_new_mux_mon(label
, devname
, NULL
);
2420 if (!serial_hds
[index
]) {
2421 error_report("could not connect serial device"
2422 " to character backend '%s'", devname
);
2429 Chardev
*serial_hd(int i
)
2432 if (i
< num_serial_hds
) {
2433 return serial_hds
[i
];
2438 int serial_max_hds(void)
2440 return num_serial_hds
;
2443 static int parallel_parse(const char *devname
)
2445 static int index
= 0;
2448 if (strcmp(devname
, "none") == 0)
2450 if (index
== MAX_PARALLEL_PORTS
) {
2451 error_report("too many parallel ports");
2454 snprintf(label
, sizeof(label
), "parallel%d", index
);
2455 parallel_hds
[index
] = qemu_chr_new_mux_mon(label
, devname
, NULL
);
2456 if (!parallel_hds
[index
]) {
2457 error_report("could not connect parallel device"
2458 " to character backend '%s'", devname
);
2465 static int debugcon_parse(const char *devname
)
2469 if (!qemu_chr_new_mux_mon("debugcon", devname
, NULL
)) {
2470 error_report("invalid character backend '%s'", devname
);
2473 opts
= qemu_opts_create(qemu_find_opts("device"), "debugcon", 1, NULL
);
2475 error_report("already have a debugcon device");
2478 qemu_opt_set(opts
, "driver", "isa-debugcon", &error_abort
);
2479 qemu_opt_set(opts
, "chardev", "debugcon", &error_abort
);
2483 static gint
machine_class_cmp(gconstpointer a
, gconstpointer b
)
2485 const MachineClass
*mc1
= a
, *mc2
= b
;
2488 if (mc1
->family
== NULL
) {
2489 if (mc2
->family
== NULL
) {
2490 /* Compare standalone machine types against each other; they sort
2491 * in increasing order.
2493 return strcmp(object_class_get_name(OBJECT_CLASS(mc1
)),
2494 object_class_get_name(OBJECT_CLASS(mc2
)));
2497 /* Standalone machine types sort after families. */
2501 if (mc2
->family
== NULL
) {
2502 /* Families sort before standalone machine types. */
2506 /* Families sort between each other alphabetically increasingly. */
2507 res
= strcmp(mc1
->family
, mc2
->family
);
2512 /* Within the same family, machine types sort in decreasing order. */
2513 return strcmp(object_class_get_name(OBJECT_CLASS(mc2
)),
2514 object_class_get_name(OBJECT_CLASS(mc1
)));
2517 static MachineClass
*machine_parse(const char *name
, GSList
*machines
)
2522 if (is_help_option(name
)) {
2523 printf("Supported machines are:\n");
2524 machines
= g_slist_sort(machines
, machine_class_cmp
);
2525 for (el
= machines
; el
; el
= el
->next
) {
2526 MachineClass
*mc
= el
->data
;
2528 printf("%-20s %s (alias of %s)\n", mc
->alias
, mc
->desc
, mc
->name
);
2530 printf("%-20s %s%s%s\n", mc
->name
, mc
->desc
,
2531 mc
->is_default
? " (default)" : "",
2532 mc
->deprecation_reason
? " (deprecated)" : "");
2537 mc
= find_machine(name
, machines
);
2539 error_report("unsupported machine type");
2540 error_printf("Use -machine help to list supported machines\n");
2546 void qemu_add_exit_notifier(Notifier
*notify
)
2548 notifier_list_add(&exit_notifiers
, notify
);
2551 void qemu_remove_exit_notifier(Notifier
*notify
)
2553 notifier_remove(notify
);
2556 static void qemu_run_exit_notifiers(void)
2558 notifier_list_notify(&exit_notifiers
, NULL
);
2561 static const char *pid_file
;
2562 static Notifier qemu_unlink_pidfile_notifier
;
2564 static void qemu_unlink_pidfile(Notifier
*n
, void *data
)
2571 bool machine_init_done
;
2573 void qemu_add_machine_init_done_notifier(Notifier
*notify
)
2575 notifier_list_add(&machine_init_done_notifiers
, notify
);
2576 if (machine_init_done
) {
2577 notify
->notify(notify
, NULL
);
2581 void qemu_remove_machine_init_done_notifier(Notifier
*notify
)
2583 notifier_remove(notify
);
2586 static void qemu_run_machine_init_done_notifiers(void)
2588 machine_init_done
= true;
2589 notifier_list_notify(&machine_init_done_notifiers
, NULL
);
2592 static const QEMUOption
*lookup_opt(int argc
, char **argv
,
2593 const char **poptarg
, int *poptind
)
2595 const QEMUOption
*popt
;
2596 int optind
= *poptind
;
2597 char *r
= argv
[optind
];
2600 loc_set_cmdline(argv
, optind
, 1);
2602 /* Treat --foo the same as -foo. */
2605 popt
= qemu_options
;
2608 error_report("invalid option");
2611 if (!strcmp(popt
->name
, r
+ 1))
2615 if (popt
->flags
& HAS_ARG
) {
2616 if (optind
>= argc
) {
2617 error_report("requires an argument");
2620 optarg
= argv
[optind
++];
2621 loc_set_cmdline(argv
, optind
- 2, 2);
2632 static MachineClass
*select_machine(void)
2634 GSList
*machines
= object_class_get_list(TYPE_MACHINE
, false);
2635 MachineClass
*machine_class
= find_default_machine(machines
);
2640 loc_push_none(&loc
);
2642 opts
= qemu_get_machine_opts();
2643 qemu_opts_loc_restore(opts
);
2645 optarg
= qemu_opt_get(opts
, "type");
2647 machine_class
= machine_parse(optarg
, machines
);
2650 if (!machine_class
) {
2651 error_report("No machine specified, and there is no default");
2652 error_printf("Use -machine help to list supported machines\n");
2657 g_slist_free(machines
);
2658 return machine_class
;
2661 static int machine_set_property(void *opaque
,
2662 const char *name
, const char *value
,
2665 Object
*obj
= OBJECT(opaque
);
2666 Error
*local_err
= NULL
;
2669 if (strcmp(name
, "type") == 0) {
2673 qom_name
= g_strdup(name
);
2674 for (p
= qom_name
; *p
; p
++) {
2680 object_property_parse(obj
, value
, qom_name
, &local_err
);
2684 error_propagate(errp
, local_err
);
2693 * Initial object creation happens before all other
2694 * QEMU data types are created. The majority of objects
2695 * can be created at this point. The rng-egd object
2696 * cannot be created here, as it depends on the chardev
2699 static bool object_create_initial(const char *type
, QemuOpts
*opts
)
2703 if (is_help_option(type
)) {
2706 printf("List of user creatable objects:\n");
2707 list
= object_class_get_list_sorted(TYPE_USER_CREATABLE
, false);
2708 for (l
= list
; l
!= NULL
; l
= l
->next
) {
2709 ObjectClass
*oc
= OBJECT_CLASS(l
->data
);
2710 printf(" %s\n", object_class_get_name(oc
));
2716 klass
= object_class_by_name(type
);
2717 if (klass
&& qemu_opt_has_help_opt(opts
)) {
2718 ObjectPropertyIterator iter
;
2719 ObjectProperty
*prop
;
2720 GPtrArray
*array
= g_ptr_array_new();
2723 object_class_property_iter_init(&iter
, klass
);
2724 while ((prop
= object_property_iter_next(&iter
))) {
2731 str
= g_string_new(NULL
);
2732 g_string_append_printf(str
, " %s=<%s>", prop
->name
, prop
->type
);
2733 if (prop
->description
) {
2734 if (str
->len
< 24) {
2735 g_string_append_printf(str
, "%*s", 24 - (int)str
->len
, "");
2737 g_string_append_printf(str
, " - %s", prop
->description
);
2739 g_ptr_array_add(array
, g_string_free(str
, false));
2741 g_ptr_array_sort(array
, (GCompareFunc
)qemu_pstrcmp0
);
2742 if (array
->len
> 0) {
2743 printf("%s options:\n", type
);
2745 printf("There are no options for %s.\n", type
);
2747 for (i
= 0; i
< array
->len
; i
++) {
2748 printf("%s\n", (char *)array
->pdata
[i
]);
2750 g_ptr_array_set_free_func(array
, g_free
);
2751 g_ptr_array_free(array
, true);
2756 * Objects should not be made "delayed" without a reason. If you
2757 * add one, state the reason in a comment!
2760 /* Reason: rng-egd property "chardev" */
2761 if (g_str_equal(type
, "rng-egd")) {
2765 #if defined(CONFIG_VHOST_USER) && defined(CONFIG_LINUX)
2766 /* Reason: cryptodev-vhost-user property "chardev" */
2767 if (g_str_equal(type
, "cryptodev-vhost-user")) {
2773 * Reason: filter-* property "netdev" etc.
2775 if (g_str_equal(type
, "filter-buffer") ||
2776 g_str_equal(type
, "filter-dump") ||
2777 g_str_equal(type
, "filter-mirror") ||
2778 g_str_equal(type
, "filter-redirector") ||
2779 g_str_equal(type
, "colo-compare") ||
2780 g_str_equal(type
, "filter-rewriter") ||
2781 g_str_equal(type
, "filter-replay")) {
2785 /* Memory allocation by backends needs to be done
2786 * after configure_accelerator() (due to the tcg_enabled()
2787 * checks at memory_region_init_*()).
2789 * Also, allocation of large amounts of memory may delay
2790 * chardev initialization for too long, and trigger timeouts
2791 * on software that waits for a monitor socket to be created
2794 if (g_str_has_prefix(type
, "memory-backend-")) {
2803 * The remainder of object creation happens after the
2804 * creation of chardev, fsdev, net clients and device data types.
2806 static bool object_create_delayed(const char *type
, QemuOpts
*opts
)
2808 return !object_create_initial(type
, opts
);
2812 static void set_memory_options(uint64_t *ram_slots
, ram_addr_t
*maxram_size
,
2816 const char *mem_str
;
2817 const ram_addr_t default_ram_size
= mc
->default_ram_size
;
2818 QemuOpts
*opts
= qemu_find_opts_singleton("memory");
2821 loc_push_none(&loc
);
2822 qemu_opts_loc_restore(opts
);
2825 mem_str
= qemu_opt_get(opts
, "size");
2828 error_report("missing 'size' option value");
2832 sz
= qemu_opt_get_size(opts
, "size", ram_size
);
2834 /* Fix up legacy suffix-less format */
2835 if (g_ascii_isdigit(mem_str
[strlen(mem_str
) - 1])) {
2836 uint64_t overflow_check
= sz
;
2839 if (sz
/ MiB
!= overflow_check
) {
2840 error_report("too large 'size' option value");
2846 /* backward compatibility behaviour for case "-m 0" */
2848 sz
= default_ram_size
;
2851 sz
= QEMU_ALIGN_UP(sz
, 8192);
2853 if (ram_size
!= sz
) {
2854 error_report("ram size too large");
2858 /* store value for the future use */
2859 qemu_opt_set_number(opts
, "size", ram_size
, &error_abort
);
2860 *maxram_size
= ram_size
;
2862 if (qemu_opt_get(opts
, "maxmem")) {
2865 sz
= qemu_opt_get_size(opts
, "maxmem", 0);
2866 slots
= qemu_opt_get_number(opts
, "slots", 0);
2867 if (sz
< ram_size
) {
2868 error_report("invalid value of -m option maxmem: "
2869 "maximum memory size (0x%" PRIx64
") must be at least "
2870 "the initial memory size (0x" RAM_ADDR_FMT
")",
2873 } else if (slots
&& sz
== ram_size
) {
2874 error_report("invalid value of -m option maxmem: "
2875 "memory slots were specified but maximum memory size "
2876 "(0x%" PRIx64
") is equal to the initial memory size "
2877 "(0x" RAM_ADDR_FMT
")", sz
, ram_size
);
2883 } else if (qemu_opt_get(opts
, "slots")) {
2884 error_report("invalid -m option value: missing 'maxmem' option");
2891 static int global_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2895 g
= g_malloc0(sizeof(*g
));
2896 g
->driver
= qemu_opt_get(opts
, "driver");
2897 g
->property
= qemu_opt_get(opts
, "property");
2898 g
->value
= qemu_opt_get(opts
, "value");
2899 qdev_prop_register_global(g
);
2903 static int qemu_read_default_config_file(void)
2907 ret
= qemu_read_config_file(CONFIG_QEMU_CONFDIR
"/qemu.conf");
2908 if (ret
< 0 && ret
!= -ENOENT
) {
2915 static void user_register_global_props(void)
2917 qemu_opts_foreach(qemu_find_opts("global"),
2918 global_init_func
, NULL
, NULL
);
2921 int main(int argc
, char **argv
, char **envp
)
2924 int snapshot
, linux_boot
;
2925 const char *initrd_filename
;
2926 const char *kernel_filename
, *kernel_cmdline
;
2927 const char *boot_order
= NULL
;
2928 const char *boot_once
= NULL
;
2930 QemuOpts
*opts
, *machine_opts
;
2931 QemuOpts
*icount_opts
= NULL
, *accel_opts
= NULL
;
2932 QemuOptsList
*olist
;
2935 const char *loadvm
= NULL
;
2936 MachineClass
*machine_class
;
2937 const char *cpu_option
;
2938 const char *vga_model
= NULL
;
2939 const char *qtest_chrdev
= NULL
;
2940 const char *qtest_log
= NULL
;
2941 const char *incoming
= NULL
;
2942 bool userconfig
= true;
2943 bool nographic
= false;
2944 int display_remote
= 0;
2945 const char *log_mask
= NULL
;
2946 const char *log_file
= NULL
;
2947 char *trace_file
= NULL
;
2948 ram_addr_t maxram_size
;
2949 uint64_t ram_slots
= 0;
2950 FILE *vmstate_dump_file
= NULL
;
2951 Error
*main_loop_err
= NULL
;
2953 bool list_data_dirs
= false;
2955 BlockdevOptionsQueue bdo_queue
= QSIMPLEQ_HEAD_INITIALIZER(bdo_queue
);
2957 error_init(argv
[0]);
2958 module_call_init(MODULE_INIT_TRACE
);
2960 qemu_init_cpu_list();
2961 qemu_init_cpu_loop();
2963 qemu_mutex_lock_iothread();
2965 atexit(qemu_run_exit_notifiers
);
2966 qemu_init_exec_dir(argv
[0]);
2968 module_call_init(MODULE_INIT_QOM
);
2970 qemu_add_opts(&qemu_drive_opts
);
2971 qemu_add_drive_opts(&qemu_legacy_drive_opts
);
2972 qemu_add_drive_opts(&qemu_common_drive_opts
);
2973 qemu_add_drive_opts(&qemu_drive_opts
);
2974 qemu_add_drive_opts(&bdrv_runtime_opts
);
2975 qemu_add_opts(&qemu_chardev_opts
);
2976 qemu_add_opts(&qemu_device_opts
);
2977 qemu_add_opts(&qemu_netdev_opts
);
2978 qemu_add_opts(&qemu_nic_opts
);
2979 qemu_add_opts(&qemu_net_opts
);
2980 qemu_add_opts(&qemu_rtc_opts
);
2981 qemu_add_opts(&qemu_global_opts
);
2982 qemu_add_opts(&qemu_mon_opts
);
2983 qemu_add_opts(&qemu_trace_opts
);
2984 qemu_add_opts(&qemu_option_rom_opts
);
2985 qemu_add_opts(&qemu_machine_opts
);
2986 qemu_add_opts(&qemu_accel_opts
);
2987 qemu_add_opts(&qemu_mem_opts
);
2988 qemu_add_opts(&qemu_smp_opts
);
2989 qemu_add_opts(&qemu_boot_opts
);
2990 qemu_add_opts(&qemu_add_fd_opts
);
2991 qemu_add_opts(&qemu_object_opts
);
2992 qemu_add_opts(&qemu_tpmdev_opts
);
2993 qemu_add_opts(&qemu_realtime_opts
);
2994 qemu_add_opts(&qemu_overcommit_opts
);
2995 qemu_add_opts(&qemu_msg_opts
);
2996 qemu_add_opts(&qemu_name_opts
);
2997 qemu_add_opts(&qemu_numa_opts
);
2998 qemu_add_opts(&qemu_icount_opts
);
2999 qemu_add_opts(&qemu_semihosting_config_opts
);
3000 qemu_add_opts(&qemu_fw_cfg_opts
);
3001 module_call_init(MODULE_INIT_OPTS
);
3004 precopy_infrastructure_init();
3005 postcopy_infrastructure_init();
3006 monitor_init_globals();
3008 if (qcrypto_init(&err
) < 0) {
3009 error_reportf_err(err
, "cannot initialize crypto: ");
3013 QLIST_INIT (&vm_change_state_head
);
3014 os_setup_early_signal_handling();
3021 bdrv_init_with_whitelist();
3025 /* first pass of option parsing */
3027 while (optind
< argc
) {
3028 if (argv
[optind
][0] != '-') {
3032 const QEMUOption
*popt
;
3034 popt
= lookup_opt(argc
, argv
, &optarg
, &optind
);
3035 switch (popt
->index
) {
3036 case QEMU_OPTION_nouserconfig
:
3044 if (qemu_read_default_config_file() < 0) {
3049 /* second pass of option parsing */
3054 if (argv
[optind
][0] != '-') {
3055 loc_set_cmdline(argv
, optind
, 1);
3056 drive_add(IF_DEFAULT
, 0, argv
[optind
++], HD_OPTS
);
3058 const QEMUOption
*popt
;
3060 popt
= lookup_opt(argc
, argv
, &optarg
, &optind
);
3061 if (!(popt
->arch_mask
& arch_type
)) {
3062 error_report("Option not supported for this target");
3065 switch(popt
->index
) {
3066 case QEMU_OPTION_cpu
:
3067 /* hw initialization will check this */
3068 cpu_option
= optarg
;
3070 case QEMU_OPTION_hda
:
3071 case QEMU_OPTION_hdb
:
3072 case QEMU_OPTION_hdc
:
3073 case QEMU_OPTION_hdd
:
3074 drive_add(IF_DEFAULT
, popt
->index
- QEMU_OPTION_hda
, optarg
,
3077 case QEMU_OPTION_blockdev
:
3080 BlockdevOptionsQueueEntry
*bdo
;
3082 v
= qobject_input_visitor_new_str(optarg
, "driver",
3085 bdo
= g_new(BlockdevOptionsQueueEntry
, 1);
3086 visit_type_BlockdevOptions(v
, NULL
, &bdo
->bdo
,
3089 loc_save(&bdo
->loc
);
3090 QSIMPLEQ_INSERT_TAIL(&bdo_queue
, bdo
, entry
);
3093 case QEMU_OPTION_drive
:
3094 if (drive_def(optarg
) == NULL
) {
3098 case QEMU_OPTION_set
:
3099 if (qemu_set_option(optarg
) != 0)
3102 case QEMU_OPTION_global
:
3103 if (qemu_global_option(optarg
) != 0)
3106 case QEMU_OPTION_mtdblock
:
3107 drive_add(IF_MTD
, -1, optarg
, MTD_OPTS
);
3109 case QEMU_OPTION_sd
:
3110 drive_add(IF_SD
, -1, optarg
, SD_OPTS
);
3112 case QEMU_OPTION_pflash
:
3113 drive_add(IF_PFLASH
, -1, optarg
, PFLASH_OPTS
);
3115 case QEMU_OPTION_snapshot
:
3118 case QEMU_OPTION_numa
:
3119 opts
= qemu_opts_parse_noisily(qemu_find_opts("numa"),
3125 case QEMU_OPTION_display
:
3126 parse_display(optarg
);
3128 case QEMU_OPTION_nographic
:
3129 olist
= qemu_find_opts("machine");
3130 qemu_opts_parse_noisily(olist
, "graphics=off", false);
3132 dpy
.type
= DISPLAY_TYPE_NONE
;
3134 case QEMU_OPTION_curses
:
3135 #ifdef CONFIG_CURSES
3136 dpy
.type
= DISPLAY_TYPE_CURSES
;
3138 error_report("curses or iconv support is disabled");
3142 case QEMU_OPTION_portrait
:
3143 graphic_rotate
= 90;
3145 case QEMU_OPTION_rotate
:
3146 graphic_rotate
= strtol(optarg
, (char **) &optarg
, 10);
3147 if (graphic_rotate
!= 0 && graphic_rotate
!= 90 &&
3148 graphic_rotate
!= 180 && graphic_rotate
!= 270) {
3149 error_report("only 90, 180, 270 deg rotation is available");
3153 case QEMU_OPTION_kernel
:
3154 qemu_opts_set(qemu_find_opts("machine"), 0, "kernel", optarg
,
3157 case QEMU_OPTION_initrd
:
3158 qemu_opts_set(qemu_find_opts("machine"), 0, "initrd", optarg
,
3161 case QEMU_OPTION_append
:
3162 qemu_opts_set(qemu_find_opts("machine"), 0, "append", optarg
,
3165 case QEMU_OPTION_dtb
:
3166 qemu_opts_set(qemu_find_opts("machine"), 0, "dtb", optarg
,
3169 case QEMU_OPTION_cdrom
:
3170 drive_add(IF_DEFAULT
, 2, optarg
, CDROM_OPTS
);
3172 case QEMU_OPTION_boot
:
3173 opts
= qemu_opts_parse_noisily(qemu_find_opts("boot-opts"),
3179 case QEMU_OPTION_fda
:
3180 case QEMU_OPTION_fdb
:
3181 drive_add(IF_FLOPPY
, popt
->index
- QEMU_OPTION_fda
,
3184 case QEMU_OPTION_no_fd_bootchk
:
3187 case QEMU_OPTION_netdev
:
3189 if (net_client_parse(qemu_find_opts("netdev"), optarg
) == -1) {
3193 case QEMU_OPTION_nic
:
3195 if (net_client_parse(qemu_find_opts("nic"), optarg
) == -1) {
3199 case QEMU_OPTION_net
:
3201 if (net_client_parse(qemu_find_opts("net"), optarg
) == -1) {
3205 #ifdef CONFIG_LIBISCSI
3206 case QEMU_OPTION_iscsi
:
3207 opts
= qemu_opts_parse_noisily(qemu_find_opts("iscsi"),
3214 case QEMU_OPTION_bt
:
3215 warn_report("The bluetooth subsystem is deprecated and will "
3216 "be removed soon. If the bluetooth subsystem is "
3217 "still useful for you, please send a mail to "
3218 "qemu-devel@nongnu.org with your usecase.");
3219 add_device_config(DEV_BT
, optarg
);
3221 case QEMU_OPTION_audio_help
:
3222 audio_legacy_help();
3225 case QEMU_OPTION_audiodev
:
3226 audio_parse_option(optarg
);
3228 case QEMU_OPTION_soundhw
:
3229 select_soundhw (optarg
);
3234 case QEMU_OPTION_version
:
3239 opts
= qemu_opts_parse_noisily(qemu_find_opts("memory"),
3246 case QEMU_OPTION_tpmdev
:
3247 if (tpm_config_parse(qemu_find_opts("tpmdev"), optarg
) < 0) {
3252 case QEMU_OPTION_mempath
:
3255 case QEMU_OPTION_mem_prealloc
:
3264 case QEMU_OPTION_DFILTER
:
3265 qemu_set_dfilter_ranges(optarg
, &error_fatal
);
3267 case QEMU_OPTION_seed
:
3268 qemu_guest_random_seed_main(optarg
, &error_fatal
);
3271 add_device_config(DEV_GDB
, "tcp::" DEFAULT_GDBSTUB_PORT
);
3273 case QEMU_OPTION_gdb
:
3274 add_device_config(DEV_GDB
, optarg
);
3277 if (is_help_option(optarg
)) {
3278 list_data_dirs
= true;
3280 qemu_add_data_dir(optarg
);
3283 case QEMU_OPTION_bios
:
3284 qemu_opts_set(qemu_find_opts("machine"), 0, "firmware", optarg
,
3287 case QEMU_OPTION_singlestep
:
3294 keyboard_layout
= optarg
;
3296 case QEMU_OPTION_vga
:
3305 w
= strtol(p
, (char **)&p
, 10);
3308 error_report("invalid resolution or depth");
3314 h
= strtol(p
, (char **)&p
, 10);
3319 depth
= strtol(p
, (char **)&p
, 10);
3320 if (depth
!= 8 && depth
!= 15 && depth
!= 16 &&
3321 depth
!= 24 && depth
!= 32)
3323 } else if (*p
== '\0') {
3324 depth
= graphic_depth
;
3331 graphic_depth
= depth
;
3334 case QEMU_OPTION_echr
:
3337 term_escape_char
= strtol(optarg
, &r
, 0);
3339 printf("Bad argument to echr\n");
3342 case QEMU_OPTION_monitor
:
3343 default_monitor
= 0;
3344 if (strncmp(optarg
, "none", 4)) {
3345 monitor_parse(optarg
, "readline", false);
3348 case QEMU_OPTION_qmp
:
3349 monitor_parse(optarg
, "control", false);
3350 default_monitor
= 0;
3352 case QEMU_OPTION_qmp_pretty
:
3353 monitor_parse(optarg
, "control", true);
3354 default_monitor
= 0;
3356 case QEMU_OPTION_mon
:
3357 opts
= qemu_opts_parse_noisily(qemu_find_opts("mon"), optarg
,
3362 default_monitor
= 0;
3364 case QEMU_OPTION_chardev
:
3365 opts
= qemu_opts_parse_noisily(qemu_find_opts("chardev"),
3371 case QEMU_OPTION_fsdev
:
3372 olist
= qemu_find_opts("fsdev");
3374 error_report("fsdev support is disabled");
3377 opts
= qemu_opts_parse_noisily(olist
, optarg
, true);
3382 case QEMU_OPTION_virtfs
: {
3385 const char *writeout
, *sock_fd
, *socket
, *path
, *security_model
;
3387 olist
= qemu_find_opts("virtfs");
3389 error_report("virtfs support is disabled");
3392 opts
= qemu_opts_parse_noisily(olist
, optarg
, true);
3397 if (qemu_opt_get(opts
, "fsdriver") == NULL
||
3398 qemu_opt_get(opts
, "mount_tag") == NULL
) {
3399 error_report("Usage: -virtfs fsdriver,mount_tag=tag");
3402 fsdev
= qemu_opts_create(qemu_find_opts("fsdev"),
3403 qemu_opts_id(opts
) ?:
3404 qemu_opt_get(opts
, "mount_tag"),
3407 error_report("duplicate or invalid fsdev id: %s",
3408 qemu_opt_get(opts
, "mount_tag"));
3412 writeout
= qemu_opt_get(opts
, "writeout");
3414 #ifdef CONFIG_SYNC_FILE_RANGE
3415 qemu_opt_set(fsdev
, "writeout", writeout
, &error_abort
);
3417 error_report("writeout=immediate not supported "
3418 "on this platform");
3422 qemu_opt_set(fsdev
, "fsdriver",
3423 qemu_opt_get(opts
, "fsdriver"), &error_abort
);
3424 path
= qemu_opt_get(opts
, "path");
3426 qemu_opt_set(fsdev
, "path", path
, &error_abort
);
3428 security_model
= qemu_opt_get(opts
, "security_model");
3429 if (security_model
) {
3430 qemu_opt_set(fsdev
, "security_model", security_model
,
3433 socket
= qemu_opt_get(opts
, "socket");
3435 qemu_opt_set(fsdev
, "socket", socket
, &error_abort
);
3437 sock_fd
= qemu_opt_get(opts
, "sock_fd");
3439 qemu_opt_set(fsdev
, "sock_fd", sock_fd
, &error_abort
);
3442 qemu_opt_set_bool(fsdev
, "readonly",
3443 qemu_opt_get_bool(opts
, "readonly", 0),
3445 device
= qemu_opts_create(qemu_find_opts("device"), NULL
, 0,
3447 qemu_opt_set(device
, "driver", "virtio-9p-pci", &error_abort
);
3448 qemu_opt_set(device
, "fsdev",
3449 qemu_opts_id(fsdev
), &error_abort
);
3450 qemu_opt_set(device
, "mount_tag",
3451 qemu_opt_get(opts
, "mount_tag"), &error_abort
);
3454 case QEMU_OPTION_virtfs_synth
: {
3458 warn_report("'-virtfs_synth' is deprecated, please use "
3459 "'-fsdev synth' and '-device virtio-9p-...' "
3462 fsdev
= qemu_opts_create(qemu_find_opts("fsdev"), "v_synth",
3465 error_report("duplicate option: %s", "virtfs_synth");
3468 qemu_opt_set(fsdev
, "fsdriver", "synth", &error_abort
);
3470 device
= qemu_opts_create(qemu_find_opts("device"), NULL
, 0,
3472 qemu_opt_set(device
, "driver", "virtio-9p-pci", &error_abort
);
3473 qemu_opt_set(device
, "fsdev", "v_synth", &error_abort
);
3474 qemu_opt_set(device
, "mount_tag", "v_synth", &error_abort
);
3477 case QEMU_OPTION_serial
:
3478 add_device_config(DEV_SERIAL
, optarg
);
3480 if (strncmp(optarg
, "mon:", 4) == 0) {
3481 default_monitor
= 0;
3484 case QEMU_OPTION_watchdog
:
3486 error_report("only one watchdog option may be given");
3491 case QEMU_OPTION_watchdog_action
:
3492 if (select_watchdog_action(optarg
) == -1) {
3493 error_report("unknown -watchdog-action parameter");
3497 case QEMU_OPTION_parallel
:
3498 add_device_config(DEV_PARALLEL
, optarg
);
3499 default_parallel
= 0;
3500 if (strncmp(optarg
, "mon:", 4) == 0) {
3501 default_monitor
= 0;
3504 case QEMU_OPTION_debugcon
:
3505 add_device_config(DEV_DEBUGCON
, optarg
);
3507 case QEMU_OPTION_loadvm
:
3510 case QEMU_OPTION_full_screen
:
3511 dpy
.has_full_screen
= true;
3512 dpy
.full_screen
= true;
3514 case QEMU_OPTION_alt_grab
:
3517 case QEMU_OPTION_ctrl_grab
:
3520 case QEMU_OPTION_no_quit
:
3521 dpy
.has_window_close
= true;
3522 dpy
.window_close
= false;
3524 case QEMU_OPTION_sdl
:
3526 dpy
.type
= DISPLAY_TYPE_SDL
;
3529 error_report("SDL support is disabled");
3532 case QEMU_OPTION_pidfile
:
3535 case QEMU_OPTION_win2k_hack
:
3536 win2k_install_hack
= 1;
3538 case QEMU_OPTION_acpitable
:
3539 opts
= qemu_opts_parse_noisily(qemu_find_opts("acpi"),
3544 acpi_table_add(opts
, &error_fatal
);
3546 case QEMU_OPTION_smbios
:
3547 opts
= qemu_opts_parse_noisily(qemu_find_opts("smbios"),
3552 smbios_entry_add(opts
, &error_fatal
);
3554 case QEMU_OPTION_fwcfg
:
3555 opts
= qemu_opts_parse_noisily(qemu_find_opts("fw_cfg"),
3561 case QEMU_OPTION_preconfig
:
3562 preconfig_exit_requested
= false;
3564 case QEMU_OPTION_enable_kvm
:
3565 olist
= qemu_find_opts("machine");
3566 qemu_opts_parse_noisily(olist
, "accel=kvm", false);
3569 case QEMU_OPTION_machine
:
3570 olist
= qemu_find_opts("machine");
3571 opts
= qemu_opts_parse_noisily(olist
, optarg
, true);
3576 case QEMU_OPTION_no_kvm
:
3577 olist
= qemu_find_opts("machine");
3578 qemu_opts_parse_noisily(olist
, "accel=tcg", false);
3580 case QEMU_OPTION_accel
:
3581 accel_opts
= qemu_opts_parse_noisily(qemu_find_opts("accel"),
3583 optarg
= qemu_opt_get(accel_opts
, "accel");
3584 if (!optarg
|| is_help_option(optarg
)) {
3585 printf("Accelerators supported in QEMU binary:\n");
3586 GSList
*el
, *accel_list
= object_class_get_list(TYPE_ACCEL
,
3588 for (el
= accel_list
; el
; el
= el
->next
) {
3589 gchar
*typename
= g_strdup(object_class_get_name(
3590 OBJECT_CLASS(el
->data
)));
3591 /* omit qtest which is used for tests only */
3592 if (g_strcmp0(typename
, ACCEL_CLASS_NAME("qtest")) &&
3593 g_str_has_suffix(typename
, ACCEL_CLASS_SUFFIX
)) {
3594 gchar
**optname
= g_strsplit(typename
,
3595 ACCEL_CLASS_SUFFIX
, 0);
3596 printf("%s\n", optname
[0]);
3601 g_slist_free(accel_list
);
3604 opts
= qemu_opts_create(qemu_find_opts("machine"), NULL
,
3605 false, &error_abort
);
3606 qemu_opt_set(opts
, "accel", optarg
, &error_abort
);
3608 case QEMU_OPTION_usb
:
3609 olist
= qemu_find_opts("machine");
3610 qemu_opts_parse_noisily(olist
, "usb=on", false);
3612 case QEMU_OPTION_usbdevice
:
3613 error_report("'-usbdevice' is deprecated, please use "
3614 "'-device usb-...' instead");
3615 olist
= qemu_find_opts("machine");
3616 qemu_opts_parse_noisily(olist
, "usb=on", false);
3617 add_device_config(DEV_USB
, optarg
);
3619 case QEMU_OPTION_device
:
3620 if (!qemu_opts_parse_noisily(qemu_find_opts("device"),
3625 case QEMU_OPTION_smp
:
3626 if (!qemu_opts_parse_noisily(qemu_find_opts("smp-opts"),
3631 case QEMU_OPTION_vnc
:
3632 vnc_parse(optarg
, &error_fatal
);
3634 case QEMU_OPTION_no_acpi
:
3637 case QEMU_OPTION_no_hpet
:
3640 case QEMU_OPTION_no_reboot
:
3643 case QEMU_OPTION_no_shutdown
:
3646 case QEMU_OPTION_show_cursor
:
3649 case QEMU_OPTION_uuid
:
3650 if (qemu_uuid_parse(optarg
, &qemu_uuid
) < 0) {
3651 error_report("failed to parse UUID string: wrong format");
3654 qemu_uuid_set
= true;
3656 case QEMU_OPTION_option_rom
:
3657 if (nb_option_roms
>= MAX_OPTION_ROMS
) {
3658 error_report("too many option ROMs");
3661 opts
= qemu_opts_parse_noisily(qemu_find_opts("option-rom"),
3666 option_rom
[nb_option_roms
].name
= qemu_opt_get(opts
, "romfile");
3667 option_rom
[nb_option_roms
].bootindex
=
3668 qemu_opt_get_number(opts
, "bootindex", -1);
3669 if (!option_rom
[nb_option_roms
].name
) {
3670 error_report("Option ROM file is not specified");
3675 case QEMU_OPTION_semihosting
:
3676 qemu_semihosting_enable();
3678 case QEMU_OPTION_semihosting_config
:
3679 if (qemu_semihosting_config_options(optarg
) != 0) {
3683 case QEMU_OPTION_name
:
3684 opts
= qemu_opts_parse_noisily(qemu_find_opts("name"),
3690 case QEMU_OPTION_prom_env
:
3691 if (nb_prom_envs
>= MAX_PROM_ENVS
) {
3692 error_report("too many prom variables");
3695 prom_envs
[nb_prom_envs
] = optarg
;
3698 case QEMU_OPTION_old_param
:
3701 case QEMU_OPTION_rtc
:
3702 opts
= qemu_opts_parse_noisily(qemu_find_opts("rtc"), optarg
,
3708 case QEMU_OPTION_tb_size
:
3710 error_report("TCG is disabled");
3713 if (qemu_strtoul(optarg
, NULL
, 0, &tcg_tb_size
) < 0) {
3714 error_report("Invalid argument to -tb-size");
3718 case QEMU_OPTION_icount
:
3719 icount_opts
= qemu_opts_parse_noisily(qemu_find_opts("icount"),
3725 case QEMU_OPTION_incoming
:
3727 runstate_set(RUN_STATE_INMIGRATE
);
3731 case QEMU_OPTION_only_migratable
:
3732 only_migratable
= 1;
3734 case QEMU_OPTION_nodefaults
:
3737 case QEMU_OPTION_xen_domid
:
3738 if (!(xen_available())) {
3739 error_report("Option not supported for this target");
3742 xen_domid
= atoi(optarg
);
3744 case QEMU_OPTION_xen_attach
:
3745 if (!(xen_available())) {
3746 error_report("Option not supported for this target");
3749 xen_mode
= XEN_ATTACH
;
3751 case QEMU_OPTION_xen_domid_restrict
:
3752 if (!(xen_available())) {
3753 error_report("Option not supported for this target");
3756 xen_domid_restrict
= true;
3758 case QEMU_OPTION_trace
:
3760 trace_file
= trace_opt_parse(optarg
);
3762 case QEMU_OPTION_readconfig
:
3764 int ret
= qemu_read_config_file(optarg
);
3766 error_report("read config %s: %s", optarg
,
3772 case QEMU_OPTION_spice
:
3773 olist
= qemu_find_opts("spice");
3775 error_report("spice support is disabled");
3778 opts
= qemu_opts_parse_noisily(olist
, optarg
, false);
3784 case QEMU_OPTION_writeconfig
:
3787 if (strcmp(optarg
, "-") == 0) {
3790 fp
= fopen(optarg
, "w");
3792 error_report("open %s: %s", optarg
,
3797 qemu_config_write(fp
);
3803 case QEMU_OPTION_qtest
:
3804 qtest_chrdev
= optarg
;
3806 case QEMU_OPTION_qtest_log
:
3809 case QEMU_OPTION_sandbox
:
3810 olist
= qemu_find_opts("sandbox");
3812 #ifndef CONFIG_SECCOMP
3813 error_report("-sandbox support is not enabled "
3814 "in this QEMU binary");
3819 opts
= qemu_opts_parse_noisily(olist
, optarg
, true);
3824 case QEMU_OPTION_add_fd
:
3826 opts
= qemu_opts_parse_noisily(qemu_find_opts("add-fd"),
3832 error_report("File descriptor passing is disabled on this "
3837 case QEMU_OPTION_object
:
3838 opts
= qemu_opts_parse_noisily(qemu_find_opts("object"),
3844 case QEMU_OPTION_realtime
:
3845 warn_report("'-realtime mlock=...' is deprecated, please use "
3846 "'-overcommit mem-lock=...' instead");
3847 opts
= qemu_opts_parse_noisily(qemu_find_opts("realtime"),
3852 /* Don't override the -overcommit option if set */
3853 enable_mlock
= enable_mlock
||
3854 qemu_opt_get_bool(opts
, "mlock", true);
3856 case QEMU_OPTION_overcommit
:
3857 opts
= qemu_opts_parse_noisily(qemu_find_opts("overcommit"),
3862 /* Don't override the -realtime option if set */
3863 enable_mlock
= enable_mlock
||
3864 qemu_opt_get_bool(opts
, "mem-lock", false);
3865 enable_cpu_pm
= qemu_opt_get_bool(opts
, "cpu-pm", false);
3867 case QEMU_OPTION_msg
:
3868 opts
= qemu_opts_parse_noisily(qemu_find_opts("msg"), optarg
,
3873 configure_msg(opts
);
3875 case QEMU_OPTION_dump_vmstate
:
3876 if (vmstate_dump_file
) {
3877 error_report("only one '-dump-vmstate' "
3878 "option may be given");
3881 vmstate_dump_file
= fopen(optarg
, "w");
3882 if (vmstate_dump_file
== NULL
) {
3883 error_report("open %s: %s", optarg
, strerror(errno
));
3887 case QEMU_OPTION_enable_sync_profile
:
3890 case QEMU_OPTION_nouserconfig
:
3891 /* Nothing to be parsed here. Especially, do not error out below. */
3894 if (os_parse_cmd_args(popt
->index
, optarg
)) {
3895 error_report("Option not supported in this build");
3902 * Clear error location left behind by the loop.
3903 * Best done right after the loop. Do not insert code here!
3907 user_register_global_props();
3909 replay_configure(icount_opts
);
3911 if (incoming
&& !preconfig_exit_requested
) {
3912 error_report("'preconfig' and 'incoming' options are "
3913 "mutually exclusive");
3917 configure_rtc(qemu_find_opts_singleton("rtc"));
3919 machine_class
= select_machine();
3920 object_set_machine_compat_props(machine_class
->compat_props
);
3922 set_memory_options(&ram_slots
, &maxram_size
, machine_class
);
3925 rcu_disable_atfork();
3927 if (pid_file
&& !qemu_write_pidfile(pid_file
, &err
)) {
3928 error_reportf_err(err
, "cannot create PID file: ");
3932 qemu_unlink_pidfile_notifier
.notify
= qemu_unlink_pidfile
;
3933 qemu_add_exit_notifier(&qemu_unlink_pidfile_notifier
);
3935 if (qemu_init_main_loop(&main_loop_err
)) {
3936 error_report_err(main_loop_err
);
3940 #ifdef CONFIG_SECCOMP
3941 olist
= qemu_find_opts_err("sandbox", NULL
);
3943 qemu_opts_foreach(olist
, parse_sandbox
, NULL
, &error_fatal
);
3947 qemu_opts_foreach(qemu_find_opts("name"),
3948 parse_name
, NULL
, &error_fatal
);
3951 qemu_opts_foreach(qemu_find_opts("add-fd"),
3952 parse_add_fd
, NULL
, &error_fatal
);
3954 qemu_opts_foreach(qemu_find_opts("add-fd"),
3955 cleanup_add_fd
, NULL
, &error_fatal
);
3958 current_machine
= MACHINE(object_new(object_class_get_name(
3959 OBJECT_CLASS(machine_class
))));
3960 if (machine_help_func(qemu_get_machine_opts(), current_machine
)) {
3963 object_property_add_child(object_get_root(), "machine",
3964 OBJECT(current_machine
), &error_abort
);
3965 object_property_add_child(container_get(OBJECT(current_machine
),
3967 "sysbus", OBJECT(sysbus_get_default()),
3970 if (machine_class
->minimum_page_bits
) {
3971 if (!set_preferred_target_page_bits(machine_class
->minimum_page_bits
)) {
3972 /* This would be a board error: specifying a minimum smaller than
3973 * a target's compile-time fixed setting.
3975 g_assert_not_reached();
3979 cpu_exec_init_all();
3981 if (machine_class
->hw_version
) {
3982 qemu_set_hw_version(machine_class
->hw_version
);
3985 if (cpu_option
&& is_help_option(cpu_option
)) {
3986 list_cpus(cpu_option
);
3990 if (!trace_init_backends()) {
3993 trace_init_file(trace_file
);
3995 /* Open the logfile at this point and set the log mask if necessary.
3998 qemu_set_log_filename(log_file
, &error_fatal
);
4003 mask
= qemu_str_to_log_mask(log_mask
);
4005 qemu_print_log_usage(stdout
);
4013 /* add configured firmware directories */
4014 dirs
= g_strsplit(CONFIG_QEMU_FIRMWAREPATH
, G_SEARCHPATH_SEPARATOR_S
, 0);
4015 for (i
= 0; dirs
[i
] != NULL
; i
++) {
4016 qemu_add_data_dir(dirs
[i
]);
4020 /* try to find datadir relative to the executable path */
4021 dir
= os_find_datadir();
4022 qemu_add_data_dir(dir
);
4025 /* add the datadir specified when building */
4026 qemu_add_data_dir(CONFIG_QEMU_DATADIR
);
4028 /* -L help lists the data directories and exits. */
4029 if (list_data_dirs
) {
4030 for (i
= 0; i
< data_dir_idx
; i
++) {
4031 printf("%s\n", data_dir
[i
]);
4036 /* machine_class: default to UP */
4037 machine_class
->max_cpus
= machine_class
->max_cpus
?: 1;
4038 machine_class
->min_cpus
= machine_class
->min_cpus
?: 1;
4039 machine_class
->default_cpus
= machine_class
->default_cpus
?: 1;
4041 /* default to machine_class->default_cpus */
4042 smp_cpus
= machine_class
->default_cpus
;
4043 max_cpus
= machine_class
->default_cpus
;
4045 smp_parse(qemu_opts_find(qemu_find_opts("smp-opts"), NULL
));
4047 /* sanity-check smp_cpus and max_cpus against machine_class */
4048 if (smp_cpus
< machine_class
->min_cpus
) {
4049 error_report("Invalid SMP CPUs %d. The min CPUs "
4050 "supported by machine '%s' is %d", smp_cpus
,
4051 machine_class
->name
, machine_class
->min_cpus
);
4054 if (max_cpus
> machine_class
->max_cpus
) {
4055 error_report("Invalid SMP CPUs %d. The max CPUs "
4056 "supported by machine '%s' is %d", max_cpus
,
4057 machine_class
->name
, machine_class
->max_cpus
);
4062 * Get the default machine options from the machine if it is not already
4063 * specified either by the configuration file or by the command line.
4065 if (machine_class
->default_machine_opts
) {
4066 qemu_opts_set_defaults(qemu_find_opts("machine"),
4067 machine_class
->default_machine_opts
, 0);
4070 qemu_opts_foreach(qemu_find_opts("device"),
4071 default_driver_check
, NULL
, NULL
);
4072 qemu_opts_foreach(qemu_find_opts("global"),
4073 default_driver_check
, NULL
, NULL
);
4075 if (!vga_model
&& !default_vga
) {
4076 vga_interface_type
= VGA_DEVICE
;
4078 if (!has_defaults
|| machine_class
->no_serial
) {
4081 if (!has_defaults
|| machine_class
->no_parallel
) {
4082 default_parallel
= 0;
4084 if (!has_defaults
|| machine_class
->no_floppy
) {
4087 if (!has_defaults
|| machine_class
->no_cdrom
) {
4090 if (!has_defaults
|| machine_class
->no_sdcard
) {
4093 if (!has_defaults
) {
4094 default_monitor
= 0;
4099 if (is_daemonized()) {
4100 if (!preconfig_exit_requested
) {
4101 error_report("'preconfig' and 'daemonize' options are "
4102 "mutually exclusive");
4106 /* According to documentation and historically, -nographic redirects
4107 * serial port, parallel port and monitor to stdio, which does not work
4108 * with -daemonize. We can redirect these to null instead, but since
4109 * -nographic is legacy, let's just error out.
4110 * We disallow -nographic only if all other ports are not redirected
4111 * explicitly, to not break existing legacy setups which uses
4112 * -nographic _and_ redirects all ports explicitly - this is valid
4113 * usage, -nographic is just a no-op in this case.
4116 && (default_parallel
|| default_serial
|| default_monitor
)) {
4117 error_report("-nographic cannot be used with -daemonize");
4120 #ifdef CONFIG_CURSES
4121 if (dpy
.type
== DISPLAY_TYPE_CURSES
) {
4122 error_report("curses display cannot be used with -daemonize");
4129 if (default_parallel
)
4130 add_device_config(DEV_PARALLEL
, "null");
4131 if (default_serial
&& default_monitor
) {
4132 add_device_config(DEV_SERIAL
, "mon:stdio");
4135 add_device_config(DEV_SERIAL
, "stdio");
4136 if (default_monitor
)
4137 monitor_parse("stdio", "readline", false);
4141 add_device_config(DEV_SERIAL
, "vc:80Cx24C");
4142 if (default_parallel
)
4143 add_device_config(DEV_PARALLEL
, "vc:80Cx24C");
4144 if (default_monitor
)
4145 monitor_parse("vc:80Cx24C", "readline", false);
4148 #if defined(CONFIG_VNC)
4149 if (!QTAILQ_EMPTY(&(qemu_find_opts("vnc")->head
))) {
4153 if (dpy
.type
== DISPLAY_TYPE_DEFAULT
&& !display_remote
) {
4154 if (!qemu_display_find_default(&dpy
)) {
4155 dpy
.type
= DISPLAY_TYPE_NONE
;
4156 #if defined(CONFIG_VNC)
4157 vnc_parse("localhost:0,to=99,id=default", &error_abort
);
4161 if (dpy
.type
== DISPLAY_TYPE_DEFAULT
) {
4162 dpy
.type
= DISPLAY_TYPE_NONE
;
4165 if ((alt_grab
|| ctrl_grab
) && dpy
.type
!= DISPLAY_TYPE_SDL
) {
4166 error_report("-alt-grab and -ctrl-grab are only valid "
4167 "for SDL, ignoring option");
4169 if (dpy
.has_window_close
&&
4170 (dpy
.type
!= DISPLAY_TYPE_GTK
&& dpy
.type
!= DISPLAY_TYPE_SDL
)) {
4171 error_report("-no-quit is only valid for GTK and SDL, "
4175 qemu_display_early_init(&dpy
);
4176 qemu_console_early_init();
4178 if (dpy
.has_gl
&& dpy
.gl
!= DISPLAYGL_MODE_OFF
&& display_opengl
== 0) {
4179 #if defined(CONFIG_OPENGL)
4180 error_report("OpenGL is not supported by the display");
4182 error_report("OpenGL support is disabled");
4190 qemu_opts_foreach(qemu_find_opts("object"),
4191 user_creatable_add_opts_foreach
,
4192 object_create_initial
, &error_fatal
);
4194 qemu_opts_foreach(qemu_find_opts("chardev"),
4195 chardev_init_func
, NULL
, &error_fatal
);
4196 /* now chardevs have been created we may have semihosting to connect */
4197 qemu_semihosting_connect_chardevs();
4199 #ifdef CONFIG_VIRTFS
4200 qemu_opts_foreach(qemu_find_opts("fsdev"),
4201 fsdev_init_func
, NULL
, &error_fatal
);
4204 if (qemu_opts_foreach(qemu_find_opts("device"),
4205 device_help_func
, NULL
, NULL
)) {
4210 * Note: we need to create block backends before
4211 * machine_set_property(), so machine properties can refer to
4214 configure_blockdev(&bdo_queue
, machine_class
, snapshot
);
4216 machine_opts
= qemu_get_machine_opts();
4217 qemu_opt_foreach(machine_opts
, machine_set_property
, current_machine
,
4219 current_machine
->ram_size
= ram_size
;
4220 current_machine
->maxram_size
= maxram_size
;
4221 current_machine
->ram_slots
= ram_slots
;
4224 * Note: uses machine properties such as kernel-irqchip, must run
4225 * after machine_set_property().
4227 configure_accelerator(current_machine
, argv
[0]);
4230 * Beware, QOM objects created before this point miss global and
4231 * compat properties.
4233 * Global properties get set up by qdev_prop_register_global(),
4234 * called from user_register_global_props(), and certain option
4235 * desugaring. Also in CPU feature desugaring (buried in
4236 * parse_cpu_option()), which happens below this point, but may
4237 * only target the CPU type, which can only be created after
4238 * parse_cpu_option() returned the type.
4240 * Machine compat properties: object_set_machine_compat_props().
4241 * Accelerator compat props: object_set_accelerator_compat_props(),
4242 * called from configure_accelerator().
4245 if (!qtest_enabled() && machine_class
->deprecation_reason
) {
4246 error_report("Machine type '%s' is deprecated: %s",
4247 machine_class
->name
, machine_class
->deprecation_reason
);
4251 * Note: creates a QOM object, must run only after global and
4252 * compat properties have been set up.
4254 migration_object_init();
4257 qtest_init(qtest_chrdev
, qtest_log
, &error_fatal
);
4260 machine_opts
= qemu_get_machine_opts();
4261 kernel_filename
= qemu_opt_get(machine_opts
, "kernel");
4262 initrd_filename
= qemu_opt_get(machine_opts
, "initrd");
4263 kernel_cmdline
= qemu_opt_get(machine_opts
, "append");
4264 bios_name
= qemu_opt_get(machine_opts
, "firmware");
4266 opts
= qemu_opts_find(qemu_find_opts("boot-opts"), NULL
);
4268 boot_order
= qemu_opt_get(opts
, "order");
4270 validate_bootdevices(boot_order
, &error_fatal
);
4273 boot_once
= qemu_opt_get(opts
, "once");
4275 validate_bootdevices(boot_once
, &error_fatal
);
4278 boot_menu
= qemu_opt_get_bool(opts
, "menu", boot_menu
);
4279 boot_strict
= qemu_opt_get_bool(opts
, "strict", false);
4283 boot_order
= machine_class
->default_boot_order
;
4286 if (!kernel_cmdline
) {
4287 kernel_cmdline
= "";
4288 current_machine
->kernel_cmdline
= (char *)kernel_cmdline
;
4291 linux_boot
= (kernel_filename
!= NULL
);
4293 if (!linux_boot
&& *kernel_cmdline
!= '\0') {
4294 error_report("-append only allowed with -kernel option");
4298 if (!linux_boot
&& initrd_filename
!= NULL
) {
4299 error_report("-initrd only allowed with -kernel option");
4303 if (semihosting_enabled() && !semihosting_get_argc() && kernel_filename
) {
4304 /* fall back to the -kernel/-append */
4305 semihosting_arg_fallback(kernel_filename
, kernel_cmdline
);
4308 os_set_line_buffering();
4310 /* spice needs the timers to be initialized by this point */
4315 if (!tcg_enabled()) {
4316 error_report("-icount is not allowed with hardware virtualization");
4319 configure_icount(icount_opts
, &error_abort
);
4320 qemu_opts_del(icount_opts
);
4323 if (tcg_enabled()) {
4324 qemu_tcg_configure(accel_opts
, &error_fatal
);
4328 QemuOptsList
*net
= qemu_find_opts("net");
4329 qemu_opts_set(net
, NULL
, "type", "nic", &error_abort
);
4331 qemu_opts_set(net
, NULL
, "type", "user", &error_abort
);
4335 if (net_init_clients(&err
) < 0) {
4336 error_report_err(err
);
4340 qemu_opts_foreach(qemu_find_opts("object"),
4341 user_creatable_add_opts_foreach
,
4342 object_create_delayed
, &error_fatal
);
4346 /* init the bluetooth world */
4347 if (foreach_device_config(DEV_BT
, bt_parse
))
4350 if (!xen_enabled()) {
4351 /* On 32-bit hosts, QEMU is limited by virtual address space */
4352 if (ram_size
> (2047 << 20) && HOST_LONG_BITS
== 32) {
4353 error_report("at most 2047 MB RAM can be simulated");
4360 dirty_bitmap_mig_init();
4362 qemu_opts_foreach(qemu_find_opts("mon"),
4363 mon_init_func
, NULL
, &error_fatal
);
4365 if (foreach_device_config(DEV_SERIAL
, serial_parse
) < 0)
4367 if (foreach_device_config(DEV_PARALLEL
, parallel_parse
) < 0)
4369 if (foreach_device_config(DEV_DEBUGCON
, debugcon_parse
) < 0)
4372 /* If no default VGA is requested, the default is "none". */
4374 vga_model
= get_default_vga_model(machine_class
);
4377 select_vgahw(machine_class
, vga_model
);
4381 i
= select_watchdog(watchdog
);
4383 exit (i
== 1 ? 1 : 0);
4386 /* This checkpoint is required by replay to separate prior clock
4387 reading from the other reads, because timer polling functions query
4388 clock values from the log. */
4389 replay_checkpoint(CHECKPOINT_INIT
);
4390 qdev_machine_init();
4392 current_machine
->boot_order
= boot_order
;
4394 /* parse features once if machine provides default cpu_type */
4395 current_machine
->cpu_type
= machine_class
->default_cpu_type
;
4397 current_machine
->cpu_type
= parse_cpu_option(cpu_option
);
4399 parse_numa_opts(current_machine
);
4401 /* do monitor/qmp handling at preconfig state if requested */
4404 audio_init_audiodevs();
4406 /* from here on runstate is RUN_STATE_PRELAUNCH */
4407 machine_run_board_init(current_machine
);
4413 if (hax_enabled()) {
4417 qemu_opts_foreach(qemu_find_opts("fw_cfg"),
4418 parse_fw_cfg
, fw_cfg_find(), &error_fatal
);
4420 /* init USB devices */
4421 if (machine_usb(current_machine
)) {
4422 if (foreach_device_config(DEV_USB
, usb_parse
) < 0)
4426 /* Check if IGD GFX passthrough. */
4429 /* init generic devices */
4430 rom_set_order_override(FW_CFG_ORDER_OVERRIDE_DEVICE
);
4431 qemu_opts_foreach(qemu_find_opts("device"),
4432 device_init_func
, NULL
, &error_fatal
);
4434 cpu_synchronize_all_post_init();
4436 rom_reset_order_override();
4438 /* Did we create any drives that we failed to create a device for? */
4439 drive_check_orphaned();
4441 /* Don't warn about the default network setup that you get if
4442 * no command line -net or -netdev options are specified. There
4443 * are two cases that we would otherwise complain about:
4444 * (1) board doesn't support a NIC but the implicit "-net nic"
4446 * (2) CONFIG_SLIRP not set, in which case the implicit "-net nic"
4447 * sets up a nic that isn't connected to anything.
4449 if (!default_net
&& (!qtest_enabled() || has_defaults
)) {
4450 net_check_clients();
4454 qemu_boot_set(boot_once
, &error_fatal
);
4455 qemu_register_reset(restore_boot_order
, g_strdup(boot_order
));
4458 /* init local displays */
4459 ds
= init_displaystate();
4460 qemu_display_init(ds
, &dpy
);
4462 /* must be after terminal init, SDL library changes signal handlers */
4463 os_setup_signal_handling();
4465 /* init remote displays */
4467 qemu_opts_foreach(qemu_find_opts("vnc"),
4468 vnc_init_func
, NULL
, &error_fatal
);
4472 qemu_spice_display_init();
4475 if (foreach_device_config(DEV_GDB
, gdbserver_start
) < 0) {
4479 qdev_machine_creation_done();
4481 /* TODO: once all bus devices are qdevified, this should be done
4482 * when bus is created by qdev.c */
4483 qemu_register_reset(qbus_reset_all_fn
, sysbus_get_default());
4484 qemu_run_machine_init_done_notifiers();
4486 if (rom_check_and_register_reset() != 0) {
4487 error_report("rom check and register reset failed");
4493 /* This checkpoint is required by replay to separate prior clock
4494 reading from the other reads, because timer polling functions query
4495 clock values from the log. */
4496 replay_checkpoint(CHECKPOINT_RESET
);
4497 qemu_system_reset(SHUTDOWN_CAUSE_NONE
);
4498 register_global_state();
4500 Error
*local_err
= NULL
;
4501 if (load_snapshot(loadvm
, &local_err
) < 0) {
4502 error_report_err(local_err
);
4507 if (replay_mode
!= REPLAY_MODE_NONE
) {
4508 replay_vmstate_init();
4511 qdev_prop_check_globals();
4512 if (vmstate_dump_file
) {
4514 dump_vmstate_json_to_file(vmstate_dump_file
);
4519 Error
*local_err
= NULL
;
4520 qemu_start_incoming_migration(incoming
, &local_err
);
4522 error_reportf_err(local_err
, "-incoming %s: ", incoming
);
4525 } else if (autostart
) {
4529 accel_setup_post(current_machine
);
4534 gdbserver_cleanup();
4537 * cleaning up the migration object cancels any existing migration
4538 * try to do this early so that it also stops using devices.
4540 migration_shutdown();
4542 /* No more vcpu or device emulation activity beyond this point */
4545 job_cancel_sync_all();
4550 /* vhost-user must be cleaned up before chardevs. */
4556 user_creatable_cleanup();
4557 /* TODO: unref root container, check all devices are ok */