Use new Linux 5.12 openat2
with RESOLVE_CACHED
flag
#3733
Labels
A-tokio
Area: The main tokio crate
C-feature-request
Category: A feature request.
M-fs
Module: tokio/fs
Is your feature request related to a problem? Please describe.
We don't know whether opening a file will block or not, so we must hand it off to a thread-pool. This is inefficient if opening it wouldn't have required blocking.
Describe the solution you'd like
Try opening a file using
openat2
passing theRESOLVE_CACHED
flag only handing it off to the threadpool if it would block or if the flag is not supported. This is available on the recently released Linux 5.12. See LWN: https://lwn.net/Articles/843163/ .Describe alternatives you've considered
Alternatively users could use the
openat2
library directly like:But this requires specific handling by the user and requires
unsafe
.Additional context
This would be to
open
what #3518 was forread
.It looks like it might be tricky to do. Tokio's
File::open
wrapsstd::File::open
which takes atokio::OpenOptions
. This in turn wrapsstd::OpenOptions
, butstd::OpenOptions
doesn't provide any getters, only setters, so we can't get theflags
andmode
out to pass toopenat2
. We also can't changetokio::OpenOptions
to not be implemented in terms ofstd::OpenOptions
because it implementsFrom<std::OpenOptions>
, and the only thing you can do is store thatstd::OpenOptions
to be used later.Options:
std::fs::OpenOptions
openat2
support into std directly by enhancingstd::OpenOptions
open
API to tokio that doesn't useOpenOptions
.The text was updated successfully, but these errors were encountered: