From 6fd25968c66f117caa542813941dcace5b7d1c20 Mon Sep 17 00:00:00 2001 From: "alex.lyn" Date: Wed, 28 Jun 2023 10:07:07 +0800 Subject: [PATCH] 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 --- .../crates/resource/src/volume/block_volume.rs | 12 +++++++++--- src/runtime-rs/crates/resource/src/volume/utils.rs | 12 +++++++++++- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/src/runtime-rs/crates/resource/src/volume/block_volume.rs b/src/runtime-rs/crates/resource/src/volume/block_volume.rs index ad1c01f17f..69b57054a6 100644 --- a/src/runtime-rs/crates/resource/src/volume/block_volume.rs +++ b/src/runtime-rs/crates/resource/src/volume/block_volume.rs @@ -11,8 +11,8 @@ use tokio::sync::RwLock; use super::Volume; use crate::volume::utils::{ - generate_shared_path, volume_mount_info, DEFAULT_VOLUME_FS_TYPE, KATA_DIRECT_VOLUME_TYPE, - KATA_MOUNT_BIND_TYPE, + generate_shared_path, get_direct_volume_path, volume_mount_info, DEFAULT_VOLUME_FS_TYPE, + KATA_DIRECT_VOLUME_TYPE, KATA_MOUNT_BIND_TYPE, }; use hypervisor::{ device::{ @@ -182,8 +182,14 @@ pub(crate) fn is_block_volume(m: &oci::Mount) -> Result { 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 = - 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); match m.r#type.as_str() { diff --git a/src/runtime-rs/crates/resource/src/volume/utils.rs b/src/runtime-rs/crates/resource/src/volume/utils.rs index cffb839c86..2121b02c2c 100644 --- a/src/runtime-rs/crates/resource/src/volume/utils.rs +++ b/src/runtime-rs/crates/resource/src/volume/utils.rs @@ -13,7 +13,9 @@ use crate::{ volume::share_fs_volume::generate_mount_path, }; 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 KATA_MOUNT_BIND_TYPE: &str = "bind"; @@ -27,6 +29,14 @@ pub fn volume_mount_info(volume_path: &str) -> Result { 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 { + 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>(src: P) -> Result { let file_name = src .as_ref()