fn write(&mut self, data: &[u8], _base: GuestAddress, offset: u64) -> bool {
        match offset {
            0x00..=0xff if data.len() == 4 => {
                let value = LittleEndian::read_u32(data);
                if let Err(ref e) = self.state.config_space.write_common_config(
                    &self.device,
                    &self.interrupt_status,
                    offset,
                    value,
                ) {
                    error!(
                        "Failed to write mmio register {}, type: {}, {}",
                        offset,
                        self.device.lock().unwrap().device_type(),
                        error_chain::ChainedError::display_chain(e),
                    );
                    return false;
                }

                if self.state.config_space.check_device_status(
                    CONFIG_STATUS_ACKNOWLEDGE
                        | CONFIG_STATUS_DRIVER
                        | CONFIG_STATUS_DRIVER_OK
                        | CONFIG_STATUS_FEATURES_OK,
                    CONFIG_STATUS_FAILED,
                ) && !self.state.activated
                {
                    let ret = self.activate().map(|_| self.state.activated = true);
                    if let Err(ref e) = ret {
                        error!(
                            "Failed to activate dev, type: {}, {}",
                            self.device.lock().unwrap().device_type(),
                            error_chain::ChainedError::display_chain(e),
                        );
                    }
                }
            }
            0x100..=0xfff => {
                if self
                    .state
                    .config_space
                    .check_device_status(CONFIG_STATUS_DRIVER, CONFIG_STATUS_FAILED)
                {
                    if let Err(ref e) = self
                        .device
                        .lock()
                        .unwrap()
                        .write_config(offset as u64 - 0x100, data)
                    {
                        error!(
                            "Failed to write virtio-dev config space {}, type: {}, {}",
                            offset as u64 - 0x100,
                            self.device.lock().unwrap().device_type(),
                            error_chain::ChainedError::display_chain(e),
                        );
                        return false;
                    }
                } else {
                    error!("Failed to write virtio-dev config space: driver is not ready 0x{:X}, type: {}",
                        self.state.config_space.get_device_status(),
                        self.device.lock().unwrap().device_type(),
                    );
                    return false;
                }
            }
            _ => {
                warn!(
                    "Failed to write mmio register: overflows, offset is 0x{:x} type: {}",
                    offset,
                    self.device.lock().unwrap().device_type(),
                );
                return false;
            }
        }
        true
    }
/// Write data by virtio driver from VM.
Write data by virtio driver from VM.
Write data by virtio driver from VM .
fn write(&mut self, data: &[u8], _base: GuestAddress, offset: u64) -> bool {
        match offset {
            0x00..=0xff if data.len() == 4 => {
                let value = LittleEndian::read_u32(data);
                if let Err(ref e) = self.state.config_space.write_common_config(
                    &self.device,
                    &self.interrupt_status,
                    offset,
                    value,
                ) {
                    error!(
                        "Failed to write mmio register {}, type: {}, {}",
                        offset,
                        self.device.lock().unwrap().device_type(),
                        error_chain::ChainedError::display_chain(e),
                    );
                    return false;
                }
                if self.state.config_space.check_device_status(
                    CONFIG_STATUS_ACKNOWLEDGE
                        | CONFIG_STATUS_DRIVER
                        | CONFIG_STATUS_DRIVER_OK
                        | CONFIG_STATUS_FEATURES_OK,
                    CONFIG_STATUS_FAILED,
                ) && !self.state.activated
                {
                    let ret = self.activate().map(|_| self.state.activated = true);
                    if let Err(ref e) = ret {
                        error!(
                            "Failed to activate dev, type: {}, {}",
                            self.device.lock().unwrap().device_type(),
                            error_chain::ChainedError::display_chain(e),
                        );
                    }
                }
            }
            0x100..=0xfff => {
                if self
                    .state
                    .config_space
                    .check_device_status(CONFIG_STATUS_DRIVER, CONFIG_STATUS_FAILED)
                {
                    if let Err(ref e) = self
                        .device
                        .lock()
                        .unwrap()
                        .write_config(offset as u64 - 0x100, data)
                    {
                        error!(
                            "Failed to write virtio-dev config space {}, type: {}, {}",
                            offset as u64 - 0x100,
                            self.device.lock().unwrap().device_type(),
                            error_chain::ChainedError::display_chain(e),
                        );
                        return false;
                    }
                } else {
                    error!("Failed to write virtio-dev config space: driver is not ready 0x{:X}, type: {}",
                        self.state.config_space.get_device_status(),
                        self.device.lock().unwrap().device_type(),
                    );
                    return false;
                }
            }
            _ => {
                warn!(
                    "Failed to write mmio register: overflows, offset is 0x{:x} type: {}",
                    offset,
                    self.device.lock().unwrap().device_type(),
                );
                return false;
            }
        }
        true
    }
fn write ( & mut self , data : & [ u8 ] , _base : GuestAddress , offset : u64 ) -> bool { match offset { 0x00 ..= 0xff if data . len ( ) == 4 => { let value = LittleEndian :: read_u32 ( data ) ; if let Err ( ref e ) = self . state . config_space . write_common_config ( & self . device , & self . interrupt_status , offset , value , ) { error ! ( " " offset self device lock ( ) unwrap ( ) device_type ( ) error_chain ChainedError display_chain ( e ) ) ; return false ; } if self . state . config_space . check_device_status ( CONFIG_STATUS_ACKNOWLEDGE | CONFIG_STATUS_DRIVER | CONFIG_STATUS_DRIVER_OK | CONFIG_STATUS_FEATURES_OK , CONFIG_STATUS_FAILED , ) && ! self . state . activated { let ret = self . activate ( ) . map ( | _ | self . state . activated = true ) ; if let Err ( ref e ) = ret { error ! ( " " self device lock ( ) unwrap ( ) device_type ( ) error_chain ChainedError display_chain ( e ) ) ; } } } 0x100 ..= 0xfff => { if self . state . config_space . check_device_status ( CONFIG_STATUS_DRIVER , CONFIG_STATUS_FAILED ) { if let Err ( ref e ) = self . device . lock ( ) . unwrap ( ) . write_config ( offset as u64 - 0x100 , data ) { error ! ( " " offset as u64 0x100 self device lock ( ) unwrap ( ) device_type ( ) error_chain ChainedError display_chain ( e ) ) ; return false ; } } else { error ! ( " " self state config_space get_device_status ( ) self device lock ( ) unwrap ( ) device_type ( ) ) ; return false ; } } _ => { warn ! ( " " offset self device lock ( ) unwrap ( ) device_type ( ) ) ; return false ; } } true }
Write data by virtio driver from VM.
Write data by virtio driver from VM .
&mut self
data
&[u8]
_base
GuestAddress
offset
u64
&mut self
data
&[u8]
_base
GuestAddress
offset
u64