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 #if defined(CONFIG_SDL)
1072 dpy
.type
= DISPLAY_TYPE_SDL
;
1074 const char *nextopt
;
1076 if (strstart(opts
, ",alt_grab=", &nextopt
)) {
1078 if (strstart(opts
, "on", &nextopt
)) {
1080 } else if (strstart(opts
, "off", &nextopt
)) {
1083 goto invalid_sdl_args
;
1085 } else if (strstart(opts
, ",ctrl_grab=", &nextopt
)) {
1087 if (strstart(opts
, "on", &nextopt
)) {
1089 } else if (strstart(opts
, "off", &nextopt
)) {
1092 goto invalid_sdl_args
;
1094 } else if (strstart(opts
, ",window_close=", &nextopt
)) {
1096 dpy
.has_window_close
= true;
1097 if (strstart(opts
, "on", &nextopt
)) {
1098 dpy
.window_close
= true;
1099 } else if (strstart(opts
, "off", &nextopt
)) {
1100 dpy
.window_close
= false;
1102 goto invalid_sdl_args
;
1104 } else if (strstart(opts
, ",show-cursor=", &nextopt
)) {
1106 dpy
.has_show_cursor
= true;
1107 if (strstart(opts
, "on", &nextopt
)) {
1108 dpy
.show_cursor
= true;
1109 } else if (strstart(opts
, "off", &nextopt
)) {
1110 dpy
.show_cursor
= false;
1112 goto invalid_sdl_args
;
1114 } else if (strstart(opts
, ",gl=", &nextopt
)) {
1117 if (strstart(opts
, "on", &nextopt
)) {
1118 dpy
.gl
= DISPLAYGL_MODE_ON
;
1119 } else if (strstart(opts
, "core", &nextopt
)) {
1120 dpy
.gl
= DISPLAYGL_MODE_CORE
;
1121 } else if (strstart(opts
, "es", &nextopt
)) {
1122 dpy
.gl
= DISPLAYGL_MODE_ES
;
1123 } else if (strstart(opts
, "off", &nextopt
)) {
1124 dpy
.gl
= DISPLAYGL_MODE_OFF
;
1126 goto invalid_sdl_args
;
1130 error_report("invalid SDL option string");
1136 error_report("SDL display supported is not available in this binary");
1139 } else if (strstart(p
, "vnc", &opts
)) {
1141 * vnc isn't a (local) DisplayType but a protocol for remote
1145 vnc_parse(opts
+ 1);
1147 error_report("VNC requires a display argument vnc=<display>");
1151 parse_display_qapi(p
);
1155 static inline bool nonempty_str(const char *str
)
1160 static int parse_fw_cfg(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1164 const char *name
, *file
, *str
, *gen_id
;
1165 FWCfgState
*fw_cfg
= (FWCfgState
*) opaque
;
1167 if (fw_cfg
== NULL
) {
1168 error_setg(errp
, "fw_cfg device not available");
1171 name
= qemu_opt_get(opts
, "name");
1172 file
= qemu_opt_get(opts
, "file");
1173 str
= qemu_opt_get(opts
, "string");
1174 gen_id
= qemu_opt_get(opts
, "gen_id");
1176 /* we need the name, and exactly one of: file, content string, gen_id */
1177 if (!nonempty_str(name
) ||
1178 nonempty_str(file
) + nonempty_str(str
) + nonempty_str(gen_id
) != 1) {
1179 error_setg(errp
, "name, plus exactly one of file,"
1180 " string and gen_id, are needed");
1183 if (strlen(name
) > FW_CFG_MAX_FILE_PATH
- 1) {
1184 error_setg(errp
, "name too long (max. %d char)",
1185 FW_CFG_MAX_FILE_PATH
- 1);
1188 if (nonempty_str(gen_id
)) {
1190 * In this particular case where the content is populated
1191 * internally, the "etc/" namespace protection is relaxed,
1192 * so do not emit a warning.
1194 } else if (strncmp(name
, "opt/", 4) != 0) {
1195 warn_report("externally provided fw_cfg item names "
1196 "should be prefixed with \"opt/\"");
1198 if (nonempty_str(str
)) {
1199 size
= strlen(str
); /* NUL terminator NOT included in fw_cfg blob */
1200 buf
= g_memdup(str
, size
);
1201 } else if (nonempty_str(gen_id
)) {
1202 if (!fw_cfg_add_from_generator(fw_cfg
, name
, gen_id
, errp
)) {
1208 if (!g_file_get_contents(file
, &buf
, &size
, &err
)) {
1209 error_setg(errp
, "can't load %s: %s", file
, err
->message
);
1214 /* For legacy, keep user files in a specific global order. */
1215 fw_cfg_set_order_override(fw_cfg
, FW_CFG_ORDER_OVERRIDE_USER
);
1216 fw_cfg_add_file(fw_cfg
, name
, buf
, size
);
1217 fw_cfg_reset_order_override(fw_cfg
);
1221 static int device_help_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1223 return qdev_device_help(opts
);
1226 static int device_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1230 dev
= qdev_device_add(opts
, errp
);
1231 if (!dev
&& *errp
) {
1232 error_report_err(*errp
);
1235 object_unref(OBJECT(dev
));
1240 static int chardev_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1242 Error
*local_err
= NULL
;
1244 if (!qemu_chr_new_from_opts(opts
, NULL
, &local_err
)) {
1246 error_propagate(errp
, local_err
);
1254 #ifdef CONFIG_VIRTFS
1255 static int fsdev_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1257 return qemu_fsdev_add(opts
, errp
);
1261 static int mon_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1263 return monitor_init_opts(opts
, errp
);
1266 static void monitor_parse(const char *optarg
, const char *mode
, bool pretty
)
1268 static int monitor_device_index
= 0;
1273 if (strstart(optarg
, "chardev:", &p
)) {
1274 snprintf(label
, sizeof(label
), "%s", p
);
1276 snprintf(label
, sizeof(label
), "compat_monitor%d",
1277 monitor_device_index
);
1278 opts
= qemu_chr_parse_compat(label
, optarg
, true);
1280 error_report("parse error: %s", optarg
);
1285 opts
= qemu_opts_create(qemu_find_opts("mon"), label
, 1, &error_fatal
);
1286 qemu_opt_set(opts
, "mode", mode
, &error_abort
);
1287 qemu_opt_set(opts
, "chardev", label
, &error_abort
);
1288 if (!strcmp(mode
, "control")) {
1289 qemu_opt_set_bool(opts
, "pretty", pretty
, &error_abort
);
1291 assert(pretty
== false);
1293 monitor_device_index
++;
1296 struct device_config
{
1298 DEV_USB
, /* -usbdevice */
1299 DEV_SERIAL
, /* -serial */
1300 DEV_PARALLEL
, /* -parallel */
1301 DEV_DEBUGCON
, /* -debugcon */
1302 DEV_GDB
, /* -gdb, -s */
1303 DEV_SCLP
, /* s390 sclp */
1305 const char *cmdline
;
1307 QTAILQ_ENTRY(device_config
) next
;
1310 static QTAILQ_HEAD(, device_config
) device_configs
=
1311 QTAILQ_HEAD_INITIALIZER(device_configs
);
1313 static void add_device_config(int type
, const char *cmdline
)
1315 struct device_config
*conf
;
1317 conf
= g_malloc0(sizeof(*conf
));
1319 conf
->cmdline
= cmdline
;
1320 loc_save(&conf
->loc
);
1321 QTAILQ_INSERT_TAIL(&device_configs
, conf
, next
);
1324 static int foreach_device_config(int type
, int (*func
)(const char *cmdline
))
1326 struct device_config
*conf
;
1329 QTAILQ_FOREACH(conf
, &device_configs
, next
) {
1330 if (conf
->type
!= type
)
1332 loc_push_restore(&conf
->loc
);
1333 rc
= func(conf
->cmdline
);
1334 loc_pop(&conf
->loc
);
1342 static void qemu_disable_default_devices(void)
1344 MachineClass
*machine_class
= MACHINE_GET_CLASS(current_machine
);
1346 qemu_opts_foreach(qemu_find_opts("device"),
1347 default_driver_check
, NULL
, NULL
);
1348 qemu_opts_foreach(qemu_find_opts("global"),
1349 default_driver_check
, NULL
, NULL
);
1351 if (!vga_model
&& !default_vga
) {
1352 vga_interface_type
= VGA_DEVICE
;
1354 if (!has_defaults
|| machine_class
->no_serial
) {
1357 if (!has_defaults
|| machine_class
->no_parallel
) {
1358 default_parallel
= 0;
1360 if (!has_defaults
|| machine_class
->no_floppy
) {
1363 if (!has_defaults
|| machine_class
->no_cdrom
) {
1366 if (!has_defaults
|| machine_class
->no_sdcard
) {
1369 if (!has_defaults
) {
1370 default_monitor
= 0;
1376 static void qemu_create_default_devices(void)
1378 MachineClass
*machine_class
= MACHINE_GET_CLASS(current_machine
);
1380 if (is_daemonized()) {
1381 /* According to documentation and historically, -nographic redirects
1382 * serial port, parallel port and monitor to stdio, which does not work
1383 * with -daemonize. We can redirect these to null instead, but since
1384 * -nographic is legacy, let's just error out.
1385 * We disallow -nographic only if all other ports are not redirected
1386 * explicitly, to not break existing legacy setups which uses
1387 * -nographic _and_ redirects all ports explicitly - this is valid
1388 * usage, -nographic is just a no-op in this case.
1391 && (default_parallel
|| default_serial
|| default_monitor
)) {
1392 error_report("-nographic cannot be used with -daemonize");
1398 if (default_parallel
)
1399 add_device_config(DEV_PARALLEL
, "null");
1400 if (default_serial
&& default_monitor
) {
1401 add_device_config(DEV_SERIAL
, "mon:stdio");
1404 add_device_config(DEV_SERIAL
, "stdio");
1405 if (default_monitor
)
1406 monitor_parse("stdio", "readline", false);
1410 add_device_config(DEV_SERIAL
, "vc:80Cx24C");
1411 if (default_parallel
)
1412 add_device_config(DEV_PARALLEL
, "vc:80Cx24C");
1413 if (default_monitor
)
1414 monitor_parse("vc:80Cx24C", "readline", false);
1418 QemuOptsList
*net
= qemu_find_opts("net");
1419 qemu_opts_parse(net
, "nic", true, &error_abort
);
1421 qemu_opts_parse(net
, "user", true, &error_abort
);
1425 #if defined(CONFIG_VNC)
1426 if (!QTAILQ_EMPTY(&(qemu_find_opts("vnc")->head
))) {
1430 if (dpy
.type
== DISPLAY_TYPE_DEFAULT
&& !display_remote
) {
1431 if (!qemu_display_find_default(&dpy
)) {
1432 dpy
.type
= DISPLAY_TYPE_NONE
;
1433 #if defined(CONFIG_VNC)
1434 vnc_parse("localhost:0,to=99,id=default");
1438 if (dpy
.type
== DISPLAY_TYPE_DEFAULT
) {
1439 dpy
.type
= DISPLAY_TYPE_NONE
;
1442 /* If no default VGA is requested, the default is "none". */
1444 vga_model
= get_default_vga_model(machine_class
);
1447 select_vgahw(machine_class
, vga_model
);
1451 static int serial_parse(const char *devname
)
1453 int index
= num_serial_hds
;
1456 if (strcmp(devname
, "none") == 0)
1458 snprintf(label
, sizeof(label
), "serial%d", index
);
1459 serial_hds
= g_renew(Chardev
*, serial_hds
, index
+ 1);
1461 serial_hds
[index
] = qemu_chr_new_mux_mon(label
, devname
, NULL
);
1462 if (!serial_hds
[index
]) {
1463 error_report("could not connect serial device"
1464 " to character backend '%s'", devname
);
1471 Chardev
*serial_hd(int i
)
1474 if (i
< num_serial_hds
) {
1475 return serial_hds
[i
];
1480 static int parallel_parse(const char *devname
)
1482 static int index
= 0;
1485 if (strcmp(devname
, "none") == 0)
1487 if (index
== MAX_PARALLEL_PORTS
) {
1488 error_report("too many parallel ports");
1491 snprintf(label
, sizeof(label
), "parallel%d", index
);
1492 parallel_hds
[index
] = qemu_chr_new_mux_mon(label
, devname
, NULL
);
1493 if (!parallel_hds
[index
]) {
1494 error_report("could not connect parallel device"
1495 " to character backend '%s'", devname
);
1502 static int debugcon_parse(const char *devname
)
1506 if (!qemu_chr_new_mux_mon("debugcon", devname
, NULL
)) {
1507 error_report("invalid character backend '%s'", devname
);
1510 opts
= qemu_opts_create(qemu_find_opts("device"), "debugcon", 1, NULL
);
1512 error_report("already have a debugcon device");
1515 qemu_opt_set(opts
, "driver", "isa-debugcon", &error_abort
);
1516 qemu_opt_set(opts
, "chardev", "debugcon", &error_abort
);
1520 static gint
machine_class_cmp(gconstpointer a
, gconstpointer b
)
1522 const MachineClass
*mc1
= a
, *mc2
= b
;
1525 if (mc1
->family
== NULL
) {
1526 if (mc2
->family
== NULL
) {
1527 /* Compare standalone machine types against each other; they sort
1528 * in increasing order.
1530 return strcmp(object_class_get_name(OBJECT_CLASS(mc1
)),
1531 object_class_get_name(OBJECT_CLASS(mc2
)));
1534 /* Standalone machine types sort after families. */
1538 if (mc2
->family
== NULL
) {
1539 /* Families sort before standalone machine types. */
1543 /* Families sort between each other alphabetically increasingly. */
1544 res
= strcmp(mc1
->family
, mc2
->family
);
1549 /* Within the same family, machine types sort in decreasing order. */
1550 return strcmp(object_class_get_name(OBJECT_CLASS(mc2
)),
1551 object_class_get_name(OBJECT_CLASS(mc1
)));
1554 static MachineClass
*machine_parse(const char *name
, GSList
*machines
)
1559 if (is_help_option(name
)) {
1560 printf("Supported machines are:\n");
1561 machines
= g_slist_sort(machines
, machine_class_cmp
);
1562 for (el
= machines
; el
; el
= el
->next
) {
1563 MachineClass
*mc
= el
->data
;
1565 printf("%-20s %s (alias of %s)\n", mc
->alias
, mc
->desc
, mc
->name
);
1567 printf("%-20s %s%s%s\n", mc
->name
, mc
->desc
,
1568 mc
->is_default
? " (default)" : "",
1569 mc
->deprecation_reason
? " (deprecated)" : "");
1574 mc
= find_machine(name
, machines
);
1576 error_report("unsupported machine type");
1577 error_printf("Use -machine help to list supported machines\n");
1583 static const char *pid_file
;
1584 static Notifier qemu_unlink_pidfile_notifier
;
1586 static void qemu_unlink_pidfile(Notifier
*n
, void *data
)
1593 static const QEMUOption
*lookup_opt(int argc
, char **argv
,
1594 const char **poptarg
, int *poptind
)
1596 const QEMUOption
*popt
;
1597 int optind
= *poptind
;
1598 char *r
= argv
[optind
];
1601 loc_set_cmdline(argv
, optind
, 1);
1603 /* Treat --foo the same as -foo. */
1606 popt
= qemu_options
;
1609 error_report("invalid option");
1612 if (!strcmp(popt
->name
, r
+ 1))
1616 if (popt
->flags
& HAS_ARG
) {
1617 if (optind
>= argc
) {
1618 error_report("requires an argument");
1621 optarg
= argv
[optind
++];
1622 loc_set_cmdline(argv
, optind
- 2, 2);
1633 static MachineClass
*select_machine(void)
1635 GSList
*machines
= object_class_get_list(TYPE_MACHINE
, false);
1636 MachineClass
*machine_class
= find_default_machine(machines
);
1641 loc_push_none(&loc
);
1643 opts
= qemu_get_machine_opts();
1644 qemu_opts_loc_restore(opts
);
1646 optarg
= qemu_opt_get(opts
, "type");
1648 machine_class
= machine_parse(optarg
, machines
);
1651 if (!machine_class
) {
1652 error_report("No machine specified, and there is no default");
1653 error_printf("Use -machine help to list supported machines\n");
1658 g_slist_free(machines
);
1659 return machine_class
;
1662 static int object_parse_property_opt(Object
*obj
,
1663 const char *name
, const char *value
,
1664 const char *skip
, Error
**errp
)
1666 if (g_str_equal(name
, skip
)) {
1670 if (!object_property_parse(obj
, name
, value
, errp
)) {
1677 static int machine_set_property(void *opaque
,
1678 const char *name
, const char *value
,
1681 g_autofree
char *qom_name
= g_strdup(name
);
1684 for (p
= qom_name
; *p
; p
++) {
1690 /* Legacy options do not correspond to MachineState properties. */
1691 if (g_str_equal(qom_name
, "accel")) {
1694 if (g_str_equal(qom_name
, "igd-passthru")) {
1695 object_register_sugar_prop(ACCEL_CLASS_NAME("xen"), qom_name
, value
,
1699 if (g_str_equal(qom_name
, "kvm-shadow-mem")) {
1700 object_register_sugar_prop(ACCEL_CLASS_NAME("kvm"), qom_name
, value
,
1704 if (g_str_equal(qom_name
, "kernel-irqchip")) {
1705 object_register_sugar_prop(ACCEL_CLASS_NAME("kvm"), qom_name
, value
,
1707 object_register_sugar_prop(ACCEL_CLASS_NAME("whpx"), qom_name
, value
,
1712 return object_parse_property_opt(opaque
, name
, value
, "type", errp
);
1715 static void object_option_foreach_add(bool (*type_opt_predicate
)(const char *))
1717 ObjectOption
*opt
, *next
;
1719 QTAILQ_FOREACH_SAFE(opt
, &object_opts
, next
, next
) {
1720 const char *type
= ObjectType_str(opt
->opts
->qom_type
);
1721 if (type_opt_predicate(type
)) {
1722 user_creatable_add_qapi(opt
->opts
, &error_fatal
);
1723 qapi_free_ObjectOptions(opt
->opts
);
1724 QTAILQ_REMOVE(&object_opts
, opt
, next
);
1730 static void object_option_add_visitor(Visitor
*v
)
1732 ObjectOption
*opt
= g_new0(ObjectOption
, 1);
1733 visit_type_ObjectOptions(v
, NULL
, &opt
->opts
, &error_fatal
);
1734 QTAILQ_INSERT_TAIL(&object_opts
, opt
, next
);
1737 static void object_option_parse(const char *optarg
)
1743 if (optarg
[0] == '{') {
1744 QObject
*obj
= qobject_from_json(optarg
, &error_fatal
);
1746 v
= qobject_input_visitor_new(obj
);
1749 opts
= qemu_opts_parse_noisily(qemu_find_opts("object"),
1755 type
= qemu_opt_get(opts
, "qom-type");
1757 error_setg(&error_fatal
, QERR_MISSING_PARAMETER
, "qom-type");
1759 if (user_creatable_print_help(type
, opts
)) {
1763 v
= opts_visitor_new(opts
);
1766 object_option_add_visitor(v
);
1771 * Initial object creation happens before all other
1772 * QEMU data types are created. The majority of objects
1773 * can be created at this point. The rng-egd object
1774 * cannot be created here, as it depends on the chardev
1777 static bool object_create_early(const char *type
)
1780 * Objects should not be made "delayed" without a reason. If you
1781 * add one, state the reason in a comment!
1784 /* Reason: property "chardev" */
1785 if (g_str_equal(type
, "rng-egd") ||
1786 g_str_equal(type
, "qtest")) {
1790 #if defined(CONFIG_VHOST_USER) && defined(CONFIG_LINUX)
1791 /* Reason: cryptodev-vhost-user property "chardev" */
1792 if (g_str_equal(type
, "cryptodev-vhost-user")) {
1797 /* Reason: vhost-user-blk-server property "node-name" */
1798 if (g_str_equal(type
, "vhost-user-blk-server")) {
1802 * Reason: filter-* property "netdev" etc.
1804 if (g_str_equal(type
, "filter-buffer") ||
1805 g_str_equal(type
, "filter-dump") ||
1806 g_str_equal(type
, "filter-mirror") ||
1807 g_str_equal(type
, "filter-redirector") ||
1808 g_str_equal(type
, "colo-compare") ||
1809 g_str_equal(type
, "filter-rewriter") ||
1810 g_str_equal(type
, "filter-replay")) {
1815 * Allocation of large amounts of memory may delay
1816 * chardev initialization for too long, and trigger timeouts
1817 * on software that waits for a monitor socket to be created
1820 if (g_str_has_prefix(type
, "memory-backend-")) {
1827 static void qemu_apply_machine_options(void)
1829 MachineClass
*machine_class
= MACHINE_GET_CLASS(current_machine
);
1830 QemuOpts
*machine_opts
= qemu_get_machine_opts();
1831 const char *boot_order
= NULL
;
1832 const char *boot_once
= NULL
;
1835 qemu_opt_foreach(machine_opts
, machine_set_property
, current_machine
,
1837 current_machine
->ram_size
= ram_size
;
1838 current_machine
->maxram_size
= maxram_size
;
1839 current_machine
->ram_slots
= ram_slots
;
1841 opts
= qemu_opts_find(qemu_find_opts("boot-opts"), NULL
);
1843 boot_order
= qemu_opt_get(opts
, "order");
1845 validate_bootdevices(boot_order
, &error_fatal
);
1848 boot_once
= qemu_opt_get(opts
, "once");
1850 validate_bootdevices(boot_once
, &error_fatal
);
1853 boot_menu
= qemu_opt_get_bool(opts
, "menu", boot_menu
);
1854 boot_strict
= qemu_opt_get_bool(opts
, "strict", false);
1858 boot_order
= machine_class
->default_boot_order
;
1861 current_machine
->boot_order
= boot_order
;
1862 current_machine
->boot_once
= boot_once
;
1864 if (semihosting_enabled() && !semihosting_get_argc()) {
1865 const char *kernel_filename
= qemu_opt_get(machine_opts
, "kernel");
1866 const char *kernel_cmdline
= qemu_opt_get(machine_opts
, "append") ?: "";
1867 /* fall back to the -kernel/-append */
1868 semihosting_arg_fallback(kernel_filename
, kernel_cmdline
);
1872 static void qemu_create_early_backends(void)
1874 MachineClass
*machine_class
= MACHINE_GET_CLASS(current_machine
);
1875 #if defined(CONFIG_SDL)
1876 const bool use_sdl
= (dpy
.type
== DISPLAY_TYPE_SDL
);
1878 const bool use_sdl
= false;
1880 #if defined(CONFIG_GTK)
1881 const bool use_gtk
= (dpy
.type
== DISPLAY_TYPE_GTK
);
1883 const bool use_gtk
= false;
1886 if ((alt_grab
|| ctrl_grab
) && !use_sdl
) {
1887 error_report("-alt-grab and -ctrl-grab are only valid "
1888 "for SDL, ignoring option");
1890 if (dpy
.has_window_close
&& !use_gtk
&& !use_sdl
) {
1891 error_report("-no-quit is only valid for GTK and SDL, "
1895 qemu_display_early_init(&dpy
);
1896 qemu_console_early_init();
1898 if (dpy
.has_gl
&& dpy
.gl
!= DISPLAYGL_MODE_OFF
&& display_opengl
== 0) {
1899 #if defined(CONFIG_OPENGL)
1900 error_report("OpenGL is not supported by the display");
1902 error_report("OpenGL support is disabled");
1907 object_option_foreach_add(object_create_early
);
1909 /* spice needs the timers to be initialized by this point */
1910 /* spice must initialize before audio as it changes the default auiodev */
1911 /* spice must initialize before chardevs (for spicevmc and spiceport) */
1914 qemu_opts_foreach(qemu_find_opts("chardev"),
1915 chardev_init_func
, NULL
, &error_fatal
);
1917 #ifdef CONFIG_VIRTFS
1918 qemu_opts_foreach(qemu_find_opts("fsdev"),
1919 fsdev_init_func
, NULL
, &error_fatal
);
1923 * Note: we need to create audio and block backends before
1924 * machine_set_property(), so machine properties can refer to
1927 configure_blockdev(&bdo_queue
, machine_class
, snapshot
);
1928 audio_init_audiodevs();
1933 * The remainder of object creation happens after the
1934 * creation of chardev, fsdev, net clients and device data types.
1936 static bool object_create_late(const char *type
)
1938 return !object_create_early(type
);
1941 static void qemu_create_late_backends(void)
1944 qtest_server_init(qtest_chrdev
, qtest_log
, &error_fatal
);
1947 net_init_clients(&error_fatal
);
1949 object_option_foreach_add(object_create_late
);
1951 if (tpm_init() < 0) {
1955 qemu_opts_foreach(qemu_find_opts("mon"),
1956 mon_init_func
, NULL
, &error_fatal
);
1958 if (foreach_device_config(DEV_SERIAL
, serial_parse
) < 0)
1960 if (foreach_device_config(DEV_PARALLEL
, parallel_parse
) < 0)
1962 if (foreach_device_config(DEV_DEBUGCON
, debugcon_parse
) < 0)
1965 /* now chardevs have been created we may have semihosting to connect */
1966 qemu_semihosting_connect_chardevs();
1967 qemu_semihosting_console_init();
1970 static bool have_custom_ram_size(void)
1972 QemuOpts
*opts
= qemu_find_opts_singleton("memory");
1973 return !!qemu_opt_get_size(opts
, "size", 0);
1976 static void qemu_resolve_machine_memdev(void)
1978 if (current_machine
->ram_memdev_id
) {
1980 ram_addr_t backend_size
;
1982 backend
= object_resolve_path_type(current_machine
->ram_memdev_id
,
1983 TYPE_MEMORY_BACKEND
, NULL
);
1985 error_report("Memory backend '%s' not found",
1986 current_machine
->ram_memdev_id
);
1989 backend_size
= object_property_get_uint(backend
, "size", &error_abort
);
1990 if (have_custom_ram_size() && backend_size
!= ram_size
) {
1991 error_report("Size specified by -m option must match size of "
1992 "explicitly specified 'memory-backend' property");
1996 error_report("'-mem-path' can't be used together with"
1997 "'-machine memory-backend'");
2000 ram_size
= backend_size
;
2003 if (!xen_enabled()) {
2004 /* On 32-bit hosts, QEMU is limited by virtual address space */
2005 if (ram_size
> (2047 << 20) && HOST_LONG_BITS
== 32) {
2006 error_report("at most 2047 MB RAM can be simulated");
2012 static void set_memory_options(MachineClass
*mc
)
2015 const char *mem_str
;
2016 const ram_addr_t default_ram_size
= mc
->default_ram_size
;
2017 QemuOpts
*opts
= qemu_find_opts_singleton("memory");
2020 loc_push_none(&loc
);
2021 qemu_opts_loc_restore(opts
);
2024 mem_str
= qemu_opt_get(opts
, "size");
2027 error_report("missing 'size' option value");
2031 sz
= qemu_opt_get_size(opts
, "size", ram_size
);
2033 /* Fix up legacy suffix-less format */
2034 if (g_ascii_isdigit(mem_str
[strlen(mem_str
) - 1])) {
2035 uint64_t overflow_check
= sz
;
2038 if (sz
/ MiB
!= overflow_check
) {
2039 error_report("too large 'size' option value");
2045 /* backward compatibility behaviour for case "-m 0" */
2047 sz
= default_ram_size
;
2050 sz
= QEMU_ALIGN_UP(sz
, 8192);
2051 if (mc
->fixup_ram_size
) {
2052 sz
= mc
->fixup_ram_size(sz
);
2055 if (ram_size
!= sz
) {
2056 error_report("ram size too large");
2060 maxram_size
= ram_size
;
2062 if (qemu_opt_get(opts
, "maxmem")) {
2065 sz
= qemu_opt_get_size(opts
, "maxmem", 0);
2066 slots
= qemu_opt_get_number(opts
, "slots", 0);
2067 if (sz
< ram_size
) {
2068 error_report("invalid value of -m option maxmem: "
2069 "maximum memory size (0x%" PRIx64
") must be at least "
2070 "the initial memory size (0x" RAM_ADDR_FMT
")",
2073 } else if (slots
&& sz
== ram_size
) {
2074 error_report("invalid value of -m option maxmem: "
2075 "memory slots were specified but maximum memory size "
2076 "(0x%" PRIx64
") is equal to the initial memory size "
2077 "(0x" RAM_ADDR_FMT
")", sz
, ram_size
);
2083 } else if (qemu_opt_get(opts
, "slots")) {
2084 error_report("invalid -m option value: missing 'maxmem' option");
2091 static void qemu_create_machine(MachineClass
*machine_class
)
2093 object_set_machine_compat_props(machine_class
->compat_props
);
2095 set_memory_options(machine_class
);
2097 current_machine
= MACHINE(object_new_with_class(OBJECT_CLASS(machine_class
)));
2098 if (machine_help_func(qemu_get_machine_opts(), current_machine
)) {
2101 object_property_add_child(object_get_root(), "machine",
2102 OBJECT(current_machine
));
2103 object_property_add_child(container_get(OBJECT(current_machine
),
2105 "sysbus", OBJECT(sysbus_get_default()));
2107 if (machine_class
->minimum_page_bits
) {
2108 if (!set_preferred_target_page_bits(machine_class
->minimum_page_bits
)) {
2109 /* This would be a board error: specifying a minimum smaller than
2110 * a target's compile-time fixed setting.
2112 g_assert_not_reached();
2116 cpu_exec_init_all();
2119 if (machine_class
->hw_version
) {
2120 qemu_set_hw_version(machine_class
->hw_version
);
2123 machine_smp_parse(current_machine
,
2124 qemu_opts_find(qemu_find_opts("smp-opts"), NULL
), &error_fatal
);
2127 * Get the default machine options from the machine if it is not already
2128 * specified either by the configuration file or by the command line.
2130 if (machine_class
->default_machine_opts
) {
2131 qemu_opts_set_defaults(qemu_find_opts("machine"),
2132 machine_class
->default_machine_opts
, 0);
2136 static int global_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2140 g
= g_malloc0(sizeof(*g
));
2141 g
->driver
= qemu_opt_get(opts
, "driver");
2142 g
->property
= qemu_opt_get(opts
, "property");
2143 g
->value
= qemu_opt_get(opts
, "value");
2144 qdev_prop_register_global(g
);
2149 * Return whether configuration group @group is stored in QemuOpts, or
2150 * recorded as one or more QDicts by qemu_record_config_group.
2152 static bool is_qemuopts_group(const char *group
)
2154 if (g_str_equal(group
, "object")) {
2160 static void qemu_record_config_group(const char *group
, QDict
*dict
,
2161 bool from_json
, Error
**errp
)
2163 if (g_str_equal(group
, "object")) {
2164 Visitor
*v
= qobject_input_visitor_new_keyval(QOBJECT(dict
));
2165 object_option_add_visitor(v
);
2173 * Parse non-QemuOpts config file groups, pass the rest to
2174 * qemu_config_do_parse.
2176 static void qemu_parse_config_group(const char *group
, QDict
*qdict
,
2177 void *opaque
, Error
**errp
)
2180 if (is_qemuopts_group(group
)) {
2181 qemu_config_do_parse(group
, qdict
, opaque
, errp
);
2185 crumpled
= qdict_crumple(qdict
, errp
);
2189 if (qobject_type(crumpled
) != QTYPE_QDICT
) {
2190 assert(qobject_type(crumpled
) == QTYPE_QLIST
);
2191 error_setg(errp
, "Lists cannot be at top level of a configuration section");
2194 qemu_record_config_group(group
, qobject_to(QDict
, crumpled
), false, errp
);
2197 static void qemu_read_default_config_file(Error
**errp
)
2201 g_autofree
char *file
= get_relocated_path(CONFIG_QEMU_CONFDIR
"/qemu.conf");
2203 ret
= qemu_read_config_file(file
, qemu_parse_config_group
, errp
);
2205 if (ret
== -ENOENT
) {
2212 static void qemu_set_option(const char *str
, Error
**errp
)
2214 char group
[64], id
[64], arg
[64];
2219 rc
= sscanf(str
, "%63[^.].%63[^.].%63[^=]%n", group
, id
, arg
, &offset
);
2220 if (rc
< 3 || str
[offset
] != '=') {
2221 error_setg(errp
, "can't parse: \"%s\"", str
);
2225 if (!is_qemuopts_group(group
)) {
2226 error_setg(errp
, "-set is not supported with %s", group
);
2228 list
= qemu_find_opts_err(group
, errp
);
2230 opts
= qemu_opts_find(list
, id
);
2232 error_setg(errp
, "there is no %s \"%s\" defined", group
, id
);
2235 qemu_opt_set(opts
, arg
, str
+ offset
+ 1, errp
);
2240 static void user_register_global_props(void)
2242 qemu_opts_foreach(qemu_find_opts("global"),
2243 global_init_func
, NULL
, NULL
);
2246 static int do_configure_icount(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2248 icount_configure(opts
, errp
);
2252 static int accelerator_set_property(void *opaque
,
2253 const char *name
, const char *value
,
2256 return object_parse_property_opt(opaque
, name
, value
, "accel", errp
);
2259 static int do_configure_accelerator(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2261 bool *p_init_failed
= opaque
;
2262 const char *acc
= qemu_opt_get(opts
, "accel");
2263 AccelClass
*ac
= accel_find(acc
);
2266 bool qtest_with_kvm
;
2268 qtest_with_kvm
= g_str_equal(acc
, "kvm") && qtest_chrdev
!= NULL
;
2271 *p_init_failed
= true;
2272 if (!qtest_with_kvm
) {
2273 error_report("invalid accelerator %s", acc
);
2277 accel
= ACCEL(object_new_with_class(OBJECT_CLASS(ac
)));
2278 object_apply_compat_props(OBJECT(accel
));
2279 qemu_opt_foreach(opts
, accelerator_set_property
,
2283 ret
= accel_init_machine(accel
, current_machine
);
2285 *p_init_failed
= true;
2286 if (!qtest_with_kvm
|| ret
!= -ENOENT
) {
2287 error_report("failed to initialize %s: %s", acc
, strerror(-ret
));
2295 static void configure_accelerators(const char *progname
)
2297 const char *accelerators
;
2298 bool init_failed
= false;
2300 qemu_opts_foreach(qemu_find_opts("icount"),
2301 do_configure_icount
, NULL
, &error_fatal
);
2303 accelerators
= qemu_opt_get(qemu_get_machine_opts(), "accel");
2304 if (QTAILQ_EMPTY(&qemu_accel_opts
.head
)) {
2305 char **accel_list
, **tmp
;
2307 if (accelerators
== NULL
) {
2308 /* Select the default accelerator */
2309 bool have_tcg
= accel_find("tcg");
2310 bool have_kvm
= accel_find("kvm");
2312 if (have_tcg
&& have_kvm
) {
2313 if (g_str_has_suffix(progname
, "kvm")) {
2314 /* If the program name ends with "kvm", we prefer KVM */
2315 accelerators
= "kvm:tcg";
2317 accelerators
= "tcg:kvm";
2319 } else if (have_kvm
) {
2320 accelerators
= "kvm";
2321 } else if (have_tcg
) {
2322 accelerators
= "tcg";
2324 error_report("No accelerator selected and"
2325 " no default accelerator available");
2329 accel_list
= g_strsplit(accelerators
, ":", 0);
2331 for (tmp
= accel_list
; *tmp
; tmp
++) {
2333 * Filter invalid accelerators here, to prevent obscenities
2334 * such as "-machine accel=tcg,,thread=single".
2336 if (accel_find(*tmp
)) {
2337 qemu_opts_parse_noisily(qemu_find_opts("accel"), *tmp
, true);
2340 error_report("invalid accelerator %s", *tmp
);
2343 g_strfreev(accel_list
);
2345 if (accelerators
!= NULL
) {
2346 error_report("The -accel and \"-machine accel=\" options are incompatible");
2351 if (!qemu_opts_foreach(qemu_find_opts("accel"),
2352 do_configure_accelerator
, &init_failed
, &error_fatal
)) {
2354 error_report("no accelerator found");
2359 if (init_failed
&& !qtest_chrdev
) {
2360 AccelClass
*ac
= ACCEL_GET_CLASS(current_accel());
2361 error_report("falling back to %s", ac
->name
);
2364 if (icount_enabled() && !tcg_enabled()) {
2365 error_report("-icount is not allowed with hardware virtualization");
2370 static void create_default_memdev(MachineState
*ms
, const char *path
)
2373 MachineClass
*mc
= MACHINE_GET_CLASS(ms
);
2375 obj
= object_new(path
? TYPE_MEMORY_BACKEND_FILE
: TYPE_MEMORY_BACKEND_RAM
);
2377 object_property_set_str(obj
, "mem-path", path
, &error_fatal
);
2379 object_property_set_int(obj
, "size", ms
->ram_size
, &error_fatal
);
2380 object_property_add_child(object_get_objects_root(), mc
->default_ram_id
,
2382 /* Ensure backend's memory region name is equal to mc->default_ram_id */
2383 object_property_set_bool(obj
, "x-use-canonical-path-for-ramblock-id",
2384 false, &error_fatal
);
2385 user_creatable_complete(USER_CREATABLE(obj
), &error_fatal
);
2387 object_property_set_str(OBJECT(ms
), "memory-backend", mc
->default_ram_id
,
2391 static void qemu_validate_options(void)
2393 QemuOpts
*machine_opts
= qemu_get_machine_opts();
2394 const char *kernel_filename
= qemu_opt_get(machine_opts
, "kernel");
2395 const char *initrd_filename
= qemu_opt_get(machine_opts
, "initrd");
2396 const char *kernel_cmdline
= qemu_opt_get(machine_opts
, "append");
2398 if (kernel_filename
== NULL
) {
2399 if (kernel_cmdline
!= NULL
) {
2400 error_report("-append only allowed with -kernel option");
2404 if (initrd_filename
!= NULL
) {
2405 error_report("-initrd only allowed with -kernel option");
2410 if (loadvm
&& preconfig_requested
) {
2411 error_report("'preconfig' and 'loadvm' options are "
2412 "mutually exclusive");
2415 if (incoming
&& preconfig_requested
&& strcmp(incoming
, "defer") != 0) {
2416 error_report("'preconfig' supports '-incoming defer' only");
2420 #ifdef CONFIG_CURSES
2421 if (is_daemonized() && dpy
.type
== DISPLAY_TYPE_CURSES
) {
2422 error_report("curses display cannot be used with -daemonize");
2428 static void qemu_process_sugar_options(void)
2433 val
= g_strdup_printf("%d",
2434 (uint32_t) qemu_opt_get_number(qemu_find_opts_singleton("smp-opts"), "cpus", 1));
2435 object_register_sugar_prop("memory-backend", "prealloc-threads", val
,
2438 object_register_sugar_prop("memory-backend", "prealloc", "on", false);
2442 int i
= select_watchdog(watchdog
);
2444 exit (i
== 1 ? 1 : 0);
2448 /* -action processing */
2451 * Process all the -action parameters parsed from cmdline.
2453 static int process_runstate_actions(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2455 Error
*local_err
= NULL
;
2456 QDict
*qdict
= qemu_opts_to_qdict(opts
, NULL
);
2457 QObject
*ret
= NULL
;
2458 qmp_marshal_set_action(qdict
, &ret
, &local_err
);
2460 qobject_unref(qdict
);
2462 error_propagate(errp
, local_err
);
2468 static void qemu_process_early_options(void)
2470 #ifdef CONFIG_SECCOMP
2471 QemuOptsList
*olist
= qemu_find_opts_err("sandbox", NULL
);
2473 qemu_opts_foreach(olist
, parse_sandbox
, NULL
, &error_fatal
);
2477 qemu_opts_foreach(qemu_find_opts("name"),
2478 parse_name
, NULL
, &error_fatal
);
2480 if (qemu_opts_foreach(qemu_find_opts("action"),
2481 process_runstate_actions
, NULL
, &error_fatal
)) {
2486 qemu_opts_foreach(qemu_find_opts("add-fd"),
2487 parse_add_fd
, NULL
, &error_fatal
);
2489 qemu_opts_foreach(qemu_find_opts("add-fd"),
2490 cleanup_add_fd
, NULL
, &error_fatal
);
2493 /* Open the logfile at this point and set the log mask if necessary. */
2495 qemu_set_log_filename(log_file
, &error_fatal
);
2499 mask
= qemu_str_to_log_mask(log_mask
);
2501 qemu_print_log_usage(stdout
);
2509 qemu_add_default_firmwarepath();
2512 static void qemu_process_help_options(void)
2515 * Check for -cpu help and -device help before we call select_machine(),
2516 * which will return an error if the architecture has no default machine
2517 * type and the user did not specify one, so that the user doesn't need
2518 * to say '-cpu help -machine something'.
2520 if (cpu_option
&& is_help_option(cpu_option
)) {
2521 list_cpus(cpu_option
);
2525 if (qemu_opts_foreach(qemu_find_opts("device"),
2526 device_help_func
, NULL
, NULL
)) {
2530 /* -L help lists the data directories and exits. */
2531 if (list_data_dirs
) {
2532 qemu_list_data_dirs();
2537 static void qemu_maybe_daemonize(const char *pid_file
)
2542 rcu_disable_atfork();
2544 if (pid_file
&& !qemu_write_pidfile(pid_file
, &err
)) {
2545 error_reportf_err(err
, "cannot create PID file: ");
2549 qemu_unlink_pidfile_notifier
.notify
= qemu_unlink_pidfile
;
2550 qemu_add_exit_notifier(&qemu_unlink_pidfile_notifier
);
2553 static void qemu_init_displays(void)
2557 /* init local displays */
2558 ds
= init_displaystate();
2559 qemu_display_init(ds
, &dpy
);
2561 /* must be after terminal init, SDL library changes signal handlers */
2562 os_setup_signal_handling();
2564 /* init remote displays */
2566 qemu_opts_foreach(qemu_find_opts("vnc"),
2567 vnc_init_func
, NULL
, &error_fatal
);
2571 qemu_spice
.display_init();
2575 static void qemu_init_board(void)
2577 MachineClass
*machine_class
= MACHINE_GET_CLASS(current_machine
);
2579 if (machine_class
->default_ram_id
&& current_machine
->ram_size
&&
2580 numa_uses_legacy_mem() && !current_machine
->ram_memdev_id
) {
2581 create_default_memdev(current_machine
, mem_path
);
2584 /* process plugin before CPUs are created, but once -smp has been parsed */
2585 qemu_plugin_load_list(&plugin_list
, &error_fatal
);
2587 /* From here on we enter MACHINE_PHASE_INITIALIZED. */
2588 machine_run_board_init(current_machine
);
2590 drive_check_orphaned();
2594 if (hax_enabled()) {
2595 /* FIXME: why isn't cpu_synchronize_all_post_init enough? */
2600 static void qemu_create_cli_devices(void)
2604 qemu_opts_foreach(qemu_find_opts("fw_cfg"),
2605 parse_fw_cfg
, fw_cfg_find(), &error_fatal
);
2607 /* init USB devices */
2608 if (machine_usb(current_machine
)) {
2609 if (foreach_device_config(DEV_USB
, usb_parse
) < 0)
2613 /* init generic devices */
2614 rom_set_order_override(FW_CFG_ORDER_OVERRIDE_DEVICE
);
2615 qemu_opts_foreach(qemu_find_opts("device"),
2616 device_init_func
, NULL
, &error_fatal
);
2617 rom_reset_order_override();
2620 static void qemu_machine_creation_done(void)
2622 MachineState
*machine
= MACHINE(qdev_get_machine());
2624 /* Did we create any drives that we failed to create a device for? */
2625 drive_check_orphaned();
2627 /* Don't warn about the default network setup that you get if
2628 * no command line -net or -netdev options are specified. There
2629 * are two cases that we would otherwise complain about:
2630 * (1) board doesn't support a NIC but the implicit "-net nic"
2632 * (2) CONFIG_SLIRP not set, in which case the implicit "-net nic"
2633 * sets up a nic that isn't connected to anything.
2635 if (!default_net
&& (!qtest_enabled() || has_defaults
)) {
2636 net_check_clients();
2639 qdev_prop_check_globals();
2641 qdev_machine_creation_done();
2645 * Verify that Confidential Guest Support has actually been initialized
2647 assert(machine
->cgs
->ready
);
2650 if (foreach_device_config(DEV_GDB
, gdbserver_start
) < 0) {
2655 void qmp_x_exit_preconfig(Error
**errp
)
2657 if (phase_check(PHASE_MACHINE_INITIALIZED
)) {
2658 error_setg(errp
, "The command is permitted only before machine initialization");
2663 qemu_create_cli_devices();
2664 qemu_machine_creation_done();
2667 Error
*local_err
= NULL
;
2668 if (!load_snapshot(loadvm
, NULL
, false, NULL
, &local_err
)) {
2669 error_report_err(local_err
);
2674 if (replay_mode
!= REPLAY_MODE_NONE
) {
2675 replay_vmstate_init();
2679 Error
*local_err
= NULL
;
2680 if (strcmp(incoming
, "defer") != 0) {
2681 qmp_migrate_incoming(incoming
, &local_err
);
2683 error_reportf_err(local_err
, "-incoming %s: ", incoming
);
2687 } else if (autostart
) {
2692 #ifdef CONFIG_MODULES
2693 void qemu_load_module_for_opts(const char *group
)
2695 static bool spice_tried
;
2696 if (g_str_equal(group
, "spice") && !spice_tried
) {
2697 ui_module_load_one("spice-core");
2701 static bool iscsi_tried
;
2702 if (g_str_equal(group
, "iscsi") && !iscsi_tried
) {
2703 block_module_load_one("iscsi");
2709 void qemu_init(int argc
, char **argv
, char **envp
)
2712 QemuOpts
*icount_opts
= NULL
, *accel_opts
= NULL
;
2713 QemuOptsList
*olist
;
2716 MachineClass
*machine_class
;
2717 bool userconfig
= true;
2718 FILE *vmstate_dump_file
= NULL
;
2720 qemu_add_opts(&qemu_drive_opts
);
2721 qemu_add_drive_opts(&qemu_legacy_drive_opts
);
2722 qemu_add_drive_opts(&qemu_common_drive_opts
);
2723 qemu_add_drive_opts(&qemu_drive_opts
);
2724 qemu_add_drive_opts(&bdrv_runtime_opts
);
2725 qemu_add_opts(&qemu_chardev_opts
);
2726 qemu_add_opts(&qemu_device_opts
);
2727 qemu_add_opts(&qemu_netdev_opts
);
2728 qemu_add_opts(&qemu_nic_opts
);
2729 qemu_add_opts(&qemu_net_opts
);
2730 qemu_add_opts(&qemu_rtc_opts
);
2731 qemu_add_opts(&qemu_global_opts
);
2732 qemu_add_opts(&qemu_mon_opts
);
2733 qemu_add_opts(&qemu_trace_opts
);
2734 qemu_plugin_add_opts();
2735 qemu_add_opts(&qemu_option_rom_opts
);
2736 qemu_add_opts(&qemu_machine_opts
);
2737 qemu_add_opts(&qemu_accel_opts
);
2738 qemu_add_opts(&qemu_mem_opts
);
2739 qemu_add_opts(&qemu_smp_opts
);
2740 qemu_add_opts(&qemu_boot_opts
);
2741 qemu_add_opts(&qemu_add_fd_opts
);
2742 qemu_add_opts(&qemu_object_opts
);
2743 qemu_add_opts(&qemu_tpmdev_opts
);
2744 qemu_add_opts(&qemu_overcommit_opts
);
2745 qemu_add_opts(&qemu_msg_opts
);
2746 qemu_add_opts(&qemu_name_opts
);
2747 qemu_add_opts(&qemu_numa_opts
);
2748 qemu_add_opts(&qemu_icount_opts
);
2749 qemu_add_opts(&qemu_semihosting_config_opts
);
2750 qemu_add_opts(&qemu_fw_cfg_opts
);
2751 qemu_add_opts(&qemu_action_opts
);
2752 module_call_init(MODULE_INIT_OPTS
);
2754 error_init(argv
[0]);
2755 qemu_init_exec_dir(argv
[0]);
2757 qemu_init_subsystems();
2759 /* first pass of option parsing */
2761 while (optind
< argc
) {
2762 if (argv
[optind
][0] != '-') {
2766 const QEMUOption
*popt
;
2768 popt
= lookup_opt(argc
, argv
, &optarg
, &optind
);
2769 switch (popt
->index
) {
2770 case QEMU_OPTION_nouserconfig
:
2778 qemu_read_default_config_file(&error_fatal
);
2781 /* second pass of option parsing */
2786 if (argv
[optind
][0] != '-') {
2787 loc_set_cmdline(argv
, optind
, 1);
2788 drive_add(IF_DEFAULT
, 0, argv
[optind
++], HD_OPTS
);
2790 const QEMUOption
*popt
;
2792 popt
= lookup_opt(argc
, argv
, &optarg
, &optind
);
2793 if (!(popt
->arch_mask
& arch_type
)) {
2794 error_report("Option not supported for this target");
2797 switch(popt
->index
) {
2798 case QEMU_OPTION_cpu
:
2799 /* hw initialization will check this */
2800 cpu_option
= optarg
;
2802 case QEMU_OPTION_hda
:
2803 case QEMU_OPTION_hdb
:
2804 case QEMU_OPTION_hdc
:
2805 case QEMU_OPTION_hdd
:
2806 drive_add(IF_DEFAULT
, popt
->index
- QEMU_OPTION_hda
, optarg
,
2809 case QEMU_OPTION_blockdev
:
2812 BlockdevOptionsQueueEntry
*bdo
;
2814 v
= qobject_input_visitor_new_str(optarg
, "driver",
2817 bdo
= g_new(BlockdevOptionsQueueEntry
, 1);
2818 visit_type_BlockdevOptions(v
, NULL
, &bdo
->bdo
,
2821 loc_save(&bdo
->loc
);
2822 QSIMPLEQ_INSERT_TAIL(&bdo_queue
, bdo
, entry
);
2825 case QEMU_OPTION_drive
:
2826 if (drive_def(optarg
) == NULL
) {
2830 case QEMU_OPTION_set
:
2831 qemu_set_option(optarg
, &error_fatal
);
2833 case QEMU_OPTION_global
:
2834 if (qemu_global_option(optarg
) != 0)
2837 case QEMU_OPTION_mtdblock
:
2838 drive_add(IF_MTD
, -1, optarg
, MTD_OPTS
);
2840 case QEMU_OPTION_sd
:
2841 drive_add(IF_SD
, -1, optarg
, SD_OPTS
);
2843 case QEMU_OPTION_pflash
:
2844 drive_add(IF_PFLASH
, -1, optarg
, PFLASH_OPTS
);
2846 case QEMU_OPTION_snapshot
:
2848 Error
*blocker
= NULL
;
2850 error_setg(&blocker
, QERR_REPLAY_NOT_SUPPORTED
,
2852 replay_add_blocker(blocker
);
2855 case QEMU_OPTION_numa
:
2856 opts
= qemu_opts_parse_noisily(qemu_find_opts("numa"),
2862 case QEMU_OPTION_display
:
2863 parse_display(optarg
);
2865 case QEMU_OPTION_nographic
:
2866 olist
= qemu_find_opts("machine");
2867 qemu_opts_parse_noisily(olist
, "graphics=off", false);
2869 dpy
.type
= DISPLAY_TYPE_NONE
;
2871 case QEMU_OPTION_curses
:
2872 #ifdef CONFIG_CURSES
2873 dpy
.type
= DISPLAY_TYPE_CURSES
;
2875 error_report("curses or iconv support is disabled");
2879 case QEMU_OPTION_portrait
:
2880 graphic_rotate
= 90;
2882 case QEMU_OPTION_rotate
:
2883 graphic_rotate
= strtol(optarg
, (char **) &optarg
, 10);
2884 if (graphic_rotate
!= 0 && graphic_rotate
!= 90 &&
2885 graphic_rotate
!= 180 && graphic_rotate
!= 270) {
2886 error_report("only 90, 180, 270 deg rotation is available");
2890 case QEMU_OPTION_kernel
:
2891 qemu_opts_set(qemu_find_opts("machine"), "kernel", optarg
, &error_abort
);
2893 case QEMU_OPTION_initrd
:
2894 qemu_opts_set(qemu_find_opts("machine"), "initrd", optarg
, &error_abort
);
2896 case QEMU_OPTION_append
:
2897 qemu_opts_set(qemu_find_opts("machine"), "append", optarg
, &error_abort
);
2899 case QEMU_OPTION_dtb
:
2900 qemu_opts_set(qemu_find_opts("machine"), "dtb", optarg
, &error_abort
);
2902 case QEMU_OPTION_cdrom
:
2903 drive_add(IF_DEFAULT
, 2, optarg
, CDROM_OPTS
);
2905 case QEMU_OPTION_boot
:
2906 opts
= qemu_opts_parse_noisily(qemu_find_opts("boot-opts"),
2912 case QEMU_OPTION_fda
:
2913 case QEMU_OPTION_fdb
:
2914 drive_add(IF_FLOPPY
, popt
->index
- QEMU_OPTION_fda
,
2917 case QEMU_OPTION_no_fd_bootchk
:
2920 case QEMU_OPTION_netdev
:
2922 if (net_client_parse(qemu_find_opts("netdev"), optarg
) == -1) {
2926 case QEMU_OPTION_nic
:
2928 if (net_client_parse(qemu_find_opts("nic"), optarg
) == -1) {
2932 case QEMU_OPTION_net
:
2934 if (net_client_parse(qemu_find_opts("net"), optarg
) == -1) {
2938 #ifdef CONFIG_LIBISCSI
2939 case QEMU_OPTION_iscsi
:
2940 opts
= qemu_opts_parse_noisily(qemu_find_opts("iscsi"),
2947 case QEMU_OPTION_audio_help
:
2948 audio_legacy_help();
2951 case QEMU_OPTION_audiodev
:
2952 audio_parse_option(optarg
);
2954 case QEMU_OPTION_soundhw
:
2955 select_soundhw (optarg
);
2960 case QEMU_OPTION_version
:
2965 opts
= qemu_opts_parse_noisily(qemu_find_opts("memory"),
2972 case QEMU_OPTION_tpmdev
:
2973 if (tpm_config_parse(qemu_find_opts("tpmdev"), optarg
) < 0) {
2978 case QEMU_OPTION_mempath
:
2981 case QEMU_OPTION_mem_prealloc
:
2990 case QEMU_OPTION_DFILTER
:
2991 qemu_set_dfilter_ranges(optarg
, &error_fatal
);
2993 case QEMU_OPTION_seed
:
2994 qemu_guest_random_seed_main(optarg
, &error_fatal
);
2997 add_device_config(DEV_GDB
, "tcp::" DEFAULT_GDBSTUB_PORT
);
2999 case QEMU_OPTION_gdb
:
3000 add_device_config(DEV_GDB
, optarg
);
3003 if (is_help_option(optarg
)) {
3004 list_data_dirs
= true;
3006 qemu_add_data_dir(g_strdup(optarg
));
3009 case QEMU_OPTION_bios
:
3010 qemu_opts_set(qemu_find_opts("machine"), "firmware", optarg
, &error_abort
);
3012 case QEMU_OPTION_singlestep
:
3019 keyboard_layout
= optarg
;
3021 case QEMU_OPTION_vga
:
3030 w
= strtol(p
, (char **)&p
, 10);
3033 error_report("invalid resolution or depth");
3039 h
= strtol(p
, (char **)&p
, 10);
3044 depth
= strtol(p
, (char **)&p
, 10);
3045 if (depth
!= 1 && depth
!= 2 && depth
!= 4 &&
3046 depth
!= 8 && depth
!= 15 && depth
!= 16 &&
3047 depth
!= 24 && depth
!= 32)
3049 } else if (*p
== '\0') {
3050 depth
= graphic_depth
;
3057 graphic_depth
= depth
;
3060 case QEMU_OPTION_echr
:
3063 term_escape_char
= strtol(optarg
, &r
, 0);
3065 printf("Bad argument to echr\n");
3068 case QEMU_OPTION_monitor
:
3069 default_monitor
= 0;
3070 if (strncmp(optarg
, "none", 4)) {
3071 monitor_parse(optarg
, "readline", false);
3074 case QEMU_OPTION_qmp
:
3075 monitor_parse(optarg
, "control", false);
3076 default_monitor
= 0;
3078 case QEMU_OPTION_qmp_pretty
:
3079 monitor_parse(optarg
, "control", true);
3080 default_monitor
= 0;
3082 case QEMU_OPTION_mon
:
3083 opts
= qemu_opts_parse_noisily(qemu_find_opts("mon"), optarg
,
3088 default_monitor
= 0;
3090 case QEMU_OPTION_chardev
:
3091 opts
= qemu_opts_parse_noisily(qemu_find_opts("chardev"),
3097 case QEMU_OPTION_fsdev
:
3098 olist
= qemu_find_opts("fsdev");
3100 error_report("fsdev support is disabled");
3103 opts
= qemu_opts_parse_noisily(olist
, optarg
, true);
3108 case QEMU_OPTION_virtfs
: {
3111 const char *writeout
, *sock_fd
, *socket
, *path
, *security_model
,
3114 olist
= qemu_find_opts("virtfs");
3116 error_report("virtfs support is disabled");
3119 opts
= qemu_opts_parse_noisily(olist
, optarg
, true);
3124 if (qemu_opt_get(opts
, "fsdriver") == NULL
||
3125 qemu_opt_get(opts
, "mount_tag") == NULL
) {
3126 error_report("Usage: -virtfs fsdriver,mount_tag=tag");
3129 fsdev
= qemu_opts_create(qemu_find_opts("fsdev"),
3130 qemu_opts_id(opts
) ?:
3131 qemu_opt_get(opts
, "mount_tag"),
3134 error_report("duplicate or invalid fsdev id: %s",
3135 qemu_opt_get(opts
, "mount_tag"));
3139 writeout
= qemu_opt_get(opts
, "writeout");
3141 #ifdef CONFIG_SYNC_FILE_RANGE
3142 qemu_opt_set(fsdev
, "writeout", writeout
, &error_abort
);
3144 error_report("writeout=immediate not supported "
3145 "on this platform");
3149 qemu_opt_set(fsdev
, "fsdriver",
3150 qemu_opt_get(opts
, "fsdriver"), &error_abort
);
3151 path
= qemu_opt_get(opts
, "path");
3153 qemu_opt_set(fsdev
, "path", path
, &error_abort
);
3155 security_model
= qemu_opt_get(opts
, "security_model");
3156 if (security_model
) {
3157 qemu_opt_set(fsdev
, "security_model", security_model
,
3160 socket
= qemu_opt_get(opts
, "socket");
3162 qemu_opt_set(fsdev
, "socket", socket
, &error_abort
);
3164 sock_fd
= qemu_opt_get(opts
, "sock_fd");
3166 qemu_opt_set(fsdev
, "sock_fd", sock_fd
, &error_abort
);
3169 qemu_opt_set_bool(fsdev
, "readonly",
3170 qemu_opt_get_bool(opts
, "readonly", 0),
3172 multidevs
= qemu_opt_get(opts
, "multidevs");
3174 qemu_opt_set(fsdev
, "multidevs", multidevs
, &error_abort
);
3176 device
= qemu_opts_create(qemu_find_opts("device"), NULL
, 0,
3178 qemu_opt_set(device
, "driver", "virtio-9p-pci", &error_abort
);
3179 qemu_opt_set(device
, "fsdev",
3180 qemu_opts_id(fsdev
), &error_abort
);
3181 qemu_opt_set(device
, "mount_tag",
3182 qemu_opt_get(opts
, "mount_tag"), &error_abort
);
3185 case QEMU_OPTION_serial
:
3186 add_device_config(DEV_SERIAL
, optarg
);
3188 if (strncmp(optarg
, "mon:", 4) == 0) {
3189 default_monitor
= 0;
3192 case QEMU_OPTION_watchdog
:
3194 error_report("only one watchdog option may be given");
3199 case QEMU_OPTION_action
:
3200 olist
= qemu_find_opts("action");
3201 if (!qemu_opts_parse_noisily(olist
, optarg
, false)) {
3205 case QEMU_OPTION_watchdog_action
:
3206 if (select_watchdog_action(optarg
) == -1) {
3207 error_report("unknown -watchdog-action parameter");
3211 case QEMU_OPTION_parallel
:
3212 add_device_config(DEV_PARALLEL
, optarg
);
3213 default_parallel
= 0;
3214 if (strncmp(optarg
, "mon:", 4) == 0) {
3215 default_monitor
= 0;
3218 case QEMU_OPTION_debugcon
:
3219 add_device_config(DEV_DEBUGCON
, optarg
);
3221 case QEMU_OPTION_loadvm
:
3224 case QEMU_OPTION_full_screen
:
3225 dpy
.has_full_screen
= true;
3226 dpy
.full_screen
= true;
3228 case QEMU_OPTION_alt_grab
:
3231 case QEMU_OPTION_ctrl_grab
:
3234 case QEMU_OPTION_no_quit
:
3235 dpy
.has_window_close
= true;
3236 dpy
.window_close
= false;
3238 case QEMU_OPTION_sdl
:
3240 dpy
.type
= DISPLAY_TYPE_SDL
;
3243 error_report("SDL support is disabled");
3246 case QEMU_OPTION_pidfile
:
3249 case QEMU_OPTION_win2k_hack
:
3250 win2k_install_hack
= 1;
3252 case QEMU_OPTION_acpitable
:
3253 opts
= qemu_opts_parse_noisily(qemu_find_opts("acpi"),
3258 acpi_table_add(opts
, &error_fatal
);
3260 case QEMU_OPTION_smbios
:
3261 opts
= qemu_opts_parse_noisily(qemu_find_opts("smbios"),
3266 smbios_entry_add(opts
, &error_fatal
);
3268 case QEMU_OPTION_fwcfg
:
3269 opts
= qemu_opts_parse_noisily(qemu_find_opts("fw_cfg"),
3275 case QEMU_OPTION_preconfig
:
3276 preconfig_requested
= true;
3278 case QEMU_OPTION_enable_kvm
:
3279 olist
= qemu_find_opts("machine");
3280 qemu_opts_parse_noisily(olist
, "accel=kvm", false);
3283 case QEMU_OPTION_machine
:
3284 olist
= qemu_find_opts("machine");
3285 opts
= qemu_opts_parse_noisily(olist
, optarg
, true);
3290 case QEMU_OPTION_accel
:
3291 accel_opts
= qemu_opts_parse_noisily(qemu_find_opts("accel"),
3293 optarg
= qemu_opt_get(accel_opts
, "accel");
3294 if (!optarg
|| is_help_option(optarg
)) {
3295 printf("Accelerators supported in QEMU binary:\n");
3296 GSList
*el
, *accel_list
= object_class_get_list(TYPE_ACCEL
,
3298 for (el
= accel_list
; el
; el
= el
->next
) {
3299 gchar
*typename
= g_strdup(object_class_get_name(
3300 OBJECT_CLASS(el
->data
)));
3301 /* omit qtest which is used for tests only */
3302 if (g_strcmp0(typename
, ACCEL_CLASS_NAME("qtest")) &&
3303 g_str_has_suffix(typename
, ACCEL_CLASS_SUFFIX
)) {
3304 gchar
**optname
= g_strsplit(typename
,
3305 ACCEL_CLASS_SUFFIX
, 0);
3306 printf("%s\n", optname
[0]);
3307 g_strfreev(optname
);
3311 g_slist_free(accel_list
);
3315 case QEMU_OPTION_usb
:
3316 olist
= qemu_find_opts("machine");
3317 qemu_opts_parse_noisily(olist
, "usb=on", false);
3319 case QEMU_OPTION_usbdevice
:
3320 olist
= qemu_find_opts("machine");
3321 qemu_opts_parse_noisily(olist
, "usb=on", false);
3322 add_device_config(DEV_USB
, optarg
);
3324 case QEMU_OPTION_device
:
3325 if (!qemu_opts_parse_noisily(qemu_find_opts("device"),
3330 case QEMU_OPTION_smp
:
3331 if (!qemu_opts_parse_noisily(qemu_find_opts("smp-opts"),
3336 case QEMU_OPTION_vnc
:
3339 case QEMU_OPTION_no_acpi
:
3340 olist
= qemu_find_opts("machine");
3341 qemu_opts_parse_noisily(olist
, "acpi=off", false);
3343 case QEMU_OPTION_no_hpet
:
3344 olist
= qemu_find_opts("machine");
3345 qemu_opts_parse_noisily(olist
, "hpet=off", false);
3347 case QEMU_OPTION_no_reboot
:
3348 olist
= qemu_find_opts("action");
3349 qemu_opts_parse_noisily(olist
, "reboot=shutdown", false);
3351 case QEMU_OPTION_no_shutdown
:
3352 olist
= qemu_find_opts("action");
3353 qemu_opts_parse_noisily(olist
, "shutdown=pause", false);
3355 case QEMU_OPTION_uuid
:
3356 if (qemu_uuid_parse(optarg
, &qemu_uuid
) < 0) {
3357 error_report("failed to parse UUID string: wrong format");
3360 qemu_uuid_set
= true;
3362 case QEMU_OPTION_option_rom
:
3363 if (nb_option_roms
>= MAX_OPTION_ROMS
) {
3364 error_report("too many option ROMs");
3367 opts
= qemu_opts_parse_noisily(qemu_find_opts("option-rom"),
3372 option_rom
[nb_option_roms
].name
= qemu_opt_get(opts
, "romfile");
3373 option_rom
[nb_option_roms
].bootindex
=
3374 qemu_opt_get_number(opts
, "bootindex", -1);
3375 if (!option_rom
[nb_option_roms
].name
) {
3376 error_report("Option ROM file is not specified");
3381 case QEMU_OPTION_semihosting
:
3382 qemu_semihosting_enable();
3384 case QEMU_OPTION_semihosting_config
:
3385 if (qemu_semihosting_config_options(optarg
) != 0) {
3389 case QEMU_OPTION_name
:
3390 opts
= qemu_opts_parse_noisily(qemu_find_opts("name"),
3395 /* Capture guest name if -msg guest-name is used later */
3396 error_guest_name
= qemu_opt_get(opts
, "guest");
3398 case QEMU_OPTION_prom_env
:
3399 if (nb_prom_envs
>= MAX_PROM_ENVS
) {
3400 error_report("too many prom variables");
3403 prom_envs
[nb_prom_envs
] = optarg
;
3406 case QEMU_OPTION_old_param
:
3409 case QEMU_OPTION_rtc
:
3410 opts
= qemu_opts_parse_noisily(qemu_find_opts("rtc"), optarg
,
3416 case QEMU_OPTION_icount
:
3417 icount_opts
= qemu_opts_parse_noisily(qemu_find_opts("icount"),
3423 case QEMU_OPTION_incoming
:
3425 runstate_set(RUN_STATE_INMIGRATE
);
3429 case QEMU_OPTION_only_migratable
:
3430 only_migratable
= 1;
3432 case QEMU_OPTION_nodefaults
:
3435 case QEMU_OPTION_xen_domid
:
3436 if (!(xen_available())) {
3437 error_report("Option not supported for this target");
3440 xen_domid
= atoi(optarg
);
3442 case QEMU_OPTION_xen_attach
:
3443 if (!(xen_available())) {
3444 error_report("Option not supported for this target");
3447 xen_mode
= XEN_ATTACH
;
3449 case QEMU_OPTION_xen_domid_restrict
:
3450 if (!(xen_available())) {
3451 error_report("Option not supported for this target");
3454 xen_domid_restrict
= true;
3456 case QEMU_OPTION_trace
:
3457 trace_opt_parse(optarg
);
3459 case QEMU_OPTION_plugin
:
3460 qemu_plugin_opt_parse(optarg
, &plugin_list
);
3462 case QEMU_OPTION_readconfig
:
3463 qemu_read_config_file(optarg
, qemu_parse_config_group
, &error_fatal
);
3465 case QEMU_OPTION_spice
:
3466 olist
= qemu_find_opts_err("spice", NULL
);
3468 error_report("spice support is disabled");
3471 opts
= qemu_opts_parse_noisily(olist
, optarg
, false);
3477 case QEMU_OPTION_writeconfig
:
3480 warn_report("-writeconfig is deprecated and will go away without a replacement");
3481 if (strcmp(optarg
, "-") == 0) {
3484 fp
= fopen(optarg
, "w");
3486 error_report("open %s: %s", optarg
,
3491 qemu_config_write(fp
);
3497 case QEMU_OPTION_qtest
:
3498 qtest_chrdev
= optarg
;
3500 case QEMU_OPTION_qtest_log
:
3503 case QEMU_OPTION_sandbox
:
3504 olist
= qemu_find_opts("sandbox");
3506 #ifndef CONFIG_SECCOMP
3507 error_report("-sandbox support is not enabled "
3508 "in this QEMU binary");
3513 opts
= qemu_opts_parse_noisily(olist
, optarg
, true);
3518 case QEMU_OPTION_add_fd
:
3520 opts
= qemu_opts_parse_noisily(qemu_find_opts("add-fd"),
3526 error_report("File descriptor passing is disabled on this "
3531 case QEMU_OPTION_object
:
3532 object_option_parse(optarg
);
3534 case QEMU_OPTION_overcommit
:
3535 opts
= qemu_opts_parse_noisily(qemu_find_opts("overcommit"),
3540 enable_mlock
= qemu_opt_get_bool(opts
, "mem-lock", false);
3541 enable_cpu_pm
= qemu_opt_get_bool(opts
, "cpu-pm", false);
3543 case QEMU_OPTION_compat
:
3548 v
= qobject_input_visitor_new_str(optarg
, NULL
,
3551 visit_type_CompatPolicy(v
, NULL
, &opts
, &error_fatal
);
3552 QAPI_CLONE_MEMBERS(CompatPolicy
, &compat_policy
, opts
);
3554 qapi_free_CompatPolicy(opts
);
3558 case QEMU_OPTION_msg
:
3559 opts
= qemu_opts_parse_noisily(qemu_find_opts("msg"), optarg
,
3564 configure_msg(opts
);
3566 case QEMU_OPTION_dump_vmstate
:
3567 if (vmstate_dump_file
) {
3568 error_report("only one '-dump-vmstate' "
3569 "option may be given");
3572 vmstate_dump_file
= fopen(optarg
, "w");
3573 if (vmstate_dump_file
== NULL
) {
3574 error_report("open %s: %s", optarg
, strerror(errno
));
3578 case QEMU_OPTION_enable_sync_profile
:
3581 case QEMU_OPTION_nouserconfig
:
3582 /* Nothing to be parsed here. Especially, do not error out below. */
3585 if (os_parse_cmd_args(popt
->index
, optarg
)) {
3586 error_report("Option not supported in this build");
3593 * Clear error location left behind by the loop.
3594 * Best done right after the loop. Do not insert code here!
3598 qemu_validate_options();
3599 qemu_process_sugar_options();
3602 * These options affect everything else and should be processed
3603 * before daemonizing.
3605 qemu_process_early_options();
3607 qemu_process_help_options();
3608 qemu_maybe_daemonize(pid_file
);
3611 * The trace backend must be initialized after daemonizing.
3612 * trace_init_backends() will call st_init(), which will create the
3613 * trace thread in the parent, and also register st_flush_trace_buffer()
3614 * in atexit(). This function will force the parent to wait for the
3615 * writeout thread to finish, which will not occur, and the parent
3616 * process will be left in the host.
3618 if (!trace_init_backends()) {
3623 qemu_init_main_loop(&error_fatal
);
3626 user_register_global_props();
3627 replay_configure(icount_opts
);
3629 configure_rtc(qemu_find_opts_singleton("rtc"));
3631 qemu_create_machine(select_machine());
3635 qemu_disable_default_devices();
3636 qemu_create_default_devices();
3637 qemu_create_early_backends();
3639 qemu_apply_machine_options();
3640 phase_advance(PHASE_MACHINE_CREATED
);
3643 * Note: uses machine properties such as kernel-irqchip, must run
3644 * after machine_set_property().
3646 configure_accelerators(argv
[0]);
3647 phase_advance(PHASE_ACCEL_CREATED
);
3650 * Beware, QOM objects created before this point miss global and
3651 * compat properties.
3653 * Global properties get set up by qdev_prop_register_global(),
3654 * called from user_register_global_props(), and certain option
3655 * desugaring. Also in CPU feature desugaring (buried in
3656 * parse_cpu_option()), which happens below this point, but may
3657 * only target the CPU type, which can only be created after
3658 * parse_cpu_option() returned the type.
3660 * Machine compat properties: object_set_machine_compat_props().
3661 * Accelerator compat props: object_set_accelerator_compat_props(),
3662 * called from do_configure_accelerator().
3665 machine_class
= MACHINE_GET_CLASS(current_machine
);
3666 if (!qtest_enabled() && machine_class
->deprecation_reason
) {
3667 error_report("Machine type '%s' is deprecated: %s",
3668 machine_class
->name
, machine_class
->deprecation_reason
);
3672 * Note: creates a QOM object, must run only after global and
3673 * compat properties have been set up.
3675 migration_object_init();
3677 qemu_create_late_backends();
3679 /* parse features once if machine provides default cpu_type */
3680 current_machine
->cpu_type
= machine_class
->default_cpu_type
;
3682 current_machine
->cpu_type
= parse_cpu_option(cpu_option
);
3684 /* NB: for machine none cpu_type could STILL be NULL here! */
3686 qemu_resolve_machine_memdev();
3687 parse_numa_opts(current_machine
);
3689 if (vmstate_dump_file
) {
3691 dump_vmstate_json_to_file(vmstate_dump_file
);
3695 if (!preconfig_requested
) {
3696 qmp_x_exit_preconfig(&error_fatal
);
3698 qemu_init_displays();
3699 accel_setup_post(current_machine
);