From 12c60bae56b517937ae3f771f232aa30680422ce Mon Sep 17 00:00:00 2001 From: Ikey Doherty Date: Sun, 19 May 2024 18:06:54 +0100 Subject: [PATCH] Use host `/sys` `/dev` when not in test suite. This ensures we don't rely on wonky bindmounts being present and can perform proper discovery. Signed-off-by: Ikey Doherty --- blsctl/src/main.rs | 5 ++++- blsforme/src/lib.rs | 3 +++ blsforme/src/topology.rs | 19 ++++++------------- 3 files changed, 13 insertions(+), 14 deletions(-) diff --git a/blsctl/src/main.rs b/blsctl/src/main.rs index 80cd7a5..7445af9 100644 --- a/blsctl/src/main.rs +++ b/blsctl/src/main.rs @@ -194,7 +194,10 @@ fn main() -> color_eyre::Result<()> { Root::Native("/".into()) }; - let config = Configuration { root }; + let config = Configuration { + root, + vfs: "/".into(), + }; log::trace!("Using configuration: {config:?}"); log::info!("Inspecting root device: {}", config.root.path().display()); diff --git a/blsforme/src/lib.rs b/blsforme/src/lib.rs index 228faa9..c447a93 100644 --- a/blsforme/src/lib.rs +++ b/blsforme/src/lib.rs @@ -15,6 +15,9 @@ pub mod topology; pub struct Configuration { /// Root of all operations pub root: Root, + + /// Where we can find `sysfs` `proc` etc + pub vfs: PathBuf, } /// Wrap a root into a strong type to avoid confusion diff --git a/blsforme/src/topology.rs b/blsforme/src/topology.rs index 071452c..8df366e 100644 --- a/blsforme/src/topology.rs +++ b/blsforme/src/topology.rs @@ -208,8 +208,8 @@ impl Topology { let major = stat::major(st.st_dev); let minor = stat::minor(st.st_dev); let path = config - .root - .path() + .vfs + .join("sys") .join("dev") .join("block") .join(format!("{major}:{minor}")); @@ -226,7 +226,7 @@ impl Topology { /// then scan the root disk to determine the PartUUID if applicable, /// if not we can fallback to superblock scanning. fn refine_device(config: &Configuration, device: BlockDevice) -> Result { - let efi_path = config.root.path().join("sys").join("firmware").join("efi"); + let efi_path = config.vfs.join("sys").join("firmware").join("efi"); let firmware = if efi_path.exists() { Firmware::UEFI } else { @@ -237,22 +237,15 @@ impl Topology { let id = path .file_name() .ok_or_else(|| self::Error::UnknownMount(path.clone()))?; - let sysfs_child = fs::canonicalize( - config - .root - .path() - .join("sys") - .join("class") - .join("block") - .join(id), - )?; + let sysfs_child = + fs::canonicalize(config.vfs.join("sys").join("class").join("block").join(id))?; // Grab the parent device name let sysfs_parent = sysfs_child .parent() .and_then(|p| p.file_name()) .ok_or_else(|| self::Error::UnknownMount(sysfs_child.clone()))?; - let parent_dev = config.root.path().join("dev").join(sysfs_parent); + let parent_dev = config.vfs.join("dev").join(sysfs_parent); // Determine partition uuid let part_file = sysfs_child.join("partition");