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
},
207 static QemuOptsList qemu_rtc_opts
= {
209 .head
= QTAILQ_HEAD_INITIALIZER(qemu_rtc_opts
.head
),
214 .type
= QEMU_OPT_STRING
,
217 .type
= QEMU_OPT_STRING
,
220 .type
= QEMU_OPT_STRING
,
222 { /* end of list */ }
226 static QemuOptsList qemu_option_rom_opts
= {
227 .name
= "option-rom",
228 .implied_opt_name
= "romfile",
229 .head
= QTAILQ_HEAD_INITIALIZER(qemu_option_rom_opts
.head
),
233 .type
= QEMU_OPT_NUMBER
,
236 .type
= QEMU_OPT_STRING
,
238 { /* end of list */ }
242 static QemuOptsList qemu_accel_opts
= {
244 .implied_opt_name
= "accel",
245 .head
= QTAILQ_HEAD_INITIALIZER(qemu_accel_opts
.head
),
248 * no elements => accept any
249 * sanity checking will happen later
250 * when setting accelerator properties
256 static QemuOptsList qemu_boot_opts
= {
258 .implied_opt_name
= "order",
260 .head
= QTAILQ_HEAD_INITIALIZER(qemu_boot_opts
.head
),
264 .type
= QEMU_OPT_STRING
,
267 .type
= QEMU_OPT_STRING
,
270 .type
= QEMU_OPT_BOOL
,
273 .type
= QEMU_OPT_STRING
,
275 .name
= "splash-time",
276 .type
= QEMU_OPT_NUMBER
,
278 .name
= "reboot-timeout",
279 .type
= QEMU_OPT_NUMBER
,
282 .type
= QEMU_OPT_BOOL
,
288 static QemuOptsList qemu_add_fd_opts
= {
290 .head
= QTAILQ_HEAD_INITIALIZER(qemu_add_fd_opts
.head
),
294 .type
= QEMU_OPT_NUMBER
,
295 .help
= "file descriptor of which a duplicate is added to fd set",
298 .type
= QEMU_OPT_NUMBER
,
299 .help
= "ID of the fd set to add fd to",
302 .type
= QEMU_OPT_STRING
,
303 .help
= "free-form string used to describe fd",
305 { /* end of list */ }
309 static QemuOptsList qemu_object_opts
= {
311 .implied_opt_name
= "qom-type",
312 .head
= QTAILQ_HEAD_INITIALIZER(qemu_object_opts
.head
),
318 static QemuOptsList qemu_tpmdev_opts
= {
320 .implied_opt_name
= "type",
321 .head
= QTAILQ_HEAD_INITIALIZER(qemu_tpmdev_opts
.head
),
323 /* options are defined in the TPM backends */
324 { /* end of list */ }
328 static QemuOptsList qemu_overcommit_opts
= {
329 .name
= "overcommit",
330 .head
= QTAILQ_HEAD_INITIALIZER(qemu_overcommit_opts
.head
),
334 .type
= QEMU_OPT_BOOL
,
338 .type
= QEMU_OPT_BOOL
,
340 { /* end of list */ }
344 static QemuOptsList qemu_msg_opts
= {
346 .head
= QTAILQ_HEAD_INITIALIZER(qemu_msg_opts
.head
),
350 .type
= QEMU_OPT_BOOL
,
353 .name
= "guest-name",
354 .type
= QEMU_OPT_BOOL
,
355 .help
= "Prepends guest name for error messages but only if "
356 "-name guest is set otherwise option is ignored\n",
358 { /* end of list */ }
362 static QemuOptsList qemu_name_opts
= {
364 .implied_opt_name
= "guest",
366 .head
= QTAILQ_HEAD_INITIALIZER(qemu_name_opts
.head
),
370 .type
= QEMU_OPT_STRING
,
371 .help
= "Sets the name of the guest.\n"
372 "This name will be displayed in the SDL window caption.\n"
373 "The name will also be used for the VNC server",
376 .type
= QEMU_OPT_STRING
,
377 .help
= "Sets the name of the QEMU process, as shown in top etc",
379 .name
= "debug-threads",
380 .type
= QEMU_OPT_BOOL
,
381 .help
= "When enabled, name the individual threads; defaults off.\n"
382 "NOTE: The thread names are for debugging and not a\n"
385 { /* End of list */ }
389 static QemuOptsList qemu_mem_opts
= {
391 .implied_opt_name
= "size",
392 .head
= QTAILQ_HEAD_INITIALIZER(qemu_mem_opts
.head
),
397 .type
= QEMU_OPT_SIZE
,
401 .type
= QEMU_OPT_NUMBER
,
405 .type
= QEMU_OPT_SIZE
,
407 { /* end of list */ }
411 static QemuOptsList qemu_icount_opts
= {
413 .implied_opt_name
= "shift",
415 .head
= QTAILQ_HEAD_INITIALIZER(qemu_icount_opts
.head
),
419 .type
= QEMU_OPT_STRING
,
422 .type
= QEMU_OPT_BOOL
,
425 .type
= QEMU_OPT_BOOL
,
428 .type
= QEMU_OPT_STRING
,
431 .type
= QEMU_OPT_STRING
,
433 .name
= "rrsnapshot",
434 .type
= QEMU_OPT_STRING
,
436 { /* end of list */ }
440 static QemuOptsList qemu_fw_cfg_opts
= {
442 .implied_opt_name
= "name",
443 .head
= QTAILQ_HEAD_INITIALIZER(qemu_fw_cfg_opts
.head
),
447 .type
= QEMU_OPT_STRING
,
448 .help
= "Sets the fw_cfg name of the blob to be inserted",
451 .type
= QEMU_OPT_STRING
,
452 .help
= "Sets the name of the file from which "
453 "the fw_cfg blob will be loaded",
456 .type
= QEMU_OPT_STRING
,
457 .help
= "Sets content of the blob to be inserted from a string",
460 .type
= QEMU_OPT_STRING
,
461 .help
= "Sets id of the object generating the fw_cfg blob "
464 { /* end of list */ }
468 static QemuOptsList qemu_action_opts
= {
471 .head
= QTAILQ_HEAD_INITIALIZER(qemu_action_opts
.head
),
475 .type
= QEMU_OPT_STRING
,
478 .type
= QEMU_OPT_STRING
,
481 .type
= QEMU_OPT_STRING
,
484 .type
= QEMU_OPT_STRING
,
486 { /* end of list */ }
490 const char *qemu_get_vm_name(void)
495 static int default_driver_check(void *opaque
, QemuOpts
*opts
, Error
**errp
)
497 const char *driver
= qemu_opt_get(opts
, "driver");
502 for (i
= 0; i
< ARRAY_SIZE(default_list
); i
++) {
503 if (strcmp(default_list
[i
].driver
, driver
) != 0)
505 *(default_list
[i
].flag
) = 0;
510 static int parse_name(void *opaque
, QemuOpts
*opts
, Error
**errp
)
512 const char *proc_name
;
514 if (qemu_opt_get(opts
, "debug-threads")) {
515 qemu_thread_naming(qemu_opt_get_bool(opts
, "debug-threads", false));
517 qemu_name
= qemu_opt_get(opts
, "guest");
519 proc_name
= qemu_opt_get(opts
, "process");
521 os_set_proc_name(proc_name
);
527 bool defaults_enabled(void)
533 static int parse_add_fd(void *opaque
, QemuOpts
*opts
, Error
**errp
)
535 int fd
, dupfd
, flags
;
537 const char *fd_opaque
= NULL
;
540 fd
= qemu_opt_get_number(opts
, "fd", -1);
541 fdset_id
= qemu_opt_get_number(opts
, "set", -1);
542 fd_opaque
= qemu_opt_get(opts
, "opaque");
545 error_setg(errp
, "fd option is required and must be non-negative");
549 if (fd
<= STDERR_FILENO
) {
550 error_setg(errp
, "fd cannot be a standard I/O stream");
555 * All fds inherited across exec() necessarily have FD_CLOEXEC
556 * clear, while qemu sets FD_CLOEXEC on all other fds used internally.
558 flags
= fcntl(fd
, F_GETFD
);
559 if (flags
== -1 || (flags
& FD_CLOEXEC
)) {
560 error_setg(errp
, "fd is not valid or already in use");
565 error_setg(errp
, "set option is required and must be non-negative");
569 #ifdef F_DUPFD_CLOEXEC
570 dupfd
= fcntl(fd
, F_DUPFD_CLOEXEC
, 0);
574 qemu_set_cloexec(dupfd
);
578 error_setg(errp
, "error duplicating fd: %s", strerror(errno
));
582 /* add the duplicate fd, and optionally the opaque string, to the fd set */
583 fdinfo
= monitor_fdset_add_fd(dupfd
, true, fdset_id
, !!fd_opaque
, fd_opaque
,
590 static int cleanup_add_fd(void *opaque
, QemuOpts
*opts
, Error
**errp
)
594 fd
= qemu_opt_get_number(opts
, "fd", -1);
601 /***********************************************************/
602 /* QEMU Block devices */
604 #define HD_OPTS "media=disk"
605 #define CDROM_OPTS "media=cdrom"
607 #define PFLASH_OPTS ""
611 static int drive_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
613 BlockInterfaceType
*block_default_type
= opaque
;
615 return drive_new(opts
, *block_default_type
, errp
) == NULL
;
618 static int drive_enable_snapshot(void *opaque
, QemuOpts
*opts
, Error
**errp
)
620 if (qemu_opt_get(opts
, "snapshot") == NULL
) {
621 qemu_opt_set(opts
, "snapshot", "on", &error_abort
);
626 static void default_drive(int enable
, int snapshot
, BlockInterfaceType type
,
627 int index
, const char *optstr
)
632 if (!enable
|| drive_get_by_index(type
, index
)) {
636 opts
= drive_add(type
, index
, NULL
, optstr
);
638 drive_enable_snapshot(NULL
, opts
, NULL
);
641 dinfo
= drive_new(opts
, type
, &error_abort
);
642 dinfo
->is_default
= true;
646 static void configure_blockdev(BlockdevOptionsQueue
*bdo_queue
,
647 MachineClass
*machine_class
, int snapshot
)
650 * If the currently selected machine wishes to override the
651 * units-per-bus property of its default HBA interface type, do so
654 if (machine_class
->units_per_default_bus
) {
655 override_max_devs(machine_class
->block_default_type
,
656 machine_class
->units_per_default_bus
);
659 /* open the virtual block devices */
660 while (!QSIMPLEQ_EMPTY(bdo_queue
)) {
661 BlockdevOptionsQueueEntry
*bdo
= QSIMPLEQ_FIRST(bdo_queue
);
663 QSIMPLEQ_REMOVE_HEAD(bdo_queue
, entry
);
664 loc_push_restore(&bdo
->loc
);
665 qmp_blockdev_add(bdo
->bdo
, &error_fatal
);
667 qapi_free_BlockdevOptions(bdo
->bdo
);
671 qemu_opts_foreach(qemu_find_opts("drive"), drive_enable_snapshot
,
674 if (qemu_opts_foreach(qemu_find_opts("drive"), drive_init_func
,
675 &machine_class
->block_default_type
, &error_fatal
)) {
676 /* We printed help */
680 default_drive(default_cdrom
, snapshot
, machine_class
->block_default_type
, 2,
682 default_drive(default_floppy
, snapshot
, IF_FLOPPY
, 0, FD_OPTS
);
683 default_drive(default_sdcard
, snapshot
, IF_SD
, 0, SD_OPTS
);
687 static QemuOptsList qemu_smp_opts
= {
689 .implied_opt_name
= "cpus",
691 .head
= QTAILQ_HEAD_INITIALIZER(qemu_smp_opts
.head
),
695 .type
= QEMU_OPT_NUMBER
,
698 .type
= QEMU_OPT_NUMBER
,
701 .type
= QEMU_OPT_NUMBER
,
704 .type
= QEMU_OPT_NUMBER
,
707 .type
= QEMU_OPT_NUMBER
,
710 .type
= QEMU_OPT_NUMBER
,
716 static void realtime_init(void)
719 if (os_mlock() < 0) {
720 error_report("locking memory failed");
727 static void configure_msg(QemuOpts
*opts
)
729 message_with_timestamp
= qemu_opt_get_bool(opts
, "timestamp", false);
730 error_with_guestname
= qemu_opt_get_bool(opts
, "guest-name", false);
734 /***********************************************************/
737 static int usb_device_add(const char *devname
)
739 USBDevice
*dev
= NULL
;
741 if (!machine_usb(current_machine
)) {
745 dev
= usbdevice_create(devname
);
752 static int usb_parse(const char *cmdline
)
755 r
= usb_device_add(cmdline
);
757 error_report("could not add USB device '%s'", cmdline
);
762 /***********************************************************/
763 /* machine registration */
765 static MachineClass
*find_machine(const char *name
, GSList
*machines
)
769 for (el
= machines
; el
; el
= el
->next
) {
770 MachineClass
*mc
= el
->data
;
772 if (!strcmp(mc
->name
, name
) || !g_strcmp0(mc
->alias
, name
)) {
780 static MachineClass
*find_default_machine(GSList
*machines
)
783 MachineClass
*default_machineclass
= NULL
;
785 for (el
= machines
; el
; el
= el
->next
) {
786 MachineClass
*mc
= el
->data
;
788 if (mc
->is_default
) {
789 assert(default_machineclass
== NULL
&& "Multiple default machines");
790 default_machineclass
= mc
;
794 return default_machineclass
;
797 static void version(void)
799 printf("QEMU emulator version " QEMU_FULL_VERSION
"\n"
800 QEMU_COPYRIGHT
"\n");
803 static void help(int exitcode
)
806 printf("usage: %s [options] [disk_image]\n\n"
807 "'disk_image' is a raw hard disk image for IDE hard disk 0\n\n",
808 error_get_progname());
810 #define DEF(option, opt_arg, opt_enum, opt_help, arch_mask) \
811 if ((arch_mask) & arch_type) \
812 fputs(opt_help, stdout);
814 #define ARCHHEADING(text, arch_mask) \
815 if ((arch_mask) & arch_type) \
816 puts(stringify(text));
818 #define DEFHEADING(text) ARCHHEADING(text, QEMU_ARCH_ALL)
820 #include "qemu-options.def"
822 printf("\nDuring emulation, the following keys are useful:\n"
823 "ctrl-alt-f toggle full screen\n"
824 "ctrl-alt-n switch to virtual console 'n'\n"
825 "ctrl-alt toggle mouse and keyboard grab\n"
827 "When using -nographic, press 'ctrl-a h' to get some help.\n"
829 QEMU_HELP_BOTTOM
"\n");
834 #define HAS_ARG 0x0001
836 typedef struct QEMUOption
{
843 static const QEMUOption qemu_options
[] = {
844 { "h", 0, QEMU_OPTION_h
, QEMU_ARCH_ALL
},
846 #define DEF(option, opt_arg, opt_enum, opt_help, arch_mask) \
847 { option, opt_arg, opt_enum, arch_mask },
848 #define DEFHEADING(text)
849 #define ARCHHEADING(text, arch_mask)
851 #include "qemu-options.def"
855 typedef struct VGAInterfaceInfo
{
856 const char *opt_name
; /* option name */
857 const char *name
; /* human-readable name */
858 /* Class names indicating that support is available.
859 * If no class is specified, the interface is always available */
860 const char *class_names
[2];
863 static const VGAInterfaceInfo vga_interfaces
[VGA_TYPE_MAX
] = {
866 .name
= "no graphic card",
870 .name
= "standard VGA",
871 .class_names
= { "VGA", "isa-vga" },
874 .opt_name
= "cirrus",
875 .name
= "Cirrus VGA",
876 .class_names
= { "cirrus-vga", "isa-cirrus-vga" },
879 .opt_name
= "vmware",
880 .name
= "VMWare SVGA",
881 .class_names
= { "vmware-svga" },
884 .opt_name
= "virtio",
885 .name
= "Virtio VGA",
886 .class_names
= { "virtio-vga" },
891 .class_names
= { "qxl-vga" },
895 .name
= "TCX framebuffer",
896 .class_names
= { "sun-tcx" },
900 .name
= "CG3 framebuffer",
901 .class_names
= { "cgthree" },
905 .name
= "Xen paravirtualized framebuffer",
909 static bool vga_interface_available(VGAInterfaceType t
)
911 const VGAInterfaceInfo
*ti
= &vga_interfaces
[t
];
913 assert(t
< VGA_TYPE_MAX
);
914 return !ti
->class_names
[0] ||
915 module_object_class_by_name(ti
->class_names
[0]) ||
916 module_object_class_by_name(ti
->class_names
[1]);
920 get_default_vga_model(const MachineClass
*machine_class
)
922 if (machine_class
->default_display
) {
923 return machine_class
->default_display
;
924 } else if (vga_interface_available(VGA_CIRRUS
)) {
926 } else if (vga_interface_available(VGA_STD
)) {
933 static void select_vgahw(const MachineClass
*machine_class
, const char *p
)
938 if (g_str_equal(p
, "help")) {
939 const char *def
= get_default_vga_model(machine_class
);
941 for (t
= 0; t
< VGA_TYPE_MAX
; t
++) {
942 const VGAInterfaceInfo
*ti
= &vga_interfaces
[t
];
944 if (vga_interface_available(t
) && ti
->opt_name
) {
945 printf("%-20s %s%s\n", ti
->opt_name
, ti
->name
?: "",
946 g_str_equal(ti
->opt_name
, def
) ? " (default)" : "");
952 assert(vga_interface_type
== VGA_NONE
);
953 for (t
= 0; t
< VGA_TYPE_MAX
; t
++) {
954 const VGAInterfaceInfo
*ti
= &vga_interfaces
[t
];
955 if (ti
->opt_name
&& strstart(p
, ti
->opt_name
, &opts
)) {
956 if (!vga_interface_available(t
)) {
957 error_report("%s not available", ti
->name
);
960 vga_interface_type
= t
;
964 if (t
== VGA_TYPE_MAX
) {
966 error_report("unknown vga type: %s", p
);
972 if (strstart(opts
, ",retrace=", &nextopt
)) {
974 if (strstart(opts
, "dumb", &nextopt
))
975 vga_retrace_method
= VGA_RETRACE_DUMB
;
976 else if (strstart(opts
, "precise", &nextopt
))
977 vga_retrace_method
= VGA_RETRACE_PRECISE
;
978 else goto invalid_vga
;
979 } else goto invalid_vga
;
984 static void parse_display_qapi(const char *optarg
)
986 DisplayOptions
*opts
;
989 v
= qobject_input_visitor_new_str(optarg
, "type", &error_fatal
);
991 visit_type_DisplayOptions(v
, NULL
, &opts
, &error_fatal
);
992 QAPI_CLONE_MEMBERS(DisplayOptions
, &dpy
, opts
);
994 qapi_free_DisplayOptions(opts
);
998 DisplayOptions
*qmp_query_display_options(Error
**errp
)
1000 return QAPI_CLONE(DisplayOptions
, &dpy
);
1003 static void parse_display(const char *p
)
1007 if (is_help_option(p
)) {
1008 qemu_display_help();
1012 if (strstart(p
, "sdl", &opts
)) {
1014 * sdl DisplayType needs hand-crafted parser instead of
1015 * parse_display_qapi() due to some options not in
1016 * DisplayOptions, specifically:
1017 * - ctrl_grab + alt_grab
1018 * Not clear yet what happens to them long-term. Should
1019 * replaced by something better or deprecated and dropped.
1021 #if defined(CONFIG_SDL)
1022 dpy
.type
= DISPLAY_TYPE_SDL
;
1024 const char *nextopt
;
1026 if (strstart(opts
, ",alt_grab=", &nextopt
)) {
1028 if (strstart(opts
, "on", &nextopt
)) {
1030 } else if (strstart(opts
, "off", &nextopt
)) {
1033 goto invalid_sdl_args
;
1035 } else if (strstart(opts
, ",ctrl_grab=", &nextopt
)) {
1037 if (strstart(opts
, "on", &nextopt
)) {
1039 } else if (strstart(opts
, "off", &nextopt
)) {
1042 goto invalid_sdl_args
;
1044 } else if (strstart(opts
, ",window_close=", &nextopt
) ||
1045 strstart(opts
, ",window-close=", &nextopt
)) {
1046 if (strstart(opts
, ",window_close=", NULL
)) {
1047 warn_report("window_close with an underscore is deprecated,"
1048 " please use window-close instead.");
1051 dpy
.has_window_close
= true;
1052 if (strstart(opts
, "on", &nextopt
)) {
1053 dpy
.window_close
= true;
1054 } else if (strstart(opts
, "off", &nextopt
)) {
1055 dpy
.window_close
= false;
1057 goto invalid_sdl_args
;
1059 } else if (strstart(opts
, ",show-cursor=", &nextopt
)) {
1061 dpy
.has_show_cursor
= true;
1062 if (strstart(opts
, "on", &nextopt
)) {
1063 dpy
.show_cursor
= true;
1064 } else if (strstart(opts
, "off", &nextopt
)) {
1065 dpy
.show_cursor
= false;
1067 goto invalid_sdl_args
;
1069 } else if (strstart(opts
, ",gl=", &nextopt
)) {
1072 if (strstart(opts
, "on", &nextopt
)) {
1073 dpy
.gl
= DISPLAYGL_MODE_ON
;
1074 } else if (strstart(opts
, "core", &nextopt
)) {
1075 dpy
.gl
= DISPLAYGL_MODE_CORE
;
1076 } else if (strstart(opts
, "es", &nextopt
)) {
1077 dpy
.gl
= DISPLAYGL_MODE_ES
;
1078 } else if (strstart(opts
, "off", &nextopt
)) {
1079 dpy
.gl
= DISPLAYGL_MODE_OFF
;
1081 goto invalid_sdl_args
;
1085 error_report("invalid SDL option string");
1091 error_report("SDL display supported is not available in this binary");
1094 } else if (strstart(p
, "vnc", &opts
)) {
1096 * vnc isn't a (local) DisplayType but a protocol for remote
1100 vnc_parse(opts
+ 1);
1102 error_report("VNC requires a display argument vnc=<display>");
1106 parse_display_qapi(p
);
1110 static inline bool nonempty_str(const char *str
)
1115 static int parse_fw_cfg(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1119 const char *name
, *file
, *str
, *gen_id
;
1120 FWCfgState
*fw_cfg
= (FWCfgState
*) opaque
;
1122 if (fw_cfg
== NULL
) {
1123 error_setg(errp
, "fw_cfg device not available");
1126 name
= qemu_opt_get(opts
, "name");
1127 file
= qemu_opt_get(opts
, "file");
1128 str
= qemu_opt_get(opts
, "string");
1129 gen_id
= qemu_opt_get(opts
, "gen_id");
1131 /* we need the name, and exactly one of: file, content string, gen_id */
1132 if (!nonempty_str(name
) ||
1133 nonempty_str(file
) + nonempty_str(str
) + nonempty_str(gen_id
) != 1) {
1134 error_setg(errp
, "name, plus exactly one of file,"
1135 " string and gen_id, are needed");
1138 if (strlen(name
) > FW_CFG_MAX_FILE_PATH
- 1) {
1139 error_setg(errp
, "name too long (max. %d char)",
1140 FW_CFG_MAX_FILE_PATH
- 1);
1143 if (nonempty_str(gen_id
)) {
1145 * In this particular case where the content is populated
1146 * internally, the "etc/" namespace protection is relaxed,
1147 * so do not emit a warning.
1149 } else if (strncmp(name
, "opt/", 4) != 0) {
1150 warn_report("externally provided fw_cfg item names "
1151 "should be prefixed with \"opt/\"");
1153 if (nonempty_str(str
)) {
1154 size
= strlen(str
); /* NUL terminator NOT included in fw_cfg blob */
1155 buf
= g_memdup(str
, size
);
1156 } else if (nonempty_str(gen_id
)) {
1157 if (!fw_cfg_add_from_generator(fw_cfg
, name
, gen_id
, errp
)) {
1163 if (!g_file_get_contents(file
, &buf
, &size
, &err
)) {
1164 error_setg(errp
, "can't load %s: %s", file
, err
->message
);
1169 /* For legacy, keep user files in a specific global order. */
1170 fw_cfg_set_order_override(fw_cfg
, FW_CFG_ORDER_OVERRIDE_USER
);
1171 fw_cfg_add_file(fw_cfg
, name
, buf
, size
);
1172 fw_cfg_reset_order_override(fw_cfg
);
1176 static int device_help_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1178 return qdev_device_help(opts
);
1181 static int device_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1185 dev
= qdev_device_add(opts
, errp
);
1186 if (!dev
&& *errp
) {
1187 error_report_err(*errp
);
1190 object_unref(OBJECT(dev
));
1195 static int chardev_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1197 Error
*local_err
= NULL
;
1199 if (!qemu_chr_new_from_opts(opts
, NULL
, &local_err
)) {
1201 error_propagate(errp
, local_err
);
1209 #ifdef CONFIG_VIRTFS
1210 static int fsdev_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1212 return qemu_fsdev_add(opts
, errp
);
1216 static int mon_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1218 return monitor_init_opts(opts
, errp
);
1221 static void monitor_parse(const char *optarg
, const char *mode
, bool pretty
)
1223 static int monitor_device_index
= 0;
1228 if (strstart(optarg
, "chardev:", &p
)) {
1229 snprintf(label
, sizeof(label
), "%s", p
);
1231 snprintf(label
, sizeof(label
), "compat_monitor%d",
1232 monitor_device_index
);
1233 opts
= qemu_chr_parse_compat(label
, optarg
, true);
1235 error_report("parse error: %s", optarg
);
1240 opts
= qemu_opts_create(qemu_find_opts("mon"), label
, 1, &error_fatal
);
1241 qemu_opt_set(opts
, "mode", mode
, &error_abort
);
1242 qemu_opt_set(opts
, "chardev", label
, &error_abort
);
1243 if (!strcmp(mode
, "control")) {
1244 qemu_opt_set_bool(opts
, "pretty", pretty
, &error_abort
);
1246 assert(pretty
== false);
1248 monitor_device_index
++;
1251 struct device_config
{
1253 DEV_USB
, /* -usbdevice */
1254 DEV_SERIAL
, /* -serial */
1255 DEV_PARALLEL
, /* -parallel */
1256 DEV_DEBUGCON
, /* -debugcon */
1257 DEV_GDB
, /* -gdb, -s */
1258 DEV_SCLP
, /* s390 sclp */
1260 const char *cmdline
;
1262 QTAILQ_ENTRY(device_config
) next
;
1265 static QTAILQ_HEAD(, device_config
) device_configs
=
1266 QTAILQ_HEAD_INITIALIZER(device_configs
);
1268 static void add_device_config(int type
, const char *cmdline
)
1270 struct device_config
*conf
;
1272 conf
= g_malloc0(sizeof(*conf
));
1274 conf
->cmdline
= cmdline
;
1275 loc_save(&conf
->loc
);
1276 QTAILQ_INSERT_TAIL(&device_configs
, conf
, next
);
1279 static int foreach_device_config(int type
, int (*func
)(const char *cmdline
))
1281 struct device_config
*conf
;
1284 QTAILQ_FOREACH(conf
, &device_configs
, next
) {
1285 if (conf
->type
!= type
)
1287 loc_push_restore(&conf
->loc
);
1288 rc
= func(conf
->cmdline
);
1289 loc_pop(&conf
->loc
);
1297 static void qemu_disable_default_devices(void)
1299 MachineClass
*machine_class
= MACHINE_GET_CLASS(current_machine
);
1301 qemu_opts_foreach(qemu_find_opts("device"),
1302 default_driver_check
, NULL
, NULL
);
1303 qemu_opts_foreach(qemu_find_opts("global"),
1304 default_driver_check
, NULL
, NULL
);
1306 if (!vga_model
&& !default_vga
) {
1307 vga_interface_type
= VGA_DEVICE
;
1309 if (!has_defaults
|| machine_class
->no_serial
) {
1312 if (!has_defaults
|| machine_class
->no_parallel
) {
1313 default_parallel
= 0;
1315 if (!has_defaults
|| machine_class
->no_floppy
) {
1318 if (!has_defaults
|| machine_class
->no_cdrom
) {
1321 if (!has_defaults
|| machine_class
->no_sdcard
) {
1324 if (!has_defaults
) {
1325 default_monitor
= 0;
1331 static void qemu_create_default_devices(void)
1333 MachineClass
*machine_class
= MACHINE_GET_CLASS(current_machine
);
1335 if (is_daemonized()) {
1336 /* According to documentation and historically, -nographic redirects
1337 * serial port, parallel port and monitor to stdio, which does not work
1338 * with -daemonize. We can redirect these to null instead, but since
1339 * -nographic is legacy, let's just error out.
1340 * We disallow -nographic only if all other ports are not redirected
1341 * explicitly, to not break existing legacy setups which uses
1342 * -nographic _and_ redirects all ports explicitly - this is valid
1343 * usage, -nographic is just a no-op in this case.
1346 && (default_parallel
|| default_serial
|| default_monitor
)) {
1347 error_report("-nographic cannot be used with -daemonize");
1353 if (default_parallel
)
1354 add_device_config(DEV_PARALLEL
, "null");
1355 if (default_serial
&& default_monitor
) {
1356 add_device_config(DEV_SERIAL
, "mon:stdio");
1359 add_device_config(DEV_SERIAL
, "stdio");
1360 if (default_monitor
)
1361 monitor_parse("stdio", "readline", false);
1365 add_device_config(DEV_SERIAL
, "vc:80Cx24C");
1366 if (default_parallel
)
1367 add_device_config(DEV_PARALLEL
, "vc:80Cx24C");
1368 if (default_monitor
)
1369 monitor_parse("vc:80Cx24C", "readline", false);
1373 QemuOptsList
*net
= qemu_find_opts("net");
1374 qemu_opts_parse(net
, "nic", true, &error_abort
);
1376 qemu_opts_parse(net
, "user", true, &error_abort
);
1380 #if defined(CONFIG_VNC)
1381 if (!QTAILQ_EMPTY(&(qemu_find_opts("vnc")->head
))) {
1385 if (dpy
.type
== DISPLAY_TYPE_DEFAULT
&& !display_remote
) {
1386 if (!qemu_display_find_default(&dpy
)) {
1387 dpy
.type
= DISPLAY_TYPE_NONE
;
1388 #if defined(CONFIG_VNC)
1389 vnc_parse("localhost:0,to=99,id=default");
1393 if (dpy
.type
== DISPLAY_TYPE_DEFAULT
) {
1394 dpy
.type
= DISPLAY_TYPE_NONE
;
1397 /* If no default VGA is requested, the default is "none". */
1399 vga_model
= get_default_vga_model(machine_class
);
1402 select_vgahw(machine_class
, vga_model
);
1406 static int serial_parse(const char *devname
)
1408 int index
= num_serial_hds
;
1411 if (strcmp(devname
, "none") == 0)
1413 snprintf(label
, sizeof(label
), "serial%d", index
);
1414 serial_hds
= g_renew(Chardev
*, serial_hds
, index
+ 1);
1416 serial_hds
[index
] = qemu_chr_new_mux_mon(label
, devname
, NULL
);
1417 if (!serial_hds
[index
]) {
1418 error_report("could not connect serial device"
1419 " to character backend '%s'", devname
);
1426 Chardev
*serial_hd(int i
)
1429 if (i
< num_serial_hds
) {
1430 return serial_hds
[i
];
1435 static int parallel_parse(const char *devname
)
1437 static int index
= 0;
1440 if (strcmp(devname
, "none") == 0)
1442 if (index
== MAX_PARALLEL_PORTS
) {
1443 error_report("too many parallel ports");
1446 snprintf(label
, sizeof(label
), "parallel%d", index
);
1447 parallel_hds
[index
] = qemu_chr_new_mux_mon(label
, devname
, NULL
);
1448 if (!parallel_hds
[index
]) {
1449 error_report("could not connect parallel device"
1450 " to character backend '%s'", devname
);
1457 static int debugcon_parse(const char *devname
)
1461 if (!qemu_chr_new_mux_mon("debugcon", devname
, NULL
)) {
1462 error_report("invalid character backend '%s'", devname
);
1465 opts
= qemu_opts_create(qemu_find_opts("device"), "debugcon", 1, NULL
);
1467 error_report("already have a debugcon device");
1470 qemu_opt_set(opts
, "driver", "isa-debugcon", &error_abort
);
1471 qemu_opt_set(opts
, "chardev", "debugcon", &error_abort
);
1475 static gint
machine_class_cmp(gconstpointer a
, gconstpointer b
)
1477 const MachineClass
*mc1
= a
, *mc2
= b
;
1480 if (mc1
->family
== NULL
) {
1481 if (mc2
->family
== NULL
) {
1482 /* Compare standalone machine types against each other; they sort
1483 * in increasing order.
1485 return strcmp(object_class_get_name(OBJECT_CLASS(mc1
)),
1486 object_class_get_name(OBJECT_CLASS(mc2
)));
1489 /* Standalone machine types sort after families. */
1493 if (mc2
->family
== NULL
) {
1494 /* Families sort before standalone machine types. */
1498 /* Families sort between each other alphabetically increasingly. */
1499 res
= strcmp(mc1
->family
, mc2
->family
);
1504 /* Within the same family, machine types sort in decreasing order. */
1505 return strcmp(object_class_get_name(OBJECT_CLASS(mc2
)),
1506 object_class_get_name(OBJECT_CLASS(mc1
)));
1509 static void machine_help_func(const QDict
*qdict
)
1511 GSList
*machines
, *el
;
1512 const char *type
= qdict_get_try_str(qdict
, "type");
1514 machines
= object_class_get_list(TYPE_MACHINE
, false);
1516 ObjectClass
*machine_class
= OBJECT_CLASS(find_machine(type
, machines
));
1517 if (machine_class
) {
1518 type_print_class_properties(object_class_get_name(machine_class
));
1523 printf("Supported machines are:\n");
1524 machines
= g_slist_sort(machines
, machine_class_cmp
);
1525 for (el
= machines
; el
; el
= el
->next
) {
1526 MachineClass
*mc
= el
->data
;
1528 printf("%-20s %s (alias of %s)\n", mc
->alias
, mc
->desc
, mc
->name
);
1530 printf("%-20s %s%s%s\n", mc
->name
, mc
->desc
,
1531 mc
->is_default
? " (default)" : "",
1532 mc
->deprecation_reason
? " (deprecated)" : "");
1537 machine_parse_property_opt(QemuOptsList
*opts_list
, const char *propname
,
1538 const char *arg
, Error
**errp
)
1544 prop
= keyval_parse(arg
, opts_list
->implied_opt_name
, &help
, errp
);
1546 qemu_opts_print_help(opts_list
, true);
1550 qdict_put(opts
, propname
, prop
);
1551 keyval_merge(machine_opts_dict
, opts
, errp
);
1552 qobject_unref(opts
);
1555 static const char *pid_file
;
1556 static Notifier qemu_unlink_pidfile_notifier
;
1558 static void qemu_unlink_pidfile(Notifier
*n
, void *data
)
1565 static const QEMUOption
*lookup_opt(int argc
, char **argv
,
1566 const char **poptarg
, int *poptind
)
1568 const QEMUOption
*popt
;
1569 int optind
= *poptind
;
1570 char *r
= argv
[optind
];
1573 loc_set_cmdline(argv
, optind
, 1);
1575 /* Treat --foo the same as -foo. */
1578 popt
= qemu_options
;
1581 error_report("invalid option");
1584 if (!strcmp(popt
->name
, r
+ 1))
1588 if (popt
->flags
& HAS_ARG
) {
1589 if (optind
>= argc
) {
1590 error_report("requires an argument");
1593 optarg
= argv
[optind
++];
1594 loc_set_cmdline(argv
, optind
- 2, 2);
1605 static MachineClass
*select_machine(QDict
*qdict
, Error
**errp
)
1607 const char *optarg
= qdict_get_try_str(qdict
, "type");
1608 GSList
*machines
= object_class_get_list(TYPE_MACHINE
, false);
1609 MachineClass
*machine_class
;
1610 Error
*local_err
= NULL
;
1613 machine_class
= find_machine(optarg
, machines
);
1614 qdict_del(qdict
, "type");
1615 if (!machine_class
) {
1616 error_setg(&local_err
, "unsupported machine type");
1619 machine_class
= find_default_machine(machines
);
1620 if (!machine_class
) {
1621 error_setg(&local_err
, "No machine specified, and there is no default");
1625 g_slist_free(machines
);
1627 error_append_hint(&local_err
, "Use -machine help to list supported machines\n");
1628 error_propagate(errp
, local_err
);
1630 return machine_class
;
1633 static int object_parse_property_opt(Object
*obj
,
1634 const char *name
, const char *value
,
1635 const char *skip
, Error
**errp
)
1637 if (g_str_equal(name
, skip
)) {
1641 if (!object_property_parse(obj
, name
, value
, errp
)) {
1648 /* *Non*recursively replace underscores with dashes in QDict keys. */
1649 static void keyval_dashify(QDict
*qdict
, Error
**errp
)
1651 const QDictEntry
*ent
, *next
;
1654 for (ent
= qdict_first(qdict
); ent
; ent
= next
) {
1655 g_autofree
char *new_key
= NULL
;
1657 next
= qdict_next(qdict
, ent
);
1658 if (!strchr(ent
->key
, '_')) {
1661 new_key
= g_strdup(ent
->key
);
1662 for (p
= new_key
; *p
; p
++) {
1667 if (qdict_haskey(qdict
, new_key
)) {
1668 error_setg(errp
, "Conflict between '%s' and '%s'", ent
->key
, new_key
);
1671 qobject_ref(ent
->value
);
1672 qdict_put_obj(qdict
, new_key
, ent
->value
);
1673 qdict_del(qdict
, ent
->key
);
1677 static void qemu_apply_legacy_machine_options(QDict
*qdict
)
1681 keyval_dashify(qdict
, &error_fatal
);
1683 /* Legacy options do not correspond to MachineState properties. */
1684 value
= qdict_get_try_str(qdict
, "accel");
1686 accelerators
= g_strdup(value
);
1687 qdict_del(qdict
, "accel");
1690 value
= qdict_get_try_str(qdict
, "igd-passthru");
1692 object_register_sugar_prop(ACCEL_CLASS_NAME("xen"), "igd-passthru", value
,
1694 qdict_del(qdict
, "igd-passthru");
1697 value
= qdict_get_try_str(qdict
, "kvm-shadow-mem");
1699 object_register_sugar_prop(ACCEL_CLASS_NAME("kvm"), "kvm-shadow-mem", value
,
1701 qdict_del(qdict
, "kvm-shadow-mem");
1704 value
= qdict_get_try_str(qdict
, "kernel-irqchip");
1706 object_register_sugar_prop(ACCEL_CLASS_NAME("kvm"), "kernel-irqchip", value
,
1708 object_register_sugar_prop(ACCEL_CLASS_NAME("whpx"), "kernel-irqchip", value
,
1710 qdict_del(qdict
, "kernel-irqchip");
1714 static void object_option_foreach_add(bool (*type_opt_predicate
)(const char *))
1716 ObjectOption
*opt
, *next
;
1718 QTAILQ_FOREACH_SAFE(opt
, &object_opts
, next
, next
) {
1719 const char *type
= ObjectType_str(opt
->opts
->qom_type
);
1720 if (type_opt_predicate(type
)) {
1721 user_creatable_add_qapi(opt
->opts
, &error_fatal
);
1722 qapi_free_ObjectOptions(opt
->opts
);
1723 QTAILQ_REMOVE(&object_opts
, opt
, next
);
1729 static void object_option_add_visitor(Visitor
*v
)
1731 ObjectOption
*opt
= g_new0(ObjectOption
, 1);
1732 visit_type_ObjectOptions(v
, NULL
, &opt
->opts
, &error_fatal
);
1733 QTAILQ_INSERT_TAIL(&object_opts
, opt
, next
);
1736 static void object_option_parse(const char *optarg
)
1742 if (optarg
[0] == '{') {
1743 QObject
*obj
= qobject_from_json(optarg
, &error_fatal
);
1745 v
= qobject_input_visitor_new(obj
);
1748 opts
= qemu_opts_parse_noisily(qemu_find_opts("object"),
1754 type
= qemu_opt_get(opts
, "qom-type");
1756 error_setg(&error_fatal
, QERR_MISSING_PARAMETER
, "qom-type");
1758 if (user_creatable_print_help(type
, opts
)) {
1762 v
= opts_visitor_new(opts
);
1765 object_option_add_visitor(v
);
1770 * Initial object creation happens before all other
1771 * QEMU data types are created. The majority of objects
1772 * can be created at this point. The rng-egd object
1773 * cannot be created here, as it depends on the chardev
1776 static bool object_create_early(const char *type
)
1779 * Objects should not be made "delayed" without a reason. If you
1780 * add one, state the reason in a comment!
1783 /* Reason: property "chardev" */
1784 if (g_str_equal(type
, "rng-egd") ||
1785 g_str_equal(type
, "qtest")) {
1789 #if defined(CONFIG_VHOST_USER) && defined(CONFIG_LINUX)
1790 /* Reason: cryptodev-vhost-user property "chardev" */
1791 if (g_str_equal(type
, "cryptodev-vhost-user")) {
1796 /* Reason: vhost-user-blk-server property "node-name" */
1797 if (g_str_equal(type
, "vhost-user-blk-server")) {
1801 * Reason: filter-* property "netdev" etc.
1803 if (g_str_equal(type
, "filter-buffer") ||
1804 g_str_equal(type
, "filter-dump") ||
1805 g_str_equal(type
, "filter-mirror") ||
1806 g_str_equal(type
, "filter-redirector") ||
1807 g_str_equal(type
, "colo-compare") ||
1808 g_str_equal(type
, "filter-rewriter") ||
1809 g_str_equal(type
, "filter-replay")) {
1814 * Allocation of large amounts of memory may delay
1815 * chardev initialization for too long, and trigger timeouts
1816 * on software that waits for a monitor socket to be created
1819 if (g_str_has_prefix(type
, "memory-backend-")) {
1826 static void qemu_apply_machine_options(QDict
*qdict
)
1828 MachineClass
*machine_class
= MACHINE_GET_CLASS(current_machine
);
1829 const char *boot_order
= NULL
;
1830 const char *boot_once
= NULL
;
1833 object_set_properties_from_keyval(OBJECT(current_machine
), qdict
, false, &error_fatal
);
1834 current_machine
->ram_size
= ram_size
;
1835 current_machine
->maxram_size
= maxram_size
;
1836 current_machine
->ram_slots
= ram_slots
;
1838 opts
= qemu_opts_find(qemu_find_opts("boot-opts"), NULL
);
1840 boot_order
= qemu_opt_get(opts
, "order");
1842 validate_bootdevices(boot_order
, &error_fatal
);
1845 boot_once
= qemu_opt_get(opts
, "once");
1847 validate_bootdevices(boot_once
, &error_fatal
);
1850 boot_menu
= qemu_opt_get_bool(opts
, "menu", boot_menu
);
1851 boot_strict
= qemu_opt_get_bool(opts
, "strict", false);
1855 boot_order
= machine_class
->default_boot_order
;
1858 current_machine
->boot_order
= boot_order
;
1859 current_machine
->boot_once
= boot_once
;
1861 if (semihosting_enabled() && !semihosting_get_argc()) {
1862 /* fall back to the -kernel/-append */
1863 semihosting_arg_fallback(current_machine
->kernel_filename
, current_machine
->kernel_cmdline
);
1866 if (current_machine
->smp
.cpus
> 1) {
1867 Error
*blocker
= NULL
;
1868 error_setg(&blocker
, QERR_REPLAY_NOT_SUPPORTED
, "smp");
1869 replay_add_blocker(blocker
);
1873 static void qemu_create_early_backends(void)
1875 MachineClass
*machine_class
= MACHINE_GET_CLASS(current_machine
);
1876 #if defined(CONFIG_SDL)
1877 const bool use_sdl
= (dpy
.type
== DISPLAY_TYPE_SDL
);
1879 const bool use_sdl
= false;
1881 #if defined(CONFIG_GTK)
1882 const bool use_gtk
= (dpy
.type
== DISPLAY_TYPE_GTK
);
1884 const bool use_gtk
= false;
1887 if ((alt_grab
|| ctrl_grab
) && !use_sdl
) {
1888 error_report("-alt-grab and -ctrl-grab are only valid "
1889 "for SDL, ignoring option");
1891 if (dpy
.has_window_close
&& !use_gtk
&& !use_sdl
) {
1892 error_report("-no-quit is only valid for GTK and SDL, "
1896 qemu_display_early_init(&dpy
);
1897 qemu_console_early_init();
1899 if (dpy
.has_gl
&& dpy
.gl
!= DISPLAYGL_MODE_OFF
&& display_opengl
== 0) {
1900 #if defined(CONFIG_OPENGL)
1901 error_report("OpenGL is not supported by the display");
1903 error_report("OpenGL support is disabled");
1908 object_option_foreach_add(object_create_early
);
1910 /* spice needs the timers to be initialized by this point */
1911 /* spice must initialize before audio as it changes the default auiodev */
1912 /* spice must initialize before chardevs (for spicevmc and spiceport) */
1915 qemu_opts_foreach(qemu_find_opts("chardev"),
1916 chardev_init_func
, NULL
, &error_fatal
);
1918 #ifdef CONFIG_VIRTFS
1919 qemu_opts_foreach(qemu_find_opts("fsdev"),
1920 fsdev_init_func
, NULL
, &error_fatal
);
1924 * Note: we need to create audio and block backends before
1925 * setting machine properties, so they can be referred to.
1927 configure_blockdev(&bdo_queue
, machine_class
, snapshot
);
1928 audio_init_audiodevs();
1933 * The remainder of object creation happens after the
1934 * creation of chardev, fsdev, net clients and device data types.
1936 static bool object_create_late(const char *type
)
1938 return !object_create_early(type
);
1941 static void qemu_create_late_backends(void)
1944 qtest_server_init(qtest_chrdev
, qtest_log
, &error_fatal
);
1947 net_init_clients(&error_fatal
);
1949 object_option_foreach_add(object_create_late
);
1951 if (tpm_init() < 0) {
1955 qemu_opts_foreach(qemu_find_opts("mon"),
1956 mon_init_func
, NULL
, &error_fatal
);
1958 if (foreach_device_config(DEV_SERIAL
, serial_parse
) < 0)
1960 if (foreach_device_config(DEV_PARALLEL
, parallel_parse
) < 0)
1962 if (foreach_device_config(DEV_DEBUGCON
, debugcon_parse
) < 0)
1965 /* now chardevs have been created we may have semihosting to connect */
1966 qemu_semihosting_connect_chardevs();
1967 qemu_semihosting_console_init();
1970 static bool have_custom_ram_size(void)
1972 QemuOpts
*opts
= qemu_find_opts_singleton("memory");
1973 return !!qemu_opt_get_size(opts
, "size", 0);
1976 static void qemu_resolve_machine_memdev(void)
1978 if (current_machine
->ram_memdev_id
) {
1980 ram_addr_t backend_size
;
1982 backend
= object_resolve_path_type(current_machine
->ram_memdev_id
,
1983 TYPE_MEMORY_BACKEND
, NULL
);
1985 error_report("Memory backend '%s' not found",
1986 current_machine
->ram_memdev_id
);
1989 backend_size
= object_property_get_uint(backend
, "size", &error_abort
);
1990 if (have_custom_ram_size() && backend_size
!= ram_size
) {
1991 error_report("Size specified by -m option must match size of "
1992 "explicitly specified 'memory-backend' property");
1996 error_report("'-mem-path' can't be used together with"
1997 "'-machine memory-backend'");
2000 ram_size
= backend_size
;
2003 if (!xen_enabled()) {
2004 /* On 32-bit hosts, QEMU is limited by virtual address space */
2005 if (ram_size
> (2047 << 20) && HOST_LONG_BITS
== 32) {
2006 error_report("at most 2047 MB RAM can be simulated");
2012 static void set_memory_options(MachineClass
*mc
)
2015 const char *mem_str
;
2016 const ram_addr_t default_ram_size
= mc
->default_ram_size
;
2017 QemuOpts
*opts
= qemu_find_opts_singleton("memory");
2020 loc_push_none(&loc
);
2021 qemu_opts_loc_restore(opts
);
2024 mem_str
= qemu_opt_get(opts
, "size");
2027 error_report("missing 'size' option value");
2031 sz
= qemu_opt_get_size(opts
, "size", ram_size
);
2033 /* Fix up legacy suffix-less format */
2034 if (g_ascii_isdigit(mem_str
[strlen(mem_str
) - 1])) {
2035 uint64_t overflow_check
= sz
;
2038 if (sz
/ MiB
!= overflow_check
) {
2039 error_report("too large 'size' option value");
2045 /* backward compatibility behaviour for case "-m 0" */
2047 sz
= default_ram_size
;
2050 sz
= QEMU_ALIGN_UP(sz
, 8192);
2051 if (mc
->fixup_ram_size
) {
2052 sz
= mc
->fixup_ram_size(sz
);
2055 if (ram_size
!= sz
) {
2056 error_report("ram size too large");
2060 maxram_size
= ram_size
;
2062 if (qemu_opt_get(opts
, "maxmem")) {
2065 sz
= qemu_opt_get_size(opts
, "maxmem", 0);
2066 slots
= qemu_opt_get_number(opts
, "slots", 0);
2067 if (sz
< ram_size
) {
2068 error_report("invalid value of -m option maxmem: "
2069 "maximum memory size (0x%" PRIx64
") must be at least "
2070 "the initial memory size (0x" RAM_ADDR_FMT
")",
2073 } else if (slots
&& sz
== ram_size
) {
2074 error_report("invalid value of -m option maxmem: "
2075 "memory slots were specified but maximum memory size "
2076 "(0x%" PRIx64
") is equal to the initial memory size "
2077 "(0x" RAM_ADDR_FMT
")", sz
, ram_size
);
2083 } else if (qemu_opt_get(opts
, "slots")) {
2084 error_report("invalid -m option value: missing 'maxmem' option");
2091 static void qemu_create_machine(QDict
*qdict
)
2093 MachineClass
*machine_class
= select_machine(qdict
, &error_fatal
);
2094 object_set_machine_compat_props(machine_class
->compat_props
);
2096 set_memory_options(machine_class
);
2098 current_machine
= MACHINE(object_new_with_class(OBJECT_CLASS(machine_class
)));
2099 object_property_add_child(object_get_root(), "machine",
2100 OBJECT(current_machine
));
2101 object_property_add_child(container_get(OBJECT(current_machine
),
2103 "sysbus", OBJECT(sysbus_get_default()));
2105 if (machine_class
->minimum_page_bits
) {
2106 if (!set_preferred_target_page_bits(machine_class
->minimum_page_bits
)) {
2107 /* This would be a board error: specifying a minimum smaller than
2108 * a target's compile-time fixed setting.
2110 g_assert_not_reached();
2114 cpu_exec_init_all();
2117 if (machine_class
->hw_version
) {
2118 qemu_set_hw_version(machine_class
->hw_version
);
2122 * Get the default machine options from the machine if it is not already
2123 * specified either by the configuration file or by the command line.
2125 if (machine_class
->default_machine_opts
) {
2126 QDict
*default_opts
=
2127 keyval_parse(machine_class
->default_machine_opts
, NULL
, NULL
,
2129 object_set_properties_from_keyval(OBJECT(current_machine
), default_opts
,
2130 false, &error_abort
);
2131 qobject_unref(default_opts
);
2135 static int global_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2139 g
= g_malloc0(sizeof(*g
));
2140 g
->driver
= qemu_opt_get(opts
, "driver");
2141 g
->property
= qemu_opt_get(opts
, "property");
2142 g
->value
= qemu_opt_get(opts
, "value");
2143 qdev_prop_register_global(g
);
2148 * Return whether configuration group @group is stored in QemuOpts, or
2149 * recorded as one or more QDicts by qemu_record_config_group.
2151 static bool is_qemuopts_group(const char *group
)
2153 if (g_str_equal(group
, "object") ||
2154 g_str_equal(group
, "machine")) {
2160 static void qemu_record_config_group(const char *group
, QDict
*dict
,
2161 bool from_json
, Error
**errp
)
2163 if (g_str_equal(group
, "object")) {
2164 Visitor
*v
= qobject_input_visitor_new_keyval(QOBJECT(dict
));
2165 object_option_add_visitor(v
);
2167 } else if (g_str_equal(group
, "machine")) {
2169 * Cannot merge string-valued and type-safe dictionaries, so JSON
2170 * is not accepted yet for -M.
2173 keyval_merge(machine_opts_dict
, dict
, errp
);
2180 * Parse non-QemuOpts config file groups, pass the rest to
2181 * qemu_config_do_parse.
2183 static void qemu_parse_config_group(const char *group
, QDict
*qdict
,
2184 void *opaque
, Error
**errp
)
2187 if (is_qemuopts_group(group
)) {
2188 qemu_config_do_parse(group
, qdict
, opaque
, errp
);
2192 crumpled
= qdict_crumple(qdict
, errp
);
2196 switch (qobject_type(crumpled
)) {
2198 qemu_record_config_group(group
, qobject_to(QDict
, crumpled
), false, errp
);
2201 error_setg(errp
, "Lists cannot be at top level of a configuration section");
2204 g_assert_not_reached();
2206 qobject_unref(crumpled
);
2209 static void qemu_read_default_config_file(Error
**errp
)
2213 g_autofree
char *file
= get_relocated_path(CONFIG_QEMU_CONFDIR
"/qemu.conf");
2215 ret
= qemu_read_config_file(file
, qemu_parse_config_group
, errp
);
2217 if (ret
== -ENOENT
) {
2224 static void qemu_set_option(const char *str
, Error
**errp
)
2226 char group
[64], id
[64], arg
[64];
2231 rc
= sscanf(str
, "%63[^.].%63[^.].%63[^=]%n", group
, id
, arg
, &offset
);
2232 if (rc
< 3 || str
[offset
] != '=') {
2233 error_setg(errp
, "can't parse: \"%s\"", str
);
2237 if (!is_qemuopts_group(group
)) {
2238 error_setg(errp
, "-set is not supported with %s", group
);
2240 list
= qemu_find_opts_err(group
, errp
);
2242 opts
= qemu_opts_find(list
, id
);
2244 error_setg(errp
, "there is no %s \"%s\" defined", group
, id
);
2247 qemu_opt_set(opts
, arg
, str
+ offset
+ 1, errp
);
2252 static void user_register_global_props(void)
2254 qemu_opts_foreach(qemu_find_opts("global"),
2255 global_init_func
, NULL
, NULL
);
2258 static int do_configure_icount(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2260 icount_configure(opts
, errp
);
2264 static int accelerator_set_property(void *opaque
,
2265 const char *name
, const char *value
,
2268 return object_parse_property_opt(opaque
, name
, value
, "accel", errp
);
2271 static int do_configure_accelerator(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2273 bool *p_init_failed
= opaque
;
2274 const char *acc
= qemu_opt_get(opts
, "accel");
2275 AccelClass
*ac
= accel_find(acc
);
2278 bool qtest_with_kvm
;
2280 qtest_with_kvm
= g_str_equal(acc
, "kvm") && qtest_chrdev
!= NULL
;
2283 *p_init_failed
= true;
2284 if (!qtest_with_kvm
) {
2285 error_report("invalid accelerator %s", acc
);
2289 accel
= ACCEL(object_new_with_class(OBJECT_CLASS(ac
)));
2290 object_apply_compat_props(OBJECT(accel
));
2291 qemu_opt_foreach(opts
, accelerator_set_property
,
2295 ret
= accel_init_machine(accel
, current_machine
);
2297 *p_init_failed
= true;
2298 if (!qtest_with_kvm
|| ret
!= -ENOENT
) {
2299 error_report("failed to initialize %s: %s", acc
, strerror(-ret
));
2307 static void configure_accelerators(const char *progname
)
2309 bool init_failed
= false;
2311 qemu_opts_foreach(qemu_find_opts("icount"),
2312 do_configure_icount
, NULL
, &error_fatal
);
2314 if (QTAILQ_EMPTY(&qemu_accel_opts
.head
)) {
2315 char **accel_list
, **tmp
;
2317 if (accelerators
== NULL
) {
2318 /* Select the default accelerator */
2319 bool have_tcg
= accel_find("tcg");
2320 bool have_kvm
= accel_find("kvm");
2322 if (have_tcg
&& have_kvm
) {
2323 if (g_str_has_suffix(progname
, "kvm")) {
2324 /* If the program name ends with "kvm", we prefer KVM */
2325 accelerators
= "kvm:tcg";
2327 accelerators
= "tcg:kvm";
2329 } else if (have_kvm
) {
2330 accelerators
= "kvm";
2331 } else if (have_tcg
) {
2332 accelerators
= "tcg";
2334 error_report("No accelerator selected and"
2335 " no default accelerator available");
2339 accel_list
= g_strsplit(accelerators
, ":", 0);
2341 for (tmp
= accel_list
; *tmp
; tmp
++) {
2343 * Filter invalid accelerators here, to prevent obscenities
2344 * such as "-machine accel=tcg,,thread=single".
2346 if (accel_find(*tmp
)) {
2347 qemu_opts_parse_noisily(qemu_find_opts("accel"), *tmp
, true);
2350 error_report("invalid accelerator %s", *tmp
);
2353 g_strfreev(accel_list
);
2355 if (accelerators
!= NULL
) {
2356 error_report("The -accel and \"-machine accel=\" options are incompatible");
2361 if (!qemu_opts_foreach(qemu_find_opts("accel"),
2362 do_configure_accelerator
, &init_failed
, &error_fatal
)) {
2364 error_report("no accelerator found");
2369 if (init_failed
&& !qtest_chrdev
) {
2370 AccelClass
*ac
= ACCEL_GET_CLASS(current_accel());
2371 error_report("falling back to %s", ac
->name
);
2374 if (icount_enabled() && !tcg_enabled()) {
2375 error_report("-icount is not allowed with hardware virtualization");
2380 static void create_default_memdev(MachineState
*ms
, const char *path
)
2383 MachineClass
*mc
= MACHINE_GET_CLASS(ms
);
2385 obj
= object_new(path
? TYPE_MEMORY_BACKEND_FILE
: TYPE_MEMORY_BACKEND_RAM
);
2387 object_property_set_str(obj
, "mem-path", path
, &error_fatal
);
2389 object_property_set_int(obj
, "size", ms
->ram_size
, &error_fatal
);
2390 object_property_add_child(object_get_objects_root(), mc
->default_ram_id
,
2392 /* Ensure backend's memory region name is equal to mc->default_ram_id */
2393 object_property_set_bool(obj
, "x-use-canonical-path-for-ramblock-id",
2394 false, &error_fatal
);
2395 user_creatable_complete(USER_CREATABLE(obj
), &error_fatal
);
2397 object_property_set_str(OBJECT(ms
), "memory-backend", mc
->default_ram_id
,
2401 static void qemu_validate_options(const QDict
*machine_opts
)
2403 const char *kernel_filename
= qdict_get_try_str(machine_opts
, "kernel");
2404 const char *initrd_filename
= qdict_get_try_str(machine_opts
, "initrd");
2405 const char *kernel_cmdline
= qdict_get_try_str(machine_opts
, "append");
2407 if (kernel_filename
== NULL
) {
2408 if (kernel_cmdline
!= NULL
) {
2409 error_report("-append only allowed with -kernel option");
2413 if (initrd_filename
!= NULL
) {
2414 error_report("-initrd only allowed with -kernel option");
2419 if (loadvm
&& preconfig_requested
) {
2420 error_report("'preconfig' and 'loadvm' options are "
2421 "mutually exclusive");
2424 if (incoming
&& preconfig_requested
&& strcmp(incoming
, "defer") != 0) {
2425 error_report("'preconfig' supports '-incoming defer' only");
2429 #ifdef CONFIG_CURSES
2430 if (is_daemonized() && dpy
.type
== DISPLAY_TYPE_CURSES
) {
2431 error_report("curses display cannot be used with -daemonize");
2437 static void qemu_process_sugar_options(void)
2442 val
= g_strdup_printf("%d",
2443 (uint32_t) qemu_opt_get_number(qemu_find_opts_singleton("smp-opts"), "cpus", 1));
2444 object_register_sugar_prop("memory-backend", "prealloc-threads", val
,
2447 object_register_sugar_prop("memory-backend", "prealloc", "on", false);
2451 int i
= select_watchdog(watchdog
);
2453 exit (i
== 1 ? 1 : 0);
2457 /* -action processing */
2460 * Process all the -action parameters parsed from cmdline.
2462 static int process_runstate_actions(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2464 Error
*local_err
= NULL
;
2465 QDict
*qdict
= qemu_opts_to_qdict(opts
, NULL
);
2466 QObject
*ret
= NULL
;
2467 qmp_marshal_set_action(qdict
, &ret
, &local_err
);
2469 qobject_unref(qdict
);
2471 error_propagate(errp
, local_err
);
2477 static void qemu_process_early_options(void)
2479 #ifdef CONFIG_SECCOMP
2480 QemuOptsList
*olist
= qemu_find_opts_err("sandbox", NULL
);
2482 qemu_opts_foreach(olist
, parse_sandbox
, NULL
, &error_fatal
);
2486 qemu_opts_foreach(qemu_find_opts("name"),
2487 parse_name
, NULL
, &error_fatal
);
2489 if (qemu_opts_foreach(qemu_find_opts("action"),
2490 process_runstate_actions
, NULL
, &error_fatal
)) {
2495 qemu_opts_foreach(qemu_find_opts("add-fd"),
2496 parse_add_fd
, NULL
, &error_fatal
);
2498 qemu_opts_foreach(qemu_find_opts("add-fd"),
2499 cleanup_add_fd
, NULL
, &error_fatal
);
2502 /* Open the logfile at this point and set the log mask if necessary. */
2504 qemu_set_log_filename(log_file
, &error_fatal
);
2508 mask
= qemu_str_to_log_mask(log_mask
);
2510 qemu_print_log_usage(stdout
);
2518 qemu_add_default_firmwarepath();
2521 static void qemu_process_help_options(void)
2524 * Check for -cpu help and -device help before we call select_machine(),
2525 * which will return an error if the architecture has no default machine
2526 * type and the user did not specify one, so that the user doesn't need
2527 * to say '-cpu help -machine something'.
2529 if (cpu_option
&& is_help_option(cpu_option
)) {
2530 list_cpus(cpu_option
);
2534 if (qemu_opts_foreach(qemu_find_opts("device"),
2535 device_help_func
, NULL
, NULL
)) {
2539 /* -L help lists the data directories and exits. */
2540 if (list_data_dirs
) {
2541 qemu_list_data_dirs();
2546 static void qemu_maybe_daemonize(const char *pid_file
)
2551 rcu_disable_atfork();
2553 if (pid_file
&& !qemu_write_pidfile(pid_file
, &err
)) {
2554 error_reportf_err(err
, "cannot create PID file: ");
2558 qemu_unlink_pidfile_notifier
.notify
= qemu_unlink_pidfile
;
2559 qemu_add_exit_notifier(&qemu_unlink_pidfile_notifier
);
2562 static void qemu_init_displays(void)
2566 /* init local displays */
2567 ds
= init_displaystate();
2568 qemu_display_init(ds
, &dpy
);
2570 /* must be after terminal init, SDL library changes signal handlers */
2571 os_setup_signal_handling();
2573 /* init remote displays */
2575 qemu_opts_foreach(qemu_find_opts("vnc"),
2576 vnc_init_func
, NULL
, &error_fatal
);
2580 qemu_spice
.display_init();
2584 static void qemu_init_board(void)
2586 MachineClass
*machine_class
= MACHINE_GET_CLASS(current_machine
);
2588 if (machine_class
->default_ram_id
&& current_machine
->ram_size
&&
2589 numa_uses_legacy_mem() && !current_machine
->ram_memdev_id
) {
2590 create_default_memdev(current_machine
, mem_path
);
2593 /* process plugin before CPUs are created, but once -smp has been parsed */
2594 qemu_plugin_load_list(&plugin_list
, &error_fatal
);
2596 /* From here on we enter MACHINE_PHASE_INITIALIZED. */
2597 machine_run_board_init(current_machine
);
2599 drive_check_orphaned();
2603 if (hax_enabled()) {
2604 /* FIXME: why isn't cpu_synchronize_all_post_init enough? */
2609 static void qemu_create_cli_devices(void)
2613 qemu_opts_foreach(qemu_find_opts("fw_cfg"),
2614 parse_fw_cfg
, fw_cfg_find(), &error_fatal
);
2616 /* init USB devices */
2617 if (machine_usb(current_machine
)) {
2618 if (foreach_device_config(DEV_USB
, usb_parse
) < 0)
2622 /* init generic devices */
2623 rom_set_order_override(FW_CFG_ORDER_OVERRIDE_DEVICE
);
2624 qemu_opts_foreach(qemu_find_opts("device"),
2625 device_init_func
, NULL
, &error_fatal
);
2626 rom_reset_order_override();
2629 static void qemu_machine_creation_done(void)
2631 MachineState
*machine
= MACHINE(qdev_get_machine());
2633 /* Did we create any drives that we failed to create a device for? */
2634 drive_check_orphaned();
2636 /* Don't warn about the default network setup that you get if
2637 * no command line -net or -netdev options are specified. There
2638 * are two cases that we would otherwise complain about:
2639 * (1) board doesn't support a NIC but the implicit "-net nic"
2641 * (2) CONFIG_SLIRP not set, in which case the implicit "-net nic"
2642 * sets up a nic that isn't connected to anything.
2644 if (!default_net
&& (!qtest_enabled() || has_defaults
)) {
2645 net_check_clients();
2648 qdev_prop_check_globals();
2650 qdev_machine_creation_done();
2654 * Verify that Confidential Guest Support has actually been initialized
2656 assert(machine
->cgs
->ready
);
2659 if (foreach_device_config(DEV_GDB
, gdbserver_start
) < 0) {
2664 void qmp_x_exit_preconfig(Error
**errp
)
2666 if (phase_check(PHASE_MACHINE_INITIALIZED
)) {
2667 error_setg(errp
, "The command is permitted only before machine initialization");
2672 qemu_create_cli_devices();
2673 qemu_machine_creation_done();
2676 Error
*local_err
= NULL
;
2677 if (!load_snapshot(loadvm
, NULL
, false, NULL
, &local_err
)) {
2678 error_report_err(local_err
);
2683 if (replay_mode
!= REPLAY_MODE_NONE
) {
2684 replay_vmstate_init();
2688 Error
*local_err
= NULL
;
2689 if (strcmp(incoming
, "defer") != 0) {
2690 qmp_migrate_incoming(incoming
, &local_err
);
2692 error_reportf_err(local_err
, "-incoming %s: ", incoming
);
2696 } else if (autostart
) {
2701 void qemu_init(int argc
, char **argv
, char **envp
)
2704 QemuOpts
*icount_opts
= NULL
, *accel_opts
= NULL
;
2705 QemuOptsList
*olist
;
2708 MachineClass
*machine_class
;
2709 bool userconfig
= true;
2710 FILE *vmstate_dump_file
= NULL
;
2712 qemu_add_opts(&qemu_drive_opts
);
2713 qemu_add_drive_opts(&qemu_legacy_drive_opts
);
2714 qemu_add_drive_opts(&qemu_common_drive_opts
);
2715 qemu_add_drive_opts(&qemu_drive_opts
);
2716 qemu_add_drive_opts(&bdrv_runtime_opts
);
2717 qemu_add_opts(&qemu_chardev_opts
);
2718 qemu_add_opts(&qemu_device_opts
);
2719 qemu_add_opts(&qemu_netdev_opts
);
2720 qemu_add_opts(&qemu_nic_opts
);
2721 qemu_add_opts(&qemu_net_opts
);
2722 qemu_add_opts(&qemu_rtc_opts
);
2723 qemu_add_opts(&qemu_global_opts
);
2724 qemu_add_opts(&qemu_mon_opts
);
2725 qemu_add_opts(&qemu_trace_opts
);
2726 qemu_plugin_add_opts();
2727 qemu_add_opts(&qemu_option_rom_opts
);
2728 qemu_add_opts(&qemu_accel_opts
);
2729 qemu_add_opts(&qemu_mem_opts
);
2730 qemu_add_opts(&qemu_smp_opts
);
2731 qemu_add_opts(&qemu_boot_opts
);
2732 qemu_add_opts(&qemu_add_fd_opts
);
2733 qemu_add_opts(&qemu_object_opts
);
2734 qemu_add_opts(&qemu_tpmdev_opts
);
2735 qemu_add_opts(&qemu_overcommit_opts
);
2736 qemu_add_opts(&qemu_msg_opts
);
2737 qemu_add_opts(&qemu_name_opts
);
2738 qemu_add_opts(&qemu_numa_opts
);
2739 qemu_add_opts(&qemu_icount_opts
);
2740 qemu_add_opts(&qemu_semihosting_config_opts
);
2741 qemu_add_opts(&qemu_fw_cfg_opts
);
2742 qemu_add_opts(&qemu_action_opts
);
2743 module_call_init(MODULE_INIT_OPTS
);
2745 error_init(argv
[0]);
2746 qemu_init_exec_dir(argv
[0]);
2748 #ifdef CONFIG_MODULES
2749 module_init_info(qemu_modinfo
);
2750 module_allow_arch(TARGET_NAME
);
2753 qemu_init_subsystems();
2755 /* first pass of option parsing */
2757 while (optind
< argc
) {
2758 if (argv
[optind
][0] != '-') {
2762 const QEMUOption
*popt
;
2764 popt
= lookup_opt(argc
, argv
, &optarg
, &optind
);
2765 switch (popt
->index
) {
2766 case QEMU_OPTION_nouserconfig
:
2773 machine_opts_dict
= qdict_new();
2775 qemu_read_default_config_file(&error_fatal
);
2778 /* second pass of option parsing */
2783 if (argv
[optind
][0] != '-') {
2784 loc_set_cmdline(argv
, optind
, 1);
2785 drive_add(IF_DEFAULT
, 0, argv
[optind
++], HD_OPTS
);
2787 const QEMUOption
*popt
;
2789 popt
= lookup_opt(argc
, argv
, &optarg
, &optind
);
2790 if (!(popt
->arch_mask
& arch_type
)) {
2791 error_report("Option not supported for this target");
2794 switch(popt
->index
) {
2795 case QEMU_OPTION_cpu
:
2796 /* hw initialization will check this */
2797 cpu_option
= optarg
;
2799 case QEMU_OPTION_hda
:
2800 case QEMU_OPTION_hdb
:
2801 case QEMU_OPTION_hdc
:
2802 case QEMU_OPTION_hdd
:
2803 drive_add(IF_DEFAULT
, popt
->index
- QEMU_OPTION_hda
, optarg
,
2806 case QEMU_OPTION_blockdev
:
2809 BlockdevOptionsQueueEntry
*bdo
;
2811 v
= qobject_input_visitor_new_str(optarg
, "driver",
2814 bdo
= g_new(BlockdevOptionsQueueEntry
, 1);
2815 visit_type_BlockdevOptions(v
, NULL
, &bdo
->bdo
,
2818 loc_save(&bdo
->loc
);
2819 QSIMPLEQ_INSERT_TAIL(&bdo_queue
, bdo
, entry
);
2822 case QEMU_OPTION_drive
:
2823 if (drive_def(optarg
) == NULL
) {
2827 case QEMU_OPTION_set
:
2828 qemu_set_option(optarg
, &error_fatal
);
2830 case QEMU_OPTION_global
:
2831 if (qemu_global_option(optarg
) != 0)
2834 case QEMU_OPTION_mtdblock
:
2835 drive_add(IF_MTD
, -1, optarg
, MTD_OPTS
);
2837 case QEMU_OPTION_sd
:
2838 drive_add(IF_SD
, -1, optarg
, SD_OPTS
);
2840 case QEMU_OPTION_pflash
:
2841 drive_add(IF_PFLASH
, -1, optarg
, PFLASH_OPTS
);
2843 case QEMU_OPTION_snapshot
:
2845 Error
*blocker
= NULL
;
2847 error_setg(&blocker
, QERR_REPLAY_NOT_SUPPORTED
,
2849 replay_add_blocker(blocker
);
2852 case QEMU_OPTION_numa
:
2853 opts
= qemu_opts_parse_noisily(qemu_find_opts("numa"),
2859 case QEMU_OPTION_display
:
2860 parse_display(optarg
);
2862 case QEMU_OPTION_nographic
:
2863 qdict_put_str(machine_opts_dict
, "graphics", "off");
2865 dpy
.type
= DISPLAY_TYPE_NONE
;
2867 case QEMU_OPTION_curses
:
2868 #ifdef CONFIG_CURSES
2869 dpy
.type
= DISPLAY_TYPE_CURSES
;
2871 error_report("curses or iconv support is disabled");
2875 case QEMU_OPTION_portrait
:
2876 graphic_rotate
= 90;
2878 case QEMU_OPTION_rotate
:
2879 graphic_rotate
= strtol(optarg
, (char **) &optarg
, 10);
2880 if (graphic_rotate
!= 0 && graphic_rotate
!= 90 &&
2881 graphic_rotate
!= 180 && graphic_rotate
!= 270) {
2882 error_report("only 90, 180, 270 deg rotation is available");
2886 case QEMU_OPTION_kernel
:
2887 qdict_put_str(machine_opts_dict
, "kernel", optarg
);
2889 case QEMU_OPTION_initrd
:
2890 qdict_put_str(machine_opts_dict
, "initrd", optarg
);
2892 case QEMU_OPTION_append
:
2893 qdict_put_str(machine_opts_dict
, "append", optarg
);
2895 case QEMU_OPTION_dtb
:
2896 qdict_put_str(machine_opts_dict
, "dtb", optarg
);
2898 case QEMU_OPTION_cdrom
:
2899 drive_add(IF_DEFAULT
, 2, optarg
, CDROM_OPTS
);
2901 case QEMU_OPTION_boot
:
2902 opts
= qemu_opts_parse_noisily(qemu_find_opts("boot-opts"),
2908 case QEMU_OPTION_fda
:
2909 case QEMU_OPTION_fdb
:
2910 drive_add(IF_FLOPPY
, popt
->index
- QEMU_OPTION_fda
,
2913 case QEMU_OPTION_no_fd_bootchk
:
2916 case QEMU_OPTION_netdev
:
2918 if (net_client_parse(qemu_find_opts("netdev"), optarg
) == -1) {
2922 case QEMU_OPTION_nic
:
2924 if (net_client_parse(qemu_find_opts("nic"), optarg
) == -1) {
2928 case QEMU_OPTION_net
:
2930 if (net_client_parse(qemu_find_opts("net"), optarg
) == -1) {
2934 #ifdef CONFIG_LIBISCSI
2935 case QEMU_OPTION_iscsi
:
2936 opts
= qemu_opts_parse_noisily(qemu_find_opts("iscsi"),
2943 case QEMU_OPTION_audio_help
:
2944 audio_legacy_help();
2947 case QEMU_OPTION_audiodev
:
2948 audio_parse_option(optarg
);
2950 case QEMU_OPTION_soundhw
:
2951 select_soundhw (optarg
);
2956 case QEMU_OPTION_version
:
2961 opts
= qemu_opts_parse_noisily(qemu_find_opts("memory"),
2968 case QEMU_OPTION_tpmdev
:
2969 if (tpm_config_parse(qemu_find_opts("tpmdev"), optarg
) < 0) {
2974 case QEMU_OPTION_mempath
:
2977 case QEMU_OPTION_mem_prealloc
:
2986 case QEMU_OPTION_DFILTER
:
2987 qemu_set_dfilter_ranges(optarg
, &error_fatal
);
2989 case QEMU_OPTION_seed
:
2990 qemu_guest_random_seed_main(optarg
, &error_fatal
);
2993 add_device_config(DEV_GDB
, "tcp::" DEFAULT_GDBSTUB_PORT
);
2995 case QEMU_OPTION_gdb
:
2996 add_device_config(DEV_GDB
, optarg
);
2999 if (is_help_option(optarg
)) {
3000 list_data_dirs
= true;
3002 qemu_add_data_dir(g_strdup(optarg
));
3005 case QEMU_OPTION_bios
:
3006 qdict_put_str(machine_opts_dict
, "firmware", optarg
);
3008 case QEMU_OPTION_singlestep
:
3015 keyboard_layout
= optarg
;
3017 case QEMU_OPTION_vga
:
3026 w
= strtol(p
, (char **)&p
, 10);
3029 error_report("invalid resolution or depth");
3035 h
= strtol(p
, (char **)&p
, 10);
3040 depth
= strtol(p
, (char **)&p
, 10);
3041 if (depth
!= 1 && depth
!= 2 && depth
!= 4 &&
3042 depth
!= 8 && depth
!= 15 && depth
!= 16 &&
3043 depth
!= 24 && depth
!= 32)
3045 } else if (*p
== '\0') {
3046 depth
= graphic_depth
;
3053 graphic_depth
= depth
;
3056 case QEMU_OPTION_echr
:
3059 term_escape_char
= strtol(optarg
, &r
, 0);
3061 printf("Bad argument to echr\n");
3064 case QEMU_OPTION_monitor
:
3065 default_monitor
= 0;
3066 if (strncmp(optarg
, "none", 4)) {
3067 monitor_parse(optarg
, "readline", false);
3070 case QEMU_OPTION_qmp
:
3071 monitor_parse(optarg
, "control", false);
3072 default_monitor
= 0;
3074 case QEMU_OPTION_qmp_pretty
:
3075 monitor_parse(optarg
, "control", true);
3076 default_monitor
= 0;
3078 case QEMU_OPTION_mon
:
3079 opts
= qemu_opts_parse_noisily(qemu_find_opts("mon"), optarg
,
3084 default_monitor
= 0;
3086 case QEMU_OPTION_chardev
:
3087 opts
= qemu_opts_parse_noisily(qemu_find_opts("chardev"),
3093 case QEMU_OPTION_fsdev
:
3094 olist
= qemu_find_opts("fsdev");
3096 error_report("fsdev support is disabled");
3099 opts
= qemu_opts_parse_noisily(olist
, optarg
, true);
3104 case QEMU_OPTION_virtfs
: {
3107 const char *writeout
, *sock_fd
, *socket
, *path
, *security_model
,
3110 olist
= qemu_find_opts("virtfs");
3112 error_report("virtfs support is disabled");
3115 opts
= qemu_opts_parse_noisily(olist
, optarg
, true);
3120 if (qemu_opt_get(opts
, "fsdriver") == NULL
||
3121 qemu_opt_get(opts
, "mount_tag") == NULL
) {
3122 error_report("Usage: -virtfs fsdriver,mount_tag=tag");
3125 fsdev
= qemu_opts_create(qemu_find_opts("fsdev"),
3126 qemu_opts_id(opts
) ?:
3127 qemu_opt_get(opts
, "mount_tag"),
3130 error_report("duplicate or invalid fsdev id: %s",
3131 qemu_opt_get(opts
, "mount_tag"));
3135 writeout
= qemu_opt_get(opts
, "writeout");
3137 #ifdef CONFIG_SYNC_FILE_RANGE
3138 qemu_opt_set(fsdev
, "writeout", writeout
, &error_abort
);
3140 error_report("writeout=immediate not supported "
3141 "on this platform");
3145 qemu_opt_set(fsdev
, "fsdriver",
3146 qemu_opt_get(opts
, "fsdriver"), &error_abort
);
3147 path
= qemu_opt_get(opts
, "path");
3149 qemu_opt_set(fsdev
, "path", path
, &error_abort
);
3151 security_model
= qemu_opt_get(opts
, "security_model");
3152 if (security_model
) {
3153 qemu_opt_set(fsdev
, "security_model", security_model
,
3156 socket
= qemu_opt_get(opts
, "socket");
3158 qemu_opt_set(fsdev
, "socket", socket
, &error_abort
);
3160 sock_fd
= qemu_opt_get(opts
, "sock_fd");
3162 qemu_opt_set(fsdev
, "sock_fd", sock_fd
, &error_abort
);
3165 qemu_opt_set_bool(fsdev
, "readonly",
3166 qemu_opt_get_bool(opts
, "readonly", 0),
3168 multidevs
= qemu_opt_get(opts
, "multidevs");
3170 qemu_opt_set(fsdev
, "multidevs", multidevs
, &error_abort
);
3172 device
= qemu_opts_create(qemu_find_opts("device"), NULL
, 0,
3174 qemu_opt_set(device
, "driver", "virtio-9p-pci", &error_abort
);
3175 qemu_opt_set(device
, "fsdev",
3176 qemu_opts_id(fsdev
), &error_abort
);
3177 qemu_opt_set(device
, "mount_tag",
3178 qemu_opt_get(opts
, "mount_tag"), &error_abort
);
3181 case QEMU_OPTION_serial
:
3182 add_device_config(DEV_SERIAL
, optarg
);
3184 if (strncmp(optarg
, "mon:", 4) == 0) {
3185 default_monitor
= 0;
3188 case QEMU_OPTION_watchdog
:
3190 error_report("only one watchdog option may be given");
3195 case QEMU_OPTION_action
:
3196 olist
= qemu_find_opts("action");
3197 if (!qemu_opts_parse_noisily(olist
, optarg
, false)) {
3201 case QEMU_OPTION_watchdog_action
:
3202 if (select_watchdog_action(optarg
) == -1) {
3203 error_report("unknown -watchdog-action parameter");
3207 case QEMU_OPTION_parallel
:
3208 add_device_config(DEV_PARALLEL
, optarg
);
3209 default_parallel
= 0;
3210 if (strncmp(optarg
, "mon:", 4) == 0) {
3211 default_monitor
= 0;
3214 case QEMU_OPTION_debugcon
:
3215 add_device_config(DEV_DEBUGCON
, optarg
);
3217 case QEMU_OPTION_loadvm
:
3220 case QEMU_OPTION_full_screen
:
3221 dpy
.has_full_screen
= true;
3222 dpy
.full_screen
= true;
3224 case QEMU_OPTION_alt_grab
:
3227 case QEMU_OPTION_ctrl_grab
:
3230 case QEMU_OPTION_no_quit
:
3231 dpy
.has_window_close
= true;
3232 dpy
.window_close
= false;
3233 warn_report("-no-quit is deprecated, please use "
3234 "-display ...,window-close=off instead.");
3236 case QEMU_OPTION_sdl
:
3238 dpy
.type
= DISPLAY_TYPE_SDL
;
3241 error_report("SDL support is disabled");
3244 case QEMU_OPTION_pidfile
:
3247 case QEMU_OPTION_win2k_hack
:
3248 win2k_install_hack
= 1;
3250 case QEMU_OPTION_acpitable
:
3251 opts
= qemu_opts_parse_noisily(qemu_find_opts("acpi"),
3256 acpi_table_add(opts
, &error_fatal
);
3258 case QEMU_OPTION_smbios
:
3259 opts
= qemu_opts_parse_noisily(qemu_find_opts("smbios"),
3264 smbios_entry_add(opts
, &error_fatal
);
3266 case QEMU_OPTION_fwcfg
:
3267 opts
= qemu_opts_parse_noisily(qemu_find_opts("fw_cfg"),
3273 case QEMU_OPTION_preconfig
:
3274 preconfig_requested
= true;
3276 case QEMU_OPTION_enable_kvm
:
3277 qdict_put_str(machine_opts_dict
, "accel", "kvm");
3280 case QEMU_OPTION_machine
:
3284 keyval_parse_into(machine_opts_dict
, optarg
, "type", &help
, &error_fatal
);
3286 machine_help_func(machine_opts_dict
);
3291 case QEMU_OPTION_accel
:
3292 accel_opts
= qemu_opts_parse_noisily(qemu_find_opts("accel"),
3294 optarg
= qemu_opt_get(accel_opts
, "accel");
3295 if (!optarg
|| is_help_option(optarg
)) {
3296 printf("Accelerators supported in QEMU binary:\n");
3297 GSList
*el
, *accel_list
= object_class_get_list(TYPE_ACCEL
,
3299 for (el
= accel_list
; el
; el
= el
->next
) {
3300 gchar
*typename
= g_strdup(object_class_get_name(
3301 OBJECT_CLASS(el
->data
)));
3302 /* omit qtest which is used for tests only */
3303 if (g_strcmp0(typename
, ACCEL_CLASS_NAME("qtest")) &&
3304 g_str_has_suffix(typename
, ACCEL_CLASS_SUFFIX
)) {
3305 gchar
**optname
= g_strsplit(typename
,
3306 ACCEL_CLASS_SUFFIX
, 0);
3307 printf("%s\n", optname
[0]);
3308 g_strfreev(optname
);
3312 g_slist_free(accel_list
);
3316 case QEMU_OPTION_usb
:
3317 qdict_put_str(machine_opts_dict
, "usb", "on");
3319 case QEMU_OPTION_usbdevice
:
3320 qdict_put_str(machine_opts_dict
, "usb", "on");
3321 add_device_config(DEV_USB
, optarg
);
3323 case QEMU_OPTION_device
:
3324 if (!qemu_opts_parse_noisily(qemu_find_opts("device"),
3329 case QEMU_OPTION_smp
:
3330 machine_parse_property_opt(qemu_find_opts("smp-opts"), "smp", optarg
, &error_fatal
);
3332 case QEMU_OPTION_vnc
:
3335 case QEMU_OPTION_no_acpi
:
3336 qdict_put_str(machine_opts_dict
, "acpi", "off");
3338 case QEMU_OPTION_no_hpet
:
3339 qdict_put_str(machine_opts_dict
, "hpet", "off");
3341 case QEMU_OPTION_no_reboot
:
3342 olist
= qemu_find_opts("action");
3343 qemu_opts_parse_noisily(olist
, "reboot=shutdown", false);
3345 case QEMU_OPTION_no_shutdown
:
3346 olist
= qemu_find_opts("action");
3347 qemu_opts_parse_noisily(olist
, "shutdown=pause", false);
3349 case QEMU_OPTION_uuid
:
3350 if (qemu_uuid_parse(optarg
, &qemu_uuid
) < 0) {
3351 error_report("failed to parse UUID string: wrong format");
3354 qemu_uuid_set
= true;
3356 case QEMU_OPTION_option_rom
:
3357 if (nb_option_roms
>= MAX_OPTION_ROMS
) {
3358 error_report("too many option ROMs");
3361 opts
= qemu_opts_parse_noisily(qemu_find_opts("option-rom"),
3366 option_rom
[nb_option_roms
].name
= qemu_opt_get(opts
, "romfile");
3367 option_rom
[nb_option_roms
].bootindex
=
3368 qemu_opt_get_number(opts
, "bootindex", -1);
3369 if (!option_rom
[nb_option_roms
].name
) {
3370 error_report("Option ROM file is not specified");
3375 case QEMU_OPTION_semihosting
:
3376 qemu_semihosting_enable();
3378 case QEMU_OPTION_semihosting_config
:
3379 if (qemu_semihosting_config_options(optarg
) != 0) {
3383 case QEMU_OPTION_name
:
3384 opts
= qemu_opts_parse_noisily(qemu_find_opts("name"),
3389 /* Capture guest name if -msg guest-name is used later */
3390 error_guest_name
= qemu_opt_get(opts
, "guest");
3392 case QEMU_OPTION_prom_env
:
3393 if (nb_prom_envs
>= MAX_PROM_ENVS
) {
3394 error_report("too many prom variables");
3397 prom_envs
[nb_prom_envs
] = optarg
;
3400 case QEMU_OPTION_old_param
:
3403 case QEMU_OPTION_rtc
:
3404 opts
= qemu_opts_parse_noisily(qemu_find_opts("rtc"), optarg
,
3410 case QEMU_OPTION_icount
:
3411 icount_opts
= qemu_opts_parse_noisily(qemu_find_opts("icount"),
3417 case QEMU_OPTION_incoming
:
3419 runstate_set(RUN_STATE_INMIGRATE
);
3423 case QEMU_OPTION_only_migratable
:
3424 only_migratable
= 1;
3426 case QEMU_OPTION_nodefaults
:
3429 case QEMU_OPTION_xen_domid
:
3430 if (!(xen_available())) {
3431 error_report("Option not supported for this target");
3434 xen_domid
= atoi(optarg
);
3436 case QEMU_OPTION_xen_attach
:
3437 if (!(xen_available())) {
3438 error_report("Option not supported for this target");
3441 xen_mode
= XEN_ATTACH
;
3443 case QEMU_OPTION_xen_domid_restrict
:
3444 if (!(xen_available())) {
3445 error_report("Option not supported for this target");
3448 xen_domid_restrict
= true;
3450 case QEMU_OPTION_trace
:
3451 trace_opt_parse(optarg
);
3453 case QEMU_OPTION_plugin
:
3454 qemu_plugin_opt_parse(optarg
, &plugin_list
);
3456 case QEMU_OPTION_readconfig
:
3457 qemu_read_config_file(optarg
, qemu_parse_config_group
, &error_fatal
);
3459 case QEMU_OPTION_spice
:
3460 olist
= qemu_find_opts_err("spice", NULL
);
3462 error_report("spice support is disabled");
3465 opts
= qemu_opts_parse_noisily(olist
, optarg
, false);
3471 case QEMU_OPTION_writeconfig
:
3474 warn_report("-writeconfig is deprecated and will go away without a replacement");
3475 if (strcmp(optarg
, "-") == 0) {
3478 fp
= fopen(optarg
, "w");
3480 error_report("open %s: %s", optarg
,
3485 qemu_config_write(fp
);
3491 case QEMU_OPTION_qtest
:
3492 qtest_chrdev
= optarg
;
3494 case QEMU_OPTION_qtest_log
:
3497 case QEMU_OPTION_sandbox
:
3498 olist
= qemu_find_opts("sandbox");
3500 #ifndef CONFIG_SECCOMP
3501 error_report("-sandbox support is not enabled "
3502 "in this QEMU binary");
3507 opts
= qemu_opts_parse_noisily(olist
, optarg
, true);
3512 case QEMU_OPTION_add_fd
:
3514 opts
= qemu_opts_parse_noisily(qemu_find_opts("add-fd"),
3520 error_report("File descriptor passing is disabled on this "
3525 case QEMU_OPTION_object
:
3526 object_option_parse(optarg
);
3528 case QEMU_OPTION_overcommit
:
3529 opts
= qemu_opts_parse_noisily(qemu_find_opts("overcommit"),
3534 enable_mlock
= qemu_opt_get_bool(opts
, "mem-lock", false);
3535 enable_cpu_pm
= qemu_opt_get_bool(opts
, "cpu-pm", false);
3537 case QEMU_OPTION_compat
:
3542 v
= qobject_input_visitor_new_str(optarg
, NULL
,
3545 visit_type_CompatPolicy(v
, NULL
, &opts
, &error_fatal
);
3546 QAPI_CLONE_MEMBERS(CompatPolicy
, &compat_policy
, opts
);
3548 qapi_free_CompatPolicy(opts
);
3552 case QEMU_OPTION_msg
:
3553 opts
= qemu_opts_parse_noisily(qemu_find_opts("msg"), optarg
,
3558 configure_msg(opts
);
3560 case QEMU_OPTION_dump_vmstate
:
3561 if (vmstate_dump_file
) {
3562 error_report("only one '-dump-vmstate' "
3563 "option may be given");
3566 vmstate_dump_file
= fopen(optarg
, "w");
3567 if (vmstate_dump_file
== NULL
) {
3568 error_report("open %s: %s", optarg
, strerror(errno
));
3572 case QEMU_OPTION_enable_sync_profile
:
3575 case QEMU_OPTION_nouserconfig
:
3576 /* Nothing to be parsed here. Especially, do not error out below. */
3579 if (os_parse_cmd_args(popt
->index
, optarg
)) {
3580 error_report("Option not supported in this build");
3587 * Clear error location left behind by the loop.
3588 * Best done right after the loop. Do not insert code here!
3592 qemu_validate_options(machine_opts_dict
);
3593 qemu_process_sugar_options();
3596 * These options affect everything else and should be processed
3597 * before daemonizing.
3599 qemu_process_early_options();
3601 qemu_process_help_options();
3602 qemu_maybe_daemonize(pid_file
);
3605 * The trace backend must be initialized after daemonizing.
3606 * trace_init_backends() will call st_init(), which will create the
3607 * trace thread in the parent, and also register st_flush_trace_buffer()
3608 * in atexit(). This function will force the parent to wait for the
3609 * writeout thread to finish, which will not occur, and the parent
3610 * process will be left in the host.
3612 if (!trace_init_backends()) {
3617 qemu_init_main_loop(&error_fatal
);
3620 user_register_global_props();
3621 replay_configure(icount_opts
);
3623 configure_rtc(qemu_find_opts_singleton("rtc"));
3625 qemu_create_machine(machine_opts_dict
);
3629 qemu_disable_default_devices();
3630 qemu_create_default_devices();
3631 qemu_create_early_backends();
3633 qemu_apply_legacy_machine_options(machine_opts_dict
);
3634 qemu_apply_machine_options(machine_opts_dict
);
3635 qobject_unref(machine_opts_dict
);
3636 phase_advance(PHASE_MACHINE_CREATED
);
3639 * Note: uses machine properties such as kernel-irqchip, must run
3640 * after qemu_apply_machine_options.
3642 configure_accelerators(argv
[0]);
3643 phase_advance(PHASE_ACCEL_CREATED
);
3646 * Beware, QOM objects created before this point miss global and
3647 * compat properties.
3649 * Global properties get set up by qdev_prop_register_global(),
3650 * called from user_register_global_props(), and certain option
3651 * desugaring. Also in CPU feature desugaring (buried in
3652 * parse_cpu_option()), which happens below this point, but may
3653 * only target the CPU type, which can only be created after
3654 * parse_cpu_option() returned the type.
3656 * Machine compat properties: object_set_machine_compat_props().
3657 * Accelerator compat props: object_set_accelerator_compat_props(),
3658 * called from do_configure_accelerator().
3661 machine_class
= MACHINE_GET_CLASS(current_machine
);
3662 if (!qtest_enabled() && machine_class
->deprecation_reason
) {
3663 error_report("Machine type '%s' is deprecated: %s",
3664 machine_class
->name
, machine_class
->deprecation_reason
);
3668 * Note: creates a QOM object, must run only after global and
3669 * compat properties have been set up.
3671 migration_object_init();
3673 qemu_create_late_backends();
3675 /* parse features once if machine provides default cpu_type */
3676 current_machine
->cpu_type
= machine_class
->default_cpu_type
;
3678 current_machine
->cpu_type
= parse_cpu_option(cpu_option
);
3680 /* NB: for machine none cpu_type could STILL be NULL here! */
3682 qemu_resolve_machine_memdev();
3683 parse_numa_opts(current_machine
);
3685 if (vmstate_dump_file
) {
3687 dump_vmstate_json_to_file(vmstate_dump_file
);
3691 if (!preconfig_requested
) {
3692 qmp_x_exit_preconfig(&error_fatal
);
3694 qemu_init_displays();
3695 accel_setup_post(current_machine
);