From: Julien Desfossez Date: Fri, 15 Nov 2013 02:30:26 +0000 (-0500) Subject: Fix end condition on rotate with live reading X-Git-Tag: v2.4.0-rc1~7 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=a020f610bb3e9a263d8c6509a634b90fe3321fee;p=lttng-tools.git Fix end condition on rotate with live reading We need to know what is the last tracefile to read on live with tracefile_count. 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 a2fd09e32..851be9f8e 100644 --- a/src/bin/lttng-relayd/live.c +++ b/src/bin/lttng-relayd/live.c @@ -698,6 +698,7 @@ int init_viewer_stream(struct relay_stream *stream, int seek_last) LTTNG_VIEWER_NAME_MAX); viewer_stream->tracefile_count = stream->tracefile_count; viewer_stream->metadata_flag = stream->metadata_flag; + viewer_stream->tracefile_count_last = -1ULL; if (seek_last) { viewer_stream->tracefile_count_current = stream->tracefile_count_current; @@ -764,7 +765,7 @@ error: /* * Rotate a stream to the next tracefile. * - * Returns 0 on success, a negative value on error. + * Returns 0 on success, 1 on EOF, a negative value on error. */ static int rotate_viewer_stream(struct relay_viewer_stream *viewer_stream, @@ -777,6 +778,15 @@ int rotate_viewer_stream(struct relay_viewer_stream *viewer_stream, tracefile_id = (viewer_stream->tracefile_count_current + 1) % viewer_stream->tracefile_count; + /* + * Detect the last tracefile to open. + */ + if (viewer_stream->tracefile_count_last != -1ULL && + viewer_stream->tracefile_count_last == + viewer_stream->tracefile_count_current) { + ret = 1; + goto end; + } if (stream) { pthread_mutex_lock(&stream->viewer_stream_rotation_lock); @@ -832,6 +842,7 @@ int rotate_viewer_stream(struct relay_viewer_stream *viewer_stream, ret = 0; +end: error: return ret; } @@ -1130,6 +1141,9 @@ int viewer_get_next_index(struct relay_command *cmd, ret = rotate_viewer_stream(vstream, rstream); if (ret < 0) { goto end_unlock; + } else if (ret == 1) { + viewer_index.status = htobe32(VIEWER_INDEX_HUP); + goto send_reply; } } pthread_mutex_lock(&rstream->viewer_stream_rotation_lock); @@ -1180,6 +1194,9 @@ int viewer_get_next_index(struct relay_command *cmd, ret = rotate_viewer_stream(vstream, rstream); if (ret < 0) { goto end_unlock; + } else if (ret == 1) { + viewer_index.status = htobe32(VIEWER_INDEX_HUP); + goto send_reply; } goto send_reply; } @@ -1196,6 +1213,9 @@ int viewer_get_next_index(struct relay_command *cmd, ret = rotate_viewer_stream(vstream, rstream); if (ret < 0) { goto end_unlock; + } else if (ret == 1) { + viewer_index.status = htobe32(VIEWER_INDEX_HUP); + goto send_reply; } } else { PERROR("Relay reading index file %d", diff --git a/src/bin/lttng-relayd/lttng-relayd.h b/src/bin/lttng-relayd/lttng-relayd.h index c17a67ea8..f22b115c9 100644 --- a/src/bin/lttng-relayd/lttng-relayd.h +++ b/src/bin/lttng-relayd/lttng-relayd.h @@ -163,6 +163,8 @@ struct relay_viewer_stream { uint64_t total_index_received; uint64_t tracefile_count; uint64_t tracefile_count_current; + /* Stop after reading this tracefile. */ + uint64_t tracefile_count_last; struct lttng_ht_node_u64 stream_n; struct rcu_head rcu_node; struct ctf_trace *ctf_trace; diff --git a/src/bin/lttng-relayd/main.c b/src/bin/lttng-relayd/main.c index 70a1948c3..b8e2f72e6 100644 --- a/src/bin/lttng-relayd/main.c +++ b/src/bin/lttng-relayd/main.c @@ -851,6 +851,7 @@ static void destroy_stream(struct relay_stream *stream) */ pthread_mutex_lock(&stream->viewer_stream_rotation_lock); vstream->total_index_received = stream->total_index_received; + vstream->tracefile_count_last = stream->tracefile_count_current; vstream->close_write_flag = 1; pthread_mutex_unlock(&stream->viewer_stream_rotation_lock); }