vmm: Update memory configuration upon virtio-mem resizing

Based on all the preparatory work achieved through previous commits,
this patch updates the 'hotplugged_size' field for both MemoryConfig and
MemoryZoneConfig structures when either the whole memory is resized, or
simply when a memory zone is resized.

This fixes the lack of support for rebooting a VM with the right amount
of memory plugged in.

Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com>
This commit is contained in:
Sebastien Boeuf
2020-09-14 23:50:30 +02:00
parent de2b917f55
commit 1e1a50ef70
2 changed files with 52 additions and 34 deletions

View File

@@ -664,8 +664,8 @@ impl MemoryManager {
mergeable: config.mergeable,
allocator: allocator.clone(),
hotplug_method: config.hotplug_method.clone(),
boot_ram: config.size,
current_ram: config.size,
boot_ram: ram_size,
current_ram: ram_size,
next_hotplug_slot: 0,
snapshot: Mutex::new(None),
shared: config.shared,
@@ -1268,12 +1268,7 @@ impl MemoryManager {
Ok(region)
}
pub fn resize_zone(
&mut self,
id: &str,
desired_ram: u64,
config: &MemoryConfig,
) -> Result<(), Error> {
pub fn resize_zone(&mut self, id: &str, virtio_mem_size: u64) -> Result<(), Error> {
if !self.user_provided_zones {
error!(
"Not allowed to resize guest memory zone when no zone is \
@@ -1282,25 +1277,7 @@ impl MemoryManager {
return Err(Error::ResizeZone);
}
if let Some(zones) = &config.zones {
for zone in zones.iter() {
if zone.id == id {
if desired_ram >= zone.size {
return self.virtio_mem_resize(id, desired_ram - zone.size);
} else {
error!(
"Invalid to ask less ({}) than boot RAM ({}) for \
this memory zone",
desired_ram, zone.size,
);
return Err(Error::ResizeZone);
}
}
}
}
error!("Could not find the memory zone {} for the resize", id);
Err(Error::ResizeZone)
self.virtio_mem_resize(id, virtio_mem_size)
}
#[cfg(target_arch = "x86_64")]