dcavalca / rpms / qemu

Forked from rpms/qemu a year ago
Clone

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

3f1f29
From 00cf9482be18cdacda0ae9b207b84a7e86ca1d11 Mon Sep 17 00:00:00 2001
3f1f29
From: Amit Shah <amit.shah@redhat.com>
3f1f29
Date: Mon, 21 Mar 2011 22:05:10 +0100
3f1f29
Subject: [PATCH 31/35] char: Throttle when host connection is down#
3f1f29
3f1f29
When the host-side connection goes down, throttle the virtio-serial bus
3f1f29
and later unthrottle when a connection gets established.  This helps
3f1f29
prevent any lost IO (guest->host) while the host connection was down.
3f1f29
3f1f29
Bugzilla: 621484
3f1f29
3f1f29
This commit actually helps the bug mentioned above as no writes will now
3f1f29
get lost because of the throttling done here.  With just the patches
3f1f29
sent earlier for that bug, one write will end up getting lost in the
3f1f29
worst case (host d/c, guest write, host connect).
3f1f29
3f1f29
Signed-off-by: Amit Shah <amit.shah@redhat.com>
3f1f29
---
3f1f29
 qemu-char.c |   14 ++++++++++++++
3f1f29
 1 files changed, 14 insertions(+), 0 deletions(-)
3f1f29
3f1f29
diff --git a/qemu-char.c b/qemu-char.c
3f1f29
index e9d7f0a..77ab1ed 100644
3f1f29
--- a/qemu-char.c
3f1f29
+++ b/qemu-char.c
3f1f29
@@ -140,6 +140,9 @@ static void qemu_chr_generic_open_bh(void *opaque)
3f1f29
 {
3f1f29
     CharDriverState *s = opaque;
3f1f29
     qemu_chr_event(s, CHR_EVENT_OPENED);
3f1f29
+    if (s->write_blocked) {
3f1f29
+        char_write_unblocked(s);
3f1f29
+    }
3f1f29
     qemu_bh_delete(s->bh);
3f1f29
     s->bh = NULL;
3f1f29
 }
3f1f29
@@ -2031,6 +2034,17 @@ static int tcp_chr_write(CharDriverState *chr, const uint8_t *buf, int len)
3f1f29
         ret = send_all(chr, s->fd, buf, len);
3f1f29
         if (ret == -1 && errno == EPIPE) {
3f1f29
             tcp_closed(chr);
3f1f29
+
3f1f29
+            if (chr->chr_enable_write_fd_handler && chr->chr_write_unblocked) {
3f1f29
+                /*
3f1f29
+                 * Since we haven't written out anything, let's say
3f1f29
+                 * we're throttled.  This will prevent any output from
3f1f29
+                 * the guest getting lost if host-side chardev goes
3f1f29
+                 * down.  Unthrottle when we re-connect.
3f1f29
+                 */
3f1f29
+                chr->write_blocked = true;
3f1f29
+                return 0;
3f1f29
+            }
3f1f29
         }
3f1f29
         return ret;
3f1f29
     } else {
3f1f29
-- 
3f1f29
1.7.5.1
3f1f29