async fn vfio_device_handler(
    device: &Device,
    spec: &mut Spec,
    sandbox: &Arc<Mutex<Sandbox>>,
    devidx: &DevIndex,
) -> Result<()> {
    let vfio_in_guest = device.field_type != DRIVER_VFIO_GK_TYPE;
    let mut group = None;

    for opt in device.options.iter() {
        let (_, pcipath) =
            split_vfio_option(opt).ok_or_else(|| anyhow!("Malformed VFIO option {:?}", opt))?;
        let pcipath = pci::Path::from_str(pcipath)?;

        let guestdev = wait_for_pci_device(sandbox, &pcipath).await?;
        if vfio_in_guest {
            pci_driver_override(SYSFS_BUS_PCI_PATH, guestdev, "vfio-pci")?;

            let devgroup = pci_iommu_group(SYSFS_BUS_PCI_PATH, guestdev)?;
            if devgroup.is_none() {
                // Devices must have an IOMMU group to be usable via VFIO
                return Err(anyhow!("{} has no IOMMU group", guestdev));
            }

            if group.is_some() && group != devgroup {
                // If PCI devices associated with the same VFIO device
                // (and therefore group) in the host don't end up in
                // the same group in the guest, something has gone
                // horribly wrong
                return Err(anyhow!(
                    "{} is not in guest IOMMU group {}",
                    guestdev,
                    group.unwrap()
                ));
            }

            group = devgroup;
        }
    }

    if vfio_in_guest {
        // If there are any devices at all, logic above ensures that group is not None
        let group = group.unwrap();
        let vmpath = get_vfio_device_name(sandbox, group).await?;

        update_spec_device(spec, devidx, &device.container_path, &vmpath, &vmpath)?;
    }

    Ok(())
}
// device.options should have one entry for each PCI device in the VFIO group
// Each option should have the form "DDDD:BB:DD.F=<pcipath>"
//     DDDD:BB:DD.F is the device's PCI address in the host
//     <pcipath> is a PCI path to the device in the guest (see pci.rs)
device.options should have one entry for each PCI device in the VFIO group
Each option should have the form "DDDD:BB:DD.F="
DDDD:BB:DD.F is the device's PCI address in the host
 is a PCI path to the device in the guest
device . options should have one entry for each PCI device in the VFIO group Each option should have the form " DDDD : BB : DD . F = " DDDD : BB : DD . F is the device ' s PCI address in the host is a PCI path to the device in the guest
async fn vfio_device_handler(
    device: &Device,
    spec: &mut Spec,
    sandbox: &Arc<Mutex<Sandbox>>,
    devidx: &DevIndex,
) -> Result<()> {
    let vfio_in_guest = device.field_type != DRIVER_VFIO_GK_TYPE;
    let mut group = None;
    for opt in device.options.iter() {
        let (_, pcipath) =
            split_vfio_option(opt).ok_or_else(|| anyhow!("Malformed VFIO option {:?}", opt))?;
        let pcipath = pci::Path::from_str(pcipath)?;
        let guestdev = wait_for_pci_device(sandbox, &pcipath).await?;
        if vfio_in_guest {
            pci_driver_override(SYSFS_BUS_PCI_PATH, guestdev, "vfio-pci")?;
            let devgroup = pci_iommu_group(SYSFS_BUS_PCI_PATH, guestdev)?;
            if devgroup.is_none() {
                // Devices must have an IOMMU group to be usable via VFIO
                return Err(anyhow!("{} has no IOMMU group", guestdev));
            }
            if group.is_some() && group != devgroup {
                // If PCI devices associated with the same VFIO device
                // (and therefore group) in the host don't end up in
                // the same group in the guest, something has gone
                // horribly wrong
                return Err(anyhow!(
                    "{} is not in guest IOMMU group {}",
                    guestdev,
                    group.unwrap()
                ));
            }
            group = devgroup;
        }
    }
    if vfio_in_guest {
        // If there are any devices at all, logic above ensures that group is not None
        let group = group.unwrap();
        let vmpath = get_vfio_device_name(sandbox, group).await?;
        update_spec_device(spec, devidx, &device.container_path, &vmpath, &vmpath)?;
    }
    Ok(())
}
async fn vfio_device_handler ( device : & Device , spec : & mut Spec , sandbox : & Arc < Mutex < Sandbox > > , devidx : & DevIndex , ) -> Result < ( ) > { let vfio_in_guest = device . field_type != DRIVER_VFIO_GK_TYPE ; let mut group = None ; for opt in device . options . iter ( ) { let ( _ , pcipath ) = split_vfio_option ( opt ) . ok_or_else ( | | anyhow ! ( " " opt ) ) ? ; let pcipath = pci :: Path :: from_str ( pcipath ) ? ; let guestdev = wait_for_pci_device ( sandbox , & pcipath ) . await ? ; if vfio_in_guest { pci_driver_override ( SYSFS_BUS_PCI_PATH , guestdev , " " ) ? ; let devgroup = pci_iommu_group ( SYSFS_BUS_PCI_PATH , guestdev ) ? ; if devgroup . is_none ( ) { // Devices must have an IOMMU group to be usable via VFIO return Err ( anyhow ! ( " " guestdev ) ) ; } if group . is_some ( ) && group != devgroup { // If PCI devices associated with the same VFIO device // (and therefore group) in the host don't end up in // the same group in the guest, something has gone // horribly wrong return Err ( anyhow ! ( " " guestdev group unwrap ( ) ) ) ; } group = devgroup ; } } if vfio_in_guest { // If there are any devices at all, logic above ensures that group is not None let group = group . unwrap ( ) ; let vmpath = get_vfio_device_name ( sandbox , group ) . await ? ; update_spec_device ( spec , devidx , & device . container_path , & vmpath , & vmpath ) ? ; } Ok ( ( ) ) }
device.options should have one entry for each PCI device in the VFIO group
Each option should have the form "DDDD:BB:DD.F=<pcipath>"
DDDD:BB:DD.F is the device's PCI address in the host
<pcipath> is a PCI path to the device in the guest (see pci.rs)
device . options should have one entry for each PCI device in the VFIO group Each option should have the form " DDDD : BB : DD . F = <pcipath > " DDDD : BB : DD . F is the device ' s PCI address in the host <pcipath > is a PCI path to the device in the guest ( see pci . rs )
device
&Device
spec
&mut Spec
sandbox
&Arc<Mutex<Sandbox>>
devidx
&DevIndex
device
&Device
spec
&mut Spec
sandbox
&Arc<Mutex<Sandbox>>
devidx
&DevIndex