From: Jérémie Galarneau Date: Thu, 13 Jun 2024 19:00:17 +0000 (+0000) Subject: hashtable: replace non-const iterator node accessors by a const version X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=00d7d90311aa7e4b6afe1b5e6c95362f9f5eb3f3;p=lttng-tools.git hashtable: replace non-const iterator node accessors by a const version The various lttng_ht_iter_get_node_* functions are not const-correct which makes their use difficult in some places. This is mostly due to the fact that cds_lfht_iter_get_node (from liburcu) is, itself, not const-correct. These functions are replaced by a single templated function that is const-correct by virtue of inlining the trivial iterator node accessor of liburcu. Change-Id: I4df87abedb1ec6b14eb52ce4c212a10805898954 Signed-off-by: Jérémie Galarneau --- diff --git a/src/bin/lttng-relayd/connection.cpp b/src/bin/lttng-relayd/connection.cpp index 668a61e7a..2de3abe2d 100644 --- a/src/bin/lttng-relayd/connection.cpp +++ b/src/bin/lttng-relayd/connection.cpp @@ -32,7 +32,7 @@ struct relay_connection *connection_get_by_sock(struct lttng_ht *relay_connectio lttng::urcu::read_lock_guard read_lock; lttng_ht_lookup(relay_connections_ht, (void *) ((unsigned long) sock), &iter); - node = lttng_ht_iter_get_node_ulong(&iter); + node = lttng_ht_iter_get_node(&iter); if (!node) { DBG2("Relay connection by sock %d not found", sock); goto end; diff --git a/src/bin/lttng-relayd/ctf-trace.cpp b/src/bin/lttng-relayd/ctf-trace.cpp index cde9f3927..81c5a7707 100644 --- a/src/bin/lttng-relayd/ctf-trace.cpp +++ b/src/bin/lttng-relayd/ctf-trace.cpp @@ -152,7 +152,7 @@ struct ctf_trace *ctf_trace_get_by_path_or_create(struct relay_session *session, lttng::urcu::read_lock_guard read_lock; lttng_ht_lookup(session->ctf_traces_ht, subpath, &iter); - node = lttng_ht_iter_get_node_str(&iter); + node = lttng_ht_iter_get_node(&iter); if (!node) { DBG("CTF Trace path %s not found", subpath); goto end; diff --git a/src/bin/lttng-relayd/index.cpp b/src/bin/lttng-relayd/index.cpp index e3b8bde82..7fd94ac43 100644 --- a/src/bin/lttng-relayd/index.cpp +++ b/src/bin/lttng-relayd/index.cpp @@ -122,7 +122,7 @@ struct relay_index *relay_index_get_by_id_or_create(struct relay_stream *stream, lttng::urcu::read_lock_guard read_lock; lttng_ht_lookup(stream->indexes_ht, &net_seq_num, &iter); - node = lttng_ht_iter_get_node_u64(&iter); + node = lttng_ht_iter_get_node(&iter); if (node) { index = lttng::utils::container_of(node, &relay_index::index_n); } else { diff --git a/src/bin/lttng-relayd/session.cpp b/src/bin/lttng-relayd/session.cpp index 8ac4a510d..19f1936f2 100644 --- a/src/bin/lttng-relayd/session.cpp +++ b/src/bin/lttng-relayd/session.cpp @@ -457,7 +457,7 @@ struct relay_session *session_get_by_id(uint64_t id) lttng::urcu::read_lock_guard read_lock; lttng_ht_lookup(sessions_ht, &id, &iter); - node = lttng_ht_iter_get_node_u64(&iter); + node = lttng_ht_iter_get_node(&iter); if (!node) { DBG("Session find by ID %" PRIu64 " id NOT found", id); goto end; diff --git a/src/bin/lttng-relayd/stream.cpp b/src/bin/lttng-relayd/stream.cpp index a0935231d..5390c49bb 100644 --- a/src/bin/lttng-relayd/stream.cpp +++ b/src/bin/lttng-relayd/stream.cpp @@ -50,7 +50,7 @@ struct relay_stream *stream_get_by_id(uint64_t stream_id) lttng::urcu::read_lock_guard read_lock; lttng_ht_lookup(relay_streams_ht, &stream_id, &iter); - node = lttng_ht_iter_get_node_u64(&iter); + node = lttng_ht_iter_get_node(&iter); if (!node) { DBG("Relay stream %" PRIu64 " not found", stream_id); goto end; diff --git a/src/bin/lttng-relayd/viewer-stream.cpp b/src/bin/lttng-relayd/viewer-stream.cpp index 9ca54e67e..8830dae7a 100644 --- a/src/bin/lttng-relayd/viewer-stream.cpp +++ b/src/bin/lttng-relayd/viewer-stream.cpp @@ -265,7 +265,7 @@ struct relay_viewer_stream *viewer_stream_get_by_id(uint64_t id) lttng::urcu::read_lock_guard read_lock; lttng_ht_lookup(viewer_streams_ht, &id, &iter); - node = lttng_ht_iter_get_node_u64(&iter); + node = lttng_ht_iter_get_node(&iter); if (!node) { DBG("Relay viewer stream %" PRIu64 " not found", id); goto end; diff --git a/src/bin/lttng-sessiond/agent.cpp b/src/bin/lttng-sessiond/agent.cpp index 210ec9b0c..5c080ca51 100644 --- a/src/bin/lttng-sessiond/agent.cpp +++ b/src/bin/lttng-sessiond/agent.cpp @@ -1004,7 +1004,7 @@ struct agent_app *agent_find_app_by_sock(int sock) ASSERT_RCU_READ_LOCKED(); lttng_ht_lookup(the_agent_apps_ht_by_sock, (void *) ((unsigned long) sock), &iter); - node = lttng_ht_iter_get_node_ulong(&iter); + node = lttng_ht_iter_get_node(&iter); if (node == nullptr) { goto error; } @@ -1375,7 +1375,7 @@ struct agent_event *agent_find_event(const char *name, ht_match_event, &key, &iter.iter); - node = lttng_ht_iter_get_node_str(&iter); + node = lttng_ht_iter_get_node(&iter); if (node == nullptr) { goto error; } @@ -1624,7 +1624,7 @@ struct agent *agent_find_by_event_notifier_domain(enum lttng_domain_type domain_ lttng_domain_type_str(domain_type)); lttng_ht_lookup(the_trigger_agents_ht_by_domain, &key, &iter); - node = lttng_ht_iter_get_node_u64(&iter); + node = lttng_ht_iter_get_node(&iter); if (!node) { goto end; } diff --git a/src/bin/lttng-sessiond/buffer-registry.cpp b/src/bin/lttng-sessiond/buffer-registry.cpp index b840a7fa9..8e241feb6 100644 --- a/src/bin/lttng-sessiond/buffer-registry.cpp +++ b/src/bin/lttng-sessiond/buffer-registry.cpp @@ -205,7 +205,7 @@ struct buffer_reg_uid *buffer_reg_uid_find(uint64_t session_id, uint32_t bits_pe /* Custom lookup function since it's a different key. */ cds_lfht_lookup(ht->ht, ht->hash_fct(&key, lttng_ht_seed), ht->match_fct, &key, &iter.iter); - node = lttng_ht_iter_get_node_u64(&iter); + node = lttng_ht_iter_get_node(&iter); if (!node) { goto end; } @@ -318,7 +318,7 @@ struct buffer_reg_pid *buffer_reg_pid_find(uint64_t session_id) DBG3("Buffer registry per PID find id: %" PRIu64, session_id); lttng_ht_lookup(ht, &session_id, &iter); - node = lttng_ht_iter_get_node_u64(&iter); + node = lttng_ht_iter_get_node(&iter); if (!node) { goto end; } @@ -473,7 +473,7 @@ struct buffer_reg_channel *buffer_reg_channel_find(uint64_t key, struct buffer_r } lttng_ht_lookup(ht, &key, &iter); - node = lttng_ht_iter_get_node_u64(&iter); + node = lttng_ht_iter_get_node(&iter); if (!node) { goto end; } diff --git a/src/bin/lttng-sessiond/cmd.cpp b/src/bin/lttng-sessiond/cmd.cpp index ee96fc828..8817b4568 100644 --- a/src/bin/lttng-sessiond/cmd.cpp +++ b/src/bin/lttng-sessiond/cmd.cpp @@ -407,7 +407,7 @@ static enum lttng_error_code list_lttng_ust_global_events(char *channel_name, lttng::urcu::read_lock_guard read_lock; lttng_ht_lookup(ust_global->channels, (void *) channel_name, &iter); - node = lttng_ht_iter_get_node_str(&iter); + node = lttng_ht_iter_get_node(&iter); if (node == nullptr) { ret_code = LTTNG_ERR_UST_CHAN_NOT_FOUND; goto error; diff --git a/src/bin/lttng-sessiond/consumer.cpp b/src/bin/lttng-sessiond/consumer.cpp index 9e7e05363..9629182ba 100644 --- a/src/bin/lttng-sessiond/consumer.cpp +++ b/src/bin/lttng-sessiond/consumer.cpp @@ -406,7 +406,7 @@ struct consumer_socket *consumer_find_socket(int key, const struct consumer_outp } lttng_ht_lookup(consumer->socks, (void *) ((unsigned long) key), &iter); - node = lttng_ht_iter_get_node_ulong(&iter); + node = lttng_ht_iter_get_node(&iter); if (node != nullptr) { socket = lttng::utils::container_of(node, &consumer_socket::node); } diff --git a/src/bin/lttng-sessiond/event-notifier-error-accounting.cpp b/src/bin/lttng-sessiond/event-notifier-error-accounting.cpp index 7fa54bc93..e22598223 100644 --- a/src/bin/lttng-sessiond/event-notifier-error-accounting.cpp +++ b/src/bin/lttng-sessiond/event-notifier-error-accounting.cpp @@ -307,7 +307,7 @@ static enum event_notifier_error_accounting_status get_error_counter_index_for_t lttng::urcu::read_lock_guard read_guard; lttng_ht_lookup(state->indices_ht, &tracer_token, &iter); - node = lttng_ht_iter_get_node_u64(&iter); + node = lttng_ht_iter_get_node(&iter); if (node) { index_entry = lttng::utils::container_of(node, &index_ht_entry::node); *error_counter_index = index_entry->error_counter_index; @@ -333,7 +333,7 @@ static struct ust_error_accounting_entry *ust_error_accounting_entry_find(struct uint64_t key = app->uid; lttng_ht_lookup(uid_ht, &key, &iter); - node = lttng_ht_iter_get_node_u64(&iter); + node = lttng_ht_iter_get_node(&iter); if (node == nullptr) { entry = nullptr; } else { @@ -1302,7 +1302,7 @@ void event_notifier_error_accounting_unregister_event_notifier(const struct lttn } lttng_ht_lookup(state->indices_ht, &tracer_token, &iter); - node = lttng_ht_iter_get_node_u64(&iter); + node = lttng_ht_iter_get_node(&iter); if (node) { int del_ret; struct index_ht_entry *index_entry = diff --git a/src/bin/lttng-sessiond/event.cpp b/src/bin/lttng-sessiond/event.cpp index 462ed2f0d..c0b1aeebe 100644 --- a/src/bin/lttng-sessiond/event.cpp +++ b/src/bin/lttng-sessiond/event.cpp @@ -274,7 +274,7 @@ int event_ust_disable_tracepoint(struct ltt_ust_session *usess, trace_ust_ht_match_event_by_name, event_name, &iter.iter); - node = lttng_ht_iter_get_node_str(&iter); + node = lttng_ht_iter_get_node(&iter); if (node == nullptr) { DBG2("Trace UST event NOT found by name %s", event_name); ret = LTTNG_ERR_UST_EVENT_NOT_FOUND; @@ -304,7 +304,7 @@ int event_ust_disable_tracepoint(struct ltt_ust_session *usess, /* Get next duplicate event by name. */ cds_lfht_next_duplicate( ht->ht, trace_ust_ht_match_event_by_name, event_name, &iter.iter); - node = lttng_ht_iter_get_node_str(&iter); + node = lttng_ht_iter_get_node(&iter); } while (node); ret = LTTNG_OK; @@ -877,7 +877,7 @@ int event_agent_disable(struct ltt_ust_session *usess, struct agent *agt, const lttng::urcu::read_lock_guard read_lock; agent_find_events_by_name(event_name, agt, &iter); - node = lttng_ht_iter_get_node_str(&iter); + node = lttng_ht_iter_get_node(&iter); if (node == nullptr) { DBG2("Event agent NOT found by name %s", event_name); @@ -895,7 +895,7 @@ int event_agent_disable(struct ltt_ust_session *usess, struct agent *agt, const /* Get next duplicate agent event by name. */ agent_event_next_duplicate(event_name, agt, &iter); - node = lttng_ht_iter_get_node_str(&iter); + node = lttng_ht_iter_get_node(&iter); } while (node); end: return ret; diff --git a/src/bin/lttng-sessiond/lttng-syscall.cpp b/src/bin/lttng-sessiond/lttng-syscall.cpp index 821bbaa34..06f4ab1fb 100644 --- a/src/bin/lttng-sessiond/lttng-syscall.cpp +++ b/src/bin/lttng-sessiond/lttng-syscall.cpp @@ -215,7 +215,7 @@ static struct syscall *lookup_syscall(struct lttng_ht *ht, const char *name) LTTNG_ASSERT(name); lttng_ht_lookup(ht, (void *) name, &iter); - node = lttng_ht_iter_get_node_str(&iter); + node = lttng_ht_iter_get_node(&iter); if (node) { ksyscall = lttng::utils::container_of(node, &syscall::node); } diff --git a/src/bin/lttng-sessiond/session.cpp b/src/bin/lttng-sessiond/session.cpp index 97391ad98..cfa8c8b03 100644 --- a/src/bin/lttng-sessiond/session.cpp +++ b/src/bin/lttng-sessiond/session.cpp @@ -115,7 +115,7 @@ struct ltt_session *session_find_by_id(uint64_t id) } lttng_ht_lookup(ltt_sessions_ht_by_id, &id, &iter); - node = lttng_ht_iter_get_node_u64(&iter); + node = lttng_ht_iter_get_node(&iter); if (node == nullptr) { goto end; } @@ -1407,7 +1407,7 @@ bool sample_session_id_by_name(const char *name, uint64_t *id) } lttng_ht_lookup(ltt_sessions_ht_by_name, name, &iter); - node = lttng_ht_iter_get_node_str(&iter); + node = lttng_ht_iter_get_node(&iter); if (node == nullptr) { found = false; goto end; diff --git a/src/bin/lttng-sessiond/snapshot.cpp b/src/bin/lttng-sessiond/snapshot.cpp index 4f72306ac..f9ab929d6 100644 --- a/src/bin/lttng-sessiond/snapshot.cpp +++ b/src/bin/lttng-sessiond/snapshot.cpp @@ -277,7 +277,7 @@ struct snapshot_output *snapshot_find_output_by_id(uint32_t id, struct snapshot ASSERT_RCU_READ_LOCKED(); lttng_ht_lookup(snapshot->output_ht, (void *) ((unsigned long) id), &iter); - node = lttng_ht_iter_get_node_ulong(&iter); + node = lttng_ht_iter_get_node(&iter); if (!node) { DBG3("Snapshot output not found with id %" PRId32, id); goto error; diff --git a/src/bin/lttng-sessiond/trace-ust.cpp b/src/bin/lttng-sessiond/trace-ust.cpp index e4fdef9ad..bffd2900b 100644 --- a/src/bin/lttng-sessiond/trace-ust.cpp +++ b/src/bin/lttng-sessiond/trace-ust.cpp @@ -174,7 +174,7 @@ struct ltt_ust_channel *trace_ust_find_channel_by_name(struct lttng_ht *ht, cons name = DEFAULT_CHANNEL_NAME; lttng_ht_lookup(ht, (void *) name, &iter); - node = lttng_ht_iter_get_node_str(&iter); + node = lttng_ht_iter_get_node(&iter); if (node == nullptr) { goto error; } @@ -218,7 +218,7 @@ struct ltt_ust_event *trace_ust_find_event(struct lttng_ht *ht, trace_ust_ht_match_event, &key, &iter.iter); - node = lttng_ht_iter_get_node_str(&iter); + node = lttng_ht_iter_get_node(&iter); if (node == nullptr) { goto error; } @@ -254,7 +254,7 @@ struct agent *trace_ust_find_agent(struct ltt_ust_session *session, key = domain_type; lttng_ht_lookup(session->agents, &key, &iter); - node = lttng_ht_iter_get_node_u64(&iter); + node = lttng_ht_iter_get_node(&iter); if (!node) { goto end; } @@ -785,7 +785,7 @@ id_tracker_lookup(struct ust_id_tracker *id_tracker, int id, struct lttng_ht_ite struct lttng_ht_node_ulong *node; lttng_ht_lookup(id_tracker->ht, (void *) _id, iter); - node = lttng_ht_iter_get_node_ulong(iter); + node = lttng_ht_iter_get_node(iter); if (node) { return lttng::utils::container_of(node, &ust_id_tracker_node::node); } else { diff --git a/src/bin/lttng-sessiond/ust-app.cpp b/src/bin/lttng-sessiond/ust-app.cpp index 6e7b3f5e1..1e54f3a40 100644 --- a/src/bin/lttng-sessiond/ust-app.cpp +++ b/src/bin/lttng-sessiond/ust-app.cpp @@ -1456,7 +1456,7 @@ struct ust_app *ust_app_find_by_sock(int sock) ASSERT_RCU_READ_LOCKED(); lttng_ht_lookup(ust_app_ht_by_sock, (void *) ((unsigned long) sock), &iter); - node = lttng_ht_iter_get_node_ulong(&iter); + node = lttng_ht_iter_get_node(&iter); if (node == nullptr) { DBG2("UST app find by sock %d not found", sock); goto error; @@ -1480,7 +1480,7 @@ static struct ust_app *find_app_by_notify_sock(int sock) ASSERT_RCU_READ_LOCKED(); lttng_ht_lookup(ust_app_ht_by_notify_sock, (void *) ((unsigned long) sock), &iter); - node = lttng_ht_iter_get_node_ulong(&iter); + node = lttng_ht_iter_get_node(&iter); if (node == nullptr) { DBG2("UST app find by notify sock %d not found", sock); goto error; @@ -1527,7 +1527,7 @@ static struct ust_app_event *find_ust_app_event(struct lttng_ht *ht, ht_match_ust_app_event, &key, &iter.iter); - node = lttng_ht_iter_get_node_str(&iter); + node = lttng_ht_iter_get_node(&iter); if (node == nullptr) { goto end; } @@ -1555,7 +1555,7 @@ static struct ust_app_event_notifier_rule *find_ust_app_event_notifier_rule(stru ASSERT_RCU_READ_LOCKED(); lttng_ht_lookup(ht, &token, &iter); - node = lttng_ht_iter_get_node_u64(&iter); + node = lttng_ht_iter_get_node(&iter); if (node == nullptr) { DBG2("UST app event notifier rule token not found: token = %" PRIu64, token); goto end; @@ -2540,7 +2540,7 @@ static struct ust_app_session *lookup_session_by_app(const struct ltt_ust_sessio struct lttng_ht_node_u64 *node; __lookup_session_by_app(usess, app, &iter); - node = lttng_ht_iter_get_node_u64(&iter); + node = lttng_ht_iter_get_node(&iter); if (node == nullptr) { goto error; } @@ -2885,7 +2885,7 @@ static struct ust_app_ctx *find_ust_app_context(struct lttng_ht *ht, ht_match_ust_app_ctx, uctx, &iter.iter); - node = lttng_ht_iter_get_node_ulong(&iter); + node = lttng_ht_iter_get_node(&iter); if (!node) { goto end; } @@ -3012,7 +3012,7 @@ static int enable_ust_app_channel(struct ust_app_session *ua_sess, ASSERT_RCU_READ_LOCKED(); lttng_ht_lookup(ua_sess->channels, (void *) uchan->name, &iter); - ua_chan_node = lttng_ht_iter_get_node_str(&iter); + ua_chan_node = lttng_ht_iter_get_node(&iter); if (ua_chan_node == nullptr) { DBG2("Unable to find channel %s in ust session id %" PRIu64, uchan->name, @@ -3730,7 +3730,7 @@ static int ust_app_channel_allocate(struct ust_app_session *ua_sess, /* Lookup channel in the ust app session */ lttng_ht_lookup(ua_sess->channels, (void *) uchan->name, &iter); - ua_chan_node = lttng_ht_iter_get_node_str(&iter); + ua_chan_node = lttng_ht_iter_get_node(&iter); if (ua_chan_node != nullptr) { ua_chan = lttng::utils::container_of(ua_chan_node, &ust_app_channel::node); goto end; @@ -3991,7 +3991,7 @@ struct ust_app *ust_app_find_by_pid(pid_t pid) struct lttng_ht_iter iter; lttng_ht_lookup(ust_app_ht, (void *) ((unsigned long) pid), &iter); - node = lttng_ht_iter_get_node_ulong(&iter); + node = lttng_ht_iter_get_node(&iter); if (node == nullptr) { DBG2("UST app no found with pid %d", pid); goto error; @@ -4433,7 +4433,7 @@ void ust_app_unregister_by_socket(int sock_fd) /* Get the node reference for a call_rcu */ lttng_ht_lookup(ust_app_ht_by_sock, (void *) ((unsigned long) sock_fd), &ust_app_sock_iter); - node = lttng_ht_iter_get_node_ulong(&ust_app_sock_iter); + node = lttng_ht_iter_get_node(&ust_app_sock_iter); assert(node); app = caa_container_of(node, struct ust_app, sock_n); @@ -4873,7 +4873,7 @@ int ust_app_disable_channel_glb(struct ltt_ust_session *usess, struct ltt_ust_ch /* Get channel */ lttng_ht_lookup(ua_sess->channels, (void *) uchan->name, &uiter); - ua_chan_node = lttng_ht_iter_get_node_str(&uiter); + ua_chan_node = lttng_ht_iter_get_node(&uiter); /* If the session if found for the app, the channel must be there */ LTTNG_ASSERT(ua_chan_node); @@ -4979,7 +4979,7 @@ int ust_app_disable_event_glb(struct ltt_ust_session *usess, /* Lookup channel in the ust app session */ lttng_ht_lookup(ua_sess->channels, (void *) uchan->name, &uiter); - ua_chan_node = lttng_ht_iter_get_node_str(&uiter); + ua_chan_node = lttng_ht_iter_get_node(&uiter); if (ua_chan_node == nullptr) { DBG2("Channel %s not found in session id %" PRIu64 " for app pid %d." @@ -5142,7 +5142,7 @@ int ust_app_enable_event_glb(struct ltt_ust_session *usess, /* Lookup channel in the ust app session */ lttng_ht_lookup(ua_sess->channels, (void *) uchan->name, &uiter); - ua_chan_node = lttng_ht_iter_get_node_str(&uiter); + ua_chan_node = lttng_ht_iter_get_node(&uiter); /* * It is possible that the channel cannot be found is * the channel/event creation occurs concurrently with @@ -5232,7 +5232,7 @@ int ust_app_create_event_glb(struct ltt_ust_session *usess, /* Lookup channel in the ust app session */ lttng_ht_lookup(ua_sess->channels, (void *) uchan->name, &uiter); - ua_chan_node = lttng_ht_iter_get_node_str(&uiter); + ua_chan_node = lttng_ht_iter_get_node(&uiter); /* If the channel is not found, there is a code flow error */ LTTNG_ASSERT(ua_chan_node); @@ -5777,7 +5777,7 @@ static int destroy_trace(struct ltt_ust_session *usess, struct ust_app *app) } __lookup_session_by_app(usess, app, &iter); - node = lttng_ht_iter_get_node_u64(&iter); + node = lttng_ht_iter_get_node(&iter); if (node == nullptr) { /* Session is being or is deleted. */ goto end; @@ -5922,7 +5922,7 @@ static int find_or_create_ust_app_channel(struct ltt_ust_session *usess, struct lttng_ht_node_str *ua_chan_node; lttng_ht_lookup(ua_sess->channels, (void *) uchan->name, &iter); - ua_chan_node = lttng_ht_iter_get_node_str(&iter); + ua_chan_node = lttng_ht_iter_get_node(&iter); if (ua_chan_node) { *ua_chan = caa_container_of(ua_chan_node, struct ust_app_channel, node); goto end; @@ -6363,7 +6363,7 @@ int ust_app_add_ctx_channel_glb(struct ltt_ust_session *usess, /* Lookup channel in the ust app session */ lttng_ht_lookup(ua_sess->channels, (void *) uchan->name, &uiter); - ua_chan_node = lttng_ht_iter_get_node_str(&uiter); + ua_chan_node = lttng_ht_iter_get_node(&uiter); if (ua_chan_node == nullptr) { goto next_app; } @@ -6452,7 +6452,7 @@ static struct ust_app_session *find_session_by_objd(struct ust_app *app, int obj ASSERT_RCU_READ_LOCKED(); lttng_ht_lookup(app->ust_sessions_objd, (void *) ((unsigned long) objd), &iter); - node = lttng_ht_iter_get_node_ulong(&iter); + node = lttng_ht_iter_get_node(&iter); if (node == nullptr) { DBG2("UST app session find by objd %d not found", objd); goto error; @@ -6479,7 +6479,7 @@ static struct ust_app_channel *find_channel_by_objd(struct ust_app *app, int obj ASSERT_RCU_READ_LOCKED(); lttng_ht_lookup(app->ust_objd, (void *) ((unsigned long) objd), &iter); - node = lttng_ht_iter_get_node_ulong(&iter); + node = lttng_ht_iter_get_node(&iter); if (node == nullptr) { DBG2("UST app channel find by objd %d not found", objd); goto error; @@ -7461,7 +7461,7 @@ int ust_app_pid_get_channel_runtime_stats(struct ltt_ust_session *usess, /* Get channel */ lttng_ht_lookup(ua_sess->channels, (void *) uchan->name, &uiter); - ua_chan_node = lttng_ht_iter_get_node_str(&uiter); + ua_chan_node = lttng_ht_iter_get_node(&uiter); /* If the session is found for the app, the channel must be there */ LTTNG_ASSERT(ua_chan_node); diff --git a/src/bin/lttng-sessiond/ust-registry-session.cpp b/src/bin/lttng-sessiond/ust-registry-session.cpp index 7c091f7e6..8441b4e2c 100644 --- a/src/bin/lttng-sessiond/ust-registry-session.cpp +++ b/src/bin/lttng-sessiond/ust-registry-session.cpp @@ -494,7 +494,7 @@ lttng::sessiond::ust::registry_channel& lsu::registry_session::channel(uint64_t ASSERT_LOCKED(_lock); lttng_ht_lookup(_channels.get(), &channel_key, &iter); - node = lttng_ht_iter_get_node_u64(&iter); + node = lttng_ht_iter_get_node(&iter); if (!node) { LTTNG_THROW_INVALID_ARGUMENT_ERROR(lttng::format( "Invalid channel key provided: channel key = {}", channel_key)); @@ -718,7 +718,7 @@ lsu::registry_session::enumeration(const char *enum_name, uint64_t enum_id) cons ht_match_enum_id, ®_enum_lookup, &iter.iter); - node = lttng_ht_iter_get_node_str(&iter); + node = lttng_ht_iter_get_node(&iter); if (!node) { LTTNG_THROW_PROTOCOL_ERROR(lttng::format( "Unknown enumeration referenced by application event field: enum name = `{}`, enum id = {}", @@ -752,7 +752,7 @@ lsu::registry_session::_lookup_enum(const lsu::registry_enum *reg_enum_lookup) c ht_match_enum, reg_enum_lookup, &iter.iter); - node = lttng_ht_iter_get_node_str(&iter); + node = lttng_ht_iter_get_node(&iter); if (!node) { goto end; } diff --git a/src/common/consumer/consumer.cpp b/src/common/consumer/consumer.cpp index 1da243601..ed25a42ea 100644 --- a/src/common/consumer/consumer.cpp +++ b/src/common/consumer/consumer.cpp @@ -202,7 +202,7 @@ static struct lttng_consumer_stream *find_stream(uint64_t key, struct lttng_ht * lttng::urcu::read_lock_guard read_lock; lttng_ht_lookup(ht, &key, &iter); - node = lttng_ht_iter_get_node_u64(&iter); + node = lttng_ht_iter_get_node(&iter); if (node != nullptr) { stream = lttng::utils::container_of(node, <tng_consumer_stream::node); } @@ -247,7 +247,7 @@ struct lttng_consumer_channel *consumer_find_channel(uint64_t key) } lttng_ht_lookup(the_consumer_data.channel_ht, &key, &iter); - node = lttng_ht_iter_get_node_u64(&iter); + node = lttng_ht_iter_get_node(&iter); if (node != nullptr) { channel = lttng::utils::container_of(node, <tng_consumer_channel::node); } @@ -629,7 +629,7 @@ static int add_relayd(struct consumer_relayd_sock_pair *relayd) ASSERT_RCU_READ_LOCKED(); lttng_ht_lookup(the_consumer_data.relayd_ht, &relayd->net_seq_idx, &iter); - node = lttng_ht_iter_get_node_u64(&iter); + node = lttng_ht_iter_get_node(&iter); if (node != nullptr) { goto end; } @@ -690,7 +690,7 @@ struct consumer_relayd_sock_pair *consumer_find_relayd(uint64_t key) } lttng_ht_lookup(the_consumer_data.relayd_ht, &key, &iter); - node = lttng_ht_iter_get_node_u64(&iter); + node = lttng_ht_iter_get_node(&iter); if (node != nullptr) { relayd = lttng::utils::container_of(node, &consumer_relayd_sock_pair::node); } @@ -2185,7 +2185,7 @@ void consumer_add_metadata_stream(struct lttng_consumer_stream *stream) * state. This should NEVER happen. */ lttng_ht_lookup(ht, &stream->key, &iter); - node = lttng_ht_iter_get_node_u64(&iter); + node = lttng_ht_iter_get_node(&iter); LTTNG_ASSERT(!node); /* @@ -2411,7 +2411,7 @@ void *consumer_thread_metadata_poll(void *data) lttng_ht_lookup(metadata_ht, &tmp_id, &iter); } - node = lttng_ht_iter_get_node_u64(&iter); + node = lttng_ht_iter_get_node(&iter); LTTNG_ASSERT(node); stream = caa_container_of(node, struct lttng_consumer_stream, node); @@ -3067,7 +3067,7 @@ void *consumer_thread_channel_poll(void *data) lttng_ht_lookup(channel_ht, &tmp_id, &iter); } - node = lttng_ht_iter_get_node_u64(&iter); + node = lttng_ht_iter_get_node(&iter); LTTNG_ASSERT(node); chan = caa_container_of(node, struct lttng_consumer_channel, wait_fd_node); diff --git a/src/common/hashtable/hashtable.cpp b/src/common/hashtable/hashtable.cpp index 29d3ac499..be7e77342 100644 --- a/src/common/hashtable/hashtable.cpp +++ b/src/common/hashtable/hashtable.cpp @@ -492,64 +492,4 @@ unsigned long lttng_ht_get_count(struct lttng_ht *ht) cds_lfht_count_nodes(ht->ht, &scb, &count, &sca); return count; -} - -/* - * Return lttng ht string node from iterator. - */ -struct lttng_ht_node_str *lttng_ht_iter_get_node_str(struct lttng_ht_iter *iter) -{ - struct cds_lfht_node *node; - - LTTNG_ASSERT(iter); - node = cds_lfht_iter_get_node(&iter->iter); - if (!node) { - return nullptr; - } - return lttng::utils::container_of(node, <tng_ht_node_str::node); -} - -/* - * Return lttng ht unsigned long node from iterator. - */ -struct lttng_ht_node_ulong *lttng_ht_iter_get_node_ulong(struct lttng_ht_iter *iter) -{ - struct cds_lfht_node *node; - - LTTNG_ASSERT(iter); - node = cds_lfht_iter_get_node(&iter->iter); - if (!node) { - return nullptr; - } - return lttng::utils::container_of(node, <tng_ht_node_ulong::node); -} - -/* - * Return lttng ht unsigned long node from iterator. - */ -struct lttng_ht_node_u64 *lttng_ht_iter_get_node_u64(struct lttng_ht_iter *iter) -{ - struct cds_lfht_node *node; - - LTTNG_ASSERT(iter); - node = cds_lfht_iter_get_node(&iter->iter); - if (!node) { - return nullptr; - } - return lttng::utils::container_of(node, <tng_ht_node_u64::node); -} - -/* - * Return lttng ht stream and index id node from iterator. - */ -struct lttng_ht_node_two_u64 *lttng_ht_iter_get_node_two_u64(struct lttng_ht_iter *iter) -{ - struct cds_lfht_node *node; - - LTTNG_ASSERT(iter); - node = cds_lfht_iter_get_node(&iter->iter); - if (!node) { - return nullptr; - } - return lttng::utils::container_of(node, <tng_ht_node_two_u64::node); -} +} \ No newline at end of file diff --git a/src/common/hashtable/hashtable.hpp b/src/common/hashtable/hashtable.hpp index ac1af7eed..db258e4d9 100644 --- a/src/common/hashtable/hashtable.hpp +++ b/src/common/hashtable/hashtable.hpp @@ -113,9 +113,17 @@ void lttng_ht_get_next(struct lttng_ht *ht, struct lttng_ht_iter *iter); unsigned long lttng_ht_get_count(struct lttng_ht *ht); -struct lttng_ht_node_str *lttng_ht_iter_get_node_str(struct lttng_ht_iter *iter); -struct lttng_ht_node_ulong *lttng_ht_iter_get_node_ulong(struct lttng_ht_iter *iter); -struct lttng_ht_node_u64 *lttng_ht_iter_get_node_u64(struct lttng_ht_iter *iter); -struct lttng_ht_node_two_u64 *lttng_ht_iter_get_node_two_u64(struct lttng_ht_iter *iter); +template +NodeType *lttng_ht_iter_get_node(const lttng_ht_iter *iter) +{ + LTTNG_ASSERT(iter); + + auto node = iter->iter.node; + if (!node) { + return nullptr; + } + + return lttng::utils::container_of(node, &NodeType::node); +} #endif /* _LTT_HT_H */