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.
This commit is contained in:
Thomas Haller 2018-04-22 12:13:44 +02:00
parent 3a2fbab09b
commit 9ab3d019e4
3 changed files with 31 additions and 20 deletions

View file

@ -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... */
}
}
}

View file

@ -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);

View file

@ -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)) {