• O
    nodedev: Fix the improper logic when enumerating SRIOV VF · 9a3ff01d
    Osier Yang 提交于
    virPCIGetVirtualFunctions returns 0 even if there is no "virtfn"
    entry under the device sysfs path.
    
    And virPCIGetVirtualFunctions returns -1 when it fails to get
    the PCI config space of one VF, however, with keeping the
    the VFs already detected.
    
    That's why udevProcessPCI and gather_pci_cap use logic like:
    
    if (!virPCIGetVirtualFunctions(syspath,
                                   &data->pci_dev.virtual_functions,
                                   &data->pci_dev.num_virtual_functions) ||
        data->pci_dev.num_virtual_functions > 0)
        data->pci_dev.flags |= VIR_NODE_DEV_CAP_FLAG_PCI_VIRTUAL_FUNCTION;
    
    to tag the PCI device with "virtual_function" cap.
    
    However, this results in a VF will aslo get "virtual_function" cap.
    
    This patch fixes it by:
      * Ignoring the VF which has failure of getting PCI config space
        (given that the successfully detected VFs are kept , it makes
        sense to not give up on the failure of one VF too) with a warning,
        so virPCIGetVirtualFunctions will not return -1 except out of memory.
    
      * Free the allocated *virtual_functions when out of memory
    
    And thus the logic can be changed to:
    
        /* Out of memory */
        int ret = virPCIGetVirtualFunctions(syspath,
                                            &data->pci_dev.virtual_functions,
                                            &data->pci_dev.num_virtual_functions);
    
        if (ret < 0 )
            goto out;
        if (data->pci_dev.num_virtual_functions > 0)
            data->pci_dev.flags |= VIR_NODE_DEV_CAP_FLAG_PCI_VIRTUAL_FUNCTION;
    9a3ff01d
node_device_udev.c 48.0 KB