Skip to content

Commit

Permalink
Merge pull request stratis-storage#917 from mulkieran/issue_project_698
Browse files Browse the repository at this point in the history
Use once_cell instead of lazy_static for lazy statics
  • Loading branch information
mulkieran authored Apr 29, 2024
2 parents 64b67c5 + ae8c829 commit d387943
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ semver = "1.0.0"
serde = "1.0.60"
rand = "0.8.0"
retry = {version = "2.0.0", default-features=false}
lazy_static = "1.2.0"
log = "0.4.14"
once_cell = "1.19.0"

[dev-dependencies]
assert_matches = "1.5.0"
Expand Down
16 changes: 9 additions & 7 deletions src/core/dm_ioctl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,19 @@

use std::collections::HashMap;

use once_cell::sync::Lazy;

pub use devicemapper_sys::{
dm_ioctl as Struct_dm_ioctl, dm_name_list as Struct_dm_name_list,
dm_target_deps as Struct_dm_target_deps, dm_target_msg as Struct_dm_target_msg,
dm_target_spec as Struct_dm_target_spec, dm_target_versions as Struct_dm_target_versions, *,
};

lazy_static! {
// Map device-mapper ioctl commands to the minimum ioctl interface version
// required. The mapping is based on the _cmd_data_v4 table defined in
// libdm/ioctl/libdm-iface.c in the lvm2/libdevmapper sources.
static ref IOCTL_VERSIONS: HashMap<u32, (u32, u32, u32)> = HashMap::from([
// Map device-mapper ioctl commands to the minimum ioctl interface version
// required. The mapping is based on the _cmd_data_v4 table defined in
// libdm/ioctl/libdm-iface.c in the lvm2/libdevmapper sources.
static IOCTL_VERSIONS: Lazy<HashMap<u32, (u32, u32, u32)>> = Lazy::new(|| {
HashMap::from([
(DM_VERSION_CMD, (4, 0, 0)),
(DM_REMOVE_ALL_CMD, (4, 0, 0)),
(DM_LIST_DEVICES_CMD, (4, 0, 0)),
Expand All @@ -40,8 +42,8 @@ lazy_static! {
(DM_DEV_ARM_POLL_CMD, (4, 37, 0)),
#[cfg(devicemapper441supported)]
(DM_GET_TARGET_VERSION_CMD, (4, 41, 0)),
]);
}
])
});

// Map device-mapper ioctl commands to (major, minor, patchlevel)
// tuple specifying the required kernel ioctl interface version.
Expand Down
6 changes: 3 additions & 3 deletions src/core/dm_udev_sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ pub mod sync_semaphore {

use nix::unistd::{access, AccessFlags};

use once_cell::sync::Lazy;

use rand::Rng;
use retry::{delay::NoDelay, retry, OperationResult};
use std::{io, path::Path};
Expand All @@ -59,9 +61,7 @@ pub mod sync_semaphore {
}
}

lazy_static! {
static ref SYSV_SEM_SUPPORTED: bool = sysv_sem_supported();
}
static SYSV_SEM_SUPPORTED: Lazy<bool> = Lazy::new(sysv_sem_supported);

/// Test whether the system is configured for SysV semaphore support.
fn sysv_sem_supported() -> bool {
Expand Down
2 changes: 0 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,6 @@ extern crate bitflags;
#[macro_use]
extern crate nix;
#[macro_use]
extern crate lazy_static;
#[macro_use]
extern crate log;

/// Range macros
Expand Down

0 comments on commit d387943

Please sign in to comment.