mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-04-30 12:44:39 +00:00
runtime-rs: add conditional compile for virt-sandbox persist
code refactoring, add conditional compile for virt-sandbox persist Fixes: #5706 Signed-off-by: Zhongtao Hu <zhongtaohu.tim@linux.alibaba.com>
This commit is contained in:
parent
7c8d474959
commit
6b2ef66f0f
@ -20,11 +20,12 @@ use kata_types::{annotations::Annotation, config::TomlConfig};
|
|||||||
use linux_container::LinuxContainer;
|
use linux_container::LinuxContainer;
|
||||||
use persist::sandbox_persist::Persist;
|
use persist::sandbox_persist::Persist;
|
||||||
use tokio::sync::{mpsc::Sender, RwLock};
|
use tokio::sync::{mpsc::Sender, RwLock};
|
||||||
use virt_container::sandbox::SandboxRestoreArgs;
|
|
||||||
use virt_container::sandbox::VirtSandbox;
|
|
||||||
use virt_container::sandbox_persist::{SandboxState, SandboxTYPE};
|
|
||||||
#[cfg(feature = "virt")]
|
#[cfg(feature = "virt")]
|
||||||
use virt_container::VirtContainer;
|
use virt_container::{
|
||||||
|
sandbox::{SandboxRestoreArgs, VirtSandbox},
|
||||||
|
sandbox_persist::SandboxState,
|
||||||
|
VirtContainer,
|
||||||
|
};
|
||||||
#[cfg(feature = "wasm")]
|
#[cfg(feature = "wasm")]
|
||||||
use wasm_container::WasmContainer;
|
use wasm_container::WasmContainer;
|
||||||
|
|
||||||
@ -153,8 +154,19 @@ impl RuntimeHandlerManager {
|
|||||||
toml_config: TomlConfig::default(),
|
toml_config: TomlConfig::default(),
|
||||||
sender,
|
sender,
|
||||||
};
|
};
|
||||||
match sandbox_state.sandbox_type {
|
match sandbox_state.sandbox_type.clone() {
|
||||||
SandboxTYPE::VIRTCONTAINER => {
|
#[cfg(feature = "linux")]
|
||||||
|
name if name == LinuxContainer::name() => {
|
||||||
|
// TODO :support linux container (https://github.com/kata-containers/kata-containers/issues/4905)
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
#[cfg(feature = "wasm")]
|
||||||
|
name if name == WasmContainer::name() => {
|
||||||
|
// TODO :support wasm container (https://github.com/kata-containers/kata-containers/issues/4906)
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
#[cfg(feature = "virt")]
|
||||||
|
name if name == VirtContainer::name() => {
|
||||||
let sandbox = VirtSandbox::restore(sandbox_args, sandbox_state)
|
let sandbox = VirtSandbox::restore(sandbox_args, sandbox_state)
|
||||||
.await
|
.await
|
||||||
.context("failed to restore the sandbox")?;
|
.context("failed to restore the sandbox")?;
|
||||||
@ -163,12 +175,7 @@ impl RuntimeHandlerManager {
|
|||||||
.await
|
.await
|
||||||
.context("failed to cleanup the resource")?;
|
.context("failed to cleanup the resource")?;
|
||||||
}
|
}
|
||||||
SandboxTYPE::LINUXCONTAINER => {
|
_ => {
|
||||||
// TODO :support linux container (https://github.com/kata-containers/kata-containers/issues/4905)
|
|
||||||
return Ok(());
|
|
||||||
}
|
|
||||||
SandboxTYPE::WASMCONTAINER => {
|
|
||||||
// TODO :support wasm container (https://github.com/kata-containers/kata-containers/issues/4906)
|
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -23,6 +23,7 @@ use common::{message::Message, RuntimeHandler, RuntimeInstance};
|
|||||||
use hypervisor::{dragonball::Dragonball, Hypervisor, HYPERVISOR_DRAGONBALL};
|
use hypervisor::{dragonball::Dragonball, Hypervisor, HYPERVISOR_DRAGONBALL};
|
||||||
use kata_types::config::{hypervisor::register_hypervisor_plugin, DragonballConfig, TomlConfig};
|
use kata_types::config::{hypervisor::register_hypervisor_plugin, DragonballConfig, TomlConfig};
|
||||||
use resource::ResourceManager;
|
use resource::ResourceManager;
|
||||||
|
use sandbox::VIRTCONTAINER;
|
||||||
use tokio::sync::mpsc::Sender;
|
use tokio::sync::mpsc::Sender;
|
||||||
|
|
||||||
unsafe impl Send for VirtContainer {}
|
unsafe impl Send for VirtContainer {}
|
||||||
@ -39,7 +40,7 @@ impl RuntimeHandler for VirtContainer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn name() -> String {
|
fn name() -> String {
|
||||||
"virt_container".to_string()
|
VIRTCONTAINER.to_string()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn new_handler() -> Arc<dyn RuntimeHandler> {
|
fn new_handler() -> Arc<dyn RuntimeHandler> {
|
||||||
|
@ -28,8 +28,10 @@ use resource::{
|
|||||||
};
|
};
|
||||||
use tokio::sync::{mpsc::Sender, Mutex, RwLock};
|
use tokio::sync::{mpsc::Sender, Mutex, RwLock};
|
||||||
|
|
||||||
use crate::{health_check::HealthCheck, sandbox_persist::SandboxTYPE};
|
use crate::health_check::HealthCheck;
|
||||||
use persist::{self, sandbox_persist::Persist};
|
use persist::{self, sandbox_persist::Persist};
|
||||||
|
|
||||||
|
pub(crate) const VIRTCONTAINER: &str = "virt_container";
|
||||||
pub struct SandboxRestoreArgs {
|
pub struct SandboxRestoreArgs {
|
||||||
pub sid: String,
|
pub sid: String,
|
||||||
pub toml_config: TomlConfig,
|
pub toml_config: TomlConfig,
|
||||||
@ -303,7 +305,7 @@ impl Persist for VirtSandbox {
|
|||||||
/// Save a state of Sandbox
|
/// Save a state of Sandbox
|
||||||
async fn save(&self) -> Result<Self::State> {
|
async fn save(&self) -> Result<Self::State> {
|
||||||
let sandbox_state = crate::sandbox_persist::SandboxState {
|
let sandbox_state = crate::sandbox_persist::SandboxState {
|
||||||
sandbox_type: SandboxTYPE::VIRTCONTAINER,
|
sandbox_type: VIRTCONTAINER.to_string(),
|
||||||
resource: Some(self.resource_manager.save().await?),
|
resource: Some(self.resource_manager.save().await?),
|
||||||
hypervisor: Some(self.hypervisor.save_state().await?),
|
hypervisor: Some(self.hypervisor.save_state().await?),
|
||||||
};
|
};
|
||||||
|
@ -8,16 +8,9 @@ use hypervisor::hypervisor_persist::HypervisorState;
|
|||||||
use resource::resource_persist::ResourceState;
|
use resource::resource_persist::ResourceState;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
|
||||||
pub enum SandboxTYPE {
|
|
||||||
VIRTCONTAINER,
|
|
||||||
LINUXCONTAINER,
|
|
||||||
WASMCONTAINER,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
#[derive(Serialize, Deserialize)]
|
||||||
pub struct SandboxState {
|
pub struct SandboxState {
|
||||||
pub sandbox_type: SandboxTYPE,
|
pub sandbox_type: String,
|
||||||
pub resource: Option<ResourceState>,
|
pub resource: Option<ResourceState>,
|
||||||
pub hypervisor: Option<HypervisorState>,
|
pub hypervisor: Option<HypervisorState>,
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user