Fix fork handling, where child shares shm with parent
[lttng-ust.git] / liblttng-ust / lttng-ust-abi.c
1 /*
2 * lttng-ust-abi.c
3 *
4 * Copyright 2010-2011 (c) - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
5 *
6 * LTTng UST ABI
7 *
8 * Mimic system calls for:
9 * - session creation, returns an object descriptor or failure.
10 * - channel creation, returns an object descriptor or failure.
11 * - Operates on a session object descriptor
12 * - Takes all channel options as parameters.
13 * - stream get, returns an object descriptor or failure.
14 * - Operates on a channel object descriptor.
15 * - stream notifier get, returns an object descriptor or failure.
16 * - Operates on a channel object descriptor.
17 * - event creation, returns an object descriptor or failure.
18 * - Operates on a channel object descriptor
19 * - Takes an event name as parameter
20 * - Takes an instrumentation source as parameter
21 * - e.g. tracepoints, dynamic_probes...
22 * - Takes instrumentation source specific arguments.
23 *
24 * Dual LGPL v2.1/GPL v2 license.
25 */
26
27 #include <lttng/ust-abi.h>
28 #include <urcu/compiler.h>
29 #include <urcu/list.h>
30 #include <lttng/ust-events.h>
31 #include <lttng/usterr-signal-safe.h>
32 #include "lttng/core.h"
33 #include "ltt-tracer.h"
34
35 static int lttng_ust_abi_close_in_progress;
36
37 static
38 int lttng_abi_tracepoint_list(void);
39
40 /*
41 * Object descriptor table. Should be protected from concurrent access
42 * by the caller.
43 */
44
45 struct lttng_ust_obj {
46 union {
47 struct {
48 void *private_data;
49 const struct lttng_ust_objd_ops *ops;
50 int f_count;
51 } s;
52 int freelist_next; /* offset freelist. end is -1. */
53 } u;
54 };
55
56 struct lttng_ust_objd_table {
57 struct lttng_ust_obj *array;
58 unsigned int len, allocated_len;
59 int freelist_head; /* offset freelist head. end is -1 */
60 };
61
62 static struct lttng_ust_objd_table objd_table = {
63 .freelist_head = -1,
64 };
65
66 static
67 int objd_alloc(void *private_data, const struct lttng_ust_objd_ops *ops)
68 {
69 struct lttng_ust_obj *obj;
70
71 if (objd_table.freelist_head != -1) {
72 obj = &objd_table.array[objd_table.freelist_head];
73 objd_table.freelist_head = obj->u.freelist_next;
74 goto end;
75 }
76
77 if (objd_table.len >= objd_table.allocated_len) {
78 unsigned int new_allocated_len, old_allocated_len;
79 struct lttng_ust_obj *new_table, *old_table;
80
81 old_allocated_len = objd_table.allocated_len;
82 old_table = objd_table.array;
83 if (!old_allocated_len)
84 new_allocated_len = 1;
85 else
86 new_allocated_len = old_allocated_len << 1;
87 new_table = zmalloc(sizeof(struct lttng_ust_obj) * new_allocated_len);
88 if (!new_table)
89 return -ENOMEM;
90 memcpy(new_table, old_table,
91 sizeof(struct lttng_ust_obj) * old_allocated_len);
92 free(old_table);
93 objd_table.array = new_table;
94 objd_table.allocated_len = new_allocated_len;
95 }
96 obj = &objd_table.array[objd_table.len];
97 objd_table.len++;
98 end:
99 obj->u.s.private_data = private_data;
100 obj->u.s.ops = ops;
101 obj->u.s.f_count = 2; /* count == 1 : object is allocated */
102 /* count == 2 : allocated + hold ref */
103 return obj - objd_table.array;
104 }
105
106 static
107 struct lttng_ust_obj *_objd_get(int id)
108 {
109 if (id >= objd_table.len)
110 return NULL;
111 if (!objd_table.array[id].u.s.f_count)
112 return NULL;
113 return &objd_table.array[id];
114 }
115
116 static
117 void *objd_private(int id)
118 {
119 struct lttng_ust_obj *obj = _objd_get(id);
120 assert(obj);
121 return obj->u.s.private_data;
122 }
123
124 static
125 void objd_set_private(int id, void *private_data)
126 {
127 struct lttng_ust_obj *obj = _objd_get(id);
128 assert(obj);
129 obj->u.s.private_data = private_data;
130 }
131
132 const struct lttng_ust_objd_ops *objd_ops(int id)
133 {
134 struct lttng_ust_obj *obj = _objd_get(id);
135
136 if (!obj)
137 return NULL;
138 return obj->u.s.ops;
139 }
140
141 static
142 void objd_free(int id)
143 {
144 struct lttng_ust_obj *obj = _objd_get(id);
145
146 assert(obj);
147 obj->u.freelist_next = objd_table.freelist_head;
148 objd_table.freelist_head = obj - objd_table.array;
149 assert(obj->u.s.f_count == 1);
150 obj->u.s.f_count = 0; /* deallocated */
151 }
152
153 static
154 void objd_ref(int id)
155 {
156 struct lttng_ust_obj *obj = _objd_get(id);
157 obj->u.s.f_count++;
158 }
159
160 int lttng_ust_objd_unref(int id)
161 {
162 struct lttng_ust_obj *obj = _objd_get(id);
163
164 if (!obj)
165 return -EINVAL;
166 if (obj->u.s.f_count == 1) {
167 ERR("Reference counting error\n");
168 return -EINVAL;
169 }
170 if ((--obj->u.s.f_count) == 1) {
171 const struct lttng_ust_objd_ops *ops = objd_ops(id);
172
173 if (ops->release)
174 ops->release(id);
175 objd_free(id);
176 }
177 return 0;
178 }
179
180 static
181 void objd_table_destroy(void)
182 {
183 int i;
184
185 for (i = 0; i < objd_table.allocated_len; i++)
186 (void) lttng_ust_objd_unref(i);
187 free(objd_table.array);
188 objd_table.array = NULL;
189 objd_table.len = 0;
190 objd_table.allocated_len = 0;
191 objd_table.freelist_head = -1;
192 }
193
194 /*
195 * This is LTTng's own personal way to create an ABI for sessiond.
196 * We send commands over a socket.
197 */
198
199 static const struct lttng_ust_objd_ops lttng_ops;
200 static const struct lttng_ust_objd_ops lttng_session_ops;
201 static const struct lttng_ust_objd_ops lttng_channel_ops;
202 static const struct lttng_ust_objd_ops lttng_metadata_ops;
203 static const struct lttng_ust_objd_ops lttng_event_ops;
204 static const struct lttng_ust_objd_ops lib_ring_buffer_objd_ops;
205 static const struct lttng_ust_objd_ops lttng_tracepoint_list_ops;
206
207 enum channel_type {
208 PER_CPU_CHANNEL,
209 METADATA_CHANNEL,
210 };
211
212 int lttng_abi_create_root_handle(void)
213 {
214 int root_handle;
215
216 root_handle = objd_alloc(NULL, &lttng_ops);
217 return root_handle;
218 }
219
220 static
221 int lttng_abi_create_session(void)
222 {
223 struct ltt_session *session;
224 int session_objd, ret;
225
226 session = ltt_session_create();
227 if (!session)
228 return -ENOMEM;
229 session_objd = objd_alloc(session, &lttng_session_ops);
230 if (session_objd < 0) {
231 ret = session_objd;
232 goto objd_error;
233 }
234 session->objd = session_objd;
235 return session_objd;
236
237 objd_error:
238 ltt_session_destroy(session);
239 return ret;
240 }
241
242 static
243 long lttng_abi_tracer_version(int objd,
244 struct lttng_ust_tracer_version *v)
245 {
246 v->version = LTTNG_UST_VERSION;
247 v->patchlevel = LTTNG_UST_PATCHLEVEL;
248 v->sublevel = LTTNG_UST_SUBLEVEL;
249 return 0;
250 }
251
252 static
253 long lttng_abi_add_context(int objd,
254 struct lttng_ust_context *context_param,
255 struct lttng_ctx **ctx, struct ltt_session *session)
256 {
257 if (session->been_active)
258 return -EPERM;
259
260 switch (context_param->ctx) {
261 case LTTNG_UST_CONTEXT_PTHREAD_ID:
262 return lttng_add_pthread_id_to_ctx(ctx);
263 case LTTNG_UST_CONTEXT_VTID:
264 return lttng_add_vtid_to_ctx(ctx);
265 case LTTNG_UST_CONTEXT_VPID:
266 return lttng_add_vpid_to_ctx(ctx);
267 case LTTNG_UST_CONTEXT_PROCNAME:
268 return lttng_add_procname_to_ctx(ctx);
269 default:
270 return -EINVAL;
271 }
272 }
273
274 /**
275 * lttng_cmd - lttng control through socket commands
276 *
277 * @objd: the object descriptor
278 * @cmd: the command
279 * @arg: command arg
280 *
281 * This descriptor implements lttng commands:
282 * LTTNG_UST_SESSION
283 * Returns a LTTng trace session object descriptor
284 * LTTNG_UST_TRACER_VERSION
285 * Returns the LTTng kernel tracer version
286 * LTTNG_UST_TRACEPOINT_LIST
287 * Returns a file descriptor listing available tracepoints
288 * LTTNG_UST_WAIT_QUIESCENT
289 * Returns after all previously running probes have completed
290 *
291 * The returned session will be deleted when its file descriptor is closed.
292 */
293 static
294 long lttng_cmd(int objd, unsigned int cmd, unsigned long arg)
295 {
296 switch (cmd) {
297 case LTTNG_UST_SESSION:
298 return lttng_abi_create_session();
299 case LTTNG_UST_TRACER_VERSION:
300 return lttng_abi_tracer_version(objd,
301 (struct lttng_ust_tracer_version *) arg);
302 case LTTNG_UST_TRACEPOINT_LIST:
303 return lttng_abi_tracepoint_list();
304 case LTTNG_UST_WAIT_QUIESCENT:
305 synchronize_trace();
306 return 0;
307 default:
308 return -EINVAL;
309 }
310 }
311
312 static const struct lttng_ust_objd_ops lttng_ops = {
313 .cmd = lttng_cmd,
314 };
315
316 /*
317 * We tolerate no failure in this function (if one happens, we print a dmesg
318 * error, but cannot return any error, because the channel information is
319 * invariant.
320 */
321 static
322 void lttng_metadata_create_events(int channel_objd)
323 {
324 struct ltt_channel *channel = objd_private(channel_objd);
325 static struct lttng_ust_event metadata_params = {
326 .instrumentation = LTTNG_UST_TRACEPOINT,
327 .name = "lttng_ust:metadata",
328 };
329 struct ltt_event *event;
330
331 /*
332 * We tolerate no failure path after event creation. It will stay
333 * invariant for the rest of the session.
334 */
335 event = ltt_event_create(channel, &metadata_params, NULL);
336 if (!event) {
337 goto create_error;
338 }
339 return;
340
341 create_error:
342 WARN_ON(1);
343 return; /* not allowed to return error */
344 }
345
346 int lttng_abi_create_channel(int session_objd,
347 struct lttng_ust_channel *chan_param,
348 enum channel_type channel_type)
349 {
350 struct ltt_session *session = objd_private(session_objd);
351 const struct lttng_ust_objd_ops *ops;
352 const char *transport_name;
353 struct ltt_channel *chan;
354 int chan_objd;
355 int ret = 0;
356 struct ltt_channel chan_priv_init;
357
358 switch (channel_type) {
359 case PER_CPU_CHANNEL:
360 if (chan_param->output == LTTNG_UST_MMAP) {
361 transport_name = chan_param->overwrite ?
362 "relay-overwrite-mmap" : "relay-discard-mmap";
363 } else {
364 return -EINVAL;
365 }
366 ops = &lttng_channel_ops;
367 break;
368 case METADATA_CHANNEL:
369 if (chan_param->output == LTTNG_UST_MMAP)
370 transport_name = "relay-metadata-mmap";
371 else
372 return -EINVAL;
373 ops = &lttng_metadata_ops;
374 break;
375 default:
376 transport_name = "<unknown>";
377 return -EINVAL;
378 }
379 chan_objd = objd_alloc(NULL, ops);
380 if (chan_objd < 0) {
381 ret = chan_objd;
382 goto objd_error;
383 }
384 memset(&chan_priv_init, 0, sizeof(chan_priv_init));
385 /* Copy of session UUID for consumer (availability through shm) */
386 memcpy(chan_priv_init.uuid, session->uuid, sizeof(session->uuid));
387
388 /*
389 * We tolerate no failure path after channel creation. It will stay
390 * invariant for the rest of the session.
391 */
392 chan = ltt_channel_create(session, transport_name, NULL,
393 chan_param->subbuf_size,
394 chan_param->num_subbuf,
395 chan_param->switch_timer_interval,
396 chan_param->read_timer_interval,
397 &chan_param->shm_fd,
398 &chan_param->wait_fd,
399 &chan_param->memory_map_size,
400 &chan_priv_init);
401 if (!chan) {
402 ret = -EINVAL;
403 goto chan_error;
404 }
405 objd_set_private(chan_objd, chan);
406 chan->objd = chan_objd;
407 if (channel_type == METADATA_CHANNEL) {
408 session->metadata = chan;
409 lttng_metadata_create_events(chan_objd);
410 }
411 /* The channel created holds a reference on the session */
412 objd_ref(session_objd);
413
414 return chan_objd;
415
416 chan_error:
417 {
418 int err;
419
420 err = lttng_ust_objd_unref(chan_objd);
421 assert(!err);
422 }
423 objd_error:
424 return ret;
425 }
426
427 /**
428 * lttng_session_cmd - lttng session object command
429 *
430 * @obj: the object
431 * @cmd: the command
432 * @arg: command arg
433 *
434 * This descriptor implements lttng commands:
435 * LTTNG_UST_CHANNEL
436 * Returns a LTTng channel object descriptor
437 * LTTNG_UST_ENABLE
438 * Enables tracing for a session (weak enable)
439 * LTTNG_UST_DISABLE
440 * Disables tracing for a session (strong disable)
441 * LTTNG_UST_METADATA
442 * Returns a LTTng metadata object descriptor
443 *
444 * The returned channel will be deleted when its file descriptor is closed.
445 */
446 static
447 long lttng_session_cmd(int objd, unsigned int cmd, unsigned long arg)
448 {
449 struct ltt_session *session = objd_private(objd);
450
451 switch (cmd) {
452 case LTTNG_UST_CHANNEL:
453 return lttng_abi_create_channel(objd,
454 (struct lttng_ust_channel *) arg,
455 PER_CPU_CHANNEL);
456 case LTTNG_UST_SESSION_START:
457 case LTTNG_UST_ENABLE:
458 return ltt_session_enable(session);
459 case LTTNG_UST_SESSION_STOP:
460 case LTTNG_UST_DISABLE:
461 return ltt_session_disable(session);
462 case LTTNG_UST_METADATA:
463 return lttng_abi_create_channel(objd,
464 (struct lttng_ust_channel *) arg,
465 METADATA_CHANNEL);
466 default:
467 return -EINVAL;
468 }
469 }
470
471 /*
472 * Called when the last file reference is dropped.
473 *
474 * Big fat note: channels and events are invariant for the whole session after
475 * their creation. So this session destruction also destroys all channel and
476 * event structures specific to this session (they are not destroyed when their
477 * individual file is released).
478 */
479 static
480 int lttng_release_session(int objd)
481 {
482 struct ltt_session *session = objd_private(objd);
483
484 if (session) {
485 ltt_session_destroy(session);
486 return 0;
487 } else {
488 return -EINVAL;
489 }
490 }
491
492 static const struct lttng_ust_objd_ops lttng_session_ops = {
493 .release = lttng_release_session,
494 .cmd = lttng_session_cmd,
495 };
496
497 /*
498 * beware: we don't keep the mutex over the send, but we must walk the
499 * whole list each time we are called again. So sending one tracepoint
500 * at a time means this is O(n^2). TODO: do as in the kernel and send
501 * multiple tracepoints for each call to amortize this cost.
502 */
503 static
504 void ltt_tracepoint_list_get(struct ltt_tracepoint_list *list,
505 char *tp_list_entry)
506 {
507 next:
508 if (!list->got_first) {
509 tracepoint_iter_start(&list->iter);
510 list->got_first = 1;
511 goto copy;
512 }
513 tracepoint_iter_next(&list->iter);
514 copy:
515 if (!list->iter.tracepoint) {
516 tp_list_entry[0] = '\0'; /* end of list */
517 } else {
518 if (!strcmp((*list->iter.tracepoint)->name,
519 "lttng_ust:metadata"))
520 goto next;
521 memcpy(tp_list_entry, (*list->iter.tracepoint)->name,
522 LTTNG_UST_SYM_NAME_LEN);
523 }
524 }
525
526 static
527 long lttng_tracepoint_list_cmd(int objd, unsigned int cmd, unsigned long arg)
528 {
529 struct ltt_tracepoint_list *list = objd_private(objd);
530 char *str = (char *) arg;
531
532 switch (cmd) {
533 case LTTNG_UST_TRACEPOINT_LIST_GET:
534 ltt_tracepoint_list_get(list, str);
535 if (str[0] == '\0')
536 return -ENOENT;
537 return 0;
538 default:
539 return -EINVAL;
540 }
541 }
542
543 static
544 int lttng_abi_tracepoint_list(void)
545 {
546 int list_objd, ret;
547 struct ltt_tracepoint_list *list;
548
549 list_objd = objd_alloc(NULL, &lttng_tracepoint_list_ops);
550 if (list_objd < 0) {
551 ret = list_objd;
552 goto objd_error;
553 }
554 list = zmalloc(sizeof(*list));
555 if (!list) {
556 ret = -ENOMEM;
557 goto alloc_error;
558 }
559 objd_set_private(list_objd, list);
560
561 return list_objd;
562
563 alloc_error:
564 {
565 int err;
566
567 err = lttng_ust_objd_unref(list_objd);
568 assert(!err);
569 }
570 objd_error:
571 return ret;
572 }
573
574 static
575 int lttng_release_tracepoint_list(int objd)
576 {
577 struct ltt_tracepoint_list *list = objd_private(objd);
578
579 if (list) {
580 tracepoint_iter_stop(&list->iter);
581 free(list);
582 return 0;
583 } else {
584 return -EINVAL;
585 }
586 }
587
588 static const struct lttng_ust_objd_ops lttng_tracepoint_list_ops = {
589 .release = lttng_release_tracepoint_list,
590 .cmd = lttng_tracepoint_list_cmd,
591 };
592
593 struct stream_priv_data {
594 struct lttng_ust_lib_ring_buffer *buf;
595 struct ltt_channel *ltt_chan;
596 };
597
598 static
599 int lttng_abi_open_stream(int channel_objd, struct lttng_ust_stream *info)
600 {
601 struct ltt_channel *channel = objd_private(channel_objd);
602 struct lttng_ust_lib_ring_buffer *buf;
603 struct stream_priv_data *priv;
604 int stream_objd, ret;
605
606 buf = channel->ops->buffer_read_open(channel->chan, channel->handle,
607 &info->shm_fd, &info->wait_fd, &info->memory_map_size);
608 if (!buf)
609 return -ENOENT;
610
611 priv = zmalloc(sizeof(*priv));
612 if (!priv) {
613 ret = -ENOMEM;
614 goto alloc_error;
615 }
616 priv->buf = buf;
617 priv->ltt_chan = channel;
618 stream_objd = objd_alloc(priv, &lib_ring_buffer_objd_ops);
619 if (stream_objd < 0) {
620 ret = stream_objd;
621 goto objd_error;
622 }
623 /* Hold a reference on the channel object descriptor */
624 objd_ref(channel_objd);
625 return stream_objd;
626
627 objd_error:
628 free(priv);
629 alloc_error:
630 channel->ops->buffer_read_close(buf, channel->handle);
631 return ret;
632 }
633
634 static
635 int lttng_abi_create_event(int channel_objd,
636 struct lttng_ust_event *event_param)
637 {
638 struct ltt_channel *channel = objd_private(channel_objd);
639 struct ltt_event *event;
640 int event_objd, ret;
641
642 event_param->name[LTTNG_UST_SYM_NAME_LEN - 1] = '\0';
643 event_objd = objd_alloc(NULL, &lttng_event_ops);
644 if (event_objd < 0) {
645 ret = event_objd;
646 goto objd_error;
647 }
648 /*
649 * We tolerate no failure path after event creation. It will stay
650 * invariant for the rest of the session.
651 */
652 event = ltt_event_create(channel, event_param, NULL);
653 if (!event) {
654 ret = -EINVAL;
655 goto event_error;
656 }
657 objd_set_private(event_objd, event);
658 /* The event holds a reference on the channel */
659 objd_ref(channel_objd);
660 return event_objd;
661
662 event_error:
663 {
664 int err;
665
666 err = lttng_ust_objd_unref(event_objd);
667 assert(!err);
668 }
669 objd_error:
670 return ret;
671 }
672
673 /**
674 * lttng_channel_cmd - lttng control through object descriptors
675 *
676 * @objd: the object descriptor
677 * @cmd: the command
678 * @arg: command arg
679 *
680 * This object descriptor implements lttng commands:
681 * LTTNG_UST_STREAM
682 * Returns an event stream object descriptor or failure.
683 * (typically, one event stream records events from one CPU)
684 * LTTNG_UST_EVENT
685 * Returns an event object descriptor or failure.
686 * LTTNG_UST_CONTEXT
687 * Prepend a context field to each event in the channel
688 * LTTNG_UST_ENABLE
689 * Enable recording for events in this channel (weak enable)
690 * LTTNG_UST_DISABLE
691 * Disable recording for events in this channel (strong disable)
692 *
693 * Channel and event file descriptors also hold a reference on the session.
694 */
695 static
696 long lttng_channel_cmd(int objd, unsigned int cmd, unsigned long arg)
697 {
698 struct ltt_channel *channel = objd_private(objd);
699
700 switch (cmd) {
701 case LTTNG_UST_STREAM:
702 {
703 struct lttng_ust_stream *stream;
704
705 stream = (struct lttng_ust_stream *) arg;
706 /* stream used as output */
707 return lttng_abi_open_stream(objd, stream);
708 }
709 case LTTNG_UST_EVENT:
710 return lttng_abi_create_event(objd, (struct lttng_ust_event *) arg);
711 case LTTNG_UST_CONTEXT:
712 return lttng_abi_add_context(objd,
713 (struct lttng_ust_context *) arg,
714 &channel->ctx, channel->session);
715 case LTTNG_UST_ENABLE:
716 return ltt_channel_enable(channel);
717 case LTTNG_UST_DISABLE:
718 return ltt_channel_disable(channel);
719 case LTTNG_UST_FLUSH_BUFFER:
720 return channel->ops->flush_buffer(channel->chan, channel->handle);
721 default:
722 return -EINVAL;
723 }
724 }
725
726 /**
727 * lttng_metadata_cmd - lttng control through object descriptors
728 *
729 * @objd: the object descriptor
730 * @cmd: the command
731 * @arg: command arg
732 *
733 * This object descriptor implements lttng commands:
734 * LTTNG_UST_STREAM
735 * Returns an event stream file descriptor or failure.
736 *
737 * Channel and event file descriptors also hold a reference on the session.
738 */
739 static
740 long lttng_metadata_cmd(int objd, unsigned int cmd, unsigned long arg)
741 {
742 struct ltt_channel *channel = objd_private(objd);
743
744 switch (cmd) {
745 case LTTNG_UST_STREAM:
746 {
747 struct lttng_ust_stream *stream;
748
749 stream = (struct lttng_ust_stream *) arg;
750 /* stream used as output */
751 return lttng_abi_open_stream(objd, stream);
752 }
753 case LTTNG_UST_FLUSH_BUFFER:
754 return channel->ops->flush_buffer(channel->chan, channel->handle);
755 default:
756 return -EINVAL;
757 }
758 }
759
760 #if 0
761 /**
762 * lttng_channel_poll - lttng stream addition/removal monitoring
763 *
764 * @file: the file
765 * @wait: poll table
766 */
767 unsigned int lttng_channel_poll(struct file *file, poll_table *wait)
768 {
769 struct ltt_channel *channel = file->private_data;
770 unsigned int mask = 0;
771
772 if (file->f_mode & FMODE_READ) {
773 poll_wait_set_exclusive(wait);
774 poll_wait(file, channel->ops->get_hp_wait_queue(channel->chan),
775 wait);
776
777 if (channel->ops->is_disabled(channel->chan))
778 return POLLERR;
779 if (channel->ops->is_finalized(channel->chan))
780 return POLLHUP;
781 if (channel->ops->buffer_has_read_closed_stream(channel->chan))
782 return POLLIN | POLLRDNORM;
783 return 0;
784 }
785 return mask;
786
787 }
788 #endif //0
789
790 static
791 int lttng_channel_release(int objd)
792 {
793 struct ltt_channel *channel = objd_private(objd);
794
795 if (channel)
796 return lttng_ust_objd_unref(channel->session->objd);
797 return 0;
798 }
799
800 static const struct lttng_ust_objd_ops lttng_channel_ops = {
801 .release = lttng_channel_release,
802 //.poll = lttng_channel_poll,
803 .cmd = lttng_channel_cmd,
804 };
805
806 static const struct lttng_ust_objd_ops lttng_metadata_ops = {
807 .release = lttng_channel_release,
808 .cmd = lttng_metadata_cmd,
809 };
810
811 /**
812 * lttng_rb_cmd - lttng ring buffer control through object descriptors
813 *
814 * @objd: the object descriptor
815 * @cmd: the command
816 * @arg: command arg
817 *
818 * This object descriptor implements lttng commands:
819 * (None for now. Access is done directly though shm.)
820 */
821 static
822 long lttng_rb_cmd(int objd, unsigned int cmd, unsigned long arg)
823 {
824 switch (cmd) {
825 default:
826 return -EINVAL;
827 }
828 }
829
830 static
831 int lttng_rb_release(int objd)
832 {
833 struct stream_priv_data *priv = objd_private(objd);
834 struct lttng_ust_lib_ring_buffer *buf;
835 struct ltt_channel *channel;
836
837 if (priv) {
838 buf = priv->buf;
839 channel = priv->ltt_chan;
840 free(priv);
841 /*
842 * If we are at ABI exit, we don't want to close the
843 * buffer opened for read: it is being shared between
844 * the parent and child (right after fork), and we don't
845 * want the child to close it for the parent. For a real
846 * exit, we don't care about marking it as closed, as
847 * the consumer daemon (if there is one) will do fine
848 * even if we don't mark it as "closed" for reading on
849 * our side.
850 * We only mark it as closed if it is being explicitely
851 * released by the session daemon with an explicit
852 * release command.
853 */
854 if (!lttng_ust_abi_close_in_progress)
855 channel->ops->buffer_read_close(buf, channel->handle);
856
857 return lttng_ust_objd_unref(channel->objd);
858 }
859 return 0;
860 }
861
862 static const struct lttng_ust_objd_ops lib_ring_buffer_objd_ops = {
863 .release = lttng_rb_release,
864 .cmd = lttng_rb_cmd,
865 };
866
867 /**
868 * lttng_event_cmd - lttng control through object descriptors
869 *
870 * @objd: the object descriptor
871 * @cmd: the command
872 * @arg: command arg
873 *
874 * This object descriptor implements lttng commands:
875 * LTTNG_UST_CONTEXT
876 * Prepend a context field to each record of this event
877 * LTTNG_UST_ENABLE
878 * Enable recording for this event (weak enable)
879 * LTTNG_UST_DISABLE
880 * Disable recording for this event (strong disable)
881 */
882 static
883 long lttng_event_cmd(int objd, unsigned int cmd, unsigned long arg)
884 {
885 struct ltt_event *event = objd_private(objd);
886
887 switch (cmd) {
888 case LTTNG_UST_CONTEXT:
889 return lttng_abi_add_context(objd,
890 (struct lttng_ust_context *) arg,
891 &event->ctx, event->chan->session);
892 case LTTNG_UST_ENABLE:
893 return ltt_event_enable(event);
894 case LTTNG_UST_DISABLE:
895 return ltt_event_disable(event);
896 default:
897 return -EINVAL;
898 }
899 }
900
901 static
902 int lttng_event_release(int objd)
903 {
904 struct ltt_event *event = objd_private(objd);
905
906 if (event)
907 return lttng_ust_objd_unref(event->chan->objd);
908 return 0;
909 }
910
911 /* TODO: filter control ioctl */
912 static const struct lttng_ust_objd_ops lttng_event_ops = {
913 .release = lttng_event_release,
914 .cmd = lttng_event_cmd,
915 };
916
917 void lttng_ust_abi_exit(void)
918 {
919 lttng_ust_abi_close_in_progress = 1;
920 objd_table_destroy();
921 lttng_ust_abi_close_in_progress = 0;
922 }
This page took 0.057467 seconds and 5 git commands to generate.