diff options
| author | Thomas Haller <thaller@redhat.com> | 2015-09-15 15:35:16 +0200 |
|---|---|---|
| committer | Thomas Haller <thaller@redhat.com> | 2015-09-22 10:19:17 +0200 |
| commit | 5bb47e22eab99142c2b2931115948e1b9cfff1e5 (patch) | |
| tree | 97c980395a1906a1b02cabb67e459fd755df30d5 | |
| parent | 5eb574e76c81b66c1f5b8e01bd5a9a2b061fa13b (diff) | |
| download | NetworkManager-lr/default-unmanaged-bgo746566-3.tar.gz | |
device: remove default-unmanagedlr/default-unmanaged-bgo746566-3
Get rid of NM_UNMANAGED_DEFAULT and replace it for most parts
of NM_UNMANAGED_USER.
The user-flag can be modified via D-Bus API. Also, when the user
activates a connection, it automatically clears NM_UNMANAGED_USER.
This should for the most part give a similar behavior to the previous
NM_UNMANAGED_DEFAULT behavior.
However, when deactivating a device that was previously
NM_UNMANAGED_DEFAULT, we would no longer transition the device to
unmanaged-state.
https://bugzilla.gnome.org/show_bug.cgi?id=746566
Based-on-patch-by: Lubomir Rintel <lkundrak@v3.sk>
| -rw-r--r-- | src/devices/nm-device-generic.c | 2 | ||||
| -rw-r--r-- | src/devices/nm-device.c | 125 | ||||
| -rw-r--r-- | src/devices/nm-device.h | 7 | ||||
| -rw-r--r-- | src/nm-manager.c | 66 | ||||
| -rw-r--r-- | src/settings/nm-settings.c | 2 |
5 files changed, 81 insertions, 121 deletions
diff --git a/src/devices/nm-device-generic.c b/src/devices/nm-device-generic.c index 37eae35bdc..7b0ec72d3c 100644 --- a/src/devices/nm-device-generic.c +++ b/src/devices/nm-device-generic.c @@ -138,7 +138,7 @@ constructor (GType type, n_construct_params, construct_params); - nm_device_set_unmanaged_initial (NM_DEVICE (object), NM_UNMANAGED_DEFAULT, TRUE); + nm_device_set_unmanaged_initial (NM_DEVICE (object), NM_UNMANAGED_USER, TRUE); return object; } diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c index 3fb8a5be9d..708b93ed41 100644 --- a/src/devices/nm-device.c +++ b/src/devices/nm-device.c @@ -372,8 +372,6 @@ static NMActStageReturn linklocal6_start (NMDevice *self); static void _carrier_wait_check_queued_act_request (NMDevice *self); -static gboolean nm_device_get_default_unmanaged (NMDevice *self); - static void _set_state_full (NMDevice *self, NMDeviceState state, NMDeviceStateReason reason, @@ -1152,7 +1150,7 @@ nm_device_finish_init (NMDevice *self) gboolean platform_unmanaged = FALSE; if (nm_platform_link_get_unmanaged (NM_PLATFORM_GET, priv->ifindex, &platform_unmanaged)) - nm_device_set_unmanaged_initial (self, NM_UNMANAGED_DEFAULT, platform_unmanaged); + nm_device_set_unmanaged_initial (self, NM_UNMANAGED_USER, platform_unmanaged); } else { /* Hardware and externally-created software links stay unmanaged * until they are fully initialized by the platform. NM created @@ -1494,7 +1492,7 @@ device_link_changed (NMDevice *self) if ( !priv->managed_touched_by_user && nm_platform_link_get_unmanaged (NM_PLATFORM_GET, priv->ifindex, &platform_unmanaged)) { nm_device_set_unmanaged (self, - NM_UNMANAGED_DEFAULT, + NM_UNMANAGED_USER, platform_unmanaged, NM_DEVICE_STATE_REASON_USER_REQUESTED); } @@ -2266,18 +2264,11 @@ nm_device_set_autoconnect (NMDevice *self, gboolean autoconnect) g_return_if_fail (NM_IS_DEVICE (self)); - priv = NM_DEVICE_GET_PRIVATE (self); - if (priv->autoconnect == autoconnect) - return; + autoconnect = !!autoconnect; - if (autoconnect) { - /* Default-unmanaged devices never autoconnect */ - if (!nm_device_get_default_unmanaged (self)) { - priv->autoconnect = TRUE; - g_object_notify (G_OBJECT (self), NM_DEVICE_AUTOCONNECT); - } - } else { - priv->autoconnect = FALSE; + priv = NM_DEVICE_GET_PRIVATE (self); + if (priv->autoconnect != autoconnect) { + priv->autoconnect = autoconnect; g_object_notify (G_OBJECT (self), NM_DEVICE_AUTOCONNECT); } } @@ -6429,6 +6420,7 @@ _device_activate (NMDevice *self, NMActRequest *req) g_return_val_if_fail (NM_IS_DEVICE (self), FALSE); g_return_val_if_fail (NM_IS_ACT_REQUEST (req), FALSE); + g_return_val_if_fail (nm_device_get_managed (self), FALSE); /* Ensure the activation request is still valid; the master may have * already failed in which case activation of this device should not proceed. @@ -6447,13 +6439,6 @@ _device_activate (NMDevice *self, NMActRequest *req) delete_on_deactivate_unschedule (self); - /* Move default unmanaged devices to DISCONNECTED state here */ - if (nm_device_get_default_unmanaged (self) && priv->state == NM_DEVICE_STATE_UNMANAGED) { - nm_device_state_changed (self, - NM_DEVICE_STATE_DISCONNECTED, - NM_DEVICE_STATE_REASON_NOW_MANAGED); - } - /* note: don't notify D-Bus of the new AC here, but do it later when * changing state to PREPARE so that the two properties change together. */ @@ -7681,46 +7666,40 @@ gboolean nm_device_get_managed (NMDevice *self) { NMDevicePrivate *priv; - gboolean managed; g_return_val_if_fail (NM_IS_DEVICE (self), FALSE); priv = NM_DEVICE_GET_PRIVATE (self); - /* Return the composite of all managed flags. However, if the device - * is a default-unmanaged device, and would be managed except for the - * default-unmanaged flag (eg, only NM_UNMANAGED_DEFAULT is set) then - * the device is managed whenever it's not in the UNMANAGED state. - */ - managed = !NM_FLAGS_ANY (priv->unmanaged_flags, ~NM_UNMANAGED_DEFAULT); - if (managed && NM_FLAGS_HAS (priv->unmanaged_flags, NM_UNMANAGED_DEFAULT)) - managed = (priv->state > NM_DEVICE_STATE_UNMANAGED); - - return managed; + /* For most cases, this should be identical to + * !nm_device_get_unmanaged(self, NM_UNMANAGED_ALL). While + * transitioning device-state however, they might differ. + * + * nm_device_get_managed() returns a conservative guess that the + * device is unmanaged unless both the flags and the state + * indicate so. + * Contrary to nm_device_get_unmanaged(), which only querries + * the unamanged-flags. */ + return !NM_FLAGS_ANY (priv->unmanaged_flags, NM_UNMANAGED_ALL) + && priv->state > NM_DEVICE_STATE_UNMANAGED; } /** * nm_device_get_unmanaged(): * @self: the #NMDevice + * @flags: the unmanged flags to check. + * + * Return the unmanaged flags of the device. * * Returns: %TRUE if the device is unmanaged for @flag. */ gboolean -nm_device_get_unmanaged (NMDevice *self, NMUnmanagedFlags flag) +nm_device_get_unmanaged (NMDevice *self, NMUnmanagedFlags flags) { - return NM_FLAGS_ANY (NM_DEVICE_GET_PRIVATE (self)->unmanaged_flags, flag); -} + g_return_val_if_fail (NM_IS_DEVICE (self), FALSE); + g_return_val_if_fail (flags != NM_UNMANAGED_NONE, FALSE); -/** - * nm_device_get_default_unmanaged(): - * @self: the #NMDevice - * - * Returns: %TRUE if the device is by default unmanaged - */ -static gboolean -nm_device_get_default_unmanaged (NMDevice *self) -{ - return nm_device_get_unmanaged (self, NM_UNMANAGED_DEFAULT); + return NM_FLAGS_ANY (NM_DEVICE_GET_PRIVATE (self)->unmanaged_flags, flags); } static void @@ -7758,23 +7737,19 @@ nm_device_set_unmanaged (NMDevice *self, NMDeviceStateReason reason) { NMDevicePrivate *priv; - gboolean was_managed, now_managed; + gboolean was_unmanaged, now_unmanaged; g_return_if_fail (NM_IS_DEVICE (self)); g_return_if_fail (flag <= NM_UNMANAGED_LAST); priv = NM_DEVICE_GET_PRIVATE (self); - was_managed = nm_device_get_managed (self); + was_unmanaged = NM_FLAGS_ANY (priv->unmanaged_flags, NM_UNMANAGED_ALL); _set_unmanaged_flags (self, flag, unmanaged); - now_managed = nm_device_get_managed (self); - - if (was_managed != now_managed) { - _LOGD (LOGD_DEVICE, "now %s", unmanaged ? "unmanaged" : "managed"); + now_unmanaged = NM_FLAGS_ANY (priv->unmanaged_flags, NM_UNMANAGED_ALL); - g_object_notify (G_OBJECT (self), NM_DEVICE_MANAGED); - - if (unmanaged) + if (was_unmanaged != now_unmanaged) { + if (now_unmanaged) nm_device_state_changed (self, NM_DEVICE_STATE_UNMANAGED, reason); else if (nm_device_get_state (self) == NM_DEVICE_STATE_UNMANAGED) nm_device_state_changed (self, NM_DEVICE_STATE_UNAVAILABLE, reason); @@ -7795,6 +7770,14 @@ nm_device_set_unmanaged_by_device_spec (NMDevice *self, const GSList *unmanaged_ return; unmanaged = nm_device_spec_match_list (self, unmanaged_specs); + if (!unmanaged) { + /* a device-spec can only unmanage a device. It cannot clear + * the NM_UNMANAGED_USER flag to make it managed. The device + * could already be user-unmanaged by different reasons: + * NMDeviceGeneric being user-unmanaged by default, or + * udev rules setting NM_UNMANAGED. */ + return; + } nm_device_set_unmanaged (self, NM_UNMANAGED_USER, unmanaged, @@ -8023,7 +8006,10 @@ nm_device_check_connection_available (NMDevice *self, if (state < NM_DEVICE_STATE_UNMANAGED) return FALSE; if ( state < NM_DEVICE_STATE_UNAVAILABLE - && nm_device_get_unmanaged (self, NM_UNMANAGED_ALL & ~NM_UNMANAGED_DEFAULT)) + && ( ( !NM_FLAGS_ANY (flags, NM_DEVICE_CHECK_CON_AVAILABLE_FOR_USER_REQUEST) + && nm_device_get_unmanaged (self, NM_UNMANAGED_ALL)) + || ( NM_FLAGS_ANY (flags, NM_DEVICE_CHECK_CON_AVAILABLE_FOR_USER_REQUEST) + && nm_device_get_unmanaged (self, NM_UNMANAGED_ALL & ~_NM_UNMANAGED_USER_SETTABLE)))) return FALSE; if ( state < NM_DEVICE_STATE_DISCONNECTED && ( ( !NM_FLAGS_HAS (flags, _NM_DEVICE_CHECK_CON_AVAILABLE_FOR_USER_REQUEST_WAITING_CARRIER) @@ -8736,6 +8722,7 @@ _set_state_full (NMDevice *self, NMActRequest *req; gboolean no_firmware = FALSE; NMSettingsConnection *connection; + gboolean was_managed; g_return_if_fail (NM_IS_DEVICE (self)); @@ -8772,6 +8759,8 @@ _set_state_full (NMDevice *self, priv->in_state_changed = TRUE; + was_managed = nm_device_get_managed (self); + priv->state = state; priv->state_reason = reason; @@ -8791,8 +8780,7 @@ _set_state_full (NMDevice *self, } /* Update the available connections list when a device first becomes available */ - if ( (state >= NM_DEVICE_STATE_DISCONNECTED && old_state < NM_DEVICE_STATE_DISCONNECTED) - || nm_device_get_default_unmanaged (self)) + if (state >= NM_DEVICE_STATE_DISCONNECTED && old_state < NM_DEVICE_STATE_DISCONNECTED) nm_device_recheck_available_connections (self); /* Handle the new state here; but anything that could trigger @@ -8892,11 +8880,7 @@ _set_state_full (NMDevice *self, NM_DEVICE_STATE_REASON_NONE, NM_DEVICE_STATE_REASON_NONE); } else { - if (old_state == NM_DEVICE_STATE_UNMANAGED) - _LOGD (LOGD_DEVICE, "device not yet available for transition to DISCONNECTED"); - else if ( old_state > NM_DEVICE_STATE_UNAVAILABLE - && nm_device_get_default_unmanaged (self)) - nm_device_queue_state (self, NM_DEVICE_STATE_UNMANAGED, NM_DEVICE_STATE_REASON_NONE); + _LOGD (LOGD_DEVICE, "device not yet available for transition to DISCONNECTED"); } break; case NM_DEVICE_STATE_DEACTIVATING: @@ -8942,9 +8926,6 @@ _set_state_full (NMDevice *self, break; /* fall through */ } - if ( old_state > NM_DEVICE_STATE_DISCONNECTED - && nm_device_get_default_unmanaged (self)) - nm_device_queue_state (self, NM_DEVICE_STATE_UNMANAGED, NM_DEVICE_STATE_REASON_NONE); break; case NM_DEVICE_STATE_ACTIVATED: _LOGI (LOGD_DEVICE, "Activation: successful, device activated."); @@ -9030,6 +9011,9 @@ _set_state_full (NMDevice *self, g_object_unref (req); priv->in_state_changed = FALSE; + + if (was_managed != nm_device_get_managed (self)) + g_object_notify (G_OBJECT (self), NM_DEVICE_MANAGED); } void @@ -9370,15 +9354,6 @@ constructed (GObject *object) G_CALLBACK (cp_connection_updated), self); - /* Update default-unmanaged device available connections immediately, - * since they don't transition from UNMANAGED (and thus the state handler - * doesn't run and update them) until something external happens. - */ - if (nm_device_get_default_unmanaged (self)) { - nm_device_set_autoconnect (self, FALSE); - nm_device_recheck_available_connections (self); - } - G_OBJECT_CLASS (nm_device_parent_class)->constructed (object); _LOGD (LOGD_DEVICE, "constructed (%s)", G_OBJECT_TYPE_NAME (self)); diff --git a/src/devices/nm-device.h b/src/devices/nm-device.h index b0f1255648..fb7e2c1380 100644 --- a/src/devices/nm-device.h +++ b/src/devices/nm-device.h @@ -407,7 +407,7 @@ RfKillType nm_device_get_rfkill_type (NMDevice *device); /** * NMUnmanagedFlags: * @NM_UNMANAGED_NONE: placeholder value - * @NM_UNMANAGED_DEFAULT: %TRUE when unmanaged by default (ie, Generic devices) + * @NM_UNMANAGED_LOOPBACK: %TRUE for unmanaging loopback device * @NM_UNMANAGED_INTERNAL: %TRUE when unmanaged by internal decision (ie, * because NM is sleeping or not managed for some other reason) * @NM_UNMANAGED_USER: %TRUE when unmanaged by user decision (via unmanaged-specs) @@ -415,17 +415,15 @@ RfKillType nm_device_get_rfkill_type (NMDevice *device); * @NM_UNMANAGED_EXTERNAL_DOWN: %TRUE when unmanaged because !IFF_UP and not created by NM * @NM_UNMANAGED_PLATFORM_INIT: %TRUE when unmanaged because platform link not * yet initialized - * @NM_UNMANAGED_LOOPBACK: %TRUE for unmanaging loopback device */ typedef enum { /*< skip >*/ NM_UNMANAGED_NONE = 0, - NM_UNMANAGED_DEFAULT = (1LL << 0), + NM_UNMANAGED_LOOPBACK = (1LL << 0), NM_UNMANAGED_INTERNAL = (1LL << 1), NM_UNMANAGED_USER = (1LL << 2), NM_UNMANAGED_PARENT = (1LL << 3), NM_UNMANAGED_EXTERNAL_DOWN = (1LL << 4), NM_UNMANAGED_PLATFORM_INIT = (1LL << 5), - NM_UNMANAGED_LOOPBACK = (1LL << 6), /* Boundary value */ __NM_UNMANAGED_LAST, @@ -434,7 +432,6 @@ typedef enum { /*< skip >*/ /* these flags can be cleared by the user via NMDevice:managed */ _NM_UNMANAGED_USER_SETTABLE = ( NM_UNMANAGED_USER - | NM_UNMANAGED_DEFAULT | NM_UNMANAGED_EXTERNAL_DOWN), } NMUnmanagedFlags; diff --git a/src/nm-manager.c b/src/nm-manager.c index 8d6436b9d3..c791908aaf 100644 --- a/src/nm-manager.c +++ b/src/nm-manager.c @@ -760,9 +760,9 @@ remove_device (NMManager *manager, NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (manager); nm_log_dbg (LOGD_DEVICE, "(%s): removing device (allow_unmanage %d, managed %d)", - nm_device_get_iface (device), allow_unmanage, nm_device_get_managed (device)); + nm_device_get_iface (device), allow_unmanage, !nm_device_get_unmanaged (device, NM_UNMANAGED_ALL)); - if (allow_unmanage && nm_device_get_managed (device)) { + if (allow_unmanage && !nm_device_get_unmanaged (device, NM_UNMANAGED_ALL)) { NMActRequest *req = nm_device_get_act_request (device); gboolean unmanage = FALSE; @@ -1592,15 +1592,16 @@ recheck_assume_connection (NMDevice *device, gpointer user_data) { NMManager *self = NM_MANAGER (user_data); NMSettingsConnection *connection; - gboolean was_unmanaged = FALSE, success, generated; + gboolean success, generated; NMDeviceState state; if (manager_sleeping (self)) return FALSE; - if (nm_device_get_unmanaged (device, NM_UNMANAGED_ALL & ~NM_UNMANAGED_DEFAULT)) + if (!nm_device_get_managed (device)) return FALSE; state = nm_device_get_state (device); + g_return_val_if_fail (state > NM_DEVICE_STATE_UNMANAGED, FALSE);; if (state > NM_DEVICE_STATE_DISCONNECTED) return FALSE; @@ -1611,34 +1612,12 @@ recheck_assume_connection (NMDevice *device, gpointer user_data) return FALSE; } - if (state == NM_DEVICE_STATE_UNMANAGED) { - was_unmanaged = TRUE; - nm_device_state_changed (device, - NM_DEVICE_STATE_UNAVAILABLE, - NM_DEVICE_STATE_REASON_CONNECTION_ASSUMED); - } - success = assume_connection (self, device, connection); - if (!success) { - if (was_unmanaged) { - nm_device_state_changed (device, - NM_DEVICE_STATE_UNAVAILABLE, - NM_DEVICE_STATE_REASON_CONFIG_FAILED); - - /* Return default-unmanaged devices to their original state */ - if (nm_device_get_unmanaged (device, NM_UNMANAGED_DEFAULT)) { - nm_device_state_changed (device, - NM_DEVICE_STATE_UNMANAGED, - NM_DEVICE_STATE_REASON_CONFIG_FAILED); - } - } - - if (generated) { - nm_log_dbg (LOGD_DEVICE, "(%s): connection assumption failed. Deleting generated connection", - nm_device_get_iface (device)); + if (!success && generated) { + nm_log_dbg (LOGD_DEVICE, "(%s): connection assumption failed. Deleting generated connection", + nm_device_get_iface (device)); - nm_settings_connection_delete (connection, NULL, NULL); - } + nm_settings_connection_delete (connection, NULL, NULL); } return success; @@ -1699,7 +1678,6 @@ add_device (NMManager *self, NMDevice *device, gboolean try_assume) gboolean enabled = FALSE; RfKillType rtype; GSList *iter, *remove = NULL; - gboolean connection_assumed = FALSE; int ifindex; const char *dbus_path; @@ -1782,7 +1760,12 @@ add_device (NMManager *self, NMDevice *device, gboolean try_assume) unmanaged_specs = nm_settings_get_unmanaged_specs (priv->settings); user_unmanaged = nm_device_spec_match_list (device, unmanaged_specs); - nm_device_set_unmanaged_initial (device, NM_UNMANAGED_USER, user_unmanaged); + if (user_unmanaged) { + /* We might have NM_UNMANAGED_USER already set (e.g. NMDeviceGeneric + * sets it by default. Hence, we only want to set the flag depending + * on user_unmanaged, but we don't want to clear it. */ + nm_device_set_unmanaged_initial (device, NM_UNMANAGED_USER, TRUE); + } sleeping = manager_sleeping (self); nm_device_set_unmanaged_initial (device, NM_UNMANAGED_INTERNAL, sleeping); @@ -1792,16 +1775,21 @@ add_device (NMManager *self, NMDevice *device, gboolean try_assume) nm_device_finish_init (device); - if (try_assume) { - connection_assumed = recheck_assume_connection (device, self); - g_signal_connect (device, NM_DEVICE_RECHECK_ASSUME, - G_CALLBACK (recheck_assume_connection), self); - } - - if (!connection_assumed && nm_device_get_managed (device)) { + if (!nm_device_get_unmanaged (device, NM_UNMANAGED_ALL)) { nm_device_state_changed (device, NM_DEVICE_STATE_UNAVAILABLE, NM_DEVICE_STATE_REASON_NOW_MANAGED); + + if (try_assume) { + g_signal_connect (device, NM_DEVICE_RECHECK_ASSUME, + G_CALLBACK (recheck_assume_connection), self); + + if (!recheck_assume_connection (device, self)) { + nm_device_state_changed (device, + NM_DEVICE_STATE_UNAVAILABLE, + NM_DEVICE_STATE_REASON_NOW_MANAGED); + } + } } /* Try to generate a default connection. If this fails because the link is diff --git a/src/settings/nm-settings.c b/src/settings/nm-settings.c index 951f417646..51197a9a4d 100644 --- a/src/settings/nm-settings.c +++ b/src/settings/nm-settings.c @@ -1856,7 +1856,7 @@ nm_settings_device_added (NMSettings *self, NMDevice *device) /* If the device isn't managed or it already has a default wired connection, * ignore it. */ - if ( !nm_device_get_managed (device) + if ( nm_device_get_unmanaged (device, NM_UNMANAGED_ALL) || g_object_get_data (G_OBJECT (device), DEFAULT_WIRED_CONNECTION_TAG) || have_connection_for_device (self, device)) return; |
