SoW-2020-0002: Trace Hit Counters
[deliverable/lttng-ust.git] / liblttng-ust / lttng-ust-abi.c
1 /*
2 * SPDX-License-Identifier: LGPL-2.1-only
3 *
4 * Copyright (C) 2010-2012 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
25 #define _LGPL_SOURCE
26 #include <fcntl.h>
27 #include <stdint.h>
28 #include <unistd.h>
29
30 #include <urcu/compiler.h>
31 #include <urcu/list.h>
32
33 #include <helper.h>
34 #include <lttng/tracepoint.h>
35 #include <lttng/ust-abi.h>
36 #include <lttng/ust-error.h>
37 #include <lttng/ust-events.h>
38 #include <lttng/ust-version.h>
39 #include <ust-fd.h>
40 #include <usterr-signal-safe.h>
41
42 #include "../libringbuffer/frontend_types.h"
43 #include "../libringbuffer/shm.h"
44 #include "../libcounter/counter.h"
45 #include "tracepoint-internal.h"
46 #include "lttng-tracer.h"
47 #include "string-utils.h"
48 #include "ust-events-internal.h"
49
50 #define OBJ_NAME_LEN 16
51
52 static int lttng_ust_abi_close_in_progress;
53
54 static
55 int lttng_abi_tracepoint_list(void *owner);
56 static
57 int lttng_abi_tracepoint_field_list(void *owner);
58
59 /*
60 * Object descriptor table. Should be protected from concurrent access
61 * by the caller.
62 */
63
64 struct lttng_ust_obj {
65 union {
66 struct {
67 void *private_data;
68 const struct lttng_ust_objd_ops *ops;
69 int f_count;
70 int owner_ref; /* has ref from owner */
71 void *owner;
72 char name[OBJ_NAME_LEN];
73 } s;
74 int freelist_next; /* offset freelist. end is -1. */
75 } u;
76 };
77
78 struct lttng_ust_objd_table {
79 struct lttng_ust_obj *array;
80 unsigned int len, allocated_len;
81 int freelist_head; /* offset freelist head. end is -1 */
82 };
83
84 static struct lttng_ust_objd_table objd_table = {
85 .freelist_head = -1,
86 };
87
88 static
89 int objd_alloc(void *private_data, const struct lttng_ust_objd_ops *ops,
90 void *owner, const char *name)
91 {
92 struct lttng_ust_obj *obj;
93
94 if (objd_table.freelist_head != -1) {
95 obj = &objd_table.array[objd_table.freelist_head];
96 objd_table.freelist_head = obj->u.freelist_next;
97 goto end;
98 }
99
100 if (objd_table.len >= objd_table.allocated_len) {
101 unsigned int new_allocated_len, old_allocated_len;
102 struct lttng_ust_obj *new_table, *old_table;
103
104 old_allocated_len = objd_table.allocated_len;
105 old_table = objd_table.array;
106 if (!old_allocated_len)
107 new_allocated_len = 1;
108 else
109 new_allocated_len = old_allocated_len << 1;
110 new_table = zmalloc(sizeof(struct lttng_ust_obj) * new_allocated_len);
111 if (!new_table)
112 return -ENOMEM;
113 memcpy(new_table, old_table,
114 sizeof(struct lttng_ust_obj) * old_allocated_len);
115 free(old_table);
116 objd_table.array = new_table;
117 objd_table.allocated_len = new_allocated_len;
118 }
119 obj = &objd_table.array[objd_table.len];
120 objd_table.len++;
121 end:
122 obj->u.s.private_data = private_data;
123 obj->u.s.ops = ops;
124 obj->u.s.f_count = 2; /* count == 1 : object is allocated */
125 /* count == 2 : allocated + hold ref */
126 obj->u.s.owner_ref = 1; /* One owner reference */
127 obj->u.s.owner = owner;
128 strncpy(obj->u.s.name, name, OBJ_NAME_LEN);
129 obj->u.s.name[OBJ_NAME_LEN - 1] = '\0';
130 return obj - objd_table.array;
131 }
132
133 static
134 struct lttng_ust_obj *_objd_get(int id)
135 {
136 if (id >= objd_table.len)
137 return NULL;
138 if (!objd_table.array[id].u.s.f_count)
139 return NULL;
140 return &objd_table.array[id];
141 }
142
143 static
144 void *objd_private(int id)
145 {
146 struct lttng_ust_obj *obj = _objd_get(id);
147 assert(obj);
148 return obj->u.s.private_data;
149 }
150
151 static
152 void objd_set_private(int id, void *private_data)
153 {
154 struct lttng_ust_obj *obj = _objd_get(id);
155 assert(obj);
156 obj->u.s.private_data = private_data;
157 }
158
159 const struct lttng_ust_objd_ops *objd_ops(int id)
160 {
161 struct lttng_ust_obj *obj = _objd_get(id);
162
163 if (!obj)
164 return NULL;
165 return obj->u.s.ops;
166 }
167
168 static
169 void objd_free(int id)
170 {
171 struct lttng_ust_obj *obj = _objd_get(id);
172
173 assert(obj);
174 obj->u.freelist_next = objd_table.freelist_head;
175 objd_table.freelist_head = obj - objd_table.array;
176 assert(obj->u.s.f_count == 1);
177 obj->u.s.f_count = 0; /* deallocated */
178 }
179
180 static
181 void objd_ref(int id)
182 {
183 struct lttng_ust_obj *obj = _objd_get(id);
184 assert(obj != NULL);
185 obj->u.s.f_count++;
186 }
187
188 int lttng_ust_objd_unref(int id, int is_owner)
189 {
190 struct lttng_ust_obj *obj = _objd_get(id);
191
192 if (!obj)
193 return -EINVAL;
194 if (obj->u.s.f_count == 1) {
195 ERR("Reference counting error\n");
196 return -EINVAL;
197 }
198 if (is_owner) {
199 if (!obj->u.s.owner_ref) {
200 ERR("Error decrementing owner reference\n");
201 return -EINVAL;
202 }
203 obj->u.s.owner_ref--;
204 }
205 if ((--obj->u.s.f_count) == 1) {
206 const struct lttng_ust_objd_ops *ops = objd_ops(id);
207
208 if (ops->release)
209 ops->release(id);
210 objd_free(id);
211 }
212 return 0;
213 }
214
215 static
216 void objd_table_destroy(void)
217 {
218 int i;
219
220 for (i = 0; i < objd_table.allocated_len; i++) {
221 struct lttng_ust_obj *obj;
222
223 obj = _objd_get(i);
224 if (!obj)
225 continue;
226 if (!obj->u.s.owner_ref)
227 continue; /* only unref owner ref. */
228 (void) lttng_ust_objd_unref(i, 1);
229 }
230 free(objd_table.array);
231 objd_table.array = NULL;
232 objd_table.len = 0;
233 objd_table.allocated_len = 0;
234 objd_table.freelist_head = -1;
235 }
236
237 const char *lttng_ust_obj_get_name(int id)
238 {
239 struct lttng_ust_obj *obj = _objd_get(id);
240
241 if (!obj)
242 return NULL;
243 return obj->u.s.name;
244 }
245
246 void lttng_ust_objd_table_owner_cleanup(void *owner)
247 {
248 int i;
249
250 for (i = 0; i < objd_table.allocated_len; i++) {
251 struct lttng_ust_obj *obj;
252
253 obj = _objd_get(i);
254 if (!obj)
255 continue;
256 if (!obj->u.s.owner)
257 continue; /* skip root handles */
258 if (!obj->u.s.owner_ref)
259 continue; /* only unref owner ref. */
260 if (obj->u.s.owner == owner)
261 (void) lttng_ust_objd_unref(i, 1);
262 }
263 }
264
265 /*
266 * This is LTTng's own personal way to create an ABI for sessiond.
267 * We send commands over a socket.
268 */
269
270 static const struct lttng_ust_objd_ops lttng_ops;
271 static const struct lttng_ust_objd_ops lttng_event_notifier_group_ops;
272 static const struct lttng_ust_objd_ops lttng_session_ops;
273 static const struct lttng_ust_objd_ops lttng_channel_ops;
274 static const struct lttng_ust_objd_ops lttng_counter_ops;
275 static const struct lttng_ust_objd_ops lttng_event_enabler_ops;
276 static const struct lttng_ust_objd_ops lttng_event_notifier_enabler_ops;
277 static const struct lttng_ust_objd_ops lttng_tracepoint_list_ops;
278 static const struct lttng_ust_objd_ops lttng_tracepoint_field_list_ops;
279
280 int lttng_abi_create_root_handle(void)
281 {
282 int root_handle;
283
284 /* root handles have NULL owners */
285 root_handle = objd_alloc(NULL, &lttng_ops, NULL, "root");
286 return root_handle;
287 }
288
289 static
290 int lttng_is_channel_ready(struct lttng_channel *lttng_chan)
291 {
292 struct channel *chan;
293 unsigned int nr_streams, exp_streams;
294
295 chan = lttng_chan->chan;
296 nr_streams = channel_handle_get_nr_streams(lttng_chan->handle);
297 exp_streams = chan->nr_streams;
298 return nr_streams == exp_streams;
299 }
300
301 static
302 int lttng_abi_create_session(void *owner)
303 {
304 struct lttng_session *session;
305 int session_objd, ret;
306
307 session = lttng_session_create();
308 if (!session)
309 return -ENOMEM;
310 session_objd = objd_alloc(session, &lttng_session_ops, owner, "session");
311 if (session_objd < 0) {
312 ret = session_objd;
313 goto objd_error;
314 }
315 session->objd = session_objd;
316 session->owner = owner;
317 return session_objd;
318
319 objd_error:
320 lttng_session_destroy(session);
321 return ret;
322 }
323
324 static
325 long lttng_abi_tracer_version(int objd,
326 struct lttng_ust_tracer_version *v)
327 {
328 v->major = LTTNG_UST_MAJOR_VERSION;
329 v->minor = LTTNG_UST_MINOR_VERSION;
330 v->patchlevel = LTTNG_UST_PATCHLEVEL_VERSION;
331 return 0;
332 }
333
334 static
335 int lttng_abi_event_notifier_send_fd(void *owner, int *event_notifier_notif_fd)
336 {
337 struct lttng_event_notifier_group *event_notifier_group;
338 int event_notifier_group_objd, ret, fd_flag;
339
340 event_notifier_group = lttng_event_notifier_group_create();
341 if (!event_notifier_group)
342 return -ENOMEM;
343
344 /*
345 * Set this file descriptor as NON-BLOCKING.
346 */
347 fd_flag = fcntl(*event_notifier_notif_fd, F_GETFL);
348
349 fd_flag |= O_NONBLOCK;
350
351 ret = fcntl(*event_notifier_notif_fd, F_SETFL, fd_flag);
352 if (ret) {
353 ret = -errno;
354 goto fd_error;
355 }
356
357 event_notifier_group_objd = objd_alloc(event_notifier_group,
358 &lttng_event_notifier_group_ops, owner, "event_notifier_group");
359 if (event_notifier_group_objd < 0) {
360 ret = event_notifier_group_objd;
361 goto objd_error;
362 }
363
364 event_notifier_group->objd = event_notifier_group_objd;
365 event_notifier_group->owner = owner;
366 event_notifier_group->notification_fd = *event_notifier_notif_fd;
367 /* Object descriptor takes ownership of notification fd. */
368 *event_notifier_notif_fd = -1;
369
370 return event_notifier_group_objd;
371
372 objd_error:
373 lttng_event_notifier_group_destroy(event_notifier_group);
374 fd_error:
375 return ret;
376 }
377
378 static
379 long lttng_abi_add_context(int objd,
380 struct lttng_ust_context *context_param,
381 union ust_args *uargs,
382 struct lttng_ctx **ctx, struct lttng_session *session)
383 {
384 return lttng_attach_context(context_param, uargs, ctx, session);
385 }
386
387 /**
388 * lttng_cmd - lttng control through socket commands
389 *
390 * @objd: the object descriptor
391 * @cmd: the command
392 * @arg: command arg
393 * @uargs: UST arguments (internal)
394 * @owner: objd owner
395 *
396 * This descriptor implements lttng commands:
397 * LTTNG_UST_SESSION
398 * Returns a LTTng trace session object descriptor
399 * LTTNG_UST_TRACER_VERSION
400 * Returns the LTTng kernel tracer version
401 * LTTNG_UST_TRACEPOINT_LIST
402 * Returns a file descriptor listing available tracepoints
403 * LTTNG_UST_TRACEPOINT_FIELD_LIST
404 * Returns a file descriptor listing available tracepoint fields
405 * LTTNG_UST_WAIT_QUIESCENT
406 * Returns after all previously running probes have completed
407 *
408 * The returned session will be deleted when its file descriptor is closed.
409 */
410 static
411 long lttng_cmd(int objd, unsigned int cmd, unsigned long arg,
412 union ust_args *uargs, void *owner)
413 {
414 switch (cmd) {
415 case LTTNG_UST_SESSION:
416 return lttng_abi_create_session(owner);
417 case LTTNG_UST_TRACER_VERSION:
418 return lttng_abi_tracer_version(objd,
419 (struct lttng_ust_tracer_version *) arg);
420 case LTTNG_UST_TRACEPOINT_LIST:
421 return lttng_abi_tracepoint_list(owner);
422 case LTTNG_UST_TRACEPOINT_FIELD_LIST:
423 return lttng_abi_tracepoint_field_list(owner);
424 case LTTNG_UST_WAIT_QUIESCENT:
425 lttng_ust_synchronize_trace();
426 return 0;
427 case LTTNG_UST_EVENT_NOTIFIER_GROUP_CREATE:
428 return lttng_abi_event_notifier_send_fd(owner,
429 &uargs->event_notifier_handle.event_notifier_notif_fd);
430 default:
431 return -EINVAL;
432 }
433 }
434
435 static const struct lttng_ust_objd_ops lttng_ops = {
436 .cmd = lttng_cmd,
437 };
438
439 static
440 int lttng_abi_map_channel(int session_objd,
441 struct lttng_ust_channel *ust_chan,
442 union ust_args *uargs,
443 void *owner)
444 {
445 struct lttng_session *session = objd_private(session_objd);
446 const char *transport_name;
447 const struct lttng_transport *transport;
448 const char *chan_name;
449 int chan_objd;
450 struct lttng_ust_shm_handle *channel_handle;
451 struct lttng_channel *lttng_chan;
452 struct channel *chan;
453 struct lttng_ust_lib_ring_buffer_config *config;
454 void *chan_data;
455 int wakeup_fd;
456 uint64_t len;
457 int ret;
458 enum lttng_ust_chan_type type;
459
460 chan_data = uargs->channel.chan_data;
461 wakeup_fd = uargs->channel.wakeup_fd;
462 len = ust_chan->len;
463 type = ust_chan->type;
464
465 switch (type) {
466 case LTTNG_UST_CHAN_PER_CPU:
467 break;
468 default:
469 ret = -EINVAL;
470 goto invalid;
471 }
472
473 if (session->been_active) {
474 ret = -EBUSY;
475 goto active; /* Refuse to add channel to active session */
476 }
477
478 channel_handle = channel_handle_create(chan_data, len, wakeup_fd);
479 if (!channel_handle) {
480 ret = -EINVAL;
481 goto handle_error;
482 }
483
484 /* Ownership of chan_data and wakeup_fd taken by channel handle. */
485 uargs->channel.chan_data = NULL;
486 uargs->channel.wakeup_fd = -1;
487
488 chan = shmp(channel_handle, channel_handle->chan);
489 assert(chan);
490 chan->handle = channel_handle;
491 config = &chan->backend.config;
492 lttng_chan = channel_get_private(chan);
493 if (!lttng_chan) {
494 ret = -EINVAL;
495 goto alloc_error;
496 }
497
498 /* Lookup transport name */
499 switch (type) {
500 case LTTNG_UST_CHAN_PER_CPU:
501 if (config->output == RING_BUFFER_MMAP) {
502 if (config->mode == RING_BUFFER_OVERWRITE) {
503 if (config->wakeup == RING_BUFFER_WAKEUP_BY_WRITER) {
504 transport_name = "relay-overwrite-mmap";
505 } else {
506 transport_name = "relay-overwrite-rt-mmap";
507 }
508 } else {
509 if (config->wakeup == RING_BUFFER_WAKEUP_BY_WRITER) {
510 transport_name = "relay-discard-mmap";
511 } else {
512 transport_name = "relay-discard-rt-mmap";
513 }
514 }
515 } else {
516 ret = -EINVAL;
517 goto notransport;
518 }
519 chan_name = "channel";
520 break;
521 default:
522 ret = -EINVAL;
523 goto notransport;
524 }
525 transport = lttng_transport_find(transport_name);
526 if (!transport) {
527 DBG("LTTng transport %s not found\n",
528 transport_name);
529 ret = -EINVAL;
530 goto notransport;
531 }
532
533 chan_objd = objd_alloc(NULL, &lttng_channel_ops, owner, chan_name);
534 if (chan_objd < 0) {
535 ret = chan_objd;
536 goto objd_error;
537 }
538
539 /* Initialize our lttng chan */
540 lttng_chan->chan = chan;
541 lttng_chan->enabled = 1; /* Backward compatibility */
542 lttng_chan->ctx = NULL;
543 lttng_chan->session = session; /* Backward compatibility */
544 lttng_chan->ops = &transport->ops;
545 memcpy(&lttng_chan->chan->backend.config,
546 transport->client_config,
547 sizeof(lttng_chan->chan->backend.config));
548 cds_list_add(&lttng_chan->node, &session->chan_head);
549 lttng_chan->header_type = 0;
550 lttng_chan->handle = channel_handle;
551 lttng_chan->type = type;
552
553 /* Set container properties */
554 lttng_chan->parent.type = LTTNG_EVENT_CONTAINER_CHANNEL;
555 lttng_chan->parent.session = session;
556 lttng_chan->parent.enabled = 1;
557 lttng_chan->parent.tstate = 1;
558 /*
559 * The ring buffer always coalesces hits from various event
560 * enablers matching a given event to a single event record within the
561 * ring buffer.
562 */
563 lttng_chan->parent.coalesce_hits = true;
564
565 /*
566 * We tolerate no failure path after channel creation. It will stay
567 * invariant for the rest of the session.
568 */
569 objd_set_private(chan_objd, lttng_chan);
570 lttng_chan->parent.objd = chan_objd;
571 /* The channel created holds a reference on the session */
572 objd_ref(session_objd);
573 return chan_objd;
574
575 /* error path after channel was created */
576 objd_error:
577 notransport:
578 alloc_error:
579 channel_destroy(chan, channel_handle, 0);
580 return ret;
581
582 handle_error:
583 active:
584 invalid:
585 return ret;
586 }
587
588 static
589 long lttng_abi_session_create_counter(
590 int session_objd,
591 struct lttng_ust_counter *ust_counter,
592 union ust_args *uargs,
593 void *owner)
594 {
595 struct lttng_session *session = objd_private(session_objd);
596 int counter_objd, ret, i;
597 char *counter_transport_name;
598 struct lttng_counter *counter = NULL;
599 struct lttng_event_container *container;
600 size_t dimension_sizes[LTTNG_UST_COUNTER_DIMENSION_MAX] = { 0 };
601 size_t number_dimensions;
602 const struct lttng_ust_counter_conf *counter_conf;
603
604 if (ust_counter->len != sizeof(*counter_conf)) {
605 ERR("LTTng: Map: Error counter configuration of wrong size.\n");
606 return -EINVAL;
607 }
608 counter_conf = uargs->counter.counter_data;
609
610 if (counter_conf->arithmetic != LTTNG_UST_COUNTER_ARITHMETIC_MODULAR) {
611 ERR("LTTng: Map: Error counter of the wrong type.\n");
612 return -EINVAL;
613 }
614
615 if (counter_conf->global_sum_step) {
616 /* Unsupported. */
617 return -EINVAL;
618 }
619
620 switch (counter_conf->bitness) {
621 case LTTNG_UST_COUNTER_BITNESS_64:
622 counter_transport_name = "counter-per-cpu-64-modular";
623 break;
624 case LTTNG_UST_COUNTER_BITNESS_32:
625 counter_transport_name = "counter-per-cpu-32-modular";
626 break;
627 default:
628 return -EINVAL;
629 }
630
631 number_dimensions = (size_t) counter_conf->number_dimensions;
632
633 for (i = 0; i < counter_conf->number_dimensions; i++) {
634 if (counter_conf->dimensions[i].has_underflow)
635 return -EINVAL;
636 if (counter_conf->dimensions[i].has_overflow)
637 return -EINVAL;
638 dimension_sizes[i] = counter_conf->dimensions[i].size;
639 }
640
641 counter_objd = objd_alloc(NULL, &lttng_counter_ops, owner, "counter");
642 if (counter_objd < 0) {
643 ret = counter_objd;
644 goto objd_error;
645 }
646
647 counter = lttng_session_create_counter(session,
648 counter_transport_name,
649 number_dimensions, dimension_sizes,
650 0, counter_conf->coalesce_hits);
651 if (!counter) {
652 ret = -EINVAL;
653 goto counter_error;
654 }
655 container = lttng_counter_get_event_container(counter);
656 objd_set_private(counter_objd, counter);
657 container->objd = counter_objd;
658 container->enabled = 1;
659 container->tstate = 1;
660 /* The channel created holds a reference on the session */
661 objd_ref(session_objd);
662 return counter_objd;
663
664 counter_error:
665 {
666 int err;
667
668 err = lttng_ust_objd_unref(counter_objd, 1);
669 assert(!err);
670 }
671 objd_error:
672 return ret;
673 }
674
675
676 /**
677 * lttng_session_cmd - lttng session object command
678 *
679 * @obj: the object
680 * @cmd: the command
681 * @arg: command arg
682 * @uargs: UST arguments (internal)
683 * @owner: objd owner
684 *
685 * This descriptor implements lttng commands:
686 * LTTNG_UST_CHANNEL
687 * Returns a LTTng channel object descriptor
688 * LTTNG_UST_ENABLE
689 * Enables tracing for a session (weak enable)
690 * LTTNG_UST_DISABLE
691 * Disables tracing for a session (strong disable)
692 *
693 * The returned channel will be deleted when its file descriptor is closed.
694 */
695 static
696 long lttng_session_cmd(int objd, unsigned int cmd, unsigned long arg,
697 union ust_args *uargs, void *owner)
698 {
699 struct lttng_session *session = objd_private(objd);
700
701 switch (cmd) {
702 case LTTNG_UST_CHANNEL:
703 return lttng_abi_map_channel(objd,
704 (struct lttng_ust_channel *) arg,
705 uargs, owner);
706 case LTTNG_UST_SESSION_START:
707 case LTTNG_UST_ENABLE:
708 return lttng_session_enable(session);
709 case LTTNG_UST_SESSION_STOP:
710 case LTTNG_UST_DISABLE:
711 return lttng_session_disable(session);
712 case LTTNG_UST_SESSION_STATEDUMP:
713 return lttng_session_statedump(session);
714 case LTTNG_UST_COUNTER:
715 return lttng_abi_session_create_counter(objd,
716 (struct lttng_ust_counter *) arg,
717 uargs, owner);
718 case LTTNG_UST_COUNTER_GLOBAL:
719 case LTTNG_UST_COUNTER_CPU:
720 /* Not implemented yet. */
721 return -EINVAL;
722 default:
723 return -EINVAL;
724 }
725 }
726
727 /*
728 * Called when the last file reference is dropped.
729 *
730 * Big fat note: channels and events are invariant for the whole session after
731 * their creation. So this session destruction also destroys all channel and
732 * event structures specific to this session (they are not destroyed when their
733 * individual file is released).
734 */
735 static
736 int lttng_release_session(int objd)
737 {
738 struct lttng_session *session = objd_private(objd);
739
740 if (session) {
741 lttng_session_destroy(session);
742 return 0;
743 } else {
744 return -EINVAL;
745 }
746 }
747
748 static const struct lttng_ust_objd_ops lttng_session_ops = {
749 .release = lttng_release_session,
750 .cmd = lttng_session_cmd,
751 };
752
753 static int lttng_ust_event_notifier_enabler_create(int event_notifier_group_obj,
754 void *owner, struct lttng_ust_event_notifier *event_notifier_param,
755 enum lttng_enabler_format_type type)
756 {
757 struct lttng_event_notifier_group *event_notifier_group =
758 objd_private(event_notifier_group_obj);
759 struct lttng_event_notifier_enabler *event_notifier_enabler;
760 int event_notifier_objd, ret;
761
762 event_notifier_param->event.name[LTTNG_UST_SYM_NAME_LEN - 1] = '\0';
763 event_notifier_objd = objd_alloc(NULL, &lttng_event_notifier_enabler_ops, owner,
764 "event_notifier enabler");
765 if (event_notifier_objd < 0) {
766 ret = event_notifier_objd;
767 goto objd_error;
768 }
769
770 event_notifier_enabler = lttng_event_notifier_enabler_create(
771 event_notifier_group, type, event_notifier_param);
772 if (!event_notifier_enabler) {
773 ret = -ENOMEM;
774 goto event_notifier_error;
775 }
776
777 objd_set_private(event_notifier_objd, event_notifier_enabler);
778 /* The event_notifier holds a reference on the event_notifier group. */
779 objd_ref(event_notifier_enabler->group->objd);
780
781 return event_notifier_objd;
782
783 event_notifier_error:
784 {
785 int err;
786
787 err = lttng_ust_objd_unref(event_notifier_objd, 1);
788 assert(!err);
789 }
790 objd_error:
791 return ret;
792 }
793
794 static
795 long lttng_event_notifier_enabler_cmd(int objd, unsigned int cmd, unsigned long arg,
796 union ust_args *uargs, void *owner)
797 {
798 struct lttng_event_notifier_enabler *event_notifier_enabler = objd_private(objd);
799 switch (cmd) {
800 case LTTNG_UST_FILTER:
801 return lttng_event_notifier_enabler_attach_filter_bytecode(
802 event_notifier_enabler,
803 (struct lttng_ust_bytecode_node **) arg);
804 case LTTNG_UST_EXCLUSION:
805 return lttng_event_notifier_enabler_attach_exclusion(event_notifier_enabler,
806 (struct lttng_ust_excluder_node **) arg);
807 case LTTNG_UST_CAPTURE:
808 return lttng_event_notifier_enabler_attach_capture_bytecode(
809 event_notifier_enabler,
810 (struct lttng_ust_bytecode_node **) arg);
811 case LTTNG_UST_ENABLE:
812 return lttng_event_notifier_enabler_enable(event_notifier_enabler);
813 case LTTNG_UST_DISABLE:
814 return lttng_event_notifier_enabler_disable(event_notifier_enabler);
815 default:
816 return -EINVAL;
817 }
818 }
819
820 /**
821 * lttng_event_notifier_group_error_counter_cmd - lttng event_notifier group error counter object command
822 *
823 * @obj: the object
824 * @cmd: the command
825 * @arg: command arg
826 * @uargs: UST arguments (internal)
827 * @owner: objd owner
828 *
829 * This descriptor implements lttng commands:
830 * LTTNG_UST_COUNTER_GLOBAL
831 * Return negative error code on error, 0 on success.
832 * LTTNG_UST_COUNTER_CPU
833 * Return negative error code on error, 0 on success.
834 */
835 static
836 long lttng_event_notifier_group_error_counter_cmd(int objd, unsigned int cmd, unsigned long arg,
837 union ust_args *uargs, void *owner)
838 {
839 int ret;
840 struct lttng_counter *counter = objd_private(objd);
841
842 switch (cmd) {
843 case LTTNG_UST_COUNTER_GLOBAL:
844 ret = -EINVAL; /* Unimplemented. */
845 break;
846 case LTTNG_UST_COUNTER_CPU:
847 {
848 struct lttng_ust_counter_cpu *counter_cpu =
849 (struct lttng_ust_counter_cpu *)arg;
850
851 ret = lttng_counter_set_cpu_shm(counter->counter,
852 counter_cpu->cpu_nr, uargs->counter_shm.shm_fd);
853 if (!ret) {
854 /* Take ownership of the shm_fd. */
855 uargs->counter_shm.shm_fd = -1;
856 }
857 break;
858 }
859 default:
860 ret = -EINVAL;
861 break;
862 }
863
864 return ret;
865 }
866
867 LTTNG_HIDDEN
868 int lttng_release_event_notifier_group_error_counter(int objd)
869 {
870 struct lttng_counter *counter = objd_private(objd);
871
872 if (counter) {
873 return lttng_ust_objd_unref(counter->owner.event_notifier_group->objd, 0);
874 } else {
875 return -EINVAL;
876 }
877 }
878
879 static const struct lttng_ust_objd_ops lttng_event_notifier_group_error_counter_ops = {
880 .release = lttng_release_event_notifier_group_error_counter,
881 .cmd = lttng_event_notifier_group_error_counter_cmd,
882 };
883
884 static
885 int lttng_ust_event_notifier_group_create_error_counter(int event_notifier_group_objd, void *owner,
886 struct lttng_ust_counter_conf *error_counter_conf)
887 {
888 const char *counter_transport_name;
889 struct lttng_event_notifier_group *event_notifier_group =
890 objd_private(event_notifier_group_objd);
891 struct lttng_counter *counter;
892 struct lttng_event_container *container;
893 int counter_objd, ret;
894 size_t counter_len;
895
896 if (event_notifier_group->error_counter)
897 return -EBUSY;
898
899 if (error_counter_conf->arithmetic != LTTNG_UST_COUNTER_ARITHMETIC_MODULAR)
900 return -EINVAL;
901
902 if (error_counter_conf->number_dimensions != 1)
903 return -EINVAL;
904
905 if (error_counter_conf->dimensions[0].has_underflow)
906 return -EINVAL;
907
908 if (error_counter_conf->dimensions[0].has_overflow)
909 return -EINVAL;
910
911 switch (error_counter_conf->bitness) {
912 case LTTNG_UST_COUNTER_BITNESS_64:
913 counter_transport_name = "counter-per-cpu-64-modular";
914 break;
915 case LTTNG_UST_COUNTER_BITNESS_32:
916 counter_transport_name = "counter-per-cpu-32-modular";
917 break;
918 default:
919 return -EINVAL;
920 }
921
922 counter_objd = objd_alloc(NULL, &lttng_event_notifier_group_error_counter_ops, owner,
923 "event_notifier group error counter");
924 if (counter_objd < 0) {
925 ret = counter_objd;
926 goto objd_error;
927 }
928
929 counter_len = error_counter_conf->dimensions[0].size;
930 counter = lttng_ust_counter_create(counter_transport_name, 1, &counter_len, 0, false);
931 if (!counter) {
932 ret = -EINVAL;
933 goto create_error;
934 }
935 container = lttng_counter_get_event_container(counter);
936
937 event_notifier_group->error_counter_len = counter_len;
938 /*
939 * store-release to publish error counter matches load-acquire
940 * in record_error. Ensures the counter is created and the
941 * error_counter_len is set before they are used.
942 * Currently a full memory barrier is used, which could be
943 * turned into acquire-release barriers.
944 */
945 cmm_smp_mb();
946 CMM_STORE_SHARED(event_notifier_group->error_counter, counter);
947
948 container->objd = counter_objd;
949 counter->owner.event_notifier_group = event_notifier_group; /* owner */
950
951 objd_set_private(counter_objd, counter);
952 /* The error counter holds a reference on the event_notifier group. */
953 objd_ref(event_notifier_group->objd);
954
955 return counter_objd;
956
957 create_error:
958 {
959 int err;
960
961 err = lttng_ust_objd_unref(counter_objd, 1);
962 assert(!err);
963 }
964 objd_error:
965 return ret;
966 }
967
968 static
969 long lttng_event_notifier_group_cmd(int objd, unsigned int cmd, unsigned long arg,
970 union ust_args *uargs, void *owner)
971 {
972 switch (cmd) {
973 case LTTNG_UST_EVENT_NOTIFIER_CREATE:
974 {
975 struct lttng_ust_event_notifier *event_notifier_param =
976 (struct lttng_ust_event_notifier *) arg;
977 if (strutils_is_star_glob_pattern(event_notifier_param->event.name)) {
978 /*
979 * If the event name is a star globbing pattern,
980 * we create the special star globbing enabler.
981 */
982 return lttng_ust_event_notifier_enabler_create(objd,
983 owner, event_notifier_param,
984 LTTNG_ENABLER_FORMAT_STAR_GLOB);
985 } else {
986 return lttng_ust_event_notifier_enabler_create(objd,
987 owner, event_notifier_param,
988 LTTNG_ENABLER_FORMAT_EVENT);
989 }
990 }
991 case LTTNG_UST_COUNTER:
992 {
993 struct lttng_ust_counter_conf *counter_conf =
994 (struct lttng_ust_counter_conf *) uargs->counter.counter_data;
995 return lttng_ust_event_notifier_group_create_error_counter(
996 objd, owner, counter_conf);
997 }
998 default:
999 return -EINVAL;
1000 }
1001 }
1002
1003 static
1004 int lttng_event_notifier_enabler_release(int objd)
1005 {
1006 struct lttng_event_notifier_enabler *event_notifier_enabler = objd_private(objd);
1007
1008 if (event_notifier_enabler)
1009 return lttng_ust_objd_unref(event_notifier_enabler->group->objd, 0);
1010 return 0;
1011 }
1012
1013 static const struct lttng_ust_objd_ops lttng_event_notifier_enabler_ops = {
1014 .release = lttng_event_notifier_enabler_release,
1015 .cmd = lttng_event_notifier_enabler_cmd,
1016 };
1017
1018 static
1019 int lttng_release_event_notifier_group(int objd)
1020 {
1021 struct lttng_event_notifier_group *event_notifier_group = objd_private(objd);
1022
1023 if (event_notifier_group) {
1024 lttng_event_notifier_group_destroy(event_notifier_group);
1025 return 0;
1026 } else {
1027 return -EINVAL;
1028 }
1029 }
1030
1031 static const struct lttng_ust_objd_ops lttng_event_notifier_group_ops = {
1032 .release = lttng_release_event_notifier_group,
1033 .cmd = lttng_event_notifier_group_cmd,
1034 };
1035
1036 static
1037 long lttng_tracepoint_list_cmd(int objd, unsigned int cmd, unsigned long arg,
1038 union ust_args *uargs, void *owner)
1039 {
1040 struct lttng_ust_tracepoint_list *list = objd_private(objd);
1041 struct lttng_ust_tracepoint_iter *tp =
1042 (struct lttng_ust_tracepoint_iter *) arg;
1043 struct lttng_ust_tracepoint_iter *iter;
1044
1045 switch (cmd) {
1046 case LTTNG_UST_TRACEPOINT_LIST_GET:
1047 {
1048 iter = lttng_ust_tracepoint_list_get_iter_next(list);
1049 if (!iter)
1050 return -LTTNG_UST_ERR_NOENT;
1051 memcpy(tp, iter, sizeof(*tp));
1052 return 0;
1053 }
1054 default:
1055 return -EINVAL;
1056 }
1057 }
1058
1059 static
1060 int lttng_abi_tracepoint_list(void *owner)
1061 {
1062 int list_objd, ret;
1063 struct lttng_ust_tracepoint_list *list;
1064
1065 list_objd = objd_alloc(NULL, &lttng_tracepoint_list_ops, owner, "tp_list");
1066 if (list_objd < 0) {
1067 ret = list_objd;
1068 goto objd_error;
1069 }
1070 list = zmalloc(sizeof(*list));
1071 if (!list) {
1072 ret = -ENOMEM;
1073 goto alloc_error;
1074 }
1075 objd_set_private(list_objd, list);
1076
1077 /* populate list by walking on all registered probes. */
1078 ret = lttng_probes_get_event_list(list);
1079 if (ret) {
1080 goto list_error;
1081 }
1082 return list_objd;
1083
1084 list_error:
1085 free(list);
1086 alloc_error:
1087 {
1088 int err;
1089
1090 err = lttng_ust_objd_unref(list_objd, 1);
1091 assert(!err);
1092 }
1093 objd_error:
1094 return ret;
1095 }
1096
1097 static
1098 int lttng_release_tracepoint_list(int objd)
1099 {
1100 struct lttng_ust_tracepoint_list *list = objd_private(objd);
1101
1102 if (list) {
1103 lttng_probes_prune_event_list(list);
1104 free(list);
1105 return 0;
1106 } else {
1107 return -EINVAL;
1108 }
1109 }
1110
1111 static const struct lttng_ust_objd_ops lttng_tracepoint_list_ops = {
1112 .release = lttng_release_tracepoint_list,
1113 .cmd = lttng_tracepoint_list_cmd,
1114 };
1115
1116 static
1117 long lttng_tracepoint_field_list_cmd(int objd, unsigned int cmd,
1118 unsigned long arg, union ust_args *uargs, void *owner)
1119 {
1120 struct lttng_ust_field_list *list = objd_private(objd);
1121 struct lttng_ust_field_iter *tp = &uargs->field_list.entry;
1122 struct lttng_ust_field_iter *iter;
1123
1124 switch (cmd) {
1125 case LTTNG_UST_TRACEPOINT_FIELD_LIST_GET:
1126 {
1127 iter = lttng_ust_field_list_get_iter_next(list);
1128 if (!iter)
1129 return -LTTNG_UST_ERR_NOENT;
1130 memcpy(tp, iter, sizeof(*tp));
1131 return 0;
1132 }
1133 default:
1134 return -EINVAL;
1135 }
1136 }
1137
1138 static
1139 int lttng_abi_tracepoint_field_list(void *owner)
1140 {
1141 int list_objd, ret;
1142 struct lttng_ust_field_list *list;
1143
1144 list_objd = objd_alloc(NULL, &lttng_tracepoint_field_list_ops, owner,
1145 "tp_field_list");
1146 if (list_objd < 0) {
1147 ret = list_objd;
1148 goto objd_error;
1149 }
1150 list = zmalloc(sizeof(*list));
1151 if (!list) {
1152 ret = -ENOMEM;
1153 goto alloc_error;
1154 }
1155 objd_set_private(list_objd, list);
1156
1157 /* populate list by walking on all registered probes. */
1158 ret = lttng_probes_get_field_list(list);
1159 if (ret) {
1160 goto list_error;
1161 }
1162 return list_objd;
1163
1164 list_error:
1165 free(list);
1166 alloc_error:
1167 {
1168 int err;
1169
1170 err = lttng_ust_objd_unref(list_objd, 1);
1171 assert(!err);
1172 }
1173 objd_error:
1174 return ret;
1175 }
1176
1177 static
1178 int lttng_release_tracepoint_field_list(int objd)
1179 {
1180 struct lttng_ust_field_list *list = objd_private(objd);
1181
1182 if (list) {
1183 lttng_probes_prune_field_list(list);
1184 free(list);
1185 return 0;
1186 } else {
1187 return -EINVAL;
1188 }
1189 }
1190
1191 static const struct lttng_ust_objd_ops lttng_tracepoint_field_list_ops = {
1192 .release = lttng_release_tracepoint_field_list,
1193 .cmd = lttng_tracepoint_field_list_cmd,
1194 };
1195
1196 static
1197 int lttng_abi_map_stream(int channel_objd, struct lttng_ust_stream *info,
1198 union ust_args *uargs, void *owner)
1199 {
1200 struct lttng_channel *channel = objd_private(channel_objd);
1201 int ret;
1202
1203 ret = channel_handle_add_stream(channel->handle,
1204 uargs->stream.shm_fd, uargs->stream.wakeup_fd,
1205 info->stream_nr, info->len);
1206 if (ret)
1207 goto error_add_stream;
1208 /* Take ownership of shm_fd and wakeup_fd. */
1209 uargs->stream.shm_fd = -1;
1210 uargs->stream.wakeup_fd = -1;
1211
1212 return 0;
1213
1214 error_add_stream:
1215 return ret;
1216 }
1217
1218 static
1219 int lttng_abi_create_event_enabler(int objd, /* channel or counter objd */
1220 struct lttng_event_container *container,
1221 struct lttng_ust_event *event_param,
1222 struct lttng_ust_counter_key *key_param,
1223 void *owner,
1224 enum lttng_enabler_format_type format_type)
1225 {
1226 struct lttng_event_enabler *enabler;
1227 int event_objd, ret;
1228
1229 event_param->name[LTTNG_UST_SYM_NAME_LEN - 1] = '\0';
1230 event_objd = objd_alloc(NULL, &lttng_event_enabler_ops, owner,
1231 "event enabler");
1232 if (event_objd < 0) {
1233 ret = event_objd;
1234 goto objd_error;
1235 }
1236 /*
1237 * We tolerate no failure path after event creation. It will stay
1238 * invariant for the rest of the session.
1239 */
1240 enabler = lttng_event_enabler_create(format_type, event_param,
1241 key_param, container);
1242 if (!enabler) {
1243 ret = -ENOMEM;
1244 goto event_error;
1245 }
1246 objd_set_private(event_objd, enabler);
1247 /* The event holds a reference on the channel or counter */
1248 objd_ref(objd);
1249 return event_objd;
1250
1251 event_error:
1252 {
1253 int err;
1254
1255 err = lttng_ust_objd_unref(event_objd, 1);
1256 assert(!err);
1257 }
1258 objd_error:
1259 return ret;
1260 }
1261
1262 /**
1263 * lttng_channel_cmd - lttng control through object descriptors
1264 *
1265 * @objd: the object descriptor
1266 * @cmd: the command
1267 * @arg: command arg
1268 * @uargs: UST arguments (internal)
1269 * @owner: objd owner
1270 *
1271 * This object descriptor implements lttng commands:
1272 * LTTNG_UST_STREAM
1273 * Returns an event stream object descriptor or failure.
1274 * (typically, one event stream records events from one CPU)
1275 * LTTNG_UST_EVENT
1276 * Returns an event object descriptor or failure.
1277 * LTTNG_UST_CONTEXT
1278 * Prepend a context field to each event in the channel
1279 * LTTNG_UST_ENABLE
1280 * Enable recording for events in this channel (weak enable)
1281 * LTTNG_UST_DISABLE
1282 * Disable recording for events in this channel (strong disable)
1283 *
1284 * Channel and event file descriptors also hold a reference on the session.
1285 */
1286 static
1287 long lttng_channel_cmd(int objd, unsigned int cmd, unsigned long arg,
1288 union ust_args *uargs, void *owner)
1289 {
1290 struct lttng_channel *channel = objd_private(objd);
1291 struct lttng_event_container *container = lttng_channel_get_event_container(channel);
1292
1293 if (cmd != LTTNG_UST_STREAM) {
1294 /*
1295 * Check if channel received all streams.
1296 */
1297 if (!lttng_is_channel_ready(channel))
1298 return -EPERM;
1299 }
1300
1301 switch (cmd) {
1302 case LTTNG_UST_STREAM:
1303 {
1304 struct lttng_ust_stream *stream;
1305
1306 stream = (struct lttng_ust_stream *) arg;
1307 /* stream used as output */
1308 return lttng_abi_map_stream(objd, stream, uargs, owner);
1309 }
1310 case LTTNG_UST_EVENT:
1311 {
1312 struct lttng_ust_event *event_param =
1313 (struct lttng_ust_event *) arg;
1314
1315 if (strutils_is_star_glob_pattern(event_param->name)) {
1316 /*
1317 * If the event name is a star globbing pattern,
1318 * we create the special star globbing enabler.
1319 */
1320 return lttng_abi_create_event_enabler(objd, container, event_param, NULL,
1321 owner, LTTNG_ENABLER_FORMAT_STAR_GLOB);
1322 } else {
1323 return lttng_abi_create_event_enabler(objd, container, event_param, NULL,
1324 owner, LTTNG_ENABLER_FORMAT_EVENT);
1325 }
1326 }
1327 case LTTNG_UST_CONTEXT:
1328 return lttng_abi_add_context(objd,
1329 (struct lttng_ust_context *) arg, uargs,
1330 &channel->ctx, channel->session);
1331 case LTTNG_UST_ENABLE:
1332 return lttng_event_container_enable(&channel->parent);
1333 case LTTNG_UST_DISABLE:
1334 return lttng_event_container_disable(&channel->parent);
1335 case LTTNG_UST_FLUSH_BUFFER:
1336 return channel->ops->flush_buffer(channel->chan, channel->handle);
1337 default:
1338 return -EINVAL;
1339 }
1340 }
1341
1342 static
1343 int lttng_channel_release(int objd)
1344 {
1345 struct lttng_channel *channel = objd_private(objd);
1346
1347 if (channel)
1348 return lttng_ust_objd_unref(channel->session->objd, 0);
1349 return 0;
1350 }
1351
1352 static const struct lttng_ust_objd_ops lttng_channel_ops = {
1353 .release = lttng_channel_release,
1354 .cmd = lttng_channel_cmd,
1355 };
1356
1357 /**
1358 * lttng_counter_cmd - lttng control through object descriptors
1359 *
1360 * @objd: the object descriptor
1361 * @cmd: the command
1362 * @arg: command arg
1363 * @uargs: UST arguments (internal)
1364 * @owner: objd owner
1365 *
1366 * This object descriptor implements lttng commands:
1367 * LTTNG_UST_COUNTER_GLOBAL:
1368 * Returns a global counter object descriptor or failure.
1369 * LTTNG_UST_COUNTER_CPU:
1370 * Returns a per-cpu counter object descriptor or failure.
1371 * LTTNG_UST_COUNTER_EVENT
1372 * Returns an event object descriptor or failure.
1373 * LTTNG_UST_ENABLE
1374 * Enable recording for events in this channel (weak enable)
1375 * LTTNG_UST_DISABLE
1376 * Disable recording for events in this channel (strong disable)
1377 *
1378 * Counter and event object descriptors also hold a reference on the session.
1379 */
1380 static
1381 long lttng_counter_cmd(int objd, unsigned int cmd, unsigned long arg,
1382 union ust_args *uargs, void *owner)
1383 {
1384 struct lttng_counter *counter = objd_private(objd);
1385 struct lttng_event_container *container = lttng_counter_get_event_container(counter);
1386
1387 if (cmd != LTTNG_UST_COUNTER_GLOBAL && cmd != LTTNG_UST_COUNTER_CPU) {
1388 /*
1389 * Check if counter received all global/per-cpu objects.
1390 */
1391 if (!lttng_counter_ready(counter->counter))
1392 return -EPERM;
1393 }
1394
1395 switch (cmd) {
1396 case LTTNG_UST_COUNTER_GLOBAL:
1397 {
1398 long ret;
1399 int shm_fd;
1400
1401 shm_fd = uargs->counter_shm.shm_fd;
1402 ret = lttng_counter_set_global_shm(counter->counter, shm_fd);
1403 if (!ret) {
1404 /* Take ownership of shm_fd. */
1405 uargs->counter_shm.shm_fd = -1;
1406 }
1407 return ret;
1408 }
1409 case LTTNG_UST_COUNTER_CPU:
1410 {
1411 struct lttng_ust_counter_cpu *counter_cpu =
1412 (struct lttng_ust_counter_cpu *) arg;
1413 long ret;
1414 int shm_fd;
1415
1416 shm_fd = uargs->counter_shm.shm_fd;
1417 ret = lttng_counter_set_cpu_shm(counter->counter,
1418 counter_cpu->cpu_nr, shm_fd);
1419 if (!ret) {
1420 /* Take ownership of shm_fd. */
1421 uargs->counter_shm.shm_fd = -1;
1422 }
1423 return ret;
1424 }
1425 case LTTNG_UST_COUNTER_EVENT:
1426 {
1427 struct lttng_ust_counter_event *counter_event_param =
1428 (struct lttng_ust_counter_event *) arg;
1429 struct lttng_ust_event *event_param = &counter_event_param->event;
1430 struct lttng_ust_counter_key *key_param = &counter_event_param->key;
1431
1432 if (strutils_is_star_glob_pattern(event_param->name)) {
1433 /*
1434 * If the event name is a star globbing pattern,
1435 * we create the special star globbing enabler.
1436 */
1437 return lttng_abi_create_event_enabler(objd, container, event_param, key_param,
1438 owner, LTTNG_ENABLER_FORMAT_STAR_GLOB);
1439 } else {
1440 return lttng_abi_create_event_enabler(objd, container, event_param, key_param,
1441 owner, LTTNG_ENABLER_FORMAT_EVENT);
1442 }
1443 }
1444 case LTTNG_UST_ENABLE:
1445 return lttng_event_container_enable(container);
1446 case LTTNG_UST_DISABLE:
1447 return lttng_event_container_disable(container);
1448 default:
1449 return -EINVAL;
1450 }
1451 }
1452
1453
1454 static
1455 int lttng_counter_release(int objd)
1456 {
1457 struct lttng_counter *counter = objd_private(objd);
1458
1459 if (counter) {
1460 struct lttng_event_container *container = lttng_counter_get_event_container(counter);
1461
1462 return lttng_ust_objd_unref(container->session->objd, 0);
1463 }
1464 return 0;
1465 }
1466
1467 static const struct lttng_ust_objd_ops lttng_counter_ops = {
1468 .release = lttng_counter_release,
1469 .cmd = lttng_counter_cmd,
1470 };
1471
1472 /**
1473 * lttng_enabler_cmd - lttng control through object descriptors
1474 *
1475 * @objd: the object descriptor
1476 * @cmd: the command
1477 * @arg: command arg
1478 * @uargs: UST arguments (internal)
1479 * @owner: objd owner
1480 *
1481 * This object descriptor implements lttng commands:
1482 * LTTNG_UST_CONTEXT
1483 * Prepend a context field to each record of events of this
1484 * enabler.
1485 * LTTNG_UST_ENABLE
1486 * Enable recording for this enabler
1487 * LTTNG_UST_DISABLE
1488 * Disable recording for this enabler
1489 * LTTNG_UST_FILTER
1490 * Attach a filter to an enabler.
1491 * LTTNG_UST_EXCLUSION
1492 * Attach exclusions to an enabler.
1493 */
1494 static
1495 long lttng_event_enabler_cmd(int objd, unsigned int cmd, unsigned long arg,
1496 union ust_args *uargs, void *owner)
1497 {
1498 struct lttng_event_enabler *enabler = objd_private(objd);
1499
1500 switch (cmd) {
1501 case LTTNG_UST_CONTEXT:
1502 return lttng_event_enabler_attach_context(enabler,
1503 (struct lttng_ust_context *) arg);
1504 case LTTNG_UST_ENABLE:
1505 return lttng_event_enabler_enable(enabler);
1506 case LTTNG_UST_DISABLE:
1507 return lttng_event_enabler_disable(enabler);
1508 case LTTNG_UST_FILTER:
1509 {
1510 int ret;
1511
1512 ret = lttng_event_enabler_attach_filter_bytecode(enabler,
1513 (struct lttng_ust_bytecode_node **) arg);
1514 if (ret)
1515 return ret;
1516 return 0;
1517 }
1518 case LTTNG_UST_EXCLUSION:
1519 {
1520 return lttng_event_enabler_attach_exclusion(enabler,
1521 (struct lttng_ust_excluder_node **) arg);
1522 }
1523 default:
1524 return -EINVAL;
1525 }
1526 }
1527
1528 static
1529 int lttng_event_enabler_release(int objd)
1530 {
1531 struct lttng_event_enabler *event_enabler = objd_private(objd);
1532
1533 if (event_enabler)
1534 return lttng_ust_objd_unref(event_enabler->container->objd, 0);
1535
1536 return 0;
1537 }
1538
1539 static const struct lttng_ust_objd_ops lttng_event_enabler_ops = {
1540 .release = lttng_event_enabler_release,
1541 .cmd = lttng_event_enabler_cmd,
1542 };
1543
1544 void lttng_ust_abi_exit(void)
1545 {
1546 lttng_ust_abi_close_in_progress = 1;
1547 ust_lock_nocheck();
1548 objd_table_destroy();
1549 ust_unlock();
1550 lttng_ust_abi_close_in_progress = 0;
1551 }
This page took 0.103515 seconds and 5 git commands to generate.