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

Update nix to 0.28.0 #2728

Merged
merged 2 commits into from May 23, 2024
Merged

Update nix to 0.28.0 #2728

merged 2 commits into from May 23, 2024

Conversation

omprakaash
Copy link
Contributor

@omprakaash omprakaash commented Mar 16, 2024

Updates nix to 0.28.0. Changed the deprecated functions to new recommended ones. Another noticeable change was the write() and close() functions in nix now take in OwnedFd instead of RawFd. Included changes for them as well.

@codecov-commenter
Copy link

codecov-commenter commented Mar 16, 2024

Codecov Report

Merging #2728 (1edc090) into main (18f3e0b) will decrease coverage by 0.02%.
Report is 18 commits behind head on main.
The diff coverage is 18.75%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2728      +/-   ##
==========================================
- Coverage   65.21%   65.20%   -0.02%     
==========================================
  Files         133      133              
  Lines       16981    16981              
==========================================
- Hits        11074    11072       -2     
- Misses       5907     5909       +2     

@utam0k utam0k added the kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. label Mar 16, 2024
@utam0k
Copy link
Member

utam0k commented Mar 16, 2024

Another noticeable change was the write() and close() functions in nix now take in OwnedFd instead of RawFd. Included changes for them as well.

Where can I find this change? I couldn't find the change you mentioned.
https://github.com/nix-rust/nix/blob/master/CHANGELOG.md#changed

@omprakaash
Copy link
Contributor Author

omprakaash commented Mar 16, 2024

Yeah, I could not find that in the change-log too. The change was done in this PR: nix-rust/nix#2100. Sorry, it seems that only write() has been changed. Close() still takes RawFd.

Comment on lines 167 to 171
// Since nix = "0.27.1", `mmap()` requires a generic type `F: AsFd`.
// `::<File>` doesn't have any meaning because we won't use it.
mman::mmap::<File>(
mman::mmap_anonymous(
None,
NonZeroUsize::new(default_stack_size).ok_or(CloneError::ZeroStackSize)?,
mman::ProtFlags::PROT_READ | mman::ProtFlags::PROT_WRITE,
mman::MapFlags::MAP_PRIVATE | mman::MapFlags::MAP_ANONYMOUS | mman::MapFlags::MAP_STACK,
None,
0,
)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Need to check if this change is ok (should be, just have to confirm), but in that case, we should also remove the comment above, as not applicable anymore.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Hey, this still needs to be addressed, the function change is valid, so comment should be updated/removed.

@YJDoc2 YJDoc2 mentioned this pull request Mar 26, 2024
@omprakaash omprakaash force-pushed the nix-update branch 2 times, most recently from e4ccbbd to 493da85 Compare March 27, 2024 21:27
@utam0k
Copy link
Member

utam0k commented Mar 30, 2024

@omprakaash It seems CI failed with lint. May I ask you to check it?

@omprakaash
Copy link
Contributor Author

Oh sorry about that, should have fixed the linting issues now.

@utam0k
Copy link
Member

utam0k commented Mar 31, 2024

@omprakaash Thanks!

@utam0k
Copy link
Member

utam0k commented Mar 31, 2024

@zahash @anti-entropy123 @YJDoc2 May I ask you to leave this PR to you?

Copy link
Contributor

@zahash zahash left a comment

Choose a reason for hiding this comment

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

looks good

@@ -148,13 +149,13 @@ impl TenantContainerBuilder {
let mut notify_socket = NotifySocket::new(notify_path);
notify_socket.notify_container_start()?;

close(write_end).map_err(LibcontainerError::OtherSyscall)?;
close(write_end.as_raw_fd()).map_err(LibcontainerError::OtherSyscall)?;
Copy link
Contributor

Choose a reason for hiding this comment

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

Since write_end is OwnedFd, why don't you close it by drop(write_end)?

#[stable(feature = "io_safety", since = "1.63.0")]
impl Drop for OwnedFd {
    #[inline]
    fn drop(&mut self) {
        unsafe {
            ...
            let _ = libc::close(self.fd);
            ...

https://doc.rust-lang.org/nightly/src/std/os/fd/owned.rs.html#174-186

Copy link
Collaborator

Choose a reason for hiding this comment

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

You beat me to it 😂 #2728 (comment)

Copy link
Collaborator

@YJDoc2 YJDoc2 left a comment

Choose a reason for hiding this comment

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

While other changes are ok, I have some points of concern here regarding the mix of OwnedFd and RawFd . Main point of concern for this PR, is that in several places, we are converting a RawFd to OwnedFd, and then calling close on it manually when the OwnedFd gets closed in its drop. I feel this should be addressed here.

crates/libcontainer/src/container/tenant_builder.rs Outdated Show resolved Hide resolved
crates/libcontainer/src/process/fork.rs Show resolved Hide resolved
@omprakaash omprakaash force-pushed the nix-update branch 2 times, most recently from 0ec5908 to f3f417f Compare April 19, 2024 11:05
@YJDoc2
Copy link
Collaborator

YJDoc2 commented Apr 22, 2024

Hey, thanks for updating. Two notes :

  • there's conflict in lock file, you can recreate it or copy it over from master and run build to fix it
  • Can you add explicit drop call where there was close before, and comment the reasoning, maybe linking this PR there? That way in future we know for sure that we have taken care of the fds and the reason for calling drop instead of close

@omprakaash omprakaash force-pushed the nix-update branch 2 times, most recently from e4e7429 to 1123b43 Compare April 28, 2024 10:40
@YJDoc2
Copy link
Collaborator

YJDoc2 commented May 6, 2024

Hey @omprakaash , it seems there are still some more conflicts here. In case you are busy, is it ok if I resolve them and push? because the conflicts are in cargo* files, not code, it would be pretty straight forward to resolve. Apart from that, the code is lgtm.

@omprakaash
Copy link
Contributor Author

Hey sorry for the late reply. I did not have the chance to look at this and missed your comment. Would be great if you could that. Thank you !

@yihuaf
Copy link
Collaborator

yihuaf commented May 17, 2024

I will take care of this.

@yihuaf yihuaf force-pushed the nix-update branch 2 times, most recently from 630cccc to 5e23878 Compare May 17, 2024 22:19
@yihuaf
Copy link
Collaborator

yihuaf commented May 17, 2024

Merge conflict is resolved. I will look over the review comments over the weekend and address them.

commit f0a6b388e7f132648157ca2712e20a1ee93f265a
Author: yihuaf <yihuaf@unkies.org>
Date:   Sun May 19 21:16:21 2024 -0700

    Fix the explicit close

    Signed-off-by: yihuaf <yihuaf@unkies.org>

commit 5e23878
Author: yihuaf <yihuaf@unkies.org>
Date:   Thu May 16 21:31:09 2024 -0700

    Rebase to the latest main branch

    Signed-off-by: yihuaf <yihuaf@unkies.org>

commit 3144355
Author: omprakaash <omsuseela@gmail.com>
Date:   Sat Mar 16 03:28:40 2024 +0000

    Update nix to 0.28.0

    Signed-off-by: omprakaash <omsuseela@gmail.com>
    Signed-off-by: om prakaash <omsuseela@gmail.com>

Signed-off-by: yihuaf <yihuaf@unkies.org>
@yihuaf
Copy link
Collaborator

yihuaf commented May 20, 2024

@YJDoc2 This is ready for review one last time. I have addressed the merge conflicts and went over the reviews. One note, the closing of the pipes (The fds that were converted from RawFd to OwnedFd) is actually required. We use the pipes as both a way to communicate between processes and as a barrier for synchronization. The finer control to explicitly close is required, instead of letting the scope takes care of the close through Drop trait. By closing one end of the pipe, we immediately signal to the other end of the pipe, so that any blocking calls on the pipe will immediately return. The PR already included the change, but I changed the comments to reflect this information. The previous comment implies that the drop was there only to maintain the legacy code, but the explicit close actual serves a purpose in this case, not just because we have to manually close due to the use of RawFd.

Let me know if there is anything else you would like to make change.

@yihuaf yihuaf assigned yihuaf and unassigned YJDoc2 May 20, 2024
@yihuaf yihuaf requested review from YJDoc2, anti-entropy123 and a team and removed request for anti-entropy123 May 20, 2024 04:38
Copy link
Member

@utam0k utam0k left a comment

Choose a reason for hiding this comment

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

Looks good code itself, but please wait for release v0.3.3 🙏 https://github.com/containers/youki/pulls

Copy link
Collaborator

@YJDoc2 YJDoc2 left a comment

Choose a reason for hiding this comment

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

Code looks good, but unfortunately there's another conflict due to latest release. Approving so that after resolving and @utam0k 's approval, this can get merged. Thank you @omprakaash and @yihuaf for taking care of this 🙏

Copy link
Member

@utam0k utam0k left a comment

Choose a reason for hiding this comment

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

Thanks!

@utam0k utam0k enabled auto-merge (squash) May 23, 2024 12:18
@utam0k utam0k merged commit a35d20f into containers:main May 23, 2024
28 checks passed
@github-actions github-actions bot mentioned this pull request May 23, 2024
@yihuaf
Copy link
Collaborator

yihuaf commented May 23, 2024

close #2723

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants