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/help-texts.h"
27 #include "qemu/datadir.h"
28 #include "qemu/units.h"
29 #include "exec/cpu-common.h"
30 #include "exec/page-vary.h"
31 #include "hw/qdev-properties.h"
32 #include "qapi/compat-policy.h"
33 #include "qapi/error.h"
34 #include "qapi/qmp/qdict.h"
35 #include "qapi/qmp/qstring.h"
36 #include "qapi/qmp/qjson.h"
37 #include "qemu-version.h"
38 #include "qemu/cutils.h"
39 #include "qemu/help_option.h"
40 #include "qemu/hw-version.h"
41 #include "qemu/uuid.h"
42 #include "sysemu/reset.h"
43 #include "sysemu/runstate.h"
44 #include "sysemu/runstate-action.h"
45 #include "sysemu/seccomp.h"
46 #include "sysemu/tcg.h"
47 #include "sysemu/xen.h"
49 #include "qemu/error-report.h"
50 #include "qemu/sockets.h"
51 #include "qemu/accel.h"
53 #include "hw/isa/isa.h"
54 #include "hw/scsi/scsi.h"
55 #include "hw/display/vga.h"
56 #include "sysemu/watchdog.h"
57 #include "hw/firmware/smbios.h"
58 #include "hw/acpi/acpi.h"
59 #include "hw/xen/xen.h"
60 #include "hw/loader.h"
61 #include "monitor/qdev.h"
63 #include "net/slirp.h"
64 #include "monitor/monitor.h"
65 #include "ui/console.h"
67 #include "sysemu/sysemu.h"
68 #include "sysemu/numa.h"
69 #include "sysemu/hostmem.h"
70 #include "exec/gdbstub.h"
71 #include "qemu/timer.h"
72 #include "chardev/char.h"
73 #include "qemu/bitmap.h"
75 #include "sysemu/blockdev.h"
76 #include "hw/block/block.h"
77 #include "hw/i386/x86.h"
78 #include "hw/i386/pc.h"
79 #include "migration/misc.h"
80 #include "migration/snapshot.h"
81 #include "sysemu/tpm.h"
82 #include "sysemu/dma.h"
83 #include "hw/audio/soundhw.h"
84 #include "audio/audio.h"
85 #include "sysemu/cpus.h"
86 #include "sysemu/cpu-timers.h"
87 #include "migration/colo.h"
88 #include "migration/postcopy-ram.h"
89 #include "sysemu/kvm.h"
90 #include "sysemu/hax.h"
91 #include "qapi/qobject-input-visitor.h"
92 #include "qemu/option.h"
93 #include "qemu/config-file.h"
94 #include "qemu/qemu-options.h"
95 #include "qemu/main-loop.h"
96 #include "hw/cxl/cxl.h"
98 #include "fsdev/qemu-fsdev.h"
100 #include "sysemu/qtest.h"
102 #include "disas/disas.h"
105 #include "trace/control.h"
106 #include "qemu/plugin.h"
107 #include "qemu/queue.h"
108 #include "sysemu/arch_init.h"
109 #include "exec/confidential-guest-support.h"
111 #include "ui/qemu-spice.h"
112 #include "qapi/string-input-visitor.h"
113 #include "qapi/opts-visitor.h"
114 #include "qapi/clone-visitor.h"
115 #include "qom/object_interfaces.h"
116 #include "semihosting/semihost.h"
117 #include "crypto/init.h"
118 #include "sysemu/replay.h"
119 #include "qapi/qapi-events-run-state.h"
120 #include "qapi/qapi-types-audio.h"
121 #include "qapi/qapi-visit-audio.h"
122 #include "qapi/qapi-visit-block-core.h"
123 #include "qapi/qapi-visit-compat.h"
124 #include "qapi/qapi-visit-machine.h"
125 #include "qapi/qapi-visit-ui.h"
126 #include "qapi/qapi-commands-block-core.h"
127 #include "qapi/qapi-commands-migration.h"
128 #include "qapi/qapi-commands-misc.h"
129 #include "qapi/qapi-visit-qom.h"
130 #include "qapi/qapi-commands-ui.h"
131 #include "qapi/qmp/qdict.h"
132 #include "block/qdict.h"
133 #include "qapi/qmp/qerror.h"
134 #include "sysemu/iothread.h"
135 #include "qemu/guest-random.h"
136 #include "qemu/keyval.h"
138 #include "config-host.h"
140 #define MAX_VIRTIO_CONSOLES 1
142 typedef struct BlockdevOptionsQueueEntry
{
143 BlockdevOptions
*bdo
;
145 QSIMPLEQ_ENTRY(BlockdevOptionsQueueEntry
) entry
;
146 } BlockdevOptionsQueueEntry
;
148 typedef QSIMPLEQ_HEAD(, BlockdevOptionsQueueEntry
) BlockdevOptionsQueue
;
150 typedef struct CXLFMWOptionQueueEntry
{
151 CXLFixedMemoryWindowOptions
*opts
;
153 QSIMPLEQ_ENTRY(CXLFMWOptionQueueEntry
) entry
;
154 } CXLFMWOptionQueueEntry
;
156 typedef struct ObjectOption
{
158 QTAILQ_ENTRY(ObjectOption
) next
;
161 typedef struct DeviceOption
{
164 QTAILQ_ENTRY(DeviceOption
) next
;
167 static const char *cpu_option
;
168 static const char *mem_path
;
169 static const char *incoming
;
170 static const char *loadvm
;
171 static const char *accelerators
;
172 static bool have_custom_ram_size
;
173 static const char *ram_memdev_id
;
174 static QDict
*machine_opts_dict
;
175 static QTAILQ_HEAD(, ObjectOption
) object_opts
= QTAILQ_HEAD_INITIALIZER(object_opts
);
176 static QTAILQ_HEAD(, DeviceOption
) device_opts
= QTAILQ_HEAD_INITIALIZER(device_opts
);
177 static int display_remote
;
179 static bool preconfig_requested
;
180 static QemuPluginList plugin_list
= QTAILQ_HEAD_INITIALIZER(plugin_list
);
181 static BlockdevOptionsQueue bdo_queue
= QSIMPLEQ_HEAD_INITIALIZER(bdo_queue
);
182 static QSIMPLEQ_HEAD(, CXLFMWOptionQueueEntry
) CXLFMW_opts
=
183 QSIMPLEQ_HEAD_INITIALIZER(CXLFMW_opts
);
184 static bool nographic
= false;
185 static int mem_prealloc
; /* force preallocation of physical target memory */
186 static const char *vga_model
= NULL
;
187 static DisplayOptions dpy
;
188 static int num_serial_hds
;
189 static Chardev
**serial_hds
;
190 static const char *log_mask
;
191 static const char *log_file
;
192 static bool list_data_dirs
;
193 static const char *watchdog
;
194 static const char *qtest_chrdev
;
195 static const char *qtest_log
;
197 static int has_defaults
= 1;
198 static int default_serial
= 1;
199 static int default_parallel
= 1;
200 static int default_monitor
= 1;
201 static int default_floppy
= 1;
202 static int default_cdrom
= 1;
203 static int default_sdcard
= 1;
204 static int default_vga
= 1;
205 static int default_net
= 1;
211 { .driver
= "isa-serial", .flag
= &default_serial
},
212 { .driver
= "isa-parallel", .flag
= &default_parallel
},
213 { .driver
= "isa-fdc", .flag
= &default_floppy
},
214 { .driver
= "floppy", .flag
= &default_floppy
},
215 { .driver
= "ide-cd", .flag
= &default_cdrom
},
216 { .driver
= "ide-hd", .flag
= &default_cdrom
},
217 { .driver
= "scsi-cd", .flag
= &default_cdrom
},
218 { .driver
= "scsi-hd", .flag
= &default_cdrom
},
219 { .driver
= "VGA", .flag
= &default_vga
},
220 { .driver
= "isa-vga", .flag
= &default_vga
},
221 { .driver
= "cirrus-vga", .flag
= &default_vga
},
222 { .driver
= "isa-cirrus-vga", .flag
= &default_vga
},
223 { .driver
= "vmware-svga", .flag
= &default_vga
},
224 { .driver
= "qxl-vga", .flag
= &default_vga
},
225 { .driver
= "virtio-vga", .flag
= &default_vga
},
226 { .driver
= "ati-vga", .flag
= &default_vga
},
227 { .driver
= "vhost-user-vga", .flag
= &default_vga
},
228 { .driver
= "virtio-vga-gl", .flag
= &default_vga
},
231 static QemuOptsList qemu_rtc_opts
= {
233 .head
= QTAILQ_HEAD_INITIALIZER(qemu_rtc_opts
.head
),
238 .type
= QEMU_OPT_STRING
,
241 .type
= QEMU_OPT_STRING
,
244 .type
= QEMU_OPT_STRING
,
246 { /* end of list */ }
250 static QemuOptsList qemu_option_rom_opts
= {
251 .name
= "option-rom",
252 .implied_opt_name
= "romfile",
253 .head
= QTAILQ_HEAD_INITIALIZER(qemu_option_rom_opts
.head
),
257 .type
= QEMU_OPT_NUMBER
,
260 .type
= QEMU_OPT_STRING
,
262 { /* end of list */ }
266 static QemuOptsList qemu_accel_opts
= {
268 .implied_opt_name
= "accel",
269 .head
= QTAILQ_HEAD_INITIALIZER(qemu_accel_opts
.head
),
272 * no elements => accept any
273 * sanity checking will happen later
274 * when setting accelerator properties
280 static QemuOptsList qemu_boot_opts
= {
282 .implied_opt_name
= "order",
284 .head
= QTAILQ_HEAD_INITIALIZER(qemu_boot_opts
.head
),
288 .type
= QEMU_OPT_STRING
,
291 .type
= QEMU_OPT_STRING
,
294 .type
= QEMU_OPT_BOOL
,
297 .type
= QEMU_OPT_STRING
,
299 .name
= "splash-time",
300 .type
= QEMU_OPT_NUMBER
,
302 .name
= "reboot-timeout",
303 .type
= QEMU_OPT_NUMBER
,
306 .type
= QEMU_OPT_BOOL
,
312 static QemuOptsList qemu_add_fd_opts
= {
314 .head
= QTAILQ_HEAD_INITIALIZER(qemu_add_fd_opts
.head
),
318 .type
= QEMU_OPT_NUMBER
,
319 .help
= "file descriptor of which a duplicate is added to fd set",
322 .type
= QEMU_OPT_NUMBER
,
323 .help
= "ID of the fd set to add fd to",
326 .type
= QEMU_OPT_STRING
,
327 .help
= "free-form string used to describe fd",
329 { /* end of list */ }
333 static QemuOptsList qemu_object_opts
= {
335 .implied_opt_name
= "qom-type",
336 .head
= QTAILQ_HEAD_INITIALIZER(qemu_object_opts
.head
),
342 static QemuOptsList qemu_tpmdev_opts
= {
344 .implied_opt_name
= "type",
345 .head
= QTAILQ_HEAD_INITIALIZER(qemu_tpmdev_opts
.head
),
347 /* options are defined in the TPM backends */
348 { /* end of list */ }
352 static QemuOptsList qemu_overcommit_opts
= {
353 .name
= "overcommit",
354 .head
= QTAILQ_HEAD_INITIALIZER(qemu_overcommit_opts
.head
),
358 .type
= QEMU_OPT_BOOL
,
362 .type
= QEMU_OPT_BOOL
,
364 { /* end of list */ }
368 static QemuOptsList qemu_msg_opts
= {
370 .head
= QTAILQ_HEAD_INITIALIZER(qemu_msg_opts
.head
),
374 .type
= QEMU_OPT_BOOL
,
377 .name
= "guest-name",
378 .type
= QEMU_OPT_BOOL
,
379 .help
= "Prepends guest name for error messages but only if "
380 "-name guest is set otherwise option is ignored\n",
382 { /* end of list */ }
386 static QemuOptsList qemu_name_opts
= {
388 .implied_opt_name
= "guest",
390 .head
= QTAILQ_HEAD_INITIALIZER(qemu_name_opts
.head
),
394 .type
= QEMU_OPT_STRING
,
395 .help
= "Sets the name of the guest.\n"
396 "This name will be displayed in the SDL window caption.\n"
397 "The name will also be used for the VNC server",
400 .type
= QEMU_OPT_STRING
,
401 .help
= "Sets the name of the QEMU process, as shown in top etc",
403 .name
= "debug-threads",
404 .type
= QEMU_OPT_BOOL
,
405 .help
= "When enabled, name the individual threads; defaults off.\n"
406 "NOTE: The thread names are for debugging and not a\n"
409 { /* End of list */ }
413 static QemuOptsList qemu_mem_opts
= {
415 .implied_opt_name
= "size",
416 .head
= QTAILQ_HEAD_INITIALIZER(qemu_mem_opts
.head
),
421 .type
= QEMU_OPT_SIZE
,
425 .type
= QEMU_OPT_NUMBER
,
429 .type
= QEMU_OPT_SIZE
,
431 { /* end of list */ }
435 static QemuOptsList qemu_icount_opts
= {
437 .implied_opt_name
= "shift",
439 .head
= QTAILQ_HEAD_INITIALIZER(qemu_icount_opts
.head
),
443 .type
= QEMU_OPT_STRING
,
446 .type
= QEMU_OPT_BOOL
,
449 .type
= QEMU_OPT_BOOL
,
452 .type
= QEMU_OPT_STRING
,
455 .type
= QEMU_OPT_STRING
,
457 .name
= "rrsnapshot",
458 .type
= QEMU_OPT_STRING
,
460 { /* end of list */ }
464 static QemuOptsList qemu_fw_cfg_opts
= {
466 .implied_opt_name
= "name",
467 .head
= QTAILQ_HEAD_INITIALIZER(qemu_fw_cfg_opts
.head
),
471 .type
= QEMU_OPT_STRING
,
472 .help
= "Sets the fw_cfg name of the blob to be inserted",
475 .type
= QEMU_OPT_STRING
,
476 .help
= "Sets the name of the file from which "
477 "the fw_cfg blob will be loaded",
480 .type
= QEMU_OPT_STRING
,
481 .help
= "Sets content of the blob to be inserted from a string",
484 .type
= QEMU_OPT_STRING
,
485 .help
= "Sets id of the object generating the fw_cfg blob "
488 { /* end of list */ }
492 static QemuOptsList qemu_action_opts
= {
495 .head
= QTAILQ_HEAD_INITIALIZER(qemu_action_opts
.head
),
499 .type
= QEMU_OPT_STRING
,
502 .type
= QEMU_OPT_STRING
,
505 .type
= QEMU_OPT_STRING
,
508 .type
= QEMU_OPT_STRING
,
510 { /* end of list */ }
514 const char *qemu_get_vm_name(void)
519 static void default_driver_disable(const char *driver
)
527 for (i
= 0; i
< ARRAY_SIZE(default_list
); i
++) {
528 if (strcmp(default_list
[i
].driver
, driver
) != 0)
530 *(default_list
[i
].flag
) = 0;
534 static int default_driver_check(void *opaque
, QemuOpts
*opts
, Error
**errp
)
536 const char *driver
= qemu_opt_get(opts
, "driver");
538 default_driver_disable(driver
);
542 static void default_driver_check_json(void)
546 QTAILQ_FOREACH(opt
, &device_opts
, next
) {
547 const char *driver
= qdict_get_try_str(opt
->opts
, "driver");
548 default_driver_disable(driver
);
552 static int parse_name(void *opaque
, QemuOpts
*opts
, Error
**errp
)
554 const char *proc_name
;
556 if (qemu_opt_get(opts
, "debug-threads")) {
557 qemu_thread_naming(qemu_opt_get_bool(opts
, "debug-threads", false));
559 qemu_name
= qemu_opt_get(opts
, "guest");
561 proc_name
= qemu_opt_get(opts
, "process");
563 os_set_proc_name(proc_name
);
569 bool defaults_enabled(void)
575 static int parse_add_fd(void *opaque
, QemuOpts
*opts
, Error
**errp
)
577 int fd
, dupfd
, flags
;
579 const char *fd_opaque
= NULL
;
582 fd
= qemu_opt_get_number(opts
, "fd", -1);
583 fdset_id
= qemu_opt_get_number(opts
, "set", -1);
584 fd_opaque
= qemu_opt_get(opts
, "opaque");
587 error_setg(errp
, "fd option is required and must be non-negative");
591 if (fd
<= STDERR_FILENO
) {
592 error_setg(errp
, "fd cannot be a standard I/O stream");
597 * All fds inherited across exec() necessarily have FD_CLOEXEC
598 * clear, while qemu sets FD_CLOEXEC on all other fds used internally.
600 flags
= fcntl(fd
, F_GETFD
);
601 if (flags
== -1 || (flags
& FD_CLOEXEC
)) {
602 error_setg(errp
, "fd is not valid or already in use");
607 error_setg(errp
, "set option is required and must be non-negative");
611 #ifdef F_DUPFD_CLOEXEC
612 dupfd
= fcntl(fd
, F_DUPFD_CLOEXEC
, 0);
616 qemu_set_cloexec(dupfd
);
620 error_setg(errp
, "error duplicating fd: %s", strerror(errno
));
624 /* add the duplicate fd, and optionally the opaque string, to the fd set */
625 fdinfo
= monitor_fdset_add_fd(dupfd
, true, fdset_id
, !!fd_opaque
, fd_opaque
,
632 static int cleanup_add_fd(void *opaque
, QemuOpts
*opts
, Error
**errp
)
636 fd
= qemu_opt_get_number(opts
, "fd", -1);
643 /***********************************************************/
644 /* QEMU Block devices */
646 #define HD_OPTS "media=disk"
647 #define CDROM_OPTS "media=cdrom"
649 #define PFLASH_OPTS ""
653 static int drive_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
655 BlockInterfaceType
*block_default_type
= opaque
;
657 return drive_new(opts
, *block_default_type
, errp
) == NULL
;
660 static int drive_enable_snapshot(void *opaque
, QemuOpts
*opts
, Error
**errp
)
662 if (qemu_opt_get(opts
, "snapshot") == NULL
) {
663 qemu_opt_set(opts
, "snapshot", "on", &error_abort
);
668 static void default_drive(int enable
, int snapshot
, BlockInterfaceType type
,
669 int index
, const char *optstr
)
674 if (!enable
|| drive_get_by_index(type
, index
)) {
678 opts
= drive_add(type
, index
, NULL
, optstr
);
680 drive_enable_snapshot(NULL
, opts
, NULL
);
683 dinfo
= drive_new(opts
, type
, &error_abort
);
684 dinfo
->is_default
= true;
688 static void configure_blockdev(BlockdevOptionsQueue
*bdo_queue
,
689 MachineClass
*machine_class
, int snapshot
)
692 * If the currently selected machine wishes to override the
693 * units-per-bus property of its default HBA interface type, do so
696 if (machine_class
->units_per_default_bus
) {
697 override_max_devs(machine_class
->block_default_type
,
698 machine_class
->units_per_default_bus
);
701 /* open the virtual block devices */
702 while (!QSIMPLEQ_EMPTY(bdo_queue
)) {
703 BlockdevOptionsQueueEntry
*bdo
= QSIMPLEQ_FIRST(bdo_queue
);
705 QSIMPLEQ_REMOVE_HEAD(bdo_queue
, entry
);
706 loc_push_restore(&bdo
->loc
);
707 qmp_blockdev_add(bdo
->bdo
, &error_fatal
);
709 qapi_free_BlockdevOptions(bdo
->bdo
);
713 qemu_opts_foreach(qemu_find_opts("drive"), drive_enable_snapshot
,
716 if (qemu_opts_foreach(qemu_find_opts("drive"), drive_init_func
,
717 &machine_class
->block_default_type
, &error_fatal
)) {
718 /* We printed help */
722 default_drive(default_cdrom
, snapshot
, machine_class
->block_default_type
, 2,
724 default_drive(default_floppy
, snapshot
, IF_FLOPPY
, 0, FD_OPTS
);
725 default_drive(default_sdcard
, snapshot
, IF_SD
, 0, SD_OPTS
);
729 static QemuOptsList qemu_smp_opts
= {
731 .implied_opt_name
= "cpus",
733 .head
= QTAILQ_HEAD_INITIALIZER(qemu_smp_opts
.head
),
737 .type
= QEMU_OPT_NUMBER
,
740 .type
= QEMU_OPT_NUMBER
,
743 .type
= QEMU_OPT_NUMBER
,
746 .type
= QEMU_OPT_NUMBER
,
749 .type
= QEMU_OPT_NUMBER
,
752 .type
= QEMU_OPT_NUMBER
,
755 .type
= QEMU_OPT_NUMBER
,
761 static void realtime_init(void)
764 if (os_mlock() < 0) {
765 error_report("locking memory failed");
772 static void configure_msg(QemuOpts
*opts
)
774 message_with_timestamp
= qemu_opt_get_bool(opts
, "timestamp", false);
775 error_with_guestname
= qemu_opt_get_bool(opts
, "guest-name", false);
779 /***********************************************************/
782 static int usb_device_add(const char *devname
)
784 USBDevice
*dev
= NULL
;
786 if (!machine_usb(current_machine
)) {
790 dev
= usbdevice_create(devname
);
797 static int usb_parse(const char *cmdline
)
800 r
= usb_device_add(cmdline
);
802 error_report("could not add USB device '%s'", cmdline
);
807 /***********************************************************/
808 /* machine registration */
810 static MachineClass
*find_machine(const char *name
, GSList
*machines
)
814 for (el
= machines
; el
; el
= el
->next
) {
815 MachineClass
*mc
= el
->data
;
817 if (!strcmp(mc
->name
, name
) || !g_strcmp0(mc
->alias
, name
)) {
825 static MachineClass
*find_default_machine(GSList
*machines
)
828 MachineClass
*default_machineclass
= NULL
;
830 for (el
= machines
; el
; el
= el
->next
) {
831 MachineClass
*mc
= el
->data
;
833 if (mc
->is_default
) {
834 assert(default_machineclass
== NULL
&& "Multiple default machines");
835 default_machineclass
= mc
;
839 return default_machineclass
;
842 static void version(void)
844 printf("QEMU emulator version " QEMU_FULL_VERSION
"\n"
845 QEMU_COPYRIGHT
"\n");
848 static void help(int exitcode
)
851 printf("usage: %s [options] [disk_image]\n\n"
852 "'disk_image' is a raw hard disk image for IDE hard disk 0\n\n",
855 #define DEF(option, opt_arg, opt_enum, opt_help, arch_mask) \
856 if ((arch_mask) & arch_type) \
857 fputs(opt_help, stdout);
859 #define ARCHHEADING(text, arch_mask) \
860 if ((arch_mask) & arch_type) \
861 puts(stringify(text));
863 #define DEFHEADING(text) ARCHHEADING(text, QEMU_ARCH_ALL)
865 #include "qemu-options.def"
867 printf("\nDuring emulation, the following keys are useful:\n"
868 "ctrl-alt-f toggle full screen\n"
869 "ctrl-alt-n switch to virtual console 'n'\n"
870 "ctrl-alt toggle mouse and keyboard grab\n"
872 "When using -nographic, press 'ctrl-a h' to get some help.\n"
874 QEMU_HELP_BOTTOM
"\n");
879 #define HAS_ARG 0x0001
881 typedef struct QEMUOption
{
888 static const QEMUOption qemu_options
[] = {
889 { "h", 0, QEMU_OPTION_h
, QEMU_ARCH_ALL
},
891 #define DEF(option, opt_arg, opt_enum, opt_help, arch_mask) \
892 { option, opt_arg, opt_enum, arch_mask },
893 #define DEFHEADING(text)
894 #define ARCHHEADING(text, arch_mask)
896 #include "qemu-options.def"
900 typedef struct VGAInterfaceInfo
{
901 const char *opt_name
; /* option name */
902 const char *name
; /* human-readable name */
903 /* Class names indicating that support is available.
904 * If no class is specified, the interface is always available */
905 const char *class_names
[2];
908 static const VGAInterfaceInfo vga_interfaces
[VGA_TYPE_MAX
] = {
911 .name
= "no graphic card",
915 .name
= "standard VGA",
916 .class_names
= { "VGA", "isa-vga" },
919 .opt_name
= "cirrus",
920 .name
= "Cirrus VGA",
921 .class_names
= { "cirrus-vga", "isa-cirrus-vga" },
924 .opt_name
= "vmware",
925 .name
= "VMWare SVGA",
926 .class_names
= { "vmware-svga" },
929 .opt_name
= "virtio",
930 .name
= "Virtio VGA",
931 .class_names
= { "virtio-vga" },
936 .class_names
= { "qxl-vga" },
940 .name
= "TCX framebuffer",
941 .class_names
= { "sun-tcx" },
945 .name
= "CG3 framebuffer",
946 .class_names
= { "cgthree" },
948 #ifdef CONFIG_XEN_BACKEND
951 .name
= "Xen paravirtualized framebuffer",
956 static bool vga_interface_available(VGAInterfaceType t
)
958 const VGAInterfaceInfo
*ti
= &vga_interfaces
[t
];
960 assert(t
< VGA_TYPE_MAX
);
961 return !ti
->class_names
[0] ||
962 module_object_class_by_name(ti
->class_names
[0]) ||
963 module_object_class_by_name(ti
->class_names
[1]);
967 get_default_vga_model(const MachineClass
*machine_class
)
969 if (machine_class
->default_display
) {
970 return machine_class
->default_display
;
971 } else if (vga_interface_available(VGA_CIRRUS
)) {
973 } else if (vga_interface_available(VGA_STD
)) {
980 static void select_vgahw(const MachineClass
*machine_class
, const char *p
)
985 if (g_str_equal(p
, "help")) {
986 const char *def
= get_default_vga_model(machine_class
);
988 for (t
= 0; t
< VGA_TYPE_MAX
; t
++) {
989 const VGAInterfaceInfo
*ti
= &vga_interfaces
[t
];
991 if (vga_interface_available(t
) && ti
->opt_name
) {
992 printf("%-20s %s%s\n", ti
->opt_name
, ti
->name
?: "",
993 g_str_equal(ti
->opt_name
, def
) ? " (default)" : "");
999 assert(vga_interface_type
== VGA_NONE
);
1000 for (t
= 0; t
< VGA_TYPE_MAX
; t
++) {
1001 const VGAInterfaceInfo
*ti
= &vga_interfaces
[t
];
1002 if (ti
->opt_name
&& strstart(p
, ti
->opt_name
, &opts
)) {
1003 if (!vga_interface_available(t
)) {
1004 error_report("%s not available", ti
->name
);
1007 vga_interface_type
= t
;
1011 if (t
== VGA_TYPE_MAX
) {
1013 error_report("unknown vga type: %s", p
);
1017 const char *nextopt
;
1019 if (strstart(opts
, ",retrace=", &nextopt
)) {
1021 if (strstart(opts
, "dumb", &nextopt
))
1022 vga_retrace_method
= VGA_RETRACE_DUMB
;
1023 else if (strstart(opts
, "precise", &nextopt
))
1024 vga_retrace_method
= VGA_RETRACE_PRECISE
;
1025 else goto invalid_vga
;
1026 } else goto invalid_vga
;
1031 static void parse_display_qapi(const char *optarg
)
1033 DisplayOptions
*opts
;
1036 v
= qobject_input_visitor_new_str(optarg
, "type", &error_fatal
);
1038 visit_type_DisplayOptions(v
, NULL
, &opts
, &error_fatal
);
1039 QAPI_CLONE_MEMBERS(DisplayOptions
, &dpy
, opts
);
1041 qapi_free_DisplayOptions(opts
);
1045 DisplayOptions
*qmp_query_display_options(Error
**errp
)
1047 return QAPI_CLONE(DisplayOptions
, &dpy
);
1050 static void parse_display(const char *p
)
1054 if (is_help_option(p
)) {
1055 qemu_display_help();
1059 if (strstart(p
, "vnc", &opts
)) {
1061 * vnc isn't a (local) DisplayType but a protocol for remote
1065 vnc_parse(opts
+ 1);
1067 error_report("VNC requires a display argument vnc=<display>");
1071 parse_display_qapi(p
);
1075 static void parse_cxl_fixed_memory_window(const char *optarg
)
1077 CXLFMWOptionQueueEntry
*cfmws_entry
;
1080 v
= qobject_input_visitor_new_str(optarg
, "cxl-fixed-memory-window",
1082 cfmws_entry
= g_new(CXLFMWOptionQueueEntry
, 1);
1083 visit_type_CXLFixedMemoryWindowOptions(v
, NULL
, &cfmws_entry
->opts
,
1085 if (!cfmws_entry
->opts
) {
1089 loc_save(&cfmws_entry
->loc
);
1090 QSIMPLEQ_INSERT_TAIL(&CXLFMW_opts
, cfmws_entry
, entry
);
1093 static inline bool nonempty_str(const char *str
)
1098 static int parse_fw_cfg(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1102 const char *name
, *file
, *str
, *gen_id
;
1103 FWCfgState
*fw_cfg
= (FWCfgState
*) opaque
;
1105 if (fw_cfg
== NULL
) {
1106 error_setg(errp
, "fw_cfg device not available");
1109 name
= qemu_opt_get(opts
, "name");
1110 file
= qemu_opt_get(opts
, "file");
1111 str
= qemu_opt_get(opts
, "string");
1112 gen_id
= qemu_opt_get(opts
, "gen_id");
1114 /* we need the name, and exactly one of: file, content string, gen_id */
1115 if (!nonempty_str(name
) ||
1116 nonempty_str(file
) + nonempty_str(str
) + nonempty_str(gen_id
) != 1) {
1117 error_setg(errp
, "name, plus exactly one of file,"
1118 " string and gen_id, are needed");
1121 if (strlen(name
) > FW_CFG_MAX_FILE_PATH
- 1) {
1122 error_setg(errp
, "name too long (max. %d char)",
1123 FW_CFG_MAX_FILE_PATH
- 1);
1126 if (nonempty_str(gen_id
)) {
1128 * In this particular case where the content is populated
1129 * internally, the "etc/" namespace protection is relaxed,
1130 * so do not emit a warning.
1132 } else if (strncmp(name
, "opt/", 4) != 0) {
1133 warn_report("externally provided fw_cfg item names "
1134 "should be prefixed with \"opt/\"");
1136 if (nonempty_str(str
)) {
1137 size
= strlen(str
); /* NUL terminator NOT included in fw_cfg blob */
1138 buf
= g_memdup(str
, size
);
1139 } else if (nonempty_str(gen_id
)) {
1140 if (!fw_cfg_add_from_generator(fw_cfg
, name
, gen_id
, errp
)) {
1146 if (!g_file_get_contents(file
, &buf
, &size
, &err
)) {
1147 error_setg(errp
, "can't load %s: %s", file
, err
->message
);
1152 /* For legacy, keep user files in a specific global order. */
1153 fw_cfg_set_order_override(fw_cfg
, FW_CFG_ORDER_OVERRIDE_USER
);
1154 fw_cfg_add_file(fw_cfg
, name
, buf
, size
);
1155 fw_cfg_reset_order_override(fw_cfg
);
1159 static int device_help_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1161 return qdev_device_help(opts
);
1164 static int device_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1168 dev
= qdev_device_add(opts
, errp
);
1169 if (!dev
&& *errp
) {
1170 error_report_err(*errp
);
1173 object_unref(OBJECT(dev
));
1178 static int chardev_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1180 Error
*local_err
= NULL
;
1182 if (!qemu_chr_new_from_opts(opts
, NULL
, &local_err
)) {
1184 error_propagate(errp
, local_err
);
1192 #ifdef CONFIG_VIRTFS
1193 static int fsdev_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1195 return qemu_fsdev_add(opts
, errp
);
1199 static int mon_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1201 return monitor_init_opts(opts
, errp
);
1204 static void monitor_parse(const char *optarg
, const char *mode
, bool pretty
)
1206 static int monitor_device_index
= 0;
1211 if (strstart(optarg
, "chardev:", &p
)) {
1212 snprintf(label
, sizeof(label
), "%s", p
);
1214 snprintf(label
, sizeof(label
), "compat_monitor%d",
1215 monitor_device_index
);
1216 opts
= qemu_chr_parse_compat(label
, optarg
, true);
1218 error_report("parse error: %s", optarg
);
1223 opts
= qemu_opts_create(qemu_find_opts("mon"), label
, 1, &error_fatal
);
1224 qemu_opt_set(opts
, "mode", mode
, &error_abort
);
1225 qemu_opt_set(opts
, "chardev", label
, &error_abort
);
1226 if (!strcmp(mode
, "control")) {
1227 qemu_opt_set_bool(opts
, "pretty", pretty
, &error_abort
);
1229 assert(pretty
== false);
1231 monitor_device_index
++;
1234 struct device_config
{
1236 DEV_USB
, /* -usbdevice */
1237 DEV_SERIAL
, /* -serial */
1238 DEV_PARALLEL
, /* -parallel */
1239 DEV_DEBUGCON
, /* -debugcon */
1240 DEV_GDB
, /* -gdb, -s */
1241 DEV_SCLP
, /* s390 sclp */
1243 const char *cmdline
;
1245 QTAILQ_ENTRY(device_config
) next
;
1248 static QTAILQ_HEAD(, device_config
) device_configs
=
1249 QTAILQ_HEAD_INITIALIZER(device_configs
);
1251 static void add_device_config(int type
, const char *cmdline
)
1253 struct device_config
*conf
;
1255 conf
= g_malloc0(sizeof(*conf
));
1257 conf
->cmdline
= cmdline
;
1258 loc_save(&conf
->loc
);
1259 QTAILQ_INSERT_TAIL(&device_configs
, conf
, next
);
1262 static int foreach_device_config(int type
, int (*func
)(const char *cmdline
))
1264 struct device_config
*conf
;
1267 QTAILQ_FOREACH(conf
, &device_configs
, next
) {
1268 if (conf
->type
!= type
)
1270 loc_push_restore(&conf
->loc
);
1271 rc
= func(conf
->cmdline
);
1272 loc_pop(&conf
->loc
);
1280 static void qemu_disable_default_devices(void)
1282 MachineClass
*machine_class
= MACHINE_GET_CLASS(current_machine
);
1284 default_driver_check_json();
1285 qemu_opts_foreach(qemu_find_opts("device"),
1286 default_driver_check
, NULL
, NULL
);
1287 qemu_opts_foreach(qemu_find_opts("global"),
1288 default_driver_check
, NULL
, NULL
);
1290 if (!vga_model
&& !default_vga
) {
1291 vga_interface_type
= VGA_DEVICE
;
1292 vga_interface_created
= true;
1294 if (!has_defaults
|| machine_class
->no_serial
) {
1297 if (!has_defaults
|| machine_class
->no_parallel
) {
1298 default_parallel
= 0;
1300 if (!has_defaults
|| machine_class
->no_floppy
) {
1303 if (!has_defaults
|| machine_class
->no_cdrom
) {
1306 if (!has_defaults
|| machine_class
->no_sdcard
) {
1309 if (!has_defaults
) {
1310 default_monitor
= 0;
1316 static void qemu_create_default_devices(void)
1318 MachineClass
*machine_class
= MACHINE_GET_CLASS(current_machine
);
1320 if (is_daemonized()) {
1321 /* According to documentation and historically, -nographic redirects
1322 * serial port, parallel port and monitor to stdio, which does not work
1323 * with -daemonize. We can redirect these to null instead, but since
1324 * -nographic is legacy, let's just error out.
1325 * We disallow -nographic only if all other ports are not redirected
1326 * explicitly, to not break existing legacy setups which uses
1327 * -nographic _and_ redirects all ports explicitly - this is valid
1328 * usage, -nographic is just a no-op in this case.
1331 && (default_parallel
|| default_serial
|| default_monitor
)) {
1332 error_report("-nographic cannot be used with -daemonize");
1338 if (default_parallel
)
1339 add_device_config(DEV_PARALLEL
, "null");
1340 if (default_serial
&& default_monitor
) {
1341 add_device_config(DEV_SERIAL
, "mon:stdio");
1344 add_device_config(DEV_SERIAL
, "stdio");
1345 if (default_monitor
)
1346 monitor_parse("stdio", "readline", false);
1350 add_device_config(DEV_SERIAL
, "vc:80Cx24C");
1351 if (default_parallel
)
1352 add_device_config(DEV_PARALLEL
, "vc:80Cx24C");
1353 if (default_monitor
)
1354 monitor_parse("vc:80Cx24C", "readline", false);
1358 QemuOptsList
*net
= qemu_find_opts("net");
1359 qemu_opts_parse(net
, "nic", true, &error_abort
);
1361 qemu_opts_parse(net
, "user", true, &error_abort
);
1365 #if defined(CONFIG_VNC)
1366 if (!QTAILQ_EMPTY(&(qemu_find_opts("vnc")->head
))) {
1370 if (dpy
.type
== DISPLAY_TYPE_DEFAULT
&& !display_remote
) {
1371 if (!qemu_display_find_default(&dpy
)) {
1372 dpy
.type
= DISPLAY_TYPE_NONE
;
1373 #if defined(CONFIG_VNC)
1374 vnc_parse("localhost:0,to=99,id=default");
1378 if (dpy
.type
== DISPLAY_TYPE_DEFAULT
) {
1379 dpy
.type
= DISPLAY_TYPE_NONE
;
1382 /* If no default VGA is requested, the default is "none". */
1384 vga_model
= get_default_vga_model(machine_class
);
1387 select_vgahw(machine_class
, vga_model
);
1391 static int serial_parse(const char *devname
)
1393 int index
= num_serial_hds
;
1396 if (strcmp(devname
, "none") == 0)
1398 snprintf(label
, sizeof(label
), "serial%d", index
);
1399 serial_hds
= g_renew(Chardev
*, serial_hds
, index
+ 1);
1401 serial_hds
[index
] = qemu_chr_new_mux_mon(label
, devname
, NULL
);
1402 if (!serial_hds
[index
]) {
1403 error_report("could not connect serial device"
1404 " to character backend '%s'", devname
);
1411 Chardev
*serial_hd(int i
)
1414 if (i
< num_serial_hds
) {
1415 return serial_hds
[i
];
1420 static int parallel_parse(const char *devname
)
1422 static int index
= 0;
1425 if (strcmp(devname
, "none") == 0)
1427 if (index
== MAX_PARALLEL_PORTS
) {
1428 error_report("too many parallel ports");
1431 snprintf(label
, sizeof(label
), "parallel%d", index
);
1432 parallel_hds
[index
] = qemu_chr_new_mux_mon(label
, devname
, NULL
);
1433 if (!parallel_hds
[index
]) {
1434 error_report("could not connect parallel device"
1435 " to character backend '%s'", devname
);
1442 static int debugcon_parse(const char *devname
)
1446 if (!qemu_chr_new_mux_mon("debugcon", devname
, NULL
)) {
1447 error_report("invalid character backend '%s'", devname
);
1450 opts
= qemu_opts_create(qemu_find_opts("device"), "debugcon", 1, NULL
);
1452 error_report("already have a debugcon device");
1455 qemu_opt_set(opts
, "driver", "isa-debugcon", &error_abort
);
1456 qemu_opt_set(opts
, "chardev", "debugcon", &error_abort
);
1460 static gint
machine_class_cmp(gconstpointer a
, gconstpointer b
)
1462 const MachineClass
*mc1
= a
, *mc2
= b
;
1465 if (mc1
->family
== NULL
) {
1466 if (mc2
->family
== NULL
) {
1467 /* Compare standalone machine types against each other; they sort
1468 * in increasing order.
1470 return strcmp(object_class_get_name(OBJECT_CLASS(mc1
)),
1471 object_class_get_name(OBJECT_CLASS(mc2
)));
1474 /* Standalone machine types sort after families. */
1478 if (mc2
->family
== NULL
) {
1479 /* Families sort before standalone machine types. */
1483 /* Families sort between each other alphabetically increasingly. */
1484 res
= strcmp(mc1
->family
, mc2
->family
);
1489 /* Within the same family, machine types sort in decreasing order. */
1490 return strcmp(object_class_get_name(OBJECT_CLASS(mc2
)),
1491 object_class_get_name(OBJECT_CLASS(mc1
)));
1494 static void machine_help_func(const QDict
*qdict
)
1496 GSList
*machines
, *el
;
1497 const char *type
= qdict_get_try_str(qdict
, "type");
1499 machines
= object_class_get_list(TYPE_MACHINE
, false);
1501 ObjectClass
*machine_class
= OBJECT_CLASS(find_machine(type
, machines
));
1502 if (machine_class
) {
1503 type_print_class_properties(object_class_get_name(machine_class
));
1508 printf("Supported machines are:\n");
1509 machines
= g_slist_sort(machines
, machine_class_cmp
);
1510 for (el
= machines
; el
; el
= el
->next
) {
1511 MachineClass
*mc
= el
->data
;
1513 printf("%-20s %s (alias of %s)\n", mc
->alias
, mc
->desc
, mc
->name
);
1515 printf("%-20s %s%s%s\n", mc
->name
, mc
->desc
,
1516 mc
->is_default
? " (default)" : "",
1517 mc
->deprecation_reason
? " (deprecated)" : "");
1522 machine_merge_property(const char *propname
, QDict
*prop
, Error
**errp
)
1527 /* Preserve the caller's reference to prop. */
1529 qdict_put(opts
, propname
, prop
);
1530 keyval_merge(machine_opts_dict
, opts
, errp
);
1531 qobject_unref(opts
);
1535 machine_parse_property_opt(QemuOptsList
*opts_list
, const char *propname
,
1541 prop
= keyval_parse(arg
, opts_list
->implied_opt_name
, &help
, &error_fatal
);
1543 qemu_opts_print_help(opts_list
, true);
1546 machine_merge_property(propname
, prop
, &error_fatal
);
1547 qobject_unref(prop
);
1550 static const char *pid_file
;
1551 static Notifier qemu_unlink_pidfile_notifier
;
1553 static void qemu_unlink_pidfile(Notifier
*n
, void *data
)
1560 static const QEMUOption
*lookup_opt(int argc
, char **argv
,
1561 const char **poptarg
, int *poptind
)
1563 const QEMUOption
*popt
;
1564 int optind
= *poptind
;
1565 char *r
= argv
[optind
];
1568 loc_set_cmdline(argv
, optind
, 1);
1570 /* Treat --foo the same as -foo. */
1573 popt
= qemu_options
;
1576 error_report("invalid option");
1579 if (!strcmp(popt
->name
, r
+ 1))
1583 if (popt
->flags
& HAS_ARG
) {
1584 if (optind
>= argc
) {
1585 error_report("requires an argument");
1588 optarg
= argv
[optind
++];
1589 loc_set_cmdline(argv
, optind
- 2, 2);
1600 static MachineClass
*select_machine(QDict
*qdict
, Error
**errp
)
1602 const char *optarg
= qdict_get_try_str(qdict
, "type");
1603 GSList
*machines
= object_class_get_list(TYPE_MACHINE
, false);
1604 MachineClass
*machine_class
;
1605 Error
*local_err
= NULL
;
1608 machine_class
= find_machine(optarg
, machines
);
1609 qdict_del(qdict
, "type");
1610 if (!machine_class
) {
1611 error_setg(&local_err
, "unsupported machine type");
1614 machine_class
= find_default_machine(machines
);
1615 if (!machine_class
) {
1616 error_setg(&local_err
, "No machine specified, and there is no default");
1620 g_slist_free(machines
);
1622 error_append_hint(&local_err
, "Use -machine help to list supported machines\n");
1623 error_propagate(errp
, local_err
);
1625 return machine_class
;
1628 static int object_parse_property_opt(Object
*obj
,
1629 const char *name
, const char *value
,
1630 const char *skip
, Error
**errp
)
1632 if (g_str_equal(name
, skip
)) {
1636 if (!object_property_parse(obj
, name
, value
, errp
)) {
1643 /* *Non*recursively replace underscores with dashes in QDict keys. */
1644 static void keyval_dashify(QDict
*qdict
, Error
**errp
)
1646 const QDictEntry
*ent
, *next
;
1649 for (ent
= qdict_first(qdict
); ent
; ent
= next
) {
1650 g_autofree
char *new_key
= NULL
;
1652 next
= qdict_next(qdict
, ent
);
1653 if (!strchr(ent
->key
, '_')) {
1656 new_key
= g_strdup(ent
->key
);
1657 for (p
= new_key
; *p
; p
++) {
1662 if (qdict_haskey(qdict
, new_key
)) {
1663 error_setg(errp
, "Conflict between '%s' and '%s'", ent
->key
, new_key
);
1666 qobject_ref(ent
->value
);
1667 qdict_put_obj(qdict
, new_key
, ent
->value
);
1668 qdict_del(qdict
, ent
->key
);
1672 static void qemu_apply_legacy_machine_options(QDict
*qdict
)
1677 keyval_dashify(qdict
, &error_fatal
);
1679 /* Legacy options do not correspond to MachineState properties. */
1680 value
= qdict_get_try_str(qdict
, "accel");
1682 accelerators
= g_strdup(value
);
1683 qdict_del(qdict
, "accel");
1686 value
= qdict_get_try_str(qdict
, "igd-passthru");
1688 object_register_sugar_prop(ACCEL_CLASS_NAME("xen"), "igd-passthru", value
,
1690 qdict_del(qdict
, "igd-passthru");
1693 value
= qdict_get_try_str(qdict
, "kvm-shadow-mem");
1695 object_register_sugar_prop(ACCEL_CLASS_NAME("kvm"), "kvm-shadow-mem", value
,
1697 qdict_del(qdict
, "kvm-shadow-mem");
1700 value
= qdict_get_try_str(qdict
, "kernel-irqchip");
1702 object_register_sugar_prop(ACCEL_CLASS_NAME("kvm"), "kernel-irqchip", value
,
1704 object_register_sugar_prop(ACCEL_CLASS_NAME("whpx"), "kernel-irqchip", value
,
1706 qdict_del(qdict
, "kernel-irqchip");
1709 value
= qdict_get_try_str(qdict
, "memory-backend");
1712 error_report("'-mem-path' can't be used together with"
1713 "'-machine memory-backend'");
1717 /* Resolved later. */
1718 ram_memdev_id
= g_strdup(value
);
1719 qdict_del(qdict
, "memory-backend");
1722 prop
= qdict_get(qdict
, "memory");
1724 have_custom_ram_size
=
1725 qobject_type(prop
) == QTYPE_QDICT
&&
1726 qdict_haskey(qobject_to(QDict
, prop
), "size");
1730 static void object_option_foreach_add(bool (*type_opt_predicate
)(const char *))
1732 ObjectOption
*opt
, *next
;
1734 QTAILQ_FOREACH_SAFE(opt
, &object_opts
, next
, next
) {
1735 const char *type
= ObjectType_str(opt
->opts
->qom_type
);
1736 if (type_opt_predicate(type
)) {
1737 user_creatable_add_qapi(opt
->opts
, &error_fatal
);
1738 qapi_free_ObjectOptions(opt
->opts
);
1739 QTAILQ_REMOVE(&object_opts
, opt
, next
);
1745 static void object_option_add_visitor(Visitor
*v
)
1747 ObjectOption
*opt
= g_new0(ObjectOption
, 1);
1748 visit_type_ObjectOptions(v
, NULL
, &opt
->opts
, &error_fatal
);
1749 QTAILQ_INSERT_TAIL(&object_opts
, opt
, next
);
1752 static void object_option_parse(const char *optarg
)
1758 if (optarg
[0] == '{') {
1759 QObject
*obj
= qobject_from_json(optarg
, &error_fatal
);
1761 v
= qobject_input_visitor_new(obj
);
1764 opts
= qemu_opts_parse_noisily(qemu_find_opts("object"),
1770 type
= qemu_opt_get(opts
, "qom-type");
1772 error_setg(&error_fatal
, QERR_MISSING_PARAMETER
, "qom-type");
1774 if (user_creatable_print_help(type
, opts
)) {
1778 v
= opts_visitor_new(opts
);
1781 object_option_add_visitor(v
);
1786 * Initial object creation happens before all other
1787 * QEMU data types are created. The majority of objects
1788 * can be created at this point. The rng-egd object
1789 * cannot be created here, as it depends on the chardev
1792 static bool object_create_early(const char *type
)
1795 * Objects should not be made "delayed" without a reason. If you
1796 * add one, state the reason in a comment!
1799 /* Reason: property "chardev" */
1800 if (g_str_equal(type
, "rng-egd") ||
1801 g_str_equal(type
, "qtest")) {
1805 #if defined(CONFIG_VHOST_USER) && defined(CONFIG_LINUX)
1806 /* Reason: cryptodev-vhost-user property "chardev" */
1807 if (g_str_equal(type
, "cryptodev-vhost-user")) {
1812 /* Reason: vhost-user-blk-server property "node-name" */
1813 if (g_str_equal(type
, "vhost-user-blk-server")) {
1817 * Reason: filter-* property "netdev" etc.
1819 if (g_str_equal(type
, "filter-buffer") ||
1820 g_str_equal(type
, "filter-dump") ||
1821 g_str_equal(type
, "filter-mirror") ||
1822 g_str_equal(type
, "filter-redirector") ||
1823 g_str_equal(type
, "colo-compare") ||
1824 g_str_equal(type
, "filter-rewriter") ||
1825 g_str_equal(type
, "filter-replay")) {
1830 * Allocation of large amounts of memory may delay
1831 * chardev initialization for too long, and trigger timeouts
1832 * on software that waits for a monitor socket to be created
1835 if (g_str_has_prefix(type
, "memory-backend-")) {
1842 static void qemu_apply_machine_options(QDict
*qdict
)
1844 object_set_properties_from_keyval(OBJECT(current_machine
), qdict
, false, &error_fatal
);
1846 if (semihosting_enabled() && !semihosting_get_argc()) {
1847 /* fall back to the -kernel/-append */
1848 semihosting_arg_fallback(current_machine
->kernel_filename
, current_machine
->kernel_cmdline
);
1851 if (current_machine
->smp
.cpus
> 1) {
1852 Error
*blocker
= NULL
;
1853 error_setg(&blocker
, QERR_REPLAY_NOT_SUPPORTED
, "smp");
1854 replay_add_blocker(blocker
);
1858 static void qemu_create_early_backends(void)
1860 MachineClass
*machine_class
= MACHINE_GET_CLASS(current_machine
);
1861 #if defined(CONFIG_SDL)
1862 const bool use_sdl
= (dpy
.type
== DISPLAY_TYPE_SDL
);
1864 const bool use_sdl
= false;
1866 #if defined(CONFIG_GTK)
1867 const bool use_gtk
= (dpy
.type
== DISPLAY_TYPE_GTK
);
1869 const bool use_gtk
= false;
1872 if (dpy
.has_window_close
&& !use_gtk
&& !use_sdl
) {
1873 error_report("window-close is only valid for GTK and SDL, "
1877 qemu_display_early_init(&dpy
);
1878 qemu_console_early_init();
1880 if (dpy
.has_gl
&& dpy
.gl
!= DISPLAYGL_MODE_OFF
&& display_opengl
== 0) {
1881 #if defined(CONFIG_OPENGL)
1882 error_report("OpenGL is not supported by the display");
1884 error_report("OpenGL support is disabled");
1889 object_option_foreach_add(object_create_early
);
1891 /* spice needs the timers to be initialized by this point */
1892 /* spice must initialize before audio as it changes the default audiodev */
1893 /* spice must initialize before chardevs (for spicevmc and spiceport) */
1896 qemu_opts_foreach(qemu_find_opts("chardev"),
1897 chardev_init_func
, NULL
, &error_fatal
);
1899 #ifdef CONFIG_VIRTFS
1900 qemu_opts_foreach(qemu_find_opts("fsdev"),
1901 fsdev_init_func
, NULL
, &error_fatal
);
1905 * Note: we need to create audio and block backends before
1906 * setting machine properties, so they can be referred to.
1908 configure_blockdev(&bdo_queue
, machine_class
, snapshot
);
1909 audio_init_audiodevs();
1914 * The remainder of object creation happens after the
1915 * creation of chardev, fsdev, net clients and device data types.
1917 static bool object_create_late(const char *type
)
1919 return !object_create_early(type
);
1922 static void qemu_create_late_backends(void)
1925 qtest_server_init(qtest_chrdev
, qtest_log
, &error_fatal
);
1928 net_init_clients(&error_fatal
);
1930 object_option_foreach_add(object_create_late
);
1932 if (tpm_init() < 0) {
1936 qemu_opts_foreach(qemu_find_opts("mon"),
1937 mon_init_func
, NULL
, &error_fatal
);
1939 if (foreach_device_config(DEV_SERIAL
, serial_parse
) < 0)
1941 if (foreach_device_config(DEV_PARALLEL
, parallel_parse
) < 0)
1943 if (foreach_device_config(DEV_DEBUGCON
, debugcon_parse
) < 0)
1946 /* now chardevs have been created we may have semihosting to connect */
1947 qemu_semihosting_connect_chardevs();
1948 qemu_semihosting_console_init();
1951 static void cxl_set_opts(void)
1953 while (!QSIMPLEQ_EMPTY(&CXLFMW_opts
)) {
1954 CXLFMWOptionQueueEntry
*cfmws_entry
= QSIMPLEQ_FIRST(&CXLFMW_opts
);
1956 loc_restore(&cfmws_entry
->loc
);
1957 QSIMPLEQ_REMOVE_HEAD(&CXLFMW_opts
, entry
);
1958 cxl_fixed_memory_window_config(current_machine
, cfmws_entry
->opts
,
1960 qapi_free_CXLFixedMemoryWindowOptions(cfmws_entry
->opts
);
1961 g_free(cfmws_entry
);
1965 static void qemu_resolve_machine_memdev(void)
1967 if (ram_memdev_id
) {
1969 ram_addr_t backend_size
;
1971 backend
= object_resolve_path_type(ram_memdev_id
,
1972 TYPE_MEMORY_BACKEND
, NULL
);
1974 error_report("Memory backend '%s' not found", ram_memdev_id
);
1977 if (!have_custom_ram_size
) {
1978 backend_size
= object_property_get_uint(backend
, "size", &error_abort
);
1979 current_machine
->ram_size
= backend_size
;
1981 object_property_set_link(OBJECT(current_machine
),
1982 "memory-backend", backend
, &error_fatal
);
1986 static void parse_memory_options(const char *arg
)
1990 const char *mem_str
;
1992 opts
= qemu_opts_parse_noisily(qemu_find_opts("memory"), arg
, true);
1999 if (qemu_opt_get_size(opts
, "size", 0) != 0) {
2000 mem_str
= qemu_opt_get(opts
, "size");
2002 error_report("missing 'size' option value");
2006 /* Fix up legacy suffix-less format */
2007 if (g_ascii_isdigit(mem_str
[strlen(mem_str
) - 1])) {
2008 g_autofree
char *mib_str
= g_strdup_printf("%sM", mem_str
);
2009 qdict_put_str(prop
, "size", mib_str
);
2011 qdict_put_str(prop
, "size", mem_str
);
2015 if (qemu_opt_get(opts
, "maxmem")) {
2016 qdict_put_str(prop
, "max-size", qemu_opt_get(opts
, "maxmem"));
2018 if (qemu_opt_get(opts
, "slots")) {
2019 qdict_put_str(prop
, "slots", qemu_opt_get(opts
, "slots"));
2023 qdict_put(dict
, "memory", prop
);
2024 keyval_merge(machine_opts_dict
, dict
, &error_fatal
);
2025 qobject_unref(dict
);
2028 static void qemu_create_machine(QDict
*qdict
)
2030 MachineClass
*machine_class
= select_machine(qdict
, &error_fatal
);
2031 object_set_machine_compat_props(machine_class
->compat_props
);
2033 current_machine
= MACHINE(object_new_with_class(OBJECT_CLASS(machine_class
)));
2034 object_property_add_child(object_get_root(), "machine",
2035 OBJECT(current_machine
));
2036 object_property_add_child(container_get(OBJECT(current_machine
),
2038 "sysbus", OBJECT(sysbus_get_default()));
2040 if (machine_class
->minimum_page_bits
) {
2041 if (!set_preferred_target_page_bits(machine_class
->minimum_page_bits
)) {
2042 /* This would be a board error: specifying a minimum smaller than
2043 * a target's compile-time fixed setting.
2045 g_assert_not_reached();
2049 cpu_exec_init_all();
2052 if (machine_class
->hw_version
) {
2053 qemu_set_hw_version(machine_class
->hw_version
);
2057 * Get the default machine options from the machine if it is not already
2058 * specified either by the configuration file or by the command line.
2060 if (machine_class
->default_machine_opts
) {
2061 QDict
*default_opts
=
2062 keyval_parse(machine_class
->default_machine_opts
, NULL
, NULL
,
2064 qemu_apply_legacy_machine_options(default_opts
);
2065 object_set_properties_from_keyval(OBJECT(current_machine
), default_opts
,
2066 false, &error_abort
);
2067 qobject_unref(default_opts
);
2071 static int global_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2075 g
= g_malloc0(sizeof(*g
));
2076 g
->driver
= qemu_opt_get(opts
, "driver");
2077 g
->property
= qemu_opt_get(opts
, "property");
2078 g
->value
= qemu_opt_get(opts
, "value");
2079 qdev_prop_register_global(g
);
2084 * Return whether configuration group @group is stored in QemuOpts, or
2085 * recorded as one or more QDicts by qemu_record_config_group.
2087 static bool is_qemuopts_group(const char *group
)
2089 if (g_str_equal(group
, "object") ||
2090 g_str_equal(group
, "machine") ||
2091 g_str_equal(group
, "smp-opts") ||
2092 g_str_equal(group
, "boot-opts") ||
2093 g_str_equal(group
, "memory")) {
2099 static void qemu_record_config_group(const char *group
, QDict
*dict
,
2100 bool from_json
, Error
**errp
)
2102 if (g_str_equal(group
, "object")) {
2103 Visitor
*v
= qobject_input_visitor_new_keyval(QOBJECT(dict
));
2104 object_option_add_visitor(v
);
2106 } else if (g_str_equal(group
, "machine")) {
2108 * Cannot merge string-valued and type-safe dictionaries, so JSON
2109 * is not accepted yet for -M.
2112 keyval_merge(machine_opts_dict
, dict
, errp
);
2113 } else if (g_str_equal(group
, "smp-opts")) {
2114 machine_merge_property("smp", dict
, &error_fatal
);
2115 } else if (g_str_equal(group
, "boot-opts")) {
2116 machine_merge_property("boot", dict
, &error_fatal
);
2117 } else if (g_str_equal(group
, "memory")) {
2118 machine_merge_property("memory", dict
, &error_fatal
);
2125 * Parse non-QemuOpts config file groups, pass the rest to
2126 * qemu_config_do_parse.
2128 static void qemu_parse_config_group(const char *group
, QDict
*qdict
,
2129 void *opaque
, Error
**errp
)
2132 if (is_qemuopts_group(group
)) {
2133 qemu_config_do_parse(group
, qdict
, opaque
, errp
);
2137 crumpled
= qdict_crumple(qdict
, errp
);
2141 switch (qobject_type(crumpled
)) {
2143 qemu_record_config_group(group
, qobject_to(QDict
, crumpled
), false, errp
);
2146 error_setg(errp
, "Lists cannot be at top level of a configuration section");
2149 g_assert_not_reached();
2151 qobject_unref(crumpled
);
2154 static void qemu_read_default_config_file(Error
**errp
)
2158 g_autofree
char *file
= get_relocated_path(CONFIG_QEMU_CONFDIR
"/qemu.conf");
2160 ret
= qemu_read_config_file(file
, qemu_parse_config_group
, errp
);
2162 if (ret
== -ENOENT
) {
2169 static void qemu_set_option(const char *str
, Error
**errp
)
2171 char group
[64], id
[64], arg
[64];
2176 rc
= sscanf(str
, "%63[^.].%63[^.].%63[^=]%n", group
, id
, arg
, &offset
);
2177 if (rc
< 3 || str
[offset
] != '=') {
2178 error_setg(errp
, "can't parse: \"%s\"", str
);
2182 if (!is_qemuopts_group(group
)) {
2183 error_setg(errp
, "-set is not supported with %s", group
);
2185 list
= qemu_find_opts_err(group
, errp
);
2187 opts
= qemu_opts_find(list
, id
);
2189 error_setg(errp
, "there is no %s \"%s\" defined", group
, id
);
2192 qemu_opt_set(opts
, arg
, str
+ offset
+ 1, errp
);
2197 static void user_register_global_props(void)
2199 qemu_opts_foreach(qemu_find_opts("global"),
2200 global_init_func
, NULL
, NULL
);
2203 static int do_configure_icount(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2205 icount_configure(opts
, errp
);
2209 static int accelerator_set_property(void *opaque
,
2210 const char *name
, const char *value
,
2213 return object_parse_property_opt(opaque
, name
, value
, "accel", errp
);
2216 static int do_configure_accelerator(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2218 bool *p_init_failed
= opaque
;
2219 const char *acc
= qemu_opt_get(opts
, "accel");
2220 AccelClass
*ac
= accel_find(acc
);
2223 bool qtest_with_kvm
;
2225 qtest_with_kvm
= g_str_equal(acc
, "kvm") && qtest_chrdev
!= NULL
;
2228 *p_init_failed
= true;
2229 if (!qtest_with_kvm
) {
2230 error_report("invalid accelerator %s", acc
);
2234 accel
= ACCEL(object_new_with_class(OBJECT_CLASS(ac
)));
2235 object_apply_compat_props(OBJECT(accel
));
2236 qemu_opt_foreach(opts
, accelerator_set_property
,
2240 ret
= accel_init_machine(accel
, current_machine
);
2242 *p_init_failed
= true;
2243 if (!qtest_with_kvm
|| ret
!= -ENOENT
) {
2244 error_report("failed to initialize %s: %s", acc
, strerror(-ret
));
2252 static void configure_accelerators(const char *progname
)
2254 bool init_failed
= false;
2256 qemu_opts_foreach(qemu_find_opts("icount"),
2257 do_configure_icount
, NULL
, &error_fatal
);
2259 if (QTAILQ_EMPTY(&qemu_accel_opts
.head
)) {
2260 char **accel_list
, **tmp
;
2262 if (accelerators
== NULL
) {
2263 /* Select the default accelerator */
2264 bool have_tcg
= accel_find("tcg");
2265 bool have_kvm
= accel_find("kvm");
2267 if (have_tcg
&& have_kvm
) {
2268 if (g_str_has_suffix(progname
, "kvm")) {
2269 /* If the program name ends with "kvm", we prefer KVM */
2270 accelerators
= "kvm:tcg";
2272 accelerators
= "tcg:kvm";
2274 } else if (have_kvm
) {
2275 accelerators
= "kvm";
2276 } else if (have_tcg
) {
2277 accelerators
= "tcg";
2279 error_report("No accelerator selected and"
2280 " no default accelerator available");
2284 accel_list
= g_strsplit(accelerators
, ":", 0);
2286 for (tmp
= accel_list
; *tmp
; tmp
++) {
2288 * Filter invalid accelerators here, to prevent obscenities
2289 * such as "-machine accel=tcg,,thread=single".
2291 if (accel_find(*tmp
)) {
2292 qemu_opts_parse_noisily(qemu_find_opts("accel"), *tmp
, true);
2295 error_report("invalid accelerator %s", *tmp
);
2298 g_strfreev(accel_list
);
2300 if (accelerators
!= NULL
) {
2301 error_report("The -accel and \"-machine accel=\" options are incompatible");
2306 if (!qemu_opts_foreach(qemu_find_opts("accel"),
2307 do_configure_accelerator
, &init_failed
, &error_fatal
)) {
2309 error_report("no accelerator found");
2314 if (init_failed
&& !qtest_chrdev
) {
2315 AccelClass
*ac
= ACCEL_GET_CLASS(current_accel());
2316 error_report("falling back to %s", ac
->name
);
2319 if (icount_enabled() && !tcg_enabled()) {
2320 error_report("-icount is not allowed with hardware virtualization");
2325 static void qemu_validate_options(const QDict
*machine_opts
)
2327 const char *kernel_filename
= qdict_get_try_str(machine_opts
, "kernel");
2328 const char *initrd_filename
= qdict_get_try_str(machine_opts
, "initrd");
2329 const char *kernel_cmdline
= qdict_get_try_str(machine_opts
, "append");
2331 if (kernel_filename
== NULL
) {
2332 if (kernel_cmdline
!= NULL
) {
2333 error_report("-append only allowed with -kernel option");
2337 if (initrd_filename
!= NULL
) {
2338 error_report("-initrd only allowed with -kernel option");
2343 if (loadvm
&& preconfig_requested
) {
2344 error_report("'preconfig' and 'loadvm' options are "
2345 "mutually exclusive");
2348 if (incoming
&& preconfig_requested
&& strcmp(incoming
, "defer") != 0) {
2349 error_report("'preconfig' supports '-incoming defer' only");
2353 #ifdef CONFIG_CURSES
2354 if (is_daemonized() && dpy
.type
== DISPLAY_TYPE_CURSES
) {
2355 error_report("curses display cannot be used with -daemonize");
2361 static void qemu_process_sugar_options(void)
2364 QObject
*smp
= qdict_get(machine_opts_dict
, "smp");
2365 if (smp
&& qobject_type(smp
) == QTYPE_QDICT
) {
2366 QObject
*cpus
= qdict_get(qobject_to(QDict
, smp
), "cpus");
2367 if (cpus
&& qobject_type(cpus
) == QTYPE_QSTRING
) {
2368 const char *val
= qstring_get_str(qobject_to(QString
, cpus
));
2369 object_register_sugar_prop("memory-backend", "prealloc-threads",
2373 object_register_sugar_prop("memory-backend", "prealloc", "on", false);
2377 int i
= select_watchdog(watchdog
);
2379 exit (i
== 1 ? 1 : 0);
2383 /* -action processing */
2386 * Process all the -action parameters parsed from cmdline.
2388 static int process_runstate_actions(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2390 Error
*local_err
= NULL
;
2391 QDict
*qdict
= qemu_opts_to_qdict(opts
, NULL
);
2392 QObject
*ret
= NULL
;
2393 qmp_marshal_set_action(qdict
, &ret
, &local_err
);
2395 qobject_unref(qdict
);
2397 error_propagate(errp
, local_err
);
2403 static void qemu_process_early_options(void)
2405 #ifdef CONFIG_SECCOMP
2406 QemuOptsList
*olist
= qemu_find_opts_err("sandbox", NULL
);
2408 qemu_opts_foreach(olist
, parse_sandbox
, NULL
, &error_fatal
);
2412 qemu_opts_foreach(qemu_find_opts("name"),
2413 parse_name
, NULL
, &error_fatal
);
2415 if (qemu_opts_foreach(qemu_find_opts("action"),
2416 process_runstate_actions
, NULL
, &error_fatal
)) {
2421 qemu_opts_foreach(qemu_find_opts("add-fd"),
2422 parse_add_fd
, NULL
, &error_fatal
);
2424 qemu_opts_foreach(qemu_find_opts("add-fd"),
2425 cleanup_add_fd
, NULL
, &error_fatal
);
2428 /* Open the logfile at this point and set the log mask if necessary. */
2432 mask
= qemu_str_to_log_mask(log_mask
);
2434 qemu_print_log_usage(stdout
);
2438 qemu_set_log_filename_flags(log_file
, mask
, &error_fatal
);
2441 qemu_add_default_firmwarepath();
2444 static void qemu_process_help_options(void)
2447 * Check for -cpu help and -device help before we call select_machine(),
2448 * which will return an error if the architecture has no default machine
2449 * type and the user did not specify one, so that the user doesn't need
2450 * to say '-cpu help -machine something'.
2452 if (cpu_option
&& is_help_option(cpu_option
)) {
2453 list_cpus(cpu_option
);
2457 if (qemu_opts_foreach(qemu_find_opts("device"),
2458 device_help_func
, NULL
, NULL
)) {
2462 /* -L help lists the data directories and exits. */
2463 if (list_data_dirs
) {
2464 qemu_list_data_dirs();
2469 static void qemu_maybe_daemonize(const char *pid_file
)
2474 rcu_disable_atfork();
2476 if (pid_file
&& !qemu_write_pidfile(pid_file
, &err
)) {
2477 error_reportf_err(err
, "cannot create PID file: ");
2481 qemu_unlink_pidfile_notifier
.notify
= qemu_unlink_pidfile
;
2482 qemu_add_exit_notifier(&qemu_unlink_pidfile_notifier
);
2485 static void qemu_init_displays(void)
2489 /* init local displays */
2490 ds
= init_displaystate();
2491 qemu_display_init(ds
, &dpy
);
2493 /* must be after terminal init, SDL library changes signal handlers */
2494 os_setup_signal_handling();
2496 /* init remote displays */
2498 qemu_opts_foreach(qemu_find_opts("vnc"),
2499 vnc_init_func
, NULL
, &error_fatal
);
2503 qemu_spice
.display_init();
2507 static void qemu_init_board(void)
2509 /* process plugin before CPUs are created, but once -smp has been parsed */
2510 qemu_plugin_load_list(&plugin_list
, &error_fatal
);
2512 /* From here on we enter MACHINE_PHASE_INITIALIZED. */
2513 machine_run_board_init(current_machine
, mem_path
, &error_fatal
);
2515 drive_check_orphaned();
2519 if (hax_enabled()) {
2520 /* FIXME: why isn't cpu_synchronize_all_post_init enough? */
2525 static void qemu_create_cli_devices(void)
2531 qemu_opts_foreach(qemu_find_opts("fw_cfg"),
2532 parse_fw_cfg
, fw_cfg_find(), &error_fatal
);
2534 /* init USB devices */
2535 if (machine_usb(current_machine
)) {
2536 if (foreach_device_config(DEV_USB
, usb_parse
) < 0)
2540 /* init generic devices */
2541 rom_set_order_override(FW_CFG_ORDER_OVERRIDE_DEVICE
);
2542 qemu_opts_foreach(qemu_find_opts("device"),
2543 device_init_func
, NULL
, &error_fatal
);
2544 QTAILQ_FOREACH(opt
, &device_opts
, next
) {
2546 loc_push_restore(&opt
->loc
);
2548 * TODO Eventually we should call qmp_device_add() here to make sure it
2549 * behaves the same, but QMP still has to accept incorrectly typed
2550 * options until libvirt is fixed and we want to be strict on the CLI
2551 * from the start, so call qdev_device_add_from_qdict() directly for
2554 dev
= qdev_device_add_from_qdict(opt
->opts
, true, &error_fatal
);
2555 object_unref(OBJECT(dev
));
2558 rom_reset_order_override();
2561 static void qemu_machine_creation_done(void)
2563 MachineState
*machine
= MACHINE(qdev_get_machine());
2565 /* Did we create any drives that we failed to create a device for? */
2566 drive_check_orphaned();
2568 /* Don't warn about the default network setup that you get if
2569 * no command line -net or -netdev options are specified. There
2570 * are two cases that we would otherwise complain about:
2571 * (1) board doesn't support a NIC but the implicit "-net nic"
2573 * (2) CONFIG_SLIRP not set, in which case the implicit "-net nic"
2574 * sets up a nic that isn't connected to anything.
2576 if (!default_net
&& (!qtest_enabled() || has_defaults
)) {
2577 net_check_clients();
2580 qdev_prop_check_globals();
2582 qdev_machine_creation_done();
2586 * Verify that Confidential Guest Support has actually been initialized
2588 assert(machine
->cgs
->ready
);
2591 if (foreach_device_config(DEV_GDB
, gdbserver_start
) < 0) {
2594 if (!vga_interface_created
&& !default_vga
&&
2595 vga_interface_type
!= VGA_NONE
) {
2596 warn_report("A -vga option was passed but this machine "
2597 "type does not use that option; "
2598 "No VGA device has been created");
2602 void qmp_x_exit_preconfig(Error
**errp
)
2604 if (phase_check(PHASE_MACHINE_INITIALIZED
)) {
2605 error_setg(errp
, "The command is permitted only before machine initialization");
2610 qemu_create_cli_devices();
2611 cxl_fixed_memory_window_link_targets(errp
);
2612 qemu_machine_creation_done();
2615 load_snapshot(loadvm
, NULL
, false, NULL
, &error_fatal
);
2617 if (replay_mode
!= REPLAY_MODE_NONE
) {
2618 replay_vmstate_init();
2622 Error
*local_err
= NULL
;
2623 if (strcmp(incoming
, "defer") != 0) {
2624 qmp_migrate_incoming(incoming
, &local_err
);
2626 error_reportf_err(local_err
, "-incoming %s: ", incoming
);
2630 } else if (autostart
) {
2635 void qemu_init(int argc
, char **argv
, char **envp
)
2638 QemuOpts
*icount_opts
= NULL
, *accel_opts
= NULL
;
2639 QemuOptsList
*olist
;
2642 MachineClass
*machine_class
;
2643 bool userconfig
= true;
2644 FILE *vmstate_dump_file
= NULL
;
2646 qemu_add_opts(&qemu_drive_opts
);
2647 qemu_add_drive_opts(&qemu_legacy_drive_opts
);
2648 qemu_add_drive_opts(&qemu_common_drive_opts
);
2649 qemu_add_drive_opts(&qemu_drive_opts
);
2650 qemu_add_drive_opts(&bdrv_runtime_opts
);
2651 qemu_add_opts(&qemu_chardev_opts
);
2652 qemu_add_opts(&qemu_device_opts
);
2653 qemu_add_opts(&qemu_netdev_opts
);
2654 qemu_add_opts(&qemu_nic_opts
);
2655 qemu_add_opts(&qemu_net_opts
);
2656 qemu_add_opts(&qemu_rtc_opts
);
2657 qemu_add_opts(&qemu_global_opts
);
2658 qemu_add_opts(&qemu_mon_opts
);
2659 qemu_add_opts(&qemu_trace_opts
);
2660 qemu_plugin_add_opts();
2661 qemu_add_opts(&qemu_option_rom_opts
);
2662 qemu_add_opts(&qemu_accel_opts
);
2663 qemu_add_opts(&qemu_mem_opts
);
2664 qemu_add_opts(&qemu_smp_opts
);
2665 qemu_add_opts(&qemu_boot_opts
);
2666 qemu_add_opts(&qemu_add_fd_opts
);
2667 qemu_add_opts(&qemu_object_opts
);
2668 qemu_add_opts(&qemu_tpmdev_opts
);
2669 qemu_add_opts(&qemu_overcommit_opts
);
2670 qemu_add_opts(&qemu_msg_opts
);
2671 qemu_add_opts(&qemu_name_opts
);
2672 qemu_add_opts(&qemu_numa_opts
);
2673 qemu_add_opts(&qemu_icount_opts
);
2674 qemu_add_opts(&qemu_semihosting_config_opts
);
2675 qemu_add_opts(&qemu_fw_cfg_opts
);
2676 qemu_add_opts(&qemu_action_opts
);
2677 module_call_init(MODULE_INIT_OPTS
);
2679 error_init(argv
[0]);
2680 qemu_init_exec_dir(argv
[0]);
2682 qemu_init_arch_modules();
2684 qemu_init_subsystems();
2686 /* first pass of option parsing */
2688 while (optind
< argc
) {
2689 if (argv
[optind
][0] != '-') {
2693 const QEMUOption
*popt
;
2695 popt
= lookup_opt(argc
, argv
, &optarg
, &optind
);
2696 switch (popt
->index
) {
2697 case QEMU_OPTION_nouserconfig
:
2704 machine_opts_dict
= qdict_new();
2706 qemu_read_default_config_file(&error_fatal
);
2709 /* second pass of option parsing */
2714 if (argv
[optind
][0] != '-') {
2715 loc_set_cmdline(argv
, optind
, 1);
2716 drive_add(IF_DEFAULT
, 0, argv
[optind
++], HD_OPTS
);
2718 const QEMUOption
*popt
;
2720 popt
= lookup_opt(argc
, argv
, &optarg
, &optind
);
2721 if (!(popt
->arch_mask
& arch_type
)) {
2722 error_report("Option not supported for this target");
2725 switch(popt
->index
) {
2726 case QEMU_OPTION_cpu
:
2727 /* hw initialization will check this */
2728 cpu_option
= optarg
;
2730 case QEMU_OPTION_hda
:
2731 case QEMU_OPTION_hdb
:
2732 case QEMU_OPTION_hdc
:
2733 case QEMU_OPTION_hdd
:
2734 drive_add(IF_DEFAULT
, popt
->index
- QEMU_OPTION_hda
, optarg
,
2737 case QEMU_OPTION_blockdev
:
2740 BlockdevOptionsQueueEntry
*bdo
;
2742 v
= qobject_input_visitor_new_str(optarg
, "driver",
2745 bdo
= g_new(BlockdevOptionsQueueEntry
, 1);
2746 visit_type_BlockdevOptions(v
, NULL
, &bdo
->bdo
,
2749 loc_save(&bdo
->loc
);
2750 QSIMPLEQ_INSERT_TAIL(&bdo_queue
, bdo
, entry
);
2753 case QEMU_OPTION_drive
:
2754 opts
= qemu_opts_parse_noisily(qemu_find_opts("drive"),
2760 case QEMU_OPTION_set
:
2761 qemu_set_option(optarg
, &error_fatal
);
2763 case QEMU_OPTION_global
:
2764 if (qemu_global_option(optarg
) != 0)
2767 case QEMU_OPTION_mtdblock
:
2768 drive_add(IF_MTD
, -1, optarg
, MTD_OPTS
);
2770 case QEMU_OPTION_sd
:
2771 drive_add(IF_SD
, -1, optarg
, SD_OPTS
);
2773 case QEMU_OPTION_pflash
:
2774 drive_add(IF_PFLASH
, -1, optarg
, PFLASH_OPTS
);
2776 case QEMU_OPTION_snapshot
:
2778 Error
*blocker
= NULL
;
2780 error_setg(&blocker
, QERR_REPLAY_NOT_SUPPORTED
,
2782 replay_add_blocker(blocker
);
2785 case QEMU_OPTION_numa
:
2786 opts
= qemu_opts_parse_noisily(qemu_find_opts("numa"),
2792 case QEMU_OPTION_cxl_fixed_memory_window
:
2793 parse_cxl_fixed_memory_window(optarg
);
2795 case QEMU_OPTION_display
:
2796 parse_display(optarg
);
2798 case QEMU_OPTION_nographic
:
2799 qdict_put_str(machine_opts_dict
, "graphics", "off");
2801 dpy
.type
= DISPLAY_TYPE_NONE
;
2803 case QEMU_OPTION_portrait
:
2804 graphic_rotate
= 90;
2806 case QEMU_OPTION_rotate
:
2807 graphic_rotate
= strtol(optarg
, (char **) &optarg
, 10);
2808 if (graphic_rotate
!= 0 && graphic_rotate
!= 90 &&
2809 graphic_rotate
!= 180 && graphic_rotate
!= 270) {
2810 error_report("only 90, 180, 270 deg rotation is available");
2814 case QEMU_OPTION_kernel
:
2815 qdict_put_str(machine_opts_dict
, "kernel", optarg
);
2817 case QEMU_OPTION_initrd
:
2818 qdict_put_str(machine_opts_dict
, "initrd", optarg
);
2820 case QEMU_OPTION_append
:
2821 qdict_put_str(machine_opts_dict
, "append", optarg
);
2823 case QEMU_OPTION_dtb
:
2824 qdict_put_str(machine_opts_dict
, "dtb", optarg
);
2826 case QEMU_OPTION_cdrom
:
2827 drive_add(IF_DEFAULT
, 2, optarg
, CDROM_OPTS
);
2829 case QEMU_OPTION_boot
:
2830 machine_parse_property_opt(qemu_find_opts("boot-opts"), "boot", optarg
);
2832 case QEMU_OPTION_fda
:
2833 case QEMU_OPTION_fdb
:
2834 drive_add(IF_FLOPPY
, popt
->index
- QEMU_OPTION_fda
,
2837 case QEMU_OPTION_no_fd_bootchk
:
2840 case QEMU_OPTION_netdev
:
2842 if (net_client_parse(qemu_find_opts("netdev"), optarg
) == -1) {
2846 case QEMU_OPTION_nic
:
2848 if (net_client_parse(qemu_find_opts("nic"), optarg
) == -1) {
2852 case QEMU_OPTION_net
:
2854 if (net_client_parse(qemu_find_opts("net"), optarg
) == -1) {
2858 #ifdef CONFIG_LIBISCSI
2859 case QEMU_OPTION_iscsi
:
2860 opts
= qemu_opts_parse_noisily(qemu_find_opts("iscsi"),
2867 case QEMU_OPTION_audio_help
:
2868 audio_legacy_help();
2871 case QEMU_OPTION_audiodev
:
2872 audio_parse_option(optarg
);
2874 case QEMU_OPTION_audio
: {
2875 QDict
*dict
= keyval_parse(optarg
, "driver", NULL
, &error_fatal
);
2877 Audiodev
*dev
= NULL
;
2880 if (!qdict_haskey(dict
, "id")) {
2881 qdict_put_str(dict
, "id", "audiodev0");
2883 if (!qdict_haskey(dict
, "model")) {
2884 error_setg(&error_fatal
, "Parameter 'model' is missing");
2886 model
= g_strdup(qdict_get_str(dict
, "model"));
2887 qdict_del(dict
, "model");
2888 if (is_help_option(model
)) {
2889 show_valid_soundhw();
2892 v
= qobject_input_visitor_new_keyval(QOBJECT(dict
));
2893 qobject_unref(dict
);
2894 visit_type_Audiodev(v
, NULL
, &dev
, &error_fatal
);
2897 select_soundhw(model
, dev
->id
);
2904 case QEMU_OPTION_version
:
2909 parse_memory_options(optarg
);
2912 case QEMU_OPTION_tpmdev
:
2913 if (tpm_config_parse(qemu_find_opts("tpmdev"), optarg
) < 0) {
2918 case QEMU_OPTION_mempath
:
2921 case QEMU_OPTION_mem_prealloc
:
2930 case QEMU_OPTION_DFILTER
:
2931 qemu_set_dfilter_ranges(optarg
, &error_fatal
);
2933 case QEMU_OPTION_seed
:
2934 qemu_guest_random_seed_main(optarg
, &error_fatal
);
2937 add_device_config(DEV_GDB
, "tcp::" DEFAULT_GDBSTUB_PORT
);
2939 case QEMU_OPTION_gdb
:
2940 add_device_config(DEV_GDB
, optarg
);
2943 if (is_help_option(optarg
)) {
2944 list_data_dirs
= true;
2946 qemu_add_data_dir(g_strdup(optarg
));
2949 case QEMU_OPTION_bios
:
2950 qdict_put_str(machine_opts_dict
, "firmware", optarg
);
2952 case QEMU_OPTION_singlestep
:
2959 keyboard_layout
= optarg
;
2961 case QEMU_OPTION_vga
:
2970 w
= strtol(p
, (char **)&p
, 10);
2973 error_report("invalid resolution or depth");
2979 h
= strtol(p
, (char **)&p
, 10);
2984 depth
= strtol(p
, (char **)&p
, 10);
2985 if (depth
!= 1 && depth
!= 2 && depth
!= 4 &&
2986 depth
!= 8 && depth
!= 15 && depth
!= 16 &&
2987 depth
!= 24 && depth
!= 32)
2989 } else if (*p
== '\0') {
2990 depth
= graphic_depth
;
2997 graphic_depth
= depth
;
3000 case QEMU_OPTION_echr
:
3003 term_escape_char
= strtol(optarg
, &r
, 0);
3005 printf("Bad argument to echr\n");
3008 case QEMU_OPTION_monitor
:
3009 default_monitor
= 0;
3010 if (strncmp(optarg
, "none", 4)) {
3011 monitor_parse(optarg
, "readline", false);
3014 case QEMU_OPTION_qmp
:
3015 monitor_parse(optarg
, "control", false);
3016 default_monitor
= 0;
3018 case QEMU_OPTION_qmp_pretty
:
3019 monitor_parse(optarg
, "control", true);
3020 default_monitor
= 0;
3022 case QEMU_OPTION_mon
:
3023 opts
= qemu_opts_parse_noisily(qemu_find_opts("mon"), optarg
,
3028 default_monitor
= 0;
3030 case QEMU_OPTION_chardev
:
3031 opts
= qemu_opts_parse_noisily(qemu_find_opts("chardev"),
3037 case QEMU_OPTION_fsdev
:
3038 olist
= qemu_find_opts("fsdev");
3040 error_report("fsdev support is disabled");
3043 opts
= qemu_opts_parse_noisily(olist
, optarg
, true);
3048 case QEMU_OPTION_virtfs
: {
3051 const char *writeout
, *sock_fd
, *socket
, *path
, *security_model
,
3054 olist
= qemu_find_opts("virtfs");
3056 error_report("virtfs support is disabled");
3059 opts
= qemu_opts_parse_noisily(olist
, optarg
, true);
3064 if (qemu_opt_get(opts
, "fsdriver") == NULL
||
3065 qemu_opt_get(opts
, "mount_tag") == NULL
) {
3066 error_report("Usage: -virtfs fsdriver,mount_tag=tag");
3069 fsdev
= qemu_opts_create(qemu_find_opts("fsdev"),
3070 qemu_opts_id(opts
) ?:
3071 qemu_opt_get(opts
, "mount_tag"),
3074 error_report("duplicate or invalid fsdev id: %s",
3075 qemu_opt_get(opts
, "mount_tag"));
3079 writeout
= qemu_opt_get(opts
, "writeout");
3081 #ifdef CONFIG_SYNC_FILE_RANGE
3082 qemu_opt_set(fsdev
, "writeout", writeout
, &error_abort
);
3084 error_report("writeout=immediate not supported "
3085 "on this platform");
3089 qemu_opt_set(fsdev
, "fsdriver",
3090 qemu_opt_get(opts
, "fsdriver"), &error_abort
);
3091 path
= qemu_opt_get(opts
, "path");
3093 qemu_opt_set(fsdev
, "path", path
, &error_abort
);
3095 security_model
= qemu_opt_get(opts
, "security_model");
3096 if (security_model
) {
3097 qemu_opt_set(fsdev
, "security_model", security_model
,
3100 socket
= qemu_opt_get(opts
, "socket");
3102 qemu_opt_set(fsdev
, "socket", socket
, &error_abort
);
3104 sock_fd
= qemu_opt_get(opts
, "sock_fd");
3106 qemu_opt_set(fsdev
, "sock_fd", sock_fd
, &error_abort
);
3109 qemu_opt_set_bool(fsdev
, "readonly",
3110 qemu_opt_get_bool(opts
, "readonly", 0),
3112 multidevs
= qemu_opt_get(opts
, "multidevs");
3114 qemu_opt_set(fsdev
, "multidevs", multidevs
, &error_abort
);
3116 device
= qemu_opts_create(qemu_find_opts("device"), NULL
, 0,
3118 qemu_opt_set(device
, "driver", "virtio-9p-pci", &error_abort
);
3119 qemu_opt_set(device
, "fsdev",
3120 qemu_opts_id(fsdev
), &error_abort
);
3121 qemu_opt_set(device
, "mount_tag",
3122 qemu_opt_get(opts
, "mount_tag"), &error_abort
);
3125 case QEMU_OPTION_serial
:
3126 add_device_config(DEV_SERIAL
, optarg
);
3128 if (strncmp(optarg
, "mon:", 4) == 0) {
3129 default_monitor
= 0;
3132 case QEMU_OPTION_watchdog
:
3134 error_report("only one watchdog option may be given");
3137 warn_report("-watchdog is deprecated; use -device instead.");
3140 case QEMU_OPTION_action
:
3141 olist
= qemu_find_opts("action");
3142 if (!qemu_opts_parse_noisily(olist
, optarg
, false)) {
3146 case QEMU_OPTION_watchdog_action
: {
3148 opts
= qemu_opts_create(qemu_find_opts("action"), NULL
, 0, &error_abort
);
3149 qemu_opt_set(opts
, "watchdog", optarg
, &error_abort
);
3152 case QEMU_OPTION_parallel
:
3153 add_device_config(DEV_PARALLEL
, optarg
);
3154 default_parallel
= 0;
3155 if (strncmp(optarg
, "mon:", 4) == 0) {
3156 default_monitor
= 0;
3159 case QEMU_OPTION_debugcon
:
3160 add_device_config(DEV_DEBUGCON
, optarg
);
3162 case QEMU_OPTION_loadvm
:
3165 case QEMU_OPTION_full_screen
:
3166 dpy
.has_full_screen
= true;
3167 dpy
.full_screen
= true;
3169 case QEMU_OPTION_pidfile
:
3172 case QEMU_OPTION_win2k_hack
:
3173 win2k_install_hack
= 1;
3175 case QEMU_OPTION_acpitable
:
3176 opts
= qemu_opts_parse_noisily(qemu_find_opts("acpi"),
3181 acpi_table_add(opts
, &error_fatal
);
3183 case QEMU_OPTION_smbios
:
3184 opts
= qemu_opts_parse_noisily(qemu_find_opts("smbios"),
3189 smbios_entry_add(opts
, &error_fatal
);
3191 case QEMU_OPTION_fwcfg
:
3192 opts
= qemu_opts_parse_noisily(qemu_find_opts("fw_cfg"),
3198 case QEMU_OPTION_preconfig
:
3199 preconfig_requested
= true;
3201 case QEMU_OPTION_enable_kvm
:
3202 qdict_put_str(machine_opts_dict
, "accel", "kvm");
3205 case QEMU_OPTION_machine
:
3209 keyval_parse_into(machine_opts_dict
, optarg
, "type", &help
, &error_fatal
);
3211 machine_help_func(machine_opts_dict
);
3216 case QEMU_OPTION_accel
:
3217 accel_opts
= qemu_opts_parse_noisily(qemu_find_opts("accel"),
3219 optarg
= qemu_opt_get(accel_opts
, "accel");
3220 if (!optarg
|| is_help_option(optarg
)) {
3221 printf("Accelerators supported in QEMU binary:\n");
3222 GSList
*el
, *accel_list
= object_class_get_list(TYPE_ACCEL
,
3224 for (el
= accel_list
; el
; el
= el
->next
) {
3225 gchar
*typename
= g_strdup(object_class_get_name(
3226 OBJECT_CLASS(el
->data
)));
3227 /* omit qtest which is used for tests only */
3228 if (g_strcmp0(typename
, ACCEL_CLASS_NAME("qtest")) &&
3229 g_str_has_suffix(typename
, ACCEL_CLASS_SUFFIX
)) {
3230 gchar
**optname
= g_strsplit(typename
,
3231 ACCEL_CLASS_SUFFIX
, 0);
3232 printf("%s\n", optname
[0]);
3233 g_strfreev(optname
);
3237 g_slist_free(accel_list
);
3241 case QEMU_OPTION_usb
:
3242 qdict_put_str(machine_opts_dict
, "usb", "on");
3244 case QEMU_OPTION_usbdevice
:
3245 qdict_put_str(machine_opts_dict
, "usb", "on");
3246 add_device_config(DEV_USB
, optarg
);
3248 case QEMU_OPTION_device
:
3249 if (optarg
[0] == '{') {
3250 QObject
*obj
= qobject_from_json(optarg
, &error_fatal
);
3251 DeviceOption
*opt
= g_new0(DeviceOption
, 1);
3252 opt
->opts
= qobject_to(QDict
, obj
);
3253 loc_save(&opt
->loc
);
3254 assert(opt
->opts
!= NULL
);
3255 QTAILQ_INSERT_TAIL(&device_opts
, opt
, next
);
3257 if (!qemu_opts_parse_noisily(qemu_find_opts("device"),
3263 case QEMU_OPTION_smp
:
3264 machine_parse_property_opt(qemu_find_opts("smp-opts"),
3267 case QEMU_OPTION_vnc
:
3270 case QEMU_OPTION_no_acpi
:
3271 qdict_put_str(machine_opts_dict
, "acpi", "off");
3273 case QEMU_OPTION_no_hpet
:
3274 qdict_put_str(machine_opts_dict
, "hpet", "off");
3276 case QEMU_OPTION_no_reboot
:
3277 olist
= qemu_find_opts("action");
3278 qemu_opts_parse_noisily(olist
, "reboot=shutdown", false);
3280 case QEMU_OPTION_no_shutdown
:
3281 olist
= qemu_find_opts("action");
3282 qemu_opts_parse_noisily(olist
, "shutdown=pause", false);
3284 case QEMU_OPTION_uuid
:
3285 if (qemu_uuid_parse(optarg
, &qemu_uuid
) < 0) {
3286 error_report("failed to parse UUID string: wrong format");
3289 qemu_uuid_set
= true;
3291 case QEMU_OPTION_option_rom
:
3292 if (nb_option_roms
>= MAX_OPTION_ROMS
) {
3293 error_report("too many option ROMs");
3296 opts
= qemu_opts_parse_noisily(qemu_find_opts("option-rom"),
3301 option_rom
[nb_option_roms
].name
= qemu_opt_get(opts
, "romfile");
3302 option_rom
[nb_option_roms
].bootindex
=
3303 qemu_opt_get_number(opts
, "bootindex", -1);
3304 if (!option_rom
[nb_option_roms
].name
) {
3305 error_report("Option ROM file is not specified");
3310 case QEMU_OPTION_semihosting
:
3311 qemu_semihosting_enable();
3313 case QEMU_OPTION_semihosting_config
:
3314 if (qemu_semihosting_config_options(optarg
) != 0) {
3318 case QEMU_OPTION_name
:
3319 opts
= qemu_opts_parse_noisily(qemu_find_opts("name"),
3324 /* Capture guest name if -msg guest-name is used later */
3325 error_guest_name
= qemu_opt_get(opts
, "guest");
3327 case QEMU_OPTION_prom_env
:
3328 if (nb_prom_envs
>= MAX_PROM_ENVS
) {
3329 error_report("too many prom variables");
3332 prom_envs
[nb_prom_envs
] = optarg
;
3335 case QEMU_OPTION_old_param
:
3338 case QEMU_OPTION_rtc
:
3339 opts
= qemu_opts_parse_noisily(qemu_find_opts("rtc"), optarg
,
3345 case QEMU_OPTION_icount
:
3346 icount_opts
= qemu_opts_parse_noisily(qemu_find_opts("icount"),
3352 case QEMU_OPTION_incoming
:
3354 runstate_set(RUN_STATE_INMIGRATE
);
3358 case QEMU_OPTION_only_migratable
:
3359 only_migratable
= 1;
3361 case QEMU_OPTION_nodefaults
:
3364 case QEMU_OPTION_xen_domid
:
3365 if (!(accel_find("xen"))) {
3366 error_report("Option not supported for this target");
3369 xen_domid
= atoi(optarg
);
3371 case QEMU_OPTION_xen_attach
:
3372 if (!(accel_find("xen"))) {
3373 error_report("Option not supported for this target");
3376 xen_mode
= XEN_ATTACH
;
3378 case QEMU_OPTION_xen_domid_restrict
:
3379 if (!(accel_find("xen"))) {
3380 error_report("Option not supported for this target");
3383 xen_domid_restrict
= true;
3385 case QEMU_OPTION_trace
:
3386 trace_opt_parse(optarg
);
3388 case QEMU_OPTION_plugin
:
3389 qemu_plugin_opt_parse(optarg
, &plugin_list
);
3391 case QEMU_OPTION_readconfig
:
3392 qemu_read_config_file(optarg
, qemu_parse_config_group
, &error_fatal
);
3395 case QEMU_OPTION_spice
:
3396 olist
= qemu_find_opts_err("spice", NULL
);
3398 error_report("spice support is disabled");
3401 opts
= qemu_opts_parse_noisily(olist
, optarg
, false);
3408 case QEMU_OPTION_qtest
:
3409 qtest_chrdev
= optarg
;
3411 case QEMU_OPTION_qtest_log
:
3414 case QEMU_OPTION_sandbox
:
3415 olist
= qemu_find_opts("sandbox");
3417 #ifndef CONFIG_SECCOMP
3418 error_report("-sandbox support is not enabled "
3419 "in this QEMU binary");
3424 opts
= qemu_opts_parse_noisily(olist
, optarg
, true);
3429 case QEMU_OPTION_add_fd
:
3431 opts
= qemu_opts_parse_noisily(qemu_find_opts("add-fd"),
3437 error_report("File descriptor passing is disabled on this "
3442 case QEMU_OPTION_object
:
3443 object_option_parse(optarg
);
3445 case QEMU_OPTION_overcommit
:
3446 opts
= qemu_opts_parse_noisily(qemu_find_opts("overcommit"),
3451 enable_mlock
= qemu_opt_get_bool(opts
, "mem-lock", false);
3452 enable_cpu_pm
= qemu_opt_get_bool(opts
, "cpu-pm", false);
3454 case QEMU_OPTION_compat
:
3459 v
= qobject_input_visitor_new_str(optarg
, NULL
,
3462 visit_type_CompatPolicy(v
, NULL
, &opts
, &error_fatal
);
3463 QAPI_CLONE_MEMBERS(CompatPolicy
, &compat_policy
, opts
);
3465 qapi_free_CompatPolicy(opts
);
3469 case QEMU_OPTION_msg
:
3470 opts
= qemu_opts_parse_noisily(qemu_find_opts("msg"), optarg
,
3475 configure_msg(opts
);
3477 case QEMU_OPTION_dump_vmstate
:
3478 if (vmstate_dump_file
) {
3479 error_report("only one '-dump-vmstate' "
3480 "option may be given");
3483 vmstate_dump_file
= fopen(optarg
, "w");
3484 if (vmstate_dump_file
== NULL
) {
3485 error_report("open %s: %s", optarg
, strerror(errno
));
3489 case QEMU_OPTION_enable_sync_profile
:
3492 case QEMU_OPTION_nouserconfig
:
3493 /* Nothing to be parsed here. Especially, do not error out below. */
3496 if (os_parse_cmd_args(popt
->index
, optarg
)) {
3497 error_report("Option not supported in this build");
3504 * Clear error location left behind by the loop.
3505 * Best done right after the loop. Do not insert code here!
3509 qemu_validate_options(machine_opts_dict
);
3510 qemu_process_sugar_options();
3513 * These options affect everything else and should be processed
3514 * before daemonizing.
3516 qemu_process_early_options();
3518 qemu_process_help_options();
3519 qemu_maybe_daemonize(pid_file
);
3522 * The trace backend must be initialized after daemonizing.
3523 * trace_init_backends() will call st_init(), which will create the
3524 * trace thread in the parent, and also register st_flush_trace_buffer()
3525 * in atexit(). This function will force the parent to wait for the
3526 * writeout thread to finish, which will not occur, and the parent
3527 * process will be left in the host.
3529 if (!trace_init_backends()) {
3534 qemu_init_main_loop(&error_fatal
);
3537 user_register_global_props();
3538 replay_configure(icount_opts
);
3540 configure_rtc(qemu_find_opts_singleton("rtc"));
3542 qemu_create_machine(machine_opts_dict
);
3546 qemu_disable_default_devices();
3547 qemu_create_default_devices();
3548 qemu_create_early_backends();
3550 qemu_apply_legacy_machine_options(machine_opts_dict
);
3551 qemu_apply_machine_options(machine_opts_dict
);
3552 qobject_unref(machine_opts_dict
);
3553 phase_advance(PHASE_MACHINE_CREATED
);
3556 * Note: uses machine properties such as kernel-irqchip, must run
3557 * after qemu_apply_machine_options.
3559 configure_accelerators(argv
[0]);
3560 phase_advance(PHASE_ACCEL_CREATED
);
3563 * Beware, QOM objects created before this point miss global and
3564 * compat properties.
3566 * Global properties get set up by qdev_prop_register_global(),
3567 * called from user_register_global_props(), and certain option
3568 * desugaring. Also in CPU feature desugaring (buried in
3569 * parse_cpu_option()), which happens below this point, but may
3570 * only target the CPU type, which can only be created after
3571 * parse_cpu_option() returned the type.
3573 * Machine compat properties: object_set_machine_compat_props().
3574 * Accelerator compat props: object_set_accelerator_compat_props(),
3575 * called from do_configure_accelerator().
3578 machine_class
= MACHINE_GET_CLASS(current_machine
);
3579 if (!qtest_enabled() && machine_class
->deprecation_reason
) {
3580 warn_report("Machine type '%s' is deprecated: %s",
3581 machine_class
->name
, machine_class
->deprecation_reason
);
3585 * Note: creates a QOM object, must run only after global and
3586 * compat properties have been set up.
3588 migration_object_init();
3590 qemu_create_late_backends();
3592 /* parse features once if machine provides default cpu_type */
3593 current_machine
->cpu_type
= machine_class
->default_cpu_type
;
3595 current_machine
->cpu_type
= parse_cpu_option(cpu_option
);
3597 /* NB: for machine none cpu_type could STILL be NULL here! */
3599 qemu_resolve_machine_memdev();
3600 parse_numa_opts(current_machine
);
3603 if (vmstate_dump_file
) {
3605 module_load_qom_all();
3606 dump_vmstate_json_to_file(vmstate_dump_file
);
3610 if (!preconfig_requested
) {
3611 qmp_x_exit_preconfig(&error_fatal
);
3613 qemu_init_displays();
3614 accel_setup_post(current_machine
);