]> git.ipfire.org Git - thirdparty/systemd.git/commit
vmspawn: set up varlink bridge infrastructure
authorChristian Brauner <brauner@kernel.org>
Mon, 30 Mar 2026 12:08:40 +0000 (14:08 +0200)
committerChristian Brauner <brauner@kernel.org>
Wed, 15 Apr 2026 08:14:47 +0000 (10:14 +0200)
commit1a7b6fd9dd44d53dd64d895b33ee070e7c9af0b8
tree63b37be61440b1c4abb2d463d4995115f98a8b5e
parent50dd55bb6ebcf8ae43490b8db2a917330048f1ba
vmspawn: set up varlink bridge infrastructure

Create the QMP-to-varlink bridge layer (vmspawn-qmp.{c,h}) and the
varlink server layer (vmspawn-varlink.{c,h}).

The QMP bridge (VmspawnQmpBridge) owns the QmpClient connection and
manages pending background jobs (e.g. blockdev-create continuations).
vmspawn_qmp_init() creates the client and attaches it to the event
loop. vmspawn_qmp_probe_features() drives io_uring and qcow2
discard-no-unref probes synchronously via a qmp_client_process() +
qmp_client_wait() loop — the QMP handshake completes transparently on
the first invoke. vmspawn_qmp_start() resumes vCPUs via an async
"cont" command.

The varlink server (VmspawnVarlinkContext) exposes three interfaces:

- io.systemd.MachineInstance: generic machine control (Terminate,
  PowerOff, Reboot, Pause, Resume, Describe, SubscribeEvents).
  Method handlers forward to QMP commands asynchronously — the
  varlink reply is deferred until the QMP response arrives.
- io.systemd.VirtualMachineInstance: VM-specific (placeholder for
  future snapshot/migration methods).
- io.systemd.QemuMachineInstance: QEMU-specific (AcquireQMP stub).

The server listens on <runtime_dir>/control with mode 0600.

Event streaming follows the importd Pull pattern: SubscribeEvents
sends an initial {ready:true} notification, then fans out QMP events
to all subscribers. The disconnect handler only unrefs subscriber
links (matching resolved's vl_on_notification_disconnect pattern).

Introduce the MachineConfig aggregate in vmspawn-qmp.h grouping the
per-device info structures (DriveInfos, NetworkInfo, VirtiofsInfos,
VsockInfo) together with machine_config_done() that chains the
individual done helpers. Callers populate it field-by-field and rely
on the _cleanup_ attribute for orderly teardown regardless of which
device types the invocation ends up using.

Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
src/vmspawn/meson.build
src/vmspawn/vmspawn-qmp.c [new file with mode: 0644]
src/vmspawn/vmspawn-qmp.h [new file with mode: 0644]
src/vmspawn/vmspawn-varlink.c [new file with mode: 0644]
src/vmspawn/vmspawn-varlink.h [new file with mode: 0644]