Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement O_DIRECT for open to bypass metadata cache #614

Merged
merged 4 commits into from
Nov 21, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -60,6 +60,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 {:?} 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 @@ -596,7 +602,9 @@ where
};
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
Loading