Skip to content

Commit

Permalink
Only read block devices during cache discovery (openzfs#469)
Browse files Browse the repository at this point in the history
  • Loading branch information
Prakash Surya committed Jun 6, 2022
1 parent a5fb50f commit 50ab6e1
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions cmd/zfs_object_agent/zettacache/src/open.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 50ab6e1

Please sign in to comment.