diff --git a/src/passthrough/config.rs b/src/passthrough/config.rs index bf2c101e..8d8c1224 100644 --- a/src/passthrough/config.rs +++ b/src/passthrough/config.rs @@ -175,6 +175,12 @@ pub struct Config { /// is bigger than the threshold. /// The default value for this option is `false`. pub use_host_ino: bool, + + /// Whether the file system should honor the O_DIRECT flag. If this option is disabled (which + /// is the default value), that flag will be filtered out at `open_inode`. + /// + /// The default is `false`. + pub allow_direct_io: bool, } impl Default for Config { @@ -198,6 +204,7 @@ impl Default for Config { dir_entry_timeout: None, dir_attr_timeout: None, use_host_ino: false, + allow_direct_io: false, } } } diff --git a/src/passthrough/sync_io.rs b/src/passthrough/sync_io.rs index 925bc2b2..76520efe 100644 --- a/src/passthrough/sync_io.rs +++ b/src/passthrough/sync_io.rs @@ -34,7 +34,10 @@ impl PassthroughFs { if !is_safe_inode(data.mode) { Err(ebadf()) } else { - let new_flags = self.get_writeback_open_flags(flags); + let mut new_flags = self.get_writeback_open_flags(flags); + if !self.cfg.allow_direct_io && flags & libc::O_DIRECT != 0 { + new_flags &= !libc::O_DIRECT; + } data.open_file(new_flags | libc::O_CLOEXEC, &self.proc_self_fd) } }