]> xenbits.xensource.com Git - people/liuw/libxenctrl-split/libvirt.git/commit
nodedev: Fix the improper logic when enumerating SRIOV VF
authorOsier Yang <jyang@redhat.com>
Mon, 25 Mar 2013 13:10:51 +0000 (21:10 +0800)
committerOsier Yang <jyang@redhat.com>
Mon, 25 Mar 2013 13:14:48 +0000 (21:14 +0800)
commit9a3ff01d7f16cc280ce3176620c0714f55511a65
tree6fec95910874c66e14479f41f413fa2b9877ea98
parent96d3086a4fb1caf5a756f40611bbe2586561da93
nodedev: Fix the improper logic when enumerating SRIOV VF

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;
src/node_device/node_device_hal.c
src/node_device/node_device_udev.c
src/util/virpci.c