dcavalca / rpms / qemu

Forked from rpms/qemu a year ago
Clone

Blame 0107-char-Throttle-when-host-connection-is-down.patch

bd56df
From 33883808e5203f398ceac6eaf0b6647326df9c1f Mon Sep 17 00:00:00 2001
bd56df
Message-Id: <33883808e5203f398ceac6eaf0b6647326df9c1f.1346162949.git.crobinso@redhat.com>
bd56df
In-Reply-To: <90a59d545ad6759c105b0bfcfca70f574482584f.1346162949.git.crobinso@redhat.com>
bd56df
References: <90a59d545ad6759c105b0bfcfca70f574482584f.1346162949.git.crobinso@redhat.com>
Justin M. Forbes d4cdad
From: Amit Shah <amit.shah@redhat.com>
Justin M. Forbes d4cdad
Date: Mon, 21 Mar 2011 22:05:10 +0100
bd56df
Subject: [PATCH 107/114] char: Throttle when host connection is down#
Justin M. Forbes d4cdad
Justin M. Forbes d4cdad
When the host-side connection goes down, throttle the virtio-serial bus
Justin M. Forbes d4cdad
and later unthrottle when a connection gets established.  This helps
Justin M. Forbes d4cdad
prevent any lost IO (guest->host) while the host connection was down.
Justin M. Forbes d4cdad
Justin M. Forbes d4cdad
Bugzilla: 621484
Justin M. Forbes d4cdad
Justin M. Forbes d4cdad
This commit actually helps the bug mentioned above as no writes will now
Justin M. Forbes d4cdad
get lost because of the throttling done here.  With just the patches
Justin M. Forbes d4cdad
sent earlier for that bug, one write will end up getting lost in the
Justin M. Forbes d4cdad
worst case (host d/c, guest write, host connect).
Justin M. Forbes d4cdad
Justin M. Forbes d4cdad
Signed-off-by: Amit Shah <amit.shah@redhat.com>
bd56df
Signed-off-by: Cole Robinson <crobinso@redhat.com>
Justin M. Forbes d4cdad
---
b6dd5a
 qemu-char.c | 14 ++++++++++++++
Hans de Goede 329b58
 1 file changed, 14 insertions(+)
Justin M. Forbes d4cdad
Justin M. Forbes d4cdad
diff --git a/qemu-char.c b/qemu-char.c
bd56df
index 5e136fd..d86ee88 100644
Justin M. Forbes d4cdad
--- a/qemu-char.c
Justin M. Forbes d4cdad
+++ b/qemu-char.c
Justin M. Forbes d4cdad
@@ -140,6 +140,9 @@ static void qemu_chr_generic_open_bh(void *opaque)
Justin M. Forbes d4cdad
 {
Justin M. Forbes d4cdad
     CharDriverState *s = opaque;
Justin M. Forbes d4cdad
     qemu_chr_be_event(s, CHR_EVENT_OPENED);
Justin M. Forbes d4cdad
+    if (s->write_blocked) {
Justin M. Forbes d4cdad
+        char_write_unblocked(s);
Justin M. Forbes d4cdad
+    }
Justin M. Forbes d4cdad
     qemu_bh_delete(s->bh);
Justin M. Forbes d4cdad
     s->bh = NULL;
Justin M. Forbes d4cdad
 }
bd56df
@@ -2246,6 +2249,17 @@ static int tcp_chr_write(CharDriverState *chr, const uint8_t *buf, int len)
Justin M. Forbes d4cdad
         ret = send_all(chr, s->fd, buf, len);
Justin M. Forbes d4cdad
         if (ret == -1 && errno == EPIPE) {
Justin M. Forbes d4cdad
             tcp_closed(chr);
Justin M. Forbes d4cdad
+
Justin M. Forbes d4cdad
+            if (chr->chr_enable_write_fd_handler && chr->chr_write_unblocked) {
Justin M. Forbes d4cdad
+                /*
Justin M. Forbes d4cdad
+                 * Since we haven't written out anything, let's say
Justin M. Forbes d4cdad
+                 * we're throttled.  This will prevent any output from
Justin M. Forbes d4cdad
+                 * the guest getting lost if host-side chardev goes
Justin M. Forbes d4cdad
+                 * down.  Unthrottle when we re-connect.
Justin M. Forbes d4cdad
+                 */
Justin M. Forbes d4cdad
+                chr->write_blocked = true;
Justin M. Forbes d4cdad
+                return 0;
Justin M. Forbes d4cdad
+            }
Justin M. Forbes d4cdad
         }
Justin M. Forbes d4cdad
         return ret;
Justin M. Forbes d4cdad
     } else {
Justin M. Forbes d4cdad
-- 
b6dd5a
1.7.11.2
Justin M. Forbes d4cdad