Fix: ust-consumer: metadata thread not woken-up after version change
[lttng-tools.git] / src / common / consumer / consumer.c
index 86caf6841d43501521ba0a8865402809bfa2d0b8..9709705b733b17fe2c53970d60482e964a2027df 100644 (file)
@@ -878,6 +878,43 @@ error:
        return outfd;
 }
 
+/*
+ * Write a character on the metadata poll pipe to wake the metadata thread.
+ * Returns 0 on success, -1 on error.
+ */
+int consumer_metadata_wakeup_pipe(const struct lttng_consumer_channel *channel)
+{
+       int ret = 0;
+
+       DBG("Waking up metadata poll thread (writing to pipe): channel name = '%s'",
+                       channel->name);
+       if (channel->monitor && channel->metadata_stream) {
+               const char dummy = 'c';
+               const ssize_t write_ret = lttng_write(
+                               channel->metadata_stream->ust_metadata_poll_pipe[1],
+                               &dummy, 1);
+
+               if (write_ret < 1) {
+                       if (errno == EWOULDBLOCK) {
+                               /*
+                                * This is fine, the metadata poll thread
+                                * is having a hard time keeping-up, but
+                                * it will eventually wake-up and consume
+                                * the available data.
+                                */
+                               ret = 0;
+                       } else {
+                               PERROR("Failed to write to UST metadata pipe while attempting to wake-up the metadata poll thread");
+                               ret = -1;
+                               goto end;
+                       }
+               }
+       }
+
+end:
+       return ret;
+}
+
 /*
  * Trigger a dump of the metadata content. Following/during the succesful
  * completion of this call, the metadata poll thread will start receiving
@@ -1584,7 +1621,6 @@ end:
  * Returns the number of bytes written
  */
 ssize_t lttng_consumer_on_read_subbuffer_mmap(
-               struct lttng_consumer_local_data *ctx,
                struct lttng_consumer_stream *stream,
                const struct lttng_buffer_view *buffer,
                unsigned long padding)
@@ -1687,7 +1723,7 @@ ssize_t lttng_consumer_on_read_subbuffer_mmap(
         * receive a ret value that is bigger than len.
         */
        ret = lttng_write(outfd, buffer->data, write_len);
-       DBG("Consumer mmap write() ret %zd (len %lu)", ret, write_len);
+       DBG("Consumer mmap write() ret %zd (len %zu)", ret, write_len);
        if (ret < 0 || ((size_t) ret != write_len)) {
                /*
                 * Report error to caller if nothing was written else at least send the
@@ -3254,7 +3290,7 @@ void *consumer_thread_sessiond_poll(void *data)
                        err = 0;        /* All is OK */
                        goto end;
                }
-               DBG("received command on sock");
+               DBG("Received command on sock");
        }
        /* All is OK */
        err = 0;
@@ -3315,7 +3351,7 @@ ssize_t lttng_consumer_read_subbuffer(struct lttng_consumer_stream *stream,
                struct lttng_consumer_local_data *ctx,
                bool locked_by_caller)
 {
-       ssize_t ret, written_bytes;
+       ssize_t ret, written_bytes = 0;
        int rotation_ret;
        struct stream_subbuffer subbuffer = {};
 
@@ -3348,6 +3384,7 @@ ssize_t lttng_consumer_read_subbuffer(struct lttng_consumer_stream *stream,
                if (ret == -ENODATA) {
                        /* Not an error. */
                        ret = 0;
+                       goto sleep_stream;
                }
                goto end;
        }
@@ -3360,24 +3397,10 @@ ssize_t lttng_consumer_read_subbuffer(struct lttng_consumer_stream *stream,
 
        written_bytes = stream->read_subbuffer_ops.consume_subbuffer(
                        ctx, stream, &subbuffer);
-       /*
-        * Should write subbuf_size amount of data when network streaming or
-        * the full padded size when we are not streaming.
-        */
-       if ((written_bytes != subbuffer.info.data.subbuf_size &&
-                           stream->net_seq_idx != (uint64_t) -1ULL) ||
-                       (written_bytes != subbuffer.info.data.padded_subbuf_size &&
-                                       stream->net_seq_idx ==
-                                                       (uint64_t) -1ULL)) {
-               /*
-                * Display the error but continue processing to try to
-                * release the subbuffer. This is a DBG statement
-                * since this can happen without being a critical
-                * error.
-                */
-               DBG("Failed to write to tracefile (written_bytes: %zd != padded subbuffer size: %lu, subbuffer size: %lu)",
-                               written_bytes, subbuffer.info.data.subbuf_size,
-                               subbuffer.info.data.padded_subbuf_size);
+       if (written_bytes <= 0) {
+               ERR("Error consuming subbuffer: (%zd)", written_bytes);
+               ret = (int) written_bytes;
+               goto error_put_subbuf;
        }
 
        ret = stream->read_subbuffer_ops.put_next_subbuffer(stream, &subbuffer);
@@ -3413,6 +3436,7 @@ ssize_t lttng_consumer_read_subbuffer(struct lttng_consumer_stream *stream,
                goto end;
        }
 
+sleep_stream:
        if (stream->read_subbuffer_ops.on_sleep) {
                stream->read_subbuffer_ops.on_sleep(stream, ctx);
        }
This page took 0.024784 seconds and 4 git commands to generate.