dcavalca / rpms / qemu

Forked from rpms/qemu a year ago
Clone

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

5544c1
From 542fa14530022044ab577c543fba83202d52b703 Mon Sep 17 00:00:00 2001
Justin M. Forbes d4cdad
From: Amit Shah <amit.shah@redhat.com>
Justin M. Forbes d4cdad
Date: Mon, 21 Mar 2011 22:05:10 +0100
5544c1
Subject: [PATCH] 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
5544c1
index 9f8608a..bfc94a5 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
 }
5544c1
@@ -2244,6 +2247,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
-- 
5544c1
1.7.12.1
Justin M. Forbes d4cdad