peterdelevoryas / rpms / qemu

Forked from rpms/qemu 2 years ago
Clone

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

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