Why is there a socket interface on the host and a character device interface on the guest for virtio-serial?

jobin asked:

I am trying to establish a communication channel between the host and one of its guest virtual machine using kvm as a hypervisor. For this, I am using virtio-serial.

To create the virtual machine, I issued the following command:

qemu-system-x86_64 \
-m 2048 -name ubuntu \
-hda ubuntu_image \
-device virtio-serial \
-chardev socket,path=/tmp/foo,server,nowait,id=foo \
-device virtconsole,name=jobsfoo,chardev=foo,name=org.ubuntu.foo \

And then for communicating, on the guest, I use:

socat /dev/hvc0 -

And on the host:

socat /tmp/foo -

I come to understand that /tmp/foo is a socket and /dev/hvc0 a character device.

Why is there an symmetric interface for communication: a socket on the host and a character device on the guest?

My answer:

You have a character device on the guest because Unix and Unix-like operating systems represent serial ports as guest devices, and have done so for about as long as Unix has been around, and you explicitly asked for a virtual serial port in the guest.

You have a socket on the host because you explicitly asked for one. Presumably you want two-way communication from some program on the host to some program on the guest which understands serial ports. The other end of this socket is handled, of course, by the qemu process running the virtual machine. You could also have connected this to a pty to emulate a serial console, or to a plain file to just log everything coming out of the port.

View the full question and any other answers on Server Fault.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.