mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-08-16 07:05:14 +00:00
runtime-rs: add simple Persist implementation for Qemu
This is not necessarily meant to work, just to stub out unimplemented functionality while focusing on more fundamental things. Signed-off-by: Pavel Mores <pmores@redhat.com>
This commit is contained in:
parent
45862aeec0
commit
0cfb2d2570
@ -5,8 +5,13 @@
|
|||||||
|
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
|
|
||||||
use crate::{HypervisorConfig, MemoryConfig, VcpuThreadIds};
|
use crate::{
|
||||||
|
hypervisor_persist::HypervisorState, HypervisorConfig, MemoryConfig,
|
||||||
|
VcpuThreadIds, VsockDevice, HYPERVISOR_QEMU,
|
||||||
|
};
|
||||||
use kata_types::capabilities::{Capabilities, CapabilityBits};
|
use kata_types::capabilities::{Capabilities, CapabilityBits};
|
||||||
|
use async_trait::async_trait;
|
||||||
|
use persist::sandbox_persist::Persist;
|
||||||
|
|
||||||
const VSOCK_SCHEME: &str = "vsock";
|
const VSOCK_SCHEME: &str = "vsock";
|
||||||
const VSOCK_AGENT_CID: u32 = 3;
|
const VSOCK_AGENT_CID: u32 = 3;
|
||||||
@ -178,3 +183,32 @@ impl QemuInner {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[async_trait]
|
||||||
|
impl Persist for QemuInner {
|
||||||
|
type State = HypervisorState;
|
||||||
|
type ConstructorArgs = ();
|
||||||
|
|
||||||
|
/// Save a state of hypervisor
|
||||||
|
async fn save(&self) -> Result<Self::State> {
|
||||||
|
Ok(HypervisorState {
|
||||||
|
hypervisor_type: HYPERVISOR_QEMU.to_string(),
|
||||||
|
id: self.id.clone(),
|
||||||
|
config: self.hypervisor_config(),
|
||||||
|
..Default::default()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Restore hypervisor
|
||||||
|
async fn restore(
|
||||||
|
_hypervisor_args: Self::ConstructorArgs,
|
||||||
|
hypervisor_state: Self::State,
|
||||||
|
) -> Result<Self> {
|
||||||
|
Ok(QemuInner {
|
||||||
|
id: hypervisor_state.id,
|
||||||
|
qemu_process: None,
|
||||||
|
config: hypervisor_state.config,
|
||||||
|
devices: Vec::new(),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -11,8 +11,9 @@ use crate::{Hypervisor, MemoryConfig};
|
|||||||
use crate::{HypervisorConfig, VcpuThreadIds};
|
use crate::{HypervisorConfig, VcpuThreadIds};
|
||||||
use inner::QemuInner;
|
use inner::QemuInner;
|
||||||
use kata_types::capabilities::{Capabilities, CapabilityBits};
|
use kata_types::capabilities::{Capabilities, CapabilityBits};
|
||||||
|
use persist::sandbox_persist::Persist;
|
||||||
|
|
||||||
use anyhow::Result;
|
use anyhow::{Context, Result};
|
||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
|
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
@ -145,7 +146,7 @@ impl Hypervisor for Qemu {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async fn save_state(&self) -> Result<HypervisorState> {
|
async fn save_state(&self) -> Result<HypervisorState> {
|
||||||
todo!()
|
self.save().await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn capabilities(&self) -> Result<Capabilities> {
|
async fn capabilities(&self) -> Result<Capabilities> {
|
||||||
@ -178,3 +179,26 @@ impl Hypervisor for Qemu {
|
|||||||
inner.resize_memory(new_mem_mb)
|
inner.resize_memory(new_mem_mb)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[async_trait]
|
||||||
|
impl Persist for Qemu {
|
||||||
|
type State = HypervisorState;
|
||||||
|
type ConstructorArgs = ();
|
||||||
|
|
||||||
|
/// Save a state of the component.
|
||||||
|
async fn save(&self) -> Result<Self::State> {
|
||||||
|
let inner = self.inner.read().await;
|
||||||
|
inner.save().await.context("save qemu hypervisor state")
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Restore a component from a specified state.
|
||||||
|
async fn restore(
|
||||||
|
hypervisor_args: Self::ConstructorArgs,
|
||||||
|
hypervisor_state: Self::State,
|
||||||
|
) -> Result<Self> {
|
||||||
|
let inner = QemuInner::restore(hypervisor_args, hypervisor_state).await?;
|
||||||
|
Ok(Self {
|
||||||
|
inner: Arc::new(RwLock::new(inner)),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user