diff --git a/vhost_user_fs/src/fuse.rs b/vhost_user_fs/src/fuse.rs index 897e3cfbc..6ddb71468 100644 --- a/vhost_user_fs/src/fuse.rs +++ b/vhost_user_fs/src/fuse.rs @@ -55,6 +55,9 @@ const FOPEN_KEEP_CACHE: u32 = 2; /// The file is not seekable. const FOPEN_NONSEEKABLE: u32 = 4; +/// Allow caching this directory. +const FOPEN_CACHE_DIR: u32 = 8; + bitflags! { /// Options controlling the behavior of files opened by the server in response /// to an open or create request. @@ -62,6 +65,7 @@ bitflags! { const DIRECT_IO = FOPEN_DIRECT_IO; const KEEP_CACHE = FOPEN_KEEP_CACHE; const NONSEEKABLE = FOPEN_NONSEEKABLE; + const CACHE_DIR = FOPEN_CACHE_DIR; } } diff --git a/vhost_user_fs/src/passthrough.rs b/vhost_user_fs/src/passthrough.rs index 2a1456cd2..f76478b5d 100644 --- a/vhost_user_fs/src/passthrough.rs +++ b/vhost_user_fs/src/passthrough.rs @@ -558,7 +558,13 @@ impl PassthroughFs { OpenOptions::DIRECT_IO, flags & (libc::O_DIRECTORY as u32) == 0, ), - CachePolicy::Always => opts |= OpenOptions::KEEP_CACHE, + CachePolicy::Always => { + if flags & (libc::O_DIRECTORY as u32) == 0 { + opts |= OpenOptions::KEEP_CACHE; + } else { + opts |= OpenOptions::CACHE_DIR; + } + } _ => {} };