vmm: Update memory through DeviceManager

Whenever the VM memory is resized, DeviceManager needs to be notified
so that it can subsequently notify each virtio devices about it.

Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com>
This commit is contained in:
Sebastien Boeuf 2020-03-23 12:10:26 +01:00 committed by Rob Bradford
parent bc874a9b6f
commit e54f8ec8a5
2 changed files with 24 additions and 4 deletions

View File

@ -53,9 +53,7 @@ use vm_device::interrupt::{
}; };
use vm_device::{Migratable, MigratableError, Pausable, Snapshotable}; use vm_device::{Migratable, MigratableError, Pausable, Snapshotable};
use vm_memory::guest_memory::FileOffset; use vm_memory::guest_memory::FileOffset;
#[cfg(feature = "cmos")] use vm_memory::{Address, GuestAddress, GuestAddressSpace, GuestUsize, MmapRegion};
use vm_memory::GuestAddressSpace;
use vm_memory::{Address, GuestAddress, GuestUsize, MmapRegion};
#[cfg(feature = "pci_support")] #[cfg(feature = "pci_support")]
use vm_virtio::transport::VirtioPciDevice; use vm_virtio::transport::VirtioPciDevice;
use vm_virtio::transport::VirtioTransport; use vm_virtio::transport::VirtioTransport;
@ -256,8 +254,11 @@ pub enum DeviceManagerError {
/// Incorrect device ID as it is already used by another device. /// Incorrect device ID as it is already used by another device.
DeviceIdAlreadyInUse, DeviceIdAlreadyInUse,
// No disk path was specified when one was expected /// No disk path was specified when one was expected
NoDiskPath, NoDiskPath,
/// Failed updating guest memory for virtio device.
UpdateMemoryForVirtioDevice(vm_virtio::Error),
} }
pub type DeviceManagerResult<T> = result::Result<T, DeviceManagerError>; pub type DeviceManagerResult<T> = result::Result<T, DeviceManagerError>;
@ -1812,6 +1813,19 @@ impl DeviceManager {
self.cmdline_additions.as_slice() self.cmdline_additions.as_slice()
} }
pub fn update_memory(&self) -> DeviceManagerResult<()> {
let memory = self.memory_manager.lock().unwrap().guest_memory();
for (virtio_device, _) in self.virtio_devices.iter() {
virtio_device
.lock()
.unwrap()
.update_memory(&memory.memory())
.map_err(DeviceManagerError::UpdateMemoryForVirtioDevice)?;
}
Ok(())
}
pub fn notify_hotplug( pub fn notify_hotplug(
&self, &self,
_notification_type: HotPlugNotificationFlags, _notification_type: HotPlugNotificationFlags,

View File

@ -553,6 +553,12 @@ impl Vm {
.resize(desired_memory) .resize(desired_memory)
.map_err(Error::MemoryManager)? .map_err(Error::MemoryManager)?
{ {
self.device_manager
.lock()
.unwrap()
.update_memory()
.map_err(Error::DeviceManager)?;
self.device_manager self.device_manager
.lock() .lock()
.unwrap() .unwrap()