From 4c4ff1d091270d8daa3ccc75c3eec95490790ac5 Mon Sep 17 00:00:00 2001 From: gdwnldsKSC Date: Tue, 24 Sep 2024 16:21:45 -0400 Subject: [PATCH] 0.12.0-rc2 - upstream a68fc29 - Dec 12, 2009 --- WinQemu.vcxproj | 1 + WinQemu.vcxproj.filters | 3 + qemu/Changelog | 36 ++++ qemu/Makefile | 17 +- qemu/VERSION | 2 +- qemu/block.c | 207 ++++++++++++++++--- qemu/block.h | 7 +- qemu/config-host.h | 2 +- qemu/console.h | 6 +- qemu/hw/boards.h | 4 + qemu/hw/pci-hotplug.c | 58 +++++- qemu/hw/pci.c | 11 +- qemu/hw/s390-virtio.c | 4 + qemu/migration.c | 117 +++++++++-- qemu/migration.h | 4 +- qemu/monitor.c | 313 +++++++++++++++++++++------- qemu/monitor.h | 2 - qemu/net.c | 6 +- qemu/net.h | 1 + qemu/qdict.c | 28 +++ qemu/qdict.h | 3 + qemu/qemu-char.c | 45 ++++- qemu/qemu-char.h | 5 +- qemu/qemu-config.c | 19 ++ qemu/qemu-config.h | 1 + qemu/qemu-monitor.h | 3 +- qemu/qemu-monitor.hx | 3 +- qemu/qemu-objects.h | 24 +++ qemu/qemu-option.c | 4 +- qemu/qemu-options.h | 8 + qemu/qemu-options.hx | 14 ++ qemu/sysemu.h | 9 +- qemu/target-i386/cpu.h | 2 + qemu/target-i386/kvm.c | 15 ++ qemu/target-i386/machine.c | 3 + qemu/vl.c | 405 ++++++++++++++++++++++++------------- qemu/vnc.c | 201 ++++++++++++++---- 37 files changed, 1263 insertions(+), 330 deletions(-) create mode 100644 qemu/qemu-objects.h diff --git a/WinQemu.vcxproj b/WinQemu.vcxproj index 1ed93590..9726d007 100644 --- a/WinQemu.vcxproj +++ b/WinQemu.vcxproj @@ -1780,6 +1780,7 @@ + diff --git a/WinQemu.vcxproj.filters b/WinQemu.vcxproj.filters index e5b2e9dc..09fca065 100644 --- a/WinQemu.vcxproj.filters +++ b/WinQemu.vcxproj.filters @@ -2108,6 +2108,9 @@ qemu\inc + + qemu\inc + diff --git a/qemu/Changelog b/qemu/Changelog index 2a3e37d2..79cd934a 100644 --- a/qemu/Changelog +++ b/qemu/Changelog @@ -1,3 +1,39 @@ +version 0.12.0-rc2: + + - v2: properly save kvm system time msr registers (Glauber Costa) + - convert more monitor commands to qmp (Luiz Capitulino) + - vnc: fix capslock tracking logic. (Gerd Hoffmann) + - QemuOpts: allow larger option values. (Gerd Hoffmann) + - scsi: fix drive hotplug. (Gerd Hoffmann) + - pci: don't hw_error() when no slot is available. (Gerd Hoffmann) + - pci: don't abort() when trying to hotplug with acpi off. (Gerd Hoffmann) + - allow default devices to be implemented in config file (Gerd Hoffman) + - vc: colorize chardev title line with blue background. (Gerd Hoffmann) + - chardev: make chardevs specified in config file work. (Gerd Hoffmann) + - qdev: also match bus name for global properties (Gerd Hoffmann) + - qdev: add command line option to set global defaults for properties. (Gerd Hoffmann) + - kvm: x86: Save/restore exception_index (Jan Kiszka) + - qdev: Replace device names containing whitespace (Markus Armbruster) + - fix rtc-td-hack on host without high-res timers (Gleb Natapov) + - virtio: verify features on load (Michael S. Tsirkin) + - vmware_vga: add rom file so that it boots. (Dave Airlie) + - Do not abort on qemu_malloc(0) in production builds (Anthony Liguori) + - Fix ARM userspace strex implementation. (Paul Brook) + - qemu: delete rule target on error (Michael S. Tsirkin) + - QMP: add human-readable description to error response (Markus Armbruster) + - convert more monitor commands to QError (Markus Armbruster) + - monitor: Fix double-prompt after "change vnc passwd BLA" (Markus Armbruster) + - monitor: do_cont(): Don't ask for passwords (Luiz Capitulino) + - monitor: Introduce 'block_passwd' command (Luiz Capitulino) + - pci: interrupt disable bit support (Michael S. Tsirkin) + - pci: interrupt status bit implementation (Michael S. Tsirkin) + - pci: prepare irq code for interrupt state (Michael S. Tsirkin) + - msix: function mask support (Michael S. Tsirkin) + - msix: macro rename for function mask support (Michael S. Tsirkin) + - cpuid: Fix multicore setup on Intel (Andre Przywara) + - kvm: x86: Fix initial kvm_has_msr_star (Jan Kiszka) + - Update OpenBIOS images to r640 (Aurelien Jarno) + version 0.10.2: - fix savevm/loadvm (Anthony Liguori) diff --git a/qemu/Makefile b/qemu/Makefile index 85ad6884..a662d96a 100644 --- a/qemu/Makefile +++ b/qemu/Makefile @@ -81,6 +81,12 @@ ALL_SUBDIRS=$(TARGET_DIRS) $(patsubst %,pc-bios/%, $(ROMS)) recurse-all: $(SUBDIR_RULES) $(ROMSUBDIR_RULES) +####################################################################### +# QObject +qobject-obj-y = qint.o qstring.o qdict.o qlist.o qfloat.o qbool.o +qobject-obj-y += qjson.o json-lexer.o json-streamer.o json-parser.o +qobject-obj-y += qerror.o + ####################################################################### # block-obj-y is code used by both qemu system emulation and qemu-img @@ -120,6 +126,7 @@ net-obj-y += $(addprefix net/, $(net-nested-y)) obj-y = $(block-obj-y) obj-y += $(net-obj-y) +obj-y += $(qobject-obj-y) obj-y += readline.o console.o obj-y += tcg-runtime.o host-utils.o @@ -152,8 +159,6 @@ obj-y += buffered_file.o migration.o migration-tcp.o qemu-sockets.o obj-y += qemu-char.o aio.o savevm.o obj-y += msmouse.o ps2.o obj-y += qdev.o qdev-properties.o -obj-y += qint.o qstring.o qdict.o qlist.o qfloat.o qbool.o json-lexer.o -obj-y += json-streamer.o json-parser.o qjson.o qerror.o obj-y += qemu-config.o block-migration.o obj-$(CONFIG_BRLAPI) += baum.o @@ -230,18 +235,18 @@ libqemu_common.a: $(obj-y) qemu-img.o: qemu-img-cmds.h -qemu-img$(EXESUF): qemu-img.o qemu-tool.o $(block-obj-y) +qemu-img$(EXESUF): qemu-img.o qemu-tool.o $(block-obj-y) $(qobject-obj-y) -qemu-nbd$(EXESUF): qemu-nbd.o qemu-tool.o $(block-obj-y) +qemu-nbd$(EXESUF): qemu-nbd.o qemu-tool.o $(block-obj-y) $(qobject-obj-y) -qemu-io$(EXESUF): qemu-io.o qemu-tool.o cmd.o $(block-obj-y) +qemu-io$(EXESUF): qemu-io.o qemu-tool.o cmd.o $(block-obj-y) $(qobject-obj-y) qemu-img-cmds.h: $(SRC_PATH)/qemu-img-cmds.hx $(call quiet-command,sh $(SRC_PATH)/hxtool -h < $< > $@," GEN $@") check-qint: check-qint.o qint.o qemu-malloc.o check-qstring: check-qstring.o qstring.o qemu-malloc.o -check-qdict: check-qdict.o qdict.o qint.o qstring.o qemu-malloc.o +check-qdict: check-qdict.o qdict.o qint.o qstring.o qbool.o qemu-malloc.o qlist.o check-qlist: check-qlist.o qlist.o qint.o qemu-malloc.o check-qfloat: check-qfloat.o qfloat.o qemu-malloc.o check-qjson: check-qjson.o qfloat.o qint.o qdict.o qstring.o qlist.o qbool.o qjson.o json-streamer.o json-lexer.o json-parser.o qemu-malloc.o diff --git a/qemu/VERSION b/qemu/VERSION index 568d1523..c2527649 100644 --- a/qemu/VERSION +++ b/qemu/VERSION @@ -1 +1 @@ -0.11.91 +0.11.92 diff --git a/qemu/block.c b/qemu/block.c index 96b4a29b..fba557c6 100644 --- a/qemu/block.c +++ b/qemu/block.c @@ -38,6 +38,7 @@ #include "monitor.h" #include "block_int.h" #include "module.h" +#include "qemu-objects.h" #ifdef CONFIG_BSD #include @@ -1164,61 +1165,203 @@ int bdrv_is_allocated(BlockDriverState *bs, int64_t sector_num, int nb_sectors, return bs->drv->bdrv_is_allocated(bs, sector_num, nb_sectors, pnum); } -void bdrv_info(Monitor *mon) +static void bdrv_print_dict(QObject *obj, void *opaque) { + QDict *bs_dict; + Monitor *mon = opaque; + + bs_dict = qobject_to_qdict(obj); + + monitor_printf(mon, "%s: type=%s removable=%d", + qdict_get_str(bs_dict, "device"), + qdict_get_str(bs_dict, "type"), + qdict_get_bool(bs_dict, "removable")); + + if (qdict_get_bool(bs_dict, "removable")) { + monitor_printf(mon, " locked=%d", qdict_get_bool(bs_dict, "locked")); + } + + if (qdict_haskey(bs_dict, "inserted")) { + QDict *qdict = qobject_to_qdict(qdict_get(bs_dict, "inserted")); + + monitor_printf(mon, " file="); + monitor_print_filename(mon, qdict_get_str(qdict, "file")); + if (qdict_haskey(qdict, "backing_file")) { + monitor_printf(mon, " backing_file="); + monitor_print_filename(mon, qdict_get_str(qdict, "backing_file")); + } + monitor_printf(mon, " ro=%d drv=%s encrypted=%d", + qdict_get_bool(qdict, "ro"), + qdict_get_str(qdict, "drv"), + qdict_get_bool(qdict, "encrypted")); + } else { + monitor_printf(mon, " [not inserted]"); + } + + monitor_printf(mon, "\n"); +} + +void bdrv_info_print(Monitor *mon, const QObject *data) +{ + qlist_iter(qobject_to_qlist(data), bdrv_print_dict, mon); +} + +/** + * bdrv_info(): Block devices information + * + * Each block device information is stored in a QDict and the + * returned QObject is a QList of all devices. + * + * The QDict contains the following: + * + * - "device": device name + * - "type": device type + * - "removable": true if the device is removable, false otherwise + * - "locked": true if the device is locked, false otherwise + * - "inserted": only present if the device is inserted, it is a QDict + * containing the following: + * - "file": device file name + * - "ro": true if read-only, false otherwise + * - "drv": driver format name + * - "backing_file": backing file name if one is used + * - "encrypted": true if encrypted, false otherwise + * + * Example: + * + * [ { "device": "ide0-hd0", "type": "hd", "removable": false, "locked": false, + * "inserted": { "file": "/tmp/foobar", "ro": false, "drv": "qcow2" } }, + * { "device": "floppy0", "type": "floppy", "removable": true, + * "locked": false } ] + */ +void bdrv_info(Monitor *mon, QObject **ret_data) +{ + QList *bs_list; BlockDriverState *bs; + bs_list = qlist_new(); + for (bs = bdrv_first; bs != NULL; bs = bs->next) { - monitor_printf(mon, "%s:", bs->device_name); - monitor_printf(mon, " type="); + QObject *bs_obj; + const char *type = "unknown"; + switch(bs->type) { case BDRV_TYPE_HD: - monitor_printf(mon, "hd"); + type = "hd"; break; case BDRV_TYPE_CDROM: - monitor_printf(mon, "cdrom"); + type = "cdrom"; break; case BDRV_TYPE_FLOPPY: - monitor_printf(mon, "floppy"); + type = "floppy"; break; } - monitor_printf(mon, " removable=%d", bs->removable); - if (bs->removable) { - monitor_printf(mon, " locked=%d", bs->locked); - } + + bs_obj = qobject_from_jsonf("{ 'device': %s, 'type': %s, " + "'removable': %i, 'locked': %i }", + bs->device_name, type, bs->removable, + bs->locked); + assert(bs_obj != NULL); + if (bs->drv) { - monitor_printf(mon, " file="); - monitor_print_filename(mon, bs->filename); + QObject *obj; + QDict *bs_dict = qobject_to_qdict(bs_obj); + + obj = qobject_from_jsonf("{ 'file': %s, 'ro': %i, 'drv': %s, " + "'encrypted': %i }", + bs->filename, bs->read_only, + bs->drv->format_name, + bdrv_is_encrypted(bs)); + assert(obj != NULL); if (bs->backing_file[0] != '\0') { - monitor_printf(mon, " backing_file="); - monitor_print_filename(mon, bs->backing_file); + QDict *qdict = qobject_to_qdict(obj); + qdict_put(qdict, "backing_file", + qstring_from_str(bs->backing_file)); } - monitor_printf(mon, " ro=%d", bs->read_only); - monitor_printf(mon, " drv=%s", bs->drv->format_name); - monitor_printf(mon, " encrypted=%d", bdrv_is_encrypted(bs)); - } else { - monitor_printf(mon, " [not inserted]"); + + qdict_put_obj(bs_dict, "inserted", obj); } - monitor_printf(mon, "\n"); + qlist_append_obj(bs_list, bs_obj); } + + *ret_data = QOBJECT(bs_list); +} + +static void bdrv_stats_iter(QObject *data, void *opaque) +{ + QDict *qdict; + Monitor *mon = opaque; + + qdict = qobject_to_qdict(data); + monitor_printf(mon, "%s:", qdict_get_str(qdict, "device")); + + qdict = qobject_to_qdict(qdict_get(qdict, "stats")); + monitor_printf(mon, " rd_bytes=%" PRId64 + " wr_bytes=%" PRId64 + " rd_operations=%" PRId64 + " wr_operations=%" PRId64 + "\n", + qdict_get_int(qdict, "rd_bytes"), + qdict_get_int(qdict, "wr_bytes"), + qdict_get_int(qdict, "rd_operations"), + qdict_get_int(qdict, "wr_operations")); } -/* The "info blockstats" command. */ -void bdrv_info_stats(Monitor *mon) +void bdrv_stats_print(Monitor *mon, const QObject *data) { + qlist_iter(qobject_to_qlist(data), bdrv_stats_iter, mon); +} + +/** + * bdrv_info_stats(): show block device statistics + * + * Each device statistic information is stored in a QDict and + * the returned QObject is a QList of all devices. + * + * The QDict contains the following: + * + * - "device": device name + * - "stats": A QDict with the statistics information, it contains: + * - "rd_bytes": bytes read + * - "wr_bytes": bytes written + * - "rd_operations": read operations + * - "wr_operations": write operations + * + * Example: + * + * [ { "device": "ide0-hd0", + * "stats": { "rd_bytes": 512, + * "wr_bytes": 0, + * "rd_operations": 1, + * "wr_operations": 0 } }, + * { "device": "ide1-cd0", + * "stats": { "rd_bytes": 0, + * "wr_bytes": 0, + * "rd_operations": 0, + * "wr_operations": 0 } } ] + */ +void bdrv_info_stats(Monitor *mon, QObject **ret_data) +{ + QObject *obj; + QList *devices; BlockDriverState *bs; + devices = qlist_new(); + for (bs = bdrv_first; bs != NULL; bs = bs->next) { - monitor_printf(mon, "%s:" - " rd_bytes=%" PRIu64 - " wr_bytes=%" PRIu64 - " rd_operations=%" PRIu64 - " wr_operations=%" PRIu64 - "\n", - bs->device_name, - bs->rd_bytes, bs->wr_bytes, - bs->rd_ops, bs->wr_ops); - } + obj = qobject_from_jsonf("{ 'device': %s, 'stats': {" + "'rd_bytes': %" PRId64 "," + "'wr_bytes': %" PRId64 "," + "'rd_operations': %" PRId64 "," + "'wr_operations': %" PRId64 + "} }", + bs->device_name, + bs->rd_bytes, bs->wr_bytes, + bs->rd_ops, bs->wr_ops); + assert(obj != NULL); + qlist_append_obj(devices, obj); + } + + *ret_data = QOBJECT(devices); } const char *bdrv_get_encrypted_filename(BlockDriverState *bs) diff --git a/qemu/block.h b/qemu/block.h index 4a8b6283..fa51ddf1 100644 --- a/qemu/block.h +++ b/qemu/block.h @@ -4,6 +4,7 @@ #include "qemu-aio.h" #include "qemu-common.h" #include "qemu-option.h" +#include "qobject.h" /* block.c */ typedef struct BlockDriver BlockDriver; @@ -45,8 +46,10 @@ typedef struct QEMUSnapshotInfo { #define BDRV_SECTOR_SIZE (1 << BDRV_SECTOR_BITS) #define BDRV_SECTOR_MASK ~(BDRV_SECTOR_SIZE - 1); -void bdrv_info(Monitor *mon); -void bdrv_info_stats(Monitor *mon); +void bdrv_info_print(Monitor *mon, const QObject *data); +void bdrv_info(Monitor *mon, QObject **ret_data); +void bdrv_stats_print(Monitor *mon, const QObject *data); +void bdrv_info_stats(Monitor *mon, QObject **ret_data); void bdrv_init(void); void bdrv_init_with_whitelist(void); diff --git a/qemu/config-host.h b/qemu/config-host.h index 31cc52e4..d21e7407 100644 --- a/qemu/config-host.h +++ b/qemu/config-host.h @@ -9,7 +9,7 @@ #define CONFIG_STATIC 1 #define CONFIG_SLIRP 1 #define CONFIG_ADLIB 1 -#define QEMU_VERSION "pre-0.12.0-rc1" +#define QEMU_VERSION "0.11.92" #define QEMU_PKGVERSION "MS-VisualStudio-2022" #define CONFIG_UNAME_RELEASE "" #define CONFIG_AUDIO_DRIVERS &winwave_audio_driver, \ diff --git a/qemu/console.h b/qemu/console.h index 9615f563..dfc8ae41 100644 --- a/qemu/console.h +++ b/qemu/console.h @@ -44,7 +44,8 @@ struct MouseTransformInfo { int a[7]; }; -void do_info_mice(Monitor *mon); +void do_info_mice_print(Monitor *mon, const QObject *data); +void do_info_mice(Monitor *mon, QObject **ret_data); void do_mouse_set(Monitor *mon, const QDict *qdict); /* keysym is a unicode code except for special keys (see QEMU_KEY_xxx @@ -322,7 +323,8 @@ void vnc_display_init(DisplayState *ds); void vnc_display_close(DisplayState *ds); int vnc_display_open(DisplayState *ds, const char *display); int vnc_display_password(DisplayState *ds, const char *password); -void do_info_vnc(Monitor *mon); +void do_info_vnc_print(Monitor *mon, const QObject *data); +void do_info_vnc(Monitor *mon, QObject **ret_data); char *vnc_display_local_addr(DisplayState *ds); /* curses.c */ diff --git a/qemu/hw/boards.h b/qemu/hw/boards.h index 7a0f20f6..8fe0fbc8 100644 --- a/qemu/hw/boards.h +++ b/qemu/hw/boards.h @@ -19,6 +19,10 @@ typedef struct QEMUMachine { QEMUMachineInitFunc *init; int use_scsi; int max_cpus; + int no_serial:1, + no_parallel:1, + use_virtcon:1, + no_vga:1; int is_default; GlobalProperty *compat_props; struct QEMUMachine *next; diff --git a/qemu/hw/pci-hotplug.c b/qemu/hw/pci-hotplug.c index 081d6d1a..f10c868e 100644 --- a/qemu/hw/pci-hotplug.c +++ b/qemu/hw/pci-hotplug.c @@ -33,6 +33,7 @@ #include "scsi.h" #include "virtio-blk.h" #include "qemu-config.h" +#include "qemu-objects.h" #if defined(TARGET_I386) static PCIDevice *qemu_pci_hot_add_nic(Monitor *mon, @@ -40,7 +41,18 @@ static PCIDevice *qemu_pci_hot_add_nic(Monitor *mon, const char *opts_str) { QemuOpts *opts; - int ret; + PCIBus *bus; + int ret, devfn; + + bus = pci_get_bus_devfn(&devfn, devaddr); + if (!bus) { + monitor_printf(mon, "Invalid PCI device address %s\n", devaddr); + return NULL; + } + if (!((BusState*)bus)->allow_hotplug) { + monitor_printf(mon, "PCI bus doesn't support hotplug\n"); + return NULL; + } opts = qemu_opts_parse(&qemu_net_opts, opts_str ? opts_str : "", NULL); if (!opts) { @@ -82,6 +94,7 @@ static int scsi_hot_add(DeviceState *adapter, DriveInfo *dinfo, int printinfo) */ dinfo->unit = qemu_opt_get_number(dinfo->opts, "unit", -1); scsidev = scsi_bus_legacy_add_drive(scsibus, dinfo, dinfo->unit); + dinfo->unit = scsidev->id; if (printinfo) qemu_error("OK bus %d, unit %d\n", scsibus->busnr, scsidev->id); @@ -179,6 +192,10 @@ static PCIDevice *qemu_pci_hot_add_storage(Monitor *mon, monitor_printf(mon, "Invalid PCI device address %s\n", devaddr); return NULL; } + if (!((BusState*)bus)->allow_hotplug) { + monitor_printf(mon, "PCI bus doesn't support hotplug\n"); + return NULL; + } switch (type) { case IF_SCSI: @@ -212,7 +229,36 @@ static PCIDevice *qemu_pci_hot_add_storage(Monitor *mon, return dev; } -void pci_device_hot_add(Monitor *mon, const QDict *qdict) +void pci_device_hot_add_print(Monitor *mon, const QObject *data) +{ + QDict *qdict; + + assert(qobject_type(data) == QTYPE_QDICT); + qdict = qobject_to_qdict(data); + + monitor_printf(mon, "OK domain %d, bus %d, slot %d, function %d\n", + (int) qdict_get_int(qdict, "domain"), + (int) qdict_get_int(qdict, "bus"), + (int) qdict_get_int(qdict, "slot"), + (int) qdict_get_int(qdict, "function")); + +} + +/** + * pci_device_hot_add(): Hot add a PCI device + * + * Return a QDict with the following device information: + * + * - "domain": domain number + * - "bus": bus number + * - "slot": slot number + * - "function": function number + * + * Example: + * + * { "domain": 0, "bus": 0, "slot": 5, "function": 0 } + */ +void pci_device_hot_add(Monitor *mon, const QDict *qdict, QObject **ret_data) { PCIDevice *dev = NULL; const char *pci_addr = qdict_get_str(qdict, "pci_addr"); @@ -239,9 +285,11 @@ void pci_device_hot_add(Monitor *mon, const QDict *qdict) monitor_printf(mon, "invalid type: %s\n", type); if (dev) { - monitor_printf(mon, "OK domain %d, bus %d, slot %d, function %d\n", - 0, pci_bus_num(dev->bus), PCI_SLOT(dev->devfn), - PCI_FUNC(dev->devfn)); + *ret_data = + qobject_from_jsonf("{ 'domain': 0, 'bus': %d, 'slot': %d, " + "'function': %d }", pci_bus_num(dev->bus), + PCI_SLOT(dev->devfn), PCI_FUNC(dev->devfn)); + assert(*ret_data != NULL); } else monitor_printf(mon, "failed to add %s\n", opts); } diff --git a/qemu/hw/pci.c b/qemu/hw/pci.c index 7d034db4..e2b38acb 100644 --- a/qemu/hw/pci.c +++ b/qemu/hw/pci.c @@ -580,11 +580,13 @@ static PCIDevice *do_pci_register_device(PCIDevice *pci_dev, PCIBus *bus, if (!bus->devices[devfn]) goto found; } - hw_error("PCI: no devfn available for %s, all in use\n", name); + qemu_error("PCI: no devfn available for %s, all in use\n", name); + return NULL; found: ; } else if (bus->devices[devfn]) { - hw_error("PCI: devfn %d not available for %s, in use by %s\n", devfn, + qemu_error("PCI: devfn %d not available for %s, in use by %s\n", devfn, name, bus->devices[devfn]->name); + return NULL; } pci_dev->bus = bus; pci_dev->devfn = devfn; @@ -625,6 +627,9 @@ PCIDevice *pci_register_device(PCIBus *bus, const char *name, pci_dev = do_pci_register_device(pci_dev, bus, name, devfn, config_read, config_write, PCI_HEADER_TYPE_NORMAL); + if (pci_dev == NULL) { + hw_error("PCI: can't register device\n"); + } return pci_dev; } static target_phys_addr_t pci_to_cpu_addr(target_phys_addr_t addr) @@ -1376,6 +1381,8 @@ static int pci_qdev_init(DeviceState *qdev, DeviceInfo *base) pci_dev = do_pci_register_device(pci_dev, bus, base->name, devfn, info->config_read, info->config_write, info->header_type); + if (pci_dev == NULL) + return -1; rc = info->init(pci_dev); if (rc != 0) return rc; diff --git a/qemu/hw/s390-virtio.c b/qemu/hw/s390-virtio.c index cc21ee6d..51c032ad 100644 --- a/qemu/hw/s390-virtio.c +++ b/qemu/hw/s390-virtio.c @@ -243,6 +243,10 @@ static QEMUMachine s390_machine = { .alias = "s390", .desc = "VirtIO based S390 machine", .init = s390_init, + .no_serial = 1, + .no_parallel = 1, + .use_virtcon = 1. + .no_vga = 1, .max_cpus = 255, .is_default = 1, }; diff --git a/qemu/migration.c b/qemu/migration.c index d6a3e261..fda61e64 100644 --- a/qemu/migration.c +++ b/qemu/migration.c @@ -19,6 +19,7 @@ #include "block.h" #include "qemu_socket.h" #include "block-migration.h" +#include "qemu-objects.h" //#define DEBUG_MIGRATION @@ -163,37 +164,123 @@ void do_migrate_set_downtime(Monitor *mon, const QDict *qdict) max_downtime = (uint64_t)d; } -void do_info_migrate(Monitor *mon) +static void migrate_print_status(Monitor *mon, const char *name, + const QDict *status_dict) { + QDict *qdict; + + qdict = qobject_to_qdict(qdict_get(status_dict, name)); + + monitor_printf(mon, "transferred %s: %" PRIu64 " kbytes\n", name, + qdict_get_int(qdict, "transferred") >> 10); + monitor_printf(mon, "remaining %s: %" PRIu64 " kbytes\n", name, + qdict_get_int(qdict, "remaining") >> 10); + monitor_printf(mon, "total %s: %" PRIu64 " kbytes\n", name, + qdict_get_int(qdict, "total") >> 10); +} + +void do_info_migrate_print(Monitor *mon, const QObject *data) +{ + QDict *qdict; + + qdict = qobject_to_qdict(data); + + monitor_printf(mon, "Migration status: %s\n", + qdict_get_str(qdict, "status")); + + if (qdict_haskey(qdict, "ram")) { + migrate_print_status(mon, "ram", qdict); + } + + if (qdict_haskey(qdict, "disk")) { + migrate_print_status(mon, "disk", qdict); + } +} + +static void migrate_put_status(QDict *qdict, const char *name, + uint64_t trans, uint64_t rem, uint64_t total) +{ + QObject *obj; + + obj = qobject_from_jsonf("{ 'transferred': %" PRId64 ", " + "'remaining': %" PRId64 ", " + "'total': %" PRId64 " }", trans, rem, total); + assert(obj != NULL); + + qdict_put_obj(qdict, name, obj); +} + +/** + * do_info_migrate(): Migration status + * + * Return a QDict. If migration is active there will be another + * QDict with RAM migration status and if block migration is active + * another one with block migration status. + * + * The main QDict contains the following: + * + * - "status": migration status + * - "ram": only present if "status" is "active", it is a QDict with the + * following RAM information (in bytes): + * - "transferred": amount transferred + * - "remaining": amount remaining + * - "total": total + * - "disk": only present if "status" is "active" and it is a block migration, + * it is a QDict with the following disk information (in bytes): + * - "transferred": amount transferred + * - "remaining": amount remaining + * - "total": total + * + * Examples: + * + * 1. Migration is "completed": + * + * { "status": "completed" } + * + * 2. Migration is "active" and it is not a block migration: + * + * { "status": "active", + * "ram": { "transferred": 123, "remaining": 123, "total": 246 } } + * + * 3. Migration is "active" and it is a block migration: + * + * { "status": "active", + * "ram": { "total": 1057024, "remaining": 1053304, "transferred": 3720 }, + * "disk": { "total": 20971520, "remaining": 20880384, "transferred": 91136 }} + */ +void do_info_migrate(Monitor *mon, QObject **ret_data) +{ + QDict *qdict; MigrationState *s = current_migration; if (s) { - monitor_printf(mon, "Migration status: "); switch (s->get_status(s)) { case MIG_STATE_ACTIVE: - monitor_printf(mon, "active\n"); - monitor_printf(mon, "transferred ram: %" PRIu64 " kbytes\n", ram_bytes_transferred() >> 10); - monitor_printf(mon, "remaining ram: %" PRIu64 " kbytes\n", ram_bytes_remaining() >> 10); - monitor_printf(mon, "total ram: %" PRIu64 " kbytes\n", ram_bytes_total() >> 10); + qdict = qdict_new(); + qdict_put(qdict, "status", qstring_from_str("active")); + + migrate_put_status(qdict, "ram", ram_bytes_transferred(), + ram_bytes_remaining(), ram_bytes_total()); + if (blk_mig_active()) { - monitor_printf(mon, "transferred disk: %" PRIu64 " kbytes\n", - blk_mig_bytes_transferred() >> 10); - monitor_printf(mon, "remaining disk: %" PRIu64 " kbytes\n", - blk_mig_bytes_remaining() >> 10); - monitor_printf(mon, "total disk: %" PRIu64 " kbytes\n", - blk_mig_bytes_total() >> 10); + migrate_put_status(qdict, "disk", blk_mig_bytes_transferred(), + blk_mig_bytes_remaining(), + blk_mig_bytes_total()); } + + *ret_data = QOBJECT(qdict); break; case MIG_STATE_COMPLETED: - monitor_printf(mon, "completed\n"); + *ret_data = qobject_from_jsonf("{ 'status': 'completed' }"); break; case MIG_STATE_ERROR: - monitor_printf(mon, "failed\n"); + *ret_data = qobject_from_jsonf("{ 'status': 'failed' }"); break; case MIG_STATE_CANCELLED: - monitor_printf(mon, "cancelled\n"); + *ret_data = qobject_from_jsonf("{ 'status': 'cancelled' }"); break; } + assert(*ret_data != NULL); } } diff --git a/qemu/migration.h b/qemu/migration.h index 3f2b3df2..3ac208bf 100644 --- a/qemu/migration.h +++ b/qemu/migration.h @@ -62,7 +62,9 @@ uint64_t migrate_max_downtime(void); void do_migrate_set_downtime(Monitor *mon, const QDict *qdict); -void do_info_migrate(Monitor *mon); +void do_info_migrate_print(Monitor *mon, const QObject *data); + +void do_info_migrate(Monitor *mon, QObject **ret_data); int exec_start_incoming_migration(const char *host_port); diff --git a/qemu/monitor.c b/qemu/monitor.c index 17a31cf6..781f8431 100644 --- a/qemu/monitor.c +++ b/qemu/monitor.c @@ -257,24 +257,6 @@ static inline int monitor_has_error(const Monitor *mon) return mon->error != NULL; } -static void monitor_print_qobject(Monitor *mon, const QObject *data) -{ - switch (qobject_type(data)) { - case QTYPE_QSTRING: - monitor_printf(mon, "%s",qstring_get_str(qobject_to_qstring(data))); - break; - case QTYPE_QINT: - monitor_printf(mon, "%" PRId64,qint_get_int(qobject_to_qint(data))); - break; - default: - monitor_printf(mon, "ERROR: unsupported type: %d", - qobject_type(data)); - break; - } - - monitor_puts(mon, "\n"); -} - static void monitor_json_emitter(Monitor *mon, const QObject *data) { QString *json; @@ -504,24 +486,91 @@ static void do_info(Monitor *mon, const QDict *qdict, QObject **ret_data) help_cmd(mon, "info"); } +static void do_info_version_print(Monitor *mon, const QObject *data) +{ + QDict *qdict; + + qdict = qobject_to_qdict(data); + + monitor_printf(mon, "%s%s\n", qdict_get_str(qdict, "qemu"), + qdict_get_str(qdict, "package")); +} + /** * do_info_version(): Show QEMU version + * + * Return a QDict with the following information: + * + * - "qemu": QEMU's version + * - "package": package's version + * + * Example: + * + * { "qemu": "0.11.50", "package": "" } */ static void do_info_version(Monitor *mon, QObject **ret_data) { - *ret_data = QOBJECT(qstring_from_str(QEMU_VERSION QEMU_PKGVERSION)); + *ret_data = qobject_from_jsonf("{ 'qemu': %s, 'package': %s }", + QEMU_VERSION, QEMU_PKGVERSION); } -static void do_info_name(Monitor *mon) +static void do_info_name_print(Monitor *mon, const QObject *data) { - if (qemu_name) - monitor_printf(mon, "%s\n", qemu_name); + QDict *qdict; + + qdict = qobject_to_qdict(data); + if (qdict_size(qdict) == 0) { + return; + } + + monitor_printf(mon, "%s\n", qdict_get_str(qdict, "name")); +} + +/** + * do_info_name(): Show VM name + * + * Return a QDict with the following information: + * + * - "name": VM's name (optional) + * + * Example: + * + * { "name": "qemu-name" } + */ +static void do_info_name(Monitor *mon, QObject **ret_data) +{ + *ret_data = qemu_name ? qobject_from_jsonf("{'name': %s }", qemu_name) : + qobject_from_jsonf("{}"); +} + +static QObject *get_cmd_dict(const char *name) +{ + const char *p; + + /* Remove '|' from some commands */ + p = strchr(name, '|'); + if (p) { + p++; + } else { + p = name; + } + + return qobject_from_jsonf("{ 'name': %s }", p); } /** * do_info_commands(): List QMP available commands * - * Return a QList of QStrings. + * Each command is represented by a QDict, the returned QObject is a QList + * of all commands. + * + * The QDict contains: + * + * - "name": command's name + * + * Example: + * + * { [ { "name": "query-balloon" }, { "name": "system_powerdown" } ] } */ static void do_info_commands(Monitor *mon, QObject **ret_data) { @@ -532,7 +581,7 @@ static void do_info_commands(Monitor *mon, QObject **ret_data) for (cmd = mon_cmds; cmd->name != NULL; cmd++) { if (monitor_handler_ported(cmd) && !compare_cmd(cmd->name, "info")) { - qlist_append(cmd_list, qstring_from_str(cmd->name)); + qlist_append_obj(cmd_list, get_cmd_dict(cmd->name)); } } @@ -540,7 +589,7 @@ static void do_info_commands(Monitor *mon, QObject **ret_data) if (monitor_handler_ported(cmd)) { char buf[128]; snprintf(buf, sizeof(buf), "query-%s", cmd->name); - qlist_append(cmd_list, qstring_from_str(buf)); + qlist_append_obj(cmd_list, get_cmd_dict(buf)); } } @@ -548,20 +597,56 @@ static void do_info_commands(Monitor *mon, QObject **ret_data) } #if defined(TARGET_I386) -static void do_info_hpet(Monitor *mon) +static void do_info_hpet_print(Monitor *mon, const QObject *data) { monitor_printf(mon, "HPET is %s by QEMU\n", - (no_hpet) ? "disabled" : "enabled"); + qdict_get_bool(qobject_to_qdict(data), "enabled") ? + "enabled" : "disabled"); +} + +/** + * do_info_hpet(): Show HPET state + * + * Return a QDict with the following information: + * + * - "enabled": true if hpet if enabled, false otherwise + * + * Example: + * + * { "enabled": true } + */ +static void do_info_hpet(Monitor *mon, QObject **ret_data) +{ + *ret_data = qobject_from_jsonf("{ 'enabled': %i }", !no_hpet); } #endif -static void do_info_uuid(Monitor *mon) +static void do_info_uuid_print(Monitor *mon, const QObject *data) { - monitor_printf(mon, UUID_FMT "\n", qemu_uuid[0], qemu_uuid[1], + monitor_printf(mon, "%s\n", qdict_get_str(qobject_to_qdict(data), "UUID")); +} + +/** + * do_info_uuid(): Show VM UUID + * + * Return a QDict with the following information: + * + * - "UUID": Universally Unique Identifier + * + * Example: + * + * { "UUID": "550e8400-e29b-41d4-a716-446655440000" } + */ +static void do_info_uuid(Monitor *mon, QObject **ret_data) +{ + char uuid[64]; + + snprintf(uuid, sizeof(uuid), UUID_FMT, qemu_uuid[0], qemu_uuid[1], qemu_uuid[2], qemu_uuid[3], qemu_uuid[4], qemu_uuid[5], qemu_uuid[6], qemu_uuid[7], qemu_uuid[8], qemu_uuid[9], qemu_uuid[10], qemu_uuid[11], qemu_uuid[12], qemu_uuid[13], qemu_uuid[14], qemu_uuid[15]); + *ret_data = qobject_from_jsonf("{ 'UUID': %s }", uuid); } /* get the current CPU defined by the user */ @@ -613,8 +698,9 @@ static void print_cpu_iter(QObject *obj, void *opaque) assert(qobject_type(obj) == QTYPE_QDICT); cpu = qobject_to_qdict(obj); - if (strcmp(qdict_get_str(cpu, "current"), "yes") == 0) + if (qdict_get_bool(cpu, "current")) { active = '*'; + } monitor_printf(mon, "%c CPU #%d: ", active, (int)qdict_get_int(cpu, "CPU")); @@ -634,8 +720,9 @@ static void print_cpu_iter(QObject *obj, void *opaque) (target_long) qdict_get_int(cpu, "PC")); #endif - if (strcmp(qdict_get_str(cpu, "halted"), "yes") == 0) + if (qdict_get_bool(cpu, "halted")) { monitor_printf(mon, " (halted)"); + } monitor_printf(mon, "\n"); } @@ -652,12 +739,21 @@ static void monitor_print_cpus(Monitor *mon, const QObject *data) /** * do_info_cpus(): Show CPU information * - * Return a QList with a QDict for each CPU. + * Return a QList. Each CPU is represented by a QDict, which contains: + * + * - "cpu": CPU index + * - "current": true if this is the current CPU, false otherwise + * - "halted": true if the cpu is halted, false otherwise + * - Current program counter. The key's name depends on the architecture: + * "pc": i386/x86)64 + * "nip": PPC + * "pc" and "npc": sparc + * "PC": mips * - * For example: + * Example: * - * [ { "CPU": 0, "current": "yes", "pc": 0x..., "halted": "no" }, - * { "CPU": 1, "current": "no", "pc": 0x..., "halted": "yes" } ] + * [ { "CPU": 0, "current": true, "halted": false, "pc": 3227107138 }, + * { "CPU": 1, "current": false, "halted": true, "pc": 7108165 } ] */ static void do_info_cpus(Monitor *mon, QObject **ret_data) { @@ -670,16 +766,18 @@ static void do_info_cpus(Monitor *mon, QObject **ret_data) mon_get_cpu(); for(env = first_cpu; env != NULL; env = env->next_cpu) { - const char *answer; - QDict *cpu = qdict_new(); + QDict *cpu; + QObject *obj; #ifndef _MSC_VER cpu_synchronize_state(env); #endif + obj = qobject_from_jsonf("{ 'CPU': %d, 'current': %i, 'halted': %i }", + env->cpu_index, env == mon->mon_cpu, + env->halted); + assert(obj != NULL); - qdict_put(cpu, "CPU", qint_from_int(env->cpu_index)); - answer = (env == mon->mon_cpu) ? "yes" : "no"; - qdict_put(cpu, "current", qstring_from_str(answer)); + cpu = qobject_to_qdict(obj); #if defined(TARGET_I386) qdict_put(cpu, "pc", qint_from_int(env->eip + env->segs[R_CS].base)); @@ -691,8 +789,6 @@ static void do_info_cpus(Monitor *mon, QObject **ret_data) #elif defined(TARGET_MIPS) qdict_put(cpu, "PC", qint_from_int(env->active_tc.PC)); #endif - answer = env->halted ? "yes" : "no"; - qdict_put(cpu, "halted", qstring_from_str(answer)); qlist_append(cpu_list, cpu); } @@ -1772,16 +1868,40 @@ static void tlb_info(Monitor *mon) #endif -static void do_info_kvm(Monitor *mon) +static void do_info_kvm_print(Monitor *mon, const QObject *data) { -#ifdef CONFIG_KVM + QDict *qdict; + + qdict = qobject_to_qdict(data); + monitor_printf(mon, "kvm support: "); - if (kvm_enabled()) - monitor_printf(mon, "enabled\n"); - else - monitor_printf(mon, "disabled\n"); + if (qdict_get_bool(qdict, "present")) { + monitor_printf(mon, "%s\n", qdict_get_bool(qdict, "enabled") ? + "enabled" : "disabled"); + } else { + monitor_printf(mon, "not compiled\n"); + } +} + +/** + * do_info_kvm(): Show KVM information + * + * Return a QDict with the following information: + * + * - "enabled": true if KVM support is enabled, false otherwise + * - "present": true if QEMU has KVM support, false otherwise + * + * Example: + * + * { "enabled": true, "present": true } + */ +static void do_info_kvm(Monitor *mon, QObject **ret_data) +{ +#ifdef CONFIG_KVM + *ret_data = qobject_from_jsonf("{ 'enabled': %i, 'present': true }", + kvm_enabled()); #else - monitor_printf(mon, "kvm support: not compiled\n"); + *ret_data = qobject_from_jsonf("{ 'enabled': false, 'present': false }"); #endif } @@ -1899,16 +2019,41 @@ static void do_inject_nmi(Monitor *mon, const QDict *qdict) } #endif -static void do_info_status(Monitor *mon) +static void do_info_status_print(Monitor *mon, const QObject *data) { - if (vm_running) { - if (singlestep) { - monitor_printf(mon, "VM status: running (single step mode)\n"); - } else { - monitor_printf(mon, "VM status: running\n"); + QDict *qdict; + + qdict = qobject_to_qdict(data); + + monitor_printf(mon, "VM status: "); + if (qdict_get_bool(qdict, "running")) { + monitor_printf(mon, "running"); + if (qdict_get_bool(qdict, "singlestep")) { + monitor_printf(mon, " (single step mode)"); } - } else - monitor_printf(mon, "VM status: paused\n"); + } else { + monitor_printf(mon, "paused"); + } + + monitor_printf(mon, "\n"); +} + +/** + * do_info_status(): VM status + * + * Return a QDict with the following information: + * + * - "running": true if the VM is running, or false if it is paused + * - "singlestep": true if the VM is in single step mode, false otherwise + * + * Example: + * + * { "running": true, "singlestep": false } + */ +static void do_info_status(Monitor *mon, QObject **ret_data) +{ + *ret_data = qobject_from_jsonf("{ 'running': %i, 'singlestep': %i }", + vm_running, singlestep); } /** @@ -1923,12 +2068,24 @@ static void do_balloon(Monitor *mon, const QDict *qdict, QObject **ret_data) static void monitor_print_balloon(Monitor *mon, const QObject *data) { - monitor_printf(mon, "balloon: actual=%d\n", - (int)qint_get_int(qobject_to_qint(data))); + QDict *qdict; + + qdict = qobject_to_qdict(data); + + monitor_printf(mon, "balloon: actual=%" PRId64 "\n", + qdict_get_int(qdict, "balloon") >> 20); } /** * do_info_balloon(): Balloon information + * + * Return a QDict with the following information: + * + * - "balloon": current balloon value in bytes + * + * Example: + * + * { "balloon": 1073741824 } */ static void do_info_balloon(Monitor *mon, QObject **ret_data) { @@ -1940,7 +2097,8 @@ static void do_info_balloon(Monitor *mon, QObject **ret_data) else if (actual == 0) qemu_error_new(QERR_DEVICE_NOT_ACTIVE, "balloon"); else - *ret_data = QOBJECT(qint_from_int((int)(actual >> 20))); + *ret_data = qobject_from_jsonf("{ 'balloon': %" PRId64 "}", + (int64_t) actual); } static qemu_acl *find_acl(Monitor *mon, const char *name) @@ -2178,7 +2336,7 @@ static const mon_cmd_t info_cmds[] = { .args_type = "", .params = "", .help = "show the version of QEMU", - .user_print = monitor_print_qobject, + .user_print = do_info_version_print, .mhandler.info_new = do_info_version, }, { @@ -2201,21 +2359,24 @@ static const mon_cmd_t info_cmds[] = { .args_type = "", .params = "", .help = "show the character devices", - .mhandler.info = qemu_chr_info, + .user_print = qemu_chr_info_print, + .mhandler.info_new = qemu_chr_info, }, { .name = "block", .args_type = "", .params = "", .help = "show the block devices", - .mhandler.info = bdrv_info, + .user_print = bdrv_info_print, + .mhandler.info_new = bdrv_info, }, { .name = "blockstats", .args_type = "", .params = "", .help = "show block device statistics", - .mhandler.info = bdrv_info_stats, + .user_print = bdrv_stats_print, + .mhandler.info_new = bdrv_info_stats, }, { .name = "registers", @@ -2282,7 +2443,8 @@ static const mon_cmd_t info_cmds[] = { .args_type = "", .params = "", .help = "show state of HPET", - .mhandler.info = do_info_hpet, + .user_print = do_info_hpet_print, + .mhandler.info_new = do_info_hpet, }, #endif { @@ -2297,7 +2459,8 @@ static const mon_cmd_t info_cmds[] = { .args_type = "", .params = "", .help = "show KVM information", - .mhandler.info = do_info_kvm, + .user_print = do_info_kvm_print, + .mhandler.info_new = do_info_kvm, }, { .name = "numa", @@ -2346,7 +2509,8 @@ static const mon_cmd_t info_cmds[] = { .args_type = "", .params = "", .help = "show the current VM status (running|paused)", - .mhandler.info = do_info_status, + .user_print = do_info_status_print, + .mhandler.info_new = do_info_status, }, { .name = "pcmcia", @@ -2360,28 +2524,32 @@ static const mon_cmd_t info_cmds[] = { .args_type = "", .params = "", .help = "show which guest mouse is receiving events", - .mhandler.info = do_info_mice, + .user_print = do_info_mice_print, + .mhandler.info_new = do_info_mice, }, { .name = "vnc", .args_type = "", .params = "", .help = "show the vnc server status", - .mhandler.info = do_info_vnc, + .user_print = do_info_vnc_print, + .mhandler.info_new = do_info_vnc, }, { .name = "name", .args_type = "", .params = "", .help = "show the current VM name", - .mhandler.info = do_info_name, + .user_print = do_info_name_print, + .mhandler.info_new = do_info_name, }, { .name = "uuid", .args_type = "", .params = "", .help = "show the current VM UUID", - .mhandler.info = do_info_uuid, + .user_print = do_info_uuid_print, + .mhandler.info_new = do_info_uuid, }, #if defined(TARGET_PPC) { @@ -2406,7 +2574,8 @@ static const mon_cmd_t info_cmds[] = { .args_type = "", .params = "", .help = "show migration status", - .mhandler.info = do_info_migrate, + .user_print = do_info_migrate_print, + .mhandler.info_new = do_info_migrate, }, { .name = "balloon", diff --git a/qemu/monitor.h b/qemu/monitor.h index 8f317c3d..fbcdc3ae 100644 --- a/qemu/monitor.h +++ b/qemu/monitor.h @@ -45,6 +45,4 @@ void monitor_printf(Monitor *mon, const char *fmt, ...); void monitor_print_filename(Monitor *mon, const char *filename); void monitor_flush(Monitor *mon); -void qemu_error_internal(const char* file, int linenr, const char* func, const char* fmt, ...); - #endif /* !MONITOR_H */ diff --git a/qemu/net.c b/qemu/net.c index 0505f2e8..6ef93e61 100644 --- a/qemu/net.c +++ b/qemu/net.c @@ -35,11 +35,12 @@ #include "sysemu.h" #include "qemu-common.h" #include "qemu_socket.h" -#include static QTAILQ_HEAD(, VLANState) vlans; static QTAILQ_HEAD(, VLANClientState) non_vlan_clients; +int default_net = 1; + /***********************************************************/ /* network device redirectors */ @@ -1318,7 +1319,7 @@ static int net_init_netdev(QemuOpts *opts, void *dummy) int net_init_clients(void) { - if (QTAILQ_EMPTY(&qemu_net_opts.head)) { + if (default_net) { /* if no clients, we use a default config */ qemu_opts_set(&qemu_net_opts, NULL, "type", "nic"); #ifdef CONFIG_SLIRP @@ -1354,5 +1355,6 @@ int net_client_parse(QemuOptsList *opts_list, const char *optarg) return -1; } + default_net = 0; return 0; } diff --git a/qemu/net.h b/qemu/net.h index d583d590..4971fcbb 100644 --- a/qemu/net.h +++ b/qemu/net.h @@ -139,6 +139,7 @@ struct NICInfo { extern int nb_nics; extern NICInfo nd_table[MAX_NICS]; +extern int default_net; /* BT HCI info */ diff --git a/qemu/qdict.c b/qemu/qdict.c index 0e04cb1f..ef73265f 100644 --- a/qemu/qdict.c +++ b/qemu/qdict.c @@ -12,6 +12,7 @@ #include "qint.h" #include "qdict.h" +#include "qbool.h" #include "qstring.h" #include "qobject.h" #include "qemu-queue.h" @@ -188,6 +189,33 @@ int64_t qdict_get_int(const QDict *qdict, const char *key) return qint_get_int(qobject_to_qint(obj)); } +/** + * qdict_get_bool(): Get a bool mapped by 'key' + * + * This function assumes that 'key' exists and it stores a + * QBool object. + * + * Return bool mapped by 'key'. + */ +int qdict_get_bool(const QDict *qdict, const char *key) +{ + QObject *obj = qdict_get_obj(qdict, key, QTYPE_QBOOL); + return qbool_get_int(qobject_to_qbool(obj)); +} + +/** + * qdict_get_qlist(): Get the QList mapped by 'key' + * + * This function assumes that 'key' exists and it stores a + * QList object. + * + * Return QList mapped by 'key'. + */ +QList *qdict_get_qlist(const QDict *qdict, const char *key) +{ + return qobject_to_qlist(qdict_get_obj(qdict, key, QTYPE_QLIST)); +} + /** * qdict_get_str(): Get a pointer to the stored string mapped * by 'key' diff --git a/qemu/qdict.h b/qemu/qdict.h index 14b26330..5fef1ea4 100644 --- a/qemu/qdict.h +++ b/qemu/qdict.h @@ -2,6 +2,7 @@ #define QDICT_H #include "qobject.h" +#include "qlist.h" #include "qemu-queue.h" #include @@ -37,6 +38,8 @@ void qdict_iter(const QDict *qdict, /* High level helpers */ int64_t qdict_get_int(const QDict *qdict, const char *key); +int qdict_get_bool(const QDict *qdict, const char *key); +QList *qdict_get_qlist(const QDict *qdict, const char *key); const char *qdict_get_str(const QDict *qdict, const char *key); int64_t qdict_get_try_int(const QDict *qdict, const char *key, int64_t err_value); diff --git a/qemu/qemu-char.c b/qemu/qemu-char.c index b37c7351..1c9a5d47 100644 --- a/qemu/qemu-char.c +++ b/qemu/qemu-char.c @@ -32,6 +32,7 @@ #include "hw/usb.h" #include "hw/baum.h" #include "hw/msmouse.h" +#include "qemu-objects.h" #include #include @@ -2231,7 +2232,7 @@ static CharDriverState *qemu_chr_open_socket(QemuOpts *opts) return NULL; } -static QemuOpts *qemu_chr_parse_compat(const char *label, const char *filename) +QemuOpts *qemu_chr_parse_compat(const char *label, const char *filename) { char host[65], port[33], width[8], height[8]; int pos; @@ -2469,13 +2470,51 @@ void qemu_chr_close(CharDriverState *chr) qemu_free(chr); } -void qemu_chr_info(Monitor *mon) +static void qemu_chr_qlist_iter(QObject *obj, void *opaque) { + QDict *chr_dict; + Monitor *mon = opaque; + + chr_dict = qobject_to_qdict(obj); + monitor_printf(mon, "%s: filename=%s\n", qdict_get_str(chr_dict, "label"), + qdict_get_str(chr_dict, "filename")); +} + +void qemu_chr_info_print(Monitor *mon, const QObject *ret_data) +{ + qlist_iter(qobject_to_qlist(ret_data), qemu_chr_qlist_iter, mon); +} + +/** + * qemu_chr_info(): Character devices information + * + * Each device is represented by a QDict. The returned QObject is a QList + * of all devices. + * + * The QDict contains the following: + * + * - "label": device's label + * - "filename": device's file + * + * Example: + * + * [ { "label": "monitor", "filename", "stdio" }, + * { "label": "serial0", "filename": "vc" } ] + */ +void qemu_chr_info(Monitor *mon, QObject **ret_data) +{ + QList *chr_list; CharDriverState *chr; + chr_list = qlist_new(); + QTAILQ_FOREACH(chr, &chardevs, next) { - monitor_printf(mon, "%s: filename=%s\n", chr->label, chr->filename); + QObject *obj = qobject_from_jsonf("{ 'label': %s, 'filename': %s }", + chr->label, chr->filename); + qlist_append_obj(chr_list, obj); } + + *ret_data = QOBJECT(chr_list); } CharDriverState *qemu_chr_find(const char *name) diff --git a/qemu/qemu-char.h b/qemu/qemu-char.h index 9957db1f..bcc07664 100644 --- a/qemu/qemu-char.h +++ b/qemu/qemu-char.h @@ -5,6 +5,7 @@ #include "qemu-queue.h" #include "qemu-option.h" #include "qemu-config.h" +#include "qobject.h" /* character device */ @@ -69,6 +70,7 @@ struct CharDriverState { QTAILQ_ENTRY(CharDriverState) next; }; +QemuOpts *qemu_chr_parse_compat(const char *label, const char *filename); CharDriverState *qemu_chr_open_opts(QemuOpts *opts, void (*init)(struct CharDriverState *s)); CharDriverState *qemu_chr_open(const char *label, const char *filename, void (*init)(struct CharDriverState *s)); @@ -87,7 +89,8 @@ int qemu_chr_can_read(CharDriverState *s); void qemu_chr_read(CharDriverState *s, uint8_t *buf, int len); int qemu_chr_get_msgfd(CharDriverState *s); void qemu_chr_accept_input(CharDriverState *s); -void qemu_chr_info(Monitor *mon); +void qemu_chr_info_print(Monitor *mon, const QObject *ret_data); +void qemu_chr_info(Monitor *mon, QObject **ret_data); CharDriverState *qemu_chr_find(const char *name); extern int term_escape_char; diff --git a/qemu/qemu-config.c b/qemu/qemu-config.c index a23b1256..c3203c87 100644 --- a/qemu/qemu-config.c +++ b/qemu/qemu-config.c @@ -224,6 +224,24 @@ QemuOptsList qemu_global_opts = { }, }; +QemuOptsList qemu_mon_opts = { + .name = "mon", + .head = QTAILQ_HEAD_INITIALIZER(qemu_mon_opts.head), + .desc = { + { + .name = "mode", + .type = QEMU_OPT_STRING, + },{ + .name = "chardev", + .type = QEMU_OPT_STRING, + },{ + .name = "default", + .type = QEMU_OPT_BOOL, + }, + { /* end if list */ } + }, +}; + static QemuOptsList *lists[] = { &qemu_drive_opts, &qemu_chardev_opts, @@ -232,6 +250,7 @@ static QemuOptsList *lists[] = { &qemu_net_opts, &qemu_rtc_opts, &qemu_global_opts, + &qemu_mon_opts, NULL, }; diff --git a/qemu/qemu-config.h b/qemu/qemu-config.h index 6246e76f..34dfadc5 100644 --- a/qemu/qemu-config.h +++ b/qemu/qemu-config.h @@ -7,6 +7,7 @@ extern QemuOptsList qemu_device_opts; extern QemuOptsList qemu_netdev_opts; extern QemuOptsList qemu_net_opts; extern QemuOptsList qemu_rtc_opts; +extern QemuOptsList qemu_mon_opts; int qemu_set_option(const char *str); int qemu_global_option(const char *str); diff --git a/qemu/qemu-monitor.h b/qemu/qemu-monitor.h index 54c8cea8..16ca57de 100644 --- a/qemu/qemu-monitor.h +++ b/qemu/qemu-monitor.h @@ -429,7 +429,8 @@ .args_type = "pci_addr:s,type:s,opts:s?", .params = "auto|[[:]:] nic|storage [[vlan=n][,macaddr=addr][,model=type]] [file=file][,if=type][,bus=nr]...", .help = "hot-add PCI device", -.mhandler.cmd = pci_device_hot_add, +.user_print = pci_device_hot_add_print, +.mhandler.cmd_new = pci_device_hot_add, }, #endif diff --git a/qemu/qemu-monitor.hx b/qemu/qemu-monitor.hx index 0657b2d1..c788c737 100644 --- a/qemu/qemu-monitor.hx +++ b/qemu/qemu-monitor.hx @@ -810,7 +810,8 @@ ETEXI .args_type = "pci_addr:s,type:s,opts:s?", .params = "auto|[[:]:] nic|storage [[vlan=n][,macaddr=addr][,model=type]] [file=file][,if=type][,bus=nr]...", .help = "hot-add PCI device", - .mhandler.cmd = pci_device_hot_add, + .user_print = pci_device_hot_add_print, + .mhandler.cmd_new = pci_device_hot_add, }, #endif diff --git a/qemu/qemu-objects.h b/qemu/qemu-objects.h new file mode 100644 index 00000000..e1d1e0ca --- /dev/null +++ b/qemu/qemu-objects.h @@ -0,0 +1,24 @@ +/* + * Include all QEMU objects. + * + * Copyright (C) 2009 Red Hat Inc. + * + * Authors: + * Luiz Capitulino + * + * This work is licensed under the terms of the GNU GPL, version 2. See + * the COPYING file in the top-level directory. + */ +#ifndef QEMU_OBJECTS_H +#define QEMU_OBJECTS_H + +#include "qobject.h" +#include "qint.h" +#include "qfloat.h" +#include "qbool.h" +#include "qstring.h" +#include "qdict.h" +#include "qlist.h" +#include "qjson.h" + +#endif /* QEMU_OBJECTS_H */ diff --git a/qemu/qemu-option.c b/qemu/qemu-option.c index b0091090..24392fcb 100644 --- a/qemu/qemu-option.c +++ b/qemu/qemu-option.c @@ -705,7 +705,7 @@ int qemu_opts_print(QemuOpts *opts, void *dummy) int qemu_opts_do_parse(QemuOpts *opts, const char *params, const char *firstname) { - char option[128], value[128]; + char option[128], value[1024]; const char *p,*pe,*pc; for (p = params; *p != '\0'; p++) { @@ -751,7 +751,7 @@ int qemu_opts_do_parse(QemuOpts *opts, const char *params, const char *firstname QemuOpts *qemu_opts_parse(QemuOptsList *list, const char *params, const char *firstname) { - char value[128], *id = NULL; + char value[1024], *id = NULL; const char *p; QemuOpts *opts; diff --git a/qemu/qemu-options.h b/qemu/qemu-options.h index 0b940d0e..10899cb9 100644 --- a/qemu/qemu-options.h +++ b/qemu/qemu-options.h @@ -425,6 +425,11 @@ DEF("parallel", HAS_ARG, QEMU_OPTION_parallel, \ DEF("monitor", HAS_ARG, QEMU_OPTION_monitor, \ "-monitor dev redirect the monitor to char device 'dev'\n") +DEF("qmp", HAS_ARG, QEMU_OPTION_qmp, \ +"-qmp dev like -monitor but opens in 'control' mode.\n") + +DEF("mon", HAS_ARG, QEMU_OPTION_mon, \ +"-mon chardev=[name][,mode=readline|control][,default]\n") DEF("pidfile", HAS_ARG, QEMU_OPTION_pidfile, \ "-pidfile file write PID to 'file'\n") @@ -536,6 +541,9 @@ DEF("tb-size", HAS_ARG, QEMU_OPTION_tb_size, \ DEF("incoming", HAS_ARG, QEMU_OPTION_incoming, \ "-incoming p prepare for incoming migration, listen on port p\n") +DEF("nodefaults", 0, QEMU_OPTION_nodefaults, \ +"-nodefaults don't create default devices.\n") + #ifndef _WIN32 DEF("chroot", HAS_ARG, QEMU_OPTION_chroot, \ "-chroot dir Chroot to dir just before starting the VM.\n") diff --git a/qemu/qemu-options.hx b/qemu/qemu-options.hx index 420b7d84..b8cc3750 100644 --- a/qemu/qemu-options.hx +++ b/qemu/qemu-options.hx @@ -1588,6 +1588,15 @@ serial port). The default device is @code{vc} in graphical mode and @code{stdio} in non graphical mode. ETEXI +DEF("qmp", HAS_ARG, QEMU_OPTION_qmp, \ + "-qmp dev like -monitor but opens in 'control' mode.\n") + +DEF("mon", HAS_ARG, QEMU_OPTION_mon, \ + "-mon chardev=[name][,mode=readline|control][,default]\n") +STEXI +@item -mon chardev=[name][,mode=readline|control][,default] +Setup monitor on chardev @var{name}. +ETEXI DEF("pidfile", HAS_ARG, QEMU_OPTION_pidfile, \ "-pidfile file write PID to 'file'\n") @@ -1881,6 +1890,11 @@ DEF("incoming", HAS_ARG, QEMU_OPTION_incoming, \ STEXI ETEXI +DEF("nodefaults", 0, QEMU_OPTION_nodefaults, \ + "-nodefaults don't create default devices.\n") +STEXI +ETEXI + #ifndef _WIN32 DEF("chroot", HAS_ARG, QEMU_OPTION_chroot, \ "-chroot dir Chroot to dir just before starting the VM.\n") diff --git a/qemu/sysemu.h b/qemu/sysemu.h index 60d30578..b9197663 100644 --- a/qemu/sysemu.h +++ b/qemu/sysemu.h @@ -78,7 +78,13 @@ void qemu_error(const char *fmt, ...) __attribute__ ((format(printf, 1, 2))); void qemu_error(_Printf_format_string_ const char* fmt, ...); #endif +#ifndef _MSC_VER +void qemu_error_internal(const char *file, int linenr, const char *func, + const char *fmt, ...) + __attribute__ ((format(printf, 4, 5))); +#else void qemu_error_internal(const char* file, int linenr, const char* func, const char* fmt, ...); +#endif #define qemu_error_new(fmt, ...) \ qemu_error_internal(__FILE__, __LINE__, __func__, fmt, ## __VA_ARGS__) @@ -215,7 +221,8 @@ extern DriveInfo *drive_init(QemuOpts *arg, void *machine, int *fatal_error); DriveInfo *add_init_drive(const char *opts); /* pci-hotplug */ -void pci_device_hot_add(Monitor *mon, const QDict *qdict); +void pci_device_hot_add_print(Monitor *mon, const QObject *data); +void pci_device_hot_add(Monitor *mon, const QDict *qdict, QObject **ret_data); void drive_hot_add(Monitor *mon, const QDict *qdict); void pci_device_hot_remove(Monitor *mon, const char *pci_addr); void do_pci_device_hot_remove(Monitor *mon, const QDict *qdict, diff --git a/qemu/target-i386/cpu.h b/qemu/target-i386/cpu.h index f21f73aa..235cb145 100644 --- a/qemu/target-i386/cpu.h +++ b/qemu/target-i386/cpu.h @@ -664,6 +664,8 @@ typedef struct CPUX86State { target_ulong fmask; target_ulong kernelgsbase; #endif + uint64_t system_time_msr; + uint64_t wall_clock_msr; uint64_t tsc; diff --git a/qemu/target-i386/kvm.c b/qemu/target-i386/kvm.c index 88b504c3..53955b40 100644 --- a/qemu/target-i386/kvm.c +++ b/qemu/target-i386/kvm.c @@ -35,6 +35,9 @@ do { } while (0) #endif +#define MSR_KVM_WALL_CLOCK 0x11 +#define MSR_KVM_SYSTEM_TIME 0x12 + #ifdef KVM_CAP_EXT_CPUID static struct kvm_cpuid2 *try_get_cpuid(KVMState *s, int max) @@ -494,6 +497,9 @@ static int kvm_put_msrs(CPUState *env) kvm_msr_entry_set(&msrs[n++], MSR_FMASK, env->fmask); kvm_msr_entry_set(&msrs[n++], MSR_LSTAR, env->lstar); #endif + kvm_msr_entry_set(&msrs[n++], MSR_KVM_SYSTEM_TIME, env->system_time_msr); + kvm_msr_entry_set(&msrs[n++], MSR_KVM_WALL_CLOCK, env->wall_clock_msr); + msr_data.info.nmsrs = n; return kvm_vcpu_ioctl(env, KVM_SET_MSRS, &msr_data); @@ -634,6 +640,9 @@ static int kvm_get_msrs(CPUState *env) msrs[n++].index = MSR_FMASK; msrs[n++].index = MSR_LSTAR; #endif + msrs[n++].index = MSR_KVM_SYSTEM_TIME; + msrs[n++].index = MSR_KVM_WALL_CLOCK; + msr_data.info.nmsrs = n; ret = kvm_vcpu_ioctl(env, KVM_GET_MSRS, &msr_data); if (ret < 0) @@ -670,6 +679,12 @@ static int kvm_get_msrs(CPUState *env) case MSR_IA32_TSC: env->tsc = msrs[i].data; break; + case MSR_KVM_SYSTEM_TIME: + env->system_time_msr = msrs[i].data; + break; + case MSR_KVM_WALL_CLOCK: + env->wall_clock_msr = msrs[i].data; + break; } } diff --git a/qemu/target-i386/machine.c b/qemu/target-i386/machine.c index 6f5e09d0..bdfdfffd 100644 --- a/qemu/target-i386/machine.c +++ b/qemu/target-i386/machine.c @@ -465,6 +465,9 @@ static const VMStateDescription vmstate_cpu = { VMSTATE_UINT64_ARRAY_V(mce_banks, CPUState, MCE_BANKS_DEF *4, 10), /* rdtscp */ VMSTATE_UINT64_V(tsc_aux, CPUState, 11), + /* KVM pvclock msr */ + VMSTATE_UINT64_V(system_time_msr, CPUState, 11), + VMSTATE_UINT64_V(wall_clock_msr, CPUState, 11), VMSTATE_END_OF_LIST() /* The above list is not sorted /wrt version numbers, watch out! */ } diff --git a/qemu/vl.c b/qemu/vl.c index 414647f7..30bd3420 100644 --- a/qemu/vl.c +++ b/qemu/vl.c @@ -167,6 +167,7 @@ int main(int argc, char **argv) #include "balloon.h" #include "qemu-option.h" #include "qemu-config.h" +#include "qemu-objects.h" #include "disas.h" @@ -183,9 +184,6 @@ int main(int argc, char **argv) #define DEFAULT_RAM_SIZE 128 -/* Maximum number of monitor devices */ -#define MAX_MONITOR_DEVICES 10 - static const char *data_dir; const char *bios_name = NULL; /* Note: drives_table[MAX_DRIVES] is a dummy block driver if none available @@ -204,7 +202,7 @@ int autostart; static int rtc_utc = 1; static int rtc_date_offset = -1; /* -1 means no change */ QEMUClock *rtc_clock; -int vga_interface_type = VGA_CIRRUS; +int vga_interface_type = VGA_NONE; #ifdef TARGET_SPARC int graphic_width = 1024; int graphic_height = 768; @@ -283,12 +281,23 @@ static QEMUBootSetHandler *boot_set_handler; static void *boot_set_opaque; static int default_serial = 1; +static int default_parallel = 1; +static int default_virtcon = 1; +static int default_monitor = 1; +static int default_vga = 1; +static int default_drive = 1; static struct { const char *driver; int *flag; } default_list[] = { - { .driver = "isa-serial", .flag = &default_serial }, + { .driver = "isa-serial", .flag = &default_serial }, + { .driver = "isa-parallel", .flag = &default_parallel }, + { .driver = "virtio-console-pci", .flag = &default_virtcon }, + { .driver = "virtio-console-s390", .flag = &default_virtcon }, + { .driver = "VGA", .flag = &default_vga }, + { .driver = "Cirrus VGA", .flag = &default_vga }, + { .driver = "QEMUware SVGA", .flag = &default_vga }, }; static int default_driver_check(QemuOpts *opts, void *opaque) @@ -493,25 +502,72 @@ int kbd_mouse_is_absolute(void) return qemu_put_mouse_event_current->qemu_put_mouse_event_absolute; } -void do_info_mice(Monitor *mon) +static void info_mice_iter(QObject *data, void *opaque) +{ + QDict *mouse; + Monitor *mon = opaque; + + mouse = qobject_to_qdict(data); + monitor_printf(mon, "%c Mouse #%" PRId64 ": %s\n", + (qdict_get_bool(mouse, "current") ? '*' : ' '), + qdict_get_int(mouse, "index"), qdict_get_str(mouse, "name")); +} + +void do_info_mice_print(Monitor *mon, const QObject *data) +{ + QList *mice_list; + + mice_list = qobject_to_qlist(data); + if (qlist_empty(mice_list)) { + monitor_printf(mon, "No mouse devices connected\n"); + return; + } + + qlist_iter(mice_list, info_mice_iter, mon); +} + +/** + * do_info_mice(): Show VM mice information + * + * Each mouse is represented by a QDict, the returned QObject is a QList of + * all mice. + * + * The mouse QDict contains the following: + * + * - "name": mouse's name + * - "index": mouse's index + * - "current": true if this mouse is receiving events, false otherwise + * + * Example: + * + * [ { "name": "QEMU Microsoft Mouse", "index": 0, "current": false }, + * { "name": "QEMU PS/2 Mouse", "index": 1, "current": true } ] + */ +void do_info_mice(Monitor *mon, QObject **ret_data) { QEMUPutMouseEntry *cursor; + QList *mice_list; int index = 0; + mice_list = qlist_new(); + if (!qemu_put_mouse_event_head) { - monitor_printf(mon, "No mouse devices connected\n"); - return; + goto out; } - monitor_printf(mon, "Mouse devices available:\n"); cursor = qemu_put_mouse_event_head; while (cursor != NULL) { - monitor_printf(mon, "%c Mouse #%d: %s\n", - (cursor == qemu_put_mouse_event_current ? '*' : ' '), - index, cursor->qemu_put_mouse_event_name); + QObject *obj; + obj = qobject_from_jsonf("{ 'name': %s, 'index': %d, 'current': %i }", + cursor->qemu_put_mouse_event_name, + index, cursor == qemu_put_mouse_event_current); + qlist_append_obj(mice_list, obj); index++; cursor = cursor->next; } + +out: + *ret_data = QOBJECT(mice_list); } void do_mouse_set(Monitor *mon, const QDict *qdict) @@ -4381,6 +4437,7 @@ static void select_vgahw (const char *p) { const char *opts; + default_vga = 0; vga_interface_type = VGA_NONE; if (strstart(p, "std", &opts)) { vga_interface_type = VGA_STD; @@ -4632,11 +4689,84 @@ static int chardev_init_func(QemuOpts *opts, void *opaque) return 0; } +static int mon_init_func(QemuOpts *opts, void *opaque) +{ + CharDriverState *chr; + const char *chardev; + const char *mode; + int flags; + + mode = qemu_opt_get(opts, "mode"); + if (mode == NULL) { + mode = "readline"; + } + if (strcmp(mode, "readline") == 0) { + flags = MONITOR_USE_READLINE; + } else if (strcmp(mode, "control") == 0) { + flags = MONITOR_USE_CONTROL; + } else { + fprintf(stderr, "unknown monitor mode \"%s\"\n", mode); + exit(1); + } + + if (qemu_opt_get_bool(opts, "default", 0)) + flags |= MONITOR_IS_DEFAULT; + + chardev = qemu_opt_get(opts, "chardev"); + chr = qemu_chr_find(chardev); + if (chr == NULL) { + fprintf(stderr, "chardev \"%s\" not found\n", chardev); + exit(1); + } + + monitor_init(chr, flags); + return 0; +} + +static void monitor_parse(const char *optarg, const char *mode) +{ + static int monitor_device_index = 0; + QemuOpts *opts; + const char *p; + char label[32]; + int def = 0; + + if (strstart(optarg, "chardev:", &p)) { + snprintf(label, sizeof(label), "%s", p); + } else { + if (monitor_device_index) { + snprintf(label, sizeof(label), "monitor%d", + monitor_device_index); + } else { + snprintf(label, sizeof(label), "monitor"); + def = 1; + } + opts = qemu_chr_parse_compat(label, optarg); + if (!opts) { + fprintf(stderr, "parse error: %s\n", optarg); + exit(1); + } + } + + opts = qemu_opts_create(&qemu_mon_opts, label, 1); + if (!opts) { + fprintf(stderr, "duplicate chardev: %s\n", label); + exit(1); + } + qemu_opt_set(opts, "mode", mode); + qemu_opt_set(opts, "chardev", label); + if (def) + qemu_opt_set(opts, "default", "on"); + monitor_device_index++; +} + struct device_config { enum { - DEV_USB, /* -usbdevice */ - DEV_BT, /* -bt */ - DEV_SERIAL, /* -serial */ + DEV_USB, /* -usbdevice */ + DEV_BT, /* -bt */ + DEV_SERIAL, /* -serial */ + DEV_PARALLEL, /* -parallel */ + DEV_VIRTCON, /* -virtioconsole */ } type; const char *cmdline; QTAILQ_ENTRY(device_config) next; @@ -4668,28 +4798,6 @@ static int foreach_device_config(int type, int (*func)(const char *cmdline)) return 0; } -static void serial_monitor_mux(const char *monitor_devices[]) -{ - struct device_config *serial; - const char *devname; - - if (strcmp(monitor_devices[0],"stdio") != 0) - return; - QTAILQ_FOREACH(serial, &device_configs, next) { - if (serial->type != DEV_SERIAL) - continue; - devname = serial->cmdline; - if (devname && !strcmp(devname,"mon:stdio")) { - monitor_devices[0] = NULL; - break; - } else if (devname && !strcmp(devname,"stdio")) { - monitor_devices[0] = NULL; - serial->cmdline = "mon:stdio"; - break; - } - } -} - static int serial_parse(const char *devname) { static int index = 0; @@ -4712,6 +4820,50 @@ static int serial_parse(const char *devname) return 0; } +static int parallel_parse(const char *devname) +{ + static int index = 0; + char label[32]; + + if (strcmp(devname, "none") == 0) + return 0; + if (index == MAX_PARALLEL_PORTS) { + fprintf(stderr, "qemu: too many parallel ports\n"); + exit(1); + } + snprintf(label, sizeof(label), "parallel%d", index); + parallel_hds[index] = qemu_chr_open(label, devname, NULL); + if (!parallel_hds[index]) { + fprintf(stderr, "qemu: could not open parallel device '%s': %s\n", + devname, strerror(errno)); + return -1; + } + index++; + return 0; +} + +static int virtcon_parse(const char *devname) +{ + static int index = 0; + char label[32]; + + if (strcmp(devname, "none") == 0) + return 0; + if (index == MAX_VIRTIO_CONSOLES) { + fprintf(stderr, "qemu: too many virtio consoles\n"); + exit(1); + } + snprintf(label, sizeof(label), "virtcon%d", index); + virtcon_hds[index] = qemu_chr_open(label, devname, NULL); + if (!virtcon_hds[index]) { + fprintf(stderr, "qemu: could not open virtio console '%s': %s\n", + devname, strerror(errno)); + return -1; + } + index++; + return 0; +} + #ifndef _MSC_VER int main(int argc, char** argv, char** envp) #else @@ -4732,13 +4884,6 @@ int __declspec(dllexport) qemu_main(int argc, char** argv, char** envp) QemuOpts *hda_opts = NULL, *opts; int optind; const char *r, *optarg; - CharDriverState *monitor_hds[MAX_MONITOR_DEVICES]; - const char *monitor_devices[MAX_MONITOR_DEVICES]; - int monitor_device_index; - const char *parallel_devices[MAX_PARALLEL_PORTS]; - int parallel_device_index; - const char *virtio_consoles[MAX_VIRTIO_CONSOLES]; - int virtio_console_index; const char *loadvm = NULL; QEMUMachine *machine; const char *cpu_model; @@ -4804,21 +4949,6 @@ int __declspec(dllexport) qemu_main(int argc, char** argv, char** envp) cyls = heads = secs = 0; translation = BIOS_ATA_TRANSLATION_AUTO; - parallel_devices[0] = "vc:80Cx24C"; - for(i = 1; i < MAX_PARALLEL_PORTS; i++) - parallel_devices[i] = NULL; - parallel_device_index = 0; - - for(i = 0; i < MAX_VIRTIO_CONSOLES; i++) - virtio_consoles[i] = NULL; - virtio_console_index = 0; - - monitor_devices[0] = "vc:80Cx24C"; - for (i = 1; i < MAX_MONITOR_DEVICES; i++) { - monitor_devices[i] = NULL; - } - monitor_device_index = 0; - for (i = 0; i < MAX_NODES; i++) { node_mem[i] = 0; node_cpumask[i] = 0; @@ -5236,12 +5366,20 @@ int __declspec(dllexport) qemu_main(int argc, char** argv, char** envp) break; } case QEMU_OPTION_monitor: - if (monitor_device_index >= MAX_MONITOR_DEVICES) { - fprintf(stderr, "qemu: too many monitor devices\n"); + monitor_parse(optarg, "readline"); + default_monitor = 0; + break; + case QEMU_OPTION_qmp: + monitor_parse(optarg, "control"); + default_monitor = 0; + break; + case QEMU_OPTION_mon: + opts = qemu_opts_parse(&qemu_mon_opts, optarg, "chardev"); + if (!opts) { + fprintf(stderr, "parse error: %s\n", optarg); exit(1); } - monitor_devices[monitor_device_index] = optarg; - monitor_device_index++; + default_monitor = 0; break; case QEMU_OPTION_chardev: opts = qemu_opts_parse(&qemu_chardev_opts, optarg, "backend"); @@ -5269,20 +5407,12 @@ int __declspec(dllexport) qemu_main(int argc, char** argv, char** envp) } break; case QEMU_OPTION_virtiocon: - if (virtio_console_index >= MAX_VIRTIO_CONSOLES) { - fprintf(stderr, "qemu: too many virtio consoles\n"); - exit(1); - } - virtio_consoles[virtio_console_index] = optarg; - virtio_console_index++; + add_device_config(DEV_VIRTCON, optarg); + default_virtcon = 0; break; case QEMU_OPTION_parallel: - if (parallel_device_index >= MAX_PARALLEL_PORTS) { - fprintf(stderr, "qemu: too many parallel ports\n"); - exit(1); - } - parallel_devices[parallel_device_index] = optarg; - parallel_device_index++; + add_device_config(DEV_PARALLEL, optarg); + default_parallel = 0; break; case QEMU_OPTION_loadvm: loadvm = optarg; @@ -5475,6 +5605,15 @@ int __declspec(dllexport) qemu_main(int argc, char** argv, char** envp) case QEMU_OPTION_incoming: incoming = optarg; break; + case QEMU_OPTION_nodefaults: + default_serial = 0; + default_parallel = 0; + default_virtcon = 0; + default_monitor = 0; + default_vga = 0; + default_net = 0; + default_drive = 0; + break; #ifndef _WIN32 case QEMU_OPTION_chroot: chroot_dir = optarg; @@ -5555,18 +5694,44 @@ int __declspec(dllexport) qemu_main(int argc, char** argv, char** envp) qemu_opts_foreach(&qemu_device_opts, default_driver_check, NULL, 0); + if (machine->no_serial) { + default_serial = 0; + } + if (machine->no_parallel) { + default_parallel = 0; + } + if (!machine->use_virtcon) { + default_virtcon = 0; + } + if (machine->no_vga) { + default_vga = 0; + } + if (display_type == DT_NOGRAPHIC) { - if (default_serial) - add_device_config(DEV_SERIAL, "stdio"); - if (parallel_device_index == 0) - parallel_devices[0] = "null"; - if (strncmp(monitor_devices[0], "vc", 2) == 0) { - monitor_devices[0] = "stdio"; - } + if (default_parallel) + 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"); + } } else { if (default_serial) add_device_config(DEV_SERIAL, "vc:80Cx24C"); + if (default_parallel) + add_device_config(DEV_PARALLEL, "vc:80Cx24C"); + if (default_monitor) + monitor_parse("vc:80Cx24C", "readline"); } + if (default_vga) + vga_interface_type = VGA_CIRRUS; if (qemu_opts_foreach(&qemu_chardev_opts, chardev_init_func, NULL, 1) != 0) exit(1); @@ -5697,14 +5862,16 @@ int __declspec(dllexport) qemu_main(int argc, char** argv, char** envp) blk_mig_init(); - /* we always create the cdrom drive, even if no disk is there */ - drive_add(NULL, CDROM_ALIAS); + if (default_drive) { + /* we always create the cdrom drive, even if no disk is there */ + drive_add(NULL, CDROM_ALIAS); - /* we always create at least one floppy */ - drive_add(NULL, FD_ALIAS, 0); + /* we always create at least one floppy */ + drive_add(NULL, FD_ALIAS, 0); - /* we always create one sd slot, even if no card is in it */ - drive_add(NULL, SD_ALIAS); + /* we always create one sd slot, even if no card is in it */ + drive_add(NULL, SD_ALIAS); + } /* open the virtual block devices */ if (snapshot) @@ -5716,9 +5883,6 @@ int __declspec(dllexport) qemu_main(int argc, char** argv, char** envp) register_savevm_live("ram", 0, 3, NULL, ram_save_live, NULL, ram_load, NULL); - /* Maintain compatibility with multiple stdio monitors */ - serial_monitor_mux(monitor_devices); - if (nb_numa_nodes > 0) { int i; @@ -5761,54 +5925,12 @@ int __declspec(dllexport) qemu_main(int argc, char** argv, char** envp) } } - for (i = 0; i < MAX_MONITOR_DEVICES; i++) { - const char *devname = monitor_devices[i]; - if (devname && strcmp(devname, "none")) { - char label[32]; - if (i == 0) { - snprintf(label, sizeof(label), "monitor"); - } else { - snprintf(label, sizeof(label), "monitor%d", i); - } - monitor_hds[i] = qemu_chr_open(label, devname, NULL); - if (!monitor_hds[i]) { - fprintf(stderr, "qemu: could not open monitor device '%s'\n", - devname); - exit(1); - } - } - } - if (foreach_device_config(DEV_SERIAL, serial_parse) < 0) exit(1); - - for(i = 0; i < MAX_PARALLEL_PORTS; i++) { - const char *devname = parallel_devices[i]; - if (devname && strcmp(devname, "none")) { - char label[32]; - snprintf(label, sizeof(label), "parallel%d", i); - parallel_hds[i] = qemu_chr_open(label, devname, NULL); - if (!parallel_hds[i]) { - fprintf(stderr, "qemu: could not open parallel device '%s': %s\n", - devname, strerror(errno)); - exit(1); - } - } - } - - for(i = 0; i < MAX_VIRTIO_CONSOLES; i++) { - const char *devname = virtio_consoles[i]; - if (devname && strcmp(devname, "none")) { - char label[32]; - snprintf(label, sizeof(label), "virtcon%d", i); - virtcon_hds[i] = qemu_chr_open(label, devname, NULL); - if (!virtcon_hds[i]) { - fprintf(stderr, "qemu: could not open virtio console '%s': %s\n", - devname, strerror(errno)); - exit(1); - } - } - } + if (foreach_device_config(DEV_PARALLEL, parallel_parse) < 0) + exit(1); + if (foreach_device_config(DEV_VIRTCON, virtcon_parse) < 0) + exit(1); module_call_init(MODULE_INIT_DEVICE); @@ -5915,13 +6037,8 @@ int __declspec(dllexport) qemu_main(int argc, char** argv, char** envp) text_consoles_set_display(display_state); - for (i = 0; i < MAX_MONITOR_DEVICES; i++) { - if (monitor_devices[i] && monitor_hds[i]) { - monitor_init(monitor_hds[i], - MONITOR_USE_READLINE | - ((i == 0) ? MONITOR_IS_DEFAULT : 0)); - } - } + if (qemu_opts_foreach(&qemu_mon_opts, mon_init_func, NULL, 1) != 0) + exit(1); if (gdbstub_dev && gdbserver_start(gdbstub_dev) < 0) { fprintf(stderr, "qemu: could not open gdbserver on device '%s'\n", diff --git a/qemu/vnc.c b/qemu/vnc.c index 49ef0391..02605e5d 100644 --- a/qemu/vnc.c +++ b/qemu/vnc.c @@ -39,6 +39,7 @@ #include "qemu_socket.h" #include "qemu-timer.h" #include "acl.h" +#include "qemu-objects.h" #define VNC_REFRESH_INTERVAL_BASE 30 #define VNC_REFRESH_INTERVAL_INC 50 @@ -109,6 +110,54 @@ char *vnc_socket_remote_addr(const char *format, int fd) { return addr_to_string(format, &sa, salen); } +static int put_addr_qdict(QDict *qdict, struct sockaddr_storage *sa, + socklen_t salen) +{ + char host[NI_MAXHOST]; + char serv[NI_MAXSERV]; + int err; + + if ((err = getnameinfo((struct sockaddr *)sa, salen, + host, sizeof(host), + serv, sizeof(serv), + NI_NUMERICHOST | NI_NUMERICSERV)) != 0) { + VNC_DEBUG("Cannot resolve address %d: %s\n", + err, gai_strerror(err)); + return -1; + } + + qdict_put(qdict, "host", qstring_from_str(host)); + qdict_put(qdict, "service", qstring_from_str(serv)); + + return 0; +} + +static int vnc_qdict_local_addr(QDict *qdict, int fd) +{ + struct sockaddr_storage sa; + socklen_t salen; + + salen = sizeof(sa); + if (getsockname(fd, (struct sockaddr*)&sa, &salen) < 0) { + return -1; + } + + return put_addr_qdict(qdict, &sa, salen); +} + +static int vnc_qdict_remote_addr(QDict *qdict, int fd) +{ + struct sockaddr_storage sa; + socklen_t salen; + + salen = sizeof(sa); + if (getpeername(fd, (struct sockaddr*)&sa, &salen) < 0) { + return -1; + } + + return put_addr_qdict(qdict, &sa, salen); +} + static const char *vnc_auth_name(VncDisplay *vd) { switch (vd->auth) { case VNC_AUTH_INVALID: @@ -160,58 +209,140 @@ static const char *vnc_auth_name(VncDisplay *vd) { return "unknown"; } -static void do_info_vnc_client(Monitor *mon, VncState *client) +static QDict *do_info_vnc_client(Monitor *mon, VncState *client) { - char *clientAddr = - vnc_socket_remote_addr(" address: %s:%s\n", - client->csock); - if (!clientAddr) - return; + QDict *qdict; - monitor_printf(mon, "Client:\n"); - monitor_printf(mon, "%s", clientAddr); - free(clientAddr); + qdict = qdict_new(); + if (vnc_qdict_remote_addr(qdict, client->csock) < 0) { + QDECREF(qdict); + return NULL; + } #ifdef CONFIG_VNC_TLS if (client->tls.session && - client->tls.dname) - monitor_printf(mon, " x509 dname: %s\n", client->tls.dname); - else - monitor_printf(mon, " x509 dname: none\n"); + client->tls.dname) { + qdict_put(qdict, "x509_dname", qstring_from_str(client->tls.dname)); + } #endif #ifdef CONFIG_VNC_SASL if (client->sasl.conn && - client->sasl.username) - monitor_printf(mon, " username: %s\n", client->sasl.username); - else - monitor_printf(mon, " username: none\n"); + client->sasl.username) { + qdict_put(qdict, "username", qstring_from_str(client->sasl.username)); + } #endif + + return qdict; } -void do_info_vnc(Monitor *mon) +static void info_vnc_iter(QObject *obj, void *opaque) { - if (vnc_display == NULL || vnc_display->display == NULL) { + QDict *client; + Monitor *mon = opaque; + + client = qobject_to_qdict(obj); + monitor_printf(mon, "Client:\n"); + monitor_printf(mon, " address: %s:%s\n", + qdict_get_str(client, "host"), + qdict_get_str(client, "service")); + +#ifdef CONFIG_VNC_TLS + monitor_printf(mon, " x509_dname: %s\n", + qdict_haskey(client, "x509_dname") ? + qdict_get_str(client, "x509_dname") : "none"); +#endif +#ifdef CONFIG_VNC_SASL + monitor_printf(mon, " username: %s\n", + qdict_haskey(client, "username") ? + qdict_get_str(client, "username") : "none"); +#endif +} + +void do_info_vnc_print(Monitor *mon, const QObject *data) +{ + QDict *server; + QList *clients; + + server = qobject_to_qdict(data); + if (strcmp(qdict_get_str(server, "status"), "disabled") == 0) { monitor_printf(mon, "Server: disabled\n"); - } else { - char *serverAddr = vnc_socket_local_addr(" address: %s:%s\n", - vnc_display->lsock); + return; + } - if (!serverAddr) - return; + monitor_printf(mon, "Server:\n"); + monitor_printf(mon, " address: %s:%s\n", + qdict_get_str(server, "host"), + qdict_get_str(server, "service")); + monitor_printf(mon, " auth: %s\n", + qdict_haskey(server, "auth") ? qdict_get_str(server, "auth") : "none"); - monitor_printf(mon, "Server:\n"); - monitor_printf(mon, "%s", serverAddr); - free(serverAddr); - monitor_printf(mon, " auth: %s\n", vnc_auth_name(vnc_display)); + clients = qdict_get_qlist(server, "clients"); + if (qlist_empty(clients)) { + monitor_printf(mon, "Client: none\n"); + } else { + qlist_iter(clients, info_vnc_iter, mon); + } +} +/** + * do_info_vnc(): Show VNC server information + * + * Return a QDict with server information. Connected clients are returned + * as a QList of QDicts. + * + * The main QDict contains the following: + * + * - "status": "disabled" or "enabled" + * - "host": server's IP address + * - "service": server's port number + * - "auth": authentication method (optional) + * - "clients": a QList of all connected clients + * + * Clients are described by a QDict, with the following information: + * + * - "host": client's IP address + * - "service": client's port number + * - "x509_dname": TLS dname (optional) + * - "username": SASL username (optional) + * + * Example: + * + * { "status": "enabled", "host": "0.0.0.0", "service": "50402", "auth": "vnc", + * "clients": [ { "host": "127.0.0.1", "service": "50401" } ] } + */ +void do_info_vnc(Monitor *mon, QObject **ret_data) +{ + if (vnc_display == NULL || vnc_display->display == NULL) { + *ret_data = qobject_from_jsonf("{ 'status': 'disabled' }"); + } else { + QDict *qdict; + QList *clist; + + clist = qlist_new(); if (vnc_display->clients) { VncState *client = vnc_display->clients; while (client) { - do_info_vnc_client(mon, client); + qdict = do_info_vnc_client(mon, client); + if (qdict) + qlist_append(clist, qdict); client = client->next; } - } else { - monitor_printf(mon, "Client: none\n"); + } + + *ret_data = qobject_from_jsonf("{ 'status': 'enabled', 'clients': %p }", + QOBJECT(clist)); + assert(*ret_data != NULL); + + qdict = qobject_to_qdict(*ret_data); + + if (vnc_display->auth != VNC_AUTH_NONE) { + qdict_put(qdict, "auth", + qstring_from_str(vnc_auth_name(vnc_display))); + } + + if (vnc_qdict_local_addr(qdict, vnc_display->lsock) < 0) { + qobject_decref(*ret_data); + *ret_data = NULL; } } } @@ -1528,11 +1659,13 @@ static void do_key_event(VncState *vs, int down, int keycode, int sym) static void key_event(VncState *vs, int down, uint32_t sym) { int keycode; + int lsym = sym; - if (sym >= 'A' && sym <= 'Z' && is_graphic_console()) - sym = sym - 'A' + 'a'; + if (lsym >= 'A' && lsym <= 'Z' && is_graphic_console()) { + lsym = lsym - 'A' + 'a'; + } - keycode = keysym2scancode(vs->vd->kbd_layout, sym & 0xFFFF); + keycode = keysym2scancode(vs->vd->kbd_layout, lsym & 0xFFFF); do_key_event(vs, down, keycode, sym); }