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/help-texts.h"
27 #include "qemu/datadir.h"
28 #include "qemu/units.h"
29 #include "exec/cpu-common.h"
30 #include "exec/page-vary.h"
31 #include "hw/qdev-properties.h"
32 #include "qapi/compat-policy.h"
33 #include "qapi/error.h"
34 #include "qapi/qmp/qdict.h"
35 #include "qapi/qmp/qstring.h"
36 #include "qapi/qmp/qjson.h"
37 #include "qemu-version.h"
38 #include "qemu/cutils.h"
39 #include "qemu/help_option.h"
40 #include "qemu/hw-version.h"
41 #include "qemu/uuid.h"
42 #include "sysemu/reset.h"
43 #include "sysemu/runstate.h"
44 #include "sysemu/runstate-action.h"
45 #include "sysemu/seccomp.h"
46 #include "sysemu/tcg.h"
47 #include "sysemu/xen.h"
49 #include "qemu/error-report.h"
50 #include "qemu/sockets.h"
51 #include "qemu/accel.h"
52 #include "qemu/async-teardown.h"
54 #include "hw/isa/isa.h"
55 #include "hw/scsi/scsi.h"
56 #include "hw/display/vga.h"
57 #include "hw/firmware/smbios.h"
58 #include "hw/acpi/acpi.h"
59 #include "hw/xen/xen.h"
60 #include "hw/loader.h"
61 #include "monitor/qdev.h"
63 #include "net/slirp.h"
64 #include "monitor/monitor.h"
65 #include "ui/console.h"
67 #include "sysemu/sysemu.h"
68 #include "sysemu/numa.h"
69 #include "sysemu/hostmem.h"
70 #include "exec/gdbstub.h"
71 #include "gdbstub/enums.h"
72 #include "qemu/timer.h"
73 #include "chardev/char.h"
74 #include "qemu/bitmap.h"
76 #include "sysemu/blockdev.h"
77 #include "hw/block/block.h"
78 #include "hw/i386/x86.h"
79 #include "hw/i386/pc.h"
80 #include "migration/misc.h"
81 #include "migration/snapshot.h"
82 #include "sysemu/tpm.h"
83 #include "sysemu/dma.h"
84 #include "hw/audio/soundhw.h"
85 #include "audio/audio.h"
86 #include "sysemu/cpus.h"
87 #include "sysemu/cpu-timers.h"
88 #include "migration/colo.h"
89 #include "migration/postcopy-ram.h"
90 #include "sysemu/kvm.h"
91 #include "qapi/qobject-input-visitor.h"
92 #include "qemu/option.h"
93 #include "qemu/config-file.h"
94 #include "qemu/main-loop.h"
96 #include "fsdev/qemu-fsdev.h"
98 #include "sysemu/qtest.h"
100 #include "tcg/perf.h"
103 #include "disas/disas.h"
106 #include "trace/control.h"
107 #include "qemu/plugin.h"
108 #include "qemu/queue.h"
109 #include "sysemu/arch_init.h"
110 #include "exec/confidential-guest-support.h"
112 #include "ui/qemu-spice.h"
113 #include "qapi/string-input-visitor.h"
114 #include "qapi/opts-visitor.h"
115 #include "qapi/clone-visitor.h"
116 #include "qom/object_interfaces.h"
117 #include "semihosting/semihost.h"
118 #include "crypto/init.h"
119 #include "sysemu/replay.h"
120 #include "qapi/qapi-events-run-state.h"
121 #include "qapi/qapi-types-audio.h"
122 #include "qapi/qapi-visit-audio.h"
123 #include "qapi/qapi-visit-block-core.h"
124 #include "qapi/qapi-visit-compat.h"
125 #include "qapi/qapi-visit-machine.h"
126 #include "qapi/qapi-visit-ui.h"
127 #include "qapi/qapi-commands-block-core.h"
128 #include "qapi/qapi-commands-migration.h"
129 #include "qapi/qapi-commands-misc.h"
130 #include "qapi/qapi-visit-qom.h"
131 #include "qapi/qapi-commands-ui.h"
132 #include "block/qdict.h"
133 #include "qapi/qmp/qerror.h"
134 #include "sysemu/iothread.h"
135 #include "qemu/guest-random.h"
136 #include "qemu/keyval.h"
138 #define MAX_VIRTIO_CONSOLES 1
140 typedef struct BlockdevOptionsQueueEntry
{
141 BlockdevOptions
*bdo
;
143 QSIMPLEQ_ENTRY(BlockdevOptionsQueueEntry
) entry
;
144 } BlockdevOptionsQueueEntry
;
146 typedef QSIMPLEQ_HEAD(, BlockdevOptionsQueueEntry
) BlockdevOptionsQueue
;
148 typedef struct ObjectOption
{
150 QTAILQ_ENTRY(ObjectOption
) next
;
153 typedef struct DeviceOption
{
156 QTAILQ_ENTRY(DeviceOption
) next
;
159 static const char *cpu_option
;
160 static const char *mem_path
;
161 static const char *incoming
;
162 static const char *loadvm
;
163 static const char *accelerators
;
164 static bool have_custom_ram_size
;
165 static const char *ram_memdev_id
;
166 static QDict
*machine_opts_dict
;
167 static QTAILQ_HEAD(, ObjectOption
) object_opts
= QTAILQ_HEAD_INITIALIZER(object_opts
);
168 static QTAILQ_HEAD(, DeviceOption
) device_opts
= QTAILQ_HEAD_INITIALIZER(device_opts
);
169 static int display_remote
;
171 static bool preconfig_requested
;
172 static QemuPluginList plugin_list
= QTAILQ_HEAD_INITIALIZER(plugin_list
);
173 static BlockdevOptionsQueue bdo_queue
= QSIMPLEQ_HEAD_INITIALIZER(bdo_queue
);
174 static bool nographic
= false;
175 static int mem_prealloc
; /* force preallocation of physical target memory */
176 static const char *vga_model
= NULL
;
177 static DisplayOptions dpy
;
178 static int num_serial_hds
;
179 static Chardev
**serial_hds
;
180 static const char *log_mask
;
181 static const char *log_file
;
182 static bool list_data_dirs
;
183 static const char *qtest_chrdev
;
184 static const char *qtest_log
;
186 static int has_defaults
= 1;
187 static int default_audio
= 1;
188 static int default_serial
= 1;
189 static int default_parallel
= 1;
190 static int default_monitor
= 1;
191 static int default_floppy
= 1;
192 static int default_cdrom
= 1;
193 static int default_sdcard
= 1;
194 static int default_vga
= 1;
195 static int default_net
= 1;
197 static const struct {
201 { .driver
= "xen-console", .flag
= &default_serial
},
202 { .driver
= "isa-serial", .flag
= &default_serial
},
203 { .driver
= "isa-parallel", .flag
= &default_parallel
},
204 { .driver
= "isa-fdc", .flag
= &default_floppy
},
205 { .driver
= "floppy", .flag
= &default_floppy
},
206 { .driver
= "ide-cd", .flag
= &default_cdrom
},
207 { .driver
= "ide-hd", .flag
= &default_cdrom
},
208 { .driver
= "scsi-cd", .flag
= &default_cdrom
},
209 { .driver
= "scsi-hd", .flag
= &default_cdrom
},
210 { .driver
= "VGA", .flag
= &default_vga
},
211 { .driver
= "isa-vga", .flag
= &default_vga
},
212 { .driver
= "cirrus-vga", .flag
= &default_vga
},
213 { .driver
= "isa-cirrus-vga", .flag
= &default_vga
},
214 { .driver
= "vmware-svga", .flag
= &default_vga
},
215 { .driver
= "qxl-vga", .flag
= &default_vga
},
216 { .driver
= "virtio-vga", .flag
= &default_vga
},
217 { .driver
= "ati-vga", .flag
= &default_vga
},
218 { .driver
= "vhost-user-vga", .flag
= &default_vga
},
219 { .driver
= "virtio-vga-gl", .flag
= &default_vga
},
220 { .driver
= "virtio-vga-rutabaga", .flag
= &default_vga
},
223 static QemuOptsList qemu_rtc_opts
= {
225 .head
= QTAILQ_HEAD_INITIALIZER(qemu_rtc_opts
.head
),
230 .type
= QEMU_OPT_STRING
,
233 .type
= QEMU_OPT_STRING
,
236 .type
= QEMU_OPT_STRING
,
238 { /* end of list */ }
242 static QemuOptsList qemu_option_rom_opts
= {
243 .name
= "option-rom",
244 .implied_opt_name
= "romfile",
245 .head
= QTAILQ_HEAD_INITIALIZER(qemu_option_rom_opts
.head
),
249 .type
= QEMU_OPT_NUMBER
,
252 .type
= QEMU_OPT_STRING
,
254 { /* end of list */ }
258 static QemuOptsList qemu_accel_opts
= {
260 .implied_opt_name
= "accel",
261 .head
= QTAILQ_HEAD_INITIALIZER(qemu_accel_opts
.head
),
264 * no elements => accept any
265 * sanity checking will happen later
266 * when setting accelerator properties
272 static QemuOptsList qemu_boot_opts
= {
274 .implied_opt_name
= "order",
276 .head
= QTAILQ_HEAD_INITIALIZER(qemu_boot_opts
.head
),
280 .type
= QEMU_OPT_STRING
,
283 .type
= QEMU_OPT_STRING
,
286 .type
= QEMU_OPT_BOOL
,
289 .type
= QEMU_OPT_STRING
,
291 .name
= "splash-time",
292 .type
= QEMU_OPT_NUMBER
,
294 .name
= "reboot-timeout",
295 .type
= QEMU_OPT_NUMBER
,
298 .type
= QEMU_OPT_BOOL
,
304 static QemuOptsList qemu_add_fd_opts
= {
306 .head
= QTAILQ_HEAD_INITIALIZER(qemu_add_fd_opts
.head
),
310 .type
= QEMU_OPT_NUMBER
,
311 .help
= "file descriptor of which a duplicate is added to fd set",
314 .type
= QEMU_OPT_NUMBER
,
315 .help
= "ID of the fd set to add fd to",
318 .type
= QEMU_OPT_STRING
,
319 .help
= "free-form string used to describe fd",
321 { /* end of list */ }
325 static QemuOptsList qemu_object_opts
= {
327 .implied_opt_name
= "qom-type",
328 .head
= QTAILQ_HEAD_INITIALIZER(qemu_object_opts
.head
),
334 static QemuOptsList qemu_tpmdev_opts
= {
336 .implied_opt_name
= "type",
337 .head
= QTAILQ_HEAD_INITIALIZER(qemu_tpmdev_opts
.head
),
339 /* options are defined in the TPM backends */
340 { /* end of list */ }
344 static QemuOptsList qemu_overcommit_opts
= {
345 .name
= "overcommit",
346 .head
= QTAILQ_HEAD_INITIALIZER(qemu_overcommit_opts
.head
),
350 .type
= QEMU_OPT_BOOL
,
354 .type
= QEMU_OPT_BOOL
,
356 { /* end of list */ }
360 static QemuOptsList qemu_msg_opts
= {
362 .head
= QTAILQ_HEAD_INITIALIZER(qemu_msg_opts
.head
),
366 .type
= QEMU_OPT_BOOL
,
369 .name
= "guest-name",
370 .type
= QEMU_OPT_BOOL
,
371 .help
= "Prepends guest name for error messages but only if "
372 "-name guest is set otherwise option is ignored\n",
374 { /* end of list */ }
378 static QemuOptsList qemu_name_opts
= {
380 .implied_opt_name
= "guest",
382 .head
= QTAILQ_HEAD_INITIALIZER(qemu_name_opts
.head
),
386 .type
= QEMU_OPT_STRING
,
387 .help
= "Sets the name of the guest.\n"
388 "This name will be displayed in the SDL window caption.\n"
389 "The name will also be used for the VNC server",
392 .type
= QEMU_OPT_STRING
,
393 .help
= "Sets the name of the QEMU process, as shown in top etc",
395 .name
= "debug-threads",
396 .type
= QEMU_OPT_BOOL
,
397 .help
= "When enabled, name the individual threads; defaults off.\n"
398 "NOTE: The thread names are for debugging and not a\n"
401 { /* End of list */ }
405 static QemuOptsList qemu_mem_opts
= {
407 .implied_opt_name
= "size",
408 .head
= QTAILQ_HEAD_INITIALIZER(qemu_mem_opts
.head
),
413 .type
= QEMU_OPT_SIZE
,
417 .type
= QEMU_OPT_NUMBER
,
421 .type
= QEMU_OPT_SIZE
,
423 { /* end of list */ }
427 static QemuOptsList qemu_icount_opts
= {
429 .implied_opt_name
= "shift",
431 .head
= QTAILQ_HEAD_INITIALIZER(qemu_icount_opts
.head
),
435 .type
= QEMU_OPT_STRING
,
438 .type
= QEMU_OPT_BOOL
,
441 .type
= QEMU_OPT_BOOL
,
444 .type
= QEMU_OPT_STRING
,
447 .type
= QEMU_OPT_STRING
,
449 .name
= "rrsnapshot",
450 .type
= QEMU_OPT_STRING
,
452 { /* end of list */ }
456 static QemuOptsList qemu_fw_cfg_opts
= {
458 .implied_opt_name
= "name",
459 .head
= QTAILQ_HEAD_INITIALIZER(qemu_fw_cfg_opts
.head
),
463 .type
= QEMU_OPT_STRING
,
464 .help
= "Sets the fw_cfg name of the blob to be inserted",
467 .type
= QEMU_OPT_STRING
,
468 .help
= "Sets the name of the file from which "
469 "the fw_cfg blob will be loaded",
472 .type
= QEMU_OPT_STRING
,
473 .help
= "Sets content of the blob to be inserted from a string",
476 .type
= QEMU_OPT_STRING
,
477 .help
= "Sets id of the object generating the fw_cfg blob "
480 { /* end of list */ }
484 static QemuOptsList qemu_action_opts
= {
487 .head
= QTAILQ_HEAD_INITIALIZER(qemu_action_opts
.head
),
491 .type
= QEMU_OPT_STRING
,
494 .type
= QEMU_OPT_STRING
,
497 .type
= QEMU_OPT_STRING
,
500 .type
= QEMU_OPT_STRING
,
502 { /* end of list */ }
506 const char *qemu_get_vm_name(void)
511 static void default_driver_disable(const char *driver
)
519 for (i
= 0; i
< ARRAY_SIZE(default_list
); i
++) {
520 if (strcmp(default_list
[i
].driver
, driver
) != 0)
522 *(default_list
[i
].flag
) = 0;
526 static int default_driver_check(void *opaque
, QemuOpts
*opts
, Error
**errp
)
528 const char *driver
= qemu_opt_get(opts
, "driver");
530 default_driver_disable(driver
);
534 static void default_driver_check_json(void)
538 QTAILQ_FOREACH(opt
, &device_opts
, next
) {
539 const char *driver
= qdict_get_try_str(opt
->opts
, "driver");
540 default_driver_disable(driver
);
544 static int parse_name(void *opaque
, QemuOpts
*opts
, Error
**errp
)
546 const char *proc_name
;
548 if (qemu_opt_get(opts
, "debug-threads")) {
549 qemu_thread_naming(qemu_opt_get_bool(opts
, "debug-threads", false));
551 qemu_name
= qemu_opt_get(opts
, "guest");
553 proc_name
= qemu_opt_get(opts
, "process");
555 os_set_proc_name(proc_name
);
561 bool defaults_enabled(void)
567 static int parse_add_fd(void *opaque
, QemuOpts
*opts
, Error
**errp
)
569 int fd
, dupfd
, flags
;
571 const char *fd_opaque
= NULL
;
574 fd
= qemu_opt_get_number(opts
, "fd", -1);
575 fdset_id
= qemu_opt_get_number(opts
, "set", -1);
576 fd_opaque
= qemu_opt_get(opts
, "opaque");
579 error_setg(errp
, "fd option is required and must be non-negative");
583 if (fd
<= STDERR_FILENO
) {
584 error_setg(errp
, "fd cannot be a standard I/O stream");
589 * All fds inherited across exec() necessarily have FD_CLOEXEC
590 * clear, while qemu sets FD_CLOEXEC on all other fds used internally.
592 flags
= fcntl(fd
, F_GETFD
);
593 if (flags
== -1 || (flags
& FD_CLOEXEC
)) {
594 error_setg(errp
, "fd is not valid or already in use");
599 error_setg(errp
, "set option is required and must be non-negative");
603 #ifdef F_DUPFD_CLOEXEC
604 dupfd
= fcntl(fd
, F_DUPFD_CLOEXEC
, 0);
608 qemu_set_cloexec(dupfd
);
612 error_setg(errp
, "error duplicating fd: %s", strerror(errno
));
616 /* add the duplicate fd, and optionally the opaque string, to the fd set */
617 fdinfo
= monitor_fdset_add_fd(dupfd
, true, fdset_id
, fd_opaque
,
624 static int cleanup_add_fd(void *opaque
, QemuOpts
*opts
, Error
**errp
)
628 fd
= qemu_opt_get_number(opts
, "fd", -1);
635 /***********************************************************/
636 /* QEMU Block devices */
638 #define HD_OPTS "media=disk"
639 #define CDROM_OPTS "media=cdrom"
641 #define PFLASH_OPTS ""
645 static int drive_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
647 BlockInterfaceType
*block_default_type
= opaque
;
649 return drive_new(opts
, *block_default_type
, errp
) == NULL
;
652 static int drive_enable_snapshot(void *opaque
, QemuOpts
*opts
, Error
**errp
)
654 if (qemu_opt_get(opts
, "snapshot") == NULL
) {
655 qemu_opt_set(opts
, "snapshot", "on", &error_abort
);
660 static void default_drive(int enable
, int snapshot
, BlockInterfaceType type
,
661 int index
, const char *optstr
)
666 if (!enable
|| drive_get_by_index(type
, index
)) {
670 opts
= drive_add(type
, index
, NULL
, optstr
);
672 drive_enable_snapshot(NULL
, opts
, NULL
);
675 dinfo
= drive_new(opts
, type
, &error_abort
);
676 dinfo
->is_default
= true;
680 static void configure_blockdev(BlockdevOptionsQueue
*bdo_queue
,
681 MachineClass
*machine_class
, int snapshot
)
684 * If the currently selected machine wishes to override the
685 * units-per-bus property of its default HBA interface type, do so
688 if (machine_class
->units_per_default_bus
) {
689 override_max_devs(machine_class
->block_default_type
,
690 machine_class
->units_per_default_bus
);
693 /* open the virtual block devices */
694 while (!QSIMPLEQ_EMPTY(bdo_queue
)) {
695 BlockdevOptionsQueueEntry
*bdo
= QSIMPLEQ_FIRST(bdo_queue
);
697 QSIMPLEQ_REMOVE_HEAD(bdo_queue
, entry
);
698 loc_push_restore(&bdo
->loc
);
699 qmp_blockdev_add(bdo
->bdo
, &error_fatal
);
701 qapi_free_BlockdevOptions(bdo
->bdo
);
705 qemu_opts_foreach(qemu_find_opts("drive"), drive_enable_snapshot
,
708 if (qemu_opts_foreach(qemu_find_opts("drive"), drive_init_func
,
709 &machine_class
->block_default_type
, &error_fatal
)) {
710 /* We printed help */
714 default_drive(default_cdrom
, snapshot
, machine_class
->block_default_type
, 2,
716 default_drive(default_floppy
, snapshot
, IF_FLOPPY
, 0, FD_OPTS
);
717 default_drive(default_sdcard
, snapshot
, IF_SD
, 0, SD_OPTS
);
721 static QemuOptsList qemu_smp_opts
= {
723 .implied_opt_name
= "cpus",
725 .head
= QTAILQ_HEAD_INITIALIZER(qemu_smp_opts
.head
),
729 .type
= QEMU_OPT_NUMBER
,
732 .type
= QEMU_OPT_NUMBER
,
735 .type
= QEMU_OPT_NUMBER
,
738 .type
= QEMU_OPT_NUMBER
,
741 .type
= QEMU_OPT_NUMBER
,
744 .type
= QEMU_OPT_NUMBER
,
747 .type
= QEMU_OPT_NUMBER
,
750 .type
= QEMU_OPT_NUMBER
,
753 .type
= QEMU_OPT_NUMBER
,
756 .type
= QEMU_OPT_NUMBER
,
762 #if defined(CONFIG_POSIX)
763 static QemuOptsList qemu_run_with_opts
= {
765 .head
= QTAILQ_HEAD_INITIALIZER(qemu_run_with_opts
.head
),
767 #if defined(CONFIG_LINUX)
769 .name
= "async-teardown",
770 .type
= QEMU_OPT_BOOL
,
775 .type
= QEMU_OPT_STRING
,
779 .type
= QEMU_OPT_STRING
,
781 { /* end of list */ }
785 #define qemu_add_run_with_opts() qemu_add_opts(&qemu_run_with_opts)
789 #define qemu_add_run_with_opts()
791 #endif /* CONFIG_POSIX */
793 static void realtime_init(void)
796 if (os_mlock() < 0) {
797 error_report("locking memory failed");
804 static void configure_msg(QemuOpts
*opts
)
806 message_with_timestamp
= qemu_opt_get_bool(opts
, "timestamp", false);
807 error_with_guestname
= qemu_opt_get_bool(opts
, "guest-name", false);
811 /***********************************************************/
814 static int usb_device_add(const char *devname
)
816 USBDevice
*dev
= NULL
;
818 if (!machine_usb(current_machine
)) {
822 dev
= usbdevice_create(devname
);
829 static int usb_parse(const char *cmdline
)
832 r
= usb_device_add(cmdline
);
834 error_report("could not add USB device '%s'", cmdline
);
839 /***********************************************************/
840 /* machine registration */
842 static MachineClass
*find_machine(const char *name
, GSList
*machines
)
846 for (el
= machines
; el
; el
= el
->next
) {
847 MachineClass
*mc
= el
->data
;
849 if (!strcmp(mc
->name
, name
) || !g_strcmp0(mc
->alias
, name
)) {
857 static MachineClass
*find_default_machine(GSList
*machines
)
860 MachineClass
*default_machineclass
= NULL
;
862 for (el
= machines
; el
; el
= el
->next
) {
863 MachineClass
*mc
= el
->data
;
865 if (mc
->is_default
) {
866 assert(default_machineclass
== NULL
&& "Multiple default machines");
867 default_machineclass
= mc
;
871 return default_machineclass
;
874 static void version(void)
876 printf("QEMU emulator version " QEMU_FULL_VERSION
"\n"
877 QEMU_COPYRIGHT
"\n");
880 static void help(int exitcode
)
883 printf("usage: %s [options] [disk_image]\n\n"
884 "'disk_image' is a raw hard disk image for IDE hard disk 0\n\n",
887 #define DEF(option, opt_arg, opt_enum, opt_help, arch_mask) \
888 if ((arch_mask) & arch_type) \
889 fputs(opt_help, stdout);
891 #define ARCHHEADING(text, arch_mask) \
892 if ((arch_mask) & arch_type) \
893 puts(stringify(text));
895 #define DEFHEADING(text) ARCHHEADING(text, QEMU_ARCH_ALL)
897 #include "qemu-options.def"
899 printf("\nDuring emulation, the following keys are useful:\n"
900 "ctrl-alt-f toggle full screen\n"
901 "ctrl-alt-n switch to virtual console 'n'\n"
902 "ctrl-alt-g toggle mouse and keyboard grab\n"
904 "When using -nographic, press 'ctrl-a h' to get some help.\n"
906 QEMU_HELP_BOTTOM
"\n");
913 #define DEF(option, opt_arg, opt_enum, opt_help, arch_mask) \
915 #define DEFHEADING(text)
916 #define ARCHHEADING(text, arch_mask)
918 #include "qemu-options.def"
921 #define HAS_ARG 0x0001
923 typedef struct QEMUOption
{
930 static const QEMUOption qemu_options
[] = {
931 { "h", 0, QEMU_OPTION_h
, QEMU_ARCH_ALL
},
933 #define DEF(option, opt_arg, opt_enum, opt_help, arch_mask) \
934 { option, opt_arg, opt_enum, arch_mask },
935 #define DEFHEADING(text)
936 #define ARCHHEADING(text, arch_mask)
938 #include "qemu-options.def"
939 { /* end of list */ }
942 typedef struct VGAInterfaceInfo
{
943 const char *opt_name
; /* option name */
944 const char *name
; /* human-readable name */
945 /* Class names indicating that support is available.
946 * If no class is specified, the interface is always available */
947 const char *class_names
[2];
950 static const VGAInterfaceInfo vga_interfaces
[VGA_TYPE_MAX
] = {
953 .name
= "no graphic card",
957 .name
= "standard VGA",
958 .class_names
= { "VGA", "isa-vga" },
961 .opt_name
= "cirrus",
962 .name
= "Cirrus VGA",
963 .class_names
= { "cirrus-vga", "isa-cirrus-vga" },
966 .opt_name
= "vmware",
967 .name
= "VMWare SVGA",
968 .class_names
= { "vmware-svga" },
971 .opt_name
= "virtio",
972 .name
= "Virtio VGA",
973 .class_names
= { "virtio-vga" },
978 .class_names
= { "qxl-vga" },
982 .name
= "TCX framebuffer",
983 .class_names
= { "sun-tcx" },
987 .name
= "CG3 framebuffer",
988 .class_names
= { "cgthree" },
990 #ifdef CONFIG_XEN_BACKEND
993 .name
= "Xen paravirtualized framebuffer",
998 static bool vga_interface_available(VGAInterfaceType t
)
1000 const VGAInterfaceInfo
*ti
= &vga_interfaces
[t
];
1002 assert(t
< VGA_TYPE_MAX
);
1004 if (!ti
->class_names
[0] || module_object_class_by_name(ti
->class_names
[0])) {
1008 if (ti
->class_names
[1] && module_object_class_by_name(ti
->class_names
[1])) {
1016 get_default_vga_model(const MachineClass
*machine_class
)
1018 if (machine_class
->default_display
) {
1019 for (int t
= 0; t
< VGA_TYPE_MAX
; t
++) {
1020 const VGAInterfaceInfo
*ti
= &vga_interfaces
[t
];
1022 if (ti
->opt_name
&& vga_interface_available(t
) &&
1023 g_str_equal(ti
->opt_name
, machine_class
->default_display
)) {
1024 return machine_class
->default_display
;
1028 warn_report_once("Default display '%s' is not available in this binary",
1029 machine_class
->default_display
);
1031 } else if (vga_interface_available(VGA_CIRRUS
)) {
1033 } else if (vga_interface_available(VGA_STD
)) {
1040 static void select_vgahw(const MachineClass
*machine_class
, const char *p
)
1045 if (g_str_equal(p
, "help")) {
1046 const char *def
= get_default_vga_model(machine_class
);
1048 for (t
= 0; t
< VGA_TYPE_MAX
; t
++) {
1049 const VGAInterfaceInfo
*ti
= &vga_interfaces
[t
];
1051 if (vga_interface_available(t
) && ti
->opt_name
) {
1052 printf("%-20s %s%s\n", ti
->opt_name
, ti
->name
?: "",
1053 (def
&& g_str_equal(ti
->opt_name
, def
)) ?
1060 assert(vga_interface_type
== VGA_NONE
);
1061 for (t
= 0; t
< VGA_TYPE_MAX
; t
++) {
1062 const VGAInterfaceInfo
*ti
= &vga_interfaces
[t
];
1063 if (ti
->opt_name
&& strstart(p
, ti
->opt_name
, &opts
)) {
1064 if (!vga_interface_available(t
)) {
1065 error_report("%s not available", ti
->name
);
1068 vga_interface_type
= t
;
1072 if (t
== VGA_TYPE_MAX
) {
1074 error_report("unknown vga type: %s", p
);
1078 const char *nextopt
;
1080 if (strstart(opts
, ",retrace=", &nextopt
)) {
1082 if (strstart(opts
, "dumb", &nextopt
))
1083 vga_retrace_method
= VGA_RETRACE_DUMB
;
1084 else if (strstart(opts
, "precise", &nextopt
))
1085 vga_retrace_method
= VGA_RETRACE_PRECISE
;
1086 else goto invalid_vga
;
1087 } else goto invalid_vga
;
1092 static void parse_display_qapi(const char *str
)
1094 DisplayOptions
*opts
;
1097 v
= qobject_input_visitor_new_str(str
, "type", &error_fatal
);
1099 visit_type_DisplayOptions(v
, NULL
, &opts
, &error_fatal
);
1100 QAPI_CLONE_MEMBERS(DisplayOptions
, &dpy
, opts
);
1102 qapi_free_DisplayOptions(opts
);
1106 DisplayOptions
*qmp_query_display_options(Error
**errp
)
1108 return QAPI_CLONE(DisplayOptions
, &dpy
);
1111 static void parse_display(const char *p
)
1113 if (is_help_option(p
)) {
1114 qemu_display_help();
1121 if (strstart(p
, "vnc", &opts
)) {
1123 * vnc isn't a (local) DisplayType but a protocol for remote
1127 vnc_parse(opts
+ 1);
1130 error_report("VNC requires a display argument vnc=<display>");
1137 parse_display_qapi(p
);
1140 static inline bool nonempty_str(const char *str
)
1145 static int parse_fw_cfg(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1149 const char *name
, *file
, *str
, *gen_id
;
1150 FWCfgState
*fw_cfg
= (FWCfgState
*) opaque
;
1152 if (fw_cfg
== NULL
) {
1153 error_setg(errp
, "fw_cfg device not available");
1156 name
= qemu_opt_get(opts
, "name");
1157 file
= qemu_opt_get(opts
, "file");
1158 str
= qemu_opt_get(opts
, "string");
1159 gen_id
= qemu_opt_get(opts
, "gen_id");
1161 /* we need the name, and exactly one of: file, content string, gen_id */
1162 if (!nonempty_str(name
) ||
1163 nonempty_str(file
) + nonempty_str(str
) + nonempty_str(gen_id
) != 1) {
1164 error_setg(errp
, "name, plus exactly one of file,"
1165 " string and gen_id, are needed");
1168 if (strlen(name
) > FW_CFG_MAX_FILE_PATH
- 1) {
1169 error_setg(errp
, "name too long (max. %d char)",
1170 FW_CFG_MAX_FILE_PATH
- 1);
1173 if (nonempty_str(gen_id
)) {
1175 * In this particular case where the content is populated
1176 * internally, the "etc/" namespace protection is relaxed,
1177 * so do not emit a warning.
1179 } else if (strncmp(name
, "opt/", 4) != 0) {
1180 warn_report("externally provided fw_cfg item names "
1181 "should be prefixed with \"opt/\"");
1183 if (nonempty_str(str
)) {
1184 size
= strlen(str
); /* NUL terminator NOT included in fw_cfg blob */
1185 buf
= g_memdup(str
, size
);
1186 } else if (nonempty_str(gen_id
)) {
1187 if (!fw_cfg_add_from_generator(fw_cfg
, name
, gen_id
, errp
)) {
1193 if (!g_file_get_contents(file
, &buf
, &size
, &err
)) {
1194 error_setg(errp
, "can't load %s: %s", file
, err
->message
);
1199 /* For legacy, keep user files in a specific global order. */
1200 fw_cfg_set_order_override(fw_cfg
, FW_CFG_ORDER_OVERRIDE_USER
);
1201 fw_cfg_add_file(fw_cfg
, name
, buf
, size
);
1202 fw_cfg_reset_order_override(fw_cfg
);
1206 static int device_help_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1208 return qdev_device_help(opts
);
1211 static int device_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1215 dev
= qdev_device_add(opts
, errp
);
1216 if (!dev
&& *errp
) {
1217 error_report_err(*errp
);
1220 object_unref(OBJECT(dev
));
1225 static int chardev_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1227 Error
*local_err
= NULL
;
1229 if (!qemu_chr_new_from_opts(opts
, NULL
, &local_err
)) {
1231 error_propagate(errp
, local_err
);
1239 #ifdef CONFIG_VIRTFS
1240 static int fsdev_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1242 return qemu_fsdev_add(opts
, errp
);
1246 static int mon_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1248 return monitor_init_opts(opts
, errp
);
1251 static void monitor_parse(const char *str
, const char *mode
, bool pretty
)
1253 static int monitor_device_index
= 0;
1258 if (strstart(str
, "chardev:", &p
)) {
1259 snprintf(label
, sizeof(label
), "%s", p
);
1261 snprintf(label
, sizeof(label
), "compat_monitor%d",
1262 monitor_device_index
);
1263 opts
= qemu_chr_parse_compat(label
, str
, true);
1265 error_report("parse error: %s", str
);
1270 opts
= qemu_opts_create(qemu_find_opts("mon"), label
, 1, &error_fatal
);
1271 qemu_opt_set(opts
, "mode", mode
, &error_abort
);
1272 qemu_opt_set(opts
, "chardev", label
, &error_abort
);
1273 if (!strcmp(mode
, "control")) {
1274 qemu_opt_set_bool(opts
, "pretty", pretty
, &error_abort
);
1276 assert(pretty
== false);
1278 monitor_device_index
++;
1281 struct device_config
{
1283 DEV_USB
, /* -usbdevice */
1284 DEV_SERIAL
, /* -serial */
1285 DEV_PARALLEL
, /* -parallel */
1286 DEV_DEBUGCON
, /* -debugcon */
1287 DEV_GDB
, /* -gdb, -s */
1288 DEV_SCLP
, /* s390 sclp */
1290 const char *cmdline
;
1292 QTAILQ_ENTRY(device_config
) next
;
1295 static QTAILQ_HEAD(, device_config
) device_configs
=
1296 QTAILQ_HEAD_INITIALIZER(device_configs
);
1298 static void add_device_config(int type
, const char *cmdline
)
1300 struct device_config
*conf
;
1302 conf
= g_malloc0(sizeof(*conf
));
1304 conf
->cmdline
= cmdline
;
1305 loc_save(&conf
->loc
);
1306 QTAILQ_INSERT_TAIL(&device_configs
, conf
, next
);
1309 static int foreach_device_config(int type
, int (*func
)(const char *cmdline
))
1311 struct device_config
*conf
;
1314 QTAILQ_FOREACH(conf
, &device_configs
, next
) {
1315 if (conf
->type
!= type
)
1317 loc_push_restore(&conf
->loc
);
1318 rc
= func(conf
->cmdline
);
1319 loc_pop(&conf
->loc
);
1327 static void qemu_disable_default_devices(void)
1329 MachineClass
*machine_class
= MACHINE_GET_CLASS(current_machine
);
1331 default_driver_check_json();
1332 qemu_opts_foreach(qemu_find_opts("device"),
1333 default_driver_check
, NULL
, NULL
);
1334 qemu_opts_foreach(qemu_find_opts("global"),
1335 default_driver_check
, NULL
, NULL
);
1337 if (!vga_model
&& !default_vga
) {
1338 vga_interface_type
= VGA_DEVICE
;
1339 vga_interface_created
= true;
1341 if (!has_defaults
|| machine_class
->no_serial
) {
1344 if (!has_defaults
|| machine_class
->no_parallel
) {
1345 default_parallel
= 0;
1347 if (!has_defaults
|| machine_class
->no_floppy
) {
1350 if (!has_defaults
|| machine_class
->no_cdrom
) {
1353 if (!has_defaults
|| machine_class
->no_sdcard
) {
1356 if (!has_defaults
) {
1358 default_monitor
= 0;
1362 if (default_net
&& machine_class
->default_nic
&&
1363 !module_object_class_by_name(machine_class
->default_nic
)) {
1364 warn_report("Default NIC '%s' is not available in this binary",
1365 machine_class
->default_nic
);
1371 static void qemu_setup_display(void)
1373 if (dpy
.type
== DISPLAY_TYPE_DEFAULT
&& !display_remote
) {
1374 if (!qemu_display_find_default(&dpy
)) {
1375 dpy
.type
= DISPLAY_TYPE_NONE
;
1376 #if defined(CONFIG_VNC)
1377 vnc_parse("localhost:0,to=99,id=default");
1382 if (dpy
.type
== DISPLAY_TYPE_DEFAULT
) {
1383 dpy
.type
= DISPLAY_TYPE_NONE
;
1386 qemu_display_early_init(&dpy
);
1389 static void qemu_create_default_devices(void)
1391 MachineClass
*machine_class
= MACHINE_GET_CLASS(current_machine
);
1392 const char *vc
= qemu_display_get_vc(&dpy
);
1394 if (is_daemonized()) {
1395 /* According to documentation and historically, -nographic redirects
1396 * serial port, parallel port and monitor to stdio, which does not work
1397 * with -daemonize. We can redirect these to null instead, but since
1398 * -nographic is legacy, let's just error out.
1399 * We disallow -nographic only if all other ports are not redirected
1400 * explicitly, to not break existing legacy setups which uses
1401 * -nographic _and_ redirects all ports explicitly - this is valid
1402 * usage, -nographic is just a no-op in this case.
1405 && (default_parallel
|| default_serial
|| default_monitor
)) {
1406 error_report("-nographic cannot be used with -daemonize");
1412 if (default_parallel
) {
1413 add_device_config(DEV_PARALLEL
, "null");
1415 if (default_serial
&& default_monitor
) {
1416 add_device_config(DEV_SERIAL
, "mon:stdio");
1418 if (default_serial
) {
1419 add_device_config(DEV_SERIAL
, "stdio");
1421 if (default_monitor
) {
1422 monitor_parse("stdio", "readline", false);
1426 if (default_serial
) {
1427 add_device_config(DEV_SERIAL
, vc
?: "null");
1429 if (default_parallel
) {
1430 add_device_config(DEV_PARALLEL
, vc
?: "null");
1432 if (default_monitor
&& vc
) {
1433 monitor_parse(vc
, "readline", false);
1438 QemuOptsList
*net
= qemu_find_opts("net");
1439 qemu_opts_parse(net
, "nic", true, &error_abort
);
1441 qemu_opts_parse(net
, "user", true, &error_abort
);
1445 /* If no default VGA is requested, the default is "none". */
1447 vga_model
= get_default_vga_model(machine_class
);
1450 select_vgahw(machine_class
, vga_model
);
1454 static int serial_parse(const char *devname
)
1456 int index
= num_serial_hds
;
1458 serial_hds
= g_renew(Chardev
*, serial_hds
, index
+ 1);
1460 if (strcmp(devname
, "none") == 0) {
1461 /* Don't allocate a serial device for this index */
1462 serial_hds
[index
] = NULL
;
1465 snprintf(label
, sizeof(label
), "serial%d", index
);
1467 serial_hds
[index
] = qemu_chr_new_mux_mon(label
, devname
, NULL
);
1468 if (!serial_hds
[index
]) {
1469 error_report("could not connect serial device"
1470 " to character backend '%s'", devname
);
1478 Chardev
*serial_hd(int i
)
1481 if (i
< num_serial_hds
) {
1482 return serial_hds
[i
];
1487 static int parallel_parse(const char *devname
)
1489 static int index
= 0;
1492 if (strcmp(devname
, "none") == 0)
1494 if (index
== MAX_PARALLEL_PORTS
) {
1495 error_report("too many parallel ports");
1498 snprintf(label
, sizeof(label
), "parallel%d", index
);
1499 parallel_hds
[index
] = qemu_chr_new_mux_mon(label
, devname
, NULL
);
1500 if (!parallel_hds
[index
]) {
1501 error_report("could not connect parallel device"
1502 " to character backend '%s'", devname
);
1509 static int debugcon_parse(const char *devname
)
1513 if (!qemu_chr_new_mux_mon("debugcon", devname
, NULL
)) {
1514 error_report("invalid character backend '%s'", devname
);
1517 opts
= qemu_opts_create(qemu_find_opts("device"), "debugcon", 1, NULL
);
1519 error_report("already have a debugcon device");
1522 qemu_opt_set(opts
, "driver", "isa-debugcon", &error_abort
);
1523 qemu_opt_set(opts
, "chardev", "debugcon", &error_abort
);
1527 static gint
machine_class_cmp(gconstpointer a
, gconstpointer b
)
1529 const MachineClass
*mc1
= a
, *mc2
= b
;
1532 if (mc1
->family
== NULL
) {
1533 if (mc2
->family
== NULL
) {
1534 /* Compare standalone machine types against each other; they sort
1535 * in increasing order.
1537 return strcmp(object_class_get_name(OBJECT_CLASS(mc1
)),
1538 object_class_get_name(OBJECT_CLASS(mc2
)));
1541 /* Standalone machine types sort after families. */
1545 if (mc2
->family
== NULL
) {
1546 /* Families sort before standalone machine types. */
1550 /* Families sort between each other alphabetically increasingly. */
1551 res
= strcmp(mc1
->family
, mc2
->family
);
1556 /* Within the same family, machine types sort in decreasing order. */
1557 return strcmp(object_class_get_name(OBJECT_CLASS(mc2
)),
1558 object_class_get_name(OBJECT_CLASS(mc1
)));
1561 static void machine_help_func(const QDict
*qdict
)
1563 g_autoptr(GSList
) machines
= NULL
;
1565 const char *type
= qdict_get_try_str(qdict
, "type");
1567 machines
= object_class_get_list(TYPE_MACHINE
, false);
1569 ObjectClass
*machine_class
= OBJECT_CLASS(find_machine(type
, machines
));
1570 if (machine_class
) {
1571 type_print_class_properties(object_class_get_name(machine_class
));
1576 printf("Supported machines are:\n");
1577 machines
= g_slist_sort(machines
, machine_class_cmp
);
1578 for (el
= machines
; el
; el
= el
->next
) {
1579 MachineClass
*mc
= el
->data
;
1581 printf("%-20s %s (alias of %s)\n", mc
->alias
, mc
->desc
, mc
->name
);
1583 printf("%-20s %s%s%s\n", mc
->name
, mc
->desc
,
1584 mc
->is_default
? " (default)" : "",
1585 mc
->deprecation_reason
? " (deprecated)" : "");
1590 machine_merge_property(const char *propname
, QDict
*prop
, Error
**errp
)
1595 /* Preserve the caller's reference to prop. */
1597 qdict_put(opts
, propname
, prop
);
1598 keyval_merge(machine_opts_dict
, opts
, errp
);
1599 qobject_unref(opts
);
1603 machine_parse_property_opt(QemuOptsList
*opts_list
, const char *propname
,
1609 prop
= keyval_parse(arg
, opts_list
->implied_opt_name
, &help
, &error_fatal
);
1611 qemu_opts_print_help(opts_list
, true);
1614 machine_merge_property(propname
, prop
, &error_fatal
);
1615 qobject_unref(prop
);
1618 static const char *pid_file
;
1619 struct UnlinkPidfileNotifier
{
1621 char *pid_file_realpath
;
1623 static struct UnlinkPidfileNotifier qemu_unlink_pidfile_notifier
;
1625 static void qemu_unlink_pidfile(Notifier
*n
, void *data
)
1627 struct UnlinkPidfileNotifier
*upn
;
1629 upn
= DO_UPCAST(struct UnlinkPidfileNotifier
, notifier
, n
);
1630 unlink(upn
->pid_file_realpath
);
1633 static const QEMUOption
*lookup_opt(int argc
, char **argv
,
1634 const char **poptarg
, int *poptind
)
1636 const QEMUOption
*popt
;
1637 int optind
= *poptind
;
1638 char *r
= argv
[optind
];
1641 loc_set_cmdline(argv
, optind
, 1);
1643 /* Treat --foo the same as -foo. */
1646 popt
= qemu_options
;
1649 error_report("invalid option");
1652 if (!strcmp(popt
->name
, r
+ 1))
1656 if (popt
->flags
& HAS_ARG
) {
1657 if (optind
>= argc
) {
1658 error_report("requires an argument");
1661 optarg
= argv
[optind
++];
1662 loc_set_cmdline(argv
, optind
- 2, 2);
1673 static MachineClass
*select_machine(QDict
*qdict
, Error
**errp
)
1676 const char *machine_type
= qdict_get_try_str(qdict
, "type");
1677 g_autoptr(GSList
) machines
= object_class_get_list(TYPE_MACHINE
, false);
1678 MachineClass
*machine_class
= NULL
;
1681 machine_class
= find_machine(machine_type
, machines
);
1682 qdict_del(qdict
, "type");
1683 if (!machine_class
) {
1684 error_setg(errp
, "unsupported machine type: \"%s\"", optarg
);
1687 machine_class
= find_default_machine(machines
);
1688 if (!machine_class
) {
1689 error_setg(errp
, "No machine specified, and there is no default");
1693 if (!machine_class
) {
1694 error_append_hint(errp
,
1695 "Use -machine help to list supported machines\n");
1697 return machine_class
;
1700 static int object_parse_property_opt(Object
*obj
,
1701 const char *name
, const char *value
,
1702 const char *skip
, Error
**errp
)
1704 if (g_str_equal(name
, skip
)) {
1708 if (!object_property_parse(obj
, name
, value
, errp
)) {
1715 /* *Non*recursively replace underscores with dashes in QDict keys. */
1716 static void keyval_dashify(QDict
*qdict
, Error
**errp
)
1718 const QDictEntry
*ent
, *next
;
1721 for (ent
= qdict_first(qdict
); ent
; ent
= next
) {
1722 g_autofree
char *new_key
= NULL
;
1724 next
= qdict_next(qdict
, ent
);
1725 if (!strchr(ent
->key
, '_')) {
1728 new_key
= g_strdup(ent
->key
);
1729 for (p
= new_key
; *p
; p
++) {
1734 if (qdict_haskey(qdict
, new_key
)) {
1735 error_setg(errp
, "Conflict between '%s' and '%s'", ent
->key
, new_key
);
1738 qobject_ref(ent
->value
);
1739 qdict_put_obj(qdict
, new_key
, ent
->value
);
1740 qdict_del(qdict
, ent
->key
);
1744 static void qemu_apply_legacy_machine_options(QDict
*qdict
)
1749 keyval_dashify(qdict
, &error_fatal
);
1751 /* Legacy options do not correspond to MachineState properties. */
1752 value
= qdict_get_try_str(qdict
, "accel");
1754 accelerators
= g_strdup(value
);
1755 qdict_del(qdict
, "accel");
1758 value
= qdict_get_try_str(qdict
, "igd-passthru");
1760 object_register_sugar_prop(ACCEL_CLASS_NAME("xen"), "igd-passthru", value
,
1762 qdict_del(qdict
, "igd-passthru");
1765 value
= qdict_get_try_str(qdict
, "kvm-shadow-mem");
1767 object_register_sugar_prop(ACCEL_CLASS_NAME("kvm"), "kvm-shadow-mem", value
,
1769 qdict_del(qdict
, "kvm-shadow-mem");
1772 value
= qdict_get_try_str(qdict
, "kernel-irqchip");
1774 object_register_sugar_prop(ACCEL_CLASS_NAME("kvm"), "kernel-irqchip", value
,
1776 object_register_sugar_prop(ACCEL_CLASS_NAME("whpx"), "kernel-irqchip", value
,
1778 qdict_del(qdict
, "kernel-irqchip");
1781 value
= qdict_get_try_str(qdict
, "memory-backend");
1784 error_report("'-mem-path' can't be used together with"
1785 "'-machine memory-backend'");
1789 /* Resolved later. */
1790 ram_memdev_id
= g_strdup(value
);
1791 qdict_del(qdict
, "memory-backend");
1794 prop
= qdict_get(qdict
, "memory");
1796 have_custom_ram_size
=
1797 qobject_type(prop
) == QTYPE_QDICT
&&
1798 qdict_haskey(qobject_to(QDict
, prop
), "size");
1802 static void object_option_foreach_add(bool (*type_opt_predicate
)(const char *))
1804 ObjectOption
*opt
, *next
;
1806 QTAILQ_FOREACH_SAFE(opt
, &object_opts
, next
, next
) {
1807 const char *type
= ObjectType_str(opt
->opts
->qom_type
);
1808 if (type_opt_predicate(type
)) {
1809 user_creatable_add_qapi(opt
->opts
, &error_fatal
);
1810 qapi_free_ObjectOptions(opt
->opts
);
1811 QTAILQ_REMOVE(&object_opts
, opt
, next
);
1817 static void object_option_add_visitor(Visitor
*v
)
1819 ObjectOption
*opt
= g_new0(ObjectOption
, 1);
1820 visit_type_ObjectOptions(v
, NULL
, &opt
->opts
, &error_fatal
);
1821 QTAILQ_INSERT_TAIL(&object_opts
, opt
, next
);
1824 static void object_option_parse(const char *str
)
1830 if (str
[0] == '{') {
1831 QObject
*obj
= qobject_from_json(str
, &error_fatal
);
1833 v
= qobject_input_visitor_new(obj
);
1836 opts
= qemu_opts_parse_noisily(qemu_find_opts("object"),
1842 type
= qemu_opt_get(opts
, "qom-type");
1844 error_setg(&error_fatal
, QERR_MISSING_PARAMETER
, "qom-type");
1846 if (user_creatable_print_help(type
, opts
)) {
1850 v
= opts_visitor_new(opts
);
1853 object_option_add_visitor(v
);
1858 * Very early object creation, before the sandbox options have been activated.
1860 static bool object_create_pre_sandbox(const char *type
)
1863 * Objects should in general not get initialized "too early" without
1864 * a reason. If you add one, state the reason in a comment!
1868 * Reason: -sandbox on,resourcecontrol=deny disallows setting CPU
1869 * affinity of threads.
1871 if (g_str_equal(type
, "thread-context")) {
1879 * Initial object creation happens before all other
1880 * QEMU data types are created. The majority of objects
1881 * can be created at this point. The rng-egd object
1882 * cannot be created here, as it depends on the chardev
1885 static bool object_create_early(const char *type
)
1888 * Objects should not be made "delayed" without a reason. If you
1889 * add one, state the reason in a comment!
1892 /* Reason: already created. */
1893 if (object_create_pre_sandbox(type
)) {
1897 /* Reason: property "chardev" */
1898 if (g_str_equal(type
, "rng-egd") ||
1899 g_str_equal(type
, "qtest")) {
1903 #if defined(CONFIG_VHOST_USER) && defined(CONFIG_LINUX)
1904 /* Reason: cryptodev-vhost-user property "chardev" */
1905 if (g_str_equal(type
, "cryptodev-vhost-user")) {
1910 /* Reason: vhost-user-blk-server property "node-name" */
1911 if (g_str_equal(type
, "vhost-user-blk-server")) {
1915 * Reason: filter-* property "netdev" etc.
1917 if (g_str_equal(type
, "filter-buffer") ||
1918 g_str_equal(type
, "filter-dump") ||
1919 g_str_equal(type
, "filter-mirror") ||
1920 g_str_equal(type
, "filter-redirector") ||
1921 g_str_equal(type
, "colo-compare") ||
1922 g_str_equal(type
, "filter-rewriter") ||
1923 g_str_equal(type
, "filter-replay")) {
1928 * Allocation of large amounts of memory may delay
1929 * chardev initialization for too long, and trigger timeouts
1930 * on software that waits for a monitor socket to be created
1932 if (g_str_has_prefix(type
, "memory-backend-")) {
1939 static void qemu_apply_machine_options(QDict
*qdict
)
1941 object_set_properties_from_keyval(OBJECT(current_machine
), qdict
, false, &error_fatal
);
1943 if (semihosting_enabled(false) && !semihosting_get_argc()) {
1944 /* fall back to the -kernel/-append */
1945 semihosting_arg_fallback(current_machine
->kernel_filename
, current_machine
->kernel_cmdline
);
1948 if (current_machine
->smp
.cpus
> 1) {
1949 replay_add_blocker("multiple CPUs");
1953 static void qemu_create_early_backends(void)
1955 MachineClass
*machine_class
= MACHINE_GET_CLASS(current_machine
);
1956 #if defined(CONFIG_SDL)
1957 const bool use_sdl
= (dpy
.type
== DISPLAY_TYPE_SDL
);
1959 const bool use_sdl
= false;
1961 #if defined(CONFIG_GTK)
1962 const bool use_gtk
= (dpy
.type
== DISPLAY_TYPE_GTK
);
1964 const bool use_gtk
= false;
1967 if (dpy
.has_window_close
&& !use_gtk
&& !use_sdl
) {
1968 error_report("window-close is only valid for GTK and SDL, "
1972 qemu_console_early_init();
1974 if (dpy
.has_gl
&& dpy
.gl
!= DISPLAYGL_MODE_OFF
&& display_opengl
== 0) {
1975 #if defined(CONFIG_OPENGL)
1976 error_report("OpenGL is not supported by the display");
1978 error_report("OpenGL support is disabled");
1983 object_option_foreach_add(object_create_early
);
1985 /* spice needs the timers to be initialized by this point */
1986 /* spice must initialize before audio as it changes the default audiodev */
1987 /* spice must initialize before chardevs (for spicevmc and spiceport) */
1990 qemu_opts_foreach(qemu_find_opts("chardev"),
1991 chardev_init_func
, NULL
, &error_fatal
);
1993 #ifdef CONFIG_VIRTFS
1994 qemu_opts_foreach(qemu_find_opts("fsdev"),
1995 fsdev_init_func
, NULL
, &error_fatal
);
1999 * Note: we need to create audio and block backends before
2000 * setting machine properties, so they can be referred to.
2002 configure_blockdev(&bdo_queue
, machine_class
, snapshot
);
2003 audio_init_audiodevs();
2004 if (default_audio
) {
2005 audio_create_default_audiodevs();
2011 * The remainder of object creation happens after the
2012 * creation of chardev, fsdev, net clients and device data types.
2014 static bool object_create_late(const char *type
)
2016 return !object_create_early(type
) && !object_create_pre_sandbox(type
);
2019 static void qemu_create_late_backends(void)
2022 qtest_server_init(qtest_chrdev
, qtest_log
, &error_fatal
);
2027 object_option_foreach_add(object_create_late
);
2030 * Wait for any outstanding memory prealloc from created memory
2031 * backends to complete.
2033 if (!qemu_finish_async_prealloc_mem(&error_fatal
)) {
2037 if (tpm_init() < 0) {
2041 qemu_opts_foreach(qemu_find_opts("mon"),
2042 mon_init_func
, NULL
, &error_fatal
);
2044 if (foreach_device_config(DEV_SERIAL
, serial_parse
) < 0)
2046 if (foreach_device_config(DEV_PARALLEL
, parallel_parse
) < 0)
2048 if (foreach_device_config(DEV_DEBUGCON
, debugcon_parse
) < 0)
2051 /* now chardevs have been created we may have semihosting to connect */
2052 qemu_semihosting_chardev_init();
2055 static void qemu_resolve_machine_memdev(void)
2057 if (ram_memdev_id
) {
2059 ram_addr_t backend_size
;
2061 backend
= object_resolve_path_type(ram_memdev_id
,
2062 TYPE_MEMORY_BACKEND
, NULL
);
2064 error_report("Memory backend '%s' not found", ram_memdev_id
);
2067 if (!have_custom_ram_size
) {
2068 backend_size
= object_property_get_uint(backend
, "size", &error_abort
);
2069 current_machine
->ram_size
= backend_size
;
2071 object_property_set_link(OBJECT(current_machine
),
2072 "memory-backend", backend
, &error_fatal
);
2076 static void parse_memory_options(void)
2078 QemuOpts
*opts
= qemu_find_opts_singleton("memory");
2080 const char *mem_str
;
2083 loc_push_none(&loc
);
2084 qemu_opts_loc_restore(opts
);
2088 if (qemu_opt_get_size(opts
, "size", 0) != 0) {
2089 /* Fix up legacy suffix-less format */
2090 mem_str
= qemu_opt_get(opts
, "size");
2091 if (g_ascii_isdigit(mem_str
[strlen(mem_str
) - 1])) {
2092 g_autofree
char *mib_str
= g_strdup_printf("%sM", mem_str
);
2093 qdict_put_str(prop
, "size", mib_str
);
2095 qdict_put_str(prop
, "size", mem_str
);
2099 if (qemu_opt_get(opts
, "maxmem")) {
2100 qdict_put_str(prop
, "max-size", qemu_opt_get(opts
, "maxmem"));
2102 if (qemu_opt_get(opts
, "slots")) {
2103 qdict_put_str(prop
, "slots", qemu_opt_get(opts
, "slots"));
2107 qdict_put(dict
, "memory", prop
);
2108 keyval_merge(machine_opts_dict
, dict
, &error_fatal
);
2109 qobject_unref(dict
);
2113 static void qemu_create_machine(QDict
*qdict
)
2115 MachineClass
*machine_class
= select_machine(qdict
, &error_fatal
);
2116 object_set_machine_compat_props(machine_class
->compat_props
);
2118 current_machine
= MACHINE(object_new_with_class(OBJECT_CLASS(machine_class
)));
2119 object_property_add_child(object_get_root(), "machine",
2120 OBJECT(current_machine
));
2121 object_property_add_child(container_get(OBJECT(current_machine
),
2123 "sysbus", OBJECT(sysbus_get_default()));
2125 if (machine_class
->minimum_page_bits
) {
2126 if (!set_preferred_target_page_bits(machine_class
->minimum_page_bits
)) {
2127 /* This would be a board error: specifying a minimum smaller than
2128 * a target's compile-time fixed setting.
2130 g_assert_not_reached();
2134 cpu_exec_init_all();
2136 if (machine_class
->hw_version
) {
2137 qemu_set_hw_version(machine_class
->hw_version
);
2141 * Get the default machine options from the machine if it is not already
2142 * specified either by the configuration file or by the command line.
2144 if (machine_class
->default_machine_opts
) {
2145 QDict
*default_opts
=
2146 keyval_parse(machine_class
->default_machine_opts
, NULL
, NULL
,
2148 qemu_apply_legacy_machine_options(default_opts
);
2149 object_set_properties_from_keyval(OBJECT(current_machine
), default_opts
,
2150 false, &error_abort
);
2151 qobject_unref(default_opts
);
2155 static int global_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2159 g
= g_malloc0(sizeof(*g
));
2160 g
->driver
= qemu_opt_get(opts
, "driver");
2161 g
->property
= qemu_opt_get(opts
, "property");
2162 g
->value
= qemu_opt_get(opts
, "value");
2163 qdev_prop_register_global(g
);
2168 * Return whether configuration group @group is stored in QemuOpts, or
2169 * recorded as one or more QDicts by qemu_record_config_group.
2171 static bool is_qemuopts_group(const char *group
)
2173 if (g_str_equal(group
, "object") ||
2174 g_str_equal(group
, "audiodev") ||
2175 g_str_equal(group
, "machine") ||
2176 g_str_equal(group
, "smp-opts") ||
2177 g_str_equal(group
, "boot-opts")) {
2183 static void qemu_record_config_group(const char *group
, QDict
*dict
,
2184 bool from_json
, Error
**errp
)
2186 if (g_str_equal(group
, "object")) {
2187 Visitor
*v
= qobject_input_visitor_new_keyval(QOBJECT(dict
));
2188 object_option_add_visitor(v
);
2191 } else if (g_str_equal(group
, "audiodev")) {
2192 Audiodev
*dev
= NULL
;
2193 Visitor
*v
= qobject_input_visitor_new_keyval(QOBJECT(dict
));
2194 if (visit_type_Audiodev(v
, NULL
, &dev
, errp
)) {
2199 } else if (g_str_equal(group
, "machine")) {
2201 * Cannot merge string-valued and type-safe dictionaries, so JSON
2202 * is not accepted yet for -M.
2205 keyval_merge(machine_opts_dict
, dict
, errp
);
2206 } else if (g_str_equal(group
, "smp-opts")) {
2207 machine_merge_property("smp", dict
, &error_fatal
);
2208 } else if (g_str_equal(group
, "boot-opts")) {
2209 machine_merge_property("boot", dict
, &error_fatal
);
2216 * Parse non-QemuOpts config file groups, pass the rest to
2217 * qemu_config_do_parse.
2219 static void qemu_parse_config_group(const char *group
, QDict
*qdict
,
2220 void *opaque
, Error
**errp
)
2223 if (is_qemuopts_group(group
)) {
2224 qemu_config_do_parse(group
, qdict
, opaque
, errp
);
2228 crumpled
= qdict_crumple(qdict
, errp
);
2232 switch (qobject_type(crumpled
)) {
2234 qemu_record_config_group(group
, qobject_to(QDict
, crumpled
), false, errp
);
2237 error_setg(errp
, "Lists cannot be at top level of a configuration section");
2240 g_assert_not_reached();
2242 qobject_unref(crumpled
);
2245 static void qemu_read_default_config_file(Error
**errp
)
2249 g_autofree
char *file
= get_relocated_path(CONFIG_QEMU_CONFDIR
"/qemu.conf");
2251 ret
= qemu_read_config_file(file
, qemu_parse_config_group
, errp
);
2253 if (ret
== -ENOENT
) {
2260 static void qemu_set_option(const char *str
, Error
**errp
)
2262 char group
[64], id
[64], arg
[64];
2267 rc
= sscanf(str
, "%63[^.].%63[^.].%63[^=]%n", group
, id
, arg
, &offset
);
2268 if (rc
< 3 || str
[offset
] != '=') {
2269 error_setg(errp
, "can't parse: \"%s\"", str
);
2273 if (!is_qemuopts_group(group
)) {
2274 error_setg(errp
, "-set is not supported with %s", group
);
2276 list
= qemu_find_opts_err(group
, errp
);
2278 opts
= qemu_opts_find(list
, id
);
2280 error_setg(errp
, "there is no %s \"%s\" defined", group
, id
);
2283 qemu_opt_set(opts
, arg
, str
+ offset
+ 1, errp
);
2288 static void user_register_global_props(void)
2290 qemu_opts_foreach(qemu_find_opts("global"),
2291 global_init_func
, NULL
, NULL
);
2294 static int do_configure_icount(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2296 return !icount_configure(opts
, errp
);
2299 static int accelerator_set_property(void *opaque
,
2300 const char *name
, const char *value
,
2303 return object_parse_property_opt(opaque
, name
, value
, "accel", errp
);
2306 static int do_configure_accelerator(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2308 bool *p_init_failed
= opaque
;
2309 const char *acc
= qemu_opt_get(opts
, "accel");
2310 AccelClass
*ac
= accel_find(acc
);
2313 bool qtest_with_kvm
;
2316 error_setg(errp
, QERR_MISSING_PARAMETER
, "accel");
2320 qtest_with_kvm
= g_str_equal(acc
, "kvm") && qtest_chrdev
!= NULL
;
2323 if (!qtest_with_kvm
) {
2324 error_report("invalid accelerator %s", acc
);
2328 accel
= ACCEL(object_new_with_class(OBJECT_CLASS(ac
)));
2329 object_apply_compat_props(OBJECT(accel
));
2330 qemu_opt_foreach(opts
, accelerator_set_property
,
2334 ret
= accel_init_machine(accel
, current_machine
);
2336 if (!qtest_with_kvm
|| ret
!= -ENOENT
) {
2337 error_report("failed to initialize %s: %s", acc
, strerror(-ret
));
2345 *p_init_failed
= true;
2349 static void configure_accelerators(const char *progname
)
2351 bool init_failed
= false;
2353 qemu_opts_foreach(qemu_find_opts("icount"),
2354 do_configure_icount
, NULL
, &error_fatal
);
2356 if (QTAILQ_EMPTY(&qemu_accel_opts
.head
)) {
2357 char **accel_list
, **tmp
;
2359 if (accelerators
== NULL
) {
2360 /* Select the default accelerator */
2361 bool have_tcg
= accel_find("tcg");
2362 bool have_kvm
= accel_find("kvm");
2364 if (have_tcg
&& have_kvm
) {
2365 if (g_str_has_suffix(progname
, "kvm")) {
2366 /* If the program name ends with "kvm", we prefer KVM */
2367 accelerators
= "kvm:tcg";
2369 accelerators
= "tcg:kvm";
2371 } else if (have_kvm
) {
2372 accelerators
= "kvm";
2373 } else if (have_tcg
) {
2374 accelerators
= "tcg";
2376 error_report("No accelerator selected and"
2377 " no default accelerator available");
2381 accel_list
= g_strsplit(accelerators
, ":", 0);
2383 for (tmp
= accel_list
; *tmp
; tmp
++) {
2385 * Filter invalid accelerators here, to prevent obscenities
2386 * such as "-machine accel=tcg,,thread=single".
2388 if (accel_find(*tmp
)) {
2389 qemu_opts_parse_noisily(qemu_find_opts("accel"), *tmp
, true);
2392 error_report("invalid accelerator %s", *tmp
);
2395 g_strfreev(accel_list
);
2397 if (accelerators
!= NULL
) {
2398 error_report("The -accel and \"-machine accel=\" options are incompatible");
2403 if (!qemu_opts_foreach(qemu_find_opts("accel"),
2404 do_configure_accelerator
, &init_failed
, &error_fatal
)) {
2406 error_report("no accelerator found");
2411 if (init_failed
&& !qtest_chrdev
) {
2412 error_report("falling back to %s", current_accel_name());
2415 if (icount_enabled() && !tcg_enabled()) {
2416 error_report("-icount is not allowed with hardware virtualization");
2421 static void qemu_validate_options(const QDict
*machine_opts
)
2423 const char *kernel_filename
= qdict_get_try_str(machine_opts
, "kernel");
2424 const char *initrd_filename
= qdict_get_try_str(machine_opts
, "initrd");
2425 const char *kernel_cmdline
= qdict_get_try_str(machine_opts
, "append");
2427 if (kernel_filename
== NULL
) {
2428 if (kernel_cmdline
!= NULL
) {
2429 error_report("-append only allowed with -kernel option");
2433 if (initrd_filename
!= NULL
) {
2434 error_report("-initrd only allowed with -kernel option");
2439 if (loadvm
&& incoming
) {
2440 error_report("'incoming' and 'loadvm' options are mutually exclusive");
2443 if (loadvm
&& preconfig_requested
) {
2444 error_report("'preconfig' and 'loadvm' options are "
2445 "mutually exclusive");
2448 if (incoming
&& preconfig_requested
&& strcmp(incoming
, "defer") != 0) {
2449 error_report("'preconfig' supports '-incoming defer' only");
2453 #ifdef CONFIG_CURSES
2454 if (is_daemonized() && dpy
.type
== DISPLAY_TYPE_CURSES
) {
2455 error_report("curses display cannot be used with -daemonize");
2461 static void qemu_process_sugar_options(void)
2464 QObject
*smp
= qdict_get(machine_opts_dict
, "smp");
2465 if (smp
&& qobject_type(smp
) == QTYPE_QDICT
) {
2466 QObject
*cpus
= qdict_get(qobject_to(QDict
, smp
), "cpus");
2467 if (cpus
&& qobject_type(cpus
) == QTYPE_QSTRING
) {
2468 const char *val
= qstring_get_str(qobject_to(QString
, cpus
));
2469 object_register_sugar_prop("memory-backend", "prealloc-threads",
2473 object_register_sugar_prop("memory-backend", "prealloc", "on", false);
2477 /* -action processing */
2480 * Process all the -action parameters parsed from cmdline.
2482 static int process_runstate_actions(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2484 Error
*local_err
= NULL
;
2485 QDict
*qdict
= qemu_opts_to_qdict(opts
, NULL
);
2486 QObject
*ret
= NULL
;
2487 qmp_marshal_set_action(qdict
, &ret
, &local_err
);
2489 qobject_unref(qdict
);
2491 error_propagate(errp
, local_err
);
2497 static void qemu_process_early_options(void)
2499 qemu_opts_foreach(qemu_find_opts("name"),
2500 parse_name
, NULL
, &error_fatal
);
2502 object_option_foreach_add(object_create_pre_sandbox
);
2504 #ifdef CONFIG_SECCOMP
2505 QemuOptsList
*olist
= qemu_find_opts_err("sandbox", NULL
);
2507 qemu_opts_foreach(olist
, parse_sandbox
, NULL
, &error_fatal
);
2511 if (qemu_opts_foreach(qemu_find_opts("action"),
2512 process_runstate_actions
, NULL
, &error_fatal
)) {
2517 qemu_opts_foreach(qemu_find_opts("add-fd"),
2518 parse_add_fd
, NULL
, &error_fatal
);
2520 qemu_opts_foreach(qemu_find_opts("add-fd"),
2521 cleanup_add_fd
, NULL
, &error_fatal
);
2524 /* Open the logfile at this point and set the log mask if necessary. */
2528 mask
= qemu_str_to_log_mask(log_mask
);
2530 qemu_print_log_usage(stdout
);
2534 qemu_set_log_filename_flags(log_file
, mask
, &error_fatal
);
2537 qemu_add_default_firmwarepath();
2540 static void qemu_process_help_options(void)
2543 * Check for -cpu help and -device help before we call select_machine(),
2544 * which will return an error if the architecture has no default machine
2545 * type and the user did not specify one, so that the user doesn't need
2546 * to say '-cpu help -machine something'.
2548 if (cpu_option
&& is_help_option(cpu_option
)) {
2553 if (qemu_opts_foreach(qemu_find_opts("device"),
2554 device_help_func
, NULL
, NULL
)) {
2558 /* -L help lists the data directories and exits. */
2559 if (list_data_dirs
) {
2560 qemu_list_data_dirs();
2565 static void qemu_maybe_daemonize(const char *pid_file
)
2570 rcu_disable_atfork();
2573 char *pid_file_realpath
= NULL
;
2575 if (!qemu_write_pidfile(pid_file
, &err
)) {
2576 error_reportf_err(err
, "cannot create PID file: ");
2580 pid_file_realpath
= g_malloc0(PATH_MAX
);
2581 if (!realpath(pid_file
, pid_file_realpath
)) {
2582 if (errno
!= ENOENT
) {
2583 warn_report("not removing PID file on exit: cannot resolve PID "
2584 "file path: %s: %s", pid_file
, strerror(errno
));
2589 qemu_unlink_pidfile_notifier
= (struct UnlinkPidfileNotifier
) {
2591 .notify
= qemu_unlink_pidfile
,
2593 .pid_file_realpath
= pid_file_realpath
,
2595 qemu_add_exit_notifier(&qemu_unlink_pidfile_notifier
.notifier
);
2599 static void qemu_init_displays(void)
2603 /* init local displays */
2604 ds
= init_displaystate();
2605 qemu_display_init(ds
, &dpy
);
2607 /* must be after terminal init, SDL library changes signal handlers */
2608 os_setup_signal_handling();
2610 /* init remote displays */
2612 qemu_opts_foreach(qemu_find_opts("vnc"),
2613 vnc_init_func
, NULL
, &error_fatal
);
2617 qemu_spice
.display_init();
2621 static void qemu_init_board(void)
2623 /* process plugin before CPUs are created, but once -smp has been parsed */
2624 qemu_plugin_load_list(&plugin_list
, &error_fatal
);
2626 /* From here on we enter MACHINE_PHASE_INITIALIZED. */
2627 machine_run_board_init(current_machine
, mem_path
, &error_fatal
);
2629 drive_check_orphaned();
2634 static void qemu_create_cli_devices(void)
2640 qemu_opts_foreach(qemu_find_opts("fw_cfg"),
2641 parse_fw_cfg
, fw_cfg_find(), &error_fatal
);
2643 /* init USB devices */
2644 if (machine_usb(current_machine
)) {
2645 if (foreach_device_config(DEV_USB
, usb_parse
) < 0)
2649 /* init generic devices */
2650 rom_set_order_override(FW_CFG_ORDER_OVERRIDE_DEVICE
);
2651 qemu_opts_foreach(qemu_find_opts("device"),
2652 device_init_func
, NULL
, &error_fatal
);
2653 QTAILQ_FOREACH(opt
, &device_opts
, next
) {
2655 loc_push_restore(&opt
->loc
);
2657 * TODO Eventually we should call qmp_device_add() here to make sure it
2658 * behaves the same, but QMP still has to accept incorrectly typed
2659 * options until libvirt is fixed and we want to be strict on the CLI
2660 * from the start, so call qdev_device_add_from_qdict() directly for
2663 dev
= qdev_device_add_from_qdict(opt
->opts
, true, &error_fatal
);
2664 object_unref(OBJECT(dev
));
2667 rom_reset_order_override();
2670 static bool qemu_machine_creation_done(Error
**errp
)
2672 MachineState
*machine
= MACHINE(qdev_get_machine());
2674 /* Did we create any drives that we failed to create a device for? */
2675 drive_check_orphaned();
2677 /* Don't warn about the default network setup that you get if
2678 * no command line -net or -netdev options are specified. There
2679 * are two cases that we would otherwise complain about:
2680 * (1) board doesn't support a NIC but the implicit "-net nic"
2682 * (2) CONFIG_SLIRP not set, in which case the implicit "-net nic"
2683 * sets up a nic that isn't connected to anything.
2685 if (!default_net
&& (!qtest_enabled() || has_defaults
)) {
2686 net_check_clients();
2689 qdev_prop_check_globals();
2691 qdev_machine_creation_done();
2693 if (machine
->cgs
&& !machine
->cgs
->ready
) {
2694 error_setg(errp
, "accelerator does not support confidential guest %s",
2695 object_get_typename(OBJECT(machine
->cgs
)));
2699 if (foreach_device_config(DEV_GDB
, gdbserver_start
) < 0) {
2700 error_setg(errp
, "could not start gdbserver");
2703 if (!vga_interface_created
&& !default_vga
&&
2704 vga_interface_type
!= VGA_NONE
) {
2705 warn_report("A -vga option was passed but this machine "
2706 "type does not use that option; "
2707 "No VGA device has been created");
2712 void qmp_x_exit_preconfig(Error
**errp
)
2714 if (phase_check(PHASE_MACHINE_INITIALIZED
)) {
2715 error_setg(errp
, "The command is permitted only before machine initialization");
2720 qemu_create_cli_devices();
2721 if (!qemu_machine_creation_done(errp
)) {
2726 RunState state
= autostart
? RUN_STATE_RUNNING
: runstate_get();
2727 load_snapshot(loadvm
, NULL
, false, NULL
, &error_fatal
);
2728 load_snapshot_resume(state
);
2730 if (replay_mode
!= REPLAY_MODE_NONE
) {
2731 replay_vmstate_init();
2735 Error
*local_err
= NULL
;
2736 if (strcmp(incoming
, "defer") != 0) {
2737 qmp_migrate_incoming(incoming
, false, NULL
, true, true,
2740 error_reportf_err(local_err
, "-incoming %s: ", incoming
);
2744 } else if (autostart
) {
2749 void qemu_init(int argc
, char **argv
)
2752 QemuOpts
*icount_opts
= NULL
, *accel_opts
= NULL
;
2753 QemuOptsList
*olist
;
2756 MachineClass
*machine_class
;
2757 bool userconfig
= true;
2758 FILE *vmstate_dump_file
= NULL
;
2760 qemu_add_opts(&qemu_drive_opts
);
2761 qemu_add_drive_opts(&qemu_legacy_drive_opts
);
2762 qemu_add_drive_opts(&qemu_common_drive_opts
);
2763 qemu_add_drive_opts(&qemu_drive_opts
);
2764 qemu_add_drive_opts(&bdrv_runtime_opts
);
2765 qemu_add_opts(&qemu_chardev_opts
);
2766 qemu_add_opts(&qemu_device_opts
);
2767 qemu_add_opts(&qemu_netdev_opts
);
2768 qemu_add_opts(&qemu_nic_opts
);
2769 qemu_add_opts(&qemu_net_opts
);
2770 qemu_add_opts(&qemu_rtc_opts
);
2771 qemu_add_opts(&qemu_global_opts
);
2772 qemu_add_opts(&qemu_mon_opts
);
2773 qemu_add_opts(&qemu_trace_opts
);
2774 qemu_plugin_add_opts();
2775 qemu_add_opts(&qemu_option_rom_opts
);
2776 qemu_add_opts(&qemu_accel_opts
);
2777 qemu_add_opts(&qemu_mem_opts
);
2778 qemu_add_opts(&qemu_smp_opts
);
2779 qemu_add_opts(&qemu_boot_opts
);
2780 qemu_add_opts(&qemu_add_fd_opts
);
2781 qemu_add_opts(&qemu_object_opts
);
2782 qemu_add_opts(&qemu_tpmdev_opts
);
2783 qemu_add_opts(&qemu_overcommit_opts
);
2784 qemu_add_opts(&qemu_msg_opts
);
2785 qemu_add_opts(&qemu_name_opts
);
2786 qemu_add_opts(&qemu_numa_opts
);
2787 qemu_add_opts(&qemu_icount_opts
);
2788 qemu_add_opts(&qemu_semihosting_config_opts
);
2789 qemu_add_opts(&qemu_fw_cfg_opts
);
2790 qemu_add_opts(&qemu_action_opts
);
2791 qemu_add_run_with_opts();
2792 module_call_init(MODULE_INIT_OPTS
);
2794 error_init(argv
[0]);
2795 qemu_init_exec_dir(argv
[0]);
2799 qemu_init_arch_modules();
2801 qemu_init_subsystems();
2803 /* first pass of option parsing */
2805 while (optind
< argc
) {
2806 if (argv
[optind
][0] != '-') {
2810 const QEMUOption
*popt
;
2812 popt
= lookup_opt(argc
, argv
, &optarg
, &optind
);
2813 switch (popt
->index
) {
2814 case QEMU_OPTION_nouserconfig
:
2821 machine_opts_dict
= qdict_new();
2823 qemu_read_default_config_file(&error_fatal
);
2826 /* second pass of option parsing */
2831 if (argv
[optind
][0] != '-') {
2832 loc_set_cmdline(argv
, optind
, 1);
2833 drive_add(IF_DEFAULT
, 0, argv
[optind
++], HD_OPTS
);
2835 const QEMUOption
*popt
;
2837 popt
= lookup_opt(argc
, argv
, &optarg
, &optind
);
2838 if (!(popt
->arch_mask
& arch_type
)) {
2839 error_report("Option not supported for this target");
2842 switch(popt
->index
) {
2843 case QEMU_OPTION_cpu
:
2844 /* hw initialization will check this */
2845 cpu_option
= optarg
;
2847 case QEMU_OPTION_hda
:
2848 case QEMU_OPTION_hdb
:
2849 case QEMU_OPTION_hdc
:
2850 case QEMU_OPTION_hdd
:
2851 drive_add(IF_DEFAULT
, popt
->index
- QEMU_OPTION_hda
, optarg
,
2854 case QEMU_OPTION_blockdev
:
2857 BlockdevOptionsQueueEntry
*bdo
;
2859 v
= qobject_input_visitor_new_str(optarg
, "driver",
2862 bdo
= g_new(BlockdevOptionsQueueEntry
, 1);
2863 visit_type_BlockdevOptions(v
, NULL
, &bdo
->bdo
,
2866 loc_save(&bdo
->loc
);
2867 QSIMPLEQ_INSERT_TAIL(&bdo_queue
, bdo
, entry
);
2870 case QEMU_OPTION_drive
:
2871 opts
= qemu_opts_parse_noisily(qemu_find_opts("drive"),
2877 case QEMU_OPTION_set
:
2878 qemu_set_option(optarg
, &error_fatal
);
2880 case QEMU_OPTION_global
:
2881 if (qemu_global_option(optarg
) != 0)
2884 case QEMU_OPTION_mtdblock
:
2885 drive_add(IF_MTD
, -1, optarg
, MTD_OPTS
);
2887 case QEMU_OPTION_sd
:
2888 drive_add(IF_SD
, -1, optarg
, SD_OPTS
);
2890 case QEMU_OPTION_pflash
:
2891 drive_add(IF_PFLASH
, -1, optarg
, PFLASH_OPTS
);
2893 case QEMU_OPTION_snapshot
:
2895 replay_add_blocker("-snapshot");
2897 case QEMU_OPTION_numa
:
2898 opts
= qemu_opts_parse_noisily(qemu_find_opts("numa"),
2904 case QEMU_OPTION_display
:
2905 parse_display(optarg
);
2907 case QEMU_OPTION_nographic
:
2908 qdict_put_str(machine_opts_dict
, "graphics", "off");
2910 dpy
.type
= DISPLAY_TYPE_NONE
;
2912 case QEMU_OPTION_portrait
:
2913 graphic_rotate
= 90;
2915 case QEMU_OPTION_rotate
:
2916 graphic_rotate
= strtol(optarg
, (char **) &optarg
, 10);
2917 if (graphic_rotate
!= 0 && graphic_rotate
!= 90 &&
2918 graphic_rotate
!= 180 && graphic_rotate
!= 270) {
2919 error_report("only 90, 180, 270 deg rotation is available");
2923 case QEMU_OPTION_kernel
:
2924 qdict_put_str(machine_opts_dict
, "kernel", optarg
);
2926 case QEMU_OPTION_initrd
:
2927 qdict_put_str(machine_opts_dict
, "initrd", optarg
);
2929 case QEMU_OPTION_append
:
2930 qdict_put_str(machine_opts_dict
, "append", optarg
);
2932 case QEMU_OPTION_dtb
:
2933 qdict_put_str(machine_opts_dict
, "dtb", optarg
);
2935 case QEMU_OPTION_cdrom
:
2936 drive_add(IF_DEFAULT
, 2, optarg
, CDROM_OPTS
);
2938 case QEMU_OPTION_boot
:
2939 machine_parse_property_opt(qemu_find_opts("boot-opts"), "boot", optarg
);
2941 case QEMU_OPTION_fda
:
2942 case QEMU_OPTION_fdb
:
2943 drive_add(IF_FLOPPY
, popt
->index
- QEMU_OPTION_fda
,
2946 case QEMU_OPTION_no_fd_bootchk
:
2947 qdict_put_str(machine_opts_dict
, "fd-bootchk", "off");
2949 case QEMU_OPTION_netdev
:
2951 if (netdev_is_modern(optarg
)) {
2952 netdev_parse_modern(optarg
);
2954 net_client_parse(qemu_find_opts("netdev"), optarg
);
2957 case QEMU_OPTION_nic
:
2959 net_client_parse(qemu_find_opts("nic"), optarg
);
2961 case QEMU_OPTION_net
:
2963 net_client_parse(qemu_find_opts("net"), optarg
);
2965 #ifdef CONFIG_LIBISCSI
2966 case QEMU_OPTION_iscsi
:
2967 opts
= qemu_opts_parse_noisily(qemu_find_opts("iscsi"),
2974 case QEMU_OPTION_audiodev
:
2976 audio_parse_option(optarg
);
2978 case QEMU_OPTION_audio
: {
2981 Audiodev
*dev
= NULL
;
2983 QDict
*dict
= keyval_parse(optarg
, "driver", &help
, &error_fatal
);
2985 if (help
|| (qdict_haskey(dict
, "driver") &&
2986 is_help_option(qdict_get_str(dict
, "driver")))) {
2990 if (!qdict_haskey(dict
, "id")) {
2991 qdict_put_str(dict
, "id", "audiodev0");
2993 if (qdict_haskey(dict
, "model")) {
2994 model
= g_strdup(qdict_get_str(dict
, "model"));
2995 qdict_del(dict
, "model");
2996 if (is_help_option(model
)) {
2997 show_valid_soundhw();
3001 v
= qobject_input_visitor_new_keyval(QOBJECT(dict
));
3002 qobject_unref(dict
);
3003 visit_type_Audiodev(v
, NULL
, &dev
, &error_fatal
);
3007 select_soundhw(model
, dev
->id
);
3010 audio_define_default(dev
, &error_fatal
);
3017 case QEMU_OPTION_version
:
3022 opts
= qemu_opts_parse_noisily(qemu_find_opts("memory"), optarg
, true);
3028 case QEMU_OPTION_tpmdev
:
3029 if (tpm_config_parse(qemu_find_opts("tpmdev"), optarg
) < 0) {
3034 case QEMU_OPTION_mempath
:
3037 case QEMU_OPTION_mem_prealloc
:
3046 case QEMU_OPTION_DFILTER
:
3047 qemu_set_dfilter_ranges(optarg
, &error_fatal
);
3049 #if defined(CONFIG_TCG) && defined(CONFIG_LINUX)
3050 case QEMU_OPTION_perfmap
:
3051 perf_enable_perfmap();
3053 case QEMU_OPTION_jitdump
:
3054 perf_enable_jitdump();
3057 case QEMU_OPTION_seed
:
3058 qemu_guest_random_seed_main(optarg
, &error_fatal
);
3061 add_device_config(DEV_GDB
, "tcp::" DEFAULT_GDBSTUB_PORT
);
3063 case QEMU_OPTION_gdb
:
3064 add_device_config(DEV_GDB
, optarg
);
3067 if (is_help_option(optarg
)) {
3068 list_data_dirs
= true;
3070 qemu_add_data_dir(g_strdup(optarg
));
3073 case QEMU_OPTION_bios
:
3074 qdict_put_str(machine_opts_dict
, "firmware", optarg
);
3080 keyboard_layout
= optarg
;
3082 case QEMU_OPTION_vga
:
3091 w
= strtol(p
, (char **)&p
, 10);
3094 error_report("invalid resolution or depth");
3100 h
= strtol(p
, (char **)&p
, 10);
3105 depth
= strtol(p
, (char **)&p
, 10);
3106 if (depth
!= 1 && depth
!= 2 && depth
!= 4 &&
3107 depth
!= 8 && depth
!= 15 && depth
!= 16 &&
3108 depth
!= 24 && depth
!= 32)
3110 } else if (*p
== '\0') {
3111 depth
= graphic_depth
;
3118 graphic_depth
= depth
;
3121 case QEMU_OPTION_echr
:
3124 term_escape_char
= strtol(optarg
, &r
, 0);
3126 printf("Bad argument to echr\n");
3129 case QEMU_OPTION_monitor
:
3130 default_monitor
= 0;
3131 if (strncmp(optarg
, "none", 4)) {
3132 monitor_parse(optarg
, "readline", false);
3135 case QEMU_OPTION_qmp
:
3136 monitor_parse(optarg
, "control", false);
3137 default_monitor
= 0;
3139 case QEMU_OPTION_qmp_pretty
:
3140 monitor_parse(optarg
, "control", true);
3141 default_monitor
= 0;
3143 case QEMU_OPTION_mon
:
3144 opts
= qemu_opts_parse_noisily(qemu_find_opts("mon"), optarg
,
3149 default_monitor
= 0;
3151 case QEMU_OPTION_chardev
:
3152 opts
= qemu_opts_parse_noisily(qemu_find_opts("chardev"),
3158 case QEMU_OPTION_fsdev
:
3159 olist
= qemu_find_opts("fsdev");
3161 error_report("fsdev support is disabled");
3164 opts
= qemu_opts_parse_noisily(olist
, optarg
, true);
3169 case QEMU_OPTION_virtfs
: {
3172 const char *writeout
, *sock_fd
, *socket
, *path
, *security_model
,
3175 olist
= qemu_find_opts("virtfs");
3177 error_report("virtfs support is disabled");
3180 opts
= qemu_opts_parse_noisily(olist
, optarg
, true);
3185 if (qemu_opt_get(opts
, "fsdriver") == NULL
||
3186 qemu_opt_get(opts
, "mount_tag") == NULL
) {
3187 error_report("Usage: -virtfs fsdriver,mount_tag=tag");
3190 fsdev
= qemu_opts_create(qemu_find_opts("fsdev"),
3191 qemu_opts_id(opts
) ?:
3192 qemu_opt_get(opts
, "mount_tag"),
3195 error_report("duplicate or invalid fsdev id: %s",
3196 qemu_opt_get(opts
, "mount_tag"));
3200 writeout
= qemu_opt_get(opts
, "writeout");
3202 #ifdef CONFIG_SYNC_FILE_RANGE
3203 qemu_opt_set(fsdev
, "writeout", writeout
, &error_abort
);
3205 error_report("writeout=immediate not supported "
3206 "on this platform");
3210 qemu_opt_set(fsdev
, "fsdriver",
3211 qemu_opt_get(opts
, "fsdriver"), &error_abort
);
3212 path
= qemu_opt_get(opts
, "path");
3214 qemu_opt_set(fsdev
, "path", path
, &error_abort
);
3216 security_model
= qemu_opt_get(opts
, "security_model");
3217 if (security_model
) {
3218 qemu_opt_set(fsdev
, "security_model", security_model
,
3221 socket
= qemu_opt_get(opts
, "socket");
3223 qemu_opt_set(fsdev
, "socket", socket
, &error_abort
);
3225 sock_fd
= qemu_opt_get(opts
, "sock_fd");
3227 qemu_opt_set(fsdev
, "sock_fd", sock_fd
, &error_abort
);
3230 qemu_opt_set_bool(fsdev
, "readonly",
3231 qemu_opt_get_bool(opts
, "readonly", 0),
3233 multidevs
= qemu_opt_get(opts
, "multidevs");
3235 qemu_opt_set(fsdev
, "multidevs", multidevs
, &error_abort
);
3237 device
= qemu_opts_create(qemu_find_opts("device"), NULL
, 0,
3239 qemu_opt_set(device
, "driver", "virtio-9p-pci", &error_abort
);
3240 qemu_opt_set(device
, "fsdev",
3241 qemu_opts_id(fsdev
), &error_abort
);
3242 qemu_opt_set(device
, "mount_tag",
3243 qemu_opt_get(opts
, "mount_tag"), &error_abort
);
3246 case QEMU_OPTION_serial
:
3247 add_device_config(DEV_SERIAL
, optarg
);
3249 if (strncmp(optarg
, "mon:", 4) == 0) {
3250 default_monitor
= 0;
3253 case QEMU_OPTION_action
:
3254 olist
= qemu_find_opts("action");
3255 if (!qemu_opts_parse_noisily(olist
, optarg
, false)) {
3259 case QEMU_OPTION_watchdog_action
: {
3260 opts
= qemu_opts_create(qemu_find_opts("action"), NULL
, 0, &error_abort
);
3261 qemu_opt_set(opts
, "watchdog", optarg
, &error_abort
);
3264 case QEMU_OPTION_parallel
:
3265 add_device_config(DEV_PARALLEL
, optarg
);
3266 default_parallel
= 0;
3267 if (strncmp(optarg
, "mon:", 4) == 0) {
3268 default_monitor
= 0;
3271 case QEMU_OPTION_debugcon
:
3272 add_device_config(DEV_DEBUGCON
, optarg
);
3274 case QEMU_OPTION_loadvm
:
3277 case QEMU_OPTION_full_screen
:
3278 dpy
.has_full_screen
= true;
3279 dpy
.full_screen
= true;
3281 case QEMU_OPTION_pidfile
:
3284 case QEMU_OPTION_win2k_hack
:
3285 object_register_sugar_prop("ide-device", "win2k-install-hack", "true", true);
3287 case QEMU_OPTION_acpitable
:
3288 opts
= qemu_opts_parse_noisily(qemu_find_opts("acpi"),
3293 acpi_table_add(opts
, &error_fatal
);
3295 case QEMU_OPTION_smbios
:
3296 opts
= qemu_opts_parse_noisily(qemu_find_opts("smbios"),
3301 smbios_entry_add(opts
, &error_fatal
);
3303 case QEMU_OPTION_fwcfg
:
3304 opts
= qemu_opts_parse_noisily(qemu_find_opts("fw_cfg"),
3310 case QEMU_OPTION_preconfig
:
3311 preconfig_requested
= true;
3313 case QEMU_OPTION_enable_kvm
:
3314 qdict_put_str(machine_opts_dict
, "accel", "kvm");
3317 case QEMU_OPTION_machine
:
3321 keyval_parse_into(machine_opts_dict
, optarg
, "type", &help
, &error_fatal
);
3323 machine_help_func(machine_opts_dict
);
3328 case QEMU_OPTION_accel
:
3329 accel_opts
= qemu_opts_parse_noisily(qemu_find_opts("accel"),
3331 optarg
= qemu_opt_get(accel_opts
, "accel");
3332 if (!optarg
|| is_help_option(optarg
)) {
3333 printf("Accelerators supported in QEMU binary:\n");
3334 GSList
*el
, *accel_list
= object_class_get_list(TYPE_ACCEL
,
3336 for (el
= accel_list
; el
; el
= el
->next
) {
3337 gchar
*typename
= g_strdup(object_class_get_name(
3338 OBJECT_CLASS(el
->data
)));
3339 /* omit qtest which is used for tests only */
3340 if (g_strcmp0(typename
, ACCEL_CLASS_NAME("qtest")) &&
3341 g_str_has_suffix(typename
, ACCEL_CLASS_SUFFIX
)) {
3342 gchar
**optname
= g_strsplit(typename
,
3343 ACCEL_CLASS_SUFFIX
, 0);
3344 printf("%s\n", optname
[0]);
3345 g_strfreev(optname
);
3349 g_slist_free(accel_list
);
3353 case QEMU_OPTION_usb
:
3354 qdict_put_str(machine_opts_dict
, "usb", "on");
3356 case QEMU_OPTION_usbdevice
:
3357 qdict_put_str(machine_opts_dict
, "usb", "on");
3358 add_device_config(DEV_USB
, optarg
);
3360 case QEMU_OPTION_device
:
3361 if (optarg
[0] == '{') {
3362 QObject
*obj
= qobject_from_json(optarg
, &error_fatal
);
3363 DeviceOption
*opt
= g_new0(DeviceOption
, 1);
3364 opt
->opts
= qobject_to(QDict
, obj
);
3365 loc_save(&opt
->loc
);
3366 assert(opt
->opts
!= NULL
);
3367 QTAILQ_INSERT_TAIL(&device_opts
, opt
, next
);
3369 if (!qemu_opts_parse_noisily(qemu_find_opts("device"),
3375 case QEMU_OPTION_smp
:
3376 machine_parse_property_opt(qemu_find_opts("smp-opts"),
3380 case QEMU_OPTION_vnc
:
3385 case QEMU_OPTION_no_reboot
:
3386 olist
= qemu_find_opts("action");
3387 qemu_opts_parse_noisily(olist
, "reboot=shutdown", false);
3389 case QEMU_OPTION_no_shutdown
:
3390 olist
= qemu_find_opts("action");
3391 qemu_opts_parse_noisily(olist
, "shutdown=pause", false);
3393 case QEMU_OPTION_uuid
:
3394 if (qemu_uuid_parse(optarg
, &qemu_uuid
) < 0) {
3395 error_report("failed to parse UUID string: wrong format");
3398 qemu_uuid_set
= true;
3400 case QEMU_OPTION_option_rom
:
3401 if (nb_option_roms
>= MAX_OPTION_ROMS
) {
3402 error_report("too many option ROMs");
3405 opts
= qemu_opts_parse_noisily(qemu_find_opts("option-rom"),
3410 option_rom
[nb_option_roms
].name
= qemu_opt_get(opts
, "romfile");
3411 option_rom
[nb_option_roms
].bootindex
=
3412 qemu_opt_get_number(opts
, "bootindex", -1);
3413 if (!option_rom
[nb_option_roms
].name
) {
3414 error_report("Option ROM file is not specified");
3419 case QEMU_OPTION_semihosting
:
3420 qemu_semihosting_enable();
3422 case QEMU_OPTION_semihosting_config
:
3423 if (qemu_semihosting_config_options(optarg
) != 0) {
3427 case QEMU_OPTION_name
:
3428 opts
= qemu_opts_parse_noisily(qemu_find_opts("name"),
3433 /* Capture guest name if -msg guest-name is used later */
3434 error_guest_name
= qemu_opt_get(opts
, "guest");
3436 case QEMU_OPTION_prom_env
:
3437 if (nb_prom_envs
>= MAX_PROM_ENVS
) {
3438 error_report("too many prom variables");
3441 prom_envs
[nb_prom_envs
] = optarg
;
3444 case QEMU_OPTION_old_param
:
3447 case QEMU_OPTION_rtc
:
3448 opts
= qemu_opts_parse_noisily(qemu_find_opts("rtc"), optarg
,
3454 case QEMU_OPTION_icount
:
3455 icount_opts
= qemu_opts_parse_noisily(qemu_find_opts("icount"),
3461 case QEMU_OPTION_incoming
:
3463 runstate_set(RUN_STATE_INMIGRATE
);
3467 case QEMU_OPTION_only_migratable
:
3468 only_migratable
= 1;
3470 case QEMU_OPTION_nodefaults
:
3473 case QEMU_OPTION_xen_domid
:
3474 if (!(accel_find("xen")) && !(accel_find("kvm"))) {
3475 error_report("Option not supported for this target");
3478 xen_domid
= atoi(optarg
);
3480 case QEMU_OPTION_xen_attach
:
3481 if (!(accel_find("xen"))) {
3482 error_report("Option not supported for this target");
3485 xen_mode
= XEN_ATTACH
;
3487 case QEMU_OPTION_xen_domid_restrict
:
3488 if (!(accel_find("xen"))) {
3489 error_report("Option not supported for this target");
3492 xen_domid_restrict
= true;
3494 case QEMU_OPTION_trace
:
3495 trace_opt_parse(optarg
);
3497 case QEMU_OPTION_plugin
:
3498 qemu_plugin_opt_parse(optarg
, &plugin_list
);
3500 case QEMU_OPTION_readconfig
:
3501 qemu_read_config_file(optarg
, qemu_parse_config_group
, &error_fatal
);
3504 case QEMU_OPTION_spice
:
3505 opts
= qemu_opts_parse_noisily(qemu_find_opts("spice"), optarg
, false);
3512 case QEMU_OPTION_qtest
:
3513 qtest_chrdev
= optarg
;
3515 case QEMU_OPTION_qtest_log
:
3518 case QEMU_OPTION_sandbox
:
3519 olist
= qemu_find_opts("sandbox");
3521 #ifndef CONFIG_SECCOMP
3522 error_report("-sandbox support is not enabled "
3523 "in this QEMU binary");
3528 opts
= qemu_opts_parse_noisily(olist
, optarg
, true);
3533 case QEMU_OPTION_add_fd
:
3535 opts
= qemu_opts_parse_noisily(qemu_find_opts("add-fd"),
3541 error_report("File descriptor passing is disabled on this "
3546 case QEMU_OPTION_object
:
3547 object_option_parse(optarg
);
3549 case QEMU_OPTION_overcommit
:
3550 opts
= qemu_opts_parse_noisily(qemu_find_opts("overcommit"),
3555 enable_mlock
= qemu_opt_get_bool(opts
, "mem-lock", enable_mlock
);
3556 enable_cpu_pm
= qemu_opt_get_bool(opts
, "cpu-pm", enable_cpu_pm
);
3558 case QEMU_OPTION_compat
:
3560 CompatPolicy
*opts_policy
;
3563 v
= qobject_input_visitor_new_str(optarg
, NULL
,
3566 visit_type_CompatPolicy(v
, NULL
, &opts_policy
, &error_fatal
);
3567 QAPI_CLONE_MEMBERS(CompatPolicy
, &compat_policy
, opts_policy
);
3569 qapi_free_CompatPolicy(opts_policy
);
3573 case QEMU_OPTION_msg
:
3574 opts
= qemu_opts_parse_noisily(qemu_find_opts("msg"), optarg
,
3579 configure_msg(opts
);
3581 case QEMU_OPTION_dump_vmstate
:
3582 if (vmstate_dump_file
) {
3583 error_report("only one '-dump-vmstate' "
3584 "option may be given");
3587 vmstate_dump_file
= fopen(optarg
, "w");
3588 if (vmstate_dump_file
== NULL
) {
3589 error_report("open %s: %s", optarg
, strerror(errno
));
3593 case QEMU_OPTION_enable_sync_profile
:
3596 case QEMU_OPTION_nouserconfig
:
3597 /* Nothing to be parsed here. Especially, do not error out below. */
3599 #if defined(CONFIG_POSIX)
3600 case QEMU_OPTION_runas
:
3601 warn_report("-runas is deprecated, use '-run-with user=...' instead");
3602 if (!os_set_runas(optarg
)) {
3603 error_report("User \"%s\" doesn't exist"
3604 " (and is not <uid>:<gid>)",
3609 case QEMU_OPTION_daemonize
:
3610 os_set_daemonize(true);
3612 case QEMU_OPTION_run_with
: {
3614 opts
= qemu_opts_parse_noisily(qemu_find_opts("run-with"),
3619 #if defined(CONFIG_LINUX)
3620 if (qemu_opt_get_bool(opts
, "async-teardown", false)) {
3621 init_async_teardown();
3624 str
= qemu_opt_get(opts
, "chroot");
3628 str
= qemu_opt_get(opts
, "user");
3630 if (!os_set_runas(str
)) {
3631 error_report("User \"%s\" doesn't exist"
3632 " (and is not <uid>:<gid>)",
3640 #endif /* CONFIG_POSIX */
3643 error_report("Option not supported in this build");
3649 * Clear error location left behind by the loop.
3650 * Best done right after the loop. Do not insert code here!
3654 qemu_validate_options(machine_opts_dict
);
3655 qemu_process_sugar_options();
3658 * These options affect everything else and should be processed
3659 * before daemonizing.
3661 qemu_process_early_options();
3663 qemu_process_help_options();
3664 qemu_maybe_daemonize(pid_file
);
3667 * The trace backend must be initialized after daemonizing.
3668 * trace_init_backends() will call st_init(), which will create the
3669 * trace thread in the parent, and also register st_flush_trace_buffer()
3670 * in atexit(). This function will force the parent to wait for the
3671 * writeout thread to finish, which will not occur, and the parent
3672 * process will be left in the host.
3674 if (!trace_init_backends()) {
3679 qemu_init_main_loop(&error_fatal
);
3682 user_register_global_props();
3683 replay_configure(icount_opts
);
3685 configure_rtc(qemu_find_opts_singleton("rtc"));
3687 /* Transfer QemuOpts options into machine options */
3688 parse_memory_options();
3690 qemu_create_machine(machine_opts_dict
);
3694 qemu_disable_default_devices();
3695 qemu_setup_display();
3696 qemu_create_default_devices();
3697 qemu_create_early_backends();
3699 qemu_apply_legacy_machine_options(machine_opts_dict
);
3700 qemu_apply_machine_options(machine_opts_dict
);
3701 qobject_unref(machine_opts_dict
);
3702 phase_advance(PHASE_MACHINE_CREATED
);
3705 * Note: uses machine properties such as kernel-irqchip, must run
3706 * after qemu_apply_machine_options.
3708 configure_accelerators(argv
[0]);
3709 phase_advance(PHASE_ACCEL_CREATED
);
3712 * Beware, QOM objects created before this point miss global and
3713 * compat properties.
3715 * Global properties get set up by qdev_prop_register_global(),
3716 * called from user_register_global_props(), and certain option
3717 * desugaring. Also in CPU feature desugaring (buried in
3718 * parse_cpu_option()), which happens below this point, but may
3719 * only target the CPU type, which can only be created after
3720 * parse_cpu_option() returned the type.
3722 * Machine compat properties: object_set_machine_compat_props().
3723 * Accelerator compat props: object_set_accelerator_compat_props(),
3724 * called from do_configure_accelerator().
3727 machine_class
= MACHINE_GET_CLASS(current_machine
);
3728 if (!qtest_enabled() && machine_class
->deprecation_reason
) {
3729 warn_report("Machine type '%s' is deprecated: %s",
3730 machine_class
->name
, machine_class
->deprecation_reason
);
3734 * Create backends before creating migration objects, so that it can
3735 * check against compatibilities on the backend memories (e.g. postcopy
3736 * over memory-backend-file objects).
3738 qemu_create_late_backends();
3739 phase_advance(PHASE_LATE_BACKENDS_CREATED
);
3742 * Note: creates a QOM object, must run only after global and
3743 * compat properties have been set up.
3745 migration_object_init();
3747 /* parse features once if machine provides default cpu_type */
3748 current_machine
->cpu_type
= machine_class_default_cpu_type(machine_class
);
3750 current_machine
->cpu_type
= parse_cpu_option(cpu_option
);
3752 /* NB: for machine none cpu_type could STILL be NULL here! */
3754 qemu_resolve_machine_memdev();
3755 parse_numa_opts(current_machine
);
3757 if (vmstate_dump_file
) {
3759 module_load_qom_all();
3760 dump_vmstate_json_to_file(vmstate_dump_file
);
3764 if (!preconfig_requested
) {
3765 qmp_x_exit_preconfig(&error_fatal
);
3767 qemu_init_displays();
3768 accel_setup_post(current_machine
);