Virtio-serial API: Difference between revisions
From KVM
No edit summary |
No edit summary |
||
Line 39: | Line 39: | ||
);</code> | );</code> | ||
* A pointer to an OVERLAPPED structure is required if the hFile parameter was opened with FILE_FLAG_OVERLAPPED, otherwise it can be NULL. | * A pointer to an OVERLAPPED structure is required if the hFile parameter was opened with FILE_FLAG_OVERLAPPED, otherwise it can be NULL. | ||
|- | |- | ||
|Writing | |Writing | ||
Line 46: | Line 45: | ||
* If host is not connected, write blocks or returns <code>-EAGAIN</code>. | * If host is not connected, write blocks or returns <code>-EAGAIN</code>. | ||
* Errno will contain <code>-ENODEV</code> if port or device got hot-unplugged. | * Errno will contain <code>-ENODEV</code> if port or device got hot-unplugged. | ||
| | |<code>BOOL WINAPI WriteFile( | ||
__in HANDLE hFile, | |||
__in LPCVOID lpBuffer, | |||
__in DWORD nNumberOfBytesToWrite, | |||
__out_opt LPDWORD lpNumberOfBytesWritten, | |||
__inout_opt LPOVERLAPPED lpOverlapped | |||
);</code> | |||
* A pointer to an OVERLAPPED structure is required if the hFile parameter was opened with FILE_FLAG_OVERLAPPED, otherwise this parameter can be NULL. | |||
|- | |- | ||
|Poll | |Poll |
Revision as of 11:01, 4 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)
|
HANDLE WINAPI CreateFile(
|
Reading | read(2)
|
BOOL WINAPI ReadFile(
|
Writing | write(2)
|
BOOL WINAPI WriteFile(
|
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
Caveats
- Live Migration
- When a VM uses the qemu chardev interface to talk to guest virtio-serial ports, the chardev file will be closed on the source (and may be opened on the destination). Host applications have to be aware of such migration and either collaborate with libvirt or have their own mechanism to re-connect to the destination host and continue the communication.
- A future version of qemu may introduce 'migration notifiers' that may help chardevs let apps know of migration start / stop.
- qemu chardevs
- qemu's chardevs are notoriously out of date from the state-of-the-art and need a complete rewrite to be pleasurable to use.
- However respecting the return values from the various read/write calls to chardevs will help in ensuring data is never lost. The various backends (unix, tcp sockets, file, etc.) do work well when used with care.