Query parent devices via `lsblk --inverse`. Returns `Ok(None)` if this device is already a root device (no parents). In the returned `Vec `, each device's `children` field contains its own* parents (grandparents, etc.), forming the full chain to the root device(s). A device can have multiple parents (e.g. RAID, LVM).
(&self)
| 378 | /// *its own* parents (grandparents, etc.), forming the full chain to the |
| 379 | /// root device(s). A device can have multiple parents (e.g. RAID, LVM). |
| 380 | pub fn list_parents(&self) -> Result<Option<Vec<Device>>> { |
| 381 | let path = self.path(); |
| 382 | let output: DevicesOutput = Command::new("lsblk") |
| 383 | .args(["-J", "-b", "-O", "--inverse"]) |
| 384 | .arg(&path) |
| 385 | .log_debug() |
| 386 | .run_and_parse_json()?; |
| 387 | |
| 388 | let device = output |
| 389 | .blockdevices |
| 390 | .into_iter() |
| 391 | .next() |
| 392 | .ok_or_else(|| anyhow!("no device output from lsblk --inverse for {path}"))?; |
| 393 | |
| 394 | match device.children { |
| 395 | Some(mut children) if !children.is_empty() => { |
| 396 | for child in &mut children { |
| 397 | child.backfill_missing()?; |
| 398 | } |
| 399 | Ok(Some(children)) |
| 400 | } |
| 401 | _ => Ok(None), |
| 402 | } |
| 403 | } |
| 404 | |
| 405 | /// Walk the parent chain to find all root (whole disk) devices, |
| 406 | /// and fail if more than one root is found. |
no test coverage detected