X-Git-Url: https://git.liburcu.org/?a=blobdiff_plain;f=src%2Fcommon%2Fust-consumer%2Fust-consumer.c;h=a951788bd9025ee0c95a6db925f5313758696f2c;hb=9dfbcccfb87c30a74c6059b24bfc053bdcddee54;hp=baa81d450aae793b084d2450450d0f793b7b9d20;hpb=cc84d37b5c13ad6a373137efc5d408ff099dceb4;p=lttng-tools.git diff --git a/src/common/ust-consumer/ust-consumer.c b/src/common/ust-consumer/ust-consumer.c index baa81d450..a951788bd 100644 --- a/src/common/ust-consumer/ust-consumer.c +++ b/src/common/ust-consumer/ust-consumer.c @@ -768,10 +768,19 @@ static int flush_channel(uint64_t chan_key) health_code_update(); pthread_mutex_lock(&stream->lock); + + /* + * Protect against concurrent teardown of a stream. + */ + if (cds_lfht_is_node_deleted(&stream->node.node)) { + goto next; + } + if (!stream->quiescent) { ustctl_flush_buffer(stream->ustream, 0); stream->quiescent = true; } +next: pthread_mutex_unlock(&stream->lock); } error: @@ -1180,7 +1189,7 @@ static int snapshot_channel(uint64_t key, char *path, uint64_t relayd_id, produced_pos, nb_packets_per_stream, stream->max_sb_size); - while (consumed_pos < produced_pos) { + while ((long) (consumed_pos - produced_pos) < 0) { ssize_t read_len; unsigned long len, padded_len; @@ -2255,6 +2264,13 @@ int commit_one_metadata_packet(struct lttng_consumer_stream *stream) stream->ust_metadata_pushed); ret = write_len; + /* + * Switch packet (but don't open the next one) on every commit of + * a metadata packet. Since the subbuffer is fully filled (with padding, + * if needed), the stream is "quiescent" after this commit. + */ + ustctl_flush_buffer(stream->ustream, 1); + stream->quiescent = true; end: pthread_mutex_unlock(&stream->chan->metadata_cache->lock); return ret; @@ -2299,7 +2315,6 @@ int lttng_ustconsumer_sync_metadata(struct lttng_consumer_local_data *ctx, retry = 1; } - ustctl_flush_buffer(metadata->ustream, 1); ret = ustctl_snapshot(metadata->ustream); if (ret < 0) { if (errno != EAGAIN) { @@ -2489,7 +2504,6 @@ retry: if (ret <= 0) { goto end; } - ustctl_flush_buffer(stream->ustream, 1); goto retry; }