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 #define MAX_VIRTIO_CONSOLES 1
131 typedef struct BlockdevOptionsQueueEntry
{
132 BlockdevOptions
*bdo
;
134 QSIMPLEQ_ENTRY(BlockdevOptionsQueueEntry
) entry
;
135 } BlockdevOptionsQueueEntry
;
137 typedef QSIMPLEQ_HEAD(, BlockdevOptionsQueueEntry
) BlockdevOptionsQueue
;
139 typedef struct ObjectOption
{
141 QTAILQ_ENTRY(ObjectOption
) next
;
144 static const char *cpu_option
;
145 static const char *mem_path
;
146 static const char *incoming
;
147 static const char *loadvm
;
148 static const char *accelerators
;
149 static QDict
*machine_opts_dict
;
150 static QTAILQ_HEAD(, ObjectOption
) object_opts
= QTAILQ_HEAD_INITIALIZER(object_opts
);
151 static ram_addr_t maxram_size
;
152 static uint64_t ram_slots
;
153 static int display_remote
;
155 static bool preconfig_requested
;
156 static QemuPluginList plugin_list
= QTAILQ_HEAD_INITIALIZER(plugin_list
);
157 static BlockdevOptionsQueue bdo_queue
= QSIMPLEQ_HEAD_INITIALIZER(bdo_queue
);
158 static bool nographic
= false;
159 static int mem_prealloc
; /* force preallocation of physical target memory */
160 static ram_addr_t ram_size
;
161 static const char *vga_model
= NULL
;
162 static DisplayOptions dpy
;
163 static int num_serial_hds
;
164 static Chardev
**serial_hds
;
165 static const char *log_mask
;
166 static const char *log_file
;
167 static bool list_data_dirs
;
168 static const char *watchdog
;
169 static const char *qtest_chrdev
;
170 static const char *qtest_log
;
172 static int has_defaults
= 1;
173 static int default_serial
= 1;
174 static int default_parallel
= 1;
175 static int default_monitor
= 1;
176 static int default_floppy
= 1;
177 static int default_cdrom
= 1;
178 static int default_sdcard
= 1;
179 static int default_vga
= 1;
180 static int default_net
= 1;
186 { .driver
= "isa-serial", .flag
= &default_serial
},
187 { .driver
= "isa-parallel", .flag
= &default_parallel
},
188 { .driver
= "isa-fdc", .flag
= &default_floppy
},
189 { .driver
= "floppy", .flag
= &default_floppy
},
190 { .driver
= "ide-cd", .flag
= &default_cdrom
},
191 { .driver
= "ide-hd", .flag
= &default_cdrom
},
192 { .driver
= "scsi-cd", .flag
= &default_cdrom
},
193 { .driver
= "scsi-hd", .flag
= &default_cdrom
},
194 { .driver
= "VGA", .flag
= &default_vga
},
195 { .driver
= "isa-vga", .flag
= &default_vga
},
196 { .driver
= "cirrus-vga", .flag
= &default_vga
},
197 { .driver
= "isa-cirrus-vga", .flag
= &default_vga
},
198 { .driver
= "vmware-svga", .flag
= &default_vga
},
199 { .driver
= "qxl-vga", .flag
= &default_vga
},
200 { .driver
= "virtio-vga", .flag
= &default_vga
},
201 { .driver
= "ati-vga", .flag
= &default_vga
},
202 { .driver
= "vhost-user-vga", .flag
= &default_vga
},
205 static QemuOptsList qemu_rtc_opts
= {
207 .head
= QTAILQ_HEAD_INITIALIZER(qemu_rtc_opts
.head
),
212 .type
= QEMU_OPT_STRING
,
215 .type
= QEMU_OPT_STRING
,
218 .type
= QEMU_OPT_STRING
,
220 { /* end of list */ }
224 static QemuOptsList qemu_option_rom_opts
= {
225 .name
= "option-rom",
226 .implied_opt_name
= "romfile",
227 .head
= QTAILQ_HEAD_INITIALIZER(qemu_option_rom_opts
.head
),
231 .type
= QEMU_OPT_NUMBER
,
234 .type
= QEMU_OPT_STRING
,
236 { /* end of list */ }
240 static QemuOptsList qemu_accel_opts
= {
242 .implied_opt_name
= "accel",
243 .head
= QTAILQ_HEAD_INITIALIZER(qemu_accel_opts
.head
),
246 * no elements => accept any
247 * sanity checking will happen later
248 * when setting accelerator properties
254 static QemuOptsList qemu_boot_opts
= {
256 .implied_opt_name
= "order",
258 .head
= QTAILQ_HEAD_INITIALIZER(qemu_boot_opts
.head
),
262 .type
= QEMU_OPT_STRING
,
265 .type
= QEMU_OPT_STRING
,
268 .type
= QEMU_OPT_BOOL
,
271 .type
= QEMU_OPT_STRING
,
273 .name
= "splash-time",
274 .type
= QEMU_OPT_NUMBER
,
276 .name
= "reboot-timeout",
277 .type
= QEMU_OPT_NUMBER
,
280 .type
= QEMU_OPT_BOOL
,
286 static QemuOptsList qemu_add_fd_opts
= {
288 .head
= QTAILQ_HEAD_INITIALIZER(qemu_add_fd_opts
.head
),
292 .type
= QEMU_OPT_NUMBER
,
293 .help
= "file descriptor of which a duplicate is added to fd set",
296 .type
= QEMU_OPT_NUMBER
,
297 .help
= "ID of the fd set to add fd to",
300 .type
= QEMU_OPT_STRING
,
301 .help
= "free-form string used to describe fd",
303 { /* end of list */ }
307 static QemuOptsList qemu_object_opts
= {
309 .implied_opt_name
= "qom-type",
310 .head
= QTAILQ_HEAD_INITIALIZER(qemu_object_opts
.head
),
316 static QemuOptsList qemu_tpmdev_opts
= {
318 .implied_opt_name
= "type",
319 .head
= QTAILQ_HEAD_INITIALIZER(qemu_tpmdev_opts
.head
),
321 /* options are defined in the TPM backends */
322 { /* end of list */ }
326 static QemuOptsList qemu_overcommit_opts
= {
327 .name
= "overcommit",
328 .head
= QTAILQ_HEAD_INITIALIZER(qemu_overcommit_opts
.head
),
332 .type
= QEMU_OPT_BOOL
,
336 .type
= QEMU_OPT_BOOL
,
338 { /* end of list */ }
342 static QemuOptsList qemu_msg_opts
= {
344 .head
= QTAILQ_HEAD_INITIALIZER(qemu_msg_opts
.head
),
348 .type
= QEMU_OPT_BOOL
,
351 .name
= "guest-name",
352 .type
= QEMU_OPT_BOOL
,
353 .help
= "Prepends guest name for error messages but only if "
354 "-name guest is set otherwise option is ignored\n",
356 { /* end of list */ }
360 static QemuOptsList qemu_name_opts
= {
362 .implied_opt_name
= "guest",
364 .head
= QTAILQ_HEAD_INITIALIZER(qemu_name_opts
.head
),
368 .type
= QEMU_OPT_STRING
,
369 .help
= "Sets the name of the guest.\n"
370 "This name will be displayed in the SDL window caption.\n"
371 "The name will also be used for the VNC server",
374 .type
= QEMU_OPT_STRING
,
375 .help
= "Sets the name of the QEMU process, as shown in top etc",
377 .name
= "debug-threads",
378 .type
= QEMU_OPT_BOOL
,
379 .help
= "When enabled, name the individual threads; defaults off.\n"
380 "NOTE: The thread names are for debugging and not a\n"
383 { /* End of list */ }
387 static QemuOptsList qemu_mem_opts
= {
389 .implied_opt_name
= "size",
390 .head
= QTAILQ_HEAD_INITIALIZER(qemu_mem_opts
.head
),
395 .type
= QEMU_OPT_SIZE
,
399 .type
= QEMU_OPT_NUMBER
,
403 .type
= QEMU_OPT_SIZE
,
405 { /* end of list */ }
409 static QemuOptsList qemu_icount_opts
= {
411 .implied_opt_name
= "shift",
413 .head
= QTAILQ_HEAD_INITIALIZER(qemu_icount_opts
.head
),
417 .type
= QEMU_OPT_STRING
,
420 .type
= QEMU_OPT_BOOL
,
423 .type
= QEMU_OPT_BOOL
,
426 .type
= QEMU_OPT_STRING
,
429 .type
= QEMU_OPT_STRING
,
431 .name
= "rrsnapshot",
432 .type
= QEMU_OPT_STRING
,
434 { /* end of list */ }
438 static QemuOptsList qemu_fw_cfg_opts
= {
440 .implied_opt_name
= "name",
441 .head
= QTAILQ_HEAD_INITIALIZER(qemu_fw_cfg_opts
.head
),
445 .type
= QEMU_OPT_STRING
,
446 .help
= "Sets the fw_cfg name of the blob to be inserted",
449 .type
= QEMU_OPT_STRING
,
450 .help
= "Sets the name of the file from which "
451 "the fw_cfg blob will be loaded",
454 .type
= QEMU_OPT_STRING
,
455 .help
= "Sets content of the blob to be inserted from a string",
458 .type
= QEMU_OPT_STRING
,
459 .help
= "Sets id of the object generating the fw_cfg blob "
462 { /* end of list */ }
466 static QemuOptsList qemu_action_opts
= {
469 .head
= QTAILQ_HEAD_INITIALIZER(qemu_action_opts
.head
),
473 .type
= QEMU_OPT_STRING
,
476 .type
= QEMU_OPT_STRING
,
479 .type
= QEMU_OPT_STRING
,
482 .type
= QEMU_OPT_STRING
,
484 { /* end of list */ }
488 const char *qemu_get_vm_name(void)
493 static int default_driver_check(void *opaque
, QemuOpts
*opts
, Error
**errp
)
495 const char *driver
= qemu_opt_get(opts
, "driver");
500 for (i
= 0; i
< ARRAY_SIZE(default_list
); i
++) {
501 if (strcmp(default_list
[i
].driver
, driver
) != 0)
503 *(default_list
[i
].flag
) = 0;
508 static int parse_name(void *opaque
, QemuOpts
*opts
, Error
**errp
)
510 const char *proc_name
;
512 if (qemu_opt_get(opts
, "debug-threads")) {
513 qemu_thread_naming(qemu_opt_get_bool(opts
, "debug-threads", false));
515 qemu_name
= qemu_opt_get(opts
, "guest");
517 proc_name
= qemu_opt_get(opts
, "process");
519 os_set_proc_name(proc_name
);
525 bool defaults_enabled(void)
531 static int parse_add_fd(void *opaque
, QemuOpts
*opts
, Error
**errp
)
533 int fd
, dupfd
, flags
;
535 const char *fd_opaque
= NULL
;
538 fd
= qemu_opt_get_number(opts
, "fd", -1);
539 fdset_id
= qemu_opt_get_number(opts
, "set", -1);
540 fd_opaque
= qemu_opt_get(opts
, "opaque");
543 error_setg(errp
, "fd option is required and must be non-negative");
547 if (fd
<= STDERR_FILENO
) {
548 error_setg(errp
, "fd cannot be a standard I/O stream");
553 * All fds inherited across exec() necessarily have FD_CLOEXEC
554 * clear, while qemu sets FD_CLOEXEC on all other fds used internally.
556 flags
= fcntl(fd
, F_GETFD
);
557 if (flags
== -1 || (flags
& FD_CLOEXEC
)) {
558 error_setg(errp
, "fd is not valid or already in use");
563 error_setg(errp
, "set option is required and must be non-negative");
567 #ifdef F_DUPFD_CLOEXEC
568 dupfd
= fcntl(fd
, F_DUPFD_CLOEXEC
, 0);
572 qemu_set_cloexec(dupfd
);
576 error_setg(errp
, "error duplicating fd: %s", strerror(errno
));
580 /* add the duplicate fd, and optionally the opaque string, to the fd set */
581 fdinfo
= monitor_fdset_add_fd(dupfd
, true, fdset_id
, !!fd_opaque
, fd_opaque
,
588 static int cleanup_add_fd(void *opaque
, QemuOpts
*opts
, Error
**errp
)
592 fd
= qemu_opt_get_number(opts
, "fd", -1);
599 /***********************************************************/
600 /* QEMU Block devices */
602 #define HD_OPTS "media=disk"
603 #define CDROM_OPTS "media=cdrom"
605 #define PFLASH_OPTS ""
609 static int drive_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
611 BlockInterfaceType
*block_default_type
= opaque
;
613 return drive_new(opts
, *block_default_type
, errp
) == NULL
;
616 static int drive_enable_snapshot(void *opaque
, QemuOpts
*opts
, Error
**errp
)
618 if (qemu_opt_get(opts
, "snapshot") == NULL
) {
619 qemu_opt_set(opts
, "snapshot", "on", &error_abort
);
624 static void default_drive(int enable
, int snapshot
, BlockInterfaceType type
,
625 int index
, const char *optstr
)
630 if (!enable
|| drive_get_by_index(type
, index
)) {
634 opts
= drive_add(type
, index
, NULL
, optstr
);
636 drive_enable_snapshot(NULL
, opts
, NULL
);
639 dinfo
= drive_new(opts
, type
, &error_abort
);
640 dinfo
->is_default
= true;
644 static void configure_blockdev(BlockdevOptionsQueue
*bdo_queue
,
645 MachineClass
*machine_class
, int snapshot
)
648 * If the currently selected machine wishes to override the
649 * units-per-bus property of its default HBA interface type, do so
652 if (machine_class
->units_per_default_bus
) {
653 override_max_devs(machine_class
->block_default_type
,
654 machine_class
->units_per_default_bus
);
657 /* open the virtual block devices */
658 while (!QSIMPLEQ_EMPTY(bdo_queue
)) {
659 BlockdevOptionsQueueEntry
*bdo
= QSIMPLEQ_FIRST(bdo_queue
);
661 QSIMPLEQ_REMOVE_HEAD(bdo_queue
, entry
);
662 loc_push_restore(&bdo
->loc
);
663 qmp_blockdev_add(bdo
->bdo
, &error_fatal
);
665 qapi_free_BlockdevOptions(bdo
->bdo
);
669 qemu_opts_foreach(qemu_find_opts("drive"), drive_enable_snapshot
,
672 if (qemu_opts_foreach(qemu_find_opts("drive"), drive_init_func
,
673 &machine_class
->block_default_type
, &error_fatal
)) {
674 /* We printed help */
678 default_drive(default_cdrom
, snapshot
, machine_class
->block_default_type
, 2,
680 default_drive(default_floppy
, snapshot
, IF_FLOPPY
, 0, FD_OPTS
);
681 default_drive(default_sdcard
, snapshot
, IF_SD
, 0, SD_OPTS
);
685 static QemuOptsList qemu_smp_opts
= {
687 .implied_opt_name
= "cpus",
689 .head
= QTAILQ_HEAD_INITIALIZER(qemu_smp_opts
.head
),
693 .type
= QEMU_OPT_NUMBER
,
696 .type
= QEMU_OPT_NUMBER
,
699 .type
= QEMU_OPT_NUMBER
,
702 .type
= QEMU_OPT_NUMBER
,
705 .type
= QEMU_OPT_NUMBER
,
708 .type
= QEMU_OPT_NUMBER
,
714 static void realtime_init(void)
717 if (os_mlock() < 0) {
718 error_report("locking memory failed");
725 static void configure_msg(QemuOpts
*opts
)
727 message_with_timestamp
= qemu_opt_get_bool(opts
, "timestamp", false);
728 error_with_guestname
= qemu_opt_get_bool(opts
, "guest-name", false);
732 /***********************************************************/
735 static int usb_device_add(const char *devname
)
737 USBDevice
*dev
= NULL
;
739 if (!machine_usb(current_machine
)) {
743 dev
= usbdevice_create(devname
);
750 static int usb_parse(const char *cmdline
)
753 r
= usb_device_add(cmdline
);
755 error_report("could not add USB device '%s'", cmdline
);
760 /***********************************************************/
761 /* machine registration */
763 static MachineClass
*find_machine(const char *name
, GSList
*machines
)
767 for (el
= machines
; el
; el
= el
->next
) {
768 MachineClass
*mc
= el
->data
;
770 if (!strcmp(mc
->name
, name
) || !g_strcmp0(mc
->alias
, name
)) {
778 static MachineClass
*find_default_machine(GSList
*machines
)
781 MachineClass
*default_machineclass
= NULL
;
783 for (el
= machines
; el
; el
= el
->next
) {
784 MachineClass
*mc
= el
->data
;
786 if (mc
->is_default
) {
787 assert(default_machineclass
== NULL
&& "Multiple default machines");
788 default_machineclass
= mc
;
792 return default_machineclass
;
795 static void version(void)
797 printf("QEMU emulator version " QEMU_FULL_VERSION
"\n"
798 QEMU_COPYRIGHT
"\n");
801 static void help(int exitcode
)
804 printf("usage: %s [options] [disk_image]\n\n"
805 "'disk_image' is a raw hard disk image for IDE hard disk 0\n\n",
806 error_get_progname());
808 #define DEF(option, opt_arg, opt_enum, opt_help, arch_mask) \
809 if ((arch_mask) & arch_type) \
810 fputs(opt_help, stdout);
812 #define ARCHHEADING(text, arch_mask) \
813 if ((arch_mask) & arch_type) \
814 puts(stringify(text));
816 #define DEFHEADING(text) ARCHHEADING(text, QEMU_ARCH_ALL)
818 #include "qemu-options.def"
820 printf("\nDuring emulation, the following keys are useful:\n"
821 "ctrl-alt-f toggle full screen\n"
822 "ctrl-alt-n switch to virtual console 'n'\n"
823 "ctrl-alt toggle mouse and keyboard grab\n"
825 "When using -nographic, press 'ctrl-a h' to get some help.\n"
827 QEMU_HELP_BOTTOM
"\n");
832 #define HAS_ARG 0x0001
834 typedef struct QEMUOption
{
841 static const QEMUOption qemu_options
[] = {
842 { "h", 0, QEMU_OPTION_h
, QEMU_ARCH_ALL
},
844 #define DEF(option, opt_arg, opt_enum, opt_help, arch_mask) \
845 { option, opt_arg, opt_enum, arch_mask },
846 #define DEFHEADING(text)
847 #define ARCHHEADING(text, arch_mask)
849 #include "qemu-options.def"
853 typedef struct VGAInterfaceInfo
{
854 const char *opt_name
; /* option name */
855 const char *name
; /* human-readable name */
856 /* Class names indicating that support is available.
857 * If no class is specified, the interface is always available */
858 const char *class_names
[2];
861 static const VGAInterfaceInfo vga_interfaces
[VGA_TYPE_MAX
] = {
864 .name
= "no graphic card",
868 .name
= "standard VGA",
869 .class_names
= { "VGA", "isa-vga" },
872 .opt_name
= "cirrus",
873 .name
= "Cirrus VGA",
874 .class_names
= { "cirrus-vga", "isa-cirrus-vga" },
877 .opt_name
= "vmware",
878 .name
= "VMWare SVGA",
879 .class_names
= { "vmware-svga" },
882 .opt_name
= "virtio",
883 .name
= "Virtio VGA",
884 .class_names
= { "virtio-vga" },
889 .class_names
= { "qxl-vga" },
893 .name
= "TCX framebuffer",
894 .class_names
= { "sun-tcx" },
898 .name
= "CG3 framebuffer",
899 .class_names
= { "cgthree" },
903 .name
= "Xen paravirtualized framebuffer",
907 static bool vga_interface_available(VGAInterfaceType t
)
909 const VGAInterfaceInfo
*ti
= &vga_interfaces
[t
];
911 assert(t
< VGA_TYPE_MAX
);
912 return !ti
->class_names
[0] ||
913 module_object_class_by_name(ti
->class_names
[0]) ||
914 module_object_class_by_name(ti
->class_names
[1]);
918 get_default_vga_model(const MachineClass
*machine_class
)
920 if (machine_class
->default_display
) {
921 return machine_class
->default_display
;
922 } else if (vga_interface_available(VGA_CIRRUS
)) {
924 } else if (vga_interface_available(VGA_STD
)) {
931 static void select_vgahw(const MachineClass
*machine_class
, const char *p
)
936 if (g_str_equal(p
, "help")) {
937 const char *def
= get_default_vga_model(machine_class
);
939 for (t
= 0; t
< VGA_TYPE_MAX
; t
++) {
940 const VGAInterfaceInfo
*ti
= &vga_interfaces
[t
];
942 if (vga_interface_available(t
) && ti
->opt_name
) {
943 printf("%-20s %s%s\n", ti
->opt_name
, ti
->name
?: "",
944 g_str_equal(ti
->opt_name
, def
) ? " (default)" : "");
950 assert(vga_interface_type
== VGA_NONE
);
951 for (t
= 0; t
< VGA_TYPE_MAX
; t
++) {
952 const VGAInterfaceInfo
*ti
= &vga_interfaces
[t
];
953 if (ti
->opt_name
&& strstart(p
, ti
->opt_name
, &opts
)) {
954 if (!vga_interface_available(t
)) {
955 error_report("%s not available", ti
->name
);
958 vga_interface_type
= t
;
962 if (t
== VGA_TYPE_MAX
) {
964 error_report("unknown vga type: %s", p
);
970 if (strstart(opts
, ",retrace=", &nextopt
)) {
972 if (strstart(opts
, "dumb", &nextopt
))
973 vga_retrace_method
= VGA_RETRACE_DUMB
;
974 else if (strstart(opts
, "precise", &nextopt
))
975 vga_retrace_method
= VGA_RETRACE_PRECISE
;
976 else goto invalid_vga
;
977 } else goto invalid_vga
;
982 static void parse_display_qapi(const char *optarg
)
984 DisplayOptions
*opts
;
987 v
= qobject_input_visitor_new_str(optarg
, "type", &error_fatal
);
989 visit_type_DisplayOptions(v
, NULL
, &opts
, &error_fatal
);
990 QAPI_CLONE_MEMBERS(DisplayOptions
, &dpy
, opts
);
992 qapi_free_DisplayOptions(opts
);
996 DisplayOptions
*qmp_query_display_options(Error
**errp
)
998 return QAPI_CLONE(DisplayOptions
, &dpy
);
1001 static void parse_display(const char *p
)
1005 if (is_help_option(p
)) {
1006 qemu_display_help();
1010 if (strstart(p
, "sdl", &opts
)) {
1012 * sdl DisplayType needs hand-crafted parser instead of
1013 * parse_display_qapi() due to some options not in
1014 * DisplayOptions, specifically:
1015 * - ctrl_grab + alt_grab
1016 * Not clear yet what happens to them long-term. Should
1017 * replaced by something better or deprecated and dropped.
1019 #if defined(CONFIG_SDL)
1020 dpy
.type
= DISPLAY_TYPE_SDL
;
1022 const char *nextopt
;
1024 if (strstart(opts
, ",alt_grab=", &nextopt
)) {
1026 if (strstart(opts
, "on", &nextopt
)) {
1028 } else if (strstart(opts
, "off", &nextopt
)) {
1031 goto invalid_sdl_args
;
1033 } else if (strstart(opts
, ",ctrl_grab=", &nextopt
)) {
1035 if (strstart(opts
, "on", &nextopt
)) {
1037 } else if (strstart(opts
, "off", &nextopt
)) {
1040 goto invalid_sdl_args
;
1042 } else if (strstart(opts
, ",window_close=", &nextopt
) ||
1043 strstart(opts
, ",window-close=", &nextopt
)) {
1044 if (strstart(opts
, ",window_close=", NULL
)) {
1045 warn_report("window_close with an underscore is deprecated,"
1046 " please use window-close instead.");
1049 dpy
.has_window_close
= true;
1050 if (strstart(opts
, "on", &nextopt
)) {
1051 dpy
.window_close
= true;
1052 } else if (strstart(opts
, "off", &nextopt
)) {
1053 dpy
.window_close
= false;
1055 goto invalid_sdl_args
;
1057 } else if (strstart(opts
, ",show-cursor=", &nextopt
)) {
1059 dpy
.has_show_cursor
= true;
1060 if (strstart(opts
, "on", &nextopt
)) {
1061 dpy
.show_cursor
= true;
1062 } else if (strstart(opts
, "off", &nextopt
)) {
1063 dpy
.show_cursor
= false;
1065 goto invalid_sdl_args
;
1067 } else if (strstart(opts
, ",gl=", &nextopt
)) {
1070 if (strstart(opts
, "on", &nextopt
)) {
1071 dpy
.gl
= DISPLAYGL_MODE_ON
;
1072 } else if (strstart(opts
, "core", &nextopt
)) {
1073 dpy
.gl
= DISPLAYGL_MODE_CORE
;
1074 } else if (strstart(opts
, "es", &nextopt
)) {
1075 dpy
.gl
= DISPLAYGL_MODE_ES
;
1076 } else if (strstart(opts
, "off", &nextopt
)) {
1077 dpy
.gl
= DISPLAYGL_MODE_OFF
;
1079 goto invalid_sdl_args
;
1083 error_report("invalid SDL option string");
1089 error_report("SDL display supported is not available in this binary");
1092 } else if (strstart(p
, "vnc", &opts
)) {
1094 * vnc isn't a (local) DisplayType but a protocol for remote
1098 vnc_parse(opts
+ 1);
1100 error_report("VNC requires a display argument vnc=<display>");
1104 parse_display_qapi(p
);
1108 static inline bool nonempty_str(const char *str
)
1113 static int parse_fw_cfg(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1117 const char *name
, *file
, *str
, *gen_id
;
1118 FWCfgState
*fw_cfg
= (FWCfgState
*) opaque
;
1120 if (fw_cfg
== NULL
) {
1121 error_setg(errp
, "fw_cfg device not available");
1124 name
= qemu_opt_get(opts
, "name");
1125 file
= qemu_opt_get(opts
, "file");
1126 str
= qemu_opt_get(opts
, "string");
1127 gen_id
= qemu_opt_get(opts
, "gen_id");
1129 /* we need the name, and exactly one of: file, content string, gen_id */
1130 if (!nonempty_str(name
) ||
1131 nonempty_str(file
) + nonempty_str(str
) + nonempty_str(gen_id
) != 1) {
1132 error_setg(errp
, "name, plus exactly one of file,"
1133 " string and gen_id, are needed");
1136 if (strlen(name
) > FW_CFG_MAX_FILE_PATH
- 1) {
1137 error_setg(errp
, "name too long (max. %d char)",
1138 FW_CFG_MAX_FILE_PATH
- 1);
1141 if (nonempty_str(gen_id
)) {
1143 * In this particular case where the content is populated
1144 * internally, the "etc/" namespace protection is relaxed,
1145 * so do not emit a warning.
1147 } else if (strncmp(name
, "opt/", 4) != 0) {
1148 warn_report("externally provided fw_cfg item names "
1149 "should be prefixed with \"opt/\"");
1151 if (nonempty_str(str
)) {
1152 size
= strlen(str
); /* NUL terminator NOT included in fw_cfg blob */
1153 buf
= g_memdup(str
, size
);
1154 } else if (nonempty_str(gen_id
)) {
1155 if (!fw_cfg_add_from_generator(fw_cfg
, name
, gen_id
, errp
)) {
1161 if (!g_file_get_contents(file
, &buf
, &size
, &err
)) {
1162 error_setg(errp
, "can't load %s: %s", file
, err
->message
);
1167 /* For legacy, keep user files in a specific global order. */
1168 fw_cfg_set_order_override(fw_cfg
, FW_CFG_ORDER_OVERRIDE_USER
);
1169 fw_cfg_add_file(fw_cfg
, name
, buf
, size
);
1170 fw_cfg_reset_order_override(fw_cfg
);
1174 static int device_help_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1176 return qdev_device_help(opts
);
1179 static int device_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1183 dev
= qdev_device_add(opts
, errp
);
1184 if (!dev
&& *errp
) {
1185 error_report_err(*errp
);
1188 object_unref(OBJECT(dev
));
1193 static int chardev_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1195 Error
*local_err
= NULL
;
1197 if (!qemu_chr_new_from_opts(opts
, NULL
, &local_err
)) {
1199 error_propagate(errp
, local_err
);
1207 #ifdef CONFIG_VIRTFS
1208 static int fsdev_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1210 return qemu_fsdev_add(opts
, errp
);
1214 static int mon_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1216 return monitor_init_opts(opts
, errp
);
1219 static void monitor_parse(const char *optarg
, const char *mode
, bool pretty
)
1221 static int monitor_device_index
= 0;
1226 if (strstart(optarg
, "chardev:", &p
)) {
1227 snprintf(label
, sizeof(label
), "%s", p
);
1229 snprintf(label
, sizeof(label
), "compat_monitor%d",
1230 monitor_device_index
);
1231 opts
= qemu_chr_parse_compat(label
, optarg
, true);
1233 error_report("parse error: %s", optarg
);
1238 opts
= qemu_opts_create(qemu_find_opts("mon"), label
, 1, &error_fatal
);
1239 qemu_opt_set(opts
, "mode", mode
, &error_abort
);
1240 qemu_opt_set(opts
, "chardev", label
, &error_abort
);
1241 if (!strcmp(mode
, "control")) {
1242 qemu_opt_set_bool(opts
, "pretty", pretty
, &error_abort
);
1244 assert(pretty
== false);
1246 monitor_device_index
++;
1249 struct device_config
{
1251 DEV_USB
, /* -usbdevice */
1252 DEV_SERIAL
, /* -serial */
1253 DEV_PARALLEL
, /* -parallel */
1254 DEV_DEBUGCON
, /* -debugcon */
1255 DEV_GDB
, /* -gdb, -s */
1256 DEV_SCLP
, /* s390 sclp */
1258 const char *cmdline
;
1260 QTAILQ_ENTRY(device_config
) next
;
1263 static QTAILQ_HEAD(, device_config
) device_configs
=
1264 QTAILQ_HEAD_INITIALIZER(device_configs
);
1266 static void add_device_config(int type
, const char *cmdline
)
1268 struct device_config
*conf
;
1270 conf
= g_malloc0(sizeof(*conf
));
1272 conf
->cmdline
= cmdline
;
1273 loc_save(&conf
->loc
);
1274 QTAILQ_INSERT_TAIL(&device_configs
, conf
, next
);
1277 static int foreach_device_config(int type
, int (*func
)(const char *cmdline
))
1279 struct device_config
*conf
;
1282 QTAILQ_FOREACH(conf
, &device_configs
, next
) {
1283 if (conf
->type
!= type
)
1285 loc_push_restore(&conf
->loc
);
1286 rc
= func(conf
->cmdline
);
1287 loc_pop(&conf
->loc
);
1295 static void qemu_disable_default_devices(void)
1297 MachineClass
*machine_class
= MACHINE_GET_CLASS(current_machine
);
1299 qemu_opts_foreach(qemu_find_opts("device"),
1300 default_driver_check
, NULL
, NULL
);
1301 qemu_opts_foreach(qemu_find_opts("global"),
1302 default_driver_check
, NULL
, NULL
);
1304 if (!vga_model
&& !default_vga
) {
1305 vga_interface_type
= VGA_DEVICE
;
1307 if (!has_defaults
|| machine_class
->no_serial
) {
1310 if (!has_defaults
|| machine_class
->no_parallel
) {
1311 default_parallel
= 0;
1313 if (!has_defaults
|| machine_class
->no_floppy
) {
1316 if (!has_defaults
|| machine_class
->no_cdrom
) {
1319 if (!has_defaults
|| machine_class
->no_sdcard
) {
1322 if (!has_defaults
) {
1323 default_monitor
= 0;
1329 static void qemu_create_default_devices(void)
1331 MachineClass
*machine_class
= MACHINE_GET_CLASS(current_machine
);
1333 if (is_daemonized()) {
1334 /* According to documentation and historically, -nographic redirects
1335 * serial port, parallel port and monitor to stdio, which does not work
1336 * with -daemonize. We can redirect these to null instead, but since
1337 * -nographic is legacy, let's just error out.
1338 * We disallow -nographic only if all other ports are not redirected
1339 * explicitly, to not break existing legacy setups which uses
1340 * -nographic _and_ redirects all ports explicitly - this is valid
1341 * usage, -nographic is just a no-op in this case.
1344 && (default_parallel
|| default_serial
|| default_monitor
)) {
1345 error_report("-nographic cannot be used with -daemonize");
1351 if (default_parallel
)
1352 add_device_config(DEV_PARALLEL
, "null");
1353 if (default_serial
&& default_monitor
) {
1354 add_device_config(DEV_SERIAL
, "mon:stdio");
1357 add_device_config(DEV_SERIAL
, "stdio");
1358 if (default_monitor
)
1359 monitor_parse("stdio", "readline", false);
1363 add_device_config(DEV_SERIAL
, "vc:80Cx24C");
1364 if (default_parallel
)
1365 add_device_config(DEV_PARALLEL
, "vc:80Cx24C");
1366 if (default_monitor
)
1367 monitor_parse("vc:80Cx24C", "readline", false);
1371 QemuOptsList
*net
= qemu_find_opts("net");
1372 qemu_opts_parse(net
, "nic", true, &error_abort
);
1374 qemu_opts_parse(net
, "user", true, &error_abort
);
1378 #if defined(CONFIG_VNC)
1379 if (!QTAILQ_EMPTY(&(qemu_find_opts("vnc")->head
))) {
1383 if (dpy
.type
== DISPLAY_TYPE_DEFAULT
&& !display_remote
) {
1384 if (!qemu_display_find_default(&dpy
)) {
1385 dpy
.type
= DISPLAY_TYPE_NONE
;
1386 #if defined(CONFIG_VNC)
1387 vnc_parse("localhost:0,to=99,id=default");
1391 if (dpy
.type
== DISPLAY_TYPE_DEFAULT
) {
1392 dpy
.type
= DISPLAY_TYPE_NONE
;
1395 /* If no default VGA is requested, the default is "none". */
1397 vga_model
= get_default_vga_model(machine_class
);
1400 select_vgahw(machine_class
, vga_model
);
1404 static int serial_parse(const char *devname
)
1406 int index
= num_serial_hds
;
1409 if (strcmp(devname
, "none") == 0)
1411 snprintf(label
, sizeof(label
), "serial%d", index
);
1412 serial_hds
= g_renew(Chardev
*, serial_hds
, index
+ 1);
1414 serial_hds
[index
] = qemu_chr_new_mux_mon(label
, devname
, NULL
);
1415 if (!serial_hds
[index
]) {
1416 error_report("could not connect serial device"
1417 " to character backend '%s'", devname
);
1424 Chardev
*serial_hd(int i
)
1427 if (i
< num_serial_hds
) {
1428 return serial_hds
[i
];
1433 static int parallel_parse(const char *devname
)
1435 static int index
= 0;
1438 if (strcmp(devname
, "none") == 0)
1440 if (index
== MAX_PARALLEL_PORTS
) {
1441 error_report("too many parallel ports");
1444 snprintf(label
, sizeof(label
), "parallel%d", index
);
1445 parallel_hds
[index
] = qemu_chr_new_mux_mon(label
, devname
, NULL
);
1446 if (!parallel_hds
[index
]) {
1447 error_report("could not connect parallel device"
1448 " to character backend '%s'", devname
);
1455 static int debugcon_parse(const char *devname
)
1459 if (!qemu_chr_new_mux_mon("debugcon", devname
, NULL
)) {
1460 error_report("invalid character backend '%s'", devname
);
1463 opts
= qemu_opts_create(qemu_find_opts("device"), "debugcon", 1, NULL
);
1465 error_report("already have a debugcon device");
1468 qemu_opt_set(opts
, "driver", "isa-debugcon", &error_abort
);
1469 qemu_opt_set(opts
, "chardev", "debugcon", &error_abort
);
1473 static gint
machine_class_cmp(gconstpointer a
, gconstpointer b
)
1475 const MachineClass
*mc1
= a
, *mc2
= b
;
1478 if (mc1
->family
== NULL
) {
1479 if (mc2
->family
== NULL
) {
1480 /* Compare standalone machine types against each other; they sort
1481 * in increasing order.
1483 return strcmp(object_class_get_name(OBJECT_CLASS(mc1
)),
1484 object_class_get_name(OBJECT_CLASS(mc2
)));
1487 /* Standalone machine types sort after families. */
1491 if (mc2
->family
== NULL
) {
1492 /* Families sort before standalone machine types. */
1496 /* Families sort between each other alphabetically increasingly. */
1497 res
= strcmp(mc1
->family
, mc2
->family
);
1502 /* Within the same family, machine types sort in decreasing order. */
1503 return strcmp(object_class_get_name(OBJECT_CLASS(mc2
)),
1504 object_class_get_name(OBJECT_CLASS(mc1
)));
1507 static void machine_help_func(const QDict
*qdict
)
1509 GSList
*machines
, *el
;
1510 const char *type
= qdict_get_try_str(qdict
, "type");
1512 machines
= object_class_get_list(TYPE_MACHINE
, false);
1514 ObjectClass
*machine_class
= OBJECT_CLASS(find_machine(type
, machines
));
1515 if (machine_class
) {
1516 type_print_class_properties(object_class_get_name(machine_class
));
1521 printf("Supported machines are:\n");
1522 machines
= g_slist_sort(machines
, machine_class_cmp
);
1523 for (el
= machines
; el
; el
= el
->next
) {
1524 MachineClass
*mc
= el
->data
;
1526 printf("%-20s %s (alias of %s)\n", mc
->alias
, mc
->desc
, mc
->name
);
1528 printf("%-20s %s%s%s\n", mc
->name
, mc
->desc
,
1529 mc
->is_default
? " (default)" : "",
1530 mc
->deprecation_reason
? " (deprecated)" : "");
1535 machine_parse_property_opt(QemuOptsList
*opts_list
, const char *propname
,
1536 const char *arg
, Error
**errp
)
1542 prop
= keyval_parse(arg
, opts_list
->implied_opt_name
, &help
, errp
);
1544 qemu_opts_print_help(opts_list
, true);
1548 qdict_put(opts
, propname
, prop
);
1549 keyval_merge(machine_opts_dict
, opts
, errp
);
1550 qobject_unref(opts
);
1553 static const char *pid_file
;
1554 static Notifier qemu_unlink_pidfile_notifier
;
1556 static void qemu_unlink_pidfile(Notifier
*n
, void *data
)
1563 static const QEMUOption
*lookup_opt(int argc
, char **argv
,
1564 const char **poptarg
, int *poptind
)
1566 const QEMUOption
*popt
;
1567 int optind
= *poptind
;
1568 char *r
= argv
[optind
];
1571 loc_set_cmdline(argv
, optind
, 1);
1573 /* Treat --foo the same as -foo. */
1576 popt
= qemu_options
;
1579 error_report("invalid option");
1582 if (!strcmp(popt
->name
, r
+ 1))
1586 if (popt
->flags
& HAS_ARG
) {
1587 if (optind
>= argc
) {
1588 error_report("requires an argument");
1591 optarg
= argv
[optind
++];
1592 loc_set_cmdline(argv
, optind
- 2, 2);
1603 static MachineClass
*select_machine(QDict
*qdict
, Error
**errp
)
1605 const char *optarg
= qdict_get_try_str(qdict
, "type");
1606 GSList
*machines
= object_class_get_list(TYPE_MACHINE
, false);
1607 MachineClass
*machine_class
;
1608 Error
*local_err
= NULL
;
1611 machine_class
= find_machine(optarg
, machines
);
1612 qdict_del(qdict
, "type");
1613 if (!machine_class
) {
1614 error_setg(&local_err
, "unsupported machine type");
1617 machine_class
= find_default_machine(machines
);
1618 if (!machine_class
) {
1619 error_setg(&local_err
, "No machine specified, and there is no default");
1623 g_slist_free(machines
);
1625 error_append_hint(&local_err
, "Use -machine help to list supported machines\n");
1626 error_propagate(errp
, local_err
);
1628 return machine_class
;
1631 static int object_parse_property_opt(Object
*obj
,
1632 const char *name
, const char *value
,
1633 const char *skip
, Error
**errp
)
1635 if (g_str_equal(name
, skip
)) {
1639 if (!object_property_parse(obj
, name
, value
, errp
)) {
1646 /* *Non*recursively replace underscores with dashes in QDict keys. */
1647 static void keyval_dashify(QDict
*qdict
, Error
**errp
)
1649 const QDictEntry
*ent
, *next
;
1652 for (ent
= qdict_first(qdict
); ent
; ent
= next
) {
1653 g_autofree
char *new_key
= NULL
;
1655 next
= qdict_next(qdict
, ent
);
1656 if (!strchr(ent
->key
, '_')) {
1659 new_key
= g_strdup(ent
->key
);
1660 for (p
= new_key
; *p
; p
++) {
1665 if (qdict_haskey(qdict
, new_key
)) {
1666 error_setg(errp
, "Conflict between '%s' and '%s'", ent
->key
, new_key
);
1669 qobject_ref(ent
->value
);
1670 qdict_put_obj(qdict
, new_key
, ent
->value
);
1671 qdict_del(qdict
, ent
->key
);
1675 static void qemu_apply_legacy_machine_options(QDict
*qdict
)
1679 keyval_dashify(qdict
, &error_fatal
);
1681 /* Legacy options do not correspond to MachineState properties. */
1682 value
= qdict_get_try_str(qdict
, "accel");
1684 accelerators
= g_strdup(value
);
1685 qdict_del(qdict
, "accel");
1688 value
= qdict_get_try_str(qdict
, "igd-passthru");
1690 object_register_sugar_prop(ACCEL_CLASS_NAME("xen"), "igd-passthru", value
,
1692 qdict_del(qdict
, "igd-passthru");
1695 value
= qdict_get_try_str(qdict
, "kvm-shadow-mem");
1697 object_register_sugar_prop(ACCEL_CLASS_NAME("kvm"), "kvm-shadow-mem", value
,
1699 qdict_del(qdict
, "kvm-shadow-mem");
1702 value
= qdict_get_try_str(qdict
, "kernel-irqchip");
1704 object_register_sugar_prop(ACCEL_CLASS_NAME("kvm"), "kernel-irqchip", value
,
1706 object_register_sugar_prop(ACCEL_CLASS_NAME("whpx"), "kernel-irqchip", value
,
1708 qdict_del(qdict
, "kernel-irqchip");
1712 static void object_option_foreach_add(bool (*type_opt_predicate
)(const char *))
1714 ObjectOption
*opt
, *next
;
1716 QTAILQ_FOREACH_SAFE(opt
, &object_opts
, next
, next
) {
1717 const char *type
= ObjectType_str(opt
->opts
->qom_type
);
1718 if (type_opt_predicate(type
)) {
1719 user_creatable_add_qapi(opt
->opts
, &error_fatal
);
1720 qapi_free_ObjectOptions(opt
->opts
);
1721 QTAILQ_REMOVE(&object_opts
, opt
, next
);
1727 static void object_option_add_visitor(Visitor
*v
)
1729 ObjectOption
*opt
= g_new0(ObjectOption
, 1);
1730 visit_type_ObjectOptions(v
, NULL
, &opt
->opts
, &error_fatal
);
1731 QTAILQ_INSERT_TAIL(&object_opts
, opt
, next
);
1734 static void object_option_parse(const char *optarg
)
1740 if (optarg
[0] == '{') {
1741 QObject
*obj
= qobject_from_json(optarg
, &error_fatal
);
1743 v
= qobject_input_visitor_new(obj
);
1746 opts
= qemu_opts_parse_noisily(qemu_find_opts("object"),
1752 type
= qemu_opt_get(opts
, "qom-type");
1754 error_setg(&error_fatal
, QERR_MISSING_PARAMETER
, "qom-type");
1756 if (user_creatable_print_help(type
, opts
)) {
1760 v
= opts_visitor_new(opts
);
1763 object_option_add_visitor(v
);
1768 * Initial object creation happens before all other
1769 * QEMU data types are created. The majority of objects
1770 * can be created at this point. The rng-egd object
1771 * cannot be created here, as it depends on the chardev
1774 static bool object_create_early(const char *type
)
1777 * Objects should not be made "delayed" without a reason. If you
1778 * add one, state the reason in a comment!
1781 /* Reason: property "chardev" */
1782 if (g_str_equal(type
, "rng-egd") ||
1783 g_str_equal(type
, "qtest")) {
1787 #if defined(CONFIG_VHOST_USER) && defined(CONFIG_LINUX)
1788 /* Reason: cryptodev-vhost-user property "chardev" */
1789 if (g_str_equal(type
, "cryptodev-vhost-user")) {
1794 /* Reason: vhost-user-blk-server property "node-name" */
1795 if (g_str_equal(type
, "vhost-user-blk-server")) {
1799 * Reason: filter-* property "netdev" etc.
1801 if (g_str_equal(type
, "filter-buffer") ||
1802 g_str_equal(type
, "filter-dump") ||
1803 g_str_equal(type
, "filter-mirror") ||
1804 g_str_equal(type
, "filter-redirector") ||
1805 g_str_equal(type
, "colo-compare") ||
1806 g_str_equal(type
, "filter-rewriter") ||
1807 g_str_equal(type
, "filter-replay")) {
1812 * Allocation of large amounts of memory may delay
1813 * chardev initialization for too long, and trigger timeouts
1814 * on software that waits for a monitor socket to be created
1817 if (g_str_has_prefix(type
, "memory-backend-")) {
1824 static void qemu_apply_machine_options(QDict
*qdict
)
1826 MachineClass
*machine_class
= MACHINE_GET_CLASS(current_machine
);
1827 const char *boot_order
= NULL
;
1828 const char *boot_once
= NULL
;
1831 object_set_properties_from_keyval(OBJECT(current_machine
), qdict
, false, &error_fatal
);
1832 current_machine
->ram_size
= ram_size
;
1833 current_machine
->maxram_size
= maxram_size
;
1834 current_machine
->ram_slots
= ram_slots
;
1836 opts
= qemu_opts_find(qemu_find_opts("boot-opts"), NULL
);
1838 boot_order
= qemu_opt_get(opts
, "order");
1840 validate_bootdevices(boot_order
, &error_fatal
);
1843 boot_once
= qemu_opt_get(opts
, "once");
1845 validate_bootdevices(boot_once
, &error_fatal
);
1848 boot_menu
= qemu_opt_get_bool(opts
, "menu", boot_menu
);
1849 boot_strict
= qemu_opt_get_bool(opts
, "strict", false);
1853 boot_order
= machine_class
->default_boot_order
;
1856 current_machine
->boot_order
= boot_order
;
1857 current_machine
->boot_once
= boot_once
;
1859 if (semihosting_enabled() && !semihosting_get_argc()) {
1860 /* fall back to the -kernel/-append */
1861 semihosting_arg_fallback(current_machine
->kernel_filename
, current_machine
->kernel_cmdline
);
1864 if (current_machine
->smp
.cpus
> 1) {
1865 Error
*blocker
= NULL
;
1866 error_setg(&blocker
, QERR_REPLAY_NOT_SUPPORTED
, "smp");
1867 replay_add_blocker(blocker
);
1871 static void qemu_create_early_backends(void)
1873 MachineClass
*machine_class
= MACHINE_GET_CLASS(current_machine
);
1874 #if defined(CONFIG_SDL)
1875 const bool use_sdl
= (dpy
.type
== DISPLAY_TYPE_SDL
);
1877 const bool use_sdl
= false;
1879 #if defined(CONFIG_GTK)
1880 const bool use_gtk
= (dpy
.type
== DISPLAY_TYPE_GTK
);
1882 const bool use_gtk
= false;
1885 if ((alt_grab
|| ctrl_grab
) && !use_sdl
) {
1886 error_report("-alt-grab and -ctrl-grab are only valid "
1887 "for SDL, ignoring option");
1889 if (dpy
.has_window_close
&& !use_gtk
&& !use_sdl
) {
1890 error_report("-no-quit is only valid for GTK and SDL, "
1894 qemu_display_early_init(&dpy
);
1895 qemu_console_early_init();
1897 if (dpy
.has_gl
&& dpy
.gl
!= DISPLAYGL_MODE_OFF
&& display_opengl
== 0) {
1898 #if defined(CONFIG_OPENGL)
1899 error_report("OpenGL is not supported by the display");
1901 error_report("OpenGL support is disabled");
1906 object_option_foreach_add(object_create_early
);
1908 /* spice needs the timers to be initialized by this point */
1909 /* spice must initialize before audio as it changes the default auiodev */
1910 /* spice must initialize before chardevs (for spicevmc and spiceport) */
1913 qemu_opts_foreach(qemu_find_opts("chardev"),
1914 chardev_init_func
, NULL
, &error_fatal
);
1916 #ifdef CONFIG_VIRTFS
1917 qemu_opts_foreach(qemu_find_opts("fsdev"),
1918 fsdev_init_func
, NULL
, &error_fatal
);
1922 * Note: we need to create audio and block backends before
1923 * setting machine properties, so they can be referred to.
1925 configure_blockdev(&bdo_queue
, machine_class
, snapshot
);
1926 audio_init_audiodevs();
1931 * The remainder of object creation happens after the
1932 * creation of chardev, fsdev, net clients and device data types.
1934 static bool object_create_late(const char *type
)
1936 return !object_create_early(type
);
1939 static void qemu_create_late_backends(void)
1942 qtest_server_init(qtest_chrdev
, qtest_log
, &error_fatal
);
1945 net_init_clients(&error_fatal
);
1947 object_option_foreach_add(object_create_late
);
1949 if (tpm_init() < 0) {
1953 qemu_opts_foreach(qemu_find_opts("mon"),
1954 mon_init_func
, NULL
, &error_fatal
);
1956 if (foreach_device_config(DEV_SERIAL
, serial_parse
) < 0)
1958 if (foreach_device_config(DEV_PARALLEL
, parallel_parse
) < 0)
1960 if (foreach_device_config(DEV_DEBUGCON
, debugcon_parse
) < 0)
1963 /* now chardevs have been created we may have semihosting to connect */
1964 qemu_semihosting_connect_chardevs();
1965 qemu_semihosting_console_init();
1968 static bool have_custom_ram_size(void)
1970 QemuOpts
*opts
= qemu_find_opts_singleton("memory");
1971 return !!qemu_opt_get_size(opts
, "size", 0);
1974 static void qemu_resolve_machine_memdev(void)
1976 if (current_machine
->ram_memdev_id
) {
1978 ram_addr_t backend_size
;
1980 backend
= object_resolve_path_type(current_machine
->ram_memdev_id
,
1981 TYPE_MEMORY_BACKEND
, NULL
);
1983 error_report("Memory backend '%s' not found",
1984 current_machine
->ram_memdev_id
);
1987 backend_size
= object_property_get_uint(backend
, "size", &error_abort
);
1988 if (have_custom_ram_size() && backend_size
!= ram_size
) {
1989 error_report("Size specified by -m option must match size of "
1990 "explicitly specified 'memory-backend' property");
1994 error_report("'-mem-path' can't be used together with"
1995 "'-machine memory-backend'");
1998 ram_size
= backend_size
;
2001 if (!xen_enabled()) {
2002 /* On 32-bit hosts, QEMU is limited by virtual address space */
2003 if (ram_size
> (2047 << 20) && HOST_LONG_BITS
== 32) {
2004 error_report("at most 2047 MB RAM can be simulated");
2010 static void set_memory_options(MachineClass
*mc
)
2013 const char *mem_str
;
2014 const ram_addr_t default_ram_size
= mc
->default_ram_size
;
2015 QemuOpts
*opts
= qemu_find_opts_singleton("memory");
2018 loc_push_none(&loc
);
2019 qemu_opts_loc_restore(opts
);
2022 mem_str
= qemu_opt_get(opts
, "size");
2025 error_report("missing 'size' option value");
2029 sz
= qemu_opt_get_size(opts
, "size", ram_size
);
2031 /* Fix up legacy suffix-less format */
2032 if (g_ascii_isdigit(mem_str
[strlen(mem_str
) - 1])) {
2033 uint64_t overflow_check
= sz
;
2036 if (sz
/ MiB
!= overflow_check
) {
2037 error_report("too large 'size' option value");
2043 /* backward compatibility behaviour for case "-m 0" */
2045 sz
= default_ram_size
;
2048 sz
= QEMU_ALIGN_UP(sz
, 8192);
2049 if (mc
->fixup_ram_size
) {
2050 sz
= mc
->fixup_ram_size(sz
);
2053 if (ram_size
!= sz
) {
2054 error_report("ram size too large");
2058 maxram_size
= ram_size
;
2060 if (qemu_opt_get(opts
, "maxmem")) {
2063 sz
= qemu_opt_get_size(opts
, "maxmem", 0);
2064 slots
= qemu_opt_get_number(opts
, "slots", 0);
2065 if (sz
< ram_size
) {
2066 error_report("invalid value of -m option maxmem: "
2067 "maximum memory size (0x%" PRIx64
") must be at least "
2068 "the initial memory size (0x" RAM_ADDR_FMT
")",
2071 } else if (slots
&& sz
== ram_size
) {
2072 error_report("invalid value of -m option maxmem: "
2073 "memory slots were specified but maximum memory size "
2074 "(0x%" PRIx64
") is equal to the initial memory size "
2075 "(0x" RAM_ADDR_FMT
")", sz
, ram_size
);
2081 } else if (qemu_opt_get(opts
, "slots")) {
2082 error_report("invalid -m option value: missing 'maxmem' option");
2089 static void qemu_create_machine(QDict
*qdict
)
2091 MachineClass
*machine_class
= select_machine(qdict
, &error_fatal
);
2092 object_set_machine_compat_props(machine_class
->compat_props
);
2094 set_memory_options(machine_class
);
2096 current_machine
= MACHINE(object_new_with_class(OBJECT_CLASS(machine_class
)));
2097 object_property_add_child(object_get_root(), "machine",
2098 OBJECT(current_machine
));
2099 object_property_add_child(container_get(OBJECT(current_machine
),
2101 "sysbus", OBJECT(sysbus_get_default()));
2103 if (machine_class
->minimum_page_bits
) {
2104 if (!set_preferred_target_page_bits(machine_class
->minimum_page_bits
)) {
2105 /* This would be a board error: specifying a minimum smaller than
2106 * a target's compile-time fixed setting.
2108 g_assert_not_reached();
2112 cpu_exec_init_all();
2115 if (machine_class
->hw_version
) {
2116 qemu_set_hw_version(machine_class
->hw_version
);
2120 * Get the default machine options from the machine if it is not already
2121 * specified either by the configuration file or by the command line.
2123 if (machine_class
->default_machine_opts
) {
2124 QDict
*default_opts
=
2125 keyval_parse(machine_class
->default_machine_opts
, NULL
, NULL
,
2127 object_set_properties_from_keyval(OBJECT(current_machine
), default_opts
,
2128 false, &error_abort
);
2129 qobject_unref(default_opts
);
2133 static int global_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2137 g
= g_malloc0(sizeof(*g
));
2138 g
->driver
= qemu_opt_get(opts
, "driver");
2139 g
->property
= qemu_opt_get(opts
, "property");
2140 g
->value
= qemu_opt_get(opts
, "value");
2141 qdev_prop_register_global(g
);
2146 * Return whether configuration group @group is stored in QemuOpts, or
2147 * recorded as one or more QDicts by qemu_record_config_group.
2149 static bool is_qemuopts_group(const char *group
)
2151 if (g_str_equal(group
, "object") ||
2152 g_str_equal(group
, "machine")) {
2158 static void qemu_record_config_group(const char *group
, QDict
*dict
,
2159 bool from_json
, Error
**errp
)
2161 if (g_str_equal(group
, "object")) {
2162 Visitor
*v
= qobject_input_visitor_new_keyval(QOBJECT(dict
));
2163 object_option_add_visitor(v
);
2165 } else if (g_str_equal(group
, "machine")) {
2167 * Cannot merge string-valued and type-safe dictionaries, so JSON
2168 * is not accepted yet for -M.
2171 keyval_merge(machine_opts_dict
, dict
, errp
);
2178 * Parse non-QemuOpts config file groups, pass the rest to
2179 * qemu_config_do_parse.
2181 static void qemu_parse_config_group(const char *group
, QDict
*qdict
,
2182 void *opaque
, Error
**errp
)
2185 if (is_qemuopts_group(group
)) {
2186 qemu_config_do_parse(group
, qdict
, opaque
, errp
);
2190 crumpled
= qdict_crumple(qdict
, errp
);
2194 if (qobject_type(crumpled
) != QTYPE_QDICT
) {
2195 assert(qobject_type(crumpled
) == QTYPE_QLIST
);
2196 error_setg(errp
, "Lists cannot be at top level of a configuration section");
2199 qemu_record_config_group(group
, qobject_to(QDict
, crumpled
), false, errp
);
2202 static void qemu_read_default_config_file(Error
**errp
)
2206 g_autofree
char *file
= get_relocated_path(CONFIG_QEMU_CONFDIR
"/qemu.conf");
2208 ret
= qemu_read_config_file(file
, qemu_parse_config_group
, errp
);
2210 if (ret
== -ENOENT
) {
2217 static void qemu_set_option(const char *str
, Error
**errp
)
2219 char group
[64], id
[64], arg
[64];
2224 rc
= sscanf(str
, "%63[^.].%63[^.].%63[^=]%n", group
, id
, arg
, &offset
);
2225 if (rc
< 3 || str
[offset
] != '=') {
2226 error_setg(errp
, "can't parse: \"%s\"", str
);
2230 if (!is_qemuopts_group(group
)) {
2231 error_setg(errp
, "-set is not supported with %s", group
);
2233 list
= qemu_find_opts_err(group
, errp
);
2235 opts
= qemu_opts_find(list
, id
);
2237 error_setg(errp
, "there is no %s \"%s\" defined", group
, id
);
2240 qemu_opt_set(opts
, arg
, str
+ offset
+ 1, errp
);
2245 static void user_register_global_props(void)
2247 qemu_opts_foreach(qemu_find_opts("global"),
2248 global_init_func
, NULL
, NULL
);
2251 static int do_configure_icount(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2253 icount_configure(opts
, errp
);
2257 static int accelerator_set_property(void *opaque
,
2258 const char *name
, const char *value
,
2261 return object_parse_property_opt(opaque
, name
, value
, "accel", errp
);
2264 static int do_configure_accelerator(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2266 bool *p_init_failed
= opaque
;
2267 const char *acc
= qemu_opt_get(opts
, "accel");
2268 AccelClass
*ac
= accel_find(acc
);
2271 bool qtest_with_kvm
;
2273 qtest_with_kvm
= g_str_equal(acc
, "kvm") && qtest_chrdev
!= NULL
;
2276 *p_init_failed
= true;
2277 if (!qtest_with_kvm
) {
2278 error_report("invalid accelerator %s", acc
);
2282 accel
= ACCEL(object_new_with_class(OBJECT_CLASS(ac
)));
2283 object_apply_compat_props(OBJECT(accel
));
2284 qemu_opt_foreach(opts
, accelerator_set_property
,
2288 ret
= accel_init_machine(accel
, current_machine
);
2290 *p_init_failed
= true;
2291 if (!qtest_with_kvm
|| ret
!= -ENOENT
) {
2292 error_report("failed to initialize %s: %s", acc
, strerror(-ret
));
2300 static void configure_accelerators(const char *progname
)
2302 bool init_failed
= false;
2304 qemu_opts_foreach(qemu_find_opts("icount"),
2305 do_configure_icount
, NULL
, &error_fatal
);
2307 if (QTAILQ_EMPTY(&qemu_accel_opts
.head
)) {
2308 char **accel_list
, **tmp
;
2310 if (accelerators
== NULL
) {
2311 /* Select the default accelerator */
2312 bool have_tcg
= accel_find("tcg");
2313 bool have_kvm
= accel_find("kvm");
2315 if (have_tcg
&& have_kvm
) {
2316 if (g_str_has_suffix(progname
, "kvm")) {
2317 /* If the program name ends with "kvm", we prefer KVM */
2318 accelerators
= "kvm:tcg";
2320 accelerators
= "tcg:kvm";
2322 } else if (have_kvm
) {
2323 accelerators
= "kvm";
2324 } else if (have_tcg
) {
2325 accelerators
= "tcg";
2327 error_report("No accelerator selected and"
2328 " no default accelerator available");
2332 accel_list
= g_strsplit(accelerators
, ":", 0);
2334 for (tmp
= accel_list
; *tmp
; tmp
++) {
2336 * Filter invalid accelerators here, to prevent obscenities
2337 * such as "-machine accel=tcg,,thread=single".
2339 if (accel_find(*tmp
)) {
2340 qemu_opts_parse_noisily(qemu_find_opts("accel"), *tmp
, true);
2343 error_report("invalid accelerator %s", *tmp
);
2346 g_strfreev(accel_list
);
2348 if (accelerators
!= NULL
) {
2349 error_report("The -accel and \"-machine accel=\" options are incompatible");
2354 if (!qemu_opts_foreach(qemu_find_opts("accel"),
2355 do_configure_accelerator
, &init_failed
, &error_fatal
)) {
2357 error_report("no accelerator found");
2362 if (init_failed
&& !qtest_chrdev
) {
2363 AccelClass
*ac
= ACCEL_GET_CLASS(current_accel());
2364 error_report("falling back to %s", ac
->name
);
2367 if (icount_enabled() && !tcg_enabled()) {
2368 error_report("-icount is not allowed with hardware virtualization");
2373 static void create_default_memdev(MachineState
*ms
, const char *path
)
2376 MachineClass
*mc
= MACHINE_GET_CLASS(ms
);
2378 obj
= object_new(path
? TYPE_MEMORY_BACKEND_FILE
: TYPE_MEMORY_BACKEND_RAM
);
2380 object_property_set_str(obj
, "mem-path", path
, &error_fatal
);
2382 object_property_set_int(obj
, "size", ms
->ram_size
, &error_fatal
);
2383 object_property_add_child(object_get_objects_root(), mc
->default_ram_id
,
2385 /* Ensure backend's memory region name is equal to mc->default_ram_id */
2386 object_property_set_bool(obj
, "x-use-canonical-path-for-ramblock-id",
2387 false, &error_fatal
);
2388 user_creatable_complete(USER_CREATABLE(obj
), &error_fatal
);
2390 object_property_set_str(OBJECT(ms
), "memory-backend", mc
->default_ram_id
,
2394 static void qemu_validate_options(const QDict
*machine_opts
)
2396 const char *kernel_filename
= qdict_get_try_str(machine_opts
, "kernel");
2397 const char *initrd_filename
= qdict_get_try_str(machine_opts
, "initrd");
2398 const char *kernel_cmdline
= qdict_get_try_str(machine_opts
, "append");
2400 if (kernel_filename
== NULL
) {
2401 if (kernel_cmdline
!= NULL
) {
2402 error_report("-append only allowed with -kernel option");
2406 if (initrd_filename
!= NULL
) {
2407 error_report("-initrd only allowed with -kernel option");
2412 if (loadvm
&& preconfig_requested
) {
2413 error_report("'preconfig' and 'loadvm' options are "
2414 "mutually exclusive");
2417 if (incoming
&& preconfig_requested
&& strcmp(incoming
, "defer") != 0) {
2418 error_report("'preconfig' supports '-incoming defer' only");
2422 #ifdef CONFIG_CURSES
2423 if (is_daemonized() && dpy
.type
== DISPLAY_TYPE_CURSES
) {
2424 error_report("curses display cannot be used with -daemonize");
2430 static void qemu_process_sugar_options(void)
2435 val
= g_strdup_printf("%d",
2436 (uint32_t) qemu_opt_get_number(qemu_find_opts_singleton("smp-opts"), "cpus", 1));
2437 object_register_sugar_prop("memory-backend", "prealloc-threads", val
,
2440 object_register_sugar_prop("memory-backend", "prealloc", "on", false);
2444 int i
= select_watchdog(watchdog
);
2446 exit (i
== 1 ? 1 : 0);
2450 /* -action processing */
2453 * Process all the -action parameters parsed from cmdline.
2455 static int process_runstate_actions(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2457 Error
*local_err
= NULL
;
2458 QDict
*qdict
= qemu_opts_to_qdict(opts
, NULL
);
2459 QObject
*ret
= NULL
;
2460 qmp_marshal_set_action(qdict
, &ret
, &local_err
);
2462 qobject_unref(qdict
);
2464 error_propagate(errp
, local_err
);
2470 static void qemu_process_early_options(void)
2472 #ifdef CONFIG_SECCOMP
2473 QemuOptsList
*olist
= qemu_find_opts_err("sandbox", NULL
);
2475 qemu_opts_foreach(olist
, parse_sandbox
, NULL
, &error_fatal
);
2479 qemu_opts_foreach(qemu_find_opts("name"),
2480 parse_name
, NULL
, &error_fatal
);
2482 if (qemu_opts_foreach(qemu_find_opts("action"),
2483 process_runstate_actions
, NULL
, &error_fatal
)) {
2488 qemu_opts_foreach(qemu_find_opts("add-fd"),
2489 parse_add_fd
, NULL
, &error_fatal
);
2491 qemu_opts_foreach(qemu_find_opts("add-fd"),
2492 cleanup_add_fd
, NULL
, &error_fatal
);
2495 /* Open the logfile at this point and set the log mask if necessary. */
2497 qemu_set_log_filename(log_file
, &error_fatal
);
2501 mask
= qemu_str_to_log_mask(log_mask
);
2503 qemu_print_log_usage(stdout
);
2511 qemu_add_default_firmwarepath();
2514 static void qemu_process_help_options(void)
2517 * Check for -cpu help and -device help before we call select_machine(),
2518 * which will return an error if the architecture has no default machine
2519 * type and the user did not specify one, so that the user doesn't need
2520 * to say '-cpu help -machine something'.
2522 if (cpu_option
&& is_help_option(cpu_option
)) {
2523 list_cpus(cpu_option
);
2527 if (qemu_opts_foreach(qemu_find_opts("device"),
2528 device_help_func
, NULL
, NULL
)) {
2532 /* -L help lists the data directories and exits. */
2533 if (list_data_dirs
) {
2534 qemu_list_data_dirs();
2539 static void qemu_maybe_daemonize(const char *pid_file
)
2544 rcu_disable_atfork();
2546 if (pid_file
&& !qemu_write_pidfile(pid_file
, &err
)) {
2547 error_reportf_err(err
, "cannot create PID file: ");
2551 qemu_unlink_pidfile_notifier
.notify
= qemu_unlink_pidfile
;
2552 qemu_add_exit_notifier(&qemu_unlink_pidfile_notifier
);
2555 static void qemu_init_displays(void)
2559 /* init local displays */
2560 ds
= init_displaystate();
2561 qemu_display_init(ds
, &dpy
);
2563 /* must be after terminal init, SDL library changes signal handlers */
2564 os_setup_signal_handling();
2566 /* init remote displays */
2568 qemu_opts_foreach(qemu_find_opts("vnc"),
2569 vnc_init_func
, NULL
, &error_fatal
);
2573 qemu_spice
.display_init();
2577 static void qemu_init_board(void)
2579 MachineClass
*machine_class
= MACHINE_GET_CLASS(current_machine
);
2581 if (machine_class
->default_ram_id
&& current_machine
->ram_size
&&
2582 numa_uses_legacy_mem() && !current_machine
->ram_memdev_id
) {
2583 create_default_memdev(current_machine
, mem_path
);
2586 /* process plugin before CPUs are created, but once -smp has been parsed */
2587 qemu_plugin_load_list(&plugin_list
, &error_fatal
);
2589 /* From here on we enter MACHINE_PHASE_INITIALIZED. */
2590 machine_run_board_init(current_machine
);
2592 drive_check_orphaned();
2596 if (hax_enabled()) {
2597 /* FIXME: why isn't cpu_synchronize_all_post_init enough? */
2602 static void qemu_create_cli_devices(void)
2606 qemu_opts_foreach(qemu_find_opts("fw_cfg"),
2607 parse_fw_cfg
, fw_cfg_find(), &error_fatal
);
2609 /* init USB devices */
2610 if (machine_usb(current_machine
)) {
2611 if (foreach_device_config(DEV_USB
, usb_parse
) < 0)
2615 /* init generic devices */
2616 rom_set_order_override(FW_CFG_ORDER_OVERRIDE_DEVICE
);
2617 qemu_opts_foreach(qemu_find_opts("device"),
2618 device_init_func
, NULL
, &error_fatal
);
2619 rom_reset_order_override();
2622 static void qemu_machine_creation_done(void)
2624 MachineState
*machine
= MACHINE(qdev_get_machine());
2626 /* Did we create any drives that we failed to create a device for? */
2627 drive_check_orphaned();
2629 /* Don't warn about the default network setup that you get if
2630 * no command line -net or -netdev options are specified. There
2631 * are two cases that we would otherwise complain about:
2632 * (1) board doesn't support a NIC but the implicit "-net nic"
2634 * (2) CONFIG_SLIRP not set, in which case the implicit "-net nic"
2635 * sets up a nic that isn't connected to anything.
2637 if (!default_net
&& (!qtest_enabled() || has_defaults
)) {
2638 net_check_clients();
2641 qdev_prop_check_globals();
2643 qdev_machine_creation_done();
2647 * Verify that Confidential Guest Support has actually been initialized
2649 assert(machine
->cgs
->ready
);
2652 if (foreach_device_config(DEV_GDB
, gdbserver_start
) < 0) {
2657 void qmp_x_exit_preconfig(Error
**errp
)
2659 if (phase_check(PHASE_MACHINE_INITIALIZED
)) {
2660 error_setg(errp
, "The command is permitted only before machine initialization");
2665 qemu_create_cli_devices();
2666 qemu_machine_creation_done();
2669 Error
*local_err
= NULL
;
2670 if (!load_snapshot(loadvm
, NULL
, false, NULL
, &local_err
)) {
2671 error_report_err(local_err
);
2676 if (replay_mode
!= REPLAY_MODE_NONE
) {
2677 replay_vmstate_init();
2681 Error
*local_err
= NULL
;
2682 if (strcmp(incoming
, "defer") != 0) {
2683 qmp_migrate_incoming(incoming
, &local_err
);
2685 error_reportf_err(local_err
, "-incoming %s: ", incoming
);
2689 } else if (autostart
) {
2694 #ifdef CONFIG_MODULES
2695 void qemu_load_module_for_opts(const char *group
)
2697 static bool spice_tried
;
2698 if (g_str_equal(group
, "spice") && !spice_tried
) {
2699 ui_module_load_one("spice-core");
2703 static bool iscsi_tried
;
2704 if (g_str_equal(group
, "iscsi") && !iscsi_tried
) {
2705 block_module_load_one("iscsi");
2711 void qemu_init(int argc
, char **argv
, char **envp
)
2714 QemuOpts
*icount_opts
= NULL
, *accel_opts
= NULL
;
2715 QemuOptsList
*olist
;
2718 MachineClass
*machine_class
;
2719 bool userconfig
= true;
2720 FILE *vmstate_dump_file
= NULL
;
2722 qemu_add_opts(&qemu_drive_opts
);
2723 qemu_add_drive_opts(&qemu_legacy_drive_opts
);
2724 qemu_add_drive_opts(&qemu_common_drive_opts
);
2725 qemu_add_drive_opts(&qemu_drive_opts
);
2726 qemu_add_drive_opts(&bdrv_runtime_opts
);
2727 qemu_add_opts(&qemu_chardev_opts
);
2728 qemu_add_opts(&qemu_device_opts
);
2729 qemu_add_opts(&qemu_netdev_opts
);
2730 qemu_add_opts(&qemu_nic_opts
);
2731 qemu_add_opts(&qemu_net_opts
);
2732 qemu_add_opts(&qemu_rtc_opts
);
2733 qemu_add_opts(&qemu_global_opts
);
2734 qemu_add_opts(&qemu_mon_opts
);
2735 qemu_add_opts(&qemu_trace_opts
);
2736 qemu_plugin_add_opts();
2737 qemu_add_opts(&qemu_option_rom_opts
);
2738 qemu_add_opts(&qemu_accel_opts
);
2739 qemu_add_opts(&qemu_mem_opts
);
2740 qemu_add_opts(&qemu_smp_opts
);
2741 qemu_add_opts(&qemu_boot_opts
);
2742 qemu_add_opts(&qemu_add_fd_opts
);
2743 qemu_add_opts(&qemu_object_opts
);
2744 qemu_add_opts(&qemu_tpmdev_opts
);
2745 qemu_add_opts(&qemu_overcommit_opts
);
2746 qemu_add_opts(&qemu_msg_opts
);
2747 qemu_add_opts(&qemu_name_opts
);
2748 qemu_add_opts(&qemu_numa_opts
);
2749 qemu_add_opts(&qemu_icount_opts
);
2750 qemu_add_opts(&qemu_semihosting_config_opts
);
2751 qemu_add_opts(&qemu_fw_cfg_opts
);
2752 qemu_add_opts(&qemu_action_opts
);
2753 module_call_init(MODULE_INIT_OPTS
);
2755 error_init(argv
[0]);
2756 qemu_init_exec_dir(argv
[0]);
2758 qemu_init_subsystems();
2760 /* first pass of option parsing */
2762 while (optind
< argc
) {
2763 if (argv
[optind
][0] != '-') {
2767 const QEMUOption
*popt
;
2769 popt
= lookup_opt(argc
, argv
, &optarg
, &optind
);
2770 switch (popt
->index
) {
2771 case QEMU_OPTION_nouserconfig
:
2778 machine_opts_dict
= qdict_new();
2780 qemu_read_default_config_file(&error_fatal
);
2783 /* second pass of option parsing */
2788 if (argv
[optind
][0] != '-') {
2789 loc_set_cmdline(argv
, optind
, 1);
2790 drive_add(IF_DEFAULT
, 0, argv
[optind
++], HD_OPTS
);
2792 const QEMUOption
*popt
;
2794 popt
= lookup_opt(argc
, argv
, &optarg
, &optind
);
2795 if (!(popt
->arch_mask
& arch_type
)) {
2796 error_report("Option not supported for this target");
2799 switch(popt
->index
) {
2800 case QEMU_OPTION_cpu
:
2801 /* hw initialization will check this */
2802 cpu_option
= optarg
;
2804 case QEMU_OPTION_hda
:
2805 case QEMU_OPTION_hdb
:
2806 case QEMU_OPTION_hdc
:
2807 case QEMU_OPTION_hdd
:
2808 drive_add(IF_DEFAULT
, popt
->index
- QEMU_OPTION_hda
, optarg
,
2811 case QEMU_OPTION_blockdev
:
2814 BlockdevOptionsQueueEntry
*bdo
;
2816 v
= qobject_input_visitor_new_str(optarg
, "driver",
2819 bdo
= g_new(BlockdevOptionsQueueEntry
, 1);
2820 visit_type_BlockdevOptions(v
, NULL
, &bdo
->bdo
,
2823 loc_save(&bdo
->loc
);
2824 QSIMPLEQ_INSERT_TAIL(&bdo_queue
, bdo
, entry
);
2827 case QEMU_OPTION_drive
:
2828 if (drive_def(optarg
) == NULL
) {
2832 case QEMU_OPTION_set
:
2833 qemu_set_option(optarg
, &error_fatal
);
2835 case QEMU_OPTION_global
:
2836 if (qemu_global_option(optarg
) != 0)
2839 case QEMU_OPTION_mtdblock
:
2840 drive_add(IF_MTD
, -1, optarg
, MTD_OPTS
);
2842 case QEMU_OPTION_sd
:
2843 drive_add(IF_SD
, -1, optarg
, SD_OPTS
);
2845 case QEMU_OPTION_pflash
:
2846 drive_add(IF_PFLASH
, -1, optarg
, PFLASH_OPTS
);
2848 case QEMU_OPTION_snapshot
:
2850 Error
*blocker
= NULL
;
2852 error_setg(&blocker
, QERR_REPLAY_NOT_SUPPORTED
,
2854 replay_add_blocker(blocker
);
2857 case QEMU_OPTION_numa
:
2858 opts
= qemu_opts_parse_noisily(qemu_find_opts("numa"),
2864 case QEMU_OPTION_display
:
2865 parse_display(optarg
);
2867 case QEMU_OPTION_nographic
:
2868 qdict_put_str(machine_opts_dict
, "graphics", "off");
2870 dpy
.type
= DISPLAY_TYPE_NONE
;
2872 case QEMU_OPTION_curses
:
2873 #ifdef CONFIG_CURSES
2874 dpy
.type
= DISPLAY_TYPE_CURSES
;
2876 error_report("curses or iconv support is disabled");
2880 case QEMU_OPTION_portrait
:
2881 graphic_rotate
= 90;
2883 case QEMU_OPTION_rotate
:
2884 graphic_rotate
= strtol(optarg
, (char **) &optarg
, 10);
2885 if (graphic_rotate
!= 0 && graphic_rotate
!= 90 &&
2886 graphic_rotate
!= 180 && graphic_rotate
!= 270) {
2887 error_report("only 90, 180, 270 deg rotation is available");
2891 case QEMU_OPTION_kernel
:
2892 qdict_put_str(machine_opts_dict
, "kernel", optarg
);
2894 case QEMU_OPTION_initrd
:
2895 qdict_put_str(machine_opts_dict
, "initrd", optarg
);
2897 case QEMU_OPTION_append
:
2898 qdict_put_str(machine_opts_dict
, "append", optarg
);
2900 case QEMU_OPTION_dtb
:
2901 qdict_put_str(machine_opts_dict
, "dtb", optarg
);
2903 case QEMU_OPTION_cdrom
:
2904 drive_add(IF_DEFAULT
, 2, optarg
, CDROM_OPTS
);
2906 case QEMU_OPTION_boot
:
2907 opts
= qemu_opts_parse_noisily(qemu_find_opts("boot-opts"),
2913 case QEMU_OPTION_fda
:
2914 case QEMU_OPTION_fdb
:
2915 drive_add(IF_FLOPPY
, popt
->index
- QEMU_OPTION_fda
,
2918 case QEMU_OPTION_no_fd_bootchk
:
2921 case QEMU_OPTION_netdev
:
2923 if (net_client_parse(qemu_find_opts("netdev"), optarg
) == -1) {
2927 case QEMU_OPTION_nic
:
2929 if (net_client_parse(qemu_find_opts("nic"), optarg
) == -1) {
2933 case QEMU_OPTION_net
:
2935 if (net_client_parse(qemu_find_opts("net"), optarg
) == -1) {
2939 #ifdef CONFIG_LIBISCSI
2940 case QEMU_OPTION_iscsi
:
2941 opts
= qemu_opts_parse_noisily(qemu_find_opts("iscsi"),
2948 case QEMU_OPTION_audio_help
:
2949 audio_legacy_help();
2952 case QEMU_OPTION_audiodev
:
2953 audio_parse_option(optarg
);
2955 case QEMU_OPTION_soundhw
:
2956 select_soundhw (optarg
);
2961 case QEMU_OPTION_version
:
2966 opts
= qemu_opts_parse_noisily(qemu_find_opts("memory"),
2973 case QEMU_OPTION_tpmdev
:
2974 if (tpm_config_parse(qemu_find_opts("tpmdev"), optarg
) < 0) {
2979 case QEMU_OPTION_mempath
:
2982 case QEMU_OPTION_mem_prealloc
:
2991 case QEMU_OPTION_DFILTER
:
2992 qemu_set_dfilter_ranges(optarg
, &error_fatal
);
2994 case QEMU_OPTION_seed
:
2995 qemu_guest_random_seed_main(optarg
, &error_fatal
);
2998 add_device_config(DEV_GDB
, "tcp::" DEFAULT_GDBSTUB_PORT
);
3000 case QEMU_OPTION_gdb
:
3001 add_device_config(DEV_GDB
, optarg
);
3004 if (is_help_option(optarg
)) {
3005 list_data_dirs
= true;
3007 qemu_add_data_dir(g_strdup(optarg
));
3010 case QEMU_OPTION_bios
:
3011 qdict_put_str(machine_opts_dict
, "firmware", optarg
);
3013 case QEMU_OPTION_singlestep
:
3020 keyboard_layout
= optarg
;
3022 case QEMU_OPTION_vga
:
3031 w
= strtol(p
, (char **)&p
, 10);
3034 error_report("invalid resolution or depth");
3040 h
= strtol(p
, (char **)&p
, 10);
3045 depth
= strtol(p
, (char **)&p
, 10);
3046 if (depth
!= 1 && depth
!= 2 && depth
!= 4 &&
3047 depth
!= 8 && depth
!= 15 && depth
!= 16 &&
3048 depth
!= 24 && depth
!= 32)
3050 } else if (*p
== '\0') {
3051 depth
= graphic_depth
;
3058 graphic_depth
= depth
;
3061 case QEMU_OPTION_echr
:
3064 term_escape_char
= strtol(optarg
, &r
, 0);
3066 printf("Bad argument to echr\n");
3069 case QEMU_OPTION_monitor
:
3070 default_monitor
= 0;
3071 if (strncmp(optarg
, "none", 4)) {
3072 monitor_parse(optarg
, "readline", false);
3075 case QEMU_OPTION_qmp
:
3076 monitor_parse(optarg
, "control", false);
3077 default_monitor
= 0;
3079 case QEMU_OPTION_qmp_pretty
:
3080 monitor_parse(optarg
, "control", true);
3081 default_monitor
= 0;
3083 case QEMU_OPTION_mon
:
3084 opts
= qemu_opts_parse_noisily(qemu_find_opts("mon"), optarg
,
3089 default_monitor
= 0;
3091 case QEMU_OPTION_chardev
:
3092 opts
= qemu_opts_parse_noisily(qemu_find_opts("chardev"),
3098 case QEMU_OPTION_fsdev
:
3099 olist
= qemu_find_opts("fsdev");
3101 error_report("fsdev support is disabled");
3104 opts
= qemu_opts_parse_noisily(olist
, optarg
, true);
3109 case QEMU_OPTION_virtfs
: {
3112 const char *writeout
, *sock_fd
, *socket
, *path
, *security_model
,
3115 olist
= qemu_find_opts("virtfs");
3117 error_report("virtfs support is disabled");
3120 opts
= qemu_opts_parse_noisily(olist
, optarg
, true);
3125 if (qemu_opt_get(opts
, "fsdriver") == NULL
||
3126 qemu_opt_get(opts
, "mount_tag") == NULL
) {
3127 error_report("Usage: -virtfs fsdriver,mount_tag=tag");
3130 fsdev
= qemu_opts_create(qemu_find_opts("fsdev"),
3131 qemu_opts_id(opts
) ?:
3132 qemu_opt_get(opts
, "mount_tag"),
3135 error_report("duplicate or invalid fsdev id: %s",
3136 qemu_opt_get(opts
, "mount_tag"));
3140 writeout
= qemu_opt_get(opts
, "writeout");
3142 #ifdef CONFIG_SYNC_FILE_RANGE
3143 qemu_opt_set(fsdev
, "writeout", writeout
, &error_abort
);
3145 error_report("writeout=immediate not supported "
3146 "on this platform");
3150 qemu_opt_set(fsdev
, "fsdriver",
3151 qemu_opt_get(opts
, "fsdriver"), &error_abort
);
3152 path
= qemu_opt_get(opts
, "path");
3154 qemu_opt_set(fsdev
, "path", path
, &error_abort
);
3156 security_model
= qemu_opt_get(opts
, "security_model");
3157 if (security_model
) {
3158 qemu_opt_set(fsdev
, "security_model", security_model
,
3161 socket
= qemu_opt_get(opts
, "socket");
3163 qemu_opt_set(fsdev
, "socket", socket
, &error_abort
);
3165 sock_fd
= qemu_opt_get(opts
, "sock_fd");
3167 qemu_opt_set(fsdev
, "sock_fd", sock_fd
, &error_abort
);
3170 qemu_opt_set_bool(fsdev
, "readonly",
3171 qemu_opt_get_bool(opts
, "readonly", 0),
3173 multidevs
= qemu_opt_get(opts
, "multidevs");
3175 qemu_opt_set(fsdev
, "multidevs", multidevs
, &error_abort
);
3177 device
= qemu_opts_create(qemu_find_opts("device"), NULL
, 0,
3179 qemu_opt_set(device
, "driver", "virtio-9p-pci", &error_abort
);
3180 qemu_opt_set(device
, "fsdev",
3181 qemu_opts_id(fsdev
), &error_abort
);
3182 qemu_opt_set(device
, "mount_tag",
3183 qemu_opt_get(opts
, "mount_tag"), &error_abort
);
3186 case QEMU_OPTION_serial
:
3187 add_device_config(DEV_SERIAL
, optarg
);
3189 if (strncmp(optarg
, "mon:", 4) == 0) {
3190 default_monitor
= 0;
3193 case QEMU_OPTION_watchdog
:
3195 error_report("only one watchdog option may be given");
3200 case QEMU_OPTION_action
:
3201 olist
= qemu_find_opts("action");
3202 if (!qemu_opts_parse_noisily(olist
, optarg
, false)) {
3206 case QEMU_OPTION_watchdog_action
:
3207 if (select_watchdog_action(optarg
) == -1) {
3208 error_report("unknown -watchdog-action parameter");
3212 case QEMU_OPTION_parallel
:
3213 add_device_config(DEV_PARALLEL
, optarg
);
3214 default_parallel
= 0;
3215 if (strncmp(optarg
, "mon:", 4) == 0) {
3216 default_monitor
= 0;
3219 case QEMU_OPTION_debugcon
:
3220 add_device_config(DEV_DEBUGCON
, optarg
);
3222 case QEMU_OPTION_loadvm
:
3225 case QEMU_OPTION_full_screen
:
3226 dpy
.has_full_screen
= true;
3227 dpy
.full_screen
= true;
3229 case QEMU_OPTION_alt_grab
:
3232 case QEMU_OPTION_ctrl_grab
:
3235 case QEMU_OPTION_no_quit
:
3236 dpy
.has_window_close
= true;
3237 dpy
.window_close
= false;
3238 warn_report("-no-quit is deprecated, please use "
3239 "-display ...,window-close=off instead.");
3241 case QEMU_OPTION_sdl
:
3243 dpy
.type
= DISPLAY_TYPE_SDL
;
3246 error_report("SDL support is disabled");
3249 case QEMU_OPTION_pidfile
:
3252 case QEMU_OPTION_win2k_hack
:
3253 win2k_install_hack
= 1;
3255 case QEMU_OPTION_acpitable
:
3256 opts
= qemu_opts_parse_noisily(qemu_find_opts("acpi"),
3261 acpi_table_add(opts
, &error_fatal
);
3263 case QEMU_OPTION_smbios
:
3264 opts
= qemu_opts_parse_noisily(qemu_find_opts("smbios"),
3269 smbios_entry_add(opts
, &error_fatal
);
3271 case QEMU_OPTION_fwcfg
:
3272 opts
= qemu_opts_parse_noisily(qemu_find_opts("fw_cfg"),
3278 case QEMU_OPTION_preconfig
:
3279 preconfig_requested
= true;
3281 case QEMU_OPTION_enable_kvm
:
3282 qdict_put_str(machine_opts_dict
, "accel", "kvm");
3285 case QEMU_OPTION_machine
:
3289 keyval_parse_into(machine_opts_dict
, optarg
, "type", &help
, &error_fatal
);
3291 machine_help_func(machine_opts_dict
);
3296 case QEMU_OPTION_accel
:
3297 accel_opts
= qemu_opts_parse_noisily(qemu_find_opts("accel"),
3299 optarg
= qemu_opt_get(accel_opts
, "accel");
3300 if (!optarg
|| is_help_option(optarg
)) {
3301 printf("Accelerators supported in QEMU binary:\n");
3302 GSList
*el
, *accel_list
= object_class_get_list(TYPE_ACCEL
,
3304 for (el
= accel_list
; el
; el
= el
->next
) {
3305 gchar
*typename
= g_strdup(object_class_get_name(
3306 OBJECT_CLASS(el
->data
)));
3307 /* omit qtest which is used for tests only */
3308 if (g_strcmp0(typename
, ACCEL_CLASS_NAME("qtest")) &&
3309 g_str_has_suffix(typename
, ACCEL_CLASS_SUFFIX
)) {
3310 gchar
**optname
= g_strsplit(typename
,
3311 ACCEL_CLASS_SUFFIX
, 0);
3312 printf("%s\n", optname
[0]);
3313 g_strfreev(optname
);
3317 g_slist_free(accel_list
);
3321 case QEMU_OPTION_usb
:
3322 qdict_put_str(machine_opts_dict
, "usb", "on");
3324 case QEMU_OPTION_usbdevice
:
3325 qdict_put_str(machine_opts_dict
, "usb", "on");
3326 add_device_config(DEV_USB
, optarg
);
3328 case QEMU_OPTION_device
:
3329 if (!qemu_opts_parse_noisily(qemu_find_opts("device"),
3334 case QEMU_OPTION_smp
:
3335 machine_parse_property_opt(qemu_find_opts("smp-opts"), "smp", optarg
, &error_fatal
);
3337 case QEMU_OPTION_vnc
:
3340 case QEMU_OPTION_no_acpi
:
3341 qdict_put_str(machine_opts_dict
, "acpi", "off");
3343 case QEMU_OPTION_no_hpet
:
3344 qdict_put_str(machine_opts_dict
, "hpet", "off");
3346 case QEMU_OPTION_no_reboot
:
3347 olist
= qemu_find_opts("action");
3348 qemu_opts_parse_noisily(olist
, "reboot=shutdown", false);
3350 case QEMU_OPTION_no_shutdown
:
3351 olist
= qemu_find_opts("action");
3352 qemu_opts_parse_noisily(olist
, "shutdown=pause", false);
3354 case QEMU_OPTION_uuid
:
3355 if (qemu_uuid_parse(optarg
, &qemu_uuid
) < 0) {
3356 error_report("failed to parse UUID string: wrong format");
3359 qemu_uuid_set
= true;
3361 case QEMU_OPTION_option_rom
:
3362 if (nb_option_roms
>= MAX_OPTION_ROMS
) {
3363 error_report("too many option ROMs");
3366 opts
= qemu_opts_parse_noisily(qemu_find_opts("option-rom"),
3371 option_rom
[nb_option_roms
].name
= qemu_opt_get(opts
, "romfile");
3372 option_rom
[nb_option_roms
].bootindex
=
3373 qemu_opt_get_number(opts
, "bootindex", -1);
3374 if (!option_rom
[nb_option_roms
].name
) {
3375 error_report("Option ROM file is not specified");
3380 case QEMU_OPTION_semihosting
:
3381 qemu_semihosting_enable();
3383 case QEMU_OPTION_semihosting_config
:
3384 if (qemu_semihosting_config_options(optarg
) != 0) {
3388 case QEMU_OPTION_name
:
3389 opts
= qemu_opts_parse_noisily(qemu_find_opts("name"),
3394 /* Capture guest name if -msg guest-name is used later */
3395 error_guest_name
= qemu_opt_get(opts
, "guest");
3397 case QEMU_OPTION_prom_env
:
3398 if (nb_prom_envs
>= MAX_PROM_ENVS
) {
3399 error_report("too many prom variables");
3402 prom_envs
[nb_prom_envs
] = optarg
;
3405 case QEMU_OPTION_old_param
:
3408 case QEMU_OPTION_rtc
:
3409 opts
= qemu_opts_parse_noisily(qemu_find_opts("rtc"), optarg
,
3415 case QEMU_OPTION_icount
:
3416 icount_opts
= qemu_opts_parse_noisily(qemu_find_opts("icount"),
3422 case QEMU_OPTION_incoming
:
3424 runstate_set(RUN_STATE_INMIGRATE
);
3428 case QEMU_OPTION_only_migratable
:
3429 only_migratable
= 1;
3431 case QEMU_OPTION_nodefaults
:
3434 case QEMU_OPTION_xen_domid
:
3435 if (!(xen_available())) {
3436 error_report("Option not supported for this target");
3439 xen_domid
= atoi(optarg
);
3441 case QEMU_OPTION_xen_attach
:
3442 if (!(xen_available())) {
3443 error_report("Option not supported for this target");
3446 xen_mode
= XEN_ATTACH
;
3448 case QEMU_OPTION_xen_domid_restrict
:
3449 if (!(xen_available())) {
3450 error_report("Option not supported for this target");
3453 xen_domid_restrict
= true;
3455 case QEMU_OPTION_trace
:
3456 trace_opt_parse(optarg
);
3458 case QEMU_OPTION_plugin
:
3459 qemu_plugin_opt_parse(optarg
, &plugin_list
);
3461 case QEMU_OPTION_readconfig
:
3462 qemu_read_config_file(optarg
, qemu_parse_config_group
, &error_fatal
);
3464 case QEMU_OPTION_spice
:
3465 olist
= qemu_find_opts_err("spice", NULL
);
3467 error_report("spice support is disabled");
3470 opts
= qemu_opts_parse_noisily(olist
, optarg
, false);
3476 case QEMU_OPTION_writeconfig
:
3479 warn_report("-writeconfig is deprecated and will go away without a replacement");
3480 if (strcmp(optarg
, "-") == 0) {
3483 fp
= fopen(optarg
, "w");
3485 error_report("open %s: %s", optarg
,
3490 qemu_config_write(fp
);
3496 case QEMU_OPTION_qtest
:
3497 qtest_chrdev
= optarg
;
3499 case QEMU_OPTION_qtest_log
:
3502 case QEMU_OPTION_sandbox
:
3503 olist
= qemu_find_opts("sandbox");
3505 #ifndef CONFIG_SECCOMP
3506 error_report("-sandbox support is not enabled "
3507 "in this QEMU binary");
3512 opts
= qemu_opts_parse_noisily(olist
, optarg
, true);
3517 case QEMU_OPTION_add_fd
:
3519 opts
= qemu_opts_parse_noisily(qemu_find_opts("add-fd"),
3525 error_report("File descriptor passing is disabled on this "
3530 case QEMU_OPTION_object
:
3531 object_option_parse(optarg
);
3533 case QEMU_OPTION_overcommit
:
3534 opts
= qemu_opts_parse_noisily(qemu_find_opts("overcommit"),
3539 enable_mlock
= qemu_opt_get_bool(opts
, "mem-lock", false);
3540 enable_cpu_pm
= qemu_opt_get_bool(opts
, "cpu-pm", false);
3542 case QEMU_OPTION_compat
:
3547 v
= qobject_input_visitor_new_str(optarg
, NULL
,
3550 visit_type_CompatPolicy(v
, NULL
, &opts
, &error_fatal
);
3551 QAPI_CLONE_MEMBERS(CompatPolicy
, &compat_policy
, opts
);
3553 qapi_free_CompatPolicy(opts
);
3557 case QEMU_OPTION_msg
:
3558 opts
= qemu_opts_parse_noisily(qemu_find_opts("msg"), optarg
,
3563 configure_msg(opts
);
3565 case QEMU_OPTION_dump_vmstate
:
3566 if (vmstate_dump_file
) {
3567 error_report("only one '-dump-vmstate' "
3568 "option may be given");
3571 vmstate_dump_file
= fopen(optarg
, "w");
3572 if (vmstate_dump_file
== NULL
) {
3573 error_report("open %s: %s", optarg
, strerror(errno
));
3577 case QEMU_OPTION_enable_sync_profile
:
3580 case QEMU_OPTION_nouserconfig
:
3581 /* Nothing to be parsed here. Especially, do not error out below. */
3584 if (os_parse_cmd_args(popt
->index
, optarg
)) {
3585 error_report("Option not supported in this build");
3592 * Clear error location left behind by the loop.
3593 * Best done right after the loop. Do not insert code here!
3597 qemu_validate_options(machine_opts_dict
);
3598 qemu_process_sugar_options();
3601 * These options affect everything else and should be processed
3602 * before daemonizing.
3604 qemu_process_early_options();
3606 qemu_process_help_options();
3607 qemu_maybe_daemonize(pid_file
);
3610 * The trace backend must be initialized after daemonizing.
3611 * trace_init_backends() will call st_init(), which will create the
3612 * trace thread in the parent, and also register st_flush_trace_buffer()
3613 * in atexit(). This function will force the parent to wait for the
3614 * writeout thread to finish, which will not occur, and the parent
3615 * process will be left in the host.
3617 if (!trace_init_backends()) {
3622 qemu_init_main_loop(&error_fatal
);
3625 user_register_global_props();
3626 replay_configure(icount_opts
);
3628 configure_rtc(qemu_find_opts_singleton("rtc"));
3630 qemu_create_machine(machine_opts_dict
);
3634 qemu_disable_default_devices();
3635 qemu_create_default_devices();
3636 qemu_create_early_backends();
3638 qemu_apply_legacy_machine_options(machine_opts_dict
);
3639 qemu_apply_machine_options(machine_opts_dict
);
3640 qobject_unref(machine_opts_dict
);
3641 phase_advance(PHASE_MACHINE_CREATED
);
3644 * Note: uses machine properties such as kernel-irqchip, must run
3645 * after qemu_apply_machine_options.
3647 configure_accelerators(argv
[0]);
3648 phase_advance(PHASE_ACCEL_CREATED
);
3651 * Beware, QOM objects created before this point miss global and
3652 * compat properties.
3654 * Global properties get set up by qdev_prop_register_global(),
3655 * called from user_register_global_props(), and certain option
3656 * desugaring. Also in CPU feature desugaring (buried in
3657 * parse_cpu_option()), which happens below this point, but may
3658 * only target the CPU type, which can only be created after
3659 * parse_cpu_option() returned the type.
3661 * Machine compat properties: object_set_machine_compat_props().
3662 * Accelerator compat props: object_set_accelerator_compat_props(),
3663 * called from do_configure_accelerator().
3666 machine_class
= MACHINE_GET_CLASS(current_machine
);
3667 if (!qtest_enabled() && machine_class
->deprecation_reason
) {
3668 error_report("Machine type '%s' is deprecated: %s",
3669 machine_class
->name
, machine_class
->deprecation_reason
);
3673 * Note: creates a QOM object, must run only after global and
3674 * compat properties have been set up.
3676 migration_object_init();
3678 qemu_create_late_backends();
3680 /* parse features once if machine provides default cpu_type */
3681 current_machine
->cpu_type
= machine_class
->default_cpu_type
;
3683 current_machine
->cpu_type
= parse_cpu_option(cpu_option
);
3685 /* NB: for machine none cpu_type could STILL be NULL here! */
3687 qemu_resolve_machine_memdev();
3688 parse_numa_opts(current_machine
);
3690 if (vmstate_dump_file
) {
3692 dump_vmstate_json_to_file(vmstate_dump_file
);
3696 if (!preconfig_requested
) {
3697 qmp_x_exit_preconfig(&error_fatal
);
3699 qemu_init_displays();
3700 accel_setup_post(current_machine
);