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 "hw/firmware/smbios.h"
57 #include "hw/acpi/acpi.h"
58 #include "hw/xen/xen.h"
59 #include "hw/loader.h"
60 #include "monitor/qdev.h"
62 #include "net/slirp.h"
63 #include "monitor/monitor.h"
64 #include "ui/console.h"
66 #include "sysemu/sysemu.h"
67 #include "sysemu/numa.h"
68 #include "sysemu/hostmem.h"
69 #include "exec/gdbstub.h"
70 #include "qemu/timer.h"
71 #include "chardev/char.h"
72 #include "qemu/bitmap.h"
74 #include "sysemu/blockdev.h"
75 #include "hw/block/block.h"
76 #include "hw/i386/x86.h"
77 #include "hw/i386/pc.h"
78 #include "migration/misc.h"
79 #include "migration/snapshot.h"
80 #include "sysemu/tpm.h"
81 #include "sysemu/dma.h"
82 #include "hw/audio/soundhw.h"
83 #include "audio/audio.h"
84 #include "sysemu/cpus.h"
85 #include "sysemu/cpu-timers.h"
86 #include "migration/colo.h"
87 #include "migration/postcopy-ram.h"
88 #include "sysemu/kvm.h"
89 #include "sysemu/hax.h"
90 #include "qapi/qobject-input-visitor.h"
91 #include "qemu/option.h"
92 #include "qemu/config-file.h"
93 #include "qemu/qemu-options.h"
94 #include "qemu/main-loop.h"
96 #include "fsdev/qemu-fsdev.h"
98 #include "sysemu/qtest.h"
100 #include "accel/tcg/perf.h"
103 #include "disas/disas.h"
106 #include "trace/control.h"
107 #include "qemu/plugin.h"
108 #include "qemu/queue.h"
109 #include "sysemu/arch_init.h"
110 #include "exec/confidential-guest-support.h"
112 #include "ui/qemu-spice.h"
113 #include "qapi/string-input-visitor.h"
114 #include "qapi/opts-visitor.h"
115 #include "qapi/clone-visitor.h"
116 #include "qom/object_interfaces.h"
117 #include "semihosting/semihost.h"
118 #include "crypto/init.h"
119 #include "sysemu/replay.h"
120 #include "qapi/qapi-events-run-state.h"
121 #include "qapi/qapi-types-audio.h"
122 #include "qapi/qapi-visit-audio.h"
123 #include "qapi/qapi-visit-block-core.h"
124 #include "qapi/qapi-visit-compat.h"
125 #include "qapi/qapi-visit-machine.h"
126 #include "qapi/qapi-visit-ui.h"
127 #include "qapi/qapi-commands-block-core.h"
128 #include "qapi/qapi-commands-migration.h"
129 #include "qapi/qapi-commands-misc.h"
130 #include "qapi/qapi-visit-qom.h"
131 #include "qapi/qapi-commands-ui.h"
132 #include "qapi/qmp/qdict.h"
133 #include "block/qdict.h"
134 #include "qapi/qmp/qerror.h"
135 #include "sysemu/iothread.h"
136 #include "qemu/guest-random.h"
137 #include "qemu/keyval.h"
139 #include "config-host.h"
141 #define MAX_VIRTIO_CONSOLES 1
143 typedef struct BlockdevOptionsQueueEntry
{
144 BlockdevOptions
*bdo
;
146 QSIMPLEQ_ENTRY(BlockdevOptionsQueueEntry
) entry
;
147 } BlockdevOptionsQueueEntry
;
149 typedef QSIMPLEQ_HEAD(, BlockdevOptionsQueueEntry
) BlockdevOptionsQueue
;
151 typedef struct ObjectOption
{
153 QTAILQ_ENTRY(ObjectOption
) next
;
156 typedef struct DeviceOption
{
159 QTAILQ_ENTRY(DeviceOption
) next
;
162 static const char *cpu_option
;
163 static const char *mem_path
;
164 static const char *incoming
;
165 static const char *loadvm
;
166 static const char *accelerators
;
167 static bool have_custom_ram_size
;
168 static const char *ram_memdev_id
;
169 static QDict
*machine_opts_dict
;
170 static QTAILQ_HEAD(, ObjectOption
) object_opts
= QTAILQ_HEAD_INITIALIZER(object_opts
);
171 static QTAILQ_HEAD(, DeviceOption
) device_opts
= QTAILQ_HEAD_INITIALIZER(device_opts
);
172 static int display_remote
;
174 static bool preconfig_requested
;
175 static QemuPluginList plugin_list
= QTAILQ_HEAD_INITIALIZER(plugin_list
);
176 static BlockdevOptionsQueue bdo_queue
= QSIMPLEQ_HEAD_INITIALIZER(bdo_queue
);
177 static bool nographic
= false;
178 static int mem_prealloc
; /* force preallocation of physical target memory */
179 static const char *vga_model
= NULL
;
180 static DisplayOptions dpy
;
181 static int num_serial_hds
;
182 static Chardev
**serial_hds
;
183 static const char *log_mask
;
184 static const char *log_file
;
185 static bool list_data_dirs
;
186 static const char *qtest_chrdev
;
187 static const char *qtest_log
;
189 static int has_defaults
= 1;
190 static int default_serial
= 1;
191 static int default_parallel
= 1;
192 static int default_monitor
= 1;
193 static int default_floppy
= 1;
194 static int default_cdrom
= 1;
195 static int default_sdcard
= 1;
196 static int default_vga
= 1;
197 static int default_net
= 1;
203 { .driver
= "isa-serial", .flag
= &default_serial
},
204 { .driver
= "isa-parallel", .flag
= &default_parallel
},
205 { .driver
= "isa-fdc", .flag
= &default_floppy
},
206 { .driver
= "floppy", .flag
= &default_floppy
},
207 { .driver
= "ide-cd", .flag
= &default_cdrom
},
208 { .driver
= "ide-hd", .flag
= &default_cdrom
},
209 { .driver
= "scsi-cd", .flag
= &default_cdrom
},
210 { .driver
= "scsi-hd", .flag
= &default_cdrom
},
211 { .driver
= "VGA", .flag
= &default_vga
},
212 { .driver
= "isa-vga", .flag
= &default_vga
},
213 { .driver
= "cirrus-vga", .flag
= &default_vga
},
214 { .driver
= "isa-cirrus-vga", .flag
= &default_vga
},
215 { .driver
= "vmware-svga", .flag
= &default_vga
},
216 { .driver
= "qxl-vga", .flag
= &default_vga
},
217 { .driver
= "virtio-vga", .flag
= &default_vga
},
218 { .driver
= "ati-vga", .flag
= &default_vga
},
219 { .driver
= "vhost-user-vga", .flag
= &default_vga
},
220 { .driver
= "virtio-vga-gl", .flag
= &default_vga
},
223 static QemuOptsList qemu_rtc_opts
= {
225 .head
= QTAILQ_HEAD_INITIALIZER(qemu_rtc_opts
.head
),
230 .type
= QEMU_OPT_STRING
,
233 .type
= QEMU_OPT_STRING
,
236 .type
= QEMU_OPT_STRING
,
238 { /* end of list */ }
242 static QemuOptsList qemu_option_rom_opts
= {
243 .name
= "option-rom",
244 .implied_opt_name
= "romfile",
245 .head
= QTAILQ_HEAD_INITIALIZER(qemu_option_rom_opts
.head
),
249 .type
= QEMU_OPT_NUMBER
,
252 .type
= QEMU_OPT_STRING
,
254 { /* end of list */ }
258 static QemuOptsList qemu_accel_opts
= {
260 .implied_opt_name
= "accel",
261 .head
= QTAILQ_HEAD_INITIALIZER(qemu_accel_opts
.head
),
264 * no elements => accept any
265 * sanity checking will happen later
266 * when setting accelerator properties
272 static QemuOptsList qemu_boot_opts
= {
274 .implied_opt_name
= "order",
276 .head
= QTAILQ_HEAD_INITIALIZER(qemu_boot_opts
.head
),
280 .type
= QEMU_OPT_STRING
,
283 .type
= QEMU_OPT_STRING
,
286 .type
= QEMU_OPT_BOOL
,
289 .type
= QEMU_OPT_STRING
,
291 .name
= "splash-time",
292 .type
= QEMU_OPT_NUMBER
,
294 .name
= "reboot-timeout",
295 .type
= QEMU_OPT_NUMBER
,
298 .type
= QEMU_OPT_BOOL
,
304 static QemuOptsList qemu_add_fd_opts
= {
306 .head
= QTAILQ_HEAD_INITIALIZER(qemu_add_fd_opts
.head
),
310 .type
= QEMU_OPT_NUMBER
,
311 .help
= "file descriptor of which a duplicate is added to fd set",
314 .type
= QEMU_OPT_NUMBER
,
315 .help
= "ID of the fd set to add fd to",
318 .type
= QEMU_OPT_STRING
,
319 .help
= "free-form string used to describe fd",
321 { /* end of list */ }
325 static QemuOptsList qemu_object_opts
= {
327 .implied_opt_name
= "qom-type",
328 .head
= QTAILQ_HEAD_INITIALIZER(qemu_object_opts
.head
),
334 static QemuOptsList qemu_tpmdev_opts
= {
336 .implied_opt_name
= "type",
337 .head
= QTAILQ_HEAD_INITIALIZER(qemu_tpmdev_opts
.head
),
339 /* options are defined in the TPM backends */
340 { /* end of list */ }
344 static QemuOptsList qemu_overcommit_opts
= {
345 .name
= "overcommit",
346 .head
= QTAILQ_HEAD_INITIALIZER(qemu_overcommit_opts
.head
),
350 .type
= QEMU_OPT_BOOL
,
354 .type
= QEMU_OPT_BOOL
,
356 { /* end of list */ }
360 static QemuOptsList qemu_msg_opts
= {
362 .head
= QTAILQ_HEAD_INITIALIZER(qemu_msg_opts
.head
),
366 .type
= QEMU_OPT_BOOL
,
369 .name
= "guest-name",
370 .type
= QEMU_OPT_BOOL
,
371 .help
= "Prepends guest name for error messages but only if "
372 "-name guest is set otherwise option is ignored\n",
374 { /* end of list */ }
378 static QemuOptsList qemu_name_opts
= {
380 .implied_opt_name
= "guest",
382 .head
= QTAILQ_HEAD_INITIALIZER(qemu_name_opts
.head
),
386 .type
= QEMU_OPT_STRING
,
387 .help
= "Sets the name of the guest.\n"
388 "This name will be displayed in the SDL window caption.\n"
389 "The name will also be used for the VNC server",
392 .type
= QEMU_OPT_STRING
,
393 .help
= "Sets the name of the QEMU process, as shown in top etc",
395 .name
= "debug-threads",
396 .type
= QEMU_OPT_BOOL
,
397 .help
= "When enabled, name the individual threads; defaults off.\n"
398 "NOTE: The thread names are for debugging and not a\n"
401 { /* End of list */ }
405 static QemuOptsList qemu_mem_opts
= {
407 .implied_opt_name
= "size",
408 .head
= QTAILQ_HEAD_INITIALIZER(qemu_mem_opts
.head
),
413 .type
= QEMU_OPT_SIZE
,
417 .type
= QEMU_OPT_NUMBER
,
421 .type
= QEMU_OPT_SIZE
,
423 { /* end of list */ }
427 static QemuOptsList qemu_icount_opts
= {
429 .implied_opt_name
= "shift",
431 .head
= QTAILQ_HEAD_INITIALIZER(qemu_icount_opts
.head
),
435 .type
= QEMU_OPT_STRING
,
438 .type
= QEMU_OPT_BOOL
,
441 .type
= QEMU_OPT_BOOL
,
444 .type
= QEMU_OPT_STRING
,
447 .type
= QEMU_OPT_STRING
,
449 .name
= "rrsnapshot",
450 .type
= QEMU_OPT_STRING
,
452 { /* end of list */ }
456 static QemuOptsList qemu_fw_cfg_opts
= {
458 .implied_opt_name
= "name",
459 .head
= QTAILQ_HEAD_INITIALIZER(qemu_fw_cfg_opts
.head
),
463 .type
= QEMU_OPT_STRING
,
464 .help
= "Sets the fw_cfg name of the blob to be inserted",
467 .type
= QEMU_OPT_STRING
,
468 .help
= "Sets the name of the file from which "
469 "the fw_cfg blob will be loaded",
472 .type
= QEMU_OPT_STRING
,
473 .help
= "Sets content of the blob to be inserted from a string",
476 .type
= QEMU_OPT_STRING
,
477 .help
= "Sets id of the object generating the fw_cfg blob "
480 { /* end of list */ }
484 static QemuOptsList qemu_action_opts
= {
487 .head
= QTAILQ_HEAD_INITIALIZER(qemu_action_opts
.head
),
491 .type
= QEMU_OPT_STRING
,
494 .type
= QEMU_OPT_STRING
,
497 .type
= QEMU_OPT_STRING
,
500 .type
= QEMU_OPT_STRING
,
502 { /* end of list */ }
506 const char *qemu_get_vm_name(void)
511 static void default_driver_disable(const char *driver
)
519 for (i
= 0; i
< ARRAY_SIZE(default_list
); i
++) {
520 if (strcmp(default_list
[i
].driver
, driver
) != 0)
522 *(default_list
[i
].flag
) = 0;
526 static int default_driver_check(void *opaque
, QemuOpts
*opts
, Error
**errp
)
528 const char *driver
= qemu_opt_get(opts
, "driver");
530 default_driver_disable(driver
);
534 static void default_driver_check_json(void)
538 QTAILQ_FOREACH(opt
, &device_opts
, next
) {
539 const char *driver
= qdict_get_try_str(opt
->opts
, "driver");
540 default_driver_disable(driver
);
544 static int parse_name(void *opaque
, QemuOpts
*opts
, Error
**errp
)
546 const char *proc_name
;
548 if (qemu_opt_get(opts
, "debug-threads")) {
549 qemu_thread_naming(qemu_opt_get_bool(opts
, "debug-threads", false));
551 qemu_name
= qemu_opt_get(opts
, "guest");
553 proc_name
= qemu_opt_get(opts
, "process");
555 os_set_proc_name(proc_name
);
561 bool defaults_enabled(void)
567 static int parse_add_fd(void *opaque
, QemuOpts
*opts
, Error
**errp
)
569 int fd
, dupfd
, flags
;
571 const char *fd_opaque
= NULL
;
574 fd
= qemu_opt_get_number(opts
, "fd", -1);
575 fdset_id
= qemu_opt_get_number(opts
, "set", -1);
576 fd_opaque
= qemu_opt_get(opts
, "opaque");
579 error_setg(errp
, "fd option is required and must be non-negative");
583 if (fd
<= STDERR_FILENO
) {
584 error_setg(errp
, "fd cannot be a standard I/O stream");
589 * All fds inherited across exec() necessarily have FD_CLOEXEC
590 * clear, while qemu sets FD_CLOEXEC on all other fds used internally.
592 flags
= fcntl(fd
, F_GETFD
);
593 if (flags
== -1 || (flags
& FD_CLOEXEC
)) {
594 error_setg(errp
, "fd is not valid or already in use");
599 error_setg(errp
, "set option is required and must be non-negative");
603 #ifdef F_DUPFD_CLOEXEC
604 dupfd
= fcntl(fd
, F_DUPFD_CLOEXEC
, 0);
608 qemu_set_cloexec(dupfd
);
612 error_setg(errp
, "error duplicating fd: %s", strerror(errno
));
616 /* add the duplicate fd, and optionally the opaque string, to the fd set */
617 fdinfo
= monitor_fdset_add_fd(dupfd
, true, fdset_id
, fd_opaque
,
624 static int cleanup_add_fd(void *opaque
, QemuOpts
*opts
, Error
**errp
)
628 fd
= qemu_opt_get_number(opts
, "fd", -1);
635 /***********************************************************/
636 /* QEMU Block devices */
638 #define HD_OPTS "media=disk"
639 #define CDROM_OPTS "media=cdrom"
641 #define PFLASH_OPTS ""
645 static int drive_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
647 BlockInterfaceType
*block_default_type
= opaque
;
649 return drive_new(opts
, *block_default_type
, errp
) == NULL
;
652 static int drive_enable_snapshot(void *opaque
, QemuOpts
*opts
, Error
**errp
)
654 if (qemu_opt_get(opts
, "snapshot") == NULL
) {
655 qemu_opt_set(opts
, "snapshot", "on", &error_abort
);
660 static void default_drive(int enable
, int snapshot
, BlockInterfaceType type
,
661 int index
, const char *optstr
)
666 if (!enable
|| drive_get_by_index(type
, index
)) {
670 opts
= drive_add(type
, index
, NULL
, optstr
);
672 drive_enable_snapshot(NULL
, opts
, NULL
);
675 dinfo
= drive_new(opts
, type
, &error_abort
);
676 dinfo
->is_default
= true;
680 static void configure_blockdev(BlockdevOptionsQueue
*bdo_queue
,
681 MachineClass
*machine_class
, int snapshot
)
684 * If the currently selected machine wishes to override the
685 * units-per-bus property of its default HBA interface type, do so
688 if (machine_class
->units_per_default_bus
) {
689 override_max_devs(machine_class
->block_default_type
,
690 machine_class
->units_per_default_bus
);
693 /* open the virtual block devices */
694 while (!QSIMPLEQ_EMPTY(bdo_queue
)) {
695 BlockdevOptionsQueueEntry
*bdo
= QSIMPLEQ_FIRST(bdo_queue
);
697 QSIMPLEQ_REMOVE_HEAD(bdo_queue
, entry
);
698 loc_push_restore(&bdo
->loc
);
699 qmp_blockdev_add(bdo
->bdo
, &error_fatal
);
701 qapi_free_BlockdevOptions(bdo
->bdo
);
705 qemu_opts_foreach(qemu_find_opts("drive"), drive_enable_snapshot
,
708 if (qemu_opts_foreach(qemu_find_opts("drive"), drive_init_func
,
709 &machine_class
->block_default_type
, &error_fatal
)) {
710 /* We printed help */
714 default_drive(default_cdrom
, snapshot
, machine_class
->block_default_type
, 2,
716 default_drive(default_floppy
, snapshot
, IF_FLOPPY
, 0, FD_OPTS
);
717 default_drive(default_sdcard
, snapshot
, IF_SD
, 0, SD_OPTS
);
721 static QemuOptsList qemu_smp_opts
= {
723 .implied_opt_name
= "cpus",
725 .head
= QTAILQ_HEAD_INITIALIZER(qemu_smp_opts
.head
),
729 .type
= QEMU_OPT_NUMBER
,
732 .type
= QEMU_OPT_NUMBER
,
735 .type
= QEMU_OPT_NUMBER
,
738 .type
= QEMU_OPT_NUMBER
,
741 .type
= QEMU_OPT_NUMBER
,
744 .type
= QEMU_OPT_NUMBER
,
747 .type
= QEMU_OPT_NUMBER
,
753 static void realtime_init(void)
756 if (os_mlock() < 0) {
757 error_report("locking memory failed");
764 static void configure_msg(QemuOpts
*opts
)
766 message_with_timestamp
= qemu_opt_get_bool(opts
, "timestamp", false);
767 error_with_guestname
= qemu_opt_get_bool(opts
, "guest-name", false);
771 /***********************************************************/
774 static int usb_device_add(const char *devname
)
776 USBDevice
*dev
= NULL
;
778 if (!machine_usb(current_machine
)) {
782 dev
= usbdevice_create(devname
);
789 static int usb_parse(const char *cmdline
)
792 r
= usb_device_add(cmdline
);
794 error_report("could not add USB device '%s'", cmdline
);
799 /***********************************************************/
800 /* machine registration */
802 static MachineClass
*find_machine(const char *name
, GSList
*machines
)
806 for (el
= machines
; el
; el
= el
->next
) {
807 MachineClass
*mc
= el
->data
;
809 if (!strcmp(mc
->name
, name
) || !g_strcmp0(mc
->alias
, name
)) {
817 static MachineClass
*find_default_machine(GSList
*machines
)
820 MachineClass
*default_machineclass
= NULL
;
822 for (el
= machines
; el
; el
= el
->next
) {
823 MachineClass
*mc
= el
->data
;
825 if (mc
->is_default
) {
826 assert(default_machineclass
== NULL
&& "Multiple default machines");
827 default_machineclass
= mc
;
831 return default_machineclass
;
834 static void version(void)
836 printf("QEMU emulator version " QEMU_FULL_VERSION
"\n"
837 QEMU_COPYRIGHT
"\n");
840 static void help(int exitcode
)
843 printf("usage: %s [options] [disk_image]\n\n"
844 "'disk_image' is a raw hard disk image for IDE hard disk 0\n\n",
847 #define DEF(option, opt_arg, opt_enum, opt_help, arch_mask) \
848 if ((arch_mask) & arch_type) \
849 fputs(opt_help, stdout);
851 #define ARCHHEADING(text, arch_mask) \
852 if ((arch_mask) & arch_type) \
853 puts(stringify(text));
855 #define DEFHEADING(text) ARCHHEADING(text, QEMU_ARCH_ALL)
857 #include "qemu-options.def"
859 printf("\nDuring emulation, the following keys are useful:\n"
860 "ctrl-alt-f toggle full screen\n"
861 "ctrl-alt-n switch to virtual console 'n'\n"
862 "ctrl-alt toggle mouse and keyboard grab\n"
864 "When using -nographic, press 'ctrl-a h' to get some help.\n"
866 QEMU_HELP_BOTTOM
"\n");
871 #define HAS_ARG 0x0001
873 typedef struct QEMUOption
{
880 static const QEMUOption qemu_options
[] = {
881 { "h", 0, QEMU_OPTION_h
, QEMU_ARCH_ALL
},
883 #define DEF(option, opt_arg, opt_enum, opt_help, arch_mask) \
884 { option, opt_arg, opt_enum, arch_mask },
885 #define DEFHEADING(text)
886 #define ARCHHEADING(text, arch_mask)
888 #include "qemu-options.def"
892 typedef struct VGAInterfaceInfo
{
893 const char *opt_name
; /* option name */
894 const char *name
; /* human-readable name */
895 /* Class names indicating that support is available.
896 * If no class is specified, the interface is always available */
897 const char *class_names
[2];
900 static const VGAInterfaceInfo vga_interfaces
[VGA_TYPE_MAX
] = {
903 .name
= "no graphic card",
907 .name
= "standard VGA",
908 .class_names
= { "VGA", "isa-vga" },
911 .opt_name
= "cirrus",
912 .name
= "Cirrus VGA",
913 .class_names
= { "cirrus-vga", "isa-cirrus-vga" },
916 .opt_name
= "vmware",
917 .name
= "VMWare SVGA",
918 .class_names
= { "vmware-svga" },
921 .opt_name
= "virtio",
922 .name
= "Virtio VGA",
923 .class_names
= { "virtio-vga" },
928 .class_names
= { "qxl-vga" },
932 .name
= "TCX framebuffer",
933 .class_names
= { "sun-tcx" },
937 .name
= "CG3 framebuffer",
938 .class_names
= { "cgthree" },
940 #ifdef CONFIG_XEN_BACKEND
943 .name
= "Xen paravirtualized framebuffer",
948 static bool vga_interface_available(VGAInterfaceType t
)
950 const VGAInterfaceInfo
*ti
= &vga_interfaces
[t
];
952 assert(t
< VGA_TYPE_MAX
);
953 return !ti
->class_names
[0] ||
954 module_object_class_by_name(ti
->class_names
[0]) ||
955 module_object_class_by_name(ti
->class_names
[1]);
959 get_default_vga_model(const MachineClass
*machine_class
)
961 if (machine_class
->default_display
) {
962 return machine_class
->default_display
;
963 } else if (vga_interface_available(VGA_CIRRUS
)) {
965 } else if (vga_interface_available(VGA_STD
)) {
972 static void select_vgahw(const MachineClass
*machine_class
, const char *p
)
977 if (g_str_equal(p
, "help")) {
978 const char *def
= get_default_vga_model(machine_class
);
980 for (t
= 0; t
< VGA_TYPE_MAX
; t
++) {
981 const VGAInterfaceInfo
*ti
= &vga_interfaces
[t
];
983 if (vga_interface_available(t
) && ti
->opt_name
) {
984 printf("%-20s %s%s\n", ti
->opt_name
, ti
->name
?: "",
985 (def
&& g_str_equal(ti
->opt_name
, def
)) ?
992 assert(vga_interface_type
== VGA_NONE
);
993 for (t
= 0; t
< VGA_TYPE_MAX
; t
++) {
994 const VGAInterfaceInfo
*ti
= &vga_interfaces
[t
];
995 if (ti
->opt_name
&& strstart(p
, ti
->opt_name
, &opts
)) {
996 if (!vga_interface_available(t
)) {
997 error_report("%s not available", ti
->name
);
1000 vga_interface_type
= t
;
1004 if (t
== VGA_TYPE_MAX
) {
1006 error_report("unknown vga type: %s", p
);
1010 const char *nextopt
;
1012 if (strstart(opts
, ",retrace=", &nextopt
)) {
1014 if (strstart(opts
, "dumb", &nextopt
))
1015 vga_retrace_method
= VGA_RETRACE_DUMB
;
1016 else if (strstart(opts
, "precise", &nextopt
))
1017 vga_retrace_method
= VGA_RETRACE_PRECISE
;
1018 else goto invalid_vga
;
1019 } else goto invalid_vga
;
1024 static void parse_display_qapi(const char *optarg
)
1026 DisplayOptions
*opts
;
1029 v
= qobject_input_visitor_new_str(optarg
, "type", &error_fatal
);
1031 visit_type_DisplayOptions(v
, NULL
, &opts
, &error_fatal
);
1032 QAPI_CLONE_MEMBERS(DisplayOptions
, &dpy
, opts
);
1034 qapi_free_DisplayOptions(opts
);
1038 DisplayOptions
*qmp_query_display_options(Error
**errp
)
1040 return QAPI_CLONE(DisplayOptions
, &dpy
);
1043 static void parse_display(const char *p
)
1047 if (is_help_option(p
)) {
1048 qemu_display_help();
1052 if (strstart(p
, "vnc", &opts
)) {
1054 * vnc isn't a (local) DisplayType but a protocol for remote
1058 vnc_parse(opts
+ 1);
1060 error_report("VNC requires a display argument vnc=<display>");
1064 parse_display_qapi(p
);
1068 static inline bool nonempty_str(const char *str
)
1073 static int parse_fw_cfg(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1077 const char *name
, *file
, *str
, *gen_id
;
1078 FWCfgState
*fw_cfg
= (FWCfgState
*) opaque
;
1080 if (fw_cfg
== NULL
) {
1081 error_setg(errp
, "fw_cfg device not available");
1084 name
= qemu_opt_get(opts
, "name");
1085 file
= qemu_opt_get(opts
, "file");
1086 str
= qemu_opt_get(opts
, "string");
1087 gen_id
= qemu_opt_get(opts
, "gen_id");
1089 /* we need the name, and exactly one of: file, content string, gen_id */
1090 if (!nonempty_str(name
) ||
1091 nonempty_str(file
) + nonempty_str(str
) + nonempty_str(gen_id
) != 1) {
1092 error_setg(errp
, "name, plus exactly one of file,"
1093 " string and gen_id, are needed");
1096 if (strlen(name
) > FW_CFG_MAX_FILE_PATH
- 1) {
1097 error_setg(errp
, "name too long (max. %d char)",
1098 FW_CFG_MAX_FILE_PATH
- 1);
1101 if (nonempty_str(gen_id
)) {
1103 * In this particular case where the content is populated
1104 * internally, the "etc/" namespace protection is relaxed,
1105 * so do not emit a warning.
1107 } else if (strncmp(name
, "opt/", 4) != 0) {
1108 warn_report("externally provided fw_cfg item names "
1109 "should be prefixed with \"opt/\"");
1111 if (nonempty_str(str
)) {
1112 size
= strlen(str
); /* NUL terminator NOT included in fw_cfg blob */
1113 buf
= g_memdup(str
, size
);
1114 } else if (nonempty_str(gen_id
)) {
1115 if (!fw_cfg_add_from_generator(fw_cfg
, name
, gen_id
, errp
)) {
1121 if (!g_file_get_contents(file
, &buf
, &size
, &err
)) {
1122 error_setg(errp
, "can't load %s: %s", file
, err
->message
);
1127 /* For legacy, keep user files in a specific global order. */
1128 fw_cfg_set_order_override(fw_cfg
, FW_CFG_ORDER_OVERRIDE_USER
);
1129 fw_cfg_add_file(fw_cfg
, name
, buf
, size
);
1130 fw_cfg_reset_order_override(fw_cfg
);
1134 static int device_help_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1136 return qdev_device_help(opts
);
1139 static int device_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1143 dev
= qdev_device_add(opts
, errp
);
1144 if (!dev
&& *errp
) {
1145 error_report_err(*errp
);
1148 object_unref(OBJECT(dev
));
1153 static int chardev_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1155 Error
*local_err
= NULL
;
1157 if (!qemu_chr_new_from_opts(opts
, NULL
, &local_err
)) {
1159 error_propagate(errp
, local_err
);
1167 #ifdef CONFIG_VIRTFS
1168 static int fsdev_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1170 return qemu_fsdev_add(opts
, errp
);
1174 static int mon_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1176 return monitor_init_opts(opts
, errp
);
1179 static void monitor_parse(const char *optarg
, const char *mode
, bool pretty
)
1181 static int monitor_device_index
= 0;
1186 if (strstart(optarg
, "chardev:", &p
)) {
1187 snprintf(label
, sizeof(label
), "%s", p
);
1189 snprintf(label
, sizeof(label
), "compat_monitor%d",
1190 monitor_device_index
);
1191 opts
= qemu_chr_parse_compat(label
, optarg
, true);
1193 error_report("parse error: %s", optarg
);
1198 opts
= qemu_opts_create(qemu_find_opts("mon"), label
, 1, &error_fatal
);
1199 qemu_opt_set(opts
, "mode", mode
, &error_abort
);
1200 qemu_opt_set(opts
, "chardev", label
, &error_abort
);
1201 if (!strcmp(mode
, "control")) {
1202 qemu_opt_set_bool(opts
, "pretty", pretty
, &error_abort
);
1204 assert(pretty
== false);
1206 monitor_device_index
++;
1209 struct device_config
{
1211 DEV_USB
, /* -usbdevice */
1212 DEV_SERIAL
, /* -serial */
1213 DEV_PARALLEL
, /* -parallel */
1214 DEV_DEBUGCON
, /* -debugcon */
1215 DEV_GDB
, /* -gdb, -s */
1216 DEV_SCLP
, /* s390 sclp */
1218 const char *cmdline
;
1220 QTAILQ_ENTRY(device_config
) next
;
1223 static QTAILQ_HEAD(, device_config
) device_configs
=
1224 QTAILQ_HEAD_INITIALIZER(device_configs
);
1226 static void add_device_config(int type
, const char *cmdline
)
1228 struct device_config
*conf
;
1230 conf
= g_malloc0(sizeof(*conf
));
1232 conf
->cmdline
= cmdline
;
1233 loc_save(&conf
->loc
);
1234 QTAILQ_INSERT_TAIL(&device_configs
, conf
, next
);
1237 static int foreach_device_config(int type
, int (*func
)(const char *cmdline
))
1239 struct device_config
*conf
;
1242 QTAILQ_FOREACH(conf
, &device_configs
, next
) {
1243 if (conf
->type
!= type
)
1245 loc_push_restore(&conf
->loc
);
1246 rc
= func(conf
->cmdline
);
1247 loc_pop(&conf
->loc
);
1255 static void qemu_disable_default_devices(void)
1257 MachineClass
*machine_class
= MACHINE_GET_CLASS(current_machine
);
1259 default_driver_check_json();
1260 qemu_opts_foreach(qemu_find_opts("device"),
1261 default_driver_check
, NULL
, NULL
);
1262 qemu_opts_foreach(qemu_find_opts("global"),
1263 default_driver_check
, NULL
, NULL
);
1265 if (!vga_model
&& !default_vga
) {
1266 vga_interface_type
= VGA_DEVICE
;
1267 vga_interface_created
= true;
1269 if (!has_defaults
|| machine_class
->no_serial
) {
1272 if (!has_defaults
|| machine_class
->no_parallel
) {
1273 default_parallel
= 0;
1275 if (!has_defaults
|| machine_class
->no_floppy
) {
1278 if (!has_defaults
|| machine_class
->no_cdrom
) {
1281 if (!has_defaults
|| machine_class
->no_sdcard
) {
1284 if (!has_defaults
) {
1285 default_monitor
= 0;
1291 static void qemu_create_default_devices(void)
1293 MachineClass
*machine_class
= MACHINE_GET_CLASS(current_machine
);
1295 if (is_daemonized()) {
1296 /* According to documentation and historically, -nographic redirects
1297 * serial port, parallel port and monitor to stdio, which does not work
1298 * with -daemonize. We can redirect these to null instead, but since
1299 * -nographic is legacy, let's just error out.
1300 * We disallow -nographic only if all other ports are not redirected
1301 * explicitly, to not break existing legacy setups which uses
1302 * -nographic _and_ redirects all ports explicitly - this is valid
1303 * usage, -nographic is just a no-op in this case.
1306 && (default_parallel
|| default_serial
|| default_monitor
)) {
1307 error_report("-nographic cannot be used with -daemonize");
1313 if (default_parallel
)
1314 add_device_config(DEV_PARALLEL
, "null");
1315 if (default_serial
&& default_monitor
) {
1316 add_device_config(DEV_SERIAL
, "mon:stdio");
1319 add_device_config(DEV_SERIAL
, "stdio");
1320 if (default_monitor
)
1321 monitor_parse("stdio", "readline", false);
1325 add_device_config(DEV_SERIAL
, "vc:80Cx24C");
1326 if (default_parallel
)
1327 add_device_config(DEV_PARALLEL
, "vc:80Cx24C");
1328 if (default_monitor
)
1329 monitor_parse("vc:80Cx24C", "readline", false);
1333 QemuOptsList
*net
= qemu_find_opts("net");
1334 qemu_opts_parse(net
, "nic", true, &error_abort
);
1336 qemu_opts_parse(net
, "user", true, &error_abort
);
1340 #if defined(CONFIG_VNC)
1341 if (!QTAILQ_EMPTY(&(qemu_find_opts("vnc")->head
))) {
1345 if (dpy
.type
== DISPLAY_TYPE_DEFAULT
&& !display_remote
) {
1346 if (!qemu_display_find_default(&dpy
)) {
1347 dpy
.type
= DISPLAY_TYPE_NONE
;
1348 #if defined(CONFIG_VNC)
1349 vnc_parse("localhost:0,to=99,id=default");
1353 if (dpy
.type
== DISPLAY_TYPE_DEFAULT
) {
1354 dpy
.type
= DISPLAY_TYPE_NONE
;
1357 /* If no default VGA is requested, the default is "none". */
1359 vga_model
= get_default_vga_model(machine_class
);
1362 select_vgahw(machine_class
, vga_model
);
1366 static int serial_parse(const char *devname
)
1368 int index
= num_serial_hds
;
1371 if (strcmp(devname
, "none") == 0)
1373 snprintf(label
, sizeof(label
), "serial%d", index
);
1374 serial_hds
= g_renew(Chardev
*, serial_hds
, index
+ 1);
1376 serial_hds
[index
] = qemu_chr_new_mux_mon(label
, devname
, NULL
);
1377 if (!serial_hds
[index
]) {
1378 error_report("could not connect serial device"
1379 " to character backend '%s'", devname
);
1386 Chardev
*serial_hd(int i
)
1389 if (i
< num_serial_hds
) {
1390 return serial_hds
[i
];
1395 static int parallel_parse(const char *devname
)
1397 static int index
= 0;
1400 if (strcmp(devname
, "none") == 0)
1402 if (index
== MAX_PARALLEL_PORTS
) {
1403 error_report("too many parallel ports");
1406 snprintf(label
, sizeof(label
), "parallel%d", index
);
1407 parallel_hds
[index
] = qemu_chr_new_mux_mon(label
, devname
, NULL
);
1408 if (!parallel_hds
[index
]) {
1409 error_report("could not connect parallel device"
1410 " to character backend '%s'", devname
);
1417 static int debugcon_parse(const char *devname
)
1421 if (!qemu_chr_new_mux_mon("debugcon", devname
, NULL
)) {
1422 error_report("invalid character backend '%s'", devname
);
1425 opts
= qemu_opts_create(qemu_find_opts("device"), "debugcon", 1, NULL
);
1427 error_report("already have a debugcon device");
1430 qemu_opt_set(opts
, "driver", "isa-debugcon", &error_abort
);
1431 qemu_opt_set(opts
, "chardev", "debugcon", &error_abort
);
1435 static gint
machine_class_cmp(gconstpointer a
, gconstpointer b
)
1437 const MachineClass
*mc1
= a
, *mc2
= b
;
1440 if (mc1
->family
== NULL
) {
1441 if (mc2
->family
== NULL
) {
1442 /* Compare standalone machine types against each other; they sort
1443 * in increasing order.
1445 return strcmp(object_class_get_name(OBJECT_CLASS(mc1
)),
1446 object_class_get_name(OBJECT_CLASS(mc2
)));
1449 /* Standalone machine types sort after families. */
1453 if (mc2
->family
== NULL
) {
1454 /* Families sort before standalone machine types. */
1458 /* Families sort between each other alphabetically increasingly. */
1459 res
= strcmp(mc1
->family
, mc2
->family
);
1464 /* Within the same family, machine types sort in decreasing order. */
1465 return strcmp(object_class_get_name(OBJECT_CLASS(mc2
)),
1466 object_class_get_name(OBJECT_CLASS(mc1
)));
1469 static void machine_help_func(const QDict
*qdict
)
1471 GSList
*machines
, *el
;
1472 const char *type
= qdict_get_try_str(qdict
, "type");
1474 machines
= object_class_get_list(TYPE_MACHINE
, false);
1476 ObjectClass
*machine_class
= OBJECT_CLASS(find_machine(type
, machines
));
1477 if (machine_class
) {
1478 type_print_class_properties(object_class_get_name(machine_class
));
1483 printf("Supported machines are:\n");
1484 machines
= g_slist_sort(machines
, machine_class_cmp
);
1485 for (el
= machines
; el
; el
= el
->next
) {
1486 MachineClass
*mc
= el
->data
;
1488 printf("%-20s %s (alias of %s)\n", mc
->alias
, mc
->desc
, mc
->name
);
1490 printf("%-20s %s%s%s\n", mc
->name
, mc
->desc
,
1491 mc
->is_default
? " (default)" : "",
1492 mc
->deprecation_reason
? " (deprecated)" : "");
1497 machine_merge_property(const char *propname
, QDict
*prop
, Error
**errp
)
1502 /* Preserve the caller's reference to prop. */
1504 qdict_put(opts
, propname
, prop
);
1505 keyval_merge(machine_opts_dict
, opts
, errp
);
1506 qobject_unref(opts
);
1510 machine_parse_property_opt(QemuOptsList
*opts_list
, const char *propname
,
1516 prop
= keyval_parse(arg
, opts_list
->implied_opt_name
, &help
, &error_fatal
);
1518 qemu_opts_print_help(opts_list
, true);
1521 machine_merge_property(propname
, prop
, &error_fatal
);
1522 qobject_unref(prop
);
1525 static const char *pid_file
;
1526 struct UnlinkPidfileNotifier
{
1528 char *pid_file_realpath
;
1530 static struct UnlinkPidfileNotifier qemu_unlink_pidfile_notifier
;
1532 static void qemu_unlink_pidfile(Notifier
*n
, void *data
)
1534 struct UnlinkPidfileNotifier
*upn
;
1536 upn
= DO_UPCAST(struct UnlinkPidfileNotifier
, notifier
, n
);
1537 unlink(upn
->pid_file_realpath
);
1540 static const QEMUOption
*lookup_opt(int argc
, char **argv
,
1541 const char **poptarg
, int *poptind
)
1543 const QEMUOption
*popt
;
1544 int optind
= *poptind
;
1545 char *r
= argv
[optind
];
1548 loc_set_cmdline(argv
, optind
, 1);
1550 /* Treat --foo the same as -foo. */
1553 popt
= qemu_options
;
1556 error_report("invalid option");
1559 if (!strcmp(popt
->name
, r
+ 1))
1563 if (popt
->flags
& HAS_ARG
) {
1564 if (optind
>= argc
) {
1565 error_report("requires an argument");
1568 optarg
= argv
[optind
++];
1569 loc_set_cmdline(argv
, optind
- 2, 2);
1580 static MachineClass
*select_machine(QDict
*qdict
, Error
**errp
)
1582 const char *optarg
= qdict_get_try_str(qdict
, "type");
1583 GSList
*machines
= object_class_get_list(TYPE_MACHINE
, false);
1584 MachineClass
*machine_class
;
1585 Error
*local_err
= NULL
;
1588 machine_class
= find_machine(optarg
, machines
);
1589 qdict_del(qdict
, "type");
1590 if (!machine_class
) {
1591 error_setg(&local_err
, "unsupported machine type");
1594 machine_class
= find_default_machine(machines
);
1595 if (!machine_class
) {
1596 error_setg(&local_err
, "No machine specified, and there is no default");
1600 g_slist_free(machines
);
1602 error_append_hint(&local_err
, "Use -machine help to list supported machines\n");
1603 error_propagate(errp
, local_err
);
1605 return machine_class
;
1608 static int object_parse_property_opt(Object
*obj
,
1609 const char *name
, const char *value
,
1610 const char *skip
, Error
**errp
)
1612 if (g_str_equal(name
, skip
)) {
1616 if (!object_property_parse(obj
, name
, value
, errp
)) {
1623 /* *Non*recursively replace underscores with dashes in QDict keys. */
1624 static void keyval_dashify(QDict
*qdict
, Error
**errp
)
1626 const QDictEntry
*ent
, *next
;
1629 for (ent
= qdict_first(qdict
); ent
; ent
= next
) {
1630 g_autofree
char *new_key
= NULL
;
1632 next
= qdict_next(qdict
, ent
);
1633 if (!strchr(ent
->key
, '_')) {
1636 new_key
= g_strdup(ent
->key
);
1637 for (p
= new_key
; *p
; p
++) {
1642 if (qdict_haskey(qdict
, new_key
)) {
1643 error_setg(errp
, "Conflict between '%s' and '%s'", ent
->key
, new_key
);
1646 qobject_ref(ent
->value
);
1647 qdict_put_obj(qdict
, new_key
, ent
->value
);
1648 qdict_del(qdict
, ent
->key
);
1652 static void qemu_apply_legacy_machine_options(QDict
*qdict
)
1657 keyval_dashify(qdict
, &error_fatal
);
1659 /* Legacy options do not correspond to MachineState properties. */
1660 value
= qdict_get_try_str(qdict
, "accel");
1662 accelerators
= g_strdup(value
);
1663 qdict_del(qdict
, "accel");
1666 value
= qdict_get_try_str(qdict
, "igd-passthru");
1668 object_register_sugar_prop(ACCEL_CLASS_NAME("xen"), "igd-passthru", value
,
1670 qdict_del(qdict
, "igd-passthru");
1673 value
= qdict_get_try_str(qdict
, "kvm-shadow-mem");
1675 object_register_sugar_prop(ACCEL_CLASS_NAME("kvm"), "kvm-shadow-mem", value
,
1677 qdict_del(qdict
, "kvm-shadow-mem");
1680 value
= qdict_get_try_str(qdict
, "kernel-irqchip");
1682 object_register_sugar_prop(ACCEL_CLASS_NAME("kvm"), "kernel-irqchip", value
,
1684 object_register_sugar_prop(ACCEL_CLASS_NAME("whpx"), "kernel-irqchip", value
,
1686 qdict_del(qdict
, "kernel-irqchip");
1689 value
= qdict_get_try_str(qdict
, "memory-backend");
1692 error_report("'-mem-path' can't be used together with"
1693 "'-machine memory-backend'");
1697 /* Resolved later. */
1698 ram_memdev_id
= g_strdup(value
);
1699 qdict_del(qdict
, "memory-backend");
1702 prop
= qdict_get(qdict
, "memory");
1704 have_custom_ram_size
=
1705 qobject_type(prop
) == QTYPE_QDICT
&&
1706 qdict_haskey(qobject_to(QDict
, prop
), "size");
1710 static void object_option_foreach_add(bool (*type_opt_predicate
)(const char *))
1712 ObjectOption
*opt
, *next
;
1714 QTAILQ_FOREACH_SAFE(opt
, &object_opts
, next
, next
) {
1715 const char *type
= ObjectType_str(opt
->opts
->qom_type
);
1716 if (type_opt_predicate(type
)) {
1717 user_creatable_add_qapi(opt
->opts
, &error_fatal
);
1718 qapi_free_ObjectOptions(opt
->opts
);
1719 QTAILQ_REMOVE(&object_opts
, opt
, next
);
1725 static void object_option_add_visitor(Visitor
*v
)
1727 ObjectOption
*opt
= g_new0(ObjectOption
, 1);
1728 visit_type_ObjectOptions(v
, NULL
, &opt
->opts
, &error_fatal
);
1729 QTAILQ_INSERT_TAIL(&object_opts
, opt
, next
);
1732 static void object_option_parse(const char *optarg
)
1738 if (optarg
[0] == '{') {
1739 QObject
*obj
= qobject_from_json(optarg
, &error_fatal
);
1741 v
= qobject_input_visitor_new(obj
);
1744 opts
= qemu_opts_parse_noisily(qemu_find_opts("object"),
1750 type
= qemu_opt_get(opts
, "qom-type");
1752 error_setg(&error_fatal
, QERR_MISSING_PARAMETER
, "qom-type");
1754 if (user_creatable_print_help(type
, opts
)) {
1758 v
= opts_visitor_new(opts
);
1761 object_option_add_visitor(v
);
1766 * Very early object creation, before the sandbox options have been activated.
1768 static bool object_create_pre_sandbox(const char *type
)
1771 * Objects should in general not get initialized "too early" without
1772 * a reason. If you add one, state the reason in a comment!
1776 * Reason: -sandbox on,resourcecontrol=deny disallows setting CPU
1777 * affinity of threads.
1779 if (g_str_equal(type
, "thread-context")) {
1787 * Initial object creation happens before all other
1788 * QEMU data types are created. The majority of objects
1789 * can be created at this point. The rng-egd object
1790 * cannot be created here, as it depends on the chardev
1793 static bool object_create_early(const char *type
)
1796 * Objects should not be made "delayed" without a reason. If you
1797 * add one, state the reason in a comment!
1800 /* Reason: already created. */
1801 if (object_create_pre_sandbox(type
)) {
1805 /* Reason: property "chardev" */
1806 if (g_str_equal(type
, "rng-egd") ||
1807 g_str_equal(type
, "qtest")) {
1811 #if defined(CONFIG_VHOST_USER) && defined(CONFIG_LINUX)
1812 /* Reason: cryptodev-vhost-user property "chardev" */
1813 if (g_str_equal(type
, "cryptodev-vhost-user")) {
1818 /* Reason: vhost-user-blk-server property "node-name" */
1819 if (g_str_equal(type
, "vhost-user-blk-server")) {
1823 * Reason: filter-* property "netdev" etc.
1825 if (g_str_equal(type
, "filter-buffer") ||
1826 g_str_equal(type
, "filter-dump") ||
1827 g_str_equal(type
, "filter-mirror") ||
1828 g_str_equal(type
, "filter-redirector") ||
1829 g_str_equal(type
, "colo-compare") ||
1830 g_str_equal(type
, "filter-rewriter") ||
1831 g_str_equal(type
, "filter-replay")) {
1836 * Allocation of large amounts of memory may delay
1837 * chardev initialization for too long, and trigger timeouts
1838 * on software that waits for a monitor socket to be created
1841 if (g_str_has_prefix(type
, "memory-backend-")) {
1848 static void qemu_apply_machine_options(QDict
*qdict
)
1850 object_set_properties_from_keyval(OBJECT(current_machine
), qdict
, false, &error_fatal
);
1852 if (semihosting_enabled(false) && !semihosting_get_argc()) {
1853 /* fall back to the -kernel/-append */
1854 semihosting_arg_fallback(current_machine
->kernel_filename
, current_machine
->kernel_cmdline
);
1857 if (current_machine
->smp
.cpus
> 1) {
1858 Error
*blocker
= NULL
;
1859 error_setg(&blocker
, QERR_REPLAY_NOT_SUPPORTED
, "smp");
1860 replay_add_blocker(blocker
);
1864 static void qemu_create_early_backends(void)
1866 MachineClass
*machine_class
= MACHINE_GET_CLASS(current_machine
);
1867 #if defined(CONFIG_SDL)
1868 const bool use_sdl
= (dpy
.type
== DISPLAY_TYPE_SDL
);
1870 const bool use_sdl
= false;
1872 #if defined(CONFIG_GTK)
1873 const bool use_gtk
= (dpy
.type
== DISPLAY_TYPE_GTK
);
1875 const bool use_gtk
= false;
1878 if (dpy
.has_window_close
&& !use_gtk
&& !use_sdl
) {
1879 error_report("window-close is only valid for GTK and SDL, "
1883 qemu_display_early_init(&dpy
);
1884 qemu_console_early_init();
1886 if (dpy
.has_gl
&& dpy
.gl
!= DISPLAYGL_MODE_OFF
&& display_opengl
== 0) {
1887 #if defined(CONFIG_OPENGL)
1888 error_report("OpenGL is not supported by the display");
1890 error_report("OpenGL support is disabled");
1895 object_option_foreach_add(object_create_early
);
1897 /* spice needs the timers to be initialized by this point */
1898 /* spice must initialize before audio as it changes the default audiodev */
1899 /* spice must initialize before chardevs (for spicevmc and spiceport) */
1902 qemu_opts_foreach(qemu_find_opts("chardev"),
1903 chardev_init_func
, NULL
, &error_fatal
);
1905 #ifdef CONFIG_VIRTFS
1906 qemu_opts_foreach(qemu_find_opts("fsdev"),
1907 fsdev_init_func
, NULL
, &error_fatal
);
1911 * Note: we need to create audio and block backends before
1912 * setting machine properties, so they can be referred to.
1914 configure_blockdev(&bdo_queue
, machine_class
, snapshot
);
1915 if (!audio_init_audiodevs()) {
1922 * The remainder of object creation happens after the
1923 * creation of chardev, fsdev, net clients and device data types.
1925 static bool object_create_late(const char *type
)
1927 return !object_create_early(type
) && !object_create_pre_sandbox(type
);
1930 static void qemu_create_late_backends(void)
1933 qtest_server_init(qtest_chrdev
, qtest_log
, &error_fatal
);
1938 object_option_foreach_add(object_create_late
);
1940 if (tpm_init() < 0) {
1944 qemu_opts_foreach(qemu_find_opts("mon"),
1945 mon_init_func
, NULL
, &error_fatal
);
1947 if (foreach_device_config(DEV_SERIAL
, serial_parse
) < 0)
1949 if (foreach_device_config(DEV_PARALLEL
, parallel_parse
) < 0)
1951 if (foreach_device_config(DEV_DEBUGCON
, debugcon_parse
) < 0)
1954 /* now chardevs have been created we may have semihosting to connect */
1955 qemu_semihosting_chardev_init();
1958 static void qemu_resolve_machine_memdev(void)
1960 if (ram_memdev_id
) {
1962 ram_addr_t backend_size
;
1964 backend
= object_resolve_path_type(ram_memdev_id
,
1965 TYPE_MEMORY_BACKEND
, NULL
);
1967 error_report("Memory backend '%s' not found", ram_memdev_id
);
1970 if (!have_custom_ram_size
) {
1971 backend_size
= object_property_get_uint(backend
, "size", &error_abort
);
1972 current_machine
->ram_size
= backend_size
;
1974 object_property_set_link(OBJECT(current_machine
),
1975 "memory-backend", backend
, &error_fatal
);
1979 static void parse_memory_options(void)
1981 QemuOpts
*opts
= qemu_find_opts_singleton("memory");
1983 const char *mem_str
;
1986 loc_push_none(&loc
);
1987 qemu_opts_loc_restore(opts
);
1991 if (qemu_opt_get_size(opts
, "size", 0) != 0) {
1992 /* Fix up legacy suffix-less format */
1993 mem_str
= qemu_opt_get(opts
, "size");
1994 if (g_ascii_isdigit(mem_str
[strlen(mem_str
) - 1])) {
1995 g_autofree
char *mib_str
= g_strdup_printf("%sM", mem_str
);
1996 qdict_put_str(prop
, "size", mib_str
);
1998 qdict_put_str(prop
, "size", mem_str
);
2002 if (qemu_opt_get(opts
, "maxmem")) {
2003 qdict_put_str(prop
, "max-size", qemu_opt_get(opts
, "maxmem"));
2005 if (qemu_opt_get(opts
, "slots")) {
2006 qdict_put_str(prop
, "slots", qemu_opt_get(opts
, "slots"));
2010 qdict_put(dict
, "memory", prop
);
2011 keyval_merge(machine_opts_dict
, dict
, &error_fatal
);
2012 qobject_unref(dict
);
2016 static void qemu_create_machine(QDict
*qdict
)
2018 MachineClass
*machine_class
= select_machine(qdict
, &error_fatal
);
2019 object_set_machine_compat_props(machine_class
->compat_props
);
2021 current_machine
= MACHINE(object_new_with_class(OBJECT_CLASS(machine_class
)));
2022 object_property_add_child(object_get_root(), "machine",
2023 OBJECT(current_machine
));
2024 object_property_add_child(container_get(OBJECT(current_machine
),
2026 "sysbus", OBJECT(sysbus_get_default()));
2028 if (machine_class
->minimum_page_bits
) {
2029 if (!set_preferred_target_page_bits(machine_class
->minimum_page_bits
)) {
2030 /* This would be a board error: specifying a minimum smaller than
2031 * a target's compile-time fixed setting.
2033 g_assert_not_reached();
2037 cpu_exec_init_all();
2040 if (machine_class
->hw_version
) {
2041 qemu_set_hw_version(machine_class
->hw_version
);
2045 * Get the default machine options from the machine if it is not already
2046 * specified either by the configuration file or by the command line.
2048 if (machine_class
->default_machine_opts
) {
2049 QDict
*default_opts
=
2050 keyval_parse(machine_class
->default_machine_opts
, NULL
, NULL
,
2052 qemu_apply_legacy_machine_options(default_opts
);
2053 object_set_properties_from_keyval(OBJECT(current_machine
), default_opts
,
2054 false, &error_abort
);
2055 qobject_unref(default_opts
);
2059 static int global_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2063 g
= g_malloc0(sizeof(*g
));
2064 g
->driver
= qemu_opt_get(opts
, "driver");
2065 g
->property
= qemu_opt_get(opts
, "property");
2066 g
->value
= qemu_opt_get(opts
, "value");
2067 qdev_prop_register_global(g
);
2072 * Return whether configuration group @group is stored in QemuOpts, or
2073 * recorded as one or more QDicts by qemu_record_config_group.
2075 static bool is_qemuopts_group(const char *group
)
2077 if (g_str_equal(group
, "object") ||
2078 g_str_equal(group
, "machine") ||
2079 g_str_equal(group
, "smp-opts") ||
2080 g_str_equal(group
, "boot-opts")) {
2086 static void qemu_record_config_group(const char *group
, QDict
*dict
,
2087 bool from_json
, Error
**errp
)
2089 if (g_str_equal(group
, "object")) {
2090 Visitor
*v
= qobject_input_visitor_new_keyval(QOBJECT(dict
));
2091 object_option_add_visitor(v
);
2093 } else if (g_str_equal(group
, "machine")) {
2095 * Cannot merge string-valued and type-safe dictionaries, so JSON
2096 * is not accepted yet for -M.
2099 keyval_merge(machine_opts_dict
, dict
, errp
);
2100 } else if (g_str_equal(group
, "smp-opts")) {
2101 machine_merge_property("smp", dict
, &error_fatal
);
2102 } else if (g_str_equal(group
, "boot-opts")) {
2103 machine_merge_property("boot", dict
, &error_fatal
);
2110 * Parse non-QemuOpts config file groups, pass the rest to
2111 * qemu_config_do_parse.
2113 static void qemu_parse_config_group(const char *group
, QDict
*qdict
,
2114 void *opaque
, Error
**errp
)
2117 if (is_qemuopts_group(group
)) {
2118 qemu_config_do_parse(group
, qdict
, opaque
, errp
);
2122 crumpled
= qdict_crumple(qdict
, errp
);
2126 switch (qobject_type(crumpled
)) {
2128 qemu_record_config_group(group
, qobject_to(QDict
, crumpled
), false, errp
);
2131 error_setg(errp
, "Lists cannot be at top level of a configuration section");
2134 g_assert_not_reached();
2136 qobject_unref(crumpled
);
2139 static void qemu_read_default_config_file(Error
**errp
)
2143 g_autofree
char *file
= get_relocated_path(CONFIG_QEMU_CONFDIR
"/qemu.conf");
2145 ret
= qemu_read_config_file(file
, qemu_parse_config_group
, errp
);
2147 if (ret
== -ENOENT
) {
2154 static void qemu_set_option(const char *str
, Error
**errp
)
2156 char group
[64], id
[64], arg
[64];
2161 rc
= sscanf(str
, "%63[^.].%63[^.].%63[^=]%n", group
, id
, arg
, &offset
);
2162 if (rc
< 3 || str
[offset
] != '=') {
2163 error_setg(errp
, "can't parse: \"%s\"", str
);
2167 if (!is_qemuopts_group(group
)) {
2168 error_setg(errp
, "-set is not supported with %s", group
);
2170 list
= qemu_find_opts_err(group
, errp
);
2172 opts
= qemu_opts_find(list
, id
);
2174 error_setg(errp
, "there is no %s \"%s\" defined", group
, id
);
2177 qemu_opt_set(opts
, arg
, str
+ offset
+ 1, errp
);
2182 static void user_register_global_props(void)
2184 qemu_opts_foreach(qemu_find_opts("global"),
2185 global_init_func
, NULL
, NULL
);
2188 static int do_configure_icount(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2190 icount_configure(opts
, errp
);
2194 static int accelerator_set_property(void *opaque
,
2195 const char *name
, const char *value
,
2198 return object_parse_property_opt(opaque
, name
, value
, "accel", errp
);
2201 static int do_configure_accelerator(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2203 bool *p_init_failed
= opaque
;
2204 const char *acc
= qemu_opt_get(opts
, "accel");
2205 AccelClass
*ac
= accel_find(acc
);
2208 bool qtest_with_kvm
;
2210 qtest_with_kvm
= g_str_equal(acc
, "kvm") && qtest_chrdev
!= NULL
;
2213 *p_init_failed
= true;
2214 if (!qtest_with_kvm
) {
2215 error_report("invalid accelerator %s", acc
);
2219 accel
= ACCEL(object_new_with_class(OBJECT_CLASS(ac
)));
2220 object_apply_compat_props(OBJECT(accel
));
2221 qemu_opt_foreach(opts
, accelerator_set_property
,
2225 ret
= accel_init_machine(accel
, current_machine
);
2227 *p_init_failed
= true;
2228 if (!qtest_with_kvm
|| ret
!= -ENOENT
) {
2229 error_report("failed to initialize %s: %s", acc
, strerror(-ret
));
2237 static void configure_accelerators(const char *progname
)
2239 bool init_failed
= false;
2241 qemu_opts_foreach(qemu_find_opts("icount"),
2242 do_configure_icount
, NULL
, &error_fatal
);
2244 if (QTAILQ_EMPTY(&qemu_accel_opts
.head
)) {
2245 char **accel_list
, **tmp
;
2247 if (accelerators
== NULL
) {
2248 /* Select the default accelerator */
2249 bool have_tcg
= accel_find("tcg");
2250 bool have_kvm
= accel_find("kvm");
2252 if (have_tcg
&& have_kvm
) {
2253 if (g_str_has_suffix(progname
, "kvm")) {
2254 /* If the program name ends with "kvm", we prefer KVM */
2255 accelerators
= "kvm:tcg";
2257 accelerators
= "tcg:kvm";
2259 } else if (have_kvm
) {
2260 accelerators
= "kvm";
2261 } else if (have_tcg
) {
2262 accelerators
= "tcg";
2264 error_report("No accelerator selected and"
2265 " no default accelerator available");
2269 accel_list
= g_strsplit(accelerators
, ":", 0);
2271 for (tmp
= accel_list
; *tmp
; tmp
++) {
2273 * Filter invalid accelerators here, to prevent obscenities
2274 * such as "-machine accel=tcg,,thread=single".
2276 if (accel_find(*tmp
)) {
2277 qemu_opts_parse_noisily(qemu_find_opts("accel"), *tmp
, true);
2280 error_report("invalid accelerator %s", *tmp
);
2283 g_strfreev(accel_list
);
2285 if (accelerators
!= NULL
) {
2286 error_report("The -accel and \"-machine accel=\" options are incompatible");
2291 if (!qemu_opts_foreach(qemu_find_opts("accel"),
2292 do_configure_accelerator
, &init_failed
, &error_fatal
)) {
2294 error_report("no accelerator found");
2299 if (init_failed
&& !qtest_chrdev
) {
2300 error_report("falling back to %s", current_accel_name());
2303 if (icount_enabled() && !tcg_enabled()) {
2304 error_report("-icount is not allowed with hardware virtualization");
2309 static void qemu_validate_options(const QDict
*machine_opts
)
2311 const char *kernel_filename
= qdict_get_try_str(machine_opts
, "kernel");
2312 const char *initrd_filename
= qdict_get_try_str(machine_opts
, "initrd");
2313 const char *kernel_cmdline
= qdict_get_try_str(machine_opts
, "append");
2315 if (kernel_filename
== NULL
) {
2316 if (kernel_cmdline
!= NULL
) {
2317 error_report("-append only allowed with -kernel option");
2321 if (initrd_filename
!= NULL
) {
2322 error_report("-initrd only allowed with -kernel option");
2327 if (loadvm
&& preconfig_requested
) {
2328 error_report("'preconfig' and 'loadvm' options are "
2329 "mutually exclusive");
2332 if (incoming
&& preconfig_requested
&& strcmp(incoming
, "defer") != 0) {
2333 error_report("'preconfig' supports '-incoming defer' only");
2337 #ifdef CONFIG_CURSES
2338 if (is_daemonized() && dpy
.type
== DISPLAY_TYPE_CURSES
) {
2339 error_report("curses display cannot be used with -daemonize");
2345 static void qemu_process_sugar_options(void)
2348 QObject
*smp
= qdict_get(machine_opts_dict
, "smp");
2349 if (smp
&& qobject_type(smp
) == QTYPE_QDICT
) {
2350 QObject
*cpus
= qdict_get(qobject_to(QDict
, smp
), "cpus");
2351 if (cpus
&& qobject_type(cpus
) == QTYPE_QSTRING
) {
2352 const char *val
= qstring_get_str(qobject_to(QString
, cpus
));
2353 object_register_sugar_prop("memory-backend", "prealloc-threads",
2357 object_register_sugar_prop("memory-backend", "prealloc", "on", false);
2361 /* -action processing */
2364 * Process all the -action parameters parsed from cmdline.
2366 static int process_runstate_actions(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2368 Error
*local_err
= NULL
;
2369 QDict
*qdict
= qemu_opts_to_qdict(opts
, NULL
);
2370 QObject
*ret
= NULL
;
2371 qmp_marshal_set_action(qdict
, &ret
, &local_err
);
2373 qobject_unref(qdict
);
2375 error_propagate(errp
, local_err
);
2381 static void qemu_process_early_options(void)
2383 qemu_opts_foreach(qemu_find_opts("name"),
2384 parse_name
, NULL
, &error_fatal
);
2386 object_option_foreach_add(object_create_pre_sandbox
);
2388 #ifdef CONFIG_SECCOMP
2389 QemuOptsList
*olist
= qemu_find_opts_err("sandbox", NULL
);
2391 qemu_opts_foreach(olist
, parse_sandbox
, NULL
, &error_fatal
);
2395 if (qemu_opts_foreach(qemu_find_opts("action"),
2396 process_runstate_actions
, NULL
, &error_fatal
)) {
2401 qemu_opts_foreach(qemu_find_opts("add-fd"),
2402 parse_add_fd
, NULL
, &error_fatal
);
2404 qemu_opts_foreach(qemu_find_opts("add-fd"),
2405 cleanup_add_fd
, NULL
, &error_fatal
);
2408 /* Open the logfile at this point and set the log mask if necessary. */
2412 mask
= qemu_str_to_log_mask(log_mask
);
2414 qemu_print_log_usage(stdout
);
2418 qemu_set_log_filename_flags(log_file
, mask
, &error_fatal
);
2421 qemu_add_default_firmwarepath();
2424 static void qemu_process_help_options(void)
2427 * Check for -cpu help and -device help before we call select_machine(),
2428 * which will return an error if the architecture has no default machine
2429 * type and the user did not specify one, so that the user doesn't need
2430 * to say '-cpu help -machine something'.
2432 if (cpu_option
&& is_help_option(cpu_option
)) {
2433 list_cpus(cpu_option
);
2437 if (qemu_opts_foreach(qemu_find_opts("device"),
2438 device_help_func
, NULL
, NULL
)) {
2442 /* -L help lists the data directories and exits. */
2443 if (list_data_dirs
) {
2444 qemu_list_data_dirs();
2449 static void qemu_maybe_daemonize(const char *pid_file
)
2454 rcu_disable_atfork();
2457 char *pid_file_realpath
= NULL
;
2459 if (!qemu_write_pidfile(pid_file
, &err
)) {
2460 error_reportf_err(err
, "cannot create PID file: ");
2464 pid_file_realpath
= g_malloc0(PATH_MAX
);
2465 if (!realpath(pid_file
, pid_file_realpath
)) {
2466 error_report("cannot resolve PID file path: %s: %s",
2467 pid_file
, strerror(errno
));
2472 qemu_unlink_pidfile_notifier
= (struct UnlinkPidfileNotifier
) {
2474 .notify
= qemu_unlink_pidfile
,
2476 .pid_file_realpath
= pid_file_realpath
,
2478 qemu_add_exit_notifier(&qemu_unlink_pidfile_notifier
.notifier
);
2482 static void qemu_init_displays(void)
2486 /* init local displays */
2487 ds
= init_displaystate();
2488 qemu_display_init(ds
, &dpy
);
2490 /* must be after terminal init, SDL library changes signal handlers */
2491 os_setup_signal_handling();
2493 /* init remote displays */
2495 qemu_opts_foreach(qemu_find_opts("vnc"),
2496 vnc_init_func
, NULL
, &error_fatal
);
2500 qemu_spice
.display_init();
2504 static void qemu_init_board(void)
2506 /* process plugin before CPUs are created, but once -smp has been parsed */
2507 qemu_plugin_load_list(&plugin_list
, &error_fatal
);
2509 /* From here on we enter MACHINE_PHASE_INITIALIZED. */
2510 machine_run_board_init(current_machine
, mem_path
, &error_fatal
);
2512 drive_check_orphaned();
2516 if (hax_enabled()) {
2517 /* FIXME: why isn't cpu_synchronize_all_post_init enough? */
2522 static void qemu_create_cli_devices(void)
2528 qemu_opts_foreach(qemu_find_opts("fw_cfg"),
2529 parse_fw_cfg
, fw_cfg_find(), &error_fatal
);
2531 /* init USB devices */
2532 if (machine_usb(current_machine
)) {
2533 if (foreach_device_config(DEV_USB
, usb_parse
) < 0)
2537 /* init generic devices */
2538 rom_set_order_override(FW_CFG_ORDER_OVERRIDE_DEVICE
);
2539 qemu_opts_foreach(qemu_find_opts("device"),
2540 device_init_func
, NULL
, &error_fatal
);
2541 QTAILQ_FOREACH(opt
, &device_opts
, next
) {
2543 loc_push_restore(&opt
->loc
);
2545 * TODO Eventually we should call qmp_device_add() here to make sure it
2546 * behaves the same, but QMP still has to accept incorrectly typed
2547 * options until libvirt is fixed and we want to be strict on the CLI
2548 * from the start, so call qdev_device_add_from_qdict() directly for
2551 dev
= qdev_device_add_from_qdict(opt
->opts
, true, &error_fatal
);
2552 object_unref(OBJECT(dev
));
2555 rom_reset_order_override();
2558 static void qemu_machine_creation_done(void)
2560 MachineState
*machine
= MACHINE(qdev_get_machine());
2562 /* Did we create any drives that we failed to create a device for? */
2563 drive_check_orphaned();
2565 /* Don't warn about the default network setup that you get if
2566 * no command line -net or -netdev options are specified. There
2567 * are two cases that we would otherwise complain about:
2568 * (1) board doesn't support a NIC but the implicit "-net nic"
2570 * (2) CONFIG_SLIRP not set, in which case the implicit "-net nic"
2571 * sets up a nic that isn't connected to anything.
2573 if (!default_net
&& (!qtest_enabled() || has_defaults
)) {
2574 net_check_clients();
2577 qdev_prop_check_globals();
2579 qdev_machine_creation_done();
2583 * Verify that Confidential Guest Support has actually been initialized
2585 assert(machine
->cgs
->ready
);
2588 if (foreach_device_config(DEV_GDB
, gdbserver_start
) < 0) {
2591 if (!vga_interface_created
&& !default_vga
&&
2592 vga_interface_type
!= VGA_NONE
) {
2593 warn_report("A -vga option was passed but this machine "
2594 "type does not use that option; "
2595 "No VGA device has been created");
2599 void qmp_x_exit_preconfig(Error
**errp
)
2601 if (phase_check(PHASE_MACHINE_INITIALIZED
)) {
2602 error_setg(errp
, "The command is permitted only before machine initialization");
2607 qemu_create_cli_devices();
2608 qemu_machine_creation_done();
2611 load_snapshot(loadvm
, NULL
, false, NULL
, &error_fatal
);
2613 if (replay_mode
!= REPLAY_MODE_NONE
) {
2614 replay_vmstate_init();
2618 Error
*local_err
= NULL
;
2619 if (strcmp(incoming
, "defer") != 0) {
2620 qmp_migrate_incoming(incoming
, &local_err
);
2622 error_reportf_err(local_err
, "-incoming %s: ", incoming
);
2626 } else if (autostart
) {
2631 void qemu_init(int argc
, char **argv
)
2634 QemuOpts
*icount_opts
= NULL
, *accel_opts
= NULL
;
2635 QemuOptsList
*olist
;
2638 MachineClass
*machine_class
;
2639 bool userconfig
= true;
2640 FILE *vmstate_dump_file
= NULL
;
2642 qemu_add_opts(&qemu_drive_opts
);
2643 qemu_add_drive_opts(&qemu_legacy_drive_opts
);
2644 qemu_add_drive_opts(&qemu_common_drive_opts
);
2645 qemu_add_drive_opts(&qemu_drive_opts
);
2646 qemu_add_drive_opts(&bdrv_runtime_opts
);
2647 qemu_add_opts(&qemu_chardev_opts
);
2648 qemu_add_opts(&qemu_device_opts
);
2649 qemu_add_opts(&qemu_netdev_opts
);
2650 qemu_add_opts(&qemu_nic_opts
);
2651 qemu_add_opts(&qemu_net_opts
);
2652 qemu_add_opts(&qemu_rtc_opts
);
2653 qemu_add_opts(&qemu_global_opts
);
2654 qemu_add_opts(&qemu_mon_opts
);
2655 qemu_add_opts(&qemu_trace_opts
);
2656 qemu_plugin_add_opts();
2657 qemu_add_opts(&qemu_option_rom_opts
);
2658 qemu_add_opts(&qemu_accel_opts
);
2659 qemu_add_opts(&qemu_mem_opts
);
2660 qemu_add_opts(&qemu_smp_opts
);
2661 qemu_add_opts(&qemu_boot_opts
);
2662 qemu_add_opts(&qemu_add_fd_opts
);
2663 qemu_add_opts(&qemu_object_opts
);
2664 qemu_add_opts(&qemu_tpmdev_opts
);
2665 qemu_add_opts(&qemu_overcommit_opts
);
2666 qemu_add_opts(&qemu_msg_opts
);
2667 qemu_add_opts(&qemu_name_opts
);
2668 qemu_add_opts(&qemu_numa_opts
);
2669 qemu_add_opts(&qemu_icount_opts
);
2670 qemu_add_opts(&qemu_semihosting_config_opts
);
2671 qemu_add_opts(&qemu_fw_cfg_opts
);
2672 qemu_add_opts(&qemu_action_opts
);
2673 module_call_init(MODULE_INIT_OPTS
);
2675 error_init(argv
[0]);
2676 qemu_init_exec_dir(argv
[0]);
2678 qemu_init_arch_modules();
2680 qemu_init_subsystems();
2682 /* first pass of option parsing */
2684 while (optind
< argc
) {
2685 if (argv
[optind
][0] != '-') {
2689 const QEMUOption
*popt
;
2691 popt
= lookup_opt(argc
, argv
, &optarg
, &optind
);
2692 switch (popt
->index
) {
2693 case QEMU_OPTION_nouserconfig
:
2700 machine_opts_dict
= qdict_new();
2702 qemu_read_default_config_file(&error_fatal
);
2705 /* second pass of option parsing */
2710 if (argv
[optind
][0] != '-') {
2711 loc_set_cmdline(argv
, optind
, 1);
2712 drive_add(IF_DEFAULT
, 0, argv
[optind
++], HD_OPTS
);
2714 const QEMUOption
*popt
;
2716 popt
= lookup_opt(argc
, argv
, &optarg
, &optind
);
2717 if (!(popt
->arch_mask
& arch_type
)) {
2718 error_report("Option not supported for this target");
2721 switch(popt
->index
) {
2722 case QEMU_OPTION_cpu
:
2723 /* hw initialization will check this */
2724 cpu_option
= optarg
;
2726 case QEMU_OPTION_hda
:
2727 case QEMU_OPTION_hdb
:
2728 case QEMU_OPTION_hdc
:
2729 case QEMU_OPTION_hdd
:
2730 drive_add(IF_DEFAULT
, popt
->index
- QEMU_OPTION_hda
, optarg
,
2733 case QEMU_OPTION_blockdev
:
2736 BlockdevOptionsQueueEntry
*bdo
;
2738 v
= qobject_input_visitor_new_str(optarg
, "driver",
2741 bdo
= g_new(BlockdevOptionsQueueEntry
, 1);
2742 visit_type_BlockdevOptions(v
, NULL
, &bdo
->bdo
,
2745 loc_save(&bdo
->loc
);
2746 QSIMPLEQ_INSERT_TAIL(&bdo_queue
, bdo
, entry
);
2749 case QEMU_OPTION_drive
:
2750 opts
= qemu_opts_parse_noisily(qemu_find_opts("drive"),
2756 case QEMU_OPTION_set
:
2757 qemu_set_option(optarg
, &error_fatal
);
2759 case QEMU_OPTION_global
:
2760 if (qemu_global_option(optarg
) != 0)
2763 case QEMU_OPTION_mtdblock
:
2764 drive_add(IF_MTD
, -1, optarg
, MTD_OPTS
);
2766 case QEMU_OPTION_sd
:
2767 drive_add(IF_SD
, -1, optarg
, SD_OPTS
);
2769 case QEMU_OPTION_pflash
:
2770 drive_add(IF_PFLASH
, -1, optarg
, PFLASH_OPTS
);
2772 case QEMU_OPTION_snapshot
:
2774 Error
*blocker
= NULL
;
2776 error_setg(&blocker
, QERR_REPLAY_NOT_SUPPORTED
,
2778 replay_add_blocker(blocker
);
2781 case QEMU_OPTION_numa
:
2782 opts
= qemu_opts_parse_noisily(qemu_find_opts("numa"),
2788 case QEMU_OPTION_display
:
2789 parse_display(optarg
);
2791 case QEMU_OPTION_nographic
:
2792 qdict_put_str(machine_opts_dict
, "graphics", "off");
2794 dpy
.type
= DISPLAY_TYPE_NONE
;
2796 case QEMU_OPTION_portrait
:
2797 graphic_rotate
= 90;
2799 case QEMU_OPTION_rotate
:
2800 graphic_rotate
= strtol(optarg
, (char **) &optarg
, 10);
2801 if (graphic_rotate
!= 0 && graphic_rotate
!= 90 &&
2802 graphic_rotate
!= 180 && graphic_rotate
!= 270) {
2803 error_report("only 90, 180, 270 deg rotation is available");
2807 case QEMU_OPTION_kernel
:
2808 qdict_put_str(machine_opts_dict
, "kernel", optarg
);
2810 case QEMU_OPTION_initrd
:
2811 qdict_put_str(machine_opts_dict
, "initrd", optarg
);
2813 case QEMU_OPTION_append
:
2814 qdict_put_str(machine_opts_dict
, "append", optarg
);
2816 case QEMU_OPTION_dtb
:
2817 qdict_put_str(machine_opts_dict
, "dtb", optarg
);
2819 case QEMU_OPTION_cdrom
:
2820 drive_add(IF_DEFAULT
, 2, optarg
, CDROM_OPTS
);
2822 case QEMU_OPTION_boot
:
2823 machine_parse_property_opt(qemu_find_opts("boot-opts"), "boot", optarg
);
2825 case QEMU_OPTION_fda
:
2826 case QEMU_OPTION_fdb
:
2827 drive_add(IF_FLOPPY
, popt
->index
- QEMU_OPTION_fda
,
2830 case QEMU_OPTION_no_fd_bootchk
:
2833 case QEMU_OPTION_netdev
:
2835 if (netdev_is_modern(optarg
)) {
2836 netdev_parse_modern(optarg
);
2838 net_client_parse(qemu_find_opts("netdev"), optarg
);
2841 case QEMU_OPTION_nic
:
2843 net_client_parse(qemu_find_opts("nic"), optarg
);
2845 case QEMU_OPTION_net
:
2847 net_client_parse(qemu_find_opts("net"), optarg
);
2849 #ifdef CONFIG_LIBISCSI
2850 case QEMU_OPTION_iscsi
:
2851 opts
= qemu_opts_parse_noisily(qemu_find_opts("iscsi"),
2858 case QEMU_OPTION_audio_help
:
2859 audio_legacy_help();
2862 case QEMU_OPTION_audiodev
:
2863 audio_parse_option(optarg
);
2865 case QEMU_OPTION_audio
: {
2868 Audiodev
*dev
= NULL
;
2870 QDict
*dict
= keyval_parse(optarg
, "driver", &help
, &error_fatal
);
2871 if (help
|| (qdict_haskey(dict
, "driver") &&
2872 is_help_option(qdict_get_str(dict
, "driver")))) {
2876 if (!qdict_haskey(dict
, "id")) {
2877 qdict_put_str(dict
, "id", "audiodev0");
2879 if (!qdict_haskey(dict
, "model")) {
2880 error_setg(&error_fatal
, "Parameter 'model' is missing");
2882 model
= g_strdup(qdict_get_str(dict
, "model"));
2883 qdict_del(dict
, "model");
2884 if (is_help_option(model
)) {
2885 show_valid_soundhw();
2888 v
= qobject_input_visitor_new_keyval(QOBJECT(dict
));
2889 qobject_unref(dict
);
2890 visit_type_Audiodev(v
, NULL
, &dev
, &error_fatal
);
2893 select_soundhw(model
, dev
->id
);
2900 case QEMU_OPTION_version
:
2905 opts
= qemu_opts_parse_noisily(qemu_find_opts("memory"), optarg
, true);
2911 case QEMU_OPTION_tpmdev
:
2912 if (tpm_config_parse(qemu_find_opts("tpmdev"), optarg
) < 0) {
2917 case QEMU_OPTION_mempath
:
2920 case QEMU_OPTION_mem_prealloc
:
2929 case QEMU_OPTION_DFILTER
:
2930 qemu_set_dfilter_ranges(optarg
, &error_fatal
);
2932 #if defined(CONFIG_TCG) && defined(CONFIG_LINUX)
2933 case QEMU_OPTION_perfmap
:
2934 perf_enable_perfmap();
2936 case QEMU_OPTION_jitdump
:
2937 perf_enable_jitdump();
2940 case QEMU_OPTION_seed
:
2941 qemu_guest_random_seed_main(optarg
, &error_fatal
);
2944 add_device_config(DEV_GDB
, "tcp::" DEFAULT_GDBSTUB_PORT
);
2946 case QEMU_OPTION_gdb
:
2947 add_device_config(DEV_GDB
, optarg
);
2950 if (is_help_option(optarg
)) {
2951 list_data_dirs
= true;
2953 qemu_add_data_dir(g_strdup(optarg
));
2956 case QEMU_OPTION_bios
:
2957 qdict_put_str(machine_opts_dict
, "firmware", optarg
);
2959 case QEMU_OPTION_singlestep
:
2966 keyboard_layout
= optarg
;
2968 case QEMU_OPTION_vga
:
2977 w
= strtol(p
, (char **)&p
, 10);
2980 error_report("invalid resolution or depth");
2986 h
= strtol(p
, (char **)&p
, 10);
2991 depth
= strtol(p
, (char **)&p
, 10);
2992 if (depth
!= 1 && depth
!= 2 && depth
!= 4 &&
2993 depth
!= 8 && depth
!= 15 && depth
!= 16 &&
2994 depth
!= 24 && depth
!= 32)
2996 } else if (*p
== '\0') {
2997 depth
= graphic_depth
;
3004 graphic_depth
= depth
;
3007 case QEMU_OPTION_echr
:
3010 term_escape_char
= strtol(optarg
, &r
, 0);
3012 printf("Bad argument to echr\n");
3015 case QEMU_OPTION_monitor
:
3016 default_monitor
= 0;
3017 if (strncmp(optarg
, "none", 4)) {
3018 monitor_parse(optarg
, "readline", false);
3021 case QEMU_OPTION_qmp
:
3022 monitor_parse(optarg
, "control", false);
3023 default_monitor
= 0;
3025 case QEMU_OPTION_qmp_pretty
:
3026 monitor_parse(optarg
, "control", true);
3027 default_monitor
= 0;
3029 case QEMU_OPTION_mon
:
3030 opts
= qemu_opts_parse_noisily(qemu_find_opts("mon"), optarg
,
3035 default_monitor
= 0;
3037 case QEMU_OPTION_chardev
:
3038 opts
= qemu_opts_parse_noisily(qemu_find_opts("chardev"),
3044 case QEMU_OPTION_fsdev
:
3045 olist
= qemu_find_opts("fsdev");
3047 error_report("fsdev support is disabled");
3050 opts
= qemu_opts_parse_noisily(olist
, optarg
, true);
3055 case QEMU_OPTION_virtfs
: {
3058 const char *writeout
, *sock_fd
, *socket
, *path
, *security_model
,
3061 olist
= qemu_find_opts("virtfs");
3063 error_report("virtfs support is disabled");
3066 opts
= qemu_opts_parse_noisily(olist
, optarg
, true);
3071 if (qemu_opt_get(opts
, "fsdriver") == NULL
||
3072 qemu_opt_get(opts
, "mount_tag") == NULL
) {
3073 error_report("Usage: -virtfs fsdriver,mount_tag=tag");
3076 fsdev
= qemu_opts_create(qemu_find_opts("fsdev"),
3077 qemu_opts_id(opts
) ?:
3078 qemu_opt_get(opts
, "mount_tag"),
3081 error_report("duplicate or invalid fsdev id: %s",
3082 qemu_opt_get(opts
, "mount_tag"));
3086 writeout
= qemu_opt_get(opts
, "writeout");
3088 #ifdef CONFIG_SYNC_FILE_RANGE
3089 qemu_opt_set(fsdev
, "writeout", writeout
, &error_abort
);
3091 error_report("writeout=immediate not supported "
3092 "on this platform");
3096 qemu_opt_set(fsdev
, "fsdriver",
3097 qemu_opt_get(opts
, "fsdriver"), &error_abort
);
3098 path
= qemu_opt_get(opts
, "path");
3100 qemu_opt_set(fsdev
, "path", path
, &error_abort
);
3102 security_model
= qemu_opt_get(opts
, "security_model");
3103 if (security_model
) {
3104 qemu_opt_set(fsdev
, "security_model", security_model
,
3107 socket
= qemu_opt_get(opts
, "socket");
3109 qemu_opt_set(fsdev
, "socket", socket
, &error_abort
);
3111 sock_fd
= qemu_opt_get(opts
, "sock_fd");
3113 qemu_opt_set(fsdev
, "sock_fd", sock_fd
, &error_abort
);
3116 qemu_opt_set_bool(fsdev
, "readonly",
3117 qemu_opt_get_bool(opts
, "readonly", 0),
3119 multidevs
= qemu_opt_get(opts
, "multidevs");
3121 qemu_opt_set(fsdev
, "multidevs", multidevs
, &error_abort
);
3123 device
= qemu_opts_create(qemu_find_opts("device"), NULL
, 0,
3125 qemu_opt_set(device
, "driver", "virtio-9p-pci", &error_abort
);
3126 qemu_opt_set(device
, "fsdev",
3127 qemu_opts_id(fsdev
), &error_abort
);
3128 qemu_opt_set(device
, "mount_tag",
3129 qemu_opt_get(opts
, "mount_tag"), &error_abort
);
3132 case QEMU_OPTION_serial
:
3133 add_device_config(DEV_SERIAL
, optarg
);
3135 if (strncmp(optarg
, "mon:", 4) == 0) {
3136 default_monitor
= 0;
3139 case QEMU_OPTION_action
:
3140 olist
= qemu_find_opts("action");
3141 if (!qemu_opts_parse_noisily(olist
, optarg
, false)) {
3145 case QEMU_OPTION_watchdog_action
: {
3147 opts
= qemu_opts_create(qemu_find_opts("action"), NULL
, 0, &error_abort
);
3148 qemu_opt_set(opts
, "watchdog", optarg
, &error_abort
);
3151 case QEMU_OPTION_parallel
:
3152 add_device_config(DEV_PARALLEL
, optarg
);
3153 default_parallel
= 0;
3154 if (strncmp(optarg
, "mon:", 4) == 0) {
3155 default_monitor
= 0;
3158 case QEMU_OPTION_debugcon
:
3159 add_device_config(DEV_DEBUGCON
, optarg
);
3161 case QEMU_OPTION_loadvm
:
3164 case QEMU_OPTION_full_screen
:
3165 dpy
.has_full_screen
= true;
3166 dpy
.full_screen
= true;
3168 case QEMU_OPTION_pidfile
:
3171 case QEMU_OPTION_win2k_hack
:
3172 win2k_install_hack
= 1;
3174 case QEMU_OPTION_acpitable
:
3175 opts
= qemu_opts_parse_noisily(qemu_find_opts("acpi"),
3180 acpi_table_add(opts
, &error_fatal
);
3182 case QEMU_OPTION_smbios
:
3183 opts
= qemu_opts_parse_noisily(qemu_find_opts("smbios"),
3188 smbios_entry_add(opts
, &error_fatal
);
3190 case QEMU_OPTION_fwcfg
:
3191 opts
= qemu_opts_parse_noisily(qemu_find_opts("fw_cfg"),
3197 case QEMU_OPTION_preconfig
:
3198 preconfig_requested
= true;
3200 case QEMU_OPTION_enable_kvm
:
3201 qdict_put_str(machine_opts_dict
, "accel", "kvm");
3204 case QEMU_OPTION_machine
:
3208 keyval_parse_into(machine_opts_dict
, optarg
, "type", &help
, &error_fatal
);
3210 machine_help_func(machine_opts_dict
);
3215 case QEMU_OPTION_accel
:
3216 accel_opts
= qemu_opts_parse_noisily(qemu_find_opts("accel"),
3218 optarg
= qemu_opt_get(accel_opts
, "accel");
3219 if (!optarg
|| is_help_option(optarg
)) {
3220 printf("Accelerators supported in QEMU binary:\n");
3221 GSList
*el
, *accel_list
= object_class_get_list(TYPE_ACCEL
,
3223 for (el
= accel_list
; el
; el
= el
->next
) {
3224 gchar
*typename
= g_strdup(object_class_get_name(
3225 OBJECT_CLASS(el
->data
)));
3226 /* omit qtest which is used for tests only */
3227 if (g_strcmp0(typename
, ACCEL_CLASS_NAME("qtest")) &&
3228 g_str_has_suffix(typename
, ACCEL_CLASS_SUFFIX
)) {
3229 gchar
**optname
= g_strsplit(typename
,
3230 ACCEL_CLASS_SUFFIX
, 0);
3231 printf("%s\n", optname
[0]);
3232 g_strfreev(optname
);
3236 g_slist_free(accel_list
);
3240 case QEMU_OPTION_usb
:
3241 qdict_put_str(machine_opts_dict
, "usb", "on");
3243 case QEMU_OPTION_usbdevice
:
3244 qdict_put_str(machine_opts_dict
, "usb", "on");
3245 add_device_config(DEV_USB
, optarg
);
3247 case QEMU_OPTION_device
:
3248 if (optarg
[0] == '{') {
3249 QObject
*obj
= qobject_from_json(optarg
, &error_fatal
);
3250 DeviceOption
*opt
= g_new0(DeviceOption
, 1);
3251 opt
->opts
= qobject_to(QDict
, obj
);
3252 loc_save(&opt
->loc
);
3253 assert(opt
->opts
!= NULL
);
3254 QTAILQ_INSERT_TAIL(&device_opts
, opt
, next
);
3256 if (!qemu_opts_parse_noisily(qemu_find_opts("device"),
3262 case QEMU_OPTION_smp
:
3263 machine_parse_property_opt(qemu_find_opts("smp-opts"),
3266 case QEMU_OPTION_vnc
:
3269 case QEMU_OPTION_no_acpi
:
3270 qdict_put_str(machine_opts_dict
, "acpi", "off");
3272 case QEMU_OPTION_no_hpet
:
3273 warn_report("-no-hpet is deprecated, use '-machine hpet=off' instead");
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 /* Transfer QemuOpts options into machine options */
3543 parse_memory_options();
3545 qemu_create_machine(machine_opts_dict
);
3549 qemu_disable_default_devices();
3550 qemu_create_default_devices();
3551 qemu_create_early_backends();
3553 qemu_apply_legacy_machine_options(machine_opts_dict
);
3554 qemu_apply_machine_options(machine_opts_dict
);
3555 qobject_unref(machine_opts_dict
);
3556 phase_advance(PHASE_MACHINE_CREATED
);
3559 * Note: uses machine properties such as kernel-irqchip, must run
3560 * after qemu_apply_machine_options.
3562 configure_accelerators(argv
[0]);
3563 phase_advance(PHASE_ACCEL_CREATED
);
3566 * Beware, QOM objects created before this point miss global and
3567 * compat properties.
3569 * Global properties get set up by qdev_prop_register_global(),
3570 * called from user_register_global_props(), and certain option
3571 * desugaring. Also in CPU feature desugaring (buried in
3572 * parse_cpu_option()), which happens below this point, but may
3573 * only target the CPU type, which can only be created after
3574 * parse_cpu_option() returned the type.
3576 * Machine compat properties: object_set_machine_compat_props().
3577 * Accelerator compat props: object_set_accelerator_compat_props(),
3578 * called from do_configure_accelerator().
3581 machine_class
= MACHINE_GET_CLASS(current_machine
);
3582 if (!qtest_enabled() && machine_class
->deprecation_reason
) {
3583 warn_report("Machine type '%s' is deprecated: %s",
3584 machine_class
->name
, machine_class
->deprecation_reason
);
3588 * Note: creates a QOM object, must run only after global and
3589 * compat properties have been set up.
3591 migration_object_init();
3593 qemu_create_late_backends();
3595 /* parse features once if machine provides default cpu_type */
3596 current_machine
->cpu_type
= machine_class
->default_cpu_type
;
3598 current_machine
->cpu_type
= parse_cpu_option(cpu_option
);
3600 /* NB: for machine none cpu_type could STILL be NULL here! */
3602 qemu_resolve_machine_memdev();
3603 parse_numa_opts(current_machine
);
3605 if (vmstate_dump_file
) {
3607 module_load_qom_all();
3608 dump_vmstate_json_to_file(vmstate_dump_file
);
3612 if (!preconfig_requested
) {
3613 qmp_x_exit_preconfig(&error_fatal
);
3615 qemu_init_displays();
3616 accel_setup_post(current_machine
);