a7b9285
From 563ef1912e4b0c0b5728bc53d2b225d2ff3cd9ef Mon Sep 17 00:00:00 2001
96a5f8d
From: Amit Shah <amit.shah@redhat.com>
96a5f8d
Date: Mon, 21 Mar 2011 22:06:41 +0100
96a5f8d
Subject: [PATCH] virtio-console: Enable port throttling when chardev is slow
96a5f8d
 to consume data
96a5f8d
96a5f8d
When a chardev indicates it can't accept more data, we tell the
96a5f8d
virtio-serial code to stop sending us any more data till we tell
96a5f8d
otherwise.  This helps in guests continuing to run normally while the vq
96a5f8d
keeps getting full and eventually the guest stops queueing more data.
96a5f8d
As soon as the chardev indicates it can accept more data, start pushing!
96a5f8d
96a5f8d
Signed-off-by: Amit Shah <amit.shah@redhat.com>
96a5f8d
Signed-off-by: Cole Robinson <crobinso@redhat.com>
96a5f8d
---
96a5f8d
 hw/virtio-console.c | 11 +++++++++++
96a5f8d
 1 file changed, 11 insertions(+)
96a5f8d
96a5f8d
diff --git a/hw/virtio-console.c b/hw/virtio-console.c
96a5f8d
index dd6f614..0e12514 100644
96a5f8d
--- a/hw/virtio-console.c
96a5f8d
+++ b/hw/virtio-console.c
96a5f8d
@@ -20,6 +20,16 @@ typedef struct VirtConsole {
96a5f8d
     CharDriverState *chr;
96a5f8d
 } VirtConsole;
96a5f8d
 
96a5f8d
+/*
96a5f8d
+ * Callback function that's called from chardevs when backend becomes
96a5f8d
+ * writable.
96a5f8d
+ */
96a5f8d
+static void chr_write_unblocked(void *opaque)
96a5f8d
+{
96a5f8d
+    VirtConsole *vcon = opaque;
96a5f8d
+
96a5f8d
+    virtio_serial_throttle_port(&vcon->port, false);
96a5f8d
+}
96a5f8d
 
96a5f8d
 /* Callback function that's called when the guest sends us data */
96a5f8d
 static ssize_t flush_buf(VirtIOSerialPort *port, const uint8_t *buf, size_t len)
96a5f8d
@@ -110,6 +120,7 @@ static const QemuChrHandlers chr_handlers = {
96a5f8d
     .fd_can_read = chr_can_read,
96a5f8d
     .fd_read = chr_read,
96a5f8d
     .fd_event = chr_event,
96a5f8d
+    .fd_write_unblocked = chr_write_unblocked,
96a5f8d
 };
96a5f8d
 
96a5f8d
 static int virtconsole_initfn(VirtIOSerialPort *port)