Skip to content

Commit 69feddf

Browse files
zyfjeffbergwolf
authored andcommitted
Filter out O_DIRECT at open_inode
Filter out the libc::O_DIRECT flag at open_inode. Also, add the "allow_direct_io" flag to allow users to make the file system to honor the flag instead. reference virtiofsd 894361d1e83c23460ce9aaadc40a6af598a790d4 Signed-off-by: zyfjeff <zyfjeff@linux.alibaba.com>
1 parent de3231b commit 69feddf

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

src/passthrough/config.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,12 @@ pub struct Config {
175175
/// is bigger than the threshold.
176176
/// The default value for this option is `false`.
177177
pub use_host_ino: bool,
178+
179+
/// Whether the file system should honor the O_DIRECT flag. If this option is disabled,
180+
/// that flag will be filtered out at `open_inode`.
181+
///
182+
/// The default is `true`.
183+
pub allow_direct_io: bool,
178184
}
179185

180186
impl Default for Config {
@@ -198,6 +204,7 @@ impl Default for Config {
198204
dir_entry_timeout: None,
199205
dir_attr_timeout: None,
200206
use_host_ino: false,
207+
allow_direct_io: true,
201208
}
202209
}
203210
}

src/passthrough/sync_io.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,10 @@ impl<S: BitmapSlice + Send + Sync> PassthroughFs<S> {
3434
if !is_safe_inode(data.mode) {
3535
Err(ebadf())
3636
} else {
37-
let new_flags = self.get_writeback_open_flags(flags);
37+
let mut new_flags = self.get_writeback_open_flags(flags);
38+
if !self.cfg.allow_direct_io && flags & libc::O_DIRECT != 0 {
39+
new_flags &= !libc::O_DIRECT;
40+
}
3841
data.open_file(new_flags | libc::O_CLOEXEC, &self.proc_self_fd)
3942
}
4043
}

0 commit comments

Comments
 (0)