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