summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2022-02-25 14:22:53 +0100
committerThomas Haller <thaller@redhat.com>2023-06-26 10:35:35 +0200
commitcf5c576d555b41c97864e7517d2bf94cef4f759f (patch)
tree95bcac70114b83d3a6ef78f86d86451125dcdd4a
parent9bc9fde5066fd3fd00eeb3258f8e4700d8670706 (diff)
settings,libnm: add version-id to settings/remote connection
-rw-r--r--introspection/org.freedesktop.NetworkManager.Settings.xml10
-rw-r--r--src/core/settings/nm-settings-connection.c47
-rw-r--r--src/core/settings/nm-settings-connection.h10
-rw-r--r--src/core/settings/nm-settings.c8
-rw-r--r--src/libnm-client-impl/libnm.ver1
-rw-r--r--src/libnm-client-impl/nm-remote-connection.c46
-rw-r--r--src/libnm-client-public/nm-remote-connection.h4
7 files changed, 115 insertions, 11 deletions
diff --git a/introspection/org.freedesktop.NetworkManager.Settings.xml b/introspection/org.freedesktop.NetworkManager.Settings.xml
index ea271dfaa1..2932734f87 100644
--- a/introspection/org.freedesktop.NetworkManager.Settings.xml
+++ b/introspection/org.freedesktop.NetworkManager.Settings.xml
@@ -189,6 +189,16 @@
<property name="CanModify" type="b" access="read"/>
<!--
+ VersionId:
+
+ The version of the settings. This is incremented whenever the profile
+ changes and can be used to detect concurrent modifications.
+
+ Since: 1.44
+ -->
+ <property name="VersionId" type="t" access="read"/>
+
+ <!--
NewConnection:
@connection: Object path of the new connection.
diff --git a/src/core/settings/nm-settings-connection.c b/src/core/settings/nm-settings-connection.c
index 0ad5411cd2..d0725a7042 100644
--- a/src/core/settings/nm-settings-connection.c
+++ b/src/core/settings/nm-settings-connection.c
@@ -109,7 +109,11 @@ _seen_bssids_hash_new(void)
/*****************************************************************************/
-NM_GOBJECT_PROPERTIES_DEFINE(NMSettingsConnection, PROP_UNSAVED, PROP_FLAGS, PROP_FILENAME, );
+NM_GOBJECT_PROPERTIES_DEFINE(NMSettingsConnection,
+ PROP_VERSION_ID,
+ PROP_UNSAVED,
+ PROP_FLAGS,
+ PROP_FILENAME, );
enum { UPDATED_INTERNAL, FLAGS_CHANGED, LAST_SIGNAL };
@@ -156,6 +160,8 @@ typedef struct _NMSettingsConnectionPrivate {
guint64 last_secret_agent_version_id;
+ guint64 version_id;
+
bool timestamp_set : 1;
NMSettingsAutoconnectBlockedReason autoconnect_blocked_reason : 4;
@@ -2642,6 +2648,23 @@ nm_settings_connection_get_uuid(NMSettingsConnection *self)
return uuid;
}
+guint64
+nm_settings_connection_get_version_id(NMSettingsConnection *self)
+{
+ g_return_val_if_fail(NM_IS_SETTINGS_CONNECTION(self), 0);
+
+ return NM_SETTINGS_CONNECTION_GET_PRIVATE(self)->version_id;
+}
+
+void
+nm_settings_connection_bump_version_id(NMSettingsConnection *self)
+{
+ g_return_if_fail(NM_IS_SETTINGS_CONNECTION(self));
+
+ NM_SETTINGS_CONNECTION_GET_PRIVATE(self)->version_id++;
+ _notify(self, PROP_VERSION_ID);
+}
+
const char *
nm_settings_connection_get_connection_type(NMSettingsConnection *self)
{
@@ -2665,9 +2688,13 @@ _nm_settings_connection_cleanup_after_remove(NMSettingsConnection *self)
static void
get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
{
- NMSettingsConnection *self = NM_SETTINGS_CONNECTION(object);
+ NMSettingsConnection *self = NM_SETTINGS_CONNECTION(object);
+ NMSettingsConnectionPrivate *priv = NM_SETTINGS_CONNECTION_GET_PRIVATE(self);
switch (prop_id) {
+ case PROP_VERSION_ID:
+ g_value_set_uint64(value, priv->version_id);
+ break;
case PROP_UNSAVED:
g_value_set_boolean(value, nm_settings_connection_get_unsaved(self));
break;
@@ -2704,6 +2731,8 @@ nm_settings_connection_init(NMSettingsConnection *self)
priv->agent_mgr = g_object_ref(nm_agent_manager_get());
priv->settings = g_object_ref(nm_settings_get());
+
+ priv->version_id = 1;
}
NMSettingsConnection *
@@ -2817,7 +2846,10 @@ static const NMDBusInterfaceInfoExtended interface_info_settings_connection = {
NM_SETTINGS_CONNECTION_FLAGS),
NM_DEFINE_DBUS_PROPERTY_INFO_EXTENDED_READABLE("Filename",
"s",
- NM_SETTINGS_CONNECTION_FILENAME), ), ),
+ NM_SETTINGS_CONNECTION_FILENAME),
+ NM_DEFINE_DBUS_PROPERTY_INFO_EXTENDED_READABLE("VersionId",
+ "t",
+ NM_SETTINGS_CONNECTION_VERSION_ID), ), ),
};
static void
@@ -2835,6 +2867,15 @@ nm_settings_connection_class_init(NMSettingsConnectionClass *klass)
object_class->dispose = dispose;
object_class->get_property = get_property;
+ obj_properties[PROP_VERSION_ID] =
+ g_param_spec_uint64(NM_SETTINGS_CONNECTION_VERSION_ID,
+ "",
+ "",
+ 0,
+ G_MAXUINT64,
+ 0,
+ G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
+
obj_properties[PROP_UNSAVED] = g_param_spec_boolean(NM_SETTINGS_CONNECTION_UNSAVED,
"",
"",
diff --git a/src/core/settings/nm-settings-connection.h b/src/core/settings/nm-settings-connection.h
index eec4ae1856..835a978e40 100644
--- a/src/core/settings/nm-settings-connection.h
+++ b/src/core/settings/nm-settings-connection.h
@@ -141,9 +141,10 @@ typedef enum {
#define NM_SETTINGS_CONNECTION_FLAGS_CHANGED "flags-changed"
/* Properties */
-#define NM_SETTINGS_CONNECTION_UNSAVED "unsaved"
-#define NM_SETTINGS_CONNECTION_FLAGS "flags"
-#define NM_SETTINGS_CONNECTION_FILENAME "filename"
+#define NM_SETTINGS_CONNECTION_UNSAVED "unsaved"
+#define NM_SETTINGS_CONNECTION_VERSION_ID "version-id"
+#define NM_SETTINGS_CONNECTION_FLAGS "flags"
+#define NM_SETTINGS_CONNECTION_FILENAME "filename"
/**
* NMSettingsConnectionIntFlags:
@@ -231,6 +232,9 @@ const char *nm_settings_connection_get_filename(NMSettingsConnection *self);
guint64 nm_settings_connection_get_last_secret_agent_version_id(NMSettingsConnection *self);
+guint64 nm_settings_connection_get_version_id(NMSettingsConnection *self);
+void nm_settings_connection_bump_version_id(NMSettingsConnection *self);
+
gboolean
nm_settings_connection_has_unmodified_applied_connection(NMSettingsConnection *self,
NMConnection *applied_connection,
diff --git a/src/core/settings/nm-settings.c b/src/core/settings/nm-settings.c
index c3d99cca3d..49a7c68753 100644
--- a/src/core/settings/nm-settings.c
+++ b/src/core/settings/nm-settings.c
@@ -1090,11 +1090,13 @@ _connection_changed_update(NMSettings *self,
is_new = c_list_is_empty(&sett_conn->_connections_lst);
- _LOGT("update[%s]: %s connection \"%s\" (" NM_SETTINGS_STORAGE_PRINT_FMT ")",
+ _LOGT("update[%s]: %s connection \"%s\" (" NM_SETTINGS_STORAGE_PRINT_FMT "), "
+ "new version-id %" G_GUINT64_FORMAT,
nm_settings_storage_get_uuid(storage),
is_new ? "adding" : "updating",
nm_connection_get_id(connection),
- NM_SETTINGS_STORAGE_PRINT_ARG(storage));
+ NM_SETTINGS_STORAGE_PRINT_ARG(storage),
+ (nm_settings_connection_get_version_id(sett_conn) + 1u));
_nm_settings_connection_set_storage(sett_conn, storage);
@@ -1166,6 +1168,8 @@ _connection_changed_update(NMSettings *self,
path);
}
+ nm_settings_connection_bump_version_id(sett_conn);
+
if (is_new) {
nm_dbus_object_emit_signal(NM_DBUS_OBJECT(self),
&interface_info_settings,
diff --git a/src/libnm-client-impl/libnm.ver b/src/libnm-client-impl/libnm.ver
index 7fd09072a2..919ffc74b8 100644
--- a/src/libnm-client-impl/libnm.ver
+++ b/src/libnm-client-impl/libnm.ver
@@ -1932,6 +1932,7 @@ global:
libnm_1_44_0 {
global:
+ nm_remote_connection_get_version_id;
nm_setting_gsm_get_initial_eps_apn;
nm_setting_gsm_get_initial_eps_config;
nm_setting_ip6_config_get_dhcp_pd_hint;
diff --git a/src/libnm-client-impl/nm-remote-connection.c b/src/libnm-client-impl/nm-remote-connection.c
index 38ea114b09..607c21a151 100644
--- a/src/libnm-client-impl/nm-remote-connection.c
+++ b/src/libnm-client-impl/nm-remote-connection.c
@@ -31,12 +31,14 @@ NM_GOBJECT_PROPERTIES_DEFINE(NMRemoteConnection,
PROP_UNSAVED,
PROP_FLAGS,
PROP_FILENAME,
+ PROP_VERSION_ID,
PROP_VISIBLE, );
typedef struct {
GCancellable *get_settings_cancellable;
char *filename;
+ guint64 version_id;
guint32 flags;
bool unsaved;
@@ -602,6 +604,23 @@ nm_remote_connection_get_filename(NMRemoteConnection *connection)
}
/**
+ * nm_remote_connection_get_version_id:
+ * @connection: the #NMRemoteConnection
+ *
+ * Returns: the version-id of the profile. This ID is incremented
+ * whenever the profile is modified.
+ *
+ * Since: 1.44
+ */
+guint64
+nm_remote_connection_get_version_id(NMRemoteConnection *connection)
+{
+ g_return_val_if_fail(NM_IS_REMOTE_CONNECTION(connection), 0);
+
+ return NM_REMOTE_CONNECTION_GET_PRIVATE(connection)->version_id;
+}
+
+/**
* nm_remote_connection_get_visible:
* @connection: the #NMRemoteConnection
*
@@ -724,6 +743,9 @@ get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
case PROP_FILENAME:
g_value_set_string(value, NM_REMOTE_CONNECTION_GET_PRIVATE(object)->filename);
break;
+ case PROP_VERSION_ID:
+ g_value_set_uint64(value, NM_REMOTE_CONNECTION_GET_PRIVATE(object)->version_id);
+ break;
case PROP_VISIBLE:
g_value_set_boolean(value, NM_REMOTE_CONNECTION_GET_PRIVATE(object)->visible);
break;
@@ -759,10 +781,11 @@ const NMLDBusMetaIface _nml_dbus_meta_iface_nm_settings_connection = NML_DBUS_ME
NMRemoteConnection,
_priv.filename),
NML_DBUS_META_PROPERTY_INIT_U("Flags", PROP_FLAGS, NMRemoteConnection, _priv.flags),
- NML_DBUS_META_PROPERTY_INIT_B("Unsaved",
- PROP_UNSAVED,
+ NML_DBUS_META_PROPERTY_INIT_B("Unsaved", PROP_UNSAVED, NMRemoteConnection, _priv.unsaved),
+ NML_DBUS_META_PROPERTY_INIT_T("VersionId",
+ PROP_VERSION_ID,
NMRemoteConnection,
- _priv.unsaved), ), );
+ _priv.version_id), ), );
static void
nm_remote_connection_class_init(NMRemoteConnectionClass *klass)
@@ -820,6 +843,23 @@ nm_remote_connection_class_init(NMRemoteConnectionClass *klass)
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
/**
+ * NMRemoteConnection:version-id:
+ *
+ * The version ID of the profile that is incremented when the profile gets modified.
+ * This can be used to track concurrent modifications of the profile.
+ *
+ * Since: 1.44
+ **/
+ obj_properties[PROP_VERSION_ID] =
+ g_param_spec_uint64(NM_REMOTE_CONNECTION_VERSION_ID,
+ "",
+ "",
+ 0,
+ G_MAXUINT64,
+ 0,
+ G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
+
+ /**
* NMRemoteConnection:visible:
*
* %TRUE if the remote connection is visible to the current user, %FALSE if
diff --git a/src/libnm-client-public/nm-remote-connection.h b/src/libnm-client-public/nm-remote-connection.h
index abfeecb367..1b4ea22cf1 100644
--- a/src/libnm-client-public/nm-remote-connection.h
+++ b/src/libnm-client-public/nm-remote-connection.h
@@ -32,6 +32,7 @@ G_BEGIN_DECLS
#define NM_REMOTE_CONNECTION_UNSAVED "unsaved"
#define NM_REMOTE_CONNECTION_FLAGS "flags"
#define NM_REMOTE_CONNECTION_FILENAME "filename"
+#define NM_REMOTE_CONNECTION_VERSION_ID "version-id"
#define NM_REMOTE_CONNECTION_VISIBLE "visible"
/**
@@ -120,6 +121,9 @@ const char *nm_remote_connection_get_filename(NMRemoteConnection *connection);
gboolean nm_remote_connection_get_visible(NMRemoteConnection *connection);
+NM_AVAILABLE_IN_1_44
+guint64 nm_remote_connection_get_version_id(NMRemoteConnection *connection);
+
G_END_DECLS
#endif /* __NM_REMOTE_CONNECTION__ */