diff --git a/vm-virtio/src/rng.rs b/vm-virtio/src/rng.rs index b449b15ac..21ab347ed 100755 --- a/vm-virtio/src/rng.rs +++ b/vm-virtio/src/rng.rs @@ -182,6 +182,7 @@ impl RngEpollHandler { /// Virtio device for exposing entropy to the guest OS through virtio. pub struct Rng { + id: String, kill_evt: Option, pause_evt: Option, random_file: Option, @@ -202,7 +203,7 @@ pub struct RngState { impl Rng { /// Create a new virtio rng device that gets random data from /dev/urandom. - pub fn new(path: &str, iommu: bool) -> io::Result { + pub fn new(id: String, path: &str, iommu: bool) -> io::Result { let random_file = File::open(path)?; let mut avail_features = 1u64 << VIRTIO_F_VERSION_1; @@ -211,6 +212,7 @@ impl Rng { } Ok(Rng { + id, kill_evt: None, pause_evt: None, random_file: Some(random_file), @@ -384,19 +386,18 @@ impl VirtioDevice for Rng { } virtio_pausable!(Rng); -const RNG_SNAPSHOT_ID: &str = "virtio-rng"; impl Snapshottable for Rng { fn id(&self) -> String { - RNG_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 rng_snapshot = Snapshot::new(RNG_SNAPSHOT_ID); + let mut rng_snapshot = Snapshot::new(self.id.as_str()); rng_snapshot.add_data_section(SnapshotDataSection { - id: format!("{}-section", RNG_SNAPSHOT_ID), + id: format!("{}-section", self.id), snapshot, }); @@ -404,10 +405,7 @@ impl Snapshottable for Rng { } fn restore(&mut self, snapshot: Snapshot) -> std::result::Result<(), MigratableError> { - if let Some(rng_section) = snapshot - .snapshot_data - .get(&format!("{}-section", RNG_SNAPSHOT_ID)) - { + if let Some(rng_section) = snapshot.snapshot_data.get(&format!("{}-section", self.id)) { let rng_state = match serde_json::from_slice(&rng_section.snapshot) { Ok(state) => state, Err(error) => { diff --git a/vmm/src/device_manager.rs b/vmm/src/device_manager.rs index 36443dd95..3d472543c 100644 --- a/vmm/src/device_manager.rs +++ b/vmm/src/device_manager.rs @@ -1437,7 +1437,7 @@ impl DeviceManager { let id = String::from(RNG_DEVICE_NAME); let virtio_rng_device = Arc::new(Mutex::new( - vm_virtio::Rng::new(rng_path, rng_config.iommu) + vm_virtio::Rng::new(id.clone(), rng_path, rng_config.iommu) .map_err(DeviceManagerError::CreateVirtioRng)?, )); devices.push((