vmm: config: Validate balloon size is less than RAM size

Signed-off-by: Rob Bradford <robert.bradford@intel.com>
This commit is contained in:
Rob Bradford 2022-02-09 11:14:49 +00:00
parent e864e35c29
commit 26d1a76ad9

View File

@ -155,6 +155,8 @@ pub enum ValidationError {
InvalidNumPciSegments(u16),
/// Invalid PCI segment id
InvalidPciSegment(u16),
/// Balloon too big
BalloonLargerThanRam(u64, u64),
}
type ValidationResult<T> = std::result::Result<T, ValidationError>;
@ -218,6 +220,13 @@ impl fmt::Display for ValidationError {
InvalidPciSegment(pci_segment) => {
write!(f, "Invalid PCI segment id{}", pci_segment)
}
BalloonLargerThanRam(balloon_size, ram_size) => {
write!(
f,
"Ballon size ({}) greater than RAM ({})",
balloon_size, ram_size
)
}
}
}
}
@ -2165,6 +2174,23 @@ impl VmConfig {
}
}
if let Some(balloon) = &self.balloon {
let mut ram_size = self.memory.size;
if let Some(zones) = &self.memory.zones {
for zone in zones {
ram_size += zone.size;
}
}
if balloon.size >= ram_size {
return Err(ValidationError::BalloonLargerThanRam(
balloon.size,
ram_size,
));
}
}
if let Some(devices) = &self.devices {
for device in devices {
device.validate(self)?;