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

runtime-rs: bind mount volumes in sandbox level #5607

Merged
merged 3 commits into from Dec 7, 2022

Conversation

justxuewei
Copy link
Member

@justxuewei justxuewei commented Nov 8, 2022

This PR fixes the issue mentioned in #5588. In this pull request all shared volumes, except for rootfs, are bind mounted in sandbox level. That is all volumes referred to the same source on the host are bind mounted only once until no container references to it.

It supports dynamic permission controls as well. For example, when a volume mounted with readonly permission and a new coming container needs readwrite permission, the volume should be upgraded to readwrite permission. At the same time, if readwrite permission is no longer needed, then the volume should be downgraded.

Fixes: #5588

Signed-off-by: Xuewei Niu justxuewei@apache.org

@katacontainersbot
Copy link
Contributor

Can one of the admins verify this patch?

@katacontainersbot katacontainersbot added the size/large Task of significant size label Nov 8, 2022
@justxuewei justxuewei force-pushed the feat/sandbox-level-volume branch 3 times, most recently from 42f3d20 to de7e580 Compare November 10, 2022 02:15
@justxuewei
Copy link
Member Author

Hi @liubin, I found some errors making ci failure in compiling Dragonball. However, this pull request didn't change Dragonball at all. How to fix this? Thanks.

@liubin
Copy link
Member

liubin commented Nov 11, 2022

@justxuewei #5640 is fixing the clippy issue.

@justxuewei
Copy link
Member Author

I rebased the latest main branch to fix Dragonball compiling issues, could you help me trigger the ci tests? Thanks @liubin @lifupan

@justxuewei justxuewei force-pushed the feat/sandbox-level-volume branch 2 times, most recently from 98d3ae2 to f1c1374 Compare November 22, 2022 07:50
@lifupan
Copy link
Member

lifupan commented Nov 22, 2022

/test

@@ -38,13 +38,29 @@ pub const PASSTHROUGH_FS_DIR: &str = "passthrough";
const RAFS_DIR: &str = "rafs";

#[async_trait]
pub trait ShareFs: Send + Sync {
pub trait ShareFs: Send + Sync + Debug {
Copy link
Member

Choose a reason for hiding this comment

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

Why is Debug required?

async fn share_rootfs(&self, config: ShareFsRootfsConfig) -> Result<ShareFsMountResult>;
async fn share_volume(&self, config: ShareFsVolumeConfig) -> Result<ShareFsMountResult>;
/// Upgrade to readwrite permission
async fn upgrade(&self, file_name: &str) -> Result<()>;
Copy link
Member

Choose a reason for hiding this comment

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

Please name it explicitly. Something like upgrade_rw and dowgrade_ro sound better.

let host_dest = do_get_host_path(file_name, &self.id, "", true, false);
umount_timeout(&host_dest, 0).context("Umount readonly host dest")?;
let host_dest = do_get_host_path(file_name, &self.id, "", true, true);
umount_timeout(&host_dest, 0).context("Umount readwrite host dest")?;
Copy link
Member

Choose a reason for hiding this comment

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

The umount event is propagated to the ro virtiofs mount subtree. We only need to umount the rw directory bindmount.

mounted_info.rw_ref_count += 1;
}
share_fs
.set_mounted_info(&m.source, mounted_info)
Copy link
Member

Choose a reason for hiding this comment

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

Do we need any lock when manipulating mounted_info? There are a whole bunch of race windows here.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, you are right. I am working on it.

readonly,
);
share_fs
.set_mounted_info(&m.source, mounted_info)
Copy link
Member

Choose a reason for hiding this comment

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

The same locking concern applies here too.

Implemented bind mount related managment on the sandbox side, involving bind
mount a volume if it's not mounted before, upgrade permission to readwrite if
there is a new container needs.

Fixes: kata-containers#5588

Signed-off-by: Xuewei Niu <justxuewei@apache.org>
This commit implemented umonut controls and permission controls. When a volume
is no longer referenced, it will be umounted immediately. When a volume mounted
with readonly permission and a new coming container needs readwrite permission,
the volume should be upgraded to readwrite permission. On the contrary, if a
volume with readwrite permission and no container needs readwrite, then the
volume should be downgraded.

Fixes: kata-containers#5588

Signed-off-by: Xuewei Niu <justxuewei@apache.org>
Removed the `Debug` trait for the `ShareFs` and etc. Renamed
`ShareFsMount::upgrade()` and `ShareFsMount::downgrade()` to
`upgrade_to_rw()` and `downgrade_to_ro()`. Protected `mounted_info_set`
with a mutex to avoid race conditions.

Fixes: kata-containers#5588

Signed-off-by: Xuewei Niu <justxuewei@apache.org>
@justxuewei
Copy link
Member Author

Thanks for your reviews @bergwolf. I've pushed a new commit to fix the issues you mentioned above. Please take a look.

Copy link
Member

@bergwolf bergwolf left a comment

Choose a reason for hiding this comment

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

lgtm! Thanks!

@bergwolf
Copy link
Member

bergwolf commented Dec 6, 2022

/test

@lifupan
Copy link
Member

lifupan commented Dec 6, 2022

/retest

@lifupan lifupan merged commit cce316b into kata-containers:main Dec 7, 2022
dborquez pushed a commit to dborquez/kata-containers that referenced this pull request Jun 5, 2023
…ebug

test-agent-shutdown: Fix false positive match
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size/large Task of significant size
Projects
None yet
Development

Successfully merging this pull request may close these issues.

runtime-rs: bind mount volumes in sandbox level
5 participants