virNetDevGetVirtualFunctions: Directly return virPCIVirtualFunctionList

Remove the conversion from virPCIVirtualFunctionList which encapsulates
the list of virtual functions to two disjunct arrays.

This greatly simplifies the fetching of the parameters as well as
cleanup in the caller.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
Peter Krempa 2021-08-04 17:37:50 +02:00
parent 795e9e05c3
commit d40e9d1df8
3 changed files with 12 additions and 43 deletions

View File

@ -2598,29 +2598,25 @@ networkShutdownNetworkBridge(virNetworkObj *obj G_GNUC_UNUSED)
static int static int
networkCreateInterfacePool(virNetworkDef *netdef) networkCreateInterfacePool(virNetworkDef *netdef)
{ {
size_t numVirtFns = 0; g_autoptr(virPCIVirtualFunctionList) vfs = NULL;
char **vfNames = NULL;
virPCIDeviceAddress **virtFns;
int ret = -1; int ret = -1;
size_t i; size_t i;
if (netdef->forward.npfs == 0 || netdef->forward.nifs > 0) if (netdef->forward.npfs == 0 || netdef->forward.nifs > 0)
return 0; return 0;
if ((virNetDevGetVirtualFunctions(netdef->forward.pfs->dev, &vfNames, if (virNetDevGetVirtualFunctions(netdef->forward.pfs->dev, &vfs) < 0) {
&virtFns, &numVirtFns)) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
_("Could not get Virtual functions on %s"), _("Could not get Virtual functions on %s"),
netdef->forward.pfs->dev); netdef->forward.pfs->dev);
goto cleanup; goto cleanup;
} }
netdef->forward.ifs = g_new0(virNetworkForwardIfDef, numVirtFns); netdef->forward.ifs = g_new0(virNetworkForwardIfDef, vfs->nfunctions);
for (i = 0; i < numVirtFns; i++) { for (i = 0; i < vfs->nfunctions; i++) {
virPCIDeviceAddress *thisVirtFn = virtFns[i]; virPCIDeviceAddress *thisVirtFn = vfs->functions[i].addr;
const char *thisName = vfNames[i]; const char *thisName = vfs->functions[i].ifname;
virNetworkForwardIfDef *thisIf virNetworkForwardIfDef *thisIf
= &netdef->forward.ifs[netdef->forward.nifs]; = &netdef->forward.ifs[netdef->forward.nifs];
@ -2689,12 +2685,6 @@ networkCreateInterfacePool(virNetworkDef *netdef)
if (netdef->forward.nifs == 0) if (netdef->forward.nifs == 0)
g_clear_pointer(&netdef->forward.ifs, g_free); 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; return ret;
} }

View File

@ -1213,24 +1213,17 @@ virNetDevGetPhysPortName(const char *ifname,
/** /**
* virNetDevGetVirtualFunctions: * virNetDevGetVirtualFunctions:
*
* @pfname : name of the physical function interface name * @pfname : name of the physical function interface name
* @vfname: array that will hold the interface names of the virtual_functions * @vfs: Filled with struct describing the virtual functions of @pfname
* @n_vfname: pointer to the number of virtual functions
* *
* Returns 0 on success and -1 on failure * Returns 0 on success and -1 on failure
*/ */
int int
virNetDevGetVirtualFunctions(const char *pfname, virNetDevGetVirtualFunctions(const char *pfname,
char ***vfname, virPCIVirtualFunctionList **vfs)
virPCIDeviceAddress ***virt_fns,
size_t *n_vfname)
{ {
size_t i;
g_autofree char *pf_sysfs_device_link = NULL; g_autofree char *pf_sysfs_device_link = NULL;
g_autofree char *pfPhysPortID = NULL; g_autofree char *pfPhysPortID = NULL;
g_autoptr(virPCIVirtualFunctionList) vfs = NULL;
if (virNetDevGetPhysPortID(pfname, &pfPhysPortID) < 0) if (virNetDevGetPhysPortID(pfname, &pfPhysPortID) < 0)
return -1; return -1;
@ -1238,18 +1231,9 @@ virNetDevGetVirtualFunctions(const char *pfname,
if (virNetDevSysfsFile(&pf_sysfs_device_link, pfname, "device") < 0) if (virNetDevSysfsFile(&pf_sysfs_device_link, pfname, "device") < 0)
return -1; return -1;
if (virPCIGetVirtualFunctionsFull(pf_sysfs_device_link, &vfs, pfPhysPortID) < 0) if (virPCIGetVirtualFunctionsFull(pf_sysfs_device_link, vfs, pfPhysPortID) < 0)
return -1; 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; return 0;
} }
@ -1448,9 +1432,7 @@ virNetDevGetPhysPortName(const char *ifname G_GNUC_UNUSED,
int int
virNetDevGetVirtualFunctions(const char *pfname G_GNUC_UNUSED, virNetDevGetVirtualFunctions(const char *pfname G_GNUC_UNUSED,
char ***vfname G_GNUC_UNUSED, virPCIVirtualFunctionList **vfs G_GNUC_UNUSED)
virPCIDeviceAddress ***virt_fns G_GNUC_UNUSED,
size_t *n_vfname G_GNUC_UNUSED)
{ {
virReportSystemError(ENOSYS, "%s", virReportSystemError(ENOSYS, "%s",
_("Unable to get virtual functions on this platform")); _("Unable to get virtual functions on this platform"));

View File

@ -252,11 +252,8 @@ int virNetDevGetPhysPortName(const char *ifname,
G_GNUC_WARN_UNUSED_RESULT; G_GNUC_WARN_UNUSED_RESULT;
int virNetDevGetVirtualFunctions(const char *pfname, int virNetDevGetVirtualFunctions(const char *pfname,
char ***vfname, virPCIVirtualFunctionList **vfs)
virPCIDeviceAddress ***virt_fns, ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) G_GNUC_WARN_UNUSED_RESULT;
size_t *n_vfname)
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3)
ATTRIBUTE_NONNULL(4) G_GNUC_WARN_UNUSED_RESULT;
int virNetDevSaveNetConfig(const char *linkdev, int vf, int virNetDevSaveNetConfig(const char *linkdev, int vf,
const char *stateDir, const char *stateDir,