Skip to content

Commit

Permalink
Update vhost-device-console
Browse files Browse the repository at this point in the history
Add a new "network" backend with which the device can work with multiple
QEMU guests. For each guest a new localhost server is created and the user
can connect and execute command into the guest by running:

    host# nc 127.0.0.1 12345

Signed-off-by: Timos Ampelikiotis <t.ampelikiotis@virtualopensystems.com>
  • Loading branch information
TimosAmpel committed Feb 8, 2024
1 parent 07ddc1b commit 006b2e0
Show file tree
Hide file tree
Showing 6 changed files with 507 additions and 124 deletions.
2 changes: 2 additions & 0 deletions staging/vhost-device-console/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ xen = ["vm-memory/xen", "vhost/xen", "vhost-user-backend/xen"]

[dependencies]
console = "0.15.7"
crossterm = "0.27.0"
nix = "0.21.1"
queues = "1.0.2"
clap = { version = "4.4", features = ["derive"] }
env_logger = "0.10"
Expand Down
73 changes: 50 additions & 23 deletions staging/vhost-device-console/README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,30 @@
# 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 parameter a socket, 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".

By using the "nested" backend, vhost-device-console, as soon as, the guest
is booted, will print the login prompt into the same terminal and gives
the ability to insert characters or certain keys as in a regular
terminal.

By using "network" backend, vhost-device-console, as soon as the guests
is booted, creates a local server in the given localhost port, and gives
the chance to connect on them and interact with the guests.

This program is tested with QEMU's `vhost-user-device-pci` device.
Examples' section below.

This program is a vhost-user backend that emulates a VirtIO Console device.

## Synopsis
```text
vhost-device-can --socket-path=<SOCKET_PATH>
vhost-device-console --socket-path=<SOCKET_PATH>
```

## Options
Expand All @@ -15,37 +37,31 @@ vhost-device-can --socket-path=<SOCKET_PATH>

.. option:: -s, --socket-path=PATH

Location of vhost-user Unix domain sockets
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

## Description
The localhost's port to be used for each guest, this part will be increased with
0,1,2..socket_count-1.

This program is a vhost-user backend that emulates a VirtIO Console device.
The device's binary takes as parameter a socket which is commonly used
across all vhost-devices to communicate with the vhost-user frontend device.
-- option:: -b, --backend=network|nested

This program is tested with QEMU's `vhost-user-device-pci` device and
Virtio-loopback's `-device vhost-user-can`.
Examples' section below.

This program is a vhost-user backend that emulates a VirtIO Console device.
The backend type vhost-device-console will use.
Note: The nested backend can be used only when socket_count equals 1.

## Limitations

This device is still work-in-progress (WIP). Currently the device works
only with one guest at the time (no multi-guest support).

## Next steps

Next development steps are:
1) Enable multi-guest support
2) Update the restart process of the device
This device is still work-in-progress (WIP). The current version has been tested
with VIRTIO_CONSOLE_F_MULTIPORT, but only for one console.

## Features

The current device gives access to a QEMU guest by providing a login prompt.
This prompt appears as soon as the guest is fully booted and gives the ability
to user run command as a in regular terminal.
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

Expand All @@ -62,8 +78,11 @@ For testing the device the required dependencies are:

The daemon should be started first:
```shell
host# vhost-device-can --socket-path=can.sock --can-in="can0" --can-out="can1"
host# vhost-device-console --socket-path=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.
Expand Down Expand Up @@ -96,6 +115,14 @@ host# qemu-system
...
```

Eventually, the user can connect to the console by running:
```test
host# nc 127.0.0.1 12345
```

>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
Expand Down

0 comments on commit 006b2e0

Please sign in to comment.