From 7bbfd1db43ae714abc43c028e84c23abc2f690ca Mon Sep 17 00:00:00 2001 From: Beniamino Galvani Date: Tue, 11 May 2021 14:42:31 +0200 Subject: [PATCH 1/3] device: add NM_UNMANAGED_ALL (cherry picked from commit f244aa690776e399972b092741753ba7063fc066) (cherry picked from commit 943aa1a8584d699aa1505818434d0fbc265f2573) --- src/devices/nm-device.h | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/src/devices/nm-device.h b/src/devices/nm-device.h index 3eae931834..f2d4c7c9c0 100644 --- a/src/devices/nm-device.h +++ b/src/devices/nm-device.h @@ -624,27 +624,28 @@ void nm_device_copy_ip6_dns_config(NMDevice *self, NMDevice *from_device); * setting the NM_UNMANAGED_IS_SLAVE to %TRUE makes no sense, this flag has only * meaning to set a slave device as managed if the parent is managed too. */ -typedef enum { /*< skip >*/ - NM_UNMANAGED_NONE = 0, +typedef enum { + NM_UNMANAGED_NONE = 0, - /* these flags are authoritative. If one of them is set, + /* 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_PARENT = (1LL << 2), - NM_UNMANAGED_BY_TYPE = (1LL << 3), - NM_UNMANAGED_PLATFORM_INIT = (1LL << 4), - NM_UNMANAGED_USER_EXPLICIT = (1LL << 5), - NM_UNMANAGED_USER_SETTINGS = (1LL << 6), + NM_UNMANAGED_SLEEPING = (1LL << 0), + NM_UNMANAGED_QUITTING = (1LL << 1), + NM_UNMANAGED_PARENT = (1LL << 2), + NM_UNMANAGED_BY_TYPE = (1LL << 3), + NM_UNMANAGED_PLATFORM_INIT = (1LL << 4), + NM_UNMANAGED_USER_EXPLICIT = (1LL << 5), + NM_UNMANAGED_USER_SETTINGS = (1LL << 6), - /* These flags can be non-effective and be overwritten + /* These flags can be non-effective and be overwritten * by other flags. */ - NM_UNMANAGED_BY_DEFAULT = (1LL << 8), - NM_UNMANAGED_USER_CONF = (1LL << 9), - NM_UNMANAGED_USER_UDEV = (1LL << 10), - NM_UNMANAGED_EXTERNAL_DOWN = (1LL << 11), - NM_UNMANAGED_IS_SLAVE = (1LL << 12), + NM_UNMANAGED_BY_DEFAULT = (1LL << 7), + NM_UNMANAGED_USER_CONF = (1LL << 8), + NM_UNMANAGED_USER_UDEV = (1LL << 9), + NM_UNMANAGED_EXTERNAL_DOWN = (1LL << 10), + NM_UNMANAGED_IS_SLAVE = (1LL << 11), + NM_UNMANAGED_ALL = ((1LL << 12) - 1), } NMUnmanagedFlags; typedef enum { From 587c70aace673bb31dfc63c17821c1af505d2c33 Mon Sep 17 00:00:00 2001 From: Beniamino Galvani Date: Tue, 11 May 2021 14:43:09 +0200 Subject: [PATCH 2/3] managed: remove unneeded call to nm_device_assume_state_reset() _set_state_full() in NMDevice already calls nm_device_assume_state_reset() when the device reaches state > DISCONNECTED. (cherry picked from commit 5dc6d73243572bb36dc0a3049a770d7004a1faf7) (cherry picked from commit efe8046c1d8ef5b985f4bdbb652053fc89d40b73) --- src/nm-manager.c | 1 - 1 file changed, 1 deletion(-) diff --git a/src/nm-manager.c b/src/nm-manager.c index 46f81c7cb4..d6e8ac082d 100644 --- a/src/nm-manager.c +++ b/src/nm-manager.c @@ -2825,7 +2825,6 @@ recheck_assume_connection(NMManager *self, NMDevice *device) state = nm_device_get_state(device); if (state > NM_DEVICE_STATE_DISCONNECTED) { - nm_device_assume_state_reset(device); _LOG2D(LOGD_DEVICE, device, "assume: don't assume due to device state %s", From 401f52203367838341a9e3a1b35e381300786b1e Mon Sep 17 00:00:00 2001 From: Beniamino Galvani Date: Tue, 11 May 2021 14:44:20 +0200 Subject: [PATCH 3/3] core: don't reset assume state too early If the device is still unmanaged by platform-init (which means that udev didn't emit the event for the interface) when the device gets realized, we currently clear the assume state. Later, when the device becomes managed, NM is not able to properly assume the device using the UUID. This situation arises, for example, when NM already configured the device in initrd; after NM is restarted in the real root, udev events can be delayed causing this race condition. Among all unamanaged flags, platform-init is the only one that can be delayed externally. We should not clear the assume state if the device has only platform-init in the unmanaged flags. (cherry picked from commit 3c4450aa4da19e5057b9ca8b15f8f196ca02c7cb) (cherry picked from commit 18022299bfd1ffc47bc4d88ca2ea5b7b3d095307) --- src/devices/nm-device.c | 2 +- src/nm-manager.c | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c index de93f2233c..dea4868a62 100644 --- a/src/devices/nm-device.c +++ b/src/devices/nm-device.c @@ -5337,11 +5337,11 @@ device_link_changed(NMDevice *self) /* Ensure the assume check is queued before any queued state changes * from the transition to UNAVAILABLE. */ - nm_device_queue_recheck_assume(self); reason = NM_DEVICE_STATE_REASON_CONNECTION_ASSUMED; } } + nm_device_queue_recheck_assume(self); nm_device_set_unmanaged_by_flags(self, NM_UNMANAGED_PLATFORM_INIT, FALSE, reason); } diff --git a/src/nm-manager.c b/src/nm-manager.c index d6e8ac082d..70cfc4920f 100644 --- a/src/nm-manager.c +++ b/src/nm-manager.c @@ -2818,7 +2818,10 @@ recheck_assume_connection(NMManager *self, NMDevice *device) g_return_val_if_fail(NM_IS_DEVICE(device), FALSE); if (!nm_device_get_managed(device, FALSE)) { - nm_device_assume_state_reset(device); + /* If the device is only unmanaged by NM_UNMANAGED_PLATFORM_INIT, + * don't reset the state now but wait until it becomes managed. */ + if (nm_device_get_unmanaged_flags(device, NM_UNMANAGED_ALL) != NM_UNMANAGED_PLATFORM_INIT) + nm_device_assume_state_reset(device); _LOG2D(LOGD_DEVICE, device, "assume: don't assume because %s", "not managed"); return FALSE; } @@ -3139,7 +3142,10 @@ _device_realize_finish(NMManager *self, NMDevice *device, const NMPlatformLink * nm_device_realize_finish(device, plink); if (!nm_device_get_managed(device, FALSE)) { - nm_device_assume_state_reset(device); + /* If the device is only unmanaged by NM_UNMANAGED_PLATFORM_INIT, + * don't reset the state now but wait until it becomes managed. */ + if (nm_device_get_unmanaged_flags(device, NM_UNMANAGED_ALL) != NM_UNMANAGED_PLATFORM_INIT) + nm_device_assume_state_reset(device); return; }