tools: zfs_dataset_stats: remove dataset <-> obset file mapping on error

this can only real fail for two reasons:
* the format is wrong:
    this should not happen unless the format changed, then it will
    happen every time
* the file can't be read:
    this can happen if a user deletes and recreates a dataset manually,
    since the mapped file does not exist anymore but the dataset does

for the second case, delete the mapping from the hashmap, so that the
next call will refresh the mapping with the correct file

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
This commit is contained in:
Dominik Csapak 2022-03-07 09:13:30 +01:00 committed by Wolfgang Bumiller
parent dcd1518e10
commit 6dd5944772
1 changed files with 10 additions and 2 deletions

View File

@ -198,6 +198,14 @@ pub fn zfs_dataset_stats(dataset: &str) -> Result<BlockDevStat, Error> {
} }
let (pool, objset_id) = let (pool, objset_id) =
mapping.ok_or_else(|| format_err!("could not find objset id for dataset"))?; mapping.ok_or_else(|| format_err!("could not find objset id for dataset"))?;
let (_, stat) = parse_objset_stat(&pool, &objset_id)?;
Ok(stat) match parse_objset_stat(&pool, &objset_id) {
Ok((_, stat)) => Ok(stat),
Err(err) => {
// on error remove dataset from map, it probably vanished or the
// mapping was incorrect
ZFS_DATASET_OBJSET_MAP.lock().unwrap().remove(dataset);
Err(err)
}
}
} }