render / rpms / qemu

Forked from rpms/qemu 10 months ago
Clone

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

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