From 9ab3d019e4f492cb6c6c2fcbc24e7d3de9bc4392 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sun, 22 Apr 2018 12:13:44 +0200 Subject: [PATCH] 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. --- src/devices/nm-device.c | 40 +++++++++++++++++++++++++++------------- src/devices/nm-device.h | 2 +- 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))) + self = nm_active_connection_get_device (active); + + 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); - - 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); + 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)) {