mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2024-12-22 13:45:20 +00:00
vm-virtio: mem: Expect an identifier upon device creation
This identifier is chosen from the DeviceManager so that it will manage all identifiers across the VM, which will ensure uniqueness. Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com>
This commit is contained in:
parent
1592a9292f
commit
9b53044aae
@ -738,6 +738,7 @@ impl MemEpollHandler {
|
||||
|
||||
// Virtio device for exposing entropy to the guest OS through virtio.
|
||||
pub struct Mem {
|
||||
id: String,
|
||||
resize: Resize,
|
||||
kill_evt: Option<EventFd>,
|
||||
pause_evt: Option<EventFd>,
|
||||
@ -754,7 +755,7 @@ pub struct Mem {
|
||||
|
||||
impl Mem {
|
||||
// Create a new virtio-mem device.
|
||||
pub fn new(region: &Arc<GuestRegionMmap>, resize: Resize) -> io::Result<Mem> {
|
||||
pub fn new(id: String, region: &Arc<GuestRegionMmap>, resize: Resize) -> io::Result<Mem> {
|
||||
let region_len = region.len();
|
||||
|
||||
if region_len != region_len / VIRTIO_MEM_DEFAULT_BLOCK_SIZE * VIRTIO_MEM_DEFAULT_BLOCK_SIZE
|
||||
@ -787,6 +788,7 @@ impl Mem {
|
||||
};
|
||||
|
||||
Ok(Mem {
|
||||
id,
|
||||
resize,
|
||||
kill_evt: None,
|
||||
pause_evt: None,
|
||||
@ -955,6 +957,10 @@ impl VirtioDevice for Mem {
|
||||
}
|
||||
|
||||
virtio_pausable!(Mem);
|
||||
impl Snapshottable for Mem {}
|
||||
impl Snapshottable for Mem {
|
||||
fn id(&self) -> String {
|
||||
self.id.clone()
|
||||
}
|
||||
}
|
||||
impl Transportable for Mem {}
|
||||
impl Migratable for Mem {}
|
||||
|
@ -1737,10 +1737,14 @@ impl DeviceManager {
|
||||
) -> DeviceManagerResult<Vec<(VirtioDeviceArc, bool, Option<String>)>> {
|
||||
let mut devices = Vec::new();
|
||||
|
||||
let mm = &self.memory_manager.lock().unwrap();
|
||||
let mm = self.memory_manager.clone();
|
||||
let mm = mm.lock().unwrap();
|
||||
if let (Some(region), Some(resize)) = (&mm.virtiomem_region, &mm.virtiomem_resize) {
|
||||
let id = String::from(MEM_DEVICE_NAME);
|
||||
|
||||
let virtio_mem_device = Arc::new(Mutex::new(
|
||||
vm_virtio::Mem::new(
|
||||
id.clone(),
|
||||
®ion,
|
||||
resize
|
||||
.try_clone()
|
||||
@ -1752,12 +1756,10 @@ impl DeviceManager {
|
||||
devices.push((
|
||||
Arc::clone(&virtio_mem_device) as VirtioDeviceArc,
|
||||
false,
|
||||
Some(String::from(MEM_DEVICE_NAME)),
|
||||
Some(id),
|
||||
));
|
||||
|
||||
let migratable = Arc::clone(&virtio_mem_device) as Arc<Mutex<dyn Migratable>>;
|
||||
let id = migratable.lock().unwrap().id();
|
||||
self.migratable_devices.push((id, migratable));
|
||||
self.add_migratable_device(Arc::clone(&virtio_mem_device) as Arc<Mutex<dyn Migratable>>);
|
||||
}
|
||||
|
||||
Ok(devices)
|
||||
|
Loading…
Reference in New Issue
Block a user