Skip to content

Commit d399af2

Browse files
committed
lib: Use Device::root_disk() for ESP and parent device lookups
All callers that need the whole-disk device (e.g. to find the ESP partition) now use root_disk() to traverse from the filesystem partition to the root disk. This fixes list_dev_by_dir() consumers (store, bootloader, composefs boot) that were searching for ESP partitions on a partition device rather than the whole disk, and simplifies install.rs which had an open-coded parent walk. Assisted-by: Claude Code (Opus 4) Signed-off-by: ckyrouac <ckyrouac@redhat.com>
1 parent 4b9202b commit d399af2

4 files changed

Lines changed: 7 additions & 42 deletions

File tree

crates/lib/src/bootc_composefs/boot.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,7 @@ use std::io::Write;
6767
use std::path::Path;
6868

6969
use anyhow::{Context, Result, anyhow, bail};
70-
use bootc_blockdev::find_parent_devices;
7170
use bootc_kernel_cmdline::utf8::{Cmdline, Parameter, ParameterKey};
72-
use bootc_mount::inspect_filesystem_of_dir;
7371
use bootc_mount::tempmount::TempMount;
7472
use camino::{Utf8Path, Utf8PathBuf};
7573
use cap_std_ext::{
@@ -535,7 +533,7 @@ pub(crate) fn setup_composefs_bls_boot(
535533
cmdline.add_or_modify(&param);
536534

537535
// Locate ESP partition device
538-
let root_dev = bootc_blockdev::list_dev_by_dir(&storage.physical_root)?;
536+
let root_dev = bootc_blockdev::list_dev_by_dir(&storage.physical_root)?.root_disk()?;
539537
let esp_dev = root_dev.find_partition_of_esp()?;
540538

541539
(
@@ -1067,7 +1065,7 @@ pub(crate) fn setup_composefs_uki_boot(
10671065
let bootloader = host.require_composefs_booted()?.bootloader.clone();
10681066

10691067
// Locate ESP partition device
1070-
let root_dev = bootc_blockdev::list_dev_by_dir(&storage.physical_root)?;
1068+
let root_dev = bootc_blockdev::list_dev_by_dir(&storage.physical_root)?.root_disk()?;
10711069
let esp_dev = root_dev.find_partition_of_esp()?;
10721070

10731071
(sysroot, esp_dev.path(), bootloader, false, None)

crates/lib/src/bootloader.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ pub(crate) fn mount_esp_part(root: &Dir, root_path: &Utf8Path, is_ostree: bool)
4545
root
4646
};
4747

48-
let dev = bootc_blockdev::list_dev_by_dir(physical_root)?;
48+
let dev = bootc_blockdev::list_dev_by_dir(physical_root)?.root_disk()?;
4949
if let Some(esp_dev) = dev.find_partition_of_type(bootc_blockdev::ESP) {
5050
let esp_path = esp_dev.path();
5151
bootc_mount::mount(&esp_path, &root_path.join(&efi_path))?;

crates/lib/src/install.rs

Lines changed: 3 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -2442,42 +2442,9 @@ pub(crate) async fn install_to_filesystem(
24422442
// Find the real underlying backing device for the root. This is currently just required
24432443
// for GRUB (BIOS) and in the future zipl (I think).
24442444
let device_info = {
2445-
let dev = bootc_blockdev::list_dev(Utf8Path::new(&inspect.source))?;
2446-
// Walk the inverse tree to the root device.
2447-
// In inverse lsblk output, "children" are actually parents.
2448-
match dev.list_parents()? {
2449-
None => {
2450-
tracing::debug!("Backing device: {}", dev.path());
2451-
dev
2452-
}
2453-
Some(parents) => {
2454-
let mut current = parents;
2455-
loop {
2456-
if current.len() > 1 {
2457-
anyhow::bail!(
2458-
"Found multiple parent devices {} and {}; not currently supported",
2459-
current[0].path(),
2460-
current[1].path()
2461-
);
2462-
}
2463-
let mut parent = current.into_iter().next().unwrap();
2464-
// In inverse output, children = grandparents
2465-
match parent.children.take() {
2466-
Some(grandparents) if !grandparents.is_empty() => {
2467-
current = grandparents;
2468-
}
2469-
_ => {
2470-
tracing::debug!("Backing device: {}", parent.path());
2471-
// Re-query the root device to populate its actual
2472-
// children (partitions). The inverse tree only
2473-
// carries parent links, not real children.
2474-
parent.refresh()?;
2475-
break parent;
2476-
}
2477-
}
2478-
}
2479-
}
2480-
}
2445+
let dev = bootc_blockdev::list_dev(Utf8Path::new(&inspect.source))?.root_disk()?;
2446+
tracing::debug!("Backing device: {}", dev.path());
2447+
dev
24812448
};
24822449

24832450
let rootarg = format!("root={}", root_info.mount_spec);

crates/lib/src/store/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ impl BootedStorage {
173173
let composefs = Arc::new(composefs);
174174

175175
//TODO: this assumes a single ESP on the root device
176-
let root_dev = bootc_blockdev::list_dev_by_dir(&physical_root)?;
176+
let root_dev = bootc_blockdev::list_dev_by_dir(&physical_root)?.root_disk()?;
177177
let esp_dev = root_dev.find_partition_of_esp()?;
178178
let esp_mount = mount_esp(&esp_dev.path())?;
179179

0 commit comments

Comments
 (0)