runtime-rs:add hypervisor interface capabilities

1. be able to check does hypervisor support use block device, block
device hotplug, multi-queue, and share file

2. be able to set the hypervisor capability of using block device, block
device hotplug, multi-queue, and share file

Fixes: #5569
Signed-off-by: Zhongtao Hu <zhongtaohu.tim@linux.alibaba.com>
This commit is contained in:
Zhongtao Hu
2022-11-02 17:52:47 +08:00
parent 288e337a6f
commit fef8e92af1
11 changed files with 188 additions and 9 deletions

View File

@@ -16,7 +16,10 @@ use dragonball::{
vm::VmConfigInfo,
};
use kata_sys_util::mount;
use kata_types::config::hypervisor::Hypervisor as HypervisorConfig;
use kata_types::{
capabilities::{Capabilities, CapabilityBits},
config::hypervisor::Hypervisor as HypervisorConfig,
};
use persist::{sandbox_persist::Persist, KATA_PATH};
use std::{collections::HashSet, fs::create_dir_all, path::PathBuf};
@@ -58,10 +61,19 @@ pub struct DragonballInner {
/// cached block device
pub(crate) cached_block_devices: HashSet<String>,
/// dragonball capabilities
pub(crate) capabilities: Capabilities,
}
impl DragonballInner {
pub fn new() -> DragonballInner {
let mut capabilities = Capabilities::new();
capabilities.set(
CapabilityBits::BlockDeviceSupport
| CapabilityBits::BlockDeviceHotplugSupport
| CapabilityBits::FsSharingSupport,
);
DragonballInner {
id: "".to_string(),
vm_path: "".to_string(),
@@ -74,6 +86,7 @@ impl DragonballInner {
vmm_instance: VmmInstance::new(""),
run_dir: "".to_string(),
cached_block_devices: Default::default(),
capabilities,
}
}
@@ -351,6 +364,7 @@ impl Persist for DragonballInner {
run_dir: hypervisor_state.run_dir,
pending_devices: vec![],
cached_block_devices: hypervisor_state.cached_block_devices,
capabilities: Capabilities::new(),
})
}
}

View File

@@ -9,7 +9,8 @@ use std::{
iter::FromIterator,
};
use anyhow::{Context, Result};
use anyhow::{Context, Ok, Result};
use kata_types::capabilities::Capabilities;
use super::inner::DragonballInner;
use crate::{utils, VcpuThreadIds, VmmState};
@@ -133,4 +134,8 @@ impl DragonballInner {
pub(crate) async fn get_jailer_root(&self) -> Result<String> {
Ok(self.jailer_root.clone())
}
pub(crate) async fn capabilities(&self) -> Result<Capabilities> {
Ok(self.capabilities.clone())
}
}

View File

@@ -16,6 +16,7 @@ use std::sync::Arc;
use anyhow::{Context, Result};
use async_trait::async_trait;
use kata_types::capabilities::Capabilities;
use kata_types::config::hypervisor::Hypervisor as HypervisorConfig;
use tokio::sync::RwLock;
@@ -131,6 +132,11 @@ impl Hypervisor for Dragonball {
async fn save_state(&self) -> Result<HypervisorState> {
self.save().await
}
async fn capabilities(&self) -> Result<Capabilities> {
let inner = self.inner.read().await;
inner.capabilities().await
}
}
#[async_trait]

View File

@@ -21,8 +21,8 @@ use std::collections::HashMap;
use anyhow::Result;
use async_trait::async_trait;
use hypervisor_persist::HypervisorState;
use kata_types::capabilities::Capabilities;
use kata_types::config::hypervisor::Hypervisor as HypervisorConfig;
// Config which driver to use as vm root dev
const VM_ROOTFS_DRIVER_BLK: &str = "virtio-blk";
const VM_ROOTFS_DRIVER_PMEM: &str = "virtio-pmem";
@@ -65,4 +65,5 @@ pub trait Hypervisor: Send + Sync {
async fn check(&self) -> Result<()>;
async fn get_jailer_root(&self) -> Result<String>;
async fn save_state(&self) -> Result<HypervisorState>;
async fn capabilities(&self) -> Result<Capabilities>;
}

View File

@@ -71,12 +71,21 @@ impl ResourceManagerInner {
for dc in device_configs {
match dc {
ResourceConfig::ShareFs(c) => {
let share_fs = share_fs::new(&self.sid, &c).context("new share fs")?;
share_fs
.setup_device_before_start_vm(self.hypervisor.as_ref())
.await
.context("setup share fs device before start vm")?;
self.share_fs = Some(share_fs);
self.share_fs = if self
.hypervisor
.capabilities()
.await?
.is_fs_sharing_supported()
{
let share_fs = share_fs::new(&self.sid, &c).context("new share fs")?;
share_fs
.setup_device_before_start_vm(self.hypervisor.as_ref())
.await
.context("setup share fs device before start vm")?;
Some(share_fs)
} else {
None
};
}
ResourceConfig::Network(c) => {
let d = network::new(&c).await.context("new network")?;