4 * Copyright (c) 2003-2008 Fabrice Bellard
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 #include "qemu/osdep.h"
26 #include "qemu-common.h"
27 #include "qemu/datadir.h"
28 #include "qemu/units.h"
29 #include "exec/cpu-common.h"
30 #include "hw/qdev-properties.h"
31 #include "qapi/compat-policy.h"
32 #include "qapi/error.h"
33 #include "qapi/qmp/qdict.h"
34 #include "qapi/qmp/qstring.h"
35 #include "qapi/qmp/qjson.h"
36 #include "qemu-version.h"
37 #include "qemu/cutils.h"
38 #include "qemu/help_option.h"
39 #include "qemu/uuid.h"
40 #include "sysemu/reset.h"
41 #include "sysemu/runstate.h"
42 #include "sysemu/runstate-action.h"
43 #include "sysemu/seccomp.h"
44 #include "sysemu/tcg.h"
45 #include "sysemu/xen.h"
47 #include "qemu/error-report.h"
48 #include "qemu/sockets.h"
49 #include "qemu/accel.h"
51 #include "hw/isa/isa.h"
52 #include "hw/scsi/scsi.h"
53 #include "hw/display/vga.h"
54 #include "sysemu/watchdog.h"
55 #include "hw/firmware/smbios.h"
56 #include "hw/acpi/acpi.h"
57 #include "hw/xen/xen.h"
58 #include "hw/loader.h"
59 #include "monitor/qdev.h"
61 #include "net/slirp.h"
62 #include "monitor/monitor.h"
63 #include "ui/console.h"
65 #include "sysemu/sysemu.h"
66 #include "sysemu/numa.h"
67 #include "sysemu/hostmem.h"
68 #include "exec/gdbstub.h"
69 #include "qemu/timer.h"
70 #include "chardev/char.h"
71 #include "qemu/bitmap.h"
73 #include "sysemu/blockdev.h"
74 #include "hw/block/block.h"
75 #include "hw/i386/x86.h"
76 #include "hw/i386/pc.h"
77 #include "migration/misc.h"
78 #include "migration/snapshot.h"
79 #include "sysemu/tpm.h"
80 #include "sysemu/dma.h"
81 #include "hw/audio/soundhw.h"
82 #include "audio/audio.h"
83 #include "sysemu/cpus.h"
84 #include "sysemu/cpu-timers.h"
85 #include "migration/colo.h"
86 #include "migration/postcopy-ram.h"
87 #include "sysemu/kvm.h"
88 #include "sysemu/hax.h"
89 #include "qapi/qobject-input-visitor.h"
90 #include "qemu/option.h"
91 #include "qemu/config-file.h"
92 #include "qemu/qemu-options.h"
93 #include "qemu/main-loop.h"
95 #include "fsdev/qemu-fsdev.h"
97 #include "sysemu/qtest.h"
99 #include "disas/disas.h"
102 #include "trace/control.h"
103 #include "qemu/plugin.h"
104 #include "qemu/queue.h"
105 #include "sysemu/arch_init.h"
106 #include "exec/confidential-guest-support.h"
108 #include "ui/qemu-spice.h"
109 #include "qapi/string-input-visitor.h"
110 #include "qapi/opts-visitor.h"
111 #include "qapi/clone-visitor.h"
112 #include "qom/object_interfaces.h"
113 #include "semihosting/semihost.h"
114 #include "crypto/init.h"
115 #include "sysemu/replay.h"
116 #include "qapi/qapi-events-run-state.h"
117 #include "qapi/qapi-visit-block-core.h"
118 #include "qapi/qapi-visit-compat.h"
119 #include "qapi/qapi-visit-ui.h"
120 #include "qapi/qapi-commands-block-core.h"
121 #include "qapi/qapi-commands-migration.h"
122 #include "qapi/qapi-commands-misc.h"
123 #include "qapi/qapi-visit-qom.h"
124 #include "qapi/qapi-commands-ui.h"
125 #include "qapi/qmp/qdict.h"
126 #include "qapi/qmp/qerror.h"
127 #include "sysemu/iothread.h"
128 #include "qemu/guest-random.h"
130 #include "config-host.h"
132 #define MAX_VIRTIO_CONSOLES 1
134 typedef struct BlockdevOptionsQueueEntry
{
135 BlockdevOptions
*bdo
;
137 QSIMPLEQ_ENTRY(BlockdevOptionsQueueEntry
) entry
;
138 } BlockdevOptionsQueueEntry
;
140 typedef QSIMPLEQ_HEAD(, BlockdevOptionsQueueEntry
) BlockdevOptionsQueue
;
142 typedef struct ObjectOption
{
144 QTAILQ_ENTRY(ObjectOption
) next
;
147 static const char *cpu_option
;
148 static const char *mem_path
;
149 static const char *incoming
;
150 static const char *loadvm
;
151 static const char *accelerators
;
152 static QDict
*machine_opts_dict
;
153 static QTAILQ_HEAD(, ObjectOption
) object_opts
= QTAILQ_HEAD_INITIALIZER(object_opts
);
154 static ram_addr_t maxram_size
;
155 static uint64_t ram_slots
;
156 static int display_remote
;
158 static bool preconfig_requested
;
159 static QemuPluginList plugin_list
= QTAILQ_HEAD_INITIALIZER(plugin_list
);
160 static BlockdevOptionsQueue bdo_queue
= QSIMPLEQ_HEAD_INITIALIZER(bdo_queue
);
161 static bool nographic
= false;
162 static int mem_prealloc
; /* force preallocation of physical target memory */
163 static ram_addr_t ram_size
;
164 static const char *vga_model
= NULL
;
165 static DisplayOptions dpy
;
166 static int num_serial_hds
;
167 static Chardev
**serial_hds
;
168 static const char *log_mask
;
169 static const char *log_file
;
170 static bool list_data_dirs
;
171 static const char *watchdog
;
172 static const char *qtest_chrdev
;
173 static const char *qtest_log
;
175 static int has_defaults
= 1;
176 static int default_serial
= 1;
177 static int default_parallel
= 1;
178 static int default_monitor
= 1;
179 static int default_floppy
= 1;
180 static int default_cdrom
= 1;
181 static int default_sdcard
= 1;
182 static int default_vga
= 1;
183 static int default_net
= 1;
189 { .driver
= "isa-serial", .flag
= &default_serial
},
190 { .driver
= "isa-parallel", .flag
= &default_parallel
},
191 { .driver
= "isa-fdc", .flag
= &default_floppy
},
192 { .driver
= "floppy", .flag
= &default_floppy
},
193 { .driver
= "ide-cd", .flag
= &default_cdrom
},
194 { .driver
= "ide-hd", .flag
= &default_cdrom
},
195 { .driver
= "scsi-cd", .flag
= &default_cdrom
},
196 { .driver
= "scsi-hd", .flag
= &default_cdrom
},
197 { .driver
= "VGA", .flag
= &default_vga
},
198 { .driver
= "isa-vga", .flag
= &default_vga
},
199 { .driver
= "cirrus-vga", .flag
= &default_vga
},
200 { .driver
= "isa-cirrus-vga", .flag
= &default_vga
},
201 { .driver
= "vmware-svga", .flag
= &default_vga
},
202 { .driver
= "qxl-vga", .flag
= &default_vga
},
203 { .driver
= "virtio-vga", .flag
= &default_vga
},
204 { .driver
= "ati-vga", .flag
= &default_vga
},
205 { .driver
= "vhost-user-vga", .flag
= &default_vga
},
206 { .driver
= "virtio-vga-gl", .flag
= &default_vga
},
209 static QemuOptsList qemu_rtc_opts
= {
211 .head
= QTAILQ_HEAD_INITIALIZER(qemu_rtc_opts
.head
),
216 .type
= QEMU_OPT_STRING
,
219 .type
= QEMU_OPT_STRING
,
222 .type
= QEMU_OPT_STRING
,
224 { /* end of list */ }
228 static QemuOptsList qemu_option_rom_opts
= {
229 .name
= "option-rom",
230 .implied_opt_name
= "romfile",
231 .head
= QTAILQ_HEAD_INITIALIZER(qemu_option_rom_opts
.head
),
235 .type
= QEMU_OPT_NUMBER
,
238 .type
= QEMU_OPT_STRING
,
240 { /* end of list */ }
244 static QemuOptsList qemu_accel_opts
= {
246 .implied_opt_name
= "accel",
247 .head
= QTAILQ_HEAD_INITIALIZER(qemu_accel_opts
.head
),
250 * no elements => accept any
251 * sanity checking will happen later
252 * when setting accelerator properties
258 static QemuOptsList qemu_boot_opts
= {
260 .implied_opt_name
= "order",
262 .head
= QTAILQ_HEAD_INITIALIZER(qemu_boot_opts
.head
),
266 .type
= QEMU_OPT_STRING
,
269 .type
= QEMU_OPT_STRING
,
272 .type
= QEMU_OPT_BOOL
,
275 .type
= QEMU_OPT_STRING
,
277 .name
= "splash-time",
278 .type
= QEMU_OPT_NUMBER
,
280 .name
= "reboot-timeout",
281 .type
= QEMU_OPT_NUMBER
,
284 .type
= QEMU_OPT_BOOL
,
290 static QemuOptsList qemu_add_fd_opts
= {
292 .head
= QTAILQ_HEAD_INITIALIZER(qemu_add_fd_opts
.head
),
296 .type
= QEMU_OPT_NUMBER
,
297 .help
= "file descriptor of which a duplicate is added to fd set",
300 .type
= QEMU_OPT_NUMBER
,
301 .help
= "ID of the fd set to add fd to",
304 .type
= QEMU_OPT_STRING
,
305 .help
= "free-form string used to describe fd",
307 { /* end of list */ }
311 static QemuOptsList qemu_object_opts
= {
313 .implied_opt_name
= "qom-type",
314 .head
= QTAILQ_HEAD_INITIALIZER(qemu_object_opts
.head
),
320 static QemuOptsList qemu_tpmdev_opts
= {
322 .implied_opt_name
= "type",
323 .head
= QTAILQ_HEAD_INITIALIZER(qemu_tpmdev_opts
.head
),
325 /* options are defined in the TPM backends */
326 { /* end of list */ }
330 static QemuOptsList qemu_overcommit_opts
= {
331 .name
= "overcommit",
332 .head
= QTAILQ_HEAD_INITIALIZER(qemu_overcommit_opts
.head
),
336 .type
= QEMU_OPT_BOOL
,
340 .type
= QEMU_OPT_BOOL
,
342 { /* end of list */ }
346 static QemuOptsList qemu_msg_opts
= {
348 .head
= QTAILQ_HEAD_INITIALIZER(qemu_msg_opts
.head
),
352 .type
= QEMU_OPT_BOOL
,
355 .name
= "guest-name",
356 .type
= QEMU_OPT_BOOL
,
357 .help
= "Prepends guest name for error messages but only if "
358 "-name guest is set otherwise option is ignored\n",
360 { /* end of list */ }
364 static QemuOptsList qemu_name_opts
= {
366 .implied_opt_name
= "guest",
368 .head
= QTAILQ_HEAD_INITIALIZER(qemu_name_opts
.head
),
372 .type
= QEMU_OPT_STRING
,
373 .help
= "Sets the name of the guest.\n"
374 "This name will be displayed in the SDL window caption.\n"
375 "The name will also be used for the VNC server",
378 .type
= QEMU_OPT_STRING
,
379 .help
= "Sets the name of the QEMU process, as shown in top etc",
381 .name
= "debug-threads",
382 .type
= QEMU_OPT_BOOL
,
383 .help
= "When enabled, name the individual threads; defaults off.\n"
384 "NOTE: The thread names are for debugging and not a\n"
387 { /* End of list */ }
391 static QemuOptsList qemu_mem_opts
= {
393 .implied_opt_name
= "size",
394 .head
= QTAILQ_HEAD_INITIALIZER(qemu_mem_opts
.head
),
399 .type
= QEMU_OPT_SIZE
,
403 .type
= QEMU_OPT_NUMBER
,
407 .type
= QEMU_OPT_SIZE
,
409 { /* end of list */ }
413 static QemuOptsList qemu_icount_opts
= {
415 .implied_opt_name
= "shift",
417 .head
= QTAILQ_HEAD_INITIALIZER(qemu_icount_opts
.head
),
421 .type
= QEMU_OPT_STRING
,
424 .type
= QEMU_OPT_BOOL
,
427 .type
= QEMU_OPT_BOOL
,
430 .type
= QEMU_OPT_STRING
,
433 .type
= QEMU_OPT_STRING
,
435 .name
= "rrsnapshot",
436 .type
= QEMU_OPT_STRING
,
438 { /* end of list */ }
442 static QemuOptsList qemu_fw_cfg_opts
= {
444 .implied_opt_name
= "name",
445 .head
= QTAILQ_HEAD_INITIALIZER(qemu_fw_cfg_opts
.head
),
449 .type
= QEMU_OPT_STRING
,
450 .help
= "Sets the fw_cfg name of the blob to be inserted",
453 .type
= QEMU_OPT_STRING
,
454 .help
= "Sets the name of the file from which "
455 "the fw_cfg blob will be loaded",
458 .type
= QEMU_OPT_STRING
,
459 .help
= "Sets content of the blob to be inserted from a string",
462 .type
= QEMU_OPT_STRING
,
463 .help
= "Sets id of the object generating the fw_cfg blob "
466 { /* end of list */ }
470 static QemuOptsList qemu_action_opts
= {
473 .head
= QTAILQ_HEAD_INITIALIZER(qemu_action_opts
.head
),
477 .type
= QEMU_OPT_STRING
,
480 .type
= QEMU_OPT_STRING
,
483 .type
= QEMU_OPT_STRING
,
486 .type
= QEMU_OPT_STRING
,
488 { /* end of list */ }
492 const char *qemu_get_vm_name(void)
497 static int default_driver_check(void *opaque
, QemuOpts
*opts
, Error
**errp
)
499 const char *driver
= qemu_opt_get(opts
, "driver");
504 for (i
= 0; i
< ARRAY_SIZE(default_list
); i
++) {
505 if (strcmp(default_list
[i
].driver
, driver
) != 0)
507 *(default_list
[i
].flag
) = 0;
512 static int parse_name(void *opaque
, QemuOpts
*opts
, Error
**errp
)
514 const char *proc_name
;
516 if (qemu_opt_get(opts
, "debug-threads")) {
517 qemu_thread_naming(qemu_opt_get_bool(opts
, "debug-threads", false));
519 qemu_name
= qemu_opt_get(opts
, "guest");
521 proc_name
= qemu_opt_get(opts
, "process");
523 os_set_proc_name(proc_name
);
529 bool defaults_enabled(void)
535 static int parse_add_fd(void *opaque
, QemuOpts
*opts
, Error
**errp
)
537 int fd
, dupfd
, flags
;
539 const char *fd_opaque
= NULL
;
542 fd
= qemu_opt_get_number(opts
, "fd", -1);
543 fdset_id
= qemu_opt_get_number(opts
, "set", -1);
544 fd_opaque
= qemu_opt_get(opts
, "opaque");
547 error_setg(errp
, "fd option is required and must be non-negative");
551 if (fd
<= STDERR_FILENO
) {
552 error_setg(errp
, "fd cannot be a standard I/O stream");
557 * All fds inherited across exec() necessarily have FD_CLOEXEC
558 * clear, while qemu sets FD_CLOEXEC on all other fds used internally.
560 flags
= fcntl(fd
, F_GETFD
);
561 if (flags
== -1 || (flags
& FD_CLOEXEC
)) {
562 error_setg(errp
, "fd is not valid or already in use");
567 error_setg(errp
, "set option is required and must be non-negative");
571 #ifdef F_DUPFD_CLOEXEC
572 dupfd
= fcntl(fd
, F_DUPFD_CLOEXEC
, 0);
576 qemu_set_cloexec(dupfd
);
580 error_setg(errp
, "error duplicating fd: %s", strerror(errno
));
584 /* add the duplicate fd, and optionally the opaque string, to the fd set */
585 fdinfo
= monitor_fdset_add_fd(dupfd
, true, fdset_id
, !!fd_opaque
, fd_opaque
,
592 static int cleanup_add_fd(void *opaque
, QemuOpts
*opts
, Error
**errp
)
596 fd
= qemu_opt_get_number(opts
, "fd", -1);
603 /***********************************************************/
604 /* QEMU Block devices */
606 #define HD_OPTS "media=disk"
607 #define CDROM_OPTS "media=cdrom"
609 #define PFLASH_OPTS ""
613 static int drive_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
615 BlockInterfaceType
*block_default_type
= opaque
;
617 return drive_new(opts
, *block_default_type
, errp
) == NULL
;
620 static int drive_enable_snapshot(void *opaque
, QemuOpts
*opts
, Error
**errp
)
622 if (qemu_opt_get(opts
, "snapshot") == NULL
) {
623 qemu_opt_set(opts
, "snapshot", "on", &error_abort
);
628 static void default_drive(int enable
, int snapshot
, BlockInterfaceType type
,
629 int index
, const char *optstr
)
634 if (!enable
|| drive_get_by_index(type
, index
)) {
638 opts
= drive_add(type
, index
, NULL
, optstr
);
640 drive_enable_snapshot(NULL
, opts
, NULL
);
643 dinfo
= drive_new(opts
, type
, &error_abort
);
644 dinfo
->is_default
= true;
648 static void configure_blockdev(BlockdevOptionsQueue
*bdo_queue
,
649 MachineClass
*machine_class
, int snapshot
)
652 * If the currently selected machine wishes to override the
653 * units-per-bus property of its default HBA interface type, do so
656 if (machine_class
->units_per_default_bus
) {
657 override_max_devs(machine_class
->block_default_type
,
658 machine_class
->units_per_default_bus
);
661 /* open the virtual block devices */
662 while (!QSIMPLEQ_EMPTY(bdo_queue
)) {
663 BlockdevOptionsQueueEntry
*bdo
= QSIMPLEQ_FIRST(bdo_queue
);
665 QSIMPLEQ_REMOVE_HEAD(bdo_queue
, entry
);
666 loc_push_restore(&bdo
->loc
);
667 qmp_blockdev_add(bdo
->bdo
, &error_fatal
);
669 qapi_free_BlockdevOptions(bdo
->bdo
);
673 qemu_opts_foreach(qemu_find_opts("drive"), drive_enable_snapshot
,
676 if (qemu_opts_foreach(qemu_find_opts("drive"), drive_init_func
,
677 &machine_class
->block_default_type
, &error_fatal
)) {
678 /* We printed help */
682 default_drive(default_cdrom
, snapshot
, machine_class
->block_default_type
, 2,
684 default_drive(default_floppy
, snapshot
, IF_FLOPPY
, 0, FD_OPTS
);
685 default_drive(default_sdcard
, snapshot
, IF_SD
, 0, SD_OPTS
);
689 static QemuOptsList qemu_smp_opts
= {
691 .implied_opt_name
= "cpus",
693 .head
= QTAILQ_HEAD_INITIALIZER(qemu_smp_opts
.head
),
697 .type
= QEMU_OPT_NUMBER
,
700 .type
= QEMU_OPT_NUMBER
,
703 .type
= QEMU_OPT_NUMBER
,
706 .type
= QEMU_OPT_NUMBER
,
709 .type
= QEMU_OPT_NUMBER
,
712 .type
= QEMU_OPT_NUMBER
,
718 static void realtime_init(void)
721 if (os_mlock() < 0) {
722 error_report("locking memory failed");
729 static void configure_msg(QemuOpts
*opts
)
731 message_with_timestamp
= qemu_opt_get_bool(opts
, "timestamp", false);
732 error_with_guestname
= qemu_opt_get_bool(opts
, "guest-name", false);
736 /***********************************************************/
739 static int usb_device_add(const char *devname
)
741 USBDevice
*dev
= NULL
;
743 if (!machine_usb(current_machine
)) {
747 dev
= usbdevice_create(devname
);
754 static int usb_parse(const char *cmdline
)
757 r
= usb_device_add(cmdline
);
759 error_report("could not add USB device '%s'", cmdline
);
764 /***********************************************************/
765 /* machine registration */
767 static MachineClass
*find_machine(const char *name
, GSList
*machines
)
771 for (el
= machines
; el
; el
= el
->next
) {
772 MachineClass
*mc
= el
->data
;
774 if (!strcmp(mc
->name
, name
) || !g_strcmp0(mc
->alias
, name
)) {
782 static MachineClass
*find_default_machine(GSList
*machines
)
785 MachineClass
*default_machineclass
= NULL
;
787 for (el
= machines
; el
; el
= el
->next
) {
788 MachineClass
*mc
= el
->data
;
790 if (mc
->is_default
) {
791 assert(default_machineclass
== NULL
&& "Multiple default machines");
792 default_machineclass
= mc
;
796 return default_machineclass
;
799 static void version(void)
801 printf("QEMU emulator version " QEMU_FULL_VERSION
"\n"
802 QEMU_COPYRIGHT
"\n");
805 static void help(int exitcode
)
808 printf("usage: %s [options] [disk_image]\n\n"
809 "'disk_image' is a raw hard disk image for IDE hard disk 0\n\n",
810 error_get_progname());
812 #define DEF(option, opt_arg, opt_enum, opt_help, arch_mask) \
813 if ((arch_mask) & arch_type) \
814 fputs(opt_help, stdout);
816 #define ARCHHEADING(text, arch_mask) \
817 if ((arch_mask) & arch_type) \
818 puts(stringify(text));
820 #define DEFHEADING(text) ARCHHEADING(text, QEMU_ARCH_ALL)
822 #include "qemu-options.def"
824 printf("\nDuring emulation, the following keys are useful:\n"
825 "ctrl-alt-f toggle full screen\n"
826 "ctrl-alt-n switch to virtual console 'n'\n"
827 "ctrl-alt toggle mouse and keyboard grab\n"
829 "When using -nographic, press 'ctrl-a h' to get some help.\n"
831 QEMU_HELP_BOTTOM
"\n");
836 #define HAS_ARG 0x0001
838 typedef struct QEMUOption
{
845 static const QEMUOption qemu_options
[] = {
846 { "h", 0, QEMU_OPTION_h
, QEMU_ARCH_ALL
},
848 #define DEF(option, opt_arg, opt_enum, opt_help, arch_mask) \
849 { option, opt_arg, opt_enum, arch_mask },
850 #define DEFHEADING(text)
851 #define ARCHHEADING(text, arch_mask)
853 #include "qemu-options.def"
857 typedef struct VGAInterfaceInfo
{
858 const char *opt_name
; /* option name */
859 const char *name
; /* human-readable name */
860 /* Class names indicating that support is available.
861 * If no class is specified, the interface is always available */
862 const char *class_names
[2];
865 static const VGAInterfaceInfo vga_interfaces
[VGA_TYPE_MAX
] = {
868 .name
= "no graphic card",
872 .name
= "standard VGA",
873 .class_names
= { "VGA", "isa-vga" },
876 .opt_name
= "cirrus",
877 .name
= "Cirrus VGA",
878 .class_names
= { "cirrus-vga", "isa-cirrus-vga" },
881 .opt_name
= "vmware",
882 .name
= "VMWare SVGA",
883 .class_names
= { "vmware-svga" },
886 .opt_name
= "virtio",
887 .name
= "Virtio VGA",
888 .class_names
= { "virtio-vga" },
893 .class_names
= { "qxl-vga" },
897 .name
= "TCX framebuffer",
898 .class_names
= { "sun-tcx" },
902 .name
= "CG3 framebuffer",
903 .class_names
= { "cgthree" },
907 .name
= "Xen paravirtualized framebuffer",
911 static bool vga_interface_available(VGAInterfaceType t
)
913 const VGAInterfaceInfo
*ti
= &vga_interfaces
[t
];
915 assert(t
< VGA_TYPE_MAX
);
916 return !ti
->class_names
[0] ||
917 module_object_class_by_name(ti
->class_names
[0]) ||
918 module_object_class_by_name(ti
->class_names
[1]);
922 get_default_vga_model(const MachineClass
*machine_class
)
924 if (machine_class
->default_display
) {
925 return machine_class
->default_display
;
926 } else if (vga_interface_available(VGA_CIRRUS
)) {
928 } else if (vga_interface_available(VGA_STD
)) {
935 static void select_vgahw(const MachineClass
*machine_class
, const char *p
)
940 if (g_str_equal(p
, "help")) {
941 const char *def
= get_default_vga_model(machine_class
);
943 for (t
= 0; t
< VGA_TYPE_MAX
; t
++) {
944 const VGAInterfaceInfo
*ti
= &vga_interfaces
[t
];
946 if (vga_interface_available(t
) && ti
->opt_name
) {
947 printf("%-20s %s%s\n", ti
->opt_name
, ti
->name
?: "",
948 g_str_equal(ti
->opt_name
, def
) ? " (default)" : "");
954 assert(vga_interface_type
== VGA_NONE
);
955 for (t
= 0; t
< VGA_TYPE_MAX
; t
++) {
956 const VGAInterfaceInfo
*ti
= &vga_interfaces
[t
];
957 if (ti
->opt_name
&& strstart(p
, ti
->opt_name
, &opts
)) {
958 if (!vga_interface_available(t
)) {
959 error_report("%s not available", ti
->name
);
962 vga_interface_type
= t
;
966 if (t
== VGA_TYPE_MAX
) {
968 error_report("unknown vga type: %s", p
);
974 if (strstart(opts
, ",retrace=", &nextopt
)) {
976 if (strstart(opts
, "dumb", &nextopt
))
977 vga_retrace_method
= VGA_RETRACE_DUMB
;
978 else if (strstart(opts
, "precise", &nextopt
))
979 vga_retrace_method
= VGA_RETRACE_PRECISE
;
980 else goto invalid_vga
;
981 } else goto invalid_vga
;
986 static void parse_display_qapi(const char *optarg
)
988 DisplayOptions
*opts
;
991 v
= qobject_input_visitor_new_str(optarg
, "type", &error_fatal
);
993 visit_type_DisplayOptions(v
, NULL
, &opts
, &error_fatal
);
994 QAPI_CLONE_MEMBERS(DisplayOptions
, &dpy
, opts
);
996 qapi_free_DisplayOptions(opts
);
1000 DisplayOptions
*qmp_query_display_options(Error
**errp
)
1002 return QAPI_CLONE(DisplayOptions
, &dpy
);
1005 static void parse_display(const char *p
)
1009 if (is_help_option(p
)) {
1010 qemu_display_help();
1014 if (strstart(p
, "sdl", &opts
)) {
1016 * sdl DisplayType needs hand-crafted parser instead of
1017 * parse_display_qapi() due to some options not in
1018 * DisplayOptions, specifically:
1019 * - ctrl_grab + alt_grab
1020 * They can't be moved into the QAPI since they use underscores,
1021 * thus they will get replaced by "grab-mod" in the long term
1023 #if defined(CONFIG_SDL)
1024 dpy
.type
= DISPLAY_TYPE_SDL
;
1026 const char *nextopt
;
1028 if (strstart(opts
, ",grab-mod=", &nextopt
)) {
1030 if (strstart(opts
, "lshift-lctrl-lalt", &nextopt
)) {
1032 } else if (strstart(opts
, "rctrl", &nextopt
)) {
1035 goto invalid_sdl_args
;
1037 } else if (strstart(opts
, ",alt_grab=", &nextopt
)) {
1039 if (strstart(opts
, "on", &nextopt
)) {
1041 } else if (strstart(opts
, "off", &nextopt
)) {
1044 goto invalid_sdl_args
;
1046 warn_report("alt_grab is deprecated, use grab-mod instead.");
1047 } else if (strstart(opts
, ",ctrl_grab=", &nextopt
)) {
1049 if (strstart(opts
, "on", &nextopt
)) {
1051 } else if (strstart(opts
, "off", &nextopt
)) {
1054 goto invalid_sdl_args
;
1056 warn_report("ctrl_grab is deprecated, use grab-mod instead.");
1057 } else if (strstart(opts
, ",window_close=", &nextopt
) ||
1058 strstart(opts
, ",window-close=", &nextopt
)) {
1059 if (strstart(opts
, ",window_close=", NULL
)) {
1060 warn_report("window_close with an underscore is deprecated,"
1061 " please use window-close instead.");
1064 dpy
.has_window_close
= true;
1065 if (strstart(opts
, "on", &nextopt
)) {
1066 dpy
.window_close
= true;
1067 } else if (strstart(opts
, "off", &nextopt
)) {
1068 dpy
.window_close
= false;
1070 goto invalid_sdl_args
;
1072 } else if (strstart(opts
, ",show-cursor=", &nextopt
)) {
1074 dpy
.has_show_cursor
= true;
1075 if (strstart(opts
, "on", &nextopt
)) {
1076 dpy
.show_cursor
= true;
1077 } else if (strstart(opts
, "off", &nextopt
)) {
1078 dpy
.show_cursor
= false;
1080 goto invalid_sdl_args
;
1082 } else if (strstart(opts
, ",gl=", &nextopt
)) {
1085 if (strstart(opts
, "on", &nextopt
)) {
1086 dpy
.gl
= DISPLAYGL_MODE_ON
;
1087 } else if (strstart(opts
, "core", &nextopt
)) {
1088 dpy
.gl
= DISPLAYGL_MODE_CORE
;
1089 } else if (strstart(opts
, "es", &nextopt
)) {
1090 dpy
.gl
= DISPLAYGL_MODE_ES
;
1091 } else if (strstart(opts
, "off", &nextopt
)) {
1092 dpy
.gl
= DISPLAYGL_MODE_OFF
;
1094 goto invalid_sdl_args
;
1098 error_report("invalid SDL option string");
1104 error_report("SDL display supported is not available in this binary");
1107 } else if (strstart(p
, "vnc", &opts
)) {
1109 * vnc isn't a (local) DisplayType but a protocol for remote
1113 vnc_parse(opts
+ 1);
1115 error_report("VNC requires a display argument vnc=<display>");
1119 parse_display_qapi(p
);
1123 static inline bool nonempty_str(const char *str
)
1128 static int parse_fw_cfg(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1132 const char *name
, *file
, *str
, *gen_id
;
1133 FWCfgState
*fw_cfg
= (FWCfgState
*) opaque
;
1135 if (fw_cfg
== NULL
) {
1136 error_setg(errp
, "fw_cfg device not available");
1139 name
= qemu_opt_get(opts
, "name");
1140 file
= qemu_opt_get(opts
, "file");
1141 str
= qemu_opt_get(opts
, "string");
1142 gen_id
= qemu_opt_get(opts
, "gen_id");
1144 /* we need the name, and exactly one of: file, content string, gen_id */
1145 if (!nonempty_str(name
) ||
1146 nonempty_str(file
) + nonempty_str(str
) + nonempty_str(gen_id
) != 1) {
1147 error_setg(errp
, "name, plus exactly one of file,"
1148 " string and gen_id, are needed");
1151 if (strlen(name
) > FW_CFG_MAX_FILE_PATH
- 1) {
1152 error_setg(errp
, "name too long (max. %d char)",
1153 FW_CFG_MAX_FILE_PATH
- 1);
1156 if (nonempty_str(gen_id
)) {
1158 * In this particular case where the content is populated
1159 * internally, the "etc/" namespace protection is relaxed,
1160 * so do not emit a warning.
1162 } else if (strncmp(name
, "opt/", 4) != 0) {
1163 warn_report("externally provided fw_cfg item names "
1164 "should be prefixed with \"opt/\"");
1166 if (nonempty_str(str
)) {
1167 size
= strlen(str
); /* NUL terminator NOT included in fw_cfg blob */
1168 buf
= g_memdup(str
, size
);
1169 } else if (nonempty_str(gen_id
)) {
1170 if (!fw_cfg_add_from_generator(fw_cfg
, name
, gen_id
, errp
)) {
1176 if (!g_file_get_contents(file
, &buf
, &size
, &err
)) {
1177 error_setg(errp
, "can't load %s: %s", file
, err
->message
);
1182 /* For legacy, keep user files in a specific global order. */
1183 fw_cfg_set_order_override(fw_cfg
, FW_CFG_ORDER_OVERRIDE_USER
);
1184 fw_cfg_add_file(fw_cfg
, name
, buf
, size
);
1185 fw_cfg_reset_order_override(fw_cfg
);
1189 static int device_help_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1191 return qdev_device_help(opts
);
1194 static int device_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1198 dev
= qdev_device_add(opts
, errp
);
1199 if (!dev
&& *errp
) {
1200 error_report_err(*errp
);
1203 object_unref(OBJECT(dev
));
1208 static int chardev_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1210 Error
*local_err
= NULL
;
1212 if (!qemu_chr_new_from_opts(opts
, NULL
, &local_err
)) {
1214 error_propagate(errp
, local_err
);
1222 #ifdef CONFIG_VIRTFS
1223 static int fsdev_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1225 return qemu_fsdev_add(opts
, errp
);
1229 static int mon_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1231 return monitor_init_opts(opts
, errp
);
1234 static void monitor_parse(const char *optarg
, const char *mode
, bool pretty
)
1236 static int monitor_device_index
= 0;
1241 if (strstart(optarg
, "chardev:", &p
)) {
1242 snprintf(label
, sizeof(label
), "%s", p
);
1244 snprintf(label
, sizeof(label
), "compat_monitor%d",
1245 monitor_device_index
);
1246 opts
= qemu_chr_parse_compat(label
, optarg
, true);
1248 error_report("parse error: %s", optarg
);
1253 opts
= qemu_opts_create(qemu_find_opts("mon"), label
, 1, &error_fatal
);
1254 qemu_opt_set(opts
, "mode", mode
, &error_abort
);
1255 qemu_opt_set(opts
, "chardev", label
, &error_abort
);
1256 if (!strcmp(mode
, "control")) {
1257 qemu_opt_set_bool(opts
, "pretty", pretty
, &error_abort
);
1259 assert(pretty
== false);
1261 monitor_device_index
++;
1264 struct device_config
{
1266 DEV_USB
, /* -usbdevice */
1267 DEV_SERIAL
, /* -serial */
1268 DEV_PARALLEL
, /* -parallel */
1269 DEV_DEBUGCON
, /* -debugcon */
1270 DEV_GDB
, /* -gdb, -s */
1271 DEV_SCLP
, /* s390 sclp */
1273 const char *cmdline
;
1275 QTAILQ_ENTRY(device_config
) next
;
1278 static QTAILQ_HEAD(, device_config
) device_configs
=
1279 QTAILQ_HEAD_INITIALIZER(device_configs
);
1281 static void add_device_config(int type
, const char *cmdline
)
1283 struct device_config
*conf
;
1285 conf
= g_malloc0(sizeof(*conf
));
1287 conf
->cmdline
= cmdline
;
1288 loc_save(&conf
->loc
);
1289 QTAILQ_INSERT_TAIL(&device_configs
, conf
, next
);
1292 static int foreach_device_config(int type
, int (*func
)(const char *cmdline
))
1294 struct device_config
*conf
;
1297 QTAILQ_FOREACH(conf
, &device_configs
, next
) {
1298 if (conf
->type
!= type
)
1300 loc_push_restore(&conf
->loc
);
1301 rc
= func(conf
->cmdline
);
1302 loc_pop(&conf
->loc
);
1310 static void qemu_disable_default_devices(void)
1312 MachineClass
*machine_class
= MACHINE_GET_CLASS(current_machine
);
1314 qemu_opts_foreach(qemu_find_opts("device"),
1315 default_driver_check
, NULL
, NULL
);
1316 qemu_opts_foreach(qemu_find_opts("global"),
1317 default_driver_check
, NULL
, NULL
);
1319 if (!vga_model
&& !default_vga
) {
1320 vga_interface_type
= VGA_DEVICE
;
1322 if (!has_defaults
|| machine_class
->no_serial
) {
1325 if (!has_defaults
|| machine_class
->no_parallel
) {
1326 default_parallel
= 0;
1328 if (!has_defaults
|| machine_class
->no_floppy
) {
1331 if (!has_defaults
|| machine_class
->no_cdrom
) {
1334 if (!has_defaults
|| machine_class
->no_sdcard
) {
1337 if (!has_defaults
) {
1338 default_monitor
= 0;
1344 static void qemu_create_default_devices(void)
1346 MachineClass
*machine_class
= MACHINE_GET_CLASS(current_machine
);
1348 if (is_daemonized()) {
1349 /* According to documentation and historically, -nographic redirects
1350 * serial port, parallel port and monitor to stdio, which does not work
1351 * with -daemonize. We can redirect these to null instead, but since
1352 * -nographic is legacy, let's just error out.
1353 * We disallow -nographic only if all other ports are not redirected
1354 * explicitly, to not break existing legacy setups which uses
1355 * -nographic _and_ redirects all ports explicitly - this is valid
1356 * usage, -nographic is just a no-op in this case.
1359 && (default_parallel
|| default_serial
|| default_monitor
)) {
1360 error_report("-nographic cannot be used with -daemonize");
1366 if (default_parallel
)
1367 add_device_config(DEV_PARALLEL
, "null");
1368 if (default_serial
&& default_monitor
) {
1369 add_device_config(DEV_SERIAL
, "mon:stdio");
1372 add_device_config(DEV_SERIAL
, "stdio");
1373 if (default_monitor
)
1374 monitor_parse("stdio", "readline", false);
1378 add_device_config(DEV_SERIAL
, "vc:80Cx24C");
1379 if (default_parallel
)
1380 add_device_config(DEV_PARALLEL
, "vc:80Cx24C");
1381 if (default_monitor
)
1382 monitor_parse("vc:80Cx24C", "readline", false);
1386 QemuOptsList
*net
= qemu_find_opts("net");
1387 qemu_opts_parse(net
, "nic", true, &error_abort
);
1389 qemu_opts_parse(net
, "user", true, &error_abort
);
1393 #if defined(CONFIG_VNC)
1394 if (!QTAILQ_EMPTY(&(qemu_find_opts("vnc")->head
))) {
1398 if (dpy
.type
== DISPLAY_TYPE_DEFAULT
&& !display_remote
) {
1399 if (!qemu_display_find_default(&dpy
)) {
1400 dpy
.type
= DISPLAY_TYPE_NONE
;
1401 #if defined(CONFIG_VNC)
1402 vnc_parse("localhost:0,to=99,id=default");
1406 if (dpy
.type
== DISPLAY_TYPE_DEFAULT
) {
1407 dpy
.type
= DISPLAY_TYPE_NONE
;
1410 /* If no default VGA is requested, the default is "none". */
1412 vga_model
= get_default_vga_model(machine_class
);
1415 select_vgahw(machine_class
, vga_model
);
1419 static int serial_parse(const char *devname
)
1421 int index
= num_serial_hds
;
1424 if (strcmp(devname
, "none") == 0)
1426 snprintf(label
, sizeof(label
), "serial%d", index
);
1427 serial_hds
= g_renew(Chardev
*, serial_hds
, index
+ 1);
1429 serial_hds
[index
] = qemu_chr_new_mux_mon(label
, devname
, NULL
);
1430 if (!serial_hds
[index
]) {
1431 error_report("could not connect serial device"
1432 " to character backend '%s'", devname
);
1439 Chardev
*serial_hd(int i
)
1442 if (i
< num_serial_hds
) {
1443 return serial_hds
[i
];
1448 static int parallel_parse(const char *devname
)
1450 static int index
= 0;
1453 if (strcmp(devname
, "none") == 0)
1455 if (index
== MAX_PARALLEL_PORTS
) {
1456 error_report("too many parallel ports");
1459 snprintf(label
, sizeof(label
), "parallel%d", index
);
1460 parallel_hds
[index
] = qemu_chr_new_mux_mon(label
, devname
, NULL
);
1461 if (!parallel_hds
[index
]) {
1462 error_report("could not connect parallel device"
1463 " to character backend '%s'", devname
);
1470 static int debugcon_parse(const char *devname
)
1474 if (!qemu_chr_new_mux_mon("debugcon", devname
, NULL
)) {
1475 error_report("invalid character backend '%s'", devname
);
1478 opts
= qemu_opts_create(qemu_find_opts("device"), "debugcon", 1, NULL
);
1480 error_report("already have a debugcon device");
1483 qemu_opt_set(opts
, "driver", "isa-debugcon", &error_abort
);
1484 qemu_opt_set(opts
, "chardev", "debugcon", &error_abort
);
1488 static gint
machine_class_cmp(gconstpointer a
, gconstpointer b
)
1490 const MachineClass
*mc1
= a
, *mc2
= b
;
1493 if (mc1
->family
== NULL
) {
1494 if (mc2
->family
== NULL
) {
1495 /* Compare standalone machine types against each other; they sort
1496 * in increasing order.
1498 return strcmp(object_class_get_name(OBJECT_CLASS(mc1
)),
1499 object_class_get_name(OBJECT_CLASS(mc2
)));
1502 /* Standalone machine types sort after families. */
1506 if (mc2
->family
== NULL
) {
1507 /* Families sort before standalone machine types. */
1511 /* Families sort between each other alphabetically increasingly. */
1512 res
= strcmp(mc1
->family
, mc2
->family
);
1517 /* Within the same family, machine types sort in decreasing order. */
1518 return strcmp(object_class_get_name(OBJECT_CLASS(mc2
)),
1519 object_class_get_name(OBJECT_CLASS(mc1
)));
1522 static void machine_help_func(const QDict
*qdict
)
1524 GSList
*machines
, *el
;
1525 const char *type
= qdict_get_try_str(qdict
, "type");
1527 machines
= object_class_get_list(TYPE_MACHINE
, false);
1529 ObjectClass
*machine_class
= OBJECT_CLASS(find_machine(type
, machines
));
1530 if (machine_class
) {
1531 type_print_class_properties(object_class_get_name(machine_class
));
1536 printf("Supported machines are:\n");
1537 machines
= g_slist_sort(machines
, machine_class_cmp
);
1538 for (el
= machines
; el
; el
= el
->next
) {
1539 MachineClass
*mc
= el
->data
;
1541 printf("%-20s %s (alias of %s)\n", mc
->alias
, mc
->desc
, mc
->name
);
1543 printf("%-20s %s%s%s\n", mc
->name
, mc
->desc
,
1544 mc
->is_default
? " (default)" : "",
1545 mc
->deprecation_reason
? " (deprecated)" : "");
1550 machine_merge_property(const char *propname
, QDict
*prop
, Error
**errp
)
1555 /* Preserve the caller's reference to prop. */
1557 qdict_put(opts
, propname
, prop
);
1558 keyval_merge(machine_opts_dict
, opts
, errp
);
1559 qobject_unref(opts
);
1563 machine_parse_property_opt(QemuOptsList
*opts_list
, const char *propname
,
1569 prop
= keyval_parse(arg
, opts_list
->implied_opt_name
, &help
, &error_fatal
);
1571 qemu_opts_print_help(opts_list
, true);
1574 machine_merge_property(propname
, prop
, &error_fatal
);
1575 qobject_unref(prop
);
1578 static const char *pid_file
;
1579 static Notifier qemu_unlink_pidfile_notifier
;
1581 static void qemu_unlink_pidfile(Notifier
*n
, void *data
)
1588 static const QEMUOption
*lookup_opt(int argc
, char **argv
,
1589 const char **poptarg
, int *poptind
)
1591 const QEMUOption
*popt
;
1592 int optind
= *poptind
;
1593 char *r
= argv
[optind
];
1596 loc_set_cmdline(argv
, optind
, 1);
1598 /* Treat --foo the same as -foo. */
1601 popt
= qemu_options
;
1604 error_report("invalid option");
1607 if (!strcmp(popt
->name
, r
+ 1))
1611 if (popt
->flags
& HAS_ARG
) {
1612 if (optind
>= argc
) {
1613 error_report("requires an argument");
1616 optarg
= argv
[optind
++];
1617 loc_set_cmdline(argv
, optind
- 2, 2);
1628 static MachineClass
*select_machine(QDict
*qdict
, Error
**errp
)
1630 const char *optarg
= qdict_get_try_str(qdict
, "type");
1631 GSList
*machines
= object_class_get_list(TYPE_MACHINE
, false);
1632 MachineClass
*machine_class
;
1633 Error
*local_err
= NULL
;
1636 machine_class
= find_machine(optarg
, machines
);
1637 qdict_del(qdict
, "type");
1638 if (!machine_class
) {
1639 error_setg(&local_err
, "unsupported machine type");
1642 machine_class
= find_default_machine(machines
);
1643 if (!machine_class
) {
1644 error_setg(&local_err
, "No machine specified, and there is no default");
1648 g_slist_free(machines
);
1650 error_append_hint(&local_err
, "Use -machine help to list supported machines\n");
1651 error_propagate(errp
, local_err
);
1653 return machine_class
;
1656 static int object_parse_property_opt(Object
*obj
,
1657 const char *name
, const char *value
,
1658 const char *skip
, Error
**errp
)
1660 if (g_str_equal(name
, skip
)) {
1664 if (!object_property_parse(obj
, name
, value
, errp
)) {
1671 /* *Non*recursively replace underscores with dashes in QDict keys. */
1672 static void keyval_dashify(QDict
*qdict
, Error
**errp
)
1674 const QDictEntry
*ent
, *next
;
1677 for (ent
= qdict_first(qdict
); ent
; ent
= next
) {
1678 g_autofree
char *new_key
= NULL
;
1680 next
= qdict_next(qdict
, ent
);
1681 if (!strchr(ent
->key
, '_')) {
1684 new_key
= g_strdup(ent
->key
);
1685 for (p
= new_key
; *p
; p
++) {
1690 if (qdict_haskey(qdict
, new_key
)) {
1691 error_setg(errp
, "Conflict between '%s' and '%s'", ent
->key
, new_key
);
1694 qobject_ref(ent
->value
);
1695 qdict_put_obj(qdict
, new_key
, ent
->value
);
1696 qdict_del(qdict
, ent
->key
);
1700 static void qemu_apply_legacy_machine_options(QDict
*qdict
)
1704 keyval_dashify(qdict
, &error_fatal
);
1706 /* Legacy options do not correspond to MachineState properties. */
1707 value
= qdict_get_try_str(qdict
, "accel");
1709 accelerators
= g_strdup(value
);
1710 qdict_del(qdict
, "accel");
1713 value
= qdict_get_try_str(qdict
, "igd-passthru");
1715 object_register_sugar_prop(ACCEL_CLASS_NAME("xen"), "igd-passthru", value
,
1717 qdict_del(qdict
, "igd-passthru");
1720 value
= qdict_get_try_str(qdict
, "kvm-shadow-mem");
1722 object_register_sugar_prop(ACCEL_CLASS_NAME("kvm"), "kvm-shadow-mem", value
,
1724 qdict_del(qdict
, "kvm-shadow-mem");
1727 value
= qdict_get_try_str(qdict
, "kernel-irqchip");
1729 object_register_sugar_prop(ACCEL_CLASS_NAME("kvm"), "kernel-irqchip", value
,
1731 object_register_sugar_prop(ACCEL_CLASS_NAME("whpx"), "kernel-irqchip", value
,
1733 qdict_del(qdict
, "kernel-irqchip");
1737 static void object_option_foreach_add(bool (*type_opt_predicate
)(const char *))
1739 ObjectOption
*opt
, *next
;
1741 QTAILQ_FOREACH_SAFE(opt
, &object_opts
, next
, next
) {
1742 const char *type
= ObjectType_str(opt
->opts
->qom_type
);
1743 if (type_opt_predicate(type
)) {
1744 user_creatable_add_qapi(opt
->opts
, &error_fatal
);
1745 qapi_free_ObjectOptions(opt
->opts
);
1746 QTAILQ_REMOVE(&object_opts
, opt
, next
);
1752 static void object_option_add_visitor(Visitor
*v
)
1754 ObjectOption
*opt
= g_new0(ObjectOption
, 1);
1755 visit_type_ObjectOptions(v
, NULL
, &opt
->opts
, &error_fatal
);
1756 QTAILQ_INSERT_TAIL(&object_opts
, opt
, next
);
1759 static void object_option_parse(const char *optarg
)
1765 if (optarg
[0] == '{') {
1766 QObject
*obj
= qobject_from_json(optarg
, &error_fatal
);
1768 v
= qobject_input_visitor_new(obj
);
1771 opts
= qemu_opts_parse_noisily(qemu_find_opts("object"),
1777 type
= qemu_opt_get(opts
, "qom-type");
1779 error_setg(&error_fatal
, QERR_MISSING_PARAMETER
, "qom-type");
1781 if (user_creatable_print_help(type
, opts
)) {
1785 v
= opts_visitor_new(opts
);
1788 object_option_add_visitor(v
);
1793 * Initial object creation happens before all other
1794 * QEMU data types are created. The majority of objects
1795 * can be created at this point. The rng-egd object
1796 * cannot be created here, as it depends on the chardev
1799 static bool object_create_early(const char *type
)
1802 * Objects should not be made "delayed" without a reason. If you
1803 * add one, state the reason in a comment!
1806 /* Reason: property "chardev" */
1807 if (g_str_equal(type
, "rng-egd") ||
1808 g_str_equal(type
, "qtest")) {
1812 #if defined(CONFIG_VHOST_USER) && defined(CONFIG_LINUX)
1813 /* Reason: cryptodev-vhost-user property "chardev" */
1814 if (g_str_equal(type
, "cryptodev-vhost-user")) {
1819 /* Reason: vhost-user-blk-server property "node-name" */
1820 if (g_str_equal(type
, "vhost-user-blk-server")) {
1824 * Reason: filter-* property "netdev" etc.
1826 if (g_str_equal(type
, "filter-buffer") ||
1827 g_str_equal(type
, "filter-dump") ||
1828 g_str_equal(type
, "filter-mirror") ||
1829 g_str_equal(type
, "filter-redirector") ||
1830 g_str_equal(type
, "colo-compare") ||
1831 g_str_equal(type
, "filter-rewriter") ||
1832 g_str_equal(type
, "filter-replay")) {
1837 * Allocation of large amounts of memory may delay
1838 * chardev initialization for too long, and trigger timeouts
1839 * on software that waits for a monitor socket to be created
1842 if (g_str_has_prefix(type
, "memory-backend-")) {
1849 static void qemu_apply_machine_options(QDict
*qdict
)
1851 MachineClass
*machine_class
= MACHINE_GET_CLASS(current_machine
);
1852 const char *boot_order
= NULL
;
1853 const char *boot_once
= NULL
;
1856 object_set_properties_from_keyval(OBJECT(current_machine
), qdict
, false, &error_fatal
);
1857 current_machine
->ram_size
= ram_size
;
1858 current_machine
->maxram_size
= maxram_size
;
1859 current_machine
->ram_slots
= ram_slots
;
1861 opts
= qemu_opts_find(qemu_find_opts("boot-opts"), NULL
);
1863 boot_order
= qemu_opt_get(opts
, "order");
1865 validate_bootdevices(boot_order
, &error_fatal
);
1868 boot_once
= qemu_opt_get(opts
, "once");
1870 validate_bootdevices(boot_once
, &error_fatal
);
1873 boot_menu
= qemu_opt_get_bool(opts
, "menu", boot_menu
);
1874 boot_strict
= qemu_opt_get_bool(opts
, "strict", false);
1878 boot_order
= machine_class
->default_boot_order
;
1881 current_machine
->boot_order
= boot_order
;
1882 current_machine
->boot_once
= boot_once
;
1884 if (semihosting_enabled() && !semihosting_get_argc()) {
1885 /* fall back to the -kernel/-append */
1886 semihosting_arg_fallback(current_machine
->kernel_filename
, current_machine
->kernel_cmdline
);
1889 if (current_machine
->smp
.cpus
> 1) {
1890 Error
*blocker
= NULL
;
1891 error_setg(&blocker
, QERR_REPLAY_NOT_SUPPORTED
, "smp");
1892 replay_add_blocker(blocker
);
1896 static void qemu_create_early_backends(void)
1898 MachineClass
*machine_class
= MACHINE_GET_CLASS(current_machine
);
1899 #if defined(CONFIG_SDL)
1900 const bool use_sdl
= (dpy
.type
== DISPLAY_TYPE_SDL
);
1902 const bool use_sdl
= false;
1904 #if defined(CONFIG_GTK)
1905 const bool use_gtk
= (dpy
.type
== DISPLAY_TYPE_GTK
);
1907 const bool use_gtk
= false;
1910 if ((alt_grab
|| ctrl_grab
) && !use_sdl
) {
1911 error_report("-alt-grab and -ctrl-grab are only valid "
1912 "for SDL, ignoring option");
1914 if (dpy
.has_window_close
&& !use_gtk
&& !use_sdl
) {
1915 error_report("-no-quit is only valid for GTK and SDL, "
1919 qemu_display_early_init(&dpy
);
1920 qemu_console_early_init();
1922 if (dpy
.has_gl
&& dpy
.gl
!= DISPLAYGL_MODE_OFF
&& display_opengl
== 0) {
1923 #if defined(CONFIG_OPENGL)
1924 error_report("OpenGL is not supported by the display");
1926 error_report("OpenGL support is disabled");
1931 object_option_foreach_add(object_create_early
);
1933 /* spice needs the timers to be initialized by this point */
1934 /* spice must initialize before audio as it changes the default auiodev */
1935 /* spice must initialize before chardevs (for spicevmc and spiceport) */
1938 qemu_opts_foreach(qemu_find_opts("chardev"),
1939 chardev_init_func
, NULL
, &error_fatal
);
1941 #ifdef CONFIG_VIRTFS
1942 qemu_opts_foreach(qemu_find_opts("fsdev"),
1943 fsdev_init_func
, NULL
, &error_fatal
);
1947 * Note: we need to create audio and block backends before
1948 * setting machine properties, so they can be referred to.
1950 configure_blockdev(&bdo_queue
, machine_class
, snapshot
);
1951 audio_init_audiodevs();
1956 * The remainder of object creation happens after the
1957 * creation of chardev, fsdev, net clients and device data types.
1959 static bool object_create_late(const char *type
)
1961 return !object_create_early(type
);
1964 static void qemu_create_late_backends(void)
1967 qtest_server_init(qtest_chrdev
, qtest_log
, &error_fatal
);
1970 net_init_clients(&error_fatal
);
1972 object_option_foreach_add(object_create_late
);
1974 if (tpm_init() < 0) {
1978 qemu_opts_foreach(qemu_find_opts("mon"),
1979 mon_init_func
, NULL
, &error_fatal
);
1981 if (foreach_device_config(DEV_SERIAL
, serial_parse
) < 0)
1983 if (foreach_device_config(DEV_PARALLEL
, parallel_parse
) < 0)
1985 if (foreach_device_config(DEV_DEBUGCON
, debugcon_parse
) < 0)
1988 /* now chardevs have been created we may have semihosting to connect */
1989 qemu_semihosting_connect_chardevs();
1990 qemu_semihosting_console_init();
1993 static bool have_custom_ram_size(void)
1995 QemuOpts
*opts
= qemu_find_opts_singleton("memory");
1996 return !!qemu_opt_get_size(opts
, "size", 0);
1999 static void qemu_resolve_machine_memdev(void)
2001 if (current_machine
->ram_memdev_id
) {
2003 ram_addr_t backend_size
;
2005 backend
= object_resolve_path_type(current_machine
->ram_memdev_id
,
2006 TYPE_MEMORY_BACKEND
, NULL
);
2008 error_report("Memory backend '%s' not found",
2009 current_machine
->ram_memdev_id
);
2012 backend_size
= object_property_get_uint(backend
, "size", &error_abort
);
2013 if (have_custom_ram_size() && backend_size
!= ram_size
) {
2014 error_report("Size specified by -m option must match size of "
2015 "explicitly specified 'memory-backend' property");
2019 error_report("'-mem-path' can't be used together with"
2020 "'-machine memory-backend'");
2023 ram_size
= backend_size
;
2026 if (!xen_enabled()) {
2027 /* On 32-bit hosts, QEMU is limited by virtual address space */
2028 if (ram_size
> (2047 << 20) && HOST_LONG_BITS
== 32) {
2029 error_report("at most 2047 MB RAM can be simulated");
2035 static void set_memory_options(MachineClass
*mc
)
2038 const char *mem_str
;
2039 const ram_addr_t default_ram_size
= mc
->default_ram_size
;
2040 QemuOpts
*opts
= qemu_find_opts_singleton("memory");
2043 loc_push_none(&loc
);
2044 qemu_opts_loc_restore(opts
);
2047 mem_str
= qemu_opt_get(opts
, "size");
2050 error_report("missing 'size' option value");
2054 sz
= qemu_opt_get_size(opts
, "size", ram_size
);
2056 /* Fix up legacy suffix-less format */
2057 if (g_ascii_isdigit(mem_str
[strlen(mem_str
) - 1])) {
2058 uint64_t overflow_check
= sz
;
2061 if (sz
/ MiB
!= overflow_check
) {
2062 error_report("too large 'size' option value");
2068 /* backward compatibility behaviour for case "-m 0" */
2070 sz
= default_ram_size
;
2073 sz
= QEMU_ALIGN_UP(sz
, 8192);
2074 if (mc
->fixup_ram_size
) {
2075 sz
= mc
->fixup_ram_size(sz
);
2078 if (ram_size
!= sz
) {
2079 error_report("ram size too large");
2083 maxram_size
= ram_size
;
2085 if (qemu_opt_get(opts
, "maxmem")) {
2088 sz
= qemu_opt_get_size(opts
, "maxmem", 0);
2089 slots
= qemu_opt_get_number(opts
, "slots", 0);
2090 if (sz
< ram_size
) {
2091 error_report("invalid value of -m option maxmem: "
2092 "maximum memory size (0x%" PRIx64
") must be at least "
2093 "the initial memory size (0x" RAM_ADDR_FMT
")",
2096 } else if (slots
&& sz
== ram_size
) {
2097 error_report("invalid value of -m option maxmem: "
2098 "memory slots were specified but maximum memory size "
2099 "(0x%" PRIx64
") is equal to the initial memory size "
2100 "(0x" RAM_ADDR_FMT
")", sz
, ram_size
);
2106 } else if (qemu_opt_get(opts
, "slots")) {
2107 error_report("invalid -m option value: missing 'maxmem' option");
2114 static void qemu_create_machine(QDict
*qdict
)
2116 MachineClass
*machine_class
= select_machine(qdict
, &error_fatal
);
2117 object_set_machine_compat_props(machine_class
->compat_props
);
2119 set_memory_options(machine_class
);
2121 current_machine
= MACHINE(object_new_with_class(OBJECT_CLASS(machine_class
)));
2122 object_property_add_child(object_get_root(), "machine",
2123 OBJECT(current_machine
));
2124 object_property_add_child(container_get(OBJECT(current_machine
),
2126 "sysbus", OBJECT(sysbus_get_default()));
2128 if (machine_class
->minimum_page_bits
) {
2129 if (!set_preferred_target_page_bits(machine_class
->minimum_page_bits
)) {
2130 /* This would be a board error: specifying a minimum smaller than
2131 * a target's compile-time fixed setting.
2133 g_assert_not_reached();
2137 cpu_exec_init_all();
2140 if (machine_class
->hw_version
) {
2141 qemu_set_hw_version(machine_class
->hw_version
);
2145 * Get the default machine options from the machine if it is not already
2146 * specified either by the configuration file or by the command line.
2148 if (machine_class
->default_machine_opts
) {
2149 QDict
*default_opts
=
2150 keyval_parse(machine_class
->default_machine_opts
, NULL
, NULL
,
2152 qemu_apply_legacy_machine_options(default_opts
);
2153 object_set_properties_from_keyval(OBJECT(current_machine
), default_opts
,
2154 false, &error_abort
);
2155 qobject_unref(default_opts
);
2159 static int global_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2163 g
= g_malloc0(sizeof(*g
));
2164 g
->driver
= qemu_opt_get(opts
, "driver");
2165 g
->property
= qemu_opt_get(opts
, "property");
2166 g
->value
= qemu_opt_get(opts
, "value");
2167 qdev_prop_register_global(g
);
2172 * Return whether configuration group @group is stored in QemuOpts, or
2173 * recorded as one or more QDicts by qemu_record_config_group.
2175 static bool is_qemuopts_group(const char *group
)
2177 if (g_str_equal(group
, "object") ||
2178 g_str_equal(group
, "machine") ||
2179 g_str_equal(group
, "smp-opts")) {
2185 static void qemu_record_config_group(const char *group
, QDict
*dict
,
2186 bool from_json
, Error
**errp
)
2188 if (g_str_equal(group
, "object")) {
2189 Visitor
*v
= qobject_input_visitor_new_keyval(QOBJECT(dict
));
2190 object_option_add_visitor(v
);
2192 } else if (g_str_equal(group
, "machine")) {
2194 * Cannot merge string-valued and type-safe dictionaries, so JSON
2195 * is not accepted yet for -M.
2198 keyval_merge(machine_opts_dict
, dict
, errp
);
2199 } else if (g_str_equal(group
, "smp-opts")) {
2200 machine_merge_property("smp", dict
, &error_fatal
);
2207 * Parse non-QemuOpts config file groups, pass the rest to
2208 * qemu_config_do_parse.
2210 static void qemu_parse_config_group(const char *group
, QDict
*qdict
,
2211 void *opaque
, Error
**errp
)
2214 if (is_qemuopts_group(group
)) {
2215 qemu_config_do_parse(group
, qdict
, opaque
, errp
);
2219 crumpled
= qdict_crumple(qdict
, errp
);
2223 switch (qobject_type(crumpled
)) {
2225 qemu_record_config_group(group
, qobject_to(QDict
, crumpled
), false, errp
);
2228 error_setg(errp
, "Lists cannot be at top level of a configuration section");
2231 g_assert_not_reached();
2233 qobject_unref(crumpled
);
2236 static void qemu_read_default_config_file(Error
**errp
)
2240 g_autofree
char *file
= get_relocated_path(CONFIG_QEMU_CONFDIR
"/qemu.conf");
2242 ret
= qemu_read_config_file(file
, qemu_parse_config_group
, errp
);
2244 if (ret
== -ENOENT
) {
2251 static void qemu_set_option(const char *str
, Error
**errp
)
2253 char group
[64], id
[64], arg
[64];
2258 rc
= sscanf(str
, "%63[^.].%63[^.].%63[^=]%n", group
, id
, arg
, &offset
);
2259 if (rc
< 3 || str
[offset
] != '=') {
2260 error_setg(errp
, "can't parse: \"%s\"", str
);
2264 if (!is_qemuopts_group(group
)) {
2265 error_setg(errp
, "-set is not supported with %s", group
);
2267 list
= qemu_find_opts_err(group
, errp
);
2269 opts
= qemu_opts_find(list
, id
);
2271 error_setg(errp
, "there is no %s \"%s\" defined", group
, id
);
2274 qemu_opt_set(opts
, arg
, str
+ offset
+ 1, errp
);
2279 static void user_register_global_props(void)
2281 qemu_opts_foreach(qemu_find_opts("global"),
2282 global_init_func
, NULL
, NULL
);
2285 static int do_configure_icount(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2287 icount_configure(opts
, errp
);
2291 static int accelerator_set_property(void *opaque
,
2292 const char *name
, const char *value
,
2295 return object_parse_property_opt(opaque
, name
, value
, "accel", errp
);
2298 static int do_configure_accelerator(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2300 bool *p_init_failed
= opaque
;
2301 const char *acc
= qemu_opt_get(opts
, "accel");
2302 AccelClass
*ac
= accel_find(acc
);
2305 bool qtest_with_kvm
;
2307 qtest_with_kvm
= g_str_equal(acc
, "kvm") && qtest_chrdev
!= NULL
;
2310 *p_init_failed
= true;
2311 if (!qtest_with_kvm
) {
2312 error_report("invalid accelerator %s", acc
);
2316 accel
= ACCEL(object_new_with_class(OBJECT_CLASS(ac
)));
2317 object_apply_compat_props(OBJECT(accel
));
2318 qemu_opt_foreach(opts
, accelerator_set_property
,
2322 ret
= accel_init_machine(accel
, current_machine
);
2324 *p_init_failed
= true;
2325 if (!qtest_with_kvm
|| ret
!= -ENOENT
) {
2326 error_report("failed to initialize %s: %s", acc
, strerror(-ret
));
2334 static void configure_accelerators(const char *progname
)
2336 bool init_failed
= false;
2338 qemu_opts_foreach(qemu_find_opts("icount"),
2339 do_configure_icount
, NULL
, &error_fatal
);
2341 if (QTAILQ_EMPTY(&qemu_accel_opts
.head
)) {
2342 char **accel_list
, **tmp
;
2344 if (accelerators
== NULL
) {
2345 /* Select the default accelerator */
2346 bool have_tcg
= accel_find("tcg");
2347 bool have_kvm
= accel_find("kvm");
2349 if (have_tcg
&& have_kvm
) {
2350 if (g_str_has_suffix(progname
, "kvm")) {
2351 /* If the program name ends with "kvm", we prefer KVM */
2352 accelerators
= "kvm:tcg";
2354 accelerators
= "tcg:kvm";
2356 } else if (have_kvm
) {
2357 accelerators
= "kvm";
2358 } else if (have_tcg
) {
2359 accelerators
= "tcg";
2361 error_report("No accelerator selected and"
2362 " no default accelerator available");
2366 accel_list
= g_strsplit(accelerators
, ":", 0);
2368 for (tmp
= accel_list
; *tmp
; tmp
++) {
2370 * Filter invalid accelerators here, to prevent obscenities
2371 * such as "-machine accel=tcg,,thread=single".
2373 if (accel_find(*tmp
)) {
2374 qemu_opts_parse_noisily(qemu_find_opts("accel"), *tmp
, true);
2377 error_report("invalid accelerator %s", *tmp
);
2380 g_strfreev(accel_list
);
2382 if (accelerators
!= NULL
) {
2383 error_report("The -accel and \"-machine accel=\" options are incompatible");
2388 if (!qemu_opts_foreach(qemu_find_opts("accel"),
2389 do_configure_accelerator
, &init_failed
, &error_fatal
)) {
2391 error_report("no accelerator found");
2396 if (init_failed
&& !qtest_chrdev
) {
2397 AccelClass
*ac
= ACCEL_GET_CLASS(current_accel());
2398 error_report("falling back to %s", ac
->name
);
2401 if (icount_enabled() && !tcg_enabled()) {
2402 error_report("-icount is not allowed with hardware virtualization");
2407 static void create_default_memdev(MachineState
*ms
, const char *path
)
2410 MachineClass
*mc
= MACHINE_GET_CLASS(ms
);
2412 obj
= object_new(path
? TYPE_MEMORY_BACKEND_FILE
: TYPE_MEMORY_BACKEND_RAM
);
2414 object_property_set_str(obj
, "mem-path", path
, &error_fatal
);
2416 object_property_set_int(obj
, "size", ms
->ram_size
, &error_fatal
);
2417 object_property_add_child(object_get_objects_root(), mc
->default_ram_id
,
2419 /* Ensure backend's memory region name is equal to mc->default_ram_id */
2420 object_property_set_bool(obj
, "x-use-canonical-path-for-ramblock-id",
2421 false, &error_fatal
);
2422 user_creatable_complete(USER_CREATABLE(obj
), &error_fatal
);
2424 object_property_set_str(OBJECT(ms
), "memory-backend", mc
->default_ram_id
,
2428 static void qemu_validate_options(const QDict
*machine_opts
)
2430 const char *kernel_filename
= qdict_get_try_str(machine_opts
, "kernel");
2431 const char *initrd_filename
= qdict_get_try_str(machine_opts
, "initrd");
2432 const char *kernel_cmdline
= qdict_get_try_str(machine_opts
, "append");
2434 if (kernel_filename
== NULL
) {
2435 if (kernel_cmdline
!= NULL
) {
2436 error_report("-append only allowed with -kernel option");
2440 if (initrd_filename
!= NULL
) {
2441 error_report("-initrd only allowed with -kernel option");
2446 if (loadvm
&& preconfig_requested
) {
2447 error_report("'preconfig' and 'loadvm' options are "
2448 "mutually exclusive");
2451 if (incoming
&& preconfig_requested
&& strcmp(incoming
, "defer") != 0) {
2452 error_report("'preconfig' supports '-incoming defer' only");
2456 #ifdef CONFIG_CURSES
2457 if (is_daemonized() && dpy
.type
== DISPLAY_TYPE_CURSES
) {
2458 error_report("curses display cannot be used with -daemonize");
2464 static void qemu_process_sugar_options(void)
2467 QObject
*smp
= qdict_get(machine_opts_dict
, "smp");
2468 if (smp
&& qobject_type(smp
) == QTYPE_QDICT
) {
2469 QObject
*cpus
= qdict_get(qobject_to(QDict
, smp
), "cpus");
2470 if (cpus
&& qobject_type(cpus
) == QTYPE_QSTRING
) {
2471 const char *val
= qstring_get_str(qobject_to(QString
, cpus
));
2472 object_register_sugar_prop("memory-backend", "prealloc-threads",
2476 object_register_sugar_prop("memory-backend", "prealloc", "on", false);
2480 int i
= select_watchdog(watchdog
);
2482 exit (i
== 1 ? 1 : 0);
2486 /* -action processing */
2489 * Process all the -action parameters parsed from cmdline.
2491 static int process_runstate_actions(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2493 Error
*local_err
= NULL
;
2494 QDict
*qdict
= qemu_opts_to_qdict(opts
, NULL
);
2495 QObject
*ret
= NULL
;
2496 qmp_marshal_set_action(qdict
, &ret
, &local_err
);
2498 qobject_unref(qdict
);
2500 error_propagate(errp
, local_err
);
2506 static void qemu_process_early_options(void)
2508 #ifdef CONFIG_SECCOMP
2509 QemuOptsList
*olist
= qemu_find_opts_err("sandbox", NULL
);
2511 qemu_opts_foreach(olist
, parse_sandbox
, NULL
, &error_fatal
);
2515 qemu_opts_foreach(qemu_find_opts("name"),
2516 parse_name
, NULL
, &error_fatal
);
2518 if (qemu_opts_foreach(qemu_find_opts("action"),
2519 process_runstate_actions
, NULL
, &error_fatal
)) {
2524 qemu_opts_foreach(qemu_find_opts("add-fd"),
2525 parse_add_fd
, NULL
, &error_fatal
);
2527 qemu_opts_foreach(qemu_find_opts("add-fd"),
2528 cleanup_add_fd
, NULL
, &error_fatal
);
2531 /* Open the logfile at this point and set the log mask if necessary. */
2533 qemu_set_log_filename(log_file
, &error_fatal
);
2537 mask
= qemu_str_to_log_mask(log_mask
);
2539 qemu_print_log_usage(stdout
);
2547 qemu_add_default_firmwarepath();
2550 static void qemu_process_help_options(void)
2553 * Check for -cpu help and -device help before we call select_machine(),
2554 * which will return an error if the architecture has no default machine
2555 * type and the user did not specify one, so that the user doesn't need
2556 * to say '-cpu help -machine something'.
2558 if (cpu_option
&& is_help_option(cpu_option
)) {
2559 list_cpus(cpu_option
);
2563 if (qemu_opts_foreach(qemu_find_opts("device"),
2564 device_help_func
, NULL
, NULL
)) {
2568 /* -L help lists the data directories and exits. */
2569 if (list_data_dirs
) {
2570 qemu_list_data_dirs();
2575 static void qemu_maybe_daemonize(const char *pid_file
)
2580 rcu_disable_atfork();
2582 if (pid_file
&& !qemu_write_pidfile(pid_file
, &err
)) {
2583 error_reportf_err(err
, "cannot create PID file: ");
2587 qemu_unlink_pidfile_notifier
.notify
= qemu_unlink_pidfile
;
2588 qemu_add_exit_notifier(&qemu_unlink_pidfile_notifier
);
2591 static void qemu_init_displays(void)
2595 /* init local displays */
2596 ds
= init_displaystate();
2597 qemu_display_init(ds
, &dpy
);
2599 /* must be after terminal init, SDL library changes signal handlers */
2600 os_setup_signal_handling();
2602 /* init remote displays */
2604 qemu_opts_foreach(qemu_find_opts("vnc"),
2605 vnc_init_func
, NULL
, &error_fatal
);
2609 qemu_spice
.display_init();
2613 static void qemu_init_board(void)
2615 MachineClass
*machine_class
= MACHINE_GET_CLASS(current_machine
);
2617 if (machine_class
->default_ram_id
&& current_machine
->ram_size
&&
2618 numa_uses_legacy_mem() && !current_machine
->ram_memdev_id
) {
2619 create_default_memdev(current_machine
, mem_path
);
2622 /* process plugin before CPUs are created, but once -smp has been parsed */
2623 qemu_plugin_load_list(&plugin_list
, &error_fatal
);
2625 /* From here on we enter MACHINE_PHASE_INITIALIZED. */
2626 machine_run_board_init(current_machine
);
2628 drive_check_orphaned();
2632 if (hax_enabled()) {
2633 /* FIXME: why isn't cpu_synchronize_all_post_init enough? */
2638 static void qemu_create_cli_devices(void)
2642 qemu_opts_foreach(qemu_find_opts("fw_cfg"),
2643 parse_fw_cfg
, fw_cfg_find(), &error_fatal
);
2645 /* init USB devices */
2646 if (machine_usb(current_machine
)) {
2647 if (foreach_device_config(DEV_USB
, usb_parse
) < 0)
2651 /* init generic devices */
2652 rom_set_order_override(FW_CFG_ORDER_OVERRIDE_DEVICE
);
2653 qemu_opts_foreach(qemu_find_opts("device"),
2654 device_init_func
, NULL
, &error_fatal
);
2655 rom_reset_order_override();
2658 static void qemu_machine_creation_done(void)
2660 MachineState
*machine
= MACHINE(qdev_get_machine());
2662 /* Did we create any drives that we failed to create a device for? */
2663 drive_check_orphaned();
2665 /* Don't warn about the default network setup that you get if
2666 * no command line -net or -netdev options are specified. There
2667 * are two cases that we would otherwise complain about:
2668 * (1) board doesn't support a NIC but the implicit "-net nic"
2670 * (2) CONFIG_SLIRP not set, in which case the implicit "-net nic"
2671 * sets up a nic that isn't connected to anything.
2673 if (!default_net
&& (!qtest_enabled() || has_defaults
)) {
2674 net_check_clients();
2677 qdev_prop_check_globals();
2679 qdev_machine_creation_done();
2683 * Verify that Confidential Guest Support has actually been initialized
2685 assert(machine
->cgs
->ready
);
2688 if (foreach_device_config(DEV_GDB
, gdbserver_start
) < 0) {
2693 void qmp_x_exit_preconfig(Error
**errp
)
2695 if (phase_check(PHASE_MACHINE_INITIALIZED
)) {
2696 error_setg(errp
, "The command is permitted only before machine initialization");
2701 qemu_create_cli_devices();
2702 qemu_machine_creation_done();
2705 load_snapshot(loadvm
, NULL
, false, NULL
, &error_fatal
);
2707 if (replay_mode
!= REPLAY_MODE_NONE
) {
2708 replay_vmstate_init();
2712 Error
*local_err
= NULL
;
2713 if (strcmp(incoming
, "defer") != 0) {
2714 qmp_migrate_incoming(incoming
, &local_err
);
2716 error_reportf_err(local_err
, "-incoming %s: ", incoming
);
2720 } else if (autostart
) {
2725 void qemu_init(int argc
, char **argv
, char **envp
)
2728 QemuOpts
*icount_opts
= NULL
, *accel_opts
= NULL
;
2729 QemuOptsList
*olist
;
2732 MachineClass
*machine_class
;
2733 bool userconfig
= true;
2734 FILE *vmstate_dump_file
= NULL
;
2736 qemu_add_opts(&qemu_drive_opts
);
2737 qemu_add_drive_opts(&qemu_legacy_drive_opts
);
2738 qemu_add_drive_opts(&qemu_common_drive_opts
);
2739 qemu_add_drive_opts(&qemu_drive_opts
);
2740 qemu_add_drive_opts(&bdrv_runtime_opts
);
2741 qemu_add_opts(&qemu_chardev_opts
);
2742 qemu_add_opts(&qemu_device_opts
);
2743 qemu_add_opts(&qemu_netdev_opts
);
2744 qemu_add_opts(&qemu_nic_opts
);
2745 qemu_add_opts(&qemu_net_opts
);
2746 qemu_add_opts(&qemu_rtc_opts
);
2747 qemu_add_opts(&qemu_global_opts
);
2748 qemu_add_opts(&qemu_mon_opts
);
2749 qemu_add_opts(&qemu_trace_opts
);
2750 qemu_plugin_add_opts();
2751 qemu_add_opts(&qemu_option_rom_opts
);
2752 qemu_add_opts(&qemu_accel_opts
);
2753 qemu_add_opts(&qemu_mem_opts
);
2754 qemu_add_opts(&qemu_smp_opts
);
2755 qemu_add_opts(&qemu_boot_opts
);
2756 qemu_add_opts(&qemu_add_fd_opts
);
2757 qemu_add_opts(&qemu_object_opts
);
2758 qemu_add_opts(&qemu_tpmdev_opts
);
2759 qemu_add_opts(&qemu_overcommit_opts
);
2760 qemu_add_opts(&qemu_msg_opts
);
2761 qemu_add_opts(&qemu_name_opts
);
2762 qemu_add_opts(&qemu_numa_opts
);
2763 qemu_add_opts(&qemu_icount_opts
);
2764 qemu_add_opts(&qemu_semihosting_config_opts
);
2765 qemu_add_opts(&qemu_fw_cfg_opts
);
2766 qemu_add_opts(&qemu_action_opts
);
2767 module_call_init(MODULE_INIT_OPTS
);
2769 error_init(argv
[0]);
2770 qemu_init_exec_dir(argv
[0]);
2772 #ifdef CONFIG_MODULES
2773 module_init_info(qemu_modinfo
);
2774 module_allow_arch(TARGET_NAME
);
2777 qemu_init_subsystems();
2779 /* first pass of option parsing */
2781 while (optind
< argc
) {
2782 if (argv
[optind
][0] != '-') {
2786 const QEMUOption
*popt
;
2788 popt
= lookup_opt(argc
, argv
, &optarg
, &optind
);
2789 switch (popt
->index
) {
2790 case QEMU_OPTION_nouserconfig
:
2797 machine_opts_dict
= qdict_new();
2799 qemu_read_default_config_file(&error_fatal
);
2802 /* second pass of option parsing */
2807 if (argv
[optind
][0] != '-') {
2808 loc_set_cmdline(argv
, optind
, 1);
2809 drive_add(IF_DEFAULT
, 0, argv
[optind
++], HD_OPTS
);
2811 const QEMUOption
*popt
;
2813 popt
= lookup_opt(argc
, argv
, &optarg
, &optind
);
2814 if (!(popt
->arch_mask
& arch_type
)) {
2815 error_report("Option not supported for this target");
2818 switch(popt
->index
) {
2819 case QEMU_OPTION_cpu
:
2820 /* hw initialization will check this */
2821 cpu_option
= optarg
;
2823 case QEMU_OPTION_hda
:
2824 case QEMU_OPTION_hdb
:
2825 case QEMU_OPTION_hdc
:
2826 case QEMU_OPTION_hdd
:
2827 drive_add(IF_DEFAULT
, popt
->index
- QEMU_OPTION_hda
, optarg
,
2830 case QEMU_OPTION_blockdev
:
2833 BlockdevOptionsQueueEntry
*bdo
;
2835 v
= qobject_input_visitor_new_str(optarg
, "driver",
2838 bdo
= g_new(BlockdevOptionsQueueEntry
, 1);
2839 visit_type_BlockdevOptions(v
, NULL
, &bdo
->bdo
,
2842 loc_save(&bdo
->loc
);
2843 QSIMPLEQ_INSERT_TAIL(&bdo_queue
, bdo
, entry
);
2846 case QEMU_OPTION_drive
:
2847 if (drive_def(optarg
) == NULL
) {
2851 case QEMU_OPTION_set
:
2852 qemu_set_option(optarg
, &error_fatal
);
2854 case QEMU_OPTION_global
:
2855 if (qemu_global_option(optarg
) != 0)
2858 case QEMU_OPTION_mtdblock
:
2859 drive_add(IF_MTD
, -1, optarg
, MTD_OPTS
);
2861 case QEMU_OPTION_sd
:
2862 drive_add(IF_SD
, -1, optarg
, SD_OPTS
);
2864 case QEMU_OPTION_pflash
:
2865 drive_add(IF_PFLASH
, -1, optarg
, PFLASH_OPTS
);
2867 case QEMU_OPTION_snapshot
:
2869 Error
*blocker
= NULL
;
2871 error_setg(&blocker
, QERR_REPLAY_NOT_SUPPORTED
,
2873 replay_add_blocker(blocker
);
2876 case QEMU_OPTION_numa
:
2877 opts
= qemu_opts_parse_noisily(qemu_find_opts("numa"),
2883 case QEMU_OPTION_display
:
2884 parse_display(optarg
);
2886 case QEMU_OPTION_nographic
:
2887 qdict_put_str(machine_opts_dict
, "graphics", "off");
2889 dpy
.type
= DISPLAY_TYPE_NONE
;
2891 case QEMU_OPTION_curses
:
2892 warn_report("-curses is deprecated, "
2893 "use -display curses instead.");
2894 #ifdef CONFIG_CURSES
2895 dpy
.type
= DISPLAY_TYPE_CURSES
;
2897 error_report("curses or iconv support is disabled");
2901 case QEMU_OPTION_portrait
:
2902 graphic_rotate
= 90;
2904 case QEMU_OPTION_rotate
:
2905 graphic_rotate
= strtol(optarg
, (char **) &optarg
, 10);
2906 if (graphic_rotate
!= 0 && graphic_rotate
!= 90 &&
2907 graphic_rotate
!= 180 && graphic_rotate
!= 270) {
2908 error_report("only 90, 180, 270 deg rotation is available");
2912 case QEMU_OPTION_kernel
:
2913 qdict_put_str(machine_opts_dict
, "kernel", optarg
);
2915 case QEMU_OPTION_initrd
:
2916 qdict_put_str(machine_opts_dict
, "initrd", optarg
);
2918 case QEMU_OPTION_append
:
2919 qdict_put_str(machine_opts_dict
, "append", optarg
);
2921 case QEMU_OPTION_dtb
:
2922 qdict_put_str(machine_opts_dict
, "dtb", optarg
);
2924 case QEMU_OPTION_cdrom
:
2925 drive_add(IF_DEFAULT
, 2, optarg
, CDROM_OPTS
);
2927 case QEMU_OPTION_boot
:
2928 opts
= qemu_opts_parse_noisily(qemu_find_opts("boot-opts"),
2934 case QEMU_OPTION_fda
:
2935 case QEMU_OPTION_fdb
:
2936 drive_add(IF_FLOPPY
, popt
->index
- QEMU_OPTION_fda
,
2939 case QEMU_OPTION_no_fd_bootchk
:
2942 case QEMU_OPTION_netdev
:
2944 if (net_client_parse(qemu_find_opts("netdev"), optarg
) == -1) {
2948 case QEMU_OPTION_nic
:
2950 if (net_client_parse(qemu_find_opts("nic"), optarg
) == -1) {
2954 case QEMU_OPTION_net
:
2956 if (net_client_parse(qemu_find_opts("net"), optarg
) == -1) {
2960 #ifdef CONFIG_LIBISCSI
2961 case QEMU_OPTION_iscsi
:
2962 opts
= qemu_opts_parse_noisily(qemu_find_opts("iscsi"),
2969 case QEMU_OPTION_audio_help
:
2970 audio_legacy_help();
2973 case QEMU_OPTION_audiodev
:
2974 audio_parse_option(optarg
);
2976 case QEMU_OPTION_soundhw
:
2977 select_soundhw (optarg
);
2982 case QEMU_OPTION_version
:
2987 opts
= qemu_opts_parse_noisily(qemu_find_opts("memory"),
2994 case QEMU_OPTION_tpmdev
:
2995 if (tpm_config_parse(qemu_find_opts("tpmdev"), optarg
) < 0) {
3000 case QEMU_OPTION_mempath
:
3003 case QEMU_OPTION_mem_prealloc
:
3012 case QEMU_OPTION_DFILTER
:
3013 qemu_set_dfilter_ranges(optarg
, &error_fatal
);
3015 case QEMU_OPTION_seed
:
3016 qemu_guest_random_seed_main(optarg
, &error_fatal
);
3019 add_device_config(DEV_GDB
, "tcp::" DEFAULT_GDBSTUB_PORT
);
3021 case QEMU_OPTION_gdb
:
3022 add_device_config(DEV_GDB
, optarg
);
3025 if (is_help_option(optarg
)) {
3026 list_data_dirs
= true;
3028 qemu_add_data_dir(g_strdup(optarg
));
3031 case QEMU_OPTION_bios
:
3032 qdict_put_str(machine_opts_dict
, "firmware", optarg
);
3034 case QEMU_OPTION_singlestep
:
3041 keyboard_layout
= optarg
;
3043 case QEMU_OPTION_vga
:
3052 w
= strtol(p
, (char **)&p
, 10);
3055 error_report("invalid resolution or depth");
3061 h
= strtol(p
, (char **)&p
, 10);
3066 depth
= strtol(p
, (char **)&p
, 10);
3067 if (depth
!= 1 && depth
!= 2 && depth
!= 4 &&
3068 depth
!= 8 && depth
!= 15 && depth
!= 16 &&
3069 depth
!= 24 && depth
!= 32)
3071 } else if (*p
== '\0') {
3072 depth
= graphic_depth
;
3079 graphic_depth
= depth
;
3082 case QEMU_OPTION_echr
:
3085 term_escape_char
= strtol(optarg
, &r
, 0);
3087 printf("Bad argument to echr\n");
3090 case QEMU_OPTION_monitor
:
3091 default_monitor
= 0;
3092 if (strncmp(optarg
, "none", 4)) {
3093 monitor_parse(optarg
, "readline", false);
3096 case QEMU_OPTION_qmp
:
3097 monitor_parse(optarg
, "control", false);
3098 default_monitor
= 0;
3100 case QEMU_OPTION_qmp_pretty
:
3101 monitor_parse(optarg
, "control", true);
3102 default_monitor
= 0;
3104 case QEMU_OPTION_mon
:
3105 opts
= qemu_opts_parse_noisily(qemu_find_opts("mon"), optarg
,
3110 default_monitor
= 0;
3112 case QEMU_OPTION_chardev
:
3113 opts
= qemu_opts_parse_noisily(qemu_find_opts("chardev"),
3119 case QEMU_OPTION_fsdev
:
3120 olist
= qemu_find_opts("fsdev");
3122 error_report("fsdev support is disabled");
3125 opts
= qemu_opts_parse_noisily(olist
, optarg
, true);
3130 case QEMU_OPTION_virtfs
: {
3133 const char *writeout
, *sock_fd
, *socket
, *path
, *security_model
,
3136 olist
= qemu_find_opts("virtfs");
3138 error_report("virtfs support is disabled");
3141 opts
= qemu_opts_parse_noisily(olist
, optarg
, true);
3146 if (qemu_opt_get(opts
, "fsdriver") == NULL
||
3147 qemu_opt_get(opts
, "mount_tag") == NULL
) {
3148 error_report("Usage: -virtfs fsdriver,mount_tag=tag");
3151 fsdev
= qemu_opts_create(qemu_find_opts("fsdev"),
3152 qemu_opts_id(opts
) ?:
3153 qemu_opt_get(opts
, "mount_tag"),
3156 error_report("duplicate or invalid fsdev id: %s",
3157 qemu_opt_get(opts
, "mount_tag"));
3161 writeout
= qemu_opt_get(opts
, "writeout");
3163 #ifdef CONFIG_SYNC_FILE_RANGE
3164 qemu_opt_set(fsdev
, "writeout", writeout
, &error_abort
);
3166 error_report("writeout=immediate not supported "
3167 "on this platform");
3171 qemu_opt_set(fsdev
, "fsdriver",
3172 qemu_opt_get(opts
, "fsdriver"), &error_abort
);
3173 path
= qemu_opt_get(opts
, "path");
3175 qemu_opt_set(fsdev
, "path", path
, &error_abort
);
3177 security_model
= qemu_opt_get(opts
, "security_model");
3178 if (security_model
) {
3179 qemu_opt_set(fsdev
, "security_model", security_model
,
3182 socket
= qemu_opt_get(opts
, "socket");
3184 qemu_opt_set(fsdev
, "socket", socket
, &error_abort
);
3186 sock_fd
= qemu_opt_get(opts
, "sock_fd");
3188 qemu_opt_set(fsdev
, "sock_fd", sock_fd
, &error_abort
);
3191 qemu_opt_set_bool(fsdev
, "readonly",
3192 qemu_opt_get_bool(opts
, "readonly", 0),
3194 multidevs
= qemu_opt_get(opts
, "multidevs");
3196 qemu_opt_set(fsdev
, "multidevs", multidevs
, &error_abort
);
3198 device
= qemu_opts_create(qemu_find_opts("device"), NULL
, 0,
3200 qemu_opt_set(device
, "driver", "virtio-9p-pci", &error_abort
);
3201 qemu_opt_set(device
, "fsdev",
3202 qemu_opts_id(fsdev
), &error_abort
);
3203 qemu_opt_set(device
, "mount_tag",
3204 qemu_opt_get(opts
, "mount_tag"), &error_abort
);
3207 case QEMU_OPTION_serial
:
3208 add_device_config(DEV_SERIAL
, optarg
);
3210 if (strncmp(optarg
, "mon:", 4) == 0) {
3211 default_monitor
= 0;
3214 case QEMU_OPTION_watchdog
:
3216 error_report("only one watchdog option may be given");
3221 case QEMU_OPTION_action
:
3222 olist
= qemu_find_opts("action");
3223 if (!qemu_opts_parse_noisily(olist
, optarg
, false)) {
3227 case QEMU_OPTION_watchdog_action
:
3228 if (select_watchdog_action(optarg
) == -1) {
3229 error_report("unknown -watchdog-action parameter");
3233 case QEMU_OPTION_parallel
:
3234 add_device_config(DEV_PARALLEL
, optarg
);
3235 default_parallel
= 0;
3236 if (strncmp(optarg
, "mon:", 4) == 0) {
3237 default_monitor
= 0;
3240 case QEMU_OPTION_debugcon
:
3241 add_device_config(DEV_DEBUGCON
, optarg
);
3243 case QEMU_OPTION_loadvm
:
3246 case QEMU_OPTION_full_screen
:
3247 dpy
.has_full_screen
= true;
3248 dpy
.full_screen
= true;
3250 case QEMU_OPTION_alt_grab
:
3252 warn_report("-alt-grab is deprecated, please use "
3253 "-display sdl,grab-mod=lshift-lctrl-lalt instead.");
3255 case QEMU_OPTION_ctrl_grab
:
3257 warn_report("-ctrl-grab is deprecated, please use "
3258 "-display sdl,grab-mod=rctrl instead.");
3260 case QEMU_OPTION_no_quit
:
3261 dpy
.has_window_close
= true;
3262 dpy
.window_close
= false;
3263 warn_report("-no-quit is deprecated, please use "
3264 "-display ...,window-close=off instead.");
3266 case QEMU_OPTION_sdl
:
3267 warn_report("-sdl is deprecated, use -display sdl instead.");
3269 dpy
.type
= DISPLAY_TYPE_SDL
;
3272 error_report("SDL support is disabled");
3275 case QEMU_OPTION_pidfile
:
3278 case QEMU_OPTION_win2k_hack
:
3279 win2k_install_hack
= 1;
3281 case QEMU_OPTION_acpitable
:
3282 opts
= qemu_opts_parse_noisily(qemu_find_opts("acpi"),
3287 acpi_table_add(opts
, &error_fatal
);
3289 case QEMU_OPTION_smbios
:
3290 opts
= qemu_opts_parse_noisily(qemu_find_opts("smbios"),
3295 smbios_entry_add(opts
, &error_fatal
);
3297 case QEMU_OPTION_fwcfg
:
3298 opts
= qemu_opts_parse_noisily(qemu_find_opts("fw_cfg"),
3304 case QEMU_OPTION_preconfig
:
3305 preconfig_requested
= true;
3307 case QEMU_OPTION_enable_kvm
:
3308 qdict_put_str(machine_opts_dict
, "accel", "kvm");
3311 case QEMU_OPTION_machine
:
3315 keyval_parse_into(machine_opts_dict
, optarg
, "type", &help
, &error_fatal
);
3317 machine_help_func(machine_opts_dict
);
3322 case QEMU_OPTION_accel
:
3323 accel_opts
= qemu_opts_parse_noisily(qemu_find_opts("accel"),
3325 optarg
= qemu_opt_get(accel_opts
, "accel");
3326 if (!optarg
|| is_help_option(optarg
)) {
3327 printf("Accelerators supported in QEMU binary:\n");
3328 GSList
*el
, *accel_list
= object_class_get_list(TYPE_ACCEL
,
3330 for (el
= accel_list
; el
; el
= el
->next
) {
3331 gchar
*typename
= g_strdup(object_class_get_name(
3332 OBJECT_CLASS(el
->data
)));
3333 /* omit qtest which is used for tests only */
3334 if (g_strcmp0(typename
, ACCEL_CLASS_NAME("qtest")) &&
3335 g_str_has_suffix(typename
, ACCEL_CLASS_SUFFIX
)) {
3336 gchar
**optname
= g_strsplit(typename
,
3337 ACCEL_CLASS_SUFFIX
, 0);
3338 printf("%s\n", optname
[0]);
3339 g_strfreev(optname
);
3343 g_slist_free(accel_list
);
3347 case QEMU_OPTION_usb
:
3348 qdict_put_str(machine_opts_dict
, "usb", "on");
3350 case QEMU_OPTION_usbdevice
:
3351 qdict_put_str(machine_opts_dict
, "usb", "on");
3352 add_device_config(DEV_USB
, optarg
);
3354 case QEMU_OPTION_device
:
3355 if (!qemu_opts_parse_noisily(qemu_find_opts("device"),
3360 case QEMU_OPTION_smp
:
3361 machine_parse_property_opt(qemu_find_opts("smp-opts"),
3364 case QEMU_OPTION_vnc
:
3367 case QEMU_OPTION_no_acpi
:
3368 qdict_put_str(machine_opts_dict
, "acpi", "off");
3370 case QEMU_OPTION_no_hpet
:
3371 qdict_put_str(machine_opts_dict
, "hpet", "off");
3373 case QEMU_OPTION_no_reboot
:
3374 olist
= qemu_find_opts("action");
3375 qemu_opts_parse_noisily(olist
, "reboot=shutdown", false);
3377 case QEMU_OPTION_no_shutdown
:
3378 olist
= qemu_find_opts("action");
3379 qemu_opts_parse_noisily(olist
, "shutdown=pause", false);
3381 case QEMU_OPTION_uuid
:
3382 if (qemu_uuid_parse(optarg
, &qemu_uuid
) < 0) {
3383 error_report("failed to parse UUID string: wrong format");
3386 qemu_uuid_set
= true;
3388 case QEMU_OPTION_option_rom
:
3389 if (nb_option_roms
>= MAX_OPTION_ROMS
) {
3390 error_report("too many option ROMs");
3393 opts
= qemu_opts_parse_noisily(qemu_find_opts("option-rom"),
3398 option_rom
[nb_option_roms
].name
= qemu_opt_get(opts
, "romfile");
3399 option_rom
[nb_option_roms
].bootindex
=
3400 qemu_opt_get_number(opts
, "bootindex", -1);
3401 if (!option_rom
[nb_option_roms
].name
) {
3402 error_report("Option ROM file is not specified");
3407 case QEMU_OPTION_semihosting
:
3408 qemu_semihosting_enable();
3410 case QEMU_OPTION_semihosting_config
:
3411 if (qemu_semihosting_config_options(optarg
) != 0) {
3415 case QEMU_OPTION_name
:
3416 opts
= qemu_opts_parse_noisily(qemu_find_opts("name"),
3421 /* Capture guest name if -msg guest-name is used later */
3422 error_guest_name
= qemu_opt_get(opts
, "guest");
3424 case QEMU_OPTION_prom_env
:
3425 if (nb_prom_envs
>= MAX_PROM_ENVS
) {
3426 error_report("too many prom variables");
3429 prom_envs
[nb_prom_envs
] = optarg
;
3432 case QEMU_OPTION_old_param
:
3435 case QEMU_OPTION_rtc
:
3436 opts
= qemu_opts_parse_noisily(qemu_find_opts("rtc"), optarg
,
3442 case QEMU_OPTION_icount
:
3443 icount_opts
= qemu_opts_parse_noisily(qemu_find_opts("icount"),
3449 case QEMU_OPTION_incoming
:
3451 runstate_set(RUN_STATE_INMIGRATE
);
3455 case QEMU_OPTION_only_migratable
:
3456 only_migratable
= 1;
3458 case QEMU_OPTION_nodefaults
:
3461 case QEMU_OPTION_xen_domid
:
3462 if (!(accel_find("xen"))) {
3463 error_report("Option not supported for this target");
3466 xen_domid
= atoi(optarg
);
3468 case QEMU_OPTION_xen_attach
:
3469 if (!(accel_find("xen"))) {
3470 error_report("Option not supported for this target");
3473 xen_mode
= XEN_ATTACH
;
3475 case QEMU_OPTION_xen_domid_restrict
:
3476 if (!(accel_find("xen"))) {
3477 error_report("Option not supported for this target");
3480 xen_domid_restrict
= true;
3482 case QEMU_OPTION_trace
:
3483 trace_opt_parse(optarg
);
3485 case QEMU_OPTION_plugin
:
3486 qemu_plugin_opt_parse(optarg
, &plugin_list
);
3488 case QEMU_OPTION_readconfig
:
3489 qemu_read_config_file(optarg
, qemu_parse_config_group
, &error_fatal
);
3491 case QEMU_OPTION_spice
:
3492 olist
= qemu_find_opts_err("spice", NULL
);
3494 error_report("spice support is disabled");
3497 opts
= qemu_opts_parse_noisily(olist
, optarg
, false);
3503 case QEMU_OPTION_writeconfig
:
3506 warn_report("-writeconfig is deprecated and will go away without a replacement");
3507 if (strcmp(optarg
, "-") == 0) {
3510 fp
= fopen(optarg
, "w");
3512 error_report("open %s: %s", optarg
,
3517 qemu_config_write(fp
);
3523 case QEMU_OPTION_qtest
:
3524 qtest_chrdev
= optarg
;
3526 case QEMU_OPTION_qtest_log
:
3529 case QEMU_OPTION_sandbox
:
3530 olist
= qemu_find_opts("sandbox");
3532 #ifndef CONFIG_SECCOMP
3533 error_report("-sandbox support is not enabled "
3534 "in this QEMU binary");
3539 opts
= qemu_opts_parse_noisily(olist
, optarg
, true);
3544 case QEMU_OPTION_add_fd
:
3546 opts
= qemu_opts_parse_noisily(qemu_find_opts("add-fd"),
3552 error_report("File descriptor passing is disabled on this "
3557 case QEMU_OPTION_object
:
3558 object_option_parse(optarg
);
3560 case QEMU_OPTION_overcommit
:
3561 opts
= qemu_opts_parse_noisily(qemu_find_opts("overcommit"),
3566 enable_mlock
= qemu_opt_get_bool(opts
, "mem-lock", false);
3567 enable_cpu_pm
= qemu_opt_get_bool(opts
, "cpu-pm", false);
3569 case QEMU_OPTION_compat
:
3574 v
= qobject_input_visitor_new_str(optarg
, NULL
,
3577 visit_type_CompatPolicy(v
, NULL
, &opts
, &error_fatal
);
3578 QAPI_CLONE_MEMBERS(CompatPolicy
, &compat_policy
, opts
);
3580 qapi_free_CompatPolicy(opts
);
3584 case QEMU_OPTION_msg
:
3585 opts
= qemu_opts_parse_noisily(qemu_find_opts("msg"), optarg
,
3590 configure_msg(opts
);
3592 case QEMU_OPTION_dump_vmstate
:
3593 if (vmstate_dump_file
) {
3594 error_report("only one '-dump-vmstate' "
3595 "option may be given");
3598 vmstate_dump_file
= fopen(optarg
, "w");
3599 if (vmstate_dump_file
== NULL
) {
3600 error_report("open %s: %s", optarg
, strerror(errno
));
3604 case QEMU_OPTION_enable_sync_profile
:
3607 case QEMU_OPTION_nouserconfig
:
3608 /* Nothing to be parsed here. Especially, do not error out below. */
3611 if (os_parse_cmd_args(popt
->index
, optarg
)) {
3612 error_report("Option not supported in this build");
3619 * Clear error location left behind by the loop.
3620 * Best done right after the loop. Do not insert code here!
3624 qemu_validate_options(machine_opts_dict
);
3625 qemu_process_sugar_options();
3628 * These options affect everything else and should be processed
3629 * before daemonizing.
3631 qemu_process_early_options();
3633 qemu_process_help_options();
3634 qemu_maybe_daemonize(pid_file
);
3637 * The trace backend must be initialized after daemonizing.
3638 * trace_init_backends() will call st_init(), which will create the
3639 * trace thread in the parent, and also register st_flush_trace_buffer()
3640 * in atexit(). This function will force the parent to wait for the
3641 * writeout thread to finish, which will not occur, and the parent
3642 * process will be left in the host.
3644 if (!trace_init_backends()) {
3649 qemu_init_main_loop(&error_fatal
);
3652 user_register_global_props();
3653 replay_configure(icount_opts
);
3655 configure_rtc(qemu_find_opts_singleton("rtc"));
3657 qemu_create_machine(machine_opts_dict
);
3661 qemu_disable_default_devices();
3662 qemu_create_default_devices();
3663 qemu_create_early_backends();
3665 qemu_apply_legacy_machine_options(machine_opts_dict
);
3666 qemu_apply_machine_options(machine_opts_dict
);
3667 qobject_unref(machine_opts_dict
);
3668 phase_advance(PHASE_MACHINE_CREATED
);
3671 * Note: uses machine properties such as kernel-irqchip, must run
3672 * after qemu_apply_machine_options.
3674 configure_accelerators(argv
[0]);
3675 phase_advance(PHASE_ACCEL_CREATED
);
3678 * Beware, QOM objects created before this point miss global and
3679 * compat properties.
3681 * Global properties get set up by qdev_prop_register_global(),
3682 * called from user_register_global_props(), and certain option
3683 * desugaring. Also in CPU feature desugaring (buried in
3684 * parse_cpu_option()), which happens below this point, but may
3685 * only target the CPU type, which can only be created after
3686 * parse_cpu_option() returned the type.
3688 * Machine compat properties: object_set_machine_compat_props().
3689 * Accelerator compat props: object_set_accelerator_compat_props(),
3690 * called from do_configure_accelerator().
3693 machine_class
= MACHINE_GET_CLASS(current_machine
);
3694 if (!qtest_enabled() && machine_class
->deprecation_reason
) {
3695 error_report("Machine type '%s' is deprecated: %s",
3696 machine_class
->name
, machine_class
->deprecation_reason
);
3700 * Note: creates a QOM object, must run only after global and
3701 * compat properties have been set up.
3703 migration_object_init();
3705 qemu_create_late_backends();
3707 /* parse features once if machine provides default cpu_type */
3708 current_machine
->cpu_type
= machine_class
->default_cpu_type
;
3710 current_machine
->cpu_type
= parse_cpu_option(cpu_option
);
3712 /* NB: for machine none cpu_type could STILL be NULL here! */
3714 qemu_resolve_machine_memdev();
3715 parse_numa_opts(current_machine
);
3717 if (vmstate_dump_file
) {
3719 dump_vmstate_json_to_file(vmstate_dump_file
);
3723 if (!preconfig_requested
) {
3724 qmp_x_exit_preconfig(&error_fatal
);
3726 qemu_init_displays();
3727 accel_setup_post(current_machine
);