mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-08-29 04:51:34 +00:00
runtime-rs: re-organize the volumes with adding new direct_volumes.
Add a new dire direct_volumes containing spdk, rawblock and vfio volume. Fixes: #8300 Signed-off-by: alex.lyn <alex.lyn@antgroup.com>
This commit is contained in:
parent
6731466b13
commit
17d2d465d1
@ -0,0 +1,32 @@
|
||||
// Copyright (c) 2023 Ant Group
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
|
||||
use anyhow::{Context, Result};
|
||||
|
||||
use kata_types::mount::{
|
||||
get_volume_mount_info, join_path, DirectVolumeMountInfo, KATA_DIRECT_VOLUME_ROOT_PATH,
|
||||
};
|
||||
|
||||
pub mod rawblock_volume;
|
||||
pub mod spdk_volume;
|
||||
pub mod vfio_volume;
|
||||
|
||||
pub const KATA_DIRECT_VOLUME_TYPE: &str = "directvol";
|
||||
pub const KATA_VFIO_VOLUME_TYPE: &str = "vfiovol";
|
||||
pub const KATA_SPDK_VOLUME_TYPE: &str = "spdkvol";
|
||||
pub const KATA_SPOOL_VOLUME_TYPE: &str = "spoolvol";
|
||||
|
||||
// volume mount info load infomation from mountinfo.json
|
||||
pub fn volume_mount_info(volume_path: &str) -> Result<DirectVolumeMountInfo> {
|
||||
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())
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
// Copyright (c) 2019-2022 Alibaba Cloud
|
||||
// Copyright (c) 2019-2022 Ant Group
|
||||
// Copyright (c) 2023 Alibaba Cloud
|
||||
// Copyright (c) 2023 Ant Group
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
@ -9,10 +9,6 @@ use async_trait::async_trait;
|
||||
use nix::sys::{stat, stat::SFlag};
|
||||
use tokio::sync::RwLock;
|
||||
|
||||
use super::Volume;
|
||||
use crate::volume::utils::{
|
||||
get_direct_volume_path, handle_block_volume, volume_mount_info, KATA_DIRECT_VOLUME_TYPE,
|
||||
};
|
||||
use hypervisor::{
|
||||
device::{
|
||||
device_manager::{do_handle_device, get_block_driver, DeviceManager},
|
||||
@ -21,6 +17,12 @@ use hypervisor::{
|
||||
BlockConfig,
|
||||
};
|
||||
|
||||
use crate::volume::{
|
||||
direct_volumes::{get_direct_volume_path, volume_mount_info, KATA_DIRECT_VOLUME_TYPE},
|
||||
utils::handle_block_volume,
|
||||
Volume,
|
||||
};
|
||||
|
||||
#[derive(Clone)]
|
||||
pub(crate) struct RawblockVolume {
|
||||
storage: Option<agent::Storage>,
|
@ -9,11 +9,6 @@ use async_trait::async_trait;
|
||||
use nix::sys::{stat, stat::SFlag};
|
||||
use tokio::sync::RwLock;
|
||||
|
||||
use super::Volume;
|
||||
use crate::volume::utils::{
|
||||
generate_shared_path, volume_mount_info, DEFAULT_VOLUME_FS_TYPE, KATA_SPDK_VOLUME_TYPE,
|
||||
KATA_SPOOL_VOLUME_TYPE,
|
||||
};
|
||||
use hypervisor::{
|
||||
device::{
|
||||
device_manager::{do_handle_device, get_block_driver, DeviceManager},
|
||||
@ -22,6 +17,12 @@ use hypervisor::{
|
||||
VhostUserConfig, VhostUserType,
|
||||
};
|
||||
|
||||
use crate::volume::{
|
||||
direct_volumes::{volume_mount_info, KATA_SPDK_VOLUME_TYPE, KATA_SPOOL_VOLUME_TYPE},
|
||||
utils::{generate_shared_path, DEFAULT_VOLUME_FS_TYPE},
|
||||
Volume,
|
||||
};
|
||||
|
||||
/// SPDKVolume: spdk block device volume
|
||||
#[derive(Clone)]
|
||||
pub(crate) struct SPDKVolume {
|
@ -8,10 +8,6 @@ use anyhow::{anyhow, Context, Result};
|
||||
use async_trait::async_trait;
|
||||
use tokio::sync::RwLock;
|
||||
|
||||
use super::Volume;
|
||||
use crate::volume::utils::{
|
||||
generate_shared_path, volume_mount_info, DEFAULT_VOLUME_FS_TYPE, KATA_VFIO_VOLUME_TYPE,
|
||||
};
|
||||
use hypervisor::{
|
||||
device::{
|
||||
device_manager::{do_handle_device, DeviceManager},
|
||||
@ -20,6 +16,12 @@ use hypervisor::{
|
||||
get_vfio_device, VfioConfig,
|
||||
};
|
||||
|
||||
use crate::volume::{
|
||||
direct_volumes::{volume_mount_info, KATA_VFIO_VOLUME_TYPE},
|
||||
utils::{generate_shared_path, DEFAULT_VOLUME_FS_TYPE},
|
||||
Volume,
|
||||
};
|
||||
|
||||
pub(crate) struct VfioVolume {
|
||||
storage: Option<agent::Storage>,
|
||||
mount: oci::Mount,
|
@ -11,14 +11,12 @@ mod share_fs_volume;
|
||||
mod shm_volume;
|
||||
pub mod utils;
|
||||
|
||||
pub mod vfio_volume;
|
||||
use vfio_volume::is_vfio_volume;
|
||||
|
||||
pub mod spdk_volume;
|
||||
use spdk_volume::is_spdk_volume;
|
||||
|
||||
pub mod rawblock_volume;
|
||||
use rawblock_volume::is_rawblock_volume;
|
||||
pub mod direct_volumes;
|
||||
use direct_volumes::{
|
||||
rawblock_volume::{is_rawblock_volume, RawblockVolume},
|
||||
spdk_volume::{is_spdk_volume, SPDKVolume},
|
||||
vfio_volume::{is_vfio_volume, VfioVolume},
|
||||
};
|
||||
|
||||
use std::{sync::Arc, vec::Vec};
|
||||
|
||||
@ -87,19 +85,19 @@ impl VolumeResource {
|
||||
} else if is_rawblock_volume(m)? {
|
||||
// handle rawblock volume
|
||||
Arc::new(
|
||||
rawblock_volume::RawblockVolume::new(d, m, read_only, sid)
|
||||
RawblockVolume::new(d, m, read_only, sid)
|
||||
.await
|
||||
.with_context(|| format!("new rawblock volume {:?}", m))?,
|
||||
)
|
||||
} else if is_vfio_volume(m) {
|
||||
Arc::new(
|
||||
vfio_volume::VfioVolume::new(d, m, read_only, cid, sid)
|
||||
VfioVolume::new(d, m, read_only, cid, sid)
|
||||
.await
|
||||
.with_context(|| format!("new vfio volume {:?}", m))?,
|
||||
)
|
||||
} else if is_spdk_volume(m) {
|
||||
Arc::new(
|
||||
spdk_volume::SPDKVolume::new(d, m, read_only, cid, sid)
|
||||
SPDKVolume::new(d, m, read_only, cid, sid)
|
||||
.await
|
||||
.with_context(|| format!("create spdk volume {:?}", m))?,
|
||||
)
|
||||
|
@ -13,31 +13,11 @@ use crate::{
|
||||
volume::share_fs_volume::generate_mount_path,
|
||||
};
|
||||
use kata_sys_util::eother;
|
||||
use kata_types::mount::{
|
||||
get_volume_mount_info, join_path, DirectVolumeMountInfo, KATA_DIRECT_VOLUME_ROOT_PATH,
|
||||
};
|
||||
|
||||
use hypervisor::device::DeviceType;
|
||||
|
||||
pub const DEFAULT_VOLUME_FS_TYPE: &str = "ext4";
|
||||
pub const KATA_MOUNT_BIND_TYPE: &str = "bind";
|
||||
pub const KATA_DIRECT_VOLUME_TYPE: &str = "directvol";
|
||||
pub const KATA_VFIO_VOLUME_TYPE: &str = "vfiovol";
|
||||
pub const KATA_SPDK_VOLUME_TYPE: &str = "spdkvol";
|
||||
pub const KATA_SPOOL_VOLUME_TYPE: &str = "spoolvol";
|
||||
|
||||
// volume mount info load infomation from mountinfo.json
|
||||
pub fn volume_mount_info(volume_path: &str) -> Result<DirectVolumeMountInfo> {
|
||||
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> {
|
||||
let file_name = src
|
||||
|
Loading…
Reference in New Issue
Block a user