virtio-balloon: Add memory_actual_size to vm.info to show memory actual size

The virtio-balloon change the memory size is asynchronous.
VirtioBalloonConfig.actual of balloon device show current balloon size.

This commit add memory_actual_size to vm.info to show memory actual size.

Signed-off-by: Hui Zhu <teawater@antfin.com>
This commit is contained in:
Hui Zhu
2020-08-25 14:44:21 +08:00
committed by Sebastien Boeuf
parent 9dffc5da5c
commit c75f8b2f89
8 changed files with 93 additions and 8 deletions

View File

@@ -176,6 +176,28 @@ pub trait VirtioDevice: Send {
.unwrap();
}
}
/// Helper to allow common implementation of write_config
fn write_config_helper(&self, config: &mut [u8], offset: u64, data: &[u8]) {
let config_len = config.len() as u64;
let data_len = data.len() as u64;
if offset + data_len > config_len {
error!(
"Out-of-bound access to configuration: config_len = {} offset = {:x} length = {} for {}",
config_len,
offset,
data_len,
self.device_type()
);
return;
}
if let Some(end) = offset.checked_add(config.len() as u64) {
let mut offset_config =
&mut config[offset as usize..std::cmp::min(end, config_len) as usize];
offset_config.write_all(data).unwrap();
}
}
}
/// Trait providing address translation the same way a physical DMA remapping