Expand --report-current to show partitions and all mounts (except pseudo-filesystems)

This commit is contained in:
2025-10-20 14:55:38 +02:00
parent 224adf06d8
commit 4cd8c54c44

View File

@@ -276,6 +276,7 @@ fn run_report_current(ctx: &Context) -> Result<()> {
info!("orchestrator: report-current mode");
let fs_results = zfs::probe_existing_filesystems()?;
// Read all mounts, filtering common system/uninteresting ones
let mounts_content = fs::read_to_string("/proc/mounts").unwrap_or_default();
let mounts_json: Vec<serde_json::Value> = mounts_content
.lines()
@@ -285,21 +286,77 @@ fn run_report_current(ctx: &Context) -> Result<()> {
let target = it.next()?;
let fstype = it.next()?;
let options = it.next().unwrap_or("");
if target.starts_with("/var/mounts/")
|| target == "/var/cache/system"
|| target == "/var/cache/etc"
|| target == "/var/cache/modules"
|| target == "/var/cache/vm-meta"
// Skip common pseudo/virtual filesystems and system mounts
if source.starts_with("devtmpfs")
|| source.starts_with("tmpfs")
|| source.starts_with("proc")
|| source.starts_with("sysfs")
|| source.starts_with("cgroup")
|| source.starts_with("bpf")
|| source.starts_with("debugfs")
|| source.starts_with("securityfs")
|| source.starts_with("mqueue")
|| source.starts_with("pstore")
|| source.starts_with("tracefs")
|| source.starts_with("hugetlbfs")
|| source.starts_with("efivarfs")
|| source.starts_with("systemd-1")
|| target.starts_with("/proc")
|| target.starts_with("/sys")
|| target.starts_with("/dev")
|| target.starts_with("/run")
|| target.starts_with("/boot")
|| target.starts_with("/efi")
|| target.starts_with("/boot/efi")
{
Some(json!({
"source": source,
"target": target,
"fstype": fstype,
"options": options
}))
} else {
None
return None;
}
// Include zosstorage target mounts and general data mounts
Some(json!({
"source": source,
"target": target,
"fstype": fstype,
"options": options
}))
})
.collect();
// Read partition information from /proc/partitions
let partitions_content = fs::read_to_string("/proc/partitions").unwrap_or_default();
let partitions_json: Vec<serde_json::Value> = partitions_content
.lines()
.filter_map(|line| {
let line = line.trim();
if line.is_empty() || line.starts_with("major") {
return None;
}
let parts: Vec<&str> = line.split_whitespace().collect();
if parts.len() < 4 {
return None;
}
let name = parts[3];
// Skip pseudo devices
if name.starts_with("loop")
|| name.starts_with("ram")
|| name.starts_with("zram")
|| name.starts_with("fd")
|| name.starts_with("dm-")
|| name.starts_with("md")
{
return None;
}
let major: u32 = parts[0].parse().ok()?;
let minor: u32 = parts[1].parse().ok()?;
let size_kb: u64 = parts[2].parse().ok()?;
Some(json!({
"name": name,
"major": major,
"minor": minor,
"size_kb": size_kb,
"size_gib": size_kb / (1024 * 1024)
}))
})
.collect();
@@ -325,6 +382,7 @@ fn run_report_current(ctx: &Context) -> Result<()> {
"version": "v1",
"timestamp": now,
"status": "observed",
"partitions": partitions_json,
"filesystems": fs_json,
"mounts": mounts_json
});