Skip to content

Commit 26fd798

Browse files
Manciukicroypat
authored andcommitted
refactor(balloon): derive Copy for BalloonStats
As the caller of latest_stats() always clones the object, just derive Copy on it and return the copy rather than a reference. Signed-off-by: Riccardo Mancini <[email protected]>
1 parent f36767e commit 26fd798

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ pub struct BalloonConfig {
8484
}
8585

8686
/// BalloonStats holds statistics returned from the stats_queue.
87-
#[derive(Clone, Default, Debug, PartialEq, Eq, Serialize)]
87+
#[derive(Clone, Copy, Default, Debug, PartialEq, Eq, Serialize)]
8888
#[serde(deny_unknown_fields)]
8989
pub struct BalloonStats {
9090
/// The target size of the balloon, in 4K pages.
@@ -513,13 +513,13 @@ impl Balloon {
513513
}
514514

515515
/// Retrieve latest stats for the balloon device.
516-
pub fn latest_stats(&mut self) -> Result<&BalloonStats, BalloonError> {
516+
pub fn latest_stats(&mut self) -> Result<BalloonStats, BalloonError> {
517517
if self.stats_enabled() {
518518
self.latest_stats.target_pages = self.config_space.num_pages;
519519
self.latest_stats.actual_pages = self.config_space.actual_pages;
520520
self.latest_stats.target_mib = pages_to_mib(self.latest_stats.target_pages);
521521
self.latest_stats.actual_mib = pages_to_mib(self.latest_stats.actual_pages);
522-
Ok(&self.latest_stats)
522+
Ok(self.latest_stats)
523523
} else {
524524
Err(BalloonError::StatisticsDisabled)
525525
}
@@ -1082,7 +1082,7 @@ pub(crate) mod tests {
10821082
free_memory: Some(0x5678),
10831083
..BalloonStats::default()
10841084
};
1085-
assert_eq!(stats, &expected_stats);
1085+
assert_eq!(stats, expected_stats);
10861086

10871087
// Wait for the timer to expire, although as it is non-blocking
10881088
// we could just process the timer event and it would not

src/vmm/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -582,7 +582,7 @@ impl Vmm {
582582
.try_with_virtio_device_with_id(
583583
virtio_ids::VIRTIO_ID_BALLOON,
584584
BALLOON_DEV_ID,
585-
|dev: &mut Balloon| dev.latest_stats().cloned(),
585+
|dev: &mut Balloon| dev.latest_stats(),
586586
)
587587
.map_err(VmmError::FindDeviceError)
588588
}

0 commit comments

Comments
 (0)