vmm: Don't use migratable_devices for restore

This commit switches from migratable_devices to device_tree in order to
restore devices exclusively based on the device tree.

Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com>
This commit is contained in:
Sebastien Boeuf
2020-04-30 20:19:02 +02:00
parent bc6084390f
commit 1be7037229
+10 -6
View File
@@ -3162,10 +3162,12 @@ impl Snapshottable for DeviceManager {
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.
for (_, dev) in self.migratable_devices.iter() { for (_, device_node) in self.device_tree.iter() {
let device_snapshot = dev.lock().unwrap().snapshot()?; if let Some(migratable) = &device_node.migratable {
let device_snapshot = migratable.lock().unwrap().snapshot()?;
snapshot.add_snapshot(device_snapshot); snapshot.add_snapshot(device_snapshot);
} }
}
// Then we store the DeviceManager state. // Then we store the DeviceManager state.
snapshot.add_data_section(SnapshotDataSection { snapshot.add_data_section(SnapshotDataSection {
@@ -3212,10 +3214,10 @@ impl Snapshottable for DeviceManager {
} }
// Restore the node // Restore the node
if let Some(device) = self.migratable_devices.get(id) { if let Some(migratable) = &node.migratable {
debug!("Restoring {} from DeviceManager", id); debug!("Restoring {} from DeviceManager", id);
if let Some(snapshot) = snapshot.snapshots.get(id) { if let Some(snapshot) = snapshot.snapshots.get(id) {
device.lock().unwrap().restore(*snapshot.clone())?; migratable.lock().unwrap().restore(*snapshot.clone())?;
} else { } else {
return Err(MigratableError::Restore(anyhow!("Missing device {}", id))); return Err(MigratableError::Restore(anyhow!("Missing device {}", id)));
} }
@@ -3223,10 +3225,11 @@ impl Snapshottable for DeviceManager {
// Restore the parent if it exists // Restore the parent if it exists
if let Some(parent) = &node.parent { if let Some(parent) = &node.parent {
if let Some(device) = self.migratable_devices.get(parent) { if let Some(node) = self.device_tree.get(parent) {
if let Some(migratable) = &node.migratable {
debug!("Restoring {} from DeviceManager", parent); debug!("Restoring {} from DeviceManager", parent);
if let Some(snapshot) = snapshot.snapshots.get(parent) { if let Some(snapshot) = snapshot.snapshots.get(parent) {
device.lock().unwrap().restore(*snapshot.clone())?; migratable.lock().unwrap().restore(*snapshot.clone())?;
} else { } else {
return Err(MigratableError::Restore(anyhow!( return Err(MigratableError::Restore(anyhow!(
"Missing parent device {}", "Missing parent device {}",
@@ -3236,6 +3239,7 @@ impl Snapshottable for DeviceManager {
} }
} }
} }
}
Ok(()) Ok(())
} }