From aa02ad284e6d98fdd594c0f4e4d1765f8b4574d4 Mon Sep 17 00:00:00 2001 From: Christian Brauner Date: Fri, 1 May 2026 13:32:58 +0200 Subject: [PATCH] shared: add AddStorage / RemoveStorage to io.systemd.MachineInstance MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 ':' 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) --- .../varlink-io.systemd.MachineInstance.c | 35 ++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/src/shared/varlink-io.systemd.MachineInstance.c b/src/shared/varlink-io.systemd.MachineInstance.c index 365b6f5f9e..6630402709 100644 --- a/src/shared/varlink-io.systemd.MachineInstance.c +++ b/src/shared/varlink-io.systemd.MachineInstance.c @@ -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 ':' 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 ':' 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);