Skip to content

Commit 69738c0

Browse files
bors[bot]asomers
andauthored
Merge #1713
1713: Rewrite the aio module r=rtzoeller a=asomers The existing AIO implementation has some problems: 1) The in_progress field is checked at runtime, not compile time. 2) The mutable field is checked at runtime, not compile time. 4) A downstream lio_listio user must store extra state to track whether the whole operation is partially, completely, or not at all submitted. 4) Nix does heap allocation itself, rather than allowing the caller to choose it. This can result in double (or triple, or quadruple) boxing. 5) There's no easy way to use lio_listio to submit multiple operations with a single syscall, but poll each individually. 6) The lio_listio usage is far from transparent and zero-cost. 7) No aio_readv or aio_writev support. 8) priority has type c_int; should be i32 9) aio_return should return a usize instead of an isize, since it only uses negative values to indicate errors, which Rust represents via the Result type. This rewrite solves several problems: 1) Unsolved. I don't think it can be solved without something like C++'s guaranteed type elision. It might require changing the signature of Future::poll too. 2) Solved. 3) Solved, by the new in_progress method and by removing the complicated lio_listio resubmit code. 4) Solved. 5) Solved. 6) Solved, by removing the lio_listo resubmit code. It can be reimplemented downstream if necessary. Or even in Nix, but it doesn't fit Nix's theme of zero-cost abstractions. 7) Solved. 8) Solved. 9) Solved. Co-authored-by: Alan Somers <[email protected]>
2 parents 1c36d49 + 0c07a9e commit 69738c0

File tree

9 files changed

+1570
-1525
lines changed

9 files changed

+1570
-1525
lines changed

.cirrus.yml

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,18 @@ test: &TEST
3636
# 64-bit kernel and in a 64-bit environment. Our tests don't execute any of
3737
# the system's binaries, so the environment shouldn't matter.
3838
task:
39-
name: FreeBSD amd64 & i686
4039
env:
4140
TARGET: x86_64-unknown-freebsd
42-
freebsd_instance:
43-
image: freebsd-12-3-release-amd64
41+
matrix:
42+
- name: FreeBSD 12 amd64 & i686
43+
freebsd_instance:
44+
image: freebsd-12-3-release-amd64
45+
- name: FreeBSD 14 amd64 & i686
46+
freebsd_instance:
47+
image_family: freebsd-14-0-snap
48+
# Enable tests that would fail on FreeBSD 12
49+
RUSTFLAGS: --cfg fbsd14 -D warnings
50+
RUSTDOCFLAGS: --cfg fbsd14
4451
setup_script:
4552
- kldload mqueuefs
4653
- fetch https://sh.rustup.rs -o rustup.sh

CHANGELOG.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,30 @@ This project adheres to [Semantic Versioning](https://semver.org/).
66
## [Unreleased] - ReleaseDate
77
### Added
88

9+
- Added `aio_writev` and `aio_readv`.
10+
(#[1713](https://github.com/nix-rust/nix/pull/1713))
11+
912
- impl From<SockaddrIn> for std::net::SocketAddrV4 and
1013
impl From<SockaddrIn6> for std::net::SocketAddrV6.
1114
(#[1711](https://github.com/nix-rust/nix/pull/1711))
1215

1316
### Changed
17+
18+
- Rewrote the aio module. The new module:
19+
* Does more type checking at compile time rather than runtime.
20+
* Gives the caller control over whether and when to `Box` an aio operation.
21+
* Changes the type of the `priority` arguments to `i32`.
22+
* Changes the return type of `aio_return` to `usize`.
23+
(#[1713](https://github.com/nix-rust/nix/pull/1713))
24+
1425
### Fixed
1526
### Removed
1627

28+
- Removed support for resubmitting partially complete `lio_listio` operations.
29+
It was too complicated, and didn't fit Nix's theme of zero-cost abstractions.
30+
Instead, it can be reimplemented downstream.
31+
(#[1713](https://github.com/nix-rust/nix/pull/1713))
32+
1733
## [0.24.1] - 2022-04-22
1834
### Added
1935
### Changed

Cargo.toml

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,10 @@ targets = [
2727
]
2828

2929
[dependencies]
30-
libc = { version = "0.2.124", features = [ "extra_traits" ] }
30+
libc = { git = "http://github.com/rust-lang/libc.git", rev = "cd99f681181c310abfba742aef11115d2eff03dc", features = [ "extra_traits" ] }
3131
bitflags = "1.1"
3232
cfg-if = "1.0"
33+
pin-utils = { version = "0.1.0", optional = true }
3334

3435
[target.'cfg(not(target_os = "redox"))'.dependencies]
3536
memoffset = { version = "0.6.3", optional = true }
@@ -44,7 +45,7 @@ default = [
4445
]
4546

4647
acct = []
47-
aio = []
48+
aio = ["pin-utils"]
4849
dir = ["fs"]
4950
env = []
5051
event = []
@@ -102,10 +103,6 @@ path = "test/sys/test_aio_drop.rs"
102103
name = "test-clearenv"
103104
path = "test/test_clearenv.rs"
104105

105-
[[test]]
106-
name = "test-lio-listio-resubmit"
107-
path = "test/sys/test_lio_listio_resubmit.rs"
108-
109106
[[test]]
110107
name = "test-mount"
111108
path = "test/test_mount.rs"

bors.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ status = [
55
"Android i686",
66
"Android x86_64",
77
"DragonFly BSD x86_64",
8-
"FreeBSD amd64 & i686",
8+
"FreeBSD 12 amd64 & i686",
9+
"FreeBSD 14 amd64 & i686",
910
"Fuchsia x86_64",
1011
"Linux MIPS",
1112
"Linux MIPS64 el",

src/fcntl.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -742,8 +742,8 @@ impl SpacectlRange {
742742
///
743743
/// # Example
744744
///
745-
// no_run because it fails to link until FreeBSD 14.0
746-
/// ```no_run
745+
#[cfg_attr(fbsd14, doc = " ```")]
746+
#[cfg_attr(not(fbsd14), doc = " ```no_run")]
747747
/// # use std::io::Write;
748748
/// # use std::os::unix::fs::FileExt;
749749
/// # use std::os::unix::io::AsRawFd;
@@ -788,8 +788,8 @@ pub fn fspacectl(fd: RawFd, range: SpacectlRange) -> Result<SpacectlRange> {
788788
///
789789
/// # Example
790790
///
791-
// no_run because it fails to link until FreeBSD 14.0
792-
/// ```no_run
791+
#[cfg_attr(fbsd14, doc = " ```")]
792+
#[cfg_attr(not(fbsd14), doc = " ```no_run")]
793793
/// # use std::io::Write;
794794
/// # use std::os::unix::fs::FileExt;
795795
/// # use std::os::unix::io::AsRawFd;

0 commit comments

Comments
 (0)