diff --git a/src/logging/comp-logging.h b/src/logging/comp-logging.h index 586486034..3c0aca6d2 100644 --- a/src/logging/comp-logging.h +++ b/src/logging/comp-logging.h @@ -271,4 +271,17 @@ } \ } while (0) +/* + * Logs error and appends error cause from message iterator context. + * + * There is no BT_SELF_MSG_LOGE yet, so use BT_COMP_LOGE for now. + */ +#define BT_MSG_ITER_LOGE_APPEND_CAUSE(_self_msg_iter, _fmt, ...) \ + do { \ + BT_COMP_LOG(BT_LOG_ERROR, bt_self_message_iterator_borrow_component(_self_msg_iter), \ + _fmt, ##__VA_ARGS__); \ + (void) BT_CURRENT_THREAD_ERROR_APPEND_CAUSE_FROM_MESSAGE_ITERATOR( \ + _self_msg_iter, _fmt, ##__VA_ARGS__); \ + } while (0) + #endif /* BABELTRACE_LOGGING_COMP_LOGGING_H */ diff --git a/src/plugins/ctf/common/msg-iter/msg-iter.c b/src/plugins/ctf/common/msg-iter/msg-iter.c index 9edc55c80..fb87e7d3e 100644 --- a/src/plugins/ctf/common/msg-iter/msg-iter.c +++ b/src/plugins/ctf/common/msg-iter/msg-iter.c @@ -708,7 +708,7 @@ void release_all_dscopes(struct ctf_msg_iter *msg_it) static enum ctf_msg_iter_status switch_packet_state(struct ctf_msg_iter *msg_it) { - enum ctf_msg_iter_status status = CTF_MSG_ITER_STATUS_OK; + enum ctf_msg_iter_status status; bt_self_component *self_comp = msg_it->self_comp; /* @@ -732,6 +732,30 @@ enum ctf_msg_iter_status switch_packet_state(struct ctf_msg_iter *msg_it) release_all_dscopes(msg_it); msg_it->cur_dscope_field = NULL; + if (msg_it->medium.medops.switch_packet) { + enum ctf_msg_iter_medium_status medium_status; + + medium_status = msg_it->medium.medops.switch_packet(msg_it->medium.data); + if (medium_status == CTF_MSG_ITER_MEDIUM_STATUS_EOF) { + /* No more packets. */ + msg_it->state = STATE_CHECK_EMIT_MSG_STREAM_END; + status = CTF_MSG_ITER_STATUS_OK; + goto end; + } else if (medium_status != CTF_MSG_ITER_MEDIUM_STATUS_OK) { + status = (int) medium_status; + goto end; + } + + /* + * After the packet switch, the medium might want to give us a + * different buffer for the new packet. + */ + status = request_medium_bytes(msg_it); + if (status != CTF_MSG_ITER_STATUS_OK) { + goto end; + } + } + /* * Adjust current buffer so that addr points to the beginning of the new * packet. @@ -768,6 +792,7 @@ enum ctf_msg_iter_status switch_packet_state(struct ctf_msg_iter *msg_it) msg_it->snapshots.end_clock = UINT64_C(-1); msg_it->state = STATE_DSCOPE_TRACE_PACKET_HEADER_BEGIN; + status = CTF_MSG_ITER_STATUS_OK; end: return status; } @@ -3149,14 +3174,6 @@ enum ctf_msg_iter_status read_packet_header_context_fields( return status; } -BT_HIDDEN -void ctf_msg_iter_set_medops_data(struct ctf_msg_iter *msg_it, - void *medops_data) -{ - BT_ASSERT(msg_it); - msg_it->medium.data = medops_data; -} - BT_HIDDEN enum ctf_msg_iter_status ctf_msg_iter_seek(struct ctf_msg_iter *msg_it, off_t offset) diff --git a/src/plugins/ctf/common/msg-iter/msg-iter.h b/src/plugins/ctf/common/msg-iter/msg-iter.h index 5176a93b8..0ca95e9d9 100644 --- a/src/plugins/ctf/common/msg-iter/msg-iter.h +++ b/src/plugins/ctf/common/msg-iter/msg-iter.h @@ -45,7 +45,8 @@ */ /** - * Medium operations status codes. + * Medium operations status codes. These use the same values as + * libbabeltrace2. */ enum ctf_msg_iter_medium_status { /** @@ -64,6 +65,9 @@ enum ctf_msg_iter_medium_status { /** General error. */ CTF_MSG_ITER_MEDIUM_STATUS_ERROR = -1, + /** Memory error. */ + CTF_MSG_ITER_MEDIUM_STATUS_MEMORY_ERROR = -12, + /** Everything okay. */ CTF_MSG_ITER_MEDIUM_STATUS_OK = 0, }; @@ -94,6 +98,9 @@ enum ctf_msg_iter_status { /** General error. */ CTF_MSG_ITER_STATUS_ERROR = CTF_MSG_ITER_MEDIUM_STATUS_ERROR, + /** Memory error. */ + CTF_MSG_ITER_STATUS_MEMORY_ERROR = CTF_MSG_ITER_MEDIUM_STATUS_MEMORY_ERROR, + /** Everything okay. */ CTF_MSG_ITER_STATUS_OK = CTF_MSG_ITER_MEDIUM_STATUS_OK, }; @@ -186,6 +193,15 @@ struct ctf_msg_iter_medium_ops { */ enum ctf_msg_iter_medium_status (* seek)(off_t offset, void *data); + /** + * Called when the message iterator wishes to inform the medium that it + * is about to start a new packet. + * + * After the iterator has called switch_packet, the following call to + * request_bytes must return the content at the start of the next + * packet. */ + enum ctf_msg_iter_medium_status (* switch_packet)(void *data); + /** * Returns a stream instance (weak reference) for the given * stream class. @@ -293,10 +309,6 @@ BT_HIDDEN enum ctf_msg_iter_status ctf_msg_iter_curr_packet_last_event_clock_snapshot( struct ctf_msg_iter *msg_it, uint64_t *last_event_cs); -BT_HIDDEN -void ctf_msg_iter_set_medops_data(struct ctf_msg_iter *msg_it, - void *medops_data); - BT_HIDDEN enum ctf_msg_iter_status ctf_msg_iter_seek( struct ctf_msg_iter *msg_it, off_t offset); diff --git a/src/plugins/ctf/fs-src/data-stream-file.c b/src/plugins/ctf/fs-src/data-stream-file.c index 7fe4e6a52..fe14f8cc3 100644 --- a/src/plugins/ctf/fs-src/data-stream-file.c +++ b/src/plugins/ctf/fs-src/data-stream-file.c @@ -99,7 +99,9 @@ enum ctf_msg_iter_medium_status ds_file_munmap( * mapping. If the currently mmap-ed region already contains * `requested_offset_in_file`, the mapping is kept. * - * Set `ds_file->requested_offset_in_mapping` based on `request_offset_in_file` + * Set `ds_file->requested_offset_in_mapping` based on `request_offset_in_file`, + * such that the next call to `request_bytes` will return bytes starting at that + * position. * * `requested_offset_in_file` must be a valid offset in the file. */ @@ -301,6 +303,217 @@ struct ctf_msg_iter_medium_ops ctf_fs_ds_file_medops = { .seek = medop_seek, }; +struct ctf_fs_ds_group_medops_data { + /* Weak, set once at creation time. */ + struct ctf_fs_ds_file_group *ds_file_group; + + /* + * Index (as in element rank) of the index entry of ds_file_groups' + * index we will read next (so, the one after the one we are reading + * right now). + */ + guint next_index_entry_index; + + /* + * File we are currently reading. Changes whenever we switch to + * reading another data file. + * + * Owned by this. + */ + struct ctf_fs_ds_file *file; + + /* Weak, for context / logging / appending causes. */ + bt_self_message_iterator *self_msg_iter; + bt_logging_level log_level; +}; + +static +enum ctf_msg_iter_medium_status medop_group_request_bytes( + size_t request_sz, + uint8_t **buffer_addr, + size_t *buffer_sz, + void *void_data) +{ + struct ctf_fs_ds_group_medops_data *data = void_data; + + /* Return bytes from the current file. */ + return medop_request_bytes(request_sz, buffer_addr, buffer_sz, data->file); +} + +static +bt_stream *medop_group_borrow_stream( + bt_stream_class *stream_class, + int64_t stream_id, + void *void_data) +{ + struct ctf_fs_ds_group_medops_data *data = void_data; + + return medop_borrow_stream(stream_class, stream_id, data->file); +} + +/* + * Set `data->file` to prepare it to read the packet described + * by `index_entry`. + */ + +static +enum ctf_msg_iter_medium_status ctf_fs_ds_group_medops_set_file( + struct ctf_fs_ds_group_medops_data *data, + struct ctf_fs_ds_index_entry *index_entry, + bt_self_message_iterator *self_msg_iter, + bt_logging_level log_level) +{ + enum ctf_msg_iter_medium_status status; + + BT_ASSERT(data); + BT_ASSERT(index_entry); + + /* Check if that file is already the one mapped. */ + if (!data->file || strcmp(index_entry->path, data->file->file->path->str) != 0) { + /* Destroy the previously used file. */ + ctf_fs_ds_file_destroy(data->file); + + /* Create the new file. */ + data->file = ctf_fs_ds_file_create( + data->ds_file_group->ctf_fs_trace, + self_msg_iter, + data->ds_file_group->stream, + index_entry->path, + log_level); + if (!data->file) { + BT_MSG_ITER_LOGE_APPEND_CAUSE(self_msg_iter, + "failed to create ctf_fs_ds_file."); + status = CTF_MSG_ITER_MEDIUM_STATUS_ERROR; + goto end; + } + } + + /* + * Ensure the right portion of the file will be returned on the next + * request_bytes call. + */ + status = ds_file_mmap(data->file, index_entry->offset); + if (status != CTF_MSG_ITER_MEDIUM_STATUS_OK) { + goto end; + } + + status = CTF_MSG_ITER_MEDIUM_STATUS_OK; + +end: + return status; +} + +static +enum ctf_msg_iter_medium_status medop_group_switch_packet(void *void_data) +{ + struct ctf_fs_ds_group_medops_data *data = void_data; + struct ctf_fs_ds_index_entry *index_entry; + enum ctf_msg_iter_medium_status status; + + /* If we have gone through all index entries, we are done. */ + if (data->next_index_entry_index >= + data->ds_file_group->index->entries->len) { + status = CTF_MSG_ITER_MEDIUM_STATUS_EOF; + goto end; + } + + /* + * Otherwise, look up the next index entry / packet and prepare it + * for reading. + */ + index_entry = g_ptr_array_index( + data->ds_file_group->index->entries, + data->next_index_entry_index); + + status = ctf_fs_ds_group_medops_set_file( + data, index_entry, data->self_msg_iter, data->log_level); + if (status != CTF_MSG_ITER_MEDIUM_STATUS_OK) { + goto end; + } + + data->next_index_entry_index++; + + status = CTF_MSG_ITER_MEDIUM_STATUS_OK; +end: + return status; +} + +BT_HIDDEN +void ctf_fs_ds_group_medops_data_destroy( + struct ctf_fs_ds_group_medops_data *data) +{ + if (!data) { + goto end; + } + + ctf_fs_ds_file_destroy(data->file); + + g_free(data); + +end: + return; +} + +enum ctf_msg_iter_medium_status ctf_fs_ds_group_medops_data_create( + struct ctf_fs_ds_file_group *ds_file_group, + bt_self_message_iterator *self_msg_iter, + bt_logging_level log_level, + struct ctf_fs_ds_group_medops_data **out) +{ + struct ctf_fs_ds_group_medops_data *data; + enum ctf_msg_iter_medium_status status; + + BT_ASSERT(self_msg_iter); + BT_ASSERT(ds_file_group); + BT_ASSERT(ds_file_group->index); + BT_ASSERT(ds_file_group->index->entries->len > 0); + + data = g_new0(struct ctf_fs_ds_group_medops_data, 1); + if (!data) { + BT_MSG_ITER_LOGE_APPEND_CAUSE(self_msg_iter, + "Failed to allocate a struct ctf_fs_ds_group_medops_data"); + status = CTF_MSG_ITER_MEDIUM_STATUS_MEMORY_ERROR; + goto error; + } + + data->ds_file_group = ds_file_group; + data->self_msg_iter = self_msg_iter; + data->log_level = log_level; + + /* + * No need to prepare the first file. ctf_msg_iter will call + * switch_packet before reading the first packet, it will be + * done then. + */ + + *out = data; + status = CTF_MSG_ITER_MEDIUM_STATUS_OK; + goto end; + +error: + ctf_fs_ds_group_medops_data_destroy(data); + +end: + return status; +} + +void ctf_fs_ds_group_medops_data_reset(struct ctf_fs_ds_group_medops_data *data) +{ + data->next_index_entry_index = 0; +} + +struct ctf_msg_iter_medium_ops ctf_fs_ds_group_medops = { + .request_bytes = medop_group_request_bytes, + .borrow_stream = medop_group_borrow_stream, + .switch_packet = medop_group_switch_packet, + + /* + * We don't support seeking using this medops. It would probably be + * possible, but it's not needed at the moment. + */ + .seek = NULL, +}; + static struct ctf_fs_ds_index_entry *ctf_fs_ds_index_entry_create( bt_self_component *self_comp, bt_logging_level log_level) diff --git a/src/plugins/ctf/fs-src/data-stream-file.h b/src/plugins/ctf/fs-src/data-stream-file.h index e42890b43..654e64f66 100644 --- a/src/plugins/ctf/fs-src/data-stream-file.h +++ b/src/plugins/ctf/fs-src/data-stream-file.h @@ -36,6 +36,8 @@ struct ctf_fs_component; struct ctf_fs_file; struct ctf_fs_trace; struct ctf_fs_ds_file; +struct ctf_fs_ds_file_group; +struct ctf_fs_ds_group_medops_data; struct ctf_fs_ds_file_info { /* Owned by this. */ @@ -109,6 +111,35 @@ struct ctf_fs_ds_index *ctf_fs_ds_index_create(bt_logging_level log_level, BT_HIDDEN void ctf_fs_ds_index_destroy(struct ctf_fs_ds_index *index); +/* + * Medium operations to iterate on a single ctf_fs_ds_file. + * + * The data pointer when using this must be a pointer to the ctf_fs_ds_file. + */ extern struct ctf_msg_iter_medium_ops ctf_fs_ds_file_medops; +/* + * Medium operations to iterate on the packet of a ctf_fs_ds_group. + * + * The iteration is done based on the index of the group. + * + * The data pointer when using these medops must be a pointer to a ctf_fs_ds + * group_medops_data structure. + */ +extern struct ctf_msg_iter_medium_ops ctf_fs_ds_group_medops; + +BT_HIDDEN +enum ctf_msg_iter_medium_status ctf_fs_ds_group_medops_data_create( + struct ctf_fs_ds_file_group *ds_file_group, + bt_self_message_iterator *self_msg_iter, + bt_logging_level log_level, + struct ctf_fs_ds_group_medops_data **out); + +BT_HIDDEN +void ctf_fs_ds_group_medops_data_reset(struct ctf_fs_ds_group_medops_data *data); + +BT_HIDDEN +void ctf_fs_ds_group_medops_data_destroy( + struct ctf_fs_ds_group_medops_data *data); + #endif /* CTF_FS_DS_FILE_H */ diff --git a/src/plugins/ctf/fs-src/fs.c b/src/plugins/ctf/fs-src/fs.c index 0f28a09a8..451e41166 100644 --- a/src/plugins/ctf/fs-src/fs.c +++ b/src/plugins/ctf/fs-src/fs.c @@ -54,39 +54,6 @@ struct tracer_info { int64_t patch; }; -static -int msg_iter_data_set_current_ds_file(struct ctf_fs_msg_iter_data *msg_iter_data) -{ - struct ctf_fs_ds_file_info *ds_file_info; - int ret = 0; - - BT_ASSERT(msg_iter_data->ds_file_info_index < - msg_iter_data->ds_file_group->ds_file_infos->len); - ds_file_info = g_ptr_array_index( - msg_iter_data->ds_file_group->ds_file_infos, - msg_iter_data->ds_file_info_index); - - /* Destroy the previous ds file. */ - ctf_fs_ds_file_destroy(msg_iter_data->ds_file); - - /* Create the new ds file. */ - msg_iter_data->ds_file = ctf_fs_ds_file_create( - msg_iter_data->ds_file_group->ctf_fs_trace, - msg_iter_data->self_msg_iter, - msg_iter_data->ds_file_group->stream, - ds_file_info->path->str, - msg_iter_data->log_level); - if (!msg_iter_data->ds_file) { - ret = -1; - } - - /* Tell the ctf message iterator to iterate on the new ds file. */ - ctf_msg_iter_set_medops_data(msg_iter_data->msg_iter, - msg_iter_data->ds_file); - - return ret; -} - static void ctf_fs_msg_iter_data_destroy( struct ctf_fs_msg_iter_data *msg_iter_data) @@ -95,26 +62,16 @@ void ctf_fs_msg_iter_data_destroy( return; } - ctf_fs_ds_file_destroy(msg_iter_data->ds_file); - if (msg_iter_data->msg_iter) { ctf_msg_iter_destroy(msg_iter_data->msg_iter); } - g_free(msg_iter_data); -} + if (msg_iter_data->msg_iter_medops_data) { + ctf_fs_ds_group_medops_data_destroy( + msg_iter_data->msg_iter_medops_data); + } -static -void set_msg_iter_emits_stream_beginning_end_messages( - struct ctf_fs_msg_iter_data *msg_iter_data) -{ - ctf_msg_iter_set_emit_stream_beginning_message( - msg_iter_data->msg_iter, - msg_iter_data->ds_file_info_index == 0); - ctf_msg_iter_set_emit_stream_end_message( - msg_iter_data->msg_iter, - msg_iter_data->ds_file_info_index == - msg_iter_data->ds_file_group->ds_file_infos->len - 1); + g_free(msg_iter_data); } static @@ -123,64 +80,46 @@ bt_component_class_message_iterator_next_method_status ctf_fs_iterator_next_one( const bt_message **out_msg) { bt_component_class_message_iterator_next_method_status status; + enum ctf_msg_iter_status msg_iter_status; + bt_logging_level log_level = msg_iter_data->log_level; - BT_ASSERT_DBG(msg_iter_data->ds_file); - - while (true) { - enum ctf_msg_iter_status msg_iter_status; - int ret; - - msg_iter_status = ctf_msg_iter_get_next_message( - msg_iter_data->msg_iter, out_msg); - - switch (msg_iter_status) { - case CTF_MSG_ITER_STATUS_OK: - /* Cool, message has been written to *out_msg. */ - status = BT_COMPONENT_CLASS_MESSAGE_ITERATOR_NEXT_METHOD_STATUS_OK; - goto end; + msg_iter_status = ctf_msg_iter_get_next_message( + msg_iter_data->msg_iter, out_msg); - case CTF_MSG_ITER_STATUS_EOF: - if (msg_iter_data->ds_file_info_index == - msg_iter_data->ds_file_group->ds_file_infos->len - 1) { - /* End of all group's stream files */ - status = BT_COMPONENT_CLASS_MESSAGE_ITERATOR_NEXT_METHOD_STATUS_END; - goto end; - } + switch (msg_iter_status) { + case CTF_MSG_ITER_STATUS_OK: + /* Cool, message has been written to *out_msg. */ + status = BT_COMPONENT_CLASS_MESSAGE_ITERATOR_NEXT_METHOD_STATUS_OK; + break; - msg_iter_data->ds_file_info_index++; - ctf_msg_iter_reset_for_next_stream_file( - msg_iter_data->msg_iter); - set_msg_iter_emits_stream_beginning_end_messages( - msg_iter_data); + case CTF_MSG_ITER_STATUS_EOF: + status = BT_COMPONENT_CLASS_MESSAGE_ITERATOR_NEXT_METHOD_STATUS_END; + break; - /* - * Open and start reading the next stream file - * within our stream file group. - */ - ret = msg_iter_data_set_current_ds_file(msg_iter_data); - if (ret) { - status = BT_COMPONENT_CLASS_MESSAGE_ITERATOR_NEXT_METHOD_STATUS_ERROR; - goto end; - } + case CTF_MSG_ITER_STATUS_AGAIN: + /* + * Should not make it this far as this is + * medium-specific; there is nothing for the user to do + * and it should have been handled upstream. + */ + bt_common_abort(); - /* Continue the loop to get the next message. */ - break; + case CTF_MSG_ITER_MEDIUM_STATUS_ERROR: + BT_MSG_ITER_LOGE_APPEND_CAUSE(msg_iter_data->self_msg_iter, + "Failed to get next message from CTF message iterator."); + status = BT_COMPONENT_CLASS_MESSAGE_ITERATOR_NEXT_METHOD_STATUS_ERROR; + break; - case CTF_MSG_ITER_STATUS_AGAIN: - /* - * Should not make it this far as this is - * medium-specific; there is nothing for the user to do - * and it should have been handled upstream. - */ - bt_common_abort(); + case CTF_MSG_ITER_MEDIUM_STATUS_MEMORY_ERROR: + BT_MSG_ITER_LOGE_APPEND_CAUSE(msg_iter_data->self_msg_iter, + "Failed to get next message from CTF message iterator."); + status = BT_COMPONENT_CLASS_MESSAGE_ITERATOR_NEXT_METHOD_STATUS_MEMORY_ERROR; + break; - default: - status = BT_COMPONENT_CLASS_MESSAGE_ITERATOR_NEXT_METHOD_STATUS_ERROR; - goto end; - } + default: + bt_common_abort(); } -end: return status; } @@ -246,39 +185,19 @@ bt_component_class_message_iterator_next_method_status ctf_fs_iterator_next( return status; } -static -int ctf_fs_iterator_reset(struct ctf_fs_msg_iter_data *msg_iter_data) -{ - int ret; - - msg_iter_data->ds_file_info_index = 0; - ret = msg_iter_data_set_current_ds_file(msg_iter_data); - if (ret) { - goto end; - } - - ctf_msg_iter_reset(msg_iter_data->msg_iter); - set_msg_iter_emits_stream_beginning_end_messages(msg_iter_data); - -end: - return ret; -} - BT_HIDDEN bt_component_class_message_iterator_seek_beginning_method_status ctf_fs_iterator_seek_beginning(bt_self_message_iterator *it) { struct ctf_fs_msg_iter_data *msg_iter_data = bt_self_message_iterator_get_data(it); - bt_component_class_message_iterator_seek_beginning_method_status status = - BT_COMPONENT_CLASS_MESSAGE_ITERATOR_SEEK_BEGINNING_METHOD_STATUS_OK; BT_ASSERT(msg_iter_data); - if (ctf_fs_iterator_reset(msg_iter_data)) { - status = BT_COMPONENT_CLASS_MESSAGE_ITERATOR_SEEK_BEGINNING_METHOD_STATUS_ERROR; - } - return status; + ctf_msg_iter_reset(msg_iter_data->msg_iter); + ctf_fs_ds_group_medops_data_reset(msg_iter_data->msg_iter_medops_data); + + return BT_COMPONENT_CLASS_MESSAGE_ITERATOR_SEEK_BEGINNING_METHOD_STATUS_OK; } BT_HIDDEN @@ -297,11 +216,11 @@ bt_component_class_message_iterator_initialize_method_status ctf_fs_iterator_ini { struct ctf_fs_port_data *port_data; struct ctf_fs_msg_iter_data *msg_iter_data = NULL; - bt_component_class_message_iterator_initialize_method_status ret = - BT_COMPONENT_CLASS_MESSAGE_ITERATOR_INITIALIZE_METHOD_STATUS_OK; + bt_component_class_message_iterator_initialize_method_status status; bt_logging_level log_level; bt_self_component *self_comp = bt_self_component_source_as_self_component(self_comp_src); + enum ctf_msg_iter_medium_status medium_status; port_data = bt_self_component_port_get_data( bt_self_component_port_output_as_self_component_port( @@ -310,29 +229,47 @@ bt_component_class_message_iterator_initialize_method_status ctf_fs_iterator_ini log_level = port_data->ctf_fs->log_level; msg_iter_data = g_new0(struct ctf_fs_msg_iter_data, 1); if (!msg_iter_data) { - ret = BT_COMPONENT_CLASS_MESSAGE_ITERATOR_INITIALIZE_METHOD_STATUS_MEMORY_ERROR; + status = BT_COMPONENT_CLASS_MESSAGE_ITERATOR_INITIALIZE_METHOD_STATUS_MEMORY_ERROR; goto error; } msg_iter_data->log_level = log_level; msg_iter_data->self_comp = self_comp; msg_iter_data->self_msg_iter = self_msg_iter; + msg_iter_data->ds_file_group = port_data->ds_file_group; + + medium_status = ctf_fs_ds_group_medops_data_create( + msg_iter_data->ds_file_group, self_msg_iter, log_level, + &msg_iter_data->msg_iter_medops_data); + BT_ASSERT( + medium_status == CTF_MSG_ITER_MEDIUM_STATUS_OK || + medium_status == CTF_MSG_ITER_MEDIUM_STATUS_ERROR || + medium_status == CTF_MSG_ITER_MEDIUM_STATUS_MEMORY_ERROR); + if (medium_status != CTF_MSG_ITER_MEDIUM_STATUS_OK) { + BT_MSG_ITER_LOGE_APPEND_CAUSE(self_msg_iter, + "Failed to create ctf_fs_ds_group_medops"); + status = (int) medium_status; + goto error; + } + msg_iter_data->msg_iter = ctf_msg_iter_create( - port_data->ds_file_group->ctf_fs_trace->metadata->tc, + msg_iter_data->ds_file_group->ctf_fs_trace->metadata->tc, bt_common_get_page_size(msg_iter_data->log_level) * 8, - ctf_fs_ds_file_medops, NULL, msg_iter_data->log_level, + ctf_fs_ds_group_medops, + msg_iter_data->msg_iter_medops_data, + msg_iter_data->log_level, self_comp, self_msg_iter); if (!msg_iter_data->msg_iter) { BT_COMP_LOGE_APPEND_CAUSE(self_comp, "Cannot create a CTF message iterator."); - ret = BT_COMPONENT_CLASS_MESSAGE_ITERATOR_INITIALIZE_METHOD_STATUS_MEMORY_ERROR; + status = BT_COMPONENT_CLASS_MESSAGE_ITERATOR_INITIALIZE_METHOD_STATUS_MEMORY_ERROR; goto error; } - msg_iter_data->ds_file_group = port_data->ds_file_group; - if (ctf_fs_iterator_reset(msg_iter_data)) { - ret = BT_COMPONENT_CLASS_MESSAGE_ITERATOR_INITIALIZE_METHOD_STATUS_ERROR; - goto error; - } + /* FIXME: This is temporary, those functions will be removed. */ + ctf_msg_iter_set_emit_stream_end_message( + msg_iter_data->msg_iter, true); + ctf_msg_iter_set_emit_stream_beginning_message( + msg_iter_data->msg_iter, true); /* * This iterator can seek forward if its stream class has a default @@ -345,10 +282,9 @@ bt_component_class_message_iterator_initialize_method_status ctf_fs_iterator_ini bt_self_message_iterator_set_data(self_msg_iter, msg_iter_data); - if (ret != BT_COMPONENT_CLASS_MESSAGE_ITERATOR_INITIALIZE_METHOD_STATUS_OK) { - goto error; - } msg_iter_data = NULL; + + status = BT_COMPONENT_CLASS_MESSAGE_ITERATOR_INITIALIZE_METHOD_STATUS_OK; goto end; error: @@ -356,7 +292,7 @@ bt_component_class_message_iterator_initialize_method_status ctf_fs_iterator_ini end: ctf_fs_msg_iter_data_destroy(msg_iter_data); - return ret; + return status; } static diff --git a/src/plugins/ctf/fs-src/fs.h b/src/plugins/ctf/fs-src/fs.h index 78faded2a..446e84e55 100644 --- a/src/plugins/ctf/fs-src/fs.h +++ b/src/plugins/ctf/fs-src/fs.h @@ -191,12 +191,6 @@ struct ctf_fs_msg_iter_data { /* Weak, belongs to ctf_fs_trace */ struct ctf_fs_ds_file_group *ds_file_group; - /* Owned by this */ - struct ctf_fs_ds_file *ds_file; - - /* Which file the iterator is _currently_ operating on */ - size_t ds_file_info_index; - /* Owned by this */ struct ctf_msg_iter *msg_iter; @@ -207,6 +201,8 @@ struct ctf_fs_msg_iter_data { */ bt_component_class_message_iterator_next_method_status next_saved_status; const struct bt_error *next_saved_error; + + struct ctf_fs_ds_group_medops_data *msg_iter_medops_data; }; BT_HIDDEN