From: Julien Desfossez Date: Wed, 15 Jan 2014 16:54:38 +0000 (-0500) Subject: Fix: notify the viewer if new streams got added X-Git-Tag: v2.5.0-rc1~218 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=4a9daf1745ccbd2aab029206a664f39fcbd640ce;p=lttng-tools.git Fix: notify the viewer if new streams got added As soon as new streams are available, the viewer must start reading them, otherwise we risk to ignore complete streams. Signed-off-by: Julien Desfossez Signed-off-by: David Goulet --- diff --git a/src/bin/lttng-relayd/live.c b/src/bin/lttng-relayd/live.c index 80c3da57a..1a691a849 100644 --- a/src/bin/lttng-relayd/live.c +++ b/src/bin/lttng-relayd/live.c @@ -1142,6 +1142,40 @@ void destroy_viewer_stream(struct relay_viewer_stream *vstream) call_rcu(&vstream->rcu_node, deferred_free_viewer_stream); } +/* + * Atomically check if new streams got added in the session since the last + * check and reset the flag to 0. + * + * Returns 1 if new streams got added, 0 if nothing changed, a negative value + * on error. + */ +static +int check_new_streams(uint64_t session_id, struct lttng_ht *sessions_ht) +{ + struct lttng_ht_node_ulong *node; + struct lttng_ht_iter iter; + struct relay_session *session; + unsigned long current_val; + int ret; + + lttng_ht_lookup(sessions_ht, + (void *)((unsigned long) session_id), &iter); + node = lttng_ht_iter_get_node_ulong(&iter); + if (node == NULL) { + DBG("Relay session %" PRIu64 " not found", session_id); + ret = -1; + goto error; + } + + session = caa_container_of(node, struct relay_session, session_n); + + current_val = uatomic_cmpxchg(&session->new_streams, 1, 0); + ret = current_val; + +error: + return ret; +} + /* * Send the next index for a stream. * @@ -1266,6 +1300,13 @@ int viewer_get_next_index(struct relay_command *cmd, viewer_index.flags |= LTTNG_VIEWER_FLAG_NEW_METADATA; } + ret = check_new_streams(vstream->session_id, sessions_ht); + if (ret < 0) { + goto end_unlock; + } else if (ret == 1) { + viewer_index.flags |= LTTNG_VIEWER_FLAG_NEW_STREAM; + } + pthread_mutex_lock(&vstream->overwrite_lock); if (vstream->abort_flag) { /* @@ -1354,7 +1395,8 @@ end: * Return 0 on success or else a negative value. */ static -int viewer_get_packet(struct relay_command *cmd) +int viewer_get_packet(struct relay_command *cmd, + struct lttng_ht *sessions_ht) { int ret, send_data = 0; char *data = NULL; @@ -1429,6 +1471,15 @@ int viewer_get_packet(struct relay_command *cmd) goto send_reply; } + ret = check_new_streams(stream->session_id, sessions_ht); + if (ret < 0) { + goto end_unlock; + } else if (ret == 1) { + reply.status = htobe32(VIEWER_GET_PACKET_ERR); + reply.flags |= LTTNG_VIEWER_FLAG_NEW_STREAM; + goto send_reply; + } + len = be32toh(get_packet_info.len); data = zmalloc(len); if (!data) { @@ -1663,7 +1714,7 @@ int process_control(struct lttng_viewer_cmd *recv_hdr, ret = viewer_get_next_index(cmd, sessions_ht); break; case VIEWER_GET_PACKET: - ret = viewer_get_packet(cmd); + ret = viewer_get_packet(cmd, sessions_ht); break; case VIEWER_GET_METADATA: ret = viewer_get_metadata(cmd); diff --git a/src/bin/lttng-relayd/lttng-relayd.h b/src/bin/lttng-relayd/lttng-relayd.h index c08c17a4f..ab1ccd410 100644 --- a/src/bin/lttng-relayd/lttng-relayd.h +++ b/src/bin/lttng-relayd/lttng-relayd.h @@ -83,6 +83,11 @@ struct relay_session { */ uint64_t minor; uint64_t major; + /* + * Flag checked and exchanged with uatomic_cmpxchg to tell the + * viewer-side if new streams got added since the last check. + */ + unsigned long new_streams; }; /* diff --git a/src/bin/lttng-relayd/main.c b/src/bin/lttng-relayd/main.c index d8105e405..380b4f833 100644 --- a/src/bin/lttng-relayd/main.c +++ b/src/bin/lttng-relayd/main.c @@ -2128,6 +2128,11 @@ int relay_streams_sent(struct lttcomm_relayd_hdr *recv_hdr, */ set_viewer_ready_flag(cmd); + /* + * Inform the viewer that there are new streams in the session. + */ + uatomic_set(&cmd->session->new_streams, 1); + reply.ret_code = htobe32(LTTNG_OK); send_ret = cmd->sock->ops->sendmsg(cmd->sock, &reply, sizeof(reply), 0); if (send_ret < 0) {