Skip to content

Commit f36767e

Browse files
Manciukicroypat
authored andcommitted
fix(balloon): improve error message in case of too much requested memory
The balloon device always returns "Amount of pages requested cannot fit in u32" even if it fails due to the guest memory check. Reword the error to make it more clear. Signed-off-by: Riccardo Mancini <[email protected]>
1 parent 3b10bf2 commit f36767e

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

src/vmm/src/devices/virtio/balloon/device.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,9 @@ const SIZE_OF_STAT: usize = std::mem::size_of::<BalloonStat>();
4141
fn mib_to_pages(amount_mib: u32) -> Result<u32, BalloonError> {
4242
amount_mib
4343
.checked_mul(MIB_TO_4K_PAGES)
44-
.ok_or(BalloonError::TooManyPagesRequested)
44+
.ok_or(BalloonError::TooMuchMemoryRequested(
45+
u32::MAX / MIB_TO_4K_PAGES,
46+
))
4547
}
4648

4749
fn pages_to_mib(amount_pages: u32) -> u32 {
@@ -455,7 +457,7 @@ impl Balloon {
455457
// The balloon cannot have a target size greater than the size of
456458
// the guest memory.
457459
if u64::from(amount_mib) > mem_size_mib(mem) {
458-
return Err(BalloonError::TooManyPagesRequested);
460+
return Err(BalloonError::TooMuchMemoryRequested(amount_mib));
459461
}
460462
self.config_space.num_pages = mib_to_pages(amount_mib)?;
461463
self.interrupt_trigger()

src/vmm/src/devices/virtio/balloon/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,8 @@ pub enum BalloonError {
8383
StatisticsDisabled,
8484
/// Statistics cannot be enabled/disabled after activation.
8585
StatisticsStateChange,
86-
/// Amount of pages requested cannot fit in `u32`.
87-
TooManyPagesRequested,
86+
/// Requested memory should be less than {0}MiB
87+
TooMuchMemoryRequested(u32),
8888
/// Error while processing the virt queues: {0}
8989
Queue(#[from] QueueError),
9090
/// {0}

0 commit comments

Comments
 (0)