shared/varlink-io.systemd.MachineInstance: add ReplaceStorage method

Define the IDL for io.systemd.MachineInstance.ReplaceStorage, a
runtime hot-swap of an already-attached storage volume's backing
file. The signature mirrors AddStorage minus the 'config' field
because the device frontend (virtio-blk, virtio-scsi, nvme, scsi-cd)
does not change — only the backing file behind it.

The implementation lives in vmspawn (next commit) and uses QMP
blockdev-reopen to swap the file child of the existing format node.
The reused error vocabulary (NoSuchStorage, StorageImmutable,
NotConnected, plus the generic errno path) covers every failure
mode; no new errors are added.

Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
This commit is contained in:
Christian Brauner
2026-05-12 22:54:07 +02:00
parent 8dc5dbe3c0
commit 3063448b51
@@ -39,6 +39,13 @@ static SD_VARLINK_DEFINE_METHOD(
SD_VARLINK_FIELD_COMMENT("Unique storage name '<provider>:<volume>' to detach"),
SD_VARLINK_DEFINE_INPUT(name, SD_VARLINK_STRING, 0));
static SD_VARLINK_DEFINE_METHOD(
ReplaceStorage,
SD_VARLINK_FIELD_COMMENT("Index of the attached file descriptor for the new backing storage"),
SD_VARLINK_DEFINE_INPUT(fileDescriptorIndex, SD_VARLINK_INT, 0),
SD_VARLINK_FIELD_COMMENT("Identifier of the existing binding whose backing is being replaced (as supplied to AddStorage)"),
SD_VARLINK_DEFINE_INPUT(name, SD_VARLINK_STRING, 0));
static SD_VARLINK_DEFINE_ERROR(NotConnected);
static SD_VARLINK_DEFINE_ERROR(NotSupported);
static SD_VARLINK_DEFINE_ERROR(NoSuchStorage);
@@ -68,6 +75,8 @@ SD_VARLINK_DEFINE_INTERFACE(
&vl_method_AddStorage,
SD_VARLINK_SYMBOL_COMMENT("Detach a previously-attached storage volume from the running machine"),
&vl_method_RemoveStorage,
SD_VARLINK_SYMBOL_COMMENT("Replace the backing of a previously-attached storage volume in place"),
&vl_method_ReplaceStorage,
SD_VARLINK_SYMBOL_COMMENT("The connection to the machine backend is not available"),
&vl_error_NotConnected,
SD_VARLINK_SYMBOL_COMMENT("The requested operation is not supported"),