Repository: firecracker-microvm/firecracker
File: src/vmm/src/device_manager/mmio.rs (Rust)

Code before:
            let mmio_device = MmioTransport::new(guest_mem, device, false);
            let device_info = self.register_mmio_virtio_for_boot(
                vm,
                resource_allocator,
                dev_id.to_string(),
                mmio_device,
                cmdline,
            )?;
            Ok(device_info.addr)
        }

        #[cfg(target_arch = "x86_64")]
        /// Gets the number of interrupts used by the devices registered.
        pub fn used_irqs_count(&self) -> usize {
            let mut irq_number = 0;
            self.get_device_info()
                .iter()
                .for_each(|(_, device_info)| irq_number += 
                if device_info.irq.is_none() {
                    0
                } else {
                    1
                }
                    
            );
            
            irq_number

        }
    }

    #[allow(dead_code)]
    #[derive(Debug)]
    struct DummyDevice {
        dummy: u32,
        queues: Vec<Queue>,
        queue_evts: [EventFd; 1],
        interrupt_evt: EventFd,
    }

    impl DummyDevice {
        pub fn new() -> Self {
            DummyDevice {
                dummy: 0,
                queues: QUEUE_SIZES.iter().map(|&s| Queue::new(s)).collect(),
                queue_evts: [EventFd::new(libc::EFD_NONBLOCK).expect("cannot create eventFD")],
                interrupt_evt: EventFd::new(libc::EFD_NONBLOCK).expect("cannot create eventFD"),
            }
        }
    }


Review comment (suggestion):
nit:
```suggestion
        let irq_number = self.get_device_info().iter().map(|(_, device_info)| device_info.is_some()).count();
```

Code after:
    use crate::vstate::memory::{GuestAddress, GuestMemoryMmap};
    use crate::{builder, Vm};

    const QUEUE_SIZES: &[u16] = &[64];

    impl MMIODeviceManager {
        fn register_virtio_test_device(
            &mut self,
            vm: &VmFd,
            guest_mem: GuestMemoryMmap,
            resource_allocator: &mut ResourceAllocator,
            device: Arc<Mutex<dyn VirtioDevice>>,
            cmdline: &mut kernel_cmdline::Cmdline,
            dev_id: &str,
        ) -> Result<u64, MmioError> {
            let mmio_device = MmioTransport::new(guest_mem, device, false);
            let device_info = self.register_mmio_virtio_for_boot(
                vm,
                resource_allocator,
                dev_id.to_string(),
                mmio_device,
                cmdline,
            )?;
            Ok(device_info.addr)
        }

        #[cfg(target_arch = "x86_64")]
        /// Gets the number of interrupts used by the devices registered.
        pub fn used_irqs_count(&self) -> usize {
            self.get_device_info()
                .iter()
                .filter(|(_, device_info)| device_info.irq.is_some())
                .count()
        }
    }

    #[allow(dead_code)]
    #[derive(Debug)]
    struct DummyDevice {
        dummy: u32,
        queues: Vec<Queue>,
        queue_evts: [EventFd; 1],
        interrupt_trigger: IrqTrigger,
    }

    impl DummyDevice {
        pub fn new() -> Self {
            DummyDevice {
                dummy: 0,
                queues: QUEUE_SIZES.iter().map(|&s| Queue::new(s)).collect(),
                queue_evts: [EventFd::new(libc::EFD_NONBLOCK).expect("cannot create eventFD")],