settings,libnm: add version-id to settings/remote connection

This commit is contained in:
Thomas Haller 2022-02-25 14:22:53 +01:00
parent 9bc9fde506
commit cf5c576d55
No known key found for this signature in database
GPG Key ID: 29C2366E4DFC5728
7 changed files with 115 additions and 11 deletions

View File

@ -188,6 +188,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.

View File

@ -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,
"",
"",

View File

@ -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,

View File

@ -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,

View File

@ -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;

View File

@ -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;
@ -601,6 +603,23 @@ nm_remote_connection_get_filename(NMRemoteConnection *connection)
return NM_REMOTE_CONNECTION_GET_PRIVATE(connection)->filename;
}
/**
* 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)
@ -819,6 +842,23 @@ nm_remote_connection_class_init(NMRemoteConnectionClass *klass)
NULL,
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:
*

View File

@ -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__ */