2 * Copyright 2016-2017 - Philippe Proulx <pproulx@efficios.com>
3 * Copyright 2016 - Jérémie Galarneau <jeremie.galarneau@efficios.com>
4 * Copyright 2010-2011 - EfficiOS Inc. and Linux Foundation
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 #define BT_COMP_LOG_SELF_COMP (ds_file->self_comp)
26 #define BT_LOG_OUTPUT_LEVEL (ds_file->log_level)
27 #define BT_LOG_TAG "PLUGIN/SRC.CTF.FS/DS"
28 #include "logging/comp-logging.h"
36 #include "compat/mman.h"
37 #include "compat/endian.h"
38 #include <babeltrace2/babeltrace.h>
39 #include "common/common.h"
42 #include "../common/msg-iter/msg-iter.h"
43 #include "common/assert.h"
44 #include "data-stream-file.h"
48 size_t remaining_mmap_bytes(struct ctf_fs_ds_file
*ds_file
)
50 BT_ASSERT_DBG(ds_file
->mmap_len
>= ds_file
->request_offset
);
51 return ds_file
->mmap_len
- ds_file
->request_offset
;
55 int ds_file_munmap(struct ctf_fs_ds_file
*ds_file
)
59 if (!ds_file
|| !ds_file
->mmap_addr
) {
63 if (bt_munmap(ds_file
->mmap_addr
, ds_file
->mmap_len
)) {
64 BT_COMP_LOGE_ERRNO("Cannot memory-unmap file",
65 ": address=%p, size=%zu, file_path=\"%s\", file=%p",
66 ds_file
->mmap_addr
, ds_file
->mmap_len
,
67 ds_file
->file
? ds_file
->file
->path
->str
: "NULL",
68 ds_file
->file
? ds_file
->file
->fp
: NULL
);
73 ds_file
->mmap_addr
= NULL
;
80 enum ctf_msg_iter_medium_status
ds_file_mmap_next(
81 struct ctf_fs_ds_file
*ds_file
)
83 enum ctf_msg_iter_medium_status ret
=
84 CTF_MSG_ITER_MEDIUM_STATUS_OK
;
86 /* Unmap old region */
87 if (ds_file
->mmap_addr
) {
88 if (ds_file_munmap(ds_file
)) {
93 * mmap_len is guaranteed to be page-aligned except on the
94 * last mapping where it may not be possible (since the file's
95 * size itself may not be a page multiple).
97 ds_file
->mmap_offset
+= ds_file
->mmap_len
;
98 ds_file
->request_offset
= 0;
101 ds_file
->mmap_len
= MIN(ds_file
->file
->size
- ds_file
->mmap_offset
,
102 ds_file
->mmap_max_len
);
103 if (ds_file
->mmap_len
== 0) {
104 ret
= CTF_MSG_ITER_MEDIUM_STATUS_EOF
;
108 BT_ASSERT(ds_file
->mmap_len
);
109 ds_file
->mmap_addr
= bt_mmap((void *) 0, ds_file
->mmap_len
,
110 PROT_READ
, MAP_PRIVATE
, fileno(ds_file
->file
->fp
),
111 ds_file
->mmap_offset
, ds_file
->log_level
);
112 if (ds_file
->mmap_addr
== MAP_FAILED
) {
113 BT_COMP_LOGE("Cannot memory-map address (size %zu) of file \"%s\" (%p) at offset %jd: %s",
114 ds_file
->mmap_len
, ds_file
->file
->path
->str
,
115 ds_file
->file
->fp
, (intmax_t) ds_file
->mmap_offset
,
122 ds_file_munmap(ds_file
);
123 ret
= CTF_MSG_ITER_MEDIUM_STATUS_ERROR
;
129 enum ctf_msg_iter_medium_status
medop_request_bytes(
130 size_t request_sz
, uint8_t **buffer_addr
,
131 size_t *buffer_sz
, void *data
)
133 enum ctf_msg_iter_medium_status status
=
134 CTF_MSG_ITER_MEDIUM_STATUS_OK
;
135 struct ctf_fs_ds_file
*ds_file
= data
;
137 if (request_sz
== 0) {
142 * Check if we have at least one memory-mapped byte left. If we don't,
143 * mmap the next file.
145 if (remaining_mmap_bytes(ds_file
) == 0) {
146 /* Are we at the end of the file? */
147 if (ds_file
->mmap_offset
>= ds_file
->file
->size
) {
148 BT_COMP_LOGD("Reached end of file \"%s\" (%p)",
149 ds_file
->file
->path
->str
, ds_file
->file
->fp
);
150 status
= CTF_MSG_ITER_MEDIUM_STATUS_EOF
;
154 status
= ds_file_mmap_next(ds_file
);
156 case CTF_MSG_ITER_MEDIUM_STATUS_OK
:
158 case CTF_MSG_ITER_MEDIUM_STATUS_EOF
:
161 BT_COMP_LOGE("Cannot memory-map next region of file \"%s\" (%p)",
162 ds_file
->file
->path
->str
,
168 *buffer_sz
= MIN(remaining_mmap_bytes(ds_file
), request_sz
);
169 BT_ASSERT(ds_file
->mmap_addr
);
170 *buffer_addr
= ((uint8_t *) ds_file
->mmap_addr
) + ds_file
->request_offset
;
171 ds_file
->request_offset
+= *buffer_sz
;
175 status
= CTF_MSG_ITER_MEDIUM_STATUS_ERROR
;
182 bt_stream
*medop_borrow_stream(bt_stream_class
*stream_class
, int64_t stream_id
,
185 struct ctf_fs_ds_file
*ds_file
= data
;
186 bt_stream_class
*ds_file_stream_class
;
187 bt_stream
*stream
= NULL
;
189 ds_file_stream_class
= bt_stream_borrow_class(
192 if (stream_class
!= ds_file_stream_class
) {
194 * Not supported: two packets described by two different
195 * stream classes within the same data stream file.
200 stream
= ds_file
->stream
;
207 enum ctf_msg_iter_medium_status
medop_seek(enum ctf_msg_iter_seek_whence whence
,
208 off_t offset
, void *data
)
210 enum ctf_msg_iter_medium_status ret
=
211 CTF_MSG_ITER_MEDIUM_STATUS_OK
;
212 struct ctf_fs_ds_file
*ds_file
= data
;
213 off_t offset_in_mapping
, file_size
= ds_file
->file
->size
;
215 if (whence
!= CTF_MSG_ITER_SEEK_WHENCE_SET
||
216 offset
< 0 || offset
> file_size
) {
217 BT_COMP_LOGE("Invalid medium seek request: whence=%d, offset=%jd, "
218 "file-size=%jd", (int) whence
, (intmax_t) offset
,
219 (intmax_t) file_size
);
220 ret
= CTF_MSG_ITER_MEDIUM_STATUS_INVAL
;
224 /* If there is no current mapping, map the right file directly. */
225 if (!ds_file
->mmap_addr
) {
226 goto map_requested_offset
;
230 * Determine whether or not the destination is contained within the
233 if (offset
< ds_file
->mmap_offset
||
234 offset
>= ds_file
->mmap_offset
+ ds_file
->mmap_len
) {
236 BT_COMP_LOGD("Medium seek request cannot be accomodated by the current "
237 "file mapping: offset=%jd, mmap-offset=%jd, "
238 "mmap-len=%zu", (intmax_t) offset
, (intmax_t) ds_file
->mmap_offset
,
240 unmap_ret
= ds_file_munmap(ds_file
);
242 ret
= CTF_MSG_ITER_MEDIUM_STATUS_ERROR
;
245 goto map_requested_offset
;
247 ds_file
->request_offset
= offset
- ds_file
->mmap_offset
;
251 map_requested_offset
:
252 offset_in_mapping
= offset
%
253 bt_mmap_get_offset_align_size(ds_file
->log_level
);
255 ds_file
->mmap_offset
= offset
- offset_in_mapping
;
256 ds_file
->request_offset
= offset_in_mapping
;
257 ret
= ds_file_mmap_next(ds_file
);
258 if (ret
!= CTF_MSG_ITER_MEDIUM_STATUS_OK
) {
263 ds_file
->end_reached
= (offset
== file_size
);
269 struct ctf_msg_iter_medium_ops ctf_fs_ds_file_medops
= {
270 .request_bytes
= medop_request_bytes
,
271 .borrow_stream
= medop_borrow_stream
,
276 int convert_cycles_to_ns(struct ctf_clock_class
*clock_class
,
277 uint64_t cycles
, int64_t *ns
)
279 return bt_util_clock_cycles_to_ns_from_origin(cycles
,
280 clock_class
->frequency
, clock_class
->offset_seconds
,
281 clock_class
->offset_cycles
, ns
);
285 struct ctf_fs_ds_index
*build_index_from_idx_file(
286 struct ctf_fs_ds_file
*ds_file
,
287 struct ctf_fs_ds_file_info
*file_info
)
290 gchar
*directory
= NULL
;
291 gchar
*basename
= NULL
;
292 GString
*index_basename
= NULL
;
293 gchar
*index_file_path
= NULL
;
294 GMappedFile
*mapped_file
= NULL
;
296 const char *mmap_begin
= NULL
, *file_pos
= NULL
;
297 const struct ctf_packet_index_file_hdr
*header
= NULL
;
298 struct ctf_fs_ds_index
*index
= NULL
;
299 struct ctf_fs_ds_index_entry
*index_entry
= NULL
, *prev_index_entry
= NULL
;
300 uint64_t total_packets_size
= 0;
301 size_t file_index_entry_size
;
302 size_t file_entry_count
;
304 struct ctf_stream_class
*sc
;
305 struct ctf_msg_iter_packet_properties props
;
306 uint32_t version_major
, version_minor
;
308 BT_COMP_LOGI("Building index from .idx file of stream file %s",
309 ds_file
->file
->path
->str
);
310 ret
= ctf_msg_iter_get_packet_properties(ds_file
->msg_iter
, &props
);
312 BT_COMP_LOGI_STR("Cannot read first packet's header and context fields.");
316 sc
= ctf_trace_class_borrow_stream_class_by_id(ds_file
->metadata
->tc
,
317 props
.stream_class_id
);
319 if (!sc
->default_clock_class
) {
320 BT_COMP_LOGI_STR("Cannot find stream class's default clock class.");
324 /* Look for index file in relative path index/name.idx. */
325 basename
= g_path_get_basename(ds_file
->file
->path
->str
);
327 BT_COMP_LOGE("Cannot get the basename of datastream file %s",
328 ds_file
->file
->path
->str
);
332 directory
= g_path_get_dirname(ds_file
->file
->path
->str
);
334 BT_COMP_LOGE("Cannot get dirname of datastream file %s",
335 ds_file
->file
->path
->str
);
339 index_basename
= g_string_new(basename
);
340 if (!index_basename
) {
341 BT_COMP_LOGE_STR("Cannot allocate index file basename string");
345 g_string_append(index_basename
, ".idx");
346 index_file_path
= g_build_filename(directory
, "index",
347 index_basename
->str
, NULL
);
348 mapped_file
= g_mapped_file_new(index_file_path
, FALSE
, NULL
);
350 BT_COMP_LOGD("Cannot create new mapped file %s",
356 * The g_mapped_file API limits us to 4GB files on 32-bit.
357 * Traces with such large indexes have never been seen in the wild,
358 * but this would need to be adjusted to support them.
360 filesize
= g_mapped_file_get_length(mapped_file
);
361 if (filesize
< sizeof(*header
)) {
362 BT_COMP_LOGW("Invalid LTTng trace index file: "
363 "file size (%zu bytes) < header size (%zu bytes)",
364 filesize
, sizeof(*header
));
368 mmap_begin
= g_mapped_file_get_contents(mapped_file
);
369 header
= (struct ctf_packet_index_file_hdr
*) mmap_begin
;
371 file_pos
= g_mapped_file_get_contents(mapped_file
) + sizeof(*header
);
372 if (be32toh(header
->magic
) != CTF_INDEX_MAGIC
) {
373 BT_COMP_LOGW_STR("Invalid LTTng trace index: \"magic\" field validation failed");
377 version_major
= be32toh(header
->index_major
);
378 version_minor
= be32toh(header
->index_minor
);
379 if (version_major
!= 1) {
381 "Unknown LTTng trace index version: "
382 "major=%" PRIu32
", minor=%" PRIu32
,
383 version_major
, version_minor
);
387 file_index_entry_size
= be32toh(header
->packet_index_len
);
388 file_entry_count
= (filesize
- sizeof(*header
)) / file_index_entry_size
;
389 if ((filesize
- sizeof(*header
)) % file_index_entry_size
) {
390 BT_COMP_LOGW("Invalid LTTng trace index: the index's size after the header "
391 "(%zu bytes) is not a multiple of the index entry size "
392 "(%zu bytes)", (filesize
- sizeof(*header
)),
397 index
= ctf_fs_ds_index_create(ds_file
->log_level
, ds_file
->self_comp
);
402 for (i
= 0; i
< file_entry_count
; i
++) {
403 struct ctf_packet_index
*file_index
=
404 (struct ctf_packet_index
*) file_pos
;
405 uint64_t packet_size
= be64toh(file_index
->packet_size
);
407 if (packet_size
% CHAR_BIT
) {
408 BT_COMP_LOGW("Invalid packet size encountered in LTTng trace index file");
412 index_entry
= g_new0(struct ctf_fs_ds_index_entry
, 1);
417 /* Set path to stream file. */
418 index_entry
->path
= file_info
->path
->str
;
420 /* Convert size in bits to bytes. */
421 packet_size
/= CHAR_BIT
;
422 index_entry
->packet_size
= packet_size
;
424 index_entry
->offset
= be64toh(file_index
->offset
);
425 if (i
!= 0 && index_entry
->offset
< prev_index_entry
->offset
) {
426 BT_COMP_LOGW("Invalid, non-monotonic, packet offset encountered in LTTng trace index file: "
427 "previous offset=%" PRIu64
", current offset=%" PRIu64
,
428 prev_index_entry
->offset
, index_entry
->offset
);
432 index_entry
->timestamp_begin
= be64toh(file_index
->timestamp_begin
);
433 index_entry
->timestamp_end
= be64toh(file_index
->timestamp_end
);
434 if (index_entry
->timestamp_end
< index_entry
->timestamp_begin
) {
435 BT_COMP_LOGW("Invalid packet time bounds encountered in LTTng trace index file (begin > end): "
436 "timestamp_begin=%" PRIu64
"timestamp_end=%" PRIu64
,
437 index_entry
->timestamp_begin
,
438 index_entry
->timestamp_end
);
442 /* Convert the packet's bound to nanoseconds since Epoch. */
443 ret
= convert_cycles_to_ns(sc
->default_clock_class
,
444 index_entry
->timestamp_begin
,
445 &index_entry
->timestamp_begin_ns
);
447 BT_COMP_LOGI_STR("Failed to convert raw timestamp to nanoseconds since Epoch during index parsing");
450 ret
= convert_cycles_to_ns(sc
->default_clock_class
,
451 index_entry
->timestamp_end
,
452 &index_entry
->timestamp_end_ns
);
454 BT_COMP_LOGI_STR("Failed to convert raw timestamp to nanoseconds since Epoch during LTTng trace index parsing");
458 total_packets_size
+= packet_size
;
459 file_pos
+= file_index_entry_size
;
461 prev_index_entry
= index_entry
;
463 /* Give ownership of `index_entry` to `index->entries`. */
464 g_ptr_array_add(index
->entries
, index_entry
);
468 /* Validate that the index addresses the complete stream. */
469 if (ds_file
->file
->size
!= total_packets_size
) {
470 BT_COMP_LOGW("Invalid LTTng trace index file; indexed size != stream file size: "
471 "file-size=%" PRIu64
", total-packets-size=%" PRIu64
,
472 ds_file
->file
->size
, total_packets_size
);
478 g_free(index_file_path
);
479 if (index_basename
) {
480 g_string_free(index_basename
, TRUE
);
483 g_mapped_file_unref(mapped_file
);
487 ctf_fs_ds_index_destroy(index
);
494 int init_index_entry(struct ctf_fs_ds_index_entry
*entry
,
495 struct ctf_fs_ds_file
*ds_file
,
496 struct ctf_msg_iter_packet_properties
*props
,
497 off_t packet_size
, off_t packet_offset
)
500 struct ctf_stream_class
*sc
;
502 sc
= ctf_trace_class_borrow_stream_class_by_id(ds_file
->metadata
->tc
,
503 props
->stream_class_id
);
505 BT_ASSERT(packet_offset
>= 0);
506 entry
->offset
= packet_offset
;
507 BT_ASSERT(packet_size
>= 0);
508 entry
->packet_size
= packet_size
;
510 if (props
->snapshots
.beginning_clock
!= UINT64_C(-1)) {
511 entry
->timestamp_begin
= props
->snapshots
.beginning_clock
;
513 /* Convert the packet's bound to nanoseconds since Epoch. */
514 ret
= convert_cycles_to_ns(sc
->default_clock_class
,
515 props
->snapshots
.beginning_clock
,
516 &entry
->timestamp_begin_ns
);
518 BT_COMP_LOGI_STR("Failed to convert raw timestamp to nanoseconds since Epoch.");
522 entry
->timestamp_begin
= UINT64_C(-1);
523 entry
->timestamp_begin_ns
= UINT64_C(-1);
526 if (props
->snapshots
.end_clock
!= UINT64_C(-1)) {
527 entry
->timestamp_end
= props
->snapshots
.end_clock
;
529 /* Convert the packet's bound to nanoseconds since Epoch. */
530 ret
= convert_cycles_to_ns(sc
->default_clock_class
,
531 props
->snapshots
.end_clock
,
532 &entry
->timestamp_end_ns
);
534 BT_COMP_LOGI_STR("Failed to convert raw timestamp to nanoseconds since Epoch.");
538 entry
->timestamp_end
= UINT64_C(-1);
539 entry
->timestamp_end_ns
= UINT64_C(-1);
547 struct ctf_fs_ds_index
*build_index_from_stream_file(
548 struct ctf_fs_ds_file
*ds_file
,
549 struct ctf_fs_ds_file_info
*file_info
)
552 struct ctf_fs_ds_index
*index
= NULL
;
553 enum ctf_msg_iter_status iter_status
= CTF_MSG_ITER_STATUS_OK
;
554 off_t current_packet_offset_bytes
= 0;
556 BT_COMP_LOGI("Indexing stream file %s", ds_file
->file
->path
->str
);
558 index
= ctf_fs_ds_index_create(ds_file
->log_level
, ds_file
->self_comp
);
564 off_t current_packet_size_bytes
;
565 struct ctf_fs_ds_index_entry
*index_entry
;
566 struct ctf_msg_iter_packet_properties props
;
568 if (current_packet_offset_bytes
< 0) {
569 BT_COMP_LOGE_STR("Cannot get the current packet's offset.");
571 } else if (current_packet_offset_bytes
> ds_file
->file
->size
) {
572 BT_COMP_LOGE_STR("Unexpected current packet's offset (larger than file).");
574 } else if (current_packet_offset_bytes
== ds_file
->file
->size
) {
579 iter_status
= ctf_msg_iter_seek(ds_file
->msg_iter
,
580 current_packet_offset_bytes
);
581 if (iter_status
!= CTF_MSG_ITER_STATUS_OK
) {
585 iter_status
= ctf_msg_iter_get_packet_properties(
586 ds_file
->msg_iter
, &props
);
587 if (iter_status
!= CTF_MSG_ITER_STATUS_OK
) {
591 if (props
.exp_packet_total_size
>= 0) {
592 current_packet_size_bytes
=
593 (uint64_t) props
.exp_packet_total_size
/ 8;
595 current_packet_size_bytes
= ds_file
->file
->size
;
598 if (current_packet_offset_bytes
+ current_packet_size_bytes
>
599 ds_file
->file
->size
) {
600 BT_COMP_LOGW("Invalid packet size reported in file: stream=\"%s\", "
601 "packet-offset=%jd, packet-size-bytes=%jd, "
603 ds_file
->file
->path
->str
,
604 (intmax_t) current_packet_offset_bytes
,
605 (intmax_t) current_packet_size_bytes
,
606 (intmax_t) ds_file
->file
->size
);
610 index_entry
= g_new0(struct ctf_fs_ds_index_entry
, 1);
612 BT_COMP_LOGE_STR("Failed to allocate a new index entry.");
616 /* Set path to stream file. */
617 index_entry
->path
= file_info
->path
->str
;
619 ret
= init_index_entry(index_entry
, ds_file
, &props
,
620 current_packet_size_bytes
, current_packet_offset_bytes
);
626 g_ptr_array_add(index
->entries
, index_entry
);
628 current_packet_offset_bytes
+= current_packet_size_bytes
;
629 BT_COMP_LOGD("Seeking to next packet: current-packet-offset=%jd, "
630 "next-packet-offset=%jd",
631 (intmax_t) (current_packet_offset_bytes
- current_packet_size_bytes
),
632 (intmax_t) current_packet_offset_bytes
);
639 ctf_fs_ds_index_destroy(index
);
645 struct ctf_fs_ds_file
*ctf_fs_ds_file_create(
646 struct ctf_fs_trace
*ctf_fs_trace
,
647 bt_self_message_iterator
*pc_msg_iter
,
648 struct ctf_msg_iter
*msg_iter
,
649 bt_stream
*stream
, const char *path
,
650 bt_logging_level log_level
)
653 const size_t offset_align
= bt_mmap_get_offset_align_size(log_level
);
654 struct ctf_fs_ds_file
*ds_file
= g_new0(struct ctf_fs_ds_file
, 1);
660 ds_file
->log_level
= log_level
;
661 ds_file
->self_comp
= ctf_fs_trace
->self_comp
;
662 ds_file
->self_msg_iter
= pc_msg_iter
;
663 ds_file
->file
= ctf_fs_file_create(log_level
, ds_file
->self_comp
);
664 if (!ds_file
->file
) {
668 ds_file
->stream
= stream
;
669 bt_stream_get_ref(ds_file
->stream
);
670 ds_file
->metadata
= ctf_fs_trace
->metadata
;
671 g_string_assign(ds_file
->file
->path
, path
);
672 ret
= ctf_fs_file_open(ds_file
->file
, "rb");
677 ds_file
->msg_iter
= msg_iter
;
678 ctf_msg_iter_set_medops_data(ds_file
->msg_iter
, ds_file
);
679 if (!ds_file
->msg_iter
) {
683 ds_file
->mmap_max_len
= offset_align
* 2048;
688 /* Do not touch "borrowed" file. */
689 ctf_fs_ds_file_destroy(ds_file
);
697 struct ctf_fs_ds_index
*ctf_fs_ds_file_build_index(
698 struct ctf_fs_ds_file
*ds_file
,
699 struct ctf_fs_ds_file_info
*file_info
)
701 struct ctf_fs_ds_index
*index
;
703 index
= build_index_from_idx_file(ds_file
, file_info
);
708 BT_COMP_LOGI("Failed to build index from .index file; "
709 "falling back to stream indexing.");
710 index
= build_index_from_stream_file(ds_file
, file_info
);
716 struct ctf_fs_ds_index
*ctf_fs_ds_index_create(bt_logging_level log_level
,
717 bt_self_component
*self_comp
)
719 struct ctf_fs_ds_index
*index
= g_new0(struct ctf_fs_ds_index
, 1);
722 BT_COMP_LOG_CUR_LVL(BT_LOG_ERROR
, log_level
, self_comp
,
723 "Failed to allocate index");
727 index
->entries
= g_ptr_array_new_with_free_func((GDestroyNotify
) g_free
);
728 if (!index
->entries
) {
729 BT_COMP_LOG_CUR_LVL(BT_LOG_ERROR
, log_level
, self_comp
,
730 "Failed to allocate index entries.");
737 ctf_fs_ds_index_destroy(index
);
744 void ctf_fs_ds_file_destroy(struct ctf_fs_ds_file
*ds_file
)
750 bt_stream_put_ref(ds_file
->stream
);
751 (void) ds_file_munmap(ds_file
);
754 ctf_fs_file_destroy(ds_file
->file
);
761 bt_component_class_message_iterator_next_method_status
ctf_fs_ds_file_next(
762 struct ctf_fs_ds_file
*ds_file
,
765 enum ctf_msg_iter_status msg_iter_status
;
766 bt_component_class_message_iterator_next_method_status status
;
768 msg_iter_status
= ctf_msg_iter_get_next_message(
769 ds_file
->msg_iter
, msg
);
771 switch (msg_iter_status
) {
772 case CTF_MSG_ITER_STATUS_EOF
:
773 status
= BT_COMPONENT_CLASS_MESSAGE_ITERATOR_NEXT_METHOD_STATUS_END
;
775 case CTF_MSG_ITER_STATUS_OK
:
776 status
= BT_COMPONENT_CLASS_MESSAGE_ITERATOR_NEXT_METHOD_STATUS_OK
;
778 case CTF_MSG_ITER_STATUS_AGAIN
:
780 * Should not make it this far as this is
781 * medium-specific; there is nothing for the user to do
782 * and it should have been handled upstream.
785 case CTF_MSG_ITER_STATUS_INVAL
:
786 case CTF_MSG_ITER_STATUS_ERROR
:
788 status
= BT_COMPONENT_CLASS_MESSAGE_ITERATOR_NEXT_METHOD_STATUS_ERROR
;
795 void ctf_fs_ds_index_destroy(struct ctf_fs_ds_index
*index
)
801 if (index
->entries
) {
802 g_ptr_array_free(index
->entries
, TRUE
);