more import cleanups

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
This commit is contained in:
Wolfgang Bumiller 2021-08-31 14:01:03 +02:00
parent cabdabba3d
commit dd2162f6bd
13 changed files with 37 additions and 54 deletions

View File

@ -175,9 +175,9 @@ pub fn create_datastore_disk(
let mount_unit_name = create_datastore_mount_unit(&name, &mount_point, filesystem, &uuid_path)?; let mount_unit_name = create_datastore_mount_unit(&name, &mount_point, filesystem, &uuid_path)?;
systemd::reload_daemon()?; pbs_systemd::reload_daemon()?;
systemd::enable_unit(&mount_unit_name)?; pbs_systemd::enable_unit(&mount_unit_name)?;
systemd::start_unit(&mount_unit_name)?; pbs_systemd::start_unit(&mount_unit_name)?;
if add_datastore { if add_datastore {
let lock = open_backup_lockfile(datastore::DATASTORE_CFG_LOCKFILE, None, true)?; let lock = open_backup_lockfile(datastore::DATASTORE_CFG_LOCKFILE, None, true)?;
@ -231,9 +231,9 @@ pub fn delete_datastore_disk(name: String) -> Result<(), Error> {
} }
// disable systemd mount-unit // disable systemd mount-unit
let mut mount_unit_name = systemd::escape_unit(&path, true); let mut mount_unit_name = pbs_systemd::escape_unit(&path, true);
mount_unit_name.push_str(".mount"); mount_unit_name.push_str(".mount");
systemd::disable_unit(&mount_unit_name)?; pbs_systemd::disable_unit(&mount_unit_name)?;
// delete .mount-file // delete .mount-file
let mount_unit_path = format!("/etc/systemd/system/{}", mount_unit_name); let mount_unit_path = format!("/etc/systemd/system/{}", mount_unit_name);
@ -270,7 +270,7 @@ fn create_datastore_mount_unit(
what: &str, what: &str,
) -> Result<String, Error> { ) -> Result<String, Error> {
let mut mount_unit_name = systemd::escape_unit(&mount_point, true); let mut mount_unit_name = pbs_systemd::escape_unit(&mount_point, true);
mount_unit_name.push_str(".mount"); mount_unit_name.push_str(".mount");
let mount_unit_path = format!("/etc/systemd/system/{}", mount_unit_name); let mount_unit_path = format!("/etc/systemd/system/{}", mount_unit_name);

View File

@ -26,8 +26,6 @@ use crate::server::WorkerTask;
use crate::api2::types::*; use crate::api2::types::*;
use crate::tools::systemd;
pub const DISK_ARRAY_SCHEMA: Schema = ArraySchema::new( pub const DISK_ARRAY_SCHEMA: Schema = ArraySchema::new(
"Disk name list.", &BLOCKDEVICE_NAME_SCHEMA) "Disk name list.", &BLOCKDEVICE_NAME_SCHEMA)
.schema(); .schema();
@ -362,8 +360,8 @@ pub fn create_zpool(
worker.log(output); worker.log(output);
if std::path::Path::new("/lib/systemd/system/zfs-import@.service").exists() { if std::path::Path::new("/lib/systemd/system/zfs-import@.service").exists() {
let import_unit = format!("zfs-import@{}.service", systemd::escape_unit(&name, false)); let import_unit = format!("zfs-import@{}.service", pbs_systemd::escape_unit(&name, false));
systemd::enable_unit(&import_unit)?; pbs_systemd::enable_unit(&import_unit)?;
} }
if let Some(compression) = compression { if let Some(compression) = compression {

View File

@ -264,25 +264,25 @@ pub const MEDIA_UUID_SCHEMA: Schema =
pub const SYNC_SCHEDULE_SCHEMA: Schema = StringSchema::new( pub const SYNC_SCHEDULE_SCHEMA: Schema = StringSchema::new(
"Run sync job at specified schedule.") "Run sync job at specified schedule.")
.format(&ApiStringFormat::VerifyFn(crate::tools::systemd::time::verify_calendar_event)) .format(&ApiStringFormat::VerifyFn(pbs_systemd::time::verify_calendar_event))
.type_text("<calendar-event>") .type_text("<calendar-event>")
.schema(); .schema();
pub const GC_SCHEDULE_SCHEMA: Schema = StringSchema::new( pub const GC_SCHEDULE_SCHEMA: Schema = StringSchema::new(
"Run garbage collection job at specified schedule.") "Run garbage collection job at specified schedule.")
.format(&ApiStringFormat::VerifyFn(crate::tools::systemd::time::verify_calendar_event)) .format(&ApiStringFormat::VerifyFn(pbs_systemd::time::verify_calendar_event))
.type_text("<calendar-event>") .type_text("<calendar-event>")
.schema(); .schema();
pub const PRUNE_SCHEDULE_SCHEMA: Schema = StringSchema::new( pub const PRUNE_SCHEDULE_SCHEMA: Schema = StringSchema::new(
"Run prune job at specified schedule.") "Run prune job at specified schedule.")
.format(&ApiStringFormat::VerifyFn(crate::tools::systemd::time::verify_calendar_event)) .format(&ApiStringFormat::VerifyFn(pbs_systemd::time::verify_calendar_event))
.type_text("<calendar-event>") .type_text("<calendar-event>")
.schema(); .schema();
pub const VERIFICATION_SCHEDULE_SCHEMA: Schema = StringSchema::new( pub const VERIFICATION_SCHEDULE_SCHEMA: Schema = StringSchema::new(
"Run verify job at specified schedule.") "Run verify job at specified schedule.")
.format(&ApiStringFormat::VerifyFn(crate::tools::systemd::time::verify_calendar_event)) .format(&ApiStringFormat::VerifyFn(pbs_systemd::time::verify_calendar_event))
.type_text("<calendar-event>") .type_text("<calendar-event>")
.schema(); .schema();

View File

@ -4,8 +4,9 @@
//! so we cannot use them directly for the API. Instead, we represent //! so we cannot use them directly for the API. Instead, we represent
//! them as String. //! them as String.
use anyhow::Error;
use std::str::FromStr; use std::str::FromStr;
use anyhow::Error;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use proxmox::api::{ use proxmox::api::{
@ -13,19 +14,13 @@ use proxmox::api::{
schema::{Schema, StringSchema, ApiStringFormat, Updater}, schema::{Schema, StringSchema, ApiStringFormat, Updater},
}; };
use crate::{ use pbs_systemd::time::{parse_calendar_event, parse_time_span, CalendarEvent, TimeSpan};
tools::systemd::time::{
CalendarEvent, use crate::api2::types::{
TimeSpan, PROXMOX_SAFE_ID_FORMAT,
parse_time_span, SINGLE_LINE_COMMENT_FORMAT,
parse_calendar_event, SINGLE_LINE_COMMENT_SCHEMA,
}, TAPE_ENCRYPTION_KEY_FINGERPRINT_SCHEMA,
api2::types::{
PROXMOX_SAFE_ID_FORMAT,
SINGLE_LINE_COMMENT_FORMAT,
SINGLE_LINE_COMMENT_SCHEMA,
TAPE_ENCRYPTION_KEY_FINGERPRINT_SCHEMA,
},
}; };
pub const MEDIA_POOL_NAME_SCHEMA: Schema = StringSchema::new("Media pool name.") pub const MEDIA_POOL_NAME_SCHEMA: Schema = StringSchema::new("Media pool name.")

View File

@ -26,13 +26,10 @@ use proxmox_backup::{
}, },
rotate_task_log_archive, rotate_task_log_archive,
}, },
tools::systemd::time::{
parse_calendar_event,
compute_next_event,
},
}; };
use pbs_buildcfg::configdir; use pbs_buildcfg::configdir;
use pbs_systemd::time::{compute_next_event, parse_calendar_event};
use proxmox_backup::api2::types::Authid; use proxmox_backup::api2::types::Authid;
use proxmox_backup::server; use proxmox_backup::server;

View File

@ -14,8 +14,6 @@ use pbs_client::{DEFAULT_VSOCK_PORT, BackupRepository, VsockClient};
use pbs_datastore::backup_info::BackupDir; use pbs_datastore::backup_info::BackupDir;
use pbs_datastore::catalog::ArchiveEntry; use pbs_datastore::catalog::ArchiveEntry;
use proxmox_backup::tools;
use super::block_driver::*; use super::block_driver::*;
use crate::get_user_run_dir; use crate::get_user_run_dir;
@ -82,7 +80,7 @@ impl VMStateMap {
fn make_name(repo: &BackupRepository, snap: &BackupDir) -> String { fn make_name(repo: &BackupRepository, snap: &BackupDir) -> String {
let full = format!("qemu_{}/{}", repo, snap); let full = format!("qemu_{}/{}", repo, snap);
tools::systemd::escape_unit(&full, false) pbs_systemd::escape_unit(&full, false)
} }
/// remove non-responsive VMs from given map, returns 'true' if map was modified /// remove non-responsive VMs from given map, returns 'true' if map was modified
@ -259,7 +257,7 @@ impl BlockRestoreDriver for QemuBlockDriver {
let resp = client let resp = client
.get("api2/json/status", Some(json!({"keep-timeout": true}))) .get("api2/json/status", Some(json!({"keep-timeout": true})))
.await; .await;
let name = tools::systemd::unescape_unit(n) let name = pbs_systemd::unescape_unit(n)
.unwrap_or_else(|_| "<invalid name>".to_owned()); .unwrap_or_else(|_| "<invalid name>".to_owned());
let mut extra = json!({"pid": s.pid, "cid": s.cid}); let mut extra = json!({"pid": s.pid, "cid": s.cid});
@ -297,7 +295,7 @@ impl BlockRestoreDriver for QemuBlockDriver {
fn stop(&self, id: String) -> Async<Result<(), Error>> { fn stop(&self, id: String) -> Async<Result<(), Error>> {
async move { async move {
let name = tools::systemd::escape_unit(&id, false); let name = pbs_systemd::escape_unit(&id, false);
let mut map = VMStateMap::load()?; let mut map = VMStateMap::load()?;
let map_mod = cleanup_map(&mut map.map).await; let map_mod = cleanup_map(&mut map.map).await;
match map.map.get(&name) { match map.map.get(&name) {
@ -327,7 +325,7 @@ impl BlockRestoreDriver for QemuBlockDriver {
match VMStateMap::load_read_only() { match VMStateMap::load_read_only() {
Ok(state) => state Ok(state) => state
.iter() .iter()
.filter_map(|(name, _)| tools::systemd::unescape_unit(&name).ok()) .filter_map(|(name, _)| pbs_systemd::unescape_unit(&name).ok())
.collect(), .collect(),
Err(_) => Vec::new(), Err(_) => Vec::new(),
} }

View File

@ -440,7 +440,7 @@ pub fn send_tape_backup_status(
) -> Result<(), Error> { ) -> Result<(), Error> {
let (fqdn, port) = get_server_url(); let (fqdn, port) = get_server_url();
let duration: crate::tools::systemd::time::TimeSpan = summary.duration.into(); let duration: pbs_systemd::time::TimeSpan = summary.duration.into();
let mut data = json!({ let mut data = json!({
"job": job, "job": job,
"fqdn": fqdn, "fqdn": fqdn,

View File

@ -40,17 +40,16 @@
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
use anyhow::{bail, format_err, Error}; use anyhow::{bail, format_err, Error};
use serde::{Deserialize, Serialize};
use proxmox::tools::fs::{ use proxmox::tools::fs::{
create_path, file_read_optional_string, replace_file, CreateOptions, create_path, file_read_optional_string, replace_file, CreateOptions,
}; };
use serde::{Deserialize, Serialize};
use pbs_systemd::time::{compute_next_event, parse_calendar_event};
use crate::{ use crate::{
backup::{open_backup_lockfile, BackupLockGuard}, backup::{open_backup_lockfile, BackupLockGuard},
tools::systemd::time::{
parse_calendar_event,
compute_next_event,
},
api2::types::JobScheduleStatus, api2::types::JobScheduleStatus,
server::{ server::{
UPID, UPID,

View File

@ -607,7 +607,7 @@ pub struct DeviceLockGuard(std::fs::File);
// Uses systemd escape_unit to compute a file name from `device_path`, the try // Uses systemd escape_unit to compute a file name from `device_path`, the try
// to lock `/var/lock/<name>`. // to lock `/var/lock/<name>`.
fn open_device_lock(device_path: &str) -> Result<std::fs::File, Error> { fn open_device_lock(device_path: &str) -> Result<std::fs::File, Error> {
let lock_name = crate::tools::systemd::escape_unit(device_path, true); let lock_name = pbs_systemd::escape_unit(device_path, true);
let mut path = std::path::PathBuf::from(crate::tape::DRIVE_LOCK_DIR); let mut path = std::path::PathBuf::from(crate::tape::DRIVE_LOCK_DIR);
path.push(lock_name); path.push(lock_name);

View File

@ -39,8 +39,9 @@ use proxmox::tools::{
}, },
}; };
use pbs_systemd::time::compute_next_event;
use crate::{ use crate::{
tools::systemd::time::compute_next_event,
api2::types::{ api2::types::{
MediaSetPolicy, MediaSetPolicy,
RetentionPolicy, RetentionPolicy,

View File

@ -15,6 +15,7 @@ use serde::{Deserialize, Serialize};
use proxmox::tools::Uuid; use proxmox::tools::Uuid;
use pbs_api_types::Fingerprint; use pbs_api_types::Fingerprint;
use pbs_systemd::time::compute_next_event;
use crate::{ use crate::{
backup::BackupLockGuard, backup::BackupLockGuard,
@ -25,7 +26,6 @@ use crate::{
RetentionPolicy, RetentionPolicy,
MediaPoolConfig, MediaPoolConfig,
}, },
tools::systemd::time::compute_next_event,
tape::{ tape::{
MediaId, MediaId,
MediaSet, MediaSet,

View File

@ -1,7 +1,2 @@
pub use pbs_systemd::reload_daemon;
pub use pbs_systemd::time;
pub use pbs_systemd::{disable_unit, enable_unit, reload_unit, start_unit, stop_unit};
pub use pbs_systemd::{escape_unit, unescape_unit};
pub mod config; pub mod config;
pub mod types; pub mod types;

View File

@ -248,10 +248,10 @@ pub enum ServiceStartup {
pub const SYSTEMD_TIMESPAN_SCHEMA: Schema = StringSchema::new( pub const SYSTEMD_TIMESPAN_SCHEMA: Schema = StringSchema::new(
"systemd time span") "systemd time span")
.format(&ApiStringFormat::VerifyFn(super::time::verify_time_span)) .format(&ApiStringFormat::VerifyFn(pbs_systemd::time::verify_time_span))
.schema(); .schema();
pub const SYSTEMD_CALENDAR_EVENT_SCHEMA: Schema = StringSchema::new( pub const SYSTEMD_CALENDAR_EVENT_SCHEMA: Schema = StringSchema::new(
"systemd calendar event") "systemd calendar event")
.format(&ApiStringFormat::VerifyFn(super::time::verify_calendar_event)) .format(&ApiStringFormat::VerifyFn(pbs_systemd::time::verify_calendar_event))
.schema(); .schema();