pub fn build_queues_checked(
        &self,
        mem: &GuestMemoryMmap,
        expected_device_type: u32,
        expected_num_queues: usize,
        expected_queue_max_size: u16,
    ) -> std::result::Result<Vec<Queue>, Error> {
        // Sanity check:
        // - right device type,
        // - acked features is a subset of available ones,
        // - right number of queues,
        if self.device_type != expected_device_type
            || (self.acked_features & !self.avail_features) != 0
            || self.queues.len() != expected_num_queues
        {
            return Err(Error::InvalidInput);
        }

        let uses_notif_suppression = (self.acked_features & 1u64 << VIRTIO_RING_F_EVENT_IDX) != 0;
        let queues: Vec<Queue> = self
            .queues
            .iter()
            .map(|queue_state| {
                // Safe to unwrap, `Queue::restore` has no error case.
                let mut queue = Queue::restore((), &queue_state).unwrap();
                if uses_notif_suppression {
                    queue.enable_notif_suppression();
                }
                queue
            })
            .collect();

        for q in &queues {
            // Sanity check queue size and queue max size.
            if q.max_size != expected_queue_max_size || q.size > expected_queue_max_size {
                return Err(Error::InvalidInput);
            }
            // Snapshot can happen at any time, including during device configuration/activation
            // when fields are only partially configured.
            //
            // Only if the device was activated, check `q.is_valid()`.
            if self.activated && !q.is_valid(mem) {
                return Err(Error::InvalidInput);
            }
        }
        Ok(queues)
    }
/// Does sanity checking on the `self` state against expected values
/// and builds queues from state.
Does sanity checking on the `self` state against expected values
and builds queues from state.
Does sanity checking on the ` self ` state against expected values and builds queues from state .
pub fn build_queues_checked(
        &self,
        mem: &GuestMemoryMmap,
        expected_device_type: u32,
        expected_num_queues: usize,
        expected_queue_max_size: u16,
    ) -> std::result::Result<Vec<Queue>, Error> {
        // Sanity check:
        // - right device type,
        // - acked features is a subset of available ones,
        // - right number of queues,
        if self.device_type != expected_device_type
            || (self.acked_features & !self.avail_features) != 0
            || self.queues.len() != expected_num_queues
        {
            return Err(Error::InvalidInput);
        }
        let uses_notif_suppression = (self.acked_features & 1u64 << VIRTIO_RING_F_EVENT_IDX) != 0;
        let queues: Vec<Queue> = self
            .queues
            .iter()
            .map(|queue_state| {
                // Safe to unwrap, `Queue::restore` has no error case.
                let mut queue = Queue::restore((), &queue_state).unwrap();
                if uses_notif_suppression {
                    queue.enable_notif_suppression();
                }
                queue
            })
            .collect();
        for q in &queues {
            // Sanity check queue size and queue max size.
            if q.max_size != expected_queue_max_size || q.size > expected_queue_max_size {
                return Err(Error::InvalidInput);
            }
            // Snapshot can happen at any time, including during device configuration/activation
            // when fields are only partially configured.
            //
            // Only if the device was activated, check `q.is_valid()`.
            if self.activated && !q.is_valid(mem) {
                return Err(Error::InvalidInput);
            }
        }
        Ok(queues)
    }
pub fn build_queues_checked ( & self , mem : & GuestMemoryMmap , expected_device_type : u32 , expected_num_queues : usize , expected_queue_max_size : u16 , ) -> std :: result :: Result < Vec < Queue > , Error > { // Sanity check: // - right device type, // - acked features is a subset of available ones, // - right number of queues, if self . device_type != expected_device_type || ( self . acked_features & ! self . avail_features ) != 0 || self . queues . len ( ) != expected_num_queues { return Err ( Error :: InvalidInput ) ; } let uses_notif_suppression = ( self . acked_features & 1u64 << VIRTIO_RING_F_EVENT_IDX ) != 0 ; let queues : Vec < Queue > = self . queues . iter ( ) . map ( | queue_state | { // Safe to unwrap, `Queue::restore` has no error case. let mut queue = Queue :: restore ( ( ) , & queue_state ) . unwrap ( ) ; if uses_notif_suppression { queue . enable_notif_suppression ( ) ; } queue } ) . collect ( ) ; for q in & queues { // Sanity check queue size and queue max size. if q . max_size != expected_queue_max_size || q . size > expected_queue_max_size { return Err ( Error :: InvalidInput ) ; } // Snapshot can happen at any time, including during device configuration/activation // when fields are only partially configured. // // Only if the device was activated, check `q.is_valid()`. if self . activated && ! q . is_valid ( mem ) { return Err ( Error :: InvalidInput ) ; } } Ok ( queues ) }
Does sanity checking on the `self` state against expected values
and builds queues from state.
Does sanity checking on the ` self ` state against expected values and builds queues from state .
&self
mem
&GuestMemoryMmap
expected_device_type
u32
expected_num_queues
usize
expected_queue_max_size
u16
&self
mem
&GuestMemoryMmap
expected_device_type
u32
expected_num_queues
usize
expected_queue_max_size
u16