vmm: Move restore parameters into common RestoreConfig structure

The goal here is to move the restore parameters into a dedicated
structure that can be reused from the entire codebase, making the
addition or removal of a parameter easier.

Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com>
This commit is contained in:
Sebastien Boeuf
2020-04-07 14:50:19 +02:00
parent 6712958f23
commit a517ca23a0
7 changed files with 63 additions and 29 deletions

View File

@@ -8,7 +8,7 @@ use crate::api::{
vm_add_device, vm_add_disk, vm_add_net, vm_add_pmem, vm_boot, vm_create, vm_delete, vm_info,
vm_pause, vm_reboot, vm_remove_device, vm_resize, vm_restore, vm_resume, vm_shutdown,
vm_snapshot, vmm_ping, vmm_shutdown, ApiError, ApiRequest, ApiResult, DeviceConfig, DiskConfig,
NetConfig, PmemConfig, VmAction, VmConfig, VmRemoveDeviceData, VmResizeData, VmRestoreConfig,
NetConfig, PmemConfig, RestoreConfig, VmAction, VmConfig, VmRemoveDeviceData, VmResizeData,
VmSnapshotConfig,
};
use micro_http::{Body, Method, Request, Response, StatusCode, Version};
@@ -252,8 +252,8 @@ impl EndpointHandler for VmRestore {
Method::Put => {
match &req.body {
Some(body) => {
// Deserialize into a VmRestoreConfig
let vm_restore_data: VmRestoreConfig =
// Deserialize into a RestoreConfig
let vm_restore_data: RestoreConfig =
match serde_json::from_slice(body.raw())
.map_err(HttpError::SerdeJsonDeserialize)
{

View File

@@ -37,7 +37,7 @@ pub use self::http::start_http_thread;
pub mod http;
pub mod http_endpoint;
use crate::config::{DeviceConfig, DiskConfig, NetConfig, PmemConfig, VmConfig};
use crate::config::{DeviceConfig, DiskConfig, NetConfig, PmemConfig, RestoreConfig, VmConfig};
use crate::vm::{Error as VmError, VmState};
use std::io;
use std::sync::mpsc::{channel, RecvError, SendError, Sender};
@@ -158,13 +158,6 @@ 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,
@@ -247,7 +240,7 @@ pub enum ApiRequest {
VmSnapshot(Arc<VmSnapshotConfig>, Sender<ApiResponse>),
/// Restore from a VM snapshot
VmRestore(Arc<VmRestoreConfig>, Sender<ApiResponse>),
VmRestore(Arc<RestoreConfig>, Sender<ApiResponse>),
}
pub fn vm_create(
@@ -357,7 +350,7 @@ pub fn vm_snapshot(
pub fn vm_restore(
api_evt: EventFd,
api_sender: Sender<ApiRequest>,
data: Arc<VmRestoreConfig>,
data: Arc<RestoreConfig>,
) -> ApiResult<()> {
let (response_sender, response_receiver) = channel();