policy: move setting autoconnect retries to a separate function

Note that for the

  if (nm_device_state_reason_check (reason) == NM_DEVICE_STATE_REASON_NO_SECRETS)

case we no longer do the

  if (nm_settings_connection_autoconnect_retries_get (connection) == 0)

check. But that is fine, because we only skip schedling a reset_connections_retries()
action. But note, that that previously we also would never actually
scheudle a new timeout, because

  - either nm_settings_connection_autoconnect_retries_get (connection) != 0
  - or the retries count was zero, in which case we already have a
    reset_connections_retries action pending (from the time when we
    set it to zero.

So, there is no change in behavior at all except dropping of a redundant
logging line.
This commit is contained in:
Thomas Haller 2017-11-22 17:03:22 +01:00
parent 3177b18aab
commit 124b905f97
2 changed files with 26 additions and 14 deletions

View file

@ -1529,6 +1529,29 @@ reset_connections_retries (gpointer user_data)
return FALSE;
}
static void
_connection_autoconnect_retries_set (NMPolicy *self,
NMSettingsConnection *connection,
int tries)
{
NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE (self);
nm_assert (NM_IS_SETTINGS_CONNECTION (connection));
nm_assert (tries >= 0);
nm_settings_connection_autoconnect_retries_set (connection, tries);
if (tries == 0) {
/* Schedule a handler to reset retries count */
if (!priv->reset_retries_id) {
gint32 retry_time = nm_settings_connection_autoconnect_retries_blocked_until (connection);
g_warn_if_fail (retry_time != 0);
priv->reset_retries_id = g_timeout_add_seconds (MAX (0, retry_time - nm_utils_get_monotonic_timestamp_s ()), reset_connections_retries, self);
}
}
}
static void
activate_slave_connections (NMPolicy *self, NMDevice *device)
{
@ -1723,24 +1746,13 @@ device_state_changed (NMDevice *device,
if (tries > 0) {
_LOGD (LOGD_DEVICE, "connection '%s' failed to autoconnect; %d tries left",
nm_settings_connection_get_id (connection), tries);
nm_settings_connection_autoconnect_retries_set (connection, --tries);
_connection_autoconnect_retries_set (self, connection, tries - 1);
} else {
_LOGD (LOGD_DEVICE, "connection '%s' failed to autoconnect; infinite tries left",
nm_settings_connection_get_id (connection));
}
}
if (nm_settings_connection_autoconnect_retries_get (connection) == 0) {
_LOGI (LOGD_DEVICE, "disabling autoconnect for connection '%s'.",
nm_settings_connection_get_id (connection));
/* Schedule a handler to reset retries count */
if (!priv->reset_retries_id) {
gint32 retry_time = nm_settings_connection_autoconnect_retries_blocked_until (connection);
g_warn_if_fail (retry_time != 0);
priv->reset_retries_id = g_timeout_add_seconds (MAX (0, retry_time - nm_utils_get_monotonic_timestamp_s ()), reset_connections_retries, self);
}
}
nm_connection_clear_secrets (NM_CONNECTION (connection));
}
break;

View file

@ -2577,8 +2577,8 @@ nm_settings_connection_autoconnect_retries_set (NMSettingsConnection *self,
else {
/* XXX: the blocked time must be identical for all connections, otherwise
* the tracking of resetting the retry count in NMPolicy needs adjustment
* (as it would need to re-evaluate the next-timeout everytime a
* connection gets blocked). */
* in _connection_autoconnect_retries_set() (as it would need to re-evaluate
* the next-timeout everytime a connection gets blocked). */
priv->autoconnect_retries_blocked_until = nm_utils_get_monotonic_timestamp_s () + AUTOCONNECT_RESET_RETRIES_TIMER;
}
}