@@ -18,14 +18,15 @@ use virtio_gen::virtio_blk::VIRTIO_F_VERSION_1;
18
18
use super :: super :: { ActivateResult , DeviceState , Queue , VirtioDevice , TYPE_BALLOON } ;
19
19
use super :: util:: { compact_page_frame_numbers, remove_range} ;
20
20
use 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 ,
27
28
} ;
28
- use crate :: devices:: virtio:: balloon:: Error as BalloonError ;
29
+ use crate :: devices:: virtio:: balloon:: BalloonError ;
29
30
use crate :: devices:: virtio:: { IrqTrigger , IrqType } ;
30
31
31
32
const SIZE_OF_U32 : usize = std:: mem:: size_of :: < u32 > ( ) ;
@@ -134,7 +135,7 @@ pub struct Balloon {
134
135
135
136
// Transport related fields.
136
137
pub ( crate ) queues : Vec < Queue > ,
137
- pub ( crate ) queue_evts : [ EventFd ; NUM_QUEUES ] ,
138
+ pub ( crate ) queue_evts : [ EventFd ; BALLOON_NUM_QUEUES ] ,
138
139
pub ( crate ) device_state : DeviceState ,
139
140
pub ( crate ) irq_trigger : IrqTrigger ,
140
141
@@ -173,7 +174,7 @@ impl Balloon {
173
174
EventFd :: new ( libc:: EFD_NONBLOCK ) . map_err ( BalloonError :: EventFd ) ?,
174
175
] ;
175
176
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 ( ) ;
177
178
178
179
// The VirtIO specification states that the statistics queue should
179
180
// not be present at all if the statistics are not enabled.
@@ -589,7 +590,7 @@ pub(crate) mod tests {
589
590
590
591
use utils:: vm_memory:: GuestAddress ;
591
592
592
- use super :: super :: CONFIG_SPACE_SIZE ;
593
+ use super :: super :: BALLOON_CONFIG_SPACE_SIZE ;
593
594
use super :: * ;
594
595
use crate :: check_metric_after_block;
595
596
use crate :: devices:: report_balloon_event_fail;
@@ -716,21 +717,24 @@ pub(crate) mod tests {
716
717
} ;
717
718
assert_eq ! ( balloon. config( ) , cfg) ;
718
719
719
- let mut actual_config_space = [ 0u8 ; CONFIG_SPACE_SIZE ] ;
720
+ let mut actual_config_space = [ 0u8 ; BALLOON_CONFIG_SPACE_SIZE ] ;
720
721
balloon. read_config ( 0 , & mut actual_config_space) ;
721
722
// The first 4 bytes are num_pages, the last 4 bytes are actual_pages.
722
723
// The config space is little endian.
723
724
// 0x10 MB in the constructor corresponds to 0x1000 pages in the
724
725
// config space.
725
- let expected_config_space: [ u8 ; CONFIG_SPACE_SIZE ] =
726
+ let expected_config_space: [ u8 ; BALLOON_CONFIG_SPACE_SIZE ] =
726
727
[ 0x00 , 0x10 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ] ;
727
728
assert_eq ! ( actual_config_space, expected_config_space) ;
728
729
729
730
// Invalid read.
730
- let expected_config_space: [ u8 ; CONFIG_SPACE_SIZE ] =
731
+ let expected_config_space: [ u8 ; BALLOON_CONFIG_SPACE_SIZE ] =
731
732
[ 0xd , 0xe , 0xa , 0xd , 0xb , 0xe , 0xe , 0xf ] ;
732
733
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
+ ) ;
734
738
735
739
// Validate read failed (the config space was not updated).
736
740
assert_eq ! ( actual_config_space, expected_config_space) ;
@@ -740,11 +744,11 @@ pub(crate) mod tests {
740
744
fn test_virtio_write_config ( ) {
741
745
let mut balloon = Balloon :: new ( 0 , true , 0 , false ) . unwrap ( ) ;
742
746
743
- let expected_config_space: [ u8 ; CONFIG_SPACE_SIZE ] =
747
+ let expected_config_space: [ u8 ; BALLOON_CONFIG_SPACE_SIZE ] =
744
748
[ 0x00 , 0x50 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ] ;
745
749
balloon. write_config ( 0 , & expected_config_space) ;
746
750
747
- let mut actual_config_space = [ 0u8 ; CONFIG_SPACE_SIZE ] ;
751
+ let mut actual_config_space = [ 0u8 ; BALLOON_CONFIG_SPACE_SIZE ] ;
748
752
balloon. read_config ( 0 , & mut actual_config_space) ;
749
753
assert_eq ! ( actual_config_space, expected_config_space) ;
750
754
@@ -1043,7 +1047,7 @@ pub(crate) mod tests {
1043
1047
assert_eq ! ( balloon. num_pages( ) , 0x100 ) ;
1044
1048
assert ! ( balloon. update_size( 16 ) . is_ok( ) ) ;
1045
1049
1046
- let mut actual_config = vec ! [ 0 ; CONFIG_SPACE_SIZE ] ;
1050
+ let mut actual_config = vec ! [ 0 ; BALLOON_CONFIG_SPACE_SIZE ] ;
1047
1051
balloon. read_config ( 0 , & mut actual_config) ;
1048
1052
assert_eq ! ( actual_config, vec![ 0x0 , 0x10 , 0x0 , 0x0 , 0x34 , 0x12 , 0 , 0 ] ) ;
1049
1053
assert_eq ! ( balloon. num_pages( ) , 0x1000 ) ;
0 commit comments