X-Git-Url: https://git.lttng.org/?p=lttng-tools.git;a=blobdiff_plain;f=src%2Fcommon%2Fconsumer-stream.c;h=920948760264405f16941f0069617513e9d27d6f;hp=2bb5ce7e8adee8a235d9b5b6783b66fe5ecef7fd;hb=1c20f0e29cbf8627bfb1ff444572d52d6655c4e2;hpb=3c4599b9a5c12ceff19368c6cd51e01d81824726 diff --git a/src/common/consumer-stream.c b/src/common/consumer-stream.c index 2bb5ce7e8..920948760 100644 --- a/src/common/consumer-stream.c +++ b/src/common/consumer-stream.c @@ -24,6 +24,7 @@ #include #include +#include #include #include @@ -322,3 +323,35 @@ void consumer_stream_destroy(struct lttng_consumer_stream *stream, /* Free stream within a RCU call. */ consumer_stream_free(stream); } + +/* + * Write index of a specific stream either on the relayd or local disk. + * + * Return 0 on success or else a negative value. + */ +int consumer_stream_write_index(struct lttng_consumer_stream *stream, + struct lttng_packet_index *index) +{ + int ret; + struct consumer_relayd_sock_pair *relayd; + + assert(stream); + assert(index); + + rcu_read_lock(); + relayd = consumer_find_relayd(stream->net_seq_idx); + if (relayd) { + ret = relayd_send_index(&relayd->control_sock, index, + stream->relayd_stream_id, stream->next_net_seq_num - 1); + } else { + ret = index_write(stream->index_fd, index, + sizeof(struct lttng_packet_index)); + } + if (ret < 0) { + goto error; + } + +error: + rcu_read_unlock(); + return ret; +}