mirror of
https://github.com/aljazceru/kata-containers.git
synced 2025-12-17 22:34:25 +01:00
Merge pull request #5570 from openanolis/capability
runtime-rs:add hypervisor interface capabilities
This commit is contained in:
@@ -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(),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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]
|
||||
|
||||
@@ -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>;
|
||||
}
|
||||
|
||||
@@ -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")?;
|
||||
|
||||
Reference in New Issue
Block a user