vm-migration: Make snapshot() mutable

There will be some cases where the implementation of the snapshot()
function from the Snapshottable trait will require to modify some
internal data, therefore we make this possible by updating the trait
definition with snapshot(&mut self).

Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com>
This commit is contained in:
Sebastien Boeuf 2020-08-21 14:31:58 +02:00 committed by Samuel Ortiz
parent 7b898285d5
commit 871138d5cc
21 changed files with 22 additions and 22 deletions

View File

@ -70,7 +70,7 @@ impl Snapshottable for Gic {
GIC_SNAPSHOT_ID.to_string() GIC_SNAPSHOT_ID.to_string()
} }
fn snapshot(&self) -> std::result::Result<Snapshot, MigratableError> { fn snapshot(&mut self) -> std::result::Result<Snapshot, MigratableError> {
unimplemented!(); unimplemented!();
} }

View File

@ -405,7 +405,7 @@ impl Snapshottable for Ioapic {
self.id.clone() self.id.clone()
} }
fn snapshot(&self) -> std::result::Result<Snapshot, MigratableError> { fn snapshot(&mut self) -> std::result::Result<Snapshot, MigratableError> {
let snapshot = let snapshot =
serde_json::to_vec(&self.state()).map_err(|e| MigratableError::Snapshot(e.into()))?; serde_json::to_vec(&self.state()).map_err(|e| MigratableError::Snapshot(e.into()))?;

View File

@ -289,7 +289,7 @@ impl Snapshottable for Serial {
self.id.clone() self.id.clone()
} }
fn snapshot(&self) -> std::result::Result<Snapshot, MigratableError> { fn snapshot(&mut self) -> std::result::Result<Snapshot, MigratableError> {
let snapshot = let snapshot =
serde_json::to_vec(&self.state()).map_err(|e| MigratableError::Snapshot(e.into()))?; serde_json::to_vec(&self.state()).map_err(|e| MigratableError::Snapshot(e.into()))?;

View File

@ -889,7 +889,7 @@ impl Snapshottable for PciConfiguration {
String::from("pci_configuration") String::from("pci_configuration")
} }
fn snapshot(&self) -> std::result::Result<Snapshot, MigratableError> { fn snapshot(&mut self) -> std::result::Result<Snapshot, MigratableError> {
let snapshot = let snapshot =
serde_json::to_vec(&self.state()).map_err(|e| MigratableError::Snapshot(e.into()))?; serde_json::to_vec(&self.state()).map_err(|e| MigratableError::Snapshot(e.into()))?;

View File

@ -437,7 +437,7 @@ impl Snapshottable for MsixConfig {
String::from("msix_config") String::from("msix_config")
} }
fn snapshot(&self) -> std::result::Result<Snapshot, MigratableError> { fn snapshot(&mut self) -> std::result::Result<Snapshot, MigratableError> {
let snapshot = let snapshot =
serde_json::to_vec(&self.state()).map_err(|e| MigratableError::Snapshot(e.into()))?; serde_json::to_vec(&self.state()).map_err(|e| MigratableError::Snapshot(e.into()))?;

View File

@ -620,7 +620,7 @@ impl<T: 'static + DiskFile + Send> Snapshottable for Block<T> {
self.id.clone() self.id.clone()
} }
fn snapshot(&self) -> std::result::Result<Snapshot, MigratableError> { fn snapshot(&mut self) -> std::result::Result<Snapshot, MigratableError> {
let snapshot = let snapshot =
serde_json::to_vec(&self.state()).map_err(|e| MigratableError::Snapshot(e.into()))?; serde_json::to_vec(&self.state()).map_err(|e| MigratableError::Snapshot(e.into()))?;

View File

@ -670,7 +670,7 @@ impl Snapshottable for BlockIoUring {
self.id.clone() self.id.clone()
} }
fn snapshot(&self) -> std::result::Result<Snapshot, MigratableError> { fn snapshot(&mut self) -> std::result::Result<Snapshot, MigratableError> {
let snapshot = let snapshot =
serde_json::to_vec(&self.state()).map_err(|e| MigratableError::Snapshot(e.into()))?; serde_json::to_vec(&self.state()).map_err(|e| MigratableError::Snapshot(e.into()))?;

View File

@ -552,7 +552,7 @@ impl Snapshottable for Console {
self.id.clone() self.id.clone()
} }
fn snapshot(&self) -> std::result::Result<Snapshot, MigratableError> { fn snapshot(&mut self) -> std::result::Result<Snapshot, MigratableError> {
let snapshot = let snapshot =
serde_json::to_vec(&self.state()).map_err(|e| MigratableError::Snapshot(e.into()))?; serde_json::to_vec(&self.state()).map_err(|e| MigratableError::Snapshot(e.into()))?;

View File

@ -1016,7 +1016,7 @@ impl Snapshottable for Iommu {
self.id.clone() self.id.clone()
} }
fn snapshot(&self) -> std::result::Result<Snapshot, MigratableError> { fn snapshot(&mut self) -> std::result::Result<Snapshot, MigratableError> {
let snapshot = let snapshot =
serde_json::to_vec(&self.state()).map_err(|e| MigratableError::Snapshot(e.into()))?; serde_json::to_vec(&self.state()).map_err(|e| MigratableError::Snapshot(e.into()))?;

View File

@ -565,7 +565,7 @@ impl Snapshottable for Net {
self.id.clone() self.id.clone()
} }
fn snapshot(&self) -> std::result::Result<Snapshot, MigratableError> { fn snapshot(&mut self) -> std::result::Result<Snapshot, MigratableError> {
let snapshot = let snapshot =
serde_json::to_vec(&self.state()).map_err(|e| MigratableError::Snapshot(e.into()))?; serde_json::to_vec(&self.state()).map_err(|e| MigratableError::Snapshot(e.into()))?;

View File

@ -524,7 +524,7 @@ impl Snapshottable for Pmem {
self.id.clone() self.id.clone()
} }
fn snapshot(&self) -> std::result::Result<Snapshot, MigratableError> { fn snapshot(&mut self) -> std::result::Result<Snapshot, MigratableError> {
let snapshot = let snapshot =
serde_json::to_vec(&self.state()).map_err(|e| MigratableError::Snapshot(e.into()))?; serde_json::to_vec(&self.state()).map_err(|e| MigratableError::Snapshot(e.into()))?;

View File

@ -348,7 +348,7 @@ impl Snapshottable for Rng {
self.id.clone() self.id.clone()
} }
fn snapshot(&self) -> std::result::Result<Snapshot, MigratableError> { fn snapshot(&mut self) -> std::result::Result<Snapshot, MigratableError> {
let snapshot = let snapshot =
serde_json::to_vec(&self.state()).map_err(|e| MigratableError::Snapshot(e.into()))?; serde_json::to_vec(&self.state()).map_err(|e| MigratableError::Snapshot(e.into()))?;

View File

@ -462,7 +462,7 @@ impl Snapshottable for MmioDevice {
self.id.clone() self.id.clone()
} }
fn snapshot(&self) -> std::result::Result<Snapshot, MigratableError> { fn snapshot(&mut self) -> std::result::Result<Snapshot, MigratableError> {
let snapshot = let snapshot =
serde_json::to_vec(&self.state()).map_err(|e| MigratableError::Snapshot(e.into()))?; serde_json::to_vec(&self.state()).map_err(|e| MigratableError::Snapshot(e.into()))?;

View File

@ -290,7 +290,7 @@ impl Snapshottable for VirtioPciCommonConfig {
String::from("virtio_pci_common_config") String::from("virtio_pci_common_config")
} }
fn snapshot(&self) -> std::result::Result<Snapshot, MigratableError> { fn snapshot(&mut self) -> std::result::Result<Snapshot, MigratableError> {
let snapshot = let snapshot =
serde_json::to_vec(&self.state()).map_err(|e| MigratableError::Snapshot(e.into()))?; serde_json::to_vec(&self.state()).map_err(|e| MigratableError::Snapshot(e.into()))?;

View File

@ -1040,7 +1040,7 @@ impl Snapshottable for VirtioPciDevice {
self.id.clone() self.id.clone()
} }
fn snapshot(&self) -> std::result::Result<Snapshot, MigratableError> { fn snapshot(&mut self) -> std::result::Result<Snapshot, MigratableError> {
let snapshot = let snapshot =
serde_json::to_vec(&self.state()).map_err(|e| MigratableError::Snapshot(e.into()))?; serde_json::to_vec(&self.state()).map_err(|e| MigratableError::Snapshot(e.into()))?;

View File

@ -535,7 +535,7 @@ where
self.id.clone() self.id.clone()
} }
fn snapshot(&self) -> std::result::Result<Snapshot, MigratableError> { fn snapshot(&mut self) -> std::result::Result<Snapshot, MigratableError> {
let snapshot = let snapshot =
serde_json::to_vec(&self.state()).map_err(|e| MigratableError::Snapshot(e.into()))?; serde_json::to_vec(&self.state()).map_err(|e| MigratableError::Snapshot(e.into()))?;

View File

@ -111,7 +111,7 @@ pub trait Snapshottable: Pausable {
} }
/// Take a component snapshot. /// Take a component snapshot.
fn snapshot(&self) -> std::result::Result<Snapshot, MigratableError> { fn snapshot(&mut self) -> std::result::Result<Snapshot, MigratableError> {
Ok(Snapshot::new("")) Ok(Snapshot::new(""))
} }

View File

@ -400,7 +400,7 @@ impl Snapshottable for Vcpu {
VCPU_SNAPSHOT_ID.to_string() VCPU_SNAPSHOT_ID.to_string()
} }
fn snapshot(&self) -> std::result::Result<Snapshot, MigratableError> { fn snapshot(&mut self) -> std::result::Result<Snapshot, MigratableError> {
let snapshot = serde_json::to_vec(&self.saved_state) let snapshot = serde_json::to_vec(&self.saved_state)
.map_err(|e| MigratableError::Snapshot(e.into()))?; .map_err(|e| MigratableError::Snapshot(e.into()))?;
@ -1368,7 +1368,7 @@ impl Snapshottable for CpuManager {
CPU_MANAGER_SNAPSHOT_ID.to_string() CPU_MANAGER_SNAPSHOT_ID.to_string()
} }
fn snapshot(&self) -> std::result::Result<Snapshot, MigratableError> { fn snapshot(&mut self) -> std::result::Result<Snapshot, MigratableError> {
let mut cpu_manager_snapshot = Snapshot::new(CPU_MANAGER_SNAPSHOT_ID); let mut cpu_manager_snapshot = Snapshot::new(CPU_MANAGER_SNAPSHOT_ID);
// The CpuManager snapshot is a collection of all vCPUs snapshots. // The CpuManager snapshot is a collection of all vCPUs snapshots.

View File

@ -3626,7 +3626,7 @@ impl Snapshottable for DeviceManager {
DEVICE_MANAGER_SNAPSHOT_ID.to_string() DEVICE_MANAGER_SNAPSHOT_ID.to_string()
} }
fn snapshot(&self) -> std::result::Result<Snapshot, MigratableError> { fn snapshot(&mut self) -> std::result::Result<Snapshot, MigratableError> {
let mut snapshot = Snapshot::new(DEVICE_MANAGER_SNAPSHOT_ID); let mut snapshot = Snapshot::new(DEVICE_MANAGER_SNAPSHOT_ID);
// We aggregate all devices snapshots. // We aggregate all devices snapshots.

View File

@ -1526,7 +1526,7 @@ impl Snapshottable for MemoryManager {
MEMORY_MANAGER_SNAPSHOT_ID.to_string() MEMORY_MANAGER_SNAPSHOT_ID.to_string()
} }
fn snapshot(&self) -> result::Result<Snapshot, MigratableError> { fn snapshot(&mut self) -> result::Result<Snapshot, MigratableError> {
if self.use_zones { if self.use_zones {
return Err(MigratableError::Snapshot(anyhow!( return Err(MigratableError::Snapshot(anyhow!(
"Not allowed to snapshot guest memory when backed with user \ "Not allowed to snapshot guest memory when backed with user \

View File

@ -1267,7 +1267,7 @@ impl Snapshottable for Vm {
VM_SNAPSHOT_ID.to_string() VM_SNAPSHOT_ID.to_string()
} }
fn snapshot(&self) -> std::result::Result<Snapshot, MigratableError> { fn snapshot(&mut self) -> std::result::Result<Snapshot, MigratableError> {
let current_state = self.get_state().unwrap(); let current_state = self.get_state().unwrap();
if current_state != VmState::Paused { if current_state != VmState::Paused {
return Err(MigratableError::Snapshot(anyhow!( return Err(MigratableError::Snapshot(anyhow!(