QEMU supports runtime hotplug for chardevs, devices, block backends,
and netdevs. Monitors are the only major subsystem that lacks this --
all QMP monitors must be configured at launch via -mon or -qmp CLI
options.
This series adds monitor-add, monitor-remove, and query-monitors QMP
commands so that management tools can create independent QMP sessions
on demand at runtime.
I've currently implemented a bridge that bridges QMP and Varlink in
systemd. This allows sytemd-vmspawn to control virtual machines and
containers through a unified Varlink interface. Varlink allows protocol
upgrades. For example, it is possible to switch from Varlink to say
http. I'm allow Varlink clients to upgrade from the Varlink interfact to
the native QMP interface. Such clients get a new monitor assigned that
allows them to manage the virtual machine directly via QMP. The main
monitor remains unaffected and tied to the generic Varlink interface.
We can't pre-allocate monitors as we have no control over how many
protocol upgrades we actually get but it won't just be one. And having
unused monitors around really isn't ideal either.
Having the ability to hotplug monitors would really be helpful. I'm not
yet super well-versed in qemu internals so this might be done wrong but
testing works so far.
My systemd patch that triggerd this is at
https://github.com/systemd/systemd/pull/41449.
The usage pattern mirrors chardev hotplug:
-> chardev-add id=qmp-extra backend=socket,...
-> monitor-add id=extra-qmp chardev=qmp-extra
[client connects to socket, gets QMP greeting, negotiates, sends commands]
-> monitor-remove id=extra-qmp
-> chardev-remove id=qmp-extra
Patches 1-2 add the data model (id/dynamic/dead fields in Monitor) and
the infrastructure for safe per-monitor destruction without shutting
down the shared dispatcher coroutine.
Patch 3 adds the QAPI schema and command handlers.
Patches 4-5 add qtest unit tests and a functional e2e test that
performs a full hotplug -> connect -> handshake -> unplug cycle.
Signed-off-by: Christian Brauner <brauner@kernel.org>
---
Christian Brauner (5):
monitor: store monitor id and dynamic flag in Monitor struct
monitor/qmp: add infrastructure for safe dynamic monitor removal
qapi: add monitor-add, monitor-remove, query-monitors commands
tests/qtest: add tests for dynamic monitor add/remove
tests/functional: add e2e test for dynamic QMP monitor hotplug
include/monitor/monitor.h | 3 +-
monitor/monitor-internal.h | 8 ++
monitor/monitor.c | 15 +++-
monitor/qmp-cmds-control.c | 94 ++++++++++++++++++++
monitor/qmp.c | 41 ++++++++-
qapi/control.json | 106 +++++++++++++++++++++++
tests/functional/generic/meson.build | 1 +
tests/functional/generic/test_monitor_hotplug.py | 102 ++++++++++++++++++++++
tests/qtest/qmp-test.c | 101 +++++++++++++++++++++
9 files changed, 467 insertions(+), 4 deletions(-)
---
base-commit: b6a7d06213e5d2f7d124d16418bc289c4a8a4b82
change-id: 20260402-work-qmp-monitor-hotplug-fba7c618e3db