diff options
author | Thomas Haller <thaller@redhat.com> | 2018-04-22 12:13:44 +0200 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2018-04-30 16:36:30 +0200 |
commit | 9ab3d019e4f492cb6c6c2fcbc24e7d3de9bc4392 (patch) | |
tree | 566259a7731814c48bd22aafadcb7a8990c8823d | |
parent | 3a2fbab09b15e7c21abb3e7828acb613cb3dffb7 (diff) | |
download | NetworkManager-9ab3d019e4f492cb6c6c2fcbc24e7d3de9bc4392.tar.gz |
core: rework nm_device_steal_connection()
nm_device_steal_connection() was a bit misleading. It only had one caller,
and what _internal_activate_device() really wants it to deactivate all
other active-connections for the same connection. Hence, it already
performed a lookup for the active-connection that should be disconnected,
only to then lookup the device, and tell it to steal the connection.
Note, that if existing_ac happens to be neither the queued nor the currenct
active connection, then previously it would have done nothing. It's
unclear when that exactly can happen, however, we can avoid that
question entirely.
Instead of having steal-connection(), have a disconnect-active-connection().
If there is no matching device, it will just set the active-connection's
state to DISCONNECTED. Which in turn does nothing, if the state is
already DISCONNECTED.
-rw-r--r-- | src/devices/nm-device.c | 40 | ||||
-rw-r--r-- | src/devices/nm-device.h | 2 | ||||
-rw-r--r-- | src/nm-manager.c | 9 |
3 files changed, 31 insertions, 20 deletions
diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c index 28e073d0d3..02f631761a 100644 --- a/src/devices/nm-device.c +++ b/src/devices/nm-device.c @@ -10836,23 +10836,37 @@ _carrier_wait_check_act_request_must_queue (NMDevice *self, NMActRequest *req) } void -nm_device_steal_connection (NMDevice *self, NMSettingsConnection *connection) +nm_device_disconnect_active_connection (NMActiveConnection *active) { - NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self); + NMDevice *self; + NMDevicePrivate *priv; - _LOGI (LOGD_DEVICE, "disconnecting connection '%s' for new activation request", - nm_settings_connection_get_id (connection)); + g_return_if_fail (NM_IS_ACTIVE_CONNECTION (active)); - if ( priv->queued_act_request - && connection == nm_active_connection_get_settings_connection (NM_ACTIVE_CONNECTION (priv->queued_act_request))) - _clear_queued_act_request (priv); + self = nm_active_connection_get_device (active); - if ( priv->act_request.obj - && connection == nm_active_connection_get_settings_connection (NM_ACTIVE_CONNECTION (priv->act_request.obj)) - && priv->state < NM_DEVICE_STATE_DEACTIVATING) { - nm_device_state_changed (self, - NM_DEVICE_STATE_DEACTIVATING, - NM_DEVICE_STATE_REASON_NEW_ACTIVATION); + if (!self) { + /* hm, no device? Just fail the active connection. */ + nm_active_connection_set_state_fail (active, + NM_ACTIVE_CONNECTION_STATE_REASON_UNKNOWN, + NULL); + return; + } + + priv = NM_DEVICE_GET_PRIVATE (self); + + if (NM_ACTIVE_CONNECTION (priv->queued_act_request) == active) { + _clear_queued_act_request (priv); + return; + } + if (NM_ACTIVE_CONNECTION (priv->act_request.obj) == active) { + if (priv->state < NM_DEVICE_STATE_DEACTIVATING) { + nm_device_state_changed (self, + NM_DEVICE_STATE_DEACTIVATING, + NM_DEVICE_STATE_REASON_NEW_ACTIVATION); + } else { + /* it's going down already... */ + } } } diff --git a/src/devices/nm-device.h b/src/devices/nm-device.h index 397123cd35..0d4d5cf8c4 100644 --- a/src/devices/nm-device.h +++ b/src/devices/nm-device.h @@ -717,7 +717,7 @@ void nm_device_queue_state (NMDevice *self, gboolean nm_device_get_firmware_missing (NMDevice *self); -void nm_device_steal_connection (NMDevice *device, NMSettingsConnection *connection); +void nm_device_disconnect_active_connection (NMActiveConnection *active); void nm_device_queue_activation (NMDevice *device, NMActRequest *req); diff --git a/src/nm-manager.c b/src/nm-manager.c index dc1f229b43..fc9a08f039 100644 --- a/src/nm-manager.c +++ b/src/nm-manager.c @@ -3954,7 +3954,7 @@ active_connection_parent_active (NMActiveConnection *active, static gboolean _internal_activate_device (NMManager *self, NMActiveConnection *active, GError **error) { - NMDevice *device, *existing, *master_device = NULL; + NMDevice *device, *master_device = NULL; NMActiveConnection *existing_ac; NMConnection *applied; NMSettingsConnection *connection; @@ -4121,11 +4121,8 @@ _internal_activate_device (NMManager *self, NMActiveConnection *active, GError * /* Disconnect the connection if connected or queued on another device */ existing_ac = active_connection_find (self, connection, NULL, NM_ACTIVE_CONNECTION_STATE_ACTIVATED, NULL); - if (existing_ac) { - existing = nm_active_connection_get_device (existing_ac); - if (existing) - nm_device_steal_connection (existing, connection); - } + if (existing_ac) + nm_device_disconnect_active_connection (existing_ac); /* If the device is there, we can ready it for the activation. */ if (nm_device_is_real (device)) { |