vmm: Move devices creation to Vm creation

This moves the devices creation out of the dedicated restore function
which will be eventually removed.

This factorizes the creation of all devices into a single location.

Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com>
This commit is contained in:
Sebastien Boeuf 2022-12-01 10:32:56 +01:00
parent bccfa81368
commit 1c36065754
3 changed files with 29 additions and 19 deletions

View File

@ -5845,12 +5845,20 @@ mod common_parallel {
event: "starting".to_string(),
device_id: None,
},
&MetaEvent {
event: "activated".to_string(),
device_id: Some("__console".to_string()),
},
&MetaEvent {
event: "activated".to_string(),
device_id: Some("__rng".to_string()),
},
&MetaEvent {
event: "restoring".to_string(),
device_id: None,
},
];
assert!(check_sequential_events_exact(
assert!(check_sequential_events(
&expected_events,
&event_path_restored
));

View File

@ -1253,6 +1253,9 @@ impl Vmm {
activate_evt,
true,
timestamp,
None,
None,
None,
Some(&snapshot),
)
.map_err(|e| {

View File

@ -476,6 +476,9 @@ impl Vm {
activate_evt: EventFd,
restoring: bool,
timestamp: Instant,
serial_pty: Option<PtyPair>,
console_pty: Option<PtyPair>,
console_resize_pipe: Option<File>,
snapshot: Option<&Snapshot>,
) -> Result<Self> {
trace_scoped!("Vm::new_from_memory_manager");
@ -573,6 +576,12 @@ impl Vm {
)
.map_err(Error::DeviceManager)?;
device_manager
.lock()
.unwrap()
.create_devices(serial_pty, console_pty, console_resize_pipe)
.map_err(Error::DeviceManager)?;
// SAFETY: trivially safe
let on_tty = unsafe { libc::isatty(libc::STDIN_FILENO) } != 0;
@ -754,7 +763,7 @@ impl Vm {
)
.map_err(Error::MemoryManager)?;
let new_vm = Vm::new_from_memory_manager(
Vm::new_from_memory_manager(
config,
memory_manager,
vm,
@ -767,18 +776,11 @@ impl Vm {
activate_evt,
false,
timestamp,
serial_pty,
console_pty,
console_resize_pipe,
None,
)?;
// The device manager must create the devices from here as it is part
// of the regular code path creating everything from scratch.
new_vm
.device_manager
.lock()
.unwrap()
.create_devices(serial_pty, console_pty, console_resize_pipe)
.map_err(Error::DeviceManager)?;
Ok(new_vm)
)
}
#[allow(clippy::too_many_arguments)]
@ -834,6 +836,9 @@ impl Vm {
activate_evt,
true,
timestamp,
None,
None,
None,
Some(snapshot),
)
}
@ -2619,12 +2624,6 @@ impl Snapshottable for Vm {
MigratableError::Restore(anyhow!("Could not restore VM state: {:#?}", e))
})?;
self.device_manager
.lock()
.unwrap()
.create_devices(None, None, None)
.map_err(|e| MigratableError::Restore(anyhow!("Error restoring devices: {:#?}", e)))?;
#[cfg(target_arch = "aarch64")]
self.restore_vgic_and_enable_interrupt(&_snapshot)?;