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:
Pavel Mores 2023-11-07 15:18:28 +01:00
parent 45862aeec0
commit 0cfb2d2570
2 changed files with 61 additions and 3 deletions

View File

@ -5,8 +5,13 @@
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 async_trait::async_trait;
use persist::sandbox_persist::Persist;
const VSOCK_SCHEME: &str = "vsock";
const VSOCK_AGENT_CID: u32 = 3;
@ -178,3 +183,32 @@ impl QemuInner {
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(),
})
}
}

View File

@ -11,8 +11,9 @@ use crate::{Hypervisor, MemoryConfig};
use crate::{HypervisorConfig, VcpuThreadIds};
use inner::QemuInner;
use kata_types::capabilities::{Capabilities, CapabilityBits};
use persist::sandbox_persist::Persist;
use anyhow::Result;
use anyhow::{Context, Result};
use async_trait::async_trait;
use std::sync::Arc;
@ -145,7 +146,7 @@ impl Hypervisor for Qemu {
}
async fn save_state(&self) -> Result<HypervisorState> {
todo!()
self.save().await
}
async fn capabilities(&self) -> Result<Capabilities> {
@ -178,3 +179,26 @@ impl Hypervisor for Qemu {
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)),
})
}
}