From 1f1b71ad9f8a650dbe808d225af6ac108bd398f4 Mon Sep 17 00:00:00 2001 From: Beniamino Galvani Date: Tue, 8 Aug 2023 11:51:10 +0200 Subject: [PATCH 1/2] checkpoint: preserve devices that were removed and readded With flag DISCONNECT_NEW_DEVICES, on rollback we delete devices that are present in the system and are not in the checkpoint. The problem is that we remove the device from `NMCheckpointPriv->devices` when it is deleted and so we lose the information that the device was in the checkpoint. We need to also look in the `removed_devices` list. Fixes: 0e2f7ac7b5ea ('nm-checkpoint: drop reference to NM_DEVICE objects on removal signal') (cherry picked from commit 0fcfd6e24f471170cf44d8ace0202e1e2fc9ffbb) --- src/core/nm-checkpoint.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/core/nm-checkpoint.c b/src/core/nm-checkpoint.c index 0beeb4ba26..52d8a649b3 100644 --- a/src/core/nm-checkpoint.c +++ b/src/core/nm-checkpoint.c @@ -458,8 +458,25 @@ next_dev: NMDeviceState state; nm_manager_for_each_device (priv->manager, device, tmp_lst) { + gboolean found = FALSE; + if (g_hash_table_contains(priv->devices, device)) continue; + + /* Also ignore devices that were in the checkpoint initially and + * were moved to 'removed_devices' because they got removed from + * the system. */ + for (i = 0; i < priv->removed_devices->len; i++) { + dev_checkpoint = priv->removed_devices->pdata[i]; + if (dev_checkpoint->dev_type == nm_device_get_device_type(device) + && nm_streq0(dev_checkpoint->original_dev_name, nm_device_get_iface(device))) { + found = TRUE; + break; + } + } + if (found) + continue; + state = nm_device_get_state(device); if (state > NM_DEVICE_STATE_DISCONNECTED && state < NM_DEVICE_STATE_DEACTIVATING) { _LOGD("rollback: disconnecting new device %s", nm_device_get_iface(device)); From 8a881e638f8b07b1049713292488aabb32fb7b7e Mon Sep 17 00:00:00 2001 From: Beniamino Galvani Date: Tue, 8 Aug 2023 13:53:50 +0200 Subject: [PATCH 2/2] checkpoint: fetch new device on rollback When a device belonging to a checkpoint is removed, we clear the device pointer from the DeviceCheckpoint and move the object from the devices list to the removed-devices list of the checkpoint. Later, when restoring the connection we need to set again the device pointer in DeviceCheckpoint; otherwise, any connection on that device can't be reactivated if changed. Fixes: 0e2f7ac7b5ea ('nm-checkpoint: drop reference to NM_DEVICE objects on removal signal') (cherry picked from commit b80a398306b3f30b3563df43141215e6645e652d) --- src/core/nm-checkpoint.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/core/nm-checkpoint.c b/src/core/nm-checkpoint.c index 52d8a649b3..5c4d4e53d6 100644 --- a/src/core/nm-checkpoint.c +++ b/src/core/nm-checkpoint.c @@ -259,17 +259,19 @@ restore_and_activate_connection(NMCheckpoint *self, DeviceCheckpoint *dev_checkp g_clear_error(&local_error); return FALSE; } - - /* If the device is software, a brand new NMDevice may have been created */ - if (dev_checkpoint->is_software && !dev_checkpoint->device) { - dev_checkpoint->device = nm_manager_get_device(priv->manager, - dev_checkpoint->original_dev_name, - dev_checkpoint->dev_type); - nm_g_object_ref(dev_checkpoint->device); - } need_activation = TRUE; } + /* If the device is software, a brand new NMDevice may have been created + * after adding the new connection; or the old device might have been + * deleted and we need to fetch it again. */ + if (dev_checkpoint->is_software && !dev_checkpoint->device) { + dev_checkpoint->device = nm_manager_get_device(priv->manager, + dev_checkpoint->original_dev_name, + dev_checkpoint->dev_type); + nm_g_object_ref(dev_checkpoint->device); + } + if (!dev_checkpoint->device) { _LOGD("rollback: device cannot be restored"); return FALSE;