X-Git-Url: https://git.lttng.org/?a=blobdiff_plain;f=src%2Fcommon%2Fkernel-consumer%2Fkernel-consumer.c;h=236c2c98f9d80f98b2e43b7c74ba9175893a64e3;hb=a0377dfefe40662ba7d68617bce6ff467114136c;hp=5464822aaa58678377869a30d7c8bd9dbae1c6ba;hpb=6e5e3c512dd7c4ead8ce89bff2de1a56a6d5e360;p=lttng-tools.git diff --git a/src/common/kernel-consumer/kernel-consumer.c b/src/common/kernel-consumer/kernel-consumer.c index 5464822aa..236c2c98f 100644 --- a/src/common/kernel-consumer/kernel-consumer.c +++ b/src/common/kernel-consumer/kernel-consumer.c @@ -8,7 +8,6 @@ */ #define _LGPL_SOURCE -#include #include #include #include @@ -74,7 +73,7 @@ int lttng_kconsumer_take_snapshot(struct lttng_consumer_stream *stream) int lttng_kconsumer_sample_snapshot_positions( struct lttng_consumer_stream *stream) { - assert(stream); + LTTNG_ASSERT(stream); return kernctl_snapshot_sample_positions(stream->wait_fd); } @@ -174,7 +173,7 @@ static int lttng_kconsumer_snapshot_channel( */ pthread_mutex_lock(&stream->lock); - assert(channel->trace_chunk); + LTTNG_ASSERT(channel->trace_chunk); if (!lttng_trace_chunk_get(channel->trace_chunk)) { /* * Can't happen barring an internal error as the channel @@ -184,7 +183,7 @@ static int lttng_kconsumer_snapshot_channel( ret = -1; goto end_unlock; } - assert(!stream->trace_chunk); + LTTNG_ASSERT(!stream->trace_chunk); stream->trace_chunk = channel->trace_chunk; /* @@ -366,7 +365,7 @@ static int lttng_kconsumer_snapshot_metadata( ssize_t ret_read; struct lttng_consumer_stream *metadata_stream; - assert(ctx); + LTTNG_ASSERT(ctx); DBG("Kernel consumer snapshot metadata with key %" PRIu64 " at path %s", key, path); @@ -374,11 +373,11 @@ static int lttng_kconsumer_snapshot_metadata( rcu_read_lock(); metadata_stream = metadata_channel->metadata_stream; - assert(metadata_stream); + LTTNG_ASSERT(metadata_stream); pthread_mutex_lock(&metadata_stream->lock); - assert(metadata_channel->trace_chunk); - assert(metadata_stream->trace_chunk); + LTTNG_ASSERT(metadata_channel->trace_chunk); + LTTNG_ASSERT(metadata_stream->trace_chunk); /* Flag once that we have a valid relayd for the stream. */ if (relayd_id != (uint64_t) -1ULL) { @@ -470,7 +469,7 @@ int lttng_kconsumer_recv_cmd(struct lttng_consumer_local_data *ctx, health_code_update(); /* Deprecated command */ - assert(msg.cmd_type != LTTNG_CONSUMER_STOP); + LTTNG_ASSERT(msg.cmd_type != LTTNG_CONSUMER_STOP); health_code_update(); @@ -542,7 +541,7 @@ int lttng_kconsumer_recv_cmd(struct lttng_consumer_local_data *ctx, new_channel->type = msg.u.channel.type; break; default: - assert(0); + abort(); goto end_nosignal; }; @@ -1031,13 +1030,13 @@ error_streams_sent_nosignal: * This command should ONLY be issued for channel with streams set in * no monitor mode. */ - assert(!channel->monitor); + LTTNG_ASSERT(!channel->monitor); /* * The refcount should ALWAYS be 0 in the case of a channel in no * monitor mode. */ - assert(!uatomic_sub_return(&channel->refcount, 1)); + LTTNG_ASSERT(!uatomic_sub_return(&channel->refcount, 1)); consumer_del_channel(channel); end_destroy_channel: @@ -1432,7 +1431,7 @@ enum sync_metadata_status lttng_kconsumer_sync_metadata( int ret; enum sync_metadata_status status; - assert(metadata); + LTTNG_ASSERT(metadata); ret = kernctl_buffer_flush(metadata->wait_fd); if (ret < 0) { @@ -1583,13 +1582,20 @@ end: } static -int get_subbuffer_common(struct lttng_consumer_stream *stream, +enum get_next_subbuffer_status get_subbuffer_common( + struct lttng_consumer_stream *stream, struct stream_subbuffer *subbuffer) { int ret; + enum get_next_subbuffer_status status; ret = kernctl_get_next_subbuf(stream->wait_fd); - if (ret) { + switch (ret) { + case 0: + status = GET_NEXT_SUBBUFFER_STATUS_OK; + break; + case -ENODATA: + case -EAGAIN: /* * The caller only expects -ENODATA when there is no data to * read, but the kernel tracer returns -EAGAIN when there is @@ -1597,65 +1603,73 @@ int get_subbuffer_common(struct lttng_consumer_stream *stream, * when there is no data for a finalized stream. Those can be * combined into a -ENODATA return value. */ - if (ret == -EAGAIN) { - ret = -ENODATA; - } - + status = GET_NEXT_SUBBUFFER_STATUS_NO_DATA; + goto end; + default: + status = GET_NEXT_SUBBUFFER_STATUS_ERROR; goto end; } ret = stream->read_subbuffer_ops.extract_subbuffer_info( - stream, subbuffer); + stream, subbuffer); + if (ret) { + status = GET_NEXT_SUBBUFFER_STATUS_ERROR; + } end: - return ret; + return status; } static -int get_next_subbuffer_splice(struct lttng_consumer_stream *stream, +enum get_next_subbuffer_status get_next_subbuffer_splice( + struct lttng_consumer_stream *stream, struct stream_subbuffer *subbuffer) { - int ret; + const enum get_next_subbuffer_status status = + get_subbuffer_common(stream, subbuffer); - ret = get_subbuffer_common(stream, subbuffer); - if (ret) { + if (status != GET_NEXT_SUBBUFFER_STATUS_OK) { goto end; } subbuffer->buffer.fd = stream->wait_fd; end: - return ret; + return status; } static -int get_next_subbuffer_mmap(struct lttng_consumer_stream *stream, +enum get_next_subbuffer_status get_next_subbuffer_mmap( + struct lttng_consumer_stream *stream, struct stream_subbuffer *subbuffer) { int ret; + enum get_next_subbuffer_status status; const char *addr; - ret = get_subbuffer_common(stream, subbuffer); - if (ret) { + status = get_subbuffer_common(stream, subbuffer); + if (status != GET_NEXT_SUBBUFFER_STATUS_OK) { goto end; } ret = get_current_subbuf_addr(stream, &addr); if (ret) { + status = GET_NEXT_SUBBUFFER_STATUS_ERROR; goto end; } subbuffer->buffer.buffer = lttng_buffer_view_init( addr, 0, subbuffer->info.data.padded_subbuf_size); end: - return ret; + return status; } static -int get_next_subbuffer_metadata_check(struct lttng_consumer_stream *stream, +enum get_next_subbuffer_status get_next_subbuffer_metadata_check(struct lttng_consumer_stream *stream, struct stream_subbuffer *subbuffer) { int ret; const char *addr; bool coherent; + enum get_next_subbuffer_status status; ret = kernctl_get_next_subbuf_metadata_check(stream->wait_fd, &coherent); @@ -1688,11 +1702,27 @@ end: * for a non-finalized stream, and -ENODATA when there is no data for a * finalized stream. Those can be combined into a -ENODATA return value. */ - if (ret == -EAGAIN) { - ret = -ENODATA; + switch (ret) { + case 0: + status = GET_NEXT_SUBBUFFER_STATUS_OK; + break; + case -ENODATA: + case -EAGAIN: + /* + * The caller only expects -ENODATA when there is no data to + * read, but the kernel tracer returns -EAGAIN when there is + * currently no data for a non-finalized stream, and -ENODATA + * when there is no data for a finalized stream. Those can be + * combined into a -ENODATA return value. + */ + status = GET_NEXT_SUBBUFFER_STATUS_NO_DATA; + break; + default: + status = GET_NEXT_SUBBUFFER_STATUS_ERROR; + break; } - return ret; + return status; } static @@ -1800,7 +1830,7 @@ int lttng_kconsumer_on_recv_stream(struct lttng_consumer_stream *stream) { int ret; - assert(stream); + LTTNG_ASSERT(stream); /* * Don't create anything if this is set for streaming or if there is @@ -1847,7 +1877,7 @@ error_close_fd: int err; err = close(stream->out_fd); - assert(!err); + LTTNG_ASSERT(!err); stream->out_fd = -1; } error: @@ -1866,7 +1896,7 @@ int lttng_kconsumer_data_pending(struct lttng_consumer_stream *stream) { int ret; - assert(stream); + LTTNG_ASSERT(stream); if (stream->endpoint_status != CONSUMER_ENDPOINT_ACTIVE) { ret = 0; @@ -1877,7 +1907,7 @@ int lttng_kconsumer_data_pending(struct lttng_consumer_stream *stream) if (ret == 0) { /* There is still data so let's put back this subbuffer. */ ret = kernctl_put_subbuf(stream->wait_fd); - assert(ret == 0); + LTTNG_ASSERT(ret == 0); ret = 1; /* Data is pending */ goto end; }