From 50ab6e17263bec842fcbebba8677ccfc0eefde78 Mon Sep 17 00:00:00 2001 From: Prakash Surya Date: Mon, 6 Jun 2022 10:41:59 -0700 Subject: [PATCH] Only read block devices during cache discovery (#469) --- cmd/zfs_object_agent/zettacache/src/open.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/cmd/zfs_object_agent/zettacache/src/open.rs b/cmd/zfs_object_agent/zettacache/src/open.rs index 9ada49a018ee..92aa51ade934 100644 --- a/cmd/zfs_object_agent/zettacache/src/open.rs +++ b/cmd/zfs_object_agent/zettacache/src/open.rs @@ -1,6 +1,7 @@ use std::collections::BTreeMap; use std::collections::HashMap; use std::collections::HashSet; +use std::os::unix::fs::FileTypeExt; use std::path::Path; use std::path::PathBuf; @@ -56,6 +57,12 @@ impl DiscoveredDevice { let mut file = File::open(&path) .await .with_context(|| format!("open {path:?}"))?; + + let filetype = file.metadata().await?.file_type(); + if !filetype.is_block_device() && !filetype.is_file() { + return Err(anyhow!("{path:?} is not a file nor a block device")); + } + let mut buf = vec![0u8; SUPERBLOCK_SIZE]; file.read_exact(&mut buf) .await