vmm: device_manager: Implement the Pausable trait

Since the Snapshotable placeholder and Migratable traits are provided as
well, the DeviceManager object and all its objects are now Migratable.

All Migratable devices are tracked as Arc<Mutex<dyn Migratable>>
references.

Keeping track of all migratable devices allows for implementing the
Migratable trait for the DeviceManager structure, making the whole
device model potentially migratable.

Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
This commit is contained in:
Samuel Ortiz
2019-11-19 00:24:31 +01:00
parent a122da4bef
commit 35dd1523c9
4 changed files with 40 additions and 0 deletions
+9
View File
@@ -43,6 +43,7 @@ use std::os::unix::io::FromRawFd;
use std::sync::{Arc, Mutex, RwLock};
use std::{result, str, thread};
use vm_allocator::{GsiApic, SystemAllocator};
use vm_device::{MigratableError, Pausable};
use vm_memory::guest_memory::FileOffset;
use vm_memory::{
Address, Bytes, Error as MmapError, GuestAddress, GuestMemory, GuestMemoryMmap,
@@ -145,6 +146,12 @@ pub enum Error {
/// Capability missing
CapabilityMissing(Cap),
/// Cannot pause devices
PauseDevices(MigratableError),
/// Cannot resume devices
ResumeDevices(MigratableError),
}
pub type Result<T> = result::Result<T, Error>;
@@ -627,6 +634,7 @@ impl Vm {
.unwrap()
.pause()
.map_err(Error::CpuManager)?;
self.devices.pause().map_err(Error::PauseDevices)?;
*state = new_state;
@@ -639,6 +647,7 @@ impl Vm {
state.valid_transition(new_state)?;
self.devices.resume().map_err(Error::ResumeDevices)?;
self.cpu_manager
.lock()
.unwrap()