virtio-console: Add support for multiple ports for generic guest-host communication
cover virtio-console: Add support for multiple ports for generic guest-host communication
Hello,
These are the newest patches that address all the previous comments.
In particular, the problem of maintaining backward compat with old kernel and new qemu is handled by reserving port #0 for a console port.
The old way of invocation,
-virtconsole ...
is still acceptable but to use multiple ports, the new invocation method is preferred:
-device virtio-serial-pci \
-device virtconsole... \
-device virtserialport...In case of no '-device virtconsole' specified in the new form of invocation, an older guest kernel will assume that a virtio-console port exists. Any writes to such a port end up being ignored.
For requirements, use-cases and some history see
http://www.linux-kvm.org/page/VMchannel_Requirements
I've also been testing all the features that are presented here by a small program that is to be run in the guest. It's an interactive program, available here:
http://fedorapeople.org/gitweb?p=amitshah/public_git/test-virtserial.git
The automated version of the program will also be put up in the same repo.
These patches are based on top of the char patches I've sent previously (and are in Anthony's queue).
Amit Shah (2):
virtio-console: Add a virtio-serial bus, support for multiple ports
virtio-console: Add a new virtserialport device for generic serial
port support
Gerd Hoffmann (1):
qdev: add string property.
Makefile.target | 2 +- hw/pc.c | 9 - hw/ppc440_bamboo.c | 7 - hw/qdev-properties.c | 28 ++ hw/qdev.c | 8 +- hw/qdev.h | 4 + hw/virtio-console.c | 206 +++++++------- hw/virtio-console.h | 19 -- hw/virtio-pci.c | 8 +- hw/virtio-serial-bus.c | 757 ++++++++++++++++++++++++++++++++++++++++++++++++ hw/virtio-serial.h | 220 ++++++++++++++ hw/virtio.h | 2 +- qemu-options.hx | 6 +- sysemu.h | 6 - vl.c | 65 +++-- 15 files changed, 1168 insertions(+), 179 deletions(-) delete mode 100644 hw/virtio-console.h create mode 100644 hw/virtio-serial-bus.c create mode 100644 hw/virtio-serial.h
PATCH 1/3 qdev: add string property.
From: Gerd Hoffmann <[email protected]>
--- hw/qdev-properties.c | 28 ++++++++++++++++++++++++++++ hw/qdev.h | 4 ++++ 2 files changed, 32 insertions(+), 0 deletions(-)
hw/qdev-properties.c +28 -0
@@ -193,6 +193,34 @@ PropertyInfo qdev_prop_hex64 = { .print = print_hex64, }; +/* --- string --- */ + +static int parse_string (DeviceState *dev,Property *prop,const char *str) +{ +char **ptr =qdev_get_prop_ptr (dev, prop); + +if (*ptr) +qemu_free (*ptr); + *ptr =qemu_strdup (str); +return 0 ; +} + +static int print_string (DeviceState *dev,Property *prop,char *dest,size_t len) +{ +char **ptr =qdev_get_prop_ptr (dev, prop); +if (!*ptr) +return snprintf (dest, len,"<null>" ); +return snprintf (dest, len,"\"%s\"" , *ptr); +} + +PropertyInfo qdev_prop_string = { + .name ="string" , + .type =PROP_TYPE_STRING , + .size =sizeof (char *), + .parse = parse_string, + .print = print_string, +}; +/* --- drive --- */ static int parse_drive (DeviceState *dev,Property *prop,const char *str)
hw/qdev.h +4 -0
@@ -79,6 +79,7 @@ enum PropertyType {PROP_TYPE_MACADDR ,PROP_TYPE_DRIVE ,PROP_TYPE_CHR , +PROP_TYPE_STRING , PROP_TYPE_PTR, };
@@ -186,6 +187,7 @@ extern PropertyInfo qdev_prop_int32;extern PropertyInfo qdev_prop_uint64;extern PropertyInfo qdev_prop_hex32;extern PropertyInfo qdev_prop_hex64; +extern PropertyInfo qdev_prop_string;extern PropertyInfo qdev_prop_chr;extern PropertyInfo qdev_prop_ptr;extern PropertyInfo qdev_prop_macaddr;
@@ -227,6 +229,8 @@ extern PropertyInfo qdev_prop_pci_devfn; DEFINE_PROP(_n, _s, _f, qdev_prop_ptr, void*) #define DEFINE_PROP_CHR(_n, _s, _f) \ DEFINE_PROP(_n, _s, _f, qdev_prop_chr, CharDriverState*) +#define DEFINE_PROP_STRING(_n, _s, _f) \ + DEFINE_PROP(_n, _s, _f, qdev_prop_string, char*) #define DEFINE_PROP_DRIVE(_n, _s, _f) \ DEFINE_PROP(_n, _s, _f, qdev_prop_drive, DriveInfo*) #define DEFINE_PROP_MACADDR(_n, _s, _f) \
Signature · 1 line
1.6.2.5
PATCH 2/3 virtio-console: Add a virtio-serial bus, support for multiple ports
This patch migrates virtio-console to the qdev infrastructure and creates a new virtio-serial bus on which multiple ports are exposed as devices. The bulk of the code now resides in a new file with virtio-console.c being just a simple qdev device.
This interface enables spawning of multiple virtio consoles as well as generic serial ports.
The older -virtconsole argument still works, but when using the new functionality, it is recommended to use
-device virtio-serial-pci -device virtconsole,...
The virtconsole device type accepts a chardev as an argument and a 'name' argument to identify the corresponding consoles on the host as well as the guest. The name, if given, is exposed via the 'name' sysfs attribute.
Care has been taken to ensure compatibility with kernels that do not support multiple ports as well as accepting incoming migrations from older qemu versions.
--- Makefile.target | 2 +- hw/pc.c | 9 - hw/ppc440_bamboo.c | 7 - hw/qdev.c | 8 +- hw/virtio-console.c | 180 +++++------- hw/virtio-console.h | 19 -- hw/virtio-pci.c | 8 +- hw/virtio-serial-bus.c | 757 ++++++++++++++++++++++++++++++++++++++++++++++++ hw/virtio-serial.h | 220 ++++++++++++++ hw/virtio.h | 2 +- qemu-options.hx | 6 +- sysemu.h | 6 - vl.c | 65 +++-- 13 files changed, 1104 insertions(+), 185 deletions(-) delete mode 100644 hw/virtio-console.h create mode 100644 hw/virtio-serial-bus.c create mode 100644 hw/virtio-serial.h
Makefile.target +1 -1
@@ -157,7 +157,7 @@ ifdef CONFIG_SOFTMMU obj-y = vl.o monitor.o pci.o machine.o gdbstub.o # virtio has to be here due to weird dependency between PCI and virtio-net. # need to fix this properly -obj-y += virtio-blk.o virtio-balloon.o virtio-net.o virtio-console.o virtio-pci.o +obj-y += virtio-blk.o virtio-balloon.o virtio-net.o virtio-serial-bus.o virtio-console.o virtio-pci.o obj-$(CONFIG_KVM) += kvm.o kvm-all.o obj-$(CONFIG_ISA_MMIO) += isa_mmio.o LIBS+=-lz
hw/pc.c +0 -9
@@ -1312,15 +1312,6 @@ static void pc_init1(ram_addr_t ram_size,pci_create_simple (pci_bus,-1 ,"lsi53c895a" ); } } - -/* Add virtio console devices */ -if (pci_enabled) { -for (i =0 ; i <MAX_VIRTIO_CONSOLES ; i++) { -if (virtcon_hds[i]) { -pci_create_simple (pci_bus,-1 ,"virtio-console-pci" ); - } - } - } } static void pc_init_pci(ram_addr_t ram_size,
hw/ppc440_bamboo.c +0 -7
@@ -108,13 +108,6 @@ static void bamboo_init(ram_addr_t ram_size, env =ppc440ep_init (&ram_size, &pcibus, pci_irq_nrs,1 , cpu_model);if (pcibus) { -/* Add virtio console devices */ -for (i =0 ; i <MAX_VIRTIO_CONSOLES ; i++) { -if (virtcon_hds[i]) { -pci_create_simple (pcibus,-1 ,"virtio-console-pci" ); - } - } -/* Register network interfaces. */ for (i =0 ; i < nb_nics; i++) {/* There are no PCI NICs on the Bamboo board, but there are
hw/qdev.c +2 -6
@@ -321,13 +321,9 @@ void qdev_machine_creation_done(void)CharDriverState *qdev_init_chardev (DeviceState *dev) {static int next_serial; -static int next_virtconsole; +/* FIXME: This is a nasty hack that needs to go away. */ -if (strncmp (dev->info->name,"virtio" ,6 ) ==0 ) { -return virtcon_hds[next_virtconsole++]; - }else { -return serial_hds[next_serial++]; - } +return serial_hds[next_serial++]; }BusState *qdev_get_parent_bus (DeviceState *dev)
hw/virtio-console.c +73 -107
216 lines not on this page · raw message
hw/virtio-console.h deleted +0 -19
@@ -1,19 +0,0 @@ -/* -* Virtio Console Support -* -* Copyright IBM, Corp. 2008 -* -* Authors: -* Christian Ehrhardt <[email protected]> -* -* This work is licensed under the terms of the GNU GPL, version 2. See -* the COPYING file in the top-level directory. -* -*/ -#ifndef _QEMU_VIRTIO_CONSOLE_H -#define _QEMU_VIRTIO_CONSOLE_H - -/* The ID for virtio console */ -#define VIRTIO_ID_CONSOLE 3 - -#endif
hw/virtio-pci.c +4 -4
@@ -467,7 +467,7 @@ static int virtio_blk_exit_pci(PCIDevice *pci_dev)return virtio_exit_pci (pci_dev); } -static int virtio_console_init_pci (PCIDevice *pci_dev) +static int virtio_serial_init_pci (PCIDevice *pci_dev) {VirtIOPCIProxy *proxy =DO_UPCAST (VirtIOPCIProxy, pci_dev, pci_dev);VirtIODevice *vdev;
@@ -477,7 +477,7 @@ static int virtio_console_init_pci(PCIDevice *pci_dev) proxy->class_code != PCI_CLASS_OTHERS) /* qemu-kvm */ proxy->class_code =PCI_CLASS_COMMUNICATION_OTHER ; - vdev =virtio_console_init (&pci_dev->qdev); + vdev =virtio_serial_init (&pci_dev->qdev);if (!vdev) {return -1 ; }
@@ -551,9 +551,9 @@ static PCIDeviceInfo virtio_info[] = { }, .qdev.reset = virtio_pci_reset, },{ - .qdev.name = "virtio-console-pci", + .qdev.name = "virtio-serial-pci", .qdev.size = sizeof(VirtIOPCIProxy), - .init = virtio_console_init_pci, + .init = virtio_serial_init_pci, .exit = virtio_exit_pci, .qdev.props = (Property []) {DEFINE_PROP_HEX32 ("class" , VirtIOPCIProxy, class_code,0 ),
hw/virtio-serial-bus.c new file +757 -0
757 lines not on this page · raw message
hw/virtio-serial.h new file +220 -0
220 lines not on this page · raw message
hw/virtio.h +1 -1
@@ -164,7 +164,7 @@ void virtio_bind_device(VirtIODevice *vdev, const VirtIOBindings *binding,/* Base devices. */ VirtIODevice *virtio_blk_init (DeviceState *dev,DriveInfo *dinfo);VirtIODevice *virtio_net_init (DeviceState *dev); -VirtIODevice *virtio_console_init (DeviceState *dev); +VirtIODevice *virtio_serial_init (DeviceState *dev);VirtIODevice *virtio_balloon_init (DeviceState *dev);#endif
qemu-options.hx +5 -1
@@ -1624,10 +1624,14 @@ ETEXI DEF("virtioconsole", HAS_ARG, QEMU_OPTION_virtiocon, \ "-virtioconsole c\n" \ - " set virtio console\n") + " define virtio console\n") STEXI @item -virtioconsole @var{c} Set virtio console. + +This option is maintained for backward compatibility. + +Please use @code{-device virtioconsole} for the new way of invocation ETEXI DEF("show-cursor", 0, QEMU_OPTION_show_cursor, \
sysemu.h +0 -6
@@ -226,12 +226,6 @@ extern CharDriverState *serial_hds[MAX_SERIAL_PORTS];extern CharDriverState *parallel_hds[MAX_PARALLEL_PORTS ]; -/* virtio consoles */ - -#define MAX_VIRTIO_CONSOLES 1 - -extern CharDriverState *virtcon_hds[MAX_VIRTIO_CONSOLES ]; -#define TFR (expr) do { if ((expr) != -1) break; } while (errno == EINTR)#ifdef HAS_AUDIO
vl.c +41 -24
108 lines not on this page · raw message
Signature · 1 line
1.6.2.5
PATCH 3/3 virtio-console: Add a new virtserialport device for generic serial port support
This patch adds generic serial ports over the virtio serial bus. These ports have a few more options that are not relevant for virtio console ports: the ability to cache buffers that are received for a port while it's disconnected, setting of limits to the bytes that are cached so as to prevent OOM conditions, etc.
Sample uses for such a device can be obtaining info from the guest like the file systems used, apps installed, etc. for offline usage and logged-in users, clipboard copy-paste, etc. for online usage.
For requirements, use-cases and some history see
http://www.linux-kvm.org/page/VMchannel_Requirements
--- hw/virtio-console.c | 38 ++++++++++++++++++++++++++++++++++++++ 1 files changed, 38 insertions(+), 0 deletions(-)
hw/virtio-console.c +38 -0
@@ -107,3 +107,41 @@ static void virtcon_register(void)virtio_serial_port_qdev_register (&virtcon_info); }device_init (virtcon_register) + + +/* Generic Virtio Serial Ports */ +static int virtserial_port_initfn(VirtIOSerialDevice *dev) +{ +VirtIOSerialPort *port =DO_UPCAST (VirtIOSerialPort, dev, &dev->qdev); +VirtConsole *vcon =DO_UPCAST (VirtConsole, port, port); + + port->info = dev->info; + +if (vcon->chr) { +qemu_chr_add_handlers (vcon->chr, chr_can_read, chr_read, chr_event, + vcon); + } +return 0 ; +} + +static VirtIOSerialPortInfo virtserial_port_info = { + .qdev.name ="virtserialport" , + .qdev.size =sizeof (VirtConsole), + .init = virtserial_port_initfn, + .have_data = flush_buf, + .qdev.props = (Property []) { +DEFINE_PROP_CHR ("chardev" , VirtConsole, chr), +DEFINE_PROP_STRING ("name" , VirtIOSerialPort, name), +DEFINE_PROP_INT32 ("cache_buffers" , VirtIOSerialPort, cache_buffers,1 ), +DEFINE_PROP_UINT64 ("byte_limit" , VirtIOSerialPort, byte_limit,0 ), +DEFINE_PROP_UINT64 ("guest_byte_limit" , VirtIOSerialPort, + guest_byte_limit,0 ), +DEFINE_PROP_END_OF_LIST (), + }, +}; + +static void virtserial_port_register (void ) +{ +virtio_serial_port_qdev_register (&virtserial_port_info); +} +device_init (virtserial_port_register)
Signature · 1 line
1.6.2.5