diff options
author | Thomas Haller <thaller@redhat.com> | 2014-04-28 11:18:05 +0200 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2014-05-01 22:06:52 +0200 |
commit | a16faa3985042dadb34600cb0df2eefc61360340 (patch) | |
tree | af699acf0c3aff6ac79d664565d19d32b72cc3d9 | |
parent | 50bafeaf2e318f63dd24053440712dee3035fa84 (diff) | |
download | NetworkManager-a16faa3985042dadb34600cb0df2eefc61360340.tar.gz |
core: add parameter to ignore error in add/remove pending action
Add a parameter to nm_device_add_pending_action() to silently
accept adding duplicate actions.
Same for nm_device_remove_pending_action(), to silently ignore
removing non-pending actions.
Signed-off-by: Thomas Haller <thaller@redhat.com>
-rw-r--r-- | src/devices/nm-device-olpc-mesh.c | 4 | ||||
-rw-r--r-- | src/devices/nm-device-wifi.c | 8 | ||||
-rw-r--r-- | src/devices/nm-device.c | 89 | ||||
-rw-r--r-- | src/devices/nm-device.h | 4 | ||||
-rw-r--r-- | src/nm-active-connection.c | 8 | ||||
-rw-r--r-- | src/nm-policy.c | 4 |
6 files changed, 74 insertions, 43 deletions
diff --git a/src/devices/nm-device-olpc-mesh.c b/src/devices/nm-device-olpc-mesh.c index c80d9b345e..0460dc6a8b 100644 --- a/src/devices/nm-device-olpc-mesh.c +++ b/src/devices/nm-device-olpc-mesh.c @@ -609,7 +609,7 @@ check_companion_cb (gpointer user_data) } done: - nm_device_remove_pending_action (NM_DEVICE (self), "waiting for companion"); + nm_device_remove_pending_action (NM_DEVICE (self), "waiting for companion", TRUE); return FALSE; } @@ -627,7 +627,7 @@ state_changed (NMDevice *device, NMDeviceState new_state, * transition to DISCONNECTED otherwise wait for our companion. */ g_idle_add (check_companion_cb, self); - nm_device_add_pending_action (device, "waiting for companion"); + nm_device_add_pending_action (device, "waiting for companion", TRUE); break; case NM_DEVICE_STATE_ACTIVATED: break; diff --git a/src/devices/nm-device-wifi.c b/src/devices/nm-device-wifi.c index d6b71396b1..a1e8bed66e 100644 --- a/src/devices/nm-device-wifi.c +++ b/src/devices/nm-device-wifi.c @@ -357,7 +357,7 @@ supplicant_interface_acquire (NMDeviceWifi *self) } if (nm_supplicant_interface_get_state (priv->supplicant.iface) < NM_SUPPLICANT_INTERFACE_STATE_READY) - nm_device_add_pending_action (NM_DEVICE (self), "waiting for supplicant"); + nm_device_add_pending_action (NM_DEVICE (self), "waiting for supplicant", TRUE); g_signal_connect (priv->supplicant.iface, NM_SUPPLICANT_INTERFACE_STATE, @@ -1722,7 +1722,7 @@ request_wireless_scan (gpointer user_data) /* success */ backoff = TRUE; priv->requested_scan = TRUE; - nm_device_add_pending_action (NM_DEVICE (self), "scan"); + nm_device_add_pending_action (NM_DEVICE (self), "scan", TRUE); } if (ssids) { @@ -1823,7 +1823,7 @@ supplicant_iface_scan_done_cb (NMSupplicantInterface *iface, if (priv->requested_scan) { priv->requested_scan = FALSE; - nm_device_remove_pending_action (NM_DEVICE (self), "scan"); + nm_device_remove_pending_action (NM_DEVICE (self), "scan", TRUE); } } @@ -2364,7 +2364,7 @@ supplicant_iface_state_cb (NMSupplicantInterface *iface, request_wireless_scan (self); if (old_state < NM_SUPPLICANT_INTERFACE_STATE_READY) - nm_device_remove_pending_action (device, "waiting for supplicant"); + nm_device_remove_pending_action (device, "waiting for supplicant", TRUE); break; case NM_SUPPLICANT_INTERFACE_STATE_COMPLETED: remove_supplicant_interface_error_handler (self); diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c index 60050727d3..86ce054886 100644 --- a/src/devices/nm-device.c +++ b/src/devices/nm-device.c @@ -1122,7 +1122,7 @@ nm_device_set_carrier (NMDevice *device, gboolean carrier) if (priv->carrier_wait_id) { g_source_remove (priv->carrier_wait_id); priv->carrier_wait_id = 0; - nm_device_remove_pending_action (device, "carrier wait"); + nm_device_remove_pending_action (device, "carrier wait", TRUE); } } else if (state <= NM_DEVICE_STATE_DISCONNECTED) { nm_log_info (LOGD_DEVICE, "(%s): link disconnected", iface); @@ -5505,7 +5505,7 @@ carrier_wait_timeout (gpointer user_data) NMDevice *self = NM_DEVICE (user_data); NM_DEVICE_GET_PRIVATE (self)->carrier_wait_id = 0; - nm_device_remove_pending_action (self, "carrier wait"); + nm_device_remove_pending_action (self, "carrier wait", TRUE); return G_SOURCE_REMOVE; } @@ -5553,10 +5553,10 @@ nm_device_bring_up (NMDevice *self, gboolean block, gboolean *no_firmware) if (device_has_capability (self, NM_DEVICE_CAP_CARRIER_DETECT)) { if (priv->carrier_wait_id) { g_source_remove (priv->carrier_wait_id); - nm_device_remove_pending_action (self, "carrier wait"); + nm_device_remove_pending_action (self, "carrier wait", TRUE); } priv->carrier_wait_id = g_timeout_add_seconds (5, carrier_wait_timeout, self); - nm_device_add_pending_action (self, "carrier wait"); + nm_device_add_pending_action (self, "carrier wait", TRUE); } /* Can only get HW address of some devices when they are up */ @@ -6820,7 +6820,7 @@ queued_set_state (gpointer user_data) nm_device_queued_state_clear (self); nm_device_state_changed (self, new_state, new_reason); - nm_device_remove_pending_action (self, queued_state_to_string (new_state)); + nm_device_remove_pending_action (self, queued_state_to_string (new_state), TRUE); } else { g_warn_if_fail (priv->queued_state.state == NM_DEVICE_STATE_UNKNOWN); g_warn_if_fail (priv->queued_state.reason == NM_DEVICE_STATE_REASON_NONE); @@ -6844,7 +6844,7 @@ nm_device_queue_state (NMDevice *self, /* Add pending action for the new state before clearing the queued states, so * that we don't accidently pop all pending states and reach 'startup complete' */ - nm_device_add_pending_action (self, queued_state_to_string (state)); + nm_device_add_pending_action (self, queued_state_to_string (state), TRUE); /* We should only ever have one delayed state transition at a time */ if (priv->queued_state.id) { @@ -6885,7 +6885,7 @@ nm_device_queued_state_clear (NMDevice *self) nm_log_dbg (LOGD_DEVICE, "(%s): clearing queued state transition (id %d)", nm_device_get_iface (self), priv->queued_state.id); g_source_remove (priv->queued_state.id); - nm_device_remove_pending_action (self, queued_state_to_string (priv->queued_state.state)); + nm_device_remove_pending_action (self, queued_state_to_string (priv->queued_state.state), TRUE); } memset (&priv->queued_state, 0, sizeof (priv->queued_state)); } @@ -7660,31 +7660,46 @@ nm_device_set_hw_addr (NMDevice *device, const guint8 *addr, * nm_device_add_pending_action(): * @device: the #NMDevice to add the pending action to * @action: a static string that identifies the action + * @assert_not_yet_pending: if %TRUE, assert that the @action is currently not yet pending. + * Otherwise, ignore duplicate scheduling of the same action silently. * * Adds a pending action to the device. + * + * Returns: %TRUE if the action was added (and not already added before). %FALSE + * if the same action is already scheduled. In the latter case, the action was not scheduled + * a second time. */ -void -nm_device_add_pending_action (NMDevice *device, const char *action) +gboolean +nm_device_add_pending_action (NMDevice *device, const char *action, gboolean assert_not_yet_pending) { NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (device); GSList *iter; - guint count; + guint count = 0; - g_return_if_fail (action); + g_return_val_if_fail (action, FALSE); - /* Shouldn't ever add the same pending action twice */ + /* Check if the action is already pending. Cannot add duplicate actions */ for (iter = priv->pending_actions; iter; iter = iter->next) { if (!strcmp (action, iter->data)) { - nm_log_warn (LOGD_DEVICE, "(%s): add_pending_action (%d): '%s' already added", - nm_device_get_iface (device), - g_slist_length (priv->pending_actions), - action); - g_return_if_reached (); + if (assert_not_yet_pending) { + nm_log_warn (LOGD_DEVICE, "(%s): add_pending_action (%d): '%s' already pending", + nm_device_get_iface (device), + count + g_slist_length (iter), + action); + g_return_val_if_reached (FALSE); + } else { + nm_log_dbg (LOGD_DEVICE, "(%s): add_pending_action (%d): '%s' already pending (expected)", + nm_device_get_iface (device), + count + g_slist_length (iter), + action); + } + return FALSE; } + count++; } priv->pending_actions = g_slist_append (priv->pending_actions, g_strdup (action)); - count = g_slist_length (priv->pending_actions); + count++; nm_log_dbg (LOGD_DEVICE, "(%s): add_pending_action (%d): '%s'", nm_device_get_iface (device), @@ -7693,44 +7708,60 @@ nm_device_add_pending_action (NMDevice *device, const char *action) if (count == 1) g_object_notify (G_OBJECT (device), NM_DEVICE_HAS_PENDING_ACTION); + + return TRUE; } /** * nm_device_remove_pending_action(): * @device: the #NMDevice to remove the pending action from * @action: a static string that identifies the action + * @assert_is_pending: if %TRUE, assert that the @action is pending. + * If %FALSE, don't do anything if the current action is not pending and + * return %FALSE. * * Removes a pending action previously added by nm_device_add_pending_action(). + * + * Returns: whether the @action was pending and is now removed. */ -void -nm_device_remove_pending_action (NMDevice *device, const char *action) +gboolean +nm_device_remove_pending_action (NMDevice *device, const char *action, gboolean assert_is_pending) { NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (device); GSList *iter; + guint count = 0; - g_return_if_fail (action); + g_return_val_if_fail (action, FALSE); - /* Shouldn't ever add the same pending action twice */ for (iter = priv->pending_actions; iter; iter = iter->next) { if (!strcmp (action, iter->data)) { g_free (iter->data); priv->pending_actions = g_slist_delete_link (priv->pending_actions, iter); nm_log_dbg (LOGD_DEVICE, "(%s): remove_pending_action (%d): '%s'", nm_device_get_iface (device), - g_slist_length (priv->pending_actions), + count + g_slist_length (iter), action); if (priv->pending_actions == NULL) g_object_notify (G_OBJECT (device), NM_DEVICE_HAS_PENDING_ACTION); - return; + return TRUE; } + count++; } - nm_log_warn (LOGD_DEVICE, "(%s): remove_pending_action (%d): '%s' never added", - nm_device_get_iface (device), - g_slist_length (priv->pending_actions), - action); - g_return_if_reached (); + if (assert_is_pending) { + nm_log_warn (LOGD_DEVICE, "(%s): remove_pending_action (%d): '%s' not pending", + nm_device_get_iface (device), + count, + action); + g_return_val_if_reached (FALSE); + } else { + nm_log_dbg (LOGD_DEVICE, "(%s): remove_pending_action (%d): '%s' not pending (expected)", + nm_device_get_iface (device), + count, + action); + } + return FALSE; } gboolean diff --git a/src/devices/nm-device.h b/src/devices/nm-device.h index a253fd425c..d70af3b1ab 100644 --- a/src/devices/nm-device.h +++ b/src/devices/nm-device.h @@ -351,8 +351,8 @@ void nm_device_queue_activation (NMDevice *device, NMActRequest *req); gboolean nm_device_supports_vlans (NMDevice *device); -void nm_device_add_pending_action (NMDevice *device, const char *action); -void nm_device_remove_pending_action (NMDevice *device, const char *action); +gboolean nm_device_add_pending_action (NMDevice *device, const char *action, gboolean assert_not_yet_pending); +gboolean nm_device_remove_pending_action (NMDevice *device, const char *action, gboolean assert_is_pending); gboolean nm_device_has_pending_action (NMDevice *device); GPtrArray *nm_device_get_available_connections (NMDevice *device, diff --git a/src/nm-active-connection.c b/src/nm-active-connection.c index 43f81893e3..172aa61419 100644 --- a/src/nm-active-connection.c +++ b/src/nm-active-connection.c @@ -152,7 +152,7 @@ nm_active_connection_set_state (NMActiveConnection *self, && new_state >= NM_ACTIVE_CONNECTION_STATE_ACTIVATED && priv->pending_activation_id) { - nm_device_remove_pending_action (priv->device, priv->pending_activation_id); + nm_device_remove_pending_action (priv->device, priv->pending_activation_id, TRUE); g_clear_pointer (&priv->pending_activation_id, g_free); } } @@ -399,7 +399,7 @@ nm_active_connection_set_device (NMActiveConnection *self, NMDevice *device) if (!priv->assumed) { priv->pending_activation_id = g_strdup_printf ("activation::%p", (void *)self); - nm_device_add_pending_action (device, priv->pending_activation_id); + nm_device_add_pending_action (device, priv->pending_activation_id, TRUE); } } return TRUE; @@ -540,7 +540,7 @@ nm_active_connection_set_assumed (NMActiveConnection *self, gboolean assumed) priv->assumed = assumed; if (priv->pending_activation_id) { - nm_device_remove_pending_action (priv->device, priv->pending_activation_id); + nm_device_remove_pending_action (priv->device, priv->pending_activation_id, TRUE); g_clear_pointer (&priv->pending_activation_id, g_free); } } @@ -795,7 +795,7 @@ _device_cleanup (NMActiveConnection *self) } if (priv->pending_activation_id) { - nm_device_remove_pending_action (priv->device, priv->pending_activation_id); + nm_device_remove_pending_action (priv->device, priv->pending_activation_id, TRUE); g_clear_pointer (&priv->pending_activation_id, g_free); } diff --git a/src/nm-policy.c b/src/nm-policy.c index 380f4ced47..88bc31a161 100644 --- a/src/nm-policy.c +++ b/src/nm-policy.c @@ -941,7 +941,7 @@ activate_data_free (ActivateData *data) { NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE (data->policy); - nm_device_remove_pending_action (data->device, "autoactivate"); + nm_device_remove_pending_action (data->device, "autoactivate", TRUE); priv->pending_activation_checks = g_slist_remove (priv->pending_activation_checks, data); if (data->autoactivate_id) @@ -1226,7 +1226,7 @@ schedule_activate_check (NMPolicy *policy, NMDevice *device) return; } - nm_device_add_pending_action (device, "autoactivate"); + nm_device_add_pending_action (device, "autoactivate", TRUE); data = g_malloc0 (sizeof (ActivateData)); data->policy = policy; |