diff options
author | Beniamino Galvani <bgalvani@redhat.com> | 2021-09-28 22:15:24 +0200 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2021-09-28 22:18:13 +0200 |
commit | 8a06d66d0e634dc6eddf7c061d043facb535fb72 (patch) | |
tree | 16214f2e8e21116ce8a9e0400c081e738f1f0eb1 | |
parent | f3def63fed8c6c1baf66aa5426d3e8c95b917762 (diff) | |
download | NetworkManager-8a06d66d0e634dc6eddf7c061d043facb535fb72.tar.gz |
l3cfg: fix nm_l3cfg_commit_type_register() to set commit_type and add debug logging
Co-authored-by: Thomas Haller <thaller@redhat.com>
-rw-r--r-- | src/core/nm-l3-ipv4ll.c | 3 | ||||
-rw-r--r-- | src/core/nm-l3-ipv6ll.c | 3 | ||||
-rw-r--r-- | src/core/nm-l3cfg.c | 33 | ||||
-rw-r--r-- | src/core/nm-l3cfg.h | 3 | ||||
-rw-r--r-- | src/core/tests/test-l3cfg.c | 9 |
5 files changed, 37 insertions, 14 deletions
diff --git a/src/core/nm-l3-ipv4ll.c b/src/core/nm-l3-ipv4ll.c index bcc6931896..eb9ceb9b85 100644 --- a/src/core/nm-l3-ipv4ll.c +++ b/src/core/nm-l3-ipv4ll.c @@ -601,7 +601,8 @@ _l3cd_config_add(NML3IPv4LL *self) self->l3cfg_commit_handle = nm_l3cfg_commit_type_register(self->l3cfg, NM_L3_CFG_COMMIT_TYPE_ASSUME, - self->l3cfg_commit_handle); + self->l3cfg_commit_handle, + "ipv4ll"); nm_l3cfg_commit_on_idle_schedule(self->l3cfg, NM_L3_CFG_COMMIT_TYPE_AUTO); } diff --git a/src/core/nm-l3-ipv6ll.c b/src/core/nm-l3-ipv6ll.c index 49c59ae57a..143873213d 100644 --- a/src/core/nm-l3-ipv6ll.c +++ b/src/core/nm-l3-ipv6ll.c @@ -430,7 +430,8 @@ _lladdr_handle_changed(NML3IPv6LL *self) self->l3cfg_commit_handle = nm_l3cfg_commit_type_register(self->l3cfg, l3cd ? NM_L3_CFG_COMMIT_TYPE_ASSUME : NM_L3_CFG_COMMIT_TYPE_NONE, - self->l3cfg_commit_handle); + self->l3cfg_commit_handle, + "ipv6ll"); if (changed) nm_l3cfg_commit_on_idle_schedule(self->l3cfg, NM_L3_CFG_COMMIT_TYPE_AUTO); diff --git a/src/core/nm-l3cfg.c b/src/core/nm-l3cfg.c index ca41f8bbbc..ecbbd8ec0a 100644 --- a/src/core/nm-l3cfg.c +++ b/src/core/nm-l3cfg.c @@ -3811,6 +3811,7 @@ nm_l3cfg_commit_type_get(NML3Cfg *self) * @commit_type: the commit type to register * @existing_handle: instead of being a new registration, update an existing handle. * This may be %NULL, which is like having no previous registration. + * @source: the source of the commit type, for logging. * * NML3Cfg needs to know whether it is in charge of an interface (and how "much"). * By default, it is not in charge, but various users can register themself with @@ -3823,11 +3824,14 @@ nm_l3cfg_commit_type_get(NML3Cfg *self) NML3CfgCommitTypeHandle * nm_l3cfg_commit_type_register(NML3Cfg * self, NML3CfgCommitType commit_type, - NML3CfgCommitTypeHandle *existing_handle) + NML3CfgCommitTypeHandle *existing_handle, + const char * source) { NML3CfgCommitTypeHandle *handle; NML3CfgCommitTypeHandle *h; gboolean linked; + NML3CfgCommitTypeHandle *ret = NULL; + char buf[64]; nm_assert(NM_IS_L3CFG(self)); nm_assert(NM_IN_SET(commit_type, @@ -3841,21 +3845,24 @@ nm_l3cfg_commit_type_register(NML3Cfg * self, if (existing_handle) { if (commit_type == NM_L3_CFG_COMMIT_TYPE_NONE) { nm_l3cfg_commit_type_unregister(self, existing_handle); - return NULL; + goto out; + } + if (existing_handle->commit_type == commit_type) { + ret = existing_handle; + goto out; } - if (existing_handle->commit_type == commit_type) - return existing_handle; c_list_unlink_stale(&existing_handle->commit_type_lst); handle = existing_handle; } else { if (commit_type == NM_L3_CFG_COMMIT_TYPE_NONE) - return NULL; - handle = g_slice_new(NML3CfgCommitTypeHandle); - handle->commit_type = commit_type; + goto out; + handle = g_slice_new(NML3CfgCommitTypeHandle); if (c_list_is_empty(&self->priv.p->commit_type_lst_head)) g_object_ref(self); } + handle->commit_type = commit_type; + linked = FALSE; c_list_for_each_entry (h, &self->priv.p->commit_type_lst_head, commit_type_lst) { if (handle->commit_type >= h->commit_type) { @@ -3867,7 +3874,15 @@ nm_l3cfg_commit_type_register(NML3Cfg * self, if (!linked) c_list_link_tail(&self->priv.p->commit_type_lst_head, &handle->commit_type_lst); - return handle; + ret = handle; +out: + _LOGT("commit type register (type \"%s\", source \"%s\", existing " NM_HASH_OBFUSCATE_PTR_FMT + ") -> " NM_HASH_OBFUSCATE_PTR_FMT "", + _l3_cfg_commit_type_to_string(commit_type, buf, sizeof(buf)), + source, + NM_HASH_OBFUSCATE_PTR(existing_handle), + NM_HASH_OBFUSCATE_PTR(ret)); + return ret; } void @@ -3880,6 +3895,8 @@ nm_l3cfg_commit_type_unregister(NML3Cfg *self, NML3CfgCommitTypeHandle *handle) nm_assert(c_list_contains(&self->priv.p->commit_type_lst_head, &handle->commit_type_lst)); + _LOGT("commit type unregister " NM_HASH_OBFUSCATE_PTR_FMT "", NM_HASH_OBFUSCATE_PTR(handle)); + c_list_unlink_stale(&handle->commit_type_lst); if (c_list_is_empty(&self->priv.p->commit_type_lst_head)) g_object_unref(self); diff --git a/src/core/nm-l3cfg.h b/src/core/nm-l3cfg.h index 76cbd3cf3a..368165ac7c 100644 --- a/src/core/nm-l3cfg.h +++ b/src/core/nm-l3cfg.h @@ -384,7 +384,8 @@ typedef struct _NML3CfgCommitTypeHandle NML3CfgCommitTypeHandle; NML3CfgCommitTypeHandle *nm_l3cfg_commit_type_register(NML3Cfg * self, NML3CfgCommitType commit_type, - NML3CfgCommitTypeHandle *existing_handle); + NML3CfgCommitTypeHandle *existing_handle, + const char * source); void nm_l3cfg_commit_type_unregister(NML3Cfg *self, NML3CfgCommitTypeHandle *handle); diff --git a/src/core/tests/test-l3cfg.c b/src/core/tests/test-l3cfg.c index 82b515d0f2..7b8db6778e 100644 --- a/src/core/tests/test-l3cfg.c +++ b/src/core/tests/test-l3cfg.c @@ -371,7 +371,8 @@ test_l3cfg(gconstpointer test_data) g_signal_connect(l3cfg0, NM_L3CFG_SIGNAL_NOTIFY, G_CALLBACK(_test_l3cfg_signal_notify), tdata); - commit_type_1 = nm_l3cfg_commit_type_register(l3cfg0, NM_L3_CFG_COMMIT_TYPE_UPDATE, NULL); + commit_type_1 = + nm_l3cfg_commit_type_register(l3cfg0, NM_L3_CFG_COMMIT_TYPE_UPDATE, NULL, "test1"); if (!nmtst_get_rand_one_case_in(4)) { commit_type_2 = @@ -379,7 +380,8 @@ test_l3cfg(gconstpointer test_data) nmtst_rand_select(NM_L3_CFG_COMMIT_TYPE_NONE, NM_L3_CFG_COMMIT_TYPE_ASSUME, NM_L3_CFG_COMMIT_TYPE_UPDATE), - NULL); + NULL, + "test2"); } else commit_type_2 = NULL; @@ -612,7 +614,8 @@ _test_l3_ipv4ll_signal_notify(NML3Cfg * l3cfg, tdata->l3cfg_commit_type_1 = nm_l3cfg_commit_type_register(nm_l3_ipv4ll_get_l3cfg(tdata->l3ipv4ll), NM_L3_CFG_COMMIT_TYPE_UPDATE, - tdata->l3cfg_commit_type_1); + tdata->l3cfg_commit_type_1, + "test"); } } else if (nm_l3_ipv4ll_get_state(tdata->l3ipv4ll) != NM_L3_IPV4LL_STATE_DEFENDING && tdata->ready_seen > 0) { |