]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
shared: add AddStorage / RemoveStorage to io.systemd.MachineInstance
authorChristian Brauner <brauner@kernel.org>
Fri, 1 May 2026 11:32:58 +0000 (13:32 +0200)
committerChristian Brauner <brauner@kernel.org>
Wed, 6 May 2026 08:30:17 +0000 (10:30 +0200)
Define two new methods on the generic 'MachineInstance' Varlink
interface that systemd-vmspawn (this series) and (future)
systemd-nspawn implement on their per-machine control sockets:

  AddStorage(fileDescriptorIndex, name, config?) -> ()
      Attach a storage volume — the caller passes an fd previously
      acquired from a StorageProvider, plus a unique name of the form
      '<provider>:<volume>' that identifies this binding for later
      removal, plus a backend-specific 'config' field (vmspawn: guest
      device type; future nspawn: mount path).

  RemoveStorage(name) -> ()
      Detach a previously-added storage volume.

Plus errors NoSuchStorage, StorageExists, StorageImmutable (the volume
was attached at boot and cannot be removed), BadConfig, and
ConfigNotSupported. Names follow the io.systemd.StorageProvider
vocabulary (NoSuchVolume, BadTemplate, TypeNotSupported, etc.) so the
two interfaces are visually consistent.

Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
src/shared/varlink-io.systemd.MachineInstance.c

index 365b6f5f9e1af019c0a4d9fd610032aca5f5ce17..6630402709870ea7bb17927c9d07a07b6730a214 100644 (file)
@@ -25,8 +25,27 @@ static SD_VARLINK_DEFINE_METHOD_FULL(
                 SD_VARLINK_FIELD_COMMENT("Event-specific payload"),
                 SD_VARLINK_DEFINE_OUTPUT(data, SD_VARLINK_OBJECT, SD_VARLINK_NULLABLE));
 
+static SD_VARLINK_DEFINE_METHOD(
+                AddStorage,
+                SD_VARLINK_FIELD_COMMENT("Index of the attached file descriptor for the storage volume"),
+                SD_VARLINK_DEFINE_INPUT(fileDescriptorIndex, SD_VARLINK_INT, 0),
+                SD_VARLINK_FIELD_COMMENT("Unique storage name of the form '<provider>:<volume>' identifying this binding for later removal"),
+                SD_VARLINK_DEFINE_INPUT(name, SD_VARLINK_STRING, 0),
+                SD_VARLINK_FIELD_COMMENT("Backend-specific configuration"),
+                SD_VARLINK_DEFINE_INPUT(config, SD_VARLINK_STRING, SD_VARLINK_NULLABLE));
+
+static SD_VARLINK_DEFINE_METHOD(
+                RemoveStorage,
+                SD_VARLINK_FIELD_COMMENT("Unique storage name '<provider>:<volume>' to detach"),
+                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);
+static SD_VARLINK_DEFINE_ERROR(StorageExists);
+static SD_VARLINK_DEFINE_ERROR(StorageImmutable);
+static SD_VARLINK_DEFINE_ERROR(BadConfig);
+static SD_VARLINK_DEFINE_ERROR(ConfigNotSupported);
 
 SD_VARLINK_DEFINE_INTERFACE(
                 io_systemd_MachineInstance,
@@ -45,7 +64,21 @@ SD_VARLINK_DEFINE_INTERFACE(
                 &vl_method_Describe,
                 SD_VARLINK_SYMBOL_COMMENT("Subscribe to machine events. Returns a stream of events as they occur."),
                 &vl_method_SubscribeEvents,
+                SD_VARLINK_SYMBOL_COMMENT("Attach a storage volume (passed via file descriptor) to the running machine"),
+                &vl_method_AddStorage,
+                SD_VARLINK_SYMBOL_COMMENT("Detach a previously-attached storage volume from the running machine"),
+                &vl_method_RemoveStorage,
                 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"),
-                &vl_error_NotSupported);
+                &vl_error_NotSupported,
+                SD_VARLINK_SYMBOL_COMMENT("The named storage binding does not exist"),
+                &vl_error_NoSuchStorage,
+                SD_VARLINK_SYMBOL_COMMENT("A storage binding with this name already exists"),
+                &vl_error_StorageExists,
+                SD_VARLINK_SYMBOL_COMMENT("The storage binding cannot be detached at runtime (e.g. attached at boot)"),
+                &vl_error_StorageImmutable,
+                SD_VARLINK_SYMBOL_COMMENT("The supplied 'config' value is not valid for this backend"),
+                &vl_error_BadConfig,
+                SD_VARLINK_SYMBOL_COMMENT("The supplied 'config' value is recognized but not supported by this backend"),
+                &vl_error_ConfigNotSupported);