Move to kernel style SPDX license identifiers
[babeltrace.git] / src / plugins / ctf / lttng-live / data-stream.c
index ee351648a417880411bc24f8355af9898a98599c..aba9c807659d718abdf7e7be4aecb9374e65e63f 100644 (file)
@@ -1,26 +1,10 @@
 /*
- * Copyright 2019 Francis Deslauriers <francis.deslauriers@efficios.com>
- * Copyright 2016 - Philippe Proulx <pproulx@efficios.com>
- * Copyright 2016 - Jérémie Galarneau <jeremie.galarneau@efficios.com>
- * Copyright 2010-2011 - EfficiOS Inc. and Linux Foundation
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
+ * SPDX-License-Identifier: MIT
  *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
+ * Copyright 2019 Francis Deslauriers <francis.deslauriers@efficios.com>
+ * Copyright 2016 Philippe Proulx <pproulx@efficios.com>
+ * Copyright 2016 Jérémie Galarneau <jeremie.galarneau@efficios.com>
+ * Copyright 2010-2011 EfficiOS Inc. and Linux Foundation
  */
 
 #define BT_COMP_LOG_SELF_COMP self_comp
 #define BT_LOG_TAG "PLUGIN/SRC.CTF.LTTNG-LIVE/DS"
 #include "logging/comp-logging.h"
 
+#include <inttypes.h>
 #include <stdio.h>
-#include <stdint.h>
 #include <stdlib.h>
+
 #include <glib.h>
-#include <inttypes.h>
-#include "compat/mman.h"
+
 #include <babeltrace2/babeltrace.h>
+
 #include "../common/msg-iter/msg-iter.h"
 #include "common/assert.h"
-
+#include "compat/mman.h"
 #include "data-stream.h"
 
 #define STREAM_NAME_PREFIX     "stream-"
 
 static
-enum bt_msg_iter_medium_status medop_request_bytes(
+enum ctf_msg_iter_medium_status medop_request_bytes(
                size_t request_sz, uint8_t **buffer_addr,
                size_t *buffer_sz, void *data)
 {
-       enum bt_msg_iter_medium_status status =
-               BT_MSG_ITER_MEDIUM_STATUS_OK;
+       enum ctf_msg_iter_medium_status status =
+               CTF_MSG_ITER_MEDIUM_STATUS_OK;
        struct lttng_live_stream_iterator *stream = data;
        struct lttng_live_trace *trace = stream->trace;
        struct lttng_live_session *session = trace->session;
@@ -57,15 +42,17 @@ enum bt_msg_iter_medium_status medop_request_bytes(
        uint64_t len_left;
        uint64_t read_len;
 
+       BT_ASSERT(request_sz);
+
        if (stream->has_stream_hung_up) {
-               status = BT_MSG_ITER_MEDIUM_STATUS_EOF;
+               status = CTF_MSG_ITER_MEDIUM_STATUS_EOF;
                goto end;
        }
 
        len_left = stream->base_offset + stream->len - stream->offset;
        if (!len_left) {
                stream->state = LTTNG_LIVE_STREAM_ACTIVE_NO_DATA;
-               status = BT_MSG_ITER_MEDIUM_STATUS_AGAIN;
+               status = CTF_MSG_ITER_MEDIUM_STATUS_AGAIN;
                goto end;
        }
 
@@ -113,7 +100,8 @@ bt_stream *medop_borrow_stream(bt_stream_class *stream_class,
                }
 
                if (!lttng_live_stream->stream) {
-                       BT_COMP_LOGE("Cannot create stream %s (stream class ID "
+                       BT_COMP_LOGE_APPEND_CAUSE(self_comp,
+                               "Cannot create stream %s (stream class ID "
                                "%" PRId64 ", stream ID %" PRIu64 ")",
                                lttng_live_stream->name->str,
                                stream_class_id, stream_id);
@@ -128,7 +116,7 @@ end:
        return lttng_live_stream->stream;
 }
 
-static struct bt_msg_iter_medium_ops medops = {
+static struct ctf_msg_iter_medium_ops medops = {
        .request_bytes = medop_request_bytes,
        .seek = NULL,
        .borrow_stream = medop_borrow_stream,
@@ -136,7 +124,8 @@ static struct bt_msg_iter_medium_ops medops = {
 
 BT_HIDDEN
 enum lttng_live_iterator_status lttng_live_lazy_msg_init(
-               struct lttng_live_session *session)
+               struct lttng_live_session *session,
+               bt_self_message_iterator *self_msg_iter)
 {
        struct lttng_live_component *lttng_live =
                session->lttng_live_msg_iter->lttng_live_comp;
@@ -148,6 +137,10 @@ enum lttng_live_iterator_status lttng_live_lazy_msg_init(
                return LTTNG_LIVE_ITERATOR_STATUS_OK;
        }
 
+       BT_COMP_LOGD("Lazily initializing self message iterator for live session: "
+               "session-id=%"PRIu64", self-msg-iter-addr=%p", session->id,
+               self_msg_iter);
+
        for (trace_idx = 0; trace_idx < session->traces->len; trace_idx++) {
                struct lttng_live_trace *trace =
                        g_ptr_array_index(session->traces, trace_idx);
@@ -165,17 +158,18 @@ enum lttng_live_iterator_status lttng_live_lazy_msg_init(
                        }
                        ctf_tc = ctf_metadata_decoder_borrow_ctf_trace_class(
                                trace->metadata->decoder);
-                       stream_iter->msg_iter = bt_msg_iter_create(ctf_tc,
+                       BT_COMP_LOGD("Creating CTF message iterator: "
+                               "session-id=%"PRIu64", ctf-tc-addr=%p, "
+                               "stream-iter-name=%s, self-msg-iter-addr=%p",
+                               session->id, ctf_tc, stream_iter->name->str, self_msg_iter);
+                       stream_iter->msg_iter = ctf_msg_iter_create(ctf_tc,
                                lttng_live->max_query_size, medops, stream_iter,
-                               log_level, self_comp);
+                               log_level, self_comp, self_msg_iter);
                        if (!stream_iter->msg_iter) {
+                               BT_COMP_LOGE_APPEND_CAUSE(self_comp,
+                                       "Failed to create CTF message iterator");
                                goto error;
                        }
-
-                       bt_msg_iter_set_emit_stream_end_message(
-                               stream_iter->msg_iter, true);
-                       bt_msg_iter_set_emit_stream_beginning_message(
-                               stream_iter->msg_iter, true);
                }
        }
 
@@ -191,7 +185,8 @@ BT_HIDDEN
 struct lttng_live_stream_iterator *lttng_live_stream_iterator_create(
                struct lttng_live_session *session,
                uint64_t ctf_trace_id,
-               uint64_t stream_id)
+               uint64_t stream_id,
+               bt_self_message_iterator *self_msg_iter)
 {
        struct lttng_live_stream_iterator *stream_iter;
        struct lttng_live_component *lttng_live;
@@ -209,13 +204,17 @@ struct lttng_live_stream_iterator *lttng_live_stream_iterator_create(
 
        stream_iter = g_new0(struct lttng_live_stream_iterator, 1);
        if (!stream_iter) {
+               BT_COMP_LOGE_APPEND_CAUSE(self_comp,
+                       "Failed to allocate struct lttng_live_stream_iterator");
                goto error;
        }
 
        stream_iter->log_level = log_level;
        stream_iter->self_comp = self_comp;
-       trace = lttng_live_borrow_trace(session, ctf_trace_id);
+       trace = lttng_live_session_borrow_or_create_trace_by_id(session, ctf_trace_id);
        if (!trace) {
+               BT_COMP_LOGE_APPEND_CAUSE(self_comp,
+                       "Failed to borrow CTF trace.");
                goto error;
        }
 
@@ -230,26 +229,27 @@ struct lttng_live_stream_iterator *lttng_live_stream_iterator_create(
                        ctf_metadata_decoder_borrow_ctf_trace_class(
                                trace->metadata->decoder);
                BT_ASSERT(!stream_iter->msg_iter);
-               stream_iter->msg_iter = bt_msg_iter_create(ctf_tc,
+               stream_iter->msg_iter = ctf_msg_iter_create(ctf_tc,
                        lttng_live->max_query_size, medops, stream_iter,
-                       log_level, self_comp);
+                       log_level, self_comp, self_msg_iter);
                if (!stream_iter->msg_iter) {
+                       BT_COMP_LOGE_APPEND_CAUSE(self_comp,
+                               "Failed to create CTF message iterator");
                        goto error;
                }
-
-               bt_msg_iter_set_emit_stream_end_message(
-                       stream_iter->msg_iter, true);
-               bt_msg_iter_set_emit_stream_beginning_message(
-                       stream_iter->msg_iter, true);
        }
        stream_iter->buf = g_new0(uint8_t, lttng_live->max_query_size);
        if (!stream_iter->buf) {
+               BT_COMP_LOGE_APPEND_CAUSE(self_comp,
+                       "Failed to allocate live stream iterator buffer");
                goto error;
        }
 
        stream_iter->buflen = lttng_live->max_query_size;
        stream_iter->name = g_string_new(NULL);
        if (!stream_iter->name) {
+               BT_COMP_LOGE_APPEND_CAUSE(self_comp,
+                       "Failed to allocate live stream iterator name buffer");
                goto error;
        }
 
@@ -281,7 +281,7 @@ void lttng_live_stream_iterator_destroy(
        }
 
        if (stream_iter->msg_iter) {
-               bt_msg_iter_destroy(stream_iter->msg_iter);
+               ctf_msg_iter_destroy(stream_iter->msg_iter);
        }
        g_free(stream_iter->buf);
        if (stream_iter->name) {
@@ -293,10 +293,5 @@ void lttng_live_stream_iterator_destroy(
        /* Track the number of active stream iterator. */
        stream_iter->trace->session->lttng_live_msg_iter->active_stream_iter--;
 
-       /*
-        * Ensure we poke the trace metadata in the future, which is
-        * required to release the metadata reference on the trace.
-        */
-       stream_iter->trace->new_metadata_needed = true;
        g_free(stream_iter);
 }
This page took 0.026406 seconds and 4 git commands to generate.