mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2024-11-04 19:11:11 +00:00
vmm: config: Validate balloon size is less than RAM size
Signed-off-by: Rob Bradford <robert.bradford@intel.com>
This commit is contained in:
parent
e864e35c29
commit
26d1a76ad9
@ -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)?;
|
||||
|
Loading…
Reference in New Issue
Block a user