virtio-console: Add support for multiple ports for generic guest-host communication
v10 cover virtio-console: Add support for multiple ports for generic guest-host communication
Hello,
This iteration of the series fixes a style bug pointed out by Gerd and a typo noticed by Rich.
In addition to that, it also introduces a few debug prints in the 'info qtree' output that shows some per-port data that could be helpful for debugging.
I've been testing all the features that are presented here from the testsuite at
http://fedorapeople.org/gitweb?p=amitshah/public_git/test-virtserial.git
The testsuite tests for host-guest interaction as well as qemu chardev-virtioserial interaction.
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
Makefile.target | 2 +- hw/pc.c | 9 - hw/ppc440_bamboo.c | 7 - hw/qdev.c | 8 +- hw/virtio-console.c | 206 +++++++------ hw/virtio-console.h | 19 -- hw/virtio-pci.c | 8 +- hw/virtio-serial-bus.c | 785 ++++++++++++++++++++++++++++++++++++++++++++++++ hw/virtio-serial.h | 227 ++++++++++++++ hw/virtio.h | 2 +- qemu-options.hx | 6 +- sysemu.h | 6 - vl.c | 65 +++-- 13 files changed, 1171 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 v10 1/2 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 | 785 ++++++++++++++++++++++++++++++++++++++++++++++++ hw/virtio-serial.h | 227 ++++++++++++++ hw/virtio.h | 2 +- qemu-options.hx | 6 +- sysemu.h | 6 - vl.c | 65 +++-- 13 files changed, 1139 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
@@ -1319,15 +1319,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 +785 -0
785 lines not on this page · raw message
hw/virtio-serial.h new file +227 -0
227 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
@@ -1635,10 +1635,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 virtconsole} 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 v10 2/2 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, test 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" , VirtConsole, port.name), +DEFINE_PROP_INT32 ("cache_buffers" , VirtConsole, port.cache_buffers,1 ), +DEFINE_PROP_UINT64 ("byte_limit" , VirtConsole, port.byte_limit,0 ), +DEFINE_PROP_UINT64 ("guest_byte_limit" , VirtConsole, + port.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