allow evdev input devices to be attached at runtime on QEMU

Goal

I'd like to request support for adding evdev input devices to QEMU domains at runtime using libvirt.

It is possible to hotplug Virtio and USB input devices using libvirt (added in 2017 according to RedHat Bugzilla).

QEMU additionally supports hotplugging evdev input devices, but libvirt currently claims that it is not supported since the bus is none.

Since evdev does not reattach devices that have been disconnected from the host automatically, it is necessary to do this manually. But with libvirt, this is currently only possible using QEMU monitor commands.

Technical details

libvirt supports detaching evdev devices using detach-device but using the same XML with attach-device leads to the following error: error: Operation not supported: input device on bus 'none' cannot be hot plugged..

This is due to different placement of VIR_DOMAIN_INPUT_BUS_NONE in the switch/case statements for the bus in the functions qemuDomainAttachInputDevice and qemuDomainDetachPrepInput in src/qemu/qemu_hotplug.c.

In the attach function, both the VIR_DOMAIN_INPUT_BUS_NONE and VIR_DOMAIN_INPUT_BUS_LAST options cause an error while in the detach function, they do not.

The case of VIR_DOMAIN_INPUT_BUS_NONE in the attach function would likely need special handling for devices of the type evdev.

Due to evdev also requiring access to files on the host system, some additional code to modify the cgroup would likely be needed.

Please note that the cgroup is not modified in the detach function either.

Additional information

evdev input devices can be attached and detached at runtime using the following QMP commands:

{"execute": "object-add", "arguments": {"qom-type": "input-linux", "id": "<id>", "evdev": "/dev/input/by-id/<evdev-id>"}}
{"execute": "object-del", "arguments": {"id": "<id>"}}

My C is rusty at best, but in case this proposal is accepted but there is no capacity to implement it, I'd be willing to give it a try.

To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information