src.ctf.lttng-live: use BT_COMP_LOG*() instead of BT_LOG*()
[babeltrace.git] / src / plugins / ctf / fs-src / fs.c
CommitLineData
7a278c8e 1/*
ea0b4b9e 2 * fs.c
7a278c8e 3 *
ea0b4b9e 4 * Babeltrace CTF file system Reader Component
7a278c8e 5 *
1a9f7075 6 * Copyright 2015-2017 Philippe Proulx <pproulx@efficios.com>
f3bc2010 7 * Copyright 2016 Jérémie Galarneau <jeremie.galarneau@efficios.com>
7a278c8e 8 *
7a278c8e
JG
9 * Permission is hereby granted, free of charge, to any person obtaining a copy
10 * of this software and associated documentation files (the "Software"), to deal
11 * in the Software without restriction, including without limitation the rights
12 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 * copies of the Software, and to permit persons to whom the Software is
14 * furnished to do so, subject to the following conditions:
15 *
16 * The above copyright notice and this permission notice shall be included in
17 * all copies or substantial portions of the Software.
18 *
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 * SOFTWARE.
26 */
27
578e048b 28#include "common/common.h"
3fadfbc0 29#include <babeltrace2/babeltrace.h>
578e048b 30#include "compat/uuid.h"
ea0b4b9e 31#include <glib.h>
578e048b 32#include "common/assert.h"
94cf822e 33#include <inttypes.h>
c55a9f58 34#include <stdbool.h>
56a1cced 35#include "fs.h"
413bc2c4 36#include "metadata.h"
94cf822e 37#include "data-stream-file.h"
e7a4393b 38#include "file.h"
1e649dff 39#include "../common/metadata/decoder.h"
d6e69534 40#include "../common/msg-iter/msg-iter.h"
04c0ba87 41#include "query.h"
e7a4393b 42
350ad6c1 43#define BT_LOG_TAG "PLUGIN/SRC.CTF.FS"
55314f2a 44#include "logging.h"
ea0b4b9e 45
94cf822e 46static
d6e69534 47int msg_iter_data_set_current_ds_file(struct ctf_fs_msg_iter_data *msg_iter_data)
94cf822e
PP
48{
49 struct ctf_fs_ds_file_info *ds_file_info;
50 int ret = 0;
51
d6e69534
PP
52 BT_ASSERT(msg_iter_data->ds_file_info_index <
53 msg_iter_data->ds_file_group->ds_file_infos->len);
94cf822e 54 ds_file_info = g_ptr_array_index(
d6e69534
PP
55 msg_iter_data->ds_file_group->ds_file_infos,
56 msg_iter_data->ds_file_info_index);
57
58 ctf_fs_ds_file_destroy(msg_iter_data->ds_file);
59 msg_iter_data->ds_file = ctf_fs_ds_file_create(
60 msg_iter_data->ds_file_group->ctf_fs_trace,
61 msg_iter_data->pc_msg_iter,
62 msg_iter_data->msg_iter,
63 msg_iter_data->ds_file_group->stream,
97ade20b 64 ds_file_info->path->str);
d6e69534 65 if (!msg_iter_data->ds_file) {
94cf822e
PP
66 ret = -1;
67 }
68
69 return ret;
70}
71
72static
d6e69534
PP
73void ctf_fs_msg_iter_data_destroy(
74 struct ctf_fs_msg_iter_data *msg_iter_data)
94cf822e 75{
d6e69534 76 if (!msg_iter_data) {
94cf822e
PP
77 return;
78 }
79
d6e69534 80 ctf_fs_ds_file_destroy(msg_iter_data->ds_file);
6de92955 81
d6e69534
PP
82 if (msg_iter_data->msg_iter) {
83 bt_msg_iter_destroy(msg_iter_data->msg_iter);
6de92955
PP
84 }
85
d6e69534 86 g_free(msg_iter_data);
94cf822e
PP
87}
88
fc917f65
PP
89static
90void set_msg_iter_emits_stream_beginning_end_messages(
91 struct ctf_fs_msg_iter_data *msg_iter_data)
92{
93 bt_msg_iter_set_emit_stream_beginning_message(
94 msg_iter_data->ds_file->msg_iter,
95 msg_iter_data->ds_file_info_index == 0);
96 bt_msg_iter_set_emit_stream_end_message(
97 msg_iter_data->ds_file->msg_iter,
98 msg_iter_data->ds_file_info_index ==
99 msg_iter_data->ds_file_group->ds_file_infos->len - 1);
100}
101
d4393e08 102static
4cdfc5e8 103bt_self_message_iterator_status ctf_fs_iterator_next_one(
d6e69534 104 struct ctf_fs_msg_iter_data *msg_iter_data,
fc917f65 105 const bt_message **out_msg)
ea0b4b9e 106{
4cdfc5e8 107 bt_self_message_iterator_status status;
94cf822e 108
d6e69534 109 BT_ASSERT(msg_iter_data->ds_file);
f42867e2 110
fc917f65
PP
111 while (true) {
112 bt_message *msg;
113
114 status = ctf_fs_ds_file_next(msg_iter_data->ds_file, &msg);
115 switch (status) {
116 case BT_SELF_MESSAGE_ITERATOR_STATUS_OK:
117 *out_msg = msg;
118 msg = NULL;
f42867e2 119 goto end;
fc917f65
PP
120 case BT_SELF_MESSAGE_ITERATOR_STATUS_END:
121 {
122 int ret;
f42867e2 123
fc917f65
PP
124 if (msg_iter_data->ds_file_info_index ==
125 msg_iter_data->ds_file_group->ds_file_infos->len - 1) {
126 /* End of all group's stream files */
127 goto end;
128 }
129
130 msg_iter_data->ds_file_info_index++;
495490c5
PP
131 bt_msg_iter_reset_for_next_stream_file(
132 msg_iter_data->msg_iter);
fc917f65
PP
133 set_msg_iter_emits_stream_beginning_end_messages(
134 msg_iter_data);
94cf822e 135
94cf822e 136 /*
fc917f65
PP
137 * Open and start reading the next stream file
138 * within our stream file group.
94cf822e 139 */
fc917f65
PP
140 ret = msg_iter_data_set_current_ds_file(msg_iter_data);
141 if (ret) {
142 status = BT_SELF_MESSAGE_ITERATOR_STATUS_ERROR;
143 goto end;
144 }
145
146 /* Continue the loop to get the next message */
147 break;
94cf822e 148 }
fc917f65 149 default:
94cf822e
PP
150 goto end;
151 }
94cf822e 152 }
d01e0f33 153
94cf822e 154end:
d4393e08
PP
155 return status;
156}
157
158BT_HIDDEN
4cdfc5e8 159bt_self_message_iterator_status ctf_fs_iterator_next(
d6e69534
PP
160 bt_self_message_iterator *iterator,
161 bt_message_array_const msgs, uint64_t capacity,
d4393e08
PP
162 uint64_t *count)
163{
4cdfc5e8 164 bt_self_message_iterator_status status =
d6e69534
PP
165 BT_SELF_MESSAGE_ITERATOR_STATUS_OK;
166 struct ctf_fs_msg_iter_data *msg_iter_data =
167 bt_self_message_iterator_get_data(iterator);
d4393e08
PP
168 uint64_t i = 0;
169
d6e69534
PP
170 while (i < capacity && status == BT_SELF_MESSAGE_ITERATOR_STATUS_OK) {
171 status = ctf_fs_iterator_next_one(msg_iter_data, &msgs[i]);
172 if (status == BT_SELF_MESSAGE_ITERATOR_STATUS_OK) {
d4393e08
PP
173 i++;
174 }
175 }
176
177 if (i > 0) {
178 /*
179 * Even if ctf_fs_iterator_next_one() returned something
d6e69534
PP
180 * else than BT_SELF_MESSAGE_ITERATOR_STATUS_OK, we
181 * accumulated message objects in the output
182 * message array, so we need to return
183 * BT_SELF_MESSAGE_ITERATOR_STATUS_OK so that they are
d4393e08 184 * transfered to downstream. This other status occurs
d6e69534 185 * again the next time muxer_msg_iter_do_next() is
d4393e08 186 * called, possibly without any accumulated
d6e69534 187 * message, in which case we'll return it.
d4393e08
PP
188 */
189 *count = i;
d6e69534 190 status = BT_SELF_MESSAGE_ITERATOR_STATUS_OK;
d4393e08
PP
191 }
192
193 return status;
ea0b4b9e 194}
bfd20a42 195
6a9bb5e9
PP
196static
197int ctf_fs_iterator_reset(struct ctf_fs_msg_iter_data *msg_iter_data)
198{
199 int ret;
200
201 msg_iter_data->ds_file_info_index = 0;
202 ret = msg_iter_data_set_current_ds_file(msg_iter_data);
203 if (ret) {
204 goto end;
205 }
206
207 bt_msg_iter_reset(msg_iter_data->msg_iter);
208 set_msg_iter_emits_stream_beginning_end_messages(msg_iter_data);
209
210end:
211 return ret;
212}
213
214BT_HIDDEN
215bt_self_message_iterator_status ctf_fs_iterator_seek_beginning(
216 bt_self_message_iterator *it)
217{
218 struct ctf_fs_msg_iter_data *msg_iter_data =
219 bt_self_message_iterator_get_data(it);
220 bt_self_message_iterator_status status =
221 BT_SELF_MESSAGE_ITERATOR_STATUS_OK;
222
223 BT_ASSERT(msg_iter_data);
224 if (ctf_fs_iterator_reset(msg_iter_data)) {
225 status = BT_SELF_MESSAGE_ITERATOR_STATUS_ERROR;
226 }
227
228 return status;
229}
230
231BT_HIDDEN
d6e69534 232void ctf_fs_iterator_finalize(bt_self_message_iterator *it)
760051fa 233{
d6e69534
PP
234 ctf_fs_msg_iter_data_destroy(
235 bt_self_message_iterator_get_data(it));
760051fa
JG
236}
237
6a9bb5e9 238BT_HIDDEN
4cdfc5e8 239bt_self_message_iterator_status ctf_fs_iterator_init(
d6e69534 240 bt_self_message_iterator *self_msg_iter,
b19ff26f
PP
241 bt_self_component_source *self_comp,
242 bt_self_component_port_output *self_port)
4c1456f0 243{
4f1f88a6 244 struct ctf_fs_port_data *port_data;
d6e69534 245 struct ctf_fs_msg_iter_data *msg_iter_data = NULL;
4cdfc5e8 246 bt_self_message_iterator_status ret =
d6e69534 247 BT_SELF_MESSAGE_ITERATOR_STATUS_OK;
760051fa 248
d94d92ac 249 port_data = bt_self_component_port_get_data(
707b7d35 250 bt_self_component_port_output_as_self_component_port(
d94d92ac
PP
251 self_port));
252 BT_ASSERT(port_data);
d6e69534
PP
253 msg_iter_data = g_new0(struct ctf_fs_msg_iter_data, 1);
254 if (!msg_iter_data) {
255 ret = BT_SELF_MESSAGE_ITERATOR_STATUS_NOMEM;
94cf822e
PP
256 goto error;
257 }
258
d6e69534
PP
259 msg_iter_data->pc_msg_iter = self_msg_iter;
260 msg_iter_data->msg_iter = bt_msg_iter_create(
44c440bc 261 port_data->ds_file_group->ctf_fs_trace->metadata->tc,
86d8b7b8 262 bt_common_get_page_size(BT_LOG_OUTPUT_LEVEL) * 8,
eb7f6c4f 263 ctf_fs_ds_file_medops, NULL, BT_LOG_OUTPUT_LEVEL, NULL);
d6e69534
PP
264 if (!msg_iter_data->msg_iter) {
265 BT_LOGE_STR("Cannot create a CTF message iterator.");
266 ret = BT_SELF_MESSAGE_ITERATOR_STATUS_NOMEM;
6de92955
PP
267 goto error;
268 }
269
d6e69534 270 msg_iter_data->ds_file_group = port_data->ds_file_group;
6a9bb5e9 271 if (ctf_fs_iterator_reset(msg_iter_data)) {
d6e69534 272 ret = BT_SELF_MESSAGE_ITERATOR_STATUS_ERROR;
4f1f88a6 273 goto error;
760051fa
JG
274 }
275
d6e69534
PP
276 bt_self_message_iterator_set_data(self_msg_iter,
277 msg_iter_data);
278 if (ret != BT_SELF_MESSAGE_ITERATOR_STATUS_OK) {
4f1f88a6 279 goto error;
760051fa
JG
280 }
281
d6e69534 282 msg_iter_data = NULL;
4f1f88a6 283 goto end;
5b29e799 284
4f1f88a6 285error:
d6e69534 286 bt_self_message_iterator_set_data(self_msg_iter, NULL);
4f1f88a6 287
760051fa 288end:
d6e69534 289 ctf_fs_msg_iter_data_destroy(msg_iter_data);
760051fa
JG
290 return ret;
291}
292
f280892e 293BT_HIDDEN
1a9f7075 294void ctf_fs_destroy(struct ctf_fs_component *ctf_fs)
760051fa 295{
4f1f88a6 296 if (!ctf_fs) {
8fa760ba
JG
297 return;
298 }
4f1f88a6 299
1a9f7075
PP
300 if (ctf_fs->traces) {
301 g_ptr_array_free(ctf_fs->traces, TRUE);
56a1cced 302 }
4f1f88a6
PP
303
304 if (ctf_fs->port_data) {
305 g_ptr_array_free(ctf_fs->port_data, TRUE);
c14d7e26 306 }
760051fa 307
1a9f7075
PP
308 g_free(ctf_fs);
309}
310
f280892e
SM
311static
312void port_data_destroy(struct ctf_fs_port_data *port_data)
313{
314 if (!port_data) {
315 return;
316 }
317
318 g_free(port_data);
319}
320
321static
322void port_data_destroy_notifier(void *data) {
323 port_data_destroy(data);
324}
325
326static
97ade20b 327void ctf_fs_trace_destroy(struct ctf_fs_trace *ctf_fs_trace)
1a9f7075 328{
1a9f7075
PP
329 if (!ctf_fs_trace) {
330 return;
331 }
332
94cf822e
PP
333 if (ctf_fs_trace->ds_file_groups) {
334 g_ptr_array_free(ctf_fs_trace->ds_file_groups, TRUE);
335 }
336
c5b9b441 337 BT_TRACE_PUT_REF_AND_RESET(ctf_fs_trace->trace);
862ca4ed 338
1a9f7075
PP
339 if (ctf_fs_trace->path) {
340 g_string_free(ctf_fs_trace->path, TRUE);
4f1f88a6 341 }
760051fa 342
1a9f7075
PP
343 if (ctf_fs_trace->name) {
344 g_string_free(ctf_fs_trace->name, TRUE);
345 }
346
347 if (ctf_fs_trace->metadata) {
348 ctf_fs_metadata_fini(ctf_fs_trace->metadata);
349 g_free(ctf_fs_trace->metadata);
350 }
351
1a9f7075 352 g_free(ctf_fs_trace);
4c1456f0
JG
353}
354
97ade20b 355static
56a924f4 356void ctf_fs_trace_destroy_notifier(void *data)
97ade20b
JG
357{
358 struct ctf_fs_trace *trace = data;
359 ctf_fs_trace_destroy(trace);
360}
361
f280892e 362struct ctf_fs_component *ctf_fs_component_create(void)
a4792757 363{
f280892e 364 struct ctf_fs_component *ctf_fs;
a4792757 365
f280892e
SM
366 ctf_fs = g_new0(struct ctf_fs_component, 1);
367 if (!ctf_fs) {
368 goto error;
369 }
4f1f88a6 370
f280892e
SM
371 ctf_fs->port_data =
372 g_ptr_array_new_with_free_func(port_data_destroy_notifier);
373 if (!ctf_fs->port_data) {
374 goto error;
4f1f88a6
PP
375 }
376
f280892e
SM
377 ctf_fs->traces =
378 g_ptr_array_new_with_free_func(ctf_fs_trace_destroy_notifier);
379 if (!ctf_fs->traces) {
380 goto error;
381 }
382
383 goto end;
384
385error:
386 if (ctf_fs) {
387 ctf_fs_destroy(ctf_fs);
388 }
389
390end:
391 return ctf_fs;
392}
393
394void ctf_fs_finalize(bt_self_component_source *component)
395{
396 ctf_fs_destroy(bt_self_component_get_data(
397 bt_self_component_source_as_self_component(component)));
5b29e799
JG
398}
399
a38d7650 400gchar *ctf_fs_make_port_name(struct ctf_fs_ds_file_group *ds_file_group)
547eacf1 401{
a38d7650 402 GString *name = g_string_new(NULL);
547eacf1 403
a38d7650
SM
404 /*
405 * The unique port name is generated by concatenating unique identifiers
406 * for:
407 *
408 * - the trace
409 * - the stream class
410 * - the stream
411 */
412
413 /* For the trace, use the uuid if present, else the path. */
414 if (ds_file_group->ctf_fs_trace->metadata->tc->is_uuid_set) {
415 char uuid_str[BABELTRACE_UUID_STR_LEN];
416
417 bt_uuid_unparse(ds_file_group->ctf_fs_trace->metadata->tc->uuid, uuid_str);
418 g_string_assign(name, uuid_str);
419 } else {
420 g_string_assign(name, ds_file_group->ctf_fs_trace->path->str);
547eacf1
PP
421 }
422
423 /*
a38d7650
SM
424 * For the stream class, use the id if present. We can omit this field
425 * otherwise, as there will only be a single stream class.
547eacf1 426 */
a38d7650
SM
427 if (ds_file_group->sc->id != UINT64_C(-1)) {
428 g_string_append_printf(name, " | %" PRIu64, ds_file_group->sc->id);
429 }
547eacf1 430
a38d7650
SM
431 /* For the stream, use the id if present, else, use the path. */
432 if (ds_file_group->stream_id != UINT64_C(-1)) {
433 g_string_append_printf(name, " | %" PRIu64, ds_file_group->stream_id);
434 } else {
435 BT_ASSERT(ds_file_group->ds_file_infos->len == 1);
436 struct ctf_fs_ds_file_info *ds_file_info =
437 g_ptr_array_index(ds_file_group->ds_file_infos, 0);
438 g_string_append_printf(name, " | %s", ds_file_info->path->str);
439 }
440
441 return g_string_free(name, FALSE);
547eacf1
PP
442}
443
5b29e799 444static
55314f2a
JG
445int create_one_port_for_trace(struct ctf_fs_component *ctf_fs,
446 struct ctf_fs_trace *ctf_fs_trace,
94cf822e 447 struct ctf_fs_ds_file_group *ds_file_group)
5b29e799 448{
4f1f88a6 449 int ret = 0;
4f1f88a6 450 struct ctf_fs_port_data *port_data = NULL;
a38d7650 451 gchar *port_name;
4f1f88a6 452
a38d7650 453 port_name = ctf_fs_make_port_name(ds_file_group);
4f1f88a6
PP
454 if (!port_name) {
455 goto error;
456 }
457
3f7d4d90 458 BT_LOGI("Creating one port named `%s`", port_name);
4f1f88a6
PP
459
460 /* Create output port for this file */
4f1f88a6
PP
461 port_data = g_new0(struct ctf_fs_port_data, 1);
462 if (!port_data) {
463 goto error;
464 }
465
5c563278 466 port_data->ctf_fs = ctf_fs;
94cf822e 467 port_data->ds_file_group = ds_file_group;
d94d92ac 468 ret = bt_self_component_source_add_output_port(
a38d7650 469 ctf_fs->self_comp, port_name, port_data, NULL);
147337a3 470 if (ret) {
4f1f88a6
PP
471 goto error;
472 }
473
474 g_ptr_array_add(ctf_fs->port_data, port_data);
475 port_data = NULL;
476 goto end;
477
478error:
479 ret = -1;
480
481end:
482 if (port_name) {
a38d7650 483 g_free(port_name);
4f1f88a6
PP
484 }
485
4f1f88a6
PP
486 port_data_destroy(port_data);
487 return ret;
5b29e799
JG
488}
489
490static
55314f2a
JG
491int create_ports_for_trace(struct ctf_fs_component *ctf_fs,
492 struct ctf_fs_trace *ctf_fs_trace)
94cf822e
PP
493{
494 int ret = 0;
94cf822e
PP
495 size_t i;
496
497 /* Create one output port for each stream file group */
498 for (i = 0; i < ctf_fs_trace->ds_file_groups->len; i++) {
499 struct ctf_fs_ds_file_group *ds_file_group =
500 g_ptr_array_index(ctf_fs_trace->ds_file_groups, i);
501
55314f2a
JG
502 ret = create_one_port_for_trace(ctf_fs, ctf_fs_trace,
503 ds_file_group);
94cf822e 504 if (ret) {
55314f2a 505 BT_LOGE("Cannot create output port.");
94cf822e
PP
506 goto end;
507 }
508 }
509
510end:
511 return ret;
512}
513
94cf822e
PP
514static
515void ctf_fs_ds_file_info_destroy(struct ctf_fs_ds_file_info *ds_file_info)
516{
517 if (!ds_file_info) {
518 return;
519 }
520
521 if (ds_file_info->path) {
522 g_string_free(ds_file_info->path, TRUE);
523 }
524
525 g_free(ds_file_info);
526}
527
528static
529struct ctf_fs_ds_file_info *ctf_fs_ds_file_info_create(const char *path,
7ed5243a 530 int64_t begin_ns)
94cf822e
PP
531{
532 struct ctf_fs_ds_file_info *ds_file_info;
533
534 ds_file_info = g_new0(struct ctf_fs_ds_file_info, 1);
535 if (!ds_file_info) {
536 goto end;
537 }
538
539 ds_file_info->path = g_string_new(path);
540 if (!ds_file_info->path) {
541 ctf_fs_ds_file_info_destroy(ds_file_info);
542 ds_file_info = NULL;
543 goto end;
544 }
545
546 ds_file_info->begin_ns = begin_ns;
547
548end:
549 return ds_file_info;
550}
551
552static
553void ctf_fs_ds_file_group_destroy(struct ctf_fs_ds_file_group *ds_file_group)
554{
555 if (!ds_file_group) {
556 return;
557 }
558
559 if (ds_file_group->ds_file_infos) {
560 g_ptr_array_free(ds_file_group->ds_file_infos, TRUE);
561 }
562
7ed5243a
FD
563 if (ds_file_group->index) {
564 if (ds_file_group->index->entries) {
565 g_ptr_array_free(ds_file_group->index->entries, TRUE);
566 }
567 g_free(ds_file_group->index);
568 }
569
c5b9b441 570 bt_stream_put_ref(ds_file_group->stream);
94cf822e
PP
571 g_free(ds_file_group);
572}
573
574static
575struct ctf_fs_ds_file_group *ctf_fs_ds_file_group_create(
576 struct ctf_fs_trace *ctf_fs_trace,
60363f2f 577 struct ctf_stream_class *sc,
7ed5243a
FD
578 uint64_t stream_instance_id,
579 struct ctf_fs_ds_index *index)
94cf822e
PP
580{
581 struct ctf_fs_ds_file_group *ds_file_group;
582
94cf822e
PP
583 ds_file_group = g_new0(struct ctf_fs_ds_file_group, 1);
584 if (!ds_file_group) {
585 goto error;
586 }
587
588 ds_file_group->ds_file_infos = g_ptr_array_new_with_free_func(
589 (GDestroyNotify) ctf_fs_ds_file_info_destroy);
590 if (!ds_file_group->ds_file_infos) {
591 goto error;
592 }
593
7ed5243a
FD
594 ds_file_group->index = index;
595
547eacf1 596 ds_file_group->stream_id = stream_instance_id;
60363f2f
PP
597 BT_ASSERT(sc);
598 ds_file_group->sc = sc;
94cf822e 599 ds_file_group->ctf_fs_trace = ctf_fs_trace;
94cf822e
PP
600 goto end;
601
602error:
603 ctf_fs_ds_file_group_destroy(ds_file_group);
7ed5243a 604 ctf_fs_ds_index_destroy(index);
94cf822e
PP
605 ds_file_group = NULL;
606
607end:
608 return ds_file_group;
609}
610
8bf7105e
MJ
611/* Replace by g_ptr_array_insert when we depend on glib >= 2.40. */
612static
613void array_insert(GPtrArray *array, gpointer element, size_t pos)
614{
615 size_t original_array_len = array->len;
616
617 /* Allocate an unused element at the end of the array. */
618 g_ptr_array_add(array, NULL);
619
620 /* If we are not inserting at the end, move the elements by one. */
621 if (pos < original_array_len) {
622 memmove(&(array->pdata[pos + 1]),
623 &(array->pdata[pos]),
624 (original_array_len - pos) * sizeof(gpointer));
625 }
626
f897d50c 627 /* Insert the value. */
8bf7105e
MJ
628 array->pdata[pos] = element;
629}
630
41a65f30
SM
631/*
632 * Insert ds_file_info in ds_file_group's list of ds_file_infos at the right
633 * place to keep it sorted.
634 */
635
636static
637void ds_file_group_insert_ds_file_info_sorted(
638 struct ctf_fs_ds_file_group *ds_file_group,
639 struct ctf_fs_ds_file_info *ds_file_info)
640{
641 guint i;
642
643 /* Find the spot where to insert this ds_file_info. */
644 for (i = 0; i < ds_file_group->ds_file_infos->len; i++) {
645 struct ctf_fs_ds_file_info *other_ds_file_info =
646 g_ptr_array_index(ds_file_group->ds_file_infos, i);
647
648 if (ds_file_info->begin_ns < other_ds_file_info->begin_ns) {
649 break;
650 }
651 }
652
653 array_insert(ds_file_group->ds_file_infos, ds_file_info, i);
654}
655
7ed5243a
FD
656static
657void ds_file_group_insert_ds_index_entry_sorted(
658 struct ctf_fs_ds_file_group *ds_file_group,
659 struct ctf_fs_ds_index_entry *entry)
660{
661 guint i;
662
663 /* Find the spot where to insert this index entry. */
664 for (i = 0; i < ds_file_group->index->entries->len; i++) {
665 struct ctf_fs_ds_index_entry *other_entry = g_ptr_array_index(
666 ds_file_group->index->entries, i);
667
668 if (entry->timestamp_begin_ns < other_entry->timestamp_begin_ns) {
669 break;
670 }
671 }
672
673 array_insert(ds_file_group->index->entries, entry, i);
674}
675
41a65f30
SM
676/*
677 * Create a new ds_file_info using the provided path, begin_ns and index, then
678 * add it to ds_file_group's list of ds_file_infos.
679 */
680
94cf822e
PP
681static
682int ctf_fs_ds_file_group_add_ds_file_info(
683 struct ctf_fs_ds_file_group *ds_file_group,
7ed5243a 684 const char *path, int64_t begin_ns)
94cf822e
PP
685{
686 struct ctf_fs_ds_file_info *ds_file_info;
94cf822e
PP
687 int ret = 0;
688
7ed5243a 689 ds_file_info = ctf_fs_ds_file_info_create(path, begin_ns);
94cf822e
PP
690 if (!ds_file_info) {
691 goto error;
692 }
693
41a65f30 694 ds_file_group_insert_ds_file_info_sorted(ds_file_group, ds_file_info);
94cf822e 695
94cf822e
PP
696 ds_file_info = NULL;
697 goto end;
698
699error:
700 ctf_fs_ds_file_info_destroy(ds_file_info);
701 ret = -1;
94cf822e
PP
702end:
703 return ret;
704}
705
706static
707int add_ds_file_to_ds_file_group(struct ctf_fs_trace *ctf_fs_trace,
e5be10ef 708 const char *path)
94cf822e 709{
44c440bc
PP
710 int64_t stream_instance_id = -1;
711 int64_t begin_ns = -1;
94cf822e
PP
712 struct ctf_fs_ds_file_group *ds_file_group = NULL;
713 bool add_group = false;
714 int ret;
715 size_t i;
6de92955 716 struct ctf_fs_ds_file *ds_file = NULL;
97ade20b 717 struct ctf_fs_ds_index *index = NULL;
d6e69534 718 struct bt_msg_iter *msg_iter = NULL;
44c440bc 719 struct ctf_stream_class *sc = NULL;
d6e69534 720 struct bt_msg_iter_packet_properties props;
94cf822e 721
d6e69534 722 msg_iter = bt_msg_iter_create(ctf_fs_trace->metadata->tc,
86d8b7b8 723 bt_common_get_page_size(BT_LOG_OUTPUT_LEVEL) * 8,
eb7f6c4f 724 ctf_fs_ds_file_medops, NULL, BT_LOG_OUTPUT_LEVEL, NULL);
d6e69534
PP
725 if (!msg_iter) {
726 BT_LOGE_STR("Cannot create a CTF message iterator.");
6de92955
PP
727 goto error;
728 }
729
d6e69534 730 ds_file = ctf_fs_ds_file_create(ctf_fs_trace, NULL, msg_iter,
5c563278 731 NULL, path);
97ade20b
JG
732 if (!ds_file) {
733 goto error;
734 }
735
41693723 736 ret = bt_msg_iter_get_packet_properties(ds_file->msg_iter, &props);
94cf822e 737 if (ret) {
55314f2a 738 BT_LOGE("Cannot get stream file's first packet's header and context fields (`%s`).",
94cf822e
PP
739 path);
740 goto error;
741 }
742
44c440bc
PP
743 sc = ctf_trace_class_borrow_stream_class_by_id(ds_file->metadata->tc,
744 props.stream_class_id);
745 BT_ASSERT(sc);
44c440bc
PP
746 stream_instance_id = props.data_stream_id;
747
748 if (props.snapshots.beginning_clock != UINT64_C(-1)) {
749 BT_ASSERT(sc->default_clock_class);
0f2d58c9
PP
750 ret = bt_util_clock_cycles_to_ns_from_origin(
751 props.snapshots.beginning_clock,
752 sc->default_clock_class->frequency,
753 sc->default_clock_class->offset_seconds,
754 sc->default_clock_class->offset_cycles, &begin_ns);
44c440bc
PP
755 if (ret) {
756 BT_LOGE("Cannot convert clock cycles to nanoseconds from origin (`%s`).",
757 path);
758 goto error;
759 }
94cf822e
PP
760 }
761
97ade20b
JG
762 index = ctf_fs_ds_file_build_index(ds_file);
763 if (!index) {
764 BT_LOGW("Failed to index CTF stream file \'%s\'",
765 ds_file->file->path->str);
766 }
767
44c440bc 768 if (begin_ns == -1) {
94cf822e
PP
769 /*
770 * No beggining timestamp to sort the stream files
771 * within a stream file group, so consider that this
772 * file must be the only one within its group.
773 */
44c440bc 774 stream_instance_id = -1;
94cf822e
PP
775 }
776
44c440bc 777 if (stream_instance_id == -1) {
94cf822e
PP
778 /*
779 * No stream instance ID or no beginning timestamp:
780 * create a unique stream file group for this stream
781 * file because, even if there's a stream instance ID,
782 * there's no timestamp to order the file within its
783 * group.
784 */
94cf822e 785 ds_file_group = ctf_fs_ds_file_group_create(ctf_fs_trace,
7ed5243a
FD
786 sc, UINT64_C(-1), index);
787 /* Ownership of index is transferred. */
788 index = NULL;
789
94cf822e
PP
790 if (!ds_file_group) {
791 goto error;
792 }
793
794 ret = ctf_fs_ds_file_group_add_ds_file_info(ds_file_group,
7ed5243a 795 path, begin_ns);
94cf822e
PP
796 if (ret) {
797 goto error;
798 }
799
800 add_group = true;
801 goto end;
802 }
803
44c440bc
PP
804 BT_ASSERT(stream_instance_id != -1);
805 BT_ASSERT(begin_ns != -1);
94cf822e
PP
806
807 /* Find an existing stream file group with this ID */
808 for (i = 0; i < ctf_fs_trace->ds_file_groups->len; i++) {
94cf822e
PP
809 ds_file_group = g_ptr_array_index(
810 ctf_fs_trace->ds_file_groups, i);
94cf822e 811
60363f2f 812 if (ds_file_group->sc == sc &&
547eacf1
PP
813 ds_file_group->stream_id ==
814 stream_instance_id) {
94cf822e
PP
815 break;
816 }
817
818 ds_file_group = NULL;
819 }
820
821 if (!ds_file_group) {
822 ds_file_group = ctf_fs_ds_file_group_create(ctf_fs_trace,
7ed5243a
FD
823 sc, stream_instance_id, index);
824 /* Ownership of index is transferred. */
825 index = NULL;
94cf822e
PP
826 if (!ds_file_group) {
827 goto error;
828 }
829
830 add_group = true;
831 }
832
547eacf1 833 ret = ctf_fs_ds_file_group_add_ds_file_info(ds_file_group, path,
7ed5243a 834 begin_ns);
94cf822e
PP
835 if (ret) {
836 goto error;
837 }
838
839 goto end;
840
841error:
842 ctf_fs_ds_file_group_destroy(ds_file_group);
90e1eb09 843 ds_file_group = NULL;
94cf822e
PP
844 ret = -1;
845
846end:
847 if (add_group && ds_file_group) {
848 g_ptr_array_add(ctf_fs_trace->ds_file_groups, ds_file_group);
849 }
547eacf1 850
97ade20b 851 ctf_fs_ds_file_destroy(ds_file);
6de92955 852
d6e69534
PP
853 if (msg_iter) {
854 bt_msg_iter_destroy(msg_iter);
6de92955
PP
855 }
856
97ade20b 857 ctf_fs_ds_index_destroy(index);
94cf822e
PP
858 return ret;
859}
860
861static
e5be10ef 862int create_ds_file_groups(struct ctf_fs_trace *ctf_fs_trace)
e7a4393b
JG
863{
864 int ret = 0;
4f1f88a6 865 const char *basename;
e7a4393b 866 GError *error = NULL;
4f1f88a6 867 GDir *dir = NULL;
e7a4393b 868
94cf822e 869 /* Check each file in the path directory, except specific ones */
1a9f7075 870 dir = g_dir_open(ctf_fs_trace->path->str, 0, &error);
e7a4393b 871 if (!dir) {
55314f2a 872 BT_LOGE("Cannot open directory `%s`: %s (code %d)",
1a9f7075 873 ctf_fs_trace->path->str, error->message,
4f1f88a6 874 error->code);
e7a4393b
JG
875 goto error;
876 }
877
4f1f88a6 878 while ((basename = g_dir_read_name(dir))) {
94cf822e
PP
879 struct ctf_fs_file *file;
880
4f1f88a6 881 if (!strcmp(basename, CTF_FS_METADATA_FILENAME)) {
e7a4393b 882 /* Ignore the metadata stream. */
3f7d4d90 883 BT_LOGI("Ignoring metadata file `%s" G_DIR_SEPARATOR_S "%s`",
1a9f7075 884 ctf_fs_trace->path->str, basename);
e7a4393b
JG
885 continue;
886 }
887
4f1f88a6 888 if (basename[0] == '.') {
3f7d4d90 889 BT_LOGI("Ignoring hidden file `%s" G_DIR_SEPARATOR_S "%s`",
1a9f7075 890 ctf_fs_trace->path->str, basename);
e7a4393b
JG
891 continue;
892 }
893
894 /* Create the file. */
55314f2a 895 file = ctf_fs_file_create();
e7a4393b 896 if (!file) {
3743a302 897 BT_LOGE("Cannot create stream file object for file `%s" G_DIR_SEPARATOR_S "%s`",
1a9f7075 898 ctf_fs_trace->path->str, basename);
e7a4393b
JG
899 goto error;
900 }
901
902 /* Create full path string. */
3743a302 903 g_string_append_printf(file->path, "%s" G_DIR_SEPARATOR_S "%s",
1a9f7075 904 ctf_fs_trace->path->str, basename);
e7a4393b 905 if (!g_file_test(file->path->str, G_FILE_TEST_IS_REGULAR)) {
3f7d4d90 906 BT_LOGI("Ignoring non-regular file `%s`",
1a9f7075 907 file->path->str);
e7a4393b 908 ctf_fs_file_destroy(file);
4f1f88a6 909 file = NULL;
e7a4393b
JG
910 continue;
911 }
912
55314f2a 913 ret = ctf_fs_file_open(file, "rb");
4f1f88a6 914 if (ret) {
55314f2a 915 BT_LOGE("Cannot open stream file `%s`", file->path->str);
e7a4393b
JG
916 goto error;
917 }
918
9fa0891a
JG
919 if (file->size == 0) {
920 /* Skip empty stream. */
3f7d4d90 921 BT_LOGI("Ignoring empty file `%s`", file->path->str);
9fa0891a
JG
922 ctf_fs_file_destroy(file);
923 continue;
924 }
925
e5be10ef 926 ret = add_ds_file_to_ds_file_group(ctf_fs_trace,
94cf822e 927 file->path->str);
4f1f88a6 928 if (ret) {
89b08333 929 BT_LOGE("Cannot add stream file `%s` to stream file group",
1a9f7075 930 file->path->str);
94cf822e 931 ctf_fs_file_destroy(file);
e7a4393b
JG
932 goto error;
933 }
934
4f1f88a6 935 ctf_fs_file_destroy(file);
e7a4393b
JG
936 }
937
938 goto end;
4f1f88a6 939
e7a4393b
JG
940error:
941 ret = -1;
4f1f88a6 942
e7a4393b
JG
943end:
944 if (dir) {
945 g_dir_close(dir);
946 dir = NULL;
947 }
4f1f88a6 948
e7a4393b
JG
949 if (error) {
950 g_error_free(error);
951 }
5b29e799 952
91457551 953 return ret;
5b29e799
JG
954}
955
862ca4ed 956static
b19ff26f 957int set_trace_name(bt_trace *trace, const char *name_suffix)
862ca4ed
PP
958{
959 int ret = 0;
b19ff26f
PP
960 const bt_trace_class *tc = bt_trace_borrow_class_const(trace);
961 const bt_value *val;
862ca4ed
PP
962 GString *name;
963
964 name = g_string_new(NULL);
965 if (!name) {
966 BT_LOGE_STR("Failed to allocate a GString.");
967 ret = -1;
968 goto end;
969 }
970
971 /*
972 * Check if we have a trace environment string value named `hostname`.
973 * If so, use it as the trace name's prefix.
974 */
975 val = bt_trace_class_borrow_environment_entry_value_by_name_const(
976 tc, "hostname");
977 if (val && bt_value_is_string(val)) {
978 g_string_append(name, bt_value_string_get(val));
979
980 if (name_suffix) {
981 g_string_append_c(name, G_DIR_SEPARATOR);
982 }
983 }
984
985 if (name_suffix) {
986 g_string_append(name, name_suffix);
987 }
988
989 ret = bt_trace_set_name(trace, name->str);
990 if (ret) {
991 goto end;
992 }
993
994 goto end;
995
996end:
997 if (name) {
998 g_string_free(name, TRUE);
999 }
1000
1001 return ret;
1002}
1003
f280892e 1004static
41693723
PP
1005struct ctf_fs_trace *ctf_fs_trace_create(bt_self_component_source *self_comp,
1006 const char *path, const char *name,
e5be10ef 1007 struct ctf_fs_metadata_config *metadata_config)
1a9f7075
PP
1008{
1009 struct ctf_fs_trace *ctf_fs_trace;
1010 int ret;
1011
1012 ctf_fs_trace = g_new0(struct ctf_fs_trace, 1);
1013 if (!ctf_fs_trace) {
1014 goto end;
1015 }
1016
1a9f7075
PP
1017 ctf_fs_trace->path = g_string_new(path);
1018 if (!ctf_fs_trace->path) {
1019 goto error;
1020 }
1021
1022 ctf_fs_trace->name = g_string_new(name);
1023 if (!ctf_fs_trace->name) {
1024 goto error;
1025 }
1026
1027 ctf_fs_trace->metadata = g_new0(struct ctf_fs_metadata, 1);
1028 if (!ctf_fs_trace->metadata) {
1029 goto error;
1030 }
1031
44c440bc 1032 ctf_fs_metadata_init(ctf_fs_trace->metadata);
94cf822e
PP
1033 ctf_fs_trace->ds_file_groups = g_ptr_array_new_with_free_func(
1034 (GDestroyNotify) ctf_fs_ds_file_group_destroy);
1035 if (!ctf_fs_trace->ds_file_groups) {
1036 goto error;
1037 }
1038
41693723
PP
1039 ret = ctf_fs_metadata_set_trace_class(self_comp,
1040 ctf_fs_trace, metadata_config);
862ca4ed
PP
1041 if (ret) {
1042 goto error;
1043 }
1044
41693723
PP
1045 if (ctf_fs_trace->metadata->trace_class) {
1046 ctf_fs_trace->trace =
1047 bt_trace_create(ctf_fs_trace->metadata->trace_class);
1048 if (!ctf_fs_trace->trace) {
1049 goto error;
1050 }
862ca4ed
PP
1051 }
1052
41693723
PP
1053 if (ctf_fs_trace->trace) {
1054 ret = set_trace_name(ctf_fs_trace->trace, name);
1055 if (ret) {
1056 goto error;
1057 }
1a9f7075
PP
1058 }
1059
e5be10ef 1060 ret = create_ds_file_groups(ctf_fs_trace);
94cf822e
PP
1061 if (ret) {
1062 goto error;
1063 }
1064
1a9f7075
PP
1065 goto end;
1066
1067error:
1068 ctf_fs_trace_destroy(ctf_fs_trace);
1069 ctf_fs_trace = NULL;
44c440bc 1070
1a9f7075
PP
1071end:
1072 return ctf_fs_trace;
1073}
1074
1075static
1076int path_is_ctf_trace(const char *path)
1077{
1078 GString *metadata_path = g_string_new(NULL);
1079 int ret = 0;
1080
1081 if (!metadata_path) {
1082 ret = -1;
1083 goto end;
1084 }
1085
3743a302 1086 g_string_printf(metadata_path, "%s" G_DIR_SEPARATOR_S "%s", path, CTF_FS_METADATA_FILENAME);
1a9f7075
PP
1087
1088 if (g_file_test(metadata_path->str, G_FILE_TEST_IS_REGULAR)) {
1089 ret = 1;
1090 goto end;
1091 }
1092
1093end:
1094 g_string_free(metadata_path, TRUE);
1095 return ret;
1096}
1097
1098static
55314f2a 1099int add_trace_path(GList **trace_paths, const char *path)
1a9f7075 1100{
4bd72b60 1101 GString *norm_path = NULL;
1a9f7075 1102 int ret = 0;
1a9f7075 1103
4bd72b60
PP
1104 norm_path = bt_common_normalize_path(path, NULL);
1105 if (!norm_path) {
55314f2a 1106 BT_LOGE("Failed to normalize path `%s`.", path);
1a9f7075
PP
1107 ret = -1;
1108 goto end;
1109 }
1110
3743a302 1111 // FIXME: Remove or ifdef for __MINGW32__
4bd72b60 1112 if (strcmp(norm_path->str, "/") == 0) {
55314f2a 1113 BT_LOGE("Opening a trace in `/` is not supported.");
1a9f7075
PP
1114 ret = -1;
1115 goto end;
1116 }
1117
4bd72b60 1118 *trace_paths = g_list_prepend(*trace_paths, norm_path);
f6ccaed9 1119 BT_ASSERT(*trace_paths);
4bd72b60 1120 norm_path = NULL;
1a9f7075
PP
1121
1122end:
4bd72b60
PP
1123 if (norm_path) {
1124 g_string_free(norm_path, TRUE);
1125 }
1126
1a9f7075
PP
1127 return ret;
1128}
1129
f280892e 1130static
55314f2a 1131int ctf_fs_find_traces(GList **trace_paths, const char *start_path)
1a9f7075
PP
1132{
1133 int ret;
1134 GError *error = NULL;
1135 GDir *dir = NULL;
1136 const char *basename = NULL;
1137
1138 /* Check if the starting path is a CTF trace itself */
1139 ret = path_is_ctf_trace(start_path);
1140 if (ret < 0) {
1141 goto end;
1142 }
1143
1144 if (ret) {
1145 /*
4bd72b60
PP
1146 * Stop recursion: a CTF trace cannot contain another
1147 * CTF trace.
1a9f7075 1148 */
55314f2a 1149 ret = add_trace_path(trace_paths, start_path);
1a9f7075
PP
1150 goto end;
1151 }
1152
1153 /* Look for subdirectories */
1154 if (!g_file_test(start_path, G_FILE_TEST_IS_DIR)) {
1155 /* Starting path is not a directory: end of recursion */
1156 goto end;
1157 }
1158
1159 dir = g_dir_open(start_path, 0, &error);
1160 if (!dir) {
1161 if (error->code == G_FILE_ERROR_ACCES) {
3f7d4d90 1162 BT_LOGI("Cannot open directory `%s`: %s (code %d): continuing",
1a9f7075
PP
1163 start_path, error->message, error->code);
1164 goto end;
1165 }
1166
55314f2a 1167 BT_LOGE("Cannot open directory `%s`: %s (code %d)",
1a9f7075
PP
1168 start_path, error->message, error->code);
1169 ret = -1;
1170 goto end;
1171 }
1172
1173 while ((basename = g_dir_read_name(dir))) {
1174 GString *sub_path = g_string_new(NULL);
1175
1176 if (!sub_path) {
1177 ret = -1;
1178 goto end;
1179 }
1180
3743a302 1181 g_string_printf(sub_path, "%s" G_DIR_SEPARATOR_S "%s", start_path, basename);
55314f2a 1182 ret = ctf_fs_find_traces(trace_paths, sub_path->str);
1a9f7075
PP
1183 g_string_free(sub_path, TRUE);
1184 if (ret) {
1185 goto end;
1186 }
1187 }
1188
1189end:
1190 if (dir) {
1191 g_dir_close(dir);
1192 }
1193
1194 if (error) {
1195 g_error_free(error);
1196 }
1197
1198 return ret;
1199}
1200
f280892e 1201static
55314f2a 1202GList *ctf_fs_create_trace_names(GList *trace_paths, const char *base_path) {
1a9f7075 1203 GList *trace_names = NULL;
1a9f7075 1204 GList *node;
4bd72b60
PP
1205 const char *last_sep;
1206 size_t base_dist;
1a9f7075
PP
1207
1208 /*
4bd72b60
PP
1209 * At this point we know that all the trace paths are
1210 * normalized, and so is the base path. This means that
1211 * they are absolute and they don't end with a separator.
1212 * We can simply find the location of the last separator
1213 * in the base path, which gives us the name of the actual
1214 * directory to look into, and use this location as the
1215 * start of each trace name within each trace path.
1216 *
1217 * For example:
1218 *
1219 * Base path: /home/user/my-traces/some-trace
1220 * Trace paths:
1221 * - /home/user/my-traces/some-trace/host1/trace1
1222 * - /home/user/my-traces/some-trace/host1/trace2
1223 * - /home/user/my-traces/some-trace/host2/trace
1224 * - /home/user/my-traces/some-trace/other-trace
1225 *
1226 * In this case the trace names are:
1227 *
1228 * - some-trace/host1/trace1
1229 * - some-trace/host1/trace2
1230 * - some-trace/host2/trace
1231 * - some-trace/other-trace
1a9f7075 1232 */
4bd72b60 1233 last_sep = strrchr(base_path, G_DIR_SEPARATOR);
1a9f7075 1234
4bd72b60 1235 /* We know there's at least one separator */
f6ccaed9 1236 BT_ASSERT(last_sep);
1a9f7075 1237
4bd72b60
PP
1238 /* Distance to base */
1239 base_dist = last_sep - base_path + 1;
1a9f7075
PP
1240
1241 /* Create the trace names */
1242 for (node = trace_paths; node; node = g_list_next(node)) {
1243 GString *trace_name = g_string_new(NULL);
1244 GString *trace_path = node->data;
1245
f6ccaed9 1246 BT_ASSERT(trace_name);
4bd72b60 1247 g_string_assign(trace_name, &trace_path->str[base_dist]);
1a9f7075
PP
1248 trace_names = g_list_append(trace_names, trace_name);
1249 }
1250
1251 return trace_names;
1252}
1253
f280892e
SM
1254/* Helper for ctf_fs_component_create_ctf_fs_traces, to handle a single path/root. */
1255
1a9f7075 1256static
f280892e 1257int ctf_fs_component_create_ctf_fs_traces_one_root(bt_self_component_source *self_comp,
41693723 1258 struct ctf_fs_component *ctf_fs,
1a9f7075
PP
1259 const char *path_param)
1260{
1261 struct ctf_fs_trace *ctf_fs_trace = NULL;
1262 int ret = 0;
4bd72b60 1263 GString *norm_path = NULL;
1a9f7075
PP
1264 GList *trace_paths = NULL;
1265 GList *trace_names = NULL;
1266 GList *tp_node;
1267 GList *tn_node;
1268
4bd72b60
PP
1269 norm_path = bt_common_normalize_path(path_param, NULL);
1270 if (!norm_path) {
55314f2a 1271 BT_LOGE("Failed to normalize path: `%s`.",
4bd72b60
PP
1272 path_param);
1273 goto error;
1274 }
1275
55314f2a 1276 ret = ctf_fs_find_traces(&trace_paths, norm_path->str);
1a9f7075
PP
1277 if (ret) {
1278 goto error;
1279 }
1280
1281 if (!trace_paths) {
55314f2a 1282 BT_LOGE("No CTF traces recursively found in `%s`.",
1a9f7075
PP
1283 path_param);
1284 goto error;
1285 }
1286
55314f2a 1287 trace_names = ctf_fs_create_trace_names(trace_paths, norm_path->str);
1a9f7075 1288 if (!trace_names) {
55314f2a 1289 BT_LOGE("Cannot create trace names from trace paths.");
1a9f7075
PP
1290 goto error;
1291 }
1292
1293 for (tp_node = trace_paths, tn_node = trace_names; tp_node;
1294 tp_node = g_list_next(tp_node),
1295 tn_node = g_list_next(tn_node)) {
1296 GString *trace_path = tp_node->data;
1297 GString *trace_name = tn_node->data;
1298
41693723
PP
1299 ctf_fs_trace = ctf_fs_trace_create(self_comp,
1300 trace_path->str, trace_name->str,
1301 &ctf_fs->metadata_config);
1a9f7075 1302 if (!ctf_fs_trace) {
55314f2a 1303 BT_LOGE("Cannot create trace for `%s`.",
1a9f7075
PP
1304 trace_path->str);
1305 goto error;
1306 }
52c5fe74
PP
1307
1308 g_ptr_array_add(ctf_fs->traces, ctf_fs_trace);
1309 ctf_fs_trace = NULL;
1a9f7075
PP
1310 }
1311
1a9f7075
PP
1312 goto end;
1313
1314error:
1315 ret = -1;
1316 ctf_fs_trace_destroy(ctf_fs_trace);
1317
1318end:
1319 for (tp_node = trace_paths; tp_node; tp_node = g_list_next(tp_node)) {
1320 if (tp_node->data) {
1321 g_string_free(tp_node->data, TRUE);
1322 }
1323 }
1324
1325 for (tn_node = trace_names; tn_node; tn_node = g_list_next(tn_node)) {
1326 if (tn_node->data) {
1327 g_string_free(tn_node->data, TRUE);
1328 }
1329 }
1330
1331 if (trace_paths) {
1332 g_list_free(trace_paths);
1333 }
1334
1335 if (trace_names) {
1336 g_list_free(trace_names);
1337 }
1338
4bd72b60
PP
1339 if (norm_path) {
1340 g_string_free(norm_path, TRUE);
1341 }
1342
1a9f7075
PP
1343 return ret;
1344}
1345
41a65f30
SM
1346/* GCompareFunc to sort traces by UUID. */
1347
1348static
1349gint sort_traces_by_uuid(gconstpointer a, gconstpointer b)
1350{
1351 const struct ctf_fs_trace *trace_a = *((const struct ctf_fs_trace **) a);
1352 const struct ctf_fs_trace *trace_b = *((const struct ctf_fs_trace **) b);
1353
1354 bool trace_a_has_uuid = trace_a->metadata->tc->is_uuid_set;
1355 bool trace_b_has_uuid = trace_b->metadata->tc->is_uuid_set;
1356 gint ret;
1357
1358 /* Order traces without uuid first. */
1359 if (!trace_a_has_uuid && trace_b_has_uuid) {
1360 ret = -1;
1361 } else if (trace_a_has_uuid && !trace_b_has_uuid) {
1362 ret = 1;
1363 } else if (!trace_a_has_uuid && !trace_b_has_uuid) {
1364 ret = 0;
1365 } else {
1366 ret = bt_uuid_compare(trace_a->metadata->tc->uuid, trace_b->metadata->tc->uuid);
1367 }
1368
1369 return ret;
1370}
1371
1372/*
1373 * Count the number of stream and event classes defined by this trace's metadata.
1374 *
1375 * This is used to determine which metadata is the "latest", out of multiple
1376 * traces sharing the same UUID. It is assumed that amongst all these metadatas,
1377 * a bigger metadata is a superset of a smaller metadata. Therefore, it is
1378 * enough to just count the classes.
1379 */
1380
1381static
1382unsigned int metadata_count_stream_and_event_classes(struct ctf_fs_trace *trace)
1383{
1384 unsigned int num = trace->metadata->tc->stream_classes->len;
1385 guint i;
1386
1387 for (i = 0; i < trace->metadata->tc->stream_classes->len; i++) {
1388 struct ctf_stream_class *sc = trace->metadata->tc->stream_classes->pdata[i];
1389 num += sc->event_classes->len;
1390 }
1391
1392 return num;
1393}
1394
1395/*
1396 * Merge the src ds_file_group into dest. This consists of merging their
1397 * ds_file_infos, making sure to keep the result sorted.
1398 */
1399
1400static
1401void merge_ctf_fs_ds_file_groups(struct ctf_fs_ds_file_group *dest, struct ctf_fs_ds_file_group *src)
1402{
1403 guint i;
1404
1405 for (i = 0; i < src->ds_file_infos->len; i++) {
1406 struct ctf_fs_ds_file_info *ds_file_info =
1407 g_ptr_array_index(src->ds_file_infos, i);
1408
1409 /* Ownership of the ds_file_info is transferred to dest. */
1410 g_ptr_array_index(src->ds_file_infos, i) = NULL;
1411
1412 ds_file_group_insert_ds_file_info_sorted(dest, ds_file_info);
1413 }
41a65f30 1414
7ed5243a
FD
1415 /* Merge both indexes. */
1416 for (i = 0; i < src->index->entries->len; i++) {
1417 struct ctf_fs_ds_index_entry *entry = g_ptr_array_index(
1418 src->index->entries, i);
1419
1420 /*
1421 * Ownership of the ctf_fs_ds_index_entry is transferred to
1422 * dest.
1423 */
1424 g_ptr_array_index(src->index->entries, i) = NULL;
1425
1426 ds_file_group_insert_ds_index_entry_sorted(dest, entry);
1427 }
1428}
41a65f30
SM
1429/* Merge src_trace's data stream file groups into dest_trace's. */
1430
1431static
54ef52bd 1432int merge_matching_ctf_fs_ds_file_groups(
41a65f30
SM
1433 struct ctf_fs_trace *dest_trace,
1434 struct ctf_fs_trace *src_trace)
1435{
1436
1437 GPtrArray *dest = dest_trace->ds_file_groups;
1438 GPtrArray *src = src_trace->ds_file_groups;
1439 guint s_i;
54ef52bd 1440 int ret = 0;
41a65f30
SM
1441
1442 /*
1443 * Save the initial length of dest: we only want to check against the
1444 * original elements in the inner loop.
1445 */
1446 const guint dest_len = dest->len;
1447
1448 for (s_i = 0; s_i < src->len; s_i++) {
1449 struct ctf_fs_ds_file_group *src_group = g_ptr_array_index(src, s_i);
1450 struct ctf_fs_ds_file_group *dest_group = NULL;
1451
1452 /* A stream instance without ID can't match a stream in the other trace. */
1453 if (src_group->stream_id != -1) {
1454 guint d_i;
1455
1456 /* Let's search for a matching ds_file_group in the destination. */
1457 for (d_i = 0; d_i < dest_len; d_i++) {
1458 struct ctf_fs_ds_file_group *candidate_dest = g_ptr_array_index(dest, d_i);
1459
1460 /* Can't match a stream instance without ID. */
1461 if (candidate_dest->stream_id == -1) {
1462 continue;
1463 }
1464
1465 /*
1466 * If the two groups have the same stream instance id
1467 * and belong to the same stream class (stream instance
1468 * ids are per-stream class), they represent the same
1469 * stream instance.
1470 */
1471 if (candidate_dest->stream_id != src_group->stream_id ||
1472 candidate_dest->sc->id != src_group->sc->id) {
1473 continue;
1474 }
1475
1476 dest_group = candidate_dest;
1477 break;
1478 }
1479 }
1480
1481 /*
1482 * Didn't find a friend in dest to merge our src_group into?
7ed5243a
FD
1483 * Create a new empty one. This can happen if a stream was
1484 * active in the source trace chunk but not in the destination
1485 * trace chunk.
41a65f30
SM
1486 */
1487 if (!dest_group) {
1488 struct ctf_stream_class *sc;
7ed5243a 1489 struct ctf_fs_ds_index *index;
41a65f30
SM
1490
1491 sc = ctf_trace_class_borrow_stream_class_by_id(
1492 dest_trace->metadata->tc, src_group->sc->id);
1493 BT_ASSERT(sc);
1494
7ed5243a
FD
1495 index = ctf_fs_ds_index_create();
1496 if (!index) {
1497 ret = -1;
1498 goto end;
1499 }
1500
41a65f30 1501 dest_group = ctf_fs_ds_file_group_create(dest_trace, sc,
7ed5243a
FD
1502 src_group->stream_id, index);
1503 /* Ownership of index is transferred. */
1504 index = NULL;
54ef52bd
FD
1505 if (!dest_group) {
1506 ret = -1;
1507 goto end;
1508 }
41a65f30
SM
1509
1510 g_ptr_array_add(dest_trace->ds_file_groups, dest_group);
1511 }
1512
1513 BT_ASSERT(dest_group);
1514 merge_ctf_fs_ds_file_groups(dest_group, src_group);
1515 }
54ef52bd
FD
1516
1517end:
1518 return ret;
41a65f30
SM
1519}
1520
1521/*
1522 * Collapse the given traces, which must all share the same UUID, in a single
1523 * one.
1524 *
1525 * The trace with the most expansive metadata is chosen and all other traces
1526 * are merged into that one. The array slots of all the traces that get merged
1527 * in the chosen one are set to NULL, so only the slot of the chosen trace
1528 * remains non-NULL.
1529 */
1530
1531static
54ef52bd 1532int merge_ctf_fs_traces(struct ctf_fs_trace **traces, unsigned int num_traces)
41a65f30
SM
1533{
1534 unsigned int winner_count;
1535 struct ctf_fs_trace *winner;
1536 guint i;
54ef52bd 1537 int ret = 0;
41a65f30
SM
1538 char uuid_str[BABELTRACE_UUID_STR_LEN];
1539
1540 BT_ASSERT(num_traces >= 2);
1541
1542 winner_count = metadata_count_stream_and_event_classes(traces[0]);
1543 winner = traces[0];
1544
1545 /* Find the trace with the largest metadata. */
1546 for (i = 1; i < num_traces; i++) {
1547 struct ctf_fs_trace *candidate;
1548 unsigned int candidate_count;
1549
1550 candidate = traces[i];
1551
1552 /* A bit of sanity check. */
1553 BT_ASSERT(bt_uuid_compare(winner->metadata->tc->uuid, candidate->metadata->tc->uuid) == 0);
1554
1555 candidate_count = metadata_count_stream_and_event_classes(candidate);
1556
1557 if (candidate_count > winner_count) {
1558 winner_count = candidate_count;
1559 winner = candidate;
1560 }
1561 }
1562
1563 /* Merge all the other traces in the winning trace. */
1564 for (i = 0; i < num_traces; i++) {
1565 struct ctf_fs_trace *trace = traces[i];
1566
1567 /* Don't merge the winner into itself. */
1568 if (trace == winner) {
1569 continue;
1570 }
1571
1572 /* Merge trace's data stream file groups into winner's. */
54ef52bd
FD
1573 ret = merge_matching_ctf_fs_ds_file_groups(winner, trace);
1574 if (ret) {
1575 goto end;
1576 }
41a65f30
SM
1577
1578 /* Free the trace that got merged into winner, clear the slot in the array. */
1579 ctf_fs_trace_destroy(trace);
1580 traces[i] = NULL;
1581 }
1582
1583 /* Use the string representation of the UUID as the trace name. */
1584 bt_uuid_unparse(winner->metadata->tc->uuid, uuid_str);
1585 g_string_printf(winner->name, "%s", uuid_str);
54ef52bd
FD
1586
1587end:
1588 return ret;
41a65f30
SM
1589}
1590
1591/*
1592 * Merge all traces of `ctf_fs` that share the same UUID in a single trace.
1593 * Traces with no UUID are not merged.
1594 */
1595
1596static
54ef52bd 1597int merge_traces_with_same_uuid(struct ctf_fs_component *ctf_fs)
41a65f30
SM
1598{
1599 GPtrArray *traces = ctf_fs->traces;
1600 guint range_start_idx = 0;
1601 unsigned int num_traces = 0;
1602 guint i;
54ef52bd 1603 int ret = 0;
41a65f30
SM
1604
1605 /* Sort the traces by uuid, then collapse traces with the same uuid in a single one. */
1606 g_ptr_array_sort(traces, sort_traces_by_uuid);
1607
1608 /* Find ranges of consecutive traces that share the same UUID. */
1609 while (range_start_idx < traces->len) {
1610 guint range_len;
1611 struct ctf_fs_trace *range_start_trace = g_ptr_array_index(traces, range_start_idx);
1612
1613 /* Exclusive end of range. */
1614 guint range_end_exc_idx = range_start_idx + 1;
1615
1616 while (range_end_exc_idx < traces->len) {
1617 struct ctf_fs_trace *this_trace = g_ptr_array_index(traces, range_end_exc_idx);
1618
1619 if (!range_start_trace->metadata->tc->is_uuid_set ||
1620 (bt_uuid_compare(range_start_trace->metadata->tc->uuid, this_trace->metadata->tc->uuid) != 0)) {
1621 break;
1622 }
1623
1624 range_end_exc_idx++;
1625 }
1626
1627 /* If we have two or more traces with matching UUIDs, merge them. */
1628 range_len = range_end_exc_idx - range_start_idx;
1629 if (range_len > 1) {
1630 struct ctf_fs_trace **range_start = (struct ctf_fs_trace **) &traces->pdata[range_start_idx];
54ef52bd
FD
1631 ret = merge_ctf_fs_traces(range_start, range_len);
1632 if (ret) {
1633 goto end;
1634 }
41a65f30
SM
1635 }
1636
1637 num_traces++;
1638 range_start_idx = range_end_exc_idx;
1639 }
1640
1641 /* Clear any NULL slot (traces that got merged in another one) in the array. */
1642 for (i = 0; i < traces->len;) {
1643 if (g_ptr_array_index(traces, i) == NULL) {
1644 g_ptr_array_remove_index_fast(traces, i);
1645 } else {
1646 i++;
1647 }
1648 }
1649
1650 BT_ASSERT(num_traces == traces->len);
54ef52bd
FD
1651
1652end:
1653 return ret;
41a65f30
SM
1654}
1655
f280892e
SM
1656int ctf_fs_component_create_ctf_fs_traces(bt_self_component_source *self_comp,
1657 struct ctf_fs_component *ctf_fs,
1658 const bt_value *paths_value)
1659{
1660 int ret = 0;
1661 uint64_t i;
1662
1663 for (i = 0; i < bt_value_array_get_size(paths_value); i++) {
1664 const bt_value *path_value = bt_value_array_borrow_element_by_index_const(paths_value, i);
1665 const char *path = bt_value_string_get(path_value);
1666
1667 ret = ctf_fs_component_create_ctf_fs_traces_one_root(self_comp, ctf_fs, path);
1668 if (ret) {
1669 goto end;
1670 }
1671 }
1672
54ef52bd 1673 ret = merge_traces_with_same_uuid(ctf_fs);
41a65f30 1674
f280892e
SM
1675end:
1676 return ret;
1677}
1678
a38d7650
SM
1679static
1680GString *get_stream_instance_unique_name(
1681 struct ctf_fs_ds_file_group *ds_file_group)
1682{
1683 GString *name;
1684 struct ctf_fs_ds_file_info *ds_file_info;
1685
1686 name = g_string_new(NULL);
1687 if (!name) {
1688 goto end;
1689 }
1690
1691 /*
1692 * If there's more than one stream file in the stream file
1693 * group, the first (earliest) stream file's path is used as
1694 * the stream's unique name.
1695 */
1696 BT_ASSERT(ds_file_group->ds_file_infos->len > 0);
1697 ds_file_info = g_ptr_array_index(ds_file_group->ds_file_infos, 0);
1698 g_string_assign(name, ds_file_info->path->str);
1699
1700end:
1701 return name;
1702}
1703
f280892e
SM
1704/* Create the IR stream objects for ctf_fs_trace. */
1705
1706static
1707int create_streams_for_trace(struct ctf_fs_trace *ctf_fs_trace)
1708{
1709 int ret;
1710 GString *name = NULL;
1711 guint i;
1712
1713 for (i = 0; i < ctf_fs_trace->ds_file_groups->len; i++) {
1714 struct ctf_fs_ds_file_group *ds_file_group =
1715 g_ptr_array_index(ctf_fs_trace->ds_file_groups, i);
1716 name = get_stream_instance_unique_name(ds_file_group);
1717
1718 if (!name) {
1719 goto error;
1720 }
1721
1722 if (ds_file_group->sc->ir_sc) {
1723 BT_ASSERT(ctf_fs_trace->trace);
1724
1725 if (ds_file_group->stream_id == UINT64_C(-1)) {
1726 /* No stream ID: use 0 */
1727 ds_file_group->stream = bt_stream_create_with_id(
1728 ds_file_group->sc->ir_sc,
1729 ctf_fs_trace->trace,
1730 ctf_fs_trace->next_stream_id);
1731 ctf_fs_trace->next_stream_id++;
1732 } else {
1733 /* Specific stream ID */
1734 ds_file_group->stream = bt_stream_create_with_id(
1735 ds_file_group->sc->ir_sc,
1736 ctf_fs_trace->trace,
1737 (uint64_t) ds_file_group->stream_id);
1738 }
1739 } else {
1740 ds_file_group->stream = NULL;
1741 }
1742
1743 if (!ds_file_group->stream) {
1744 BT_LOGE("Cannot create stream for DS file group: "
1745 "addr=%p, stream-name=\"%s\"",
1746 ds_file_group, name->str);
1747 goto error;
1748 }
1749
1750 ret = bt_stream_set_name(ds_file_group->stream,
1751 name->str);
1752 if (ret) {
1753 BT_LOGE("Cannot set stream's name: "
1754 "addr=%p, stream-name=\"%s\"",
1755 ds_file_group->stream, name->str);
1756 goto error;
1757 }
1758
1759 g_string_free(name, TRUE);
1760 name = NULL;
1761 }
1762
1763 ret = 0;
1764 goto end;
1765
1766error:
1767 ret = -1;
1768
1769end:
1770
1771 if (name) {
1772 g_string_free(name, TRUE);
1773 }
1774 return ret;
1775}
1776
d907165c
SM
1777/*
1778 * Validate the "paths" parameter passed to this component. It must be
1779 * present, and it must be an array of strings.
1780 */
1781
1782static
f280892e
SM
1783bool validate_paths_parameter(const bt_value *paths)
1784{
1785 bool ret;
1786 bt_value_type type;
1787 uint64_t i;
1788
1789 if (!paths) {
1790 BT_LOGE("missing \"paths\" parameter");
1791 goto error;
1792 }
1793
1794 type = bt_value_get_type(paths);
1795 if (type != BT_VALUE_TYPE_ARRAY) {
1796 BT_LOGE("`paths` parameter: expecting array value: type=%s",
1797 bt_common_value_type_string(type));
1798 goto error;
1799 }
1800
1801 for (i = 0; i < bt_value_array_get_size(paths); i++) {
1802 const bt_value *elem;
1803
1804 elem = bt_value_array_borrow_element_by_index_const(paths, i);
1805 type = bt_value_get_type(elem);
1806 if (type != BT_VALUE_TYPE_STRING) {
1807 BT_LOGE("`paths` parameter: expecting string value: index=%" PRIu64 ", type=%s",
1808 i, bt_common_value_type_string(type));
1809 goto error;
1810 }
1811 }
1812
1813 ret = true;
1814 goto end;
1815
1816error:
1817 ret = false;
1818
1819end:
1820 return ret;
1821}
1822
d907165c
SM
1823bool read_src_fs_parameters(const bt_value *params,
1824 const bt_value **paths, struct ctf_fs_component *ctf_fs) {
1825 bool ret;
1826 const bt_value *value;
1827
1828 /* paths parameter */
1829 *paths = bt_value_map_borrow_entry_value_const(params, "paths");
1830 if (!validate_paths_parameter(*paths)) {
1831 goto error;
1832 }
1833
1834 /* clock-class-offset-s parameter */
1835 value = bt_value_map_borrow_entry_value_const(params,
1836 "clock-class-offset-s");
1837 if (value) {
fdd3a2da 1838 if (!bt_value_is_signed_integer(value)) {
d907165c
SM
1839 BT_LOGE("clock-class-offset-s must be an integer");
1840 goto error;
1841 }
1842 ctf_fs->metadata_config.clock_class_offset_s =
fdd3a2da 1843 bt_value_signed_integer_get(value);
d907165c
SM
1844 }
1845
1846 /* clock-class-offset-ns parameter */
1847 value = bt_value_map_borrow_entry_value_const(params,
1848 "clock-class-offset-ns");
1849 if (value) {
fdd3a2da 1850 if (!bt_value_is_signed_integer(value)) {
d907165c
SM
1851 BT_LOGE("clock-class-offset-ns must be an integer");
1852 goto error;
1853 }
1854 ctf_fs->metadata_config.clock_class_offset_ns =
fdd3a2da 1855 bt_value_signed_integer_get(value);
d907165c
SM
1856 }
1857
1858
1859 ret = true;
1860 goto end;
1861
1862error:
1863 ret = false;
1864
1865end:
1866 return ret;
1867}
1868
5b29e799 1869static
d94d92ac 1870struct ctf_fs_component *ctf_fs_create(
b19ff26f
PP
1871 bt_self_component_source *self_comp,
1872 const bt_value *params)
56a1cced 1873{
f280892e 1874 struct ctf_fs_component *ctf_fs = NULL;
f280892e
SM
1875 guint i;
1876 const bt_value *paths_value;
56a1cced 1877
d907165c
SM
1878 ctf_fs = ctf_fs_component_create();
1879 if (!ctf_fs) {
f280892e
SM
1880 goto error;
1881 }
1882
d907165c 1883 if (!read_src_fs_parameters(params, &paths_value, ctf_fs)) {
f280892e 1884 goto error;
56a1cced
JG
1885 }
1886
d94d92ac 1887 bt_self_component_set_data(
707b7d35 1888 bt_self_component_source_as_self_component(self_comp),
d94d92ac 1889 ctf_fs);
1a9f7075 1890
4f1f88a6
PP
1891 /*
1892 * We don't need to get a new reference here because as long as
1893 * our private ctf_fs_component object exists, the containing
1894 * private component should also exist.
1895 */
d94d92ac 1896 ctf_fs->self_comp = self_comp;
56a1cced 1897
f280892e 1898 if (ctf_fs_component_create_ctf_fs_traces(self_comp, ctf_fs, paths_value)) {
4f1f88a6
PP
1899 goto error;
1900 }
1901
f280892e
SM
1902 for (i = 0; i < ctf_fs->traces->len; i++) {
1903 struct ctf_fs_trace *trace = g_ptr_array_index(ctf_fs->traces, i);
599faa1c 1904
f280892e
SM
1905 if (create_streams_for_trace(trace)) {
1906 goto error;
1907 }
1908
1909 if (create_ports_for_trace(ctf_fs, trace)) {
1910 goto error;
1911 }
4f1f88a6
PP
1912 }
1913
1ef09eb5
JG
1914 goto end;
1915
56a1cced 1916error:
1a9f7075 1917 ctf_fs_destroy(ctf_fs);
e7a4393b 1918 ctf_fs = NULL;
d94d92ac 1919 bt_self_component_set_data(
707b7d35 1920 bt_self_component_source_as_self_component(self_comp),
d94d92ac 1921 NULL);
1a9f7075 1922
1ef09eb5 1923end:
56a1cced
JG
1924 return ctf_fs;
1925}
1926
ea0b4b9e 1927BT_HIDDEN
4cdfc5e8 1928bt_self_component_status ctf_fs_init(
b19ff26f 1929 bt_self_component_source *self_comp,
c88dd1cb 1930 const bt_value *params, __attribute__((unused)) void *init_method_data)
ea0b4b9e
JG
1931{
1932 struct ctf_fs_component *ctf_fs;
4cdfc5e8 1933 bt_self_component_status ret = BT_SELF_COMPONENT_STATUS_OK;
ea0b4b9e 1934
d94d92ac 1935 ctf_fs = ctf_fs_create(self_comp, params);
ea0b4b9e 1936 if (!ctf_fs) {
d94d92ac 1937 ret = BT_SELF_COMPONENT_STATUS_ERROR;
ea0b4b9e 1938 }
4c1456f0 1939
ea0b4b9e
JG
1940 return ret;
1941}
33f93973
PP
1942
1943BT_HIDDEN
4cdfc5e8 1944bt_query_status ctf_fs_query(
b19ff26f
PP
1945 bt_self_component_class_source *comp_class,
1946 const bt_query_executor *query_exec,
1947 const char *object, const bt_value *params,
f4e38e70 1948 __attribute__((unused)) bt_logging_level log_level,
b19ff26f 1949 const bt_value **result)
33f93973 1950{
4cdfc5e8 1951 bt_query_status status = BT_QUERY_STATUS_OK;
33f93973 1952
04c0ba87 1953 if (!strcmp(object, "metadata-info")) {
d94d92ac 1954 status = metadata_info_query(comp_class, params, result);
97ade20b 1955 } else if (!strcmp(object, "trace-info")) {
d94d92ac 1956 status = trace_info_query(comp_class, params, result);
33f93973 1957 } else {
55314f2a 1958 BT_LOGE("Unknown query object `%s`", object);
d94d92ac 1959 status = BT_QUERY_STATUS_INVALID_OBJECT;
04c0ba87 1960 goto end;
33f93973 1961 }
33f93973 1962end:
d94d92ac 1963 return status;
33f93973 1964}
This page took 0.143674 seconds and 4 git commands to generate.