From b9cf6ee797f3b65dd951664eb5c5ae060af1a400 Mon Sep 17 00:00:00 2001 From: Dietmar Maurer Date: Tue, 9 Jun 2020 18:46:27 +0200 Subject: [PATCH] src/tools/systemd/types.rs: add Mount config --- src/tools/systemd/config.rs | 34 ++++++++++++++++++++++++++++++ src/tools/systemd/types.rs | 42 +++++++++++++++++++++++++++++++++++++ 2 files changed, 76 insertions(+) diff --git a/src/tools/systemd/config.rs b/src/tools/systemd/config.rs index 3f2c0e14..68d9c229 100644 --- a/src/tools/systemd/config.rs +++ b/src/tools/systemd/config.rs @@ -18,6 +18,7 @@ use proxmox::tools::{fs::replace_file, fs::CreateOptions}; lazy_static! { pub static ref SERVICE_CONFIG: SectionConfig = init_service(); pub static ref TIMER_CONFIG: SectionConfig = init_timer(); + pub static ref MOUNT_CONFIG: SectionConfig = init_mount(); } fn init_service() -> SectionConfig { @@ -78,6 +79,35 @@ fn init_timer() -> SectionConfig { config } +fn init_mount() -> SectionConfig { + + let mut config = SectionConfig::with_systemd_syntax(&SYSTEMD_SECTION_NAME_SCHEMA); + + match SystemdUnitSection::API_SCHEMA { + Schema::Object(ref obj_schema) => { + let plugin = SectionConfigPlugin::new("Unit".to_string(), None, obj_schema); + config.register_plugin(plugin); + } + _ => unreachable!(), + }; + match SystemdInstallSection::API_SCHEMA { + Schema::Object(ref obj_schema) => { + let plugin = SectionConfigPlugin::new("Install".to_string(), None, obj_schema); + config.register_plugin(plugin); + } + _ => unreachable!(), + }; + match SystemdMountSection::API_SCHEMA { + Schema::Object(ref obj_schema) => { + let plugin = SectionConfigPlugin::new("Mount".to_string(), None, obj_schema); + config.register_plugin(plugin); + } + _ => unreachable!(), + }; + + config +} + fn parse_systemd_config(config: &SectionConfig, filename: &str) -> Result { let raw = proxmox::tools::fs::file_get_contents(filename)?; @@ -117,3 +147,7 @@ pub fn save_systemd_service(filename: &str, data: &SectionConfigData) -> Result< pub fn save_systemd_timer(filename: &str, data: &SectionConfigData) -> Result<(), Error> { save_systemd_config(&TIMER_CONFIG, filename, data) } + +pub fn save_systemd_mount(filename: &str, data: &SectionConfigData) -> Result<(), Error> { + save_systemd_config(&MOUNT_CONFIG, filename, data) +} diff --git a/src/tools/systemd/types.rs b/src/tools/systemd/types.rs index 006e5cb2..b57282ca 100644 --- a/src/tools/systemd/types.rs +++ b/src/tools/systemd/types.rs @@ -9,6 +9,7 @@ pub const SYSTEMD_SECTION_NAME_SCHEMA: Schema = StringSchema::new( EnumEntry::new("Unit", "Unit"), EnumEntry::new("Timer", "Timer"), EnumEntry::new("Install", "Install"), + EnumEntry::new("Mount", "Mount"), EnumEntry::new("Service", "Service")])) .schema(); @@ -185,6 +186,47 @@ pub struct SystemdInstallSection { pub RequiredBy: Option>, } +#[api( + properties: { + "TimeoutSec": { + schema: SYSTEMD_TIMESPAN_ARRAY_SCHEMA, + optional: true, + }, + } +)] +#[derive(Serialize, Deserialize, Default)] +#[allow(non_snake_case)] +/// Systemd Service Section +pub struct SystemdMountSection { + /// absolute path of a device node, file or other resource to mount + pub What: String, + /// absolute path of a file or directory for the mount point + pub Where: String, + /// Takes a string for the file system type. See mount(8) for details. + #[serde(skip_serializing_if="Option::is_none")] + pub Type: Option, + /// Mount options to use when mounting. This takes a comma-separated list of options. + #[serde(skip_serializing_if="Option::is_none")] + pub Options: Option, + /// If true, parsing of the options specified in Options= is relaxed, and unknown mount options are tolerated. + #[serde(skip_serializing_if="Option::is_none")] + pub SloppyOptions: Option, + /// Use lazy unmount + #[serde(skip_serializing_if="Option::is_none")] + pub LazyUnmount: Option, + /// Use forces unmount + #[serde(skip_serializing_if="Option::is_none")] + pub ForceUnmount: Option, + /// Directories of mount points (and any parent directories) are + /// automatically created if needed. Takes an access mode in octal + /// notation. Defaults to 0755. + #[serde(skip_serializing_if="Option::is_none")] + pub DirectoryMode: Option, + /// Configures the time to wait for the mount command to finish. + #[serde(skip_serializing_if="Option::is_none")] + pub TimeoutSec: Option, +} + #[api()] #[derive(Debug, Copy, Clone, PartialEq, Serialize, Deserialize)] #[serde(rename_all = "lowercase")]