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];
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;
}
/**
* 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;
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;
}
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"));
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,