4 * Copyright (c) 2003-2008 Fabrice Bellard
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 #include "qemu/osdep.h"
26 #include "qemu-common.h"
27 #include "qemu/datadir.h"
28 #include "qemu/units.h"
29 #include "exec/cpu-common.h"
30 #include "hw/qdev-properties.h"
31 #include "qapi/compat-policy.h"
32 #include "qapi/error.h"
33 #include "qapi/qmp/qdict.h"
34 #include "qapi/qmp/qjson.h"
35 #include "qemu-version.h"
36 #include "qemu/cutils.h"
37 #include "qemu/help_option.h"
38 #include "qemu/uuid.h"
39 #include "sysemu/reset.h"
40 #include "sysemu/runstate.h"
41 #include "sysemu/runstate-action.h"
42 #include "sysemu/seccomp.h"
43 #include "sysemu/tcg.h"
44 #include "sysemu/xen.h"
46 #include "qemu/error-report.h"
47 #include "qemu/sockets.h"
48 #include "qemu/accel.h"
50 #include "hw/isa/isa.h"
51 #include "hw/scsi/scsi.h"
52 #include "hw/display/vga.h"
53 #include "sysemu/watchdog.h"
54 #include "hw/firmware/smbios.h"
55 #include "hw/acpi/acpi.h"
56 #include "hw/xen/xen.h"
57 #include "hw/loader.h"
58 #include "monitor/qdev.h"
60 #include "net/slirp.h"
61 #include "monitor/monitor.h"
62 #include "ui/console.h"
64 #include "sysemu/sysemu.h"
65 #include "sysemu/numa.h"
66 #include "sysemu/hostmem.h"
67 #include "exec/gdbstub.h"
68 #include "qemu/timer.h"
69 #include "chardev/char.h"
70 #include "qemu/bitmap.h"
72 #include "sysemu/blockdev.h"
73 #include "hw/block/block.h"
74 #include "hw/i386/x86.h"
75 #include "hw/i386/pc.h"
76 #include "migration/misc.h"
77 #include "migration/snapshot.h"
78 #include "sysemu/tpm.h"
79 #include "sysemu/dma.h"
80 #include "hw/audio/soundhw.h"
81 #include "audio/audio.h"
82 #include "sysemu/cpus.h"
83 #include "sysemu/cpu-timers.h"
84 #include "migration/colo.h"
85 #include "migration/postcopy-ram.h"
86 #include "sysemu/kvm.h"
87 #include "sysemu/hax.h"
88 #include "qapi/qobject-input-visitor.h"
89 #include "qemu/option.h"
90 #include "qemu/config-file.h"
91 #include "qemu/qemu-options.h"
92 #include "qemu/main-loop.h"
94 #include "fsdev/qemu-fsdev.h"
96 #include "sysemu/qtest.h"
98 #include "disas/disas.h"
101 #include "trace/control.h"
102 #include "qemu/plugin.h"
103 #include "qemu/queue.h"
104 #include "sysemu/arch_init.h"
105 #include "exec/confidential-guest-support.h"
107 #include "ui/qemu-spice.h"
108 #include "qapi/string-input-visitor.h"
109 #include "qapi/opts-visitor.h"
110 #include "qapi/clone-visitor.h"
111 #include "qom/object_interfaces.h"
112 #include "semihosting/semihost.h"
113 #include "crypto/init.h"
114 #include "sysemu/replay.h"
115 #include "qapi/qapi-events-run-state.h"
116 #include "qapi/qapi-visit-block-core.h"
117 #include "qapi/qapi-visit-compat.h"
118 #include "qapi/qapi-visit-ui.h"
119 #include "qapi/qapi-commands-block-core.h"
120 #include "qapi/qapi-commands-migration.h"
121 #include "qapi/qapi-commands-misc.h"
122 #include "qapi/qapi-visit-qom.h"
123 #include "qapi/qapi-commands-ui.h"
124 #include "qapi/qmp/qdict.h"
125 #include "qapi/qmp/qerror.h"
126 #include "sysemu/iothread.h"
127 #include "qemu/guest-random.h"
129 #define MAX_VIRTIO_CONSOLES 1
131 typedef struct BlockdevOptionsQueueEntry
{
132 BlockdevOptions
*bdo
;
134 QSIMPLEQ_ENTRY(BlockdevOptionsQueueEntry
) entry
;
135 } BlockdevOptionsQueueEntry
;
137 typedef QSIMPLEQ_HEAD(, BlockdevOptionsQueueEntry
) BlockdevOptionsQueue
;
139 typedef struct ObjectOption
{
141 QTAILQ_ENTRY(ObjectOption
) next
;
144 static const char *cpu_option
;
145 static const char *mem_path
;
146 static const char *incoming
;
147 static const char *loadvm
;
148 static QTAILQ_HEAD(, ObjectOption
) object_opts
= QTAILQ_HEAD_INITIALIZER(object_opts
);
149 static ram_addr_t maxram_size
;
150 static uint64_t ram_slots
;
151 static int display_remote
;
153 static bool preconfig_requested
;
154 static QemuPluginList plugin_list
= QTAILQ_HEAD_INITIALIZER(plugin_list
);
155 static BlockdevOptionsQueue bdo_queue
= QSIMPLEQ_HEAD_INITIALIZER(bdo_queue
);
156 static bool nographic
= false;
157 static int mem_prealloc
; /* force preallocation of physical target memory */
158 static ram_addr_t ram_size
;
159 static const char *vga_model
= NULL
;
160 static DisplayOptions dpy
;
161 static int num_serial_hds
;
162 static Chardev
**serial_hds
;
163 static const char *log_mask
;
164 static const char *log_file
;
165 static bool list_data_dirs
;
166 static const char *watchdog
;
167 static const char *qtest_chrdev
;
168 static const char *qtest_log
;
170 static int has_defaults
= 1;
171 static int default_serial
= 1;
172 static int default_parallel
= 1;
173 static int default_monitor
= 1;
174 static int default_floppy
= 1;
175 static int default_cdrom
= 1;
176 static int default_sdcard
= 1;
177 static int default_vga
= 1;
178 static int default_net
= 1;
184 { .driver
= "isa-serial", .flag
= &default_serial
},
185 { .driver
= "isa-parallel", .flag
= &default_parallel
},
186 { .driver
= "isa-fdc", .flag
= &default_floppy
},
187 { .driver
= "floppy", .flag
= &default_floppy
},
188 { .driver
= "ide-cd", .flag
= &default_cdrom
},
189 { .driver
= "ide-hd", .flag
= &default_cdrom
},
190 { .driver
= "scsi-cd", .flag
= &default_cdrom
},
191 { .driver
= "scsi-hd", .flag
= &default_cdrom
},
192 { .driver
= "VGA", .flag
= &default_vga
},
193 { .driver
= "isa-vga", .flag
= &default_vga
},
194 { .driver
= "cirrus-vga", .flag
= &default_vga
},
195 { .driver
= "isa-cirrus-vga", .flag
= &default_vga
},
196 { .driver
= "vmware-svga", .flag
= &default_vga
},
197 { .driver
= "qxl-vga", .flag
= &default_vga
},
198 { .driver
= "virtio-vga", .flag
= &default_vga
},
199 { .driver
= "ati-vga", .flag
= &default_vga
},
200 { .driver
= "vhost-user-vga", .flag
= &default_vga
},
203 static QemuOptsList qemu_rtc_opts
= {
205 .head
= QTAILQ_HEAD_INITIALIZER(qemu_rtc_opts
.head
),
210 .type
= QEMU_OPT_STRING
,
213 .type
= QEMU_OPT_STRING
,
216 .type
= QEMU_OPT_STRING
,
218 { /* end of list */ }
222 static QemuOptsList qemu_option_rom_opts
= {
223 .name
= "option-rom",
224 .implied_opt_name
= "romfile",
225 .head
= QTAILQ_HEAD_INITIALIZER(qemu_option_rom_opts
.head
),
229 .type
= QEMU_OPT_NUMBER
,
232 .type
= QEMU_OPT_STRING
,
234 { /* end of list */ }
238 static QemuOptsList qemu_machine_opts
= {
240 .implied_opt_name
= "type",
242 .head
= QTAILQ_HEAD_INITIALIZER(qemu_machine_opts
.head
),
245 * no elements => accept any
246 * sanity checking will happen later
247 * when setting machine properties
253 static QemuOptsList qemu_accel_opts
= {
255 .implied_opt_name
= "accel",
256 .head
= QTAILQ_HEAD_INITIALIZER(qemu_accel_opts
.head
),
259 * no elements => accept any
260 * sanity checking will happen later
261 * when setting accelerator properties
267 static QemuOptsList qemu_boot_opts
= {
269 .implied_opt_name
= "order",
271 .head
= QTAILQ_HEAD_INITIALIZER(qemu_boot_opts
.head
),
275 .type
= QEMU_OPT_STRING
,
278 .type
= QEMU_OPT_STRING
,
281 .type
= QEMU_OPT_BOOL
,
284 .type
= QEMU_OPT_STRING
,
286 .name
= "splash-time",
287 .type
= QEMU_OPT_NUMBER
,
289 .name
= "reboot-timeout",
290 .type
= QEMU_OPT_NUMBER
,
293 .type
= QEMU_OPT_BOOL
,
299 static QemuOptsList qemu_add_fd_opts
= {
301 .head
= QTAILQ_HEAD_INITIALIZER(qemu_add_fd_opts
.head
),
305 .type
= QEMU_OPT_NUMBER
,
306 .help
= "file descriptor of which a duplicate is added to fd set",
309 .type
= QEMU_OPT_NUMBER
,
310 .help
= "ID of the fd set to add fd to",
313 .type
= QEMU_OPT_STRING
,
314 .help
= "free-form string used to describe fd",
316 { /* end of list */ }
320 static QemuOptsList qemu_object_opts
= {
322 .implied_opt_name
= "qom-type",
323 .head
= QTAILQ_HEAD_INITIALIZER(qemu_object_opts
.head
),
329 static QemuOptsList qemu_tpmdev_opts
= {
331 .implied_opt_name
= "type",
332 .head
= QTAILQ_HEAD_INITIALIZER(qemu_tpmdev_opts
.head
),
334 /* options are defined in the TPM backends */
335 { /* end of list */ }
339 static QemuOptsList qemu_overcommit_opts
= {
340 .name
= "overcommit",
341 .head
= QTAILQ_HEAD_INITIALIZER(qemu_overcommit_opts
.head
),
345 .type
= QEMU_OPT_BOOL
,
349 .type
= QEMU_OPT_BOOL
,
351 { /* end of list */ }
355 static QemuOptsList qemu_msg_opts
= {
357 .head
= QTAILQ_HEAD_INITIALIZER(qemu_msg_opts
.head
),
361 .type
= QEMU_OPT_BOOL
,
364 .name
= "guest-name",
365 .type
= QEMU_OPT_BOOL
,
366 .help
= "Prepends guest name for error messages but only if "
367 "-name guest is set otherwise option is ignored\n",
369 { /* end of list */ }
373 static QemuOptsList qemu_name_opts
= {
375 .implied_opt_name
= "guest",
377 .head
= QTAILQ_HEAD_INITIALIZER(qemu_name_opts
.head
),
381 .type
= QEMU_OPT_STRING
,
382 .help
= "Sets the name of the guest.\n"
383 "This name will be displayed in the SDL window caption.\n"
384 "The name will also be used for the VNC server",
387 .type
= QEMU_OPT_STRING
,
388 .help
= "Sets the name of the QEMU process, as shown in top etc",
390 .name
= "debug-threads",
391 .type
= QEMU_OPT_BOOL
,
392 .help
= "When enabled, name the individual threads; defaults off.\n"
393 "NOTE: The thread names are for debugging and not a\n"
396 { /* End of list */ }
400 static QemuOptsList qemu_mem_opts
= {
402 .implied_opt_name
= "size",
403 .head
= QTAILQ_HEAD_INITIALIZER(qemu_mem_opts
.head
),
408 .type
= QEMU_OPT_SIZE
,
412 .type
= QEMU_OPT_NUMBER
,
416 .type
= QEMU_OPT_SIZE
,
418 { /* end of list */ }
422 static QemuOptsList qemu_icount_opts
= {
424 .implied_opt_name
= "shift",
426 .head
= QTAILQ_HEAD_INITIALIZER(qemu_icount_opts
.head
),
430 .type
= QEMU_OPT_STRING
,
433 .type
= QEMU_OPT_BOOL
,
436 .type
= QEMU_OPT_BOOL
,
439 .type
= QEMU_OPT_STRING
,
442 .type
= QEMU_OPT_STRING
,
444 .name
= "rrsnapshot",
445 .type
= QEMU_OPT_STRING
,
447 { /* end of list */ }
451 static QemuOptsList qemu_fw_cfg_opts
= {
453 .implied_opt_name
= "name",
454 .head
= QTAILQ_HEAD_INITIALIZER(qemu_fw_cfg_opts
.head
),
458 .type
= QEMU_OPT_STRING
,
459 .help
= "Sets the fw_cfg name of the blob to be inserted",
462 .type
= QEMU_OPT_STRING
,
463 .help
= "Sets the name of the file from which "
464 "the fw_cfg blob will be loaded",
467 .type
= QEMU_OPT_STRING
,
468 .help
= "Sets content of the blob to be inserted from a string",
471 .type
= QEMU_OPT_STRING
,
472 .help
= "Sets id of the object generating the fw_cfg blob "
475 { /* end of list */ }
479 static QemuOptsList qemu_action_opts
= {
482 .head
= QTAILQ_HEAD_INITIALIZER(qemu_action_opts
.head
),
486 .type
= QEMU_OPT_STRING
,
489 .type
= QEMU_OPT_STRING
,
492 .type
= QEMU_OPT_STRING
,
495 .type
= QEMU_OPT_STRING
,
497 { /* end of list */ }
502 * Get machine options
504 * Returns: machine options (never null).
506 static QemuOpts
*qemu_get_machine_opts(void)
508 return qemu_find_opts_singleton("machine");
511 const char *qemu_get_vm_name(void)
516 static int default_driver_check(void *opaque
, QemuOpts
*opts
, Error
**errp
)
518 const char *driver
= qemu_opt_get(opts
, "driver");
523 for (i
= 0; i
< ARRAY_SIZE(default_list
); i
++) {
524 if (strcmp(default_list
[i
].driver
, driver
) != 0)
526 *(default_list
[i
].flag
) = 0;
531 static int parse_name(void *opaque
, QemuOpts
*opts
, Error
**errp
)
533 const char *proc_name
;
535 if (qemu_opt_get(opts
, "debug-threads")) {
536 qemu_thread_naming(qemu_opt_get_bool(opts
, "debug-threads", false));
538 qemu_name
= qemu_opt_get(opts
, "guest");
540 proc_name
= qemu_opt_get(opts
, "process");
542 os_set_proc_name(proc_name
);
548 bool defaults_enabled(void)
554 static int parse_add_fd(void *opaque
, QemuOpts
*opts
, Error
**errp
)
556 int fd
, dupfd
, flags
;
558 const char *fd_opaque
= NULL
;
561 fd
= qemu_opt_get_number(opts
, "fd", -1);
562 fdset_id
= qemu_opt_get_number(opts
, "set", -1);
563 fd_opaque
= qemu_opt_get(opts
, "opaque");
566 error_setg(errp
, "fd option is required and must be non-negative");
570 if (fd
<= STDERR_FILENO
) {
571 error_setg(errp
, "fd cannot be a standard I/O stream");
576 * All fds inherited across exec() necessarily have FD_CLOEXEC
577 * clear, while qemu sets FD_CLOEXEC on all other fds used internally.
579 flags
= fcntl(fd
, F_GETFD
);
580 if (flags
== -1 || (flags
& FD_CLOEXEC
)) {
581 error_setg(errp
, "fd is not valid or already in use");
586 error_setg(errp
, "set option is required and must be non-negative");
590 #ifdef F_DUPFD_CLOEXEC
591 dupfd
= fcntl(fd
, F_DUPFD_CLOEXEC
, 0);
595 qemu_set_cloexec(dupfd
);
599 error_setg(errp
, "error duplicating fd: %s", strerror(errno
));
603 /* add the duplicate fd, and optionally the opaque string, to the fd set */
604 fdinfo
= monitor_fdset_add_fd(dupfd
, true, fdset_id
, !!fd_opaque
, fd_opaque
,
611 static int cleanup_add_fd(void *opaque
, QemuOpts
*opts
, Error
**errp
)
615 fd
= qemu_opt_get_number(opts
, "fd", -1);
622 /***********************************************************/
623 /* QEMU Block devices */
625 #define HD_OPTS "media=disk"
626 #define CDROM_OPTS "media=cdrom"
628 #define PFLASH_OPTS ""
632 static int drive_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
634 BlockInterfaceType
*block_default_type
= opaque
;
636 return drive_new(opts
, *block_default_type
, errp
) == NULL
;
639 static int drive_enable_snapshot(void *opaque
, QemuOpts
*opts
, Error
**errp
)
641 if (qemu_opt_get(opts
, "snapshot") == NULL
) {
642 qemu_opt_set(opts
, "snapshot", "on", &error_abort
);
647 static void default_drive(int enable
, int snapshot
, BlockInterfaceType type
,
648 int index
, const char *optstr
)
653 if (!enable
|| drive_get_by_index(type
, index
)) {
657 opts
= drive_add(type
, index
, NULL
, optstr
);
659 drive_enable_snapshot(NULL
, opts
, NULL
);
662 dinfo
= drive_new(opts
, type
, &error_abort
);
663 dinfo
->is_default
= true;
667 static void configure_blockdev(BlockdevOptionsQueue
*bdo_queue
,
668 MachineClass
*machine_class
, int snapshot
)
671 * If the currently selected machine wishes to override the
672 * units-per-bus property of its default HBA interface type, do so
675 if (machine_class
->units_per_default_bus
) {
676 override_max_devs(machine_class
->block_default_type
,
677 machine_class
->units_per_default_bus
);
680 /* open the virtual block devices */
681 while (!QSIMPLEQ_EMPTY(bdo_queue
)) {
682 BlockdevOptionsQueueEntry
*bdo
= QSIMPLEQ_FIRST(bdo_queue
);
684 QSIMPLEQ_REMOVE_HEAD(bdo_queue
, entry
);
685 loc_push_restore(&bdo
->loc
);
686 qmp_blockdev_add(bdo
->bdo
, &error_fatal
);
688 qapi_free_BlockdevOptions(bdo
->bdo
);
692 qemu_opts_foreach(qemu_find_opts("drive"), drive_enable_snapshot
,
695 if (qemu_opts_foreach(qemu_find_opts("drive"), drive_init_func
,
696 &machine_class
->block_default_type
, &error_fatal
)) {
697 /* We printed help */
701 default_drive(default_cdrom
, snapshot
, machine_class
->block_default_type
, 2,
703 default_drive(default_floppy
, snapshot
, IF_FLOPPY
, 0, FD_OPTS
);
704 default_drive(default_sdcard
, snapshot
, IF_SD
, 0, SD_OPTS
);
708 static QemuOptsList qemu_smp_opts
= {
710 .implied_opt_name
= "cpus",
712 .head
= QTAILQ_HEAD_INITIALIZER(qemu_smp_opts
.head
),
716 .type
= QEMU_OPT_NUMBER
,
719 .type
= QEMU_OPT_NUMBER
,
722 .type
= QEMU_OPT_NUMBER
,
725 .type
= QEMU_OPT_NUMBER
,
728 .type
= QEMU_OPT_NUMBER
,
731 .type
= QEMU_OPT_NUMBER
,
737 static void realtime_init(void)
740 if (os_mlock() < 0) {
741 error_report("locking memory failed");
748 static void configure_msg(QemuOpts
*opts
)
750 message_with_timestamp
= qemu_opt_get_bool(opts
, "timestamp", false);
751 error_with_guestname
= qemu_opt_get_bool(opts
, "guest-name", false);
755 /***********************************************************/
758 static int usb_device_add(const char *devname
)
760 USBDevice
*dev
= NULL
;
762 if (!machine_usb(current_machine
)) {
766 dev
= usbdevice_create(devname
);
773 static int usb_parse(const char *cmdline
)
776 r
= usb_device_add(cmdline
);
778 error_report("could not add USB device '%s'", cmdline
);
783 /***********************************************************/
784 /* machine registration */
786 static MachineClass
*find_machine(const char *name
, GSList
*machines
)
790 for (el
= machines
; el
; el
= el
->next
) {
791 MachineClass
*mc
= el
->data
;
793 if (!strcmp(mc
->name
, name
) || !g_strcmp0(mc
->alias
, name
)) {
801 static MachineClass
*find_default_machine(GSList
*machines
)
804 MachineClass
*default_machineclass
= NULL
;
806 for (el
= machines
; el
; el
= el
->next
) {
807 MachineClass
*mc
= el
->data
;
809 if (mc
->is_default
) {
810 assert(default_machineclass
== NULL
&& "Multiple default machines");
811 default_machineclass
= mc
;
815 return default_machineclass
;
818 static int machine_help_func(QemuOpts
*opts
, MachineState
*machine
)
820 ObjectProperty
*prop
;
821 ObjectPropertyIterator iter
;
823 if (!qemu_opt_has_help_opt(opts
)) {
827 object_property_iter_init(&iter
, OBJECT(machine
));
828 while ((prop
= object_property_iter_next(&iter
))) {
833 printf("%s.%s=%s", MACHINE_GET_CLASS(machine
)->name
,
834 prop
->name
, prop
->type
);
835 if (prop
->description
) {
836 printf(" (%s)\n", prop
->description
);
845 static void version(void)
847 printf("QEMU emulator version " QEMU_FULL_VERSION
"\n"
848 QEMU_COPYRIGHT
"\n");
851 static void help(int exitcode
)
854 printf("usage: %s [options] [disk_image]\n\n"
855 "'disk_image' is a raw hard disk image for IDE hard disk 0\n\n",
856 error_get_progname());
858 #define DEF(option, opt_arg, opt_enum, opt_help, arch_mask) \
859 if ((arch_mask) & arch_type) \
860 fputs(opt_help, stdout);
862 #define ARCHHEADING(text, arch_mask) \
863 if ((arch_mask) & arch_type) \
864 puts(stringify(text));
866 #define DEFHEADING(text) ARCHHEADING(text, QEMU_ARCH_ALL)
868 #include "qemu-options.def"
870 printf("\nDuring emulation, the following keys are useful:\n"
871 "ctrl-alt-f toggle full screen\n"
872 "ctrl-alt-n switch to virtual console 'n'\n"
873 "ctrl-alt toggle mouse and keyboard grab\n"
875 "When using -nographic, press 'ctrl-a h' to get some help.\n"
877 QEMU_HELP_BOTTOM
"\n");
882 #define HAS_ARG 0x0001
884 typedef struct QEMUOption
{
891 static const QEMUOption qemu_options
[] = {
892 { "h", 0, QEMU_OPTION_h
, QEMU_ARCH_ALL
},
894 #define DEF(option, opt_arg, opt_enum, opt_help, arch_mask) \
895 { option, opt_arg, opt_enum, arch_mask },
896 #define DEFHEADING(text)
897 #define ARCHHEADING(text, arch_mask)
899 #include "qemu-options.def"
903 typedef struct VGAInterfaceInfo
{
904 const char *opt_name
; /* option name */
905 const char *name
; /* human-readable name */
906 /* Class names indicating that support is available.
907 * If no class is specified, the interface is always available */
908 const char *class_names
[2];
911 static const VGAInterfaceInfo vga_interfaces
[VGA_TYPE_MAX
] = {
914 .name
= "no graphic card",
918 .name
= "standard VGA",
919 .class_names
= { "VGA", "isa-vga" },
922 .opt_name
= "cirrus",
923 .name
= "Cirrus VGA",
924 .class_names
= { "cirrus-vga", "isa-cirrus-vga" },
927 .opt_name
= "vmware",
928 .name
= "VMWare SVGA",
929 .class_names
= { "vmware-svga" },
932 .opt_name
= "virtio",
933 .name
= "Virtio VGA",
934 .class_names
= { "virtio-vga" },
939 .class_names
= { "qxl-vga" },
943 .name
= "TCX framebuffer",
944 .class_names
= { "sun-tcx" },
948 .name
= "CG3 framebuffer",
949 .class_names
= { "cgthree" },
953 .name
= "Xen paravirtualized framebuffer",
957 static bool vga_interface_available(VGAInterfaceType t
)
959 const VGAInterfaceInfo
*ti
= &vga_interfaces
[t
];
961 assert(t
< VGA_TYPE_MAX
);
962 return !ti
->class_names
[0] ||
963 module_object_class_by_name(ti
->class_names
[0]) ||
964 module_object_class_by_name(ti
->class_names
[1]);
968 get_default_vga_model(const MachineClass
*machine_class
)
970 if (machine_class
->default_display
) {
971 return machine_class
->default_display
;
972 } else if (vga_interface_available(VGA_CIRRUS
)) {
974 } else if (vga_interface_available(VGA_STD
)) {
981 static void select_vgahw(const MachineClass
*machine_class
, const char *p
)
986 if (g_str_equal(p
, "help")) {
987 const char *def
= get_default_vga_model(machine_class
);
989 for (t
= 0; t
< VGA_TYPE_MAX
; t
++) {
990 const VGAInterfaceInfo
*ti
= &vga_interfaces
[t
];
992 if (vga_interface_available(t
) && ti
->opt_name
) {
993 printf("%-20s %s%s\n", ti
->opt_name
, ti
->name
?: "",
994 g_str_equal(ti
->opt_name
, def
) ? " (default)" : "");
1000 assert(vga_interface_type
== VGA_NONE
);
1001 for (t
= 0; t
< VGA_TYPE_MAX
; t
++) {
1002 const VGAInterfaceInfo
*ti
= &vga_interfaces
[t
];
1003 if (ti
->opt_name
&& strstart(p
, ti
->opt_name
, &opts
)) {
1004 if (!vga_interface_available(t
)) {
1005 error_report("%s not available", ti
->name
);
1008 vga_interface_type
= t
;
1012 if (t
== VGA_TYPE_MAX
) {
1014 error_report("unknown vga type: %s", p
);
1018 const char *nextopt
;
1020 if (strstart(opts
, ",retrace=", &nextopt
)) {
1022 if (strstart(opts
, "dumb", &nextopt
))
1023 vga_retrace_method
= VGA_RETRACE_DUMB
;
1024 else if (strstart(opts
, "precise", &nextopt
))
1025 vga_retrace_method
= VGA_RETRACE_PRECISE
;
1026 else goto invalid_vga
;
1027 } else goto invalid_vga
;
1032 static void parse_display_qapi(const char *optarg
)
1034 DisplayOptions
*opts
;
1037 v
= qobject_input_visitor_new_str(optarg
, "type", &error_fatal
);
1039 visit_type_DisplayOptions(v
, NULL
, &opts
, &error_fatal
);
1040 QAPI_CLONE_MEMBERS(DisplayOptions
, &dpy
, opts
);
1042 qapi_free_DisplayOptions(opts
);
1046 DisplayOptions
*qmp_query_display_options(Error
**errp
)
1048 return QAPI_CLONE(DisplayOptions
, &dpy
);
1051 static void parse_display(const char *p
)
1055 if (is_help_option(p
)) {
1056 qemu_display_help();
1060 if (strstart(p
, "sdl", &opts
)) {
1062 * sdl DisplayType needs hand-crafted parser instead of
1063 * parse_display_qapi() due to some options not in
1064 * DisplayOptions, specifically:
1066 * Already deprecated.
1067 * - ctrl_grab + alt_grab
1068 * Not clear yet what happens to them long-term. Should
1069 * replaced by something better or deprecated and dropped.
1071 dpy
.type
= DISPLAY_TYPE_SDL
;
1073 const char *nextopt
;
1075 if (strstart(opts
, ",alt_grab=", &nextopt
)) {
1077 if (strstart(opts
, "on", &nextopt
)) {
1079 } else if (strstart(opts
, "off", &nextopt
)) {
1082 goto invalid_sdl_args
;
1084 } else if (strstart(opts
, ",ctrl_grab=", &nextopt
)) {
1086 if (strstart(opts
, "on", &nextopt
)) {
1088 } else if (strstart(opts
, "off", &nextopt
)) {
1091 goto invalid_sdl_args
;
1093 } else if (strstart(opts
, ",window_close=", &nextopt
)) {
1095 dpy
.has_window_close
= true;
1096 if (strstart(opts
, "on", &nextopt
)) {
1097 dpy
.window_close
= true;
1098 } else if (strstart(opts
, "off", &nextopt
)) {
1099 dpy
.window_close
= false;
1101 goto invalid_sdl_args
;
1103 } else if (strstart(opts
, ",show-cursor=", &nextopt
)) {
1105 dpy
.has_show_cursor
= true;
1106 if (strstart(opts
, "on", &nextopt
)) {
1107 dpy
.show_cursor
= true;
1108 } else if (strstart(opts
, "off", &nextopt
)) {
1109 dpy
.show_cursor
= false;
1111 goto invalid_sdl_args
;
1113 } else if (strstart(opts
, ",gl=", &nextopt
)) {
1116 if (strstart(opts
, "on", &nextopt
)) {
1117 dpy
.gl
= DISPLAYGL_MODE_ON
;
1118 } else if (strstart(opts
, "core", &nextopt
)) {
1119 dpy
.gl
= DISPLAYGL_MODE_CORE
;
1120 } else if (strstart(opts
, "es", &nextopt
)) {
1121 dpy
.gl
= DISPLAYGL_MODE_ES
;
1122 } else if (strstart(opts
, "off", &nextopt
)) {
1123 dpy
.gl
= DISPLAYGL_MODE_OFF
;
1125 goto invalid_sdl_args
;
1129 error_report("invalid SDL option string");
1134 } else if (strstart(p
, "vnc", &opts
)) {
1136 * vnc isn't a (local) DisplayType but a protocol for remote
1140 vnc_parse(opts
+ 1);
1142 error_report("VNC requires a display argument vnc=<display>");
1146 parse_display_qapi(p
);
1150 static inline bool nonempty_str(const char *str
)
1155 static int parse_fw_cfg(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1159 const char *name
, *file
, *str
, *gen_id
;
1160 FWCfgState
*fw_cfg
= (FWCfgState
*) opaque
;
1162 if (fw_cfg
== NULL
) {
1163 error_setg(errp
, "fw_cfg device not available");
1166 name
= qemu_opt_get(opts
, "name");
1167 file
= qemu_opt_get(opts
, "file");
1168 str
= qemu_opt_get(opts
, "string");
1169 gen_id
= qemu_opt_get(opts
, "gen_id");
1171 /* we need the name, and exactly one of: file, content string, gen_id */
1172 if (!nonempty_str(name
) ||
1173 nonempty_str(file
) + nonempty_str(str
) + nonempty_str(gen_id
) != 1) {
1174 error_setg(errp
, "name, plus exactly one of file,"
1175 " string and gen_id, are needed");
1178 if (strlen(name
) > FW_CFG_MAX_FILE_PATH
- 1) {
1179 error_setg(errp
, "name too long (max. %d char)",
1180 FW_CFG_MAX_FILE_PATH
- 1);
1183 if (nonempty_str(gen_id
)) {
1185 * In this particular case where the content is populated
1186 * internally, the "etc/" namespace protection is relaxed,
1187 * so do not emit a warning.
1189 } else if (strncmp(name
, "opt/", 4) != 0) {
1190 warn_report("externally provided fw_cfg item names "
1191 "should be prefixed with \"opt/\"");
1193 if (nonempty_str(str
)) {
1194 size
= strlen(str
); /* NUL terminator NOT included in fw_cfg blob */
1195 buf
= g_memdup(str
, size
);
1196 } else if (nonempty_str(gen_id
)) {
1197 if (!fw_cfg_add_from_generator(fw_cfg
, name
, gen_id
, errp
)) {
1203 if (!g_file_get_contents(file
, &buf
, &size
, &err
)) {
1204 error_setg(errp
, "can't load %s: %s", file
, err
->message
);
1209 /* For legacy, keep user files in a specific global order. */
1210 fw_cfg_set_order_override(fw_cfg
, FW_CFG_ORDER_OVERRIDE_USER
);
1211 fw_cfg_add_file(fw_cfg
, name
, buf
, size
);
1212 fw_cfg_reset_order_override(fw_cfg
);
1216 static int device_help_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1218 return qdev_device_help(opts
);
1221 static int device_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1225 dev
= qdev_device_add(opts
, errp
);
1226 if (!dev
&& *errp
) {
1227 error_report_err(*errp
);
1230 object_unref(OBJECT(dev
));
1235 static int chardev_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1237 Error
*local_err
= NULL
;
1239 if (!qemu_chr_new_from_opts(opts
, NULL
, &local_err
)) {
1241 error_propagate(errp
, local_err
);
1249 #ifdef CONFIG_VIRTFS
1250 static int fsdev_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1252 return qemu_fsdev_add(opts
, errp
);
1256 static int mon_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1258 return monitor_init_opts(opts
, errp
);
1261 static void monitor_parse(const char *optarg
, const char *mode
, bool pretty
)
1263 static int monitor_device_index
= 0;
1268 if (strstart(optarg
, "chardev:", &p
)) {
1269 snprintf(label
, sizeof(label
), "%s", p
);
1271 snprintf(label
, sizeof(label
), "compat_monitor%d",
1272 monitor_device_index
);
1273 opts
= qemu_chr_parse_compat(label
, optarg
, true);
1275 error_report("parse error: %s", optarg
);
1280 opts
= qemu_opts_create(qemu_find_opts("mon"), label
, 1, &error_fatal
);
1281 qemu_opt_set(opts
, "mode", mode
, &error_abort
);
1282 qemu_opt_set(opts
, "chardev", label
, &error_abort
);
1283 if (!strcmp(mode
, "control")) {
1284 qemu_opt_set_bool(opts
, "pretty", pretty
, &error_abort
);
1286 assert(pretty
== false);
1288 monitor_device_index
++;
1291 struct device_config
{
1293 DEV_USB
, /* -usbdevice */
1294 DEV_SERIAL
, /* -serial */
1295 DEV_PARALLEL
, /* -parallel */
1296 DEV_DEBUGCON
, /* -debugcon */
1297 DEV_GDB
, /* -gdb, -s */
1298 DEV_SCLP
, /* s390 sclp */
1300 const char *cmdline
;
1302 QTAILQ_ENTRY(device_config
) next
;
1305 static QTAILQ_HEAD(, device_config
) device_configs
=
1306 QTAILQ_HEAD_INITIALIZER(device_configs
);
1308 static void add_device_config(int type
, const char *cmdline
)
1310 struct device_config
*conf
;
1312 conf
= g_malloc0(sizeof(*conf
));
1314 conf
->cmdline
= cmdline
;
1315 loc_save(&conf
->loc
);
1316 QTAILQ_INSERT_TAIL(&device_configs
, conf
, next
);
1319 static int foreach_device_config(int type
, int (*func
)(const char *cmdline
))
1321 struct device_config
*conf
;
1324 QTAILQ_FOREACH(conf
, &device_configs
, next
) {
1325 if (conf
->type
!= type
)
1327 loc_push_restore(&conf
->loc
);
1328 rc
= func(conf
->cmdline
);
1329 loc_pop(&conf
->loc
);
1337 static void qemu_disable_default_devices(void)
1339 MachineClass
*machine_class
= MACHINE_GET_CLASS(current_machine
);
1341 qemu_opts_foreach(qemu_find_opts("device"),
1342 default_driver_check
, NULL
, NULL
);
1343 qemu_opts_foreach(qemu_find_opts("global"),
1344 default_driver_check
, NULL
, NULL
);
1346 if (!vga_model
&& !default_vga
) {
1347 vga_interface_type
= VGA_DEVICE
;
1349 if (!has_defaults
|| machine_class
->no_serial
) {
1352 if (!has_defaults
|| machine_class
->no_parallel
) {
1353 default_parallel
= 0;
1355 if (!has_defaults
|| machine_class
->no_floppy
) {
1358 if (!has_defaults
|| machine_class
->no_cdrom
) {
1361 if (!has_defaults
|| machine_class
->no_sdcard
) {
1364 if (!has_defaults
) {
1365 default_monitor
= 0;
1371 static void qemu_create_default_devices(void)
1373 MachineClass
*machine_class
= MACHINE_GET_CLASS(current_machine
);
1375 if (is_daemonized()) {
1376 /* According to documentation and historically, -nographic redirects
1377 * serial port, parallel port and monitor to stdio, which does not work
1378 * with -daemonize. We can redirect these to null instead, but since
1379 * -nographic is legacy, let's just error out.
1380 * We disallow -nographic only if all other ports are not redirected
1381 * explicitly, to not break existing legacy setups which uses
1382 * -nographic _and_ redirects all ports explicitly - this is valid
1383 * usage, -nographic is just a no-op in this case.
1386 && (default_parallel
|| default_serial
|| default_monitor
)) {
1387 error_report("-nographic cannot be used with -daemonize");
1393 if (default_parallel
)
1394 add_device_config(DEV_PARALLEL
, "null");
1395 if (default_serial
&& default_monitor
) {
1396 add_device_config(DEV_SERIAL
, "mon:stdio");
1399 add_device_config(DEV_SERIAL
, "stdio");
1400 if (default_monitor
)
1401 monitor_parse("stdio", "readline", false);
1405 add_device_config(DEV_SERIAL
, "vc:80Cx24C");
1406 if (default_parallel
)
1407 add_device_config(DEV_PARALLEL
, "vc:80Cx24C");
1408 if (default_monitor
)
1409 monitor_parse("vc:80Cx24C", "readline", false);
1413 QemuOptsList
*net
= qemu_find_opts("net");
1414 qemu_opts_parse(net
, "nic", true, &error_abort
);
1416 qemu_opts_parse(net
, "user", true, &error_abort
);
1420 #if defined(CONFIG_VNC)
1421 if (!QTAILQ_EMPTY(&(qemu_find_opts("vnc")->head
))) {
1425 if (dpy
.type
== DISPLAY_TYPE_DEFAULT
&& !display_remote
) {
1426 if (!qemu_display_find_default(&dpy
)) {
1427 dpy
.type
= DISPLAY_TYPE_NONE
;
1428 #if defined(CONFIG_VNC)
1429 vnc_parse("localhost:0,to=99,id=default");
1433 if (dpy
.type
== DISPLAY_TYPE_DEFAULT
) {
1434 dpy
.type
= DISPLAY_TYPE_NONE
;
1437 /* If no default VGA is requested, the default is "none". */
1439 vga_model
= get_default_vga_model(machine_class
);
1442 select_vgahw(machine_class
, vga_model
);
1446 static int serial_parse(const char *devname
)
1448 int index
= num_serial_hds
;
1451 if (strcmp(devname
, "none") == 0)
1453 snprintf(label
, sizeof(label
), "serial%d", index
);
1454 serial_hds
= g_renew(Chardev
*, serial_hds
, index
+ 1);
1456 serial_hds
[index
] = qemu_chr_new_mux_mon(label
, devname
, NULL
);
1457 if (!serial_hds
[index
]) {
1458 error_report("could not connect serial device"
1459 " to character backend '%s'", devname
);
1466 Chardev
*serial_hd(int i
)
1469 if (i
< num_serial_hds
) {
1470 return serial_hds
[i
];
1475 static int parallel_parse(const char *devname
)
1477 static int index
= 0;
1480 if (strcmp(devname
, "none") == 0)
1482 if (index
== MAX_PARALLEL_PORTS
) {
1483 error_report("too many parallel ports");
1486 snprintf(label
, sizeof(label
), "parallel%d", index
);
1487 parallel_hds
[index
] = qemu_chr_new_mux_mon(label
, devname
, NULL
);
1488 if (!parallel_hds
[index
]) {
1489 error_report("could not connect parallel device"
1490 " to character backend '%s'", devname
);
1497 static int debugcon_parse(const char *devname
)
1501 if (!qemu_chr_new_mux_mon("debugcon", devname
, NULL
)) {
1502 error_report("invalid character backend '%s'", devname
);
1505 opts
= qemu_opts_create(qemu_find_opts("device"), "debugcon", 1, NULL
);
1507 error_report("already have a debugcon device");
1510 qemu_opt_set(opts
, "driver", "isa-debugcon", &error_abort
);
1511 qemu_opt_set(opts
, "chardev", "debugcon", &error_abort
);
1515 static gint
machine_class_cmp(gconstpointer a
, gconstpointer b
)
1517 const MachineClass
*mc1
= a
, *mc2
= b
;
1520 if (mc1
->family
== NULL
) {
1521 if (mc2
->family
== NULL
) {
1522 /* Compare standalone machine types against each other; they sort
1523 * in increasing order.
1525 return strcmp(object_class_get_name(OBJECT_CLASS(mc1
)),
1526 object_class_get_name(OBJECT_CLASS(mc2
)));
1529 /* Standalone machine types sort after families. */
1533 if (mc2
->family
== NULL
) {
1534 /* Families sort before standalone machine types. */
1538 /* Families sort between each other alphabetically increasingly. */
1539 res
= strcmp(mc1
->family
, mc2
->family
);
1544 /* Within the same family, machine types sort in decreasing order. */
1545 return strcmp(object_class_get_name(OBJECT_CLASS(mc2
)),
1546 object_class_get_name(OBJECT_CLASS(mc1
)));
1549 static MachineClass
*machine_parse(const char *name
, GSList
*machines
)
1554 if (is_help_option(name
)) {
1555 printf("Supported machines are:\n");
1556 machines
= g_slist_sort(machines
, machine_class_cmp
);
1557 for (el
= machines
; el
; el
= el
->next
) {
1558 MachineClass
*mc
= el
->data
;
1560 printf("%-20s %s (alias of %s)\n", mc
->alias
, mc
->desc
, mc
->name
);
1562 printf("%-20s %s%s%s\n", mc
->name
, mc
->desc
,
1563 mc
->is_default
? " (default)" : "",
1564 mc
->deprecation_reason
? " (deprecated)" : "");
1569 mc
= find_machine(name
, machines
);
1571 error_report("unsupported machine type");
1572 error_printf("Use -machine help to list supported machines\n");
1578 static const char *pid_file
;
1579 static Notifier qemu_unlink_pidfile_notifier
;
1581 static void qemu_unlink_pidfile(Notifier
*n
, void *data
)
1588 static const QEMUOption
*lookup_opt(int argc
, char **argv
,
1589 const char **poptarg
, int *poptind
)
1591 const QEMUOption
*popt
;
1592 int optind
= *poptind
;
1593 char *r
= argv
[optind
];
1596 loc_set_cmdline(argv
, optind
, 1);
1598 /* Treat --foo the same as -foo. */
1601 popt
= qemu_options
;
1604 error_report("invalid option");
1607 if (!strcmp(popt
->name
, r
+ 1))
1611 if (popt
->flags
& HAS_ARG
) {
1612 if (optind
>= argc
) {
1613 error_report("requires an argument");
1616 optarg
= argv
[optind
++];
1617 loc_set_cmdline(argv
, optind
- 2, 2);
1628 static MachineClass
*select_machine(void)
1630 GSList
*machines
= object_class_get_list(TYPE_MACHINE
, false);
1631 MachineClass
*machine_class
= find_default_machine(machines
);
1636 loc_push_none(&loc
);
1638 opts
= qemu_get_machine_opts();
1639 qemu_opts_loc_restore(opts
);
1641 optarg
= qemu_opt_get(opts
, "type");
1643 machine_class
= machine_parse(optarg
, machines
);
1646 if (!machine_class
) {
1647 error_report("No machine specified, and there is no default");
1648 error_printf("Use -machine help to list supported machines\n");
1653 g_slist_free(machines
);
1654 return machine_class
;
1657 static int object_parse_property_opt(Object
*obj
,
1658 const char *name
, const char *value
,
1659 const char *skip
, Error
**errp
)
1661 if (g_str_equal(name
, skip
)) {
1665 if (!object_property_parse(obj
, name
, value
, errp
)) {
1672 static int machine_set_property(void *opaque
,
1673 const char *name
, const char *value
,
1676 g_autofree
char *qom_name
= g_strdup(name
);
1679 for (p
= qom_name
; *p
; p
++) {
1685 /* Legacy options do not correspond to MachineState properties. */
1686 if (g_str_equal(qom_name
, "accel")) {
1689 if (g_str_equal(qom_name
, "igd-passthru")) {
1690 object_register_sugar_prop(ACCEL_CLASS_NAME("xen"), qom_name
, value
,
1694 if (g_str_equal(qom_name
, "kvm-shadow-mem")) {
1695 object_register_sugar_prop(ACCEL_CLASS_NAME("kvm"), qom_name
, value
,
1699 if (g_str_equal(qom_name
, "kernel-irqchip")) {
1700 object_register_sugar_prop(ACCEL_CLASS_NAME("kvm"), qom_name
, value
,
1702 object_register_sugar_prop(ACCEL_CLASS_NAME("whpx"), qom_name
, value
,
1707 return object_parse_property_opt(opaque
, name
, value
, "type", errp
);
1710 static void object_option_foreach_add(bool (*type_opt_predicate
)(const char *))
1712 ObjectOption
*opt
, *next
;
1714 QTAILQ_FOREACH_SAFE(opt
, &object_opts
, next
, next
) {
1715 const char *type
= ObjectType_str(opt
->opts
->qom_type
);
1716 if (type_opt_predicate(type
)) {
1717 user_creatable_add_qapi(opt
->opts
, &error_fatal
);
1718 qapi_free_ObjectOptions(opt
->opts
);
1719 QTAILQ_REMOVE(&object_opts
, opt
, next
);
1725 static void object_option_add_visitor(Visitor
*v
)
1727 ObjectOption
*opt
= g_new0(ObjectOption
, 1);
1728 visit_type_ObjectOptions(v
, NULL
, &opt
->opts
, &error_fatal
);
1729 QTAILQ_INSERT_TAIL(&object_opts
, opt
, next
);
1732 static void object_option_parse(const char *optarg
)
1738 if (optarg
[0] == '{') {
1739 QObject
*obj
= qobject_from_json(optarg
, &error_fatal
);
1741 v
= qobject_input_visitor_new(obj
);
1744 opts
= qemu_opts_parse_noisily(qemu_find_opts("object"),
1750 type
= qemu_opt_get(opts
, "qom-type");
1752 error_setg(&error_fatal
, QERR_MISSING_PARAMETER
, "qom-type");
1754 if (user_creatable_print_help(type
, opts
)) {
1758 v
= opts_visitor_new(opts
);
1761 object_option_add_visitor(v
);
1766 * Initial object creation happens before all other
1767 * QEMU data types are created. The majority of objects
1768 * can be created at this point. The rng-egd object
1769 * cannot be created here, as it depends on the chardev
1772 static bool object_create_early(const char *type
)
1775 * Objects should not be made "delayed" without a reason. If you
1776 * add one, state the reason in a comment!
1779 /* Reason: property "chardev" */
1780 if (g_str_equal(type
, "rng-egd") ||
1781 g_str_equal(type
, "qtest")) {
1785 #if defined(CONFIG_VHOST_USER) && defined(CONFIG_LINUX)
1786 /* Reason: cryptodev-vhost-user property "chardev" */
1787 if (g_str_equal(type
, "cryptodev-vhost-user")) {
1792 /* Reason: vhost-user-blk-server property "node-name" */
1793 if (g_str_equal(type
, "vhost-user-blk-server")) {
1797 * Reason: filter-* property "netdev" etc.
1799 if (g_str_equal(type
, "filter-buffer") ||
1800 g_str_equal(type
, "filter-dump") ||
1801 g_str_equal(type
, "filter-mirror") ||
1802 g_str_equal(type
, "filter-redirector") ||
1803 g_str_equal(type
, "colo-compare") ||
1804 g_str_equal(type
, "filter-rewriter") ||
1805 g_str_equal(type
, "filter-replay")) {
1810 * Allocation of large amounts of memory may delay
1811 * chardev initialization for too long, and trigger timeouts
1812 * on software that waits for a monitor socket to be created
1815 if (g_str_has_prefix(type
, "memory-backend-")) {
1822 static void qemu_apply_machine_options(void)
1824 MachineClass
*machine_class
= MACHINE_GET_CLASS(current_machine
);
1825 QemuOpts
*machine_opts
= qemu_get_machine_opts();
1826 const char *boot_order
= NULL
;
1827 const char *boot_once
= NULL
;
1830 qemu_opt_foreach(machine_opts
, machine_set_property
, current_machine
,
1832 current_machine
->ram_size
= ram_size
;
1833 current_machine
->maxram_size
= maxram_size
;
1834 current_machine
->ram_slots
= ram_slots
;
1836 opts
= qemu_opts_find(qemu_find_opts("boot-opts"), NULL
);
1838 boot_order
= qemu_opt_get(opts
, "order");
1840 validate_bootdevices(boot_order
, &error_fatal
);
1843 boot_once
= qemu_opt_get(opts
, "once");
1845 validate_bootdevices(boot_once
, &error_fatal
);
1848 boot_menu
= qemu_opt_get_bool(opts
, "menu", boot_menu
);
1849 boot_strict
= qemu_opt_get_bool(opts
, "strict", false);
1853 boot_order
= machine_class
->default_boot_order
;
1856 current_machine
->boot_order
= boot_order
;
1857 current_machine
->boot_once
= boot_once
;
1859 if (semihosting_enabled() && !semihosting_get_argc()) {
1860 const char *kernel_filename
= qemu_opt_get(machine_opts
, "kernel");
1861 const char *kernel_cmdline
= qemu_opt_get(machine_opts
, "append") ?: "";
1862 /* fall back to the -kernel/-append */
1863 semihosting_arg_fallback(kernel_filename
, kernel_cmdline
);
1867 static void qemu_create_early_backends(void)
1869 MachineClass
*machine_class
= MACHINE_GET_CLASS(current_machine
);
1871 if ((alt_grab
|| ctrl_grab
) && dpy
.type
!= DISPLAY_TYPE_SDL
) {
1872 error_report("-alt-grab and -ctrl-grab are only valid "
1873 "for SDL, ignoring option");
1875 if (dpy
.has_window_close
&&
1876 (dpy
.type
!= DISPLAY_TYPE_GTK
&& dpy
.type
!= DISPLAY_TYPE_SDL
)) {
1877 error_report("-no-quit is only valid for GTK and SDL, "
1881 qemu_display_early_init(&dpy
);
1882 qemu_console_early_init();
1884 if (dpy
.has_gl
&& dpy
.gl
!= DISPLAYGL_MODE_OFF
&& display_opengl
== 0) {
1885 #if defined(CONFIG_OPENGL)
1886 error_report("OpenGL is not supported by the display");
1888 error_report("OpenGL support is disabled");
1893 object_option_foreach_add(object_create_early
);
1895 /* spice needs the timers to be initialized by this point */
1896 /* spice must initialize before audio as it changes the default auiodev */
1897 /* spice must initialize before chardevs (for spicevmc and spiceport) */
1900 qemu_opts_foreach(qemu_find_opts("chardev"),
1901 chardev_init_func
, NULL
, &error_fatal
);
1903 #ifdef CONFIG_VIRTFS
1904 qemu_opts_foreach(qemu_find_opts("fsdev"),
1905 fsdev_init_func
, NULL
, &error_fatal
);
1909 * Note: we need to create audio and block backends before
1910 * machine_set_property(), so machine properties can refer to
1913 configure_blockdev(&bdo_queue
, machine_class
, snapshot
);
1914 audio_init_audiodevs();
1919 * The remainder of object creation happens after the
1920 * creation of chardev, fsdev, net clients and device data types.
1922 static bool object_create_late(const char *type
)
1924 return !object_create_early(type
);
1927 static void qemu_create_late_backends(void)
1930 qtest_server_init(qtest_chrdev
, qtest_log
, &error_fatal
);
1933 net_init_clients(&error_fatal
);
1935 object_option_foreach_add(object_create_late
);
1937 if (tpm_init() < 0) {
1941 qemu_opts_foreach(qemu_find_opts("mon"),
1942 mon_init_func
, NULL
, &error_fatal
);
1944 if (foreach_device_config(DEV_SERIAL
, serial_parse
) < 0)
1946 if (foreach_device_config(DEV_PARALLEL
, parallel_parse
) < 0)
1948 if (foreach_device_config(DEV_DEBUGCON
, debugcon_parse
) < 0)
1951 /* now chardevs have been created we may have semihosting to connect */
1952 qemu_semihosting_connect_chardevs();
1953 qemu_semihosting_console_init();
1956 static bool have_custom_ram_size(void)
1958 QemuOpts
*opts
= qemu_find_opts_singleton("memory");
1959 return !!qemu_opt_get_size(opts
, "size", 0);
1962 static void qemu_resolve_machine_memdev(void)
1964 if (current_machine
->ram_memdev_id
) {
1966 ram_addr_t backend_size
;
1968 backend
= object_resolve_path_type(current_machine
->ram_memdev_id
,
1969 TYPE_MEMORY_BACKEND
, NULL
);
1971 error_report("Memory backend '%s' not found",
1972 current_machine
->ram_memdev_id
);
1975 backend_size
= object_property_get_uint(backend
, "size", &error_abort
);
1976 if (have_custom_ram_size() && backend_size
!= ram_size
) {
1977 error_report("Size specified by -m option must match size of "
1978 "explicitly specified 'memory-backend' property");
1982 error_report("'-mem-path' can't be used together with"
1983 "'-machine memory-backend'");
1986 ram_size
= backend_size
;
1989 if (!xen_enabled()) {
1990 /* On 32-bit hosts, QEMU is limited by virtual address space */
1991 if (ram_size
> (2047 << 20) && HOST_LONG_BITS
== 32) {
1992 error_report("at most 2047 MB RAM can be simulated");
1998 static void set_memory_options(MachineClass
*mc
)
2001 const char *mem_str
;
2002 const ram_addr_t default_ram_size
= mc
->default_ram_size
;
2003 QemuOpts
*opts
= qemu_find_opts_singleton("memory");
2006 loc_push_none(&loc
);
2007 qemu_opts_loc_restore(opts
);
2010 mem_str
= qemu_opt_get(opts
, "size");
2013 error_report("missing 'size' option value");
2017 sz
= qemu_opt_get_size(opts
, "size", ram_size
);
2019 /* Fix up legacy suffix-less format */
2020 if (g_ascii_isdigit(mem_str
[strlen(mem_str
) - 1])) {
2021 uint64_t overflow_check
= sz
;
2024 if (sz
/ MiB
!= overflow_check
) {
2025 error_report("too large 'size' option value");
2031 /* backward compatibility behaviour for case "-m 0" */
2033 sz
= default_ram_size
;
2036 sz
= QEMU_ALIGN_UP(sz
, 8192);
2037 if (mc
->fixup_ram_size
) {
2038 sz
= mc
->fixup_ram_size(sz
);
2041 if (ram_size
!= sz
) {
2042 error_report("ram size too large");
2046 maxram_size
= ram_size
;
2048 if (qemu_opt_get(opts
, "maxmem")) {
2051 sz
= qemu_opt_get_size(opts
, "maxmem", 0);
2052 slots
= qemu_opt_get_number(opts
, "slots", 0);
2053 if (sz
< ram_size
) {
2054 error_report("invalid value of -m option maxmem: "
2055 "maximum memory size (0x%" PRIx64
") must be at least "
2056 "the initial memory size (0x" RAM_ADDR_FMT
")",
2059 } else if (slots
&& sz
== ram_size
) {
2060 error_report("invalid value of -m option maxmem: "
2061 "memory slots were specified but maximum memory size "
2062 "(0x%" PRIx64
") is equal to the initial memory size "
2063 "(0x" RAM_ADDR_FMT
")", sz
, ram_size
);
2069 } else if (qemu_opt_get(opts
, "slots")) {
2070 error_report("invalid -m option value: missing 'maxmem' option");
2077 static void qemu_create_machine(MachineClass
*machine_class
)
2079 object_set_machine_compat_props(machine_class
->compat_props
);
2081 set_memory_options(machine_class
);
2083 current_machine
= MACHINE(object_new_with_class(OBJECT_CLASS(machine_class
)));
2084 if (machine_help_func(qemu_get_machine_opts(), current_machine
)) {
2087 object_property_add_child(object_get_root(), "machine",
2088 OBJECT(current_machine
));
2089 object_property_add_child(container_get(OBJECT(current_machine
),
2091 "sysbus", OBJECT(sysbus_get_default()));
2093 if (machine_class
->minimum_page_bits
) {
2094 if (!set_preferred_target_page_bits(machine_class
->minimum_page_bits
)) {
2095 /* This would be a board error: specifying a minimum smaller than
2096 * a target's compile-time fixed setting.
2098 g_assert_not_reached();
2102 cpu_exec_init_all();
2105 if (machine_class
->hw_version
) {
2106 qemu_set_hw_version(machine_class
->hw_version
);
2109 machine_smp_parse(current_machine
,
2110 qemu_opts_find(qemu_find_opts("smp-opts"), NULL
), &error_fatal
);
2113 * Get the default machine options from the machine if it is not already
2114 * specified either by the configuration file or by the command line.
2116 if (machine_class
->default_machine_opts
) {
2117 qemu_opts_set_defaults(qemu_find_opts("machine"),
2118 machine_class
->default_machine_opts
, 0);
2122 static int global_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2126 g
= g_malloc0(sizeof(*g
));
2127 g
->driver
= qemu_opt_get(opts
, "driver");
2128 g
->property
= qemu_opt_get(opts
, "property");
2129 g
->value
= qemu_opt_get(opts
, "value");
2130 qdev_prop_register_global(g
);
2135 * Return whether configuration group @group is stored in QemuOpts, or
2136 * recorded as one or more QDicts by qemu_record_config_group.
2138 static bool is_qemuopts_group(const char *group
)
2140 if (g_str_equal(group
, "object")) {
2146 static void qemu_record_config_group(const char *group
, QDict
*dict
,
2147 bool from_json
, Error
**errp
)
2149 if (g_str_equal(group
, "object")) {
2150 Visitor
*v
= qobject_input_visitor_new_keyval(QOBJECT(dict
));
2151 object_option_add_visitor(v
);
2159 * Parse non-QemuOpts config file groups, pass the rest to
2160 * qemu_config_do_parse.
2162 static void qemu_parse_config_group(const char *group
, QDict
*qdict
,
2163 void *opaque
, Error
**errp
)
2166 if (is_qemuopts_group(group
)) {
2167 qemu_config_do_parse(group
, qdict
, opaque
, errp
);
2171 crumpled
= qdict_crumple(qdict
, errp
);
2175 if (qobject_type(crumpled
) != QTYPE_QDICT
) {
2176 assert(qobject_type(crumpled
) == QTYPE_QLIST
);
2177 error_setg(errp
, "Lists cannot be at top level of a configuration section");
2180 qemu_record_config_group(group
, qobject_to(QDict
, crumpled
), false, errp
);
2183 static void qemu_read_default_config_file(Error
**errp
)
2187 g_autofree
char *file
= get_relocated_path(CONFIG_QEMU_CONFDIR
"/qemu.conf");
2189 ret
= qemu_read_config_file(file
, qemu_parse_config_group
, errp
);
2191 if (ret
== -ENOENT
) {
2198 static void qemu_set_option(const char *str
, Error
**errp
)
2200 char group
[64], id
[64], arg
[64];
2205 rc
= sscanf(str
, "%63[^.].%63[^.].%63[^=]%n", group
, id
, arg
, &offset
);
2206 if (rc
< 3 || str
[offset
] != '=') {
2207 error_setg(errp
, "can't parse: \"%s\"", str
);
2211 if (!is_qemuopts_group(group
)) {
2212 error_setg(errp
, "-set is not supported with %s", group
);
2214 list
= qemu_find_opts_err(group
, errp
);
2216 opts
= qemu_opts_find(list
, id
);
2218 error_setg(errp
, "there is no %s \"%s\" defined", group
, id
);
2221 qemu_opt_set(opts
, arg
, str
+ offset
+ 1, errp
);
2226 static void user_register_global_props(void)
2228 qemu_opts_foreach(qemu_find_opts("global"),
2229 global_init_func
, NULL
, NULL
);
2232 static int do_configure_icount(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2234 icount_configure(opts
, errp
);
2238 static int accelerator_set_property(void *opaque
,
2239 const char *name
, const char *value
,
2242 return object_parse_property_opt(opaque
, name
, value
, "accel", errp
);
2245 static int do_configure_accelerator(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2247 bool *p_init_failed
= opaque
;
2248 const char *acc
= qemu_opt_get(opts
, "accel");
2249 AccelClass
*ac
= accel_find(acc
);
2252 bool qtest_with_kvm
;
2254 qtest_with_kvm
= g_str_equal(acc
, "kvm") && qtest_chrdev
!= NULL
;
2257 *p_init_failed
= true;
2258 if (!qtest_with_kvm
) {
2259 error_report("invalid accelerator %s", acc
);
2263 accel
= ACCEL(object_new_with_class(OBJECT_CLASS(ac
)));
2264 object_apply_compat_props(OBJECT(accel
));
2265 qemu_opt_foreach(opts
, accelerator_set_property
,
2269 ret
= accel_init_machine(accel
, current_machine
);
2271 *p_init_failed
= true;
2272 if (!qtest_with_kvm
|| ret
!= -ENOENT
) {
2273 error_report("failed to initialize %s: %s", acc
, strerror(-ret
));
2281 static void configure_accelerators(const char *progname
)
2283 const char *accelerators
;
2284 bool init_failed
= false;
2286 qemu_opts_foreach(qemu_find_opts("icount"),
2287 do_configure_icount
, NULL
, &error_fatal
);
2289 accelerators
= qemu_opt_get(qemu_get_machine_opts(), "accel");
2290 if (QTAILQ_EMPTY(&qemu_accel_opts
.head
)) {
2291 char **accel_list
, **tmp
;
2293 if (accelerators
== NULL
) {
2294 /* Select the default accelerator */
2295 bool have_tcg
= accel_find("tcg");
2296 bool have_kvm
= accel_find("kvm");
2298 if (have_tcg
&& have_kvm
) {
2299 if (g_str_has_suffix(progname
, "kvm")) {
2300 /* If the program name ends with "kvm", we prefer KVM */
2301 accelerators
= "kvm:tcg";
2303 accelerators
= "tcg:kvm";
2305 } else if (have_kvm
) {
2306 accelerators
= "kvm";
2307 } else if (have_tcg
) {
2308 accelerators
= "tcg";
2310 error_report("No accelerator selected and"
2311 " no default accelerator available");
2315 accel_list
= g_strsplit(accelerators
, ":", 0);
2317 for (tmp
= accel_list
; *tmp
; tmp
++) {
2319 * Filter invalid accelerators here, to prevent obscenities
2320 * such as "-machine accel=tcg,,thread=single".
2322 if (accel_find(*tmp
)) {
2323 qemu_opts_parse_noisily(qemu_find_opts("accel"), *tmp
, true);
2326 error_report("invalid accelerator %s", *tmp
);
2329 g_strfreev(accel_list
);
2331 if (accelerators
!= NULL
) {
2332 error_report("The -accel and \"-machine accel=\" options are incompatible");
2337 if (!qemu_opts_foreach(qemu_find_opts("accel"),
2338 do_configure_accelerator
, &init_failed
, &error_fatal
)) {
2340 error_report("no accelerator found");
2345 if (init_failed
&& !qtest_chrdev
) {
2346 AccelClass
*ac
= ACCEL_GET_CLASS(current_accel());
2347 error_report("falling back to %s", ac
->name
);
2350 if (icount_enabled() && !tcg_enabled()) {
2351 error_report("-icount is not allowed with hardware virtualization");
2356 static void create_default_memdev(MachineState
*ms
, const char *path
)
2359 MachineClass
*mc
= MACHINE_GET_CLASS(ms
);
2361 obj
= object_new(path
? TYPE_MEMORY_BACKEND_FILE
: TYPE_MEMORY_BACKEND_RAM
);
2363 object_property_set_str(obj
, "mem-path", path
, &error_fatal
);
2365 object_property_set_int(obj
, "size", ms
->ram_size
, &error_fatal
);
2366 object_property_add_child(object_get_objects_root(), mc
->default_ram_id
,
2368 /* Ensure backend's memory region name is equal to mc->default_ram_id */
2369 object_property_set_bool(obj
, "x-use-canonical-path-for-ramblock-id",
2370 false, &error_fatal
);
2371 user_creatable_complete(USER_CREATABLE(obj
), &error_fatal
);
2373 object_property_set_str(OBJECT(ms
), "memory-backend", mc
->default_ram_id
,
2377 static void qemu_validate_options(void)
2379 QemuOpts
*machine_opts
= qemu_get_machine_opts();
2380 const char *kernel_filename
= qemu_opt_get(machine_opts
, "kernel");
2381 const char *initrd_filename
= qemu_opt_get(machine_opts
, "initrd");
2382 const char *kernel_cmdline
= qemu_opt_get(machine_opts
, "append");
2384 if (kernel_filename
== NULL
) {
2385 if (kernel_cmdline
!= NULL
) {
2386 error_report("-append only allowed with -kernel option");
2390 if (initrd_filename
!= NULL
) {
2391 error_report("-initrd only allowed with -kernel option");
2396 if (loadvm
&& preconfig_requested
) {
2397 error_report("'preconfig' and 'loadvm' options are "
2398 "mutually exclusive");
2401 if (incoming
&& preconfig_requested
&& strcmp(incoming
, "defer") != 0) {
2402 error_report("'preconfig' supports '-incoming defer' only");
2406 #ifdef CONFIG_CURSES
2407 if (is_daemonized() && dpy
.type
== DISPLAY_TYPE_CURSES
) {
2408 error_report("curses display cannot be used with -daemonize");
2414 static void qemu_process_sugar_options(void)
2419 val
= g_strdup_printf("%d",
2420 (uint32_t) qemu_opt_get_number(qemu_find_opts_singleton("smp-opts"), "cpus", 1));
2421 object_register_sugar_prop("memory-backend", "prealloc-threads", val
,
2424 object_register_sugar_prop("memory-backend", "prealloc", "on", false);
2428 int i
= select_watchdog(watchdog
);
2430 exit (i
== 1 ? 1 : 0);
2434 /* -action processing */
2437 * Process all the -action parameters parsed from cmdline.
2439 static int process_runstate_actions(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2441 Error
*local_err
= NULL
;
2442 QDict
*qdict
= qemu_opts_to_qdict(opts
, NULL
);
2443 QObject
*ret
= NULL
;
2444 qmp_marshal_set_action(qdict
, &ret
, &local_err
);
2446 qobject_unref(qdict
);
2448 error_propagate(errp
, local_err
);
2454 static void qemu_process_early_options(void)
2456 #ifdef CONFIG_SECCOMP
2457 QemuOptsList
*olist
= qemu_find_opts_err("sandbox", NULL
);
2459 qemu_opts_foreach(olist
, parse_sandbox
, NULL
, &error_fatal
);
2463 qemu_opts_foreach(qemu_find_opts("name"),
2464 parse_name
, NULL
, &error_fatal
);
2466 if (qemu_opts_foreach(qemu_find_opts("action"),
2467 process_runstate_actions
, NULL
, &error_fatal
)) {
2472 qemu_opts_foreach(qemu_find_opts("add-fd"),
2473 parse_add_fd
, NULL
, &error_fatal
);
2475 qemu_opts_foreach(qemu_find_opts("add-fd"),
2476 cleanup_add_fd
, NULL
, &error_fatal
);
2479 /* Open the logfile at this point and set the log mask if necessary. */
2481 qemu_set_log_filename(log_file
, &error_fatal
);
2485 mask
= qemu_str_to_log_mask(log_mask
);
2487 qemu_print_log_usage(stdout
);
2495 qemu_add_default_firmwarepath();
2498 static void qemu_process_help_options(void)
2501 * Check for -cpu help and -device help before we call select_machine(),
2502 * which will return an error if the architecture has no default machine
2503 * type and the user did not specify one, so that the user doesn't need
2504 * to say '-cpu help -machine something'.
2506 if (cpu_option
&& is_help_option(cpu_option
)) {
2507 list_cpus(cpu_option
);
2511 if (qemu_opts_foreach(qemu_find_opts("device"),
2512 device_help_func
, NULL
, NULL
)) {
2516 /* -L help lists the data directories and exits. */
2517 if (list_data_dirs
) {
2518 qemu_list_data_dirs();
2523 static void qemu_maybe_daemonize(const char *pid_file
)
2528 rcu_disable_atfork();
2530 if (pid_file
&& !qemu_write_pidfile(pid_file
, &err
)) {
2531 error_reportf_err(err
, "cannot create PID file: ");
2535 qemu_unlink_pidfile_notifier
.notify
= qemu_unlink_pidfile
;
2536 qemu_add_exit_notifier(&qemu_unlink_pidfile_notifier
);
2539 static void qemu_init_displays(void)
2543 /* init local displays */
2544 ds
= init_displaystate();
2545 qemu_display_init(ds
, &dpy
);
2547 /* must be after terminal init, SDL library changes signal handlers */
2548 os_setup_signal_handling();
2550 /* init remote displays */
2552 qemu_opts_foreach(qemu_find_opts("vnc"),
2553 vnc_init_func
, NULL
, &error_fatal
);
2557 qemu_spice
.display_init();
2561 static void qemu_init_board(void)
2563 MachineClass
*machine_class
= MACHINE_GET_CLASS(current_machine
);
2565 if (machine_class
->default_ram_id
&& current_machine
->ram_size
&&
2566 numa_uses_legacy_mem() && !current_machine
->ram_memdev_id
) {
2567 create_default_memdev(current_machine
, mem_path
);
2570 /* process plugin before CPUs are created, but once -smp has been parsed */
2571 qemu_plugin_load_list(&plugin_list
, &error_fatal
);
2573 /* From here on we enter MACHINE_PHASE_INITIALIZED. */
2574 machine_run_board_init(current_machine
);
2576 drive_check_orphaned();
2580 if (hax_enabled()) {
2581 /* FIXME: why isn't cpu_synchronize_all_post_init enough? */
2586 static void qemu_create_cli_devices(void)
2590 qemu_opts_foreach(qemu_find_opts("fw_cfg"),
2591 parse_fw_cfg
, fw_cfg_find(), &error_fatal
);
2593 /* init USB devices */
2594 if (machine_usb(current_machine
)) {
2595 if (foreach_device_config(DEV_USB
, usb_parse
) < 0)
2599 /* init generic devices */
2600 rom_set_order_override(FW_CFG_ORDER_OVERRIDE_DEVICE
);
2601 qemu_opts_foreach(qemu_find_opts("device"),
2602 device_init_func
, NULL
, &error_fatal
);
2603 rom_reset_order_override();
2606 static void qemu_machine_creation_done(void)
2608 MachineState
*machine
= MACHINE(qdev_get_machine());
2610 /* Did we create any drives that we failed to create a device for? */
2611 drive_check_orphaned();
2613 /* Don't warn about the default network setup that you get if
2614 * no command line -net or -netdev options are specified. There
2615 * are two cases that we would otherwise complain about:
2616 * (1) board doesn't support a NIC but the implicit "-net nic"
2618 * (2) CONFIG_SLIRP not set, in which case the implicit "-net nic"
2619 * sets up a nic that isn't connected to anything.
2621 if (!default_net
&& (!qtest_enabled() || has_defaults
)) {
2622 net_check_clients();
2625 qdev_prop_check_globals();
2627 qdev_machine_creation_done();
2631 * Verify that Confidential Guest Support has actually been initialized
2633 assert(machine
->cgs
->ready
);
2636 if (foreach_device_config(DEV_GDB
, gdbserver_start
) < 0) {
2641 void qmp_x_exit_preconfig(Error
**errp
)
2643 if (phase_check(PHASE_MACHINE_INITIALIZED
)) {
2644 error_setg(errp
, "The command is permitted only before machine initialization");
2649 qemu_create_cli_devices();
2650 qemu_machine_creation_done();
2653 Error
*local_err
= NULL
;
2654 if (!load_snapshot(loadvm
, NULL
, false, NULL
, &local_err
)) {
2655 error_report_err(local_err
);
2660 if (replay_mode
!= REPLAY_MODE_NONE
) {
2661 replay_vmstate_init();
2665 Error
*local_err
= NULL
;
2666 if (strcmp(incoming
, "defer") != 0) {
2667 qmp_migrate_incoming(incoming
, &local_err
);
2669 error_reportf_err(local_err
, "-incoming %s: ", incoming
);
2673 } else if (autostart
) {
2678 #ifdef CONFIG_MODULES
2679 void qemu_load_module_for_opts(const char *group
)
2681 static bool spice_tried
;
2682 if (g_str_equal(group
, "spice") && !spice_tried
) {
2683 ui_module_load_one("spice-core");
2687 static bool iscsi_tried
;
2688 if (g_str_equal(group
, "iscsi") && !iscsi_tried
) {
2689 block_module_load_one("iscsi");
2695 void qemu_init(int argc
, char **argv
, char **envp
)
2698 QemuOpts
*icount_opts
= NULL
, *accel_opts
= NULL
;
2699 QemuOptsList
*olist
;
2702 MachineClass
*machine_class
;
2703 bool userconfig
= true;
2704 FILE *vmstate_dump_file
= NULL
;
2706 qemu_add_opts(&qemu_drive_opts
);
2707 qemu_add_drive_opts(&qemu_legacy_drive_opts
);
2708 qemu_add_drive_opts(&qemu_common_drive_opts
);
2709 qemu_add_drive_opts(&qemu_drive_opts
);
2710 qemu_add_drive_opts(&bdrv_runtime_opts
);
2711 qemu_add_opts(&qemu_chardev_opts
);
2712 qemu_add_opts(&qemu_device_opts
);
2713 qemu_add_opts(&qemu_netdev_opts
);
2714 qemu_add_opts(&qemu_nic_opts
);
2715 qemu_add_opts(&qemu_net_opts
);
2716 qemu_add_opts(&qemu_rtc_opts
);
2717 qemu_add_opts(&qemu_global_opts
);
2718 qemu_add_opts(&qemu_mon_opts
);
2719 qemu_add_opts(&qemu_trace_opts
);
2720 qemu_plugin_add_opts();
2721 qemu_add_opts(&qemu_option_rom_opts
);
2722 qemu_add_opts(&qemu_machine_opts
);
2723 qemu_add_opts(&qemu_accel_opts
);
2724 qemu_add_opts(&qemu_mem_opts
);
2725 qemu_add_opts(&qemu_smp_opts
);
2726 qemu_add_opts(&qemu_boot_opts
);
2727 qemu_add_opts(&qemu_add_fd_opts
);
2728 qemu_add_opts(&qemu_object_opts
);
2729 qemu_add_opts(&qemu_tpmdev_opts
);
2730 qemu_add_opts(&qemu_overcommit_opts
);
2731 qemu_add_opts(&qemu_msg_opts
);
2732 qemu_add_opts(&qemu_name_opts
);
2733 qemu_add_opts(&qemu_numa_opts
);
2734 qemu_add_opts(&qemu_icount_opts
);
2735 qemu_add_opts(&qemu_semihosting_config_opts
);
2736 qemu_add_opts(&qemu_fw_cfg_opts
);
2737 qemu_add_opts(&qemu_action_opts
);
2738 module_call_init(MODULE_INIT_OPTS
);
2740 error_init(argv
[0]);
2741 qemu_init_exec_dir(argv
[0]);
2743 qemu_init_subsystems();
2745 /* first pass of option parsing */
2747 while (optind
< argc
) {
2748 if (argv
[optind
][0] != '-') {
2752 const QEMUOption
*popt
;
2754 popt
= lookup_opt(argc
, argv
, &optarg
, &optind
);
2755 switch (popt
->index
) {
2756 case QEMU_OPTION_nouserconfig
:
2764 qemu_read_default_config_file(&error_fatal
);
2767 /* second pass of option parsing */
2772 if (argv
[optind
][0] != '-') {
2773 loc_set_cmdline(argv
, optind
, 1);
2774 drive_add(IF_DEFAULT
, 0, argv
[optind
++], HD_OPTS
);
2776 const QEMUOption
*popt
;
2778 popt
= lookup_opt(argc
, argv
, &optarg
, &optind
);
2779 if (!(popt
->arch_mask
& arch_type
)) {
2780 error_report("Option not supported for this target");
2783 switch(popt
->index
) {
2784 case QEMU_OPTION_cpu
:
2785 /* hw initialization will check this */
2786 cpu_option
= optarg
;
2788 case QEMU_OPTION_hda
:
2789 case QEMU_OPTION_hdb
:
2790 case QEMU_OPTION_hdc
:
2791 case QEMU_OPTION_hdd
:
2792 drive_add(IF_DEFAULT
, popt
->index
- QEMU_OPTION_hda
, optarg
,
2795 case QEMU_OPTION_blockdev
:
2798 BlockdevOptionsQueueEntry
*bdo
;
2800 v
= qobject_input_visitor_new_str(optarg
, "driver",
2803 bdo
= g_new(BlockdevOptionsQueueEntry
, 1);
2804 visit_type_BlockdevOptions(v
, NULL
, &bdo
->bdo
,
2807 loc_save(&bdo
->loc
);
2808 QSIMPLEQ_INSERT_TAIL(&bdo_queue
, bdo
, entry
);
2811 case QEMU_OPTION_drive
:
2812 if (drive_def(optarg
) == NULL
) {
2816 case QEMU_OPTION_set
:
2817 qemu_set_option(optarg
, &error_fatal
);
2819 case QEMU_OPTION_global
:
2820 if (qemu_global_option(optarg
) != 0)
2823 case QEMU_OPTION_mtdblock
:
2824 drive_add(IF_MTD
, -1, optarg
, MTD_OPTS
);
2826 case QEMU_OPTION_sd
:
2827 drive_add(IF_SD
, -1, optarg
, SD_OPTS
);
2829 case QEMU_OPTION_pflash
:
2830 drive_add(IF_PFLASH
, -1, optarg
, PFLASH_OPTS
);
2832 case QEMU_OPTION_snapshot
:
2834 Error
*blocker
= NULL
;
2836 error_setg(&blocker
, QERR_REPLAY_NOT_SUPPORTED
,
2838 replay_add_blocker(blocker
);
2841 case QEMU_OPTION_numa
:
2842 opts
= qemu_opts_parse_noisily(qemu_find_opts("numa"),
2848 case QEMU_OPTION_display
:
2849 parse_display(optarg
);
2851 case QEMU_OPTION_nographic
:
2852 olist
= qemu_find_opts("machine");
2853 qemu_opts_parse_noisily(olist
, "graphics=off", false);
2855 dpy
.type
= DISPLAY_TYPE_NONE
;
2857 case QEMU_OPTION_curses
:
2858 #ifdef CONFIG_CURSES
2859 dpy
.type
= DISPLAY_TYPE_CURSES
;
2861 error_report("curses or iconv support is disabled");
2865 case QEMU_OPTION_portrait
:
2866 graphic_rotate
= 90;
2868 case QEMU_OPTION_rotate
:
2869 graphic_rotate
= strtol(optarg
, (char **) &optarg
, 10);
2870 if (graphic_rotate
!= 0 && graphic_rotate
!= 90 &&
2871 graphic_rotate
!= 180 && graphic_rotate
!= 270) {
2872 error_report("only 90, 180, 270 deg rotation is available");
2876 case QEMU_OPTION_kernel
:
2877 qemu_opts_set(qemu_find_opts("machine"), "kernel", optarg
, &error_abort
);
2879 case QEMU_OPTION_initrd
:
2880 qemu_opts_set(qemu_find_opts("machine"), "initrd", optarg
, &error_abort
);
2882 case QEMU_OPTION_append
:
2883 qemu_opts_set(qemu_find_opts("machine"), "append", optarg
, &error_abort
);
2885 case QEMU_OPTION_dtb
:
2886 qemu_opts_set(qemu_find_opts("machine"), "dtb", optarg
, &error_abort
);
2888 case QEMU_OPTION_cdrom
:
2889 drive_add(IF_DEFAULT
, 2, optarg
, CDROM_OPTS
);
2891 case QEMU_OPTION_boot
:
2892 opts
= qemu_opts_parse_noisily(qemu_find_opts("boot-opts"),
2898 case QEMU_OPTION_fda
:
2899 case QEMU_OPTION_fdb
:
2900 drive_add(IF_FLOPPY
, popt
->index
- QEMU_OPTION_fda
,
2903 case QEMU_OPTION_no_fd_bootchk
:
2906 case QEMU_OPTION_netdev
:
2908 if (net_client_parse(qemu_find_opts("netdev"), optarg
) == -1) {
2912 case QEMU_OPTION_nic
:
2914 if (net_client_parse(qemu_find_opts("nic"), optarg
) == -1) {
2918 case QEMU_OPTION_net
:
2920 if (net_client_parse(qemu_find_opts("net"), optarg
) == -1) {
2924 #ifdef CONFIG_LIBISCSI
2925 case QEMU_OPTION_iscsi
:
2926 opts
= qemu_opts_parse_noisily(qemu_find_opts("iscsi"),
2933 case QEMU_OPTION_audio_help
:
2934 audio_legacy_help();
2937 case QEMU_OPTION_audiodev
:
2938 audio_parse_option(optarg
);
2940 case QEMU_OPTION_soundhw
:
2941 select_soundhw (optarg
);
2946 case QEMU_OPTION_version
:
2951 opts
= qemu_opts_parse_noisily(qemu_find_opts("memory"),
2958 case QEMU_OPTION_tpmdev
:
2959 if (tpm_config_parse(qemu_find_opts("tpmdev"), optarg
) < 0) {
2964 case QEMU_OPTION_mempath
:
2967 case QEMU_OPTION_mem_prealloc
:
2976 case QEMU_OPTION_DFILTER
:
2977 qemu_set_dfilter_ranges(optarg
, &error_fatal
);
2979 case QEMU_OPTION_seed
:
2980 qemu_guest_random_seed_main(optarg
, &error_fatal
);
2983 add_device_config(DEV_GDB
, "tcp::" DEFAULT_GDBSTUB_PORT
);
2985 case QEMU_OPTION_gdb
:
2986 add_device_config(DEV_GDB
, optarg
);
2989 if (is_help_option(optarg
)) {
2990 list_data_dirs
= true;
2992 qemu_add_data_dir(g_strdup(optarg
));
2995 case QEMU_OPTION_bios
:
2996 qemu_opts_set(qemu_find_opts("machine"), "firmware", optarg
, &error_abort
);
2998 case QEMU_OPTION_singlestep
:
3005 keyboard_layout
= optarg
;
3007 case QEMU_OPTION_vga
:
3016 w
= strtol(p
, (char **)&p
, 10);
3019 error_report("invalid resolution or depth");
3025 h
= strtol(p
, (char **)&p
, 10);
3030 depth
= strtol(p
, (char **)&p
, 10);
3031 if (depth
!= 1 && depth
!= 2 && depth
!= 4 &&
3032 depth
!= 8 && depth
!= 15 && depth
!= 16 &&
3033 depth
!= 24 && depth
!= 32)
3035 } else if (*p
== '\0') {
3036 depth
= graphic_depth
;
3043 graphic_depth
= depth
;
3046 case QEMU_OPTION_echr
:
3049 term_escape_char
= strtol(optarg
, &r
, 0);
3051 printf("Bad argument to echr\n");
3054 case QEMU_OPTION_monitor
:
3055 default_monitor
= 0;
3056 if (strncmp(optarg
, "none", 4)) {
3057 monitor_parse(optarg
, "readline", false);
3060 case QEMU_OPTION_qmp
:
3061 monitor_parse(optarg
, "control", false);
3062 default_monitor
= 0;
3064 case QEMU_OPTION_qmp_pretty
:
3065 monitor_parse(optarg
, "control", true);
3066 default_monitor
= 0;
3068 case QEMU_OPTION_mon
:
3069 opts
= qemu_opts_parse_noisily(qemu_find_opts("mon"), optarg
,
3074 default_monitor
= 0;
3076 case QEMU_OPTION_chardev
:
3077 opts
= qemu_opts_parse_noisily(qemu_find_opts("chardev"),
3083 case QEMU_OPTION_fsdev
:
3084 olist
= qemu_find_opts("fsdev");
3086 error_report("fsdev support is disabled");
3089 opts
= qemu_opts_parse_noisily(olist
, optarg
, true);
3094 case QEMU_OPTION_virtfs
: {
3097 const char *writeout
, *sock_fd
, *socket
, *path
, *security_model
,
3100 olist
= qemu_find_opts("virtfs");
3102 error_report("virtfs support is disabled");
3105 opts
= qemu_opts_parse_noisily(olist
, optarg
, true);
3110 if (qemu_opt_get(opts
, "fsdriver") == NULL
||
3111 qemu_opt_get(opts
, "mount_tag") == NULL
) {
3112 error_report("Usage: -virtfs fsdriver,mount_tag=tag");
3115 fsdev
= qemu_opts_create(qemu_find_opts("fsdev"),
3116 qemu_opts_id(opts
) ?:
3117 qemu_opt_get(opts
, "mount_tag"),
3120 error_report("duplicate or invalid fsdev id: %s",
3121 qemu_opt_get(opts
, "mount_tag"));
3125 writeout
= qemu_opt_get(opts
, "writeout");
3127 #ifdef CONFIG_SYNC_FILE_RANGE
3128 qemu_opt_set(fsdev
, "writeout", writeout
, &error_abort
);
3130 error_report("writeout=immediate not supported "
3131 "on this platform");
3135 qemu_opt_set(fsdev
, "fsdriver",
3136 qemu_opt_get(opts
, "fsdriver"), &error_abort
);
3137 path
= qemu_opt_get(opts
, "path");
3139 qemu_opt_set(fsdev
, "path", path
, &error_abort
);
3141 security_model
= qemu_opt_get(opts
, "security_model");
3142 if (security_model
) {
3143 qemu_opt_set(fsdev
, "security_model", security_model
,
3146 socket
= qemu_opt_get(opts
, "socket");
3148 qemu_opt_set(fsdev
, "socket", socket
, &error_abort
);
3150 sock_fd
= qemu_opt_get(opts
, "sock_fd");
3152 qemu_opt_set(fsdev
, "sock_fd", sock_fd
, &error_abort
);
3155 qemu_opt_set_bool(fsdev
, "readonly",
3156 qemu_opt_get_bool(opts
, "readonly", 0),
3158 multidevs
= qemu_opt_get(opts
, "multidevs");
3160 qemu_opt_set(fsdev
, "multidevs", multidevs
, &error_abort
);
3162 device
= qemu_opts_create(qemu_find_opts("device"), NULL
, 0,
3164 qemu_opt_set(device
, "driver", "virtio-9p-pci", &error_abort
);
3165 qemu_opt_set(device
, "fsdev",
3166 qemu_opts_id(fsdev
), &error_abort
);
3167 qemu_opt_set(device
, "mount_tag",
3168 qemu_opt_get(opts
, "mount_tag"), &error_abort
);
3171 case QEMU_OPTION_serial
:
3172 add_device_config(DEV_SERIAL
, optarg
);
3174 if (strncmp(optarg
, "mon:", 4) == 0) {
3175 default_monitor
= 0;
3178 case QEMU_OPTION_watchdog
:
3180 error_report("only one watchdog option may be given");
3185 case QEMU_OPTION_action
:
3186 olist
= qemu_find_opts("action");
3187 if (!qemu_opts_parse_noisily(olist
, optarg
, false)) {
3191 case QEMU_OPTION_watchdog_action
:
3192 if (select_watchdog_action(optarg
) == -1) {
3193 error_report("unknown -watchdog-action parameter");
3197 case QEMU_OPTION_parallel
:
3198 add_device_config(DEV_PARALLEL
, optarg
);
3199 default_parallel
= 0;
3200 if (strncmp(optarg
, "mon:", 4) == 0) {
3201 default_monitor
= 0;
3204 case QEMU_OPTION_debugcon
:
3205 add_device_config(DEV_DEBUGCON
, optarg
);
3207 case QEMU_OPTION_loadvm
:
3210 case QEMU_OPTION_full_screen
:
3211 dpy
.has_full_screen
= true;
3212 dpy
.full_screen
= true;
3214 case QEMU_OPTION_alt_grab
:
3217 case QEMU_OPTION_ctrl_grab
:
3220 case QEMU_OPTION_no_quit
:
3221 dpy
.has_window_close
= true;
3222 dpy
.window_close
= false;
3224 case QEMU_OPTION_sdl
:
3226 dpy
.type
= DISPLAY_TYPE_SDL
;
3229 error_report("SDL support is disabled");
3232 case QEMU_OPTION_pidfile
:
3235 case QEMU_OPTION_win2k_hack
:
3236 win2k_install_hack
= 1;
3238 case QEMU_OPTION_acpitable
:
3239 opts
= qemu_opts_parse_noisily(qemu_find_opts("acpi"),
3244 acpi_table_add(opts
, &error_fatal
);
3246 case QEMU_OPTION_smbios
:
3247 opts
= qemu_opts_parse_noisily(qemu_find_opts("smbios"),
3252 smbios_entry_add(opts
, &error_fatal
);
3254 case QEMU_OPTION_fwcfg
:
3255 opts
= qemu_opts_parse_noisily(qemu_find_opts("fw_cfg"),
3261 case QEMU_OPTION_preconfig
:
3262 preconfig_requested
= true;
3264 case QEMU_OPTION_enable_kvm
:
3265 olist
= qemu_find_opts("machine");
3266 qemu_opts_parse_noisily(olist
, "accel=kvm", false);
3269 case QEMU_OPTION_machine
:
3270 olist
= qemu_find_opts("machine");
3271 opts
= qemu_opts_parse_noisily(olist
, optarg
, true);
3276 case QEMU_OPTION_accel
:
3277 accel_opts
= qemu_opts_parse_noisily(qemu_find_opts("accel"),
3279 optarg
= qemu_opt_get(accel_opts
, "accel");
3280 if (!optarg
|| is_help_option(optarg
)) {
3281 printf("Accelerators supported in QEMU binary:\n");
3282 GSList
*el
, *accel_list
= object_class_get_list(TYPE_ACCEL
,
3284 for (el
= accel_list
; el
; el
= el
->next
) {
3285 gchar
*typename
= g_strdup(object_class_get_name(
3286 OBJECT_CLASS(el
->data
)));
3287 /* omit qtest which is used for tests only */
3288 if (g_strcmp0(typename
, ACCEL_CLASS_NAME("qtest")) &&
3289 g_str_has_suffix(typename
, ACCEL_CLASS_SUFFIX
)) {
3290 gchar
**optname
= g_strsplit(typename
,
3291 ACCEL_CLASS_SUFFIX
, 0);
3292 printf("%s\n", optname
[0]);
3293 g_strfreev(optname
);
3297 g_slist_free(accel_list
);
3301 case QEMU_OPTION_usb
:
3302 olist
= qemu_find_opts("machine");
3303 qemu_opts_parse_noisily(olist
, "usb=on", false);
3305 case QEMU_OPTION_usbdevice
:
3306 olist
= qemu_find_opts("machine");
3307 qemu_opts_parse_noisily(olist
, "usb=on", false);
3308 add_device_config(DEV_USB
, optarg
);
3310 case QEMU_OPTION_device
:
3311 if (!qemu_opts_parse_noisily(qemu_find_opts("device"),
3316 case QEMU_OPTION_smp
:
3317 if (!qemu_opts_parse_noisily(qemu_find_opts("smp-opts"),
3322 case QEMU_OPTION_vnc
:
3325 case QEMU_OPTION_no_acpi
:
3326 olist
= qemu_find_opts("machine");
3327 qemu_opts_parse_noisily(olist
, "acpi=off", false);
3329 case QEMU_OPTION_no_hpet
:
3330 olist
= qemu_find_opts("machine");
3331 qemu_opts_parse_noisily(olist
, "hpet=off", false);
3333 case QEMU_OPTION_no_reboot
:
3334 olist
= qemu_find_opts("action");
3335 qemu_opts_parse_noisily(olist
, "reboot=shutdown", false);
3337 case QEMU_OPTION_no_shutdown
:
3338 olist
= qemu_find_opts("action");
3339 qemu_opts_parse_noisily(olist
, "shutdown=pause", false);
3341 case QEMU_OPTION_uuid
:
3342 if (qemu_uuid_parse(optarg
, &qemu_uuid
) < 0) {
3343 error_report("failed to parse UUID string: wrong format");
3346 qemu_uuid_set
= true;
3348 case QEMU_OPTION_option_rom
:
3349 if (nb_option_roms
>= MAX_OPTION_ROMS
) {
3350 error_report("too many option ROMs");
3353 opts
= qemu_opts_parse_noisily(qemu_find_opts("option-rom"),
3358 option_rom
[nb_option_roms
].name
= qemu_opt_get(opts
, "romfile");
3359 option_rom
[nb_option_roms
].bootindex
=
3360 qemu_opt_get_number(opts
, "bootindex", -1);
3361 if (!option_rom
[nb_option_roms
].name
) {
3362 error_report("Option ROM file is not specified");
3367 case QEMU_OPTION_semihosting
:
3368 qemu_semihosting_enable();
3370 case QEMU_OPTION_semihosting_config
:
3371 if (qemu_semihosting_config_options(optarg
) != 0) {
3375 case QEMU_OPTION_name
:
3376 opts
= qemu_opts_parse_noisily(qemu_find_opts("name"),
3381 /* Capture guest name if -msg guest-name is used later */
3382 error_guest_name
= qemu_opt_get(opts
, "guest");
3384 case QEMU_OPTION_prom_env
:
3385 if (nb_prom_envs
>= MAX_PROM_ENVS
) {
3386 error_report("too many prom variables");
3389 prom_envs
[nb_prom_envs
] = optarg
;
3392 case QEMU_OPTION_old_param
:
3395 case QEMU_OPTION_rtc
:
3396 opts
= qemu_opts_parse_noisily(qemu_find_opts("rtc"), optarg
,
3402 case QEMU_OPTION_icount
:
3403 icount_opts
= qemu_opts_parse_noisily(qemu_find_opts("icount"),
3409 case QEMU_OPTION_incoming
:
3411 runstate_set(RUN_STATE_INMIGRATE
);
3415 case QEMU_OPTION_only_migratable
:
3416 only_migratable
= 1;
3418 case QEMU_OPTION_nodefaults
:
3421 case QEMU_OPTION_xen_domid
:
3422 if (!(xen_available())) {
3423 error_report("Option not supported for this target");
3426 xen_domid
= atoi(optarg
);
3428 case QEMU_OPTION_xen_attach
:
3429 if (!(xen_available())) {
3430 error_report("Option not supported for this target");
3433 xen_mode
= XEN_ATTACH
;
3435 case QEMU_OPTION_xen_domid_restrict
:
3436 if (!(xen_available())) {
3437 error_report("Option not supported for this target");
3440 xen_domid_restrict
= true;
3442 case QEMU_OPTION_trace
:
3443 trace_opt_parse(optarg
);
3445 case QEMU_OPTION_plugin
:
3446 qemu_plugin_opt_parse(optarg
, &plugin_list
);
3448 case QEMU_OPTION_readconfig
:
3449 qemu_read_config_file(optarg
, qemu_parse_config_group
, &error_fatal
);
3451 case QEMU_OPTION_spice
:
3452 olist
= qemu_find_opts_err("spice", NULL
);
3454 error_report("spice support is disabled");
3457 opts
= qemu_opts_parse_noisily(olist
, optarg
, false);
3463 case QEMU_OPTION_writeconfig
:
3466 warn_report("-writeconfig is deprecated and will go away without a replacement");
3467 if (strcmp(optarg
, "-") == 0) {
3470 fp
= fopen(optarg
, "w");
3472 error_report("open %s: %s", optarg
,
3477 qemu_config_write(fp
);
3483 case QEMU_OPTION_qtest
:
3484 qtest_chrdev
= optarg
;
3486 case QEMU_OPTION_qtest_log
:
3489 case QEMU_OPTION_sandbox
:
3490 olist
= qemu_find_opts("sandbox");
3492 #ifndef CONFIG_SECCOMP
3493 error_report("-sandbox support is not enabled "
3494 "in this QEMU binary");
3499 opts
= qemu_opts_parse_noisily(olist
, optarg
, true);
3504 case QEMU_OPTION_add_fd
:
3506 opts
= qemu_opts_parse_noisily(qemu_find_opts("add-fd"),
3512 error_report("File descriptor passing is disabled on this "
3517 case QEMU_OPTION_object
:
3518 object_option_parse(optarg
);
3520 case QEMU_OPTION_overcommit
:
3521 opts
= qemu_opts_parse_noisily(qemu_find_opts("overcommit"),
3526 enable_mlock
= qemu_opt_get_bool(opts
, "mem-lock", false);
3527 enable_cpu_pm
= qemu_opt_get_bool(opts
, "cpu-pm", false);
3529 case QEMU_OPTION_compat
:
3534 v
= qobject_input_visitor_new_str(optarg
, NULL
,
3537 visit_type_CompatPolicy(v
, NULL
, &opts
, &error_fatal
);
3538 QAPI_CLONE_MEMBERS(CompatPolicy
, &compat_policy
, opts
);
3540 qapi_free_CompatPolicy(opts
);
3544 case QEMU_OPTION_msg
:
3545 opts
= qemu_opts_parse_noisily(qemu_find_opts("msg"), optarg
,
3550 configure_msg(opts
);
3552 case QEMU_OPTION_dump_vmstate
:
3553 if (vmstate_dump_file
) {
3554 error_report("only one '-dump-vmstate' "
3555 "option may be given");
3558 vmstate_dump_file
= fopen(optarg
, "w");
3559 if (vmstate_dump_file
== NULL
) {
3560 error_report("open %s: %s", optarg
, strerror(errno
));
3564 case QEMU_OPTION_enable_sync_profile
:
3567 case QEMU_OPTION_nouserconfig
:
3568 /* Nothing to be parsed here. Especially, do not error out below. */
3571 if (os_parse_cmd_args(popt
->index
, optarg
)) {
3572 error_report("Option not supported in this build");
3579 * Clear error location left behind by the loop.
3580 * Best done right after the loop. Do not insert code here!
3584 qemu_validate_options();
3585 qemu_process_sugar_options();
3588 * These options affect everything else and should be processed
3589 * before daemonizing.
3591 qemu_process_early_options();
3593 qemu_process_help_options();
3594 qemu_maybe_daemonize(pid_file
);
3597 * The trace backend must be initialized after daemonizing.
3598 * trace_init_backends() will call st_init(), which will create the
3599 * trace thread in the parent, and also register st_flush_trace_buffer()
3600 * in atexit(). This function will force the parent to wait for the
3601 * writeout thread to finish, which will not occur, and the parent
3602 * process will be left in the host.
3604 if (!trace_init_backends()) {
3609 qemu_init_main_loop(&error_fatal
);
3612 user_register_global_props();
3613 replay_configure(icount_opts
);
3615 configure_rtc(qemu_find_opts_singleton("rtc"));
3617 qemu_create_machine(select_machine());
3621 qemu_disable_default_devices();
3622 qemu_create_default_devices();
3623 qemu_create_early_backends();
3625 qemu_apply_machine_options();
3626 phase_advance(PHASE_MACHINE_CREATED
);
3629 * Note: uses machine properties such as kernel-irqchip, must run
3630 * after machine_set_property().
3632 configure_accelerators(argv
[0]);
3633 phase_advance(PHASE_ACCEL_CREATED
);
3636 * Beware, QOM objects created before this point miss global and
3637 * compat properties.
3639 * Global properties get set up by qdev_prop_register_global(),
3640 * called from user_register_global_props(), and certain option
3641 * desugaring. Also in CPU feature desugaring (buried in
3642 * parse_cpu_option()), which happens below this point, but may
3643 * only target the CPU type, which can only be created after
3644 * parse_cpu_option() returned the type.
3646 * Machine compat properties: object_set_machine_compat_props().
3647 * Accelerator compat props: object_set_accelerator_compat_props(),
3648 * called from do_configure_accelerator().
3651 machine_class
= MACHINE_GET_CLASS(current_machine
);
3652 if (!qtest_enabled() && machine_class
->deprecation_reason
) {
3653 error_report("Machine type '%s' is deprecated: %s",
3654 machine_class
->name
, machine_class
->deprecation_reason
);
3658 * Note: creates a QOM object, must run only after global and
3659 * compat properties have been set up.
3661 migration_object_init();
3663 qemu_create_late_backends();
3665 /* parse features once if machine provides default cpu_type */
3666 current_machine
->cpu_type
= machine_class
->default_cpu_type
;
3668 current_machine
->cpu_type
= parse_cpu_option(cpu_option
);
3670 /* NB: for machine none cpu_type could STILL be NULL here! */
3672 qemu_resolve_machine_memdev();
3673 parse_numa_opts(current_machine
);
3675 if (vmstate_dump_file
) {
3677 dump_vmstate_json_to_file(vmstate_dump_file
);
3681 if (!preconfig_requested
) {
3682 qmp_x_exit_preconfig(&error_fatal
);
3684 qemu_init_displays();
3685 accel_setup_post(current_machine
);