File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -834,6 +834,10 @@ impl Mem {
834834 } )
835835 }
836836
837+ pub fn plugged_size ( & self ) -> u64 {
838+ self . config . lock ( ) . unwrap ( ) . plugged_size
839+ }
840+
837841 pub fn resize ( & mut self , size : u64 ) -> result:: Result < ( ) , Error > {
838842 let mut config = self . config . lock ( ) . unwrap ( ) ;
839843 config. resize ( size) . map_err ( |e| {
Original file line number Diff line number Diff line change @@ -1039,21 +1039,24 @@ impl MemoryConfig {
10391039 }
10401040
10411041 pub fn total_size ( & self ) -> u64 {
1042- let mut size = self . size ;
1043- if let Some ( hotplugged_size) = self . hotplugged_size {
1044- size += hotplugged_size;
1045- }
1046-
1047- if let Some ( zones) = & self . zones {
1048- for zone in zones. iter ( ) {
1049- size += zone. size ;
1050- if let Some ( hotplugged_size) = zone. hotplugged_size {
1051- size += hotplugged_size;
1052- }
1053- }
1054- }
1042+ self . size
1043+ + self
1044+ . zones
1045+ . iter ( )
1046+ . flatten ( )
1047+ . map ( |zone| zone. size )
1048+ . sum :: < u64 > ( )
1049+ + self . hotplugged_size ( )
1050+ }
10551051
1056- size
1052+ pub fn hotplugged_size ( & self ) -> u64 {
1053+ self . hotplugged_size . unwrap_or ( 0 )
1054+ + self
1055+ . zones
1056+ . iter ( )
1057+ . flatten ( )
1058+ . filter_map ( |zone| zone. hotplugged_size )
1059+ . sum :: < u64 > ( )
10571060 }
10581061}
10591062
Original file line number Diff line number Diff line change @@ -1915,9 +1915,11 @@ impl RequestHandler for Vmm {
19151915 } ;
19161916 let config = vm_config. lock ( ) . unwrap ( ) . clone ( ) ;
19171917
1918- let mut memory_actual_size = config. memory . total_size ( ) ;
1918+ let mut memory_actual_size =
1919+ config. memory . total_size ( ) - config. memory . hotplugged_size ( ) ;
19191920 if let Some ( vm) = & self . vm {
19201921 memory_actual_size = memory_actual_size. saturating_sub ( vm. balloon_size ( ) ) ;
1922+ memory_actual_size += vm. virtio_mem_plugged_size ( ) ;
19211923 }
19221924
19231925 let device_tree = self
Original file line number Diff line number Diff line change @@ -2420,6 +2420,19 @@ impl MemoryManager {
24202420 unsafe { ( * stat. as_ptr ( ) ) . st_nlink as usize > 0 }
24212421 }
24222422
2423+ pub fn virtio_mem_plugged_size ( & self ) -> u64 {
2424+ self . memory_zones
2425+ . values ( )
2426+ . filter_map ( |zone| {
2427+ zone. virtio_mem_zone
2428+ . as_ref ( ) ?
2429+ . virtio_device
2430+ . as_ref ( )
2431+ . map ( |dev| dev. lock ( ) . unwrap ( ) . plugged_size ( ) )
2432+ } )
2433+ . sum ( )
2434+ }
2435+
24232436 pub fn memory_zones ( & self ) -> & MemoryZones {
24242437 & self . memory_zones
24252438 }
Original file line number Diff line number Diff line change @@ -2822,6 +2822,14 @@ impl Vm {
28222822 self . device_manager . lock ( ) . unwrap ( ) . balloon_size ( )
28232823 }
28242824
2825+ /// Get the actual size of the virtio_mem regions
2826+ pub fn virtio_mem_plugged_size ( & self ) -> u64 {
2827+ self . memory_manager
2828+ . lock ( )
2829+ . unwrap ( )
2830+ . virtio_mem_plugged_size ( )
2831+ }
2832+
28252833 pub fn send_memory_fds (
28262834 & mut self ,
28272835 socket : & mut UnixStream ,
You can’t perform that action at this time.
0 commit comments