mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-04-30 04:34:27 +00:00
rustjail: fix the issue of bind mount /dev
In case the container rootfs's /dev was overrided by binding mount from another directory, then there's no need to create the default devices nodes and symlinks in /dev. Fixes: #692 Signed-off-by: fupan.lfp <fupan.lfp@antfin.com>
This commit is contained in:
parent
f531bab745
commit
0dc02f6dd3
@ -188,6 +188,7 @@ pub fn init_rootfs(
|
|||||||
None::<&str>,
|
None::<&str>,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
|
let mut bind_mount_dev = false;
|
||||||
for m in &spec.mounts {
|
for m in &spec.mounts {
|
||||||
let (mut flags, data) = parse_mount(&m);
|
let (mut flags, data) = parse_mount(&m);
|
||||||
if !m.destination.starts_with('/') || m.destination.contains("..") {
|
if !m.destination.starts_with('/') || m.destination.contains("..") {
|
||||||
@ -201,6 +202,9 @@ pub fn init_rootfs(
|
|||||||
mount_cgroups(cfd_log, &m, rootfs, flags, &data, cpath, mounts)?;
|
mount_cgroups(cfd_log, &m, rootfs, flags, &data, cpath, mounts)?;
|
||||||
} else {
|
} else {
|
||||||
if m.destination == "/dev" {
|
if m.destination == "/dev" {
|
||||||
|
if m.r#type == "bind" {
|
||||||
|
bind_mount_dev = true;
|
||||||
|
}
|
||||||
flags &= !MsFlags::MS_RDONLY;
|
flags &= !MsFlags::MS_RDONLY;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -242,9 +246,14 @@ pub fn init_rootfs(
|
|||||||
let olddir = unistd::getcwd()?;
|
let olddir = unistd::getcwd()?;
|
||||||
unistd::chdir(rootfs)?;
|
unistd::chdir(rootfs)?;
|
||||||
|
|
||||||
|
// in case the /dev directory was binded mount from guest,
|
||||||
|
// then there's no need to create devices nodes and symlinks
|
||||||
|
// in /dev.
|
||||||
|
if !bind_mount_dev {
|
||||||
default_symlinks()?;
|
default_symlinks()?;
|
||||||
create_devices(&linux.devices, bind_device)?;
|
create_devices(&linux.devices, bind_device)?;
|
||||||
ensure_ptmx()?;
|
ensure_ptmx()?;
|
||||||
|
}
|
||||||
|
|
||||||
unistd::chdir(&olddir)?;
|
unistd::chdir(&olddir)?;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user