Skip to content

Commit b61faad

Browse files
committed
update according to Colin's comment
1 parent 7b65bfb commit b61faad

File tree

2 files changed

+9
-19
lines changed

2 files changed

+9
-19
lines changed

src/blockdev.rs

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,10 @@ use anyhow::{bail, Context, Result};
66
use bootc_blockdev::PartitionTable;
77
use fn_error_context::context;
88

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")
9+
/// Get parent devices
10+
pub fn get_or_init_parent_devices(devices: Option<Vec<String>>) -> &'static [String] {
11+
static PARENT_DEVICES: OnceLock<Vec<String>> = OnceLock::new();
12+
PARENT_DEVICES.get_or_init(|| devices.unwrap())
1913
}
2014

2115
#[context("get parent devices from mount point boot")]
@@ -68,7 +62,7 @@ pub fn get_esp_partition(device: &str) -> Result<Option<String>> {
6862
#[allow(dead_code)]
6963
pub fn find_colocated_esps() -> Result<Vec<String>> {
7064
// first, get the parent device
71-
let devices = get_parent_devices();
65+
let devices = get_or_init_parent_devices(None);
7266

7367
// now, look for all ESPs on those devices
7468
let mut esps = Vec::new();
@@ -99,7 +93,7 @@ pub fn get_bios_boot_partition(device: &str) -> Result<Option<String>> {
9993
#[allow(dead_code)]
10094
pub fn find_colocated_bios_boot() -> Result<Vec<String>> {
10195
// first, get the parent device
102-
let devices = get_parent_devices();
96+
let devices = get_or_init_parent_devices(None);
10397

10498
// now, look for all bios_boot parts on those devices
10599
let mut bios_boots = Vec::new();

src/cli/bootupctl.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ use anyhow::{Context, Result};
33
use clap::Parser;
44
use log::LevelFilter;
55

6-
use std::os::unix::io::AsRawFd;
76
use std::os::unix::process::CommandExt;
87
use std::process::{Command, Stdio};
98

@@ -220,11 +219,8 @@ fn run_status_in_container(json_format: bool) -> Result<()> {
220219
/// Initialize parent devices to prepare the update
221220
fn prep_before_update() -> Result<openat::Dir> {
222221
let sysroot = openat::Dir::open("/").context("Opening root dir")?;
223-
let dest_fd = format!("/proc/self/fd/{}", sysroot.as_raw_fd());
224-
let dest_root = std::fs::read_link(dest_fd)?;
225-
226-
let devices = crate::blockdev::get_devices(&dest_root)
227-
.with_context(|| "while looking for parent devices")?;
228-
crate::blockdev::init_parent_devices(devices);
222+
let devices = crate::blockdev::get_devices("/").context("get parent devices")?;
223+
crate::blockdev::get_or_init_parent_devices(Some(devices));
224+
crate::blockdev::get_or_init_parent_devices(None);
229225
Ok(sysroot)
230226
}

0 commit comments

Comments
 (0)