mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-06-22 05:28:25 +00:00
Merge pull request #10643 from justxuewei/fix-bind-vol
runtime-rs & agent: Fix the issues with bind volumes
This commit is contained in:
commit
07fe7325c2
@ -233,7 +233,7 @@ pub fn init_rootfs(
|
||||
// bind may be only specified in the oci spec options -> flags update r#type
|
||||
let m = &{
|
||||
let mut mbind = m.clone();
|
||||
if mbind.typ().is_none() && flags & MsFlags::MS_BIND == MsFlags::MS_BIND {
|
||||
if is_none_mount_type(mbind.typ()) && flags & MsFlags::MS_BIND == MsFlags::MS_BIND {
|
||||
mbind.set_typ(Some("bind".to_string()));
|
||||
}
|
||||
mbind
|
||||
@ -397,6 +397,13 @@ fn mount_cgroups_v2(cfd_log: RawFd, m: &Mount, rootfs: &str, flags: MsFlags) ->
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn is_none_mount_type(typ: &Option<String>) -> bool {
|
||||
match typ {
|
||||
Some(t) => t == "none",
|
||||
None => true,
|
||||
}
|
||||
}
|
||||
|
||||
fn mount_cgroups(
|
||||
cfd_log: RawFd,
|
||||
m: &Mount,
|
||||
|
@ -53,6 +53,7 @@ use std::time::Instant;
|
||||
use lazy_static::lazy_static;
|
||||
use nix::mount::{mount, MntFlags, MsFlags};
|
||||
use nix::{unistd, NixPath};
|
||||
use oci_spec::runtime as oci;
|
||||
|
||||
use crate::fs::is_symlink;
|
||||
use crate::sl;
|
||||
@ -799,8 +800,20 @@ pub fn get_mount_options(options: &Option<Vec<String>>) -> Vec<String> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_mount_type(typ: &Option<String>) -> String {
|
||||
typ.clone().unwrap_or("bind".to_string())
|
||||
pub fn get_mount_type(m: &oci::Mount) -> String {
|
||||
m.typ()
|
||||
.clone()
|
||||
.map(|typ| {
|
||||
if typ.as_str() == "none" {
|
||||
if let Some(opts) = m.options() {
|
||||
if opts.iter().any(|opt| opt == "bind" || opt == "rbind") {
|
||||
return "bind".to_string();
|
||||
}
|
||||
}
|
||||
}
|
||||
typ
|
||||
})
|
||||
.unwrap_or("bind".to_string())
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
@ -120,7 +120,7 @@ impl ShareFsMount for VirtiofsShareMount {
|
||||
guest_path,
|
||||
storages,
|
||||
});
|
||||
} else if get_mount_type(config.mount.typ()).as_str() == mount::KATA_EPHEMERAL_VOLUME_TYPE {
|
||||
} else if get_mount_type(&config.mount).as_str() == mount::KATA_EPHEMERAL_VOLUME_TYPE {
|
||||
// refer to the golang `handleEphemeralStorage` code at
|
||||
// https://github.com/kata-containers/kata-containers/blob/9516286f6dd5cfd6b138810e5d7c9e01cf6fc043/src/runtime/virtcontainers/kata_agent.go#L1354
|
||||
|
||||
|
@ -98,7 +98,7 @@ pub(crate) async fn handle_direct_volume(
|
||||
}
|
||||
|
||||
pub(crate) fn is_direct_volume(m: &oci::Mount) -> Result<bool> {
|
||||
let mnt_type = get_mount_type(m.typ());
|
||||
let mnt_type = get_mount_type(m);
|
||||
let mount_type = mnt_type.as_str();
|
||||
|
||||
// Filter the non-bind volume and non-direct-vol volume
|
||||
|
@ -125,7 +125,7 @@ impl SPDKVolume {
|
||||
.context("generate host-guest shared path failed")?;
|
||||
storage.mount_point = guest_path.clone();
|
||||
|
||||
if get_mount_type(m.typ()).as_str() != "bind" {
|
||||
if get_mount_type(m).as_str() != "bind" {
|
||||
storage.fs_type = mount_info.fs_type.clone();
|
||||
} else {
|
||||
storage.fs_type = DEFAULT_VOLUME_FS_TYPE.to_string();
|
||||
|
@ -80,7 +80,7 @@ impl VfioVolume {
|
||||
.context("generate host-guest shared path failed")?;
|
||||
storage.mount_point = guest_path.clone();
|
||||
|
||||
if get_mount_type(m.typ()).as_str() != "bind" {
|
||||
if get_mount_type(m).as_str() != "bind" {
|
||||
storage.fs_type = mount_info.fs_type.clone();
|
||||
} else {
|
||||
storage.fs_type = DEFAULT_VOLUME_FS_TYPE.to_string();
|
||||
|
@ -308,8 +308,8 @@ impl Volume for ShareFsVolume {
|
||||
}
|
||||
|
||||
pub(crate) fn is_share_fs_volume(m: &oci::Mount) -> bool {
|
||||
(get_mount_type(m.typ()).as_str() == "bind"
|
||||
|| get_mount_type(m.typ()).as_str() == mount::KATA_EPHEMERAL_VOLUME_TYPE)
|
||||
let mount_type = get_mount_type(m);
|
||||
(mount_type == "bind" || mount_type == mount::KATA_EPHEMERAL_VOLUME_TYPE)
|
||||
&& !is_host_device(&get_mount_path(&Some(m.destination().clone())))
|
||||
&& !is_system_mount(&get_mount_path(m.source()))
|
||||
}
|
||||
|
@ -115,5 +115,5 @@ impl Volume for ShmVolume {
|
||||
|
||||
pub(crate) fn is_shm_volume(m: &oci::Mount) -> bool {
|
||||
get_mount_path(&Some(m.destination().clone())).as_str() == "/dev/shm"
|
||||
&& get_mount_type(m.typ()).as_str() != KATA_EPHEMERAL_DEV_TYPE
|
||||
&& get_mount_type(m).as_str() != KATA_EPHEMERAL_DEV_TYPE
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user