Remove old (now unused) loglevel control code entirely
[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_wildcard_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 * @uargs: UST arguments (internal)
284 *
285 * This descriptor implements lttng commands:
286 * LTTNG_UST_SESSION
287 * Returns a LTTng trace session object descriptor
288 * LTTNG_UST_TRACER_VERSION
289 * Returns the LTTng kernel tracer version
290 * LTTNG_UST_TRACEPOINT_LIST
291 * Returns a file descriptor listing available tracepoints
292 * LTTNG_UST_WAIT_QUIESCENT
293 * Returns after all previously running probes have completed
294 *
295 * The returned session will be deleted when its file descriptor is closed.
296 */
297 static
298 long lttng_cmd(int objd, unsigned int cmd, unsigned long arg,
299 union ust_args *uargs)
300 {
301 switch (cmd) {
302 case LTTNG_UST_SESSION:
303 return lttng_abi_create_session();
304 case LTTNG_UST_TRACER_VERSION:
305 return lttng_abi_tracer_version(objd,
306 (struct lttng_ust_tracer_version *) arg);
307 case LTTNG_UST_TRACEPOINT_LIST:
308 return lttng_abi_tracepoint_list();
309 case LTTNG_UST_WAIT_QUIESCENT:
310 synchronize_trace();
311 return 0;
312 default:
313 return -EINVAL;
314 }
315 }
316
317 static const struct lttng_ust_objd_ops lttng_ops = {
318 .cmd = lttng_cmd,
319 };
320
321 /*
322 * We tolerate no failure in this function (if one happens, we print a dmesg
323 * error, but cannot return any error, because the channel information is
324 * invariant.
325 */
326 static
327 void lttng_metadata_create_events(int channel_objd)
328 {
329 struct ltt_channel *channel = objd_private(channel_objd);
330 static struct lttng_ust_event metadata_params = {
331 .instrumentation = LTTNG_UST_TRACEPOINT,
332 .name = "lttng_ust:metadata",
333 };
334 struct ltt_event *event;
335 int ret;
336
337 /*
338 * We tolerate no failure path after event creation. It will stay
339 * invariant for the rest of the session.
340 */
341 ret = ltt_event_create(channel, &metadata_params, NULL, &event);
342 if (ret < 0) {
343 goto create_error;
344 }
345 return;
346
347 create_error:
348 WARN_ON(1);
349 return; /* not allowed to return error */
350 }
351
352 int lttng_abi_create_channel(int session_objd,
353 struct lttng_ust_channel *chan_param,
354 enum channel_type channel_type,
355 union ust_args *uargs)
356 {
357 struct ltt_session *session = objd_private(session_objd);
358 const struct lttng_ust_objd_ops *ops;
359 const char *transport_name;
360 struct ltt_channel *chan;
361 int chan_objd;
362 int ret = 0;
363 struct ltt_channel chan_priv_init;
364
365 switch (channel_type) {
366 case PER_CPU_CHANNEL:
367 if (chan_param->output == LTTNG_UST_MMAP) {
368 transport_name = chan_param->overwrite ?
369 "relay-overwrite-mmap" : "relay-discard-mmap";
370 } else {
371 return -EINVAL;
372 }
373 ops = &lttng_channel_ops;
374 break;
375 case METADATA_CHANNEL:
376 if (chan_param->output == LTTNG_UST_MMAP)
377 transport_name = "relay-metadata-mmap";
378 else
379 return -EINVAL;
380 ops = &lttng_metadata_ops;
381 break;
382 default:
383 transport_name = "<unknown>";
384 return -EINVAL;
385 }
386 chan_objd = objd_alloc(NULL, ops);
387 if (chan_objd < 0) {
388 ret = chan_objd;
389 goto objd_error;
390 }
391 memset(&chan_priv_init, 0, sizeof(chan_priv_init));
392 /* Copy of session UUID for consumer (availability through shm) */
393 memcpy(chan_priv_init.uuid, session->uuid, sizeof(session->uuid));
394
395 /*
396 * We tolerate no failure path after channel creation. It will stay
397 * invariant for the rest of the session.
398 */
399 chan = ltt_channel_create(session, transport_name, NULL,
400 chan_param->subbuf_size,
401 chan_param->num_subbuf,
402 chan_param->switch_timer_interval,
403 chan_param->read_timer_interval,
404 &uargs->channel.shm_fd,
405 &uargs->channel.wait_fd,
406 &uargs->channel.memory_map_size,
407 &chan_priv_init);
408 if (!chan) {
409 ret = -EINVAL;
410 goto chan_error;
411 }
412 objd_set_private(chan_objd, chan);
413 chan->objd = chan_objd;
414 if (channel_type == METADATA_CHANNEL) {
415 session->metadata = chan;
416 lttng_metadata_create_events(chan_objd);
417 }
418 /* The channel created holds a reference on the session */
419 objd_ref(session_objd);
420
421 return chan_objd;
422
423 chan_error:
424 {
425 int err;
426
427 err = lttng_ust_objd_unref(chan_objd);
428 assert(!err);
429 }
430 objd_error:
431 return ret;
432 }
433
434 /**
435 * lttng_session_cmd - lttng session object command
436 *
437 * @obj: the object
438 * @cmd: the command
439 * @arg: command arg
440 * @uargs: UST arguments (internal)
441 *
442 * This descriptor implements lttng commands:
443 * LTTNG_UST_CHANNEL
444 * Returns a LTTng channel object descriptor
445 * LTTNG_UST_ENABLE
446 * Enables tracing for a session (weak enable)
447 * LTTNG_UST_DISABLE
448 * Disables tracing for a session (strong disable)
449 * LTTNG_UST_METADATA
450 * Returns a LTTng metadata object descriptor
451 *
452 * The returned channel will be deleted when its file descriptor is closed.
453 */
454 static
455 long lttng_session_cmd(int objd, unsigned int cmd, unsigned long arg,
456 union ust_args *uargs)
457 {
458 struct ltt_session *session = objd_private(objd);
459
460 switch (cmd) {
461 case LTTNG_UST_CHANNEL:
462 return lttng_abi_create_channel(objd,
463 (struct lttng_ust_channel *) arg,
464 PER_CPU_CHANNEL, uargs);
465 case LTTNG_UST_SESSION_START:
466 case LTTNG_UST_ENABLE:
467 return ltt_session_enable(session);
468 case LTTNG_UST_SESSION_STOP:
469 case LTTNG_UST_DISABLE:
470 return ltt_session_disable(session);
471 case LTTNG_UST_METADATA:
472 return lttng_abi_create_channel(objd,
473 (struct lttng_ust_channel *) arg,
474 METADATA_CHANNEL, uargs);
475 default:
476 return -EINVAL;
477 }
478 }
479
480 /*
481 * Called when the last file reference is dropped.
482 *
483 * Big fat note: channels and events are invariant for the whole session after
484 * their creation. So this session destruction also destroys all channel and
485 * event structures specific to this session (they are not destroyed when their
486 * individual file is released).
487 */
488 static
489 int lttng_release_session(int objd)
490 {
491 struct ltt_session *session = objd_private(objd);
492
493 if (session) {
494 ltt_session_destroy(session);
495 return 0;
496 } else {
497 return -EINVAL;
498 }
499 }
500
501 static const struct lttng_ust_objd_ops lttng_session_ops = {
502 .release = lttng_release_session,
503 .cmd = lttng_session_cmd,
504 };
505
506 static
507 long lttng_tracepoint_list_cmd(int objd, unsigned int cmd, unsigned long arg,
508 union ust_args *uargs)
509 {
510 struct lttng_ust_tracepoint_list *list = objd_private(objd);
511 struct lttng_ust_tracepoint_iter *tp =
512 (struct lttng_ust_tracepoint_iter *) arg;
513 struct lttng_ust_tracepoint_iter *iter;
514
515 switch (cmd) {
516 case LTTNG_UST_TRACEPOINT_LIST_GET:
517 {
518 retry:
519 iter = lttng_ust_tracepoint_list_get_iter_next(list);
520 if (!iter)
521 return -ENOENT;
522 if (!strcmp(iter->name, "lttng_ust:metadata"))
523 goto retry;
524 memcpy(tp, iter, sizeof(*tp));
525 return 0;
526 }
527 default:
528 return -EINVAL;
529 }
530 }
531
532 static
533 int lttng_abi_tracepoint_list(void)
534 {
535 int list_objd, ret;
536 struct lttng_ust_tracepoint_list *list;
537
538 list_objd = objd_alloc(NULL, &lttng_tracepoint_list_ops);
539 if (list_objd < 0) {
540 ret = list_objd;
541 goto objd_error;
542 }
543 list = zmalloc(sizeof(*list));
544 if (!list) {
545 ret = -ENOMEM;
546 goto alloc_error;
547 }
548 objd_set_private(list_objd, list);
549
550 /* populate list by walking on all registered probes. */
551 ret = ltt_probes_get_event_list(list);
552 if (ret) {
553 goto list_error;
554 }
555 return list_objd;
556
557 list_error:
558 free(list);
559 alloc_error:
560 {
561 int err;
562
563 err = lttng_ust_objd_unref(list_objd);
564 assert(!err);
565 }
566 objd_error:
567 return ret;
568 }
569
570 static
571 int lttng_release_tracepoint_list(int objd)
572 {
573 struct lttng_ust_tracepoint_list *list = objd_private(objd);
574
575 if (list) {
576 ltt_probes_prune_event_list(list);
577 free(list);
578 return 0;
579 } else {
580 return -EINVAL;
581 }
582 }
583
584 static const struct lttng_ust_objd_ops lttng_tracepoint_list_ops = {
585 .release = lttng_release_tracepoint_list,
586 .cmd = lttng_tracepoint_list_cmd,
587 };
588
589 struct stream_priv_data {
590 struct lttng_ust_lib_ring_buffer *buf;
591 struct ltt_channel *ltt_chan;
592 };
593
594 static
595 int lttng_abi_open_stream(int channel_objd, struct lttng_ust_stream *info,
596 union ust_args *uargs)
597 {
598 struct ltt_channel *channel = objd_private(channel_objd);
599 struct lttng_ust_lib_ring_buffer *buf;
600 struct stream_priv_data *priv;
601 int stream_objd, ret;
602
603 buf = channel->ops->buffer_read_open(channel->chan, channel->handle,
604 &uargs->stream.shm_fd,
605 &uargs->stream.wait_fd,
606 &uargs->stream.memory_map_size);
607 if (!buf)
608 return -ENOENT;
609
610 priv = zmalloc(sizeof(*priv));
611 if (!priv) {
612 ret = -ENOMEM;
613 goto alloc_error;
614 }
615 priv->buf = buf;
616 priv->ltt_chan = channel;
617 stream_objd = objd_alloc(priv, &lib_ring_buffer_objd_ops);
618 if (stream_objd < 0) {
619 ret = stream_objd;
620 goto objd_error;
621 }
622 /* Hold a reference on the channel object descriptor */
623 objd_ref(channel_objd);
624 return stream_objd;
625
626 objd_error:
627 free(priv);
628 alloc_error:
629 channel->ops->buffer_read_close(buf, channel->handle);
630 return ret;
631 }
632
633 static
634 int lttng_abi_create_event(int channel_objd,
635 struct lttng_ust_event *event_param)
636 {
637 struct ltt_channel *channel = objd_private(channel_objd);
638 struct ltt_event *event;
639 int event_objd, ret;
640
641 event_param->name[LTTNG_UST_SYM_NAME_LEN - 1] = '\0';
642 event_objd = objd_alloc(NULL, &lttng_event_ops);
643 if (event_objd < 0) {
644 ret = event_objd;
645 goto objd_error;
646 }
647 /*
648 * We tolerate no failure path after event creation. It will stay
649 * invariant for the rest of the session.
650 */
651 ret = ltt_event_create(channel, event_param, NULL, &event);
652 if (ret < 0) {
653 goto event_error;
654 }
655 objd_set_private(event_objd, event);
656 /* The event holds a reference on the channel */
657 objd_ref(channel_objd);
658 return event_objd;
659
660 event_error:
661 {
662 int err;
663
664 err = lttng_ust_objd_unref(event_objd);
665 assert(!err);
666 }
667 objd_error:
668 return ret;
669 }
670
671 static
672 int lttng_abi_create_wildcard(int channel_objd,
673 struct lttng_ust_event *event_param)
674 {
675 struct ltt_channel *channel = objd_private(channel_objd);
676 struct session_wildcard *wildcard;
677 int wildcard_objd, ret;
678
679 event_param->name[LTTNG_UST_SYM_NAME_LEN - 1] = '\0';
680 wildcard_objd = objd_alloc(NULL, &lttng_wildcard_ops);
681 if (wildcard_objd < 0) {
682 ret = wildcard_objd;
683 goto objd_error;
684 }
685 /*
686 * We tolerate no failure path after wildcard creation. It will
687 * stay invariant for the rest of the session.
688 */
689 ret = ltt_wildcard_create(channel, event_param, &wildcard);
690 if (ret < 0) {
691 goto wildcard_error;
692 }
693 objd_set_private(wildcard_objd, wildcard);
694 /* The wildcard holds a reference on the channel */
695 objd_ref(channel_objd);
696 return wildcard_objd;
697
698 wildcard_error:
699 {
700 int err;
701
702 err = lttng_ust_objd_unref(wildcard_objd);
703 assert(!err);
704 }
705 objd_error:
706 return ret;
707 }
708
709 /**
710 * lttng_channel_cmd - lttng control through object descriptors
711 *
712 * @objd: the object descriptor
713 * @cmd: the command
714 * @arg: command arg
715 * @uargs: UST arguments (internal)
716 *
717 * This object descriptor implements lttng commands:
718 * LTTNG_UST_STREAM
719 * Returns an event stream object descriptor or failure.
720 * (typically, one event stream records events from one CPU)
721 * LTTNG_UST_EVENT
722 * Returns an event object descriptor or failure.
723 * LTTNG_UST_CONTEXT
724 * Prepend a context field to each event in the channel
725 * LTTNG_UST_ENABLE
726 * Enable recording for events in this channel (weak enable)
727 * LTTNG_UST_DISABLE
728 * Disable recording for events in this channel (strong disable)
729 *
730 * Channel and event file descriptors also hold a reference on the session.
731 */
732 static
733 long lttng_channel_cmd(int objd, unsigned int cmd, unsigned long arg,
734 union ust_args *uargs)
735 {
736 struct ltt_channel *channel = objd_private(objd);
737
738 switch (cmd) {
739 case LTTNG_UST_STREAM:
740 {
741 struct lttng_ust_stream *stream;
742
743 stream = (struct lttng_ust_stream *) arg;
744 /* stream used as output */
745 return lttng_abi_open_stream(objd, stream, uargs);
746 }
747 case LTTNG_UST_EVENT:
748 {
749 struct lttng_ust_event *event_param =
750 (struct lttng_ust_event *) arg;
751 if (event_param->name[strlen(event_param->name) - 1] == '*') {
752 /* If ends with wildcard, create wildcard. */
753 return lttng_abi_create_wildcard(objd, event_param);
754 } else {
755 return lttng_abi_create_event(objd, event_param);
756 }
757 }
758 case LTTNG_UST_CONTEXT:
759 return lttng_abi_add_context(objd,
760 (struct lttng_ust_context *) arg,
761 &channel->ctx, channel->session);
762 case LTTNG_UST_ENABLE:
763 return ltt_channel_enable(channel);
764 case LTTNG_UST_DISABLE:
765 return ltt_channel_disable(channel);
766 case LTTNG_UST_FLUSH_BUFFER:
767 return channel->ops->flush_buffer(channel->chan, channel->handle);
768 default:
769 return -EINVAL;
770 }
771 }
772
773 /**
774 * lttng_metadata_cmd - lttng control through object descriptors
775 *
776 * @objd: the object descriptor
777 * @cmd: the command
778 * @arg: command arg
779 * @uargs: UST arguments (internal)
780 *
781 * This object descriptor implements lttng commands:
782 * LTTNG_UST_STREAM
783 * Returns an event stream file descriptor or failure.
784 *
785 * Channel and event file descriptors also hold a reference on the session.
786 */
787 static
788 long lttng_metadata_cmd(int objd, unsigned int cmd, unsigned long arg,
789 union ust_args *uargs)
790 {
791 struct ltt_channel *channel = objd_private(objd);
792
793 switch (cmd) {
794 case LTTNG_UST_STREAM:
795 {
796 struct lttng_ust_stream *stream;
797
798 stream = (struct lttng_ust_stream *) arg;
799 /* stream used as output */
800 return lttng_abi_open_stream(objd, stream, uargs);
801 }
802 case LTTNG_UST_FLUSH_BUFFER:
803 return channel->ops->flush_buffer(channel->chan, channel->handle);
804 default:
805 return -EINVAL;
806 }
807 }
808
809 #if 0
810 /**
811 * lttng_channel_poll - lttng stream addition/removal monitoring
812 *
813 * @file: the file
814 * @wait: poll table
815 */
816 unsigned int lttng_channel_poll(struct file *file, poll_table *wait)
817 {
818 struct ltt_channel *channel = file->private_data;
819 unsigned int mask = 0;
820
821 if (file->f_mode & FMODE_READ) {
822 poll_wait_set_exclusive(wait);
823 poll_wait(file, channel->ops->get_hp_wait_queue(channel->chan),
824 wait);
825
826 if (channel->ops->is_disabled(channel->chan))
827 return POLLERR;
828 if (channel->ops->is_finalized(channel->chan))
829 return POLLHUP;
830 if (channel->ops->buffer_has_read_closed_stream(channel->chan))
831 return POLLIN | POLLRDNORM;
832 return 0;
833 }
834 return mask;
835
836 }
837 #endif //0
838
839 static
840 int lttng_channel_release(int objd)
841 {
842 struct ltt_channel *channel = objd_private(objd);
843
844 if (channel)
845 return lttng_ust_objd_unref(channel->session->objd);
846 return 0;
847 }
848
849 static const struct lttng_ust_objd_ops lttng_channel_ops = {
850 .release = lttng_channel_release,
851 //.poll = lttng_channel_poll,
852 .cmd = lttng_channel_cmd,
853 };
854
855 static const struct lttng_ust_objd_ops lttng_metadata_ops = {
856 .release = lttng_channel_release,
857 .cmd = lttng_metadata_cmd,
858 };
859
860 /**
861 * lttng_rb_cmd - lttng ring buffer control through object descriptors
862 *
863 * @objd: the object descriptor
864 * @cmd: the command
865 * @arg: command arg
866 * @uargs: UST arguments (internal)
867 *
868 * This object descriptor implements lttng commands:
869 * (None for now. Access is done directly though shm.)
870 */
871 static
872 long lttng_rb_cmd(int objd, unsigned int cmd, unsigned long arg,
873 union ust_args *uargs)
874 {
875 switch (cmd) {
876 default:
877 return -EINVAL;
878 }
879 }
880
881 static
882 int lttng_rb_release(int objd)
883 {
884 struct stream_priv_data *priv = objd_private(objd);
885 struct lttng_ust_lib_ring_buffer *buf;
886 struct ltt_channel *channel;
887
888 if (priv) {
889 buf = priv->buf;
890 channel = priv->ltt_chan;
891 free(priv);
892 /*
893 * If we are at ABI exit, we don't want to close the
894 * buffer opened for read: it is being shared between
895 * the parent and child (right after fork), and we don't
896 * want the child to close it for the parent. For a real
897 * exit, we don't care about marking it as closed, as
898 * the consumer daemon (if there is one) will do fine
899 * even if we don't mark it as "closed" for reading on
900 * our side.
901 * We only mark it as closed if it is being explicitely
902 * released by the session daemon with an explicit
903 * release command.
904 */
905 if (!lttng_ust_abi_close_in_progress)
906 channel->ops->buffer_read_close(buf, channel->handle);
907
908 return lttng_ust_objd_unref(channel->objd);
909 }
910 return 0;
911 }
912
913 static const struct lttng_ust_objd_ops lib_ring_buffer_objd_ops = {
914 .release = lttng_rb_release,
915 .cmd = lttng_rb_cmd,
916 };
917
918 /**
919 * lttng_event_cmd - lttng control through object descriptors
920 *
921 * @objd: the object descriptor
922 * @cmd: the command
923 * @arg: command arg
924 * @uargs: UST arguments (internal)
925 *
926 * This object descriptor implements lttng commands:
927 * LTTNG_UST_CONTEXT
928 * Prepend a context field to each record of this event
929 * LTTNG_UST_ENABLE
930 * Enable recording for this event (weak enable)
931 * LTTNG_UST_DISABLE
932 * Disable recording for this event (strong disable)
933 */
934 static
935 long lttng_event_cmd(int objd, unsigned int cmd, unsigned long arg,
936 union ust_args *uargs)
937 {
938 struct ltt_event *event = objd_private(objd);
939
940 switch (cmd) {
941 case LTTNG_UST_CONTEXT:
942 return lttng_abi_add_context(objd,
943 (struct lttng_ust_context *) arg,
944 &event->ctx, event->chan->session);
945 case LTTNG_UST_ENABLE:
946 return ltt_event_enable(event);
947 case LTTNG_UST_DISABLE:
948 return ltt_event_disable(event);
949 default:
950 return -EINVAL;
951 }
952 }
953
954 static
955 int lttng_event_release(int objd)
956 {
957 struct ltt_event *event = objd_private(objd);
958
959 if (event)
960 return lttng_ust_objd_unref(event->chan->objd);
961 return 0;
962 }
963
964 /* TODO: filter control ioctl */
965 static const struct lttng_ust_objd_ops lttng_event_ops = {
966 .release = lttng_event_release,
967 .cmd = lttng_event_cmd,
968 };
969
970 /**
971 * lttng_wildcard_cmd - lttng control through object descriptors
972 *
973 * @objd: the object descriptor
974 * @cmd: the command
975 * @arg: command arg
976 * @uargs: UST arguments (internal)
977 *
978 * This object descriptor implements lttng commands:
979 * LTTNG_UST_CONTEXT
980 * Prepend a context field to each record of events of this
981 * wildcard.
982 * LTTNG_UST_ENABLE
983 * Enable recording for these wildcard events (weak enable)
984 * LTTNG_UST_DISABLE
985 * Disable recording for these wildcard events (strong disable)
986 */
987 static
988 long lttng_wildcard_cmd(int objd, unsigned int cmd, unsigned long arg,
989 union ust_args *uargs)
990 {
991 struct session_wildcard *wildcard = objd_private(objd);
992
993 switch (cmd) {
994 case LTTNG_UST_CONTEXT:
995 return -ENOSYS; /* not implemented yet */
996 #if 0
997 return lttng_abi_add_context(objd,
998 (struct lttng_ust_context *) arg,
999 &wildcard->ctx, wildcard->chan->session);
1000 #endif
1001 case LTTNG_UST_ENABLE:
1002 return ltt_wildcard_enable(wildcard);
1003 case LTTNG_UST_DISABLE:
1004 return ltt_wildcard_disable(wildcard);
1005 default:
1006 return -EINVAL;
1007 }
1008 }
1009
1010 static
1011 int lttng_wildcard_release(int objd)
1012 {
1013 struct session_wildcard *wildcard = objd_private(objd);
1014
1015 if (wildcard)
1016 return lttng_ust_objd_unref(wildcard->chan->objd);
1017 return 0;
1018 }
1019
1020 /* TODO: filter control ioctl */
1021 static const struct lttng_ust_objd_ops lttng_wildcard_ops = {
1022 .release = lttng_wildcard_release,
1023 .cmd = lttng_wildcard_cmd,
1024 };
1025
1026 void lttng_ust_abi_exit(void)
1027 {
1028 lttng_ust_abi_close_in_progress = 1;
1029 objd_table_destroy();
1030 lttng_ust_abi_close_in_progress = 0;
1031 }
This page took 0.049448 seconds and 5 git commands to generate.