platform: do not rely on the presence of sriov_totalvfs sysfs file

The file doesn't exist for all interfaces that support SR-IOV. In
particular, netdevsim devices support SR-IOV but don't expose the
file.
This commit is contained in:
Beniamino Galvani 2020-06-25 11:43:14 +02:00
parent 3a3c436571
commit 63a932b851

View file

@ -7254,7 +7254,7 @@ link_supports_sriov (NMPlatform *platform, int ifindex)
nm_auto_pop_netns NMPNetns *netns = NULL;
nm_auto_close int dirfd = -1;
char ifname[IFNAMSIZ];
int total = -1;
int num = -1;
if (!nm_platform_netns_push (platform, &netns))
return FALSE;
@ -7263,13 +7263,13 @@ link_supports_sriov (NMPlatform *platform, int ifindex)
if (dirfd < 0)
return FALSE;
total = nm_platform_sysctl_get_int32 (platform,
NMP_SYSCTL_PATHID_NETDIR (dirfd,
ifname,
"device/sriov_totalvfs"),
-1);
num = nm_platform_sysctl_get_int32 (platform,
NMP_SYSCTL_PATHID_NETDIR (dirfd,
ifname,
"device/sriov_numvfs"),
-1);
return total > 0;
return num != -1;
}
static int
@ -7412,15 +7412,7 @@ link_set_sriov_params_async (NMPlatform *platform,
ifname,
"device/sriov_totalvfs"),
10, 0, G_MAXUINT, 0);
if (errno) {
g_set_error (&error,
NM_UTILS_ERROR,
NM_UTILS_ERROR_UNKNOWN,
"failed reading sriov_totalvfs value: %s",
nm_strerror_native (errno));
goto out_idle;
}
if (num_vfs > total) {
if (!errno && num_vfs > total) {
_LOGW ("link: %d only supports %u VFs (requested %u)", ifindex, total, num_vfs);
num_vfs = total;
}