Skip to content

Commit

Permalink
Use host /sys /dev when not in test suite.
Browse files Browse the repository at this point in the history
This ensures we don't rely on wonky bindmounts being
present and can perform proper discovery.

Signed-off-by: Ikey Doherty <[email protected]>
  • Loading branch information
ikeycode committed May 19, 2024
1 parent 25de563 commit 12c60ba
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 14 deletions.
5 changes: 4 additions & 1 deletion blsctl/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
3 changes: 3 additions & 0 deletions blsforme/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 6 additions & 13 deletions blsforme/src/topology.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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}"));
Expand All @@ -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<Self, self::Error> {
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 {
Expand All @@ -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");
Expand Down

0 comments on commit 12c60ba

Please sign in to comment.