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?
You have a character device on the guest because Unix and Unix-like operating systems represent serial ports as character 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. The port is created by a kernel device driver, so it must be a character device special.
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.