From 19366458f855f97fe112ba27f90a88388b8dfaba Mon Sep 17 00:00:00 2001 From: Vijay Dhanraj Date: Tue, 28 May 2019 17:48:08 -0700 Subject: [PATCH] DM: handle virtio-console writes when no socket backend is connected When virtio-console is used as console port with socket backend, guest kernel tries to hook it up with hvc console and sets it up. It doesn't check if a client is connected and can result in ENOTCONN with virtio-console backend being reset. This will prevent client connection at a later point. To avoid this, ignore ENOTCONN error. PS: For Kata, the runtime first launches VM and then proxy which acts as a client connects to this socket. If this error is not handled, proxy will never be able to connect as the backend itself will be reset. Tracked-On: #3189 Signed-off-by: Vijay Dhanraj Acked-by: Yu Wang --- devicemodel/hw/pci/virtio/virtio_console.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/devicemodel/hw/pci/virtio/virtio_console.c b/devicemodel/hw/pci/virtio/virtio_console.c index 36f141f33..4c8a6385f 100644 --- a/devicemodel/hw/pci/virtio/virtio_console.c +++ b/devicemodel/hw/pci/virtio/virtio_console.c @@ -499,11 +499,22 @@ virtio_console_backend_write(struct virtio_console_port *port, void *arg, ret = writev(be->fd, iov, niov); if (ret <= 0) { - /* backend cannot receive more data. For example when pts is + /* Case 1:backend cannot receive more data. For example when pts is * not connected to any client, its tty buffer will become full. * In this case we just drop data from guest hvc console. + * + * Case 2: Backend connection not yet setup. For example, when + * virtio-console is used as console port with socket backend, guest + * kernel tries to hook it up with hvc console and sets it up. It + * doesn't check if a client is connected and can result in ENOTCONN + * with virtio-console backend being reset. This will prevent + * client connection at a later point. To avoid this, ignore + * ENOTCONN error. + * + * PS: For Kata, the runtime first launches VM and then proxy which + * acts as a client connects to this socket. */ - if (ret == -1 && errno == EAGAIN) + if (ret == -1 && (errno == EAGAIN || errno == ENOTCONN)) return; virtio_console_reset_backend(be);