Extracting PCI from virNodeDeviceGetPCIMdevTypesCaps creating virNodeDeviceGetMdevTypesCaps to make later reuse possible. Signed-off-by: Boris Fiuczynski <fiuczy@xxxxxxxxxxxxx> Reviewed-by: Bjoern Walk <bwalk@xxxxxxxxxxxxx> --- src/conf/node_device_conf.c | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/src/conf/node_device_conf.c b/src/conf/node_device_conf.c index af8edded3c..811d102208 100644 --- a/src/conf/node_device_conf.c +++ b/src/conf/node_device_conf.c @@ -2570,26 +2570,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; } @@ -2606,9 +2605,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; } -- 2.25.1