Decouple component class from plugin subsystem, remove component factory
[babeltrace.git] / plugins / ctf / fs / fs.c
1 /*
2 * fs.c
3 *
4 * Babeltrace CTF file system Reader Component
5 *
6 * Copyright 2016 Jérémie Galarneau <jeremie.galarneau@efficios.com>
7 *
8 * Author: Jérémie Galarneau <jeremie.galarneau@efficios.com>
9 *
10 * Permission is hereby granted, free of charge, to any person obtaining a copy
11 * of this software and associated documentation files (the "Software"), to deal
12 * in the Software without restriction, including without limitation the rights
13 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14 * copies of the Software, and to permit persons to whom the Software is
15 * furnished to do so, subject to the following conditions:
16 *
17 * The above copyright notice and this permission notice shall be included in
18 * all copies or substantial portions of the Software.
19 *
20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26 * SOFTWARE.
27 */
28
29 #include <babeltrace/ctf-ir/packet.h>
30 #include <babeltrace/ctf-ir/clock-class.h>
31 #include <babeltrace/component/notification/iterator.h>
32 #include <babeltrace/component/notification/stream.h>
33 #include <babeltrace/component/notification/event.h>
34 #include <babeltrace/component/notification/packet.h>
35 #include <babeltrace/component/notification/heap.h>
36 #include <glib.h>
37 #include <assert.h>
38 #include <unistd.h>
39 #include "fs.h"
40 #include "metadata.h"
41 #include "data-stream.h"
42 #include "file.h"
43
44 #define PRINT_ERR_STREAM ctf_fs->error_fp
45 #define PRINT_PREFIX "ctf-fs"
46 #include "print.h"
47
48 BT_HIDDEN
49 bool ctf_fs_debug;
50
51 static
52 enum bt_notification_iterator_status ctf_fs_iterator_next(
53 struct bt_notification_iterator *iterator);
54
55 static
56 struct bt_notification *ctf_fs_iterator_get(
57 struct bt_notification_iterator *iterator)
58 {
59 struct ctf_fs_iterator *ctf_it =
60 bt_notification_iterator_get_private_data(iterator);
61
62 if (!ctf_it->current_notification) {
63 (void) ctf_fs_iterator_next(iterator);
64 }
65
66 return bt_get(ctf_it->current_notification);
67 }
68
69 static
70 enum bt_notification_iterator_status ctf_fs_iterator_get_next_notification(
71 struct ctf_fs_iterator *it,
72 struct ctf_fs_stream *stream,
73 struct bt_notification **notification)
74 {
75 enum bt_ctf_notif_iter_status status;
76 enum bt_notification_iterator_status ret;
77
78 if (stream->end_reached) {
79 status = BT_CTF_NOTIF_ITER_STATUS_EOF;
80 goto end;
81 }
82
83 status = bt_ctf_notif_iter_get_next_notification(stream->notif_iter,
84 notification);
85 if (status != BT_CTF_NOTIF_ITER_STATUS_OK &&
86 status != BT_CTF_NOTIF_ITER_STATUS_EOF) {
87 goto end;
88 }
89
90 /* Should be handled in bt_ctf_notif_iter_get_next_notification. */
91 if (status == BT_CTF_NOTIF_ITER_STATUS_EOF) {
92 *notification = bt_notification_stream_end_create(
93 stream->stream);
94 if (!*notification) {
95 status = BT_CTF_NOTIF_ITER_STATUS_ERROR;
96 }
97 status = BT_CTF_NOTIF_ITER_STATUS_OK;
98 stream->end_reached = true;
99 }
100 end:
101 switch (status) {
102 case BT_CTF_NOTIF_ITER_STATUS_EOF:
103 ret = BT_NOTIFICATION_ITERATOR_STATUS_END;
104 break;
105 case BT_CTF_NOTIF_ITER_STATUS_OK:
106 ret = BT_NOTIFICATION_ITERATOR_STATUS_OK;
107 break;
108 case BT_CTF_NOTIF_ITER_STATUS_AGAIN:
109 /*
110 * Should not make it this far as this is medium-specific;
111 * there is nothing for the user to do and it should have been
112 * handled upstream.
113 */
114 assert(0);
115 case BT_CTF_NOTIF_ITER_STATUS_INVAL:
116 /* No argument provided by the user, so don't return INVAL. */
117 case BT_CTF_NOTIF_ITER_STATUS_ERROR:
118 default:
119 ret = BT_NOTIFICATION_ITERATOR_STATUS_ERROR;
120 break;
121 }
122 return ret;
123 }
124
125 /*
126 * Remove me. This is a temporary work-around due to our inhability to use
127 * libbabeltrace-ctf from libbabeltrace-plugin.
128 */
129 static
130 struct bt_ctf_stream *internal_bt_notification_get_stream(
131 struct bt_notification *notification)
132 {
133 struct bt_ctf_stream *stream = NULL;
134
135 assert(notification);
136 switch (bt_notification_get_type(notification)) {
137 case BT_NOTIFICATION_TYPE_EVENT:
138 {
139 struct bt_ctf_event *event;
140
141 event = bt_notification_event_get_event(notification);
142 stream = bt_ctf_event_get_stream(event);
143 bt_put(event);
144 break;
145 }
146 case BT_NOTIFICATION_TYPE_PACKET_BEGIN:
147 {
148 struct bt_ctf_packet *packet;
149
150 packet = bt_notification_packet_begin_get_packet(notification);
151 stream = bt_ctf_packet_get_stream(packet);
152 bt_put(packet);
153 break;
154 }
155 case BT_NOTIFICATION_TYPE_PACKET_END:
156 {
157 struct bt_ctf_packet *packet;
158
159 packet = bt_notification_packet_end_get_packet(notification);
160 stream = bt_ctf_packet_get_stream(packet);
161 bt_put(packet);
162 break;
163 }
164 case BT_NOTIFICATION_TYPE_STREAM_END:
165 stream = bt_notification_stream_end_get_stream(notification);
166 break;
167 default:
168 goto end;
169 }
170 end:
171 return stream;
172 }
173
174 static
175 enum bt_notification_iterator_status populate_heap(struct ctf_fs_iterator *it)
176 {
177 size_t i, pending_streams_count = it->pending_streams->len;
178 enum bt_notification_iterator_status ret =
179 BT_NOTIFICATION_ITERATOR_STATUS_OK;
180
181 /* Insert one stream-associated notification for each stream. */
182 for (i = 0; i < pending_streams_count; i++) {
183 struct bt_notification *notification;
184 struct ctf_fs_stream *fs_stream;
185 struct bt_ctf_stream *stream;
186 size_t pending_stream_index = pending_streams_count - 1 - i;
187
188 fs_stream = g_ptr_array_index(it->pending_streams,
189 pending_stream_index);
190
191 do {
192 int heap_ret;
193
194 ret = ctf_fs_iterator_get_next_notification(
195 it, fs_stream, &notification);
196 if (ret && ret != BT_NOTIFICATION_ITERATOR_STATUS_END) {
197 printf_debug("Failed to populate heap at stream %zu\n",
198 pending_stream_index);
199 goto end;
200 }
201
202 stream = internal_bt_notification_get_stream(
203 notification);
204 if (stream) {
205 gboolean inserted;
206
207 /*
208 * Associate pending ctf_fs_stream to
209 * bt_ctf_stream. Ownership of stream
210 * is passed to the stream ht.
211 */
212 inserted = g_hash_table_insert(it->stream_ht,
213 stream, fs_stream);
214 if (!inserted) {
215 ret = BT_NOTIFICATION_ITERATOR_STATUS_NOMEM;
216 printf_debug("Failed to associate fs stream to ctf stream\n");
217 goto end;
218 }
219 }
220
221 heap_ret = bt_notification_heap_insert(
222 it->pending_notifications,
223 notification);
224 bt_put(notification);
225 if (heap_ret) {
226 ret = BT_NOTIFICATION_ITERATOR_STATUS_NOMEM;
227 printf_debug("Failed to insert notification in heap\n");
228 goto end;
229 }
230 } while (!stream && ret != BT_NOTIFICATION_ITERATOR_STATUS_END);
231 /*
232 * Set NULL so the destruction callback registered with the
233 * array is not invoked on the stream (its ownership was
234 * transferred to the streams hashtable).
235 */
236 g_ptr_array_index(it->pending_streams,
237 pending_stream_index) = NULL;
238 g_ptr_array_remove_index(it->pending_streams,
239 pending_stream_index);
240 }
241
242 g_ptr_array_free(it->pending_streams, TRUE);
243 it->pending_streams = NULL;
244 end:
245 return ret;
246 }
247
248 static
249 enum bt_notification_iterator_status ctf_fs_iterator_next(
250 struct bt_notification_iterator *iterator)
251 {
252 int heap_ret;
253 struct bt_ctf_stream *stream = NULL;
254 struct ctf_fs_stream *fs_stream;
255 struct bt_notification *notification;
256 struct bt_notification *next_stream_notification;
257 enum bt_notification_iterator_status ret =
258 BT_NOTIFICATION_ITERATOR_STATUS_OK;
259 struct ctf_fs_iterator *ctf_it =
260 bt_notification_iterator_get_private_data(iterator);
261
262 notification = bt_notification_heap_pop(ctf_it->pending_notifications);
263 if (!notification && !ctf_it->pending_streams) {
264 ret = BT_NOTIFICATION_ITERATOR_STATUS_END;
265 goto end;
266 }
267
268 if (!notification && ctf_it->pending_streams) {
269 /*
270 * Insert at one notification per stream in the heap and pop
271 * one.
272 */
273 ret = populate_heap(ctf_it);
274 if (ret) {
275 goto end;
276 }
277
278 notification = bt_notification_heap_pop(
279 ctf_it->pending_notifications);
280 if (!notification) {
281 ret = BT_NOTIFICATION_ITERATOR_STATUS_END;
282 goto end;
283 }
284 }
285
286 /* notification is set from here. */
287
288 stream = internal_bt_notification_get_stream(notification);
289 if (!stream) {
290 /*
291 * The current notification is not associated to a particular
292 * stream, there is no need to insert a new notification from
293 * a stream in the heap.
294 */
295 goto end;
296 }
297
298 fs_stream = g_hash_table_lookup(ctf_it->stream_ht, stream);
299 if (!fs_stream) {
300 /* We have reached this stream's end. */
301 goto end;
302 }
303
304 ret = ctf_fs_iterator_get_next_notification(ctf_it, fs_stream,
305 &next_stream_notification);
306 if ((ret && ret != BT_NOTIFICATION_ITERATOR_STATUS_END)) {
307 heap_ret = bt_notification_heap_insert(
308 ctf_it->pending_notifications, notification);
309
310 assert(!next_stream_notification);
311 if (heap_ret) {
312 /*
313 * We're dropping the most recent notification, but at
314 * this point, something is seriously wrong...
315 */
316 ret = BT_NOTIFICATION_ITERATOR_STATUS_NOMEM;
317 }
318 BT_PUT(notification);
319 goto end;
320 }
321
322 if (ret == BT_NOTIFICATION_ITERATOR_STATUS_END) {
323 gboolean success;
324
325 /* Remove stream. */
326 success = g_hash_table_remove(ctf_it->stream_ht, stream);
327 assert(success);
328 ret = BT_NOTIFICATION_ITERATOR_STATUS_OK;
329 } else {
330 heap_ret = bt_notification_heap_insert(ctf_it->pending_notifications,
331 next_stream_notification);
332 BT_PUT(next_stream_notification);
333 if (heap_ret) {
334 /*
335 * We're dropping the most recent notification...
336 */
337 ret = BT_NOTIFICATION_ITERATOR_STATUS_NOMEM;
338 }
339 }
340
341 /*
342 * Ensure that the stream is removed from both pending_streams and
343 * the streams hashtable on reception of the "end of stream"
344 * notification.
345 */
346 end:
347 BT_MOVE(ctf_it->current_notification, notification);
348 bt_put(stream);
349 return ret;
350 }
351
352 static
353 void ctf_fs_iterator_destroy_data(struct ctf_fs_iterator *ctf_it)
354 {
355 bt_put(ctf_it->current_notification);
356 bt_put(ctf_it->pending_notifications);
357 if (ctf_it->pending_streams) {
358 g_ptr_array_free(ctf_it->pending_streams, TRUE);
359 }
360 if (ctf_it->stream_ht) {
361 g_hash_table_destroy(ctf_it->stream_ht);
362 }
363 g_free(ctf_it);
364 }
365
366 static
367 void ctf_fs_iterator_destroy(struct bt_notification_iterator *it)
368 {
369 void *data = bt_notification_iterator_get_private_data(it);
370
371 ctf_fs_iterator_destroy_data(data);
372 }
373
374 static
375 bool compare_event_notifications(struct bt_notification *a,
376 struct bt_notification *b)
377 {
378 int ret;
379 struct bt_ctf_clock_class *clock_class;
380 struct bt_ctf_clock_value *a_clock_value, *b_clock_value;
381 struct bt_ctf_stream_class *a_stream_class;
382 struct bt_ctf_stream *a_stream;
383 struct bt_ctf_event *a_event, *b_event;
384 struct bt_ctf_trace *trace;
385 int64_t a_ts, b_ts;
386
387 // FIXME - assumes only one clock
388 a_event = bt_notification_event_get_event(a);
389 b_event = bt_notification_event_get_event(b);
390 assert(a_event);
391 assert(b_event);
392
393 a_stream = bt_ctf_event_get_stream(a_event);
394 assert(a_stream);
395 a_stream_class = bt_ctf_stream_get_class(a_stream);
396 assert(a_stream_class);
397 trace = bt_ctf_stream_class_get_trace(a_stream_class);
398 assert(trace);
399
400 clock_class = bt_ctf_trace_get_clock_class(trace, 0);
401 a_clock_value = bt_ctf_event_get_clock_value(a_event, clock_class);
402 b_clock_value = bt_ctf_event_get_clock_value(b_event, clock_class);
403 assert(a_clock_value);
404 assert(b_clock_value);
405
406 ret = bt_ctf_clock_value_get_value_ns_from_epoch(a_clock_value, &a_ts);
407 assert(!ret);
408 ret = bt_ctf_clock_value_get_value_ns_from_epoch(b_clock_value, &b_ts);
409 assert(!ret);
410
411 bt_put(a_event);
412 bt_put(b_event);
413 bt_put(a_clock_value);
414 bt_put(b_clock_value);
415 bt_put(a_stream);
416 bt_put(a_stream_class);
417 bt_put(clock_class);
418 bt_put(trace);
419 return a_ts < b_ts;
420 }
421
422 static
423 bool compare_notifications(struct bt_notification *a, struct bt_notification *b,
424 void *unused)
425 {
426 static int notification_priorities[] = {
427 [BT_NOTIFICATION_TYPE_NEW_TRACE] = 0,
428 [BT_NOTIFICATION_TYPE_NEW_STREAM_CLASS] = 1,
429 [BT_NOTIFICATION_TYPE_NEW_EVENT_CLASS] = 2,
430 [BT_NOTIFICATION_TYPE_PACKET_BEGIN] = 3,
431 [BT_NOTIFICATION_TYPE_PACKET_END] = 4,
432 [BT_NOTIFICATION_TYPE_EVENT] = 5,
433 [BT_NOTIFICATION_TYPE_END_OF_TRACE] = 6,
434 };
435 int a_prio, b_prio;
436 enum bt_notification_type a_type, b_type;
437
438 assert(a && b);
439 a_type = bt_notification_get_type(a);
440 b_type = bt_notification_get_type(b);
441 assert(a_type > BT_NOTIFICATION_TYPE_ALL);
442 assert(a_type < BT_NOTIFICATION_TYPE_NR);
443 assert(b_type > BT_NOTIFICATION_TYPE_ALL);
444 assert(b_type < BT_NOTIFICATION_TYPE_NR);
445
446 a_prio = notification_priorities[a_type];
447 b_prio = notification_priorities[b_type];
448
449 if (likely((a_type == b_type) && a_type == BT_NOTIFICATION_TYPE_EVENT)) {
450 return compare_event_notifications(a, b);
451 }
452
453 if (unlikely(a_prio != b_prio)) {
454 return a_prio < b_prio;
455 }
456
457 /* Notification types are equal, but not of type "event". */
458 switch (a_type) {
459 case BT_NOTIFICATION_TYPE_PACKET_BEGIN:
460 case BT_NOTIFICATION_TYPE_PACKET_END:
461 case BT_NOTIFICATION_TYPE_STREAM_END:
462 {
463 int64_t a_sc_id, b_sc_id;
464 struct bt_ctf_stream *a_stream, *b_stream;
465 struct bt_ctf_stream_class *a_sc, *b_sc;
466
467 a_stream = internal_bt_notification_get_stream(a);
468 b_stream = internal_bt_notification_get_stream(b);
469 assert(a_stream && b_stream);
470
471 a_sc = bt_ctf_stream_get_class(a_stream);
472 b_sc = bt_ctf_stream_get_class(b_stream);
473 assert(a_sc && b_sc);
474
475 a_sc_id = bt_ctf_stream_class_get_id(a_sc);
476 b_sc_id = bt_ctf_stream_class_get_id(b_sc);
477 assert(a_sc_id >= 0 && b_sc_id >= 0);
478 bt_put(a_sc);
479 bt_put(a_stream);
480 bt_put(b_sc);
481 bt_put(b_stream);
482 return a_sc_id < b_sc_id;
483 }
484 case BT_NOTIFICATION_TYPE_NEW_TRACE:
485 case BT_NOTIFICATION_TYPE_END_OF_TRACE:
486 /* Impossible to have two separate traces. */
487 default:
488 assert(0);
489 }
490
491 assert(0);
492 return a < b;
493 }
494
495 static
496 void stream_destroy(void *stream)
497 {
498 ctf_fs_stream_destroy((struct ctf_fs_stream *) stream);
499 }
500
501 static
502 int open_trace_streams(struct ctf_fs_component *ctf_fs,
503 struct ctf_fs_iterator *ctf_it)
504 {
505 int ret = 0;
506 const char *name;
507 GError *error = NULL;
508 GDir *dir = g_dir_open(ctf_fs->trace_path->str, 0, &error);
509
510 if (!dir) {
511 PERR("Cannot open directory \"%s\": %s (code %d)\n",
512 ctf_fs->trace_path->str, error->message,
513 error->code);
514 goto error;
515 }
516
517 while ((name = g_dir_read_name(dir))) {
518 struct ctf_fs_file *file = NULL;
519 struct ctf_fs_stream *stream = NULL;
520
521 if (!strcmp(name, CTF_FS_METADATA_FILENAME)) {
522 /* Ignore the metadata stream. */
523 PDBG("Ignoring metadata file \"%s\"\n",
524 name);
525 continue;
526 }
527
528 if (name[0] == '.') {
529 PDBG("Ignoring hidden file \"%s\"\n",
530 name);
531 continue;
532 }
533
534 /* Create the file. */
535 file = ctf_fs_file_create(ctf_fs);
536 if (!file) {
537 PERR("Cannot create stream file object\n");
538 goto error;
539 }
540
541 /* Create full path string. */
542 g_string_append_printf(file->path, "%s/%s",
543 ctf_fs->trace_path->str, name);
544 if (!g_file_test(file->path->str, G_FILE_TEST_IS_REGULAR)) {
545 PDBG("Ignoring non-regular file \"%s\"\n", name);
546 ctf_fs_file_destroy(file);
547 continue;
548 }
549
550 /* Open the file. */
551 if (ctf_fs_file_open(ctf_fs, file, "rb")) {
552 ctf_fs_file_destroy(file);
553 goto error;
554 }
555
556 if (file->size == 0) {
557 /* Skip empty stream. */
558 ctf_fs_file_destroy(file);
559 continue;
560 }
561
562 /* Create a private stream; file ownership is passed to it. */
563 stream = ctf_fs_stream_create(ctf_fs, file);
564 if (!stream) {
565 ctf_fs_file_destroy(file);
566 goto error;
567 }
568
569 g_ptr_array_add(ctf_it->pending_streams, stream);
570 }
571
572 goto end;
573 error:
574 ret = -1;
575 end:
576 if (dir) {
577 g_dir_close(dir);
578 dir = NULL;
579 }
580 if (error) {
581 g_error_free(error);
582 }
583 return ret;
584 }
585
586 static
587 enum bt_component_status ctf_fs_iterator_init(struct bt_component *source,
588 struct bt_notification_iterator *it)
589 {
590 struct ctf_fs_iterator *ctf_it;
591 struct ctf_fs_component *ctf_fs;
592 enum bt_component_status ret = BT_COMPONENT_STATUS_OK;
593
594 assert(source && it);
595
596 ctf_fs = bt_component_get_private_data(source);
597 if (!ctf_fs) {
598 ret = BT_COMPONENT_STATUS_INVALID;
599 goto end;
600 }
601
602 ctf_it = g_new0(struct ctf_fs_iterator, 1);
603 if (!ctf_it) {
604 ret = BT_COMPONENT_STATUS_NOMEM;
605 goto end;
606 }
607
608 ctf_it->stream_ht = g_hash_table_new_full(g_direct_hash,
609 g_direct_equal, bt_put, stream_destroy);
610 if (!ctf_it->stream_ht) {
611 goto error;
612 }
613 ctf_it->pending_streams = g_ptr_array_new_with_free_func(
614 stream_destroy);
615 if (!ctf_it->pending_streams) {
616 goto error;
617 }
618 ctf_it->pending_notifications = bt_notification_heap_create(
619 compare_notifications, NULL);
620 if (!ctf_it->pending_notifications) {
621 goto error;
622 }
623
624 ret = open_trace_streams(ctf_fs, ctf_it);
625 if (ret) {
626 goto error;
627 }
628
629 ret = bt_notification_iterator_set_get_cb(it, ctf_fs_iterator_get);
630 if (ret) {
631 goto error;
632 }
633
634 ret = bt_notification_iterator_set_next_cb(it, ctf_fs_iterator_next);
635 if (ret) {
636 goto error;
637 }
638
639 ret = bt_notification_iterator_set_destroy_cb(it,
640 ctf_fs_iterator_destroy);
641 if (ret) {
642 goto error;
643 }
644
645 ret = bt_notification_iterator_set_private_data(it, ctf_it);
646 if (ret) {
647 goto error;
648 }
649
650 end:
651 return ret;
652 error:
653 (void) bt_notification_iterator_set_private_data(it, NULL);
654 ctf_fs_iterator_destroy_data(ctf_it);
655 goto end;
656 }
657
658 static
659 void ctf_fs_destroy_data(struct ctf_fs_component *ctf_fs)
660 {
661 if (ctf_fs->trace_path) {
662 g_string_free(ctf_fs->trace_path, TRUE);
663 }
664 if (ctf_fs->metadata) {
665 ctf_fs_metadata_fini(ctf_fs->metadata);
666 g_free(ctf_fs->metadata);
667 }
668 g_free(ctf_fs);
669 }
670
671 static
672 void ctf_fs_destroy(struct bt_component *component)
673 {
674 void *data = bt_component_get_private_data(component);
675
676 ctf_fs_destroy_data(data);
677 }
678
679 static
680 struct ctf_fs_component *ctf_fs_create(struct bt_value *params)
681 {
682 struct ctf_fs_component *ctf_fs;
683 struct bt_value *value = NULL;
684 const char *path;
685 enum bt_value_status ret;
686
687 ctf_fs = g_new0(struct ctf_fs_component, 1);
688 if (!ctf_fs) {
689 goto end;
690 }
691
692 /* FIXME: should probably look for a source URI */
693 value = bt_value_map_get(params, "path");
694 if (!value || bt_value_is_null(value) || !bt_value_is_string(value)) {
695 goto error;
696 }
697
698 ret = bt_value_string_get(value, &path);
699 if (ret != BT_VALUE_STATUS_OK) {
700 goto error;
701 }
702
703 ctf_fs->trace_path = g_string_new(path);
704 if (!ctf_fs->trace_path) {
705 goto error;
706 }
707 ctf_fs->error_fp = stderr;
708 ctf_fs->page_size = (size_t) getpagesize();
709
710 // FIXME: check error.
711 ctf_fs->metadata = g_new0(struct ctf_fs_metadata, 1);
712 if (!ctf_fs->metadata) {
713 goto error;
714 }
715 ctf_fs_metadata_set_trace(ctf_fs);
716 goto end;
717
718 error:
719 ctf_fs_destroy_data(ctf_fs);
720 ctf_fs = NULL;
721 end:
722 BT_PUT(value);
723 return ctf_fs;
724 }
725
726 BT_HIDDEN
727 enum bt_component_status ctf_fs_init(struct bt_component *source,
728 struct bt_value *params)
729 {
730 struct ctf_fs_component *ctf_fs;
731 enum bt_component_status ret = BT_COMPONENT_STATUS_OK;
732
733 assert(source);
734 ctf_fs_debug = g_strcmp0(getenv("CTF_FS_DEBUG"), "1") == 0;
735 ctf_fs = ctf_fs_create(params);
736 if (!ctf_fs) {
737 ret = BT_COMPONENT_STATUS_NOMEM;
738 goto end;
739 }
740
741 ret = bt_component_set_destroy_cb(source, ctf_fs_destroy);
742 if (ret != BT_COMPONENT_STATUS_OK) {
743 goto error;
744 }
745
746 ret = bt_component_set_private_data(source, ctf_fs);
747 if (ret != BT_COMPONENT_STATUS_OK) {
748 goto error;
749 }
750
751 ret = bt_component_source_set_iterator_init_cb(source,
752 ctf_fs_iterator_init);
753 if (ret != BT_COMPONENT_STATUS_OK) {
754 goto error;
755 }
756 end:
757 return ret;
758 error:
759 (void) bt_component_set_private_data(source, NULL);
760 ctf_fs_destroy_data(ctf_fs);
761 return ret;
762 }
This page took 0.044193 seconds and 4 git commands to generate.