Skip to content

Commit

Permalink
Implement O_DIRECT for open to bypass metadata cache (#614)
Browse files Browse the repository at this point in the history
* Implement O_DIRECT for open to bypass metadata cache if enabled

Signed-off-by: Daniel Carl Jones <[email protected]>

* Re-organize integration test modules to be able to run O_DIRECT tests serially

Signed-off-by: Alessandro Passaro <[email protected]>

* Add Rustdoc for the common test module

Signed-off-by: Alessandro Passaro <[email protected]>

* Configure the direct_io tests with the correct feature ("fuse_tests")

Signed-off-by: Alessandro Passaro <[email protected]>

---------

Signed-off-by: Daniel Carl Jones <[email protected]>
Signed-off-by: Alessandro Passaro <[email protected]>
Co-authored-by: Alessandro Passaro <[email protected]>
  • Loading branch information
dannycjones and passaro authored Nov 21, 2023
1 parent 8d8c07b commit 3c5f93d
Show file tree
Hide file tree
Showing 20 changed files with 801 additions and 659 deletions.
36 changes: 36 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions mountpoint-s3/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ proptest = "1.0.0"
proptest-derive = "0.3.0"
rand = "0.8.5"
rand_chacha = "0.3.1"
serial_test = "2.0.0"
sha2 = "0.10.6"
shuttle = { version = "0.5.0" }
tempfile = "3.4.0"
Expand Down
12 changes: 10 additions & 2 deletions mountpoint-s3/src/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use std::time::{Duration, UNIX_EPOCH};
use time::OffsetDateTime;
use tracing::{debug, error, trace};

use fuser::consts::FOPEN_DIRECT_IO;
use fuser::{FileAttr, KernelConfig};
use mountpoint_s3_client::error::{GetObjectError, ObjectClientError};
use mountpoint_s3_client::types::ETag;
Expand Down Expand Up @@ -562,7 +563,12 @@ where
pub async fn open(&self, ino: InodeNo, flags: i32, pid: u32) -> Result<Opened, Error> {
trace!("fs:open with ino {:?} flags {:#b} pid {:?}", ino, flags, pid);

let force_revalidate = !self.config.cache_config.serve_lookup_from_cache;
#[cfg(not(target_os = "linux"))]
let direct_io = false;
#[cfg(target_os = "linux")]
let direct_io = flags & libc::O_DIRECT != 0;

let force_revalidate = !self.config.cache_config.serve_lookup_from_cache || direct_io;
let lookup = self.superblock.getattr(&self.client, ino, force_revalidate).await?;

match lookup.inode.kind() {
Expand Down Expand Up @@ -597,7 +603,9 @@ where
debug!(fh, ino, "new file handle created");
self.file_handles.write().await.insert(fh, Arc::new(handle));

Ok(Opened { fh, flags: 0 })
let reply_flags = if direct_io { FOPEN_DIRECT_IO } else { 0 };

Ok(Opened { fh, flags: reply_flags })
}

#[allow(clippy::too_many_arguments)] // We don't get to choose this interface
Expand Down
Loading

0 comments on commit 3c5f93d

Please sign in to comment.