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

Replace the IoVec struct with IoSlice and IoSliceMut from the standard library #1643

Merged
merged 1 commit into from Apr 8, 2022
Merged

Conversation

notgull
Copy link
Contributor

@notgull notgull commented Jan 23, 2022

As per discussion in #1637, the IoVec<&[u8]> and IoVec<&mut [u8]> types have been replaced with std::io::IoSlice and IoSliceMut, respectively. Notable changes made in this pull request include:

  • The complete replacement of IoVec with IoSlice* types in both public API, private API, and tests.
  • Replacing IoVec with IoSlice in docs.
  • Replacing &[IoVec<&mut [u8]>] with &mut [IoSliceMut], note that the slice requires a mutable reference now. This is how it's done in the standard library, and there might be a soundness issue in doing it the other way.

Resolves #1637

@notgull
Copy link
Contributor Author

notgull commented Jan 23, 2022

Checks appear to be failing because IoSlice does not implement Hash, PartialEq, and some other common traits. Not sure how it would be preferred to respond to this.

Copy link
Member

@asomers asomers left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't forget a CHANGELOG, too!

@@ -68,24 +68,24 @@ cfg_if! {
target_os = "freebsd",
target_os = "ios",
target_os = "macos"))] {
use crate::sys::uio::IoVec;
use std::io::IoSlice;

#[derive(Clone, Debug, Eq, Hash, PartialEq)]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is causing failures, because IoSlice doesn't implement some of these traits. But SendfileHeaderTrailer isn't pub, so there's no penalty to remove some of its trait impls. What happens if you remove the offending trait impls? If it breaks something else, then you'll probably have to manually implement them, rather than derive them.

src/sys/uio.rs Show resolved Hide resolved
src/sys/uio.rs Outdated
@@ -88,7 +98,7 @@ pub fn pread(fd: RawFd, buf: &mut [u8], offset: off_t) -> Result<usize>{
/// A slice of memory in a remote process, starting at address `base`
/// and consisting of `len` bytes.
///
/// This is the same underlying C structure as [`IoVec`](struct.IoVec.html),
/// This is the same underlying C structure as `IoVec`,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// This is the same underlying C structure as `IoVec`,
/// This is the same underlying C structure as `IoSlice`,

src/sys/uio.rs Show resolved Hide resolved
src/sys/uio.rs Show resolved Hide resolved
@notgull
Copy link
Contributor Author

notgull commented Jan 24, 2022

The CI errors appear to be due to a clippy error unrelated to this pull request.

@asomers
Copy link
Member

asomers commented Jan 24, 2022

The CI errors appear to be due to a clippy error unrelated to this pull request.

I don't think so. I think those errors were introduced by this PR. nmount uses IoVec/IoSlice.

@notgull
Copy link
Contributor Author

notgull commented Jan 24, 2022

Remainder of CI failures appear to be due to the aforementioned clippy error

@asomers
Copy link
Member

asomers commented Jan 24, 2022

The ptrace warning is fixed in master. You need to rebase.

@notgull
Copy link
Contributor Author

notgull commented Jan 27, 2022

Is there anything else that I need to do here before I can merge this request?

Copy link
Member

@asomers asomers left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the slow response, I've been working on other things lately. This looks 99% good; I just have a few comments about nmount.

@@ -371,19 +371,27 @@ impl<'a> Nmount<'a> {
pub fn nmount(&mut self, flags: MntFlags) -> NmountResult {
// nmount can return extra error information via a "errmsg" return
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment got separated from the code it describes. It should be directly above line 380.

src/mount/bsd.rs Outdated

// N.B. notgull: the last entry here is technically an IoSliceMut.
// this is a workaround to keep soundness in place
let mut iovecs: Vec<libc::iovec> =
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of doing a const transmutation, should self.iov be a vec of IoSliceMut instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think so. nmount's methods by default takes several immutable pointers. Maybe we could just make it a list of libc::iovec by default?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess the problem is that the C API isn't const-correct. All of nmount's arguments are supposed to be const, except for the errmsg argument. So a transmutation like you had is probably Nix's best option.

Copy link
Member

@asomers asomers left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess whether you do a mem::transmute or a pointer cast, it's equally ugly, and it's C's fault. This PR looks almost good to me, but I suggest getting rid of the #[inline] on private methods.

src/mount/bsd.rs Outdated
}

#[cfg(target_os = "freebsd")]
#[cfg_attr(docsrs, doc(cfg(all())))]
impl<'a> Nmount<'a> {
/// Helper function to push a slice onto the `iov` array.
#[inline]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's no need to specify #[inline] for private methods.

@asomers asomers added this to the 0.24.0 milestone Mar 13, 2022
@asomers
Copy link
Member

asomers commented Mar 24, 2022

Could you please rebase? You've got some conflicts now, and a rebase will also fix the test failure on uclibc.

@asomers
Copy link
Member

asomers commented Mar 25, 2022

@notgull are you sure you rebased to the current master? It doesn't look like it.

@SUPERCILEX
Copy link
Contributor

Should this be blocking the 0.24 release? It'd be nice to have the feature splits out the door.

@rtzoeller
Copy link
Collaborator

@asomers will you have a chance to look at this in the next week or so? If not I can take a look; I agree with @SUPERCILEX that it'd be nice to get a 0.24.0 out soon (even if it means releasing a smaller 0.25.0 shortly thereafter).

Copy link
Member

@asomers asomers left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It LGTM, apart from a few minor nits.

CHANGELOG.md Outdated Show resolved Hide resolved
src/sys/socket/mod.rs Outdated Show resolved Hide resolved
src/sys/uio.rs Outdated Show resolved Hide resolved
@asomers
Copy link
Member

asomers commented Apr 8, 2022

Ok, it looks like you've made all requested changes and the tests pass. Would you please squash now? Then we'll merge it.

@notgull
Copy link
Contributor Author

notgull commented Apr 8, 2022

Squashed and ready to rumble!

Copy link
Member

@asomers asomers left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bors r+

@SUPERCILEX
Copy link
Contributor

Thanks everyone for helping get 0.24 out! :)

@bors bors bot merged commit 256707e into nix-rust:master Apr 8, 2022
@notgull notgull deleted the ioslices branch April 8, 2022 20:22
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.

Add an "advance" function for the iovec type.
4 participants