shared: move machine registration to shared machine-register.{c,h}

Move register_machine() and unregister_machine() from
vmspawn-register.{c,h} into shared machine-register.{c,h} so both
nspawn and vmspawn can use the same implementation.

The unified register_machine() uses varlink first (for richer
features like SSH support and unit allocation) with a D-Bus
RegisterMachineWithNetwork fallback for older machined. The
interface adds a class parameter ("vm" or "container") and
local_ifindex for nspawn's network interface support.

The unified unregister_machine() similarly tries varlink first
(io.systemd.Machine.Unregister) before falling back to D-Bus.

Both register_machine() and unregister_machine() only log at debug
level internally, leaving error/notice logging to callers.

Add register_machine_with_fallback() which tries system and/or user
scope registration based on a RuntimeScope parameter
(_RUNTIME_SCOPE_INVALID for both), and
unregister_machine_with_fallback() as its counterpart. Both use
RET_GATHER() to collect errors from each scope.

Make --register= a tristate (yes/no/auto) defaulting to auto. When
set to auto, registration failures are logged at notice level and
ignored. When set to yes, failures are fatal.

Co-developed-by: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Daan De Meyer
2026-04-06 17:13:40 +02:00
committed by Daan De Meyer
parent 0e231729fd
commit 1e084aad7d
15 changed files with 493 additions and 375 deletions
+1 -1
View File
@@ -131,7 +131,7 @@ _systemd_nspawn() {
comps=''
;;
--register)
comps='yes no'
comps='yes no auto'
;;
--network-interface)
comps=$(__get_interfaces)
+3 -3
View File
@@ -31,8 +31,8 @@ _systemd_vmspawn() {
local -A OPTS=(
[STANDALONE]='-h --help --version -q --quiet --no-pager -n --network-tap --network-user-mode --user --system -x --ephemeral'
[PATH]='-D --directory -i --image --linux --initrd --extra-drive --forward-journal --efi-nvram-template'
[BOOL]='--kvm --cxl --vsock --tpm --discard-disk --register --pass-ssh-key'
[SECURE_BOOT]='--secure-boot'
[BOOL]='--kvm --cxl --vsock --tpm --discard-disk --pass-ssh-key'
[TRISTATE]='--register --secure-boot'
[FIRMWARE]='--firmware'
[FIRMWARE_FEATURES]='--firmware-features'
[BIND]='--bind --bind-ro'
@@ -47,7 +47,7 @@ _systemd_vmspawn() {
if __contains_word "$prev" ${OPTS[BOOL]}; then
comps='yes no'
elif __contains_word "$prev" ${OPTS[SECURE_BOOT]}; then
elif __contains_word "$prev" ${OPTS[TRISTATE]}; then
comps='yes no auto'
elif __contains_word "$prev" ${OPTS[PATH]}; then
compopt -o nospace -o filenames