From b73ba2e4a4fa35025dd55d09c343b55123060b92 Mon Sep 17 00:00:00 2001
Message-Id: <b73ba2e4a4fa35025dd55d09c343b55123060b92.1368111914.git.minovotn@redhat.com>
In-Reply-To: <405603258af5154387bea676be1f904b6713f6ae.1368111913.git.minovotn@redhat.com>
References: <405603258af5154387bea676be1f904b6713f6ae.1368111913.git.minovotn@redhat.com>
From: Amit Shah <amit.shah@redhat.com>
Date: Wed, 24 Apr 2013 08:18:16 +0200
Subject: [PATCH 42/65] virtio: console: add flow control

RH-Author: Amit Shah <amit.shah@redhat.com>
Message-id: <d1cf5d9729cdf8c19e8a7ec6efbd4dcb2ead0007.1366724981.git.amit.shah@redhat.com>
Patchwork-id: 50820
O-Subject: [RHEL6.5 qemu-kvm PATCH 42/65] virtio: console: add flow control
Bugzilla: 909059
RH-Acked-by: Hans de Goede <hdegoede@redhat.com>
RH-Acked-by: Gerd Hoffmann <kraxel@redhat.com>
RH-Acked-by: Paolo Bonzini <pbonzini@redhat.com>

The virtio-serial-bus already has the logic to make flow control work
properly.  Hook into the char layer's new ability to signal a backend is
writable again.

Signed-off-by: Amit Shah <amit.shah@redhat.com>
Message-id: abffa02235d55ca6e2489068c58971c8897e976c.1362505276.git.amit.shah@redhat.com
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
(cherry picked from commit 7df4d4578f70b565870f353ba0b72f2f23781a09)

Signed-off-by: Amit Shah <amit.shah@redhat.com>

Conflicts:
	hw/virtio-console.c

RHEL: Switch to newer (upstream) flow control routines
---
 hw/virtio-console.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)

Signed-off-by: Michal Novotny <minovotn@redhat.com>
---
 hw/virtio-console.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/hw/virtio-console.c b/hw/virtio-console.c
index cc758ec..7cc4b69 100644
--- a/hw/virtio-console.c
+++ b/hw/virtio-console.c
@@ -19,6 +19,18 @@ typedef struct VirtConsole {
     CharDriverState *chr;
 } VirtConsole;
 
+/*
+ * Callback function that's called from chardevs when backend becomes
+ * writable.
+ */
+static gboolean chr_write_unblocked(GIOChannel *chan, GIOCondition cond,
+                                    void *opaque)
+{
+    VirtConsole *vcon = opaque;
+
+    virtio_serial_throttle_port(&vcon->port, false);
+    return FALSE;
+}
 
 /* Callback function that's called when the guest sends us data */
 static ssize_t flush_buf(VirtIOSerialPort *port, const uint8_t *buf, size_t len)
@@ -44,6 +56,7 @@ static ssize_t flush_buf(VirtIOSerialPort *port, const uint8_t *buf, size_t len)
          * do_flush_queued_data().
          */
         ret = 0;
+        qemu_chr_fe_add_watch(vcon->chr, G_IO_OUT, chr_write_unblocked, vcon);
     }
     return ret;
 }
-- 
1.7.11.7

