@@ -18,14 +18,15 @@ use virtio_gen::virtio_blk::VIRTIO_F_VERSION_1;
1818use super :: super :: { ActivateResult , DeviceState , Queue , VirtioDevice , TYPE_BALLOON } ;
1919use super :: util:: { compact_page_frame_numbers, remove_range} ;
2020use super :: {
21- BALLOON_DEV_ID , DEFLATE_INDEX , INFLATE_INDEX , MAX_PAGES_IN_DESC , MAX_PAGE_COMPACT_BUFFER ,
22- MIB_TO_4K_PAGES , NUM_QUEUES , QUEUE_SIZES , STATS_INDEX , VIRTIO_BALLOON_F_DEFLATE_ON_OOM ,
23- VIRTIO_BALLOON_F_STATS_VQ , VIRTIO_BALLOON_PFN_SHIFT , VIRTIO_BALLOON_S_AVAIL ,
24- VIRTIO_BALLOON_S_CACHES , VIRTIO_BALLOON_S_HTLB_PGALLOC , VIRTIO_BALLOON_S_HTLB_PGFAIL ,
25- VIRTIO_BALLOON_S_MAJFLT , VIRTIO_BALLOON_S_MEMFREE , VIRTIO_BALLOON_S_MEMTOT ,
26- VIRTIO_BALLOON_S_MINFLT , VIRTIO_BALLOON_S_SWAP_IN , VIRTIO_BALLOON_S_SWAP_OUT ,
21+ BALLOON_DEV_ID , BALLOON_NUM_QUEUES , BALLOON_QUEUE_SIZES , DEFLATE_INDEX , INFLATE_INDEX ,
22+ MAX_PAGES_IN_DESC , MAX_PAGE_COMPACT_BUFFER , MIB_TO_4K_PAGES , STATS_INDEX ,
23+ VIRTIO_BALLOON_F_DEFLATE_ON_OOM , VIRTIO_BALLOON_F_STATS_VQ , VIRTIO_BALLOON_PFN_SHIFT ,
24+ VIRTIO_BALLOON_S_AVAIL , VIRTIO_BALLOON_S_CACHES , VIRTIO_BALLOON_S_HTLB_PGALLOC ,
25+ VIRTIO_BALLOON_S_HTLB_PGFAIL , VIRTIO_BALLOON_S_MAJFLT , VIRTIO_BALLOON_S_MEMFREE ,
26+ VIRTIO_BALLOON_S_MEMTOT , VIRTIO_BALLOON_S_MINFLT , VIRTIO_BALLOON_S_SWAP_IN ,
27+ VIRTIO_BALLOON_S_SWAP_OUT ,
2728} ;
28- use crate :: devices:: virtio:: balloon:: Error as BalloonError ;
29+ use crate :: devices:: virtio:: balloon:: BalloonError ;
2930use crate :: devices:: virtio:: { IrqTrigger , IrqType } ;
3031
3132const SIZE_OF_U32 : usize = std:: mem:: size_of :: < u32 > ( ) ;
@@ -134,7 +135,7 @@ pub struct Balloon {
134135
135136 // Transport related fields.
136137 pub ( crate ) queues : Vec < Queue > ,
137- pub ( crate ) queue_evts : [ EventFd ; NUM_QUEUES ] ,
138+ pub ( crate ) queue_evts : [ EventFd ; BALLOON_NUM_QUEUES ] ,
138139 pub ( crate ) device_state : DeviceState ,
139140 pub ( crate ) irq_trigger : IrqTrigger ,
140141
@@ -173,7 +174,7 @@ impl Balloon {
173174 EventFd :: new ( libc:: EFD_NONBLOCK ) . map_err ( BalloonError :: EventFd ) ?,
174175 ] ;
175176
176- let mut queues: Vec < Queue > = QUEUE_SIZES . iter ( ) . map ( |& s| Queue :: new ( s) ) . collect ( ) ;
177+ let mut queues: Vec < Queue > = BALLOON_QUEUE_SIZES . iter ( ) . map ( |& s| Queue :: new ( s) ) . collect ( ) ;
177178
178179 // The VirtIO specification states that the statistics queue should
179180 // not be present at all if the statistics are not enabled.
@@ -589,7 +590,7 @@ pub(crate) mod tests {
589590
590591 use utils:: vm_memory:: GuestAddress ;
591592
592- use super :: super :: CONFIG_SPACE_SIZE ;
593+ use super :: super :: BALLOON_CONFIG_SPACE_SIZE ;
593594 use super :: * ;
594595 use crate :: check_metric_after_block;
595596 use crate :: devices:: report_balloon_event_fail;
@@ -716,21 +717,24 @@ pub(crate) mod tests {
716717 } ;
717718 assert_eq ! ( balloon. config( ) , cfg) ;
718719
719- let mut actual_config_space = [ 0u8 ; CONFIG_SPACE_SIZE ] ;
720+ let mut actual_config_space = [ 0u8 ; BALLOON_CONFIG_SPACE_SIZE ] ;
720721 balloon. read_config ( 0 , & mut actual_config_space) ;
721722 // The first 4 bytes are num_pages, the last 4 bytes are actual_pages.
722723 // The config space is little endian.
723724 // 0x10 MB in the constructor corresponds to 0x1000 pages in the
724725 // config space.
725- let expected_config_space: [ u8 ; CONFIG_SPACE_SIZE ] =
726+ let expected_config_space: [ u8 ; BALLOON_CONFIG_SPACE_SIZE ] =
726727 [ 0x00 , 0x10 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ] ;
727728 assert_eq ! ( actual_config_space, expected_config_space) ;
728729
729730 // Invalid read.
730- let expected_config_space: [ u8 ; CONFIG_SPACE_SIZE ] =
731+ let expected_config_space: [ u8 ; BALLOON_CONFIG_SPACE_SIZE ] =
731732 [ 0xd , 0xe , 0xa , 0xd , 0xb , 0xe , 0xe , 0xf ] ;
732733 actual_config_space = expected_config_space;
733- balloon. read_config ( CONFIG_SPACE_SIZE as u64 + 1 , & mut actual_config_space) ;
734+ balloon. read_config (
735+ BALLOON_CONFIG_SPACE_SIZE as u64 + 1 ,
736+ & mut actual_config_space,
737+ ) ;
734738
735739 // Validate read failed (the config space was not updated).
736740 assert_eq ! ( actual_config_space, expected_config_space) ;
@@ -740,11 +744,11 @@ pub(crate) mod tests {
740744 fn test_virtio_write_config ( ) {
741745 let mut balloon = Balloon :: new ( 0 , true , 0 , false ) . unwrap ( ) ;
742746
743- let expected_config_space: [ u8 ; CONFIG_SPACE_SIZE ] =
747+ let expected_config_space: [ u8 ; BALLOON_CONFIG_SPACE_SIZE ] =
744748 [ 0x00 , 0x50 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ] ;
745749 balloon. write_config ( 0 , & expected_config_space) ;
746750
747- let mut actual_config_space = [ 0u8 ; CONFIG_SPACE_SIZE ] ;
751+ let mut actual_config_space = [ 0u8 ; BALLOON_CONFIG_SPACE_SIZE ] ;
748752 balloon. read_config ( 0 , & mut actual_config_space) ;
749753 assert_eq ! ( actual_config_space, expected_config_space) ;
750754
@@ -1043,7 +1047,7 @@ pub(crate) mod tests {
10431047 assert_eq ! ( balloon. num_pages( ) , 0x100 ) ;
10441048 assert ! ( balloon. update_size( 16 ) . is_ok( ) ) ;
10451049
1046- let mut actual_config = vec ! [ 0 ; CONFIG_SPACE_SIZE ] ;
1050+ let mut actual_config = vec ! [ 0 ; BALLOON_CONFIG_SPACE_SIZE ] ;
10471051 balloon. read_config ( 0 , & mut actual_config) ;
10481052 assert_eq ! ( actual_config, vec![ 0x0 , 0x10 , 0x0 , 0x0 , 0x34 , 0x12 , 0 , 0 ] ) ;
10491053 assert_eq ! ( balloon. num_pages( ) , 0x1000 ) ;
0 commit comments