mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-06-27 07:48:55 +00:00
rustjail: fix the issue of bind mount device file from guest
When do pass guest device files to container, the source file wouldn't be a regular file, but we also need to create a corresponding destination file to bind mount source file to it. Thus it's better to check whether the source file was a directory instead of regular file. Fixes: #1477 Signed-off-by: fupan.lfp <fupan.lfp@antfin.com>
This commit is contained in:
parent
61f0291d63
commit
34dc861cde
@ -736,10 +736,10 @@ fn mount_from(
|
|||||||
|
|
||||||
let src = if m.r#type.as_str() == "bind" {
|
let src = if m.r#type.as_str() == "bind" {
|
||||||
let src = fs::canonicalize(m.source.as_str())?;
|
let src = fs::canonicalize(m.source.as_str())?;
|
||||||
let dir = if src.is_file() {
|
let dir = if src.is_dir() {
|
||||||
Path::new(&dest).parent().unwrap()
|
|
||||||
} else {
|
|
||||||
Path::new(&dest)
|
Path::new(&dest)
|
||||||
|
} else {
|
||||||
|
Path::new(&dest).parent().unwrap()
|
||||||
};
|
};
|
||||||
|
|
||||||
let _ = fs::create_dir_all(&dir).map_err(|e| {
|
let _ = fs::create_dir_all(&dir).map_err(|e| {
|
||||||
@ -752,7 +752,7 @@ fn mount_from(
|
|||||||
});
|
});
|
||||||
|
|
||||||
// make sure file exists so we can bind over it
|
// make sure file exists so we can bind over it
|
||||||
if src.is_file() {
|
if !src.is_dir() {
|
||||||
let _ = OpenOptions::new().create(true).write(true).open(&dest);
|
let _ = OpenOptions::new().create(true).write(true).open(&dest);
|
||||||
}
|
}
|
||||||
src.to_str().unwrap().to_string()
|
src.to_str().unwrap().to_string()
|
||||||
|
Loading…
Reference in New Issue
Block a user