[pbs-devel] [RFC proxmox 2/2] pbs-api-types: extend datastore config by backend config enum
Christian Ebner
c.ebner at proxmox.com
Mon May 19 13:46:03 CEST 2025
Allows to configure a backend config variant for a datastore on
creation. The current default `Filesystem` backend variant is
introduced to be compatible with existing storages. A new S3 backend
variant allows to create datastores backed by an S3 compatible object
store instead.
For S3 backends, the id of the corresponding S3 client configuration
is storered. A valid datastore backend configuration for S3 therefore
contains:
```
...
backend s3=<S3_CONFIG_ID>
...
```
Signed-off-by: Christian Ebner <c.ebner at proxmox.com>
---
pbs-api-types/src/datastore.rs | 58 +++++++++++++++++++++++++++++++++-
1 file changed, 57 insertions(+), 1 deletion(-)
diff --git a/pbs-api-types/src/datastore.rs b/pbs-api-types/src/datastore.rs
index 5bd953ac..2b983cb2 100644
--- a/pbs-api-types/src/datastore.rs
+++ b/pbs-api-types/src/datastore.rs
@@ -336,7 +336,11 @@ pub const DATASTORE_TUNING_STRING_SCHEMA: Schema = StringSchema::new("Datastore
optional: true,
format: &proxmox_schema::api_types::UUID_FORMAT,
type: String,
- }
+ },
+ backend: {
+ schema: DATASTORE_BACKEND_SCHEMA,
+ optional: true,
+ },
}
)]
#[derive(Serialize, Deserialize, Updater, Clone, PartialEq)]
@@ -389,8 +393,59 @@ pub struct DataStoreConfig {
#[updater(skip)]
#[serde(skip_serializing_if = "Option::is_none")]
pub backing_device: Option<String>,
+
+ /// Backend to be used by datastore
+ #[updater(skip)]
+ #[serde(skip_serializing_if = "Option::is_none")]
+ pub backend: Option<String>,
+}
+
+pub const DATASTORE_BACKEND_SCHEMA: Schema = StringSchema::new("Backend config to be used for datastore.")
+ .format(&ApiStringFormat::VerifyFn(verify_datastore_backend))
+ .type_text("<filesystem|s3=S3_CONFIG_ID>")
+ .schema();
+
+fn verify_datastore_backend(input: &str) -> Result<(), Error> {
+ DatastoreBackendConfig::from_str(input).map(|_| ())
+}
+
+#[derive(Clone, Default)]
+/// Available backend configurations for datastores.
+pub enum DatastoreBackendConfig {
+ #[default]
+ Filesystem,
+ S3(String),
}
+impl std::str::FromStr for DatastoreBackendConfig {
+ type Err = Error;
+
+ fn from_str(s: &str) -> Result<Self, Self::Err> {
+ if s == "filesystem" {
+ return Ok(Self::Filesystem);
+ }
+ match s.split_once('=') {
+ Some(("s3", value)) => {
+ let s3_config_id = value.parse()?;
+ Ok(Self::S3(s3_config_id))
+ }
+ _ => bail!("invalid datastore backend configuration"),
+ }
+ }
+}
+
+impl std::fmt::Display for DatastoreBackendConfig {
+ fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+ match self {
+ Self::Filesystem => write!(f, "filesystem"),
+ Self::S3(s3_config_id) => write!(f, "s3:{s3_config_id}"),
+ }
+ }
+}
+
+proxmox_serde::forward_serialize_to_display!(DatastoreBackendConfig);
+proxmox_serde::forward_deserialize_to_from_str!(DatastoreBackendConfig);
+
#[api]
#[derive(Serialize, Deserialize, Updater, Clone, PartialEq, Default)]
#[serde(rename_all = "kebab-case")]
@@ -424,6 +479,7 @@ impl DataStoreConfig {
tuning: None,
maintenance_mode: None,
backing_device: None,
+ backend: None,
}
}
--
2.39.5
More information about the pbs-devel
mailing list