Virtio-serial API: Difference between revisions
From KVM
(Add note on using poll inside signal handler) |
No edit summary |
||
Line 40: | Line 40: | ||
* From kernel 2.6.37, <code>SIGIO</code> will be sent to guest apps that set <code>O_ASYNC</code> flag on the fd using <code>fcntl(2)</code>. | * From kernel 2.6.37, <code>SIGIO</code> will be sent to guest apps that set <code>O_ASYNC</code> flag on the fd using <code>fcntl(2)</code>. | ||
* <code>SIGIO</code> will be sent on host connection up, down and port unplug events. | * <code>SIGIO</code> will be sent on host connection up, down and port unplug events. | ||
* Use poll() within signal handler to identify which port(s) changed state and how. | * Use <code>poll()</code> within signal handler to identify which port(s) changed state and how. | ||
| | | | ||
|- | |- |
Revision as of 06:29, 2 September 2010
Guest API
Function | Linux guest | Windows guest |
---|---|---|
Port discovery | symlinks from /dev/virtio-port/<portname> to /dev/vportNpn as mentioned in Invocation and How To Test
|
|
Opening port | open(2)
|
|
Reading | read(2)
|
|
Writing | write(2)
|
|
Poll | poll()
| |
Asynchronous notifications | signal(7)
|
For an example of a C program that uses the virtio-serial Linux guest API, see auto-virtserial-guest.c
Host API
There's an in-qemu host API exposed by the virtio-serial code. The following is true for the in-qemu API for qemu version 0.13 and for the qemu version found in Red Hat Enterprise Linux 6.0, straight from hw/virtio-serial.h:
|
In addition to this, the VirtIOSerialPortInfo struct has a function pointer for a callback to be called when guest writes some data to the port:
|
For an example use of this API, see hw/virtio-console.c