libnm: rework team handling of JSON config

System Internals / NetworkManager - Thomas Haller [] - 23 May 2019 16:09 EDT

Completely refactor the team/JSON handling in libnm's NMSettingTeam and NMSettingTeamPort.

- team handling was added as rh#1398925. The goal is to have a more convenient way to set properties than constructing JSON. This requires libnm to implement the hard task of parsing JSON (and exposing well-understood properties) and generating JSON (based on these "artificial" properties). But not only libnm. In particular nmcli and the D-Bus API must make this "simpler" API accessible.

- since NMSettingTeam and NMSettingTeamPort are conceptually the same, add "libnm-core/nm-team-utils.h" and NMTeamSetting that tries to handle the similar code side-by-sdie. The setting classes now just delegate for everything to NMTeamSetting.

- Previously, there was a very fuzzy understanding of the provided JSON config. Tighten that up, when setting a JSON config it regenerates/parses all other properties and tries to make the best of it. When modifying any abstraction property, the entire JSON config gets regenerated. In particular, don't try to merge existing JSON config with the new fields. If the user uses the abstraction API, then the entire JSON gets replaced.

For example note that nm_setting_team_add_link_watcher() would not be reflected in the JSON config (a bug). That only accidentally worked because client would serializing the changed link watcher to GVariant/D-Bus, then NetworkManager would set it via g_object_set(), which would renerate the JSON, and finally persist it to disk. But as far as libnm is concerned, nm_setting_team_add_link_watcher() would bring the settings instance in an inconsistent state where JSON and the link watcher property disagree. Setting any property must immediately update both the JSON and the abstraction API.

- when constucting a team setting from D-Bus, we would previously parse both "config" and abstraction properties. That is wrong. Since our settings plugins only support JSON, all information must be present in the JSON config anyway. So, when "config" is present, only the JSON must be parsed. In the best case, the other information is redudant and contributes nothing. In the worse case, they information differs (which might happen if the client version differs from the server
version). As the settings plugin only supports JSON, it's wrong to consider redundant, differing information from D-Bus.

- we now only convert string to JSON or back when needed. Previously, setting a property resulted in parsing several JSON multiple times (per property). All operations should now scale well and be reasonably efficient.

- also the property-changed signals are now handled correctly. Since NMTeamSetting knows the current state of all attributes, it can emit the exact property changed signals for what changed.

- we no longer use libjansson to generate the JSON. JSON is supposed to be a machine readable exchange format, hence a major goal is to be easily handled by applications. While parsing JSON is not so trivial, writing a well-known set of values to JSON is. The advantage is that when you build libnm without libjansson support, then we still can convert the artificial properties to JSON.

- Requiring libjansson in libnm is a burden, because most of the time it is not needed (as most users don't create team configurations). With this change we only require it to parse the team settings (no longer to write them). It should be reasonably simple to use a more minimalistic JSON parser that is sufficient for us, so that we can get rid of the libjansson dependency (for libnm). This also avoids the pain that we have due to the symbol collision of libjansson and libjson-glib.

13f6f3a41 libnm: rework team handling of JSON config
clients/common/ | 2 +-
libnm-core/nm-core-internal.h | 13 -
libnm-core/nm-setting-team-port.c | 344 ++--
libnm-core/nm-setting-team.c | 694 +++----
libnm-core/nm-team-utils.c | 1990 ++++++++++++++++++++
libnm-core/nm-team-utils.h | 246 +++
libnm-core/nm-utils-private.h | 112 --
libnm-core/nm-utils.c | 752 +-------
libnm-core/tests/test-general.c | 59 +-
libnm-core/tests/test-setting.c | 86 +-
libnm/ | 2 +
po/ | 1 +
.../plugins/ifcfg-rh/tests/test-ifcfg-rh.c | 10 +-
13 files changed, 2728 insertions(+), 1583 deletions(-)


  • Share