4 * Copyright (c) 2003-2008 Fabrice Bellard
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 #include "qemu/osdep.h"
26 #include "qemu-common.h"
27 #include "qemu/datadir.h"
28 #include "qemu/units.h"
29 #include "exec/cpu-common.h"
30 #include "hw/qdev-properties.h"
31 #include "qapi/compat-policy.h"
32 #include "qapi/error.h"
33 #include "qapi/qmp/qdict.h"
34 #include "qapi/qmp/qjson.h"
35 #include "qemu-version.h"
36 #include "qemu/cutils.h"
37 #include "qemu/help_option.h"
38 #include "qemu/uuid.h"
39 #include "sysemu/reset.h"
40 #include "sysemu/runstate.h"
41 #include "sysemu/runstate-action.h"
42 #include "sysemu/seccomp.h"
43 #include "sysemu/tcg.h"
44 #include "sysemu/xen.h"
46 #include "qemu/error-report.h"
47 #include "qemu/sockets.h"
48 #include "qemu/accel.h"
50 #include "hw/isa/isa.h"
51 #include "hw/scsi/scsi.h"
52 #include "hw/display/vga.h"
53 #include "sysemu/watchdog.h"
54 #include "hw/firmware/smbios.h"
55 #include "hw/acpi/acpi.h"
56 #include "hw/xen/xen.h"
57 #include "hw/loader.h"
58 #include "monitor/qdev.h"
60 #include "net/slirp.h"
61 #include "monitor/monitor.h"
62 #include "ui/console.h"
64 #include "sysemu/sysemu.h"
65 #include "sysemu/numa.h"
66 #include "sysemu/hostmem.h"
67 #include "exec/gdbstub.h"
68 #include "qemu/timer.h"
69 #include "chardev/char.h"
70 #include "qemu/bitmap.h"
72 #include "sysemu/blockdev.h"
73 #include "hw/block/block.h"
74 #include "hw/i386/x86.h"
75 #include "hw/i386/pc.h"
76 #include "migration/misc.h"
77 #include "migration/snapshot.h"
78 #include "sysemu/tpm.h"
79 #include "sysemu/dma.h"
80 #include "hw/audio/soundhw.h"
81 #include "audio/audio.h"
82 #include "sysemu/cpus.h"
83 #include "sysemu/cpu-timers.h"
84 #include "migration/colo.h"
85 #include "migration/postcopy-ram.h"
86 #include "sysemu/kvm.h"
87 #include "sysemu/hax.h"
88 #include "qapi/qobject-input-visitor.h"
89 #include "qemu/option.h"
90 #include "qemu/config-file.h"
91 #include "qemu/qemu-options.h"
92 #include "qemu/main-loop.h"
94 #include "fsdev/qemu-fsdev.h"
96 #include "sysemu/qtest.h"
98 #include "disas/disas.h"
101 #include "trace/control.h"
102 #include "qemu/plugin.h"
103 #include "qemu/queue.h"
104 #include "sysemu/arch_init.h"
105 #include "exec/confidential-guest-support.h"
107 #include "ui/qemu-spice.h"
108 #include "qapi/string-input-visitor.h"
109 #include "qapi/opts-visitor.h"
110 #include "qapi/clone-visitor.h"
111 #include "qom/object_interfaces.h"
112 #include "semihosting/semihost.h"
113 #include "crypto/init.h"
114 #include "sysemu/replay.h"
115 #include "qapi/qapi-events-run-state.h"
116 #include "qapi/qapi-visit-block-core.h"
117 #include "qapi/qapi-visit-compat.h"
118 #include "qapi/qapi-visit-ui.h"
119 #include "qapi/qapi-commands-block-core.h"
120 #include "qapi/qapi-commands-migration.h"
121 #include "qapi/qapi-commands-misc.h"
122 #include "qapi/qapi-visit-qom.h"
123 #include "qapi/qapi-commands-ui.h"
124 #include "qapi/qmp/qdict.h"
125 #include "qapi/qmp/qerror.h"
126 #include "sysemu/iothread.h"
127 #include "qemu/guest-random.h"
129 #include "config-host.h"
131 #define MAX_VIRTIO_CONSOLES 1
133 typedef struct BlockdevOptionsQueueEntry
{
134 BlockdevOptions
*bdo
;
136 QSIMPLEQ_ENTRY(BlockdevOptionsQueueEntry
) entry
;
137 } BlockdevOptionsQueueEntry
;
139 typedef QSIMPLEQ_HEAD(, BlockdevOptionsQueueEntry
) BlockdevOptionsQueue
;
141 typedef struct ObjectOption
{
143 QTAILQ_ENTRY(ObjectOption
) next
;
146 static const char *cpu_option
;
147 static const char *mem_path
;
148 static const char *incoming
;
149 static const char *loadvm
;
150 static const char *accelerators
;
151 static QDict
*machine_opts_dict
;
152 static QTAILQ_HEAD(, ObjectOption
) object_opts
= QTAILQ_HEAD_INITIALIZER(object_opts
);
153 static ram_addr_t maxram_size
;
154 static uint64_t ram_slots
;
155 static int display_remote
;
157 static bool preconfig_requested
;
158 static QemuPluginList plugin_list
= QTAILQ_HEAD_INITIALIZER(plugin_list
);
159 static BlockdevOptionsQueue bdo_queue
= QSIMPLEQ_HEAD_INITIALIZER(bdo_queue
);
160 static bool nographic
= false;
161 static int mem_prealloc
; /* force preallocation of physical target memory */
162 static ram_addr_t ram_size
;
163 static const char *vga_model
= NULL
;
164 static DisplayOptions dpy
;
165 static int num_serial_hds
;
166 static Chardev
**serial_hds
;
167 static const char *log_mask
;
168 static const char *log_file
;
169 static bool list_data_dirs
;
170 static const char *watchdog
;
171 static const char *qtest_chrdev
;
172 static const char *qtest_log
;
174 static int has_defaults
= 1;
175 static int default_serial
= 1;
176 static int default_parallel
= 1;
177 static int default_monitor
= 1;
178 static int default_floppy
= 1;
179 static int default_cdrom
= 1;
180 static int default_sdcard
= 1;
181 static int default_vga
= 1;
182 static int default_net
= 1;
188 { .driver
= "isa-serial", .flag
= &default_serial
},
189 { .driver
= "isa-parallel", .flag
= &default_parallel
},
190 { .driver
= "isa-fdc", .flag
= &default_floppy
},
191 { .driver
= "floppy", .flag
= &default_floppy
},
192 { .driver
= "ide-cd", .flag
= &default_cdrom
},
193 { .driver
= "ide-hd", .flag
= &default_cdrom
},
194 { .driver
= "scsi-cd", .flag
= &default_cdrom
},
195 { .driver
= "scsi-hd", .flag
= &default_cdrom
},
196 { .driver
= "VGA", .flag
= &default_vga
},
197 { .driver
= "isa-vga", .flag
= &default_vga
},
198 { .driver
= "cirrus-vga", .flag
= &default_vga
},
199 { .driver
= "isa-cirrus-vga", .flag
= &default_vga
},
200 { .driver
= "vmware-svga", .flag
= &default_vga
},
201 { .driver
= "qxl-vga", .flag
= &default_vga
},
202 { .driver
= "virtio-vga", .flag
= &default_vga
},
203 { .driver
= "ati-vga", .flag
= &default_vga
},
204 { .driver
= "vhost-user-vga", .flag
= &default_vga
},
205 { .driver
= "virtio-vga-gl", .flag
= &default_vga
},
208 static QemuOptsList qemu_rtc_opts
= {
210 .head
= QTAILQ_HEAD_INITIALIZER(qemu_rtc_opts
.head
),
215 .type
= QEMU_OPT_STRING
,
218 .type
= QEMU_OPT_STRING
,
221 .type
= QEMU_OPT_STRING
,
223 { /* end of list */ }
227 static QemuOptsList qemu_option_rom_opts
= {
228 .name
= "option-rom",
229 .implied_opt_name
= "romfile",
230 .head
= QTAILQ_HEAD_INITIALIZER(qemu_option_rom_opts
.head
),
234 .type
= QEMU_OPT_NUMBER
,
237 .type
= QEMU_OPT_STRING
,
239 { /* end of list */ }
243 static QemuOptsList qemu_accel_opts
= {
245 .implied_opt_name
= "accel",
246 .head
= QTAILQ_HEAD_INITIALIZER(qemu_accel_opts
.head
),
249 * no elements => accept any
250 * sanity checking will happen later
251 * when setting accelerator properties
257 static QemuOptsList qemu_boot_opts
= {
259 .implied_opt_name
= "order",
261 .head
= QTAILQ_HEAD_INITIALIZER(qemu_boot_opts
.head
),
265 .type
= QEMU_OPT_STRING
,
268 .type
= QEMU_OPT_STRING
,
271 .type
= QEMU_OPT_BOOL
,
274 .type
= QEMU_OPT_STRING
,
276 .name
= "splash-time",
277 .type
= QEMU_OPT_NUMBER
,
279 .name
= "reboot-timeout",
280 .type
= QEMU_OPT_NUMBER
,
283 .type
= QEMU_OPT_BOOL
,
289 static QemuOptsList qemu_add_fd_opts
= {
291 .head
= QTAILQ_HEAD_INITIALIZER(qemu_add_fd_opts
.head
),
295 .type
= QEMU_OPT_NUMBER
,
296 .help
= "file descriptor of which a duplicate is added to fd set",
299 .type
= QEMU_OPT_NUMBER
,
300 .help
= "ID of the fd set to add fd to",
303 .type
= QEMU_OPT_STRING
,
304 .help
= "free-form string used to describe fd",
306 { /* end of list */ }
310 static QemuOptsList qemu_object_opts
= {
312 .implied_opt_name
= "qom-type",
313 .head
= QTAILQ_HEAD_INITIALIZER(qemu_object_opts
.head
),
319 static QemuOptsList qemu_tpmdev_opts
= {
321 .implied_opt_name
= "type",
322 .head
= QTAILQ_HEAD_INITIALIZER(qemu_tpmdev_opts
.head
),
324 /* options are defined in the TPM backends */
325 { /* end of list */ }
329 static QemuOptsList qemu_overcommit_opts
= {
330 .name
= "overcommit",
331 .head
= QTAILQ_HEAD_INITIALIZER(qemu_overcommit_opts
.head
),
335 .type
= QEMU_OPT_BOOL
,
339 .type
= QEMU_OPT_BOOL
,
341 { /* end of list */ }
345 static QemuOptsList qemu_msg_opts
= {
347 .head
= QTAILQ_HEAD_INITIALIZER(qemu_msg_opts
.head
),
351 .type
= QEMU_OPT_BOOL
,
354 .name
= "guest-name",
355 .type
= QEMU_OPT_BOOL
,
356 .help
= "Prepends guest name for error messages but only if "
357 "-name guest is set otherwise option is ignored\n",
359 { /* end of list */ }
363 static QemuOptsList qemu_name_opts
= {
365 .implied_opt_name
= "guest",
367 .head
= QTAILQ_HEAD_INITIALIZER(qemu_name_opts
.head
),
371 .type
= QEMU_OPT_STRING
,
372 .help
= "Sets the name of the guest.\n"
373 "This name will be displayed in the SDL window caption.\n"
374 "The name will also be used for the VNC server",
377 .type
= QEMU_OPT_STRING
,
378 .help
= "Sets the name of the QEMU process, as shown in top etc",
380 .name
= "debug-threads",
381 .type
= QEMU_OPT_BOOL
,
382 .help
= "When enabled, name the individual threads; defaults off.\n"
383 "NOTE: The thread names are for debugging and not a\n"
386 { /* End of list */ }
390 static QemuOptsList qemu_mem_opts
= {
392 .implied_opt_name
= "size",
393 .head
= QTAILQ_HEAD_INITIALIZER(qemu_mem_opts
.head
),
398 .type
= QEMU_OPT_SIZE
,
402 .type
= QEMU_OPT_NUMBER
,
406 .type
= QEMU_OPT_SIZE
,
408 { /* end of list */ }
412 static QemuOptsList qemu_icount_opts
= {
414 .implied_opt_name
= "shift",
416 .head
= QTAILQ_HEAD_INITIALIZER(qemu_icount_opts
.head
),
420 .type
= QEMU_OPT_STRING
,
423 .type
= QEMU_OPT_BOOL
,
426 .type
= QEMU_OPT_BOOL
,
429 .type
= QEMU_OPT_STRING
,
432 .type
= QEMU_OPT_STRING
,
434 .name
= "rrsnapshot",
435 .type
= QEMU_OPT_STRING
,
437 { /* end of list */ }
441 static QemuOptsList qemu_fw_cfg_opts
= {
443 .implied_opt_name
= "name",
444 .head
= QTAILQ_HEAD_INITIALIZER(qemu_fw_cfg_opts
.head
),
448 .type
= QEMU_OPT_STRING
,
449 .help
= "Sets the fw_cfg name of the blob to be inserted",
452 .type
= QEMU_OPT_STRING
,
453 .help
= "Sets the name of the file from which "
454 "the fw_cfg blob will be loaded",
457 .type
= QEMU_OPT_STRING
,
458 .help
= "Sets content of the blob to be inserted from a string",
461 .type
= QEMU_OPT_STRING
,
462 .help
= "Sets id of the object generating the fw_cfg blob "
465 { /* end of list */ }
469 static QemuOptsList qemu_action_opts
= {
472 .head
= QTAILQ_HEAD_INITIALIZER(qemu_action_opts
.head
),
476 .type
= QEMU_OPT_STRING
,
479 .type
= QEMU_OPT_STRING
,
482 .type
= QEMU_OPT_STRING
,
485 .type
= QEMU_OPT_STRING
,
487 { /* end of list */ }
491 const char *qemu_get_vm_name(void)
496 static int default_driver_check(void *opaque
, QemuOpts
*opts
, Error
**errp
)
498 const char *driver
= qemu_opt_get(opts
, "driver");
503 for (i
= 0; i
< ARRAY_SIZE(default_list
); i
++) {
504 if (strcmp(default_list
[i
].driver
, driver
) != 0)
506 *(default_list
[i
].flag
) = 0;
511 static int parse_name(void *opaque
, QemuOpts
*opts
, Error
**errp
)
513 const char *proc_name
;
515 if (qemu_opt_get(opts
, "debug-threads")) {
516 qemu_thread_naming(qemu_opt_get_bool(opts
, "debug-threads", false));
518 qemu_name
= qemu_opt_get(opts
, "guest");
520 proc_name
= qemu_opt_get(opts
, "process");
522 os_set_proc_name(proc_name
);
528 bool defaults_enabled(void)
534 static int parse_add_fd(void *opaque
, QemuOpts
*opts
, Error
**errp
)
536 int fd
, dupfd
, flags
;
538 const char *fd_opaque
= NULL
;
541 fd
= qemu_opt_get_number(opts
, "fd", -1);
542 fdset_id
= qemu_opt_get_number(opts
, "set", -1);
543 fd_opaque
= qemu_opt_get(opts
, "opaque");
546 error_setg(errp
, "fd option is required and must be non-negative");
550 if (fd
<= STDERR_FILENO
) {
551 error_setg(errp
, "fd cannot be a standard I/O stream");
556 * All fds inherited across exec() necessarily have FD_CLOEXEC
557 * clear, while qemu sets FD_CLOEXEC on all other fds used internally.
559 flags
= fcntl(fd
, F_GETFD
);
560 if (flags
== -1 || (flags
& FD_CLOEXEC
)) {
561 error_setg(errp
, "fd is not valid or already in use");
566 error_setg(errp
, "set option is required and must be non-negative");
570 #ifdef F_DUPFD_CLOEXEC
571 dupfd
= fcntl(fd
, F_DUPFD_CLOEXEC
, 0);
575 qemu_set_cloexec(dupfd
);
579 error_setg(errp
, "error duplicating fd: %s", strerror(errno
));
583 /* add the duplicate fd, and optionally the opaque string, to the fd set */
584 fdinfo
= monitor_fdset_add_fd(dupfd
, true, fdset_id
, !!fd_opaque
, fd_opaque
,
591 static int cleanup_add_fd(void *opaque
, QemuOpts
*opts
, Error
**errp
)
595 fd
= qemu_opt_get_number(opts
, "fd", -1);
602 /***********************************************************/
603 /* QEMU Block devices */
605 #define HD_OPTS "media=disk"
606 #define CDROM_OPTS "media=cdrom"
608 #define PFLASH_OPTS ""
612 static int drive_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
614 BlockInterfaceType
*block_default_type
= opaque
;
616 return drive_new(opts
, *block_default_type
, errp
) == NULL
;
619 static int drive_enable_snapshot(void *opaque
, QemuOpts
*opts
, Error
**errp
)
621 if (qemu_opt_get(opts
, "snapshot") == NULL
) {
622 qemu_opt_set(opts
, "snapshot", "on", &error_abort
);
627 static void default_drive(int enable
, int snapshot
, BlockInterfaceType type
,
628 int index
, const char *optstr
)
633 if (!enable
|| drive_get_by_index(type
, index
)) {
637 opts
= drive_add(type
, index
, NULL
, optstr
);
639 drive_enable_snapshot(NULL
, opts
, NULL
);
642 dinfo
= drive_new(opts
, type
, &error_abort
);
643 dinfo
->is_default
= true;
647 static void configure_blockdev(BlockdevOptionsQueue
*bdo_queue
,
648 MachineClass
*machine_class
, int snapshot
)
651 * If the currently selected machine wishes to override the
652 * units-per-bus property of its default HBA interface type, do so
655 if (machine_class
->units_per_default_bus
) {
656 override_max_devs(machine_class
->block_default_type
,
657 machine_class
->units_per_default_bus
);
660 /* open the virtual block devices */
661 while (!QSIMPLEQ_EMPTY(bdo_queue
)) {
662 BlockdevOptionsQueueEntry
*bdo
= QSIMPLEQ_FIRST(bdo_queue
);
664 QSIMPLEQ_REMOVE_HEAD(bdo_queue
, entry
);
665 loc_push_restore(&bdo
->loc
);
666 qmp_blockdev_add(bdo
->bdo
, &error_fatal
);
668 qapi_free_BlockdevOptions(bdo
->bdo
);
672 qemu_opts_foreach(qemu_find_opts("drive"), drive_enable_snapshot
,
675 if (qemu_opts_foreach(qemu_find_opts("drive"), drive_init_func
,
676 &machine_class
->block_default_type
, &error_fatal
)) {
677 /* We printed help */
681 default_drive(default_cdrom
, snapshot
, machine_class
->block_default_type
, 2,
683 default_drive(default_floppy
, snapshot
, IF_FLOPPY
, 0, FD_OPTS
);
684 default_drive(default_sdcard
, snapshot
, IF_SD
, 0, SD_OPTS
);
688 static QemuOptsList qemu_smp_opts
= {
690 .implied_opt_name
= "cpus",
692 .head
= QTAILQ_HEAD_INITIALIZER(qemu_smp_opts
.head
),
696 .type
= QEMU_OPT_NUMBER
,
699 .type
= QEMU_OPT_NUMBER
,
702 .type
= QEMU_OPT_NUMBER
,
705 .type
= QEMU_OPT_NUMBER
,
708 .type
= QEMU_OPT_NUMBER
,
711 .type
= QEMU_OPT_NUMBER
,
717 static void realtime_init(void)
720 if (os_mlock() < 0) {
721 error_report("locking memory failed");
728 static void configure_msg(QemuOpts
*opts
)
730 message_with_timestamp
= qemu_opt_get_bool(opts
, "timestamp", false);
731 error_with_guestname
= qemu_opt_get_bool(opts
, "guest-name", false);
735 /***********************************************************/
738 static int usb_device_add(const char *devname
)
740 USBDevice
*dev
= NULL
;
742 if (!machine_usb(current_machine
)) {
746 dev
= usbdevice_create(devname
);
753 static int usb_parse(const char *cmdline
)
756 r
= usb_device_add(cmdline
);
758 error_report("could not add USB device '%s'", cmdline
);
763 /***********************************************************/
764 /* machine registration */
766 static MachineClass
*find_machine(const char *name
, GSList
*machines
)
770 for (el
= machines
; el
; el
= el
->next
) {
771 MachineClass
*mc
= el
->data
;
773 if (!strcmp(mc
->name
, name
) || !g_strcmp0(mc
->alias
, name
)) {
781 static MachineClass
*find_default_machine(GSList
*machines
)
784 MachineClass
*default_machineclass
= NULL
;
786 for (el
= machines
; el
; el
= el
->next
) {
787 MachineClass
*mc
= el
->data
;
789 if (mc
->is_default
) {
790 assert(default_machineclass
== NULL
&& "Multiple default machines");
791 default_machineclass
= mc
;
795 return default_machineclass
;
798 static void version(void)
800 printf("QEMU emulator version " QEMU_FULL_VERSION
"\n"
801 QEMU_COPYRIGHT
"\n");
804 static void help(int exitcode
)
807 printf("usage: %s [options] [disk_image]\n\n"
808 "'disk_image' is a raw hard disk image for IDE hard disk 0\n\n",
809 error_get_progname());
811 #define DEF(option, opt_arg, opt_enum, opt_help, arch_mask) \
812 if ((arch_mask) & arch_type) \
813 fputs(opt_help, stdout);
815 #define ARCHHEADING(text, arch_mask) \
816 if ((arch_mask) & arch_type) \
817 puts(stringify(text));
819 #define DEFHEADING(text) ARCHHEADING(text, QEMU_ARCH_ALL)
821 #include "qemu-options.def"
823 printf("\nDuring emulation, the following keys are useful:\n"
824 "ctrl-alt-f toggle full screen\n"
825 "ctrl-alt-n switch to virtual console 'n'\n"
826 "ctrl-alt toggle mouse and keyboard grab\n"
828 "When using -nographic, press 'ctrl-a h' to get some help.\n"
830 QEMU_HELP_BOTTOM
"\n");
835 #define HAS_ARG 0x0001
837 typedef struct QEMUOption
{
844 static const QEMUOption qemu_options
[] = {
845 { "h", 0, QEMU_OPTION_h
, QEMU_ARCH_ALL
},
847 #define DEF(option, opt_arg, opt_enum, opt_help, arch_mask) \
848 { option, opt_arg, opt_enum, arch_mask },
849 #define DEFHEADING(text)
850 #define ARCHHEADING(text, arch_mask)
852 #include "qemu-options.def"
856 typedef struct VGAInterfaceInfo
{
857 const char *opt_name
; /* option name */
858 const char *name
; /* human-readable name */
859 /* Class names indicating that support is available.
860 * If no class is specified, the interface is always available */
861 const char *class_names
[2];
864 static const VGAInterfaceInfo vga_interfaces
[VGA_TYPE_MAX
] = {
867 .name
= "no graphic card",
871 .name
= "standard VGA",
872 .class_names
= { "VGA", "isa-vga" },
875 .opt_name
= "cirrus",
876 .name
= "Cirrus VGA",
877 .class_names
= { "cirrus-vga", "isa-cirrus-vga" },
880 .opt_name
= "vmware",
881 .name
= "VMWare SVGA",
882 .class_names
= { "vmware-svga" },
885 .opt_name
= "virtio",
886 .name
= "Virtio VGA",
887 .class_names
= { "virtio-vga" },
892 .class_names
= { "qxl-vga" },
896 .name
= "TCX framebuffer",
897 .class_names
= { "sun-tcx" },
901 .name
= "CG3 framebuffer",
902 .class_names
= { "cgthree" },
906 .name
= "Xen paravirtualized framebuffer",
910 static bool vga_interface_available(VGAInterfaceType t
)
912 const VGAInterfaceInfo
*ti
= &vga_interfaces
[t
];
914 assert(t
< VGA_TYPE_MAX
);
915 return !ti
->class_names
[0] ||
916 module_object_class_by_name(ti
->class_names
[0]) ||
917 module_object_class_by_name(ti
->class_names
[1]);
921 get_default_vga_model(const MachineClass
*machine_class
)
923 if (machine_class
->default_display
) {
924 return machine_class
->default_display
;
925 } else if (vga_interface_available(VGA_CIRRUS
)) {
927 } else if (vga_interface_available(VGA_STD
)) {
934 static void select_vgahw(const MachineClass
*machine_class
, const char *p
)
939 if (g_str_equal(p
, "help")) {
940 const char *def
= get_default_vga_model(machine_class
);
942 for (t
= 0; t
< VGA_TYPE_MAX
; t
++) {
943 const VGAInterfaceInfo
*ti
= &vga_interfaces
[t
];
945 if (vga_interface_available(t
) && ti
->opt_name
) {
946 printf("%-20s %s%s\n", ti
->opt_name
, ti
->name
?: "",
947 g_str_equal(ti
->opt_name
, def
) ? " (default)" : "");
953 assert(vga_interface_type
== VGA_NONE
);
954 for (t
= 0; t
< VGA_TYPE_MAX
; t
++) {
955 const VGAInterfaceInfo
*ti
= &vga_interfaces
[t
];
956 if (ti
->opt_name
&& strstart(p
, ti
->opt_name
, &opts
)) {
957 if (!vga_interface_available(t
)) {
958 error_report("%s not available", ti
->name
);
961 vga_interface_type
= t
;
965 if (t
== VGA_TYPE_MAX
) {
967 error_report("unknown vga type: %s", p
);
973 if (strstart(opts
, ",retrace=", &nextopt
)) {
975 if (strstart(opts
, "dumb", &nextopt
))
976 vga_retrace_method
= VGA_RETRACE_DUMB
;
977 else if (strstart(opts
, "precise", &nextopt
))
978 vga_retrace_method
= VGA_RETRACE_PRECISE
;
979 else goto invalid_vga
;
980 } else goto invalid_vga
;
985 static void parse_display_qapi(const char *optarg
)
987 DisplayOptions
*opts
;
990 v
= qobject_input_visitor_new_str(optarg
, "type", &error_fatal
);
992 visit_type_DisplayOptions(v
, NULL
, &opts
, &error_fatal
);
993 QAPI_CLONE_MEMBERS(DisplayOptions
, &dpy
, opts
);
995 qapi_free_DisplayOptions(opts
);
999 DisplayOptions
*qmp_query_display_options(Error
**errp
)
1001 return QAPI_CLONE(DisplayOptions
, &dpy
);
1004 static void parse_display(const char *p
)
1008 if (is_help_option(p
)) {
1009 qemu_display_help();
1013 if (strstart(p
, "sdl", &opts
)) {
1015 * sdl DisplayType needs hand-crafted parser instead of
1016 * parse_display_qapi() due to some options not in
1017 * DisplayOptions, specifically:
1018 * - ctrl_grab + alt_grab
1019 * Not clear yet what happens to them long-term. Should
1020 * replaced by something better or deprecated and dropped.
1022 #if defined(CONFIG_SDL)
1023 dpy
.type
= DISPLAY_TYPE_SDL
;
1025 const char *nextopt
;
1027 if (strstart(opts
, ",alt_grab=", &nextopt
)) {
1029 if (strstart(opts
, "on", &nextopt
)) {
1031 } else if (strstart(opts
, "off", &nextopt
)) {
1034 goto invalid_sdl_args
;
1036 } else if (strstart(opts
, ",ctrl_grab=", &nextopt
)) {
1038 if (strstart(opts
, "on", &nextopt
)) {
1040 } else if (strstart(opts
, "off", &nextopt
)) {
1043 goto invalid_sdl_args
;
1045 } else if (strstart(opts
, ",window_close=", &nextopt
) ||
1046 strstart(opts
, ",window-close=", &nextopt
)) {
1047 if (strstart(opts
, ",window_close=", NULL
)) {
1048 warn_report("window_close with an underscore is deprecated,"
1049 " please use window-close instead.");
1052 dpy
.has_window_close
= true;
1053 if (strstart(opts
, "on", &nextopt
)) {
1054 dpy
.window_close
= true;
1055 } else if (strstart(opts
, "off", &nextopt
)) {
1056 dpy
.window_close
= false;
1058 goto invalid_sdl_args
;
1060 } else if (strstart(opts
, ",show-cursor=", &nextopt
)) {
1062 dpy
.has_show_cursor
= true;
1063 if (strstart(opts
, "on", &nextopt
)) {
1064 dpy
.show_cursor
= true;
1065 } else if (strstart(opts
, "off", &nextopt
)) {
1066 dpy
.show_cursor
= false;
1068 goto invalid_sdl_args
;
1070 } else if (strstart(opts
, ",gl=", &nextopt
)) {
1073 if (strstart(opts
, "on", &nextopt
)) {
1074 dpy
.gl
= DISPLAYGL_MODE_ON
;
1075 } else if (strstart(opts
, "core", &nextopt
)) {
1076 dpy
.gl
= DISPLAYGL_MODE_CORE
;
1077 } else if (strstart(opts
, "es", &nextopt
)) {
1078 dpy
.gl
= DISPLAYGL_MODE_ES
;
1079 } else if (strstart(opts
, "off", &nextopt
)) {
1080 dpy
.gl
= DISPLAYGL_MODE_OFF
;
1082 goto invalid_sdl_args
;
1086 error_report("invalid SDL option string");
1092 error_report("SDL display supported is not available in this binary");
1095 } else if (strstart(p
, "vnc", &opts
)) {
1097 * vnc isn't a (local) DisplayType but a protocol for remote
1101 vnc_parse(opts
+ 1);
1103 error_report("VNC requires a display argument vnc=<display>");
1107 parse_display_qapi(p
);
1111 static inline bool nonempty_str(const char *str
)
1116 static int parse_fw_cfg(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1120 const char *name
, *file
, *str
, *gen_id
;
1121 FWCfgState
*fw_cfg
= (FWCfgState
*) opaque
;
1123 if (fw_cfg
== NULL
) {
1124 error_setg(errp
, "fw_cfg device not available");
1127 name
= qemu_opt_get(opts
, "name");
1128 file
= qemu_opt_get(opts
, "file");
1129 str
= qemu_opt_get(opts
, "string");
1130 gen_id
= qemu_opt_get(opts
, "gen_id");
1132 /* we need the name, and exactly one of: file, content string, gen_id */
1133 if (!nonempty_str(name
) ||
1134 nonempty_str(file
) + nonempty_str(str
) + nonempty_str(gen_id
) != 1) {
1135 error_setg(errp
, "name, plus exactly one of file,"
1136 " string and gen_id, are needed");
1139 if (strlen(name
) > FW_CFG_MAX_FILE_PATH
- 1) {
1140 error_setg(errp
, "name too long (max. %d char)",
1141 FW_CFG_MAX_FILE_PATH
- 1);
1144 if (nonempty_str(gen_id
)) {
1146 * In this particular case where the content is populated
1147 * internally, the "etc/" namespace protection is relaxed,
1148 * so do not emit a warning.
1150 } else if (strncmp(name
, "opt/", 4) != 0) {
1151 warn_report("externally provided fw_cfg item names "
1152 "should be prefixed with \"opt/\"");
1154 if (nonempty_str(str
)) {
1155 size
= strlen(str
); /* NUL terminator NOT included in fw_cfg blob */
1156 buf
= g_memdup(str
, size
);
1157 } else if (nonempty_str(gen_id
)) {
1158 if (!fw_cfg_add_from_generator(fw_cfg
, name
, gen_id
, errp
)) {
1164 if (!g_file_get_contents(file
, &buf
, &size
, &err
)) {
1165 error_setg(errp
, "can't load %s: %s", file
, err
->message
);
1170 /* For legacy, keep user files in a specific global order. */
1171 fw_cfg_set_order_override(fw_cfg
, FW_CFG_ORDER_OVERRIDE_USER
);
1172 fw_cfg_add_file(fw_cfg
, name
, buf
, size
);
1173 fw_cfg_reset_order_override(fw_cfg
);
1177 static int device_help_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1179 return qdev_device_help(opts
);
1182 static int device_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1186 dev
= qdev_device_add(opts
, errp
);
1187 if (!dev
&& *errp
) {
1188 error_report_err(*errp
);
1191 object_unref(OBJECT(dev
));
1196 static int chardev_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1198 Error
*local_err
= NULL
;
1200 if (!qemu_chr_new_from_opts(opts
, NULL
, &local_err
)) {
1202 error_propagate(errp
, local_err
);
1210 #ifdef CONFIG_VIRTFS
1211 static int fsdev_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1213 return qemu_fsdev_add(opts
, errp
);
1217 static int mon_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1219 return monitor_init_opts(opts
, errp
);
1222 static void monitor_parse(const char *optarg
, const char *mode
, bool pretty
)
1224 static int monitor_device_index
= 0;
1229 if (strstart(optarg
, "chardev:", &p
)) {
1230 snprintf(label
, sizeof(label
), "%s", p
);
1232 snprintf(label
, sizeof(label
), "compat_monitor%d",
1233 monitor_device_index
);
1234 opts
= qemu_chr_parse_compat(label
, optarg
, true);
1236 error_report("parse error: %s", optarg
);
1241 opts
= qemu_opts_create(qemu_find_opts("mon"), label
, 1, &error_fatal
);
1242 qemu_opt_set(opts
, "mode", mode
, &error_abort
);
1243 qemu_opt_set(opts
, "chardev", label
, &error_abort
);
1244 if (!strcmp(mode
, "control")) {
1245 qemu_opt_set_bool(opts
, "pretty", pretty
, &error_abort
);
1247 assert(pretty
== false);
1249 monitor_device_index
++;
1252 struct device_config
{
1254 DEV_USB
, /* -usbdevice */
1255 DEV_SERIAL
, /* -serial */
1256 DEV_PARALLEL
, /* -parallel */
1257 DEV_DEBUGCON
, /* -debugcon */
1258 DEV_GDB
, /* -gdb, -s */
1259 DEV_SCLP
, /* s390 sclp */
1261 const char *cmdline
;
1263 QTAILQ_ENTRY(device_config
) next
;
1266 static QTAILQ_HEAD(, device_config
) device_configs
=
1267 QTAILQ_HEAD_INITIALIZER(device_configs
);
1269 static void add_device_config(int type
, const char *cmdline
)
1271 struct device_config
*conf
;
1273 conf
= g_malloc0(sizeof(*conf
));
1275 conf
->cmdline
= cmdline
;
1276 loc_save(&conf
->loc
);
1277 QTAILQ_INSERT_TAIL(&device_configs
, conf
, next
);
1280 static int foreach_device_config(int type
, int (*func
)(const char *cmdline
))
1282 struct device_config
*conf
;
1285 QTAILQ_FOREACH(conf
, &device_configs
, next
) {
1286 if (conf
->type
!= type
)
1288 loc_push_restore(&conf
->loc
);
1289 rc
= func(conf
->cmdline
);
1290 loc_pop(&conf
->loc
);
1298 static void qemu_disable_default_devices(void)
1300 MachineClass
*machine_class
= MACHINE_GET_CLASS(current_machine
);
1302 qemu_opts_foreach(qemu_find_opts("device"),
1303 default_driver_check
, NULL
, NULL
);
1304 qemu_opts_foreach(qemu_find_opts("global"),
1305 default_driver_check
, NULL
, NULL
);
1307 if (!vga_model
&& !default_vga
) {
1308 vga_interface_type
= VGA_DEVICE
;
1310 if (!has_defaults
|| machine_class
->no_serial
) {
1313 if (!has_defaults
|| machine_class
->no_parallel
) {
1314 default_parallel
= 0;
1316 if (!has_defaults
|| machine_class
->no_floppy
) {
1319 if (!has_defaults
|| machine_class
->no_cdrom
) {
1322 if (!has_defaults
|| machine_class
->no_sdcard
) {
1325 if (!has_defaults
) {
1326 default_monitor
= 0;
1332 static void qemu_create_default_devices(void)
1334 MachineClass
*machine_class
= MACHINE_GET_CLASS(current_machine
);
1336 if (is_daemonized()) {
1337 /* According to documentation and historically, -nographic redirects
1338 * serial port, parallel port and monitor to stdio, which does not work
1339 * with -daemonize. We can redirect these to null instead, but since
1340 * -nographic is legacy, let's just error out.
1341 * We disallow -nographic only if all other ports are not redirected
1342 * explicitly, to not break existing legacy setups which uses
1343 * -nographic _and_ redirects all ports explicitly - this is valid
1344 * usage, -nographic is just a no-op in this case.
1347 && (default_parallel
|| default_serial
|| default_monitor
)) {
1348 error_report("-nographic cannot be used with -daemonize");
1354 if (default_parallel
)
1355 add_device_config(DEV_PARALLEL
, "null");
1356 if (default_serial
&& default_monitor
) {
1357 add_device_config(DEV_SERIAL
, "mon:stdio");
1360 add_device_config(DEV_SERIAL
, "stdio");
1361 if (default_monitor
)
1362 monitor_parse("stdio", "readline", false);
1366 add_device_config(DEV_SERIAL
, "vc:80Cx24C");
1367 if (default_parallel
)
1368 add_device_config(DEV_PARALLEL
, "vc:80Cx24C");
1369 if (default_monitor
)
1370 monitor_parse("vc:80Cx24C", "readline", false);
1374 QemuOptsList
*net
= qemu_find_opts("net");
1375 qemu_opts_parse(net
, "nic", true, &error_abort
);
1377 qemu_opts_parse(net
, "user", true, &error_abort
);
1381 #if defined(CONFIG_VNC)
1382 if (!QTAILQ_EMPTY(&(qemu_find_opts("vnc")->head
))) {
1386 if (dpy
.type
== DISPLAY_TYPE_DEFAULT
&& !display_remote
) {
1387 if (!qemu_display_find_default(&dpy
)) {
1388 dpy
.type
= DISPLAY_TYPE_NONE
;
1389 #if defined(CONFIG_VNC)
1390 vnc_parse("localhost:0,to=99,id=default");
1394 if (dpy
.type
== DISPLAY_TYPE_DEFAULT
) {
1395 dpy
.type
= DISPLAY_TYPE_NONE
;
1398 /* If no default VGA is requested, the default is "none". */
1400 vga_model
= get_default_vga_model(machine_class
);
1403 select_vgahw(machine_class
, vga_model
);
1407 static int serial_parse(const char *devname
)
1409 int index
= num_serial_hds
;
1412 if (strcmp(devname
, "none") == 0)
1414 snprintf(label
, sizeof(label
), "serial%d", index
);
1415 serial_hds
= g_renew(Chardev
*, serial_hds
, index
+ 1);
1417 serial_hds
[index
] = qemu_chr_new_mux_mon(label
, devname
, NULL
);
1418 if (!serial_hds
[index
]) {
1419 error_report("could not connect serial device"
1420 " to character backend '%s'", devname
);
1427 Chardev
*serial_hd(int i
)
1430 if (i
< num_serial_hds
) {
1431 return serial_hds
[i
];
1436 static int parallel_parse(const char *devname
)
1438 static int index
= 0;
1441 if (strcmp(devname
, "none") == 0)
1443 if (index
== MAX_PARALLEL_PORTS
) {
1444 error_report("too many parallel ports");
1447 snprintf(label
, sizeof(label
), "parallel%d", index
);
1448 parallel_hds
[index
] = qemu_chr_new_mux_mon(label
, devname
, NULL
);
1449 if (!parallel_hds
[index
]) {
1450 error_report("could not connect parallel device"
1451 " to character backend '%s'", devname
);
1458 static int debugcon_parse(const char *devname
)
1462 if (!qemu_chr_new_mux_mon("debugcon", devname
, NULL
)) {
1463 error_report("invalid character backend '%s'", devname
);
1466 opts
= qemu_opts_create(qemu_find_opts("device"), "debugcon", 1, NULL
);
1468 error_report("already have a debugcon device");
1471 qemu_opt_set(opts
, "driver", "isa-debugcon", &error_abort
);
1472 qemu_opt_set(opts
, "chardev", "debugcon", &error_abort
);
1476 static gint
machine_class_cmp(gconstpointer a
, gconstpointer b
)
1478 const MachineClass
*mc1
= a
, *mc2
= b
;
1481 if (mc1
->family
== NULL
) {
1482 if (mc2
->family
== NULL
) {
1483 /* Compare standalone machine types against each other; they sort
1484 * in increasing order.
1486 return strcmp(object_class_get_name(OBJECT_CLASS(mc1
)),
1487 object_class_get_name(OBJECT_CLASS(mc2
)));
1490 /* Standalone machine types sort after families. */
1494 if (mc2
->family
== NULL
) {
1495 /* Families sort before standalone machine types. */
1499 /* Families sort between each other alphabetically increasingly. */
1500 res
= strcmp(mc1
->family
, mc2
->family
);
1505 /* Within the same family, machine types sort in decreasing order. */
1506 return strcmp(object_class_get_name(OBJECT_CLASS(mc2
)),
1507 object_class_get_name(OBJECT_CLASS(mc1
)));
1510 static void machine_help_func(const QDict
*qdict
)
1512 GSList
*machines
, *el
;
1513 const char *type
= qdict_get_try_str(qdict
, "type");
1515 machines
= object_class_get_list(TYPE_MACHINE
, false);
1517 ObjectClass
*machine_class
= OBJECT_CLASS(find_machine(type
, machines
));
1518 if (machine_class
) {
1519 type_print_class_properties(object_class_get_name(machine_class
));
1524 printf("Supported machines are:\n");
1525 machines
= g_slist_sort(machines
, machine_class_cmp
);
1526 for (el
= machines
; el
; el
= el
->next
) {
1527 MachineClass
*mc
= el
->data
;
1529 printf("%-20s %s (alias of %s)\n", mc
->alias
, mc
->desc
, mc
->name
);
1531 printf("%-20s %s%s%s\n", mc
->name
, mc
->desc
,
1532 mc
->is_default
? " (default)" : "",
1533 mc
->deprecation_reason
? " (deprecated)" : "");
1538 machine_parse_property_opt(QemuOptsList
*opts_list
, const char *propname
,
1539 const char *arg
, Error
**errp
)
1545 prop
= keyval_parse(arg
, opts_list
->implied_opt_name
, &help
, errp
);
1547 qemu_opts_print_help(opts_list
, true);
1551 qdict_put(opts
, propname
, prop
);
1552 keyval_merge(machine_opts_dict
, opts
, errp
);
1553 qobject_unref(opts
);
1556 static const char *pid_file
;
1557 static Notifier qemu_unlink_pidfile_notifier
;
1559 static void qemu_unlink_pidfile(Notifier
*n
, void *data
)
1566 static const QEMUOption
*lookup_opt(int argc
, char **argv
,
1567 const char **poptarg
, int *poptind
)
1569 const QEMUOption
*popt
;
1570 int optind
= *poptind
;
1571 char *r
= argv
[optind
];
1574 loc_set_cmdline(argv
, optind
, 1);
1576 /* Treat --foo the same as -foo. */
1579 popt
= qemu_options
;
1582 error_report("invalid option");
1585 if (!strcmp(popt
->name
, r
+ 1))
1589 if (popt
->flags
& HAS_ARG
) {
1590 if (optind
>= argc
) {
1591 error_report("requires an argument");
1594 optarg
= argv
[optind
++];
1595 loc_set_cmdline(argv
, optind
- 2, 2);
1606 static MachineClass
*select_machine(QDict
*qdict
, Error
**errp
)
1608 const char *optarg
= qdict_get_try_str(qdict
, "type");
1609 GSList
*machines
= object_class_get_list(TYPE_MACHINE
, false);
1610 MachineClass
*machine_class
;
1611 Error
*local_err
= NULL
;
1614 machine_class
= find_machine(optarg
, machines
);
1615 qdict_del(qdict
, "type");
1616 if (!machine_class
) {
1617 error_setg(&local_err
, "unsupported machine type");
1620 machine_class
= find_default_machine(machines
);
1621 if (!machine_class
) {
1622 error_setg(&local_err
, "No machine specified, and there is no default");
1626 g_slist_free(machines
);
1628 error_append_hint(&local_err
, "Use -machine help to list supported machines\n");
1629 error_propagate(errp
, local_err
);
1631 return machine_class
;
1634 static int object_parse_property_opt(Object
*obj
,
1635 const char *name
, const char *value
,
1636 const char *skip
, Error
**errp
)
1638 if (g_str_equal(name
, skip
)) {
1642 if (!object_property_parse(obj
, name
, value
, errp
)) {
1649 /* *Non*recursively replace underscores with dashes in QDict keys. */
1650 static void keyval_dashify(QDict
*qdict
, Error
**errp
)
1652 const QDictEntry
*ent
, *next
;
1655 for (ent
= qdict_first(qdict
); ent
; ent
= next
) {
1656 g_autofree
char *new_key
= NULL
;
1658 next
= qdict_next(qdict
, ent
);
1659 if (!strchr(ent
->key
, '_')) {
1662 new_key
= g_strdup(ent
->key
);
1663 for (p
= new_key
; *p
; p
++) {
1668 if (qdict_haskey(qdict
, new_key
)) {
1669 error_setg(errp
, "Conflict between '%s' and '%s'", ent
->key
, new_key
);
1672 qobject_ref(ent
->value
);
1673 qdict_put_obj(qdict
, new_key
, ent
->value
);
1674 qdict_del(qdict
, ent
->key
);
1678 static void qemu_apply_legacy_machine_options(QDict
*qdict
)
1682 keyval_dashify(qdict
, &error_fatal
);
1684 /* Legacy options do not correspond to MachineState properties. */
1685 value
= qdict_get_try_str(qdict
, "accel");
1687 accelerators
= g_strdup(value
);
1688 qdict_del(qdict
, "accel");
1691 value
= qdict_get_try_str(qdict
, "igd-passthru");
1693 object_register_sugar_prop(ACCEL_CLASS_NAME("xen"), "igd-passthru", value
,
1695 qdict_del(qdict
, "igd-passthru");
1698 value
= qdict_get_try_str(qdict
, "kvm-shadow-mem");
1700 object_register_sugar_prop(ACCEL_CLASS_NAME("kvm"), "kvm-shadow-mem", value
,
1702 qdict_del(qdict
, "kvm-shadow-mem");
1705 value
= qdict_get_try_str(qdict
, "kernel-irqchip");
1707 object_register_sugar_prop(ACCEL_CLASS_NAME("kvm"), "kernel-irqchip", value
,
1709 object_register_sugar_prop(ACCEL_CLASS_NAME("whpx"), "kernel-irqchip", value
,
1711 qdict_del(qdict
, "kernel-irqchip");
1715 static void object_option_foreach_add(bool (*type_opt_predicate
)(const char *))
1717 ObjectOption
*opt
, *next
;
1719 QTAILQ_FOREACH_SAFE(opt
, &object_opts
, next
, next
) {
1720 const char *type
= ObjectType_str(opt
->opts
->qom_type
);
1721 if (type_opt_predicate(type
)) {
1722 user_creatable_add_qapi(opt
->opts
, &error_fatal
);
1723 qapi_free_ObjectOptions(opt
->opts
);
1724 QTAILQ_REMOVE(&object_opts
, opt
, next
);
1730 static void object_option_add_visitor(Visitor
*v
)
1732 ObjectOption
*opt
= g_new0(ObjectOption
, 1);
1733 visit_type_ObjectOptions(v
, NULL
, &opt
->opts
, &error_fatal
);
1734 QTAILQ_INSERT_TAIL(&object_opts
, opt
, next
);
1737 static void object_option_parse(const char *optarg
)
1743 if (optarg
[0] == '{') {
1744 QObject
*obj
= qobject_from_json(optarg
, &error_fatal
);
1746 v
= qobject_input_visitor_new(obj
);
1749 opts
= qemu_opts_parse_noisily(qemu_find_opts("object"),
1755 type
= qemu_opt_get(opts
, "qom-type");
1757 error_setg(&error_fatal
, QERR_MISSING_PARAMETER
, "qom-type");
1759 if (user_creatable_print_help(type
, opts
)) {
1763 v
= opts_visitor_new(opts
);
1766 object_option_add_visitor(v
);
1771 * Initial object creation happens before all other
1772 * QEMU data types are created. The majority of objects
1773 * can be created at this point. The rng-egd object
1774 * cannot be created here, as it depends on the chardev
1777 static bool object_create_early(const char *type
)
1780 * Objects should not be made "delayed" without a reason. If you
1781 * add one, state the reason in a comment!
1784 /* Reason: property "chardev" */
1785 if (g_str_equal(type
, "rng-egd") ||
1786 g_str_equal(type
, "qtest")) {
1790 #if defined(CONFIG_VHOST_USER) && defined(CONFIG_LINUX)
1791 /* Reason: cryptodev-vhost-user property "chardev" */
1792 if (g_str_equal(type
, "cryptodev-vhost-user")) {
1797 /* Reason: vhost-user-blk-server property "node-name" */
1798 if (g_str_equal(type
, "vhost-user-blk-server")) {
1802 * Reason: filter-* property "netdev" etc.
1804 if (g_str_equal(type
, "filter-buffer") ||
1805 g_str_equal(type
, "filter-dump") ||
1806 g_str_equal(type
, "filter-mirror") ||
1807 g_str_equal(type
, "filter-redirector") ||
1808 g_str_equal(type
, "colo-compare") ||
1809 g_str_equal(type
, "filter-rewriter") ||
1810 g_str_equal(type
, "filter-replay")) {
1815 * Allocation of large amounts of memory may delay
1816 * chardev initialization for too long, and trigger timeouts
1817 * on software that waits for a monitor socket to be created
1820 if (g_str_has_prefix(type
, "memory-backend-")) {
1827 static void qemu_apply_machine_options(QDict
*qdict
)
1829 MachineClass
*machine_class
= MACHINE_GET_CLASS(current_machine
);
1830 const char *boot_order
= NULL
;
1831 const char *boot_once
= NULL
;
1834 object_set_properties_from_keyval(OBJECT(current_machine
), qdict
, false, &error_fatal
);
1835 current_machine
->ram_size
= ram_size
;
1836 current_machine
->maxram_size
= maxram_size
;
1837 current_machine
->ram_slots
= ram_slots
;
1839 opts
= qemu_opts_find(qemu_find_opts("boot-opts"), NULL
);
1841 boot_order
= qemu_opt_get(opts
, "order");
1843 validate_bootdevices(boot_order
, &error_fatal
);
1846 boot_once
= qemu_opt_get(opts
, "once");
1848 validate_bootdevices(boot_once
, &error_fatal
);
1851 boot_menu
= qemu_opt_get_bool(opts
, "menu", boot_menu
);
1852 boot_strict
= qemu_opt_get_bool(opts
, "strict", false);
1856 boot_order
= machine_class
->default_boot_order
;
1859 current_machine
->boot_order
= boot_order
;
1860 current_machine
->boot_once
= boot_once
;
1862 if (semihosting_enabled() && !semihosting_get_argc()) {
1863 /* fall back to the -kernel/-append */
1864 semihosting_arg_fallback(current_machine
->kernel_filename
, current_machine
->kernel_cmdline
);
1867 if (current_machine
->smp
.cpus
> 1) {
1868 Error
*blocker
= NULL
;
1869 error_setg(&blocker
, QERR_REPLAY_NOT_SUPPORTED
, "smp");
1870 replay_add_blocker(blocker
);
1874 static void qemu_create_early_backends(void)
1876 MachineClass
*machine_class
= MACHINE_GET_CLASS(current_machine
);
1877 #if defined(CONFIG_SDL)
1878 const bool use_sdl
= (dpy
.type
== DISPLAY_TYPE_SDL
);
1880 const bool use_sdl
= false;
1882 #if defined(CONFIG_GTK)
1883 const bool use_gtk
= (dpy
.type
== DISPLAY_TYPE_GTK
);
1885 const bool use_gtk
= false;
1888 if ((alt_grab
|| ctrl_grab
) && !use_sdl
) {
1889 error_report("-alt-grab and -ctrl-grab are only valid "
1890 "for SDL, ignoring option");
1892 if (dpy
.has_window_close
&& !use_gtk
&& !use_sdl
) {
1893 error_report("-no-quit is only valid for GTK and SDL, "
1897 qemu_display_early_init(&dpy
);
1898 qemu_console_early_init();
1900 if (dpy
.has_gl
&& dpy
.gl
!= DISPLAYGL_MODE_OFF
&& display_opengl
== 0) {
1901 #if defined(CONFIG_OPENGL)
1902 error_report("OpenGL is not supported by the display");
1904 error_report("OpenGL support is disabled");
1909 object_option_foreach_add(object_create_early
);
1911 /* spice needs the timers to be initialized by this point */
1912 /* spice must initialize before audio as it changes the default auiodev */
1913 /* spice must initialize before chardevs (for spicevmc and spiceport) */
1916 qemu_opts_foreach(qemu_find_opts("chardev"),
1917 chardev_init_func
, NULL
, &error_fatal
);
1919 #ifdef CONFIG_VIRTFS
1920 qemu_opts_foreach(qemu_find_opts("fsdev"),
1921 fsdev_init_func
, NULL
, &error_fatal
);
1925 * Note: we need to create audio and block backends before
1926 * setting machine properties, so they can be referred to.
1928 configure_blockdev(&bdo_queue
, machine_class
, snapshot
);
1929 audio_init_audiodevs();
1934 * The remainder of object creation happens after the
1935 * creation of chardev, fsdev, net clients and device data types.
1937 static bool object_create_late(const char *type
)
1939 return !object_create_early(type
);
1942 static void qemu_create_late_backends(void)
1945 qtest_server_init(qtest_chrdev
, qtest_log
, &error_fatal
);
1948 net_init_clients(&error_fatal
);
1950 object_option_foreach_add(object_create_late
);
1952 if (tpm_init() < 0) {
1956 qemu_opts_foreach(qemu_find_opts("mon"),
1957 mon_init_func
, NULL
, &error_fatal
);
1959 if (foreach_device_config(DEV_SERIAL
, serial_parse
) < 0)
1961 if (foreach_device_config(DEV_PARALLEL
, parallel_parse
) < 0)
1963 if (foreach_device_config(DEV_DEBUGCON
, debugcon_parse
) < 0)
1966 /* now chardevs have been created we may have semihosting to connect */
1967 qemu_semihosting_connect_chardevs();
1968 qemu_semihosting_console_init();
1971 static bool have_custom_ram_size(void)
1973 QemuOpts
*opts
= qemu_find_opts_singleton("memory");
1974 return !!qemu_opt_get_size(opts
, "size", 0);
1977 static void qemu_resolve_machine_memdev(void)
1979 if (current_machine
->ram_memdev_id
) {
1981 ram_addr_t backend_size
;
1983 backend
= object_resolve_path_type(current_machine
->ram_memdev_id
,
1984 TYPE_MEMORY_BACKEND
, NULL
);
1986 error_report("Memory backend '%s' not found",
1987 current_machine
->ram_memdev_id
);
1990 backend_size
= object_property_get_uint(backend
, "size", &error_abort
);
1991 if (have_custom_ram_size() && backend_size
!= ram_size
) {
1992 error_report("Size specified by -m option must match size of "
1993 "explicitly specified 'memory-backend' property");
1997 error_report("'-mem-path' can't be used together with"
1998 "'-machine memory-backend'");
2001 ram_size
= backend_size
;
2004 if (!xen_enabled()) {
2005 /* On 32-bit hosts, QEMU is limited by virtual address space */
2006 if (ram_size
> (2047 << 20) && HOST_LONG_BITS
== 32) {
2007 error_report("at most 2047 MB RAM can be simulated");
2013 static void set_memory_options(MachineClass
*mc
)
2016 const char *mem_str
;
2017 const ram_addr_t default_ram_size
= mc
->default_ram_size
;
2018 QemuOpts
*opts
= qemu_find_opts_singleton("memory");
2021 loc_push_none(&loc
);
2022 qemu_opts_loc_restore(opts
);
2025 mem_str
= qemu_opt_get(opts
, "size");
2028 error_report("missing 'size' option value");
2032 sz
= qemu_opt_get_size(opts
, "size", ram_size
);
2034 /* Fix up legacy suffix-less format */
2035 if (g_ascii_isdigit(mem_str
[strlen(mem_str
) - 1])) {
2036 uint64_t overflow_check
= sz
;
2039 if (sz
/ MiB
!= overflow_check
) {
2040 error_report("too large 'size' option value");
2046 /* backward compatibility behaviour for case "-m 0" */
2048 sz
= default_ram_size
;
2051 sz
= QEMU_ALIGN_UP(sz
, 8192);
2052 if (mc
->fixup_ram_size
) {
2053 sz
= mc
->fixup_ram_size(sz
);
2056 if (ram_size
!= sz
) {
2057 error_report("ram size too large");
2061 maxram_size
= ram_size
;
2063 if (qemu_opt_get(opts
, "maxmem")) {
2066 sz
= qemu_opt_get_size(opts
, "maxmem", 0);
2067 slots
= qemu_opt_get_number(opts
, "slots", 0);
2068 if (sz
< ram_size
) {
2069 error_report("invalid value of -m option maxmem: "
2070 "maximum memory size (0x%" PRIx64
") must be at least "
2071 "the initial memory size (0x" RAM_ADDR_FMT
")",
2074 } else if (slots
&& sz
== ram_size
) {
2075 error_report("invalid value of -m option maxmem: "
2076 "memory slots were specified but maximum memory size "
2077 "(0x%" PRIx64
") is equal to the initial memory size "
2078 "(0x" RAM_ADDR_FMT
")", sz
, ram_size
);
2084 } else if (qemu_opt_get(opts
, "slots")) {
2085 error_report("invalid -m option value: missing 'maxmem' option");
2092 static void qemu_create_machine(QDict
*qdict
)
2094 MachineClass
*machine_class
= select_machine(qdict
, &error_fatal
);
2095 object_set_machine_compat_props(machine_class
->compat_props
);
2097 set_memory_options(machine_class
);
2099 current_machine
= MACHINE(object_new_with_class(OBJECT_CLASS(machine_class
)));
2100 object_property_add_child(object_get_root(), "machine",
2101 OBJECT(current_machine
));
2102 object_property_add_child(container_get(OBJECT(current_machine
),
2104 "sysbus", OBJECT(sysbus_get_default()));
2106 if (machine_class
->minimum_page_bits
) {
2107 if (!set_preferred_target_page_bits(machine_class
->minimum_page_bits
)) {
2108 /* This would be a board error: specifying a minimum smaller than
2109 * a target's compile-time fixed setting.
2111 g_assert_not_reached();
2115 cpu_exec_init_all();
2118 if (machine_class
->hw_version
) {
2119 qemu_set_hw_version(machine_class
->hw_version
);
2123 * Get the default machine options from the machine if it is not already
2124 * specified either by the configuration file or by the command line.
2126 if (machine_class
->default_machine_opts
) {
2127 QDict
*default_opts
=
2128 keyval_parse(machine_class
->default_machine_opts
, NULL
, NULL
,
2130 qemu_apply_legacy_machine_options(default_opts
);
2131 object_set_properties_from_keyval(OBJECT(current_machine
), default_opts
,
2132 false, &error_abort
);
2133 qobject_unref(default_opts
);
2137 static int global_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2141 g
= g_malloc0(sizeof(*g
));
2142 g
->driver
= qemu_opt_get(opts
, "driver");
2143 g
->property
= qemu_opt_get(opts
, "property");
2144 g
->value
= qemu_opt_get(opts
, "value");
2145 qdev_prop_register_global(g
);
2150 * Return whether configuration group @group is stored in QemuOpts, or
2151 * recorded as one or more QDicts by qemu_record_config_group.
2153 static bool is_qemuopts_group(const char *group
)
2155 if (g_str_equal(group
, "object") ||
2156 g_str_equal(group
, "machine")) {
2162 static void qemu_record_config_group(const char *group
, QDict
*dict
,
2163 bool from_json
, Error
**errp
)
2165 if (g_str_equal(group
, "object")) {
2166 Visitor
*v
= qobject_input_visitor_new_keyval(QOBJECT(dict
));
2167 object_option_add_visitor(v
);
2169 } else if (g_str_equal(group
, "machine")) {
2171 * Cannot merge string-valued and type-safe dictionaries, so JSON
2172 * is not accepted yet for -M.
2175 keyval_merge(machine_opts_dict
, dict
, errp
);
2182 * Parse non-QemuOpts config file groups, pass the rest to
2183 * qemu_config_do_parse.
2185 static void qemu_parse_config_group(const char *group
, QDict
*qdict
,
2186 void *opaque
, Error
**errp
)
2189 if (is_qemuopts_group(group
)) {
2190 qemu_config_do_parse(group
, qdict
, opaque
, errp
);
2194 crumpled
= qdict_crumple(qdict
, errp
);
2198 switch (qobject_type(crumpled
)) {
2200 qemu_record_config_group(group
, qobject_to(QDict
, crumpled
), false, errp
);
2203 error_setg(errp
, "Lists cannot be at top level of a configuration section");
2206 g_assert_not_reached();
2208 qobject_unref(crumpled
);
2211 static void qemu_read_default_config_file(Error
**errp
)
2215 g_autofree
char *file
= get_relocated_path(CONFIG_QEMU_CONFDIR
"/qemu.conf");
2217 ret
= qemu_read_config_file(file
, qemu_parse_config_group
, errp
);
2219 if (ret
== -ENOENT
) {
2226 static void qemu_set_option(const char *str
, Error
**errp
)
2228 char group
[64], id
[64], arg
[64];
2233 rc
= sscanf(str
, "%63[^.].%63[^.].%63[^=]%n", group
, id
, arg
, &offset
);
2234 if (rc
< 3 || str
[offset
] != '=') {
2235 error_setg(errp
, "can't parse: \"%s\"", str
);
2239 if (!is_qemuopts_group(group
)) {
2240 error_setg(errp
, "-set is not supported with %s", group
);
2242 list
= qemu_find_opts_err(group
, errp
);
2244 opts
= qemu_opts_find(list
, id
);
2246 error_setg(errp
, "there is no %s \"%s\" defined", group
, id
);
2249 qemu_opt_set(opts
, arg
, str
+ offset
+ 1, errp
);
2254 static void user_register_global_props(void)
2256 qemu_opts_foreach(qemu_find_opts("global"),
2257 global_init_func
, NULL
, NULL
);
2260 static int do_configure_icount(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2262 icount_configure(opts
, errp
);
2266 static int accelerator_set_property(void *opaque
,
2267 const char *name
, const char *value
,
2270 return object_parse_property_opt(opaque
, name
, value
, "accel", errp
);
2273 static int do_configure_accelerator(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2275 bool *p_init_failed
= opaque
;
2276 const char *acc
= qemu_opt_get(opts
, "accel");
2277 AccelClass
*ac
= accel_find(acc
);
2280 bool qtest_with_kvm
;
2282 qtest_with_kvm
= g_str_equal(acc
, "kvm") && qtest_chrdev
!= NULL
;
2285 *p_init_failed
= true;
2286 if (!qtest_with_kvm
) {
2287 error_report("invalid accelerator %s", acc
);
2291 accel
= ACCEL(object_new_with_class(OBJECT_CLASS(ac
)));
2292 object_apply_compat_props(OBJECT(accel
));
2293 qemu_opt_foreach(opts
, accelerator_set_property
,
2297 ret
= accel_init_machine(accel
, current_machine
);
2299 *p_init_failed
= true;
2300 if (!qtest_with_kvm
|| ret
!= -ENOENT
) {
2301 error_report("failed to initialize %s: %s", acc
, strerror(-ret
));
2309 static void configure_accelerators(const char *progname
)
2311 bool init_failed
= false;
2313 qemu_opts_foreach(qemu_find_opts("icount"),
2314 do_configure_icount
, NULL
, &error_fatal
);
2316 if (QTAILQ_EMPTY(&qemu_accel_opts
.head
)) {
2317 char **accel_list
, **tmp
;
2319 if (accelerators
== NULL
) {
2320 /* Select the default accelerator */
2321 bool have_tcg
= accel_find("tcg");
2322 bool have_kvm
= accel_find("kvm");
2324 if (have_tcg
&& have_kvm
) {
2325 if (g_str_has_suffix(progname
, "kvm")) {
2326 /* If the program name ends with "kvm", we prefer KVM */
2327 accelerators
= "kvm:tcg";
2329 accelerators
= "tcg:kvm";
2331 } else if (have_kvm
) {
2332 accelerators
= "kvm";
2333 } else if (have_tcg
) {
2334 accelerators
= "tcg";
2336 error_report("No accelerator selected and"
2337 " no default accelerator available");
2341 accel_list
= g_strsplit(accelerators
, ":", 0);
2343 for (tmp
= accel_list
; *tmp
; tmp
++) {
2345 * Filter invalid accelerators here, to prevent obscenities
2346 * such as "-machine accel=tcg,,thread=single".
2348 if (accel_find(*tmp
)) {
2349 qemu_opts_parse_noisily(qemu_find_opts("accel"), *tmp
, true);
2352 error_report("invalid accelerator %s", *tmp
);
2355 g_strfreev(accel_list
);
2357 if (accelerators
!= NULL
) {
2358 error_report("The -accel and \"-machine accel=\" options are incompatible");
2363 if (!qemu_opts_foreach(qemu_find_opts("accel"),
2364 do_configure_accelerator
, &init_failed
, &error_fatal
)) {
2366 error_report("no accelerator found");
2371 if (init_failed
&& !qtest_chrdev
) {
2372 AccelClass
*ac
= ACCEL_GET_CLASS(current_accel());
2373 error_report("falling back to %s", ac
->name
);
2376 if (icount_enabled() && !tcg_enabled()) {
2377 error_report("-icount is not allowed with hardware virtualization");
2382 static void create_default_memdev(MachineState
*ms
, const char *path
)
2385 MachineClass
*mc
= MACHINE_GET_CLASS(ms
);
2387 obj
= object_new(path
? TYPE_MEMORY_BACKEND_FILE
: TYPE_MEMORY_BACKEND_RAM
);
2389 object_property_set_str(obj
, "mem-path", path
, &error_fatal
);
2391 object_property_set_int(obj
, "size", ms
->ram_size
, &error_fatal
);
2392 object_property_add_child(object_get_objects_root(), mc
->default_ram_id
,
2394 /* Ensure backend's memory region name is equal to mc->default_ram_id */
2395 object_property_set_bool(obj
, "x-use-canonical-path-for-ramblock-id",
2396 false, &error_fatal
);
2397 user_creatable_complete(USER_CREATABLE(obj
), &error_fatal
);
2399 object_property_set_str(OBJECT(ms
), "memory-backend", mc
->default_ram_id
,
2403 static void qemu_validate_options(const QDict
*machine_opts
)
2405 const char *kernel_filename
= qdict_get_try_str(machine_opts
, "kernel");
2406 const char *initrd_filename
= qdict_get_try_str(machine_opts
, "initrd");
2407 const char *kernel_cmdline
= qdict_get_try_str(machine_opts
, "append");
2409 if (kernel_filename
== NULL
) {
2410 if (kernel_cmdline
!= NULL
) {
2411 error_report("-append only allowed with -kernel option");
2415 if (initrd_filename
!= NULL
) {
2416 error_report("-initrd only allowed with -kernel option");
2421 if (loadvm
&& preconfig_requested
) {
2422 error_report("'preconfig' and 'loadvm' options are "
2423 "mutually exclusive");
2426 if (incoming
&& preconfig_requested
&& strcmp(incoming
, "defer") != 0) {
2427 error_report("'preconfig' supports '-incoming defer' only");
2431 #ifdef CONFIG_CURSES
2432 if (is_daemonized() && dpy
.type
== DISPLAY_TYPE_CURSES
) {
2433 error_report("curses display cannot be used with -daemonize");
2439 static void qemu_process_sugar_options(void)
2444 val
= g_strdup_printf("%d",
2445 (uint32_t) qemu_opt_get_number(qemu_find_opts_singleton("smp-opts"), "cpus", 1));
2446 object_register_sugar_prop("memory-backend", "prealloc-threads", val
,
2449 object_register_sugar_prop("memory-backend", "prealloc", "on", false);
2453 int i
= select_watchdog(watchdog
);
2455 exit (i
== 1 ? 1 : 0);
2459 /* -action processing */
2462 * Process all the -action parameters parsed from cmdline.
2464 static int process_runstate_actions(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2466 Error
*local_err
= NULL
;
2467 QDict
*qdict
= qemu_opts_to_qdict(opts
, NULL
);
2468 QObject
*ret
= NULL
;
2469 qmp_marshal_set_action(qdict
, &ret
, &local_err
);
2471 qobject_unref(qdict
);
2473 error_propagate(errp
, local_err
);
2479 static void qemu_process_early_options(void)
2481 #ifdef CONFIG_SECCOMP
2482 QemuOptsList
*olist
= qemu_find_opts_err("sandbox", NULL
);
2484 qemu_opts_foreach(olist
, parse_sandbox
, NULL
, &error_fatal
);
2488 qemu_opts_foreach(qemu_find_opts("name"),
2489 parse_name
, NULL
, &error_fatal
);
2491 if (qemu_opts_foreach(qemu_find_opts("action"),
2492 process_runstate_actions
, NULL
, &error_fatal
)) {
2497 qemu_opts_foreach(qemu_find_opts("add-fd"),
2498 parse_add_fd
, NULL
, &error_fatal
);
2500 qemu_opts_foreach(qemu_find_opts("add-fd"),
2501 cleanup_add_fd
, NULL
, &error_fatal
);
2504 /* Open the logfile at this point and set the log mask if necessary. */
2506 qemu_set_log_filename(log_file
, &error_fatal
);
2510 mask
= qemu_str_to_log_mask(log_mask
);
2512 qemu_print_log_usage(stdout
);
2520 qemu_add_default_firmwarepath();
2523 static void qemu_process_help_options(void)
2526 * Check for -cpu help and -device help before we call select_machine(),
2527 * which will return an error if the architecture has no default machine
2528 * type and the user did not specify one, so that the user doesn't need
2529 * to say '-cpu help -machine something'.
2531 if (cpu_option
&& is_help_option(cpu_option
)) {
2532 list_cpus(cpu_option
);
2536 if (qemu_opts_foreach(qemu_find_opts("device"),
2537 device_help_func
, NULL
, NULL
)) {
2541 /* -L help lists the data directories and exits. */
2542 if (list_data_dirs
) {
2543 qemu_list_data_dirs();
2548 static void qemu_maybe_daemonize(const char *pid_file
)
2553 rcu_disable_atfork();
2555 if (pid_file
&& !qemu_write_pidfile(pid_file
, &err
)) {
2556 error_reportf_err(err
, "cannot create PID file: ");
2560 qemu_unlink_pidfile_notifier
.notify
= qemu_unlink_pidfile
;
2561 qemu_add_exit_notifier(&qemu_unlink_pidfile_notifier
);
2564 static void qemu_init_displays(void)
2568 /* init local displays */
2569 ds
= init_displaystate();
2570 qemu_display_init(ds
, &dpy
);
2572 /* must be after terminal init, SDL library changes signal handlers */
2573 os_setup_signal_handling();
2575 /* init remote displays */
2577 qemu_opts_foreach(qemu_find_opts("vnc"),
2578 vnc_init_func
, NULL
, &error_fatal
);
2582 qemu_spice
.display_init();
2586 static void qemu_init_board(void)
2588 MachineClass
*machine_class
= MACHINE_GET_CLASS(current_machine
);
2590 if (machine_class
->default_ram_id
&& current_machine
->ram_size
&&
2591 numa_uses_legacy_mem() && !current_machine
->ram_memdev_id
) {
2592 create_default_memdev(current_machine
, mem_path
);
2595 /* process plugin before CPUs are created, but once -smp has been parsed */
2596 qemu_plugin_load_list(&plugin_list
, &error_fatal
);
2598 /* From here on we enter MACHINE_PHASE_INITIALIZED. */
2599 machine_run_board_init(current_machine
);
2601 drive_check_orphaned();
2605 if (hax_enabled()) {
2606 /* FIXME: why isn't cpu_synchronize_all_post_init enough? */
2611 static void qemu_create_cli_devices(void)
2615 qemu_opts_foreach(qemu_find_opts("fw_cfg"),
2616 parse_fw_cfg
, fw_cfg_find(), &error_fatal
);
2618 /* init USB devices */
2619 if (machine_usb(current_machine
)) {
2620 if (foreach_device_config(DEV_USB
, usb_parse
) < 0)
2624 /* init generic devices */
2625 rom_set_order_override(FW_CFG_ORDER_OVERRIDE_DEVICE
);
2626 qemu_opts_foreach(qemu_find_opts("device"),
2627 device_init_func
, NULL
, &error_fatal
);
2628 rom_reset_order_override();
2631 static void qemu_machine_creation_done(void)
2633 MachineState
*machine
= MACHINE(qdev_get_machine());
2635 /* Did we create any drives that we failed to create a device for? */
2636 drive_check_orphaned();
2638 /* Don't warn about the default network setup that you get if
2639 * no command line -net or -netdev options are specified. There
2640 * are two cases that we would otherwise complain about:
2641 * (1) board doesn't support a NIC but the implicit "-net nic"
2643 * (2) CONFIG_SLIRP not set, in which case the implicit "-net nic"
2644 * sets up a nic that isn't connected to anything.
2646 if (!default_net
&& (!qtest_enabled() || has_defaults
)) {
2647 net_check_clients();
2650 qdev_prop_check_globals();
2652 qdev_machine_creation_done();
2656 * Verify that Confidential Guest Support has actually been initialized
2658 assert(machine
->cgs
->ready
);
2661 if (foreach_device_config(DEV_GDB
, gdbserver_start
) < 0) {
2666 void qmp_x_exit_preconfig(Error
**errp
)
2668 if (phase_check(PHASE_MACHINE_INITIALIZED
)) {
2669 error_setg(errp
, "The command is permitted only before machine initialization");
2674 qemu_create_cli_devices();
2675 qemu_machine_creation_done();
2678 Error
*local_err
= NULL
;
2679 if (!load_snapshot(loadvm
, NULL
, false, NULL
, &local_err
)) {
2680 error_report_err(local_err
);
2685 if (replay_mode
!= REPLAY_MODE_NONE
) {
2686 replay_vmstate_init();
2690 Error
*local_err
= NULL
;
2691 if (strcmp(incoming
, "defer") != 0) {
2692 qmp_migrate_incoming(incoming
, &local_err
);
2694 error_reportf_err(local_err
, "-incoming %s: ", incoming
);
2698 } else if (autostart
) {
2703 void qemu_init(int argc
, char **argv
, char **envp
)
2706 QemuOpts
*icount_opts
= NULL
, *accel_opts
= NULL
;
2707 QemuOptsList
*olist
;
2710 MachineClass
*machine_class
;
2711 bool userconfig
= true;
2712 FILE *vmstate_dump_file
= NULL
;
2714 qemu_add_opts(&qemu_drive_opts
);
2715 qemu_add_drive_opts(&qemu_legacy_drive_opts
);
2716 qemu_add_drive_opts(&qemu_common_drive_opts
);
2717 qemu_add_drive_opts(&qemu_drive_opts
);
2718 qemu_add_drive_opts(&bdrv_runtime_opts
);
2719 qemu_add_opts(&qemu_chardev_opts
);
2720 qemu_add_opts(&qemu_device_opts
);
2721 qemu_add_opts(&qemu_netdev_opts
);
2722 qemu_add_opts(&qemu_nic_opts
);
2723 qemu_add_opts(&qemu_net_opts
);
2724 qemu_add_opts(&qemu_rtc_opts
);
2725 qemu_add_opts(&qemu_global_opts
);
2726 qemu_add_opts(&qemu_mon_opts
);
2727 qemu_add_opts(&qemu_trace_opts
);
2728 qemu_plugin_add_opts();
2729 qemu_add_opts(&qemu_option_rom_opts
);
2730 qemu_add_opts(&qemu_accel_opts
);
2731 qemu_add_opts(&qemu_mem_opts
);
2732 qemu_add_opts(&qemu_smp_opts
);
2733 qemu_add_opts(&qemu_boot_opts
);
2734 qemu_add_opts(&qemu_add_fd_opts
);
2735 qemu_add_opts(&qemu_object_opts
);
2736 qemu_add_opts(&qemu_tpmdev_opts
);
2737 qemu_add_opts(&qemu_overcommit_opts
);
2738 qemu_add_opts(&qemu_msg_opts
);
2739 qemu_add_opts(&qemu_name_opts
);
2740 qemu_add_opts(&qemu_numa_opts
);
2741 qemu_add_opts(&qemu_icount_opts
);
2742 qemu_add_opts(&qemu_semihosting_config_opts
);
2743 qemu_add_opts(&qemu_fw_cfg_opts
);
2744 qemu_add_opts(&qemu_action_opts
);
2745 module_call_init(MODULE_INIT_OPTS
);
2747 error_init(argv
[0]);
2748 qemu_init_exec_dir(argv
[0]);
2750 #ifdef CONFIG_MODULES
2751 module_init_info(qemu_modinfo
);
2752 module_allow_arch(TARGET_NAME
);
2755 qemu_init_subsystems();
2757 /* first pass of option parsing */
2759 while (optind
< argc
) {
2760 if (argv
[optind
][0] != '-') {
2764 const QEMUOption
*popt
;
2766 popt
= lookup_opt(argc
, argv
, &optarg
, &optind
);
2767 switch (popt
->index
) {
2768 case QEMU_OPTION_nouserconfig
:
2775 machine_opts_dict
= qdict_new();
2777 qemu_read_default_config_file(&error_fatal
);
2780 /* second pass of option parsing */
2785 if (argv
[optind
][0] != '-') {
2786 loc_set_cmdline(argv
, optind
, 1);
2787 drive_add(IF_DEFAULT
, 0, argv
[optind
++], HD_OPTS
);
2789 const QEMUOption
*popt
;
2791 popt
= lookup_opt(argc
, argv
, &optarg
, &optind
);
2792 if (!(popt
->arch_mask
& arch_type
)) {
2793 error_report("Option not supported for this target");
2796 switch(popt
->index
) {
2797 case QEMU_OPTION_cpu
:
2798 /* hw initialization will check this */
2799 cpu_option
= optarg
;
2801 case QEMU_OPTION_hda
:
2802 case QEMU_OPTION_hdb
:
2803 case QEMU_OPTION_hdc
:
2804 case QEMU_OPTION_hdd
:
2805 drive_add(IF_DEFAULT
, popt
->index
- QEMU_OPTION_hda
, optarg
,
2808 case QEMU_OPTION_blockdev
:
2811 BlockdevOptionsQueueEntry
*bdo
;
2813 v
= qobject_input_visitor_new_str(optarg
, "driver",
2816 bdo
= g_new(BlockdevOptionsQueueEntry
, 1);
2817 visit_type_BlockdevOptions(v
, NULL
, &bdo
->bdo
,
2820 loc_save(&bdo
->loc
);
2821 QSIMPLEQ_INSERT_TAIL(&bdo_queue
, bdo
, entry
);
2824 case QEMU_OPTION_drive
:
2825 if (drive_def(optarg
) == NULL
) {
2829 case QEMU_OPTION_set
:
2830 qemu_set_option(optarg
, &error_fatal
);
2832 case QEMU_OPTION_global
:
2833 if (qemu_global_option(optarg
) != 0)
2836 case QEMU_OPTION_mtdblock
:
2837 drive_add(IF_MTD
, -1, optarg
, MTD_OPTS
);
2839 case QEMU_OPTION_sd
:
2840 drive_add(IF_SD
, -1, optarg
, SD_OPTS
);
2842 case QEMU_OPTION_pflash
:
2843 drive_add(IF_PFLASH
, -1, optarg
, PFLASH_OPTS
);
2845 case QEMU_OPTION_snapshot
:
2847 Error
*blocker
= NULL
;
2849 error_setg(&blocker
, QERR_REPLAY_NOT_SUPPORTED
,
2851 replay_add_blocker(blocker
);
2854 case QEMU_OPTION_numa
:
2855 opts
= qemu_opts_parse_noisily(qemu_find_opts("numa"),
2861 case QEMU_OPTION_display
:
2862 parse_display(optarg
);
2864 case QEMU_OPTION_nographic
:
2865 qdict_put_str(machine_opts_dict
, "graphics", "off");
2867 dpy
.type
= DISPLAY_TYPE_NONE
;
2869 case QEMU_OPTION_curses
:
2870 #ifdef CONFIG_CURSES
2871 dpy
.type
= DISPLAY_TYPE_CURSES
;
2873 error_report("curses or iconv support is disabled");
2877 case QEMU_OPTION_portrait
:
2878 graphic_rotate
= 90;
2880 case QEMU_OPTION_rotate
:
2881 graphic_rotate
= strtol(optarg
, (char **) &optarg
, 10);
2882 if (graphic_rotate
!= 0 && graphic_rotate
!= 90 &&
2883 graphic_rotate
!= 180 && graphic_rotate
!= 270) {
2884 error_report("only 90, 180, 270 deg rotation is available");
2888 case QEMU_OPTION_kernel
:
2889 qdict_put_str(machine_opts_dict
, "kernel", optarg
);
2891 case QEMU_OPTION_initrd
:
2892 qdict_put_str(machine_opts_dict
, "initrd", optarg
);
2894 case QEMU_OPTION_append
:
2895 qdict_put_str(machine_opts_dict
, "append", optarg
);
2897 case QEMU_OPTION_dtb
:
2898 qdict_put_str(machine_opts_dict
, "dtb", optarg
);
2900 case QEMU_OPTION_cdrom
:
2901 drive_add(IF_DEFAULT
, 2, optarg
, CDROM_OPTS
);
2903 case QEMU_OPTION_boot
:
2904 opts
= qemu_opts_parse_noisily(qemu_find_opts("boot-opts"),
2910 case QEMU_OPTION_fda
:
2911 case QEMU_OPTION_fdb
:
2912 drive_add(IF_FLOPPY
, popt
->index
- QEMU_OPTION_fda
,
2915 case QEMU_OPTION_no_fd_bootchk
:
2918 case QEMU_OPTION_netdev
:
2920 if (net_client_parse(qemu_find_opts("netdev"), optarg
) == -1) {
2924 case QEMU_OPTION_nic
:
2926 if (net_client_parse(qemu_find_opts("nic"), optarg
) == -1) {
2930 case QEMU_OPTION_net
:
2932 if (net_client_parse(qemu_find_opts("net"), optarg
) == -1) {
2936 #ifdef CONFIG_LIBISCSI
2937 case QEMU_OPTION_iscsi
:
2938 opts
= qemu_opts_parse_noisily(qemu_find_opts("iscsi"),
2945 case QEMU_OPTION_audio_help
:
2946 audio_legacy_help();
2949 case QEMU_OPTION_audiodev
:
2950 audio_parse_option(optarg
);
2952 case QEMU_OPTION_soundhw
:
2953 select_soundhw (optarg
);
2958 case QEMU_OPTION_version
:
2963 opts
= qemu_opts_parse_noisily(qemu_find_opts("memory"),
2970 case QEMU_OPTION_tpmdev
:
2971 if (tpm_config_parse(qemu_find_opts("tpmdev"), optarg
) < 0) {
2976 case QEMU_OPTION_mempath
:
2979 case QEMU_OPTION_mem_prealloc
:
2988 case QEMU_OPTION_DFILTER
:
2989 qemu_set_dfilter_ranges(optarg
, &error_fatal
);
2991 case QEMU_OPTION_seed
:
2992 qemu_guest_random_seed_main(optarg
, &error_fatal
);
2995 add_device_config(DEV_GDB
, "tcp::" DEFAULT_GDBSTUB_PORT
);
2997 case QEMU_OPTION_gdb
:
2998 add_device_config(DEV_GDB
, optarg
);
3001 if (is_help_option(optarg
)) {
3002 list_data_dirs
= true;
3004 qemu_add_data_dir(g_strdup(optarg
));
3007 case QEMU_OPTION_bios
:
3008 qdict_put_str(machine_opts_dict
, "firmware", optarg
);
3010 case QEMU_OPTION_singlestep
:
3017 keyboard_layout
= optarg
;
3019 case QEMU_OPTION_vga
:
3028 w
= strtol(p
, (char **)&p
, 10);
3031 error_report("invalid resolution or depth");
3037 h
= strtol(p
, (char **)&p
, 10);
3042 depth
= strtol(p
, (char **)&p
, 10);
3043 if (depth
!= 1 && depth
!= 2 && depth
!= 4 &&
3044 depth
!= 8 && depth
!= 15 && depth
!= 16 &&
3045 depth
!= 24 && depth
!= 32)
3047 } else if (*p
== '\0') {
3048 depth
= graphic_depth
;
3055 graphic_depth
= depth
;
3058 case QEMU_OPTION_echr
:
3061 term_escape_char
= strtol(optarg
, &r
, 0);
3063 printf("Bad argument to echr\n");
3066 case QEMU_OPTION_monitor
:
3067 default_monitor
= 0;
3068 if (strncmp(optarg
, "none", 4)) {
3069 monitor_parse(optarg
, "readline", false);
3072 case QEMU_OPTION_qmp
:
3073 monitor_parse(optarg
, "control", false);
3074 default_monitor
= 0;
3076 case QEMU_OPTION_qmp_pretty
:
3077 monitor_parse(optarg
, "control", true);
3078 default_monitor
= 0;
3080 case QEMU_OPTION_mon
:
3081 opts
= qemu_opts_parse_noisily(qemu_find_opts("mon"), optarg
,
3086 default_monitor
= 0;
3088 case QEMU_OPTION_chardev
:
3089 opts
= qemu_opts_parse_noisily(qemu_find_opts("chardev"),
3095 case QEMU_OPTION_fsdev
:
3096 olist
= qemu_find_opts("fsdev");
3098 error_report("fsdev support is disabled");
3101 opts
= qemu_opts_parse_noisily(olist
, optarg
, true);
3106 case QEMU_OPTION_virtfs
: {
3109 const char *writeout
, *sock_fd
, *socket
, *path
, *security_model
,
3112 olist
= qemu_find_opts("virtfs");
3114 error_report("virtfs support is disabled");
3117 opts
= qemu_opts_parse_noisily(olist
, optarg
, true);
3122 if (qemu_opt_get(opts
, "fsdriver") == NULL
||
3123 qemu_opt_get(opts
, "mount_tag") == NULL
) {
3124 error_report("Usage: -virtfs fsdriver,mount_tag=tag");
3127 fsdev
= qemu_opts_create(qemu_find_opts("fsdev"),
3128 qemu_opts_id(opts
) ?:
3129 qemu_opt_get(opts
, "mount_tag"),
3132 error_report("duplicate or invalid fsdev id: %s",
3133 qemu_opt_get(opts
, "mount_tag"));
3137 writeout
= qemu_opt_get(opts
, "writeout");
3139 #ifdef CONFIG_SYNC_FILE_RANGE
3140 qemu_opt_set(fsdev
, "writeout", writeout
, &error_abort
);
3142 error_report("writeout=immediate not supported "
3143 "on this platform");
3147 qemu_opt_set(fsdev
, "fsdriver",
3148 qemu_opt_get(opts
, "fsdriver"), &error_abort
);
3149 path
= qemu_opt_get(opts
, "path");
3151 qemu_opt_set(fsdev
, "path", path
, &error_abort
);
3153 security_model
= qemu_opt_get(opts
, "security_model");
3154 if (security_model
) {
3155 qemu_opt_set(fsdev
, "security_model", security_model
,
3158 socket
= qemu_opt_get(opts
, "socket");
3160 qemu_opt_set(fsdev
, "socket", socket
, &error_abort
);
3162 sock_fd
= qemu_opt_get(opts
, "sock_fd");
3164 qemu_opt_set(fsdev
, "sock_fd", sock_fd
, &error_abort
);
3167 qemu_opt_set_bool(fsdev
, "readonly",
3168 qemu_opt_get_bool(opts
, "readonly", 0),
3170 multidevs
= qemu_opt_get(opts
, "multidevs");
3172 qemu_opt_set(fsdev
, "multidevs", multidevs
, &error_abort
);
3174 device
= qemu_opts_create(qemu_find_opts("device"), NULL
, 0,
3176 qemu_opt_set(device
, "driver", "virtio-9p-pci", &error_abort
);
3177 qemu_opt_set(device
, "fsdev",
3178 qemu_opts_id(fsdev
), &error_abort
);
3179 qemu_opt_set(device
, "mount_tag",
3180 qemu_opt_get(opts
, "mount_tag"), &error_abort
);
3183 case QEMU_OPTION_serial
:
3184 add_device_config(DEV_SERIAL
, optarg
);
3186 if (strncmp(optarg
, "mon:", 4) == 0) {
3187 default_monitor
= 0;
3190 case QEMU_OPTION_watchdog
:
3192 error_report("only one watchdog option may be given");
3197 case QEMU_OPTION_action
:
3198 olist
= qemu_find_opts("action");
3199 if (!qemu_opts_parse_noisily(olist
, optarg
, false)) {
3203 case QEMU_OPTION_watchdog_action
:
3204 if (select_watchdog_action(optarg
) == -1) {
3205 error_report("unknown -watchdog-action parameter");
3209 case QEMU_OPTION_parallel
:
3210 add_device_config(DEV_PARALLEL
, optarg
);
3211 default_parallel
= 0;
3212 if (strncmp(optarg
, "mon:", 4) == 0) {
3213 default_monitor
= 0;
3216 case QEMU_OPTION_debugcon
:
3217 add_device_config(DEV_DEBUGCON
, optarg
);
3219 case QEMU_OPTION_loadvm
:
3222 case QEMU_OPTION_full_screen
:
3223 dpy
.has_full_screen
= true;
3224 dpy
.full_screen
= true;
3226 case QEMU_OPTION_alt_grab
:
3229 case QEMU_OPTION_ctrl_grab
:
3232 case QEMU_OPTION_no_quit
:
3233 dpy
.has_window_close
= true;
3234 dpy
.window_close
= false;
3235 warn_report("-no-quit is deprecated, please use "
3236 "-display ...,window-close=off instead.");
3238 case QEMU_OPTION_sdl
:
3240 dpy
.type
= DISPLAY_TYPE_SDL
;
3243 error_report("SDL support is disabled");
3246 case QEMU_OPTION_pidfile
:
3249 case QEMU_OPTION_win2k_hack
:
3250 win2k_install_hack
= 1;
3252 case QEMU_OPTION_acpitable
:
3253 opts
= qemu_opts_parse_noisily(qemu_find_opts("acpi"),
3258 acpi_table_add(opts
, &error_fatal
);
3260 case QEMU_OPTION_smbios
:
3261 opts
= qemu_opts_parse_noisily(qemu_find_opts("smbios"),
3266 smbios_entry_add(opts
, &error_fatal
);
3268 case QEMU_OPTION_fwcfg
:
3269 opts
= qemu_opts_parse_noisily(qemu_find_opts("fw_cfg"),
3275 case QEMU_OPTION_preconfig
:
3276 preconfig_requested
= true;
3278 case QEMU_OPTION_enable_kvm
:
3279 qdict_put_str(machine_opts_dict
, "accel", "kvm");
3282 case QEMU_OPTION_machine
:
3286 keyval_parse_into(machine_opts_dict
, optarg
, "type", &help
, &error_fatal
);
3288 machine_help_func(machine_opts_dict
);
3293 case QEMU_OPTION_accel
:
3294 accel_opts
= qemu_opts_parse_noisily(qemu_find_opts("accel"),
3296 optarg
= qemu_opt_get(accel_opts
, "accel");
3297 if (!optarg
|| is_help_option(optarg
)) {
3298 printf("Accelerators supported in QEMU binary:\n");
3299 GSList
*el
, *accel_list
= object_class_get_list(TYPE_ACCEL
,
3301 for (el
= accel_list
; el
; el
= el
->next
) {
3302 gchar
*typename
= g_strdup(object_class_get_name(
3303 OBJECT_CLASS(el
->data
)));
3304 /* omit qtest which is used for tests only */
3305 if (g_strcmp0(typename
, ACCEL_CLASS_NAME("qtest")) &&
3306 g_str_has_suffix(typename
, ACCEL_CLASS_SUFFIX
)) {
3307 gchar
**optname
= g_strsplit(typename
,
3308 ACCEL_CLASS_SUFFIX
, 0);
3309 printf("%s\n", optname
[0]);
3310 g_strfreev(optname
);
3314 g_slist_free(accel_list
);
3318 case QEMU_OPTION_usb
:
3319 qdict_put_str(machine_opts_dict
, "usb", "on");
3321 case QEMU_OPTION_usbdevice
:
3322 qdict_put_str(machine_opts_dict
, "usb", "on");
3323 add_device_config(DEV_USB
, optarg
);
3325 case QEMU_OPTION_device
:
3326 if (!qemu_opts_parse_noisily(qemu_find_opts("device"),
3331 case QEMU_OPTION_smp
:
3332 machine_parse_property_opt(qemu_find_opts("smp-opts"), "smp", optarg
, &error_fatal
);
3334 case QEMU_OPTION_vnc
:
3337 case QEMU_OPTION_no_acpi
:
3338 qdict_put_str(machine_opts_dict
, "acpi", "off");
3340 case QEMU_OPTION_no_hpet
:
3341 qdict_put_str(machine_opts_dict
, "hpet", "off");
3343 case QEMU_OPTION_no_reboot
:
3344 olist
= qemu_find_opts("action");
3345 qemu_opts_parse_noisily(olist
, "reboot=shutdown", false);
3347 case QEMU_OPTION_no_shutdown
:
3348 olist
= qemu_find_opts("action");
3349 qemu_opts_parse_noisily(olist
, "shutdown=pause", false);
3351 case QEMU_OPTION_uuid
:
3352 if (qemu_uuid_parse(optarg
, &qemu_uuid
) < 0) {
3353 error_report("failed to parse UUID string: wrong format");
3356 qemu_uuid_set
= true;
3358 case QEMU_OPTION_option_rom
:
3359 if (nb_option_roms
>= MAX_OPTION_ROMS
) {
3360 error_report("too many option ROMs");
3363 opts
= qemu_opts_parse_noisily(qemu_find_opts("option-rom"),
3368 option_rom
[nb_option_roms
].name
= qemu_opt_get(opts
, "romfile");
3369 option_rom
[nb_option_roms
].bootindex
=
3370 qemu_opt_get_number(opts
, "bootindex", -1);
3371 if (!option_rom
[nb_option_roms
].name
) {
3372 error_report("Option ROM file is not specified");
3377 case QEMU_OPTION_semihosting
:
3378 qemu_semihosting_enable();
3380 case QEMU_OPTION_semihosting_config
:
3381 if (qemu_semihosting_config_options(optarg
) != 0) {
3385 case QEMU_OPTION_name
:
3386 opts
= qemu_opts_parse_noisily(qemu_find_opts("name"),
3391 /* Capture guest name if -msg guest-name is used later */
3392 error_guest_name
= qemu_opt_get(opts
, "guest");
3394 case QEMU_OPTION_prom_env
:
3395 if (nb_prom_envs
>= MAX_PROM_ENVS
) {
3396 error_report("too many prom variables");
3399 prom_envs
[nb_prom_envs
] = optarg
;
3402 case QEMU_OPTION_old_param
:
3405 case QEMU_OPTION_rtc
:
3406 opts
= qemu_opts_parse_noisily(qemu_find_opts("rtc"), optarg
,
3412 case QEMU_OPTION_icount
:
3413 icount_opts
= qemu_opts_parse_noisily(qemu_find_opts("icount"),
3419 case QEMU_OPTION_incoming
:
3421 runstate_set(RUN_STATE_INMIGRATE
);
3425 case QEMU_OPTION_only_migratable
:
3426 only_migratable
= 1;
3428 case QEMU_OPTION_nodefaults
:
3431 case QEMU_OPTION_xen_domid
:
3432 if (!(xen_available())) {
3433 error_report("Option not supported for this target");
3436 xen_domid
= atoi(optarg
);
3438 case QEMU_OPTION_xen_attach
:
3439 if (!(xen_available())) {
3440 error_report("Option not supported for this target");
3443 xen_mode
= XEN_ATTACH
;
3445 case QEMU_OPTION_xen_domid_restrict
:
3446 if (!(xen_available())) {
3447 error_report("Option not supported for this target");
3450 xen_domid_restrict
= true;
3452 case QEMU_OPTION_trace
:
3453 trace_opt_parse(optarg
);
3455 case QEMU_OPTION_plugin
:
3456 qemu_plugin_opt_parse(optarg
, &plugin_list
);
3458 case QEMU_OPTION_readconfig
:
3459 qemu_read_config_file(optarg
, qemu_parse_config_group
, &error_fatal
);
3461 case QEMU_OPTION_spice
:
3462 olist
= qemu_find_opts_err("spice", NULL
);
3464 error_report("spice support is disabled");
3467 opts
= qemu_opts_parse_noisily(olist
, optarg
, false);
3473 case QEMU_OPTION_writeconfig
:
3476 warn_report("-writeconfig is deprecated and will go away without a replacement");
3477 if (strcmp(optarg
, "-") == 0) {
3480 fp
= fopen(optarg
, "w");
3482 error_report("open %s: %s", optarg
,
3487 qemu_config_write(fp
);
3493 case QEMU_OPTION_qtest
:
3494 qtest_chrdev
= optarg
;
3496 case QEMU_OPTION_qtest_log
:
3499 case QEMU_OPTION_sandbox
:
3500 olist
= qemu_find_opts("sandbox");
3502 #ifndef CONFIG_SECCOMP
3503 error_report("-sandbox support is not enabled "
3504 "in this QEMU binary");
3509 opts
= qemu_opts_parse_noisily(olist
, optarg
, true);
3514 case QEMU_OPTION_add_fd
:
3516 opts
= qemu_opts_parse_noisily(qemu_find_opts("add-fd"),
3522 error_report("File descriptor passing is disabled on this "
3527 case QEMU_OPTION_object
:
3528 object_option_parse(optarg
);
3530 case QEMU_OPTION_overcommit
:
3531 opts
= qemu_opts_parse_noisily(qemu_find_opts("overcommit"),
3536 enable_mlock
= qemu_opt_get_bool(opts
, "mem-lock", false);
3537 enable_cpu_pm
= qemu_opt_get_bool(opts
, "cpu-pm", false);
3539 case QEMU_OPTION_compat
:
3544 v
= qobject_input_visitor_new_str(optarg
, NULL
,
3547 visit_type_CompatPolicy(v
, NULL
, &opts
, &error_fatal
);
3548 QAPI_CLONE_MEMBERS(CompatPolicy
, &compat_policy
, opts
);
3550 qapi_free_CompatPolicy(opts
);
3554 case QEMU_OPTION_msg
:
3555 opts
= qemu_opts_parse_noisily(qemu_find_opts("msg"), optarg
,
3560 configure_msg(opts
);
3562 case QEMU_OPTION_dump_vmstate
:
3563 if (vmstate_dump_file
) {
3564 error_report("only one '-dump-vmstate' "
3565 "option may be given");
3568 vmstate_dump_file
= fopen(optarg
, "w");
3569 if (vmstate_dump_file
== NULL
) {
3570 error_report("open %s: %s", optarg
, strerror(errno
));
3574 case QEMU_OPTION_enable_sync_profile
:
3577 case QEMU_OPTION_nouserconfig
:
3578 /* Nothing to be parsed here. Especially, do not error out below. */
3581 if (os_parse_cmd_args(popt
->index
, optarg
)) {
3582 error_report("Option not supported in this build");
3589 * Clear error location left behind by the loop.
3590 * Best done right after the loop. Do not insert code here!
3594 qemu_validate_options(machine_opts_dict
);
3595 qemu_process_sugar_options();
3598 * These options affect everything else and should be processed
3599 * before daemonizing.
3601 qemu_process_early_options();
3603 qemu_process_help_options();
3604 qemu_maybe_daemonize(pid_file
);
3607 * The trace backend must be initialized after daemonizing.
3608 * trace_init_backends() will call st_init(), which will create the
3609 * trace thread in the parent, and also register st_flush_trace_buffer()
3610 * in atexit(). This function will force the parent to wait for the
3611 * writeout thread to finish, which will not occur, and the parent
3612 * process will be left in the host.
3614 if (!trace_init_backends()) {
3619 qemu_init_main_loop(&error_fatal
);
3622 user_register_global_props();
3623 replay_configure(icount_opts
);
3625 configure_rtc(qemu_find_opts_singleton("rtc"));
3627 qemu_create_machine(machine_opts_dict
);
3631 qemu_disable_default_devices();
3632 qemu_create_default_devices();
3633 qemu_create_early_backends();
3635 qemu_apply_legacy_machine_options(machine_opts_dict
);
3636 qemu_apply_machine_options(machine_opts_dict
);
3637 qobject_unref(machine_opts_dict
);
3638 phase_advance(PHASE_MACHINE_CREATED
);
3641 * Note: uses machine properties such as kernel-irqchip, must run
3642 * after qemu_apply_machine_options.
3644 configure_accelerators(argv
[0]);
3645 phase_advance(PHASE_ACCEL_CREATED
);
3648 * Beware, QOM objects created before this point miss global and
3649 * compat properties.
3651 * Global properties get set up by qdev_prop_register_global(),
3652 * called from user_register_global_props(), and certain option
3653 * desugaring. Also in CPU feature desugaring (buried in
3654 * parse_cpu_option()), which happens below this point, but may
3655 * only target the CPU type, which can only be created after
3656 * parse_cpu_option() returned the type.
3658 * Machine compat properties: object_set_machine_compat_props().
3659 * Accelerator compat props: object_set_accelerator_compat_props(),
3660 * called from do_configure_accelerator().
3663 machine_class
= MACHINE_GET_CLASS(current_machine
);
3664 if (!qtest_enabled() && machine_class
->deprecation_reason
) {
3665 error_report("Machine type '%s' is deprecated: %s",
3666 machine_class
->name
, machine_class
->deprecation_reason
);
3670 * Note: creates a QOM object, must run only after global and
3671 * compat properties have been set up.
3673 migration_object_init();
3675 qemu_create_late_backends();
3677 /* parse features once if machine provides default cpu_type */
3678 current_machine
->cpu_type
= machine_class
->default_cpu_type
;
3680 current_machine
->cpu_type
= parse_cpu_option(cpu_option
);
3682 /* NB: for machine none cpu_type could STILL be NULL here! */
3684 qemu_resolve_machine_memdev();
3685 parse_numa_opts(current_machine
);
3687 if (vmstate_dump_file
) {
3689 dump_vmstate_json_to_file(vmstate_dump_file
);
3693 if (!preconfig_requested
) {
3694 qmp_x_exit_preconfig(&error_fatal
);
3696 qemu_init_displays();
3697 accel_setup_post(current_machine
);