MCPcopy Create free account
hub / github.com/bootc-dev/bootc / list_dev_for_zfs_dataset

Function list_dev_for_zfs_dataset

crates/blockdev/src/blockdev.rs:473–495  ·  view source on GitHub ↗
(dataset: &str)

Source from the content-addressed store, hash-verified

471
472#[context("Finding block device for ZFS dataset {dataset}")]
473fn 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.
498pub fn list_dev_by_dir(dir: &Dir) -> Result<Device> {

Callers 1

list_dev_by_dirFunction · 0.85

Calls 4

list_devFunction · 0.85
argsMethod · 0.80
nextMethod · 0.45
run_get_stringMethod · 0.45

Tested by

no test coverage detected