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/qstring.h"
35 #include "qapi/qmp/qjson.h"
36 #include "qemu-version.h"
37 #include "qemu/cutils.h"
38 #include "qemu/help_option.h"
39 #include "qemu/uuid.h"
40 #include "sysemu/reset.h"
41 #include "sysemu/runstate.h"
42 #include "sysemu/runstate-action.h"
43 #include "sysemu/seccomp.h"
44 #include "sysemu/tcg.h"
45 #include "sysemu/xen.h"
47 #include "qemu/error-report.h"
48 #include "qemu/sockets.h"
49 #include "qemu/accel.h"
51 #include "hw/isa/isa.h"
52 #include "hw/scsi/scsi.h"
53 #include "hw/display/vga.h"
54 #include "sysemu/watchdog.h"
55 #include "hw/firmware/smbios.h"
56 #include "hw/acpi/acpi.h"
57 #include "hw/xen/xen.h"
58 #include "hw/loader.h"
59 #include "monitor/qdev.h"
61 #include "net/slirp.h"
62 #include "monitor/monitor.h"
63 #include "ui/console.h"
65 #include "sysemu/sysemu.h"
66 #include "sysemu/numa.h"
67 #include "sysemu/hostmem.h"
68 #include "exec/gdbstub.h"
69 #include "qemu/timer.h"
70 #include "chardev/char.h"
71 #include "qemu/bitmap.h"
73 #include "sysemu/blockdev.h"
74 #include "hw/block/block.h"
75 #include "hw/i386/x86.h"
76 #include "hw/i386/pc.h"
77 #include "migration/misc.h"
78 #include "migration/snapshot.h"
79 #include "sysemu/tpm.h"
80 #include "sysemu/dma.h"
81 #include "hw/audio/soundhw.h"
82 #include "audio/audio.h"
83 #include "sysemu/cpus.h"
84 #include "sysemu/cpu-timers.h"
85 #include "migration/colo.h"
86 #include "migration/postcopy-ram.h"
87 #include "sysemu/kvm.h"
88 #include "sysemu/hax.h"
89 #include "qapi/qobject-input-visitor.h"
90 #include "qemu/option.h"
91 #include "qemu/config-file.h"
92 #include "qemu/qemu-options.h"
93 #include "qemu/main-loop.h"
95 #include "fsdev/qemu-fsdev.h"
97 #include "sysemu/qtest.h"
99 #include "disas/disas.h"
102 #include "trace/control.h"
103 #include "qemu/plugin.h"
104 #include "qemu/queue.h"
105 #include "sysemu/arch_init.h"
106 #include "exec/confidential-guest-support.h"
108 #include "ui/qemu-spice.h"
109 #include "qapi/string-input-visitor.h"
110 #include "qapi/opts-visitor.h"
111 #include "qapi/clone-visitor.h"
112 #include "qom/object_interfaces.h"
113 #include "semihosting/semihost.h"
114 #include "crypto/init.h"
115 #include "sysemu/replay.h"
116 #include "qapi/qapi-events-run-state.h"
117 #include "qapi/qapi-visit-block-core.h"
118 #include "qapi/qapi-visit-compat.h"
119 #include "qapi/qapi-visit-ui.h"
120 #include "qapi/qapi-commands-block-core.h"
121 #include "qapi/qapi-commands-migration.h"
122 #include "qapi/qapi-commands-misc.h"
123 #include "qapi/qapi-visit-qom.h"
124 #include "qapi/qapi-commands-ui.h"
125 #include "qapi/qmp/qdict.h"
126 #include "qapi/qmp/qerror.h"
127 #include "sysemu/iothread.h"
128 #include "qemu/guest-random.h"
130 #include "config-host.h"
132 #define MAX_VIRTIO_CONSOLES 1
134 typedef struct BlockdevOptionsQueueEntry
{
135 BlockdevOptions
*bdo
;
137 QSIMPLEQ_ENTRY(BlockdevOptionsQueueEntry
) entry
;
138 } BlockdevOptionsQueueEntry
;
140 typedef QSIMPLEQ_HEAD(, BlockdevOptionsQueueEntry
) BlockdevOptionsQueue
;
142 typedef struct ObjectOption
{
144 QTAILQ_ENTRY(ObjectOption
) next
;
147 static const char *cpu_option
;
148 static const char *mem_path
;
149 static const char *incoming
;
150 static const char *loadvm
;
151 static const char *accelerators
;
152 static QDict
*machine_opts_dict
;
153 static QTAILQ_HEAD(, ObjectOption
) object_opts
= QTAILQ_HEAD_INITIALIZER(object_opts
);
154 static ram_addr_t maxram_size
;
155 static uint64_t ram_slots
;
156 static int display_remote
;
158 static bool preconfig_requested
;
159 static QemuPluginList plugin_list
= QTAILQ_HEAD_INITIALIZER(plugin_list
);
160 static BlockdevOptionsQueue bdo_queue
= QSIMPLEQ_HEAD_INITIALIZER(bdo_queue
);
161 static bool nographic
= false;
162 static int mem_prealloc
; /* force preallocation of physical target memory */
163 static ram_addr_t ram_size
;
164 static const char *vga_model
= NULL
;
165 static DisplayOptions dpy
;
166 static int num_serial_hds
;
167 static Chardev
**serial_hds
;
168 static const char *log_mask
;
169 static const char *log_file
;
170 static bool list_data_dirs
;
171 static const char *watchdog
;
172 static const char *qtest_chrdev
;
173 static const char *qtest_log
;
175 static int has_defaults
= 1;
176 static int default_serial
= 1;
177 static int default_parallel
= 1;
178 static int default_monitor
= 1;
179 static int default_floppy
= 1;
180 static int default_cdrom
= 1;
181 static int default_sdcard
= 1;
182 static int default_vga
= 1;
183 static int default_net
= 1;
189 { .driver
= "isa-serial", .flag
= &default_serial
},
190 { .driver
= "isa-parallel", .flag
= &default_parallel
},
191 { .driver
= "isa-fdc", .flag
= &default_floppy
},
192 { .driver
= "floppy", .flag
= &default_floppy
},
193 { .driver
= "ide-cd", .flag
= &default_cdrom
},
194 { .driver
= "ide-hd", .flag
= &default_cdrom
},
195 { .driver
= "scsi-cd", .flag
= &default_cdrom
},
196 { .driver
= "scsi-hd", .flag
= &default_cdrom
},
197 { .driver
= "VGA", .flag
= &default_vga
},
198 { .driver
= "isa-vga", .flag
= &default_vga
},
199 { .driver
= "cirrus-vga", .flag
= &default_vga
},
200 { .driver
= "isa-cirrus-vga", .flag
= &default_vga
},
201 { .driver
= "vmware-svga", .flag
= &default_vga
},
202 { .driver
= "qxl-vga", .flag
= &default_vga
},
203 { .driver
= "virtio-vga", .flag
= &default_vga
},
204 { .driver
= "ati-vga", .flag
= &default_vga
},
205 { .driver
= "vhost-user-vga", .flag
= &default_vga
},
206 { .driver
= "virtio-vga-gl", .flag
= &default_vga
},
209 static QemuOptsList qemu_rtc_opts
= {
211 .head
= QTAILQ_HEAD_INITIALIZER(qemu_rtc_opts
.head
),
216 .type
= QEMU_OPT_STRING
,
219 .type
= QEMU_OPT_STRING
,
222 .type
= QEMU_OPT_STRING
,
224 { /* end of list */ }
228 static QemuOptsList qemu_option_rom_opts
= {
229 .name
= "option-rom",
230 .implied_opt_name
= "romfile",
231 .head
= QTAILQ_HEAD_INITIALIZER(qemu_option_rom_opts
.head
),
235 .type
= QEMU_OPT_NUMBER
,
238 .type
= QEMU_OPT_STRING
,
240 { /* end of list */ }
244 static QemuOptsList qemu_accel_opts
= {
246 .implied_opt_name
= "accel",
247 .head
= QTAILQ_HEAD_INITIALIZER(qemu_accel_opts
.head
),
250 * no elements => accept any
251 * sanity checking will happen later
252 * when setting accelerator properties
258 static QemuOptsList qemu_boot_opts
= {
260 .implied_opt_name
= "order",
262 .head
= QTAILQ_HEAD_INITIALIZER(qemu_boot_opts
.head
),
266 .type
= QEMU_OPT_STRING
,
269 .type
= QEMU_OPT_STRING
,
272 .type
= QEMU_OPT_BOOL
,
275 .type
= QEMU_OPT_STRING
,
277 .name
= "splash-time",
278 .type
= QEMU_OPT_NUMBER
,
280 .name
= "reboot-timeout",
281 .type
= QEMU_OPT_NUMBER
,
284 .type
= QEMU_OPT_BOOL
,
290 static QemuOptsList qemu_add_fd_opts
= {
292 .head
= QTAILQ_HEAD_INITIALIZER(qemu_add_fd_opts
.head
),
296 .type
= QEMU_OPT_NUMBER
,
297 .help
= "file descriptor of which a duplicate is added to fd set",
300 .type
= QEMU_OPT_NUMBER
,
301 .help
= "ID of the fd set to add fd to",
304 .type
= QEMU_OPT_STRING
,
305 .help
= "free-form string used to describe fd",
307 { /* end of list */ }
311 static QemuOptsList qemu_object_opts
= {
313 .implied_opt_name
= "qom-type",
314 .head
= QTAILQ_HEAD_INITIALIZER(qemu_object_opts
.head
),
320 static QemuOptsList qemu_tpmdev_opts
= {
322 .implied_opt_name
= "type",
323 .head
= QTAILQ_HEAD_INITIALIZER(qemu_tpmdev_opts
.head
),
325 /* options are defined in the TPM backends */
326 { /* end of list */ }
330 static QemuOptsList qemu_overcommit_opts
= {
331 .name
= "overcommit",
332 .head
= QTAILQ_HEAD_INITIALIZER(qemu_overcommit_opts
.head
),
336 .type
= QEMU_OPT_BOOL
,
340 .type
= QEMU_OPT_BOOL
,
342 { /* end of list */ }
346 static QemuOptsList qemu_msg_opts
= {
348 .head
= QTAILQ_HEAD_INITIALIZER(qemu_msg_opts
.head
),
352 .type
= QEMU_OPT_BOOL
,
355 .name
= "guest-name",
356 .type
= QEMU_OPT_BOOL
,
357 .help
= "Prepends guest name for error messages but only if "
358 "-name guest is set otherwise option is ignored\n",
360 { /* end of list */ }
364 static QemuOptsList qemu_name_opts
= {
366 .implied_opt_name
= "guest",
368 .head
= QTAILQ_HEAD_INITIALIZER(qemu_name_opts
.head
),
372 .type
= QEMU_OPT_STRING
,
373 .help
= "Sets the name of the guest.\n"
374 "This name will be displayed in the SDL window caption.\n"
375 "The name will also be used for the VNC server",
378 .type
= QEMU_OPT_STRING
,
379 .help
= "Sets the name of the QEMU process, as shown in top etc",
381 .name
= "debug-threads",
382 .type
= QEMU_OPT_BOOL
,
383 .help
= "When enabled, name the individual threads; defaults off.\n"
384 "NOTE: The thread names are for debugging and not a\n"
387 { /* End of list */ }
391 static QemuOptsList qemu_mem_opts
= {
393 .implied_opt_name
= "size",
394 .head
= QTAILQ_HEAD_INITIALIZER(qemu_mem_opts
.head
),
399 .type
= QEMU_OPT_SIZE
,
403 .type
= QEMU_OPT_NUMBER
,
407 .type
= QEMU_OPT_SIZE
,
409 { /* end of list */ }
413 static QemuOptsList qemu_icount_opts
= {
415 .implied_opt_name
= "shift",
417 .head
= QTAILQ_HEAD_INITIALIZER(qemu_icount_opts
.head
),
421 .type
= QEMU_OPT_STRING
,
424 .type
= QEMU_OPT_BOOL
,
427 .type
= QEMU_OPT_BOOL
,
430 .type
= QEMU_OPT_STRING
,
433 .type
= QEMU_OPT_STRING
,
435 .name
= "rrsnapshot",
436 .type
= QEMU_OPT_STRING
,
438 { /* end of list */ }
442 static QemuOptsList qemu_fw_cfg_opts
= {
444 .implied_opt_name
= "name",
445 .head
= QTAILQ_HEAD_INITIALIZER(qemu_fw_cfg_opts
.head
),
449 .type
= QEMU_OPT_STRING
,
450 .help
= "Sets the fw_cfg name of the blob to be inserted",
453 .type
= QEMU_OPT_STRING
,
454 .help
= "Sets the name of the file from which "
455 "the fw_cfg blob will be loaded",
458 .type
= QEMU_OPT_STRING
,
459 .help
= "Sets content of the blob to be inserted from a string",
462 .type
= QEMU_OPT_STRING
,
463 .help
= "Sets id of the object generating the fw_cfg blob "
466 { /* end of list */ }
470 static QemuOptsList qemu_action_opts
= {
473 .head
= QTAILQ_HEAD_INITIALIZER(qemu_action_opts
.head
),
477 .type
= QEMU_OPT_STRING
,
480 .type
= QEMU_OPT_STRING
,
483 .type
= QEMU_OPT_STRING
,
486 .type
= QEMU_OPT_STRING
,
488 { /* end of list */ }
492 const char *qemu_get_vm_name(void)
497 static int default_driver_check(void *opaque
, QemuOpts
*opts
, Error
**errp
)
499 const char *driver
= qemu_opt_get(opts
, "driver");
504 for (i
= 0; i
< ARRAY_SIZE(default_list
); i
++) {
505 if (strcmp(default_list
[i
].driver
, driver
) != 0)
507 *(default_list
[i
].flag
) = 0;
512 static int parse_name(void *opaque
, QemuOpts
*opts
, Error
**errp
)
514 const char *proc_name
;
516 if (qemu_opt_get(opts
, "debug-threads")) {
517 qemu_thread_naming(qemu_opt_get_bool(opts
, "debug-threads", false));
519 qemu_name
= qemu_opt_get(opts
, "guest");
521 proc_name
= qemu_opt_get(opts
, "process");
523 os_set_proc_name(proc_name
);
529 bool defaults_enabled(void)
535 static int parse_add_fd(void *opaque
, QemuOpts
*opts
, Error
**errp
)
537 int fd
, dupfd
, flags
;
539 const char *fd_opaque
= NULL
;
542 fd
= qemu_opt_get_number(opts
, "fd", -1);
543 fdset_id
= qemu_opt_get_number(opts
, "set", -1);
544 fd_opaque
= qemu_opt_get(opts
, "opaque");
547 error_setg(errp
, "fd option is required and must be non-negative");
551 if (fd
<= STDERR_FILENO
) {
552 error_setg(errp
, "fd cannot be a standard I/O stream");
557 * All fds inherited across exec() necessarily have FD_CLOEXEC
558 * clear, while qemu sets FD_CLOEXEC on all other fds used internally.
560 flags
= fcntl(fd
, F_GETFD
);
561 if (flags
== -1 || (flags
& FD_CLOEXEC
)) {
562 error_setg(errp
, "fd is not valid or already in use");
567 error_setg(errp
, "set option is required and must be non-negative");
571 #ifdef F_DUPFD_CLOEXEC
572 dupfd
= fcntl(fd
, F_DUPFD_CLOEXEC
, 0);
576 qemu_set_cloexec(dupfd
);
580 error_setg(errp
, "error duplicating fd: %s", strerror(errno
));
584 /* add the duplicate fd, and optionally the opaque string, to the fd set */
585 fdinfo
= monitor_fdset_add_fd(dupfd
, true, fdset_id
, !!fd_opaque
, fd_opaque
,
592 static int cleanup_add_fd(void *opaque
, QemuOpts
*opts
, Error
**errp
)
596 fd
= qemu_opt_get_number(opts
, "fd", -1);
603 /***********************************************************/
604 /* QEMU Block devices */
606 #define HD_OPTS "media=disk"
607 #define CDROM_OPTS "media=cdrom"
609 #define PFLASH_OPTS ""
613 static int drive_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
615 BlockInterfaceType
*block_default_type
= opaque
;
617 return drive_new(opts
, *block_default_type
, errp
) == NULL
;
620 static int drive_enable_snapshot(void *opaque
, QemuOpts
*opts
, Error
**errp
)
622 if (qemu_opt_get(opts
, "snapshot") == NULL
) {
623 qemu_opt_set(opts
, "snapshot", "on", &error_abort
);
628 static void default_drive(int enable
, int snapshot
, BlockInterfaceType type
,
629 int index
, const char *optstr
)
634 if (!enable
|| drive_get_by_index(type
, index
)) {
638 opts
= drive_add(type
, index
, NULL
, optstr
);
640 drive_enable_snapshot(NULL
, opts
, NULL
);
643 dinfo
= drive_new(opts
, type
, &error_abort
);
644 dinfo
->is_default
= true;
648 static void configure_blockdev(BlockdevOptionsQueue
*bdo_queue
,
649 MachineClass
*machine_class
, int snapshot
)
652 * If the currently selected machine wishes to override the
653 * units-per-bus property of its default HBA interface type, do so
656 if (machine_class
->units_per_default_bus
) {
657 override_max_devs(machine_class
->block_default_type
,
658 machine_class
->units_per_default_bus
);
661 /* open the virtual block devices */
662 while (!QSIMPLEQ_EMPTY(bdo_queue
)) {
663 BlockdevOptionsQueueEntry
*bdo
= QSIMPLEQ_FIRST(bdo_queue
);
665 QSIMPLEQ_REMOVE_HEAD(bdo_queue
, entry
);
666 loc_push_restore(&bdo
->loc
);
667 qmp_blockdev_add(bdo
->bdo
, &error_fatal
);
669 qapi_free_BlockdevOptions(bdo
->bdo
);
673 qemu_opts_foreach(qemu_find_opts("drive"), drive_enable_snapshot
,
676 if (qemu_opts_foreach(qemu_find_opts("drive"), drive_init_func
,
677 &machine_class
->block_default_type
, &error_fatal
)) {
678 /* We printed help */
682 default_drive(default_cdrom
, snapshot
, machine_class
->block_default_type
, 2,
684 default_drive(default_floppy
, snapshot
, IF_FLOPPY
, 0, FD_OPTS
);
685 default_drive(default_sdcard
, snapshot
, IF_SD
, 0, SD_OPTS
);
689 static QemuOptsList qemu_smp_opts
= {
691 .implied_opt_name
= "cpus",
693 .head
= QTAILQ_HEAD_INITIALIZER(qemu_smp_opts
.head
),
697 .type
= QEMU_OPT_NUMBER
,
700 .type
= QEMU_OPT_NUMBER
,
703 .type
= QEMU_OPT_NUMBER
,
706 .type
= QEMU_OPT_NUMBER
,
709 .type
= QEMU_OPT_NUMBER
,
712 .type
= QEMU_OPT_NUMBER
,
718 static void realtime_init(void)
721 if (os_mlock() < 0) {
722 error_report("locking memory failed");
729 static void configure_msg(QemuOpts
*opts
)
731 message_with_timestamp
= qemu_opt_get_bool(opts
, "timestamp", false);
732 error_with_guestname
= qemu_opt_get_bool(opts
, "guest-name", false);
736 /***********************************************************/
739 static int usb_device_add(const char *devname
)
741 USBDevice
*dev
= NULL
;
743 if (!machine_usb(current_machine
)) {
747 dev
= usbdevice_create(devname
);
754 static int usb_parse(const char *cmdline
)
757 r
= usb_device_add(cmdline
);
759 error_report("could not add USB device '%s'", cmdline
);
764 /***********************************************************/
765 /* machine registration */
767 static MachineClass
*find_machine(const char *name
, GSList
*machines
)
771 for (el
= machines
; el
; el
= el
->next
) {
772 MachineClass
*mc
= el
->data
;
774 if (!strcmp(mc
->name
, name
) || !g_strcmp0(mc
->alias
, name
)) {
782 static MachineClass
*find_default_machine(GSList
*machines
)
785 MachineClass
*default_machineclass
= NULL
;
787 for (el
= machines
; el
; el
= el
->next
) {
788 MachineClass
*mc
= el
->data
;
790 if (mc
->is_default
) {
791 assert(default_machineclass
== NULL
&& "Multiple default machines");
792 default_machineclass
= mc
;
796 return default_machineclass
;
799 static void version(void)
801 printf("QEMU emulator version " QEMU_FULL_VERSION
"\n"
802 QEMU_COPYRIGHT
"\n");
805 static void help(int exitcode
)
808 printf("usage: %s [options] [disk_image]\n\n"
809 "'disk_image' is a raw hard disk image for IDE hard disk 0\n\n",
810 error_get_progname());
812 #define DEF(option, opt_arg, opt_enum, opt_help, arch_mask) \
813 if ((arch_mask) & arch_type) \
814 fputs(opt_help, stdout);
816 #define ARCHHEADING(text, arch_mask) \
817 if ((arch_mask) & arch_type) \
818 puts(stringify(text));
820 #define DEFHEADING(text) ARCHHEADING(text, QEMU_ARCH_ALL)
822 #include "qemu-options.def"
824 printf("\nDuring emulation, the following keys are useful:\n"
825 "ctrl-alt-f toggle full screen\n"
826 "ctrl-alt-n switch to virtual console 'n'\n"
827 "ctrl-alt toggle mouse and keyboard grab\n"
829 "When using -nographic, press 'ctrl-a h' to get some help.\n"
831 QEMU_HELP_BOTTOM
"\n");
836 #define HAS_ARG 0x0001
838 typedef struct QEMUOption
{
845 static const QEMUOption qemu_options
[] = {
846 { "h", 0, QEMU_OPTION_h
, QEMU_ARCH_ALL
},
848 #define DEF(option, opt_arg, opt_enum, opt_help, arch_mask) \
849 { option, opt_arg, opt_enum, arch_mask },
850 #define DEFHEADING(text)
851 #define ARCHHEADING(text, arch_mask)
853 #include "qemu-options.def"
857 typedef struct VGAInterfaceInfo
{
858 const char *opt_name
; /* option name */
859 const char *name
; /* human-readable name */
860 /* Class names indicating that support is available.
861 * If no class is specified, the interface is always available */
862 const char *class_names
[2];
865 static const VGAInterfaceInfo vga_interfaces
[VGA_TYPE_MAX
] = {
868 .name
= "no graphic card",
872 .name
= "standard VGA",
873 .class_names
= { "VGA", "isa-vga" },
876 .opt_name
= "cirrus",
877 .name
= "Cirrus VGA",
878 .class_names
= { "cirrus-vga", "isa-cirrus-vga" },
881 .opt_name
= "vmware",
882 .name
= "VMWare SVGA",
883 .class_names
= { "vmware-svga" },
886 .opt_name
= "virtio",
887 .name
= "Virtio VGA",
888 .class_names
= { "virtio-vga" },
893 .class_names
= { "qxl-vga" },
897 .name
= "TCX framebuffer",
898 .class_names
= { "sun-tcx" },
902 .name
= "CG3 framebuffer",
903 .class_names
= { "cgthree" },
907 .name
= "Xen paravirtualized framebuffer",
911 static bool vga_interface_available(VGAInterfaceType t
)
913 const VGAInterfaceInfo
*ti
= &vga_interfaces
[t
];
915 assert(t
< VGA_TYPE_MAX
);
916 return !ti
->class_names
[0] ||
917 module_object_class_by_name(ti
->class_names
[0]) ||
918 module_object_class_by_name(ti
->class_names
[1]);
922 get_default_vga_model(const MachineClass
*machine_class
)
924 if (machine_class
->default_display
) {
925 return machine_class
->default_display
;
926 } else if (vga_interface_available(VGA_CIRRUS
)) {
928 } else if (vga_interface_available(VGA_STD
)) {
935 static void select_vgahw(const MachineClass
*machine_class
, const char *p
)
940 if (g_str_equal(p
, "help")) {
941 const char *def
= get_default_vga_model(machine_class
);
943 for (t
= 0; t
< VGA_TYPE_MAX
; t
++) {
944 const VGAInterfaceInfo
*ti
= &vga_interfaces
[t
];
946 if (vga_interface_available(t
) && ti
->opt_name
) {
947 printf("%-20s %s%s\n", ti
->opt_name
, ti
->name
?: "",
948 g_str_equal(ti
->opt_name
, def
) ? " (default)" : "");
954 assert(vga_interface_type
== VGA_NONE
);
955 for (t
= 0; t
< VGA_TYPE_MAX
; t
++) {
956 const VGAInterfaceInfo
*ti
= &vga_interfaces
[t
];
957 if (ti
->opt_name
&& strstart(p
, ti
->opt_name
, &opts
)) {
958 if (!vga_interface_available(t
)) {
959 error_report("%s not available", ti
->name
);
962 vga_interface_type
= t
;
966 if (t
== VGA_TYPE_MAX
) {
968 error_report("unknown vga type: %s", p
);
974 if (strstart(opts
, ",retrace=", &nextopt
)) {
976 if (strstart(opts
, "dumb", &nextopt
))
977 vga_retrace_method
= VGA_RETRACE_DUMB
;
978 else if (strstart(opts
, "precise", &nextopt
))
979 vga_retrace_method
= VGA_RETRACE_PRECISE
;
980 else goto invalid_vga
;
981 } else goto invalid_vga
;
986 static void parse_display_qapi(const char *optarg
)
988 DisplayOptions
*opts
;
991 v
= qobject_input_visitor_new_str(optarg
, "type", &error_fatal
);
993 visit_type_DisplayOptions(v
, NULL
, &opts
, &error_fatal
);
994 QAPI_CLONE_MEMBERS(DisplayOptions
, &dpy
, opts
);
996 qapi_free_DisplayOptions(opts
);
1000 DisplayOptions
*qmp_query_display_options(Error
**errp
)
1002 return QAPI_CLONE(DisplayOptions
, &dpy
);
1005 static void parse_display(const char *p
)
1009 if (is_help_option(p
)) {
1010 qemu_display_help();
1014 if (strstart(p
, "sdl", &opts
)) {
1016 * sdl DisplayType needs hand-crafted parser instead of
1017 * parse_display_qapi() due to some options not in
1018 * DisplayOptions, specifically:
1019 * - ctrl_grab + alt_grab
1020 * Not clear yet what happens to them long-term. Should
1021 * replaced by something better or deprecated and dropped.
1023 #if defined(CONFIG_SDL)
1024 dpy
.type
= DISPLAY_TYPE_SDL
;
1026 const char *nextopt
;
1028 if (strstart(opts
, ",alt_grab=", &nextopt
)) {
1030 if (strstart(opts
, "on", &nextopt
)) {
1032 } else if (strstart(opts
, "off", &nextopt
)) {
1035 goto invalid_sdl_args
;
1037 } else if (strstart(opts
, ",ctrl_grab=", &nextopt
)) {
1039 if (strstart(opts
, "on", &nextopt
)) {
1041 } else if (strstart(opts
, "off", &nextopt
)) {
1044 goto invalid_sdl_args
;
1046 } else if (strstart(opts
, ",window_close=", &nextopt
) ||
1047 strstart(opts
, ",window-close=", &nextopt
)) {
1048 if (strstart(opts
, ",window_close=", NULL
)) {
1049 warn_report("window_close with an underscore is deprecated,"
1050 " please use window-close instead.");
1053 dpy
.has_window_close
= true;
1054 if (strstart(opts
, "on", &nextopt
)) {
1055 dpy
.window_close
= true;
1056 } else if (strstart(opts
, "off", &nextopt
)) {
1057 dpy
.window_close
= false;
1059 goto invalid_sdl_args
;
1061 } else if (strstart(opts
, ",show-cursor=", &nextopt
)) {
1063 dpy
.has_show_cursor
= true;
1064 if (strstart(opts
, "on", &nextopt
)) {
1065 dpy
.show_cursor
= true;
1066 } else if (strstart(opts
, "off", &nextopt
)) {
1067 dpy
.show_cursor
= false;
1069 goto invalid_sdl_args
;
1071 } else if (strstart(opts
, ",gl=", &nextopt
)) {
1074 if (strstart(opts
, "on", &nextopt
)) {
1075 dpy
.gl
= DISPLAYGL_MODE_ON
;
1076 } else if (strstart(opts
, "core", &nextopt
)) {
1077 dpy
.gl
= DISPLAYGL_MODE_CORE
;
1078 } else if (strstart(opts
, "es", &nextopt
)) {
1079 dpy
.gl
= DISPLAYGL_MODE_ES
;
1080 } else if (strstart(opts
, "off", &nextopt
)) {
1081 dpy
.gl
= DISPLAYGL_MODE_OFF
;
1083 goto invalid_sdl_args
;
1087 error_report("invalid SDL option string");
1093 error_report("SDL display supported is not available in this binary");
1096 } else if (strstart(p
, "vnc", &opts
)) {
1098 * vnc isn't a (local) DisplayType but a protocol for remote
1102 vnc_parse(opts
+ 1);
1104 error_report("VNC requires a display argument vnc=<display>");
1108 parse_display_qapi(p
);
1112 static inline bool nonempty_str(const char *str
)
1117 static int parse_fw_cfg(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1121 const char *name
, *file
, *str
, *gen_id
;
1122 FWCfgState
*fw_cfg
= (FWCfgState
*) opaque
;
1124 if (fw_cfg
== NULL
) {
1125 error_setg(errp
, "fw_cfg device not available");
1128 name
= qemu_opt_get(opts
, "name");
1129 file
= qemu_opt_get(opts
, "file");
1130 str
= qemu_opt_get(opts
, "string");
1131 gen_id
= qemu_opt_get(opts
, "gen_id");
1133 /* we need the name, and exactly one of: file, content string, gen_id */
1134 if (!nonempty_str(name
) ||
1135 nonempty_str(file
) + nonempty_str(str
) + nonempty_str(gen_id
) != 1) {
1136 error_setg(errp
, "name, plus exactly one of file,"
1137 " string and gen_id, are needed");
1140 if (strlen(name
) > FW_CFG_MAX_FILE_PATH
- 1) {
1141 error_setg(errp
, "name too long (max. %d char)",
1142 FW_CFG_MAX_FILE_PATH
- 1);
1145 if (nonempty_str(gen_id
)) {
1147 * In this particular case where the content is populated
1148 * internally, the "etc/" namespace protection is relaxed,
1149 * so do not emit a warning.
1151 } else if (strncmp(name
, "opt/", 4) != 0) {
1152 warn_report("externally provided fw_cfg item names "
1153 "should be prefixed with \"opt/\"");
1155 if (nonempty_str(str
)) {
1156 size
= strlen(str
); /* NUL terminator NOT included in fw_cfg blob */
1157 buf
= g_memdup(str
, size
);
1158 } else if (nonempty_str(gen_id
)) {
1159 if (!fw_cfg_add_from_generator(fw_cfg
, name
, gen_id
, errp
)) {
1165 if (!g_file_get_contents(file
, &buf
, &size
, &err
)) {
1166 error_setg(errp
, "can't load %s: %s", file
, err
->message
);
1171 /* For legacy, keep user files in a specific global order. */
1172 fw_cfg_set_order_override(fw_cfg
, FW_CFG_ORDER_OVERRIDE_USER
);
1173 fw_cfg_add_file(fw_cfg
, name
, buf
, size
);
1174 fw_cfg_reset_order_override(fw_cfg
);
1178 static int device_help_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1180 return qdev_device_help(opts
);
1183 static int device_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1187 dev
= qdev_device_add(opts
, errp
);
1188 if (!dev
&& *errp
) {
1189 error_report_err(*errp
);
1192 object_unref(OBJECT(dev
));
1197 static int chardev_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1199 Error
*local_err
= NULL
;
1201 if (!qemu_chr_new_from_opts(opts
, NULL
, &local_err
)) {
1203 error_propagate(errp
, local_err
);
1211 #ifdef CONFIG_VIRTFS
1212 static int fsdev_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1214 return qemu_fsdev_add(opts
, errp
);
1218 static int mon_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1220 return monitor_init_opts(opts
, errp
);
1223 static void monitor_parse(const char *optarg
, const char *mode
, bool pretty
)
1225 static int monitor_device_index
= 0;
1230 if (strstart(optarg
, "chardev:", &p
)) {
1231 snprintf(label
, sizeof(label
), "%s", p
);
1233 snprintf(label
, sizeof(label
), "compat_monitor%d",
1234 monitor_device_index
);
1235 opts
= qemu_chr_parse_compat(label
, optarg
, true);
1237 error_report("parse error: %s", optarg
);
1242 opts
= qemu_opts_create(qemu_find_opts("mon"), label
, 1, &error_fatal
);
1243 qemu_opt_set(opts
, "mode", mode
, &error_abort
);
1244 qemu_opt_set(opts
, "chardev", label
, &error_abort
);
1245 if (!strcmp(mode
, "control")) {
1246 qemu_opt_set_bool(opts
, "pretty", pretty
, &error_abort
);
1248 assert(pretty
== false);
1250 monitor_device_index
++;
1253 struct device_config
{
1255 DEV_USB
, /* -usbdevice */
1256 DEV_SERIAL
, /* -serial */
1257 DEV_PARALLEL
, /* -parallel */
1258 DEV_DEBUGCON
, /* -debugcon */
1259 DEV_GDB
, /* -gdb, -s */
1260 DEV_SCLP
, /* s390 sclp */
1262 const char *cmdline
;
1264 QTAILQ_ENTRY(device_config
) next
;
1267 static QTAILQ_HEAD(, device_config
) device_configs
=
1268 QTAILQ_HEAD_INITIALIZER(device_configs
);
1270 static void add_device_config(int type
, const char *cmdline
)
1272 struct device_config
*conf
;
1274 conf
= g_malloc0(sizeof(*conf
));
1276 conf
->cmdline
= cmdline
;
1277 loc_save(&conf
->loc
);
1278 QTAILQ_INSERT_TAIL(&device_configs
, conf
, next
);
1281 static int foreach_device_config(int type
, int (*func
)(const char *cmdline
))
1283 struct device_config
*conf
;
1286 QTAILQ_FOREACH(conf
, &device_configs
, next
) {
1287 if (conf
->type
!= type
)
1289 loc_push_restore(&conf
->loc
);
1290 rc
= func(conf
->cmdline
);
1291 loc_pop(&conf
->loc
);
1299 static void qemu_disable_default_devices(void)
1301 MachineClass
*machine_class
= MACHINE_GET_CLASS(current_machine
);
1303 qemu_opts_foreach(qemu_find_opts("device"),
1304 default_driver_check
, NULL
, NULL
);
1305 qemu_opts_foreach(qemu_find_opts("global"),
1306 default_driver_check
, NULL
, NULL
);
1308 if (!vga_model
&& !default_vga
) {
1309 vga_interface_type
= VGA_DEVICE
;
1311 if (!has_defaults
|| machine_class
->no_serial
) {
1314 if (!has_defaults
|| machine_class
->no_parallel
) {
1315 default_parallel
= 0;
1317 if (!has_defaults
|| machine_class
->no_floppy
) {
1320 if (!has_defaults
|| machine_class
->no_cdrom
) {
1323 if (!has_defaults
|| machine_class
->no_sdcard
) {
1326 if (!has_defaults
) {
1327 default_monitor
= 0;
1333 static void qemu_create_default_devices(void)
1335 MachineClass
*machine_class
= MACHINE_GET_CLASS(current_machine
);
1337 if (is_daemonized()) {
1338 /* According to documentation and historically, -nographic redirects
1339 * serial port, parallel port and monitor to stdio, which does not work
1340 * with -daemonize. We can redirect these to null instead, but since
1341 * -nographic is legacy, let's just error out.
1342 * We disallow -nographic only if all other ports are not redirected
1343 * explicitly, to not break existing legacy setups which uses
1344 * -nographic _and_ redirects all ports explicitly - this is valid
1345 * usage, -nographic is just a no-op in this case.
1348 && (default_parallel
|| default_serial
|| default_monitor
)) {
1349 error_report("-nographic cannot be used with -daemonize");
1355 if (default_parallel
)
1356 add_device_config(DEV_PARALLEL
, "null");
1357 if (default_serial
&& default_monitor
) {
1358 add_device_config(DEV_SERIAL
, "mon:stdio");
1361 add_device_config(DEV_SERIAL
, "stdio");
1362 if (default_monitor
)
1363 monitor_parse("stdio", "readline", false);
1367 add_device_config(DEV_SERIAL
, "vc:80Cx24C");
1368 if (default_parallel
)
1369 add_device_config(DEV_PARALLEL
, "vc:80Cx24C");
1370 if (default_monitor
)
1371 monitor_parse("vc:80Cx24C", "readline", false);
1375 QemuOptsList
*net
= qemu_find_opts("net");
1376 qemu_opts_parse(net
, "nic", true, &error_abort
);
1378 qemu_opts_parse(net
, "user", true, &error_abort
);
1382 #if defined(CONFIG_VNC)
1383 if (!QTAILQ_EMPTY(&(qemu_find_opts("vnc")->head
))) {
1387 if (dpy
.type
== DISPLAY_TYPE_DEFAULT
&& !display_remote
) {
1388 if (!qemu_display_find_default(&dpy
)) {
1389 dpy
.type
= DISPLAY_TYPE_NONE
;
1390 #if defined(CONFIG_VNC)
1391 vnc_parse("localhost:0,to=99,id=default");
1395 if (dpy
.type
== DISPLAY_TYPE_DEFAULT
) {
1396 dpy
.type
= DISPLAY_TYPE_NONE
;
1399 /* If no default VGA is requested, the default is "none". */
1401 vga_model
= get_default_vga_model(machine_class
);
1404 select_vgahw(machine_class
, vga_model
);
1408 static int serial_parse(const char *devname
)
1410 int index
= num_serial_hds
;
1413 if (strcmp(devname
, "none") == 0)
1415 snprintf(label
, sizeof(label
), "serial%d", index
);
1416 serial_hds
= g_renew(Chardev
*, serial_hds
, index
+ 1);
1418 serial_hds
[index
] = qemu_chr_new_mux_mon(label
, devname
, NULL
);
1419 if (!serial_hds
[index
]) {
1420 error_report("could not connect serial device"
1421 " to character backend '%s'", devname
);
1428 Chardev
*serial_hd(int i
)
1431 if (i
< num_serial_hds
) {
1432 return serial_hds
[i
];
1437 static int parallel_parse(const char *devname
)
1439 static int index
= 0;
1442 if (strcmp(devname
, "none") == 0)
1444 if (index
== MAX_PARALLEL_PORTS
) {
1445 error_report("too many parallel ports");
1448 snprintf(label
, sizeof(label
), "parallel%d", index
);
1449 parallel_hds
[index
] = qemu_chr_new_mux_mon(label
, devname
, NULL
);
1450 if (!parallel_hds
[index
]) {
1451 error_report("could not connect parallel device"
1452 " to character backend '%s'", devname
);
1459 static int debugcon_parse(const char *devname
)
1463 if (!qemu_chr_new_mux_mon("debugcon", devname
, NULL
)) {
1464 error_report("invalid character backend '%s'", devname
);
1467 opts
= qemu_opts_create(qemu_find_opts("device"), "debugcon", 1, NULL
);
1469 error_report("already have a debugcon device");
1472 qemu_opt_set(opts
, "driver", "isa-debugcon", &error_abort
);
1473 qemu_opt_set(opts
, "chardev", "debugcon", &error_abort
);
1477 static gint
machine_class_cmp(gconstpointer a
, gconstpointer b
)
1479 const MachineClass
*mc1
= a
, *mc2
= b
;
1482 if (mc1
->family
== NULL
) {
1483 if (mc2
->family
== NULL
) {
1484 /* Compare standalone machine types against each other; they sort
1485 * in increasing order.
1487 return strcmp(object_class_get_name(OBJECT_CLASS(mc1
)),
1488 object_class_get_name(OBJECT_CLASS(mc2
)));
1491 /* Standalone machine types sort after families. */
1495 if (mc2
->family
== NULL
) {
1496 /* Families sort before standalone machine types. */
1500 /* Families sort between each other alphabetically increasingly. */
1501 res
= strcmp(mc1
->family
, mc2
->family
);
1506 /* Within the same family, machine types sort in decreasing order. */
1507 return strcmp(object_class_get_name(OBJECT_CLASS(mc2
)),
1508 object_class_get_name(OBJECT_CLASS(mc1
)));
1511 static void machine_help_func(const QDict
*qdict
)
1513 GSList
*machines
, *el
;
1514 const char *type
= qdict_get_try_str(qdict
, "type");
1516 machines
= object_class_get_list(TYPE_MACHINE
, false);
1518 ObjectClass
*machine_class
= OBJECT_CLASS(find_machine(type
, machines
));
1519 if (machine_class
) {
1520 type_print_class_properties(object_class_get_name(machine_class
));
1525 printf("Supported machines are:\n");
1526 machines
= g_slist_sort(machines
, machine_class_cmp
);
1527 for (el
= machines
; el
; el
= el
->next
) {
1528 MachineClass
*mc
= el
->data
;
1530 printf("%-20s %s (alias of %s)\n", mc
->alias
, mc
->desc
, mc
->name
);
1532 printf("%-20s %s%s%s\n", mc
->name
, mc
->desc
,
1533 mc
->is_default
? " (default)" : "",
1534 mc
->deprecation_reason
? " (deprecated)" : "");
1539 machine_merge_property(const char *propname
, QDict
*prop
, Error
**errp
)
1544 /* Preserve the caller's reference to prop. */
1546 qdict_put(opts
, propname
, prop
);
1547 keyval_merge(machine_opts_dict
, opts
, errp
);
1548 qobject_unref(opts
);
1552 machine_parse_property_opt(QemuOptsList
*opts_list
, const char *propname
,
1558 prop
= keyval_parse(arg
, opts_list
->implied_opt_name
, &help
, &error_fatal
);
1560 qemu_opts_print_help(opts_list
, true);
1563 machine_merge_property(propname
, prop
, &error_fatal
);
1564 qobject_unref(prop
);
1567 static const char *pid_file
;
1568 static Notifier qemu_unlink_pidfile_notifier
;
1570 static void qemu_unlink_pidfile(Notifier
*n
, void *data
)
1577 static const QEMUOption
*lookup_opt(int argc
, char **argv
,
1578 const char **poptarg
, int *poptind
)
1580 const QEMUOption
*popt
;
1581 int optind
= *poptind
;
1582 char *r
= argv
[optind
];
1585 loc_set_cmdline(argv
, optind
, 1);
1587 /* Treat --foo the same as -foo. */
1590 popt
= qemu_options
;
1593 error_report("invalid option");
1596 if (!strcmp(popt
->name
, r
+ 1))
1600 if (popt
->flags
& HAS_ARG
) {
1601 if (optind
>= argc
) {
1602 error_report("requires an argument");
1605 optarg
= argv
[optind
++];
1606 loc_set_cmdline(argv
, optind
- 2, 2);
1617 static MachineClass
*select_machine(QDict
*qdict
, Error
**errp
)
1619 const char *optarg
= qdict_get_try_str(qdict
, "type");
1620 GSList
*machines
= object_class_get_list(TYPE_MACHINE
, false);
1621 MachineClass
*machine_class
;
1622 Error
*local_err
= NULL
;
1625 machine_class
= find_machine(optarg
, machines
);
1626 qdict_del(qdict
, "type");
1627 if (!machine_class
) {
1628 error_setg(&local_err
, "unsupported machine type");
1631 machine_class
= find_default_machine(machines
);
1632 if (!machine_class
) {
1633 error_setg(&local_err
, "No machine specified, and there is no default");
1637 g_slist_free(machines
);
1639 error_append_hint(&local_err
, "Use -machine help to list supported machines\n");
1640 error_propagate(errp
, local_err
);
1642 return machine_class
;
1645 static int object_parse_property_opt(Object
*obj
,
1646 const char *name
, const char *value
,
1647 const char *skip
, Error
**errp
)
1649 if (g_str_equal(name
, skip
)) {
1653 if (!object_property_parse(obj
, name
, value
, errp
)) {
1660 /* *Non*recursively replace underscores with dashes in QDict keys. */
1661 static void keyval_dashify(QDict
*qdict
, Error
**errp
)
1663 const QDictEntry
*ent
, *next
;
1666 for (ent
= qdict_first(qdict
); ent
; ent
= next
) {
1667 g_autofree
char *new_key
= NULL
;
1669 next
= qdict_next(qdict
, ent
);
1670 if (!strchr(ent
->key
, '_')) {
1673 new_key
= g_strdup(ent
->key
);
1674 for (p
= new_key
; *p
; p
++) {
1679 if (qdict_haskey(qdict
, new_key
)) {
1680 error_setg(errp
, "Conflict between '%s' and '%s'", ent
->key
, new_key
);
1683 qobject_ref(ent
->value
);
1684 qdict_put_obj(qdict
, new_key
, ent
->value
);
1685 qdict_del(qdict
, ent
->key
);
1689 static void qemu_apply_legacy_machine_options(QDict
*qdict
)
1693 keyval_dashify(qdict
, &error_fatal
);
1695 /* Legacy options do not correspond to MachineState properties. */
1696 value
= qdict_get_try_str(qdict
, "accel");
1698 accelerators
= g_strdup(value
);
1699 qdict_del(qdict
, "accel");
1702 value
= qdict_get_try_str(qdict
, "igd-passthru");
1704 object_register_sugar_prop(ACCEL_CLASS_NAME("xen"), "igd-passthru", value
,
1706 qdict_del(qdict
, "igd-passthru");
1709 value
= qdict_get_try_str(qdict
, "kvm-shadow-mem");
1711 object_register_sugar_prop(ACCEL_CLASS_NAME("kvm"), "kvm-shadow-mem", value
,
1713 qdict_del(qdict
, "kvm-shadow-mem");
1716 value
= qdict_get_try_str(qdict
, "kernel-irqchip");
1718 object_register_sugar_prop(ACCEL_CLASS_NAME("kvm"), "kernel-irqchip", value
,
1720 object_register_sugar_prop(ACCEL_CLASS_NAME("whpx"), "kernel-irqchip", value
,
1722 qdict_del(qdict
, "kernel-irqchip");
1726 static void object_option_foreach_add(bool (*type_opt_predicate
)(const char *))
1728 ObjectOption
*opt
, *next
;
1730 QTAILQ_FOREACH_SAFE(opt
, &object_opts
, next
, next
) {
1731 const char *type
= ObjectType_str(opt
->opts
->qom_type
);
1732 if (type_opt_predicate(type
)) {
1733 user_creatable_add_qapi(opt
->opts
, &error_fatal
);
1734 qapi_free_ObjectOptions(opt
->opts
);
1735 QTAILQ_REMOVE(&object_opts
, opt
, next
);
1741 static void object_option_add_visitor(Visitor
*v
)
1743 ObjectOption
*opt
= g_new0(ObjectOption
, 1);
1744 visit_type_ObjectOptions(v
, NULL
, &opt
->opts
, &error_fatal
);
1745 QTAILQ_INSERT_TAIL(&object_opts
, opt
, next
);
1748 static void object_option_parse(const char *optarg
)
1754 if (optarg
[0] == '{') {
1755 QObject
*obj
= qobject_from_json(optarg
, &error_fatal
);
1757 v
= qobject_input_visitor_new(obj
);
1760 opts
= qemu_opts_parse_noisily(qemu_find_opts("object"),
1766 type
= qemu_opt_get(opts
, "qom-type");
1768 error_setg(&error_fatal
, QERR_MISSING_PARAMETER
, "qom-type");
1770 if (user_creatable_print_help(type
, opts
)) {
1774 v
= opts_visitor_new(opts
);
1777 object_option_add_visitor(v
);
1782 * Initial object creation happens before all other
1783 * QEMU data types are created. The majority of objects
1784 * can be created at this point. The rng-egd object
1785 * cannot be created here, as it depends on the chardev
1788 static bool object_create_early(const char *type
)
1791 * Objects should not be made "delayed" without a reason. If you
1792 * add one, state the reason in a comment!
1795 /* Reason: property "chardev" */
1796 if (g_str_equal(type
, "rng-egd") ||
1797 g_str_equal(type
, "qtest")) {
1801 #if defined(CONFIG_VHOST_USER) && defined(CONFIG_LINUX)
1802 /* Reason: cryptodev-vhost-user property "chardev" */
1803 if (g_str_equal(type
, "cryptodev-vhost-user")) {
1808 /* Reason: vhost-user-blk-server property "node-name" */
1809 if (g_str_equal(type
, "vhost-user-blk-server")) {
1813 * Reason: filter-* property "netdev" etc.
1815 if (g_str_equal(type
, "filter-buffer") ||
1816 g_str_equal(type
, "filter-dump") ||
1817 g_str_equal(type
, "filter-mirror") ||
1818 g_str_equal(type
, "filter-redirector") ||
1819 g_str_equal(type
, "colo-compare") ||
1820 g_str_equal(type
, "filter-rewriter") ||
1821 g_str_equal(type
, "filter-replay")) {
1826 * Allocation of large amounts of memory may delay
1827 * chardev initialization for too long, and trigger timeouts
1828 * on software that waits for a monitor socket to be created
1831 if (g_str_has_prefix(type
, "memory-backend-")) {
1838 static void qemu_apply_machine_options(QDict
*qdict
)
1840 MachineClass
*machine_class
= MACHINE_GET_CLASS(current_machine
);
1841 const char *boot_order
= NULL
;
1842 const char *boot_once
= NULL
;
1845 object_set_properties_from_keyval(OBJECT(current_machine
), qdict
, false, &error_fatal
);
1846 current_machine
->ram_size
= ram_size
;
1847 current_machine
->maxram_size
= maxram_size
;
1848 current_machine
->ram_slots
= ram_slots
;
1850 opts
= qemu_opts_find(qemu_find_opts("boot-opts"), NULL
);
1852 boot_order
= qemu_opt_get(opts
, "order");
1854 validate_bootdevices(boot_order
, &error_fatal
);
1857 boot_once
= qemu_opt_get(opts
, "once");
1859 validate_bootdevices(boot_once
, &error_fatal
);
1862 boot_menu
= qemu_opt_get_bool(opts
, "menu", boot_menu
);
1863 boot_strict
= qemu_opt_get_bool(opts
, "strict", false);
1867 boot_order
= machine_class
->default_boot_order
;
1870 current_machine
->boot_order
= boot_order
;
1871 current_machine
->boot_once
= boot_once
;
1873 if (semihosting_enabled() && !semihosting_get_argc()) {
1874 /* fall back to the -kernel/-append */
1875 semihosting_arg_fallback(current_machine
->kernel_filename
, current_machine
->kernel_cmdline
);
1878 if (current_machine
->smp
.cpus
> 1) {
1879 Error
*blocker
= NULL
;
1880 error_setg(&blocker
, QERR_REPLAY_NOT_SUPPORTED
, "smp");
1881 replay_add_blocker(blocker
);
1885 static void qemu_create_early_backends(void)
1887 MachineClass
*machine_class
= MACHINE_GET_CLASS(current_machine
);
1888 #if defined(CONFIG_SDL)
1889 const bool use_sdl
= (dpy
.type
== DISPLAY_TYPE_SDL
);
1891 const bool use_sdl
= false;
1893 #if defined(CONFIG_GTK)
1894 const bool use_gtk
= (dpy
.type
== DISPLAY_TYPE_GTK
);
1896 const bool use_gtk
= false;
1899 if ((alt_grab
|| ctrl_grab
) && !use_sdl
) {
1900 error_report("-alt-grab and -ctrl-grab are only valid "
1901 "for SDL, ignoring option");
1903 if (dpy
.has_window_close
&& !use_gtk
&& !use_sdl
) {
1904 error_report("-no-quit is only valid for GTK and SDL, "
1908 qemu_display_early_init(&dpy
);
1909 qemu_console_early_init();
1911 if (dpy
.has_gl
&& dpy
.gl
!= DISPLAYGL_MODE_OFF
&& display_opengl
== 0) {
1912 #if defined(CONFIG_OPENGL)
1913 error_report("OpenGL is not supported by the display");
1915 error_report("OpenGL support is disabled");
1920 object_option_foreach_add(object_create_early
);
1922 /* spice needs the timers to be initialized by this point */
1923 /* spice must initialize before audio as it changes the default auiodev */
1924 /* spice must initialize before chardevs (for spicevmc and spiceport) */
1927 qemu_opts_foreach(qemu_find_opts("chardev"),
1928 chardev_init_func
, NULL
, &error_fatal
);
1930 #ifdef CONFIG_VIRTFS
1931 qemu_opts_foreach(qemu_find_opts("fsdev"),
1932 fsdev_init_func
, NULL
, &error_fatal
);
1936 * Note: we need to create audio and block backends before
1937 * setting machine properties, so they can be referred to.
1939 configure_blockdev(&bdo_queue
, machine_class
, snapshot
);
1940 audio_init_audiodevs();
1945 * The remainder of object creation happens after the
1946 * creation of chardev, fsdev, net clients and device data types.
1948 static bool object_create_late(const char *type
)
1950 return !object_create_early(type
);
1953 static void qemu_create_late_backends(void)
1956 qtest_server_init(qtest_chrdev
, qtest_log
, &error_fatal
);
1959 net_init_clients(&error_fatal
);
1961 object_option_foreach_add(object_create_late
);
1963 if (tpm_init() < 0) {
1967 qemu_opts_foreach(qemu_find_opts("mon"),
1968 mon_init_func
, NULL
, &error_fatal
);
1970 if (foreach_device_config(DEV_SERIAL
, serial_parse
) < 0)
1972 if (foreach_device_config(DEV_PARALLEL
, parallel_parse
) < 0)
1974 if (foreach_device_config(DEV_DEBUGCON
, debugcon_parse
) < 0)
1977 /* now chardevs have been created we may have semihosting to connect */
1978 qemu_semihosting_connect_chardevs();
1979 qemu_semihosting_console_init();
1982 static bool have_custom_ram_size(void)
1984 QemuOpts
*opts
= qemu_find_opts_singleton("memory");
1985 return !!qemu_opt_get_size(opts
, "size", 0);
1988 static void qemu_resolve_machine_memdev(void)
1990 if (current_machine
->ram_memdev_id
) {
1992 ram_addr_t backend_size
;
1994 backend
= object_resolve_path_type(current_machine
->ram_memdev_id
,
1995 TYPE_MEMORY_BACKEND
, NULL
);
1997 error_report("Memory backend '%s' not found",
1998 current_machine
->ram_memdev_id
);
2001 backend_size
= object_property_get_uint(backend
, "size", &error_abort
);
2002 if (have_custom_ram_size() && backend_size
!= ram_size
) {
2003 error_report("Size specified by -m option must match size of "
2004 "explicitly specified 'memory-backend' property");
2008 error_report("'-mem-path' can't be used together with"
2009 "'-machine memory-backend'");
2012 ram_size
= backend_size
;
2015 if (!xen_enabled()) {
2016 /* On 32-bit hosts, QEMU is limited by virtual address space */
2017 if (ram_size
> (2047 << 20) && HOST_LONG_BITS
== 32) {
2018 error_report("at most 2047 MB RAM can be simulated");
2024 static void set_memory_options(MachineClass
*mc
)
2027 const char *mem_str
;
2028 const ram_addr_t default_ram_size
= mc
->default_ram_size
;
2029 QemuOpts
*opts
= qemu_find_opts_singleton("memory");
2032 loc_push_none(&loc
);
2033 qemu_opts_loc_restore(opts
);
2036 mem_str
= qemu_opt_get(opts
, "size");
2039 error_report("missing 'size' option value");
2043 sz
= qemu_opt_get_size(opts
, "size", ram_size
);
2045 /* Fix up legacy suffix-less format */
2046 if (g_ascii_isdigit(mem_str
[strlen(mem_str
) - 1])) {
2047 uint64_t overflow_check
= sz
;
2050 if (sz
/ MiB
!= overflow_check
) {
2051 error_report("too large 'size' option value");
2057 /* backward compatibility behaviour for case "-m 0" */
2059 sz
= default_ram_size
;
2062 sz
= QEMU_ALIGN_UP(sz
, 8192);
2063 if (mc
->fixup_ram_size
) {
2064 sz
= mc
->fixup_ram_size(sz
);
2067 if (ram_size
!= sz
) {
2068 error_report("ram size too large");
2072 maxram_size
= ram_size
;
2074 if (qemu_opt_get(opts
, "maxmem")) {
2077 sz
= qemu_opt_get_size(opts
, "maxmem", 0);
2078 slots
= qemu_opt_get_number(opts
, "slots", 0);
2079 if (sz
< ram_size
) {
2080 error_report("invalid value of -m option maxmem: "
2081 "maximum memory size (0x%" PRIx64
") must be at least "
2082 "the initial memory size (0x" RAM_ADDR_FMT
")",
2085 } else if (slots
&& sz
== ram_size
) {
2086 error_report("invalid value of -m option maxmem: "
2087 "memory slots were specified but maximum memory size "
2088 "(0x%" PRIx64
") is equal to the initial memory size "
2089 "(0x" RAM_ADDR_FMT
")", sz
, ram_size
);
2095 } else if (qemu_opt_get(opts
, "slots")) {
2096 error_report("invalid -m option value: missing 'maxmem' option");
2103 static void qemu_create_machine(QDict
*qdict
)
2105 MachineClass
*machine_class
= select_machine(qdict
, &error_fatal
);
2106 object_set_machine_compat_props(machine_class
->compat_props
);
2108 set_memory_options(machine_class
);
2110 current_machine
= MACHINE(object_new_with_class(OBJECT_CLASS(machine_class
)));
2111 object_property_add_child(object_get_root(), "machine",
2112 OBJECT(current_machine
));
2113 object_property_add_child(container_get(OBJECT(current_machine
),
2115 "sysbus", OBJECT(sysbus_get_default()));
2117 if (machine_class
->minimum_page_bits
) {
2118 if (!set_preferred_target_page_bits(machine_class
->minimum_page_bits
)) {
2119 /* This would be a board error: specifying a minimum smaller than
2120 * a target's compile-time fixed setting.
2122 g_assert_not_reached();
2126 cpu_exec_init_all();
2129 if (machine_class
->hw_version
) {
2130 qemu_set_hw_version(machine_class
->hw_version
);
2134 * Get the default machine options from the machine if it is not already
2135 * specified either by the configuration file or by the command line.
2137 if (machine_class
->default_machine_opts
) {
2138 QDict
*default_opts
=
2139 keyval_parse(machine_class
->default_machine_opts
, NULL
, NULL
,
2141 qemu_apply_legacy_machine_options(default_opts
);
2142 object_set_properties_from_keyval(OBJECT(current_machine
), default_opts
,
2143 false, &error_abort
);
2144 qobject_unref(default_opts
);
2148 static int global_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2152 g
= g_malloc0(sizeof(*g
));
2153 g
->driver
= qemu_opt_get(opts
, "driver");
2154 g
->property
= qemu_opt_get(opts
, "property");
2155 g
->value
= qemu_opt_get(opts
, "value");
2156 qdev_prop_register_global(g
);
2161 * Return whether configuration group @group is stored in QemuOpts, or
2162 * recorded as one or more QDicts by qemu_record_config_group.
2164 static bool is_qemuopts_group(const char *group
)
2166 if (g_str_equal(group
, "object") ||
2167 g_str_equal(group
, "machine") ||
2168 g_str_equal(group
, "smp-opts")) {
2174 static void qemu_record_config_group(const char *group
, QDict
*dict
,
2175 bool from_json
, Error
**errp
)
2177 if (g_str_equal(group
, "object")) {
2178 Visitor
*v
= qobject_input_visitor_new_keyval(QOBJECT(dict
));
2179 object_option_add_visitor(v
);
2181 } else if (g_str_equal(group
, "machine")) {
2183 * Cannot merge string-valued and type-safe dictionaries, so JSON
2184 * is not accepted yet for -M.
2187 keyval_merge(machine_opts_dict
, dict
, errp
);
2188 } else if (g_str_equal(group
, "smp-opts")) {
2189 machine_merge_property("smp", dict
, &error_fatal
);
2196 * Parse non-QemuOpts config file groups, pass the rest to
2197 * qemu_config_do_parse.
2199 static void qemu_parse_config_group(const char *group
, QDict
*qdict
,
2200 void *opaque
, Error
**errp
)
2203 if (is_qemuopts_group(group
)) {
2204 qemu_config_do_parse(group
, qdict
, opaque
, errp
);
2208 crumpled
= qdict_crumple(qdict
, errp
);
2212 switch (qobject_type(crumpled
)) {
2214 qemu_record_config_group(group
, qobject_to(QDict
, crumpled
), false, errp
);
2217 error_setg(errp
, "Lists cannot be at top level of a configuration section");
2220 g_assert_not_reached();
2222 qobject_unref(crumpled
);
2225 static void qemu_read_default_config_file(Error
**errp
)
2229 g_autofree
char *file
= get_relocated_path(CONFIG_QEMU_CONFDIR
"/qemu.conf");
2231 ret
= qemu_read_config_file(file
, qemu_parse_config_group
, errp
);
2233 if (ret
== -ENOENT
) {
2240 static void qemu_set_option(const char *str
, Error
**errp
)
2242 char group
[64], id
[64], arg
[64];
2247 rc
= sscanf(str
, "%63[^.].%63[^.].%63[^=]%n", group
, id
, arg
, &offset
);
2248 if (rc
< 3 || str
[offset
] != '=') {
2249 error_setg(errp
, "can't parse: \"%s\"", str
);
2253 if (!is_qemuopts_group(group
)) {
2254 error_setg(errp
, "-set is not supported with %s", group
);
2256 list
= qemu_find_opts_err(group
, errp
);
2258 opts
= qemu_opts_find(list
, id
);
2260 error_setg(errp
, "there is no %s \"%s\" defined", group
, id
);
2263 qemu_opt_set(opts
, arg
, str
+ offset
+ 1, errp
);
2268 static void user_register_global_props(void)
2270 qemu_opts_foreach(qemu_find_opts("global"),
2271 global_init_func
, NULL
, NULL
);
2274 static int do_configure_icount(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2276 icount_configure(opts
, errp
);
2280 static int accelerator_set_property(void *opaque
,
2281 const char *name
, const char *value
,
2284 return object_parse_property_opt(opaque
, name
, value
, "accel", errp
);
2287 static int do_configure_accelerator(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2289 bool *p_init_failed
= opaque
;
2290 const char *acc
= qemu_opt_get(opts
, "accel");
2291 AccelClass
*ac
= accel_find(acc
);
2294 bool qtest_with_kvm
;
2296 qtest_with_kvm
= g_str_equal(acc
, "kvm") && qtest_chrdev
!= NULL
;
2299 *p_init_failed
= true;
2300 if (!qtest_with_kvm
) {
2301 error_report("invalid accelerator %s", acc
);
2305 accel
= ACCEL(object_new_with_class(OBJECT_CLASS(ac
)));
2306 object_apply_compat_props(OBJECT(accel
));
2307 qemu_opt_foreach(opts
, accelerator_set_property
,
2311 ret
= accel_init_machine(accel
, current_machine
);
2313 *p_init_failed
= true;
2314 if (!qtest_with_kvm
|| ret
!= -ENOENT
) {
2315 error_report("failed to initialize %s: %s", acc
, strerror(-ret
));
2323 static void configure_accelerators(const char *progname
)
2325 bool init_failed
= false;
2327 qemu_opts_foreach(qemu_find_opts("icount"),
2328 do_configure_icount
, NULL
, &error_fatal
);
2330 if (QTAILQ_EMPTY(&qemu_accel_opts
.head
)) {
2331 char **accel_list
, **tmp
;
2333 if (accelerators
== NULL
) {
2334 /* Select the default accelerator */
2335 bool have_tcg
= accel_find("tcg");
2336 bool have_kvm
= accel_find("kvm");
2338 if (have_tcg
&& have_kvm
) {
2339 if (g_str_has_suffix(progname
, "kvm")) {
2340 /* If the program name ends with "kvm", we prefer KVM */
2341 accelerators
= "kvm:tcg";
2343 accelerators
= "tcg:kvm";
2345 } else if (have_kvm
) {
2346 accelerators
= "kvm";
2347 } else if (have_tcg
) {
2348 accelerators
= "tcg";
2350 error_report("No accelerator selected and"
2351 " no default accelerator available");
2355 accel_list
= g_strsplit(accelerators
, ":", 0);
2357 for (tmp
= accel_list
; *tmp
; tmp
++) {
2359 * Filter invalid accelerators here, to prevent obscenities
2360 * such as "-machine accel=tcg,,thread=single".
2362 if (accel_find(*tmp
)) {
2363 qemu_opts_parse_noisily(qemu_find_opts("accel"), *tmp
, true);
2366 error_report("invalid accelerator %s", *tmp
);
2369 g_strfreev(accel_list
);
2371 if (accelerators
!= NULL
) {
2372 error_report("The -accel and \"-machine accel=\" options are incompatible");
2377 if (!qemu_opts_foreach(qemu_find_opts("accel"),
2378 do_configure_accelerator
, &init_failed
, &error_fatal
)) {
2380 error_report("no accelerator found");
2385 if (init_failed
&& !qtest_chrdev
) {
2386 AccelClass
*ac
= ACCEL_GET_CLASS(current_accel());
2387 error_report("falling back to %s", ac
->name
);
2390 if (icount_enabled() && !tcg_enabled()) {
2391 error_report("-icount is not allowed with hardware virtualization");
2396 static void create_default_memdev(MachineState
*ms
, const char *path
)
2399 MachineClass
*mc
= MACHINE_GET_CLASS(ms
);
2401 obj
= object_new(path
? TYPE_MEMORY_BACKEND_FILE
: TYPE_MEMORY_BACKEND_RAM
);
2403 object_property_set_str(obj
, "mem-path", path
, &error_fatal
);
2405 object_property_set_int(obj
, "size", ms
->ram_size
, &error_fatal
);
2406 object_property_add_child(object_get_objects_root(), mc
->default_ram_id
,
2408 /* Ensure backend's memory region name is equal to mc->default_ram_id */
2409 object_property_set_bool(obj
, "x-use-canonical-path-for-ramblock-id",
2410 false, &error_fatal
);
2411 user_creatable_complete(USER_CREATABLE(obj
), &error_fatal
);
2413 object_property_set_str(OBJECT(ms
), "memory-backend", mc
->default_ram_id
,
2417 static void qemu_validate_options(const QDict
*machine_opts
)
2419 const char *kernel_filename
= qdict_get_try_str(machine_opts
, "kernel");
2420 const char *initrd_filename
= qdict_get_try_str(machine_opts
, "initrd");
2421 const char *kernel_cmdline
= qdict_get_try_str(machine_opts
, "append");
2423 if (kernel_filename
== NULL
) {
2424 if (kernel_cmdline
!= NULL
) {
2425 error_report("-append only allowed with -kernel option");
2429 if (initrd_filename
!= NULL
) {
2430 error_report("-initrd only allowed with -kernel option");
2435 if (loadvm
&& preconfig_requested
) {
2436 error_report("'preconfig' and 'loadvm' options are "
2437 "mutually exclusive");
2440 if (incoming
&& preconfig_requested
&& strcmp(incoming
, "defer") != 0) {
2441 error_report("'preconfig' supports '-incoming defer' only");
2445 #ifdef CONFIG_CURSES
2446 if (is_daemonized() && dpy
.type
== DISPLAY_TYPE_CURSES
) {
2447 error_report("curses display cannot be used with -daemonize");
2453 static void qemu_process_sugar_options(void)
2456 QObject
*smp
= qdict_get(machine_opts_dict
, "smp");
2457 if (smp
&& qobject_type(smp
) == QTYPE_QDICT
) {
2458 QObject
*cpus
= qdict_get(qobject_to(QDict
, smp
), "cpus");
2459 if (cpus
&& qobject_type(cpus
) == QTYPE_QSTRING
) {
2460 const char *val
= qstring_get_str(qobject_to(QString
, cpus
));
2461 object_register_sugar_prop("memory-backend", "prealloc-threads",
2465 object_register_sugar_prop("memory-backend", "prealloc", "on", false);
2469 int i
= select_watchdog(watchdog
);
2471 exit (i
== 1 ? 1 : 0);
2475 /* -action processing */
2478 * Process all the -action parameters parsed from cmdline.
2480 static int process_runstate_actions(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2482 Error
*local_err
= NULL
;
2483 QDict
*qdict
= qemu_opts_to_qdict(opts
, NULL
);
2484 QObject
*ret
= NULL
;
2485 qmp_marshal_set_action(qdict
, &ret
, &local_err
);
2487 qobject_unref(qdict
);
2489 error_propagate(errp
, local_err
);
2495 static void qemu_process_early_options(void)
2497 #ifdef CONFIG_SECCOMP
2498 QemuOptsList
*olist
= qemu_find_opts_err("sandbox", NULL
);
2500 qemu_opts_foreach(olist
, parse_sandbox
, NULL
, &error_fatal
);
2504 qemu_opts_foreach(qemu_find_opts("name"),
2505 parse_name
, NULL
, &error_fatal
);
2507 if (qemu_opts_foreach(qemu_find_opts("action"),
2508 process_runstate_actions
, NULL
, &error_fatal
)) {
2513 qemu_opts_foreach(qemu_find_opts("add-fd"),
2514 parse_add_fd
, NULL
, &error_fatal
);
2516 qemu_opts_foreach(qemu_find_opts("add-fd"),
2517 cleanup_add_fd
, NULL
, &error_fatal
);
2520 /* Open the logfile at this point and set the log mask if necessary. */
2522 qemu_set_log_filename(log_file
, &error_fatal
);
2526 mask
= qemu_str_to_log_mask(log_mask
);
2528 qemu_print_log_usage(stdout
);
2536 qemu_add_default_firmwarepath();
2539 static void qemu_process_help_options(void)
2542 * Check for -cpu help and -device help before we call select_machine(),
2543 * which will return an error if the architecture has no default machine
2544 * type and the user did not specify one, so that the user doesn't need
2545 * to say '-cpu help -machine something'.
2547 if (cpu_option
&& is_help_option(cpu_option
)) {
2548 list_cpus(cpu_option
);
2552 if (qemu_opts_foreach(qemu_find_opts("device"),
2553 device_help_func
, NULL
, NULL
)) {
2557 /* -L help lists the data directories and exits. */
2558 if (list_data_dirs
) {
2559 qemu_list_data_dirs();
2564 static void qemu_maybe_daemonize(const char *pid_file
)
2569 rcu_disable_atfork();
2571 if (pid_file
&& !qemu_write_pidfile(pid_file
, &err
)) {
2572 error_reportf_err(err
, "cannot create PID file: ");
2576 qemu_unlink_pidfile_notifier
.notify
= qemu_unlink_pidfile
;
2577 qemu_add_exit_notifier(&qemu_unlink_pidfile_notifier
);
2580 static void qemu_init_displays(void)
2584 /* init local displays */
2585 ds
= init_displaystate();
2586 qemu_display_init(ds
, &dpy
);
2588 /* must be after terminal init, SDL library changes signal handlers */
2589 os_setup_signal_handling();
2591 /* init remote displays */
2593 qemu_opts_foreach(qemu_find_opts("vnc"),
2594 vnc_init_func
, NULL
, &error_fatal
);
2598 qemu_spice
.display_init();
2602 static void qemu_init_board(void)
2604 MachineClass
*machine_class
= MACHINE_GET_CLASS(current_machine
);
2606 if (machine_class
->default_ram_id
&& current_machine
->ram_size
&&
2607 numa_uses_legacy_mem() && !current_machine
->ram_memdev_id
) {
2608 create_default_memdev(current_machine
, mem_path
);
2611 /* process plugin before CPUs are created, but once -smp has been parsed */
2612 qemu_plugin_load_list(&plugin_list
, &error_fatal
);
2614 /* From here on we enter MACHINE_PHASE_INITIALIZED. */
2615 machine_run_board_init(current_machine
);
2617 drive_check_orphaned();
2621 if (hax_enabled()) {
2622 /* FIXME: why isn't cpu_synchronize_all_post_init enough? */
2627 static void qemu_create_cli_devices(void)
2631 qemu_opts_foreach(qemu_find_opts("fw_cfg"),
2632 parse_fw_cfg
, fw_cfg_find(), &error_fatal
);
2634 /* init USB devices */
2635 if (machine_usb(current_machine
)) {
2636 if (foreach_device_config(DEV_USB
, usb_parse
) < 0)
2640 /* init generic devices */
2641 rom_set_order_override(FW_CFG_ORDER_OVERRIDE_DEVICE
);
2642 qemu_opts_foreach(qemu_find_opts("device"),
2643 device_init_func
, NULL
, &error_fatal
);
2644 rom_reset_order_override();
2647 static void qemu_machine_creation_done(void)
2649 MachineState
*machine
= MACHINE(qdev_get_machine());
2651 /* Did we create any drives that we failed to create a device for? */
2652 drive_check_orphaned();
2654 /* Don't warn about the default network setup that you get if
2655 * no command line -net or -netdev options are specified. There
2656 * are two cases that we would otherwise complain about:
2657 * (1) board doesn't support a NIC but the implicit "-net nic"
2659 * (2) CONFIG_SLIRP not set, in which case the implicit "-net nic"
2660 * sets up a nic that isn't connected to anything.
2662 if (!default_net
&& (!qtest_enabled() || has_defaults
)) {
2663 net_check_clients();
2666 qdev_prop_check_globals();
2668 qdev_machine_creation_done();
2672 * Verify that Confidential Guest Support has actually been initialized
2674 assert(machine
->cgs
->ready
);
2677 if (foreach_device_config(DEV_GDB
, gdbserver_start
) < 0) {
2682 void qmp_x_exit_preconfig(Error
**errp
)
2684 if (phase_check(PHASE_MACHINE_INITIALIZED
)) {
2685 error_setg(errp
, "The command is permitted only before machine initialization");
2690 qemu_create_cli_devices();
2691 qemu_machine_creation_done();
2694 load_snapshot(loadvm
, NULL
, false, NULL
, &error_fatal
);
2696 if (replay_mode
!= REPLAY_MODE_NONE
) {
2697 replay_vmstate_init();
2701 Error
*local_err
= NULL
;
2702 if (strcmp(incoming
, "defer") != 0) {
2703 qmp_migrate_incoming(incoming
, &local_err
);
2705 error_reportf_err(local_err
, "-incoming %s: ", incoming
);
2709 } else if (autostart
) {
2714 void qemu_init(int argc
, char **argv
, char **envp
)
2717 QemuOpts
*icount_opts
= NULL
, *accel_opts
= NULL
;
2718 QemuOptsList
*olist
;
2721 MachineClass
*machine_class
;
2722 bool userconfig
= true;
2723 FILE *vmstate_dump_file
= NULL
;
2725 qemu_add_opts(&qemu_drive_opts
);
2726 qemu_add_drive_opts(&qemu_legacy_drive_opts
);
2727 qemu_add_drive_opts(&qemu_common_drive_opts
);
2728 qemu_add_drive_opts(&qemu_drive_opts
);
2729 qemu_add_drive_opts(&bdrv_runtime_opts
);
2730 qemu_add_opts(&qemu_chardev_opts
);
2731 qemu_add_opts(&qemu_device_opts
);
2732 qemu_add_opts(&qemu_netdev_opts
);
2733 qemu_add_opts(&qemu_nic_opts
);
2734 qemu_add_opts(&qemu_net_opts
);
2735 qemu_add_opts(&qemu_rtc_opts
);
2736 qemu_add_opts(&qemu_global_opts
);
2737 qemu_add_opts(&qemu_mon_opts
);
2738 qemu_add_opts(&qemu_trace_opts
);
2739 qemu_plugin_add_opts();
2740 qemu_add_opts(&qemu_option_rom_opts
);
2741 qemu_add_opts(&qemu_accel_opts
);
2742 qemu_add_opts(&qemu_mem_opts
);
2743 qemu_add_opts(&qemu_smp_opts
);
2744 qemu_add_opts(&qemu_boot_opts
);
2745 qemu_add_opts(&qemu_add_fd_opts
);
2746 qemu_add_opts(&qemu_object_opts
);
2747 qemu_add_opts(&qemu_tpmdev_opts
);
2748 qemu_add_opts(&qemu_overcommit_opts
);
2749 qemu_add_opts(&qemu_msg_opts
);
2750 qemu_add_opts(&qemu_name_opts
);
2751 qemu_add_opts(&qemu_numa_opts
);
2752 qemu_add_opts(&qemu_icount_opts
);
2753 qemu_add_opts(&qemu_semihosting_config_opts
);
2754 qemu_add_opts(&qemu_fw_cfg_opts
);
2755 qemu_add_opts(&qemu_action_opts
);
2756 module_call_init(MODULE_INIT_OPTS
);
2758 error_init(argv
[0]);
2759 qemu_init_exec_dir(argv
[0]);
2761 #ifdef CONFIG_MODULES
2762 module_init_info(qemu_modinfo
);
2763 module_allow_arch(TARGET_NAME
);
2766 qemu_init_subsystems();
2768 /* first pass of option parsing */
2770 while (optind
< argc
) {
2771 if (argv
[optind
][0] != '-') {
2775 const QEMUOption
*popt
;
2777 popt
= lookup_opt(argc
, argv
, &optarg
, &optind
);
2778 switch (popt
->index
) {
2779 case QEMU_OPTION_nouserconfig
:
2786 machine_opts_dict
= qdict_new();
2788 qemu_read_default_config_file(&error_fatal
);
2791 /* second pass of option parsing */
2796 if (argv
[optind
][0] != '-') {
2797 loc_set_cmdline(argv
, optind
, 1);
2798 drive_add(IF_DEFAULT
, 0, argv
[optind
++], HD_OPTS
);
2800 const QEMUOption
*popt
;
2802 popt
= lookup_opt(argc
, argv
, &optarg
, &optind
);
2803 if (!(popt
->arch_mask
& arch_type
)) {
2804 error_report("Option not supported for this target");
2807 switch(popt
->index
) {
2808 case QEMU_OPTION_cpu
:
2809 /* hw initialization will check this */
2810 cpu_option
= optarg
;
2812 case QEMU_OPTION_hda
:
2813 case QEMU_OPTION_hdb
:
2814 case QEMU_OPTION_hdc
:
2815 case QEMU_OPTION_hdd
:
2816 drive_add(IF_DEFAULT
, popt
->index
- QEMU_OPTION_hda
, optarg
,
2819 case QEMU_OPTION_blockdev
:
2822 BlockdevOptionsQueueEntry
*bdo
;
2824 v
= qobject_input_visitor_new_str(optarg
, "driver",
2827 bdo
= g_new(BlockdevOptionsQueueEntry
, 1);
2828 visit_type_BlockdevOptions(v
, NULL
, &bdo
->bdo
,
2831 loc_save(&bdo
->loc
);
2832 QSIMPLEQ_INSERT_TAIL(&bdo_queue
, bdo
, entry
);
2835 case QEMU_OPTION_drive
:
2836 if (drive_def(optarg
) == NULL
) {
2840 case QEMU_OPTION_set
:
2841 qemu_set_option(optarg
, &error_fatal
);
2843 case QEMU_OPTION_global
:
2844 if (qemu_global_option(optarg
) != 0)
2847 case QEMU_OPTION_mtdblock
:
2848 drive_add(IF_MTD
, -1, optarg
, MTD_OPTS
);
2850 case QEMU_OPTION_sd
:
2851 drive_add(IF_SD
, -1, optarg
, SD_OPTS
);
2853 case QEMU_OPTION_pflash
:
2854 drive_add(IF_PFLASH
, -1, optarg
, PFLASH_OPTS
);
2856 case QEMU_OPTION_snapshot
:
2858 Error
*blocker
= NULL
;
2860 error_setg(&blocker
, QERR_REPLAY_NOT_SUPPORTED
,
2862 replay_add_blocker(blocker
);
2865 case QEMU_OPTION_numa
:
2866 opts
= qemu_opts_parse_noisily(qemu_find_opts("numa"),
2872 case QEMU_OPTION_display
:
2873 parse_display(optarg
);
2875 case QEMU_OPTION_nographic
:
2876 qdict_put_str(machine_opts_dict
, "graphics", "off");
2878 dpy
.type
= DISPLAY_TYPE_NONE
;
2880 case QEMU_OPTION_curses
:
2881 #ifdef CONFIG_CURSES
2882 dpy
.type
= DISPLAY_TYPE_CURSES
;
2884 error_report("curses or iconv support is disabled");
2888 case QEMU_OPTION_portrait
:
2889 graphic_rotate
= 90;
2891 case QEMU_OPTION_rotate
:
2892 graphic_rotate
= strtol(optarg
, (char **) &optarg
, 10);
2893 if (graphic_rotate
!= 0 && graphic_rotate
!= 90 &&
2894 graphic_rotate
!= 180 && graphic_rotate
!= 270) {
2895 error_report("only 90, 180, 270 deg rotation is available");
2899 case QEMU_OPTION_kernel
:
2900 qdict_put_str(machine_opts_dict
, "kernel", optarg
);
2902 case QEMU_OPTION_initrd
:
2903 qdict_put_str(machine_opts_dict
, "initrd", optarg
);
2905 case QEMU_OPTION_append
:
2906 qdict_put_str(machine_opts_dict
, "append", optarg
);
2908 case QEMU_OPTION_dtb
:
2909 qdict_put_str(machine_opts_dict
, "dtb", optarg
);
2911 case QEMU_OPTION_cdrom
:
2912 drive_add(IF_DEFAULT
, 2, optarg
, CDROM_OPTS
);
2914 case QEMU_OPTION_boot
:
2915 opts
= qemu_opts_parse_noisily(qemu_find_opts("boot-opts"),
2921 case QEMU_OPTION_fda
:
2922 case QEMU_OPTION_fdb
:
2923 drive_add(IF_FLOPPY
, popt
->index
- QEMU_OPTION_fda
,
2926 case QEMU_OPTION_no_fd_bootchk
:
2929 case QEMU_OPTION_netdev
:
2931 if (net_client_parse(qemu_find_opts("netdev"), optarg
) == -1) {
2935 case QEMU_OPTION_nic
:
2937 if (net_client_parse(qemu_find_opts("nic"), optarg
) == -1) {
2941 case QEMU_OPTION_net
:
2943 if (net_client_parse(qemu_find_opts("net"), optarg
) == -1) {
2947 #ifdef CONFIG_LIBISCSI
2948 case QEMU_OPTION_iscsi
:
2949 opts
= qemu_opts_parse_noisily(qemu_find_opts("iscsi"),
2956 case QEMU_OPTION_audio_help
:
2957 audio_legacy_help();
2960 case QEMU_OPTION_audiodev
:
2961 audio_parse_option(optarg
);
2963 case QEMU_OPTION_soundhw
:
2964 select_soundhw (optarg
);
2969 case QEMU_OPTION_version
:
2974 opts
= qemu_opts_parse_noisily(qemu_find_opts("memory"),
2981 case QEMU_OPTION_tpmdev
:
2982 if (tpm_config_parse(qemu_find_opts("tpmdev"), optarg
) < 0) {
2987 case QEMU_OPTION_mempath
:
2990 case QEMU_OPTION_mem_prealloc
:
2999 case QEMU_OPTION_DFILTER
:
3000 qemu_set_dfilter_ranges(optarg
, &error_fatal
);
3002 case QEMU_OPTION_seed
:
3003 qemu_guest_random_seed_main(optarg
, &error_fatal
);
3006 add_device_config(DEV_GDB
, "tcp::" DEFAULT_GDBSTUB_PORT
);
3008 case QEMU_OPTION_gdb
:
3009 add_device_config(DEV_GDB
, optarg
);
3012 if (is_help_option(optarg
)) {
3013 list_data_dirs
= true;
3015 qemu_add_data_dir(g_strdup(optarg
));
3018 case QEMU_OPTION_bios
:
3019 qdict_put_str(machine_opts_dict
, "firmware", optarg
);
3021 case QEMU_OPTION_singlestep
:
3028 keyboard_layout
= optarg
;
3030 case QEMU_OPTION_vga
:
3039 w
= strtol(p
, (char **)&p
, 10);
3042 error_report("invalid resolution or depth");
3048 h
= strtol(p
, (char **)&p
, 10);
3053 depth
= strtol(p
, (char **)&p
, 10);
3054 if (depth
!= 1 && depth
!= 2 && depth
!= 4 &&
3055 depth
!= 8 && depth
!= 15 && depth
!= 16 &&
3056 depth
!= 24 && depth
!= 32)
3058 } else if (*p
== '\0') {
3059 depth
= graphic_depth
;
3066 graphic_depth
= depth
;
3069 case QEMU_OPTION_echr
:
3072 term_escape_char
= strtol(optarg
, &r
, 0);
3074 printf("Bad argument to echr\n");
3077 case QEMU_OPTION_monitor
:
3078 default_monitor
= 0;
3079 if (strncmp(optarg
, "none", 4)) {
3080 monitor_parse(optarg
, "readline", false);
3083 case QEMU_OPTION_qmp
:
3084 monitor_parse(optarg
, "control", false);
3085 default_monitor
= 0;
3087 case QEMU_OPTION_qmp_pretty
:
3088 monitor_parse(optarg
, "control", true);
3089 default_monitor
= 0;
3091 case QEMU_OPTION_mon
:
3092 opts
= qemu_opts_parse_noisily(qemu_find_opts("mon"), optarg
,
3097 default_monitor
= 0;
3099 case QEMU_OPTION_chardev
:
3100 opts
= qemu_opts_parse_noisily(qemu_find_opts("chardev"),
3106 case QEMU_OPTION_fsdev
:
3107 olist
= qemu_find_opts("fsdev");
3109 error_report("fsdev support is disabled");
3112 opts
= qemu_opts_parse_noisily(olist
, optarg
, true);
3117 case QEMU_OPTION_virtfs
: {
3120 const char *writeout
, *sock_fd
, *socket
, *path
, *security_model
,
3123 olist
= qemu_find_opts("virtfs");
3125 error_report("virtfs support is disabled");
3128 opts
= qemu_opts_parse_noisily(olist
, optarg
, true);
3133 if (qemu_opt_get(opts
, "fsdriver") == NULL
||
3134 qemu_opt_get(opts
, "mount_tag") == NULL
) {
3135 error_report("Usage: -virtfs fsdriver,mount_tag=tag");
3138 fsdev
= qemu_opts_create(qemu_find_opts("fsdev"),
3139 qemu_opts_id(opts
) ?:
3140 qemu_opt_get(opts
, "mount_tag"),
3143 error_report("duplicate or invalid fsdev id: %s",
3144 qemu_opt_get(opts
, "mount_tag"));
3148 writeout
= qemu_opt_get(opts
, "writeout");
3150 #ifdef CONFIG_SYNC_FILE_RANGE
3151 qemu_opt_set(fsdev
, "writeout", writeout
, &error_abort
);
3153 error_report("writeout=immediate not supported "
3154 "on this platform");
3158 qemu_opt_set(fsdev
, "fsdriver",
3159 qemu_opt_get(opts
, "fsdriver"), &error_abort
);
3160 path
= qemu_opt_get(opts
, "path");
3162 qemu_opt_set(fsdev
, "path", path
, &error_abort
);
3164 security_model
= qemu_opt_get(opts
, "security_model");
3165 if (security_model
) {
3166 qemu_opt_set(fsdev
, "security_model", security_model
,
3169 socket
= qemu_opt_get(opts
, "socket");
3171 qemu_opt_set(fsdev
, "socket", socket
, &error_abort
);
3173 sock_fd
= qemu_opt_get(opts
, "sock_fd");
3175 qemu_opt_set(fsdev
, "sock_fd", sock_fd
, &error_abort
);
3178 qemu_opt_set_bool(fsdev
, "readonly",
3179 qemu_opt_get_bool(opts
, "readonly", 0),
3181 multidevs
= qemu_opt_get(opts
, "multidevs");
3183 qemu_opt_set(fsdev
, "multidevs", multidevs
, &error_abort
);
3185 device
= qemu_opts_create(qemu_find_opts("device"), NULL
, 0,
3187 qemu_opt_set(device
, "driver", "virtio-9p-pci", &error_abort
);
3188 qemu_opt_set(device
, "fsdev",
3189 qemu_opts_id(fsdev
), &error_abort
);
3190 qemu_opt_set(device
, "mount_tag",
3191 qemu_opt_get(opts
, "mount_tag"), &error_abort
);
3194 case QEMU_OPTION_serial
:
3195 add_device_config(DEV_SERIAL
, optarg
);
3197 if (strncmp(optarg
, "mon:", 4) == 0) {
3198 default_monitor
= 0;
3201 case QEMU_OPTION_watchdog
:
3203 error_report("only one watchdog option may be given");
3208 case QEMU_OPTION_action
:
3209 olist
= qemu_find_opts("action");
3210 if (!qemu_opts_parse_noisily(olist
, optarg
, false)) {
3214 case QEMU_OPTION_watchdog_action
:
3215 if (select_watchdog_action(optarg
) == -1) {
3216 error_report("unknown -watchdog-action parameter");
3220 case QEMU_OPTION_parallel
:
3221 add_device_config(DEV_PARALLEL
, optarg
);
3222 default_parallel
= 0;
3223 if (strncmp(optarg
, "mon:", 4) == 0) {
3224 default_monitor
= 0;
3227 case QEMU_OPTION_debugcon
:
3228 add_device_config(DEV_DEBUGCON
, optarg
);
3230 case QEMU_OPTION_loadvm
:
3233 case QEMU_OPTION_full_screen
:
3234 dpy
.has_full_screen
= true;
3235 dpy
.full_screen
= true;
3237 case QEMU_OPTION_alt_grab
:
3240 case QEMU_OPTION_ctrl_grab
:
3243 case QEMU_OPTION_no_quit
:
3244 dpy
.has_window_close
= true;
3245 dpy
.window_close
= false;
3246 warn_report("-no-quit is deprecated, please use "
3247 "-display ...,window-close=off instead.");
3249 case QEMU_OPTION_sdl
:
3251 dpy
.type
= DISPLAY_TYPE_SDL
;
3254 error_report("SDL support is disabled");
3257 case QEMU_OPTION_pidfile
:
3260 case QEMU_OPTION_win2k_hack
:
3261 win2k_install_hack
= 1;
3263 case QEMU_OPTION_acpitable
:
3264 opts
= qemu_opts_parse_noisily(qemu_find_opts("acpi"),
3269 acpi_table_add(opts
, &error_fatal
);
3271 case QEMU_OPTION_smbios
:
3272 opts
= qemu_opts_parse_noisily(qemu_find_opts("smbios"),
3277 smbios_entry_add(opts
, &error_fatal
);
3279 case QEMU_OPTION_fwcfg
:
3280 opts
= qemu_opts_parse_noisily(qemu_find_opts("fw_cfg"),
3286 case QEMU_OPTION_preconfig
:
3287 preconfig_requested
= true;
3289 case QEMU_OPTION_enable_kvm
:
3290 qdict_put_str(machine_opts_dict
, "accel", "kvm");
3293 case QEMU_OPTION_machine
:
3297 keyval_parse_into(machine_opts_dict
, optarg
, "type", &help
, &error_fatal
);
3299 machine_help_func(machine_opts_dict
);
3304 case QEMU_OPTION_accel
:
3305 accel_opts
= qemu_opts_parse_noisily(qemu_find_opts("accel"),
3307 optarg
= qemu_opt_get(accel_opts
, "accel");
3308 if (!optarg
|| is_help_option(optarg
)) {
3309 printf("Accelerators supported in QEMU binary:\n");
3310 GSList
*el
, *accel_list
= object_class_get_list(TYPE_ACCEL
,
3312 for (el
= accel_list
; el
; el
= el
->next
) {
3313 gchar
*typename
= g_strdup(object_class_get_name(
3314 OBJECT_CLASS(el
->data
)));
3315 /* omit qtest which is used for tests only */
3316 if (g_strcmp0(typename
, ACCEL_CLASS_NAME("qtest")) &&
3317 g_str_has_suffix(typename
, ACCEL_CLASS_SUFFIX
)) {
3318 gchar
**optname
= g_strsplit(typename
,
3319 ACCEL_CLASS_SUFFIX
, 0);
3320 printf("%s\n", optname
[0]);
3321 g_strfreev(optname
);
3325 g_slist_free(accel_list
);
3329 case QEMU_OPTION_usb
:
3330 qdict_put_str(machine_opts_dict
, "usb", "on");
3332 case QEMU_OPTION_usbdevice
:
3333 qdict_put_str(machine_opts_dict
, "usb", "on");
3334 add_device_config(DEV_USB
, optarg
);
3336 case QEMU_OPTION_device
:
3337 if (!qemu_opts_parse_noisily(qemu_find_opts("device"),
3342 case QEMU_OPTION_smp
:
3343 machine_parse_property_opt(qemu_find_opts("smp-opts"),
3346 case QEMU_OPTION_vnc
:
3349 case QEMU_OPTION_no_acpi
:
3350 qdict_put_str(machine_opts_dict
, "acpi", "off");
3352 case QEMU_OPTION_no_hpet
:
3353 qdict_put_str(machine_opts_dict
, "hpet", "off");
3355 case QEMU_OPTION_no_reboot
:
3356 olist
= qemu_find_opts("action");
3357 qemu_opts_parse_noisily(olist
, "reboot=shutdown", false);
3359 case QEMU_OPTION_no_shutdown
:
3360 olist
= qemu_find_opts("action");
3361 qemu_opts_parse_noisily(olist
, "shutdown=pause", false);
3363 case QEMU_OPTION_uuid
:
3364 if (qemu_uuid_parse(optarg
, &qemu_uuid
) < 0) {
3365 error_report("failed to parse UUID string: wrong format");
3368 qemu_uuid_set
= true;
3370 case QEMU_OPTION_option_rom
:
3371 if (nb_option_roms
>= MAX_OPTION_ROMS
) {
3372 error_report("too many option ROMs");
3375 opts
= qemu_opts_parse_noisily(qemu_find_opts("option-rom"),
3380 option_rom
[nb_option_roms
].name
= qemu_opt_get(opts
, "romfile");
3381 option_rom
[nb_option_roms
].bootindex
=
3382 qemu_opt_get_number(opts
, "bootindex", -1);
3383 if (!option_rom
[nb_option_roms
].name
) {
3384 error_report("Option ROM file is not specified");
3389 case QEMU_OPTION_semihosting
:
3390 qemu_semihosting_enable();
3392 case QEMU_OPTION_semihosting_config
:
3393 if (qemu_semihosting_config_options(optarg
) != 0) {
3397 case QEMU_OPTION_name
:
3398 opts
= qemu_opts_parse_noisily(qemu_find_opts("name"),
3403 /* Capture guest name if -msg guest-name is used later */
3404 error_guest_name
= qemu_opt_get(opts
, "guest");
3406 case QEMU_OPTION_prom_env
:
3407 if (nb_prom_envs
>= MAX_PROM_ENVS
) {
3408 error_report("too many prom variables");
3411 prom_envs
[nb_prom_envs
] = optarg
;
3414 case QEMU_OPTION_old_param
:
3417 case QEMU_OPTION_rtc
:
3418 opts
= qemu_opts_parse_noisily(qemu_find_opts("rtc"), optarg
,
3424 case QEMU_OPTION_icount
:
3425 icount_opts
= qemu_opts_parse_noisily(qemu_find_opts("icount"),
3431 case QEMU_OPTION_incoming
:
3433 runstate_set(RUN_STATE_INMIGRATE
);
3437 case QEMU_OPTION_only_migratable
:
3438 only_migratable
= 1;
3440 case QEMU_OPTION_nodefaults
:
3443 case QEMU_OPTION_xen_domid
:
3444 if (!(accel_find("xen"))) {
3445 error_report("Option not supported for this target");
3448 xen_domid
= atoi(optarg
);
3450 case QEMU_OPTION_xen_attach
:
3451 if (!(accel_find("xen"))) {
3452 error_report("Option not supported for this target");
3455 xen_mode
= XEN_ATTACH
;
3457 case QEMU_OPTION_xen_domid_restrict
:
3458 if (!(accel_find("xen"))) {
3459 error_report("Option not supported for this target");
3462 xen_domid_restrict
= true;
3464 case QEMU_OPTION_trace
:
3465 trace_opt_parse(optarg
);
3467 case QEMU_OPTION_plugin
:
3468 qemu_plugin_opt_parse(optarg
, &plugin_list
);
3470 case QEMU_OPTION_readconfig
:
3471 qemu_read_config_file(optarg
, qemu_parse_config_group
, &error_fatal
);
3473 case QEMU_OPTION_spice
:
3474 olist
= qemu_find_opts_err("spice", NULL
);
3476 error_report("spice support is disabled");
3479 opts
= qemu_opts_parse_noisily(olist
, optarg
, false);
3485 case QEMU_OPTION_writeconfig
:
3488 warn_report("-writeconfig is deprecated and will go away without a replacement");
3489 if (strcmp(optarg
, "-") == 0) {
3492 fp
= fopen(optarg
, "w");
3494 error_report("open %s: %s", optarg
,
3499 qemu_config_write(fp
);
3505 case QEMU_OPTION_qtest
:
3506 qtest_chrdev
= optarg
;
3508 case QEMU_OPTION_qtest_log
:
3511 case QEMU_OPTION_sandbox
:
3512 olist
= qemu_find_opts("sandbox");
3514 #ifndef CONFIG_SECCOMP
3515 error_report("-sandbox support is not enabled "
3516 "in this QEMU binary");
3521 opts
= qemu_opts_parse_noisily(olist
, optarg
, true);
3526 case QEMU_OPTION_add_fd
:
3528 opts
= qemu_opts_parse_noisily(qemu_find_opts("add-fd"),
3534 error_report("File descriptor passing is disabled on this "
3539 case QEMU_OPTION_object
:
3540 object_option_parse(optarg
);
3542 case QEMU_OPTION_overcommit
:
3543 opts
= qemu_opts_parse_noisily(qemu_find_opts("overcommit"),
3548 enable_mlock
= qemu_opt_get_bool(opts
, "mem-lock", false);
3549 enable_cpu_pm
= qemu_opt_get_bool(opts
, "cpu-pm", false);
3551 case QEMU_OPTION_compat
:
3556 v
= qobject_input_visitor_new_str(optarg
, NULL
,
3559 visit_type_CompatPolicy(v
, NULL
, &opts
, &error_fatal
);
3560 QAPI_CLONE_MEMBERS(CompatPolicy
, &compat_policy
, opts
);
3562 qapi_free_CompatPolicy(opts
);
3566 case QEMU_OPTION_msg
:
3567 opts
= qemu_opts_parse_noisily(qemu_find_opts("msg"), optarg
,
3572 configure_msg(opts
);
3574 case QEMU_OPTION_dump_vmstate
:
3575 if (vmstate_dump_file
) {
3576 error_report("only one '-dump-vmstate' "
3577 "option may be given");
3580 vmstate_dump_file
= fopen(optarg
, "w");
3581 if (vmstate_dump_file
== NULL
) {
3582 error_report("open %s: %s", optarg
, strerror(errno
));
3586 case QEMU_OPTION_enable_sync_profile
:
3589 case QEMU_OPTION_nouserconfig
:
3590 /* Nothing to be parsed here. Especially, do not error out below. */
3593 if (os_parse_cmd_args(popt
->index
, optarg
)) {
3594 error_report("Option not supported in this build");
3601 * Clear error location left behind by the loop.
3602 * Best done right after the loop. Do not insert code here!
3606 qemu_validate_options(machine_opts_dict
);
3607 qemu_process_sugar_options();
3610 * These options affect everything else and should be processed
3611 * before daemonizing.
3613 qemu_process_early_options();
3615 qemu_process_help_options();
3616 qemu_maybe_daemonize(pid_file
);
3619 * The trace backend must be initialized after daemonizing.
3620 * trace_init_backends() will call st_init(), which will create the
3621 * trace thread in the parent, and also register st_flush_trace_buffer()
3622 * in atexit(). This function will force the parent to wait for the
3623 * writeout thread to finish, which will not occur, and the parent
3624 * process will be left in the host.
3626 if (!trace_init_backends()) {
3631 qemu_init_main_loop(&error_fatal
);
3634 user_register_global_props();
3635 replay_configure(icount_opts
);
3637 configure_rtc(qemu_find_opts_singleton("rtc"));
3639 qemu_create_machine(machine_opts_dict
);
3643 qemu_disable_default_devices();
3644 qemu_create_default_devices();
3645 qemu_create_early_backends();
3647 qemu_apply_legacy_machine_options(machine_opts_dict
);
3648 qemu_apply_machine_options(machine_opts_dict
);
3649 qobject_unref(machine_opts_dict
);
3650 phase_advance(PHASE_MACHINE_CREATED
);
3653 * Note: uses machine properties such as kernel-irqchip, must run
3654 * after qemu_apply_machine_options.
3656 configure_accelerators(argv
[0]);
3657 phase_advance(PHASE_ACCEL_CREATED
);
3660 * Beware, QOM objects created before this point miss global and
3661 * compat properties.
3663 * Global properties get set up by qdev_prop_register_global(),
3664 * called from user_register_global_props(), and certain option
3665 * desugaring. Also in CPU feature desugaring (buried in
3666 * parse_cpu_option()), which happens below this point, but may
3667 * only target the CPU type, which can only be created after
3668 * parse_cpu_option() returned the type.
3670 * Machine compat properties: object_set_machine_compat_props().
3671 * Accelerator compat props: object_set_accelerator_compat_props(),
3672 * called from do_configure_accelerator().
3675 machine_class
= MACHINE_GET_CLASS(current_machine
);
3676 if (!qtest_enabled() && machine_class
->deprecation_reason
) {
3677 error_report("Machine type '%s' is deprecated: %s",
3678 machine_class
->name
, machine_class
->deprecation_reason
);
3682 * Note: creates a QOM object, must run only after global and
3683 * compat properties have been set up.
3685 migration_object_init();
3687 qemu_create_late_backends();
3689 /* parse features once if machine provides default cpu_type */
3690 current_machine
->cpu_type
= machine_class
->default_cpu_type
;
3692 current_machine
->cpu_type
= parse_cpu_option(cpu_option
);
3694 /* NB: for machine none cpu_type could STILL be NULL here! */
3696 qemu_resolve_machine_memdev();
3697 parse_numa_opts(current_machine
);
3699 if (vmstate_dump_file
) {
3701 dump_vmstate_json_to_file(vmstate_dump_file
);
3705 if (!preconfig_requested
) {
3706 qmp_x_exit_preconfig(&error_fatal
);
3708 qemu_init_displays();
3709 accel_setup_post(current_machine
);