Skip to content

Commit 8ab6410

Browse files
committed
feat(balloon): add logging for malformed balloon-stats tag
Added warn logging to the decode of BalloonStats if unknown tag is introduced. Additionally, updated integration test of BalloonStats to fail if this warn occurs. Signed-off-by: Aaron Lo <[email protected]>
1 parent d130c7d commit 8ab6410

File tree

2 files changed

+28
-26
lines changed

2 files changed

+28
-26
lines changed

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

Lines changed: 22 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use std::ops::Deref;
55
use std::sync::Arc;
66
use std::time::Duration;
77

8-
use log::{error, info, warn};
8+
use log::{debug, error, info, warn};
99
use serde::{Deserialize, Serialize};
1010
use utils::time::TimerFd;
1111
use vmm_sys_util::eventfd::EventFd;
@@ -207,7 +207,7 @@ pub struct BalloonStats {
207207
}
208208

209209
impl BalloonStats {
210-
fn update_with_stat(&mut self, stat: &BalloonStat) -> Result<(), BalloonError> {
210+
fn update_with_stat(&mut self, stat: &BalloonStat) {
211211
let val = Some(stat.val);
212212
match stat.tag {
213213
VIRTIO_BALLOON_S_SWAP_IN => self.swap_in = val,
@@ -226,12 +226,11 @@ impl BalloonStats {
226226
VIRTIO_BALLOON_S_DIRECT_SCAN => self.direct_scan = val,
227227
VIRTIO_BALLOON_S_ASYNC_RECLAIM => self.async_reclaim = val,
228228
VIRTIO_BALLOON_S_DIRECT_RECLAIM => self.direct_reclaim = val,
229-
_ => {
230-
return Err(BalloonError::MalformedPayload);
229+
tag => {
230+
METRICS.stats_update_fails.inc();
231+
debug!("balloon: unknown stats update tag: {tag}");
231232
}
232233
}
233-
234-
Ok(())
235234
}
236235
}
237236

@@ -503,10 +502,7 @@ impl Balloon {
503502
let stat = mem
504503
.read_obj::<BalloonStat>(addr)
505504
.map_err(|_| BalloonError::MalformedDescriptor)?;
506-
self.latest_stats.update_with_stat(&stat).map_err(|_| {
507-
METRICS.stats_update_fails.inc();
508-
BalloonError::MalformedPayload
509-
})?;
505+
self.latest_stats.update_with_stat(&stat);
510506
}
511507

512508
self.stats_desc_index = Some(head.index);
@@ -1067,52 +1063,52 @@ pub(crate) mod tests {
10671063
val: 1,
10681064
};
10691065

1070-
stats.update_with_stat(&stat).unwrap();
1066+
stats.update_with_stat(&stat);
10711067
assert_eq!(stats.swap_in, Some(1));
10721068
stat.tag = VIRTIO_BALLOON_S_SWAP_OUT;
1073-
stats.update_with_stat(&stat).unwrap();
1069+
stats.update_with_stat(&stat);
10741070
assert_eq!(stats.swap_out, Some(1));
10751071
stat.tag = VIRTIO_BALLOON_S_MAJFLT;
1076-
stats.update_with_stat(&stat).unwrap();
1072+
stats.update_with_stat(&stat);
10771073
assert_eq!(stats.major_faults, Some(1));
10781074
stat.tag = VIRTIO_BALLOON_S_MINFLT;
1079-
stats.update_with_stat(&stat).unwrap();
1075+
stats.update_with_stat(&stat);
10801076
assert_eq!(stats.minor_faults, Some(1));
10811077
stat.tag = VIRTIO_BALLOON_S_MEMFREE;
1082-
stats.update_with_stat(&stat).unwrap();
1078+
stats.update_with_stat(&stat);
10831079
assert_eq!(stats.free_memory, Some(1));
10841080
stat.tag = VIRTIO_BALLOON_S_MEMTOT;
1085-
stats.update_with_stat(&stat).unwrap();
1081+
stats.update_with_stat(&stat);
10861082
assert_eq!(stats.total_memory, Some(1));
10871083
stat.tag = VIRTIO_BALLOON_S_AVAIL;
1088-
stats.update_with_stat(&stat).unwrap();
1084+
stats.update_with_stat(&stat);
10891085
assert_eq!(stats.available_memory, Some(1));
10901086
stat.tag = VIRTIO_BALLOON_S_CACHES;
1091-
stats.update_with_stat(&stat).unwrap();
1087+
stats.update_with_stat(&stat);
10921088
assert_eq!(stats.disk_caches, Some(1));
10931089
stat.tag = VIRTIO_BALLOON_S_HTLB_PGALLOC;
1094-
stats.update_with_stat(&stat).unwrap();
1090+
stats.update_with_stat(&stat);
10951091
assert_eq!(stats.hugetlb_allocations, Some(1));
10961092
stat.tag = VIRTIO_BALLOON_S_HTLB_PGFAIL;
1097-
stats.update_with_stat(&stat).unwrap();
1093+
stats.update_with_stat(&stat);
10981094
assert_eq!(stats.hugetlb_failures, Some(1));
10991095
stat.tag = VIRTIO_BALLOON_S_OOM_KILL;
1100-
stats.update_with_stat(&stat).unwrap();
1096+
stats.update_with_stat(&stat);
11011097
assert_eq!(stats.oom_kill, Some(1));
11021098
stat.tag = VIRTIO_BALLOON_S_ALLOC_STALL;
1103-
stats.update_with_stat(&stat).unwrap();
1099+
stats.update_with_stat(&stat);
11041100
assert_eq!(stats.alloc_stall, Some(1));
11051101
stat.tag = VIRTIO_BALLOON_S_ASYNC_SCAN;
1106-
stats.update_with_stat(&stat).unwrap();
1102+
stats.update_with_stat(&stat);
11071103
assert_eq!(stats.async_scan, Some(1));
11081104
stat.tag = VIRTIO_BALLOON_S_DIRECT_SCAN;
1109-
stats.update_with_stat(&stat).unwrap();
1105+
stats.update_with_stat(&stat);
11101106
assert_eq!(stats.direct_scan, Some(1));
11111107
stat.tag = VIRTIO_BALLOON_S_ASYNC_RECLAIM;
1112-
stats.update_with_stat(&stat).unwrap();
1108+
stats.update_with_stat(&stat);
11131109
assert_eq!(stats.async_reclaim, Some(1));
11141110
stat.tag = VIRTIO_BALLOON_S_DIRECT_RECLAIM;
1115-
stats.update_with_stat(&stat).unwrap();
1111+
stats.update_with_stat(&stat);
11161112
assert_eq!(stats.direct_reclaim, Some(1));
11171113
}
11181114

tests/integration_tests/functional/test_balloon.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,9 @@ def test_stats(uvm_plain_any):
320320
# Get another reading of the stats after the polling interval has passed.
321321
deflated_stats = test_microvm.api.balloon_stats.get().json()
322322

323+
# Ensure that stats don't have unknown balloon stats fields
324+
assert "balloon: unknown stats update tag:" not in test_microvm.log_data
325+
323326
# Ensure the stats reflect deflating the balloon.
324327
assert inflated_stats["free_memory"] < deflated_stats["free_memory"]
325328
assert inflated_stats["available_memory"] < deflated_stats["available_memory"]
@@ -372,6 +375,9 @@ def test_stats_update(uvm_plain_any):
372375
final_stats = test_microvm.api.balloon_stats.get().json()
373376
assert next_stats["available_memory"] != final_stats["available_memory"]
374377

378+
# Ensure that stats don't have unknown balloon stats fields
379+
assert "balloon: unknown stats update tag:" not in test_microvm.log_data
380+
375381

376382
def test_balloon_snapshot(uvm_plain_any, microvm_factory):
377383
"""

0 commit comments

Comments
 (0)