mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-06-27 15:57:09 +00:00
runtime-rs: fix the issues mentioned in the code review
In order to avoid cloning, changed the signature of `ShareFsMount::share_rootfs`, `ShareFsMount::share_volume`, and `ShareFsMount::umount_rootfs` to receive a reference to a config. Fixes: #5898 Signed-off-by: Xuewei Niu <niuxuewei.nxw@antgroup.com>
This commit is contained in:
parent
0e69207909
commit
fd77eebd4d
15
src/runtime-rs/Cargo.lock
generated
15
src/runtime-rs/Cargo.lock
generated
@ -1223,6 +1223,7 @@ dependencies = [
|
|||||||
"seccompiler",
|
"seccompiler",
|
||||||
"serde",
|
"serde",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
|
"shim-interface",
|
||||||
"slog",
|
"slog",
|
||||||
"slog-scope",
|
"slog-scope",
|
||||||
"thiserror",
|
"thiserror",
|
||||||
@ -1919,6 +1920,7 @@ dependencies = [
|
|||||||
"safe-path",
|
"safe-path",
|
||||||
"serde",
|
"serde",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
|
"shim-interface",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@ -2343,6 +2345,7 @@ dependencies = [
|
|||||||
"logging",
|
"logging",
|
||||||
"oci",
|
"oci",
|
||||||
"persist",
|
"persist",
|
||||||
|
"shim-interface",
|
||||||
"slog",
|
"slog",
|
||||||
"slog-scope",
|
"slog-scope",
|
||||||
"tokio",
|
"tokio",
|
||||||
@ -2474,6 +2477,7 @@ dependencies = [
|
|||||||
"logging",
|
"logging",
|
||||||
"persist",
|
"persist",
|
||||||
"runtimes",
|
"runtimes",
|
||||||
|
"shim-interface",
|
||||||
"slog",
|
"slog",
|
||||||
"slog-scope",
|
"slog-scope",
|
||||||
"tokio",
|
"tokio",
|
||||||
@ -2539,12 +2543,23 @@ dependencies = [
|
|||||||
name = "shim-ctl"
|
name = "shim-ctl"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"anyhow",
|
||||||
"common",
|
"common",
|
||||||
"logging",
|
"logging",
|
||||||
"runtimes",
|
"runtimes",
|
||||||
"tokio",
|
"tokio",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "shim-interface"
|
||||||
|
version = "0.1.0"
|
||||||
|
dependencies = [
|
||||||
|
"anyhow",
|
||||||
|
"hyper",
|
||||||
|
"hyperlocal",
|
||||||
|
"tokio",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "signal-hook-registry"
|
name = "signal-hook-registry"
|
||||||
version = "1.4.0"
|
version = "1.4.0"
|
||||||
|
@ -42,19 +42,11 @@ impl NydusRootfs {
|
|||||||
cid: &str,
|
cid: &str,
|
||||||
rootfs: &Mount,
|
rootfs: &Mount,
|
||||||
) -> Result<Self> {
|
) -> Result<Self> {
|
||||||
let share_fs = Arc::clone(share_fs);
|
|
||||||
let share_fs_mount = share_fs.get_share_fs_mount();
|
let share_fs_mount = share_fs.get_share_fs_mount();
|
||||||
let extra_options =
|
let extra_options =
|
||||||
NydusExtraOptions::new(rootfs).context("failed to parse nydus extra options")?;
|
NydusExtraOptions::new(rootfs).context("failed to parse nydus extra options")?;
|
||||||
info!(sl!(), "extra_option {:?}", &extra_options);
|
info!(sl!(), "extra_option {:?}", &extra_options);
|
||||||
let rafs_meta = &extra_options.source;
|
let rafs_meta = &extra_options.source;
|
||||||
let config = ShareFsRootfsConfig {
|
|
||||||
cid: cid.to_string(),
|
|
||||||
source: extra_options.snapshot_dir.clone(),
|
|
||||||
target: SNAPSHOT_DIR.to_string(),
|
|
||||||
readonly: true,
|
|
||||||
is_rafs: false,
|
|
||||||
};
|
|
||||||
let (rootfs_storage, rootfs_guest_path) = match extra_options.fs_version.as_str() {
|
let (rootfs_storage, rootfs_guest_path) = match extra_options.fs_version.as_str() {
|
||||||
// both nydus v5 and v6 can be handled by the builtin nydus in dragonball by using the rafs mode.
|
// both nydus v5 and v6 can be handled by the builtin nydus in dragonball by using the rafs mode.
|
||||||
// nydus v6 could also be handled by the guest kernel as well, but some kernel patch is not support in the upstream community. We will add an option to let runtime-rs handle nydus v6 in the guest kernel optionally once the patch is ready
|
// nydus v6 could also be handled by the guest kernel as well, but some kernel patch is not support in the upstream community. We will add an option to let runtime-rs handle nydus v6 in the guest kernel optionally once the patch is ready
|
||||||
@ -81,7 +73,13 @@ impl NydusRootfs {
|
|||||||
let rootfs_guest_path = do_get_guest_path(ROOTFS, cid, false, false);
|
let rootfs_guest_path = do_get_guest_path(ROOTFS, cid, false, false);
|
||||||
// bind mount the snapshot dir under the share directory
|
// bind mount the snapshot dir under the share directory
|
||||||
share_fs_mount
|
share_fs_mount
|
||||||
.share_rootfs(config.clone())
|
.share_rootfs(&ShareFsRootfsConfig {
|
||||||
|
cid: cid.to_string(),
|
||||||
|
source: extra_options.snapshot_dir.clone(),
|
||||||
|
target: SNAPSHOT_DIR.to_string(),
|
||||||
|
readonly: true,
|
||||||
|
is_rafs: false,
|
||||||
|
})
|
||||||
.await
|
.await
|
||||||
.context("share nydus rootfs")?;
|
.context("share nydus rootfs")?;
|
||||||
let mut options: Vec<String> = Vec::new();
|
let mut options: Vec<String> = Vec::new();
|
||||||
@ -148,7 +146,8 @@ impl Rootfs for NydusRootfs {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async fn cleanup(&self) -> Result<()> {
|
async fn cleanup(&self) -> Result<()> {
|
||||||
warn!(sl!(), "Cleaning up Nydus Rootfs is still unimplemented.");
|
// TODO: Clean up NydusRootfs after the container is killed
|
||||||
|
warn!(sl!(), "Cleaning up NydusRootfs is still unimplemented.");
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -48,7 +48,7 @@ impl ShareFsRootfs {
|
|||||||
};
|
};
|
||||||
|
|
||||||
let mount_result = share_fs_mount
|
let mount_result = share_fs_mount
|
||||||
.share_rootfs(config.clone())
|
.share_rootfs(&config)
|
||||||
.await
|
.await
|
||||||
.context("share rootfs")?;
|
.context("share rootfs")?;
|
||||||
|
|
||||||
@ -78,7 +78,7 @@ impl Rootfs for ShareFsRootfs {
|
|||||||
// Umount the mount point shared to guest
|
// Umount the mount point shared to guest
|
||||||
let share_fs_mount = self.share_fs.get_share_fs_mount();
|
let share_fs_mount = self.share_fs.get_share_fs_mount();
|
||||||
share_fs_mount
|
share_fs_mount
|
||||||
.umount_rootfs(self.config.clone())
|
.umount_rootfs(&self.config)
|
||||||
.await
|
.await
|
||||||
.context("umount shared rootfs")?;
|
.context("umount shared rootfs")?;
|
||||||
|
|
||||||
|
@ -120,8 +120,8 @@ impl MountedInfo {
|
|||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
pub trait ShareFsMount: Send + Sync {
|
pub trait ShareFsMount: Send + Sync {
|
||||||
async fn share_rootfs(&self, config: ShareFsRootfsConfig) -> Result<ShareFsMountResult>;
|
async fn share_rootfs(&self, config: &ShareFsRootfsConfig) -> Result<ShareFsMountResult>;
|
||||||
async fn share_volume(&self, config: ShareFsVolumeConfig) -> Result<ShareFsMountResult>;
|
async fn share_volume(&self, config: &ShareFsVolumeConfig) -> Result<ShareFsMountResult>;
|
||||||
/// Upgrade to readwrite permission
|
/// Upgrade to readwrite permission
|
||||||
async fn upgrade_to_rw(&self, file_name: &str) -> Result<()>;
|
async fn upgrade_to_rw(&self, file_name: &str) -> Result<()>;
|
||||||
/// Downgrade to readonly permission
|
/// Downgrade to readonly permission
|
||||||
@ -129,7 +129,7 @@ pub trait ShareFsMount: Send + Sync {
|
|||||||
/// Umount the volume
|
/// Umount the volume
|
||||||
async fn umount_volume(&self, file_name: &str) -> Result<()>;
|
async fn umount_volume(&self, file_name: &str) -> Result<()>;
|
||||||
/// Umount the rootfs
|
/// Umount the rootfs
|
||||||
async fn umount_rootfs(&self, config: ShareFsRootfsConfig) -> Result<()>;
|
async fn umount_rootfs(&self, config: &ShareFsRootfsConfig) -> Result<()>;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new(id: &str, config: &SharedFsInfo) -> Result<Arc<dyn ShareFs>> {
|
pub fn new(id: &str, config: &SharedFsInfo) -> Result<Arc<dyn ShareFs>> {
|
||||||
|
@ -38,7 +38,7 @@ impl VirtiofsShareMount {
|
|||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl ShareFsMount for VirtiofsShareMount {
|
impl ShareFsMount for VirtiofsShareMount {
|
||||||
async fn share_rootfs(&self, config: ShareFsRootfsConfig) -> Result<ShareFsMountResult> {
|
async fn share_rootfs(&self, config: &ShareFsRootfsConfig) -> Result<ShareFsMountResult> {
|
||||||
// TODO: select virtiofs or support nydus
|
// TODO: select virtiofs or support nydus
|
||||||
let guest_path = utils::share_to_guest(
|
let guest_path = utils::share_to_guest(
|
||||||
&config.source,
|
&config.source,
|
||||||
@ -56,7 +56,7 @@ impl ShareFsMount for VirtiofsShareMount {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn share_volume(&self, config: ShareFsVolumeConfig) -> Result<ShareFsMountResult> {
|
async fn share_volume(&self, config: &ShareFsVolumeConfig) -> Result<ShareFsMountResult> {
|
||||||
let mut guest_path = utils::share_to_guest(
|
let mut guest_path = utils::share_to_guest(
|
||||||
&config.source,
|
&config.source,
|
||||||
&config.target,
|
&config.target,
|
||||||
@ -103,7 +103,7 @@ impl ShareFsMount for VirtiofsShareMount {
|
|||||||
source: guest_path,
|
source: guest_path,
|
||||||
fs_type: String::from("bind"),
|
fs_type: String::from("bind"),
|
||||||
fs_group: None,
|
fs_group: None,
|
||||||
options: config.mount_options,
|
options: config.mount_options.clone(),
|
||||||
mount_point: watchable_guest_mount.clone(),
|
mount_point: watchable_guest_mount.clone(),
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -211,7 +211,7 @@ impl ShareFsMount for VirtiofsShareMount {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn umount_rootfs(&self, config: ShareFsRootfsConfig) -> Result<()> {
|
async fn umount_rootfs(&self, config: &ShareFsRootfsConfig) -> Result<()> {
|
||||||
let host_dest = do_get_host_path(&config.target, &self.id, &config.cid, false, false);
|
let host_dest = do_get_host_path(&config.target, &self.id, &config.cid, false, false);
|
||||||
umount_timeout(&host_dest, 0).context("umount rootfs")?;
|
umount_timeout(&host_dest, 0).context("umount rootfs")?;
|
||||||
|
|
||||||
|
@ -30,6 +30,7 @@ impl Volume for BlockVolume {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async fn cleanup(&self) -> Result<()> {
|
async fn cleanup(&self) -> Result<()> {
|
||||||
|
// TODO: Clean up BlockVolume
|
||||||
warn!(sl!(), "Cleaning up BlockVolume is still unimplemented.");
|
warn!(sl!(), "Cleaning up BlockVolume is still unimplemented.");
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -34,6 +34,7 @@ impl Volume for DefaultVolume {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async fn cleanup(&self) -> Result<()> {
|
async fn cleanup(&self) -> Result<()> {
|
||||||
|
// TODO: Clean up DefaultVolume
|
||||||
warn!(sl!(), "Cleaning up DefaultVolume is still unimplemented.");
|
warn!(sl!(), "Cleaning up DefaultVolume is still unimplemented.");
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -112,7 +112,7 @@ impl ShareFsVolume {
|
|||||||
} else {
|
} else {
|
||||||
// Not mounted ever
|
// Not mounted ever
|
||||||
let mount_result = share_fs_mount
|
let mount_result = share_fs_mount
|
||||||
.share_volume(ShareFsVolumeConfig {
|
.share_volume(&ShareFsVolumeConfig {
|
||||||
// The scope of shared volume is sandbox
|
// The scope of shared volume is sandbox
|
||||||
cid: String::from(""),
|
cid: String::from(""),
|
||||||
source: m.source.clone(),
|
source: m.source.clone(),
|
||||||
@ -158,10 +158,10 @@ impl Volume for ShareFsVolume {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async fn cleanup(&self) -> Result<()> {
|
async fn cleanup(&self) -> Result<()> {
|
||||||
if self.share_fs.is_none() {
|
let share_fs = match self.share_fs.as_ref() {
|
||||||
return Ok(());
|
Some(fs) => fs,
|
||||||
}
|
None => return Ok(()),
|
||||||
let share_fs = self.share_fs.as_ref().unwrap();
|
};
|
||||||
|
|
||||||
let mounted_info_set = share_fs.mounted_info_set();
|
let mounted_info_set = share_fs.mounted_info_set();
|
||||||
let mut mounted_info_set = mounted_info_set.lock().await;
|
let mut mounted_info_set = mounted_info_set.lock().await;
|
||||||
|
@ -100,6 +100,7 @@ impl Volume for ShmVolume {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async fn cleanup(&self) -> Result<()> {
|
async fn cleanup(&self) -> Result<()> {
|
||||||
|
// TODO: Clean up ShmVolume
|
||||||
warn!(sl!(), "Cleaning up ShmVolume is still unimplemented.");
|
warn!(sl!(), "Cleaning up ShmVolume is still unimplemented.");
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user