virtio-balloon: Store the balloon size to support reboot

This commit store balloon size to MemoryConfig.
After reboot, virtio-balloon can use this size to inflate back to
the size before reboot.

Signed-off-by: Hui Zhu <teawater@antfin.com>
This commit is contained in:
Hui Zhu
2020-06-23 17:52:30 +08:00
committed by Rob Bradford
parent 50da100afd
commit 800220acbb
6 changed files with 24 additions and 12 deletions

View File

@@ -799,13 +799,12 @@ impl MemoryManager {
Ok(())
}
pub fn balloon_resize(&mut self, expected_ram: u64) -> Result<(), Error> {
pub fn balloon_resize(&mut self, expected_ram: u64) -> Result<u64, Error> {
let mut balloon_size = 0;
if let Some(balloon) = &self.balloon {
let balloon_size = if expected_ram < self.current_ram {
self.current_ram - expected_ram
} else {
0
};
if expected_ram < self.current_ram {
balloon_size = self.current_ram - expected_ram;
}
balloon
.lock()
.unwrap()
@@ -813,7 +812,7 @@ impl MemoryManager {
.map_err(Error::VirtioBalloonResizeFail)?;
}
Ok(())
Ok(balloon_size)
}
/// In case this function resulted in adding a new memory region to the