Skip to content

Commit 245cc7c

Browse files
committed
ptfs: add support for new cache mode Metadata
Add support for new cache mode Metadata. Signed-off-by: Jiang Liu <[email protected]>
1 parent 5ae92b3 commit 245cc7c

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

src/passthrough/config.rs

+10
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,15 @@ pub enum CachePolicy {
1414
/// the FUSE client (i.e., the file system does not have exclusive access to the directory).
1515
Never,
1616

17+
/// This is almost same as Never, but it allows page cache of directories, dentries and attr
18+
/// cache in guest. In other words, it acts like cache=never for normal files, and like
19+
/// cache=always for directories, besides, metadata like dentries and attrs are kept as well.
20+
/// This policy can be used if:
21+
/// 1. the client wants to use Never policy but it's performance in I/O is not good enough
22+
/// 2. the file system has exclusive access to the directory
23+
/// 3. cache directory content and other fs metadata can make a difference on performance.
24+
Metadata,
25+
1726
/// The client is free to choose when and how to cache file data. This is the default policy and
1827
/// uses close-to-open consistency as described in the enum documentation.
1928
#[default]
@@ -32,6 +41,7 @@ impl FromStr for CachePolicy {
3241
fn from_str(s: &str) -> Result<Self, Self::Err> {
3342
match s {
3443
"never" | "Never" | "NEVER" | "none" | "None" | "NONE" => Ok(CachePolicy::Never),
44+
"metadata" => Ok(CachePolicy::Metadata),
3545
"auto" | "Auto" | "AUTO" => Ok(CachePolicy::Auto),
3646
"always" | "Always" | "ALWAYS" => Ok(CachePolicy::Always),
3747
_ => Err("invalid cache policy"),

src/passthrough/sync_io.rs

+14-1
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,19 @@ impl<S: BitmapSlice + Send + Sync> PassthroughFs<S> {
203203
OpenOptions::DIRECT_IO,
204204
flags & (libc::O_DIRECTORY as u32) == 0,
205205
),
206-
CachePolicy::Always => opts |= OpenOptions::KEEP_CACHE,
206+
CachePolicy::Metadata => {
207+
if flags & (libc::O_DIRECTORY as u32) == 0 {
208+
opts |= OpenOptions::DIRECT_IO;
209+
} else {
210+
opts |= OpenOptions::CACHE_DIR | OpenOptions::KEEP_CACHE;
211+
}
212+
}
213+
CachePolicy::Always => {
214+
opts |= OpenOptions::KEEP_CACHE;
215+
if flags & (libc::O_DIRECTORY as u32) != 0 {
216+
opts |= OpenOptions::CACHE_DIR;
217+
}
218+
}
207219
_ => {}
208220
};
209221

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

0 commit comments

Comments
 (0)