vmm: Add a VmRestore command

Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
This commit is contained in:
Samuel Ortiz
2020-02-26 00:03:06 +01:00
committed by Rob Bradford
parent 39d4f817f0
commit 92c73c3b78
4 changed files with 72 additions and 0 deletions

View File

@@ -98,6 +98,9 @@ pub enum ApiError {
/// The VM could not be snapshotted.
VmSnapshot(VmError),
/// The VM could not restored.
VmRestore(VmError),
/// The VMM could not shutdown.
VmmShutdown(VmError),
@@ -155,6 +158,13 @@ pub struct VmSnapshotConfig {
pub destination_url: String,
}
#[derive(Clone, Deserialize, Serialize)]
pub struct VmRestoreConfig {
/// The snapshot restore source URL.
/// This is where the VMM is going to get its snapshot to restore itself from.
pub source_url: String,
}
pub enum ApiResponsePayload {
/// No data is sent on the channel.
Empty,
@@ -235,6 +245,9 @@ pub enum ApiRequest {
/// Take a VM snapshot
VmSnapshot(Arc<VmSnapshotConfig>, Sender<ApiResponse>),
/// Restore from a VM snapshot
VmRestore(Arc<VmRestoreConfig>, Sender<ApiResponse>),
}
pub fn vm_create(
@@ -341,6 +354,24 @@ pub fn vm_snapshot(
Ok(())
}
pub fn vm_restore(
api_evt: EventFd,
api_sender: Sender<ApiRequest>,
data: Arc<VmRestoreConfig>,
) -> ApiResult<()> {
let (response_sender, response_receiver) = channel();
// Send the VM restore request.
api_sender
.send(ApiRequest::VmRestore(data, response_sender))
.map_err(ApiError::RequestSend)?;
api_evt.write(1).map_err(ApiError::EventFdWrite)?;
response_receiver.recv().map_err(ApiError::ResponseRecv)??;
Ok(())
}
pub fn vm_info(api_evt: EventFd, api_sender: Sender<ApiRequest>) -> ApiResult<VmInfo> {
let (response_sender, response_receiver) = channel();