8000 fix: disable O_DIRECT on non-linux targets by MrCroxx · Pull Request #40 · foyer-rs/foyer · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

fix: disable O_DIRECT on non-linux targets #40

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

Merged
merged 1 commit into from
Jul 3, 2023
Merged
Changes from all 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
19 changes: 14 additions & 5 deletions foyer-storage/src/device/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@

use std::{
fs::{create_dir_all, File, OpenOptions},
os::{
fd::{AsRawFd, RawFd},
unix::prelude::OpenOptionsExt,
},
os::fd::{AsRawFd, RawFd},
path::PathBuf,
sync::Arc,
};
Expand Down Expand Up @@ -64,6 +61,7 @@ impl FsDeviceConfig {
struct FsDeviceInner {
config: FsDeviceConfig,

#[allow(unused)]
dir: File,

files: Vec<File>,
Expand Down Expand Up @@ -125,12 +123,12 @@ impl Device for FsDevice {
Ok(res)
}

#[cfg(target_os = "linux")]
async fn flush(&self) -> Result<()> {
let fd = self.inner.dir.as_raw_fd();
// Commit fs cache to disk. Linux waits for I/O completions.
//
// See also [syncfs(2)](https://man7.org/linux/man-pages/man2/sync.2.html)
#[cfg(target_os = "linux")]
asyncify(move || {
nix::unistd::syncfs(fd)?;
Ok(())
Expand All @@ -142,6 +140,13 @@ impl Device for FsDevice {
Ok(())
}

#[cfg(not(target_os = "linux"))]
async fn flush(&self) -> Result<()> {
// TODO(MrCroxx): track dirty files and call fsync(2) on them on other target os.

Ok(())
}

fn capacity(&self) -> usize {
self.inner.confi 745C g.capacity
}
Expand Down Expand Up @@ -190,10 +195,14 @@ impl FsDevice {
.map(|i| {
let path = config.dir.clone().join(Self::filename(i as RegionId));
async move {
#[cfg(target_os = "linux")]
use std::os::unix::prelude::OpenOptionsExt;

let mut opts = OpenOptions::new();
opts.create(true);
opts.write(true);
opts.read(true);
#[cfg(target_os = "linux")]
opts.custom_flags(libc::O_DIRECT);

let file = opts.open(path).map_err(Error::io)?;
Expand Down
0