Clean-up: consumerd: reduce duplication of stream output close code
[lttng-tools.git] / src / common / kernel-consumer / kernel-consumer.cpp
index d22aea1831978225da90eaf5b5d9507bd248ca4a..ce1d3d8293463898d09b1d9f12eeab018dbbbf9e 100644 (file)
@@ -135,30 +135,6 @@ error:
        return ret;
 }
 
-static void finalize_snapshot_stream(
-               struct lttng_consumer_stream *stream, uint64_t relayd_id)
-{
-       ASSERT_LOCKED(stream->lock);
-
-       if (relayd_id == (uint64_t) -1ULL) {
-               if (stream->out_fd >= 0) {
-                       const int ret = close(stream->out_fd);
-
-                       if (ret < 0) {
-                               PERROR("Failed to close stream snapshot output file descriptor");
-                       }
-
-                       stream->out_fd = -1;
-               }
-       } else {
-               close_relayd_stream(stream);
-               stream->net_seq_idx = (uint64_t) -1ULL;
-       }
-
-       lttng_trace_chunk_put(stream->trace_chunk);
-       stream->trace_chunk = NULL;
-}
-
 /*
  * Take a snapshot of all the stream of a channel
  * RCU read-side lock must be held across this function to ensure existence of
@@ -222,13 +198,13 @@ static int lttng_kconsumer_snapshot_channel(
                        ret = consumer_send_relayd_stream(stream, path);
                        if (ret < 0) {
                                ERR("sending stream to relayd");
-                               goto error_finalize_stream;
+                               goto error_close_stream_output;
                        }
                } else {
                        ret = consumer_stream_create_output_files(stream,
                                        false);
                        if (ret < 0) {
-                               goto error_finalize_stream;
+                               goto error_close_stream_output;
                        }
                        DBG("Kernel consumer snapshot stream (%" PRIu64 ")",
                                        stream->key);
@@ -246,7 +222,7 @@ static int lttng_kconsumer_snapshot_channel(
                        ret = kernctl_buffer_flush(stream->wait_fd);
                        if (ret < 0) {
                                ERR("Failed to flush kernel stream");
-                               goto error_finalize_stream;
+                               goto error_close_stream_output;
                        }
                        goto end_unlock;
                }
@@ -254,19 +230,19 @@ static int lttng_kconsumer_snapshot_channel(
                ret = lttng_kconsumer_take_snapshot(stream);
                if (ret < 0) {
                        ERR("Taking kernel snapshot");
-                       goto error_finalize_stream;
+                       goto error_close_stream_output;
                }
 
                ret = lttng_kconsumer_get_produced_snapshot(stream, &produced_pos);
                if (ret < 0) {
                        ERR("Produced kernel snapshot position");
-                       goto error_finalize_stream;
+                       goto error_close_stream_output;
                }
 
                ret = lttng_kconsumer_get_consumed_snapshot(stream, &consumed_pos);
                if (ret < 0) {
                        ERR("Consumerd kernel snapshot position");
-                       goto error_finalize_stream;
+                       goto error_close_stream_output;
                }
 
                consumed_pos = consumer_get_consume_start_pos(consumed_pos,
@@ -286,7 +262,7 @@ static int lttng_kconsumer_snapshot_channel(
                        if (ret < 0) {
                                if (ret != -EAGAIN) {
                                        PERROR("kernctl_get_subbuf snapshot");
-                                       goto error_finalize_stream;
+                                       goto error_close_stream_output;
                                }
                                DBG("Kernel consumer get subbuf failed. Skipping it.");
                                consumed_pos += stream->max_sb_size;
@@ -336,12 +312,12 @@ static int lttng_kconsumer_snapshot_channel(
                        ret = kernctl_put_subbuf(stream->wait_fd);
                        if (ret < 0) {
                                ERR("Snapshot kernctl_put_subbuf");
-                               goto error_finalize_stream;
+                               goto error_close_stream_output;
                        }
                        consumed_pos += stream->max_sb_size;
                }
 
-               finalize_snapshot_stream(stream, relayd_id);
+               consumer_stream_close_output(stream);
                pthread_mutex_unlock(&stream->lock);
        }
 
@@ -354,8 +330,8 @@ error_put_subbuf:
        if (ret < 0) {
                ERR("Snapshot kernctl_put_subbuf error path");
        }
-error_finalize_stream:
-       finalize_snapshot_stream(stream, relayd_id);
+error_close_stream_output:
+       consumer_stream_close_output(stream);
 end_unlock:
        pthread_mutex_unlock(&stream->lock);
 end:
This page took 0.025473 seconds and 4 git commands to generate.