[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 16/17] virtio-serial: Discard data that guest sends
From: |
Amit Shah |
Subject: |
[Qemu-devel] [PATCH 16/17] virtio-serial: Discard data that guest sends us when ports aren't connected |
Date: |
Wed, 31 Mar 2010 13:04:07 +0530 |
Before the earlier patch, we relied on incorrect virtio api usage to
signal to the guest that a particular buffer wasn't consumed by the
host.
After fixing that, we now just discard the data the guest sends us while
a host port is disconnected or doesn't have a handler registered for
consuming data.
This commit really doesn't change anything from the current behaviour,
just makes the code slightly better by spinning off data handling to
ports in another function.
Signed-off-by: Amit Shah <address@hidden>
---
hw/virtio-serial-bus.c | 68 ++++++++++++++++++++++--------------------------
1 files changed, 31 insertions(+), 37 deletions(-)
diff --git a/hw/virtio-serial-bus.c b/hw/virtio-serial-bus.c
index 7ac46f5..757de7c 100644
--- a/hw/virtio-serial-bus.c
+++ b/hw/virtio-serial-bus.c
@@ -111,6 +111,29 @@ static size_t write_to_port(VirtIOSerialPort *port,
return offset;
}
+static void flush_queued_data(VirtIOSerialPort *port, bool discard)
+{
+ VirtQueue *vq;
+ VirtQueueElement elem;
+
+ vq = port->ovq;
+ while (virtqueue_pop(vq, &elem)) {
+ uint8_t *buf;
+ size_t ret, buf_size;
+
+ if (!discard) {
+ buf_size = iov_size(elem.out_sg, elem.out_num);
+ buf = qemu_malloc(buf_size);
+ ret = iov_to_buf(elem.out_sg, elem.out_num, buf, 0, buf_size);
+
+ port->info->have_data(port, buf, ret);
+ qemu_free(buf);
+ }
+ virtqueue_push(vq, &elem, 0);
+ }
+ virtio_notify(&port->vser->vdev, vq);
+}
+
static size_t send_control_msg(VirtIOSerialPort *port, void *buf, size_t len)
{
VirtQueueElement elem;
@@ -348,47 +371,18 @@ static void control_out(VirtIODevice *vdev, VirtQueue *vq)
static void handle_output(VirtIODevice *vdev, VirtQueue *vq)
{
VirtIOSerial *vser;
- VirtQueueElement elem;
+ VirtIOSerialPort *port;
+ bool discard;
vser = DO_UPCAST(VirtIOSerial, vdev, vdev);
+ port = find_port_by_vq(vser, vq);
- while (virtqueue_pop(vq, &elem)) {
- VirtIOSerialPort *port;
- uint8_t *buf;
- size_t ret, buf_size;
-
- port = find_port_by_vq(vser, vq);
- if (!port) {
- ret = 0;
- goto next_buf;
- }
-
- if (!port->host_connected) {
- ret = 0;
- goto next_buf;
- }
-
- /*
- * A port may not have any handler registered for consuming the
- * data that the guest sends or it may not have a chardev associated
- * with it. Just ignore the data in that case.
- */
- if (!port->info->have_data) {
- ret = 0;
- goto next_buf;
- }
-
- buf_size = iov_size(elem.out_sg, elem.out_num);
- buf = qemu_malloc(buf_size);
- ret = iov_to_buf(elem.out_sg, elem.out_num, buf, 0, buf_size);
-
- port->info->have_data(port, buf, ret);
- qemu_free(buf);
-
- next_buf:
- virtqueue_push(vq, &elem, 0);
+ discard = false;
+ if (!port || !port->host_connected || !port->info->have_data) {
+ discard = true;
}
- virtio_notify(vdev, vq);
+
+ flush_queued_data(port, discard);
}
static void handle_input(VirtIODevice *vdev, VirtQueue *vq)
--
1.6.2.5
- [Qemu-devel] [PATCH 06/17] virtio-serial: whitespace: match surrounding code, (continued)
- [Qemu-devel] [PATCH 06/17] virtio-serial: whitespace: match surrounding code, Amit Shah, 2010/03/31
- [Qemu-devel] [PATCH 07/17] virtio-serial: Remove redundant check for 0-sized write request, Amit Shah, 2010/03/31
- [Qemu-devel] [PATCH 08/17] virtio-serial: Update copyright year to 2010, Amit Shah, 2010/03/31
- [Qemu-devel] [PATCH 09/17] virtio-serial: Propagate errors in initialising ports / devices in guest, Amit Shah, 2010/03/31
- [Qemu-devel] [PATCH 10/17] virtio-serial: Send out guest data to ports only if port is opened, Amit Shah, 2010/03/31
- [Qemu-devel] [PATCH 11/17] iov: Introduce a new file for helpers around iovs, add iov_from_buf(), Amit Shah, 2010/03/31
- [Qemu-devel] [PATCH 12/17] iov: Add iov_to_buf and iov_size helpers, Amit Shah, 2010/03/31
- [Qemu-devel] [PATCH 13/17] virtio-serial: Handle scatter-gather buffers for control messages, Amit Shah, 2010/03/31
- [Qemu-devel] [PATCH 14/17] virtio-serial: Handle scatter/gather input from the guest, Amit Shah, 2010/03/31
- [Qemu-devel] [PATCH 15/17] virtio-serial: Apps should consume all data that guest sends out / Fix virtio api abuse, Amit Shah, 2010/03/31
- [Qemu-devel] [PATCH 16/17] virtio-serial: Discard data that guest sends us when ports aren't connected,
Amit Shah <=
- [Qemu-devel] [PATCH 17/17] virtio-serial: Implement flow control for individual ports, Amit Shah, 2010/03/31
- [Qemu-devel] Re: [PATCH 16/17] virtio-serial: Discard data that guest sends us when ports aren't connected, Juan Quintela, 2010/03/31
- Re: [Qemu-devel] [PATCH 15/17] virtio-serial: Apps should consume all data that guest sends out / Fix virtio api abuse, Gerd Hoffmann, 2010/03/31
- Re: [Qemu-devel] [PATCH 15/17] virtio-serial: Apps should consume all data that guest sends out / Fix virtio api abuse, Amit Shah, 2010/03/31
[Qemu-devel] Re: [PATCH 00/17] v4: virtio-serial fixes, new abi for port discovery, Juan Quintela, 2010/03/31