Fix: protect close_write_flag with the rotation lock
authorDavid Goulet <dgoulet@efficios.com>
Tue, 11 Feb 2014 21:27:57 +0000 (16:27 -0500)
committerDavid Goulet <dgoulet@efficios.com>
Wed, 12 Feb 2014 19:54:19 +0000 (14:54 -0500)
Acked-by: Julien Desfossez <julien.desfossez@efficios.com>
Signed-off-by: David Goulet <dgoulet@efficios.com>
src/bin/lttng-relayd/live.c

index 292f0601e958e97eee1b3d021bb96570a712c2e0..06c1c15134cf63af055729b6b28f75d0489962ce 100644 (file)
@@ -1189,23 +1189,25 @@ int viewer_get_next_index(struct relay_connection *conn)
        rstream = stream_find_by_id(relay_streams_ht, vstream->stream_handle);
        assert(rstream);
 
+       pthread_mutex_lock(&rstream->viewer_stream_rotation_lock);
        if (!rstream->close_flag) {
                if (vstream->abort_flag) {
                        /* Rotate on abort (overwrite). */
                        DBG("Viewer rotate because of overwrite");
                        ret = viewer_stream_rotate(vstream, rstream);
                        if (ret < 0) {
+                               pthread_mutex_unlock(&rstream->viewer_stream_rotation_lock);
                                goto end_unlock;
                        } else if (ret == 1) {
                                viewer_index.status = htobe32(LTTNG_VIEWER_INDEX_HUP);
                                viewer_stream_delete(vstream);
                                viewer_stream_destroy(ctf_trace, vstream);
+                               pthread_mutex_unlock(&rstream->viewer_stream_rotation_lock);
                                goto send_reply;
                        }
                        /* ret == 0 means successful so we continue. */
                }
 
-               pthread_mutex_lock(&rstream->viewer_stream_rotation_lock);
                if (rstream->tracefile_count_current == vstream->tracefile_count_current) {
                        if (rstream->beacon_ts_end != -1ULL &&
                                vstream->last_sent_index == rstream->total_index_received) {
@@ -1226,17 +1228,18 @@ int viewer_get_next_index(struct relay_connection *conn)
                                goto send_reply;
                        }
                }
-               pthread_mutex_unlock(&rstream->viewer_stream_rotation_lock);
        } else if (rstream->close_flag && vstream->close_write_flag &&
                        vstream->total_index_received == vstream->last_sent_index) {
                /* Last index sent and current tracefile closed in write */
                viewer_index.status = htobe32(LTTNG_VIEWER_INDEX_HUP);
                viewer_stream_delete(vstream);
                viewer_stream_destroy(ctf_trace, vstream);
+               pthread_mutex_unlock(&rstream->viewer_stream_rotation_lock);
                goto send_reply;
        } else {
                vstream->close_write_flag = 1;
        }
+       pthread_mutex_unlock(&rstream->viewer_stream_rotation_lock);
 
        if (!ctf_trace->metadata_received ||
                        ctf_trace->metadata_received > ctf_trace->metadata_sent) {
@@ -1273,10 +1276,15 @@ int viewer_get_next_index(struct relay_connection *conn)
                        sizeof(packet_index));
        pthread_mutex_unlock(&vstream->overwrite_lock);
        if (ret < sizeof(packet_index)) {
+               unsigned int close_write_flag;
+
+               pthread_mutex_lock(&rstream->viewer_stream_rotation_lock);
+               close_write_flag = vstream->close_write_flag;
+               pthread_mutex_unlock(&rstream->viewer_stream_rotation_lock);
                /*
                 * The tracefile is closed in write, so we read up to EOF.
                 */
-               if (vstream->close_write_flag == 1) {
+               if (close_write_flag == 1) {
                        viewer_index.status = htobe32(LTTNG_VIEWER_INDEX_RETRY);
                        /* Rotate on normal EOF */
                        ret = viewer_stream_rotate(vstream, rstream);
This page took 0.027075 seconds and 4 git commands to generate.