diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c index 4ffcecdf9f..2555119892 100644 --- a/src/network/bridge_driver.c +++ b/src/network/bridge_driver.c @@ -2598,29 +2598,25 @@ networkShutdownNetworkBridge(virNetworkObj *obj G_GNUC_UNUSED) static int networkCreateInterfacePool(virNetworkDef *netdef) { - size_t numVirtFns = 0; - char **vfNames = NULL; - virPCIDeviceAddress **virtFns; - + g_autoptr(virPCIVirtualFunctionList) vfs = NULL; int ret = -1; size_t i; if (netdef->forward.npfs == 0 || netdef->forward.nifs > 0) return 0; - if ((virNetDevGetVirtualFunctions(netdef->forward.pfs->dev, &vfNames, - &virtFns, &numVirtFns)) < 0) { + if (virNetDevGetVirtualFunctions(netdef->forward.pfs->dev, &vfs) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Could not get Virtual functions on %s"), netdef->forward.pfs->dev); goto cleanup; } - netdef->forward.ifs = g_new0(virNetworkForwardIfDef, numVirtFns); + netdef->forward.ifs = g_new0(virNetworkForwardIfDef, vfs->nfunctions); - for (i = 0; i < numVirtFns; i++) { - virPCIDeviceAddress *thisVirtFn = virtFns[i]; - const char *thisName = vfNames[i]; + for (i = 0; i < vfs->nfunctions; i++) { + virPCIDeviceAddress *thisVirtFn = vfs->functions[i].addr; + const char *thisName = vfs->functions[i].ifname; virNetworkForwardIfDef *thisIf = &netdef->forward.ifs[netdef->forward.nifs]; @@ -2689,12 +2685,6 @@ networkCreateInterfacePool(virNetworkDef *netdef) if (netdef->forward.nifs == 0) g_clear_pointer(&netdef->forward.ifs, g_free); - for (i = 0; i < numVirtFns; i++) { - g_free(vfNames[i]); - g_free(virtFns[i]); - } - g_free(vfNames); - g_free(virtFns); return ret; } diff --git a/src/util/virnetdev.c b/src/util/virnetdev.c index 4db3b255f6..5b4c585716 100644 --- a/src/util/virnetdev.c +++ b/src/util/virnetdev.c @@ -1213,24 +1213,17 @@ virNetDevGetPhysPortName(const char *ifname, /** * virNetDevGetVirtualFunctions: - * * @pfname : name of the physical function interface name - * @vfname: array that will hold the interface names of the virtual_functions - * @n_vfname: pointer to the number of virtual functions + * @vfs: Filled with struct describing the virtual functions of @pfname * * Returns 0 on success and -1 on failure */ - int virNetDevGetVirtualFunctions(const char *pfname, - char ***vfname, - virPCIDeviceAddress ***virt_fns, - size_t *n_vfname) + virPCIVirtualFunctionList **vfs) { - size_t i; g_autofree char *pf_sysfs_device_link = NULL; g_autofree char *pfPhysPortID = NULL; - g_autoptr(virPCIVirtualFunctionList) vfs = NULL; if (virNetDevGetPhysPortID(pfname, &pfPhysPortID) < 0) return -1; @@ -1238,18 +1231,9 @@ virNetDevGetVirtualFunctions(const char *pfname, if (virNetDevSysfsFile(&pf_sysfs_device_link, pfname, "device") < 0) return -1; - if (virPCIGetVirtualFunctionsFull(pf_sysfs_device_link, &vfs, pfPhysPortID) < 0) + if (virPCIGetVirtualFunctionsFull(pf_sysfs_device_link, vfs, pfPhysPortID) < 0) return -1; - *vfname = g_new0(char *, vfs->nfunctions); - *virt_fns = g_new0(virPCIDeviceAddress *, vfs->nfunctions); - *n_vfname = vfs->nfunctions; - - for (i = 0; i < *n_vfname; i++) { - virt_fns[i] = g_steal_pointer(&vfs->functions[i].addr); - vfname[i] = g_steal_pointer(&vfs->functions[i].ifname); - } - return 0; } @@ -1448,9 +1432,7 @@ virNetDevGetPhysPortName(const char *ifname G_GNUC_UNUSED, int virNetDevGetVirtualFunctions(const char *pfname G_GNUC_UNUSED, - char ***vfname G_GNUC_UNUSED, - virPCIDeviceAddress ***virt_fns G_GNUC_UNUSED, - size_t *n_vfname G_GNUC_UNUSED) + virPCIVirtualFunctionList **vfs G_GNUC_UNUSED) { virReportSystemError(ENOSYS, "%s", _("Unable to get virtual functions on this platform")); diff --git a/src/util/virnetdev.h b/src/util/virnetdev.h index de786c9789..790fae5f7a 100644 --- a/src/util/virnetdev.h +++ b/src/util/virnetdev.h @@ -252,11 +252,8 @@ int virNetDevGetPhysPortName(const char *ifname, G_GNUC_WARN_UNUSED_RESULT; int virNetDevGetVirtualFunctions(const char *pfname, - char ***vfname, - virPCIDeviceAddress ***virt_fns, - size_t *n_vfname) - ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3) - ATTRIBUTE_NONNULL(4) G_GNUC_WARN_UNUSED_RESULT; + virPCIVirtualFunctionList **vfs) + ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) G_GNUC_WARN_UNUSED_RESULT; int virNetDevSaveNetConfig(const char *linkdev, int vf, const char *stateDir,