pub fn insert(&mut self, config: BlockDeviceConfig) -> Result<()> {
        let is_root_device = config.is_root_device;
        let position = self.get_index_of_drive_id(&config.drive_id);
        let has_root_block = self.has_root_device();

        // Don't allow adding a second root block device.
        // If the new device cfg is root and not an update to the existing root, fail fast.
        if is_root_device && has_root_block && position != Some(0) {
            return Err(DriveError::RootBlockDeviceAlreadyAdded);
        }

        let block_dev = Arc::new(Mutex::new(Self::create_block(config)?));
        // If the id of the drive already exists in the list, the operation is update/overwrite.
        match position {
            // New block device.
            None => {
                if is_root_device {
                    self.list.push_front(block_dev);
                } else {
                    self.list.push_back(block_dev);
                }
            }
            // Update existing block device.
            Some(index) => {
                // Update the slot with the new block.
                self.list[index] = block_dev;
                // Check if the root block device is being updated.
                if index != 0 && is_root_device {
                    // Make sure the root device is on the first position.
                    self.list.swap(0, index);
                }
            }
        }
        Ok(())
    }
/// Inserts a `Block` in the block devices list using the specified configuration.
/// If a block with the same id already exists, it will overwrite it.
/// Inserting a secondary root block device will fail.
Inserts a `Block` in the block devices list using the specified configuration.
If a block with the same id already exists, it will overwrite it.
Inserting a secondary root block device will fail.
Inserts a ` Block ` in the block devices list using the specified configuration . If a block with the same id already exists it will overwrite it . Inserting a secondary root block device will fail .
pub fn insert(&mut self, config: BlockDeviceConfig) -> Result<()> {
        let is_root_device = config.is_root_device;
        let position = self.get_index_of_drive_id(&config.drive_id);
        let has_root_block = self.has_root_device();
        // Don't allow adding a second root block device.
        // If the new device cfg is root and not an update to the existing root, fail fast.
        if is_root_device && has_root_block && position != Some(0) {
            return Err(DriveError::RootBlockDeviceAlreadyAdded);
        }
        let block_dev = Arc::new(Mutex::new(Self::create_block(config)?));
        // If the id of the drive already exists in the list, the operation is update/overwrite.
        match position {
            // New block device.
            None => {
                if is_root_device {
                    self.list.push_front(block_dev);
                } else {
                    self.list.push_back(block_dev);
                }
            }
            // Update existing block device.
            Some(index) => {
                // Update the slot with the new block.
                self.list[index] = block_dev;
                // Check if the root block device is being updated.
                if index != 0 && is_root_device {
                    // Make sure the root device is on the first position.
                    self.list.swap(0, index);
                }
            }
        }
        Ok(())
    }
pub fn insert ( & mut self , config : BlockDeviceConfig ) -> Result < ( ) > { let is_root_device = config . is_root_device ; let position = self . get_index_of_drive_id ( & config . drive_id ) ; let has_root_block = self . has_root_device ( ) ; // Don't allow adding a second root block device. // If the new device cfg is root and not an update to the existing root, fail fast. if is_root_device && has_root_block && position != Some ( 0 ) { return Err ( DriveError :: RootBlockDeviceAlreadyAdded ) ; } let block_dev = Arc :: new ( Mutex :: new ( Self :: create_block ( config ) ? ) ) ; // If the id of the drive already exists in the list, the operation is update/overwrite. match position { // New block device. None => { if is_root_device { self . list . push_front ( block_dev ) ; } else { self . list . push_back ( block_dev ) ; } } // Update existing block device. Some ( index ) => { // Update the slot with the new block. self . list [ index ] = block_dev ; // Check if the root block device is being updated. if index != 0 && is_root_device { // Make sure the root device is on the first position. self . list . swap ( 0 , index ) ; } } } Ok ( ( ) ) }
Inserts a `Block` in the block devices list using the specified configuration.
Inserts a ` Block ` in the block devices list using the specified configuration .
&mut self
config
BlockDeviceConfig
&mut self
config
BlockDeviceConfig