Skip to content

Commit 62ea078

Browse files
committed
blockdev: Backfill partition number from sysfs for older lsblk
The PARTN column was added in util-linux 2.39, but CentOS 9 / RHEL 9 ship util-linux 2.37. When lsblk -O is used on these systems, the partn field is absent from JSON output, causing find_device_by_partno() to fail with "Missing partition for index N". Add backfill_partn() alongside the existing backfill_start() to read the partition number from /sys/dev/block/{maj:min}/partition when lsblk doesn't provide it. Assisted-by: Claude Code (Opus 4) Signed-off-by: ckyrouac <ckyrouac@redhat.com>
1 parent dc0ed00 commit 62ea078

1 file changed

Lines changed: 22 additions & 0 deletions

File tree

crates/blockdev/src/blockdev.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,10 +120,32 @@ impl Device {
120120
Ok(())
121121
}
122122

123+
// The "partn" column was added in util-linux 2.39, which is newer than
124+
// what CentOS 9 / RHEL 9 ship (2.37).
125+
fn backfill_partn(&mut self) -> Result<()> {
126+
let Some(majmin) = self.maj_min.as_deref() else {
127+
return Ok(());
128+
};
129+
let sysfs_partn_path = format!("/sys/dev/block/{majmin}/partition");
130+
if Utf8Path::new(&sysfs_partn_path).try_exists()? {
131+
let partn = std::fs::read_to_string(&sysfs_partn_path)
132+
.with_context(|| format!("Reading {sysfs_partn_path}"))?;
133+
tracing::debug!("backfilled partn to {partn}");
134+
self.partn = Some(
135+
partn
136+
.trim()
137+
.parse()
138+
.context("Parsing sysfs partition property")?,
139+
);
140+
}
141+
Ok(())
142+
}
143+
123144
/// Older versions of util-linux may be missing some properties. Backfill them if they're missing.
124145
pub fn backfill_missing(&mut self) -> Result<()> {
125146
// Add new properties to backfill here
126147
self.backfill_start()?;
148+
self.backfill_partn()?;
127149
// And recurse to child devices
128150
for child in self.children.iter_mut().flatten() {
129151
child.backfill_missing()?;

0 commit comments

Comments
 (0)