Fix: deadlock during rotation
authorJulien Desfossez <jdesfossez@efficios.com>
Fri, 14 Feb 2014 20:51:34 +0000 (15:51 -0500)
committerDavid Goulet <dgoulet@efficios.com>
Fri, 14 Feb 2014 21:32:56 +0000 (16:32 -0500)
The overwrite_lock is nested inside the viewer_stream_rotation_lock.
And the viewer_stream_rotate function is always called with the
viewer_stream_rotation_lock held.

Signed-off-by: Julien Desfossez <jdesfossez@efficios.com>
Signed-off-by: David Goulet <dgoulet@efficios.com>
src/bin/lttng-relayd/live.c
src/bin/lttng-relayd/viewer-stream.c

index d29804cd624f03795e78b706e11af58f7b3b8ebc..a720ed732f0f6746fc399c9ad203635086acfd0a 100644 (file)
@@ -1337,11 +1337,13 @@ int viewer_get_next_index(struct relay_connection *conn)
                viewer_index.flags |= LTTNG_VIEWER_FLAG_NEW_STREAM;
        }
 
+       pthread_mutex_lock(&rstream->viewer_stream_rotation_lock);
        pthread_mutex_lock(&vstream->overwrite_lock);
        if (vstream->abort_flag) {
                /* The file is being overwritten by the writer, we cannot use it. */
                pthread_mutex_unlock(&vstream->overwrite_lock);
                ret = viewer_stream_rotate(vstream, rstream);
+               pthread_mutex_unlock(&rstream->viewer_stream_rotation_lock);
                if (ret < 0) {
                        goto end_unlock;
                } else if (ret == 1) {
@@ -1357,6 +1359,7 @@ int viewer_get_next_index(struct relay_connection *conn)
        read_ret = lttng_read(vstream->index_read_fd, &packet_index,
                        sizeof(packet_index));
        pthread_mutex_unlock(&vstream->overwrite_lock);
+       pthread_mutex_unlock(&rstream->viewer_stream_rotation_lock);
        if (read_ret < 0) {
                viewer_index.status = htobe32(LTTNG_VIEWER_INDEX_HUP);
                viewer_stream_delete(vstream);
index 8ed84a1d118163d7a74c5f2e47b7c9a5a29b0ded..5ab7be790de867f42676f8c6c84bd2e86bfb7083 100644 (file)
@@ -196,6 +196,7 @@ end:
 /*
  * Rotate a stream to the next tracefile.
  *
+ * Must be called with viewer_stream_rotation_lock held.
  * Returns 0 on success, 1 on EOF, a negative value on error.
  */
 int viewer_stream_rotate(struct relay_viewer_stream *vstream,
@@ -224,12 +225,6 @@ int viewer_stream_rotate(struct relay_viewer_stream *vstream,
                goto end;
        }
 
-       /*
-        * Lock to execute rotation in order to avoid races between a modification
-        * on the index values.
-        */
-       pthread_mutex_lock(&stream->viewer_stream_rotation_lock);
-
        /*
         * The writer and the reader are not working in the same tracefile, we can
         * read up to EOF, we don't care about the total_index_received.
@@ -264,8 +259,6 @@ int viewer_stream_rotate(struct relay_viewer_stream *vstream,
        vstream->abort_flag = 0;
        pthread_mutex_unlock(&vstream->overwrite_lock);
 
-       pthread_mutex_unlock(&stream->viewer_stream_rotation_lock);
-
        ret = index_open(vstream->path_name, vstream->channel_name,
                        vstream->tracefile_count, vstream->tracefile_count_current);
        if (ret < 0) {
This page took 0.027495 seconds and 4 git commands to generate.