dcavalca / rpms / qemu

Forked from rpms/qemu a year ago
Clone

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

Justin M. Forbes d4cdad
From e5eb5b185d39942a2011b21114bb7f0b8e11427a 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
Justin M. Forbes d4cdad
Subject: [PATCH 112/118] 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 ++++++++++++++
Justin M. Forbes d4cdad
 1 files changed, 14 insertions(+), 0 deletions(-)
Justin M. Forbes d4cdad
Justin M. Forbes d4cdad
diff --git a/qemu-char.c b/qemu-char.c
Justin M. Forbes d4cdad
index f98b240..5f67652 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
 }
Justin M. Forbes d4cdad
@@ -2266,6 +2269,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
-- 
Justin M. Forbes d4cdad
1.7.7.5
Justin M. Forbes d4cdad