Add patches for the VirtioSerial feature; update spec to build with the new

patches.
This commit is contained in:
amitshah 2010-01-27 18:10:32 +00:00
parent 6a83af9e13
commit 15dff558ab
10 changed files with 2320 additions and 1 deletions

View File

@ -0,0 +1,44 @@
From 12a074387284fc530876ef709b3d344adea9b226 Mon Sep 17 00:00:00 2001
From: Amit Shah <amit.shah@redhat.com>
Date: Wed, 20 Jan 2010 00:36:57 +0530
Subject: [PATCH 7/9] Move virtio-serial to Makefile.objs
There's nothing target-dependent in the virtio-serial code so allow it
to be compiled just once for all the targets.
Signed-off-by: Amit Shah <amit.shah@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
---
Makefile.hw | 2 +-
Makefile.target | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/Makefile.hw b/Makefile.hw
index 6f4dbc4..de8a0c5 100644
--- a/Makefile.hw
+++ b/Makefile.hw
@@ -13,7 +13,7 @@ QEMU_CFLAGS+=-I.. -I$(SRC_PATH)/fpu
obj-y =
obj-y += loader.o
-obj-y += virtio.o
+obj-y += virtio.o virtio-serial.o
obj-y += fw_cfg.o
obj-y += watchdog.o
obj-$(CONFIG_ECC) += ecc.o
diff --git a/Makefile.target b/Makefile.target
index 234577c..0e4cfd1 100644
--- a/Makefile.target
+++ b/Makefile.target
@@ -166,7 +166,7 @@ ifdef CONFIG_SOFTMMU
obj-y = vl.o async.o monitor.o pci.o pci_host.o pcie_host.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-serial.o virtio-serial-bus.o virtio-pci.o
+obj-y += virtio-blk.o virtio-balloon.o virtio-net.o virtio-pci.o virtio-serial-bus.o
obj-$(CONFIG_KVM) += kvm.o kvm-all.o
# MSI-X depends on kvm for interrupt injection,
# so moved it from Makefile.hw to Makefile.target for now
--
1.6.2.5

View File

@ -0,0 +1,47 @@
From c11631e8bc91a1d1be2b89196e886a1385820dfb Mon Sep 17 00:00:00 2001
From: Amit Shah <amit.shah@redhat.com>
Date: Wed, 20 Jan 2010 00:36:51 +0530
Subject: [PATCH 1/9] virtio: Remove duplicate macro definition for max. virtqueues, bump up the max
VIRTIO_PCI_QUEUE_MAX is redefined in hw/virtio.c. Let's just keep it in
hw/virtio.h.
Also, bump up the value of the maximum allowed virtqueues to 64. This is
in preparation to allow multiple ports per virtio-console device.
Signed-off-by: Amit Shah <amit.shah@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
---
hw/virtio.c | 2 --
hw/virtio.h | 2 +-
2 files changed, 1 insertions(+), 3 deletions(-)
diff --git a/hw/virtio.c b/hw/virtio.c
index cecd0dc..88f4e78 100644
--- a/hw/virtio.c
+++ b/hw/virtio.c
@@ -75,8 +75,6 @@ struct VirtQueue
void (*handle_output)(VirtIODevice *vdev, VirtQueue *vq);
};
-#define VIRTIO_PCI_QUEUE_MAX 16
-
/* virt queue functions */
static void virtqueue_init(VirtQueue *vq)
{
diff --git a/hw/virtio.h b/hw/virtio.h
index 35532a6..051910a 100644
--- a/hw/virtio.h
+++ b/hw/virtio.h
@@ -90,7 +90,7 @@ typedef struct {
unsigned (*get_features)(void * opaque);
} VirtIOBindings;
-#define VIRTIO_PCI_QUEUE_MAX 16
+#define VIRTIO_PCI_QUEUE_MAX 64
#define VIRTIO_NO_VECTOR 0xffff
--
1.6.2.5

View File

@ -0,0 +1,341 @@
From 9c7f6b094950f7772068b957c795d76463cdeba0 Mon Sep 17 00:00:00 2001
From: Amit Shah <amit.shah@redhat.com>
Date: Thu, 21 Jan 2010 15:43:26 +0530
Subject: [PATCH 9/9] virtio-console: Rename virtio-serial.c back to virtio-console.c
This file was renamed to ease the reviews of the recent changes
that went in.
Now that the changes are done, rename the file back to its original
name.
Signed-off-by: Amit Shah <amit.shah@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
---
Makefile.hw | 2 +-
hw/virtio-console.c | 146 +++++++++++++++++++++++++++++++++++++++++++++++++++
hw/virtio-serial.c | 146 ---------------------------------------------------
3 files changed, 147 insertions(+), 147 deletions(-)
create mode 100644 hw/virtio-console.c
delete mode 100644 hw/virtio-serial.c
diff --git a/Makefile.hw b/Makefile.hw
index de8a0c5..43ca541 100644
--- a/Makefile.hw
+++ b/Makefile.hw
@@ -13,7 +13,7 @@ QEMU_CFLAGS+=-I.. -I$(SRC_PATH)/fpu
obj-y =
obj-y += loader.o
-obj-y += virtio.o virtio-serial.o
+obj-y += virtio.o virtio-console.o
obj-y += fw_cfg.o
obj-y += watchdog.o
obj-$(CONFIG_ECC) += ecc.o
diff --git a/hw/virtio-console.c b/hw/virtio-console.c
new file mode 100644
index 0000000..bd44ec6
--- /dev/null
+++ b/hw/virtio-console.c
@@ -0,0 +1,146 @@
+/*
+ * Virtio Console and Generic Serial Port Devices
+ *
+ * Copyright Red Hat, Inc. 2009
+ *
+ * Authors:
+ * Amit Shah <amit.shah@redhat.com>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2. See
+ * the COPYING file in the top-level directory.
+ */
+
+#include "qemu-char.h"
+#include "virtio-serial.h"
+
+typedef struct VirtConsole {
+ VirtIOSerialPort port;
+ CharDriverState *chr;
+} VirtConsole;
+
+
+/* Callback function that's called when the guest sends us data */
+static size_t flush_buf(VirtIOSerialPort *port, const uint8_t *buf, size_t len)
+{
+ VirtConsole *vcon = DO_UPCAST(VirtConsole, port, port);
+ ssize_t ret;
+
+ ret = qemu_chr_write(vcon->chr, buf, len);
+
+ return ret < 0 ? 0 : ret;
+}
+
+/* Readiness of the guest to accept data on a port */
+static int chr_can_read(void *opaque)
+{
+ VirtConsole *vcon = opaque;
+
+ return virtio_serial_guest_ready(&vcon->port);
+}
+
+/* Send data from a char device over to the guest */
+static void chr_read(void *opaque, const uint8_t *buf, int size)
+{
+ VirtConsole *vcon = opaque;
+
+ virtio_serial_write(&vcon->port, buf, size);
+}
+
+static void chr_event(void *opaque, int event)
+{
+ VirtConsole *vcon = opaque;
+
+ switch (event) {
+ case CHR_EVENT_OPENED: {
+ virtio_serial_open(&vcon->port);
+ break;
+ }
+ case CHR_EVENT_CLOSED:
+ virtio_serial_close(&vcon->port);
+ break;
+ }
+}
+
+/* Virtio Console Ports */
+static int virtconsole_initfn(VirtIOSerialDevice *dev)
+{
+ VirtIOSerialPort *port = DO_UPCAST(VirtIOSerialPort, dev, &dev->qdev);
+ VirtConsole *vcon = DO_UPCAST(VirtConsole, port, port);
+
+ port->info = dev->info;
+
+ port->is_console = true;
+
+ if (vcon->chr) {
+ qemu_chr_add_handlers(vcon->chr, chr_can_read, chr_read, chr_event,
+ vcon);
+ port->info->have_data = flush_buf;
+ }
+ return 0;
+}
+
+static int virtconsole_exitfn(VirtIOSerialDevice *dev)
+{
+ VirtIOSerialPort *port = DO_UPCAST(VirtIOSerialPort, dev, &dev->qdev);
+ VirtConsole *vcon = DO_UPCAST(VirtConsole, port, port);
+
+ if (vcon->chr) {
+ port->info->have_data = NULL;
+ qemu_chr_close(vcon->chr);
+ }
+
+ return 0;
+}
+
+static VirtIOSerialPortInfo virtconsole_info = {
+ .qdev.name = "virtconsole",
+ .qdev.size = sizeof(VirtConsole),
+ .init = virtconsole_initfn,
+ .exit = virtconsole_exitfn,
+ .qdev.props = (Property[]) {
+ DEFINE_PROP_UINT8("is_console", VirtConsole, port.is_console, 1),
+ DEFINE_PROP_CHR("chardev", VirtConsole, chr),
+ DEFINE_PROP_STRING("name", VirtConsole, port.name),
+ DEFINE_PROP_END_OF_LIST(),
+ },
+};
+
+static void virtconsole_register(void)
+{
+ virtio_serial_port_qdev_register(&virtconsole_info);
+}
+device_init(virtconsole_register)
+
+/* Generic Virtio Serial Ports */
+static int virtserialport_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);
+ port->info->have_data = flush_buf;
+ }
+ return 0;
+}
+
+static VirtIOSerialPortInfo virtserialport_info = {
+ .qdev.name = "virtserialport",
+ .qdev.size = sizeof(VirtConsole),
+ .init = virtserialport_initfn,
+ .exit = virtconsole_exitfn,
+ .qdev.props = (Property[]) {
+ DEFINE_PROP_CHR("chardev", VirtConsole, chr),
+ DEFINE_PROP_STRING("name", VirtConsole, port.name),
+ DEFINE_PROP_END_OF_LIST(),
+ },
+};
+
+static void virtserialport_register(void)
+{
+ virtio_serial_port_qdev_register(&virtserialport_info);
+}
+device_init(virtserialport_register)
diff --git a/hw/virtio-serial.c b/hw/virtio-serial.c
deleted file mode 100644
index bd44ec6..0000000
--- a/hw/virtio-serial.c
+++ /dev/null
@@ -1,146 +0,0 @@
-/*
- * Virtio Console and Generic Serial Port Devices
- *
- * Copyright Red Hat, Inc. 2009
- *
- * Authors:
- * Amit Shah <amit.shah@redhat.com>
- *
- * This work is licensed under the terms of the GNU GPL, version 2. See
- * the COPYING file in the top-level directory.
- */
-
-#include "qemu-char.h"
-#include "virtio-serial.h"
-
-typedef struct VirtConsole {
- VirtIOSerialPort port;
- CharDriverState *chr;
-} VirtConsole;
-
-
-/* Callback function that's called when the guest sends us data */
-static size_t flush_buf(VirtIOSerialPort *port, const uint8_t *buf, size_t len)
-{
- VirtConsole *vcon = DO_UPCAST(VirtConsole, port, port);
- ssize_t ret;
-
- ret = qemu_chr_write(vcon->chr, buf, len);
-
- return ret < 0 ? 0 : ret;
-}
-
-/* Readiness of the guest to accept data on a port */
-static int chr_can_read(void *opaque)
-{
- VirtConsole *vcon = opaque;
-
- return virtio_serial_guest_ready(&vcon->port);
-}
-
-/* Send data from a char device over to the guest */
-static void chr_read(void *opaque, const uint8_t *buf, int size)
-{
- VirtConsole *vcon = opaque;
-
- virtio_serial_write(&vcon->port, buf, size);
-}
-
-static void chr_event(void *opaque, int event)
-{
- VirtConsole *vcon = opaque;
-
- switch (event) {
- case CHR_EVENT_OPENED: {
- virtio_serial_open(&vcon->port);
- break;
- }
- case CHR_EVENT_CLOSED:
- virtio_serial_close(&vcon->port);
- break;
- }
-}
-
-/* Virtio Console Ports */
-static int virtconsole_initfn(VirtIOSerialDevice *dev)
-{
- VirtIOSerialPort *port = DO_UPCAST(VirtIOSerialPort, dev, &dev->qdev);
- VirtConsole *vcon = DO_UPCAST(VirtConsole, port, port);
-
- port->info = dev->info;
-
- port->is_console = true;
-
- if (vcon->chr) {
- qemu_chr_add_handlers(vcon->chr, chr_can_read, chr_read, chr_event,
- vcon);
- port->info->have_data = flush_buf;
- }
- return 0;
-}
-
-static int virtconsole_exitfn(VirtIOSerialDevice *dev)
-{
- VirtIOSerialPort *port = DO_UPCAST(VirtIOSerialPort, dev, &dev->qdev);
- VirtConsole *vcon = DO_UPCAST(VirtConsole, port, port);
-
- if (vcon->chr) {
- port->info->have_data = NULL;
- qemu_chr_close(vcon->chr);
- }
-
- return 0;
-}
-
-static VirtIOSerialPortInfo virtconsole_info = {
- .qdev.name = "virtconsole",
- .qdev.size = sizeof(VirtConsole),
- .init = virtconsole_initfn,
- .exit = virtconsole_exitfn,
- .qdev.props = (Property[]) {
- DEFINE_PROP_UINT8("is_console", VirtConsole, port.is_console, 1),
- DEFINE_PROP_CHR("chardev", VirtConsole, chr),
- DEFINE_PROP_STRING("name", VirtConsole, port.name),
- DEFINE_PROP_END_OF_LIST(),
- },
-};
-
-static void virtconsole_register(void)
-{
- virtio_serial_port_qdev_register(&virtconsole_info);
-}
-device_init(virtconsole_register)
-
-/* Generic Virtio Serial Ports */
-static int virtserialport_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);
- port->info->have_data = flush_buf;
- }
- return 0;
-}
-
-static VirtIOSerialPortInfo virtserialport_info = {
- .qdev.name = "virtserialport",
- .qdev.size = sizeof(VirtConsole),
- .init = virtserialport_initfn,
- .exit = virtconsole_exitfn,
- .qdev.props = (Property[]) {
- DEFINE_PROP_CHR("chardev", VirtConsole, chr),
- DEFINE_PROP_STRING("name", VirtConsole, port.name),
- DEFINE_PROP_END_OF_LIST(),
- },
-};
-
-static void virtserialport_register(void)
-{
- virtio_serial_port_qdev_register(&virtserialport_info);
-}
-device_init(virtserialport_register)
--
1.6.2.5

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,63 @@
From fcb66d7ac2271bcf0b46d6b1ae2d3db38e78bf2b Mon Sep 17 00:00:00 2001
From: Amit Shah <amit.shah@redhat.com>
Date: Wed, 20 Jan 2010 00:36:56 +0530
Subject: [PATCH 6/9] virtio-serial: Add a 'virtserialport' device for generic serial port support
This commit adds a simple chardev-based serial port. Any data the guest
sends is forwarded to the chardev and vice-versa.
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.
Signed-off-by: Amit Shah <amit.shah@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
---
hw/virtio-serial.c | 34 ++++++++++++++++++++++++++++++++++
1 files changed, 34 insertions(+), 0 deletions(-)
diff --git a/hw/virtio-serial.c b/hw/virtio-serial.c
index 9c2c93c..bd44ec6 100644
--- a/hw/virtio-serial.c
+++ b/hw/virtio-serial.c
@@ -110,3 +110,37 @@ static void virtconsole_register(void)
virtio_serial_port_qdev_register(&virtconsole_info);
}
device_init(virtconsole_register)
+
+/* Generic Virtio Serial Ports */
+static int virtserialport_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);
+ port->info->have_data = flush_buf;
+ }
+ return 0;
+}
+
+static VirtIOSerialPortInfo virtserialport_info = {
+ .qdev.name = "virtserialport",
+ .qdev.size = sizeof(VirtConsole),
+ .init = virtserialport_initfn,
+ .exit = virtconsole_exitfn,
+ .qdev.props = (Property[]) {
+ DEFINE_PROP_CHR("chardev", VirtConsole, chr),
+ DEFINE_PROP_STRING("name", VirtConsole, port.name),
+ DEFINE_PROP_END_OF_LIST(),
+ },
+};
+
+static void virtserialport_register(void)
+{
+ virtio_serial_port_qdev_register(&virtserialport_info);
+}
+device_init(virtserialport_register)
--
1.6.2.5

View File

@ -0,0 +1,45 @@
From 43fa8533e10c478825952d489269d55e5c652c1a Mon Sep 17 00:00:00 2001
From: Amit Shah <amit.shah@redhat.com>
Date: Wed, 20 Jan 2010 00:36:58 +0530
Subject: [PATCH 8/9] virtio-serial: Use MSI vectors for port virtqueues
This commit enables the use of MSI interrupts for virtqueue
notifications for ports. We use nr_ports + 1 (for control channel) msi
entries for the ports, as only the in_vq operations need an interrupt on
the guest.
Signed-off-by: Amit Shah <amit.shah@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
---
hw/virtio-pci.c | 4 ++++
1 files changed, 4 insertions(+), 0 deletions(-)
diff --git a/hw/virtio-pci.c b/hw/virtio-pci.c
index c1a1e4c..4451a63 100644
--- a/hw/virtio-pci.c
+++ b/hw/virtio-pci.c
@@ -497,10 +497,13 @@ static int virtio_serial_init_pci(PCIDevice *pci_dev)
if (!vdev) {
return -1;
}
+ vdev->nvectors = proxy->nvectors ? proxy->nvectors
+ : proxy->max_virtserial_ports + 1;
virtio_init_pci(proxy, vdev,
PCI_VENDOR_ID_REDHAT_QUMRANET,
PCI_DEVICE_ID_VIRTIO_CONSOLE,
proxy->class_code, 0x00);
+ proxy->nvectors = vdev->nvectors;
return 0;
}
@@ -577,6 +580,7 @@ static PCIDeviceInfo virtio_info[] = {
.init = virtio_serial_init_pci,
.exit = virtio_exit_pci,
.qdev.props = (Property[]) {
+ DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors, 0),
DEFINE_PROP_HEX32("class", VirtIOPCIProxy, class_code, 0),
DEFINE_PROP_UINT32("max_ports", VirtIOPCIProxy, max_virtserial_ports,
31),
--
1.6.2.5

View File

@ -0,0 +1,116 @@
From ed4daf8c7722562ec05e83ec98a4d4d8adf20f7f Mon Sep 17 00:00:00 2001
From: Amit Shah <amit.shah@redhat.com>
Date: Wed, 20 Jan 2010 00:36:54 +0530
Subject: [PATCH 4/9] virtio-serial-bus: Add a port 'name' property for port discovery in guests
The port 'id' or number is internal state between the guest kernel and
our bus implementation. This is invocation-dependent and isn't part of
the guest-host ABI.
To correcly enumerate and map ports between the host and the guest, the
'name' property is used.
Example:
-device virtserialport,name=org.qemu.port.0
This invocation will get us a char device in the guest at:
/dev/virtio-ports/org.qemu.port.0
which can be a symlink to
/dev/vport0p3
This 'name' property is exposed by the guest kernel in a sysfs
attribute:
/sys/kernel/virtio-ports/vport0p3/name
A simple udev script can pick up this name and create the symlink
mentioned above.
Signed-off-by: Amit Shah <amit.shah@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
---
hw/virtio-serial-bus.c | 17 +++++++++++++++++
hw/virtio-serial.c | 1 +
hw/virtio-serial.h | 8 ++++++++
3 files changed, 26 insertions(+), 0 deletions(-)
diff --git a/hw/virtio-serial-bus.c b/hw/virtio-serial-bus.c
index 9af21df..6d69c56 100644
--- a/hw/virtio-serial-bus.c
+++ b/hw/virtio-serial-bus.c
@@ -204,6 +204,8 @@ static void handle_control_message(VirtIOSerial *vser, void *buf)
{
struct VirtIOSerialPort *port;
struct virtio_console_control cpkt, *gcpkt;
+ uint8_t *buffer;
+ size_t buffer_len;
gcpkt = buf;
port = find_port_by_id(vser, ldl_p(&gcpkt->id));
@@ -226,6 +228,21 @@ static void handle_control_message(VirtIOSerial *vser, void *buf)
send_control_event(port, VIRTIO_CONSOLE_CONSOLE_PORT, 1);
}
+ if (port->name) {
+ stw_p(&cpkt.event, VIRTIO_CONSOLE_PORT_NAME);
+ stw_p(&cpkt.value, 1);
+
+ buffer_len = sizeof(cpkt) + strlen(port->name) + 1;
+ buffer = qemu_malloc(buffer_len);
+
+ memcpy(buffer, &cpkt, sizeof(cpkt));
+ memcpy(buffer + sizeof(cpkt), port->name, strlen(port->name));
+ buffer[buffer_len - 1] = 0;
+
+ send_control_msg(port, buffer, buffer_len);
+ qemu_free(buffer);
+ }
+
if (port->host_connected) {
send_control_event(port, VIRTIO_CONSOLE_PORT_OPEN, 1);
}
diff --git a/hw/virtio-serial.c b/hw/virtio-serial.c
index 1dc031e..9c2c93c 100644
--- a/hw/virtio-serial.c
+++ b/hw/virtio-serial.c
@@ -100,6 +100,7 @@ static VirtIOSerialPortInfo virtconsole_info = {
.qdev.props = (Property[]) {
DEFINE_PROP_UINT8("is_console", VirtConsole, port.is_console, 1),
DEFINE_PROP_CHR("chardev", VirtConsole, chr),
+ DEFINE_PROP_STRING("name", VirtConsole, port.name),
DEFINE_PROP_END_OF_LIST(),
},
};
diff --git a/hw/virtio-serial.h b/hw/virtio-serial.h
index d9c7acb..28ea7da 100644
--- a/hw/virtio-serial.h
+++ b/hw/virtio-serial.h
@@ -50,6 +50,7 @@ struct virtio_console_control {
#define VIRTIO_CONSOLE_CONSOLE_PORT 1
#define VIRTIO_CONSOLE_RESIZE 2
#define VIRTIO_CONSOLE_PORT_OPEN 3
+#define VIRTIO_CONSOLE_PORT_NAME 4
/* == In-qemu interface == */
@@ -84,6 +85,13 @@ struct VirtIOSerialPort {
VirtQueue *ivq, *ovq;
/*
+ * This name is sent to the guest and exported via sysfs.
+ * The guest could create symlinks based on this information.
+ * The name is in the reverse fqdn format, like org.qemu.console.0
+ */
+ char *name;
+
+ /*
* This id helps identify ports between the guest and the host.
* The guest sends a "header" with this id with each data packet
* that it sends and the host can then find out which associated
--
1.6.2.5

View File

@ -0,0 +1,40 @@
From c101ff585d5b156a1f3461015a9acd73f15a45f6 Mon Sep 17 00:00:00 2001
From: Amit Shah <amit.shah@redhat.com>
Date: Wed, 20 Jan 2010 00:36:55 +0530
Subject: [PATCH 5/9] virtio-serial-bus: Add ability to hot-unplug ports
Signed-off-by: Amit Shah <amit.shah@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
---
hw/virtio-serial-bus.c | 2 ++
hw/virtio-serial.h | 1 +
2 files changed, 3 insertions(+), 0 deletions(-)
diff --git a/hw/virtio-serial-bus.c b/hw/virtio-serial-bus.c
index 6d69c56..037864f 100644
--- a/hw/virtio-serial-bus.c
+++ b/hw/virtio-serial-bus.c
@@ -517,6 +517,8 @@ static int virtser_port_qdev_exit(DeviceState *qdev)
VirtIOSerialPort *port = DO_UPCAST(VirtIOSerialPort, dev, &dev->qdev);
VirtIOSerial *vser = port->vser;
+ send_control_event(port, VIRTIO_CONSOLE_PORT_REMOVE, 1);
+
/*
* Don't decrement nr_ports here; thus we keep a linearly
* increasing port id. Not utilising an id again saves us a couple
diff --git a/hw/virtio-serial.h b/hw/virtio-serial.h
index 28ea7da..f297b00 100644
--- a/hw/virtio-serial.h
+++ b/hw/virtio-serial.h
@@ -51,6 +51,7 @@ struct virtio_console_control {
#define VIRTIO_CONSOLE_RESIZE 2
#define VIRTIO_CONSOLE_PORT_OPEN 3
#define VIRTIO_CONSOLE_PORT_NAME 4
+#define VIRTIO_CONSOLE_PORT_REMOVE 5
/* == In-qemu interface == */
--
1.6.2.5

View File

@ -0,0 +1,232 @@
From 4945aee74f494cc8a17ce1634b5200eb9ee227d2 Mon Sep 17 00:00:00 2001
From: Amit Shah <amit.shah@redhat.com>
Date: Wed, 20 Jan 2010 00:36:53 +0530
Subject: [PATCH 3/9] virtio-serial-bus: Maintain guest and host port open/close state
Via control channel messages, the guest can tell us whether a port got
opened or closed. Similarly, we can also indicate to the guest of host
port open/close events.
Signed-off-by: Amit Shah <amit.shah@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
---
hw/virtio-serial-bus.c | 94 ++++++++++++++++++++++++++++++++++++++++++++++++
hw/virtio-serial.h | 6 +++
2 files changed, 100 insertions(+), 0 deletions(-)
diff --git a/hw/virtio-serial-bus.c b/hw/virtio-serial-bus.c
index 5132c9c..9af21df 100644
--- a/hw/virtio-serial-bus.c
+++ b/hw/virtio-serial-bus.c
@@ -66,6 +66,11 @@ static VirtIOSerialPort *find_port_by_vq(VirtIOSerial *vser, VirtQueue *vq)
return NULL;
}
+static bool use_multiport(VirtIOSerial *vser)
+{
+ return vser->vdev.features & (1 << VIRTIO_CONSOLE_F_MULTIPORT);
+}
+
static size_t write_to_port(VirtIOSerialPort *port,
const uint8_t *buf, size_t size)
{
@@ -139,11 +144,22 @@ static size_t send_control_event(VirtIOSerialPort *port, uint16_t event,
/* Functions for use inside qemu to open and read from/write to ports */
int virtio_serial_open(VirtIOSerialPort *port)
{
+ /* Don't allow opening an already-open port */
+ if (port->host_connected) {
+ return 0;
+ }
+ /* Send port open notification to the guest */
+ port->host_connected = true;
+ send_control_event(port, VIRTIO_CONSOLE_PORT_OPEN, 1);
+
return 0;
}
int virtio_serial_close(VirtIOSerialPort *port)
{
+ port->host_connected = false;
+ send_control_event(port, VIRTIO_CONSOLE_PORT_OPEN, 0);
+
return 0;
}
@@ -151,6 +167,9 @@ int virtio_serial_close(VirtIOSerialPort *port)
ssize_t virtio_serial_write(VirtIOSerialPort *port, const uint8_t *buf,
size_t size)
{
+ if (!port || !port->host_connected || !port->guest_connected) {
+ return 0;
+ }
return write_to_port(port, buf, size);
}
@@ -167,6 +186,9 @@ size_t virtio_serial_guest_ready(VirtIOSerialPort *port)
virtio_queue_empty(vq)) {
return 0;
}
+ if (use_multiport(port->vser) && !port->guest_connected) {
+ return 0;
+ }
if (virtqueue_avail_bytes(vq, 4096, 0)) {
return 4096;
@@ -203,6 +225,11 @@ static void handle_control_message(VirtIOSerial *vser, void *buf)
if (port->is_console) {
send_control_event(port, VIRTIO_CONSOLE_CONSOLE_PORT, 1);
}
+
+ if (port->host_connected) {
+ send_control_event(port, VIRTIO_CONSOLE_PORT_OPEN, 1);
+ }
+
/*
* When the guest has asked us for this information it means
* the guest is all setup and has its virtqueues
@@ -213,6 +240,19 @@ static void handle_control_message(VirtIOSerial *vser, void *buf)
port->info->guest_ready(port);
}
break;
+
+ case VIRTIO_CONSOLE_PORT_OPEN:
+ port->guest_connected = cpkt.value;
+ if (cpkt.value && port->info->guest_open) {
+ /* Send the guest opened notification if an app is interested */
+ port->info->guest_open(port);
+ }
+
+ if (!cpkt.value && port->info->guest_close) {
+ /* Send the guest closed notification if an app is interested */
+ port->info->guest_close(port);
+ }
+ break;
}
}
@@ -300,6 +340,8 @@ static void set_config(VirtIODevice *vdev, const uint8_t *config_data)
static void virtio_serial_save(QEMUFile *f, void *opaque)
{
VirtIOSerial *s = opaque;
+ VirtIOSerialPort *port;
+ uint32_t nr_active_ports;
/* The virtio device */
virtio_save(&s->vdev, f);
@@ -308,15 +350,41 @@ static void virtio_serial_save(QEMUFile *f, void *opaque)
qemu_put_be16s(f, &s->config.cols);
qemu_put_be16s(f, &s->config.rows);
qemu_put_be32s(f, &s->config.nr_ports);
+
+ /* Items in struct VirtIOSerial */
+
+ /* Do this because we might have hot-unplugged some ports */
+ nr_active_ports = 0;
+ QTAILQ_FOREACH(port, &s->ports, next)
+ nr_active_ports++;
+
+ qemu_put_be32s(f, &nr_active_ports);
+
+ /*
+ * Items in struct VirtIOSerialPort.
+ */
+ QTAILQ_FOREACH(port, &s->ports, next) {
+ /*
+ * We put the port number because we may not have an active
+ * port at id 0 that's reserved for a console port, or in case
+ * of ports that might have gotten unplugged
+ */
+ qemu_put_be32s(f, &port->id);
+ qemu_put_byte(f, port->guest_connected);
+ }
}
static int virtio_serial_load(QEMUFile *f, void *opaque, int version_id)
{
VirtIOSerial *s = opaque;
+ VirtIOSerialPort *port;
+ uint32_t nr_active_ports;
+ unsigned int i;
if (version_id > 2) {
return -EINVAL;
}
+
/* The virtio device */
virtio_load(&s->vdev, f);
@@ -329,6 +397,20 @@ static int virtio_serial_load(QEMUFile *f, void *opaque, int version_id)
qemu_get_be16s(f, &s->config.rows);
s->config.nr_ports = qemu_get_be32(f);
+ /* Items in struct VirtIOSerial */
+
+ qemu_get_be32s(f, &nr_active_ports);
+
+ /* Items in struct VirtIOSerialPort */
+ for (i = 0; i < nr_active_ports; i++) {
+ uint32_t id;
+
+ id = qemu_get_be32(f);
+ port = find_port_by_id(s, id);
+
+ port->guest_connected = qemu_get_byte(f);
+ }
+
return 0;
}
@@ -357,6 +439,10 @@ static void virtser_bus_dev_print(Monitor *mon, DeviceState *qdev, int indent)
monitor_printf(mon, "%*s dev-prop-int: id: %u\n",
indent, "", port->id);
+ monitor_printf(mon, "%*s dev-prop-int: guest_connected: %d\n",
+ indent, "", port->guest_connected);
+ monitor_printf(mon, "%*s dev-prop-int: host_connected: %d\n",
+ indent, "", port->host_connected);
}
static int virtser_port_qdev_init(DeviceState *qdev, DeviceInfo *base)
@@ -390,6 +476,14 @@ static int virtser_port_qdev_init(DeviceState *qdev, DeviceInfo *base)
port->id = plugging_port0 ? 0 : port->vser->config.nr_ports++;
+ if (!use_multiport(port->vser)) {
+ /*
+ * Allow writes to guest in this case; we have no way of
+ * knowing if a guest port is connected.
+ */
+ port->guest_connected = true;
+ }
+
QTAILQ_INSERT_TAIL(&port->vser->ports, port, next);
port->ivq = port->vser->ivqs[port->id];
port->ovq = port->vser->ovqs[port->id];
diff --git a/hw/virtio-serial.h b/hw/virtio-serial.h
index fe8e357..d9c7acb 100644
--- a/hw/virtio-serial.h
+++ b/hw/virtio-serial.h
@@ -49,6 +49,7 @@ struct virtio_console_control {
#define VIRTIO_CONSOLE_PORT_READY 0
#define VIRTIO_CONSOLE_CONSOLE_PORT 1
#define VIRTIO_CONSOLE_RESIZE 2
+#define VIRTIO_CONSOLE_PORT_OPEN 3
/* == In-qemu interface == */
@@ -92,6 +93,11 @@ struct VirtIOSerialPort {
/* Identify if this is a port that binds with hvc in the guest */
uint8_t is_console;
+
+ /* Is the corresponding guest device open? */
+ bool guest_connected;
+ /* Is this device open for IO on the host? */
+ bool host_connected;
};
struct VirtIOSerialPortInfo {
--
1.6.2.5

View File

@ -1,7 +1,7 @@
Summary: QEMU is a FAST! processor emulator
Name: qemu
Version: 0.12.2
Release: 1%{?dist}
Release: 2%{?dist}
# Epoch because we pushed a qemu-1.0 package
Epoch: 2
License: GPLv2+ and LGPLv2+ and BSD
@ -24,6 +24,18 @@ Source6: ksmtuned.init
Source7: ksmtuned
Source8: ksmtuned.conf
# virtio-console changes for the F13 VirtioSerial feature
Patch01: qemu-virtio-Remove-duplicate-macro-definition-for-max.-v.patch
Patch02: qemu-virtio-console-qdev-conversion-new-virtio-serial-b.patch
Patch03: qemu-virtio-serial-bus-Maintain-guest-and-host-port-open.patch
Patch04: qemu-virtio-serial-bus-Add-a-port-name-property-for-po.patch
Patch05: qemu-virtio-serial-bus-Add-ability-to-hot-unplug-ports.patch
Patch06: qemu-virtio-serial-Add-a-virtserialport-device-for-gen.patch
Patch07: qemu-Move-virtio-serial-to-Makefile.objs.patch
Patch08: qemu-virtio-serial-Use-MSI-vectors-for-port-virtqueues.patch
Patch09: qemu-virtio-console-Rename-virtio-serial.c-back-to-virti.patch
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
BuildRequires: SDL-devel zlib-devel which texi2html gnutls-devel cyrus-sasl-devel
BuildRequires: rsync dev86 iasl
@ -211,6 +223,16 @@ such as kvmtrace and kvm_stat.
%prep
%setup -q -n qemu-kvm-%{version}
%patch01 -p1
%patch02 -p1
%patch03 -p1
%patch04 -p1
%patch05 -p1
%patch06 -p1
%patch07 -p1
%patch08 -p1
%patch09 -p1
%build
# --build-id option is used fedora 8 onwards for giving info to the debug packages.
extraldflags="-Wl,--build-id";
@ -493,6 +515,9 @@ fi
%{_mandir}/man1/qemu-img.1*
%changelog
* Wed Jan 27 2010 Amit Shah <amit.shah@redhat.com> - 2:0.12.2-2
- Add virtio-console patches from upstream for the F13 VirtioSerial feature
* Mon Jan 25 2010 Justin M. Forbes <jforbes@redhat.com> - 2:0.12.2-1
- Update to 0.12.2 upstream