conf: node_device: refactor GetPCIMdevTypesCaps into GetMdevTypeCapes

Extracting PCI from virNodeDeviceGetPCIMdevTypesCaps creating
virNodeDeviceGetMdevTypesCaps to make later reuse possible.

Signed-off-by: Boris Fiuczynski <fiuczy@linux.ibm.com>
Reviewed-by: Bjoern Walk <bwalk@linux.ibm.com>
Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
Boris Fiuczynski 2020-10-23 19:31:46 +02:00 committed by Ján Tomko
parent da5cf518ad
commit f1b08901f7

View File

@ -2584,26 +2584,25 @@ virNodeDeviceGetPCIIOMMUGroupCaps(virNodeDevCapPCIDevPtr pci_dev)
static int
virNodeDeviceGetPCIMdevTypesCaps(const char *sysfspath,
virNodeDevCapPCIDevPtr pci_dev)
virNodeDeviceGetMdevTypesCaps(const char *sysfspath,
virMediatedDeviceTypePtr **mdev_types,
size_t *nmdev_types)
{
virMediatedDeviceTypePtr *types = NULL;
size_t ntypes = 0;
size_t i;
/* this could be a refresh, so clear out the old data */
for (i = 0; i < pci_dev->nmdev_types; i++)
virMediatedDeviceTypeFree(pci_dev->mdev_types[i]);
VIR_FREE(pci_dev->mdev_types);
pci_dev->nmdev_types = 0;
pci_dev->flags &= ~VIR_NODE_DEV_CAP_FLAG_PCI_MDEV;
for (i = 0; i < *nmdev_types; i++)
virMediatedDeviceTypeFree(*mdev_types[i]);
VIR_FREE(*mdev_types);
*nmdev_types = 0;
if (virMediatedDeviceGetMdevTypes(sysfspath, &types, &ntypes) < 0)
return -1;
pci_dev->mdev_types = g_steal_pointer(&types);
pci_dev->nmdev_types = ntypes;
pci_dev->flags |= VIR_NODE_DEV_CAP_FLAG_PCI_MDEV;
*mdev_types = g_steal_pointer(&types);
*nmdev_types = ntypes;
return 0;
}
@ -2620,9 +2619,17 @@ virNodeDeviceGetPCIDynamicCaps(const char *sysfsPath,
virNodeDevCapPCIDevPtr pci_dev)
{
if (virNodeDeviceGetPCISRIOVCaps(sysfsPath, pci_dev) < 0 ||
virNodeDeviceGetPCIIOMMUGroupCaps(pci_dev) < 0 ||
virNodeDeviceGetPCIMdevTypesCaps(sysfsPath, pci_dev) < 0)
virNodeDeviceGetPCIIOMMUGroupCaps(pci_dev) < 0)
return -1;
pci_dev->flags &= ~VIR_NODE_DEV_CAP_FLAG_PCI_MDEV;
if (virNodeDeviceGetMdevTypesCaps(sysfsPath,
&pci_dev->mdev_types,
&pci_dev->nmdev_types) < 0)
return -1;
if (pci_dev->nmdev_types > 0)
pci_dev->flags |= VIR_NODE_DEV_CAP_FLAG_PCI_MDEV;
return 0;
}