fn delete_region(&self, flat_range: &FlatRange) -> Result<()> {
        if flat_range.owner.region_type() != RegionType::Ram
            && flat_range.owner.region_type() != RegionType::RomDevice
            && flat_range.owner.region_type() != RegionType::RamDevice
        {
            return Ok(());
        }

        let (aligned_addr, aligned_size) =
            Self::align_mem_slot(flat_range.addr_range, host_page_size())
                .map(|r| (r.base, r.size))
                .chain_err(|| "Failed to align mem slot")?;

        let mem_slot = match self.delete_slot(aligned_addr.raw_value(), aligned_size) {
            Ok(m) => m,
            Err(_) => {
                debug!("no match mem slot registered to KVM, just return");
                return Ok(());
            }
        };

        let kvm_region = kvm_userspace_memory_region {
            slot: mem_slot.index | (self.as_id.load(Ordering::SeqCst) << 16),
            guest_phys_addr: mem_slot.guest_addr,
            memory_size: 0_u64,
            userspace_addr: mem_slot.host_addr,
            flags: 0,
        };
        unsafe {
            KVM_FDS
                .load()
                .vm_fd
                .as_ref()
                .unwrap()
                .set_user_memory_region(kvm_region)
                .chain_err(|| {
                    format!(
                        "KVM unregister memory region failed: addr 0x{:X}",
                        aligned_addr.raw_value(),
                    )
                })?;
        }

        Ok(())
    }
/// Callback function for deleting Region, which only care about Ram-type Region yet.
///
/// # Arguments
///
/// * `flat_range` - Corresponding FlatRange of new-deleted region.
Callback function for deleting Region, which only care about Ram-type Region yet.
Callback function for deleting Region which only care about Ram - type Region yet .
fn delete_region(&self, flat_range: &FlatRange) -> Result<()> {
        if flat_range.owner.region_type() != RegionType::Ram
            && flat_range.owner.region_type() != RegionType::RomDevice
            && flat_range.owner.region_type() != RegionType::RamDevice
        {
            return Ok(());
        }
        let (aligned_addr, aligned_size) =
            Self::align_mem_slot(flat_range.addr_range, host_page_size())
                .map(|r| (r.base, r.size))
                .chain_err(|| "Failed to align mem slot")?;
        let mem_slot = match self.delete_slot(aligned_addr.raw_value(), aligned_size) {
            Ok(m) => m,
            Err(_) => {
                debug!("no match mem slot registered to KVM, just return");
                return Ok(());
            }
        };
        let kvm_region = kvm_userspace_memory_region {
            slot: mem_slot.index | (self.as_id.load(Ordering::SeqCst) << 16),
            guest_phys_addr: mem_slot.guest_addr,
            memory_size: 0_u64,
            userspace_addr: mem_slot.host_addr,
            flags: 0,
        };
        unsafe {
            KVM_FDS
                .load()
                .vm_fd
                .as_ref()
                .unwrap()
                .set_user_memory_region(kvm_region)
                .chain_err(|| {
                    format!(
                        "KVM unregister memory region failed: addr 0x{:X}",
                        aligned_addr.raw_value(),
                    )
                })?;
        }
        Ok(())
    }
fn delete_region ( & self , flat_range : & FlatRange ) -> Result < ( ) > { if flat_range . owner . region_type ( ) != RegionType :: Ram && flat_range . owner . region_type ( ) != RegionType :: RomDevice && flat_range . owner . region_type ( ) != RegionType :: RamDevice { return Ok ( ( ) ) ; } let ( aligned_addr , aligned_size ) = Self :: align_mem_slot ( flat_range . addr_range , host_page_size ( ) ) . map ( | r | ( r . base , r . size ) ) . chain_err ( | | " " ) ? ; let mem_slot = match self . delete_slot ( aligned_addr . raw_value ( ) , aligned_size ) { Ok ( m ) => m , Err ( _ ) => { debug ! ( " " ) ; return Ok ( ( ) ) ; } } ; let kvm_region = kvm_userspace_memory_region { slot : mem_slot . index | ( self . as_id . load ( Ordering :: SeqCst ) << 16 ) , guest_phys_addr : mem_slot . guest_addr , memory_size : 0_u64 , userspace_addr : mem_slot . host_addr , flags : 0 , } ; unsafe { KVM_FDS . load ( ) . vm_fd . as_ref ( ) . unwrap ( ) . set_user_memory_region ( kvm_region ) . chain_err ( | | { format ! ( " " aligned_addr raw_value ( ) ) } ) ? ; } Ok ( ( ) ) }
Callback function for deleting Region, which only care about Ram-type Region yet.
Callback function for deleting Region which only care about Ram - type Region yet .
&self
flat_range
&FlatRange
&self
flat_range
&FlatRange