yeahuh / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone
619821
From 4b71b3a9e37d06da2ecc48e06eea7e4a4ae1cfe9 Mon Sep 17 00:00:00 2001
b28c64
From: Fam Zheng <famz@redhat.com>
619821
Date: Thu, 18 May 2017 09:21:20 +0200
b28c64
Subject: [PATCH 07/18] serial: poll the serial console with G_IO_HUP
b28c64
MIME-Version: 1.0
b28c64
Content-Type: text/plain; charset=UTF-8
b28c64
Content-Transfer-Encoding: 8bit
b28c64
b28c64
RH-Author: Fam Zheng <famz@redhat.com>
619821
Message-id: <20170518092131.16571-8-famz@redhat.com>
619821
Patchwork-id: 75297
619821
O-Subject: [RHEL-7.4 qemu-kvm PATCH v3 07/18] serial: poll the serial console with G_IO_HUP
619821
Bugzilla: 1451470
b28c64
RH-Acked-by: Paolo Bonzini <pbonzini@redhat.com>
619821
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
b28c64
RH-Acked-by: Eduardo Habkost <ehabkost@redhat.com>
b28c64
b28c64
From: Roger Pau Monne <roger.pau@citrix.com>
b28c64
b28c64
On FreeBSD polling a master pty while the other end is not connected
b28c64
with G_IO_OUT only results in an endless wait. This is different from
b28c64
the Linux behaviour, that returns immediately. In order to demonstrate
b28c64
this, I have the following example code:
b28c64
b28c64
http://xenbits.xen.org/people/royger/test_poll.c
b28c64
b28c64
When executed on Linux:
b28c64
b28c64
$ ./test_poll
b28c64
In callback
b28c64
b28c64
On FreeBSD instead, the callback never gets called:
b28c64
b28c64
$ ./test_poll
b28c64
b28c64
So, in order to workaround this, poll the source with G_IO_HUP (which
b28c64
makes the code behave the same way on both Linux and FreeBSD).
b28c64
b28c64
Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
b28c64
Cc: Peter Crosthwaite <peter.crosthwaite@xilinx.com>
b28c64
Cc: Michael Tokarev <mjt@tls.msk.ru>
b28c64
Cc: "Andreas Färber" <afaerber@suse.de>
b28c64
Cc: Paolo Bonzini <pbonzini@redhat.com>
b28c64
Cc: xen-devel@lists.xenproject.org
b28c64
[Add hw/char/cadence_uart.c too. - Paolo]
b28c64
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
b28c64
b28c64
(cherry picked from commit e02bc6de30c44fd668dc0d6e1cd1804f2eed3ed3)
b28c64
Signed-off-by: Fam Zheng <famz@redhat.com>
b28c64
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
b28c64
b28c64
Conflicts:
b28c64
	hw/char/cadence_uart.c
b28c64
b28c64
Downstream doesn't use qemu_chr_fe_add_watch because we don't have
b28c64
38acd64b1c etc.
b28c64
b28c64
	monitor.c
b28c64
b28c64
The changed line is different because we don't have 6cff3e8594 (monitor:
b28c64
protect outbuf and mux_out with mutex).
b28c64
---
b28c64
 hw/char/serial.c         | 2 +-
b28c64
 hw/char/virtio-console.c | 3 ++-
b28c64
 hw/usb/redirect.c        | 2 +-
b28c64
 monitor.c                | 2 +-
b28c64
 4 files changed, 5 insertions(+), 4 deletions(-)
b28c64
b28c64
diff --git a/hw/char/serial.c b/hw/char/serial.c
b28c64
index e020b0e..add4738 100644
b28c64
--- a/hw/char/serial.c
b28c64
+++ b/hw/char/serial.c
b28c64
@@ -246,7 +246,7 @@ static gboolean serial_xmit(GIOChannel *chan, GIOCondition cond, void *opaque)
b28c64
         serial_receive1(s, &s->tsr, 1);
b28c64
     } else if (qemu_chr_fe_write(s->chr, &s->tsr, 1) != 1) {
b28c64
         if (s->tsr_retry >= 0 && s->tsr_retry < MAX_XMIT_RETRY &&
b28c64
-            qemu_chr_fe_add_watch(s->chr, G_IO_OUT, serial_xmit, s) > 0) {
b28c64
+            qemu_chr_fe_add_watch(s->chr, G_IO_OUT|G_IO_HUP, serial_xmit, s) > 0) {
b28c64
             s->tsr_retry++;
b28c64
             return FALSE;
b28c64
         }
b28c64
diff --git a/hw/char/virtio-console.c b/hw/char/virtio-console.c
b28c64
index 1b01dcd..69dd95a 100644
b28c64
--- a/hw/char/virtio-console.c
b28c64
+++ b/hw/char/virtio-console.c
b28c64
@@ -66,7 +66,8 @@ static ssize_t flush_buf(VirtIOSerialPort *port,
b28c64
         if (!k->is_console) {
b28c64
             virtio_serial_throttle_port(port, true);
b28c64
             if (!vcon->watch) {
b28c64
-                vcon->watch = qemu_chr_fe_add_watch(vcon->chr, G_IO_OUT,
b28c64
+                vcon->watch = qemu_chr_fe_add_watch(vcon->chr,
b28c64
+                                                    G_IO_OUT|G_IO_HUP,
b28c64
                                                     chr_write_unblocked, vcon);
b28c64
             }
b28c64
         }
b28c64
diff --git a/hw/usb/redirect.c b/hw/usb/redirect.c
b28c64
index e3b9f32..3fe2106 100644
b28c64
--- a/hw/usb/redirect.c
b28c64
+++ b/hw/usb/redirect.c
b28c64
@@ -284,7 +284,7 @@ static int usbredir_write(void *priv, uint8_t *data, int count)
b28c64
     r = qemu_chr_fe_write(dev->cs, data, count);
b28c64
     if (r < count) {
b28c64
         if (!dev->watch) {
b28c64
-            dev->watch = qemu_chr_fe_add_watch(dev->cs, G_IO_OUT,
b28c64
+            dev->watch = qemu_chr_fe_add_watch(dev->cs, G_IO_OUT|G_IO_HUP,
b28c64
                                                usbredir_write_unblocked, dev);
b28c64
         }
b28c64
         if (r < 0) {
b28c64
diff --git a/monitor.c b/monitor.c
b28c64
index 1b28ff3..393a508 100644
b28c64
--- a/monitor.c
b28c64
+++ b/monitor.c
b28c64
@@ -300,7 +300,7 @@ void monitor_flush(Monitor *mon)
b28c64
             mon->outbuf = tmp;
b28c64
         }
b28c64
         if (mon->watch == 0) {
b28c64
-            mon->watch = qemu_chr_fe_add_watch(mon->chr, G_IO_OUT,
b28c64
+            mon->watch = qemu_chr_fe_add_watch(mon->chr, G_IO_OUT|G_IO_HUP,
b28c64
                                                monitor_unblocked, mon);
b28c64
         }
b28c64
     }
b28c64
-- 
b28c64
1.8.3.1
b28c64