diff options
| author | Thomas Haller <thaller@redhat.com> | 2018-06-14 11:24:42 +0200 |
|---|---|---|
| committer | Thomas Haller <thaller@redhat.com> | 2018-06-14 12:30:28 +0200 |
| commit | e4426e302a6890cc2588d59eeea542cf0ad971d5 (patch) | |
| tree | ade81a195c4a68e2649c61eebfbc7eb32b0b8345 | |
| parent | 0a018a961fb1fc8d32b6d2a8b148e359249915e2 (diff) | |
| download | NetworkManager-e4426e302a6890cc2588d59eeea542cf0ad971d5.tar.gz | |
device: cache the NMConfigData instance for the current activation
NMConfig has pointers to current NMConfigData. The NMConfigData itself
is immutable, during config-reload, NMConfig will switch the instance
to a new config-data. This conveniently allows to take a snapshot
of a particular configuration.
Cache such an instance in the NMDevice, and initialize it, when
activation begins.
| -rw-r--r-- | src/devices/nm-device.c | 10 | ||||
| -rw-r--r-- | src/tests/config/test-config.c | 10 |
2 files changed, 17 insertions, 3 deletions
diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c index f07a40d015..08ed04fef4 100644 --- a/src/devices/nm-device.c +++ b/src/devices/nm-device.c @@ -324,6 +324,11 @@ typedef struct _NMDevicePrivate { guint32 ip4_address; + /* a snapshot of the config-data instance, when the device was activated. + * It is cached for the duraction of the activation, to avoid unintentional + * changes. */ + NMConfigData *cur_config_data; + NMActRequest * queued_act_request; bool queued_act_request_is_waiting_for_carrier:1; NMDBusTrackObjPath act_request; @@ -14083,6 +14088,7 @@ _set_state_full (NMDevice *self, } break; case NM_DEVICE_STATE_PREPARE: + nm_g_object_ref_set (&priv->cur_config_data, NM_CONFIG_GET_DATA); nm_device_update_initial_hw_address (self); break; case NM_DEVICE_STATE_NEED_AUTH: @@ -15234,6 +15240,8 @@ nm_device_init (NMDevice *self) nm_dbus_track_obj_path_init (&priv->parent_device, G_OBJECT (self), obj_properties[PROP_PARENT]); nm_dbus_track_obj_path_init (&priv->act_request, G_OBJECT (self), obj_properties[PROP_ACTIVE_CONNECTION]); + priv->cur_config_data = g_object_ref (NM_CONFIG_GET_DATA); + priv->netns = g_object_ref (NM_NETNS_GET); priv->autoconnect_blocked_flags = DEFAULT_AUTOCONNECT @@ -15484,6 +15492,8 @@ finalize (GObject *object) nm_g_object_unref (priv->concheck_mgr); g_object_unref (priv->netns); + + g_object_unref (priv->cur_config_data); } static void diff --git a/src/tests/config/test-config.c b/src/tests/config/test-config.c index 75fef4fad1..b7db63fd92 100644 --- a/src/tests/config/test-config.c +++ b/src/tests/config/test-config.c @@ -132,12 +132,16 @@ test_config_simple (void) gs_unref_object NMConfig *config = NULL; gs_strfreev char **plugins = NULL; char *value; - gs_unref_object NMDevice *dev50 = nm_test_device_new ("00:00:00:00:00:50"); - gs_unref_object NMDevice *dev51 = nm_test_device_new ("00:00:00:00:00:51"); - gs_unref_object NMDevice *dev52 = nm_test_device_new ("00:00:00:00:00:52"); + gs_unref_object NMDevice *dev50 = NULL; + gs_unref_object NMDevice *dev51 = NULL; + gs_unref_object NMDevice *dev52 = NULL; config = setup_config (NULL, TEST_DIR "/NetworkManager.conf", "", NULL, "/no/such/dir", "", NULL); + dev50 = nm_test_device_new ("00:00:00:00:00:50"); + dev51 = nm_test_device_new ("00:00:00:00:00:51"); + dev52 = nm_test_device_new ("00:00:00:00:00:52"); + g_assert_cmpstr (nm_config_data_get_config_main_file (nm_config_get_data_orig (config)), ==, TEST_DIR "/NetworkManager.conf"); g_assert_cmpstr (_config_get_dhcp_client_a (config), ==, "dhclient"); g_assert_cmpstr (nm_config_get_log_level (config), ==, "INFO"); |
