mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-07-21 18:53:30 +00:00
runtime-rs: enhancement of spdk volume.
(1) Add enum DirectVolumeType for direct volumes. (2) Reimplement spdk volume into direct_volume and do alignment of rawblock volume. Fixes: #8300 Signed-off-by: alex.lyn <alex.lyn@antgroup.com>
This commit is contained in:
parent
f973729029
commit
e3fd403126
@ -14,12 +14,25 @@ use hypervisor::device::device_manager::DeviceManager;
|
|||||||
|
|
||||||
use crate::volume::{
|
use crate::volume::{
|
||||||
direct_volumes::{
|
direct_volumes::{
|
||||||
get_direct_volume_path, rawblock_volume, volume_mount_info, KATA_DIRECT_VOLUME_TYPE,
|
get_direct_volume_path, rawblock_volume, spdk_volume, volume_mount_info,
|
||||||
|
KATA_DIRECT_VOLUME_TYPE, KATA_SPDK_VOLUME_TYPE, KATA_SPOOL_VOLUME_TYPE,
|
||||||
},
|
},
|
||||||
utils::KATA_MOUNT_BIND_TYPE,
|
utils::KATA_MOUNT_BIND_TYPE,
|
||||||
Volume,
|
Volume,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum DirectVolumeType {
|
||||||
|
RawBlock,
|
||||||
|
Spdk,
|
||||||
|
}
|
||||||
|
|
||||||
|
fn to_volume_type(volume_type: &str) -> DirectVolumeType {
|
||||||
|
match volume_type {
|
||||||
|
KATA_SPDK_VOLUME_TYPE | KATA_SPOOL_VOLUME_TYPE => DirectVolumeType::Spdk,
|
||||||
|
_ => DirectVolumeType::RawBlock,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub(crate) async fn handle_direct_volume(
|
pub(crate) async fn handle_direct_volume(
|
||||||
d: &RwLock<DeviceManager>,
|
d: &RwLock<DeviceManager>,
|
||||||
m: &oci::Mount,
|
m: &oci::Mount,
|
||||||
@ -59,11 +72,18 @@ pub(crate) async fn handle_direct_volume(
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let direct_volume: Arc<dyn Volume> = Arc::new(
|
let direct_volume: Arc<dyn Volume> = match to_volume_type(mount_info.volume_type.as_str()) {
|
||||||
rawblock_volume::RawblockVolume::new(d, m, &mount_info, read_only, sid)
|
DirectVolumeType::RawBlock => Arc::new(
|
||||||
.await
|
rawblock_volume::RawblockVolume::new(d, m, &mount_info, read_only, sid)
|
||||||
.with_context(|| format!("new sid {:?} rawblock volume {:?}", &sid, m))?,
|
.await
|
||||||
);
|
.with_context(|| format!("new sid {:?} rawblock volume {:?}", &sid, m))?,
|
||||||
|
),
|
||||||
|
DirectVolumeType::Spdk => Arc::new(
|
||||||
|
spdk_volume::SPDKVolume::new(d, m, &mount_info, read_only, sid)
|
||||||
|
.await
|
||||||
|
.with_context(|| format!("create spdk volume {:?}", m))?,
|
||||||
|
),
|
||||||
|
};
|
||||||
|
|
||||||
Ok(Some(direct_volume))
|
Ok(Some(direct_volume))
|
||||||
}
|
}
|
||||||
@ -71,7 +91,12 @@ pub(crate) async fn handle_direct_volume(
|
|||||||
pub(crate) fn is_direct_volume(m: &oci::Mount) -> Result<bool> {
|
pub(crate) fn is_direct_volume(m: &oci::Mount) -> Result<bool> {
|
||||||
let mount_type = m.r#type.as_str();
|
let mount_type = m.r#type.as_str();
|
||||||
// Filter the non-bind volume and non-direct-vol volume
|
// Filter the non-bind volume and non-direct-vol volume
|
||||||
let vol_types = [KATA_MOUNT_BIND_TYPE, KATA_DIRECT_VOLUME_TYPE];
|
let vol_types = [
|
||||||
|
KATA_MOUNT_BIND_TYPE,
|
||||||
|
KATA_DIRECT_VOLUME_TYPE,
|
||||||
|
KATA_SPDK_VOLUME_TYPE,
|
||||||
|
KATA_SPOOL_VOLUME_TYPE,
|
||||||
|
];
|
||||||
if !vol_types.contains(&mount_type) {
|
if !vol_types.contains(&mount_type) {
|
||||||
return Ok(false);
|
return Ok(false);
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
|
|
||||||
use anyhow::{anyhow, Context, Result};
|
use anyhow::{anyhow, Context, Result};
|
||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
|
use kata_types::mount::DirectVolumeMountInfo;
|
||||||
use nix::sys::{stat, stat::SFlag};
|
use nix::sys::{stat, stat::SFlag};
|
||||||
use tokio::sync::RwLock;
|
use tokio::sync::RwLock;
|
||||||
|
|
||||||
@ -18,7 +19,7 @@ use hypervisor::{
|
|||||||
};
|
};
|
||||||
|
|
||||||
use crate::volume::{
|
use crate::volume::{
|
||||||
direct_volumes::{volume_mount_info, KATA_SPDK_VOLUME_TYPE, KATA_SPOOL_VOLUME_TYPE},
|
direct_volumes::{KATA_SPDK_VOLUME_TYPE, KATA_SPOOL_VOLUME_TYPE},
|
||||||
utils::{generate_shared_path, DEFAULT_VOLUME_FS_TYPE},
|
utils::{generate_shared_path, DEFAULT_VOLUME_FS_TYPE},
|
||||||
Volume,
|
Volume,
|
||||||
};
|
};
|
||||||
@ -35,26 +36,23 @@ impl SPDKVolume {
|
|||||||
pub(crate) async fn new(
|
pub(crate) async fn new(
|
||||||
d: &RwLock<DeviceManager>,
|
d: &RwLock<DeviceManager>,
|
||||||
m: &oci::Mount,
|
m: &oci::Mount,
|
||||||
|
mount_info: &DirectVolumeMountInfo,
|
||||||
read_only: bool,
|
read_only: bool,
|
||||||
sid: &str,
|
sid: &str,
|
||||||
) -> Result<Self> {
|
) -> Result<Self> {
|
||||||
let mnt_src: &str = &m.source;
|
let device = match mount_info.volume_type.as_str() {
|
||||||
|
|
||||||
// deserde Information from mountinfo.json
|
|
||||||
let v = volume_mount_info(mnt_src).context("deserde information from mountinfo.json")?;
|
|
||||||
let device = match v.volume_type.as_str() {
|
|
||||||
KATA_SPDK_VOLUME_TYPE => {
|
KATA_SPDK_VOLUME_TYPE => {
|
||||||
if v.device.starts_with("spdk://") {
|
if mount_info.device.starts_with("spdk://") {
|
||||||
v.device.clone()
|
mount_info.device.clone()
|
||||||
} else {
|
} else {
|
||||||
format!("spdk://{}", v.device.as_str())
|
format!("spdk://{}", mount_info.device.as_str())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
KATA_SPOOL_VOLUME_TYPE => {
|
KATA_SPOOL_VOLUME_TYPE => {
|
||||||
if v.device.starts_with("spool://") {
|
if mount_info.device.starts_with("spool://") {
|
||||||
v.device.clone()
|
mount_info.device.clone()
|
||||||
} else {
|
} else {
|
||||||
format!("spool://{}", v.device.as_str())
|
format!("spool://{}", mount_info.device.as_str())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => return Err(anyhow!("mountinfo.json is invalid")),
|
_ => return Err(anyhow!("mountinfo.json is invalid")),
|
||||||
@ -82,12 +80,12 @@ impl SPDKVolume {
|
|||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
|
|
||||||
if let Some(num) = v.metadata.get("num_queues") {
|
if let Some(num) = mount_info.metadata.get("num_queues") {
|
||||||
vhu_blk_config.num_queues = num
|
vhu_blk_config.num_queues = num
|
||||||
.parse::<usize>()
|
.parse::<usize>()
|
||||||
.context("num queues parse usize failed.")?;
|
.context("num queues parse usize failed.")?;
|
||||||
}
|
}
|
||||||
if let Some(size) = v.metadata.get("queue_size") {
|
if let Some(size) = mount_info.metadata.get("queue_size") {
|
||||||
vhu_blk_config.queue_size = size
|
vhu_blk_config.queue_size = size
|
||||||
.parse::<u32>()
|
.parse::<u32>()
|
||||||
.context("num queues parse u32 failed.")?;
|
.context("num queues parse u32 failed.")?;
|
||||||
@ -125,7 +123,7 @@ impl SPDKVolume {
|
|||||||
storage.mount_point = guest_path.clone();
|
storage.mount_point = guest_path.clone();
|
||||||
|
|
||||||
if m.r#type != "bind" {
|
if m.r#type != "bind" {
|
||||||
storage.fs_type = v.fs_type.clone();
|
storage.fs_type = mount_info.fs_type.clone();
|
||||||
} else {
|
} else {
|
||||||
storage.fs_type = DEFAULT_VOLUME_FS_TYPE.to_string();
|
storage.fs_type = DEFAULT_VOLUME_FS_TYPE.to_string();
|
||||||
}
|
}
|
||||||
@ -179,13 +177,3 @@ impl Volume for SPDKVolume {
|
|||||||
Ok(Some(self.device_id.clone()))
|
Ok(Some(self.device_id.clone()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn is_spdk_volume(m: &oci::Mount) -> bool {
|
|
||||||
// spdkvol or spoolvol will share the same implementation
|
|
||||||
let vol_types = [KATA_SPDK_VOLUME_TYPE, KATA_SPOOL_VOLUME_TYPE];
|
|
||||||
if vol_types.contains(&m.r#type.as_str()) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
false
|
|
||||||
}
|
|
||||||
|
@ -15,10 +15,7 @@ pub mod direct_volume;
|
|||||||
use crate::volume::direct_volume::is_direct_volume;
|
use crate::volume::direct_volume::is_direct_volume;
|
||||||
|
|
||||||
pub mod direct_volumes;
|
pub mod direct_volumes;
|
||||||
use direct_volumes::{
|
use direct_volumes::vfio_volume::{is_vfio_volume, VfioVolume};
|
||||||
spdk_volume::{is_spdk_volume, SPDKVolume},
|
|
||||||
vfio_volume::{is_vfio_volume, VfioVolume},
|
|
||||||
};
|
|
||||||
|
|
||||||
use std::{sync::Arc, vec::Vec};
|
use std::{sync::Arc, vec::Vec};
|
||||||
|
|
||||||
@ -99,12 +96,6 @@ impl VolumeResource {
|
|||||||
.await
|
.await
|
||||||
.with_context(|| format!("new vfio volume {:?}", m))?,
|
.with_context(|| format!("new vfio volume {:?}", m))?,
|
||||||
)
|
)
|
||||||
} else if is_spdk_volume(m) {
|
|
||||||
Arc::new(
|
|
||||||
SPDKVolume::new(d, m, read_only, sid)
|
|
||||||
.await
|
|
||||||
.with_context(|| format!("create spdk volume {:?}", m))?,
|
|
||||||
)
|
|
||||||
} else if let Some(options) =
|
} else if let Some(options) =
|
||||||
get_huge_page_option(m).context("failed to check huge page")?
|
get_huge_page_option(m).context("failed to check huge page")?
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user