backup: remove lazy_static dependency

Signed-off-by: Maximiliano Sandoval <m.sandoval@proxmox.com>
This commit is contained in:
Maximiliano Sandoval 2024-08-13 10:44:15 +02:00 committed by Wolfgang Bumiller
parent 8dc1b5abf7
commit 17c82d4a73
12 changed files with 87 additions and 83 deletions

View File

@ -128,7 +128,6 @@ handlebars = "3.0"
hex = "0.4.3"
http = "0.2"
hyper = { version = "0.14", features = [ "full" ] }
lazy_static = "1.4"
libc = "0.2"
log = "0.4.17"
nix = "0.26.1"
@ -180,7 +179,6 @@ handlebars.workspace = true
hex.workspace = true
http.workspace = true
hyper.workspace = true
lazy_static.workspace = true
libc.workspace = true
log.workspace = true
nix.workspace = true

View File

@ -1,12 +1,11 @@
use std::fs;
use std::ops::ControlFlow;
use std::path::Path;
use std::sync::{Arc, Mutex};
use std::sync::{Arc, LazyLock, Mutex};
use std::time::SystemTime;
use anyhow::{bail, format_err, Error};
use hex::FromHex;
use lazy_static::lazy_static;
use serde::{Deserialize, Serialize};
use serde_json::{json, Value};
use tracing::{info, warn};
@ -430,10 +429,8 @@ impl Serialize for ChallengeSchemaWrapper {
}
fn get_cached_challenge_schemas() -> Result<ChallengeSchemaWrapper, Error> {
lazy_static! {
static ref CACHE: Mutex<Option<(Arc<Vec<AcmeChallengeSchema>>, SystemTime)>> =
Mutex::new(None);
}
static CACHE: LazyLock<Mutex<Option<(Arc<Vec<AcmeChallengeSchema>>, SystemTime)>>> =
LazyLock::new(|| Mutex::new(None));
// the actual loading code
let mut last = CACHE.lock().unwrap();

View File

@ -1,3 +1,5 @@
use std::sync::LazyLock;
use ::serde::{Deserialize, Serialize};
use anyhow::{bail, Error};
use serde_json::json;
@ -71,9 +73,8 @@ pub struct DatastoreMountInfo {
)]
/// List systemd datastore mount units.
pub fn list_datastore_mounts() -> Result<Vec<DatastoreMountInfo>, Error> {
lazy_static::lazy_static! {
static ref MOUNT_NAME_REGEX: regex::Regex = regex::Regex::new(r"^mnt-datastore-(.+)\.mount$").unwrap();
}
static MOUNT_NAME_REGEX: LazyLock<regex::Regex> =
LazyLock::new(|| regex::Regex::new(r"^mnt-datastore-(.+)\.mount$").unwrap());
let mut list = Vec::new();

View File

@ -1,9 +1,8 @@
use std::sync::{Arc, Mutex};
use std::sync::{Arc, LazyLock, Mutex};
use ::serde::{Deserialize, Serialize};
use anyhow::Error;
use const_format::concatcp;
use lazy_static::lazy_static;
use openssl::sha;
use regex::Regex;
use serde_json::{json, Value};
@ -46,11 +45,10 @@ pub fn read_etc_resolv_conf() -> Result<Value, Error> {
let data = String::from_utf8(raw)?;
lazy_static! {
static ref DOMAIN_REGEX: Regex = Regex::new(r"^\s*(?:search|domain)\s+(\S+)\s*").unwrap();
static ref SERVER_REGEX: Regex =
Regex::new(concatcp!(r"^\s*nameserver\s+(", IPRE_STR, r")\s*")).unwrap();
}
static DOMAIN_REGEX: LazyLock<Regex> =
LazyLock::new(|| Regex::new(r"^\s*(?:search|domain)\s+(\S+)\s*").unwrap());
static SERVER_REGEX: LazyLock<Regex> =
LazyLock::new(|| Regex::new(concatcp!(r"^\s*nameserver\s+(", IPRE_STR, r")\s*")).unwrap());
let mut options = String::new();
@ -131,9 +129,7 @@ pub fn update_dns(
delete: Option<Vec<DeletableProperty>>,
digest: Option<String>,
) -> Result<Value, Error> {
lazy_static! {
static ref MUTEX: Arc<Mutex<()>> = Arc::new(Mutex::new(()));
}
static MUTEX: LazyLock<Arc<Mutex<()>>> = LazyLock::new(|| Arc::new(Mutex::new(())));
let _guard = MUTEX.lock();

View File

@ -1,5 +1,6 @@
use std::sync::LazyLock;
use anyhow::Error;
use lazy_static::lazy_static;
use serde::{Deserialize, Serialize};
use serde_json::Value;
@ -15,9 +16,7 @@ pub const PLUGIN_ID_SCHEMA: Schema = StringSchema::new("ACME Challenge Plugin ID
.max_length(32)
.schema();
lazy_static! {
pub static ref CONFIG: SectionConfig = init();
}
pub static CONFIG: LazyLock<SectionConfig> = LazyLock::new(init);
#[api(
properties: {

View File

@ -2,6 +2,7 @@
//! tapes
use std::collections::HashMap;
use std::sync::LazyLock;
use endian_trait::Endian;
use serde::{Deserialize, Serialize};
@ -56,22 +57,48 @@ pub const PROXMOX_BACKUP_CATALOG_ARCHIVE_MAGIC_1_0: [u8; 8] =
// openssl::sha::sha256(b"Proxmox Backup Catalog Archive v1.1")[0..8];
pub const PROXMOX_BACKUP_CATALOG_ARCHIVE_MAGIC_1_1: [u8; 8] = [179, 236, 113, 240, 173, 236, 2, 96];
lazy_static::lazy_static! {
// Map content magic numbers to human readable names.
static ref PROXMOX_TAPE_CONTENT_NAME: HashMap<&'static [u8;8], &'static str> = {
// Map content magic numbers to human readable names.
static PROXMOX_TAPE_CONTENT_NAME: LazyLock<HashMap<&'static [u8; 8], &'static str>> =
LazyLock::new(|| {
let mut map = HashMap::new();
map.insert(&PROXMOX_BACKUP_MEDIA_LABEL_MAGIC_1_0, "Proxmox Backup Tape Label v1.0");
map.insert(&PROXMOX_BACKUP_MEDIA_SET_LABEL_MAGIC_1_0, "Proxmox Backup MediaSet Label v1.0");
map.insert(&PROXMOX_BACKUP_CHUNK_ARCHIVE_MAGIC_1_0, "Proxmox Backup Chunk Archive v1.0");
map.insert(&PROXMOX_BACKUP_CHUNK_ARCHIVE_MAGIC_1_1, "Proxmox Backup Chunk Archive v1.1");
map.insert(&PROXMOX_BACKUP_SNAPSHOT_ARCHIVE_MAGIC_1_0, "Proxmox Backup Snapshot Archive v1.0");
map.insert(&PROXMOX_BACKUP_SNAPSHOT_ARCHIVE_MAGIC_1_1, "Proxmox Backup Snapshot Archive v1.1");
map.insert(&PROXMOX_BACKUP_SNAPSHOT_ARCHIVE_MAGIC_1_2, "Proxmox Backup Snapshot Archive v1.2");
map.insert(&PROXMOX_BACKUP_CATALOG_ARCHIVE_MAGIC_1_0, "Proxmox Backup Catalog Archive v1.0");
map.insert(&PROXMOX_BACKUP_CATALOG_ARCHIVE_MAGIC_1_1, "Proxmox Backup Catalog Archive v1.1");
map.insert(
&PROXMOX_BACKUP_MEDIA_LABEL_MAGIC_1_0,
"Proxmox Backup Tape Label v1.0",
);
map.insert(
&PROXMOX_BACKUP_MEDIA_SET_LABEL_MAGIC_1_0,
"Proxmox Backup MediaSet Label v1.0",
);
map.insert(
&PROXMOX_BACKUP_CHUNK_ARCHIVE_MAGIC_1_0,
"Proxmox Backup Chunk Archive v1.0",
);
map.insert(
&PROXMOX_BACKUP_CHUNK_ARCHIVE_MAGIC_1_1,
"Proxmox Backup Chunk Archive v1.1",
);
map.insert(
&PROXMOX_BACKUP_SNAPSHOT_ARCHIVE_MAGIC_1_0,
"Proxmox Backup Snapshot Archive v1.0",
);
map.insert(
&PROXMOX_BACKUP_SNAPSHOT_ARCHIVE_MAGIC_1_1,
"Proxmox Backup Snapshot Archive v1.1",
);
map.insert(
&PROXMOX_BACKUP_SNAPSHOT_ARCHIVE_MAGIC_1_2,
"Proxmox Backup Snapshot Archive v1.2",
);
map.insert(
&PROXMOX_BACKUP_CATALOG_ARCHIVE_MAGIC_1_0,
"Proxmox Backup Catalog Archive v1.0",
);
map.insert(
&PROXMOX_BACKUP_CATALOG_ARCHIVE_MAGIC_1_1,
"Proxmox Backup Catalog Archive v1.1",
);
map
};
}
});
/// Map content magic numbers to human readable names.
pub fn proxmox_tape_magic_to_text(magic: &[u8; 8]) -> Option<String> {

View File

@ -1,19 +1,17 @@
use std::collections::HashSet;
use std::os::unix::fs::MetadataExt;
use std::sync::LazyLock;
use anyhow::Error;
use lazy_static::lazy_static;
use serde_json::Value;
use super::LsblkInfo;
lazy_static! {
static ref LVM_UUIDS: HashSet<&'static str> = {
let mut set = HashSet::new();
set.insert("e6d6d379-f507-44c2-a23c-238f2a3df928");
set
};
}
static LVM_UUIDS: LazyLock<HashSet<&'static str>> = LazyLock::new(|| {
let mut set = HashSet::new();
set.insert("e6d6d379-f507-44c2-a23c-238f2a3df928");
set
});
/// Get set of devices used by LVM (pvs).
///

View File

@ -6,7 +6,7 @@ use std::io;
use std::os::unix::ffi::{OsStrExt, OsStringExt};
use std::os::unix::fs::MetadataExt;
use std::path::{Path, PathBuf};
use std::sync::Arc;
use std::sync::{Arc, LazyLock};
use anyhow::{bail, format_err, Error};
use libc::dev_t;
@ -32,10 +32,8 @@ pub use lvm::*;
mod smart;
pub use smart::*;
lazy_static::lazy_static! {
static ref ISCSI_PATH_REGEX: regex::Regex =
regex::Regex::new(r"host[^/]*/session[^/]*").unwrap();
}
static ISCSI_PATH_REGEX: LazyLock<regex::Regex> =
LazyLock::new(|| regex::Regex::new(r"host[^/]*/session[^/]*").unwrap());
/// Disk management context.
///

View File

@ -1,8 +1,8 @@
use std::collections::{HashMap, HashSet};
use std::sync::LazyLock;
use ::serde::{Deserialize, Serialize};
use anyhow::{bail, Error};
use lazy_static::lazy_static;
use proxmox_schema::api;
@ -224,7 +224,5 @@ static WEAROUT_FIELD_ORDER: &[&str] = &[
"Perc_Rated_Life_Used",
];
lazy_static! {
static ref WEAROUT_FIELD_NAMES: HashSet<&'static str> =
WEAROUT_FIELD_ORDER.iter().cloned().collect();
}
static WEAROUT_FIELD_NAMES: LazyLock<HashSet<&'static str>> =
LazyLock::new(|| WEAROUT_FIELD_ORDER.iter().cloned().collect());

View File

@ -1,23 +1,20 @@
use std::collections::HashSet;
use std::os::unix::fs::MetadataExt;
use std::path::PathBuf;
use std::sync::{Arc, Mutex};
use std::sync::{Arc, LazyLock, Mutex};
use anyhow::{bail, Error};
use lazy_static::lazy_static;
use proxmox_schema::const_regex;
use super::*;
lazy_static! {
static ref ZFS_UUIDS: HashSet<&'static str> = {
let mut set = HashSet::new();
set.insert("6a898cc3-1dd2-11b2-99a6-080020736631"); // apple
set.insert("516e7cba-6ecf-11d6-8ff8-00022d09712b"); // bsd
set
};
}
static ZFS_UUIDS: LazyLock<HashSet<&'static str>> = LazyLock::new(|| {
let mut set = HashSet::new();
set.insert("6a898cc3-1dd2-11b2-99a6-080020736631"); // apple
set.insert("516e7cba-6ecf-11d6-8ff8-00022d09712b"); // bsd
set
});
fn get_pool_from_dataset(dataset: &str) -> &str {
if let Some(idx) = dataset.find('/') {
@ -100,10 +97,8 @@ const_regex! {
OBJSET_REGEX = r"^objset-0x[a-fA-F0-9]+$";
}
lazy_static::lazy_static! {
pub static ref ZFS_DATASET_OBJSET_MAP: Arc<Mutex<HashMap<String, (String, String)>>> =
Arc::new(Mutex::new(HashMap::new()));
}
pub static ZFS_DATASET_OBJSET_MAP: LazyLock<Arc<Mutex<HashMap<String, (String, String)>>>> =
LazyLock::new(|| Arc::new(Mutex::new(HashMap::new())));
// parses /proc/spl/kstat/zfs/POOL/objset-ID files
// they have the following format:

View File

@ -1,5 +1,6 @@
use std::sync::LazyLock;
use anyhow::Error;
use lazy_static::lazy_static;
use super::types::*;
@ -8,11 +9,9 @@ use proxmox_section_config::{SectionConfig, SectionConfigData, SectionConfigPlug
use proxmox_sys::{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();
}
pub static SERVICE_CONFIG: LazyLock<SectionConfig> = LazyLock::new(init_service);
pub static TIMER_CONFIG: LazyLock<SectionConfig> = LazyLock::new(init_timer);
pub static MOUNT_CONFIG: LazyLock<SectionConfig> = LazyLock::new(init_mount);
fn init_service() -> SectionConfig {
let mut config = SectionConfig::with_systemd_syntax(&SYSTEMD_SECTION_NAME_SCHEMA);

View File

@ -2,7 +2,7 @@
use std::collections::HashMap;
use std::net::{IpAddr, Ipv4Addr, SocketAddr};
use std::sync::{Arc, Mutex};
use std::sync::{Arc, LazyLock, Mutex};
use std::time::Instant;
use anyhow::Error;
@ -21,11 +21,9 @@ use crate::tools::SharedRateLimiter;
pub type SharedRateLimit = Arc<dyn ShareableRateLimit>;
lazy_static::lazy_static! {
/// Shared traffic control cache singleton.
pub static ref TRAFFIC_CONTROL_CACHE: Arc<Mutex<TrafficControlCache>> =
Arc::new(Mutex::new(TrafficControlCache::new()));
}
/// Shared traffic control cache singleton.
pub static TRAFFIC_CONTROL_CACHE: LazyLock<Arc<Mutex<TrafficControlCache>>> =
LazyLock::new(|| Arc::new(Mutex::new(TrafficControlCache::new())));
struct ParsedTcRule {
config: TrafficControlRule, // original rule config