mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-06-19 12:14:11 +00:00
kata-sys-util: fix issues where umount2 couldn't get the correct path
Strings in Rust don't have \0 at the end, but C does, which leads to `umount2` in the libc can't get the correct path. Besides, calling `nix::mount::umount2` to avoid using an unsafe block is a robust solution. Fixes: #5871 Signed-off-by: Xuewei Niu <niuxuewei.nxw@antgroup.com>
This commit is contained in:
parent
5ef7ed72ae
commit
8079a9732d
8
src/libs/Cargo.lock
generated
8
src/libs/Cargo.lock
generated
@ -40,6 +40,12 @@ version = "1.1.0"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa"
|
checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "base64"
|
||||||
|
version = "0.13.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "bitflags"
|
name = "bitflags"
|
||||||
version = "1.2.1"
|
version = "1.2.1"
|
||||||
@ -420,6 +426,8 @@ dependencies = [
|
|||||||
name = "kata-types"
|
name = "kata-types"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"anyhow",
|
||||||
|
"base64",
|
||||||
"bitmask-enum",
|
"bitmask-enum",
|
||||||
"byte-unit",
|
"byte-unit",
|
||||||
"glob",
|
"glob",
|
||||||
|
@ -43,8 +43,6 @@
|
|||||||
use std::fmt::Debug;
|
use std::fmt::Debug;
|
||||||
use std::fs;
|
use std::fs;
|
||||||
use std::io::{self, BufRead};
|
use std::io::{self, BufRead};
|
||||||
use std::os::raw::c_char;
|
|
||||||
use std::os::unix::ffi::OsStrExt;
|
|
||||||
use std::os::unix::fs::{DirBuilderExt, OpenOptionsExt};
|
use std::os::unix::fs::{DirBuilderExt, OpenOptionsExt};
|
||||||
use std::os::unix::io::AsRawFd;
|
use std::os::unix::io::AsRawFd;
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
@ -760,18 +758,11 @@ pub fn umount_all<P: AsRef<Path>>(mountpoint: P, lazy_umount: bool) -> Result<()
|
|||||||
|
|
||||||
// Counterpart of nix::umount2, with support of `UMOUNT_FOLLOW`.
|
// Counterpart of nix::umount2, with support of `UMOUNT_FOLLOW`.
|
||||||
fn umount2<P: AsRef<Path>>(path: P, lazy_umount: bool) -> std::io::Result<()> {
|
fn umount2<P: AsRef<Path>>(path: P, lazy_umount: bool) -> std::io::Result<()> {
|
||||||
let path_ptr = path.as_ref().as_os_str().as_bytes().as_ptr() as *const c_char;
|
let mut flags = MntFlags::UMOUNT_NOFOLLOW;
|
||||||
let mut flags = MntFlags::UMOUNT_NOFOLLOW.bits();
|
|
||||||
if lazy_umount {
|
if lazy_umount {
|
||||||
flags |= MntFlags::MNT_DETACH.bits();
|
flags |= MntFlags::MNT_DETACH;
|
||||||
}
|
|
||||||
|
|
||||||
// Safe because parameter is valid and we have checked the reuslt.
|
|
||||||
if unsafe { libc::umount2(path_ptr, flags) } < 0 {
|
|
||||||
Err(io::Error::last_os_error())
|
|
||||||
} else {
|
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
|
nix::mount::umount2(path.as_ref(), flags).map_err(io::Error::from)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
Loading…
Reference in New Issue
Block a user