diff options
author | Thomas Haller <thaller@redhat.com> | 2019-04-19 11:51:42 +0200 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2019-04-20 08:09:33 +0200 |
commit | 48316f987a55474fc6db53c0354961f79ae475cf (patch) | |
tree | 7a0870862b326b209fbf9b20f2c4336eec655596 | |
parent | 84e19c6ca9a921bb780d9109a93e338f50ede7eb (diff) | |
download | NetworkManager-48316f987a55474fc6db53c0354961f79ae475cf.tar.gz |
libnm-core: avoid cloning attributes of NMTCQdisc/NMTCAction to convert to string
-rw-r--r-- | libnm-core/nm-core-internal.h | 5 | ||||
-rw-r--r-- | libnm-core/nm-keyfile.c | 5 | ||||
-rw-r--r-- | libnm-core/nm-setting-ip-config.c | 2 | ||||
-rw-r--r-- | libnm-core/nm-setting-tc-config.c | 16 | ||||
-rw-r--r-- | libnm-core/nm-utils.c | 32 |
5 files changed, 29 insertions, 31 deletions
diff --git a/libnm-core/nm-core-internal.h b/libnm-core/nm-core-internal.h index 966a4ada9c..3e33dd930d 100644 --- a/libnm-core/nm-core-internal.h +++ b/libnm-core/nm-core-internal.h @@ -262,7 +262,7 @@ const char **_nm_ip_address_get_attribute_names (const NMIPAddress *addr, gboole gboolean _nm_ip_route_attribute_validate_all (const NMIPRoute *route); const char **_nm_ip_route_get_attribute_names (const NMIPRoute *route, gboolean sorted, guint *out_length); -GHashTable *_nm_ip_route_get_attributes_direct (NMIPRoute *route); +GHashTable *_nm_ip_route_get_attributes (NMIPRoute *route); NMSriovVF *_nm_utils_sriov_vf_from_strparts (const char *index, const char *detail, gboolean ignore_unknown, GError **error); gboolean _nm_sriov_vf_attribute_validate_all (const NMSriovVF *vf, GError **error); @@ -560,6 +560,9 @@ gboolean _nm_utils_string_append_tc_tfilter_rest (GString *string, NMTCTfilter *tfilter, GError **error); +GHashTable *_nm_tc_qdisc_get_attributes (NMTCQdisc *qdisc); +GHashTable *_nm_tc_action_get_attributes (NMTCAction *action); + /*****************************************************************************/ static inline gboolean diff --git a/libnm-core/nm-keyfile.c b/libnm-core/nm-keyfile.c index 6fb0099e85..bf8d219310 100644 --- a/libnm-core/nm-keyfile.c +++ b/libnm-core/nm-keyfile.c @@ -1943,10 +1943,9 @@ write_ip_values (GKeyFile *file, if (is_route) { gs_free char *attributes = NULL; - GHashTable *hash; - hash = _nm_ip_route_get_attributes_direct (array->pdata[i]); - attributes = nm_utils_format_variant_attributes (hash, ',', '='); + attributes = nm_utils_format_variant_attributes (_nm_ip_route_get_attributes (array->pdata[i]), + ',', '='); if (attributes) { g_strlcat (key_name, "_options", sizeof (key_name)); nm_keyfile_plugin_kf_set_string (file, setting_name, key_name, attributes); diff --git a/libnm-core/nm-setting-ip-config.c b/libnm-core/nm-setting-ip-config.c index d4a38161dd..f362945f41 100644 --- a/libnm-core/nm-setting-ip-config.c +++ b/libnm-core/nm-setting-ip-config.c @@ -1116,7 +1116,7 @@ nm_ip_route_set_metric (NMIPRoute *route, } GHashTable * -_nm_ip_route_get_attributes_direct (NMIPRoute *route) +_nm_ip_route_get_attributes (NMIPRoute *route) { nm_assert (route); diff --git a/libnm-core/nm-setting-tc-config.c b/libnm-core/nm-setting-tc-config.c index d040a2ffbc..aa822d83d1 100644 --- a/libnm-core/nm-setting-tc-config.c +++ b/libnm-core/nm-setting-tc-config.c @@ -342,6 +342,14 @@ nm_tc_qdisc_get_attribute_names (NMTCQdisc *qdisc) return nm_utils_strv_make_deep_copied_nonnull (names); } +GHashTable * +_nm_tc_qdisc_get_attributes (NMTCQdisc *qdisc) +{ + nm_assert (qdisc); + + return qdisc->attributes; +} + /** * nm_tc_qdisc_get_attribute: * @qdisc: the #NMTCQdisc @@ -605,6 +613,14 @@ nm_tc_action_get_attribute_names (NMTCAction *action) return nm_utils_strv_make_deep_copied_nonnull (names); } +GHashTable * +_nm_tc_action_get_attributes (NMTCAction *action) +{ + nm_assert (action); + + return action->attributes; +} + /** * nm_tc_action_get_attribute: * @action: the #NMTCAction diff --git a/libnm-core/nm-utils.c b/libnm-core/nm-utils.c index 3238c12345..04d5b1b558 100644 --- a/libnm-core/nm-utils.c +++ b/libnm-core/nm-utils.c @@ -2332,12 +2332,9 @@ static const NMQdiscAttributeSpec *const tc_qdisc_attribute_spec[] = { void _nm_utils_string_append_tc_qdisc_rest (GString *string, NMTCQdisc *qdisc) { - gs_unref_hashtable GHashTable *ht = NULL; guint32 handle = nm_tc_qdisc_get_handle (qdisc); const char *kind = nm_tc_qdisc_get_kind (qdisc); - gs_strfreev char **attr_names = NULL; gs_free char *str = NULL; - guint i; if (handle != TC_H_UNSPEC && strcmp (kind, "ingress") != 0) { g_string_append (string, "handle "); @@ -2347,16 +2344,9 @@ _nm_utils_string_append_tc_qdisc_rest (GString *string, NMTCQdisc *qdisc) g_string_append (string, kind); - attr_names = nm_tc_qdisc_get_attribute_names (qdisc); - if (attr_names[0]) - ht = g_hash_table_new_full (nm_str_hash, g_str_equal, NULL, NULL); - for (i = 0; attr_names[i]; i++) { - g_hash_table_insert (ht, attr_names[i], - nm_tc_qdisc_get_attribute (qdisc, attr_names[i])); - } - - if (i) { - str = nm_utils_format_variant_attributes (ht, ' ', ' '); + str = nm_utils_format_variant_attributes (_nm_tc_qdisc_get_attributes (qdisc), + ' ', ' '); + if (str) { g_string_append_c (string, ' '); g_string_append (string, str); } @@ -2548,24 +2538,14 @@ static const NMVariantAttributeSpec * const tc_action_attribute_spec[] = { static gboolean _string_append_tc_action (GString *string, NMTCAction *action, GError **error) { - gs_unref_hashtable GHashTable *ht = NULL; const char *kind = nm_tc_action_get_kind (action); - gs_strfreev char **attr_names = NULL; gs_free char *str = NULL; - int i; - - ht = g_hash_table_new_full (nm_str_hash, g_str_equal, NULL, NULL); g_string_append (string, kind); - attr_names = nm_tc_action_get_attribute_names (action); - for (i = 0; attr_names[i]; i++) { - g_hash_table_insert (ht, attr_names[i], - nm_tc_action_get_attribute (action, attr_names[i])); - } - - if (i) { - str = nm_utils_format_variant_attributes (ht, ' ', ' '); + str = nm_utils_format_variant_attributes (_nm_tc_action_get_attributes (action), + ' ', ' '); + if (str) { g_string_append_c (string, ' '); g_string_append (string, str); } |