1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
|
# vhost-device-console - Console emulation backend daemon
## Description
This program is a vhost-user backend that emulates a VirtIO Console device.
The device's binary takes as parameters a socket path, a socket number which
is the number of connections, commonly used across all vhost-devices to
communicate with the vhost-user frontend devices, and the backend type
"nested" or "network".
The "nested" backend allows input/output to the guest console through the
current terminal.
The "network" backend creates a local TCP port (specified on vhost-device-console
arguments) and allows input/output to the guest console via that socket.
This program is tested with QEMU's `vhost-user-device-pci` device.
Examples' section below.
## Staging Device
This device will be in `staging` until we complete the following steps:
- [ ] Increase test coverage
- [ ] Support VIRTIO_CONSOLE_F_SIZE feature (optional)
- [ ] Support VIRTIO_CONSOLE_F_EMERG_WRITE feature (optional)
## Synopsis
```text
vhost-device-console --socket-path=<SOCKET_PATH>
```
## Options
.. program:: vhost-device-console
.. option:: -h, --help
Print help.
.. option:: -s, --socket-path=PATH
Location of vhost-user Unix domain sockets, this path will be suffixed with
0,1,2..socket_count-1.
.. option:: -p, --tcp-port=PORT_NUMBER
The localhost's port to be used for each guest, this part will be increased with
0,1,2..socket_count-1.
-- option:: -b, --backend=nested|network
The backend type vhost-device-console to be used. The current implementation
supports two types of backends: "nested", "network" (described above).
Note: The nested backend is selected by default and can be used only when
socket_count equals 1.
## Limitations
This device is still work-in-progress (WIP). The current version has been tested
with VIRTIO_CONSOLE_F_MULTIPORT, but only for one console (`max_nr_ports = 1`).
Also it does not yet support the VIRTIO_CONSOLE_F_EMERG_WRITE and
VIRTIO_CONSOLE_F_SIZE features.
## Features
The current device gives access to multiple QEMU guest by providing a login prompt
either by connecting to a localhost server port (network backend) or by creating an
nested command prompt in the current terminal (nested backend). This prompt appears
as soon as the guest is fully booted and gives the ability to user run command as a
in regular terminal.
## Examples
### Dependencies
For testing the device the required dependencies are:
- Linux:
- Set `CONFIG_VIRTIO_CONSOLE=y`
- QEMU (optional):
- A new vhost-user-console device has been implemented in the following repo:
- https://github.com/virtualopensystems/qemu/tree/vhu-console-rfc
### Test the device
The daemon should be started first:
```shell
host# vhost-device-console --socket-path=/tmp/console.sock --socket-count=1 \
--tcp-port=12345 --backend=network
```
>Note: In case the backend is "nested" there is no need to provide
"--socket-count" and "--tcp-port" parameters.
The QEMU invocation needs to create a chardev socket the device can
use to communicate as well as share the guests memory over a memfd.
There are two option for running QEMU with vhost-device-console:
1) Using `vhost-user-console-pci`:
```text
host# qemu-system \
<normal QEMU options> \
-machine <machine options>,memory-backend=mem0 \
-object memory-backend-memfd,id=mem0,size=<Guest RAM size> \ # size == -m size
-chardev socket,path=/tmp/console.sock0,id=con \
-device vhost-user-console-pci,chardev=con0,id=console \
...
```
> Note: For testing this scenario the reader needs to clone the QEMU version from the following repo
> which implements `vhost-user-console` device.
> - https://github.com/virtualopensystems/qemu/tree/vhu-console-rfc
2) Using `vhost-user-device-pci`:
```text
host# qemu-system \
<normal QEMU options> \
-machine <machine options>,memory-backend=mem0 \
-object memory-backend-memfd,id=mem0,size=<Guest RAM size> \ # size == -m size
-chardev socket,id=con0,path=/tmp/console.sock0 \
-device vhost-user-device-pci,chardev=con0,virtio-id=3,num_vqs=4,config_size=12 \
...
```
Eventually, the user can connect to the console by running:
```test
host# stty -icanon -echo && nc localhost 12345 && stty echo
```
>Note: `stty -icanon -echo` is used to force the tty layer to disable buffering and send / receive each character individually. After closing the connection please run `stty echo` so character are printed back on the local terminal console.
>Note: In case the backend is "nested" a nested terminal will be shown into
vhost-device-console terminal space.
## License
This project is licensed under either of
- [Apache License](http://www.apache.org/licenses/LICENSE-2.0), Version 2.0
- [BSD-3-Clause License](https://opensource.org/licenses/BSD-3-Clause)
|