daemon: lvm_utils: Handle stat errors

lvm returns logical volumes even if they're broken, for instance when a
physical volume is missing in their volume group.
In such cases, stat would fail to resolve the provided path.
Handle such cases by skipping such failures when finding the matching
lvm device.
This commit is contained in:
Arye Yurkovsky
2025-12-07 09:58:57 +02:00
committed by rwmjones
parent c56e6ff39b
commit c7228cd1ce

View File

@@ -34,15 +34,26 @@ open Utils
* resolved.
*)
let lv_canonical device =
let stat1 = stat device in
let stat1 =
try Some (stat device)
with Unix_error _ -> None in
match stat1 with
| None -> None
| Some stat1 ->
(
let lvs = Lvm.lvs () in
try
Some (
List.find (
fun lv ->
let stat2 = stat lv in
stat1.st_rdev = stat2.st_rdev
let stat2 =
try Some (stat lv)
with Unix_error _ -> None in
match stat2 with
| Some stat2 -> stat1.st_rdev = stat2.st_rdev
| None -> false
) lvs
)
with
| Not_found -> None
)