Issue
=====
When indexing a trace using `*.idx` files, if streams span more than one
packet the user may witness the following warning message:
W PLUGIN/SRC.CTF.FS/DS build_index_from_idx_file@data-stream-file.c:400
[source-ctf-fs] Invalid, non-monotonic, packet offset encountered in
LTTng trace index file: previous offset=
14757395258967641292, current offset=4096
This is caused by the fact the we're using pointer arithmetics to get
the pointer to the previous entry of an array. This ends returning
garbage because it's a pointer array and not a regular array storing the
objects as the code expects to.
This regression was most probably introduced by the following commit:
commit
7ed5243afe12c7c12fa5305fff99b93ad23bbdff
Author: Francis Deslauriers <francis.deslauriers@efficios.com>
Date: Wed May 15 14:59:10 2019 -0400
src.ctf.fs: merge all indexes to the fs_ds_group level
This problematic commit changes the `entries` fields of the `struct
ctf_fs_ds_index` from a `GArray *` to `GPtrArray * without changing the
pointer arithmetics.
This was not an error because indexing using `*.idx` files is optional
and indexing may fail back to direct packet indexing.
Solution
========
Use a local variable to store a pointer to the previous index_entry
rather than using pointer arithmetics.
Drawbacks
=========
None.
Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Change-Id: I3e5608d0359be2a447e79415517068c64f5a2817
Reviewed-on: https://review.lttng.org/c/babeltrace/+/1637
Tested-by: jenkins <jenkins@lttng.org>
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
const char *mmap_begin = NULL, *file_pos = NULL;
const struct ctf_packet_index_file_hdr *header = NULL;
struct ctf_fs_ds_index *index = NULL;
- struct ctf_fs_ds_index_entry *index_entry = NULL;
+ struct ctf_fs_ds_index_entry *index_entry = NULL, *prev_index_entry = NULL;
uint64_t total_packets_size = 0;
size_t file_index_entry_size;
size_t file_entry_count;
index_entry->packet_size = packet_size;
index_entry->offset = be64toh(file_index->offset);
- if (i != 0 && index_entry->offset < (index_entry - 1)->offset) {
+ if (i != 0 && index_entry->offset < prev_index_entry->offset) {
BT_COMP_LOGW("Invalid, non-monotonic, packet offset encountered in LTTng trace index file: "
"previous offset=%" PRIu64 ", current offset=%" PRIu64,
(index_entry - 1)->offset, index_entry->offset);
file_pos += file_index_entry_size;
g_ptr_array_add(index->entries, index_entry);
+ prev_index_entry = index_entry;
}
/* Validate that the index addresses the complete stream. */