summaryrefslogtreecommitdiff
path: root/src/platform/nm-linux-platform.c
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2019-05-02 17:13:51 +0200
committerThomas Haller <thaller@redhat.com>2019-05-06 08:59:44 +0200
commit5185dd3145c0c411d452ba525c683227e6f990c0 (patch)
tree82ca5caaffae979ee13daece632f6e282433ebcc /src/platform/nm-linux-platform.c
parentb28345586327ad48c0fefb769f920fb11b005fb6 (diff)
downloadNetworkManager-th/ethtool-retry.tar.gz
platform/ethtool,mii: retry ioctl when interface name was renamed for ehttool/miith/ethtool-retry
ethtool/mii API is based on the ifname. As an interface can be renamed, this API is inherently racy. We would prefer to use the ifindex instead. The ifindex of a device cannot change (altough it can repeat, which opens a different race *sigh*). Anyway, we were already trying to minimize the racy be resolving the name from ifindex immediately before the call to ethtool/mii. Do better than that. Now resolve the name before and after the call. If the name changed in the meantime, we have an indication that a race happend (but we cannot be sure). Note that this can not catch every possible rename race. If you are very unlucky a swapping of names cannot be detected. For getters this is relatively straight forward. Just retry when we have an indication to fall victim to a race (up to a few times). Yes, we still cannot be 100% sure, but this should be very reliable in practice. For setters (that modify the device) we also retry. We do so under the assumption that setting the same options multiple times has no bad effect. Note that for setters the race of swapping interface names is particularly bad. If we hit a very unlucky race condition, we might set the setting on the wrong interface and there is nothing we can do about it. The retry only ensures that eventually we will set it on the right interface. Note that this involves one more if_indextoname() call for each operation (in the common case when there is no renaming race). In cases where we require multiple ioctl calls we cache and reuse the information though. So, for such calls the overhead is even smaller.
Diffstat (limited to 'src/platform/nm-linux-platform.c')
-rw-r--r--src/platform/nm-linux-platform.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/src/platform/nm-linux-platform.c b/src/platform/nm-linux-platform.c
index 6064d89eb6..a11ebcc163 100644
--- a/src/platform/nm-linux-platform.c
+++ b/src/platform/nm-linux-platform.c
@@ -6514,7 +6514,8 @@ link_supports_carrier_detect (NMPlatform *platform, int ifindex)
* us whether the device actually supports carrier detection in the first
* place. We assume any device that does implements one of these two APIs.
*/
- return nmp_utils_ethtool_supports_carrier_detect (ifindex) || nmp_utils_mii_supports_carrier_detect (ifindex);
+ return nmp_utils_ethtool_supports_carrier_detect (ifindex)
+ || nmp_utils_mii_supports_carrier_detect (ifindex);
}
static gboolean