Skip to content
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

Added I/O safety to sys::aio #2401

Merged
merged 1 commit into from
May 15, 2024
Merged

Added I/O safety to sys::aio #2401

merged 1 commit into from
May 15, 2024

Conversation

asomers
Copy link
Member

@asomers asomers commented May 12, 2024

What does this PR do

Adds I/O safety to the sys/aio module. Those methods now take AsFd arguments instead of RawFd. And struct Aiocb now has a lifetime argument.

Checklist:

  • I have read CONTRIBUTING.md
  • I have written necessary tests and rustdoc comments
  • A change log has been added if this PR modifies nix's API

@SteveLauC
Copy link
Member

Will review this tomorrow:)

@SteveLauC
Copy link
Member

SteveLauC commented May 15, 2024

I found some minor issues that are not related to this PR, but the code of aio:

  1. O_DSYNC seems to be available on FreeBSD
libc_enum! {
    /// Mode for `AioCb::fsync`.  Controls whether only data or both data and
    /// metadata are synced.
    #[repr(i32)]
    #[non_exhaustive]
    pub enum AioFsyncMode {
        /// do it like `fsync`
        O_SYNC,
        /// on supported operating systems only, do it like `fdatasync`
        #[cfg(any(apple_targets,
                  target_os = "linux",
                  netbsdlike))]
        O_DSYNC
    }
    impl TryFrom<i32>
}
#[cfg(any(
    freebsdlike,
    all(target_os = "linux", not(target_env = "uclibc")),
    apple_targets,
    target_os = "netbsd"
))]
feature! {
    #![feature = "aio"]
    pub mod aio;
}

O_DSYNC is available on OpenBSD, the aio module is not, though this won't harm anything.

  1. There is an unnecessary type cast in the example of aio_suspend():
/// assert_eq!(aiocb.as_mut().aio_return().unwrap() as usize, WBUF.len());

aio_return() already returns an usize

@asomers
Copy link
Member Author

asomers commented May 15, 2024

Good find. I'll make a separate PR for those.

@asomers asomers added this pull request to the merge queue May 15, 2024
Merged via the queue into nix-rust:master with commit 0c08f39 May 15, 2024
36 checks passed
@asomers asomers deleted the aio-iosafety branch May 15, 2024 15:13
@SteveLauC SteveLauC mentioned this pull request Jun 7, 2024
29 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants