Skip to content

Commit 038d252

Browse files
author
Dorinda Bassey
committed
libkrun: Add API constants and example for vhost-user input
Add public API constants for vhost-user input devices and example usage in chroot_vm. The underlying support already exists via the generic VhostUserDevice wrapper. Console devices require 2 queues (event, status). Example integration: - Added --vhost-user-console option to chroot_vm Example usage: On host, start vhost-device-input backend vhost-device-input --socket-path /tmp/input.sock \ --event-list /dev/input/event3 In libkrun ./chroot_vm --vhost-user-input=/tmp/input.sock0 / /bin/sh The guest will see the input device as /dev/input/event0 and can read input events from the host device. Signed-off-by: Dorinda Bassey <dbassey@redhat.com>
1 parent 9fd1fb1 commit 038d252

2 files changed

Lines changed: 27 additions & 0 deletions

File tree

examples/chroot_vm.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ static void print_help(char *const name)
4040
" --net=NET_MODE Set network mode\n"
4141
" --passt-socket=PATH Instead of starting passt, connect to passt socket at PATH\n"
4242
" --vhost-user-rng=PATH Use vhost-user RNG backend at socket PATH\n"
43+
" --vhost-user-input=PATH Use vhost-user input backend at socket PATH\n"
4344
" --vhost-user-snd=PATH Use vhost-user sound backend at socket PATH\n"
4445
" --vhost-user-vsock=PATH Use vhost-user vsock backend at socket PATH\n"
4546
" --vhost-user-can=PATH Use vhost-user CAN backend at socket PATH\n"
@@ -70,6 +71,7 @@ static const struct option long_options[] = {
7071
{ "net_mode", required_argument, NULL, 'N' },
7172
{ "passt-socket", required_argument, NULL, 'P' },
7273
{ "vhost-user-rng", required_argument, NULL, 'V' },
74+
{ "vhost-user-input", required_argument, NULL, 'I' },
7375
{ "vhost-user-snd", required_argument, NULL, 'S' },
7476
{ "vhost-user-vsock", required_argument, NULL, 'K' },
7577
{ "vhost-user-can", required_argument, NULL, 'A' },
@@ -84,6 +86,7 @@ struct cmdline {
8486
enum net_mode net_mode;
8587
char const *passt_socket_path;
8688
char const *vhost_user_rng_socket;
89+
char const *vhost_user_input_socket;
8790
char const *vhost_user_snd_socket;
8891
char const *vhost_user_vsock_socket;
8992
char const *vhost_user_can_socket;
@@ -115,6 +118,7 @@ bool parse_cmdline(int argc, char *const argv[], struct cmdline *cmdline)
115118
.net_mode = NET_MODE_TSI,
116119
.passt_socket_path = NULL,
117120
.vhost_user_rng_socket = NULL,
121+
.vhost_user_input_socket = NULL,
118122
.vhost_user_snd_socket = NULL,
119123
.vhost_user_vsock_socket = NULL,
120124
.vhost_user_can_socket = NULL,
@@ -157,6 +161,9 @@ bool parse_cmdline(int argc, char *const argv[], struct cmdline *cmdline)
157161
case 'V':
158162
cmdline->vhost_user_rng_socket = optarg;
159163
break;
164+
case 'I':
165+
cmdline->vhost_user_input_socket = optarg;
166+
break;
160167
case 'S':
161168
cmdline->vhost_user_snd_socket = optarg;
162169
break;
@@ -307,6 +314,18 @@ int main(int argc, char *const argv[])
307314
printf("Using vhost-user RNG backend at %s (custom queue size: 512)\n", cmdline.vhost_user_rng_socket);
308315
}
309316

317+
// Configure vhost-user input if requested
318+
if (cmdline.vhost_user_input_socket != NULL) {
319+
if (!check_krun_error(krun_add_vhost_user_device(ctx_id, KRUN_VIRTIO_DEVICE_INPUT,
320+
cmdline.vhost_user_input_socket, NULL,
321+
KRUN_VHOST_USER_INPUT_NUM_QUEUES,
322+
KRUN_VHOST_USER_INPUT_QUEUE_SIZES),
323+
"Error adding vhost-user input device")) {
324+
return -1;
325+
}
326+
printf("Using vhost-user input backend at %s\n", cmdline.vhost_user_input_socket);
327+
}
328+
310329
// Configure vhost-user sound if requested
311330
if (cmdline.vhost_user_snd_socket != NULL) {
312331
if (!check_krun_error(krun_add_vhost_user_device(ctx_id, KRUN_VIRTIO_DEVICE_SND,

include/libkrun.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -753,6 +753,7 @@ int32_t krun_set_snd_device(uint32_t ctx_id, bool enable);
753753
*/
754754
#define KRUN_VIRTIO_DEVICE_CONSOLE 3
755755
#define KRUN_VIRTIO_DEVICE_RNG 4
756+
#define KRUN_VIRTIO_DEVICE_INPUT 18
756757
#define KRUN_VIRTIO_DEVICE_VSOCK 19
757758
#define KRUN_VIRTIO_DEVICE_SND 25
758759
#define KRUN_VIRTIO_DEVICE_CAN 36
@@ -772,6 +773,13 @@ int32_t krun_set_snd_device(uint32_t ctx_id, bool enable);
772773
#define KRUN_VHOST_USER_RNG_NUM_QUEUES 1
773774
#define KRUN_VHOST_USER_RNG_QUEUE_SIZES ((uint16_t[]){256})
774775

776+
/**
777+
* Vhost-user input device default queue configuration.
778+
* Input device uses 2 queues: eventq (idx 0), statusq (idx 1).
779+
*/
780+
#define KRUN_VHOST_USER_INPUT_NUM_QUEUES 2
781+
#define KRUN_VHOST_USER_INPUT_QUEUE_SIZES ((uint16_t[]){1024, 1024})
782+
775783
/**
776784
* Vhost-user sound device default queue configuration.
777785
* Sound device uses 4 queues: control (idx 0), event (idx 1), TX/playback (idx 2), RX/capture (idx 3).

0 commit comments

Comments
 (0)