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

Support 'shared' and 'unbindable' rootfs propagations #309

Merged
merged 3 commits into from
Sep 20, 2021

Conversation

tiqwab
Copy link
Contributor

@tiqwab tiqwab commented Sep 19, 2021

Resolve #256.

This pull request enables youki to handle shared and unbindable rootfs propagation.

Most of the change in the pull request follows runc implementation, but one difference is that runc actually doesn't pass linux_rootfs_propagation/linux_rootfs_propagation.t integration test (it fails in setting shared or unbindable propagation type).

This pull request added rootfs::adjust_root_mount_propagation after pivot_root to set appropriate propagation type at root mount point of container if shared or unbindable rootfs propagation is specified. This approach comes from an open pull request of runc.

@codecov-commenter
Copy link

codecov-commenter commented Sep 19, 2021

Codecov Report

Merging #309 (10c6c26) into main (8250889) will decrease coverage by 3.95%.
The diff coverage is 58.75%.

@@            Coverage Diff             @@
##             main     #309      +/-   ##
==========================================
- Coverage   77.11%   73.15%   -3.96%     
==========================================
  Files          43       44       +1     
  Lines        6139     6541     +402     
==========================================
+ Hits         4734     4785      +51     
- Misses       1405     1756     +351     

@utam0k
Copy link
Member

utam0k commented Sep 19, 2021

@tiqwab Thanks for your PR! Could you add unit tests whenever possible?

@tiqwab
Copy link
Contributor Author

tiqwab commented Sep 19, 2021

Of course. I feel for now it is difficult to add enough unit tests, but I'll try it.

@utam0k
Copy link
Member

utam0k commented Sep 19, 2021

Of course. I feel for now it is difficult to add enough unit tests, but I'll try it.

I know it is difficult to add complete unit tests in this area. So it's okay as long as you can.

Copy link
Collaborator

@yihuaf yihuaf left a comment

Choose a reason for hiding this comment

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

Overall looks good. Thanks for doing this.

Can you please add error handling and context when you can. I know some of the existing code are not doing this, but we are trying to have better error handling whenever we can :)

You may have to create the unit test using fork and entering into user and mount namespace. Let me know if you run into any troubles.

@@ -248,6 +248,8 @@ pub fn container_init(
.with_context(|| format!("Failed to chroot to {:?}", rootfs))?;
}

rootfs::adjust_root_mount_propagation(spec)?;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we add context to the error handling? with_context or context.

src/rootfs.rs Outdated
@@ -35,6 +38,8 @@ pub fn prepare_rootfs(spec: &Spec, rootfs: &Path, bind_devices: bool) -> Result<
nix_mount(None::<&str>, "/", None::<&str>, flags, None::<&str>)
.context("Failed to mount rootfs")?;

make_parent_mount_private(rootfs)?;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same, add error context.

src/rootfs.rs Outdated
}

/// Change propagation type of rootfs as specified in spec.
pub fn adjust_root_mount_propagation(spec: &Spec) -> Result<()> {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we pass in linux rather than the whole spec. Looks like only the linux is used.

@tiqwab
Copy link
Contributor Author

tiqwab commented Sep 20, 2021

I added some error contexts at the suggest places and a simple unit test for rootfs::find_parent_mount, which doesn't require real mount nor namespaces. I'll work on more complicated tests in a few days.

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.

LGTM

@utam0k utam0k merged commit 15e0e37 into containers:main Sep 20, 2021
@tiqwab tiqwab deleted the support-other-rootfs-propagations branch September 21, 2021 11:39
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.

Pass rootfs propagation test
4 participants