Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ptfs: add support for new cache mode Metadata #174

Merged
merged 1 commit into from
Nov 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/passthrough/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,15 @@ pub enum CachePolicy {
/// the FUSE client (i.e., the file system does not have exclusive access to the directory).
Never,

/// This is almost same as Never, but it allows page cache of directories, dentries and attr
/// cache in guest. In other words, it acts like cache=never for normal files, and like
/// cache=always for directories, besides, metadata like dentries and attrs are kept as well.
/// This policy can be used if:
/// 1. the client wants to use Never policy but it's performance in I/O is not good enough
/// 2. the file system has exclusive access to the directory
/// 3. cache directory content and other fs metadata can make a difference on performance.
Metadata,

/// The client is free to choose when and how to cache file data. This is the default policy and
/// uses close-to-open consistency as described in the enum documentation.
#[default]
Expand All @@ -32,6 +41,7 @@ impl FromStr for CachePolicy {
fn from_str(s: &str) -> Result<Self, Self::Err> {
match s {
"never" | "Never" | "NEVER" | "none" | "None" | "NONE" => Ok(CachePolicy::Never),
"metadata" => Ok(CachePolicy::Metadata),
"auto" | "Auto" | "AUTO" => Ok(CachePolicy::Auto),
"always" | "Always" | "ALWAYS" => Ok(CachePolicy::Always),
_ => Err("invalid cache policy"),
Expand Down
15 changes: 14 additions & 1 deletion src/passthrough/sync_io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,19 @@ impl<S: BitmapSlice + Send + Sync> PassthroughFs<S> {
OpenOptions::DIRECT_IO,
flags & (libc::O_DIRECTORY as u32) == 0,
),
CachePolicy::Always => opts |= OpenOptions::KEEP_CACHE,
CachePolicy::Metadata => {
if flags & (libc::O_DIRECTORY as u32) == 0 {
opts |= OpenOptions::DIRECT_IO;
} else {
opts |= OpenOptions::CACHE_DIR | OpenOptions::KEEP_CACHE;
}
}
CachePolicy::Always => {
opts |= OpenOptions::KEEP_CACHE;
if flags & (libc::O_DIRECTORY as u32) != 0 {
opts |= OpenOptions::CACHE_DIR;
}
}
_ => {}
};

Expand Down Expand Up @@ -584,6 +596,7 @@ impl<S: BitmapSlice + Send + Sync> FileSystem for PassthroughFs<S> {
let mut opts = OpenOptions::empty();
match self.cfg.cache_policy {
CachePolicy::Never => opts |= OpenOptions::DIRECT_IO,
CachePolicy::Metadata => opts |= OpenOptions::DIRECT_IO,
CachePolicy::Always => opts |= OpenOptions::KEEP_CACHE,
_ => {}
};
Expand Down