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