]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
shared/varlink-io.systemd.MachineInstance: add ReplaceStorage method
authorChristian Brauner <brauner@kernel.org>
Fri, 8 May 2026 08:42:55 +0000 (10:42 +0200)
committerChristian Brauner <brauner@kernel.org>
Tue, 12 May 2026 20:54:07 +0000 (22:54 +0200)
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>
src/shared/varlink-io.systemd.MachineInstance.c

index 6630402709870ea7bb17927c9d07a07b6730a214..b496ea565c48134999cea2627c525e4d93c6f568 100644 (file)
@@ -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"),