Skip to content

Commit fbd29ae

Browse files
committed
refactor: Cleanuo Balloon error
Add from #[from] annotation to avoid map_err() calls, and delete unused variants. Signed-off-by: Patrick Roy <roypat@amazon.co.uk>
1 parent 589160a commit fbd29ae

File tree

2 files changed

+5
-16
lines changed

2 files changed

+5
-16
lines changed

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

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ impl Balloon {
339339

340340
// Acknowledge the receipt of the descriptor.
341341
// 0 is number of bytes the device has written to memory.
342-
queue.add_used(head.index, 0).map_err(BalloonError::Queue)?;
342+
queue.add_used(head.index, 0)?;
343343
needs_interrupt = true;
344344
}
345345

@@ -376,7 +376,7 @@ impl Balloon {
376376
let mut needs_interrupt = false;
377377

378378
while let Some(head) = queue.pop() {
379-
queue.add_used(head.index, 0).map_err(BalloonError::Queue)?;
379+
queue.add_used(head.index, 0)?;
380380
needs_interrupt = true;
381381
}
382382

@@ -397,9 +397,7 @@ impl Balloon {
397397
// We shouldn't ever have an extra buffer if the driver follows
398398
// the protocol, but return it if we find one.
399399
error!("balloon: driver is not compliant, more than one stats buffer received");
400-
self.queues[STATS_INDEX]
401-
.add_used(prev_stats_desc, 0)
402-
.map_err(BalloonError::Queue)?;
400+
self.queues[STATS_INDEX].add_used(prev_stats_desc, 0)?;
403401
}
404402
for index in (0..head.len).step_by(SIZE_OF_STAT) {
405403
// Read the address at position `index`. The only case
@@ -447,9 +445,7 @@ impl Balloon {
447445
// The communication is driven by the device by using the buffer
448446
// and sending a used buffer notification
449447
if let Some(index) = self.stats_desc_index.take() {
450-
self.queues[STATS_INDEX]
451-
.add_used(index, 0)
452-
.map_err(BalloonError::Queue)?;
448+
self.queues[STATS_INDEX].add_used(index, 0)?;
453449
self.signal_used_queue()
454450
} else {
455451
error!("Failed to update balloon stats, missing descriptor.");

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

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ pub mod test_utils;
1111
mod util;
1212

1313
use log::error;
14-
use vm_memory::GuestMemoryError;
1514

1615
pub use self::device::{Balloon, BalloonConfig, BalloonStats};
1716
use super::queue::QueueError;
@@ -68,16 +67,12 @@ const VIRTIO_BALLOON_S_HTLB_PGFAIL: u16 = 9;
6867
/// Balloon device related errors.
6968
#[derive(Debug, thiserror::Error, displaydoc::Display)]
7069
pub enum BalloonError {
71-
/// Activation error: {0}
72-
Activate(super::ActivateError),
7370
/// No balloon device found.
7471
DeviceNotFound,
7572
/// Device not activated yet.
7673
DeviceNotActive,
7774
/// EventFd error: {0}
7875
EventFd(std::io::Error),
79-
/// Guest gave us bad memory addresses: {0}
80-
GuestMemory(GuestMemoryError),
8176
/// Received error while sending an interrupt: {0}
8277
InterruptError(std::io::Error),
8378
/// Guest gave us a malformed descriptor.
@@ -93,9 +88,7 @@ pub enum BalloonError {
9388
/// Amount of pages requested cannot fit in `u32`.
9489
TooManyPagesRequested,
9590
/// Error while processing the virt queues: {0}
96-
Queue(QueueError),
97-
/// Error removing a memory region at inflate time: {0}
98-
RemoveMemoryRegion(RemoveRegionError),
91+
Queue(#[from] QueueError),
9992
/// Error creating the statistics timer: {0}
10093
Timer(std::io::Error),
10194
}

0 commit comments

Comments
 (0)