dcavalca / rpms / qemu

Forked from rpms/qemu a year ago
Clone

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

Hans de Goede 329b58
From 52aef47122bcbdd556f9fd3510a2047b8f920064 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
Hans de Goede 329b58
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>
Justin M. Forbes d4cdad
---
Justin M. Forbes d4cdad
 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
Hans de Goede 329b58
index ed306e5..c263328 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
 }
Hans de Goede 329b58
@@ -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
-- 
Hans de Goede 329b58
1.7.10.4
Justin M. Forbes d4cdad