From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) by lore.proxmox.com (Postfix) with ESMTPS id 83DEC1FF161 for ; Tue, 13 Aug 2024 10:45:05 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id C6FA33DFB4; Tue, 13 Aug 2024 10:45:19 +0200 (CEST) From: Maximiliano Sandoval To: pbs-devel@lists.proxmox.com Date: Tue, 13 Aug 2024 10:44:10 +0200 Message-Id: <20240813084416.177460-5-m.sandoval@proxmox.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240813084416.177460-1-m.sandoval@proxmox.com> References: <20240813084416.177460-1-m.sandoval@proxmox.com> MIME-Version: 1.0 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.117 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record T_SCC_BODY_TEXT_LINE -0.01 - Subject: [pbs-devel] [PATCH backup 05/11] config: remove lazy_static dependency X-BeenThere: pbs-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox Backup Server development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Proxmox Backup Server development discussion Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: pbs-devel-bounces@lists.proxmox.com Sender: "pbs-devel" Signed-off-by: Maximiliano Sandoval --- pbs-config/Cargo.toml | 2 +- pbs-config/src/acl.rs | 49 +++++++++++----------- pbs-config/src/cached_user_info.rs | 13 +++--- pbs-config/src/datastore.rs | 9 ++-- pbs-config/src/domains.rs | 6 +-- pbs-config/src/drive.rs | 8 ++-- pbs-config/src/media_pool.rs | 8 ++-- pbs-config/src/metrics.rs | 6 +-- pbs-config/src/network/helper.rs | 36 +++++++--------- pbs-config/src/network/lexer.rs | 67 ++++++++++++++---------------- pbs-config/src/network/mod.rs | 17 ++++---- pbs-config/src/network/parser.rs | 7 ++-- pbs-config/src/prune.rs | 6 +-- pbs-config/src/remote.rs | 6 +-- pbs-config/src/sync.rs | 6 +-- pbs-config/src/tape_job.rs | 6 +-- pbs-config/src/traffic_control.rs | 8 ++-- pbs-config/src/user.rs | 17 ++++---- pbs-config/src/verify.rs | 6 +-- 19 files changed, 124 insertions(+), 159 deletions(-) diff --git a/pbs-config/Cargo.toml b/pbs-config/Cargo.toml index ac639a8e..12d0eb3d 100644 --- a/pbs-config/Cargo.toml +++ b/pbs-config/Cargo.toml @@ -4,11 +4,11 @@ version = "0.1.0" authors.workspace = true edition.workspace = true description = "Configuration file management for PBS" +rust-version.workspace = true [dependencies] anyhow.workspace = true const_format.workspace = true -lazy_static.workspace = true libc.workspace = true nix.workspace = true once_cell.workspace = true diff --git a/pbs-config/src/acl.rs b/pbs-config/src/acl.rs index 8b6215ef..4ce4c13c 100644 --- a/pbs-config/src/acl.rs +++ b/pbs-config/src/acl.rs @@ -2,37 +2,36 @@ use std::collections::{BTreeMap, BTreeSet, HashMap}; use std::io::Write; use std::path::{Path, PathBuf}; use std::str::FromStr; -use std::sync::{Arc, RwLock}; +use std::sync::{Arc, LazyLock, RwLock}; use anyhow::{bail, Error}; -use lazy_static::lazy_static; - use proxmox_schema::{ApiStringFormat, ApiType, Schema, StringSchema}; use pbs_api_types::{Authid, Role, Userid, ROLE_NAME_NO_ACCESS}; use crate::{open_backup_lockfile, replace_backup_config, BackupLockGuard}; -lazy_static! { - /// Map of pre-defined [Roles](Role) to their associated [privileges](PRIVILEGES) combination - /// and description. - pub static ref ROLE_NAMES: HashMap<&'static str, (u64, &'static str)> = { - let mut map = HashMap::new(); - - let list = match Role::API_SCHEMA { - Schema::String(StringSchema { format: Some(ApiStringFormat::Enum(list)), .. }) => list, - _ => unreachable!(), - }; +/// Map of pre-defined [Roles](Role) to their associated [privileges](PRIVILEGES) combination +/// and description. +pub static ROLE_NAMES: LazyLock> = LazyLock::new(|| { + let mut map = HashMap::new(); + + let list = match Role::API_SCHEMA { + Schema::String(StringSchema { + format: Some(ApiStringFormat::Enum(list)), + .. + }) => list, + _ => unreachable!(), + }; - for entry in list.iter() { - let privs: u64 = Role::from_str(entry.value).unwrap() as u64; - map.insert(entry.value, (privs, entry.description)); - } + for entry in list.iter() { + let privs: u64 = Role::from_str(entry.value).unwrap() as u64; + map.insert(entry.value, (privs, entry.description)); + } - map - }; -} + map +}); pub fn split_acl_path(path: &str) -> Vec<&str> { let items = path.split('/'); @@ -722,13 +721,13 @@ pub fn cached_config() -> Result, Error> { last_mtime_nsec: i64, } - lazy_static! { - static ref CACHED_CONFIG: RwLock = RwLock::new(ConfigCache { + static CACHED_CONFIG: LazyLock> = LazyLock::new(|| { + RwLock::new(ConfigCache { data: None, last_mtime: 0, - last_mtime_nsec: 0 - }); - } + last_mtime_nsec: 0, + }) + }); let stat = match nix::sys::stat::stat(ACL_CFG_FILENAME) { Ok(stat) => Some(stat), diff --git a/pbs-config/src/cached_user_info.rs b/pbs-config/src/cached_user_info.rs index f8ecb6c1..e1cd2d68 100644 --- a/pbs-config/src/cached_user_info.rs +++ b/pbs-config/src/cached_user_info.rs @@ -1,9 +1,8 @@ //! Cached user info for fast ACL permission checks -use std::sync::{Arc, RwLock}; +use std::sync::{Arc, LazyLock, RwLock}; use anyhow::{bail, Error}; -use lazy_static::lazy_static; use proxmox_router::UserInformation; use proxmox_section_config::SectionConfigData; @@ -26,13 +25,13 @@ struct ConfigCache { last_user_cache_generation: usize, } -lazy_static! { - static ref CACHED_CONFIG: RwLock = RwLock::new(ConfigCache { +static CACHED_CONFIG: LazyLock> = LazyLock::new(|| { + RwLock::new(ConfigCache { data: None, last_update: 0, - last_user_cache_generation: 0 - }); -} + last_user_cache_generation: 0, + }) +}); impl CachedUserInfo { /// Returns a cached instance (up to 5 seconds old). diff --git a/pbs-config/src/datastore.rs b/pbs-config/src/datastore.rs index 5844a174..dc5bb3da 100644 --- a/pbs-config/src/datastore.rs +++ b/pbs-config/src/datastore.rs @@ -1,6 +1,7 @@ -use anyhow::Error; -use lazy_static::lazy_static; use std::collections::HashMap; +use std::sync::LazyLock; + +use anyhow::Error; use proxmox_schema::{AllOfSchema, ApiType}; use proxmox_section_config::{SectionConfig, SectionConfigData, SectionConfigPlugin}; @@ -9,9 +10,7 @@ use pbs_api_types::{DataStoreConfig, DATASTORE_SCHEMA}; use crate::{open_backup_lockfile, replace_backup_config, BackupLockGuard, ConfigVersionCache}; -lazy_static! { - pub static ref CONFIG: SectionConfig = init(); -} +pub static CONFIG: LazyLock = LazyLock::new(init); fn init() -> SectionConfig { const OBJ_SCHEMA: &AllOfSchema = DataStoreConfig::API_SCHEMA.unwrap_all_of_schema(); diff --git a/pbs-config/src/domains.rs b/pbs-config/src/domains.rs index 5b6ce480..32bd967a 100644 --- a/pbs-config/src/domains.rs +++ b/pbs-config/src/domains.rs @@ -1,7 +1,7 @@ use std::collections::HashMap; +use std::sync::LazyLock; use anyhow::Error; -use lazy_static::lazy_static; use pbs_buildcfg::configdir; use proxmox_schema::{ApiType, ObjectSchema}; @@ -10,9 +10,7 @@ use proxmox_section_config::{SectionConfig, SectionConfigData, SectionConfigPlug use crate::{open_backup_lockfile, replace_backup_config, BackupLockGuard}; use pbs_api_types::{AdRealmConfig, LdapRealmConfig, OpenIdRealmConfig, REALM_ID_SCHEMA}; -lazy_static! { - pub static ref CONFIG: SectionConfig = init(); -} +pub static CONFIG: LazyLock = LazyLock::new(init); fn init() -> SectionConfig { const AD_SCHEMA: &ObjectSchema = AdRealmConfig::API_SCHEMA.unwrap_object_schema(); diff --git a/pbs-config/src/drive.rs b/pbs-config/src/drive.rs index 67ffc554..4e2befd2 100644 --- a/pbs-config/src/drive.rs +++ b/pbs-config/src/drive.rs @@ -12,9 +12,9 @@ //! [SectionConfig]: proxmox::api::section_config::SectionConfig use std::collections::HashMap; +use std::sync::LazyLock; use anyhow::{bail, Error}; -use lazy_static::lazy_static; use proxmox_schema::*; use proxmox_section_config::{SectionConfig, SectionConfigData, SectionConfigPlugin}; @@ -23,10 +23,8 @@ use crate::{open_backup_lockfile, replace_backup_config, BackupLockGuard}; use pbs_api_types::{LtoTapeDrive, ScsiTapeChanger, VirtualTapeDrive, DRIVE_NAME_SCHEMA}; -lazy_static! { - /// Static [`SectionConfig`] to access parser/writer functions. - pub static ref CONFIG: SectionConfig = init(); -} +/// Static [`SectionConfig`] to access parser/writer functions. +pub static CONFIG: LazyLock = LazyLock::new(init); fn init() -> SectionConfig { let mut config = SectionConfig::new(&DRIVE_NAME_SCHEMA); diff --git a/pbs-config/src/media_pool.rs b/pbs-config/src/media_pool.rs index 3b6448c3..3bf15188 100644 --- a/pbs-config/src/media_pool.rs +++ b/pbs-config/src/media_pool.rs @@ -7,9 +7,9 @@ //! [SectionConfig]: proxmox_section_config::SectionConfig use std::collections::HashMap; +use std::sync::LazyLock; use anyhow::Error; -use lazy_static::lazy_static; use proxmox_schema::*; use proxmox_section_config::{SectionConfig, SectionConfigData, SectionConfigPlugin}; @@ -18,10 +18,8 @@ use pbs_api_types::{MediaPoolConfig, MEDIA_POOL_NAME_SCHEMA}; use crate::{open_backup_lockfile, replace_backup_config, BackupLockGuard}; -lazy_static! { - /// Static [`SectionConfig`] to access parser/writer functions. - pub static ref CONFIG: SectionConfig = init(); -} +/// Static [`SectionConfig`] to access parser/writer functions. +pub static CONFIG: LazyLock = LazyLock::new(init); fn init() -> SectionConfig { let mut config = SectionConfig::new(&MEDIA_POOL_NAME_SCHEMA); diff --git a/pbs-config/src/metrics.rs b/pbs-config/src/metrics.rs index 78e683e3..1b93f70c 100644 --- a/pbs-config/src/metrics.rs +++ b/pbs-config/src/metrics.rs @@ -1,7 +1,7 @@ use std::collections::HashMap; +use std::sync::LazyLock; use anyhow::Error; -use lazy_static::lazy_static; use proxmox_schema::*; use proxmox_section_config::{SectionConfig, SectionConfigData, SectionConfigPlugin}; @@ -10,9 +10,7 @@ use pbs_api_types::{InfluxDbHttp, InfluxDbUdp, METRIC_SERVER_ID_SCHEMA}; use crate::{open_backup_lockfile, BackupLockGuard}; -lazy_static! { - pub static ref CONFIG: SectionConfig = init(); -} +pub static CONFIG: LazyLock = LazyLock::new(init); fn init() -> SectionConfig { let mut config = SectionConfig::new(&METRIC_SERVER_ID_SCHEMA); diff --git a/pbs-config/src/network/helper.rs b/pbs-config/src/network/helper.rs index 9e195d71..87a0e24f 100644 --- a/pbs-config/src/network/helper.rs +++ b/pbs-config/src/network/helper.rs @@ -2,10 +2,10 @@ use std::collections::HashMap; use std::os::unix::io::{AsRawFd, FromRawFd, OwnedFd}; use std::path::Path; use std::process::Command; +use std::sync::LazyLock; use anyhow::{bail, format_err, Error}; use const_format::concatcp; -use lazy_static::lazy_static; use nix::ioctl_read_bad; use nix::sys::socket::{socket, AddressFamily, SockFlag, SockType}; use regex::Regex; @@ -48,16 +48,14 @@ pub static IPV4_REVERSE_MASK: &[&str] = &[ "255.255.255.255", ]; -lazy_static! { - pub static ref IPV4_MASK_HASH_LOCALNET: HashMap<&'static str, u8> = { - let mut map = HashMap::new(); - #[allow(clippy::needless_range_loop)] - for i in 0..IPV4_REVERSE_MASK.len() { - map.insert(IPV4_REVERSE_MASK[i], i as u8); - } - map - }; -} +pub static IPV4_MASK_HASH_LOCALNET: LazyLock> = LazyLock::new(|| { + let mut map = HashMap::new(); + #[allow(clippy::needless_range_loop)] + for i in 0..IPV4_REVERSE_MASK.len() { + map.insert(IPV4_REVERSE_MASK[i], i as u8); + } + map +}); pub fn parse_cidr(cidr: &str) -> Result<(String, u8, bool), Error> { let (address, mask, is_v6) = parse_address_or_cidr(cidr)?; @@ -92,12 +90,10 @@ pub fn check_netmask(mask: u8, is_v6: bool) -> Result<(), Error> { pub fn parse_address_or_cidr(cidr: &str) -> Result<(String, Option, bool), Error> { // NOTE: This is NOT the same regex as in proxmox-schema as this one has capture groups for // the addresses vs cidr portions! - lazy_static! { - pub static ref CIDR_V4_REGEX: Regex = - Regex::new(concatcp!(r"^(", IPV4RE_STR, r")(?:/(\d{1,2}))?$")).unwrap(); - pub static ref CIDR_V6_REGEX: Regex = - Regex::new(concatcp!(r"^(", IPV6RE_STR, r")(?:/(\d{1,3}))?$")).unwrap(); - } + pub static CIDR_V4_REGEX: LazyLock = + LazyLock::new(|| Regex::new(concatcp!(r"^(", IPV4RE_STR, r")(?:/(\d{1,2}))?$")).unwrap()); + pub static CIDR_V6_REGEX: LazyLock = + LazyLock::new(|| Regex::new(concatcp!(r"^(", IPV6RE_STR, r")(?:/(\d{1,3}))?$")).unwrap()); if let Some(caps) = CIDR_V4_REGEX.captures(cidr) { let address = &caps[1]; @@ -133,9 +129,9 @@ pub fn get_network_interfaces() -> Result, Error> { ioctl_read_bad!(get_interface_flags, libc::SIOCGIFFLAGS, ifreq); - lazy_static! { - static ref IFACE_LINE_REGEX: Regex = Regex::new(r"^\s*([^:\s]+):").unwrap(); - } + static IFACE_LINE_REGEX: LazyLock = + LazyLock::new(|| Regex::new(r"^\s*([^:\s]+):").unwrap()); + let raw = std::fs::read_to_string(PROC_NET_DEV) .map_err(|err| format_err!("unable to read {} - {}", PROC_NET_DEV, err))?; diff --git a/pbs-config/src/network/lexer.rs b/pbs-config/src/network/lexer.rs index d0b7d8cd..6a20f009 100644 --- a/pbs-config/src/network/lexer.rs +++ b/pbs-config/src/network/lexer.rs @@ -1,8 +1,7 @@ use std::collections::{HashMap, VecDeque}; use std::io::BufRead; use std::iter::Iterator; - -use lazy_static::lazy_static; +use std::sync::LazyLock; #[derive(Debug, Copy, Clone, Eq, PartialEq)] pub enum Token { @@ -33,39 +32,37 @@ pub enum Token { EOF, } -lazy_static! { - static ref KEYWORDS: HashMap<&'static str, Token> = { - let mut map = HashMap::new(); - map.insert("address", Token::Address); - map.insert("auto", Token::Auto); - map.insert("dhcp", Token::DHCP); - map.insert("gateway", Token::Gateway); - map.insert("inet", Token::Inet); - map.insert("inet6", Token::Inet6); - map.insert("iface", Token::Iface); - map.insert("loopback", Token::Loopback); - map.insert("manual", Token::Manual); - map.insert("netmask", Token::Netmask); - map.insert("static", Token::Static); - map.insert("mtu", Token::MTU); - map.insert("bridge-ports", Token::BridgePorts); - map.insert("bridge_ports", Token::BridgePorts); - map.insert("bridge-vlan-aware", Token::BridgeVlanAware); - map.insert("bridge_vlan_aware", Token::BridgeVlanAware); - map.insert("vlan-id", Token::VlanId); - map.insert("vlan_id", Token::VlanId); - map.insert("vlan-raw-device", Token::VlanRawDevice); - map.insert("vlan_raw_device", Token::VlanRawDevice); - map.insert("bond-slaves", Token::BondSlaves); - map.insert("bond_slaves", Token::BondSlaves); - map.insert("bond-mode", Token::BondMode); - map.insert("bond-primary", Token::BondPrimary); - map.insert("bond_primary", Token::BondPrimary); - map.insert("bond_xmit_hash_policy", Token::BondXmitHashPolicy); - map.insert("bond-xmit-hash-policy", Token::BondXmitHashPolicy); - map - }; -} +static KEYWORDS: LazyLock> = LazyLock::new(|| { + let mut map = HashMap::new(); + map.insert("address", Token::Address); + map.insert("auto", Token::Auto); + map.insert("dhcp", Token::DHCP); + map.insert("gateway", Token::Gateway); + map.insert("inet", Token::Inet); + map.insert("inet6", Token::Inet6); + map.insert("iface", Token::Iface); + map.insert("loopback", Token::Loopback); + map.insert("manual", Token::Manual); + map.insert("netmask", Token::Netmask); + map.insert("static", Token::Static); + map.insert("mtu", Token::MTU); + map.insert("bridge-ports", Token::BridgePorts); + map.insert("bridge_ports", Token::BridgePorts); + map.insert("bridge-vlan-aware", Token::BridgeVlanAware); + map.insert("bridge_vlan_aware", Token::BridgeVlanAware); + map.insert("vlan-id", Token::VlanId); + map.insert("vlan_id", Token::VlanId); + map.insert("vlan-raw-device", Token::VlanRawDevice); + map.insert("vlan_raw_device", Token::VlanRawDevice); + map.insert("bond-slaves", Token::BondSlaves); + map.insert("bond_slaves", Token::BondSlaves); + map.insert("bond-mode", Token::BondMode); + map.insert("bond-primary", Token::BondPrimary); + map.insert("bond_primary", Token::BondPrimary); + map.insert("bond_xmit_hash_policy", Token::BondXmitHashPolicy); + map.insert("bond-xmit-hash-policy", Token::BondXmitHashPolicy); + map +}); pub struct Lexer { input: R, diff --git a/pbs-config/src/network/mod.rs b/pbs-config/src/network/mod.rs index c5b7775c..21ad9943 100644 --- a/pbs-config/src/network/mod.rs +++ b/pbs-config/src/network/mod.rs @@ -1,8 +1,8 @@ use std::collections::{BTreeMap, HashMap, HashSet}; use std::io::Write; +use std::sync::LazyLock; use anyhow::{bail, format_err, Error}; -use lazy_static::lazy_static; use regex::Regex; use serde::de::{value, Deserialize, IntoDeserializer}; @@ -23,11 +23,11 @@ use pbs_api_types::{ use crate::{open_backup_lockfile, BackupLockGuard}; -lazy_static! { - static ref PHYSICAL_NIC_REGEX: Regex = Regex::new(r"^(?:eth\d+|en[^:.]+|ib\d+)$").unwrap(); - static ref VLAN_INTERFACE_REGEX: Regex = - Regex::new(r"^(?P\S+)\.(?P\d+)|vlan(?P\d+)$").unwrap(); -} +static PHYSICAL_NIC_REGEX: LazyLock = + LazyLock::new(|| Regex::new(r"^(?:eth\d+|en[^:.]+|ib\d+)$").unwrap()); +static VLAN_INTERFACE_REGEX: LazyLock = LazyLock::new(|| { + Regex::new(r"^(?P\S+)\.(?P\d+)|vlan(?P\d+)$").unwrap() +}); pub fn is_physical_nic(iface: &str) -> bool { PHYSICAL_NIC_REGEX.is_match(iface) @@ -366,9 +366,8 @@ impl NetworkConfig { /// Check if bridge ports exists fn check_bridge_ports(&self) -> Result<(), Error> { - lazy_static! { - static ref VLAN_INTERFACE_REGEX: Regex = Regex::new(r"^(\S+)\.(\d+)$").unwrap(); - } + static VLAN_INTERFACE_REGEX: LazyLock = + LazyLock::new(|| Regex::new(r"^(\S+)\.(\d+)$").unwrap()); for (iface, interface) in self.interfaces.iter() { if let Some(ports) = &interface.bridge_ports { diff --git a/pbs-config/src/network/parser.rs b/pbs-config/src/network/parser.rs index 7498dd35..a5d05c6e 100644 --- a/pbs-config/src/network/parser.rs +++ b/pbs-config/src/network/parser.rs @@ -3,9 +3,9 @@ use crate::network::VLAN_INTERFACE_REGEX; use std::collections::{HashMap, HashSet}; use std::io::BufRead; use std::iter::{Iterator, Peekable}; +use std::sync::LazyLock; use anyhow::{bail, format_err, Error}; -use lazy_static::lazy_static; use regex::Regex; use super::helper::*; @@ -536,9 +536,8 @@ impl NetworkParser { } } - lazy_static! { - static ref INTERFACE_ALIAS_REGEX: Regex = Regex::new(r"^\S+:\d+$").unwrap(); - } + static INTERFACE_ALIAS_REGEX: LazyLock = + LazyLock::new(|| Regex::new(r"^\S+:\d+$").unwrap()); if let Some(existing_interfaces) = existing_interfaces { for (iface, active) in existing_interfaces.iter() { diff --git a/pbs-config/src/prune.rs b/pbs-config/src/prune.rs index 21e52ffc..14a95404 100644 --- a/pbs-config/src/prune.rs +++ b/pbs-config/src/prune.rs @@ -1,7 +1,7 @@ use std::collections::HashMap; use anyhow::Error; -use lazy_static::lazy_static; +use std::sync::LazyLock; use proxmox_schema::*; use proxmox_section_config::{SectionConfig, SectionConfigData, SectionConfigPlugin}; @@ -10,9 +10,7 @@ use pbs_api_types::{PruneJobConfig, JOB_ID_SCHEMA}; use crate::{open_backup_lockfile, replace_backup_config, BackupLockGuard}; -lazy_static! { - pub static ref CONFIG: SectionConfig = init(); -} +pub static CONFIG: LazyLock = LazyLock::new(init); fn init() -> SectionConfig { const OBJ_SCHEMA: &AllOfSchema = PruneJobConfig::API_SCHEMA.unwrap_all_of_schema(); diff --git a/pbs-config/src/remote.rs b/pbs-config/src/remote.rs index 9cbd1321..26b21751 100644 --- a/pbs-config/src/remote.rs +++ b/pbs-config/src/remote.rs @@ -1,7 +1,7 @@ use std::collections::HashMap; +use std::sync::LazyLock; use anyhow::Error; -use lazy_static::lazy_static; use proxmox_schema::*; use proxmox_section_config::{SectionConfig, SectionConfigData, SectionConfigPlugin}; @@ -10,9 +10,7 @@ use pbs_api_types::{Remote, REMOTE_ID_SCHEMA}; use crate::{open_backup_lockfile, BackupLockGuard}; -lazy_static! { - pub static ref CONFIG: SectionConfig = init(); -} +pub static CONFIG: LazyLock = LazyLock::new(init); fn init() -> SectionConfig { let obj_schema = match Remote::API_SCHEMA { diff --git a/pbs-config/src/sync.rs b/pbs-config/src/sync.rs index 6d27c123..45453abb 100644 --- a/pbs-config/src/sync.rs +++ b/pbs-config/src/sync.rs @@ -1,7 +1,7 @@ use std::collections::HashMap; +use std::sync::LazyLock; use anyhow::Error; -use lazy_static::lazy_static; use proxmox_schema::{ApiType, Schema}; use proxmox_section_config::{SectionConfig, SectionConfigData, SectionConfigPlugin}; @@ -10,9 +10,7 @@ use pbs_api_types::{SyncJobConfig, JOB_ID_SCHEMA}; use crate::{open_backup_lockfile, replace_backup_config, BackupLockGuard}; -lazy_static! { - pub static ref CONFIG: SectionConfig = init(); -} +pub static CONFIG: LazyLock = LazyLock::new(init); fn init() -> SectionConfig { let obj_schema = match SyncJobConfig::API_SCHEMA { diff --git a/pbs-config/src/tape_job.rs b/pbs-config/src/tape_job.rs index 75ace6c7..66e4a797 100644 --- a/pbs-config/src/tape_job.rs +++ b/pbs-config/src/tape_job.rs @@ -1,6 +1,6 @@ use anyhow::Error; -use lazy_static::lazy_static; use std::collections::HashMap; +use std::sync::LazyLock; use proxmox_schema::{ApiType, Schema}; use proxmox_section_config::{SectionConfig, SectionConfigData, SectionConfigPlugin}; @@ -9,9 +9,7 @@ use pbs_api_types::{TapeBackupJobConfig, JOB_ID_SCHEMA}; use crate::{open_backup_lockfile, replace_backup_config, BackupLockGuard}; -lazy_static! { - pub static ref CONFIG: SectionConfig = init(); -} +pub static CONFIG: LazyLock = LazyLock::new(init); fn init() -> SectionConfig { let obj_schema = match TapeBackupJobConfig::API_SCHEMA { diff --git a/pbs-config/src/traffic_control.rs b/pbs-config/src/traffic_control.rs index 0826be83..4ae1000d 100644 --- a/pbs-config/src/traffic_control.rs +++ b/pbs-config/src/traffic_control.rs @@ -1,8 +1,8 @@ //! Traffic Control Settings (Network rate limits) use std::collections::HashMap; +use std::sync::LazyLock; use anyhow::Error; -use lazy_static::lazy_static; use proxmox_schema::{ApiType, Schema}; @@ -13,10 +13,8 @@ use proxmox_section_config::{SectionConfig, SectionConfigData, SectionConfigPlug use crate::ConfigVersionCache; use crate::{open_backup_lockfile, replace_backup_config, BackupLockGuard}; -lazy_static! { - /// Static [`SectionConfig`] to access parser/writer functions. - pub static ref CONFIG: SectionConfig = init(); -} +/// Static [`SectionConfig`] to access parser/writer functions. +pub static CONFIG: LazyLock = LazyLock::new(init); fn init() -> SectionConfig { let mut config = SectionConfig::new(&TRAFFIC_CONTROL_ID_SCHEMA); diff --git a/pbs-config/src/user.rs b/pbs-config/src/user.rs index f5ea03db..08d141e6 100644 --- a/pbs-config/src/user.rs +++ b/pbs-config/src/user.rs @@ -1,8 +1,7 @@ use std::collections::HashMap; -use std::sync::{Arc, RwLock}; +use std::sync::{Arc, LazyLock, RwLock}; use anyhow::{bail, Error}; -use lazy_static::lazy_static; use proxmox_schema::*; use proxmox_section_config::{SectionConfig, SectionConfigData, SectionConfigPlugin}; @@ -13,9 +12,7 @@ use crate::ConfigVersionCache; use crate::{open_backup_lockfile, replace_backup_config, BackupLockGuard}; -lazy_static! { - pub static ref CONFIG: SectionConfig = init(); -} +pub static CONFIG: LazyLock = LazyLock::new(init); fn init() -> SectionConfig { let mut config = SectionConfig::new(&Authid::API_SCHEMA); @@ -80,13 +77,13 @@ pub fn cached_config() -> Result, Error> { last_mtime_nsec: i64, } - lazy_static! { - static ref CACHED_CONFIG: RwLock = RwLock::new(ConfigCache { + static CACHED_CONFIG: LazyLock> = LazyLock::new(|| { + RwLock::new(ConfigCache { data: None, last_mtime: 0, - last_mtime_nsec: 0 - }); - } + last_mtime_nsec: 0, + }) + }); let stat = match nix::sys::stat::stat(USER_CFG_FILENAME) { Ok(stat) => Some(stat), diff --git a/pbs-config/src/verify.rs b/pbs-config/src/verify.rs index 2631eeef..93776f8c 100644 --- a/pbs-config/src/verify.rs +++ b/pbs-config/src/verify.rs @@ -1,7 +1,7 @@ use std::collections::HashMap; +use std::sync::LazyLock; use anyhow::Error; -use lazy_static::lazy_static; use proxmox_schema::*; use proxmox_section_config::{SectionConfig, SectionConfigData, SectionConfigPlugin}; @@ -10,9 +10,7 @@ use pbs_api_types::{VerificationJobConfig, JOB_ID_SCHEMA}; use crate::{open_backup_lockfile, replace_backup_config, BackupLockGuard}; -lazy_static! { - pub static ref CONFIG: SectionConfig = init(); -} +pub static CONFIG: LazyLock = LazyLock::new(init); fn init() -> SectionConfig { let obj_schema = match VerificationJobConfig::API_SCHEMA { -- 2.39.2 _______________________________________________ pbs-devel mailing list pbs-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel