[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 05/23] qemu-char: socket backend: disconnect on write
From: |
Paolo Bonzini |
Subject: |
[Qemu-devel] [PULL 05/23] qemu-char: socket backend: disconnect on write error |
Date: |
Thu, 16 Feb 2017 15:31:29 +0100 |
From: Anton Nefedov <address@hidden>
Socket backend read handler should normally perform a disconnect, however
the read handler may not get a chance to run if the frontend is not ready
(qemu_chr_be_can_write() == 0).
This means that in virtio-serial frontend case if
- the host has disconnected (giving EPIPE on socket write)
- and the guest has disconnected (-> frontend not ready -> backend
will not read)
- and there is still data (frontend->backend) to flush (has to be a really
tricky timing but nevertheless, we have observed the case in production)
This results in virtio-serial trying to flush this data continiously forming
a busy loop.
Solution: react on write error in the socket write handler.
errno is not reliable after qio_channel_writev_full(), so we may not get
the exact EPIPE, so disconnect on any error but QIO_CHANNEL_ERR_BLOCK which
io_channel_send_full() converts to errno EAGAIN.
We must not disconnect right away though, there still may be data to read
(see 4bf1cb0).
Signed-off-by: Anton Nefedov <address@hidden>
Signed-off-by: Denis V. Lunev <address@hidden>
CC: Paolo Bonzini <address@hidden>
CC: Daniel P. Berrange <address@hidden>
CC: Marc-André Lureau <address@hidden>
Message-Id: <address@hidden>
Signed-off-by: Paolo Bonzini <address@hidden>
---
chardev/char-socket.c | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/chardev/char-socket.c b/chardev/char-socket.c
index 4068dc5..865c527 100644
--- a/chardev/char-socket.c
+++ b/chardev/char-socket.c
@@ -97,6 +97,9 @@ static gboolean tcp_chr_accept(QIOChannel *chan,
GIOCondition cond,
void *opaque);
+static int tcp_chr_read_poll(void *opaque);
+static void tcp_chr_disconnect(Chardev *chr);
+
/* Called with chr_write_lock held. */
static int tcp_chr_write(Chardev *chr, const uint8_t *buf, int len)
{
@@ -114,6 +117,13 @@ static int tcp_chr_write(Chardev *chr, const uint8_t *buf,
int len)
s->write_msgfds_num = 0;
}
+ if (ret < 0 && errno != EAGAIN) {
+ if (tcp_chr_read_poll(chr) <= 0) {
+ tcp_chr_disconnect(chr);
+ return len;
+ } /* else let the read handler finish it properly */
+ }
+
return ret;
} else {
/* XXX: indicate an error ? */
--
1.8.3.1
- [Qemu-devel] [PULL 00/23] Misc patches for 2017-02-16, Paolo Bonzini, 2017/02/16
- [Qemu-devel] [PULL 01/23] kvm/ioapic: dump real object instead of a fake one, Paolo Bonzini, 2017/02/16
- [Qemu-devel] [PULL 02/23] ioapic: fix error report value of def version, Paolo Bonzini, 2017/02/16
- [Qemu-devel] [PULL 03/23] kvm/ioapic: correct kvm ioapic version, Paolo Bonzini, 2017/02/16
- [Qemu-devel] [PULL 04/23] test-vmstate: remove yield_until_fd_readable, Paolo Bonzini, 2017/02/16
- [Qemu-devel] [PULL 05/23] qemu-char: socket backend: disconnect on write error,
Paolo Bonzini <=
- [Qemu-devel] [PULL 06/23] apic: reset apic_delivered global variable on machine reset, Paolo Bonzini, 2017/02/16
- [Qemu-devel] [PULL 07/23] char: drop data written to a disconnected pty, Paolo Bonzini, 2017/02/16
- [Qemu-devel] [PULL 09/23] gdbstub: Fix vCont behaviour, Paolo Bonzini, 2017/02/16
- [Qemu-devel] [PULL 08/23] move vm_start to cpus.c, Paolo Bonzini, 2017/02/16
- [Qemu-devel] [PULL 10/23] hw/char/mcf_uart: QOMify the ColdFire UART, Paolo Bonzini, 2017/02/16
- [Qemu-devel] [PULL 11/23] cpu-exec: fix icount out-of-bounds access, Paolo Bonzini, 2017/02/16
- [Qemu-devel] [PULL 13/23] cpu-exec: avoid cpu_loop_exit in cpu_handle_interrupt, Paolo Bonzini, 2017/02/16
- [Qemu-devel] [PULL 12/23] cpu-exec: tighten barrier on TCG_EXIT_REQUESTED, Paolo Bonzini, 2017/02/16
- [Qemu-devel] [PULL 14/23] cpu-exec: avoid repeated sigsetjmp on interrupts, Paolo Bonzini, 2017/02/16
- [Qemu-devel] [PULL 16/23] qemu-doc: Clarify that -vga std is now the default, Paolo Bonzini, 2017/02/16