(dataset: &str)
| 471 | |
| 472 | #[context("Finding block device for ZFS dataset {dataset}")] |
| 473 | fn list_dev_for_zfs_dataset(dataset: &str) -> Result<Device> { |
| 474 | let dataset = dataset.strip_prefix("ZFS=").unwrap_or(dataset); |
| 475 | let pool = dataset |
| 476 | .split('/') |
| 477 | .next() |
| 478 | .ok_or_else(|| anyhow!("Invalid ZFS dataset: {dataset}"))?; |
| 479 | |
| 480 | let output = Command::new("zpool") |
| 481 | .args(["list", "-H", "-v", "-P", pool]) |
| 482 | .run_get_string() |
| 483 | .with_context(|| format!("Querying ZFS pool {pool}"))?; |
| 484 | |
| 485 | for line in output.lines() { |
| 486 | if line.starts_with('\t') || line.starts_with(' ') { |
| 487 | let dev_path = line.trim_start().split('\t').next().unwrap_or("").trim(); |
| 488 | if dev_path.starts_with('/') { |
| 489 | return list_dev(Utf8Path::new(dev_path)); |
| 490 | } |
| 491 | } |
| 492 | } |
| 493 | |
| 494 | anyhow::bail!("Could not find a block device backing ZFS pool {pool}") |
| 495 | } |
| 496 | |
| 497 | /// List the device containing the filesystem mounted at the given directory. |
| 498 | pub fn list_dev_by_dir(dir: &Dir) -> Result<Device> { |
no test coverage detected