From 5eb903a509f7b8471ba5365536d00188bbbe70c0 Mon Sep 17 00:00:00 2001 From: Sergio Lopez Date: Fri, 20 Mar 2020 17:26:27 +0100 Subject: [PATCH] vhost_user_fs: Add support for FOPEN_CACHE_DIR Add support for FOPEN_CACHE_DIR, a flag that allows us to tell the guest that it's safe to cache a directory, introduced in FUSE 7.28. Signed-off-by: Sergio Lopez --- vhost_user_fs/src/fuse.rs | 4 ++++ vhost_user_fs/src/passthrough.rs | 8 +++++++- 2 files changed, 11 insertions(+), 1 deletion(-) 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; + } + } _ => {} };