diff --git a/vm-virtio/src/console.rs b/vm-virtio/src/console.rs index 708ac6818..1201663be 100755 --- a/vm-virtio/src/console.rs +++ b/vm-virtio/src/console.rs @@ -372,6 +372,7 @@ impl VirtioConsoleConfig { /// Virtio device for exposing console to the guest OS through virtio. pub struct Console { + id: String, kill_evt: Option, pause_evt: Option, avail_features: u64, @@ -396,6 +397,7 @@ pub struct ConsoleState { impl Console { /// Create a new virtio console device that gets random data from /dev/urandom. pub fn new( + id: String, out: Box, cols: u16, rows: u16, @@ -420,6 +422,7 @@ impl Console { Ok(( Console { + id, kill_evt: None, pause_evt: None, avail_features, @@ -618,19 +621,18 @@ impl VirtioDevice for Console { } virtio_pausable!(Console); -const CONSOLE_SNAPSHOT_ID: &str = "virtio-console"; impl Snapshottable for Console { fn id(&self) -> String { - CONSOLE_SNAPSHOT_ID.to_string() + self.id.clone() } fn snapshot(&self) -> std::result::Result { let snapshot = serde_json::to_vec(&self.state()).map_err(|e| MigratableError::Snapshot(e.into()))?; - let mut console_snapshot = Snapshot::new(CONSOLE_SNAPSHOT_ID); + let mut console_snapshot = Snapshot::new(self.id.as_str()); console_snapshot.add_data_section(SnapshotDataSection { - id: format!("{}-section", CONSOLE_SNAPSHOT_ID), + id: format!("{}-section", self.id), snapshot, }); @@ -638,10 +640,7 @@ impl Snapshottable for Console { } fn restore(&mut self, snapshot: Snapshot) -> std::result::Result<(), MigratableError> { - if let Some(console_section) = snapshot - .snapshot_data - .get(&format!("{}-section", CONSOLE_SNAPSHOT_ID)) - { + if let Some(console_section) = snapshot.snapshot_data.get(&format!("{}-section", self.id)) { let console_state = match serde_json::from_slice(&console_section.snapshot) { Ok(state) => state, Err(error) => { diff --git a/vmm/src/device_manager.rs b/vmm/src/device_manager.rs index 998e0dd19..06287b67a 100644 --- a/vmm/src/device_manager.rs +++ b/vmm/src/device_manager.rs @@ -1099,13 +1099,14 @@ impl DeviceManager { }; let (col, row) = get_win_size(); let console_input = if let Some(writer) = console_writer { + let id = String::from(CONSOLE_DEVICE_NAME); let (virtio_console_device, console_input) = - vm_virtio::Console::new(writer, col, row, console_config.iommu) + vm_virtio::Console::new(id.clone(), writer, col, row, console_config.iommu) .map_err(DeviceManagerError::CreateVirtioConsole)?; virtio_devices.push(( Arc::new(Mutex::new(virtio_console_device)) as VirtioDeviceArc, console_config.iommu, - Some(String::from(CONSOLE_DEVICE_NAME)), + Some(id), )); Some(console_input) } else {