From 6dd5944772e99c8087314225dd1134f908b60b3c Mon Sep 17 00:00:00 2001 From: Dominik Csapak Date: Mon, 7 Mar 2022 09:13:30 +0100 Subject: [PATCH] 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 Signed-off-by: Wolfgang Bumiller --- src/tools/disks/zfs.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/tools/disks/zfs.rs b/src/tools/disks/zfs.rs index 9bca0297..a02baa00 100644 --- a/src/tools/disks/zfs.rs +++ b/src/tools/disks/zfs.rs @@ -198,6 +198,14 @@ pub fn zfs_dataset_stats(dataset: &str) -> Result { } let (pool, objset_id) = 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) + } + } }