Blame SOURCES/0005-device-fix-wait-carrier-rh1450444.patch

fc9aca
From fde61a81ee3ff70c85aed230bcfda79f2fb70ea8 Mon Sep 17 00:00:00 2001
fc9aca
From: Thomas Haller <thaller@redhat.com>
fc9aca
Date: Fri, 12 May 2017 16:17:18 +0200
fc9aca
Subject: [PATCH 1/7] device: don't call virtual function carrier_changed()
fc9aca
 directly
fc9aca
fc9aca
Don't give the subclass the ability to override the parents
fc9aca
behavior. The parent implementation is not intended to allow
fc9aca
for that. Instead, restrict the flexibility of how the virtual
fc9aca
function integrates with the larger picture. That means, the
fc9aca
virtual function is only called at one place, and there is only
fc9aca
one implementation in NMDeviceEthernet (and it doesn't really
fc9aca
matter whether the implementation chains up the parent implementation
fc9aca
or not).
fc9aca
fc9aca
(cherry picked from commit 5a7374d8be33086a5c00a450a472069595ba1734)
fc9aca
(cherry picked from commit e9aa3cc3575b8456eb712c0e06dc815940b49cbc)
fc9aca
---
fc9aca
 src/devices/nm-device-ethernet.c |  7 +++----
fc9aca
 src/devices/nm-device.c          | 17 ++++++++++++-----
fc9aca
 src/devices/nm-device.h          |  2 +-
fc9aca
 3 files changed, 16 insertions(+), 10 deletions(-)
fc9aca
fc9aca
diff --git a/src/devices/nm-device-ethernet.c b/src/devices/nm-device-ethernet.c
fc9aca
index 4c5aeb5..8a04d40 100644
fc9aca
--- a/src/devices/nm-device-ethernet.c
fc9aca
+++ b/src/devices/nm-device-ethernet.c
fc9aca
@@ -1597,12 +1597,11 @@ get_link_speed (NMDevice *device)
fc9aca
 }
fc9aca
 
fc9aca
 static void
fc9aca
-carrier_changed (NMDevice *device, gboolean carrier)
fc9aca
+carrier_changed_notify (NMDevice *device, gboolean carrier)
fc9aca
 {
fc9aca
 	if (carrier)
fc9aca
 		get_link_speed (device);
fc9aca
-
fc9aca
-	NM_DEVICE_CLASS (nm_device_ethernet_parent_class)->carrier_changed (device, carrier);
fc9aca
+	NM_DEVICE_CLASS (nm_device_ethernet_parent_class)->carrier_changed_notify (device, carrier);
fc9aca
 }
fc9aca
 
fc9aca
 static void
fc9aca
@@ -1764,7 +1763,7 @@ nm_device_ethernet_class_init (NMDeviceEthernetClass *klass)
fc9aca
 	parent_class->deactivate = deactivate;
fc9aca
 	parent_class->get_s390_subchannels = get_s390_subchannels;
fc9aca
 	parent_class->update_connection = update_connection;
fc9aca
-	parent_class->carrier_changed = carrier_changed;
fc9aca
+	parent_class->carrier_changed_notify = carrier_changed_notify;
fc9aca
 	parent_class->link_changed = link_changed;
fc9aca
 	parent_class->is_available = is_available;
fc9aca
 	parent_class->can_reapply_change = can_reapply_change;
fc9aca
diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c
fc9aca
index 9c30790..652bede 100644
fc9aca
--- a/src/devices/nm-device.c
fc9aca
+++ b/src/devices/nm-device.c
fc9aca
@@ -2168,10 +2168,18 @@ nm_device_update_dynamic_ip_setup (NMDevice *self)
fc9aca
 }
fc9aca
 
fc9aca
 static void
fc9aca
+carrier_changed_notify (NMDevice *self, gboolean carrier)
fc9aca
+{
fc9aca
+	/* stub */
fc9aca
+}
fc9aca
+
fc9aca
+static void
fc9aca
 carrier_changed (NMDevice *self, gboolean carrier)
fc9aca
 {
fc9aca
 	NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
fc9aca
 
fc9aca
+	NM_DEVICE_GET_CLASS (self)->carrier_changed_notify (self, carrier);
fc9aca
+
fc9aca
 	if (priv->state <= NM_DEVICE_STATE_UNMANAGED)
fc9aca
 		return;
fc9aca
 
fc9aca
@@ -2245,7 +2253,7 @@ link_disconnect_action_cb (gpointer user_data)
fc9aca
 
fc9aca
 	priv->carrier_defer_id = 0;
fc9aca
 
fc9aca
-	NM_DEVICE_GET_CLASS (self)->carrier_changed (self, FALSE);
fc9aca
+	carrier_changed (self, FALSE);
fc9aca
 
fc9aca
 	return FALSE;
fc9aca
 }
fc9aca
@@ -2266,7 +2274,6 @@ void
fc9aca
 nm_device_set_carrier (NMDevice *self, gboolean carrier)
fc9aca
 {
fc9aca
 	NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
fc9aca
-	NMDeviceClass *klass = NM_DEVICE_GET_CLASS (self);
fc9aca
 	NMDeviceState state = nm_device_get_state (self);
fc9aca
 
fc9aca
 	if (priv->carrier == carrier)
fc9aca
@@ -2278,7 +2285,7 @@ nm_device_set_carrier (NMDevice *self, gboolean carrier)
fc9aca
 	if (priv->carrier) {
fc9aca
 		_LOGI (LOGD_DEVICE, "link connected");
fc9aca
 		link_disconnect_action_cancel (self);
fc9aca
-		klass->carrier_changed (self, TRUE);
fc9aca
+		carrier_changed (self, TRUE);
fc9aca
 
fc9aca
 		if (nm_clear_g_source (&priv->carrier_wait_id)) {
fc9aca
 			nm_device_remove_pending_action (self, NM_PENDING_ACTION_CARRIER_WAIT, TRUE);
fc9aca
@@ -2287,7 +2294,7 @@ nm_device_set_carrier (NMDevice *self, gboolean carrier)
fc9aca
 	} else if (   state <= NM_DEVICE_STATE_DISCONNECTED
fc9aca
 	           && !priv->queued_act_request) {
fc9aca
 		_LOGD (LOGD_DEVICE, "link disconnected");
fc9aca
-		klass->carrier_changed (self, FALSE);
fc9aca
+		carrier_changed (self, FALSE);
fc9aca
 	} else {
fc9aca
 		priv->carrier_defer_id = g_timeout_add_seconds (LINK_DISCONNECT_DELAY,
fc9aca
 		                                                link_disconnect_action_cb, self);
fc9aca
@@ -14162,7 +14169,7 @@ nm_device_class_init (NMDeviceClass *klass)
fc9aca
 	klass->can_unmanaged_external_down = can_unmanaged_external_down;
fc9aca
 	klass->realize_start_notify = realize_start_notify;
fc9aca
 	klass->unrealize_notify = unrealize_notify;
fc9aca
-	klass->carrier_changed = carrier_changed;
fc9aca
+	klass->carrier_changed_notify = carrier_changed_notify;
fc9aca
 	klass->get_ip_iface_identifier = get_ip_iface_identifier;
fc9aca
 	klass->unmanaged_on_quit = unmanaged_on_quit;
fc9aca
 	klass->deactivate_reset_hw_addr = deactivate_reset_hw_addr;
fc9aca
diff --git a/src/devices/nm-device.h b/src/devices/nm-device.h
fc9aca
index be328eb..5e6abb4 100644
fc9aca
--- a/src/devices/nm-device.h
fc9aca
+++ b/src/devices/nm-device.h
fc9aca
@@ -261,7 +261,7 @@ typedef struct {
fc9aca
 	gboolean        (*can_unmanaged_external_down)  (NMDevice *self);
fc9aca
 
fc9aca
 	/* Carrier state (IFF_LOWER_UP) */
fc9aca
-	void            (*carrier_changed) (NMDevice *, gboolean carrier);
fc9aca
+	void            (*carrier_changed_notify) (NMDevice *, gboolean carrier);
fc9aca
 
fc9aca
 	gboolean    (* get_ip_iface_identifier) (NMDevice *self, NMUtilsIPv6IfaceId *out_iid);
fc9aca
 
fc9aca
-- 
fc9aca
2.9.4
fc9aca
fc9aca
fc9aca
From 02daf0bdd66115456c6d9ccbf99909996013239d Mon Sep 17 00:00:00 2001
fc9aca
From: Thomas Haller <thaller@redhat.com>
fc9aca
Date: Fri, 12 May 2017 16:21:55 +0200
fc9aca
Subject: [PATCH 2/7] device/trivial: rename functions related to "carrier"
fc9aca
fc9aca
(cherry picked from commit a07c6255a02e098dae934ee0e6765e1ce5b927ae)
fc9aca
(cherry picked from commit 0ed6b5bfff4d8a915e69866d15027d26e3785271)
fc9aca
---
fc9aca
 src/devices/nm-device.c | 14 +++++++++-----
fc9aca
 1 file changed, 9 insertions(+), 5 deletions(-)
fc9aca
fc9aca
diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c
fc9aca
index 652bede..e615f32 100644
fc9aca
--- a/src/devices/nm-device.c
fc9aca
+++ b/src/devices/nm-device.c
fc9aca
@@ -2167,6 +2167,8 @@ nm_device_update_dynamic_ip_setup (NMDevice *self)
fc9aca
 	}
fc9aca
 }
fc9aca
 
fc9aca
+/*****************************************************************************/
fc9aca
+
fc9aca
 static void
fc9aca
 carrier_changed_notify (NMDevice *self, gboolean carrier)
fc9aca
 {
fc9aca
@@ -2244,7 +2246,7 @@ carrier_changed (NMDevice *self, gboolean carrier)
fc9aca
 #define LINK_DISCONNECT_DELAY 4
fc9aca
 
fc9aca
 static gboolean
fc9aca
-link_disconnect_action_cb (gpointer user_data)
fc9aca
+carrier_disconnected_action_cb (gpointer user_data)
fc9aca
 {
fc9aca
 	NMDevice *self = NM_DEVICE (user_data);
fc9aca
 	NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
fc9aca
@@ -2259,7 +2261,7 @@ link_disconnect_action_cb (gpointer user_data)
fc9aca
 }
fc9aca
 
fc9aca
 static void
fc9aca
-link_disconnect_action_cancel (NMDevice *self)
fc9aca
+carrier_disconnected_action_cancel (NMDevice *self)
fc9aca
 {
fc9aca
 	NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
fc9aca
 
fc9aca
@@ -2284,7 +2286,7 @@ nm_device_set_carrier (NMDevice *self, gboolean carrier)
fc9aca
 
fc9aca
 	if (priv->carrier) {
fc9aca
 		_LOGI (LOGD_DEVICE, "link connected");
fc9aca
-		link_disconnect_action_cancel (self);
fc9aca
+		carrier_disconnected_action_cancel (self);
fc9aca
 		carrier_changed (self, TRUE);
fc9aca
 
fc9aca
 		if (nm_clear_g_source (&priv->carrier_wait_id)) {
fc9aca
@@ -2297,12 +2299,14 @@ nm_device_set_carrier (NMDevice *self, gboolean carrier)
fc9aca
 		carrier_changed (self, FALSE);
fc9aca
 	} else {
fc9aca
 		priv->carrier_defer_id = g_timeout_add_seconds (LINK_DISCONNECT_DELAY,
fc9aca
-		                                                link_disconnect_action_cb, self);
fc9aca
+		                                                carrier_disconnected_action_cb, self);
fc9aca
 		_LOGD (LOGD_DEVICE, "link disconnected (deferring action for %d seconds) (id=%u)",
fc9aca
 		       LINK_DISCONNECT_DELAY, priv->carrier_defer_id);
fc9aca
 	}
fc9aca
 }
fc9aca
 
fc9aca
+/*****************************************************************************/
fc9aca
+
fc9aca
 static void
fc9aca
 device_recheck_slave_status (NMDevice *self, const NMPlatformLink *plink)
fc9aca
 {
fc9aca
@@ -13775,7 +13779,7 @@ dispose (GObject *object)
fc9aca
 
fc9aca
 	nm_clear_g_source (&priv->stats.timeout_id);
fc9aca
 
fc9aca
-	link_disconnect_action_cancel (self);
fc9aca
+	carrier_disconnected_action_cancel (self);
fc9aca
 
fc9aca
 	if (priv->ifindex > 0) {
fc9aca
 		priv->ifindex = 0;
fc9aca
-- 
fc9aca
2.9.4
fc9aca
fc9aca
fc9aca
From 5385cb00a8686c55e84f1924038ec20102939ac9 Mon Sep 17 00:00:00 2001
fc9aca
From: Thomas Haller <thaller@redhat.com>
fc9aca
Date: Fri, 12 May 2017 16:22:47 +0200
fc9aca
Subject: [PATCH 3/7] device: minor cleanup of
fc9aca
 carrier_disconnected_action_cancel()
fc9aca
fc9aca
(cherry picked from commit 6c5d883a4bd9ef167ee4fe8ec2b0187c7bc77142)
fc9aca
(cherry picked from commit 62f1875766a181528c36596b7bd16a78663879cc)
fc9aca
---
fc9aca
 src/devices/nm-device.c | 10 ++++------
fc9aca
 1 file changed, 4 insertions(+), 6 deletions(-)
fc9aca
fc9aca
diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c
fc9aca
index e615f32..dabe87e 100644
fc9aca
--- a/src/devices/nm-device.c
fc9aca
+++ b/src/devices/nm-device.c
fc9aca
@@ -2254,9 +2254,7 @@ carrier_disconnected_action_cb (gpointer user_data)
fc9aca
 	_LOGD (LOGD_DEVICE, "link disconnected (calling deferred action) (id=%u)", priv->carrier_defer_id);
fc9aca
 
fc9aca
 	priv->carrier_defer_id = 0;
fc9aca
-
fc9aca
 	carrier_changed (self, FALSE);
fc9aca
-
fc9aca
 	return FALSE;
fc9aca
 }
fc9aca
 
fc9aca
@@ -2264,11 +2262,11 @@ static void
fc9aca
 carrier_disconnected_action_cancel (NMDevice *self)
fc9aca
 {
fc9aca
 	NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
fc9aca
+	guint id = priv->carrier_defer_id;
fc9aca
 
fc9aca
-	if (priv->carrier_defer_id) {
fc9aca
-		g_source_remove (priv->carrier_defer_id);
fc9aca
-		_LOGD (LOGD_DEVICE, "link disconnected (canceling deferred action) (id=%u)", priv->carrier_defer_id);
fc9aca
-		priv->carrier_defer_id = 0;
fc9aca
+	if (nm_clear_g_source (&priv->carrier_defer_id)) {
fc9aca
+		_LOGD (LOGD_DEVICE, "link disconnected (canceling deferred action) (id=%u)",
fc9aca
+		       id);
fc9aca
 	}
fc9aca
 }
fc9aca
 
fc9aca
-- 
fc9aca
2.9.4
fc9aca
fc9aca
fc9aca
From 68703df31190d899d881490ce3f0742890a3f5d2 Mon Sep 17 00:00:00 2001
fc9aca
From: Thomas Haller <thaller@redhat.com>
fc9aca
Date: Fri, 12 May 2017 16:48:57 +0200
fc9aca
Subject: [PATCH 4/7] device: downgrade logging messages about (non) pending
fc9aca
 action
fc9aca
fc9aca
Adding/Removing a pending action with assert_not_yet_pending/
fc9aca
assert_is_pending means that we expect that no action is taken.
fc9aca
fc9aca
Downgrade the logging level in those cases to <trace>.
fc9aca
fc9aca
(cherry picked from commit eaba285375248a691aaa896fecdd991ad695c1b1)
fc9aca
(cherry picked from commit f4600c7fa5afd960fb3657ca6d694e56f5dc5dac)
fc9aca
---
fc9aca
 src/devices/nm-device.c | 4 ++--
fc9aca
 1 file changed, 2 insertions(+), 2 deletions(-)
fc9aca
fc9aca
diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c
fc9aca
index dabe87e..d58c50d 100644
fc9aca
--- a/src/devices/nm-device.c
fc9aca
+++ b/src/devices/nm-device.c
fc9aca
@@ -11821,7 +11821,7 @@ nm_device_add_pending_action (NMDevice *self, const char *action, gboolean asser
fc9aca
 				       count + g_slist_length (iter), action);
fc9aca
 				g_return_val_if_reached (FALSE);
fc9aca
 			} else {
fc9aca
-				_LOGD (LOGD_DEVICE, "add_pending_action (%d): '%s' already pending (expected)",
fc9aca
+				_LOGT (LOGD_DEVICE, "add_pending_action (%d): '%s' already pending (expected)",
fc9aca
 				       count + g_slist_length (iter), action);
fc9aca
 			}
fc9aca
 			return FALSE;
fc9aca
@@ -11882,7 +11882,7 @@ nm_device_remove_pending_action (NMDevice *self, const char *action, gboolean as
fc9aca
 		_LOGW (LOGD_DEVICE, "remove_pending_action (%d): '%s' not pending", count, action);
fc9aca
 		g_return_val_if_reached (FALSE);
fc9aca
 	} else
fc9aca
-		_LOGD (LOGD_DEVICE, "remove_pending_action (%d): '%s' not pending (expected)", count, action);
fc9aca
+		_LOGT (LOGD_DEVICE, "remove_pending_action (%d): '%s' not pending (expected)", count, action);
fc9aca
 
fc9aca
 	return FALSE;
fc9aca
 }
fc9aca
-- 
fc9aca
2.9.4
fc9aca
fc9aca
fc9aca
From 8615608b36b72f8c47ae813583bad31ae7f7ec0c Mon Sep 17 00:00:00 2001
fc9aca
From: Thomas Haller <thaller@redhat.com>
fc9aca
Date: Sun, 14 May 2017 22:08:26 +0200
fc9aca
Subject: [PATCH 5/7] device: rename and minor refactoring of check_carrier()
fc9aca
fc9aca
The name should mirror what we already have: nm_device_set_carrier().
fc9aca
Also, move the code closer to nm_device_set_carrier() and refactor
fc9aca
it a bit.
fc9aca
fc9aca
(cherry picked from commit 7e472b4eb36347684e81e1c3a2bd7348e19eb628)
fc9aca
(cherry picked from commit 83c2243d800fb20a651f787b65e6c5586a6f970d)
fc9aca
---
fc9aca
 src/devices/nm-device.c | 23 ++++++++++++-----------
fc9aca
 1 file changed, 12 insertions(+), 11 deletions(-)
fc9aca
fc9aca
diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c
fc9aca
index d58c50d..4a330d0 100644
fc9aca
--- a/src/devices/nm-device.c
fc9aca
+++ b/src/devices/nm-device.c
fc9aca
@@ -2303,6 +2303,16 @@ nm_device_set_carrier (NMDevice *self, gboolean carrier)
fc9aca
 	}
fc9aca
 }
fc9aca
 
fc9aca
+static void
fc9aca
+nm_device_set_carrier_from_platform (NMDevice *self)
fc9aca
+{
fc9aca
+	if (!nm_device_has_capability (self, NM_DEVICE_CAP_NONSTANDARD_CARRIER)) {
fc9aca
+		nm_device_set_carrier (self,
fc9aca
+		                       nm_platform_link_is_connected (nm_device_get_platform (self),
fc9aca
+		                                                      nm_device_get_ip_ifindex (self)));
fc9aca
+	}
fc9aca
+}
fc9aca
+
fc9aca
 /*****************************************************************************/
fc9aca
 
fc9aca
 static void
fc9aca
@@ -2881,15 +2891,6 @@ config_changed (NMConfig *config,
fc9aca
 }
fc9aca
 
fc9aca
 static void
fc9aca
-check_carrier (NMDevice *self)
fc9aca
-{
fc9aca
-	int ifindex = nm_device_get_ip_ifindex (self);
fc9aca
-
fc9aca
-	if (!nm_device_has_capability (self, NM_DEVICE_CAP_NONSTANDARD_CARRIER))
fc9aca
-		nm_device_set_carrier (self, nm_platform_link_is_connected (nm_device_get_platform (self), ifindex));
fc9aca
-}
fc9aca
-
fc9aca
-static void
fc9aca
 realize_start_notify (NMDevice *self,
fc9aca
                       const NMPlatformLink *pllink)
fc9aca
 {
fc9aca
@@ -3020,7 +3021,7 @@ realize_start_setup (NMDevice *self,
fc9aca
 	}
fc9aca
 
fc9aca
 	if (nm_device_has_capability (self, NM_DEVICE_CAP_CARRIER_DETECT)) {
fc9aca
-		check_carrier (self);
fc9aca
+		nm_device_set_carrier_from_platform (self);
fc9aca
 		_LOGD (LOGD_PLATFORM,
fc9aca
 		       "carrier is %s%s",
fc9aca
 		       priv->carrier ? "ON" : "OFF",
fc9aca
@@ -10343,7 +10344,7 @@ nm_device_bring_up (NMDevice *self, gboolean block, gboolean *no_firmware)
fc9aca
 
fc9aca
 	/* Store carrier immediately. */
fc9aca
 	if (nm_device_has_capability (self, NM_DEVICE_CAP_CARRIER_DETECT))
fc9aca
-		check_carrier (self);
fc9aca
+		nm_device_set_carrier_from_platform (self);
fc9aca
 
fc9aca
 	device_is_up = nm_device_is_up (self);
fc9aca
 	if (block && !device_is_up) {
fc9aca
-- 
fc9aca
2.9.4
fc9aca
fc9aca
fc9aca
From 1520c770db02577c54bf25736adba5d344378568 Mon Sep 17 00:00:00 2001
fc9aca
From: Thomas Haller <thaller@redhat.com>
fc9aca
Date: Mon, 15 May 2017 11:35:41 +0200
fc9aca
Subject: [PATCH 6/7] device: cleanup nm_device_set_carrier_from_platform()
fc9aca
fc9aca
nm_device_set_carrier_from_platform() is only called from two places.
fc9aca
fc9aca
- both check for NM_DEVICE_CAP_CARRIER_DETECT, so move that check
fc9aca
  inside the function.
fc9aca
- drop the logging in realize_start_setup(). nm_device_set_carrier() already
fc9aca
  does logging.
fc9aca
- always set the fake carrier in nm_device_set_carrier_from_platform().
fc9aca
  For the fake carrer, we anyway expect it to be already TRUE in most
fc9aca
  case, so usually this should have no effect.
fc9aca
  Also emit a property changed signal. That is necessary to refresh the
fc9aca
  D-Bus property.
fc9aca
fc9aca
(cherry picked from commit 02bb4ce7eb518bf955ed802511f1efde921bc919)
fc9aca
(cherry picked from commit 3786e17c0f86561e23779490ec5032b432aa7178)
fc9aca
---
fc9aca
 src/devices/nm-device.c | 32 ++++++++++++++++----------------
fc9aca
 1 file changed, 16 insertions(+), 16 deletions(-)
fc9aca
fc9aca
diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c
fc9aca
index 4a330d0..851e0a3 100644
fc9aca
--- a/src/devices/nm-device.c
fc9aca
+++ b/src/devices/nm-device.c
fc9aca
@@ -2306,10 +2306,20 @@ nm_device_set_carrier (NMDevice *self, gboolean carrier)
fc9aca
 static void
fc9aca
 nm_device_set_carrier_from_platform (NMDevice *self)
fc9aca
 {
fc9aca
-	if (!nm_device_has_capability (self, NM_DEVICE_CAP_NONSTANDARD_CARRIER)) {
fc9aca
-		nm_device_set_carrier (self,
fc9aca
-		                       nm_platform_link_is_connected (nm_device_get_platform (self),
fc9aca
-		                                                      nm_device_get_ip_ifindex (self)));
fc9aca
+	if (nm_device_has_capability (self, NM_DEVICE_CAP_CARRIER_DETECT)) {
fc9aca
+		if (!nm_device_has_capability (self, NM_DEVICE_CAP_NONSTANDARD_CARRIER)) {
fc9aca
+			nm_device_set_carrier (self,
fc9aca
+			                       nm_platform_link_is_connected (nm_device_get_platform (self),
fc9aca
+			                                                      nm_device_get_ip_ifindex (self)));
fc9aca
+		}
fc9aca
+	} else {
fc9aca
+		NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
fc9aca
+
fc9aca
+		/* Fake online link when carrier detection is not available. */
fc9aca
+		if (!priv->carrier) {
fc9aca
+			priv->carrier = TRUE;
fc9aca
+			_notify (self, PROP_CARRIER);
fc9aca
+		}
fc9aca
 	}
fc9aca
 }
fc9aca
 
fc9aca
@@ -3020,16 +3030,7 @@ realize_start_setup (NMDevice *self,
fc9aca
 		                                            self);
fc9aca
 	}
fc9aca
 
fc9aca
-	if (nm_device_has_capability (self, NM_DEVICE_CAP_CARRIER_DETECT)) {
fc9aca
-		nm_device_set_carrier_from_platform (self);
fc9aca
-		_LOGD (LOGD_PLATFORM,
fc9aca
-		       "carrier is %s%s",
fc9aca
-		       priv->carrier ? "ON" : "OFF",
fc9aca
-		       priv->ignore_carrier ? " (but ignored)" : "");
fc9aca
-	} else {
fc9aca
-		/* Fake online link when carrier detection is not available. */
fc9aca
-		priv->carrier = TRUE;
fc9aca
-	}
fc9aca
+	nm_device_set_carrier_from_platform (self);
fc9aca
 
fc9aca
 	device_init_sriov_num_vfs (self);
fc9aca
 
fc9aca
@@ -10343,8 +10344,7 @@ nm_device_bring_up (NMDevice *self, gboolean block, gboolean *no_firmware)
fc9aca
 	}
fc9aca
 
fc9aca
 	/* Store carrier immediately. */
fc9aca
-	if (nm_device_has_capability (self, NM_DEVICE_CAP_CARRIER_DETECT))
fc9aca
-		nm_device_set_carrier_from_platform (self);
fc9aca
+	nm_device_set_carrier_from_platform (self);
fc9aca
 
fc9aca
 	device_is_up = nm_device_is_up (self);
fc9aca
 	if (block && !device_is_up) {
fc9aca
-- 
fc9aca
2.9.4
fc9aca
fc9aca
fc9aca
From 15bb8709410d829c63b502ac845b93a8c95c3f15 Mon Sep 17 00:00:00 2001
fc9aca
From: Thomas Haller <thaller@redhat.com>
fc9aca
Date: Fri, 12 May 2017 16:32:15 +0200
fc9aca
Subject: [PATCH 7/7] device: fix delaying startup complete waiting for carrier
fc9aca
fc9aca
    platform: signal: link changed: 2: eth0 <DOWN;broadcast,multicast> mtu ...
fc9aca
    ...
fc9aca
    device[0x7f90c29c64d0] (eth0): bringing up device
fc9aca
    ...
fc9aca
    platform: signal: link changed: 2: eth0 <UP,LOWER_UP;broadcast,multicast,up,running,lowerup> mtu ...
fc9aca
    ...
fc9aca
    device (eth0): link connected
fc9aca
    ...
fc9aca
    device[0x7f90c29c64d0] (eth0): add_pending_action (2): 'carrier wait'
fc9aca
fc9aca
Note how we schedule the pending action 'carrier-wait', although the device
fc9aca
already has carrier. That means, the pending action will not be removed
fc9aca
until timeout, 5 seconds later.
fc9aca
fc9aca
Avoid scheduling 'carrier-wait' if we already have carrier.
fc9aca
fc9aca
However, don't just add the pending action 'carrier-wait' only during
fc9aca
nm_device_bring_up(). Instead, always schedule the carrier_wait timeout.
fc9aca
This gives a grace period during which we keep setting 'carrier-wait' whenever
fc9aca
we have no carrier. This should prevent two cases:
fc9aca
  - during nm_device_bring_up() the platform state might not yet have
fc9aca
    caught up. If we don't add the pending action there, we will add
fc9aca
    it a moment later when carrier goes away.
fc9aca
  - bringing the interface up might cause carrier to get lost for a
fc9aca
    moment (flapping). If that happens within the timeout, also add the
fc9aca
    pending action.
fc9aca
fc9aca
(cherry picked from commit 9f874d166d260bb4b9af32cb8d12d287341a9a8b)
fc9aca
(cherry picked from commit 51a1fc3cd9f281f1348cf0ec1ea17d4d03ecd0b7)
fc9aca
---
fc9aca
 src/devices/nm-device.c | 47 +++++++++++++++++++++++++++++------------------
fc9aca
 1 file changed, 29 insertions(+), 18 deletions(-)
fc9aca
fc9aca
diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c
fc9aca
index 851e0a3..8540b4c 100644
fc9aca
--- a/src/devices/nm-device.c
fc9aca
+++ b/src/devices/nm-device.c
fc9aca
@@ -2287,19 +2287,23 @@ nm_device_set_carrier (NMDevice *self, gboolean carrier)
fc9aca
 		carrier_disconnected_action_cancel (self);
fc9aca
 		carrier_changed (self, TRUE);
fc9aca
 
fc9aca
-		if (nm_clear_g_source (&priv->carrier_wait_id)) {
fc9aca
-			nm_device_remove_pending_action (self, NM_PENDING_ACTION_CARRIER_WAIT, TRUE);
fc9aca
+		if (priv->carrier_wait_id) {
fc9aca
+			nm_device_remove_pending_action (self, NM_PENDING_ACTION_CARRIER_WAIT, FALSE);
fc9aca
 			_carrier_wait_check_queued_act_request (self);
fc9aca
 		}
fc9aca
-	} else if (   state <= NM_DEVICE_STATE_DISCONNECTED
fc9aca
-	           && !priv->queued_act_request) {
fc9aca
-		_LOGD (LOGD_DEVICE, "link disconnected");
fc9aca
-		carrier_changed (self, FALSE);
fc9aca
 	} else {
fc9aca
-		priv->carrier_defer_id = g_timeout_add_seconds (LINK_DISCONNECT_DELAY,
fc9aca
-		                                                carrier_disconnected_action_cb, self);
fc9aca
-		_LOGD (LOGD_DEVICE, "link disconnected (deferring action for %d seconds) (id=%u)",
fc9aca
-		       LINK_DISCONNECT_DELAY, priv->carrier_defer_id);
fc9aca
+		if (priv->carrier_wait_id)
fc9aca
+			nm_device_add_pending_action (self, NM_PENDING_ACTION_CARRIER_WAIT, FALSE);
fc9aca
+		if (   state <= NM_DEVICE_STATE_DISCONNECTED
fc9aca
+		    && !priv->queued_act_request) {
fc9aca
+			_LOGD (LOGD_DEVICE, "link disconnected");
fc9aca
+			carrier_changed (self, FALSE);
fc9aca
+		} else {
fc9aca
+			priv->carrier_defer_id = g_timeout_add_seconds (LINK_DISCONNECT_DELAY,
fc9aca
+			                                                carrier_disconnected_action_cb, self);
fc9aca
+			_LOGD (LOGD_DEVICE, "link disconnected (deferring action for %d seconds) (id=%u)",
fc9aca
+			       LINK_DISCONNECT_DELAY, priv->carrier_defer_id);
fc9aca
+		}
fc9aca
 	}
fc9aca
 }
fc9aca
 
fc9aca
@@ -10297,12 +10301,12 @@ static gboolean
fc9aca
 carrier_wait_timeout (gpointer user_data)
fc9aca
 {
fc9aca
 	NMDevice *self = NM_DEVICE (user_data);
fc9aca
+	NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
fc9aca
 
fc9aca
-	NM_DEVICE_GET_PRIVATE (self)->carrier_wait_id = 0;
fc9aca
-	nm_device_remove_pending_action (self, NM_PENDING_ACTION_CARRIER_WAIT, TRUE);
fc9aca
-
fc9aca
-	_carrier_wait_check_queued_act_request (self);
fc9aca
-
fc9aca
+	priv->carrier_wait_id = 0;
fc9aca
+	nm_device_remove_pending_action (self, NM_PENDING_ACTION_CARRIER_WAIT, FALSE);
fc9aca
+	if (!priv->carrier)
fc9aca
+		_carrier_wait_check_queued_act_request (self);
fc9aca
 	return G_SOURCE_REMOVE;
fc9aca
 }
fc9aca
 
fc9aca
@@ -10379,8 +10383,14 @@ nm_device_bring_up (NMDevice *self, gboolean block, gboolean *no_firmware)
fc9aca
 	 * a timeout is reached.
fc9aca
 	 */
fc9aca
 	if (nm_device_has_capability (self, NM_DEVICE_CAP_CARRIER_DETECT)) {
fc9aca
-		if (!nm_clear_g_source (&priv->carrier_wait_id))
fc9aca
-			nm_device_add_pending_action (self, NM_PENDING_ACTION_CARRIER_WAIT, TRUE);
fc9aca
+		/* we start a grace period of 5 seconds during which we will schedule
fc9aca
+		 * a pending action whenever we have no carrier.
fc9aca
+		 *
fc9aca
+		 * If during that time carrier goes away, we declare the interface
fc9aca
+		 * as not ready. */
fc9aca
+		nm_clear_g_source (&priv->carrier_wait_id);
fc9aca
+		if (!priv->carrier)
fc9aca
+			nm_device_add_pending_action (self, NM_PENDING_ACTION_CARRIER_WAIT, FALSE);
fc9aca
 		priv->carrier_wait_id = g_timeout_add_seconds (5, carrier_wait_timeout, self);
fc9aca
 	}
fc9aca
 
fc9aca
@@ -13793,7 +13803,8 @@ dispose (GObject *object)
fc9aca
 
fc9aca
 	available_connections_del_all (self);
fc9aca
 
fc9aca
-	nm_clear_g_source (&priv->carrier_wait_id);
fc9aca
+	if (nm_clear_g_source (&priv->carrier_wait_id))
fc9aca
+		nm_device_remove_pending_action (self, NM_PENDING_ACTION_CARRIER_WAIT, FALSE);
fc9aca
 
fc9aca
 	_clear_queued_act_request (priv);
fc9aca
 
fc9aca
-- 
fc9aca
2.9.4
fc9aca