@@ -57,8 +57,6 @@ pub enum MemoryError {
5757 FileMetadata ( std:: io:: Error ) ,
5858 /// Memory region is not aligned
5959 Unaligned ,
60- /// Memory slot is invalid: {0}
61- InvalidSlot ( u32 ) ,
6260 /// Error protecting memory slot: {0}
6361 Mprotect ( std:: io:: Error ) ,
6462}
@@ -307,19 +305,23 @@ impl GuestRegionMmapExt {
307305 }
308306
309307 /// (un)plug a slot from an Hotpluggable memory region
310- pub ( crate ) fn update_slot ( & self , vm : & Vm , slot : u32 , plug : bool ) -> Result < ( ) , VmError > {
308+ pub ( crate ) fn update_slot (
309+ & self ,
310+ vm : & Vm ,
311+ mem_slot : & GuestMemorySlot < ' _ > ,
312+ plug : bool ,
313+ ) -> Result < ( ) , VmError > {
311314 // This function can only be called on hotpluggable regions!
312315 assert ! ( self . region_type == GuestRegionType :: Hotpluggable ) ;
313316
314- let mem_slot = self . mem_slot ( slot) . ok_or ( MemoryError :: InvalidSlot ( slot) ) ?;
315317 let mut bitmap_guard = self . plugged . lock ( ) . unwrap ( ) ;
316- let prev = bitmap_guard. replace ( ( slot - self . slot_from ) as usize , plug) ;
318+ let prev = bitmap_guard. replace ( ( mem_slot . slot - self . slot_from ) as usize , plug) ;
317319 // do not do anything if the state is what we're trying to set
318320 if prev == plug {
319321 return Ok ( ( ) ) ;
320322 }
321323
322- let mut kvm_region = kvm_userspace_memory_region:: from ( & mem_slot) ;
324+ let mut kvm_region = kvm_userspace_memory_region:: from ( mem_slot) ;
323325 if plug {
324326 // make it accessible _before_ adding it to KVM
325327 mem_slot. protect ( false ) ?;
0 commit comments