-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Vendor in `OpenOptions` from `tokio-uring.git:d5e90539bd6d1c518e848298564a098c300866bc` * Remove the `OpenOptions::open()` function which is `tokio-uring`-specific * Add the extension trait that allows for conversion of OpenOptions into an `io_uring::squeue::Entry` * Use it throughout the code base.
- Loading branch information
Showing
6 changed files
with
485 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,4 +4,5 @@ | |
pub use crate::system::submission::op_fut::Op; | ||
|
||
pub mod nop; | ||
pub mod open_at; | ||
pub mod read; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
use crate::system::submission::op_fut::Op; | ||
use std::ffi::CString; | ||
use std::os::fd::{FromRawFd, OwnedFd}; | ||
use std::os::unix::prelude::OsStrExt; | ||
use std::path::Path; | ||
|
||
use uring_common::io_uring; | ||
pub use uring_common::open_options::OpenOptions; | ||
|
||
pub struct OpenAtOp { | ||
dir_fd: Option<OwnedFd>, | ||
_path: CString, // need to keep it alive for lifetime of the operation | ||
sqe: io_uring::squeue::Entry, | ||
} | ||
|
||
impl OpenAtOp { | ||
pub(crate) fn new_cwd(path: &Path, options: &OpenOptions) -> std::io::Result<Self> { | ||
let path = CString::new(path.as_os_str().as_bytes())?; | ||
// SAFETY: we keep `pathname` alive inside the OpenAtOp, so, the pointer stored int the SQE remains valid. | ||
let sqe = unsafe { | ||
uring_common::open_options_io_uring_ext::OpenOptionsIoUringExt::as_openat_sqe( | ||
options, | ||
path.as_c_str().as_ptr(), | ||
) | ||
}?; | ||
Ok(OpenAtOp { | ||
dir_fd: None, | ||
_path: path, | ||
sqe, | ||
}) | ||
} | ||
} | ||
|
||
impl crate::sealed::Sealed for OpenAtOp {} | ||
|
||
impl Op for OpenAtOp { | ||
type Resources = Option<OwnedFd>; | ||
type Success = OwnedFd; | ||
type Error = std::io::Error; | ||
|
||
fn make_sqe(&mut self) -> io_uring::squeue::Entry { | ||
self.sqe.clone() | ||
} | ||
|
||
fn on_failed_submission(self) -> Self::Resources { | ||
self.dir_fd | ||
} | ||
|
||
fn on_op_completion(self, res: i32) -> (Self::Resources, Result<Self::Success, Self::Error>) { | ||
// https://man.archlinux.org/man/io_uring_prep_openat.3.en | ||
// and https://man.archlinux.org/man/openat.2.en | ||
let res = if res < 0 { | ||
Err(std::io::Error::from_raw_os_error(-res)) | ||
} else { | ||
Ok(unsafe { OwnedFd::from_raw_fd(res) }) | ||
}; | ||
(self.dir_fd, res) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
pub mod buf; | ||
pub mod open_options; | ||
pub mod open_options_io_uring_ext; | ||
|
||
pub use io_uring; |
Oops, something went wrong.