summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2023-03-08 15:32:30 +0100
committerThomas Haller <thaller@redhat.com>2023-03-08 15:34:48 +0100
commita44489697dd690544922208e6cb4880088a84653 (patch)
treed6867154d5b25bf5b1cf2f6c3ac0fef2b4f570fd
parent17935511a571ffc9e831b629d25a5b526179f34e (diff)
parent5558498721b5c693418c555f14090a511151a52b (diff)
downloadNetworkManager-a44489697dd690544922208e6cb4880088a84653.tar.gz
all: merge branch 'th/platform-rt-prefsrc' (part 1)
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1550
-rw-r--r--src/core/nm-netns.c2
-rw-r--r--src/libnm-core-impl/tests/test-general.c8
-rw-r--r--src/libnm-glib-aux/nm-dedup-multi.c2
-rw-r--r--src/libnm-glib-aux/nm-logging-fwd.h18
-rw-r--r--src/libnm-platform/nmp-global-tracker.c5
-rw-r--r--src/libnm-std-aux/c-list-util.h6
-rw-r--r--src/libnm-std-aux/nm-std-aux.h3
7 files changed, 31 insertions, 13 deletions
diff --git a/src/core/nm-netns.c b/src/core/nm-netns.c
index dfdaaa06c7..88a4d66001 100644
--- a/src/core/nm-netns.c
+++ b/src/core/nm-netns.c
@@ -695,7 +695,7 @@ nm_netns_ip_route_ecmp_commit(NMNetns *self,
/* This route is onlink. We don't need to configure an onlink route
* to the gateway, and the route is immediately ready for configuration. */
track_obj->is_ready = TRUE;
- } else if (c_list_length_is(&track_ecmpid->ecmpid_lst_head, 1)) {
+ } else if (c_list_is_empty_or_single(&track_ecmpid->ecmpid_lst_head)) {
/* This route has no merge partner and ends up being a
* single hop route. It will be returned and configured by
* the calling "l3cfg".
diff --git a/src/libnm-core-impl/tests/test-general.c b/src/libnm-core-impl/tests/test-general.c
index 8a98265abb..84d9caaeae 100644
--- a/src/libnm-core-impl/tests/test-general.c
+++ b/src/libnm-core-impl/tests/test-general.c
@@ -1417,6 +1417,7 @@ _do_test_c_list_sort(CListSort *elements, guint n_list, gboolean headless)
g_assert(!c_list_is_empty(&head));
g_assert(c_list_length(&head) == n_list);
+ g_assert(c_list_is_empty_or_single(&head) == (n_list <= 1));
el_prev = NULL;
c_list_for_each (iter, &head) {
@@ -1443,6 +1444,10 @@ test_c_list_sort(void)
guint n_list;
guint repeat;
+ g_assert(!c_list_is_linked(NULL));
+ g_assert(c_list_is_empty(NULL));
+ g_assert(c_list_is_empty_or_single(NULL));
+
{
CList head;
@@ -1450,6 +1455,7 @@ test_c_list_sort(void)
c_list_sort(&head, _c_list_sort_cmp, NULL);
g_assert(c_list_length(&head) == 0);
g_assert(c_list_is_empty(&head));
+ g_assert(c_list_is_empty_or_single(&head));
}
elements = g_new0(CListSort, N_ELEMENTS);
@@ -1517,6 +1523,8 @@ _do_test_c_list_insert_sorted(CListSort *elements, guint n_list, bool append_equ
g_assert(c_list_length_is(&head, n_list));
g_assert(!c_list_length_is(&head, n_list + 1));
+ g_assert(c_list_is_empty_or_single(&head) == (n_list <= 1));
+
el_prev = NULL;
c_list_for_each_entry (el, &head, lst) {
if (el_prev) {
diff --git a/src/libnm-glib-aux/nm-dedup-multi.c b/src/libnm-glib-aux/nm-dedup-multi.c
index 625c4ef31e..82f4802f3b 100644
--- a/src/libnm-glib-aux/nm-dedup-multi.c
+++ b/src/libnm-glib-aux/nm-dedup-multi.c
@@ -97,7 +97,7 @@ _entry_lookup_head(const NMDedupMultiIndex *self,
if (c_list_is_empty(&idx_type->lst_idx_head))
head_entry = NULL;
else {
- nm_assert(c_list_length(&idx_type->lst_idx_head) == 1);
+ nm_assert(c_list_length_is(&idx_type->lst_idx_head, 1));
head_entry = c_list_entry(idx_type->lst_idx_head.next, NMDedupMultiHeadEntry, lst_idx);
}
nm_assert(head_entry == g_hash_table_lookup(self->idx_entries, &stack_entry));
diff --git a/src/libnm-glib-aux/nm-logging-fwd.h b/src/libnm-glib-aux/nm-logging-fwd.h
index 72e5723c28..f7ab9098bf 100644
--- a/src/libnm-glib-aux/nm-logging-fwd.h
+++ b/src/libnm-glib-aux/nm-logging-fwd.h
@@ -177,8 +177,8 @@ extern void _nm_utils_monotonic_timestamp_initialized(const struct timespec *tp,
#define _LOGW(...) _NMLOG(_LOGL_WARN, __VA_ARGS__)
#define _LOGE(...) _NMLOG(_LOGL_ERR, __VA_ARGS__)
-#define _LOGT_ENABLED(...) _NMLOG_ENABLED(_LOGL_TRACE, ##__VA_ARGS__)
-#define _LOGD_ENABLED(...) _NMLOG_ENABLED(_LOGL_DEBUG, ##__VA_ARGS__)
+#define _LOGT_ENABLED(...) G_UNLIKELY(_NMLOG_ENABLED(_LOGL_TRACE, ##__VA_ARGS__))
+#define _LOGD_ENABLED(...) G_UNLIKELY(_NMLOG_ENABLED(_LOGL_DEBUG, ##__VA_ARGS__))
#define _LOGI_ENABLED(...) _NMLOG_ENABLED(_LOGL_INFO, ##__VA_ARGS__)
#define _LOGW_ENABLED(...) _NMLOG_ENABLED(_LOGL_WARN, ##__VA_ARGS__)
#define _LOGE_ENABLED(...) _NMLOG_ENABLED(_LOGL_ERR, ##__VA_ARGS__)
@@ -192,7 +192,7 @@ extern void _nm_utils_monotonic_timestamp_initialized(const struct timespec *tp,
/* _LOGT() and _LOGt() both log with level TRACE, but the latter is disabled by default,
* unless building with --with-more-logging. */
#if NM_MORE_LOGGING
-#define _LOGt_ENABLED(...) _NMLOG_ENABLED(_LOGL_TRACE, ##__VA_ARGS__)
+#define _LOGt_ENABLED(...) G_UNLIKELY(_NMLOG_ENABLED(_LOGL_TRACE, ##__VA_ARGS__))
#define _LOGt(...) _NMLOG(_LOGL_TRACE, __VA_ARGS__)
#define _LOGt_err(errsv, ...) _NMLOG_err(errsv, _LOGL_TRACE, __VA_ARGS__)
#else
@@ -233,8 +233,8 @@ extern void _nm_utils_monotonic_timestamp_initialized(const struct timespec *tp,
#define _LOG2W(...) _NMLOG2(_LOGL_WARN, __VA_ARGS__)
#define _LOG2E(...) _NMLOG2(_LOGL_ERR, __VA_ARGS__)
-#define _LOG2T_ENABLED(...) _NMLOG2_ENABLED(_LOGL_TRACE, ##__VA_ARGS__)
-#define _LOG2D_ENABLED(...) _NMLOG2_ENABLED(_LOGL_DEBUG, ##__VA_ARGS__)
+#define _LOG2T_ENABLED(...) G_UNLIKELY(_NMLOG2_ENABLED(_LOGL_TRACE, ##__VA_ARGS__))
+#define _LOG2D_ENABLED(...) G_UNLIKELY(_NMLOG2_ENABLED(_LOGL_DEBUG, ##__VA_ARGS__))
#define _LOG2I_ENABLED(...) _NMLOG2_ENABLED(_LOGL_INFO, ##__VA_ARGS__)
#define _LOG2W_ENABLED(...) _NMLOG2_ENABLED(_LOGL_WARN, ##__VA_ARGS__)
#define _LOG2E_ENABLED(...) _NMLOG2_ENABLED(_LOGL_ERR, ##__VA_ARGS__)
@@ -246,7 +246,7 @@ extern void _nm_utils_monotonic_timestamp_initialized(const struct timespec *tp,
#define _LOG2E_err(errsv, ...) _NMLOG2_err(errsv, _LOGL_ERR, __VA_ARGS__)
#if NM_MORE_LOGGING
-#define _LOG2t_ENABLED(...) _NMLOG2_ENABLED(_LOGL_TRACE, ##__VA_ARGS__)
+#define _LOG2t_ENABLED(...) G_UNLIKELY(_NMLOG2_ENABLED(_LOGL_TRACE, ##__VA_ARGS__))
#define _LOG2t(...) _NMLOG2(_LOGL_TRACE, __VA_ARGS__)
#define _LOG2t_err(errsv, ...) _NMLOG2_err(errsv, _LOGL_TRACE, __VA_ARGS__)
#else
@@ -278,8 +278,8 @@ extern void _nm_utils_monotonic_timestamp_initialized(const struct timespec *tp,
#define _LOG3W(...) _NMLOG3(_LOGL_WARN, __VA_ARGS__)
#define _LOG3E(...) _NMLOG3(_LOGL_ERR, __VA_ARGS__)
-#define _LOG3T_ENABLED(...) _NMLOG3_ENABLED(_LOGL_TRACE, ##__VA_ARGS__)
-#define _LOG3D_ENABLED(...) _NMLOG3_ENABLED(_LOGL_DEBUG, ##__VA_ARGS__)
+#define _LOG3T_ENABLED(...) G_UNLIKELY(_NMLOG3_ENABLED(_LOGL_TRACE, ##__VA_ARGS__))
+#define _LOG3D_ENABLED(...) G_UNLIKELY(_NMLOG3_ENABLED(_LOGL_DEBUG, ##__VA_ARGS__))
#define _LOG3I_ENABLED(...) _NMLOG3_ENABLED(_LOGL_INFO, ##__VA_ARGS__)
#define _LOG3W_ENABLED(...) _NMLOG3_ENABLED(_LOGL_WARN, ##__VA_ARGS__)
#define _LOG3E_ENABLED(...) _NMLOG3_ENABLED(_LOGL_ERR, ##__VA_ARGS__)
@@ -291,7 +291,7 @@ extern void _nm_utils_monotonic_timestamp_initialized(const struct timespec *tp,
#define _LOG3E_err(errsv, ...) _NMLOG3_err(errsv, _LOGL_ERR, __VA_ARGS__)
#if NM_MORE_LOGGING
-#define _LOG3t_ENABLED(...) _NMLOG3_ENABLED(_LOGL_TRACE, ##__VA_ARGS__)
+#define _LOG3t_ENABLED(...) G_UNLIKELY(_NMLOG3_ENABLED(_LOGL_TRACE, ##__VA_ARGS__))
#define _LOG3t(...) _NMLOG3(_LOGL_TRACE, __VA_ARGS__)
#define _LOG3t_err(errsv, ...) _NMLOG3_err(errsv, _LOGL_TRACE, __VA_ARGS__)
#else
diff --git a/src/libnm-platform/nmp-global-tracker.c b/src/libnm-platform/nmp-global-tracker.c
index 8f36c124ef..b06e9fe5db 100644
--- a/src/libnm-platform/nmp-global-tracker.c
+++ b/src/libnm-platform/nmp-global-tracker.c
@@ -540,12 +540,13 @@ _track_data_untrack(NMPGlobalTracker *self,
* sync. */
obj_data->config_state = CONFIG_STATE_OWNED_BY_US;
}
- } else if (remove_user_tag_data && c_list_length_is(&track_data->user_tag_lst, 1))
+ } else if (remove_user_tag_data && c_list_is_empty_or_single(&track_data->user_tag_lst))
g_hash_table_remove(self->by_user_tag, &track_data->user_tag);
/* if obj_data is marked to be "added_by_us" or "removed_by_us", we need to keep this entry
* around for the next sync -- so that we can undo what we did earlier. */
- if (obj_data->config_state == CONFIG_STATE_NONE && c_list_length_is(&track_data->obj_lst, 1))
+ if (obj_data->config_state == CONFIG_STATE_NONE
+ && c_list_is_empty_or_single(&track_data->obj_lst))
g_hash_table_remove(self->by_obj, &track_data->obj);
g_hash_table_remove(self->by_data, track_data);
diff --git a/src/libnm-std-aux/c-list-util.h b/src/libnm-std-aux/c-list-util.h
index 4800a3cc11..ae2f07ec8c 100644
--- a/src/libnm-std-aux/c-list-util.h
+++ b/src/libnm-std-aux/c-list-util.h
@@ -42,6 +42,12 @@ c_list_length_is(const CList *list, unsigned long check_len)
return n == check_len;
}
+static inline int
+c_list_is_empty_or_single(const CList *list)
+{
+ return !list || (list->next->next == list);
+}
+
#define c_list_for_each_prev(_iter, _list) \
for (_iter = (_list)->prev; (_iter) != (_list); _iter = (_iter)->prev)
diff --git a/src/libnm-std-aux/nm-std-aux.h b/src/libnm-std-aux/nm-std-aux.h
index a5e5abd3d5..a146487eff 100644
--- a/src/libnm-std-aux/nm-std-aux.h
+++ b/src/libnm-std-aux/nm-std-aux.h
@@ -1419,6 +1419,9 @@ nm_utils_addr_family_to_char(int addr_family)
(NM_UNIQ_T(_addr_family, uniq) == NM_AF_INET); \
})
+/* NM_IS_IPv4() is guaranteed to give either 0 or 1! That is an important
+ * guarantee, because we often use that value to index a 2-array (where at
+ * position zero is IPv6 and at position 1 IPv4). */
#define NM_IS_IPv4(addr_family) _NM_IS_IPv4(NM_UNIQ, addr_family)
static inline int