From 11482237e4d9872e882239f7e235233c6642e9cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=8D=C3=B1igo=20Huguet?= Date: Mon, 15 Sep 2025 15:12:19 +0200 Subject: [PATCH] core: rename unmanaged flag SLEEPING->MANAGER_DISABLED The flag is used for both sleeping and networking disabled conditions. This is because internally they share logic, but it's not obvious for users and it has caused confusion in the past when investigating why devices didn't become managed. Make it explicit that it can be because of either reason. It would be better to create two separate flags, actually, and it doesn't seem complex, but better not to risk introducing bugs for that little benefit. Logs before: device (enp4s0): state change: disconnected -> unmanaged (reason 'unmanaged-sleeping' ... Logs before: device (enp4s0): state change: disconnected -> unmanaged (reason 'unmanaged-nm-disabled' ... (cherry picked from commit 48fc40e1ca68724877c931d1add0c47702d3c773) --- src/core/devices/nm-device-utils.c | 3 ++- src/core/devices/nm-device.c | 6 +++--- src/core/devices/nm-device.h | 13 +++++++------ src/core/nm-manager.c | 12 ++++++------ src/libnm-core-public/nm-dbus-interface.h | 9 ++++++--- src/libnmc-base/nm-client-utils.c | 2 +- 6 files changed, 25 insertions(+), 20 deletions(-) diff --git a/src/core/devices/nm-device-utils.c b/src/core/devices/nm-device-utils.c index 61d8066a61..a78499fb22 100644 --- a/src/core/devices/nm-device-utils.c +++ b/src/core/devices/nm-device-utils.c @@ -135,7 +135,8 @@ NM_UTILS_LOOKUP_STR_DEFINE( NM_UTILS_LOOKUP_STR_ITEM(NM_DEVICE_STATE_REASON_UNMANAGED_LINK_NOT_INIT, "unmanaged-link-not-init"), NM_UTILS_LOOKUP_STR_ITEM(NM_DEVICE_STATE_REASON_UNMANAGED_QUITTING, "unmanaged-quitting"), - NM_UTILS_LOOKUP_STR_ITEM(NM_DEVICE_STATE_REASON_UNMANAGED_SLEEPING, "unmanaged-sleeping"), + NM_UTILS_LOOKUP_STR_ITEM(NM_DEVICE_STATE_REASON_UNMANAGED_MANAGER_DISABLED, + "unmanaged-nm-disabled"), NM_UTILS_LOOKUP_STR_ITEM(NM_DEVICE_STATE_REASON_UNMANAGED_USER_CONF, "unmanaged-user-conf"), NM_UTILS_LOOKUP_STR_ITEM(NM_DEVICE_STATE_REASON_UNMANAGED_USER_EXPLICIT, "unmanaged-user-explicit"), diff --git a/src/core/devices/nm-device.c b/src/core/devices/nm-device.c index 09de780a8e..8d92f241f8 100644 --- a/src/core/devices/nm-device.c +++ b/src/core/devices/nm-device.c @@ -15665,7 +15665,7 @@ nm_device_get_firmware_missing(NMDevice *self) NM_UTILS_FLAGS2STR_DEFINE(nm_unmanaged_flags2str, NMUnmanagedFlags, - NM_UTILS_FLAGS2STR(NM_UNMANAGED_SLEEPING, "sleeping"), + NM_UTILS_FLAGS2STR(NM_UNMANAGED_MANAGER_DISABLED, "nm-disabled"), NM_UTILS_FLAGS2STR(NM_UNMANAGED_QUITTING, "quitting"), NM_UTILS_FLAGS2STR(NM_UNMANAGED_PLATFORM_INIT, "platform-init"), NM_UTILS_FLAGS2STR(NM_UNMANAGED_USER_EXPLICIT, "user-explicit"), @@ -15729,8 +15729,8 @@ unmanaged_flags_to_reason(NMUnmanagedFlags flags) /* Even if there are multiple flags, we can only return one reason. * Return the most important reason. */ - if (NM_FLAGS_HAS(flags, NM_UNMANAGED_SLEEPING)) - return NM_DEVICE_STATE_REASON_UNMANAGED_SLEEPING; + if (NM_FLAGS_HAS(flags, NM_UNMANAGED_MANAGER_DISABLED)) + return NM_DEVICE_STATE_REASON_UNMANAGED_MANAGER_DISABLED; if (NM_FLAGS_HAS(flags, NM_UNMANAGED_QUITTING)) return NM_DEVICE_STATE_REASON_UNMANAGED_QUITTING; if (NM_FLAGS_HAS(flags, NM_UNMANAGED_USER_SETTINGS)) diff --git a/src/core/devices/nm-device.h b/src/core/devices/nm-device.h index 9a663c2a95..820951ea6a 100644 --- a/src/core/devices/nm-device.h +++ b/src/core/devices/nm-device.h @@ -581,7 +581,8 @@ void nm_device_copy_ip6_dns_config(NMDevice *self, NMDevice *from_device); /** * NMUnmanagedFlags: * @NM_UNMANAGED_NONE: placeholder value - * @NM_UNMANAGED_SLEEPING: %TRUE when unmanaged because NM is sleeping. + * @NM_UNMANAGED_MANAGER_DISABLED: %TRUE when unmanaged because NM is disabled. + * Currently, this happens when sleeping or with networking disabled. * @NM_UNMANAGED_QUITTING: %TRUE when unmanaged because NM is shutting down. * @NM_UNMANAGED_PLATFORM_INIT: %TRUE when unmanaged because platform link not * yet initialized. Unrealized device are also unmanaged for this reason. @@ -610,11 +611,11 @@ typedef enum { /* these flags are authoritative. If one of them is set, * the device cannot be managed. */ - NM_UNMANAGED_SLEEPING = (1LL << 0), - NM_UNMANAGED_QUITTING = (1LL << 1), - NM_UNMANAGED_PLATFORM_INIT = (1LL << 2), - NM_UNMANAGED_USER_EXPLICIT = (1LL << 3), - NM_UNMANAGED_USER_SETTINGS = (1LL << 4), + NM_UNMANAGED_MANAGER_DISABLED = (1LL << 0), + NM_UNMANAGED_QUITTING = (1LL << 1), + NM_UNMANAGED_PLATFORM_INIT = (1LL << 2), + NM_UNMANAGED_USER_EXPLICIT = (1LL << 3), + NM_UNMANAGED_USER_SETTINGS = (1LL << 4), /* These flags can be non-effective and be overwritten * by other flags. */ diff --git a/src/core/nm-manager.c b/src/core/nm-manager.c index b614ec6a36..060e0c2c7c 100644 --- a/src/core/nm-manager.c +++ b/src/core/nm-manager.c @@ -4082,7 +4082,7 @@ add_device(NMManager *self, NMDevice *device, GError **error) nm_device_set_unmanaged_by_user_settings(device, TRUE); - nm_device_set_unmanaged_flags(device, NM_UNMANAGED_SLEEPING, manager_is_disabled(self)); + nm_device_set_unmanaged_flags(device, NM_UNMANAGED_MANAGER_DISABLED, manager_is_disabled(self)); dbus_path = nm_dbus_object_export(NM_DBUS_OBJECT(device)); _LOG2I(LOGD_DEVICE, device, "new %s device (%s)", type_desc, dbus_path); @@ -7302,7 +7302,7 @@ device_sleep_cb(NMDevice *device, GParamSpec *pspec, NMManager *self) case NM_DEVICE_STATE_DISCONNECTED: _LOGD(LOGD_SUSPEND, "sleep: unmanaging device %s", nm_device_get_ip_iface(device)); nm_device_set_unmanaged_by_flags_queue(device, - NM_UNMANAGED_SLEEPING, + NM_UNMANAGED_MANAGER_DISABLED, NM_UNMAN_FLAG_OP_SET_UNMANAGED, NM_DEVICE_STATE_REASON_SLEEPING); break; @@ -7341,7 +7341,7 @@ _handle_device_takedown(NMManager *self, nm_device_queue_state(device, NM_DEVICE_STATE_DEACTIVATING, reason); } else { nm_device_set_unmanaged_by_flags(device, - NM_UNMANAGED_SLEEPING, + NM_UNMANAGED_MANAGER_DISABLED, NM_UNMAN_FLAG_OP_SET_UNMANAGED, reason); } @@ -7402,7 +7402,7 @@ do_sleep_wake(NMManager *self, gboolean sleeping_changed) */ if (device_is_wake_on_lan(priv->platform, device)) nm_device_set_unmanaged_by_flags(device, - NM_UNMANAGED_SLEEPING, + NM_UNMANAGED_MANAGER_DISABLED, NM_UNMAN_FLAG_OP_SET_UNMANAGED, NM_DEVICE_STATE_REASON_SLEEPING); @@ -7430,7 +7430,7 @@ do_sleep_wake(NMManager *self, gboolean sleeping_changed) guint i; if (nm_device_is_software(device) - && !nm_device_get_unmanaged_flags(device, NM_UNMANAGED_SLEEPING)) { + && !nm_device_get_unmanaged_flags(device, NM_UNMANAGED_MANAGER_DISABLED)) { /* DHCP leases of software devices could have gone stale * so we need to renew them. */ nm_device_update_dynamic_ip_setup(device, @@ -7466,7 +7466,7 @@ do_sleep_wake(NMManager *self, gboolean sleeping_changed) ? NM_DEVICE_STATE_REASON_CONNECTION_ASSUMED : NM_DEVICE_STATE_REASON_NOW_MANAGED; nm_device_set_unmanaged_by_flags(device, - NM_UNMANAGED_SLEEPING, + NM_UNMANAGED_MANAGER_DISABLED, NM_UNMAN_FLAG_OP_SET_MANAGED, reason); } diff --git a/src/libnm-core-public/nm-dbus-interface.h b/src/libnm-core-public/nm-dbus-interface.h index 65b007ccf1..e62d64e10f 100644 --- a/src/libnm-core-public/nm-dbus-interface.h +++ b/src/libnm-core-public/nm-dbus-interface.h @@ -635,8 +635,10 @@ typedef enum { * not initialized by udev. Since: 1.48 * @NM_DEVICE_STATE_REASON_UNMANAGED_QUITTING: The device is unmanaged because NetworkManager is * quitting. Since: 1.48 - * @NM_DEVICE_STATE_REASON_UNMANAGED_SLEEPING: The device is unmanaged because networking is - * disabled or the system is suspended. Since: 1.48 + * @NM_DEVICE_STATE_REASON_UNMANAGED_SLEEPING: Since: 1.48. Deprecated: 1.56: Use + * %NM_DEVICE_STATE_REASON_UNMANAGED_MANAGER_DISABLED instead. + * @NM_DEVICE_STATE_REASON_UNMANAGED_MANAGER_DISABLED: The device is unmanaged because networking is + * disabled or the system is suspended. Since: 1.56 * @NM_DEVICE_STATE_REASON_UNMANAGED_USER_CONF: The device is unmanaged by user decision in * NetworkManager.conf ('unmanaged' in a [device*] section). Since: 1.48 * @NM_DEVICE_STATE_REASON_UNMANAGED_USER_EXPLICIT: The device is unmanaged by explicit user @@ -723,7 +725,8 @@ typedef enum { NM_DEVICE_STATE_REASON_UNMANAGED_EXTERNAL_DOWN = 70, NM_DEVICE_STATE_REASON_UNMANAGED_LINK_NOT_INIT = 71, NM_DEVICE_STATE_REASON_UNMANAGED_QUITTING = 72, - NM_DEVICE_STATE_REASON_UNMANAGED_SLEEPING = 73, + NM_DEVICE_STATE_REASON_UNMANAGED_SLEEPING = 73, /* Deprecated */ + NM_DEVICE_STATE_REASON_UNMANAGED_MANAGER_DISABLED = 73, NM_DEVICE_STATE_REASON_UNMANAGED_USER_CONF = 74, NM_DEVICE_STATE_REASON_UNMANAGED_USER_EXPLICIT = 75, NM_DEVICE_STATE_REASON_UNMANAGED_USER_SETTINGS = 76, diff --git a/src/libnmc-base/nm-client-utils.c b/src/libnmc-base/nm-client-utils.c index ae3fcc1c2c..326d8d20ae 100644 --- a/src/libnmc-base/nm-client-utils.c +++ b/src/libnmc-base/nm-client-utils.c @@ -467,7 +467,7 @@ NM_UTILS_LOOKUP_STR_DEFINE( N_("The Wi-Fi P2P peer could not be found")), NM_UTILS_LOOKUP_ITEM(NM_DEVICE_STATE_REASON_DEVICE_HANDLER_FAILED, N_("The device handler dispatcher returned an error")), - NM_UTILS_LOOKUP_ITEM(NM_DEVICE_STATE_REASON_UNMANAGED_SLEEPING, + NM_UTILS_LOOKUP_ITEM(NM_DEVICE_STATE_REASON_UNMANAGED_MANAGER_DISABLED, N_("The device is unmanaged because networking is disabled " "or the system is suspended")), NM_UTILS_LOOKUP_ITEM(NM_DEVICE_STATE_REASON_UNMANAGED_QUITTING,