diff options
author | Beniamino Galvani <bgalvani@redhat.com> | 2019-04-04 15:37:03 +0200 |
---|---|---|
committer | Beniamino Galvani <bgalvani@redhat.com> | 2019-04-04 15:37:03 +0200 |
commit | 9c049b3a0064f6054a816ad1de94a13f33a1db7f (patch) | |
tree | 4fd383d40603869bcb6f0e7a6fc17f1a628ea7b0 | |
parent | e7e5f4a2d6f5b55e1dd3aa26a64c361f25cd9787 (diff) | |
parent | 8698f512d793db2034745fbff4b5444287b1d48c (diff) | |
download | NetworkManager-9c049b3a0064f6054a816ad1de94a13f33a1db7f.tar.gz |
sriov: merge branch 'bg/sriov-drivers-autoprobe-rh1695093'
https://github.com/NetworkManager/NetworkManager/pull/331
https://bugzilla.redhat.com/show_bug.cgi?id=1695093
-rw-r--r-- | src/platform/nm-fake-platform.c | 9 | ||||
-rw-r--r-- | src/platform/nm-linux-platform.c | 34 | ||||
-rw-r--r-- | src/platform/nm-platform.c | 16 | ||||
-rw-r--r-- | src/platform/tests/test-link.c | 31 |
4 files changed, 78 insertions, 12 deletions
diff --git a/src/platform/nm-fake-platform.c b/src/platform/nm-fake-platform.c index 9dad647cfb..05f9667e97 100644 --- a/src/platform/nm-fake-platform.c +++ b/src/platform/nm-fake-platform.c @@ -154,10 +154,17 @@ static char * sysctl_get (NMPlatform *platform, const char *pathid, int dirfd, const char *path) { NMFakePlatformPrivate *priv = NM_FAKE_PLATFORM_GET_PRIVATE ((NMFakePlatform *) platform); + const char *v; ASSERT_SYSCTL_ARGS (pathid, dirfd, path); - return g_strdup (g_hash_table_lookup (priv->options, path)); + v = g_hash_table_lookup (priv->options, path); + if (!v) { + errno = ENOENT; + return NULL; + } + + return g_strdup (v); } static NMFakePlatformLink * diff --git a/src/platform/nm-linux-platform.c b/src/platform/nm-linux-platform.c index a35fa16a9d..e2f138e8aa 100644 --- a/src/platform/nm-linux-platform.c +++ b/src/platform/nm-linux-platform.c @@ -4618,22 +4618,31 @@ sysctl_get (NMPlatform *platform, const char *pathid, int dirfd, const char *pat ASSERT_SYSCTL_ARGS (pathid, dirfd, path); if (dirfd < 0) { - if (!nm_platform_netns_push (platform, &netns)) + if (!nm_platform_netns_push (platform, &netns)) { + errno = EBUSY; return NULL; + } pathid = path; } if (nm_utils_file_get_contents (dirfd, path, 1*1024*1024, NM_UTILS_FILE_GET_CONTENTS_FLAG_NONE, &contents, NULL, &error) < 0) { - /* We assume FAILED means EOPNOTSUP */ - if ( g_error_matches (error, G_FILE_ERROR, G_FILE_ERROR_NOENT) - || g_error_matches (error, G_FILE_ERROR, G_FILE_ERROR_NODEV) - || g_error_matches (error, G_FILE_ERROR, G_FILE_ERROR_FAILED)) - _LOGD ("error reading %s: %s", pathid, error->message); - else - _LOGE ("error reading %s: %s", pathid, error->message); + NMLogLevel log_level = LOGL_ERR; + int errsv = EBUSY; + + if (g_error_matches (error, G_FILE_ERROR, G_FILE_ERROR_NOENT)) { + errsv = ENOENT; + log_level = LOGL_DEBUG; + } else if ( g_error_matches (error, G_FILE_ERROR, G_FILE_ERROR_NODEV) + || g_error_matches (error, G_FILE_ERROR, G_FILE_ERROR_FAILED)) { + /* We assume FAILED means EOPNOTSUP and don't log a error message. */ + log_level = LOGL_DEBUG; + } + + _NMLOG (log_level, "error reading %s: %s", pathid, error->message); g_clear_error (&error); + errno = errsv; return NULL; } @@ -4641,6 +4650,7 @@ sysctl_get (NMPlatform *platform, const char *pathid, int dirfd, const char *pat _log_dbg_sysctl_get (platform, pathid, contents); + /* errno is left undefined (as we don't return NULL). */ return contents; } @@ -6652,6 +6662,14 @@ link_set_sriov_params (NMPlatform *platform, ifname, "device/sriov_drivers_autoprobe"), 10, 0, 1, -1); + + if ( current_autoprobe == -1 + && errno == ENOENT) { + /* older kernel versions don't have this sysctl. Assume the value is + * "1". */ + current_autoprobe = 1; + } + if ( current_num == num_vfs && (autoprobe == NM_TERNARY_DEFAULT || current_autoprobe == autoprobe)) return TRUE; diff --git a/src/platform/nm-platform.c b/src/platform/nm-platform.c index ffab6ac28c..4e6bf95882 100644 --- a/src/platform/nm-platform.c +++ b/src/platform/nm-platform.c @@ -469,6 +469,8 @@ nm_platform_sysctl_ip_conf_set_ipv6_hop_limit_safe (NMPlatform *self, * @path: Absolute path to sysctl * * Returns: (transfer full): Contents of the virtual sysctl file. + * + * If the path does not exist, %NULL is returned and %errno set to %ENOENT. */ char * nm_platform_sysctl_get (NMPlatform *self, const char *pathid, int dirfd, const char *path) @@ -518,6 +520,8 @@ nm_platform_sysctl_get_int32 (NMPlatform *self, const char *pathid, int dirfd, c * value. On success, %errno will be set to zero. The returned value * will always be in the range between @min and @max * (inclusive) or @fallback. + * If the file does not exist, the fallback is returned and %errno + * is set to ENOENT. */ gint64 nm_platform_sysctl_get_int_checked (NMPlatform *self, @@ -537,11 +541,17 @@ nm_platform_sysctl_get_int_checked (NMPlatform *self, g_return_val_if_fail (path, fallback); - if (path) - value = nm_platform_sysctl_get (self, pathid, dirfd, path); + if (!path) { + errno = EINVAL; + return fallback; + } + value = nm_platform_sysctl_get (self, pathid, dirfd, path); if (!value) { - errno = EINVAL; + /* nm_platform_sysctl_get() set errno to ENOENT if the file does not exist. + * Propagate/preserve that. */ + if (errno != ENOENT) + errno = EINVAL; return fallback; } diff --git a/src/platform/tests/test-link.c b/src/platform/tests/test-link.c index 71324301c7..03999fede3 100644 --- a/src/platform/tests/test-link.c +++ b/src/platform/tests/test-link.c @@ -2963,6 +2963,37 @@ test_sysctl_netns_switch (void) g_assert_cmpint (ifindex, ==, (gint32) nm_platform_sysctl_get_int32 (PL, NMP_SYSCTL_PATHID_NETDIR (dirfd, s ?: "<unknown>", "ifindex"), -1)); g_assert_cmpint (ifindex, ==, (gint32) nm_platform_sysctl_get_int32 (PL, NMP_SYSCTL_PATHID_ABSOLUTE (nm_sprintf_bufa (100, "/sys/class/net/%s/ifindex", IFNAME)), -1)); + /* also test that nm_platform_sysctl_get() sets errno to ENOENT for non-existing paths. */ + { + gint64 i64; + int errsv; + char *v; + + errno = ESRCH; + v = nm_platform_sysctl_get (PL, NMP_SYSCTL_PATHID_ABSOLUTE ("/sys/devices/virtual/net/not-existing/ifindex")); + errsv = errno; + g_assert (!v); + g_assert_cmpint (errsv, ==, ENOENT); + + errno = ESRCH; + i64 = nm_platform_sysctl_get_int_checked (PL, NMP_SYSCTL_PATHID_ABSOLUTE ("/sys/devices/virtual/net/not-existing/ifindex"), 10, 1, G_MAXINT, -1); + errsv = errno; + g_assert_cmpint (i64, ==, -1); + g_assert_cmpint (errsv, ==, ENOENT); + + errno = ESRCH; + v = nm_platform_sysctl_get (PL, NMP_SYSCTL_PATHID_ABSOLUTE ("/sys/devices/virtual/net/lo/not-existing")); + errsv = errno; + g_assert (!v); + g_assert_cmpint (errsv, ==, ENOENT); + + errno = ESRCH; + i64 = nm_platform_sysctl_get_int_checked (PL, NMP_SYSCTL_PATHID_ABSOLUTE ("/sys/devices/virtual/net/lo/not-existing"), 10, 1, G_MAXINT, -1); + errsv = errno; + g_assert_cmpint (i64, ==, -1); + g_assert_cmpint (errsv, ==, ENOENT); + } + /* accessing the path directly, only succeeds iff the current namespace happens to be the namespace * in which we created the link. */ { |