Skip to content

Commit 1936645

Browse files
vijaydhanrajwenlingz
authored andcommitted
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 <vijay.dhanraj@intel.com> Acked-by: Yu Wang <yu1.wang@intel.com>
1 parent 376fcdd commit 1936645

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

devicemodel/hw/pci/virtio/virtio_console.c

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -499,11 +499,22 @@ virtio_console_backend_write(struct virtio_console_port *port, void *arg,
499499

500500
ret = writev(be->fd, iov, niov);
501501
if (ret <= 0) {
502-
/* backend cannot receive more data. For example when pts is
502+
/* Case 1:backend cannot receive more data. For example when pts is
503503
* not connected to any client, its tty buffer will become full.
504504
* In this case we just drop data from guest hvc console.
505+
*
506+
* Case 2: Backend connection not yet setup. For example, when
507+
* virtio-console is used as console port with socket backend, guest
508+
* kernel tries to hook it up with hvc console and sets it up. It
509+
* doesn't check if a client is connected and can result in ENOTCONN
510+
* with virtio-console backend being reset. This will prevent
511+
* client connection at a later point. To avoid this, ignore
512+
* ENOTCONN error.
513+
*
514+
* PS: For Kata, the runtime first launches VM and then proxy which
515+
* acts as a client connects to this socket.
505516
*/
506-
if (ret == -1 && errno == EAGAIN)
517+
if (ret == -1 && (errno == EAGAIN || errno == ENOTCONN))
507518
return;
508519

509520
virtio_console_reset_backend(be);

0 commit comments

Comments
 (0)