mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-04-29 12:14:48 +00:00
runtime-rs: bugfix for direct volume path's validation.
The failure mainly caused by the encoded volume path and the mount/src. As the src will be validated with stat,but it's not a full path and encoded, which causes the stat mount source failed. Fixes: #7186 Signed-off-by: alex.lyn <alex.lyn@antgroup.com>
This commit is contained in:
parent
3885ba4910
commit
6fd25968c6
@ -11,8 +11,8 @@ use tokio::sync::RwLock;
|
|||||||
|
|
||||||
use super::Volume;
|
use super::Volume;
|
||||||
use crate::volume::utils::{
|
use crate::volume::utils::{
|
||||||
generate_shared_path, volume_mount_info, DEFAULT_VOLUME_FS_TYPE, KATA_DIRECT_VOLUME_TYPE,
|
generate_shared_path, get_direct_volume_path, volume_mount_info, DEFAULT_VOLUME_FS_TYPE,
|
||||||
KATA_MOUNT_BIND_TYPE,
|
KATA_DIRECT_VOLUME_TYPE, KATA_MOUNT_BIND_TYPE,
|
||||||
};
|
};
|
||||||
use hypervisor::{
|
use hypervisor::{
|
||||||
device::{
|
device::{
|
||||||
@ -182,8 +182,14 @@ pub(crate) fn is_block_volume(m: &oci::Mount) -> Result<bool> {
|
|||||||
return Ok(false);
|
return Ok(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let source = if m.r#type.as_str() == KATA_DIRECT_VOLUME_TYPE {
|
||||||
|
get_direct_volume_path(&m.source).context("get direct volume path failed")?
|
||||||
|
} else {
|
||||||
|
m.source.clone()
|
||||||
|
};
|
||||||
|
|
||||||
let fstat =
|
let fstat =
|
||||||
stat::stat(m.source.as_str()).context(format!("stat mount source {} failed.", m.source))?;
|
stat::stat(source.as_str()).context(format!("stat mount source {} failed.", source))?;
|
||||||
let s_flag = SFlag::from_bits_truncate(fstat.st_mode);
|
let s_flag = SFlag::from_bits_truncate(fstat.st_mode);
|
||||||
|
|
||||||
match m.r#type.as_str() {
|
match m.r#type.as_str() {
|
||||||
|
@ -13,7 +13,9 @@ use crate::{
|
|||||||
volume::share_fs_volume::generate_mount_path,
|
volume::share_fs_volume::generate_mount_path,
|
||||||
};
|
};
|
||||||
use kata_sys_util::eother;
|
use kata_sys_util::eother;
|
||||||
use kata_types::mount::{get_volume_mount_info, DirectVolumeMountInfo};
|
use kata_types::mount::{
|
||||||
|
get_volume_mount_info, join_path, DirectVolumeMountInfo, KATA_DIRECT_VOLUME_ROOT_PATH,
|
||||||
|
};
|
||||||
|
|
||||||
pub const DEFAULT_VOLUME_FS_TYPE: &str = "ext4";
|
pub const DEFAULT_VOLUME_FS_TYPE: &str = "ext4";
|
||||||
pub const KATA_MOUNT_BIND_TYPE: &str = "bind";
|
pub const KATA_MOUNT_BIND_TYPE: &str = "bind";
|
||||||
@ -27,6 +29,14 @@ pub fn volume_mount_info(volume_path: &str) -> Result<DirectVolumeMountInfo> {
|
|||||||
get_volume_mount_info(volume_path)
|
get_volume_mount_info(volume_path)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// get direct volume path whose volume_path encoded with base64
|
||||||
|
pub fn get_direct_volume_path(volume_path: &str) -> Result<String> {
|
||||||
|
let volume_full_path =
|
||||||
|
join_path(KATA_DIRECT_VOLUME_ROOT_PATH, volume_path).context("failed to join path.")?;
|
||||||
|
|
||||||
|
Ok(volume_full_path.display().to_string())
|
||||||
|
}
|
||||||
|
|
||||||
pub fn get_file_name<P: AsRef<Path>>(src: P) -> Result<String> {
|
pub fn get_file_name<P: AsRef<Path>>(src: P) -> Result<String> {
|
||||||
let file_name = src
|
let file_name = src
|
||||||
.as_ref()
|
.as_ref()
|
||||||
|
Loading…
Reference in New Issue
Block a user