Skip to content

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

Merged
bors[bot] merged 1 commit intonix-rust:masterfrom
notgull:ioslices
Apr 8, 2022
Merged

Replace the IoVec struct with IoSlice and IoSliceMut from the standard library#1643
bors[bot] merged 1 commit intonix-rust:masterfrom
notgull:ioslices

Conversation

@notgull
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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!

Comment thread src/sys/sendfile.rs Outdated
use crate::sys::uio::IoVec;
use std::io::IoSlice;

#[derive(Clone, Debug, Eq, Hash, PartialEq)]
Copy link
Copy Markdown
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.

Comment thread src/sys/uio.rs
Comment thread src/sys/uio.rs Outdated
/// 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
Copy Markdown
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`,

Comment thread src/sys/uio.rs
Comment thread src/sys/uio.rs
@notgull
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Contributor Author

notgull commented Jan 24, 2022

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

@asomers
Copy link
Copy Markdown
Member

asomers commented Jan 24, 2022

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

@notgull
Copy link
Copy Markdown
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
Copy Markdown
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.

Comment thread src/mount/bsd.rs
@@ -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
Copy Markdown
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.

Comment thread 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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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.

Comment thread src/mount/bsd.rs Outdated
#[cfg_attr(docsrs, doc(cfg(all())))]
impl<'a> Nmount<'a> {
/// Helper function to push a slice onto the `iov` array.
#[inline]
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Contributor

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

@rtzoeller
Copy link
Copy Markdown
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
Copy Markdown
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.

Comment thread CHANGELOG.md Outdated
Comment thread src/sys/socket/mod.rs Outdated
Comment thread src/sys/uio.rs Outdated
@asomers
Copy link
Copy Markdown
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
Copy Markdown
Contributor Author

notgull commented Apr 8, 2022

Squashed and ready to rumble!

Copy link
Copy Markdown
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
Copy Markdown
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