mirror of
https://github.com/tokio-rs/tokio.git
synced 2026-08-27 00:00:12 +02:00
fs: use the Cargo feature for io-uring support instead of cfg (#7621)
Co-authored-by: Emile Fugulin <[email protected]>
This commit is contained in:
co-authored by
Emile Fugulin
parent
2af3e4430a
commit
3b5a15dfdf
+30
-65
@@ -78,8 +78,10 @@ jobs:
|
|||||||
- name: test tokio full
|
- name: test tokio full
|
||||||
run: |
|
run: |
|
||||||
set -euxo pipefail
|
set -euxo pipefail
|
||||||
cargo nextest run --features full
|
# We use `--features "full,test-util"` instead of `--all-features` since
|
||||||
cargo test --doc --features full
|
# `--all-features` includes `io_uring`, which is not available on all targets.
|
||||||
|
cargo nextest run --features full,test-util
|
||||||
|
cargo test --doc --features full,test-util
|
||||||
working-directory: tokio
|
working-directory: tokio
|
||||||
|
|
||||||
test-workspace-all-features:
|
test-workspace-all-features:
|
||||||
@@ -245,9 +247,12 @@ jobs:
|
|||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
include:
|
include:
|
||||||
- os: windows-latest
|
# We use `--features "full,test-util"` instead of `--all-features` since
|
||||||
- os: ubuntu-latest
|
# `--all-features` includes `io_uring`, which is not available on all targets.
|
||||||
- os: macos-latest
|
- { os: windows-latest, features: "full,test-util" }
|
||||||
|
- { os: ubuntu-latest, features: "full,test-util" }
|
||||||
|
- { os: ubuntu-latest, features: "full,test-util,io-uring" }
|
||||||
|
- { os: macos-latest, features: "full,test-util" }
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v5
|
- uses: actions/checkout@v5
|
||||||
- name: Install Rust ${{ env.rust_stable }}
|
- name: Install Rust ${{ env.rust_stable }}
|
||||||
@@ -265,8 +270,8 @@ jobs:
|
|||||||
- name: test tokio full --cfg unstable
|
- name: test tokio full --cfg unstable
|
||||||
run: |
|
run: |
|
||||||
set -euxo pipefail
|
set -euxo pipefail
|
||||||
cargo nextest run --all-features
|
cargo nextest run --features ${{ matrix.features }}
|
||||||
cargo test --doc --all-features
|
cargo test --doc --features ${{ matrix.features }}
|
||||||
working-directory: tokio
|
working-directory: tokio
|
||||||
env:
|
env:
|
||||||
RUSTFLAGS: --cfg tokio_unstable -Dwarnings
|
RUSTFLAGS: --cfg tokio_unstable -Dwarnings
|
||||||
@@ -308,50 +313,6 @@ jobs:
|
|||||||
# the unstable cfg to RustDoc
|
# the unstable cfg to RustDoc
|
||||||
RUSTDOCFLAGS: --cfg tokio_unstable --cfg tokio_taskdump
|
RUSTDOCFLAGS: --cfg tokio_unstable --cfg tokio_taskdump
|
||||||
|
|
||||||
test-uring:
|
|
||||||
name: test tokio full --cfg tokio_uring
|
|
||||||
needs: basics
|
|
||||||
runs-on: ${{ matrix.os }}
|
|
||||||
strategy:
|
|
||||||
matrix:
|
|
||||||
include:
|
|
||||||
- os: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- name: check if io-uring is supported in the CI environment
|
|
||||||
run: |
|
|
||||||
# Try to read the io-uring setting in the kernel config file.
|
|
||||||
# https://github.com/torvalds/linux/blob/75f5f23f8787c5e184fcb2fbcd02d8e9317dc5e7/init/Kconfig#L1782-L1789
|
|
||||||
CONFIG_FILE="/boot/config-$(uname -r)"
|
|
||||||
echo "Checking $CONFIG_FILE for io-uring support"
|
|
||||||
if ! grep -q "CONFIG_IO_URING=y" "$CONFIG_FILE"; then
|
|
||||||
echo "Error: io_uring is not supported"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
- uses: actions/checkout@v5
|
|
||||||
- name: Install Rust ${{ env.rust_stable }}
|
|
||||||
uses: dtolnay/rust-toolchain@stable
|
|
||||||
with:
|
|
||||||
toolchain: ${{ env.rust_stable }}
|
|
||||||
|
|
||||||
- name: Install cargo-nextest
|
|
||||||
uses: taiki-e/install-action@v2
|
|
||||||
with:
|
|
||||||
tool: cargo-nextest
|
|
||||||
|
|
||||||
- uses: Swatinem/rust-cache@v2
|
|
||||||
- name: test tokio full --cfg tokio_uring
|
|
||||||
run: |
|
|
||||||
set -euxo pipefail
|
|
||||||
cargo nextest run --all-features
|
|
||||||
cargo test --doc --all-features
|
|
||||||
working-directory: tokio
|
|
||||||
env:
|
|
||||||
RUSTFLAGS: --cfg tokio_uring -Dwarnings
|
|
||||||
# in order to run doctests for unstable features, we must also pass
|
|
||||||
# the unstable cfg to RustDoc
|
|
||||||
RUSTDOCFLAGS: --cfg tokio_uring
|
|
||||||
|
|
||||||
check-unstable-mt-counters:
|
check-unstable-mt-counters:
|
||||||
name: check tokio full --internal-mt-counters
|
name: check tokio full --internal-mt-counters
|
||||||
needs: basics
|
needs: basics
|
||||||
@@ -510,7 +471,8 @@ jobs:
|
|||||||
target: ${{ matrix.target }}
|
target: ${{ matrix.target }}
|
||||||
|
|
||||||
- uses: Swatinem/rust-cache@v2
|
- uses: Swatinem/rust-cache@v2
|
||||||
- run: cargo check --workspace --all-features --target ${{ matrix.target }}
|
# We don't use --all-features since io-uring will be enabled and is not supported on those targets.
|
||||||
|
- run: cargo check --workspace --features full,test-util --target ${{ matrix.target }}
|
||||||
env:
|
env:
|
||||||
RUSTFLAGS: --cfg tokio_unstable -Dwarnings
|
RUSTFLAGS: --cfg tokio_unstable -Dwarnings
|
||||||
|
|
||||||
@@ -580,8 +542,10 @@ jobs:
|
|||||||
- name: Tests run with all features (including parking_lot)
|
- name: Tests run with all features (including parking_lot)
|
||||||
run: |
|
run: |
|
||||||
set -euxo pipefail
|
set -euxo pipefail
|
||||||
cargo nextest run -p tokio --all-features --target ${{ matrix.target }}
|
# We use `--features "full,test-util"` instead of `--all-features` since
|
||||||
cargo test --doc -p tokio --all-features --target ${{ matrix.target }}
|
# `--all-features` includes `io_uring`, which is not available on all targets.
|
||||||
|
cargo nextest run -p tokio --features full,test-util --target ${{ matrix.target }}
|
||||||
|
cargo test --doc -p tokio --features full,test-util --target ${{ matrix.target }}
|
||||||
env:
|
env:
|
||||||
RUST_TEST_THREADS: 1
|
RUST_TEST_THREADS: 1
|
||||||
RUSTFLAGS: --cfg tokio_unstable -Dwarnings --cfg tokio_no_tuning_tests ${{ matrix.rustflags }}
|
RUSTFLAGS: --cfg tokio_unstable -Dwarnings --cfg tokio_no_tuning_tests ${{ matrix.rustflags }}
|
||||||
@@ -630,6 +594,8 @@ jobs:
|
|||||||
- name: Tests run with all features (without parking_lot)
|
- name: Tests run with all features (without parking_lot)
|
||||||
run: |
|
run: |
|
||||||
set -euxo pipefail
|
set -euxo pipefail
|
||||||
|
# We use `--features "full,test-util"` instead of `--all-features` since
|
||||||
|
# `--all-features` includes `io_uring`, which is not available on all targets.
|
||||||
cargo nextest run -p tokio --features full,test-util --target ${{ matrix.target }}
|
cargo nextest run -p tokio --features full,test-util --target ${{ matrix.target }}
|
||||||
cargo test --doc -p tokio --features full,test-util --target ${{ matrix.target }}
|
cargo test --doc -p tokio --features full,test-util --target ${{ matrix.target }}
|
||||||
env:
|
env:
|
||||||
@@ -662,8 +628,10 @@ jobs:
|
|||||||
- uses: Swatinem/rust-cache@v2
|
- uses: Swatinem/rust-cache@v2
|
||||||
- name: test tokio --all-features
|
- name: test tokio --all-features
|
||||||
run: |
|
run: |
|
||||||
cargo nextest run -Zbuild-std --target target-specs/i686-unknown-linux-gnu.json -p tokio --all-features
|
# We use `--features "full,test-util"` instead of `--all-features` since
|
||||||
cargo test --doc -Zbuild-std --target target-specs/i686-unknown-linux-gnu.json -p tokio --all-features
|
# `--all-features` includes `io_uring`, which is not available on all targets.
|
||||||
|
cargo nextest run -Zbuild-std --target target-specs/i686-unknown-linux-gnu.json -p tokio --features full,test-util
|
||||||
|
cargo test --doc -Zbuild-std --target target-specs/i686-unknown-linux-gnu.json -p tokio --features full,test-util
|
||||||
env:
|
env:
|
||||||
RUST_TEST_THREADS: 1
|
RUST_TEST_THREADS: 1
|
||||||
RUSTFLAGS: --cfg tokio_unstable --cfg tokio_taskdump -Dwarnings --cfg tokio_no_tuning_tests
|
RUSTFLAGS: --cfg tokio_unstable --cfg tokio_taskdump -Dwarnings --cfg tokio_no_tuning_tests
|
||||||
@@ -689,7 +657,8 @@ jobs:
|
|||||||
# https://github.com/tokio-rs/tokio/pull/5356
|
# https://github.com/tokio-rs/tokio/pull/5356
|
||||||
# https://github.com/tokio-rs/tokio/issues/5373
|
# https://github.com/tokio-rs/tokio/issues/5373
|
||||||
- name: Check
|
- name: Check
|
||||||
run: cargo hack check -Zbuild-std --target target-specs/i686-unknown-linux-gnu.json -p tokio --feature-powerset --depth 2 --keep-going
|
# We use `--skip io-uring` since io-uring crate doesn't provide a binding for the i686 target.
|
||||||
|
run: cargo hack check -Zbuild-std --target target-specs/i686-unknown-linux-gnu.json -p tokio --feature-powerset --skip io-uring --depth 2 --keep-going
|
||||||
env:
|
env:
|
||||||
RUSTFLAGS: --cfg tokio_unstable --cfg tokio_taskdump -Dwarnings
|
RUSTFLAGS: --cfg tokio_unstable --cfg tokio_taskdump -Dwarnings
|
||||||
|
|
||||||
@@ -701,12 +670,8 @@ jobs:
|
|||||||
matrix:
|
matrix:
|
||||||
include:
|
include:
|
||||||
- { name: "", rustflags: "" }
|
- { name: "", rustflags: "" }
|
||||||
# Try with unstable feature flags
|
|
||||||
- { name: "--unstable", rustflags: "--cfg tokio_unstable -Dwarnings" }
|
- { name: "--unstable", rustflags: "--cfg tokio_unstable -Dwarnings" }
|
||||||
# Try with unstable and taskdump feature flags
|
|
||||||
- { name: "--unstable --taskdump", rustflags: "--cfg tokio_unstable -Dwarnings --cfg tokio_taskdump" }
|
- { name: "--unstable --taskdump", rustflags: "--cfg tokio_unstable -Dwarnings --cfg tokio_taskdump" }
|
||||||
- { name: "--tokio_uring", rustflags: "-Dwarnings --cfg tokio_uring" }
|
|
||||||
- { name: "--unstable --taskdump --tokio_uring", rustflags: "--cfg tokio_unstable -Dwarnings --cfg tokio_taskdump --cfg tokio_uring" }
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v5
|
- uses: actions/checkout@v5
|
||||||
- name: Install Rust ${{ env.rust_nightly }}
|
- name: Install Rust ${{ env.rust_nightly }}
|
||||||
@@ -769,7 +734,7 @@ jobs:
|
|||||||
cargo hack check --all-features --ignore-private
|
cargo hack check --all-features --ignore-private
|
||||||
- name: "check --all-features --unstable -Z minimal-versions"
|
- name: "check --all-features --unstable -Z minimal-versions"
|
||||||
env:
|
env:
|
||||||
RUSTFLAGS: --cfg tokio_unstable --cfg tokio_taskdump --cfg tokio_uring -Dwarnings
|
RUSTFLAGS: --cfg tokio_unstable --cfg tokio_taskdump -Dwarnings
|
||||||
run: |
|
run: |
|
||||||
# Remove dev-dependencies from Cargo.toml to prevent the next `cargo update`
|
# Remove dev-dependencies from Cargo.toml to prevent the next `cargo update`
|
||||||
# from determining minimal versions based on dev-dependencies.
|
# from determining minimal versions based on dev-dependencies.
|
||||||
@@ -805,7 +770,7 @@ jobs:
|
|||||||
matrix:
|
matrix:
|
||||||
rustflags:
|
rustflags:
|
||||||
- ""
|
- ""
|
||||||
- "--cfg tokio_unstable --cfg tokio_taskdump --cfg tokio_uring -Dwarnings"
|
- "--cfg tokio_unstable --cfg tokio_taskdump -Dwarnings"
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v5
|
- uses: actions/checkout@v5
|
||||||
- name: Install Rust ${{ env.rust_clippy }}
|
- name: Install Rust ${{ env.rust_clippy }}
|
||||||
@@ -828,8 +793,8 @@ jobs:
|
|||||||
run:
|
run:
|
||||||
- os: windows-latest
|
- os: windows-latest
|
||||||
- os: ubuntu-latest
|
- os: ubuntu-latest
|
||||||
RUSTFLAGS: --cfg tokio_taskdump --cfg tokio_uring
|
RUSTFLAGS: --cfg tokio_taskdump
|
||||||
RUSTDOCFLAGS: --cfg tokio_taskdump --cfg tokio_uring
|
RUSTDOCFLAGS: --cfg tokio_taskdump
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v5
|
- uses: actions/checkout@v5
|
||||||
|
|||||||
@@ -44,8 +44,8 @@ jobs:
|
|||||||
run: |
|
run: |
|
||||||
# Build both integration (tokio/tests/) and unit (e.g., tokio/src/fs/file/tests.rs) tests with io_uring enabled
|
# Build both integration (tokio/tests/) and unit (e.g., tokio/src/fs/file/tests.rs) tests with io_uring enabled
|
||||||
rustup target add x86_64-unknown-linux-musl
|
rustup target add x86_64-unknown-linux-musl
|
||||||
RUSTFLAGS="--cfg tokio_uring" \
|
RUSTFLAGS="--cfg tokio_unstable" \
|
||||||
cargo test -p tokio --features full \
|
cargo test -p tokio --features full,io-uring \
|
||||||
--target x86_64-unknown-linux-musl --test 'fs*' --lib --no-run
|
--target x86_64-unknown-linux-musl --test 'fs*' --lib --no-run
|
||||||
|
|
||||||
- name: Prepare initramfs + tests binaries
|
- name: Prepare initramfs + tests binaries
|
||||||
|
|||||||
@@ -29,6 +29,5 @@ unexpected_cfgs = { level = "warn", check-cfg = [
|
|||||||
'cfg(tokio_no_tuning_tests)',
|
'cfg(tokio_no_tuning_tests)',
|
||||||
'cfg(tokio_taskdump)',
|
'cfg(tokio_taskdump)',
|
||||||
'cfg(tokio_unstable)',
|
'cfg(tokio_unstable)',
|
||||||
'cfg(tokio_uring)',
|
|
||||||
'cfg(target_os, values("cygwin"))',
|
'cfg(target_os, values("cygwin"))',
|
||||||
] }
|
] }
|
||||||
|
|||||||
+11
-7
@@ -84,6 +84,8 @@ signal = [
|
|||||||
sync = []
|
sync = []
|
||||||
test-util = ["rt", "sync", "time"]
|
test-util = ["rt", "sync", "time"]
|
||||||
time = []
|
time = []
|
||||||
|
# Unstable feature. Requires `--cfg tokio_unstable` to enable.
|
||||||
|
io-uring = ["dep:io-uring", "libc", "mio/os-poll", "mio/os-ext", "dep:slab"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
tokio-macros = { version = "~2.5.0", path = "../tokio-macros", optional = true }
|
tokio-macros = { version = "~2.5.0", path = "../tokio-macros", optional = true }
|
||||||
@@ -103,11 +105,13 @@ socket2 = { version = "0.6.0", optional = true, features = ["all"] }
|
|||||||
[target.'cfg(tokio_unstable)'.dependencies]
|
[target.'cfg(tokio_unstable)'.dependencies]
|
||||||
tracing = { version = "0.1.29", default-features = false, features = ["std"], optional = true } # Not in full
|
tracing = { version = "0.1.29", default-features = false, features = ["std"], optional = true } # Not in full
|
||||||
|
|
||||||
[target.'cfg(all(tokio_uring, target_os = "linux"))'.dependencies]
|
# Currently unstable. The API exposed by these features may be broken at any time.
|
||||||
io-uring = { version = "0.7.6", default-features = false }
|
# Requires `--cfg tokio_unstable` to enable.
|
||||||
libc = { version = "0.2.168" }
|
[target.'cfg(all(tokio_unstable, target_os = "linux"))'.dependencies]
|
||||||
mio = { version = "1.0.1", default-features = false, features = ["os-poll", "os-ext"] }
|
io-uring = { version = "0.7.6", default-features = false, optional = true }
|
||||||
slab = "0.4.9"
|
libc = { version = "0.2.168", optional = true }
|
||||||
|
mio = { version = "1.0.1", default-features = false, features = ["os-poll", "os-ext"], optional = true }
|
||||||
|
slab = { version = "0.4.9", optional = true }
|
||||||
|
|
||||||
# Currently unstable. The API exposed by these features may be broken at any time.
|
# Currently unstable. The API exposed by these features may be broken at any time.
|
||||||
# Requires `--cfg tokio_unstable` to enable.
|
# Requires `--cfg tokio_unstable` to enable.
|
||||||
@@ -165,10 +169,10 @@ tracing-mock = "= 0.1.0-beta.1"
|
|||||||
[package.metadata.docs.rs]
|
[package.metadata.docs.rs]
|
||||||
all-features = true
|
all-features = true
|
||||||
# enable unstable features in the documentation
|
# enable unstable features in the documentation
|
||||||
rustdoc-args = ["--cfg", "docsrs", "--cfg", "tokio_unstable", "--cfg", "tokio_taskdump", "--cfg", "tokio_uring"]
|
rustdoc-args = ["--cfg", "docsrs", "--cfg", "tokio_unstable", "--cfg", "tokio_taskdump"]
|
||||||
# it's necessary to _also_ pass `--cfg tokio_unstable` and `--cfg tokio_taskdump`
|
# it's necessary to _also_ pass `--cfg tokio_unstable` and `--cfg tokio_taskdump`
|
||||||
# to rustc, or else dependencies will not be enabled, and the docs build will fail.
|
# to rustc, or else dependencies will not be enabled, and the docs build will fail.
|
||||||
rustc-args = ["--cfg", "tokio_unstable", "--cfg", "tokio_taskdump", "--cfg", "tokio_uring"]
|
rustc-args = ["--cfg", "tokio_unstable", "--cfg", "tokio_taskdump"]
|
||||||
|
|
||||||
[package.metadata.playground]
|
[package.metadata.playground]
|
||||||
features = ["full", "test-util"]
|
features = ["full", "test-util"]
|
||||||
|
|||||||
+1
-1
@@ -237,7 +237,7 @@ pub use self::metadata::metadata;
|
|||||||
|
|
||||||
mod open_options;
|
mod open_options;
|
||||||
pub use self::open_options::OpenOptions;
|
pub use self::open_options::OpenOptions;
|
||||||
cfg_tokio_uring! {
|
cfg_io_uring! {
|
||||||
pub(crate) use self::open_options::UringOpenOptions;
|
pub(crate) use self::open_options::UringOpenOptions;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ use crate::fs::{asyncify, File};
|
|||||||
use std::io;
|
use std::io;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
|
||||||
cfg_tokio_uring! {
|
cfg_io_uring! {
|
||||||
mod uring_open_options;
|
mod uring_open_options;
|
||||||
pub(crate) use uring_open_options::UringOpenOptions;
|
pub(crate) use uring_open_options::UringOpenOptions;
|
||||||
use crate::runtime::driver::op::Op;
|
use crate::runtime::driver::op::Op;
|
||||||
@@ -92,7 +92,13 @@ pub struct OpenOptions {
|
|||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
enum Kind {
|
enum Kind {
|
||||||
Std(StdOpenOptions),
|
Std(StdOpenOptions),
|
||||||
#[cfg(all(tokio_uring, feature = "rt", feature = "fs", target_os = "linux"))]
|
#[cfg(all(
|
||||||
|
tokio_unstable,
|
||||||
|
feature = "io-uring",
|
||||||
|
feature = "rt",
|
||||||
|
feature = "fs",
|
||||||
|
target_os = "linux"
|
||||||
|
))]
|
||||||
Uring(UringOpenOptions),
|
Uring(UringOpenOptions),
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -114,9 +120,21 @@ impl OpenOptions {
|
|||||||
/// let future = options.read(true).open("foo.txt");
|
/// let future = options.read(true).open("foo.txt");
|
||||||
/// ```
|
/// ```
|
||||||
pub fn new() -> OpenOptions {
|
pub fn new() -> OpenOptions {
|
||||||
#[cfg(all(tokio_uring, feature = "rt", feature = "fs", target_os = "linux"))]
|
#[cfg(all(
|
||||||
|
tokio_unstable,
|
||||||
|
feature = "io-uring",
|
||||||
|
feature = "rt",
|
||||||
|
feature = "fs",
|
||||||
|
target_os = "linux"
|
||||||
|
))]
|
||||||
let inner = Kind::Uring(UringOpenOptions::new());
|
let inner = Kind::Uring(UringOpenOptions::new());
|
||||||
#[cfg(not(all(tokio_uring, feature = "rt", feature = "fs", target_os = "linux")))]
|
#[cfg(not(all(
|
||||||
|
tokio_unstable,
|
||||||
|
feature = "io-uring",
|
||||||
|
feature = "rt",
|
||||||
|
feature = "fs",
|
||||||
|
target_os = "linux"
|
||||||
|
)))]
|
||||||
let inner = Kind::Std(StdOpenOptions::new());
|
let inner = Kind::Std(StdOpenOptions::new());
|
||||||
|
|
||||||
OpenOptions { inner }
|
OpenOptions { inner }
|
||||||
@@ -152,7 +170,13 @@ impl OpenOptions {
|
|||||||
Kind::Std(opts) => {
|
Kind::Std(opts) => {
|
||||||
opts.read(read);
|
opts.read(read);
|
||||||
}
|
}
|
||||||
#[cfg(all(tokio_uring, feature = "rt", feature = "fs", target_os = "linux"))]
|
#[cfg(all(
|
||||||
|
tokio_unstable,
|
||||||
|
feature = "io-uring",
|
||||||
|
feature = "rt",
|
||||||
|
feature = "fs",
|
||||||
|
target_os = "linux"
|
||||||
|
))]
|
||||||
Kind::Uring(opts) => {
|
Kind::Uring(opts) => {
|
||||||
opts.read(read);
|
opts.read(read);
|
||||||
}
|
}
|
||||||
@@ -190,7 +214,13 @@ impl OpenOptions {
|
|||||||
Kind::Std(opts) => {
|
Kind::Std(opts) => {
|
||||||
opts.write(write);
|
opts.write(write);
|
||||||
}
|
}
|
||||||
#[cfg(all(tokio_uring, feature = "rt", feature = "fs", target_os = "linux"))]
|
#[cfg(all(
|
||||||
|
tokio_unstable,
|
||||||
|
feature = "io-uring",
|
||||||
|
feature = "rt",
|
||||||
|
feature = "fs",
|
||||||
|
target_os = "linux"
|
||||||
|
))]
|
||||||
Kind::Uring(opts) => {
|
Kind::Uring(opts) => {
|
||||||
opts.write(write);
|
opts.write(write);
|
||||||
}
|
}
|
||||||
@@ -257,7 +287,13 @@ impl OpenOptions {
|
|||||||
Kind::Std(opts) => {
|
Kind::Std(opts) => {
|
||||||
opts.append(append);
|
opts.append(append);
|
||||||
}
|
}
|
||||||
#[cfg(all(tokio_uring, feature = "rt", feature = "fs", target_os = "linux"))]
|
#[cfg(all(
|
||||||
|
tokio_unstable,
|
||||||
|
feature = "io-uring",
|
||||||
|
feature = "rt",
|
||||||
|
feature = "fs",
|
||||||
|
target_os = "linux"
|
||||||
|
))]
|
||||||
Kind::Uring(opts) => {
|
Kind::Uring(opts) => {
|
||||||
opts.append(append);
|
opts.append(append);
|
||||||
}
|
}
|
||||||
@@ -298,7 +334,13 @@ impl OpenOptions {
|
|||||||
Kind::Std(opts) => {
|
Kind::Std(opts) => {
|
||||||
opts.truncate(truncate);
|
opts.truncate(truncate);
|
||||||
}
|
}
|
||||||
#[cfg(all(tokio_uring, feature = "rt", feature = "fs", target_os = "linux"))]
|
#[cfg(all(
|
||||||
|
tokio_unstable,
|
||||||
|
feature = "io-uring",
|
||||||
|
feature = "rt",
|
||||||
|
feature = "fs",
|
||||||
|
target_os = "linux"
|
||||||
|
))]
|
||||||
Kind::Uring(opts) => {
|
Kind::Uring(opts) => {
|
||||||
opts.truncate(truncate);
|
opts.truncate(truncate);
|
||||||
}
|
}
|
||||||
@@ -342,7 +384,13 @@ impl OpenOptions {
|
|||||||
Kind::Std(opts) => {
|
Kind::Std(opts) => {
|
||||||
opts.create(create);
|
opts.create(create);
|
||||||
}
|
}
|
||||||
#[cfg(all(tokio_uring, feature = "rt", feature = "fs", target_os = "linux"))]
|
#[cfg(all(
|
||||||
|
tokio_unstable,
|
||||||
|
feature = "io-uring",
|
||||||
|
feature = "rt",
|
||||||
|
feature = "fs",
|
||||||
|
target_os = "linux"
|
||||||
|
))]
|
||||||
Kind::Uring(opts) => {
|
Kind::Uring(opts) => {
|
||||||
opts.create(create);
|
opts.create(create);
|
||||||
}
|
}
|
||||||
@@ -393,7 +441,13 @@ impl OpenOptions {
|
|||||||
Kind::Std(opts) => {
|
Kind::Std(opts) => {
|
||||||
opts.create_new(create_new);
|
opts.create_new(create_new);
|
||||||
}
|
}
|
||||||
#[cfg(all(tokio_uring, feature = "rt", feature = "fs", target_os = "linux"))]
|
#[cfg(all(
|
||||||
|
tokio_unstable,
|
||||||
|
feature = "io-uring",
|
||||||
|
feature = "rt",
|
||||||
|
feature = "fs",
|
||||||
|
target_os = "linux"
|
||||||
|
))]
|
||||||
Kind::Uring(opts) => {
|
Kind::Uring(opts) => {
|
||||||
opts.create_new(create_new);
|
opts.create_new(create_new);
|
||||||
}
|
}
|
||||||
@@ -437,8 +491,9 @@ impl OpenOptions {
|
|||||||
/// # io_uring support
|
/// # io_uring support
|
||||||
///
|
///
|
||||||
/// On Linux, you can also use `io_uring` for executing system calls.
|
/// On Linux, you can also use `io_uring` for executing system calls.
|
||||||
/// To enable `io_uring`, you need to specify the `--cfg tokio_uring` flag
|
/// To enable `io_uring`, you need to specify the `--cfg tokio_unstable`
|
||||||
/// at compile time and set the `Builder::enable_io_uring` runtime option.
|
/// flag at compile time, enable the `io-uring` cargo feature, and set the
|
||||||
|
/// `Builder::enable_io_uring` runtime option.
|
||||||
///
|
///
|
||||||
/// Support for `io_uring` is currently experimental, so its behavior may
|
/// Support for `io_uring` is currently experimental, so its behavior may
|
||||||
/// change or it may be removed in future versions.
|
/// change or it may be removed in future versions.
|
||||||
@@ -465,7 +520,13 @@ impl OpenOptions {
|
|||||||
pub async fn open(&self, path: impl AsRef<Path>) -> io::Result<File> {
|
pub async fn open(&self, path: impl AsRef<Path>) -> io::Result<File> {
|
||||||
match &self.inner {
|
match &self.inner {
|
||||||
Kind::Std(opts) => Self::std_open(opts, path).await,
|
Kind::Std(opts) => Self::std_open(opts, path).await,
|
||||||
#[cfg(all(tokio_uring, feature = "rt", feature = "fs", target_os = "linux"))]
|
#[cfg(all(
|
||||||
|
tokio_unstable,
|
||||||
|
feature = "io-uring",
|
||||||
|
feature = "rt",
|
||||||
|
feature = "fs",
|
||||||
|
target_os = "linux"
|
||||||
|
))]
|
||||||
Kind::Uring(opts) => {
|
Kind::Uring(opts) => {
|
||||||
let handle = crate::runtime::Handle::current();
|
let handle = crate::runtime::Handle::current();
|
||||||
let driver_handle = handle.inner.driver().io();
|
let driver_handle = handle.inner.driver().io();
|
||||||
@@ -528,7 +589,13 @@ feature! {
|
|||||||
Kind::Std(opts) => {
|
Kind::Std(opts) => {
|
||||||
opts.mode(mode);
|
opts.mode(mode);
|
||||||
}
|
}
|
||||||
#[cfg(all(tokio_uring, feature = "rt", feature = "fs", target_os = "linux"))]
|
#[cfg(all(
|
||||||
|
tokio_unstable,
|
||||||
|
feature = "io-uring",
|
||||||
|
feature = "rt",
|
||||||
|
feature = "fs",
|
||||||
|
target_os = "linux"
|
||||||
|
))]
|
||||||
Kind::Uring(opts) => {
|
Kind::Uring(opts) => {
|
||||||
opts.mode(mode);
|
opts.mode(mode);
|
||||||
}
|
}
|
||||||
@@ -567,7 +634,13 @@ feature! {
|
|||||||
Kind::Std(opts) => {
|
Kind::Std(opts) => {
|
||||||
opts.custom_flags(flags);
|
opts.custom_flags(flags);
|
||||||
}
|
}
|
||||||
#[cfg(all(tokio_uring, feature = "rt", feature = "fs", target_os = "linux"))]
|
#[cfg(all(
|
||||||
|
tokio_unstable,
|
||||||
|
feature = "io-uring",
|
||||||
|
feature = "rt",
|
||||||
|
feature = "fs",
|
||||||
|
target_os = "linux"
|
||||||
|
))]
|
||||||
Kind::Uring(opts) => {
|
Kind::Uring(opts) => {
|
||||||
opts.custom_flags(flags);
|
opts.custom_flags(flags);
|
||||||
}
|
}
|
||||||
@@ -766,7 +839,7 @@ impl From<StdOpenOptions> for OpenOptions {
|
|||||||
OpenOptions {
|
OpenOptions {
|
||||||
inner: Kind::Std(options),
|
inner: Kind::Std(options),
|
||||||
// TODO: Add support for converting `StdOpenOptions` to `UringOpenOptions`
|
// TODO: Add support for converting `StdOpenOptions` to `UringOpenOptions`
|
||||||
// if user enables the `--cfg tokio_uring`. It is blocked by:
|
// if user enables `io-uring` cargo feature. It is blocked by:
|
||||||
// * https://github.com/rust-lang/rust/issues/74943
|
// * https://github.com/rust-lang/rust/issues/74943
|
||||||
// * https://github.com/rust-lang/rust/issues/76801
|
// * https://github.com/rust-lang/rust/issues/76801
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -294,6 +294,6 @@ cfg_io_blocking! {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
cfg_tokio_uring! {
|
cfg_io_uring! {
|
||||||
pub(crate) mod uring;
|
pub(crate) mod uring;
|
||||||
}
|
}
|
||||||
|
|||||||
+15
-8
@@ -142,7 +142,8 @@ macro_rules! cfg_io_driver {
|
|||||||
all(unix, feature = "process"),
|
all(unix, feature = "process"),
|
||||||
all(unix, feature = "signal"),
|
all(unix, feature = "signal"),
|
||||||
all(
|
all(
|
||||||
tokio_uring,
|
tokio_unstable,
|
||||||
|
feature = "io-uring",
|
||||||
feature = "rt",
|
feature = "rt",
|
||||||
feature = "fs",
|
feature = "fs",
|
||||||
target_os = "linux"
|
target_os = "linux"
|
||||||
@@ -153,7 +154,8 @@ macro_rules! cfg_io_driver {
|
|||||||
all(unix, feature = "process"),
|
all(unix, feature = "process"),
|
||||||
all(unix, feature = "signal"),
|
all(unix, feature = "signal"),
|
||||||
all(
|
all(
|
||||||
tokio_uring,
|
tokio_unstable,
|
||||||
|
feature = "io-uring",
|
||||||
feature = "rt",
|
feature = "rt",
|
||||||
feature = "fs",
|
feature = "fs",
|
||||||
target_os = "linux"
|
target_os = "linux"
|
||||||
@@ -172,7 +174,8 @@ macro_rules! cfg_io_driver_impl {
|
|||||||
all(unix, feature = "process"),
|
all(unix, feature = "process"),
|
||||||
all(unix, feature = "signal"),
|
all(unix, feature = "signal"),
|
||||||
all(
|
all(
|
||||||
tokio_uring,
|
tokio_unstable,
|
||||||
|
feature = "io-uring",
|
||||||
feature = "rt",
|
feature = "rt",
|
||||||
feature = "fs",
|
feature = "fs",
|
||||||
target_os = "linux"
|
target_os = "linux"
|
||||||
@@ -191,7 +194,8 @@ macro_rules! cfg_not_io_driver {
|
|||||||
all(unix, feature = "process"),
|
all(unix, feature = "process"),
|
||||||
all(unix, feature = "signal"),
|
all(unix, feature = "signal"),
|
||||||
all(
|
all(
|
||||||
tokio_uring,
|
tokio_unstable,
|
||||||
|
feature = "io-uring",
|
||||||
feature = "rt",
|
feature = "rt",
|
||||||
feature = "fs",
|
feature = "fs",
|
||||||
target_os = "linux"
|
target_os = "linux"
|
||||||
@@ -330,7 +334,8 @@ macro_rules! cfg_net_or_uring {
|
|||||||
#[cfg(any(
|
#[cfg(any(
|
||||||
feature = "net",
|
feature = "net",
|
||||||
all(
|
all(
|
||||||
tokio_uring,
|
tokio_unstable,
|
||||||
|
feature = "io-uring",
|
||||||
feature = "rt",
|
feature = "rt",
|
||||||
feature = "fs",
|
feature = "fs",
|
||||||
target_os = "linux",
|
target_os = "linux",
|
||||||
@@ -341,7 +346,8 @@ macro_rules! cfg_net_or_uring {
|
|||||||
doc(cfg(any(
|
doc(cfg(any(
|
||||||
feature = "net",
|
feature = "net",
|
||||||
all(
|
all(
|
||||||
tokio_uring,
|
tokio_unstable,
|
||||||
|
feature = "io-uring",
|
||||||
feature = "rt",
|
feature = "rt",
|
||||||
feature = "fs",
|
feature = "fs",
|
||||||
target_os = "linux",
|
target_os = "linux",
|
||||||
@@ -691,11 +697,12 @@ macro_rules! cfg_metrics_variant {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
macro_rules! cfg_tokio_uring {
|
macro_rules! cfg_io_uring {
|
||||||
($($item:item)*) => {
|
($($item:item)*) => {
|
||||||
$(
|
$(
|
||||||
#[cfg(all(
|
#[cfg(all(
|
||||||
tokio_uring,
|
tokio_unstable,
|
||||||
|
feature = "io-uring",
|
||||||
feature = "rt",
|
feature = "rt",
|
||||||
feature = "fs",
|
feature = "fs",
|
||||||
target_os = "linux",
|
target_os = "linux",
|
||||||
|
|||||||
@@ -339,7 +339,13 @@ impl Builder {
|
|||||||
))]
|
))]
|
||||||
self.enable_io();
|
self.enable_io();
|
||||||
|
|
||||||
#[cfg(all(tokio_uring, feature = "rt", feature = "fs", target_os = "linux",))]
|
#[cfg(all(
|
||||||
|
tokio_unstable,
|
||||||
|
feature = "io-uring",
|
||||||
|
feature = "rt",
|
||||||
|
feature = "fs",
|
||||||
|
target_os = "linux",
|
||||||
|
))]
|
||||||
self.enable_io_uring();
|
self.enable_io_uring();
|
||||||
|
|
||||||
#[cfg(feature = "time")]
|
#[cfg(feature = "time")]
|
||||||
@@ -1584,7 +1590,7 @@ cfg_time! {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
cfg_tokio_uring! {
|
cfg_io_uring! {
|
||||||
impl Builder {
|
impl Builder {
|
||||||
/// Enables the tokio's io_uring driver.
|
/// Enables the tokio's io_uring driver.
|
||||||
///
|
///
|
||||||
@@ -1600,7 +1606,7 @@ cfg_tokio_uring! {
|
|||||||
/// .build()
|
/// .build()
|
||||||
/// .unwrap();
|
/// .unwrap();
|
||||||
/// ```
|
/// ```
|
||||||
#[cfg_attr(docsrs, doc(cfg(tokio_uring)))]
|
#[cfg_attr(docsrs, doc(cfg(feature = "io-uring")))]
|
||||||
pub fn enable_io_uring(&mut self) -> &mut Self {
|
pub fn enable_io_uring(&mut self) -> &mut Self {
|
||||||
// Currently, the uring flag is equivalent to `enable_io`.
|
// Currently, the uring flag is equivalent to `enable_io`.
|
||||||
self.enable_io = true;
|
self.enable_io = true;
|
||||||
|
|||||||
@@ -348,6 +348,6 @@ cfg_not_time! {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
cfg_tokio_uring! {
|
cfg_io_uring! {
|
||||||
pub(crate) mod op;
|
pub(crate) mod op;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
cfg_signal_internal_and_unix! {
|
cfg_signal_internal_and_unix! {
|
||||||
mod signal;
|
mod signal;
|
||||||
}
|
}
|
||||||
cfg_tokio_uring! {
|
cfg_io_uring! {
|
||||||
mod uring;
|
mod uring;
|
||||||
use uring::UringContext;
|
use uring::UringContext;
|
||||||
use crate::loom::sync::atomic::AtomicUsize;
|
use crate::loom::sync::atomic::AtomicUsize;
|
||||||
@@ -51,10 +51,22 @@ pub(crate) struct Handle {
|
|||||||
|
|
||||||
pub(crate) metrics: IoDriverMetrics,
|
pub(crate) metrics: IoDriverMetrics,
|
||||||
|
|
||||||
#[cfg(all(tokio_uring, feature = "rt", feature = "fs", target_os = "linux",))]
|
#[cfg(all(
|
||||||
|
tokio_unstable,
|
||||||
|
feature = "io-uring",
|
||||||
|
feature = "rt",
|
||||||
|
feature = "fs",
|
||||||
|
target_os = "linux",
|
||||||
|
))]
|
||||||
pub(crate) uring_context: Mutex<UringContext>,
|
pub(crate) uring_context: Mutex<UringContext>,
|
||||||
|
|
||||||
#[cfg(all(tokio_uring, feature = "rt", feature = "fs", target_os = "linux",))]
|
#[cfg(all(
|
||||||
|
tokio_unstable,
|
||||||
|
feature = "io-uring",
|
||||||
|
feature = "rt",
|
||||||
|
feature = "fs",
|
||||||
|
target_os = "linux",
|
||||||
|
))]
|
||||||
pub(crate) uring_state: AtomicUsize,
|
pub(crate) uring_state: AtomicUsize,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -123,9 +135,21 @@ impl Driver {
|
|||||||
#[cfg(not(target_os = "wasi"))]
|
#[cfg(not(target_os = "wasi"))]
|
||||||
waker,
|
waker,
|
||||||
metrics: IoDriverMetrics::default(),
|
metrics: IoDriverMetrics::default(),
|
||||||
#[cfg(all(tokio_uring, feature = "rt", feature = "fs", target_os = "linux",))]
|
#[cfg(all(
|
||||||
|
tokio_unstable,
|
||||||
|
feature = "io-uring",
|
||||||
|
feature = "rt",
|
||||||
|
feature = "fs",
|
||||||
|
target_os = "linux",
|
||||||
|
))]
|
||||||
uring_context: Mutex::new(UringContext::new()),
|
uring_context: Mutex::new(UringContext::new()),
|
||||||
#[cfg(all(tokio_uring, feature = "rt", feature = "fs", target_os = "linux",))]
|
#[cfg(all(
|
||||||
|
tokio_unstable,
|
||||||
|
feature = "io-uring",
|
||||||
|
feature = "rt",
|
||||||
|
feature = "fs",
|
||||||
|
target_os = "linux",
|
||||||
|
))]
|
||||||
uring_state: AtomicUsize::new(0),
|
uring_state: AtomicUsize::new(0),
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -198,7 +222,13 @@ impl Driver {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(all(tokio_uring, feature = "rt", feature = "fs", target_os = "linux",))]
|
#[cfg(all(
|
||||||
|
tokio_unstable,
|
||||||
|
feature = "io-uring",
|
||||||
|
feature = "rt",
|
||||||
|
feature = "fs",
|
||||||
|
target_os = "linux",
|
||||||
|
))]
|
||||||
{
|
{
|
||||||
let mut guard = handle.get_uring().lock();
|
let mut guard = handle.get_uring().lock();
|
||||||
let ctx = &mut *guard;
|
let ctx = &mut *guard;
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
#![cfg_attr(
|
#![cfg_attr(
|
||||||
not(all(feature = "rt", feature = "net", tokio_uring)),
|
not(all(feature = "rt", feature = "net", feature = "io-uring", tokio_unstable)),
|
||||||
allow(dead_code)
|
allow(dead_code)
|
||||||
)]
|
)]
|
||||||
mod driver;
|
mod driver;
|
||||||
|
|||||||
@@ -16,7 +16,10 @@ async fn try_exists() {
|
|||||||
assert!(fs::try_exists(existing_path).await.unwrap());
|
assert!(fs::try_exists(existing_path).await.unwrap());
|
||||||
assert!(!fs::try_exists(nonexisting_path).await.unwrap());
|
assert!(!fs::try_exists(nonexisting_path).await.unwrap());
|
||||||
// FreeBSD root user always has permission to stat.
|
// FreeBSD root user always has permission to stat.
|
||||||
#[cfg(all(unix, not(any(target_os = "freebsd", tokio_uring))))]
|
#[cfg(all(
|
||||||
|
unix,
|
||||||
|
not(any(target_os = "freebsd", all(tokio_unstable, feature = "io-uring")))
|
||||||
|
))]
|
||||||
{
|
{
|
||||||
use std::os::unix::prelude::PermissionsExt;
|
use std::os::unix::prelude::PermissionsExt;
|
||||||
let permission_denied_directory_path = dir.path().join("baz");
|
let permission_denied_directory_path = dir.path().join("baz");
|
||||||
|
|||||||
@@ -1,6 +1,12 @@
|
|||||||
//! Uring file operations tests.
|
//! Uring file operations tests.
|
||||||
|
|
||||||
#![cfg(all(tokio_uring, feature = "rt", feature = "fs", target_os = "linux"))]
|
#![cfg(all(
|
||||||
|
tokio_unstable,
|
||||||
|
feature = "io-uring",
|
||||||
|
feature = "rt",
|
||||||
|
feature = "fs",
|
||||||
|
target_os = "linux"
|
||||||
|
))]
|
||||||
|
|
||||||
use futures::future::FutureExt;
|
use futures::future::FutureExt;
|
||||||
use std::sync::mpsc;
|
use std::sync::mpsc;
|
||||||
|
|||||||
Reference in New Issue
Block a user