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

fix: direct io syscall not available on mac #16574

Merged
merged 1 commit into from
Oct 9, 2024
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
77 changes: 57 additions & 20 deletions src/common/base/src/base/dma.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ use std::path::Path;
use std::ptr::Alignment;
use std::ptr::NonNull;

use rustix::fs::OFlags;
use tokio::fs::File;
use tokio::io::AsyncSeekExt;

Expand Down Expand Up @@ -109,31 +108,69 @@ struct DmaFile {
buf: Option<DmaBuffer>,
}

impl DmaFile {
/// Attempts to open a file in read-only mode.
async fn open(path: impl AsRef<Path>) -> io::Result<DmaFile> {
let file = File::options()
.read(true)
.custom_flags(OFlags::DIRECT.bits() as i32)
.open(path)
.await?;
#[cfg(target_os = "linux")]
pub mod linux {
use rustix::fs::OFlags;

use super::*;

impl DmaFile {
/// Attempts to open a file in read-only mode.
pub(super) async fn open(path: impl AsRef<Path>) -> io::Result<DmaFile> {
let file = File::options()
.read(true)
.custom_flags(OFlags::DIRECT.bits() as i32)
.open(path)
.await?;

open_dma(file).await
open_dma(file).await
}

/// Opens a file in write-only mode.
pub(super) async fn create(path: impl AsRef<Path>) -> io::Result<DmaFile> {
let file = File::options()
.write(true)
.create(true)
.truncate(true)
.custom_flags((OFlags::DIRECT | OFlags::EXCL).bits() as i32)
.open(path)
.await?;

open_dma(file).await
}
}
}

/// Opens a file in write-only mode.
async fn create(path: impl AsRef<Path>) -> io::Result<DmaFile> {
let file = File::options()
.write(true)
.create(true)
.truncate(true)
.custom_flags((OFlags::DIRECT | OFlags::EXCL).bits() as i32)
.open(path)
.await?;
#[cfg(not(target_os = "linux"))]
pub mod not_linux {
use rustix::fs::OFlags;

use super::*;

open_dma(file).await
impl DmaFile {
/// Attempts to open a file in read-only mode.
pub(super) async fn open(path: impl AsRef<Path>) -> io::Result<DmaFile> {
let file = File::options().read(true).open(path).await?;

open_dma(file).await
}

/// Opens a file in write-only mode.
pub(super) async fn create(path: impl AsRef<Path>) -> io::Result<DmaFile> {
let file = File::options()
.write(true)
.create(true)
.truncate(true)
.custom_flags(OFlags::EXCL.bits() as i32)
.open(path)
.await?;

open_dma(file).await
}
}
}

impl DmaFile {
fn set_buffer(&mut self, buf: DmaBuffer) {
self.buf = Some(buf)
}
Expand Down
Loading