Skip to content

Commit 743244c

Browse files
committed
blockdev: add PARENT_DEVICES
As `PARENT_DEVICES` is used multiple times, initialize once at the begining and read them then.
1 parent 12011d3 commit 743244c

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/blockdev.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,23 @@
11
use camino::Utf8Path;
22
use std::path::Path;
3+
use std::sync::OnceLock;
34

45
use anyhow::{bail, Context, Result};
56
use bootc_blockdev::PartitionTable;
67
use fn_error_context::context;
78

9+
static PARENT_DEVICES: OnceLock<Vec<String>> = OnceLock::new();
10+
11+
// Initialize once
12+
pub fn init_parent_devices(strings: Vec<String>) {
13+
PARENT_DEVICES.set(strings).expect("Already initialized");
14+
}
15+
16+
// Read many times (lock-free)
17+
pub fn get_parent_devices() -> &'static [String] {
18+
PARENT_DEVICES.get().expect("Not initialized")
19+
}
20+
821
#[context("get parent devices from mount point boot")]
922
pub fn get_devices<P: AsRef<Path>>(target_root: P) -> Result<Vec<String>> {
1023
let target_root = target_root.as_ref();

0 commit comments

Comments
 (0)