@@ -5,7 +5,6 @@ use std::ops::Deref;
55use std:: sync:: Arc ;
66use std:: time:: Duration ;
77
8- use log:: { debug, error, info, warn} ;
98use serde:: { Deserialize , Serialize } ;
109use utils:: time:: TimerFd ;
1110use vmm_sys_util:: eventfd:: EventFd ;
@@ -32,7 +31,10 @@ use crate::devices::virtio::device::{ActiveState, VirtioDeviceType};
3231use crate :: devices:: virtio:: generated:: virtio_config:: VIRTIO_F_VERSION_1 ;
3332use crate :: devices:: virtio:: queue:: InvalidAvailIdx ;
3433use crate :: devices:: virtio:: transport:: { VirtioInterrupt , VirtioInterruptType } ;
35- use crate :: logger:: { IncMetric , log_dev_preview_warning} ;
34+ use crate :: logger:: {
35+ IncMetric , debug, error_rate_limited, info_rate_limited, log_dev_preview_warning,
36+ warn_rate_limited,
37+ } ;
3638use crate :: utils:: u64_to_usize;
3739use crate :: vstate:: memory:: {
3840 Address , ByteValued , Bytes , GuestAddress , GuestMemoryExtension , GuestMemoryMmap ,
@@ -404,7 +406,7 @@ impl Balloon {
404406 if !head. is_write_only ( ) && len. is_multiple_of ( SIZE_OF_U32 ) {
405407 // Check descriptor pfn count.
406408 if len > max_len {
407- error ! (
409+ error_rate_limited ! (
408410 "Inflate descriptor has bogus page count {} > {}, skipping." ,
409411 len / SIZE_OF_U32 ,
410412 MAX_PAGES_IN_DESC
@@ -455,7 +457,7 @@ impl Balloon {
455457 guest_addr,
456458 usize:: try_from ( range_len) . unwrap ( ) << VIRTIO_BALLOON_PFN_SHIFT ,
457459 ) {
458- error ! ( "Error removing memory range: {:?}" , err) ;
460+ error_rate_limited ! ( "Error removing memory range: {:?}" , err) ;
459461 }
460462 }
461463 }
@@ -496,7 +498,9 @@ impl Balloon {
496498 if let Some ( prev_stats_desc) = self . stats_desc_index {
497499 // We shouldn't ever have an extra buffer if the driver follows
498500 // the protocol, but return it if we find one.
499- error ! ( "balloon: driver is not compliant, more than one stats buffer received" ) ;
501+ error_rate_limited ! (
502+ "balloon: driver is not compliant, more than one stats buffer received"
503+ ) ;
500504 self . queues [ STATS_INDEX ] . add_used ( prev_stats_desc, 0 ) ?;
501505 self . queues [ STATS_INDEX ] . advance_used_ring_idx ( ) ;
502506 self . signal_used_queue ( STATS_INDEX ) ?;
@@ -508,9 +512,10 @@ impl Balloon {
508512 // so that the stats request/response protocol is preserved and
509513 // trigger_stats_update can return it to the guest later.
510514 if head. len > MAX_STATS_DESC_LEN {
511- warn ! (
515+ warn_rate_limited ! (
512516 "balloon: stats descriptor too large: {} > {}, skipping" ,
513- head. len, MAX_STATS_DESC_LEN
517+ head. len,
518+ MAX_STATS_DESC_LEN
514519 ) ;
515520 self . stats_desc_index = Some ( head. index ) ;
516521 continue ;
@@ -571,7 +576,7 @@ impl Balloon {
571576
572577 // We don't expect this from the driver, but lets treat as a stop
573578 if cmd == FREE_PAGE_HINT_DONE {
574- warn ! ( "balloon hinting: Unexpected cmd from guest: {cmd}" ) ;
579+ warn_rate_limited ! ( "balloon hinting: Unexpected cmd from guest: {cmd}" ) ;
575580 complete = true ;
576581 }
577582
@@ -584,19 +589,21 @@ impl Balloon {
584589 }
585590
586591 let Some ( chain_cmd) = self . hinting_state . guest_cmd else {
587- warn ! ( "balloon hinting: received range with no command id." ) ;
592+ warn_rate_limited ! ( "balloon hinting: received range with no command id." ) ;
588593 continue ;
589594 } ;
590595
591596 if chain_cmd != host_cmd {
592- info ! ( "balloon hinting: Received chain from previous command ignoring." ) ;
597+ info_rate_limited ! (
598+ "balloon hinting: Received chain from previous command ignoring."
599+ ) ;
593600 continue ;
594601 }
595602
596603 METRICS . free_page_hint_count . inc ( ) ;
597604 if let Err ( err) = mem. discard_range ( desc. addr , desc. len as usize ) {
598605 METRICS . free_page_hint_fails . inc ( ) ;
599- error ! ( "balloon hinting: failed to remove range: {err:?}" ) ;
606+ error_rate_limited ! ( "balloon hinting: failed to remove range: {err:?}" ) ;
600607 } else {
601608 METRICS . free_page_hint_freed . add ( desc. len as u64 ) ;
602609 }
@@ -638,7 +645,7 @@ impl Balloon {
638645 METRICS . free_page_report_count . inc ( ) ;
639646 if let Err ( err) = mem. discard_range ( desc. addr , desc. len as usize ) {
640647 METRICS . free_page_report_fails . inc ( ) ;
641- error ! ( "balloon: failed to remove range: {err:?}" ) ;
648+ error_rate_limited ! ( "balloon: failed to remove range: {err:?}" ) ;
642649 } else {
643650 METRICS . free_page_report_freed . add ( desc. len as u64 ) ;
644651 }
@@ -709,7 +716,7 @@ impl Balloon {
709716 self . queues [ STATS_INDEX ] . advance_used_ring_idx ( ) ;
710717 self . signal_used_queue ( STATS_INDEX )
711718 } else {
712- error ! ( "Failed to update balloon stats, missing descriptor." ) ;
719+ error_rate_limited ! ( "Failed to update balloon stats, missing descriptor." ) ;
713720 Ok ( ( ) )
714721 }
715722 }
@@ -933,7 +940,7 @@ impl VirtioDevice for Balloon {
933940 let len = config_space_bytes. len ( ) . min ( data. len ( ) ) ;
934941 data[ ..len] . copy_from_slice ( & config_space_bytes[ ..len] ) ;
935942 } else {
936- error ! ( "Failed to read config space" ) ;
943+ error_rate_limited ! ( "Failed to read config space" ) ;
937944 }
938945 }
939946
@@ -945,7 +952,7 @@ impl VirtioDevice for Balloon {
945952 . zip ( end)
946953 . and_then ( |( start, end) | config_space_bytes. get_mut ( start..end) )
947954 else {
948- error ! ( "Failed to write config space" ) ;
955+ error_rate_limited ! ( "Failed to write config space" ) ;
949956 return ;
950957 } ;
951958
@@ -983,7 +990,7 @@ impl VirtioDevice for Balloon {
983990 fn kick ( & mut self ) {
984991 if self . is_activated ( ) {
985992 if self . free_page_hinting ( ) {
986- info ! (
993+ info_rate_limited ! (
987994 "[{:?}:{}] resetting free page hinting to DONE" ,
988995 self . device_type( ) ,
989996 self . id( )
0 commit comments