summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2017-11-28 10:53:12 +0100
committerThomas Haller <thaller@redhat.com>2017-11-28 10:56:39 +0100
commiteb95d6bbbb6982dac78949368fc8b2512aa906bb (patch)
treed02bedfed8337e5c1b6239a0ecbd9a7d166246a5
parentd23e050ef5c4ddd8be6b4a5a1d16ee4107f94507 (diff)
parent27e38c77dd7b2c222e98c1c8c32b18f86fd88046 (diff)
device: merge branch 'th/device-carrier-wait-timeout'
https://bugzilla.redhat.com/show_bug.cgi?id=1483343 https://bugzilla.redhat.com/show_bug.cgi?id=1487702 https://bugzilla.redhat.com/show_bug.cgi?id=1515027 https://bugzilla.gnome.org/show_bug.cgi?id=784854 (cherry picked from commit 2becc0a0ac82834ea96898c17ec79cd038e6db54)
-rw-r--r--man/NetworkManager.conf.xml18
-rw-r--r--src/devices/nm-device.c30
-rw-r--r--src/nm-config.h1
3 files changed, 41 insertions, 8 deletions
diff --git a/man/NetworkManager.conf.xml b/man/NetworkManager.conf.xml
index f0c3c5c85b..446540aa1b 100644
--- a/man/NetworkManager.conf.xml
+++ b/man/NetworkManager.conf.xml
@@ -856,6 +856,24 @@ managed=1
</para>
</listitem>
</varlistentry>
+ <varlistentry id="carrier-wait-timeout">
+ <term><varname>carrier-wait-timeout</varname></term>
+ <listitem>
+ <para>
+ Specify the timeout for waiting for carrier in milliseconds.
+ When the device loses carrier, NetworkManager does not react
+ immediately. Instead, it waits for this timeout before considering
+ the link lost. Also, on startup, NetworkManager considers the
+ device as busy for this time, as long as the device has no carrier.
+ This delays startup-complete signal and NetworkManager-wait-online.
+ Configuring this too high means to block NetworkManager-wait-online
+ longer then necessary. Configuring it too low, means that NetworkManager
+ will declare startup-complete, although carrier is about to come
+ and auto-activation to kick in.
+ The default is 5000 milliseconds.
+ </para>
+ </listitem>
+ </varlistentry>
<varlistentry id="ignore-carrier">
<term><varname>ignore-carrier</varname></term>
<listitem>
diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c
index 83dac056b2..0a942abc73 100644
--- a/src/devices/nm-device.c
+++ b/src/devices/nm-device.c
@@ -328,7 +328,7 @@ typedef struct _NMDevicePrivate {
guint32 v4_route_table;
guint32 v6_route_table;
- /* when carrier goes away, we give a grace period of CARRIER_WAIT_TIME_MS
+ /* when carrier goes away, we give a grace period of _get_carrier_wait_ms()
* until taking action.
*
* When changing MTU, the device might take longer then that. So, whenever
@@ -530,6 +530,7 @@ static gboolean addrconf6_start_with_link_ready (NMDevice *self);
static NMActStageReturn linklocal6_start (NMDevice *self);
static void _carrier_wait_check_queued_act_request (NMDevice *self);
+static gint64 _get_carrier_wait_ms (NMDevice *self);
static const char *_activation_func_to_string (ActivationHandleFunc func);
static void activation_source_handle_cb (NMDevice *self, int addr_family);
@@ -2464,8 +2465,6 @@ carrier_changed (NMDevice *self, gboolean carrier)
}
}
-#define LINK_DISCONNECT_DELAY 4
-
static gboolean
carrier_disconnected_action_cb (gpointer user_data)
{
@@ -2522,10 +2521,13 @@ nm_device_set_carrier (NMDevice *self, gboolean carrier)
_LOGD (LOGD_DEVICE, "carrier: link disconnected");
carrier_changed (self, FALSE);
} else {
- priv->carrier_defer_id = g_timeout_add_seconds (LINK_DISCONNECT_DELAY,
- carrier_disconnected_action_cb, self);
- _LOGD (LOGD_DEVICE, "carrier: link disconnected (deferring action for %d seconds) (id=%u)",
- LINK_DISCONNECT_DELAY, priv->carrier_defer_id);
+ gint64 now_ms, until_ms;
+
+ now_ms = nm_utils_get_monotonic_timestamp_ms ();
+ until_ms = NM_MAX (now_ms + _get_carrier_wait_ms (self), priv->carrier_wait_until_ms);
+ priv->carrier_defer_id = g_timeout_add (until_ms - now_ms, carrier_disconnected_action_cb, self);
+ _LOGD (LOGD_DEVICE, "carrier: link disconnected (deferring action for %ld milli seconds) (id=%u)",
+ (long) (until_ms - now_ms), priv->carrier_defer_id);
}
}
}
@@ -10697,6 +10699,18 @@ nm_device_is_up (NMDevice *self)
return ifindex > 0 ? nm_platform_link_is_up (nm_device_get_platform (self), ifindex) : TRUE;
}
+static gint64
+_get_carrier_wait_ms (NMDevice *self)
+{
+ gs_free char *value = NULL;
+
+ value = nm_config_data_get_device_config (NM_CONFIG_GET_DATA,
+ NM_CONFIG_KEYFILE_KEY_DEVICE_CARRIER_WAIT_TIMEOUT,
+ self,
+ NULL);
+ return _nm_utils_ascii_str_to_int64 (value, 10, 0, G_MAXINT32, CARRIER_WAIT_TIME_MS);
+}
+
gboolean
nm_device_bring_up (NMDevice *self, gboolean block, gboolean *no_firmware)
{
@@ -10771,7 +10785,7 @@ nm_device_bring_up (NMDevice *self, gboolean block, gboolean *no_firmware)
nm_device_add_pending_action (self, NM_PENDING_ACTION_CARRIER_WAIT, FALSE);
now_ms = nm_utils_get_monotonic_timestamp_ms ();
- until_ms = NM_MAX (now_ms + CARRIER_WAIT_TIME_MS, priv->carrier_wait_until_ms);
+ until_ms = NM_MAX (now_ms + _get_carrier_wait_ms (self), priv->carrier_wait_until_ms);
priv->carrier_wait_id = g_timeout_add (until_ms - now_ms, carrier_wait_timeout, self);
}
diff --git a/src/nm-config.h b/src/nm-config.h
index 17912185f7..8bdd5002d2 100644
--- a/src/nm-config.h
+++ b/src/nm-config.h
@@ -79,6 +79,7 @@
#define NM_CONFIG_KEYFILE_KEY_DEVICE_MANAGED "managed"
#define NM_CONFIG_KEYFILE_KEY_DEVICE_IGNORE_CARRIER "ignore-carrier"
#define NM_CONFIG_KEYFILE_KEY_DEVICE_SRIOV_NUM_VFS "sriov-num-vfs"
+#define NM_CONFIG_KEYFILE_KEY_DEVICE_CARRIER_WAIT_TIMEOUT "carrier-wait-timeout"
#define NM_CONFIG_KEYFILE_KEYPREFIX_WAS ".was."
#define NM_CONFIG_KEYFILE_KEYPREFIX_SET ".set."