device: use GSource for tracking carrier-wait timeout

This commit is contained in:
Thomas Haller 2023-06-06 19:00:16 +02:00
parent 6a54041ae1
commit 1ef58332b2
No known key found for this signature in database
GPG key ID: 29C2366E4DFC5728

View file

@ -536,9 +536,9 @@ typedef struct _NMDevicePrivate {
/* Link stuff */ /* Link stuff */
guint link_connected_id; guint link_connected_id;
guint link_disconnected_id; guint link_disconnected_id;
guint carrier_wait_id;
gulong config_changed_id; gulong config_changed_id;
gulong ifindex_changed_id; gulong ifindex_changed_id;
GSource *carrier_wait_source;
GSource *carrier_defer_source; GSource *carrier_defer_source;
guint32 mtu; guint32 mtu;
guint32 ip6_mtu; /* FIXME(l3cfg) */ guint32 ip6_mtu; /* FIXME(l3cfg) */
@ -6680,12 +6680,12 @@ nm_device_set_carrier(NMDevice *self, gboolean carrier)
NM_DEVICE_GET_CLASS(self)->carrier_changed_notify(self, carrier); NM_DEVICE_GET_CLASS(self)->carrier_changed_notify(self, carrier);
carrier_changed(self, TRUE); carrier_changed(self, TRUE);
if (priv->carrier_wait_id) { if (priv->carrier_wait_source) {
nm_device_remove_pending_action(self, NM_PENDING_ACTION_CARRIER_WAIT, FALSE); nm_device_remove_pending_action(self, NM_PENDING_ACTION_CARRIER_WAIT, FALSE);
_carrier_wait_check_queued_act_request(self); _carrier_wait_check_queued_act_request(self);
} }
} else { } else {
if (priv->carrier_wait_id) if (priv->carrier_wait_source)
nm_device_add_pending_action(self, NM_PENDING_ACTION_CARRIER_WAIT, FALSE); nm_device_add_pending_action(self, NM_PENDING_ACTION_CARRIER_WAIT, FALSE);
NM_DEVICE_GET_CLASS(self)->carrier_changed_notify(self, carrier); NM_DEVICE_GET_CLASS(self)->carrier_changed_notify(self, carrier);
if (state <= NM_DEVICE_STATE_DISCONNECTED && !priv->queued_act_request) { if (state <= NM_DEVICE_STATE_DISCONNECTED && !priv->queued_act_request) {
@ -13738,7 +13738,7 @@ _carrier_wait_check_act_request_must_queue(NMDevice *self, NMActRequest *req)
* request is not blocked waiting for carrier. */ * request is not blocked waiting for carrier. */
if (priv->carrier) if (priv->carrier)
return FALSE; return FALSE;
if (priv->carrier_wait_id == 0) if (!priv->carrier_wait_source)
return FALSE; return FALSE;
connection = nm_act_request_get_applied_connection(req); connection = nm_act_request_get_applied_connection(req);
@ -14252,11 +14252,11 @@ carrier_wait_timeout(gpointer user_data)
NMDevice *self = NM_DEVICE(user_data); NMDevice *self = NM_DEVICE(user_data);
NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self); NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self);
priv->carrier_wait_id = 0; nm_clear_g_source_inst(&priv->carrier_wait_source);
nm_device_remove_pending_action(self, NM_PENDING_ACTION_CARRIER_WAIT, FALSE); nm_device_remove_pending_action(self, NM_PENDING_ACTION_CARRIER_WAIT, FALSE);
if (!priv->carrier) if (!priv->carrier)
_carrier_wait_check_queued_act_request(self); _carrier_wait_check_queued_act_request(self);
return G_SOURCE_REMOVE; return G_SOURCE_CONTINUE;
} }
static gboolean static gboolean
@ -14303,13 +14303,14 @@ carrier_detect_wait(NMDevice *self)
* *
* If during that time carrier goes away, we declare the interface * If during that time carrier goes away, we declare the interface
* as not ready. */ * as not ready. */
nm_clear_g_source(&priv->carrier_wait_id); nm_clear_g_source_inst(&priv->carrier_wait_source);
if (!priv->carrier) if (!priv->carrier)
nm_device_add_pending_action(self, NM_PENDING_ACTION_CARRIER_WAIT, FALSE); nm_device_add_pending_action(self, NM_PENDING_ACTION_CARRIER_WAIT, FALSE);
now_ms = nm_utils_get_monotonic_timestamp_msec(); now_ms = nm_utils_get_monotonic_timestamp_msec();
until_ms = NM_MAX(now_ms + _get_carrier_wait_ms(self), 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); priv->carrier_wait_source =
nm_g_timeout_add_source(until_ms - now_ms, carrier_wait_timeout, self);
} }
gboolean gboolean
@ -15301,7 +15302,7 @@ check_connection_available(NMDevice *self,
return TRUE; return TRUE;
if (NM_FLAGS_HAS(flags, _NM_DEVICE_CHECK_CON_AVAILABLE_FOR_USER_REQUEST_WAITING_CARRIER) if (NM_FLAGS_HAS(flags, _NM_DEVICE_CHECK_CON_AVAILABLE_FOR_USER_REQUEST_WAITING_CARRIER)
&& priv->carrier_wait_id != 0) { && priv->carrier_wait_source) {
/* The device has no carrier though the connection requires it. /* The device has no carrier though the connection requires it.
* *
* If we are still waiting for carrier, the connection is available * If we are still waiting for carrier, the connection is available
@ -18151,7 +18152,7 @@ dispose(GObject *object)
available_connections_del_all(self); available_connections_del_all(self);
if (nm_clear_g_source(&priv->carrier_wait_id)) if (nm_clear_g_source_inst(&priv->carrier_wait_source))
nm_device_remove_pending_action(self, NM_PENDING_ACTION_CARRIER_WAIT, FALSE); nm_device_remove_pending_action(self, NM_PENDING_ACTION_CARRIER_WAIT, FALSE);
_clear_queued_act_request(priv, NM_ACTIVE_CONNECTION_STATE_REASON_DEVICE_DISCONNECTED); _clear_queued_act_request(priv, NM_ACTIVE_CONNECTION_STATE_REASON_DEVICE_DISCONNECTED);