pub fn add_subregion(&self, child: Region, offset: u64) -> Result<()> {
        // check parent Region's property, and check if child Region's offset is valid or not
        if self.region_type() != RegionType::Container {
            return Err(ErrorKind::RegionType(self.region_type()).into());
        }
        self.check_valid_offset(offset, child.size())
            .chain_err(|| {
                format!(
                    "Invalid offset: offset 0x{:X}, child length 0x{:X}, region size 0x{:X}",
                    offset,
                    child.size(),
                    self.size()
                )
            })?;

        // set child region's offset and father address-space
        child.set_offset(GuestAddress(offset));
        if let Some(space) = self.space.read().unwrap().upgrade() {
            child.set_belonged_address_space(&space)
        }

        // insert to `subregion` array and update topology of father address-space
        let mut sub_regions = self.subregions.write().unwrap();
        let mut index = 0_usize;
        while index < sub_regions.len() {
            if child.priority() >= sub_regions.get(index).unwrap().priority() {
                break;
            }
            index += 1;
        }
        sub_regions.insert(index, child);
        drop(sub_regions);

        if let Some(space) = self.space.read().unwrap().upgrade() {
            space
                .update_topology()
                .chain_err(|| "Failed to update topology for address_space")?;
        } else {
            debug!("add subregion to container region, which has no belonged address-space");
        }

        Ok(())
    }
/// Add sub-region to this region.
///
/// # Arguments
///
/// * `child` - Subregion of this region.
/// * `offset` - Offset of subregion.
///
/// # Errors
///
/// Return Error if
/// * This region is not a Container.
/// * The argument `offset` plus child region's size overflows or exceed this region's size.
/// * The child-region already exists in sub-regions array.
/// * Failed to generate flat view (topology changed after adding sub-region).
Add sub-region to this region.
Add sub - region to this region .
pub fn add_subregion(&self, child: Region, offset: u64) -> Result<()> {
        // check parent Region's property, and check if child Region's offset is valid or not
        if self.region_type() != RegionType::Container {
            return Err(ErrorKind::RegionType(self.region_type()).into());
        }
        self.check_valid_offset(offset, child.size())
            .chain_err(|| {
                format!(
                    "Invalid offset: offset 0x{:X}, child length 0x{:X}, region size 0x{:X}",
                    offset,
                    child.size(),
                    self.size()
                )
            })?;
        // set child region's offset and father address-space
        child.set_offset(GuestAddress(offset));
        if let Some(space) = self.space.read().unwrap().upgrade() {
            child.set_belonged_address_space(&space)
        }
        // insert to `subregion` array and update topology of father address-space
        let mut sub_regions = self.subregions.write().unwrap();
        let mut index = 0_usize;
        while index < sub_regions.len() {
            if child.priority() >= sub_regions.get(index).unwrap().priority() {
                break;
            }
            index += 1;
        }
        sub_regions.insert(index, child);
        drop(sub_regions);
        if let Some(space) = self.space.read().unwrap().upgrade() {
            space
                .update_topology()
                .chain_err(|| "Failed to update topology for address_space")?;
        } else {
            debug!("add subregion to container region, which has no belonged address-space");
        }
        Ok(())
    }
pub fn add_subregion ( & self , child : Region , offset : u64 ) -> Result < ( ) > { // check parent Region's property, and check if child Region's offset is valid or not if self . region_type ( ) != RegionType :: Container { return Err ( ErrorKind :: RegionType ( self . region_type ( ) ) . into ( ) ) ; } self . check_valid_offset ( offset , child . size ( ) ) . chain_err ( | | { format ! ( " " offset child size ( ) self size ( ) ) } ) ? ; // set child region's offset and father address-space child . set_offset ( GuestAddress ( offset ) ) ; if let Some ( space ) = self . space . read ( ) . unwrap ( ) . upgrade ( ) { child . set_belonged_address_space ( & space ) } // insert to `subregion` array and update topology of father address-space let mut sub_regions = self . subregions . write ( ) . unwrap ( ) ; let mut index = 0_usize ; while index < sub_regions . len ( ) { if child . priority ( ) >= sub_regions . get ( index ) . unwrap ( ) . priority ( ) { break ; } index += 1 ; } sub_regions . insert ( index , child ) ; drop ( sub_regions ) ; if let Some ( space ) = self . space . read ( ) . unwrap ( ) . upgrade ( ) { space . update_topology ( ) . chain_err ( | | " " ) ? ; } else { debug ! ( " " ) ; } Ok ( ( ) ) }
Add sub-region to this region.
Add sub - region to this region .
&self
child
Region
offset
u64
&self
child
Region
offset
u64
errors
Return Error if
This region is not a Container.
The argument `offset` plus child region's size overflows or exceed this region's size.
The child-region already exists in sub-regions array.
Failed to generate flat view (topology changed after adding sub-region).
Return Error if This region is not a Container . The argument ` offset ` plus child region ' s size overflows or exceed this region ' s size . The child - region already exists in sub - regions array . Failed to generate flat view ( topology changed after adding sub - region ) .