-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
fs: Implement io-uring::Op<Statx> and use it to implement fs::try_exists and complete the todo's in read_uring #7791
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| use crate::fs::OpenOptions; | ||
| use crate::fs::UringOpenOptions; | ||
| use crate::runtime::driver::op::Op; | ||
|
|
||
| use std::io; | ||
|
|
@@ -17,15 +17,13 @@ const PROBE_SIZE_U32: u32 = PROBE_SIZE as u32; | |
| const MAX_READ_SIZE: usize = 64 * 1024 * 1024; | ||
|
|
||
| pub(crate) async fn read_uring(path: &Path) -> io::Result<Vec<u8>> { | ||
| let file = OpenOptions::new().read(true).open(path).await?; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd like to keep the |
||
| let fd = UringOpenOptions::new().read(true).open(path).await?; | ||
|
|
||
| // TODO: use io uring in the future to obtain metadata | ||
| let size_hint: Option<usize> = file.metadata().await.map(|m| m.len() as usize).ok(); | ||
| let (size_hint, fd) = Op::metadata_fd(fd).await; | ||
|
|
||
| let fd: OwnedFd = file | ||
| .try_into_std() | ||
| .expect("unexpected in-flight operation detected") | ||
| .into(); | ||
| let size_hint: Option<usize> = size_hint | ||
| .ok() | ||
| .map(|m| usize::try_from(m.len()).unwrap_or(usize::MAX)); | ||
|
|
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here if we obtain size_hint |
||
| let mut buf = Vec::new(); | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,6 +23,39 @@ use std::path::Path; | |
| /// # } | ||
| /// ``` | ||
| pub async fn try_exists(path: impl AsRef<Path>) -> io::Result<bool> { | ||
| let path = path.as_ref().to_owned(); | ||
| let path = path.as_ref(); | ||
|
|
||
| #[cfg(all( | ||
| tokio_unstable, | ||
| feature = "io-uring", | ||
| feature = "rt", | ||
| feature = "fs", | ||
| target_os = "linux" | ||
| ))] | ||
| { | ||
| let handle = crate::runtime::Handle::current(); | ||
| let driver_handle = handle.inner.driver().io(); | ||
| if driver_handle.check_and_init()? { | ||
| return try_exists_uring(path).await; | ||
| } | ||
| } | ||
|
|
||
| try_exists_spawn_blocking(path).await | ||
| } | ||
|
|
||
| cfg_io_uring! { | ||
| async fn try_exists_uring(path: &Path) -> io::Result<bool> { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: IMO this function can be inlined at line 39 above |
||
| use crate::runtime::driver::op::Op; | ||
|
|
||
| match Op::metadata(path)?.await { | ||
| Ok(_) => Ok(true), | ||
| Err(error) if error.kind() == io::ErrorKind::NotFound => Ok(false), | ||
| Err(error) => Err(error), | ||
| } | ||
| } | ||
| } | ||
|
|
||
| async fn try_exists_spawn_blocking(path: &Path) -> io::Result<bool> { | ||
| let path = path.to_owned(); | ||
| asyncify(move || path.try_exists()).await | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| pub(crate) mod open; | ||
| pub(crate) mod read; | ||
| pub(crate) mod statx; | ||
| pub(crate) mod utils; | ||
| pub(crate) mod write; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a particular reason to not use
libcinstead ?AFAIS it provides all the constants used in this PR from
linux-raw-sysThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please do not use
linux-raw-sys.