X-Git-Url: https://repo.jachan.dev/qemu.git/blobdiff_plain/fa27257432689e8927cb993b251d380d654dcc86..2c324b284aac7b87f65af043b8cb6196bd6ad16b:/vl.c diff --git a/vl.c b/vl.c index 55bab005b6..db04aea7f8 100644 --- a/vl.c +++ b/vl.c @@ -61,7 +61,7 @@ int main(int argc, char **argv) #include "hw/display/vga.h" #include "hw/bt.h" #include "sysemu/watchdog.h" -#include "hw/smbios/smbios.h" +#include "hw/firmware/smbios.h" #include "hw/acpi/acpi.h" #include "hw/xen/xen.h" #include "hw/qdev.h" @@ -106,9 +106,6 @@ int main(int argc, char **argv) #include "disas/disas.h" - -#include "slirp/libslirp.h" - #include "trace-root.h" #include "trace/control.h" #include "qemu/queue.h" @@ -128,6 +125,7 @@ int main(int argc, char **argv) #include "qapi/qapi-commands-block-core.h" #include "qapi/qapi-commands-misc.h" #include "qapi/qapi-commands-run-state.h" +#include "qapi/qapi-commands-ui.h" #include "qapi/qmp/qerror.h" #include "sysemu/iothread.h" @@ -159,11 +157,9 @@ static int rtc_host_datetime_offset = -1; /* valid & used only with QEMUClockType rtc_clock; int vga_interface_type = VGA_NONE; static DisplayOptions dpy; -int no_frame; static int num_serial_hds; static Chardev **serial_hds; Chardev *parallel_hds[MAX_PARALLEL_PORTS]; -Chardev *virtcon_hds[MAX_VIRTIO_CONSOLES]; int win2k_install_hack = 0; int singlestep = 0; int smp_cpus; @@ -190,7 +186,7 @@ int boot_menu; bool boot_strict; uint8_t *boot_splash_filedata; size_t boot_splash_filedata_size; -uint8_t qemu_extra_params_fw[2]; +bool wakeup_suspend_enabled; int icount_align_option; @@ -214,7 +210,6 @@ bool xen_domid_restrict; static int has_defaults = 1; static int default_serial = 1; static int default_parallel = 1; -static int default_virtcon = 1; static int default_monitor = 1; static int default_floppy = 1; static int default_cdrom = 1; @@ -235,8 +230,6 @@ static struct { { .driver = "ide-drive", .flag = &default_cdrom }, { .driver = "scsi-cd", .flag = &default_cdrom }, { .driver = "scsi-hd", .flag = &default_cdrom }, - { .driver = "virtio-serial-pci", .flag = &default_virtcon }, - { .driver = "virtio-serial", .flag = &default_virtcon }, { .driver = "VGA", .flag = &default_vga }, { .driver = "isa-vga", .flag = &default_vga }, { .driver = "cirrus-vga", .flag = &default_vga }, @@ -336,10 +329,10 @@ static QemuOptsList qemu_boot_opts = { .type = QEMU_OPT_STRING, }, { .name = "splash-time", - .type = QEMU_OPT_STRING, + .type = QEMU_OPT_NUMBER, }, { .name = "reboot-timeout", - .type = QEMU_OPT_STRING, + .type = QEMU_OPT_NUMBER, }, { .name = "strict", .type = QEMU_OPT_BOOL, @@ -730,6 +723,9 @@ void runstate_set(RunState new_state) { assert(new_state < RUN_STATE__MAX); + trace_runstate_set(current_run_state, RunState_str(current_run_state), + new_state, RunState_str(current_run_state)); + if (current_run_state == new_state) { return; } @@ -740,7 +736,7 @@ void runstate_set(RunState new_state) RunState_str(new_state)); abort(); } - trace_runstate_set(new_state); + current_run_state = new_state; } @@ -1522,16 +1518,13 @@ static int machine_help_func(QemuOpts *opts, MachineState *machine) return 1; } -/***********************************************************/ -/* main execution loop */ - struct vm_change_state_entry { VMChangeStateHandler *cb; void *opaque; QLIST_ENTRY (vm_change_state_entry) entries; }; -static QLIST_HEAD(vm_change_state_head, vm_change_state_entry) vm_change_state_head; +static QLIST_HEAD(, vm_change_state_entry) vm_change_state_head; VMChangeStateEntry *qemu_add_vm_change_state_handler(VMChangeStateHandler *cb, void *opaque) @@ -1556,7 +1549,7 @@ void vm_state_notify(int running, RunState state) { VMChangeStateEntry *e, *next; - trace_vm_state_notify(running, state); + trace_vm_state_notify(running, state, RunState_str(state)); QLIST_FOREACH_SAFE(e, &vm_change_state_head, entries, next) { e->cb(e->opaque, running, state); @@ -1578,6 +1571,8 @@ static NotifierList suspend_notifiers = NOTIFIER_LIST_INITIALIZER(suspend_notifiers); static NotifierList wakeup_notifiers = NOTIFIER_LIST_INITIALIZER(wakeup_notifiers); +static NotifierList shutdown_notifiers = + NOTIFIER_LIST_INITIALIZER(shutdown_notifiers); static uint32_t wakeup_reason_mask = ~(1 << QEMU_WAKEUP_REASON_NONE); ShutdownCause qemu_shutdown_requested_get(void) @@ -1677,7 +1672,7 @@ void qemu_system_reset(ShutdownCause reason) qemu_devices_reset(); } if (reason != SHUTDOWN_CAUSE_SUBSYSTEM_RESET) { - qapi_event_send_reset(shutdown_caused_by_guest(reason)); + qapi_event_send_reset(shutdown_caused_by_guest(reason), reason); } cpu_synchronize_all_post_reset(); } @@ -1753,11 +1748,13 @@ void qemu_register_suspend_notifier(Notifier *notifier) notifier_list_add(&suspend_notifiers, notifier); } -void qemu_system_wakeup_request(WakeupReason reason) +void qemu_system_wakeup_request(WakeupReason reason, Error **errp) { trace_system_wakeup_request(reason); if (!runstate_check(RUN_STATE_SUSPENDED)) { + error_setg(errp, + "Unable to wake up: guest is not in suspended state"); return; } if (!(wakeup_reason_mask & (1 << reason))) { @@ -1782,6 +1779,24 @@ void qemu_register_wakeup_notifier(Notifier *notifier) notifier_list_add(&wakeup_notifiers, notifier); } +void qemu_register_wakeup_support(void) +{ + wakeup_suspend_enabled = true; +} + +bool qemu_wakeup_suspend_enabled(void) +{ + return wakeup_suspend_enabled; +} + +CurrentMachineParams *qmp_query_current_machine(Error **errp) +{ + CurrentMachineParams *params = g_malloc0(sizeof(*params)); + params->wakeup_suspend_support = qemu_wakeup_suspend_enabled(); + + return params; +} + void qemu_system_killed(int signal, pid_t pid) { shutdown_signal = signal; @@ -1809,6 +1824,12 @@ static void qemu_system_powerdown(void) notifier_list_notify(&powerdown_notifiers, NULL); } +static void qemu_system_shutdown(ShutdownCause cause) +{ + qapi_event_send_shutdown(shutdown_caused_by_guest(cause), cause); + notifier_list_notify(&shutdown_notifiers, &cause); +} + void qemu_system_powerdown_request(void) { trace_qemu_system_powerdown_request(); @@ -1821,6 +1842,11 @@ void qemu_register_powerdown_notifier(Notifier *notifier) notifier_list_add(&powerdown_notifiers, notifier); } +void qemu_register_shutdown_notifier(Notifier *notifier) +{ + notifier_list_add(&shutdown_notifiers, notifier); +} + void qemu_system_debug_request(void) { debug_requested = 1; @@ -1848,7 +1874,7 @@ static bool main_loop_should_exit(void) request = qemu_shutdown_requested(); if (request) { qemu_kill_report(); - qapi_event_send_shutdown(shutdown_caused_by_guest(request)); + qemu_system_shutdown(request); if (no_shutdown) { vm_stop(RUN_STATE_SHUTDOWN); } else { @@ -2055,6 +2081,11 @@ static void parse_display_qapi(const char *optarg) visit_free(v); } +DisplayOptions *qmp_query_display_options(Error **errp) +{ + return QAPI_CLONE(DisplayOptions, &dpy); +} + static void parse_display(const char *p) { const char *opts; @@ -2074,18 +2105,7 @@ static void parse_display(const char *p) while (*opts) { const char *nextopt; - if (strstart(opts, ",frame=", &nextopt)) { - g_printerr("The frame= sdl option is deprecated, and will be\n" - "removed in a future release.\n"); - opts = nextopt; - if (strstart(opts, "on", &nextopt)) { - no_frame = 0; - } else if (strstart(opts, "off", &nextopt)) { - no_frame = 1; - } else { - goto invalid_sdl_args; - } - } else if (strstart(opts, ",alt_grab=", &nextopt)) { + if (strstart(opts, ",alt_grab=", &nextopt)) { opts = nextopt; if (strstart(opts, "on", &nextopt)) { alt_grab = 1; @@ -2244,8 +2264,10 @@ static int parse_fw_cfg(void *opaque, QemuOpts *opts, Error **errp) size = strlen(str); /* NUL terminator NOT included in fw_cfg blob */ buf = g_memdup(str, size); } else { - if (!g_file_get_contents(file, &buf, &size, NULL)) { - error_setg(errp, "can't load %s", file); + GError *err = NULL; + if (!g_file_get_contents(file, &buf, &size, &err)) { + error_setg(errp, "can't load %s: %s", file, err->message); + g_error_free(err); return -1; } } @@ -2277,7 +2299,7 @@ static int chardev_init_func(void *opaque, QemuOpts *opts, Error **errp) { Error *local_err = NULL; - if (!qemu_chr_new_from_opts(opts, &local_err)) { + if (!qemu_chr_new_from_opts(opts, NULL, &local_err)) { if (local_err) { error_propagate(errp, local_err); return -1; @@ -2317,11 +2339,6 @@ static int mon_init_func(void *opaque, QemuOpts *opts, Error **errp) if (qemu_opt_get_bool(opts, "pretty", 0)) flags |= MONITOR_USE_PRETTY; - /* OOB is off by default */ - if (qemu_opt_get_bool(opts, "x-oob", 0)) { - flags |= MONITOR_USE_OOB; - } - chardev = qemu_opt_get(opts, "chardev"); if (!chardev) { error_report("chardev is required"); @@ -2369,7 +2386,6 @@ struct device_config { DEV_BT, /* -bt */ DEV_SERIAL, /* -serial */ DEV_PARALLEL, /* -parallel */ - DEV_VIRTCON, /* -virtioconsole */ DEV_DEBUGCON, /* -debugcon */ DEV_GDB, /* -gdb, -s */ DEV_SCLP, /* s390 sclp */ @@ -2421,7 +2437,7 @@ static int serial_parse(const char *devname) snprintf(label, sizeof(label), "serial%d", index); serial_hds = g_renew(Chardev *, serial_hds, index + 1); - serial_hds[index] = qemu_chr_new_mux_mon(label, devname); + serial_hds[index] = qemu_chr_new_mux_mon(label, devname, NULL); if (!serial_hds[index]) { error_report("could not connect serial device" " to character backend '%s'", devname); @@ -2457,7 +2473,7 @@ static int parallel_parse(const char *devname) exit(1); } snprintf(label, sizeof(label), "parallel%d", index); - parallel_hds[index] = qemu_chr_new_mux_mon(label, devname); + parallel_hds[index] = qemu_chr_new_mux_mon(label, devname, NULL); if (!parallel_hds[index]) { error_report("could not connect parallel device" " to character backend '%s'", devname); @@ -2467,44 +2483,11 @@ static int parallel_parse(const char *devname) return 0; } -static int virtcon_parse(const char *devname) -{ - QemuOptsList *device = qemu_find_opts("device"); - static int index = 0; - char label[32]; - QemuOpts *bus_opts, *dev_opts; - - if (strcmp(devname, "none") == 0) - return 0; - if (index == MAX_VIRTIO_CONSOLES) { - error_report("too many virtio consoles"); - exit(1); - } - - bus_opts = qemu_opts_create(device, NULL, 0, &error_abort); - qemu_opt_set(bus_opts, "driver", "virtio-serial", &error_abort); - - dev_opts = qemu_opts_create(device, NULL, 0, &error_abort); - qemu_opt_set(dev_opts, "driver", "virtconsole", &error_abort); - - snprintf(label, sizeof(label), "virtcon%d", index); - virtcon_hds[index] = qemu_chr_new_mux_mon(label, devname); - if (!virtcon_hds[index]) { - error_report("could not connect virtio console" - " to character backend '%s'", devname); - return -1; - } - qemu_opt_set(dev_opts, "chardev", label, &error_abort); - - index++; - return 0; -} - static int debugcon_parse(const char *devname) { QemuOpts *opts; - if (!qemu_chr_new_mux_mon("debugcon", devname)) { + if (!qemu_chr_new_mux_mon("debugcon", devname, NULL)) { error_report("invalid character backend '%s'", devname); exit(1); } @@ -2931,8 +2914,6 @@ static int global_init_func(void *opaque, QemuOpts *opts, Error **errp) g->driver = qemu_opt_get(opts, "driver"); g->property = qemu_opt_get(opts, "property"); g->value = qemu_opt_get(opts, "value"); - g->user_provided = true; - g->errp = &error_fatal; qdev_prop_register_global(g); return 0; } @@ -2963,8 +2944,6 @@ static void user_register_global_props(void) */ static void register_global_properties(MachineState *ms) { - accel_register_compat_props(ms->accelerator); - machine_register_compat_props(ms); user_register_global_props(); } @@ -3057,6 +3036,7 @@ int main(int argc, char **argv, char **envp) module_call_init(MODULE_INIT_OPTS); runstate_init(); + precopy_infrastructure_init(); postcopy_infrastructure_init(); monitor_init_globals(); @@ -3133,11 +3113,8 @@ int main(int argc, char **argv, char **envp) Visitor *v; BlockdevOptions_queue *bdo; - v = qobject_input_visitor_new_str(optarg, "driver", &err); - if (!v) { - error_report_err(err); - exit(1); - } + v = qobject_input_visitor_new_str(optarg, "driver", + &error_fatal); bdo = g_new(BlockdevOptions_queue, 1); visit_type_BlockdevOptions(v, NULL, &bdo->bdo, @@ -3269,12 +3246,19 @@ int main(int argc, char **argv, char **envp) break; #endif case QEMU_OPTION_bt: + warn_report("The bluetooth subsystem is deprecated and will " + "be removed soon. If the bluetooth subsystem is " + "still useful for you, please send a mail to " + "qemu-devel@nongnu.org with your usecase."); add_device_config(DEV_BT, optarg); break; case QEMU_OPTION_audio_help: - AUD_help (); + audio_legacy_help(); exit (0); break; + case QEMU_OPTION_audiodev: + audio_parse_option(optarg); + break; case QEMU_OPTION_soundhw: select_soundhw (optarg); break; @@ -3537,15 +3521,6 @@ int main(int argc, char **argv, char **envp) exit(1); } break; - case QEMU_OPTION_virtiocon: - warn_report("This option is deprecated, " - "use '-device virtconsole' instead"); - add_device_config(DEV_VIRTCON, optarg); - default_virtcon = 0; - if (strncmp(optarg, "mon:", 4) == 0) { - default_monitor = 0; - } - break; case QEMU_OPTION_parallel: add_device_config(DEV_PARALLEL, optarg); default_parallel = 0; @@ -3563,11 +3538,6 @@ int main(int argc, char **argv, char **envp) dpy.has_full_screen = true; dpy.full_screen = true; break; - case QEMU_OPTION_no_frame: - g_printerr("The -no-frame switch is deprecated, and will be\n" - "removed in a future release.\n"); - no_frame = 1; - break; case QEMU_OPTION_alt_grab: alt_grab = 1; break; @@ -3622,11 +3592,6 @@ int main(int argc, char **argv, char **envp) olist = qemu_find_opts("machine"); qemu_opts_parse_noisily(olist, "accel=kvm", false); break; - case QEMU_OPTION_enable_hax: - warn_report("Option is deprecated, use '-accel hax' instead"); - olist = qemu_find_opts("machine"); - qemu_opts_parse_noisily(olist, "accel=hax", false); - break; case QEMU_OPTION_M: case QEMU_OPTION_machine: olist = qemu_find_opts("machine"); @@ -3771,12 +3736,6 @@ int main(int argc, char **argv, char **envp) case QEMU_OPTION_old_param: old_param = 1; break; - case QEMU_OPTION_clock: - /* Clock options no longer exist. Keep this option for - * backward compatibility. - */ - warn_report("This option is ignored and will be removed soon"); - break; case QEMU_OPTION_rtc: opts = qemu_opts_parse_noisily(qemu_find_opts("rtc"), optarg, false); @@ -3826,13 +3785,6 @@ int main(int argc, char **argv, char **envp) } xen_domid = atoi(optarg); break; - case QEMU_OPTION_xen_create: - if (!(xen_available())) { - error_report("Option not supported for this target"); - exit(1); - } - xen_mode = XEN_CREATE; - break; case QEMU_OPTION_xen_attach: if (!(xen_available())) { error_report("Option not supported for this target"); @@ -4162,9 +4114,6 @@ int main(int argc, char **argv, char **envp) if (!has_defaults || machine_class->no_parallel) { default_parallel = 0; } - if (!has_defaults || !machine_class->use_virtcon) { - default_virtcon = 0; - } if (!has_defaults || machine_class->no_floppy) { default_floppy = 0; } @@ -4197,8 +4146,7 @@ int main(int argc, char **argv, char **envp) * usage, -nographic is just a no-op in this case. */ if (nographic - && (default_parallel || default_serial - || default_monitor || default_virtcon)) { + && (default_parallel || default_serial || default_monitor)) { error_report("-nographic cannot be used with -daemonize"); exit(1); } @@ -4215,13 +4163,9 @@ int main(int argc, char **argv, char **envp) add_device_config(DEV_PARALLEL, "null"); if (default_serial && default_monitor) { add_device_config(DEV_SERIAL, "mon:stdio"); - } else if (default_virtcon && default_monitor) { - add_device_config(DEV_VIRTCON, "mon:stdio"); } else { if (default_serial) add_device_config(DEV_SERIAL, "stdio"); - if (default_virtcon) - add_device_config(DEV_VIRTCON, "stdio"); if (default_monitor) monitor_parse("stdio", "readline", false); } @@ -4232,8 +4176,6 @@ int main(int argc, char **argv, char **envp) add_device_config(DEV_PARALLEL, "vc:80Cx24C"); if (default_monitor) monitor_parse("vc:80Cx24C", "readline", false); - if (default_virtcon) - add_device_config(DEV_VIRTCON, "vc:80Cx24C"); } #if defined(CONFIG_VNC) @@ -4253,8 +4195,8 @@ int main(int argc, char **argv, char **envp) dpy.type = DISPLAY_TYPE_NONE; } - if ((no_frame || alt_grab || ctrl_grab) && dpy.type != DISPLAY_TYPE_SDL) { - error_report("-no-frame, -alt-grab and -ctrl-grab are only valid " + if ((alt_grab || ctrl_grab) && dpy.type != DISPLAY_TYPE_SDL) { + error_report("-alt-grab and -ctrl-grab are only valid " "for SDL, ignoring option"); } if (dpy.has_window_close && @@ -4298,8 +4240,11 @@ int main(int argc, char **argv, char **envp) machine_opts = qemu_get_machine_opts(); qemu_opt_foreach(machine_opts, machine_set_property, current_machine, &error_fatal); + current_machine->ram_size = ram_size; + current_machine->maxram_size = maxram_size; + current_machine->ram_slots = ram_slots; - configure_accelerator(current_machine); + configure_accelerator(current_machine, argv[0]); if (!qtest_enabled() && machine_class->deprecation_reason) { error_report("Machine type '%s' is deprecated: %s", @@ -4464,8 +4409,6 @@ int main(int argc, char **argv, char **envp) exit(1); if (foreach_device_config(DEV_PARALLEL, parallel_parse) < 0) exit(1); - if (foreach_device_config(DEV_VIRTCON, virtcon_parse) < 0) - exit(1); if (foreach_device_config(DEV_DEBUGCON, debugcon_parse) < 0) exit(1); @@ -4495,9 +4438,6 @@ int main(int argc, char **argv, char **envp) replay_checkpoint(CHECKPOINT_INIT); qdev_machine_init(); - current_machine->ram_size = ram_size; - current_machine->maxram_size = maxram_size; - current_machine->ram_slots = ram_slots; current_machine->boot_order = boot_order; /* parse features once if machine provides default cpu_type */ @@ -4510,6 +4450,8 @@ int main(int argc, char **argv, char **envp) /* do monitor/qmp handling at preconfig state if requested */ main_loop(); + audio_init_audiodevs(); + /* from here on runstate is RUN_STATE_PRELAUNCH */ machine_run_board_init(current_machine); @@ -4640,6 +4582,12 @@ int main(int argc, char **argv, char **envp) gdbserver_cleanup(); + /* + * cleaning up the migration object cancels any existing migration + * try to do this early so that it also stops using devices. + */ + migration_shutdown(); + /* No more vcpu or device emulation activity beyond this point */ vm_shutdown(); @@ -4655,7 +4603,6 @@ int main(int argc, char **argv, char **envp) monitor_cleanup(); qemu_chr_cleanup(); user_creatable_cleanup(); - migration_object_finalize(); /* TODO: unref root container, check all devices are ok */ return 0;