1 /* SPDX-License-Identifier: (GPL-2.0-only or LGPL-2.1-only)
7 * Copyright (C) 2010-2012 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
9 * Mimic system calls for:
10 * - session creation, returns a file descriptor or failure.
11 * - channel creation, returns a file descriptor or failure.
12 * - Operates on a session file descriptor
13 * - Takes all channel options as parameters.
14 * - stream get, returns a file descriptor or failure.
15 * - Operates on a channel file descriptor.
16 * - stream notifier get, returns a file descriptor or failure.
17 * - Operates on a channel file descriptor.
18 * - event creation, returns a file descriptor or failure.
19 * - Operates on a channel file descriptor
20 * - Takes an event name as parameter
21 * - Takes an instrumentation source as parameter
22 * - e.g. tracepoints, dynamic_probes...
23 * - Takes instrumentation source specific arguments.
26 #include <linux/module.h>
27 #include <linux/proc_fs.h>
28 #include <linux/anon_inodes.h>
29 #include <linux/file.h>
30 #include <linux/uaccess.h>
31 #include <linux/slab.h>
32 #include <linux/err.h>
33 #include <wrapper/vmalloc.h> /* for wrapper_vmalloc_sync_mappings() */
34 #include <ringbuffer/vfs.h>
35 #include <ringbuffer/backend.h>
36 #include <ringbuffer/frontend.h>
37 #include <wrapper/poll.h>
38 #include <wrapper/file.h>
39 #include <wrapper/kref.h>
40 #include <wrapper/barrier.h>
41 #include <lttng/string-utils.h>
42 #include <lttng/abi.h>
43 #include <lttng/abi-old.h>
44 #include <lttng/events.h>
45 #include <lttng/events-internal.h>
46 #include <lttng/tracer.h>
47 #include <lttng/tp-mempool.h>
48 #include <ringbuffer/frontend_types.h>
49 #include <ringbuffer/iterator.h>
52 * This is LTTng's own personal way to create a system call as an external
53 * module. We use ioctl() on /proc/lttng.
56 static struct proc_dir_entry
*lttng_proc_dentry
;
58 #if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(5,6,0))
59 static const struct proc_ops lttng_proc_ops
;
61 static const struct file_operations lttng_proc_ops
;
64 static const struct file_operations lttng_session_fops
;
65 static const struct file_operations lttng_event_notifier_group_fops
;
66 static const struct file_operations lttng_channel_fops
;
67 static const struct file_operations lttng_metadata_fops
;
68 static const struct file_operations lttng_event_recorder_event_fops
;
69 static const struct file_operations lttng_event_recorder_enabler_fops
;
70 static struct file_operations lttng_stream_ring_buffer_file_operations
;
72 static int put_u64(uint64_t val
, unsigned long arg
);
73 static int put_u32(uint32_t val
, unsigned long arg
);
75 static int validate_zeroed_padding(char *p
, size_t len
)
79 for (i
= 0; i
< len
; i
++) {
87 * Teardown management: opened file descriptors keep a refcount on the module,
88 * so it can only exit when all file descriptors are closed.
92 int lttng_abi_create_session(void)
94 struct lttng_session
*session
;
95 struct file
*session_file
;
98 session
= lttng_session_create();
101 session_fd
= lttng_get_unused_fd();
102 if (session_fd
< 0) {
106 session_file
= anon_inode_getfile("[lttng_session]",
109 if (IS_ERR(session_file
)) {
110 ret
= PTR_ERR(session_file
);
113 session
->file
= session_file
;
114 fd_install(session_fd
, session_file
);
118 put_unused_fd(session_fd
);
120 lttng_session_destroy(session
);
124 void event_notifier_send_notification_work_wakeup(struct irq_work
*entry
)
126 struct lttng_event_notifier_group
*event_notifier_group
=
127 container_of(entry
, struct lttng_event_notifier_group
,
129 wake_up_interruptible(&event_notifier_group
->read_wait
);
133 int lttng_abi_create_event_notifier_group(void)
135 struct lttng_event_notifier_group
*event_notifier_group
;
136 struct file
*event_notifier_group_file
;
137 int event_notifier_group_fd
, ret
;
139 event_notifier_group
= lttng_event_notifier_group_create();
140 if (!event_notifier_group
)
143 event_notifier_group_fd
= lttng_get_unused_fd();
144 if (event_notifier_group_fd
< 0) {
145 ret
= event_notifier_group_fd
;
148 event_notifier_group_file
= anon_inode_getfile("[lttng_event_notifier_group]",
149 <tng_event_notifier_group_fops
,
150 event_notifier_group
, O_RDWR
);
151 if (IS_ERR(event_notifier_group_file
)) {
152 ret
= PTR_ERR(event_notifier_group_file
);
156 event_notifier_group
->file
= event_notifier_group_file
;
157 init_waitqueue_head(&event_notifier_group
->read_wait
);
158 init_irq_work(&event_notifier_group
->wakeup_pending
,
159 event_notifier_send_notification_work_wakeup
);
160 fd_install(event_notifier_group_fd
, event_notifier_group_file
);
161 return event_notifier_group_fd
;
164 put_unused_fd(event_notifier_group_fd
);
166 lttng_event_notifier_group_destroy(event_notifier_group
);
171 int lttng_abi_tracepoint_list(void)
173 struct file
*tracepoint_list_file
;
176 file_fd
= lttng_get_unused_fd();
182 tracepoint_list_file
= anon_inode_getfile("[lttng_tracepoint_list]",
183 <tng_tracepoint_list_fops
,
185 if (IS_ERR(tracepoint_list_file
)) {
186 ret
= PTR_ERR(tracepoint_list_file
);
189 ret
= lttng_tracepoint_list_fops
.open(NULL
, tracepoint_list_file
);
192 fd_install(file_fd
, tracepoint_list_file
);
196 fput(tracepoint_list_file
);
198 put_unused_fd(file_fd
);
203 #ifndef CONFIG_HAVE_SYSCALL_TRACEPOINTS
205 int lttng_abi_syscall_list(void)
211 int lttng_abi_syscall_list(void)
213 struct file
*syscall_list_file
;
216 file_fd
= lttng_get_unused_fd();
222 syscall_list_file
= anon_inode_getfile("[lttng_syscall_list]",
223 <tng_syscall_list_fops
,
225 if (IS_ERR(syscall_list_file
)) {
226 ret
= PTR_ERR(syscall_list_file
);
229 ret
= lttng_syscall_list_fops
.open(NULL
, syscall_list_file
);
232 fd_install(file_fd
, syscall_list_file
);
236 fput(syscall_list_file
);
238 put_unused_fd(file_fd
);
245 void lttng_abi_tracer_version(struct lttng_kernel_abi_tracer_version
*v
)
247 v
->major
= LTTNG_MODULES_MAJOR_VERSION
;
248 v
->minor
= LTTNG_MODULES_MINOR_VERSION
;
249 v
->patchlevel
= LTTNG_MODULES_PATCHLEVEL_VERSION
;
253 void lttng_abi_tracer_abi_version(struct lttng_kernel_abi_tracer_abi_version
*v
)
255 v
->major
= LTTNG_KERNEL_ABI_MAJOR_VERSION
;
256 v
->minor
= LTTNG_KERNEL_ABI_MINOR_VERSION
;
260 long lttng_abi_add_context(struct file
*file
,
261 struct lttng_kernel_abi_context
*context_param
,
262 struct lttng_kernel_ctx
**ctx
, struct lttng_session
*session
)
265 if (session
->been_active
)
268 switch (context_param
->ctx
) {
269 case LTTNG_KERNEL_ABI_CONTEXT_PID
:
270 return lttng_add_pid_to_ctx(ctx
);
271 case LTTNG_KERNEL_ABI_CONTEXT_PRIO
:
272 return lttng_add_prio_to_ctx(ctx
);
273 case LTTNG_KERNEL_ABI_CONTEXT_NICE
:
274 return lttng_add_nice_to_ctx(ctx
);
275 case LTTNG_KERNEL_ABI_CONTEXT_VPID
:
276 return lttng_add_vpid_to_ctx(ctx
);
277 case LTTNG_KERNEL_ABI_CONTEXT_TID
:
278 return lttng_add_tid_to_ctx(ctx
);
279 case LTTNG_KERNEL_ABI_CONTEXT_VTID
:
280 return lttng_add_vtid_to_ctx(ctx
);
281 case LTTNG_KERNEL_ABI_CONTEXT_PPID
:
282 return lttng_add_ppid_to_ctx(ctx
);
283 case LTTNG_KERNEL_ABI_CONTEXT_VPPID
:
284 return lttng_add_vppid_to_ctx(ctx
);
285 case LTTNG_KERNEL_ABI_CONTEXT_PERF_COUNTER
:
286 context_param
->u
.perf_counter
.name
[LTTNG_KERNEL_ABI_SYM_NAME_LEN
- 1] = '\0';
287 return lttng_add_perf_counter_to_ctx(context_param
->u
.perf_counter
.type
,
288 context_param
->u
.perf_counter
.config
,
289 context_param
->u
.perf_counter
.name
,
291 case LTTNG_KERNEL_ABI_CONTEXT_PROCNAME
:
292 return lttng_add_procname_to_ctx(ctx
);
293 case LTTNG_KERNEL_ABI_CONTEXT_HOSTNAME
:
294 return lttng_add_hostname_to_ctx(ctx
);
295 case LTTNG_KERNEL_ABI_CONTEXT_CPU_ID
:
296 return lttng_add_cpu_id_to_ctx(ctx
);
297 case LTTNG_KERNEL_ABI_CONTEXT_INTERRUPTIBLE
:
298 return lttng_add_interruptible_to_ctx(ctx
);
299 case LTTNG_KERNEL_ABI_CONTEXT_NEED_RESCHEDULE
:
300 return lttng_add_need_reschedule_to_ctx(ctx
);
301 case LTTNG_KERNEL_ABI_CONTEXT_PREEMPTIBLE
:
302 return lttng_add_preemptible_to_ctx(ctx
);
303 case LTTNG_KERNEL_ABI_CONTEXT_MIGRATABLE
:
304 return lttng_add_migratable_to_ctx(ctx
);
305 case LTTNG_KERNEL_ABI_CONTEXT_CALLSTACK_KERNEL
:
306 case LTTNG_KERNEL_ABI_CONTEXT_CALLSTACK_USER
:
307 return lttng_add_callstack_to_ctx(ctx
, context_param
->ctx
);
308 case LTTNG_KERNEL_ABI_CONTEXT_CGROUP_NS
:
309 return lttng_add_cgroup_ns_to_ctx(ctx
);
310 case LTTNG_KERNEL_ABI_CONTEXT_IPC_NS
:
311 return lttng_add_ipc_ns_to_ctx(ctx
);
312 case LTTNG_KERNEL_ABI_CONTEXT_MNT_NS
:
313 return lttng_add_mnt_ns_to_ctx(ctx
);
314 case LTTNG_KERNEL_ABI_CONTEXT_NET_NS
:
315 return lttng_add_net_ns_to_ctx(ctx
);
316 case LTTNG_KERNEL_ABI_CONTEXT_PID_NS
:
317 return lttng_add_pid_ns_to_ctx(ctx
);
318 case LTTNG_KERNEL_ABI_CONTEXT_USER_NS
:
319 return lttng_add_user_ns_to_ctx(ctx
);
320 case LTTNG_KERNEL_ABI_CONTEXT_UTS_NS
:
321 return lttng_add_uts_ns_to_ctx(ctx
);
322 case LTTNG_KERNEL_ABI_CONTEXT_UID
:
323 return lttng_add_uid_to_ctx(ctx
);
324 case LTTNG_KERNEL_ABI_CONTEXT_EUID
:
325 return lttng_add_euid_to_ctx(ctx
);
326 case LTTNG_KERNEL_ABI_CONTEXT_SUID
:
327 return lttng_add_suid_to_ctx(ctx
);
328 case LTTNG_KERNEL_ABI_CONTEXT_GID
:
329 return lttng_add_gid_to_ctx(ctx
);
330 case LTTNG_KERNEL_ABI_CONTEXT_EGID
:
331 return lttng_add_egid_to_ctx(ctx
);
332 case LTTNG_KERNEL_ABI_CONTEXT_SGID
:
333 return lttng_add_sgid_to_ctx(ctx
);
334 case LTTNG_KERNEL_ABI_CONTEXT_VUID
:
335 return lttng_add_vuid_to_ctx(ctx
);
336 case LTTNG_KERNEL_ABI_CONTEXT_VEUID
:
337 return lttng_add_veuid_to_ctx(ctx
);
338 case LTTNG_KERNEL_ABI_CONTEXT_VSUID
:
339 return lttng_add_vsuid_to_ctx(ctx
);
340 case LTTNG_KERNEL_ABI_CONTEXT_VGID
:
341 return lttng_add_vgid_to_ctx(ctx
);
342 case LTTNG_KERNEL_ABI_CONTEXT_VEGID
:
343 return lttng_add_vegid_to_ctx(ctx
);
344 case LTTNG_KERNEL_ABI_CONTEXT_VSGID
:
345 return lttng_add_vsgid_to_ctx(ctx
);
346 case LTTNG_KERNEL_ABI_CONTEXT_TIME_NS
:
347 return lttng_add_time_ns_to_ctx(ctx
);
354 * lttng_ioctl - lttng syscall through ioctl
360 * This ioctl implements lttng commands:
361 * LTTNG_KERNEL_ABI_SESSION
362 * Returns a LTTng trace session file descriptor
363 * LTTNG_KERNEL_ABI_TRACER_VERSION
364 * Returns the LTTng kernel tracer version
365 * LTTNG_KERNEL_ABI_TRACEPOINT_LIST
366 * Returns a file descriptor listing available tracepoints
367 * LTTNG_KERNEL_ABI_WAIT_QUIESCENT
368 * Returns after all previously running probes have completed
369 * LTTNG_KERNEL_ABI_TRACER_ABI_VERSION
370 * Returns the LTTng kernel tracer ABI version
371 * LTTNG_KERNEL_ABI_EVENT_NOTIFIER_GROUP_CREATE
372 * Returns a LTTng event notifier group file descriptor
374 * The returned session will be deleted when its file descriptor is closed.
377 long lttng_ioctl(struct file
*file
, unsigned int cmd
, unsigned long arg
)
380 case LTTNG_KERNEL_ABI_OLD_SESSION
:
381 case LTTNG_KERNEL_ABI_SESSION
:
382 return lttng_abi_create_session();
383 case LTTNG_KERNEL_ABI_EVENT_NOTIFIER_GROUP_CREATE
:
384 return lttng_abi_create_event_notifier_group();
385 case LTTNG_KERNEL_ABI_OLD_TRACER_VERSION
:
387 struct lttng_kernel_abi_tracer_version v
;
388 struct lttng_kernel_abi_old_tracer_version oldv
;
389 struct lttng_kernel_abi_old_tracer_version
*uversion
=
390 (struct lttng_kernel_abi_old_tracer_version __user
*) arg
;
392 lttng_abi_tracer_version(&v
);
393 oldv
.major
= v
.major
;
394 oldv
.minor
= v
.minor
;
395 oldv
.patchlevel
= v
.patchlevel
;
397 if (copy_to_user(uversion
, &oldv
, sizeof(oldv
)))
401 case LTTNG_KERNEL_ABI_TRACER_VERSION
:
403 struct lttng_kernel_abi_tracer_version version
;
404 struct lttng_kernel_abi_tracer_version
*uversion
=
405 (struct lttng_kernel_abi_tracer_version __user
*) arg
;
407 lttng_abi_tracer_version(&version
);
409 if (copy_to_user(uversion
, &version
, sizeof(version
)))
413 case LTTNG_KERNEL_ABI_TRACER_ABI_VERSION
:
415 struct lttng_kernel_abi_tracer_abi_version version
;
416 struct lttng_kernel_abi_tracer_abi_version
*uversion
=
417 (struct lttng_kernel_abi_tracer_abi_version __user
*) arg
;
419 lttng_abi_tracer_abi_version(&version
);
421 if (copy_to_user(uversion
, &version
, sizeof(version
)))
425 case LTTNG_KERNEL_ABI_OLD_TRACEPOINT_LIST
:
426 case LTTNG_KERNEL_ABI_TRACEPOINT_LIST
:
427 return lttng_abi_tracepoint_list();
428 case LTTNG_KERNEL_ABI_SYSCALL_LIST
:
429 return lttng_abi_syscall_list();
430 case LTTNG_KERNEL_ABI_OLD_WAIT_QUIESCENT
:
431 case LTTNG_KERNEL_ABI_WAIT_QUIESCENT
:
434 case LTTNG_KERNEL_ABI_OLD_CALIBRATE
:
436 struct lttng_kernel_abi_old_calibrate __user
*ucalibrate
=
437 (struct lttng_kernel_abi_old_calibrate __user
*) arg
;
438 struct lttng_kernel_abi_old_calibrate old_calibrate
;
439 struct lttng_kernel_abi_calibrate calibrate
;
442 if (copy_from_user(&old_calibrate
, ucalibrate
, sizeof(old_calibrate
)))
444 calibrate
.type
= old_calibrate
.type
;
445 ret
= lttng_calibrate(&calibrate
);
446 if (copy_to_user(ucalibrate
, &old_calibrate
, sizeof(old_calibrate
)))
450 case LTTNG_KERNEL_ABI_CALIBRATE
:
452 struct lttng_kernel_abi_calibrate __user
*ucalibrate
=
453 (struct lttng_kernel_abi_calibrate __user
*) arg
;
454 struct lttng_kernel_abi_calibrate calibrate
;
457 if (copy_from_user(&calibrate
, ucalibrate
, sizeof(calibrate
)))
459 ret
= lttng_calibrate(&calibrate
);
460 if (copy_to_user(ucalibrate
, &calibrate
, sizeof(calibrate
)))
469 #if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(5,6,0))
470 static const struct proc_ops lttng_proc_ops
= {
471 .proc_ioctl
= lttng_ioctl
,
473 .proc_compat_ioctl
= lttng_ioctl
,
474 #endif /* CONFIG_COMPAT */
477 static const struct file_operations lttng_proc_ops
= {
478 .owner
= THIS_MODULE
,
479 .unlocked_ioctl
= lttng_ioctl
,
481 .compat_ioctl
= lttng_ioctl
,
482 #endif /* CONFIG_COMPAT */
487 int lttng_abi_create_channel(struct file
*session_file
,
488 struct lttng_kernel_abi_channel
*chan_param
,
489 enum channel_type channel_type
)
491 struct lttng_session
*session
= session_file
->private_data
;
492 const struct file_operations
*fops
= NULL
;
493 const char *transport_name
;
494 struct lttng_channel
*chan
;
495 struct file
*chan_file
;
499 chan_fd
= lttng_get_unused_fd();
504 switch (channel_type
) {
505 case PER_CPU_CHANNEL
:
506 fops
= <tng_channel_fops
;
508 case METADATA_CHANNEL
:
509 fops
= <tng_metadata_fops
;
513 chan_file
= anon_inode_getfile("[lttng_channel]",
516 if (IS_ERR(chan_file
)) {
517 ret
= PTR_ERR(chan_file
);
520 switch (channel_type
) {
521 case PER_CPU_CHANNEL
:
522 if (chan_param
->output
== LTTNG_KERNEL_ABI_SPLICE
) {
523 transport_name
= chan_param
->overwrite
?
524 "relay-overwrite" : "relay-discard";
525 } else if (chan_param
->output
== LTTNG_KERNEL_ABI_MMAP
) {
526 transport_name
= chan_param
->overwrite
?
527 "relay-overwrite-mmap" : "relay-discard-mmap";
532 case METADATA_CHANNEL
:
533 if (chan_param
->output
== LTTNG_KERNEL_ABI_SPLICE
)
534 transport_name
= "relay-metadata";
535 else if (chan_param
->output
== LTTNG_KERNEL_ABI_MMAP
)
536 transport_name
= "relay-metadata-mmap";
541 transport_name
= "<unknown>";
544 if (!atomic_long_add_unless(&session_file
->f_count
, 1, LONG_MAX
)) {
549 * We tolerate no failure path after channel creation. It will stay
550 * invariant for the rest of the session.
552 chan
= lttng_channel_create(session
, transport_name
, NULL
,
553 chan_param
->subbuf_size
,
554 chan_param
->num_subbuf
,
555 chan_param
->switch_timer_interval
,
556 chan_param
->read_timer_interval
,
562 chan
->file
= chan_file
;
563 chan_file
->private_data
= chan
;
564 fd_install(chan_fd
, chan_file
);
569 atomic_long_dec(&session_file
->f_count
);
573 put_unused_fd(chan_fd
);
579 int lttng_abi_session_set_name(struct lttng_session
*session
,
580 struct lttng_kernel_abi_session_name
*name
)
584 len
= strnlen(name
->name
, LTTNG_KERNEL_ABI_SESSION_NAME_LEN
);
586 if (len
== LTTNG_KERNEL_ABI_SESSION_NAME_LEN
) {
587 /* Name is too long/malformed */
591 strcpy(session
->name
, name
->name
);
596 int lttng_abi_session_set_creation_time(struct lttng_session
*session
,
597 struct lttng_kernel_abi_session_creation_time
*time
)
601 len
= strnlen(time
->iso8601
, LTTNG_KERNEL_ABI_SESSION_CREATION_TIME_ISO8601_LEN
);
603 if (len
== LTTNG_KERNEL_ABI_SESSION_CREATION_TIME_ISO8601_LEN
) {
604 /* Time is too long/malformed */
608 strcpy(session
->creation_time
, time
->iso8601
);
613 int lttng_counter_release(struct inode
*inode
, struct file
*file
)
615 struct lttng_counter
*counter
= file
->private_data
;
619 * Do not destroy the counter itself. Wait of the owner
620 * (event_notifier group) to be destroyed.
622 fput(counter
->owner
);
629 long lttng_counter_ioctl(struct file
*file
, unsigned int cmd
, unsigned long arg
)
631 struct lttng_counter
*counter
= file
->private_data
;
632 size_t indexes
[LTTNG_KERNEL_ABI_COUNTER_DIMENSION_MAX
] = { 0 };
636 case LTTNG_KERNEL_ABI_COUNTER_READ
:
638 struct lttng_kernel_abi_counter_read local_counter_read
;
639 struct lttng_kernel_abi_counter_read __user
*ucounter_read
=
640 (struct lttng_kernel_abi_counter_read __user
*) arg
;
641 bool overflow
, underflow
;
646 if (copy_from_user(&local_counter_read
, ucounter_read
,
647 sizeof(local_counter_read
)))
649 if (validate_zeroed_padding(local_counter_read
.padding
,
650 sizeof(local_counter_read
.padding
)))
653 /* Cast all indexes into size_t. */
654 for (i
= 0; i
< local_counter_read
.index
.number_dimensions
; i
++)
655 indexes
[i
] = (size_t) local_counter_read
.index
.dimension_indexes
[i
];
656 cpu
= local_counter_read
.cpu
;
658 ret
= lttng_kernel_counter_read(counter
, indexes
, cpu
, &value
,
659 &overflow
, &underflow
);
662 local_counter_read
.value
.value
= value
;
663 local_counter_read
.value
.overflow
= overflow
;
664 local_counter_read
.value
.underflow
= underflow
;
666 if (copy_to_user(&ucounter_read
->value
, &local_counter_read
.value
,
667 sizeof(local_counter_read
.value
)))
672 case LTTNG_KERNEL_ABI_COUNTER_AGGREGATE
:
674 struct lttng_kernel_abi_counter_aggregate local_counter_aggregate
;
675 struct lttng_kernel_abi_counter_aggregate __user
*ucounter_aggregate
=
676 (struct lttng_kernel_abi_counter_aggregate __user
*) arg
;
677 bool overflow
, underflow
;
681 if (copy_from_user(&local_counter_aggregate
, ucounter_aggregate
,
682 sizeof(local_counter_aggregate
)))
684 if (validate_zeroed_padding(local_counter_aggregate
.padding
,
685 sizeof(local_counter_aggregate
.padding
)))
688 /* Cast all indexes into size_t. */
689 for (i
= 0; i
< local_counter_aggregate
.index
.number_dimensions
; i
++)
690 indexes
[i
] = (size_t) local_counter_aggregate
.index
.dimension_indexes
[i
];
692 ret
= lttng_kernel_counter_aggregate(counter
, indexes
, &value
,
693 &overflow
, &underflow
);
696 local_counter_aggregate
.value
.value
= value
;
697 local_counter_aggregate
.value
.overflow
= overflow
;
698 local_counter_aggregate
.value
.underflow
= underflow
;
700 if (copy_to_user(&ucounter_aggregate
->value
, &local_counter_aggregate
.value
,
701 sizeof(local_counter_aggregate
.value
)))
706 case LTTNG_KERNEL_ABI_COUNTER_CLEAR
:
708 struct lttng_kernel_abi_counter_clear local_counter_clear
;
709 struct lttng_kernel_abi_counter_clear __user
*ucounter_clear
=
710 (struct lttng_kernel_abi_counter_clear __user
*) arg
;
712 if (copy_from_user(&local_counter_clear
, ucounter_clear
,
713 sizeof(local_counter_clear
)))
715 if (validate_zeroed_padding(local_counter_clear
.padding
,
716 sizeof(local_counter_clear
.padding
)))
719 /* Cast all indexes into size_t. */
720 for (i
= 0; i
< local_counter_clear
.index
.number_dimensions
; i
++)
721 indexes
[i
] = (size_t) local_counter_clear
.index
.dimension_indexes
[i
];
723 return lttng_kernel_counter_clear(counter
, indexes
);
731 static const struct file_operations lttng_counter_fops
= {
732 .owner
= THIS_MODULE
,
733 .release
= lttng_counter_release
,
734 .unlocked_ioctl
= lttng_counter_ioctl
,
736 .compat_ioctl
= lttng_counter_ioctl
,
742 enum tracker_type
get_tracker_type(struct lttng_kernel_abi_tracker_args
*tracker
)
744 switch (tracker
->type
) {
745 case LTTNG_KERNEL_ABI_TRACKER_PID
:
747 case LTTNG_KERNEL_ABI_TRACKER_VPID
:
749 case LTTNG_KERNEL_ABI_TRACKER_UID
:
751 case LTTNG_KERNEL_ABI_TRACKER_VUID
:
753 case LTTNG_KERNEL_ABI_TRACKER_GID
:
755 case LTTNG_KERNEL_ABI_TRACKER_VGID
:
758 return TRACKER_UNKNOWN
;
763 * lttng_session_ioctl - lttng session fd ioctl
769 * This ioctl implements lttng commands:
770 * LTTNG_KERNEL_ABI_CHANNEL
771 * Returns a LTTng channel file descriptor
772 * LTTNG_KERNEL_ABI_ENABLE
773 * Enables tracing for a session (weak enable)
774 * LTTNG_KERNEL_ABI_DISABLE
775 * Disables tracing for a session (strong disable)
776 * LTTNG_KERNEL_ABI_METADATA
777 * Returns a LTTng metadata file descriptor
778 * LTTNG_KERNEL_ABI_SESSION_TRACK_PID
779 * Add PID to session PID tracker
780 * LTTNG_KERNEL_ABI_SESSION_UNTRACK_PID
781 * Remove PID from session PID tracker
782 * LTTNG_KERNEL_ABI_SESSION_TRACK_ID
784 * LTTNG_KERNEL_ABI_SESSION_UNTRACK_ID
785 * Remove ID from tracker
787 * The returned channel will be deleted when its file descriptor is closed.
790 long lttng_session_ioctl(struct file
*file
, unsigned int cmd
, unsigned long arg
)
792 struct lttng_session
*session
= file
->private_data
;
793 struct lttng_kernel_abi_channel chan_param
;
794 struct lttng_kernel_abi_old_channel old_chan_param
;
797 * Handle backward compatibility. OLD commands have wrong
798 * directions, replace them by the correct direction.
801 case LTTNG_KERNEL_ABI_OLD_SESSION_TRACK_PID
:
802 cmd
= LTTNG_KERNEL_ABI_SESSION_TRACK_PID
;
804 case LTTNG_KERNEL_ABI_OLD_SESSION_UNTRACK_PID
:
805 cmd
= LTTNG_KERNEL_ABI_SESSION_UNTRACK_PID
;
807 case LTTNG_KERNEL_ABI_OLD_SESSION_TRACK_ID
:
808 cmd
= LTTNG_KERNEL_ABI_SESSION_TRACK_ID
;
810 case LTTNG_KERNEL_ABI_OLD_SESSION_UNTRACK_ID
:
811 cmd
= LTTNG_KERNEL_ABI_SESSION_UNTRACK_ID
;
813 case LTTNG_KERNEL_ABI_OLD_SESSION_LIST_TRACKER_IDS
:
814 cmd
= LTTNG_KERNEL_ABI_SESSION_LIST_TRACKER_IDS
;
816 case LTTNG_KERNEL_ABI_OLD_SESSION_SET_NAME
:
817 cmd
= LTTNG_KERNEL_ABI_SESSION_SET_NAME
;
819 case LTTNG_KERNEL_ABI_OLD_SESSION_SET_CREATION_TIME
:
820 cmd
= LTTNG_KERNEL_ABI_SESSION_SET_CREATION_TIME
;
828 case LTTNG_KERNEL_ABI_OLD_CHANNEL
:
830 if (copy_from_user(&old_chan_param
,
831 (struct lttng_kernel_abi_old_channel __user
*) arg
,
832 sizeof(struct lttng_kernel_abi_old_channel
)))
834 chan_param
.overwrite
= old_chan_param
.overwrite
;
835 chan_param
.subbuf_size
= old_chan_param
.subbuf_size
;
836 chan_param
.num_subbuf
= old_chan_param
.num_subbuf
;
837 chan_param
.switch_timer_interval
= old_chan_param
.switch_timer_interval
;
838 chan_param
.read_timer_interval
= old_chan_param
.read_timer_interval
;
839 chan_param
.output
= old_chan_param
.output
;
841 return lttng_abi_create_channel(file
, &chan_param
,
844 case LTTNG_KERNEL_ABI_CHANNEL
:
846 if (copy_from_user(&chan_param
,
847 (struct lttng_kernel_abi_channel __user
*) arg
,
848 sizeof(struct lttng_kernel_abi_channel
)))
850 return lttng_abi_create_channel(file
, &chan_param
,
853 case LTTNG_KERNEL_ABI_OLD_SESSION_START
:
854 case LTTNG_KERNEL_ABI_OLD_ENABLE
:
855 case LTTNG_KERNEL_ABI_SESSION_START
:
856 case LTTNG_KERNEL_ABI_ENABLE
:
857 return lttng_session_enable(session
);
858 case LTTNG_KERNEL_ABI_OLD_SESSION_STOP
:
859 case LTTNG_KERNEL_ABI_OLD_DISABLE
:
860 case LTTNG_KERNEL_ABI_SESSION_STOP
:
861 case LTTNG_KERNEL_ABI_DISABLE
:
862 return lttng_session_disable(session
);
863 case LTTNG_KERNEL_ABI_OLD_METADATA
:
865 if (copy_from_user(&old_chan_param
,
866 (struct lttng_kernel_abi_old_channel __user
*) arg
,
867 sizeof(struct lttng_kernel_abi_old_channel
)))
869 chan_param
.overwrite
= old_chan_param
.overwrite
;
870 chan_param
.subbuf_size
= old_chan_param
.subbuf_size
;
871 chan_param
.num_subbuf
= old_chan_param
.num_subbuf
;
872 chan_param
.switch_timer_interval
= old_chan_param
.switch_timer_interval
;
873 chan_param
.read_timer_interval
= old_chan_param
.read_timer_interval
;
874 chan_param
.output
= old_chan_param
.output
;
876 return lttng_abi_create_channel(file
, &chan_param
,
879 case LTTNG_KERNEL_ABI_METADATA
:
881 if (copy_from_user(&chan_param
,
882 (struct lttng_kernel_abi_channel __user
*) arg
,
883 sizeof(struct lttng_kernel_abi_channel
)))
885 return lttng_abi_create_channel(file
, &chan_param
,
888 case LTTNG_KERNEL_ABI_SESSION_TRACK_PID
:
889 return lttng_session_track_id(session
, TRACKER_PID
, (int) arg
);
890 case LTTNG_KERNEL_ABI_SESSION_UNTRACK_PID
:
891 return lttng_session_untrack_id(session
, TRACKER_PID
, (int) arg
);
892 case LTTNG_KERNEL_ABI_SESSION_TRACK_ID
:
894 struct lttng_kernel_abi_tracker_args tracker
;
895 enum tracker_type tracker_type
;
897 if (copy_from_user(&tracker
,
898 (struct lttng_kernel_abi_tracker_args __user
*) arg
,
899 sizeof(struct lttng_kernel_abi_tracker_args
)))
901 tracker_type
= get_tracker_type(&tracker
);
902 if (tracker_type
== TRACKER_UNKNOWN
)
904 return lttng_session_track_id(session
, tracker_type
, tracker
.id
);
906 case LTTNG_KERNEL_ABI_SESSION_UNTRACK_ID
:
908 struct lttng_kernel_abi_tracker_args tracker
;
909 enum tracker_type tracker_type
;
911 if (copy_from_user(&tracker
,
912 (struct lttng_kernel_abi_tracker_args __user
*) arg
,
913 sizeof(struct lttng_kernel_abi_tracker_args
)))
915 tracker_type
= get_tracker_type(&tracker
);
916 if (tracker_type
== TRACKER_UNKNOWN
)
918 return lttng_session_untrack_id(session
, tracker_type
,
921 case LTTNG_KERNEL_ABI_SESSION_LIST_TRACKER_PIDS
:
922 return lttng_session_list_tracker_ids(session
, TRACKER_PID
);
923 case LTTNG_KERNEL_ABI_SESSION_LIST_TRACKER_IDS
:
925 struct lttng_kernel_abi_tracker_args tracker
;
926 enum tracker_type tracker_type
;
928 if (copy_from_user(&tracker
,
929 (struct lttng_kernel_abi_tracker_args __user
*) arg
,
930 sizeof(struct lttng_kernel_abi_tracker_args
)))
932 tracker_type
= get_tracker_type(&tracker
);
933 if (tracker_type
== TRACKER_UNKNOWN
)
935 return lttng_session_list_tracker_ids(session
, tracker_type
);
937 case LTTNG_KERNEL_ABI_SESSION_METADATA_REGEN
:
938 return lttng_session_metadata_regenerate(session
);
939 case LTTNG_KERNEL_ABI_SESSION_STATEDUMP
:
940 return lttng_session_statedump(session
);
941 case LTTNG_KERNEL_ABI_SESSION_SET_NAME
:
943 struct lttng_kernel_abi_session_name name
;
945 if (copy_from_user(&name
,
946 (struct lttng_kernel_abi_session_name __user
*) arg
,
947 sizeof(struct lttng_kernel_abi_session_name
)))
949 return lttng_abi_session_set_name(session
, &name
);
951 case LTTNG_KERNEL_ABI_SESSION_SET_CREATION_TIME
:
953 struct lttng_kernel_abi_session_creation_time time
;
955 if (copy_from_user(&time
,
956 (struct lttng_kernel_abi_session_creation_time __user
*) arg
,
957 sizeof(struct lttng_kernel_abi_session_creation_time
)))
959 return lttng_abi_session_set_creation_time(session
, &time
);
967 * Called when the last file reference is dropped.
969 * Big fat note: channels and events are invariant for the whole session after
970 * their creation. So this session destruction also destroys all channel and
971 * event structures specific to this session (they are not destroyed when their
972 * individual file is released).
975 int lttng_session_release(struct inode
*inode
, struct file
*file
)
977 struct lttng_session
*session
= file
->private_data
;
980 lttng_session_destroy(session
);
984 static const struct file_operations lttng_session_fops
= {
985 .owner
= THIS_MODULE
,
986 .release
= lttng_session_release
,
987 .unlocked_ioctl
= lttng_session_ioctl
,
989 .compat_ioctl
= lttng_session_ioctl
,
994 * When encountering empty buffer, flush current sub-buffer if non-empty
995 * and retry (if new data available to read after flush).
998 ssize_t
lttng_event_notifier_group_notif_read(struct file
*filp
, char __user
*user_buf
,
999 size_t count
, loff_t
*ppos
)
1001 struct lttng_event_notifier_group
*event_notifier_group
= filp
->private_data
;
1002 struct channel
*chan
= event_notifier_group
->chan
;
1003 struct lib_ring_buffer
*buf
= event_notifier_group
->buf
;
1004 ssize_t read_count
= 0, len
;
1008 if (!lttng_access_ok(VERIFY_WRITE
, user_buf
, count
))
1011 /* Finish copy of previous record */
1013 if (read_count
< count
) {
1014 len
= chan
->iter
.len_left
;
1015 read_offset
= *ppos
;
1020 while (read_count
< count
) {
1021 size_t copy_len
, space_left
;
1023 len
= lib_ring_buffer_get_next_record(chan
, buf
);
1027 * Check if buffer is finalized (end of file).
1029 if (len
== -ENODATA
) {
1030 /* A 0 read_count will tell about end of file */
1033 if (filp
->f_flags
& O_NONBLOCK
) {
1035 read_count
= -EAGAIN
;
1041 * No data available at the moment, return what
1048 * Wait for returned len to be >= 0 or -ENODATA.
1050 error
= wait_event_interruptible(
1051 event_notifier_group
->read_wait
,
1052 ((len
= lib_ring_buffer_get_next_record(
1053 chan
, buf
)), len
!= -EAGAIN
));
1054 CHAN_WARN_ON(chan
, len
== -EBUSY
);
1059 CHAN_WARN_ON(chan
, len
< 0 && len
!= -ENODATA
);
1063 read_offset
= buf
->iter
.read_offset
;
1065 space_left
= count
- read_count
;
1066 if (len
<= space_left
) {
1068 chan
->iter
.len_left
= 0;
1071 copy_len
= space_left
;
1072 chan
->iter
.len_left
= len
- copy_len
;
1073 *ppos
= read_offset
+ copy_len
;
1075 if (__lib_ring_buffer_copy_to_user(&buf
->backend
, read_offset
,
1076 &user_buf
[read_count
],
1079 * Leave the len_left and ppos values at their current
1080 * state, as we currently have a valid event to read.
1084 read_count
+= copy_len
;
1090 chan
->iter
.len_left
= 0;
1093 lib_ring_buffer_put_current_record(buf
);
1098 * If the ring buffer is non empty (even just a partial subbuffer), return that
1099 * there is data available. Perform a ring buffer flush if we encounter a
1100 * non-empty ring buffer which does not have any consumeable subbuffer available.
1103 unsigned int lttng_event_notifier_group_notif_poll(struct file
*filp
,
1106 unsigned int mask
= 0;
1107 struct lttng_event_notifier_group
*event_notifier_group
= filp
->private_data
;
1108 struct channel
*chan
= event_notifier_group
->chan
;
1109 struct lib_ring_buffer
*buf
= event_notifier_group
->buf
;
1110 const struct lib_ring_buffer_config
*config
= &chan
->backend
.config
;
1111 int finalized
, disabled
;
1112 unsigned long consumed
, offset
;
1113 size_t subbuffer_header_size
= config
->cb
.subbuffer_header_size();
1115 if (filp
->f_mode
& FMODE_READ
) {
1116 poll_wait_set_exclusive(wait
);
1117 poll_wait(filp
, &event_notifier_group
->read_wait
, wait
);
1119 finalized
= lib_ring_buffer_is_finalized(config
, buf
);
1120 disabled
= lib_ring_buffer_channel_is_disabled(chan
);
1123 * lib_ring_buffer_is_finalized() contains a smp_rmb() ordering
1124 * finalized load before offsets loads.
1126 WARN_ON(atomic_long_read(&buf
->active_readers
) != 1);
1131 offset
= lib_ring_buffer_get_offset(config
, buf
);
1132 consumed
= lib_ring_buffer_get_consumed(config
, buf
);
1135 * If there is no buffer available to consume.
1137 if (subbuf_trunc(offset
, chan
) - subbuf_trunc(consumed
, chan
) == 0) {
1139 * If there is a non-empty subbuffer, flush and try again.
1141 if (subbuf_offset(offset
, chan
) > subbuffer_header_size
) {
1142 lib_ring_buffer_switch_remote(buf
);
1150 * The memory barriers
1151 * __wait_event()/wake_up_interruptible() take
1152 * care of "raw_spin_is_locked" memory ordering.
1154 if (raw_spin_is_locked(&buf
->raw_tick_nohz_spinlock
))
1160 if (subbuf_trunc(offset
, chan
) - subbuf_trunc(consumed
, chan
)
1161 >= chan
->backend
.buf_size
)
1162 return POLLPRI
| POLLRDBAND
;
1164 return POLLIN
| POLLRDNORM
;
1172 * lttng_event_notifier_group_notif_open - event_notifier ring buffer open file operation
1173 * @inode: opened inode
1174 * @file: opened file
1176 * Open implementation. Makes sure only one open instance of a buffer is
1177 * done at a given moment.
1179 static int lttng_event_notifier_group_notif_open(struct inode
*inode
, struct file
*file
)
1181 struct lttng_event_notifier_group
*event_notifier_group
= inode
->i_private
;
1182 struct lib_ring_buffer
*buf
= event_notifier_group
->buf
;
1184 file
->private_data
= event_notifier_group
;
1185 return lib_ring_buffer_open(inode
, file
, buf
);
1189 * lttng_event_notifier_group_notif_release - event_notifier ring buffer release file operation
1190 * @inode: opened inode
1191 * @file: opened file
1193 * Release implementation.
1195 static int lttng_event_notifier_group_notif_release(struct inode
*inode
, struct file
*file
)
1197 struct lttng_event_notifier_group
*event_notifier_group
= file
->private_data
;
1198 struct lib_ring_buffer
*buf
= event_notifier_group
->buf
;
1201 ret
= lib_ring_buffer_release(inode
, file
, buf
);
1204 fput(event_notifier_group
->file
);
1208 static const struct file_operations lttng_event_notifier_group_notif_fops
= {
1209 .owner
= THIS_MODULE
,
1210 .open
= lttng_event_notifier_group_notif_open
,
1211 .release
= lttng_event_notifier_group_notif_release
,
1212 .read
= lttng_event_notifier_group_notif_read
,
1213 .poll
= lttng_event_notifier_group_notif_poll
,
1217 * lttng_metadata_ring_buffer_poll - LTTng ring buffer poll file operation
1221 * Handles the poll operations for the metadata channels.
1224 unsigned int lttng_metadata_ring_buffer_poll(struct file
*filp
,
1227 struct lttng_metadata_stream
*stream
= filp
->private_data
;
1228 struct lib_ring_buffer
*buf
= stream
->priv
;
1230 unsigned int mask
= 0;
1232 if (filp
->f_mode
& FMODE_READ
) {
1233 poll_wait_set_exclusive(wait
);
1234 poll_wait(filp
, &stream
->read_wait
, wait
);
1236 finalized
= stream
->finalized
;
1239 * lib_ring_buffer_is_finalized() contains a smp_rmb()
1240 * ordering finalized load before offsets loads.
1242 WARN_ON(atomic_long_read(&buf
->active_readers
) != 1);
1247 mutex_lock(&stream
->metadata_cache
->lock
);
1248 if (stream
->metadata_cache
->metadata_written
>
1249 stream
->metadata_out
)
1251 mutex_unlock(&stream
->metadata_cache
->lock
);
1258 void lttng_metadata_ring_buffer_ioctl_put_next_subbuf(struct file
*filp
,
1259 unsigned int cmd
, unsigned long arg
)
1261 struct lttng_metadata_stream
*stream
= filp
->private_data
;
1263 stream
->metadata_out
= stream
->metadata_in
;
1267 * Reset the counter of how much metadata has been consumed to 0. That way,
1268 * the consumer receives the content of the metadata cache unchanged. This is
1269 * different from the metadata_regenerate where the offset from epoch is
1270 * resampled, here we want the exact same content as the last time the metadata
1271 * was generated. This command is only possible if all the metadata written
1272 * in the cache has been output to the metadata stream to avoid corrupting the
1275 * Return 0 on success, a negative value on error.
1278 int lttng_metadata_cache_dump(struct lttng_metadata_stream
*stream
)
1281 struct lttng_metadata_cache
*cache
= stream
->metadata_cache
;
1283 mutex_lock(&cache
->lock
);
1284 if (stream
->metadata_out
!= cache
->metadata_written
) {
1288 stream
->metadata_out
= 0;
1289 stream
->metadata_in
= 0;
1290 wake_up_interruptible(&stream
->read_wait
);
1294 mutex_unlock(&cache
->lock
);
1299 long lttng_metadata_ring_buffer_ioctl(struct file
*filp
,
1300 unsigned int cmd
, unsigned long arg
)
1303 struct lttng_metadata_stream
*stream
= filp
->private_data
;
1304 struct lib_ring_buffer
*buf
= stream
->priv
;
1305 unsigned int rb_cmd
;
1308 if (cmd
== LTTNG_KERNEL_ABI_RING_BUFFER_GET_NEXT_SUBBUF_METADATA_CHECK
)
1309 rb_cmd
= LTTNG_KERNEL_ABI_RING_BUFFER_GET_NEXT_SUBBUF
;
1314 case LTTNG_KERNEL_ABI_RING_BUFFER_GET_NEXT_SUBBUF
:
1316 struct lttng_metadata_stream
*stream
= filp
->private_data
;
1317 struct lib_ring_buffer
*buf
= stream
->priv
;
1318 struct channel
*chan
= buf
->backend
.chan
;
1320 ret
= lttng_metadata_output_channel(stream
, chan
, NULL
);
1322 lib_ring_buffer_switch_slow(buf
, SWITCH_ACTIVE
);
1328 case LTTNG_KERNEL_ABI_RING_BUFFER_GET_SUBBUF
:
1331 * Random access is not allowed for metadata channel.
1335 case LTTNG_KERNEL_ABI_RING_BUFFER_FLUSH_EMPTY
: /* Fall-through. */
1336 case LTTNG_KERNEL_ABI_RING_BUFFER_FLUSH
:
1338 struct lttng_metadata_stream
*stream
= filp
->private_data
;
1339 struct lib_ring_buffer
*buf
= stream
->priv
;
1340 struct channel
*chan
= buf
->backend
.chan
;
1343 * Before doing the actual ring buffer flush, write up to one
1344 * packet of metadata in the ring buffer.
1346 ret
= lttng_metadata_output_channel(stream
, chan
, NULL
);
1351 case LTTNG_KERNEL_ABI_RING_BUFFER_GET_METADATA_VERSION
:
1353 struct lttng_metadata_stream
*stream
= filp
->private_data
;
1355 return put_u64(stream
->version
, arg
);
1357 case LTTNG_KERNEL_ABI_RING_BUFFER_METADATA_CACHE_DUMP
:
1359 struct lttng_metadata_stream
*stream
= filp
->private_data
;
1361 return lttng_metadata_cache_dump(stream
);
1363 case LTTNG_KERNEL_ABI_RING_BUFFER_GET_NEXT_SUBBUF_METADATA_CHECK
:
1365 struct lttng_metadata_stream
*stream
= filp
->private_data
;
1366 struct lib_ring_buffer
*buf
= stream
->priv
;
1367 struct channel
*chan
= buf
->backend
.chan
;
1369 ret
= lttng_metadata_output_channel(stream
, chan
, &coherent
);
1371 lib_ring_buffer_switch_slow(buf
, SWITCH_ACTIVE
);
1373 } else if (ret
< 0) {
1381 /* PUT_SUBBUF is the one from lib ring buffer, unmodified. */
1383 /* Performing lib ring buffer ioctl after our own. */
1384 ret
= lib_ring_buffer_ioctl(filp
, rb_cmd
, arg
, buf
);
1389 case LTTNG_KERNEL_ABI_RING_BUFFER_PUT_NEXT_SUBBUF
:
1391 lttng_metadata_ring_buffer_ioctl_put_next_subbuf(filp
,
1395 case LTTNG_KERNEL_ABI_RING_BUFFER_GET_NEXT_SUBBUF_METADATA_CHECK
:
1397 return put_u32(coherent
, arg
);
1406 #ifdef CONFIG_COMPAT
1408 long lttng_metadata_ring_buffer_compat_ioctl(struct file
*filp
,
1409 unsigned int cmd
, unsigned long arg
)
1412 struct lttng_metadata_stream
*stream
= filp
->private_data
;
1413 struct lib_ring_buffer
*buf
= stream
->priv
;
1414 unsigned int rb_cmd
;
1417 if (cmd
== LTTNG_KERNEL_ABI_RING_BUFFER_GET_NEXT_SUBBUF_METADATA_CHECK
)
1418 rb_cmd
= LTTNG_KERNEL_ABI_RING_BUFFER_GET_NEXT_SUBBUF
;
1423 case LTTNG_KERNEL_ABI_RING_BUFFER_GET_NEXT_SUBBUF
:
1425 struct lttng_metadata_stream
*stream
= filp
->private_data
;
1426 struct lib_ring_buffer
*buf
= stream
->priv
;
1427 struct channel
*chan
= buf
->backend
.chan
;
1429 ret
= lttng_metadata_output_channel(stream
, chan
, NULL
);
1431 lib_ring_buffer_switch_slow(buf
, SWITCH_ACTIVE
);
1437 case LTTNG_KERNEL_ABI_RING_BUFFER_GET_SUBBUF
:
1440 * Random access is not allowed for metadata channel.
1444 case LTTNG_KERNEL_ABI_RING_BUFFER_FLUSH_EMPTY
: /* Fall-through. */
1445 case LTTNG_KERNEL_ABI_RING_BUFFER_FLUSH
:
1447 struct lttng_metadata_stream
*stream
= filp
->private_data
;
1448 struct lib_ring_buffer
*buf
= stream
->priv
;
1449 struct channel
*chan
= buf
->backend
.chan
;
1452 * Before doing the actual ring buffer flush, write up to one
1453 * packet of metadata in the ring buffer.
1455 ret
= lttng_metadata_output_channel(stream
, chan
, NULL
);
1460 case LTTNG_KERNEL_ABI_RING_BUFFER_GET_METADATA_VERSION
:
1462 struct lttng_metadata_stream
*stream
= filp
->private_data
;
1464 return put_u64(stream
->version
, arg
);
1466 case LTTNG_KERNEL_ABI_RING_BUFFER_METADATA_CACHE_DUMP
:
1468 struct lttng_metadata_stream
*stream
= filp
->private_data
;
1470 return lttng_metadata_cache_dump(stream
);
1472 case LTTNG_KERNEL_ABI_RING_BUFFER_GET_NEXT_SUBBUF_METADATA_CHECK
:
1474 struct lttng_metadata_stream
*stream
= filp
->private_data
;
1475 struct lib_ring_buffer
*buf
= stream
->priv
;
1476 struct channel
*chan
= buf
->backend
.chan
;
1478 ret
= lttng_metadata_output_channel(stream
, chan
, &coherent
);
1480 lib_ring_buffer_switch_slow(buf
, SWITCH_ACTIVE
);
1482 } else if (ret
< 0) {
1490 /* PUT_SUBBUF is the one from lib ring buffer, unmodified. */
1492 /* Performing lib ring buffer ioctl after our own. */
1493 ret
= lib_ring_buffer_compat_ioctl(filp
, rb_cmd
, arg
, buf
);
1498 case LTTNG_KERNEL_ABI_RING_BUFFER_PUT_NEXT_SUBBUF
:
1500 lttng_metadata_ring_buffer_ioctl_put_next_subbuf(filp
,
1504 case LTTNG_KERNEL_ABI_RING_BUFFER_GET_NEXT_SUBBUF_METADATA_CHECK
:
1506 return put_u32(coherent
, arg
);
1517 * This is not used by anonymous file descriptors. This code is left
1518 * there if we ever want to implement an inode with open() operation.
1521 int lttng_metadata_ring_buffer_open(struct inode
*inode
, struct file
*file
)
1523 struct lttng_metadata_stream
*stream
= inode
->i_private
;
1524 struct lib_ring_buffer
*buf
= stream
->priv
;
1526 file
->private_data
= buf
;
1528 * Since life-time of metadata cache differs from that of
1529 * session, we need to keep our own reference on the transport.
1531 if (!try_module_get(stream
->transport
->owner
)) {
1532 printk(KERN_WARNING
"LTTng: Can't lock transport module.\n");
1535 return lib_ring_buffer_open(inode
, file
, buf
);
1539 int lttng_metadata_ring_buffer_release(struct inode
*inode
, struct file
*file
)
1541 struct lttng_metadata_stream
*stream
= file
->private_data
;
1542 struct lib_ring_buffer
*buf
= stream
->priv
;
1544 mutex_lock(&stream
->metadata_cache
->lock
);
1545 list_del(&stream
->list
);
1546 mutex_unlock(&stream
->metadata_cache
->lock
);
1547 kref_put(&stream
->metadata_cache
->refcount
, metadata_cache_destroy
);
1548 module_put(stream
->transport
->owner
);
1550 return lib_ring_buffer_release(inode
, file
, buf
);
1554 ssize_t
lttng_metadata_ring_buffer_splice_read(struct file
*in
, loff_t
*ppos
,
1555 struct pipe_inode_info
*pipe
, size_t len
,
1558 struct lttng_metadata_stream
*stream
= in
->private_data
;
1559 struct lib_ring_buffer
*buf
= stream
->priv
;
1561 return lib_ring_buffer_splice_read(in
, ppos
, pipe
, len
,
1566 int lttng_metadata_ring_buffer_mmap(struct file
*filp
,
1567 struct vm_area_struct
*vma
)
1569 struct lttng_metadata_stream
*stream
= filp
->private_data
;
1570 struct lib_ring_buffer
*buf
= stream
->priv
;
1572 return lib_ring_buffer_mmap(filp
, vma
, buf
);
1576 const struct file_operations lttng_metadata_ring_buffer_file_operations
= {
1577 .owner
= THIS_MODULE
,
1578 .open
= lttng_metadata_ring_buffer_open
,
1579 .release
= lttng_metadata_ring_buffer_release
,
1580 .poll
= lttng_metadata_ring_buffer_poll
,
1581 .splice_read
= lttng_metadata_ring_buffer_splice_read
,
1582 .mmap
= lttng_metadata_ring_buffer_mmap
,
1583 .unlocked_ioctl
= lttng_metadata_ring_buffer_ioctl
,
1584 .llseek
= vfs_lib_ring_buffer_no_llseek
,
1585 #ifdef CONFIG_COMPAT
1586 .compat_ioctl
= lttng_metadata_ring_buffer_compat_ioctl
,
1591 int lttng_abi_create_stream_fd(struct file
*channel_file
, void *stream_priv
,
1592 const struct file_operations
*fops
, const char *name
)
1595 struct file
*stream_file
;
1597 stream_fd
= lttng_get_unused_fd();
1598 if (stream_fd
< 0) {
1602 stream_file
= anon_inode_getfile(name
, fops
, stream_priv
, O_RDWR
);
1603 if (IS_ERR(stream_file
)) {
1604 ret
= PTR_ERR(stream_file
);
1608 * OPEN_FMODE, called within anon_inode_getfile/alloc_file, don't honor
1609 * FMODE_LSEEK, FMODE_PREAD nor FMODE_PWRITE. We need to read from this
1610 * file descriptor, so we set FMODE_PREAD here.
1612 stream_file
->f_mode
|= FMODE_PREAD
;
1613 fd_install(stream_fd
, stream_file
);
1615 * The stream holds a reference to the channel within the generic ring
1616 * buffer library, so no need to hold a refcount on the channel and
1617 * session files here.
1622 put_unused_fd(stream_fd
);
1628 int lttng_abi_open_stream(struct file
*channel_file
)
1630 struct lttng_channel
*channel
= channel_file
->private_data
;
1631 struct lib_ring_buffer
*buf
;
1635 buf
= channel
->ops
->buffer_read_open(channel
->chan
);
1640 ret
= lttng_abi_create_stream_fd(channel_file
, stream_priv
,
1641 <tng_stream_ring_buffer_file_operations
,
1649 channel
->ops
->buffer_read_close(buf
);
1654 int lttng_abi_open_metadata_stream(struct file
*channel_file
)
1656 struct lttng_channel
*channel
= channel_file
->private_data
;
1657 struct lttng_session
*session
= channel
->session
;
1658 struct lib_ring_buffer
*buf
;
1660 struct lttng_metadata_stream
*metadata_stream
;
1663 buf
= channel
->ops
->buffer_read_open(channel
->chan
);
1667 metadata_stream
= kzalloc(sizeof(struct lttng_metadata_stream
),
1669 if (!metadata_stream
) {
1673 metadata_stream
->metadata_cache
= session
->metadata_cache
;
1674 init_waitqueue_head(&metadata_stream
->read_wait
);
1675 metadata_stream
->priv
= buf
;
1676 stream_priv
= metadata_stream
;
1677 metadata_stream
->transport
= channel
->transport
;
1678 /* Initial state is an empty metadata, considered as incoherent. */
1679 metadata_stream
->coherent
= false;
1682 * Since life-time of metadata cache differs from that of
1683 * session, we need to keep our own reference on the transport.
1685 if (!try_module_get(metadata_stream
->transport
->owner
)) {
1686 printk(KERN_WARNING
"LTTng: Can't lock transport module.\n");
1691 if (!lttng_kref_get(&session
->metadata_cache
->refcount
)) {
1696 ret
= lttng_abi_create_stream_fd(channel_file
, stream_priv
,
1697 <tng_metadata_ring_buffer_file_operations
,
1698 "[lttng_metadata_stream]");
1702 mutex_lock(&session
->metadata_cache
->lock
);
1703 list_add(&metadata_stream
->list
,
1704 &session
->metadata_cache
->metadata_stream
);
1705 mutex_unlock(&session
->metadata_cache
->lock
);
1709 kref_put(&session
->metadata_cache
->refcount
, metadata_cache_destroy
);
1711 module_put(metadata_stream
->transport
->owner
);
1713 kfree(metadata_stream
);
1715 channel
->ops
->buffer_read_close(buf
);
1720 int lttng_abi_open_event_notifier_group_stream(struct file
*notif_file
)
1722 struct lttng_event_notifier_group
*event_notifier_group
= notif_file
->private_data
;
1723 struct channel
*chan
= event_notifier_group
->chan
;
1724 struct lib_ring_buffer
*buf
;
1728 buf
= event_notifier_group
->ops
->buffer_read_open(chan
);
1732 /* The event_notifier notification fd holds a reference on the event_notifier group */
1733 if (!atomic_long_add_unless(¬if_file
->f_count
, 1, LONG_MAX
)) {
1735 goto refcount_error
;
1737 event_notifier_group
->buf
= buf
;
1738 stream_priv
= event_notifier_group
;
1739 ret
= lttng_abi_create_stream_fd(notif_file
, stream_priv
,
1740 <tng_event_notifier_group_notif_fops
,
1741 "[lttng_event_notifier_stream]");
1748 atomic_long_dec(¬if_file
->f_count
);
1750 event_notifier_group
->ops
->buffer_read_close(buf
);
1755 int lttng_abi_validate_event_param(struct lttng_kernel_abi_event
*event_param
)
1757 /* Limit ABI to implemented features. */
1758 switch (event_param
->instrumentation
) {
1759 case LTTNG_KERNEL_ABI_SYSCALL
:
1760 switch (event_param
->u
.syscall
.entryexit
) {
1761 case LTTNG_KERNEL_ABI_SYSCALL_ENTRY
: /* Fall-through */
1762 case LTTNG_KERNEL_ABI_SYSCALL_EXIT
: /* Fall-through */
1763 case LTTNG_KERNEL_ABI_SYSCALL_ENTRYEXIT
:
1768 switch (event_param
->u
.syscall
.abi
) {
1769 case LTTNG_KERNEL_ABI_SYSCALL_ABI_ALL
:
1774 switch (event_param
->u
.syscall
.match
) {
1775 case LTTNG_KERNEL_ABI_SYSCALL_MATCH_NAME
:
1782 case LTTNG_KERNEL_ABI_KRETPROBE
:
1783 switch (event_param
->u
.kretprobe
.entryexit
) {
1784 case LTTNG_KERNEL_ABI_SYSCALL_ENTRYEXIT
:
1786 case LTTNG_KERNEL_ABI_SYSCALL_ENTRY
: /* Fall-through */
1787 case LTTNG_KERNEL_ABI_SYSCALL_EXIT
: /* Fall-through */
1793 case LTTNG_KERNEL_ABI_TRACEPOINT
: /* Fall-through */
1794 case LTTNG_KERNEL_ABI_KPROBE
: /* Fall-through */
1795 case LTTNG_KERNEL_ABI_UPROBE
:
1798 case LTTNG_KERNEL_ABI_FUNCTION
: /* Fall-through */
1799 case LTTNG_KERNEL_ABI_NOOP
: /* Fall-through */
1807 int lttng_abi_create_event(struct file
*channel_file
,
1808 struct lttng_kernel_abi_event
*event_param
)
1810 const struct file_operations
*fops
;
1811 struct lttng_channel
*channel
= channel_file
->private_data
;
1813 struct file
*event_file
;
1816 event_param
->name
[LTTNG_KERNEL_ABI_SYM_NAME_LEN
- 1] = '\0';
1817 switch (event_param
->instrumentation
) {
1818 case LTTNG_KERNEL_ABI_KRETPROBE
:
1819 event_param
->u
.kretprobe
.symbol_name
[LTTNG_KERNEL_ABI_SYM_NAME_LEN
- 1] = '\0';
1821 case LTTNG_KERNEL_ABI_KPROBE
:
1822 event_param
->u
.kprobe
.symbol_name
[LTTNG_KERNEL_ABI_SYM_NAME_LEN
- 1] = '\0';
1824 case LTTNG_KERNEL_ABI_FUNCTION
:
1826 /* Not implemented. */
1832 switch (event_param
->instrumentation
) {
1833 case LTTNG_KERNEL_ABI_TRACEPOINT
: /* Fall-through */
1834 case LTTNG_KERNEL_ABI_SYSCALL
:
1835 fops
= <tng_event_recorder_enabler_fops
;
1837 case LTTNG_KERNEL_ABI_KPROBE
: /* Fall-through */
1838 case LTTNG_KERNEL_ABI_KRETPROBE
: /* Fall-through */
1839 case LTTNG_KERNEL_ABI_UPROBE
:
1840 fops
= <tng_event_recorder_event_fops
;
1843 case LTTNG_KERNEL_ABI_FUNCTION
: /* Fall-through */
1844 case LTTNG_KERNEL_ABI_NOOP
: /* Fall-through */
1849 event_fd
= lttng_get_unused_fd();
1854 event_file
= anon_inode_getfile("[lttng_event]",
1855 fops
, NULL
, O_RDWR
);
1856 if (IS_ERR(event_file
)) {
1857 ret
= PTR_ERR(event_file
);
1860 /* The event holds a reference on the channel */
1861 if (!atomic_long_add_unless(&channel_file
->f_count
, 1, LONG_MAX
)) {
1863 goto refcount_error
;
1865 ret
= lttng_abi_validate_event_param(event_param
);
1869 switch (event_param
->instrumentation
) {
1870 case LTTNG_KERNEL_ABI_TRACEPOINT
: /* Fall-through */
1871 case LTTNG_KERNEL_ABI_SYSCALL
:
1873 struct lttng_event_enabler
*event_enabler
;
1875 if (strutils_is_star_glob_pattern(event_param
->name
)) {
1877 * If the event name is a star globbing pattern,
1878 * we create the special star globbing enabler.
1880 event_enabler
= lttng_event_enabler_create(LTTNG_ENABLER_FORMAT_STAR_GLOB
,
1881 event_param
, channel
);
1883 event_enabler
= lttng_event_enabler_create(LTTNG_ENABLER_FORMAT_NAME
,
1884 event_param
, channel
);
1886 priv
= event_enabler
;
1890 case LTTNG_KERNEL_ABI_KPROBE
: /* Fall-through */
1891 case LTTNG_KERNEL_ABI_KRETPROBE
: /* Fall-through */
1892 case LTTNG_KERNEL_ABI_UPROBE
:
1894 struct lttng_kernel_event_recorder
*event
;
1897 * We tolerate no failure path after event creation. It
1898 * will stay invariant for the rest of the session.
1900 event
= lttng_kernel_event_recorder_create(channel
, event_param
,
1901 NULL
, event_param
->instrumentation
);
1902 WARN_ON_ONCE(!event
);
1903 if (IS_ERR(event
)) {
1904 ret
= PTR_ERR(event
);
1911 case LTTNG_KERNEL_ABI_FUNCTION
: /* Fall-through */
1912 case LTTNG_KERNEL_ABI_NOOP
: /* Fall-through */
1917 event_file
->private_data
= priv
;
1918 fd_install(event_fd
, event_file
);
1922 atomic_long_dec(&channel_file
->f_count
);
1926 put_unused_fd(event_fd
);
1932 long lttng_event_notifier_event_ioctl(struct file
*file
, unsigned int cmd
, unsigned long arg
)
1934 struct lttng_kernel_event_notifier
*event_notifier
= file
->private_data
;
1937 case LTTNG_KERNEL_ABI_ENABLE
:
1938 return lttng_event_enable(&event_notifier
->parent
);
1939 case LTTNG_KERNEL_ABI_DISABLE
:
1940 return lttng_event_disable(&event_notifier
->parent
);
1941 case LTTNG_KERNEL_ABI_FILTER
:
1943 case LTTNG_KERNEL_ABI_CAPTURE
:
1945 case LTTNG_KERNEL_ABI_ADD_CALLSITE
:
1946 return lttng_event_add_callsite(&event_notifier
->parent
,
1947 (struct lttng_kernel_abi_event_callsite __user
*) arg
);
1949 return -ENOIOCTLCMD
;
1954 long lttng_event_notifier_enabler_ioctl(struct file
*file
, unsigned int cmd
, unsigned long arg
)
1956 struct lttng_event_notifier_enabler
*event_notifier_enabler
= file
->private_data
;
1959 case LTTNG_KERNEL_ABI_ENABLE
:
1960 return lttng_event_notifier_enabler_enable(event_notifier_enabler
);
1961 case LTTNG_KERNEL_ABI_DISABLE
:
1962 return lttng_event_notifier_enabler_disable(event_notifier_enabler
);
1963 case LTTNG_KERNEL_ABI_FILTER
:
1964 return lttng_event_notifier_enabler_attach_filter_bytecode(
1965 event_notifier_enabler
,
1966 (struct lttng_kernel_abi_filter_bytecode __user
*) arg
);
1967 case LTTNG_KERNEL_ABI_CAPTURE
:
1968 return lttng_event_notifier_enabler_attach_capture_bytecode(
1969 event_notifier_enabler
,
1970 (struct lttng_kernel_abi_capture_bytecode __user
*) arg
);
1971 case LTTNG_KERNEL_ABI_ADD_CALLSITE
:
1974 return -ENOIOCTLCMD
;
1979 int lttng_event_notifier_event_release(struct inode
*inode
, struct file
*file
)
1981 struct lttng_kernel_event_notifier
*event_notifier
= file
->private_data
;
1984 fput(event_notifier
->priv
->group
->file
);
1989 int lttng_event_notifier_enabler_release(struct inode
*inode
, struct file
*file
)
1991 struct lttng_event_notifier_enabler
*event_notifier_enabler
= file
->private_data
;
1993 if (event_notifier_enabler
)
1994 fput(event_notifier_enabler
->group
->file
);
1998 static const struct file_operations lttng_event_notifier_event_fops
= {
1999 .owner
= THIS_MODULE
,
2000 .release
= lttng_event_notifier_event_release
,
2001 .unlocked_ioctl
= lttng_event_notifier_event_ioctl
,
2002 #ifdef CONFIG_COMPAT
2003 .compat_ioctl
= lttng_event_notifier_event_ioctl
,
2007 static const struct file_operations lttng_event_notifier_enabler_fops
= {
2008 .owner
= THIS_MODULE
,
2009 .release
= lttng_event_notifier_enabler_release
,
2010 .unlocked_ioctl
= lttng_event_notifier_enabler_ioctl
,
2011 #ifdef CONFIG_COMPAT
2012 .compat_ioctl
= lttng_event_notifier_enabler_ioctl
,
2017 int lttng_abi_create_event_notifier(struct file
*event_notifier_group_file
,
2018 struct lttng_kernel_abi_event_notifier
*event_notifier_param
)
2020 struct lttng_event_notifier_group
*event_notifier_group
=
2021 event_notifier_group_file
->private_data
;
2022 const struct file_operations
*fops
;
2023 int event_notifier_fd
, ret
;
2024 struct file
*event_notifier_file
;
2027 switch (event_notifier_param
->event
.instrumentation
) {
2028 case LTTNG_KERNEL_ABI_TRACEPOINT
:
2029 case LTTNG_KERNEL_ABI_UPROBE
:
2031 case LTTNG_KERNEL_ABI_KPROBE
:
2032 event_notifier_param
->event
.u
.kprobe
.symbol_name
[LTTNG_KERNEL_ABI_SYM_NAME_LEN
- 1] = '\0';
2034 case LTTNG_KERNEL_ABI_SYSCALL
:
2036 case LTTNG_KERNEL_ABI_KRETPROBE
:
2037 /* Placing an event notifier on kretprobe is not supported. */
2038 case LTTNG_KERNEL_ABI_FUNCTION
:
2039 case LTTNG_KERNEL_ABI_NOOP
:
2045 switch (event_notifier_param
->event
.instrumentation
) {
2046 case LTTNG_KERNEL_ABI_TRACEPOINT
: /* Fall-through */
2047 case LTTNG_KERNEL_ABI_SYSCALL
:
2048 fops
= <tng_event_notifier_enabler_fops
;
2050 case LTTNG_KERNEL_ABI_KPROBE
: /* Fall-through */
2051 case LTTNG_KERNEL_ABI_KRETPROBE
: /* Fall-through */
2052 case LTTNG_KERNEL_ABI_UPROBE
:
2053 fops
= <tng_event_notifier_event_fops
;
2056 case LTTNG_KERNEL_ABI_FUNCTION
: /* Fall-through */
2057 case LTTNG_KERNEL_ABI_NOOP
: /* Fall-through */
2063 event_notifier_param
->event
.name
[LTTNG_KERNEL_ABI_SYM_NAME_LEN
- 1] = '\0';
2065 event_notifier_fd
= lttng_get_unused_fd();
2066 if (event_notifier_fd
< 0) {
2067 ret
= event_notifier_fd
;
2071 event_notifier_file
= anon_inode_getfile("[lttng_event_notifier]",
2072 fops
, NULL
, O_RDWR
);
2073 if (IS_ERR(event_notifier_file
)) {
2074 ret
= PTR_ERR(event_notifier_file
);
2078 /* The event notifier holds a reference on the event notifier group. */
2079 if (!atomic_long_add_unless(&event_notifier_group_file
->f_count
, 1, LONG_MAX
)) {
2081 goto refcount_error
;
2084 ret
= lttng_abi_validate_event_param(&event_notifier_param
->event
);
2086 goto event_notifier_error
;
2088 switch (event_notifier_param
->event
.instrumentation
) {
2089 case LTTNG_KERNEL_ABI_TRACEPOINT
: /* Fall-through */
2090 case LTTNG_KERNEL_ABI_SYSCALL
:
2092 struct lttng_event_notifier_enabler
*enabler
;
2094 if (strutils_is_star_glob_pattern(event_notifier_param
->event
.name
)) {
2096 * If the event name is a star globbing pattern,
2097 * we create the special star globbing enabler.
2099 enabler
= lttng_event_notifier_enabler_create(
2100 event_notifier_group
,
2101 LTTNG_ENABLER_FORMAT_STAR_GLOB
,
2102 event_notifier_param
);
2104 enabler
= lttng_event_notifier_enabler_create(
2105 event_notifier_group
,
2106 LTTNG_ENABLER_FORMAT_NAME
,
2107 event_notifier_param
);
2113 case LTTNG_KERNEL_ABI_KPROBE
: /* Fall-through */
2114 case LTTNG_KERNEL_ABI_KRETPROBE
: /* Fall-through */
2115 case LTTNG_KERNEL_ABI_UPROBE
:
2117 struct lttng_kernel_event_notifier
*event_notifier
;
2120 * We tolerate no failure path after event notifier creation.
2121 * It will stay invariant for the rest of the session.
2123 event_notifier
= lttng_event_notifier_create(NULL
,
2124 event_notifier_param
->event
.token
,
2125 event_notifier_param
->error_counter_index
,
2126 event_notifier_group
,
2127 event_notifier_param
,
2128 event_notifier_param
->event
.instrumentation
);
2129 WARN_ON_ONCE(!event_notifier
);
2130 if (IS_ERR(event_notifier
)) {
2131 ret
= PTR_ERR(event_notifier
);
2132 goto event_notifier_error
;
2134 priv
= event_notifier
;
2138 case LTTNG_KERNEL_ABI_FUNCTION
: /* Fall-through */
2139 case LTTNG_KERNEL_ABI_NOOP
: /* Fall-through */
2142 goto event_notifier_error
;
2144 event_notifier_file
->private_data
= priv
;
2145 fd_install(event_notifier_fd
, event_notifier_file
);
2146 return event_notifier_fd
;
2148 event_notifier_error
:
2149 atomic_long_dec(&event_notifier_group_file
->f_count
);
2151 fput(event_notifier_file
);
2153 put_unused_fd(event_notifier_fd
);
2160 long lttng_abi_event_notifier_group_create_error_counter(
2161 struct file
*event_notifier_group_file
,
2162 const struct lttng_kernel_abi_counter_conf
*error_counter_conf
)
2164 int counter_fd
, ret
;
2165 char *counter_transport_name
;
2167 struct lttng_counter
*counter
= NULL
;
2168 struct file
*counter_file
;
2169 struct lttng_event_notifier_group
*event_notifier_group
=
2170 (struct lttng_event_notifier_group
*) event_notifier_group_file
->private_data
;
2172 if (error_counter_conf
->arithmetic
!= LTTNG_KERNEL_ABI_COUNTER_ARITHMETIC_MODULAR
) {
2173 printk(KERN_ERR
"LTTng: event_notifier: Error counter of the wrong arithmetic type.\n");
2177 if (error_counter_conf
->number_dimensions
!= 1) {
2178 printk(KERN_ERR
"LTTng: event_notifier: Error counter has more than one dimension.\n");
2182 switch (error_counter_conf
->bitness
) {
2183 case LTTNG_KERNEL_ABI_COUNTER_BITNESS_64
:
2184 counter_transport_name
= "counter-per-cpu-64-modular";
2186 case LTTNG_KERNEL_ABI_COUNTER_BITNESS_32
:
2187 counter_transport_name
= "counter-per-cpu-32-modular";
2194 * Lock sessions to provide mutual exclusion against concurrent
2195 * modification of event_notifier group, which would result in
2196 * overwriting the error counter if set concurrently.
2198 lttng_lock_sessions();
2200 if (event_notifier_group
->error_counter
) {
2201 printk(KERN_ERR
"Error counter already created in event_notifier group\n");
2206 counter_fd
= lttng_get_unused_fd();
2207 if (counter_fd
< 0) {
2212 counter_file
= anon_inode_getfile("[lttng_counter]",
2213 <tng_counter_fops
,
2215 if (IS_ERR(counter_file
)) {
2216 ret
= PTR_ERR(counter_file
);
2220 counter_len
= error_counter_conf
->dimensions
[0].size
;
2222 if (!atomic_long_add_unless(&event_notifier_group_file
->f_count
, 1, LONG_MAX
)) {
2224 goto refcount_error
;
2227 counter
= lttng_kernel_counter_create(counter_transport_name
,
2234 event_notifier_group
->error_counter_len
= counter_len
;
2236 * store-release to publish error counter matches load-acquire
2237 * in record_error. Ensures the counter is created and the
2238 * error_counter_len is set before they are used.
2240 lttng_smp_store_release(&event_notifier_group
->error_counter
, counter
);
2242 counter
->file
= counter_file
;
2243 counter
->owner
= event_notifier_group
->file
;
2244 counter_file
->private_data
= counter
;
2245 /* Ownership transferred. */
2248 fd_install(counter_fd
, counter_file
);
2249 lttng_unlock_sessions();
2254 atomic_long_dec(&event_notifier_group_file
->f_count
);
2258 put_unused_fd(counter_fd
);
2260 lttng_unlock_sessions();
2265 long lttng_event_notifier_group_ioctl(struct file
*file
, unsigned int cmd
,
2269 case LTTNG_KERNEL_ABI_EVENT_NOTIFIER_GROUP_NOTIFICATION_FD
:
2271 return lttng_abi_open_event_notifier_group_stream(file
);
2273 case LTTNG_KERNEL_ABI_EVENT_NOTIFIER_CREATE
:
2275 struct lttng_kernel_abi_event_notifier uevent_notifier_param
;
2277 if (copy_from_user(&uevent_notifier_param
,
2278 (struct lttng_kernel_abi_event_notifier __user
*) arg
,
2279 sizeof(uevent_notifier_param
)))
2281 return lttng_abi_create_event_notifier(file
, &uevent_notifier_param
);
2283 case LTTNG_KERNEL_ABI_COUNTER
:
2285 struct lttng_kernel_abi_counter_conf uerror_counter_conf
;
2287 if (copy_from_user(&uerror_counter_conf
,
2288 (struct lttng_kernel_abi_counter_conf __user
*) arg
,
2289 sizeof(uerror_counter_conf
)))
2291 return lttng_abi_event_notifier_group_create_error_counter(file
,
2292 &uerror_counter_conf
);
2295 return -ENOIOCTLCMD
;
2301 int lttng_event_notifier_group_release(struct inode
*inode
, struct file
*file
)
2303 struct lttng_event_notifier_group
*event_notifier_group
=
2306 if (event_notifier_group
)
2307 lttng_event_notifier_group_destroy(event_notifier_group
);
2311 static const struct file_operations lttng_event_notifier_group_fops
= {
2312 .owner
= THIS_MODULE
,
2313 .release
= lttng_event_notifier_group_release
,
2314 .unlocked_ioctl
= lttng_event_notifier_group_ioctl
,
2315 #ifdef CONFIG_COMPAT
2316 .compat_ioctl
= lttng_event_notifier_group_ioctl
,
2321 * lttng_channel_ioctl - lttng syscall through ioctl
2327 * This ioctl implements lttng commands:
2328 * LTTNG_KERNEL_ABI_STREAM
2329 * Returns an event stream file descriptor or failure.
2330 * (typically, one event stream records events from one CPU)
2331 * LTTNG_KERNEL_ABI_EVENT
2332 * Returns an event file descriptor or failure.
2333 * LTTNG_KERNEL_ABI_CONTEXT
2334 * Prepend a context field to each event in the channel
2335 * LTTNG_KERNEL_ABI_ENABLE
2336 * Enable recording for events in this channel (weak enable)
2337 * LTTNG_KERNEL_ABI_DISABLE
2338 * Disable recording for events in this channel (strong disable)
2340 * Channel and event file descriptors also hold a reference on the session.
2343 long lttng_channel_ioctl(struct file
*file
, unsigned int cmd
, unsigned long arg
)
2345 struct lttng_channel
*channel
= file
->private_data
;
2348 case LTTNG_KERNEL_ABI_OLD_STREAM
:
2349 case LTTNG_KERNEL_ABI_STREAM
:
2350 return lttng_abi_open_stream(file
);
2351 case LTTNG_KERNEL_ABI_OLD_EVENT
:
2353 struct lttng_kernel_abi_event
*uevent_param
;
2354 struct lttng_kernel_abi_old_event
*old_uevent_param
;
2357 uevent_param
= kmalloc(sizeof(struct lttng_kernel_abi_event
),
2359 if (!uevent_param
) {
2363 old_uevent_param
= kmalloc(
2364 sizeof(struct lttng_kernel_abi_old_event
),
2366 if (!old_uevent_param
) {
2368 goto old_event_error_free_param
;
2370 if (copy_from_user(old_uevent_param
,
2371 (struct lttng_kernel_abi_old_event __user
*) arg
,
2372 sizeof(struct lttng_kernel_abi_old_event
))) {
2374 goto old_event_error_free_old_param
;
2377 memcpy(uevent_param
->name
, old_uevent_param
->name
,
2378 sizeof(uevent_param
->name
));
2379 uevent_param
->instrumentation
=
2380 old_uevent_param
->instrumentation
;
2382 switch (old_uevent_param
->instrumentation
) {
2383 case LTTNG_KERNEL_ABI_KPROBE
:
2384 uevent_param
->u
.kprobe
.addr
=
2385 old_uevent_param
->u
.kprobe
.addr
;
2386 uevent_param
->u
.kprobe
.offset
=
2387 old_uevent_param
->u
.kprobe
.offset
;
2388 memcpy(uevent_param
->u
.kprobe
.symbol_name
,
2389 old_uevent_param
->u
.kprobe
.symbol_name
,
2390 sizeof(uevent_param
->u
.kprobe
.symbol_name
));
2392 case LTTNG_KERNEL_ABI_KRETPROBE
:
2393 uevent_param
->u
.kretprobe
.addr
=
2394 old_uevent_param
->u
.kretprobe
.addr
;
2395 uevent_param
->u
.kretprobe
.offset
=
2396 old_uevent_param
->u
.kretprobe
.offset
;
2397 memcpy(uevent_param
->u
.kretprobe
.symbol_name
,
2398 old_uevent_param
->u
.kretprobe
.symbol_name
,
2399 sizeof(uevent_param
->u
.kretprobe
.symbol_name
));
2401 case LTTNG_KERNEL_ABI_FUNCTION
:
2403 /* Not implemented. */
2408 ret
= lttng_abi_create_event(file
, uevent_param
);
2410 old_event_error_free_old_param
:
2411 kfree(old_uevent_param
);
2412 old_event_error_free_param
:
2413 kfree(uevent_param
);
2417 case LTTNG_KERNEL_ABI_EVENT
:
2419 struct lttng_kernel_abi_event uevent_param
;
2421 if (copy_from_user(&uevent_param
,
2422 (struct lttng_kernel_abi_event __user
*) arg
,
2423 sizeof(uevent_param
)))
2425 return lttng_abi_create_event(file
, &uevent_param
);
2427 case LTTNG_KERNEL_ABI_OLD_CONTEXT
:
2429 struct lttng_kernel_abi_context
*ucontext_param
;
2430 struct lttng_kernel_abi_old_context
*old_ucontext_param
;
2433 ucontext_param
= kmalloc(sizeof(struct lttng_kernel_abi_context
),
2435 if (!ucontext_param
) {
2439 old_ucontext_param
= kmalloc(sizeof(struct lttng_kernel_abi_old_context
),
2441 if (!old_ucontext_param
) {
2443 goto old_ctx_error_free_param
;
2446 if (copy_from_user(old_ucontext_param
,
2447 (struct lttng_kernel_abi_old_context __user
*) arg
,
2448 sizeof(struct lttng_kernel_abi_old_context
))) {
2450 goto old_ctx_error_free_old_param
;
2452 ucontext_param
->ctx
= old_ucontext_param
->ctx
;
2453 memcpy(ucontext_param
->padding
, old_ucontext_param
->padding
,
2454 sizeof(ucontext_param
->padding
));
2455 /* only type that uses the union */
2456 if (old_ucontext_param
->ctx
== LTTNG_KERNEL_ABI_CONTEXT_PERF_COUNTER
) {
2457 ucontext_param
->u
.perf_counter
.type
=
2458 old_ucontext_param
->u
.perf_counter
.type
;
2459 ucontext_param
->u
.perf_counter
.config
=
2460 old_ucontext_param
->u
.perf_counter
.config
;
2461 memcpy(ucontext_param
->u
.perf_counter
.name
,
2462 old_ucontext_param
->u
.perf_counter
.name
,
2463 sizeof(ucontext_param
->u
.perf_counter
.name
));
2466 ret
= lttng_abi_add_context(file
,
2468 &channel
->ctx
, channel
->session
);
2470 old_ctx_error_free_old_param
:
2471 kfree(old_ucontext_param
);
2472 old_ctx_error_free_param
:
2473 kfree(ucontext_param
);
2477 case LTTNG_KERNEL_ABI_CONTEXT
:
2479 struct lttng_kernel_abi_context ucontext_param
;
2481 if (copy_from_user(&ucontext_param
,
2482 (struct lttng_kernel_abi_context __user
*) arg
,
2483 sizeof(ucontext_param
)))
2485 return lttng_abi_add_context(file
,
2487 &channel
->ctx
, channel
->session
);
2489 case LTTNG_KERNEL_ABI_OLD_ENABLE
:
2490 case LTTNG_KERNEL_ABI_ENABLE
:
2491 return lttng_channel_enable(channel
);
2492 case LTTNG_KERNEL_ABI_OLD_DISABLE
:
2493 case LTTNG_KERNEL_ABI_DISABLE
:
2494 return lttng_channel_disable(channel
);
2495 case LTTNG_KERNEL_ABI_SYSCALL_MASK
:
2496 return lttng_channel_syscall_mask(channel
,
2497 (struct lttng_kernel_abi_syscall_mask __user
*) arg
);
2499 return -ENOIOCTLCMD
;
2504 * lttng_metadata_ioctl - lttng syscall through ioctl
2510 * This ioctl implements lttng commands:
2511 * LTTNG_KERNEL_ABI_STREAM
2512 * Returns an event stream file descriptor or failure.
2514 * Channel and event file descriptors also hold a reference on the session.
2517 long lttng_metadata_ioctl(struct file
*file
, unsigned int cmd
, unsigned long arg
)
2520 case LTTNG_KERNEL_ABI_OLD_STREAM
:
2521 case LTTNG_KERNEL_ABI_STREAM
:
2522 return lttng_abi_open_metadata_stream(file
);
2524 return -ENOIOCTLCMD
;
2529 * lttng_channel_poll - lttng stream addition/removal monitoring
2534 unsigned int lttng_channel_poll(struct file
*file
, poll_table
*wait
)
2536 struct lttng_channel
*channel
= file
->private_data
;
2537 unsigned int mask
= 0;
2539 if (file
->f_mode
& FMODE_READ
) {
2540 poll_wait_set_exclusive(wait
);
2541 poll_wait(file
, channel
->ops
->get_hp_wait_queue(channel
->chan
),
2544 if (channel
->ops
->is_disabled(channel
->chan
))
2546 if (channel
->ops
->is_finalized(channel
->chan
))
2548 if (channel
->ops
->buffer_has_read_closed_stream(channel
->chan
))
2549 return POLLIN
| POLLRDNORM
;
2557 int lttng_channel_release(struct inode
*inode
, struct file
*file
)
2559 struct lttng_channel
*channel
= file
->private_data
;
2562 fput(channel
->session
->file
);
2567 int lttng_metadata_channel_release(struct inode
*inode
, struct file
*file
)
2569 struct lttng_channel
*channel
= file
->private_data
;
2572 fput(channel
->session
->file
);
2573 lttng_metadata_channel_destroy(channel
);
2579 static const struct file_operations lttng_channel_fops
= {
2580 .owner
= THIS_MODULE
,
2581 .release
= lttng_channel_release
,
2582 .poll
= lttng_channel_poll
,
2583 .unlocked_ioctl
= lttng_channel_ioctl
,
2584 #ifdef CONFIG_COMPAT
2585 .compat_ioctl
= lttng_channel_ioctl
,
2589 static const struct file_operations lttng_metadata_fops
= {
2590 .owner
= THIS_MODULE
,
2591 .release
= lttng_metadata_channel_release
,
2592 .unlocked_ioctl
= lttng_metadata_ioctl
,
2593 #ifdef CONFIG_COMPAT
2594 .compat_ioctl
= lttng_metadata_ioctl
,
2599 * lttng_event_recorder_event_ioctl - lttng syscall through ioctl
2605 * This ioctl implements lttng commands:
2606 * LTTNG_KERNEL_ABI_CONTEXT
2607 * Prepend a context field to each record of this event
2608 * LTTNG_KERNEL_ABI_ENABLE
2609 * Enable recording for this event (weak enable)
2610 * LTTNG_KERNEL_ABI_DISABLE
2611 * Disable recording for this event (strong disable)
2614 long lttng_event_recorder_event_ioctl(struct file
*file
, unsigned int cmd
, unsigned long arg
)
2616 struct lttng_kernel_event_recorder
*event_recorder
= file
->private_data
;
2619 case LTTNG_KERNEL_ABI_OLD_CONTEXT
:
2621 /* Not implemented */
2624 case LTTNG_KERNEL_ABI_CONTEXT
:
2626 /* Not implemented */
2629 case LTTNG_KERNEL_ABI_OLD_ENABLE
:
2630 case LTTNG_KERNEL_ABI_ENABLE
:
2631 return lttng_event_enable(&event_recorder
->parent
);
2632 case LTTNG_KERNEL_ABI_OLD_DISABLE
:
2633 case LTTNG_KERNEL_ABI_DISABLE
:
2634 return lttng_event_disable(&event_recorder
->parent
);
2635 case LTTNG_KERNEL_ABI_FILTER
:
2637 case LTTNG_KERNEL_ABI_ADD_CALLSITE
:
2638 return lttng_event_add_callsite(&event_recorder
->parent
,
2639 (struct lttng_kernel_abi_event_callsite __user
*) arg
);
2641 return -ENOIOCTLCMD
;
2646 * lttng_event_recorder_enabler_ioctl - lttng syscall through ioctl
2652 * This ioctl implements lttng commands:
2653 * LTTNG_KERNEL_ABI_CONTEXT
2654 * Prepend a context field to each record of this event
2655 * LTTNG_KERNEL_ABI_ENABLE
2656 * Enable recording for this event (weak enable)
2657 * LTTNG_KERNEL_ABI_DISABLE
2658 * Disable recording for this event (strong disable)
2661 long lttng_event_recorder_enabler_ioctl(struct file
*file
, unsigned int cmd
, unsigned long arg
)
2663 struct lttng_event_enabler
*event_enabler
= file
->private_data
;
2666 case LTTNG_KERNEL_ABI_OLD_CONTEXT
:
2668 /* Not implemented */
2671 case LTTNG_KERNEL_ABI_CONTEXT
:
2673 /* Not implemented */
2676 case LTTNG_KERNEL_ABI_OLD_ENABLE
:
2677 case LTTNG_KERNEL_ABI_ENABLE
:
2678 return lttng_event_enabler_enable(event_enabler
);
2679 case LTTNG_KERNEL_ABI_OLD_DISABLE
:
2680 case LTTNG_KERNEL_ABI_DISABLE
:
2681 return lttng_event_enabler_disable(event_enabler
);
2682 case LTTNG_KERNEL_ABI_FILTER
:
2683 return lttng_event_enabler_attach_filter_bytecode(
2685 (struct lttng_kernel_abi_filter_bytecode __user
*) arg
);
2686 case LTTNG_KERNEL_ABI_ADD_CALLSITE
:
2689 return -ENOIOCTLCMD
;
2694 int lttng_event_recorder_event_release(struct inode
*inode
, struct file
*file
)
2696 struct lttng_kernel_event_recorder
*event
= file
->private_data
;
2699 fput(event
->chan
->file
);
2704 int lttng_event_recorder_enabler_release(struct inode
*inode
, struct file
*file
)
2706 struct lttng_event_enabler
*event_enabler
= file
->private_data
;
2709 fput(event_enabler
->chan
->file
);
2713 static const struct file_operations lttng_event_recorder_event_fops
= {
2714 .owner
= THIS_MODULE
,
2715 .release
= lttng_event_recorder_event_release
,
2716 .unlocked_ioctl
= lttng_event_recorder_event_ioctl
,
2717 #ifdef CONFIG_COMPAT
2718 .compat_ioctl
= lttng_event_recorder_event_ioctl
,
2722 static const struct file_operations lttng_event_recorder_enabler_fops
= {
2723 .owner
= THIS_MODULE
,
2724 .release
= lttng_event_recorder_enabler_release
,
2725 .unlocked_ioctl
= lttng_event_recorder_enabler_ioctl
,
2726 #ifdef CONFIG_COMPAT
2727 .compat_ioctl
= lttng_event_recorder_enabler_ioctl
,
2731 static int put_u64(uint64_t val
, unsigned long arg
)
2733 return put_user(val
, (uint64_t __user
*) arg
);
2736 static int put_u32(uint32_t val
, unsigned long arg
)
2738 return put_user(val
, (uint32_t __user
*) arg
);
2741 static long lttng_stream_ring_buffer_ioctl(struct file
*filp
,
2742 unsigned int cmd
, unsigned long arg
)
2744 struct lib_ring_buffer
*buf
= filp
->private_data
;
2745 struct channel
*chan
= buf
->backend
.chan
;
2746 const struct lib_ring_buffer_config
*config
= &chan
->backend
.config
;
2747 const struct lttng_channel_ops
*ops
= chan
->backend
.priv_ops
;
2750 if (atomic_read(&chan
->record_disabled
))
2754 case LTTNG_KERNEL_ABI_RING_BUFFER_GET_TIMESTAMP_BEGIN
:
2758 ret
= ops
->timestamp_begin(config
, buf
, &ts
);
2761 return put_u64(ts
, arg
);
2763 case LTTNG_KERNEL_ABI_RING_BUFFER_GET_TIMESTAMP_END
:
2767 ret
= ops
->timestamp_end(config
, buf
, &ts
);
2770 return put_u64(ts
, arg
);
2772 case LTTNG_KERNEL_ABI_RING_BUFFER_GET_EVENTS_DISCARDED
:
2776 ret
= ops
->events_discarded(config
, buf
, &ed
);
2779 return put_u64(ed
, arg
);
2781 case LTTNG_KERNEL_ABI_RING_BUFFER_GET_CONTENT_SIZE
:
2785 ret
= ops
->content_size(config
, buf
, &cs
);
2788 return put_u64(cs
, arg
);
2790 case LTTNG_KERNEL_ABI_RING_BUFFER_GET_PACKET_SIZE
:
2794 ret
= ops
->packet_size(config
, buf
, &ps
);
2797 return put_u64(ps
, arg
);
2799 case LTTNG_KERNEL_ABI_RING_BUFFER_GET_STREAM_ID
:
2803 ret
= ops
->stream_id(config
, buf
, &si
);
2806 return put_u64(si
, arg
);
2808 case LTTNG_KERNEL_ABI_RING_BUFFER_GET_CURRENT_TIMESTAMP
:
2812 ret
= ops
->current_timestamp(config
, buf
, &ts
);
2815 return put_u64(ts
, arg
);
2817 case LTTNG_KERNEL_ABI_RING_BUFFER_GET_SEQ_NUM
:
2821 ret
= ops
->sequence_number(config
, buf
, &seq
);
2824 return put_u64(seq
, arg
);
2826 case LTTNG_KERNEL_ABI_RING_BUFFER_INSTANCE_ID
:
2830 ret
= ops
->instance_id(config
, buf
, &id
);
2833 return put_u64(id
, arg
);
2836 return lib_ring_buffer_file_operations
.unlocked_ioctl(filp
,
2844 #ifdef CONFIG_COMPAT
2845 static long lttng_stream_ring_buffer_compat_ioctl(struct file
*filp
,
2846 unsigned int cmd
, unsigned long arg
)
2848 struct lib_ring_buffer
*buf
= filp
->private_data
;
2849 struct channel
*chan
= buf
->backend
.chan
;
2850 const struct lib_ring_buffer_config
*config
= &chan
->backend
.config
;
2851 const struct lttng_channel_ops
*ops
= chan
->backend
.priv_ops
;
2854 if (atomic_read(&chan
->record_disabled
))
2858 case LTTNG_KERNEL_ABI_RING_BUFFER_COMPAT_GET_TIMESTAMP_BEGIN
:
2862 ret
= ops
->timestamp_begin(config
, buf
, &ts
);
2865 return put_u64(ts
, arg
);
2867 case LTTNG_KERNEL_ABI_RING_BUFFER_COMPAT_GET_TIMESTAMP_END
:
2871 ret
= ops
->timestamp_end(config
, buf
, &ts
);
2874 return put_u64(ts
, arg
);
2876 case LTTNG_KERNEL_ABI_RING_BUFFER_COMPAT_GET_EVENTS_DISCARDED
:
2880 ret
= ops
->events_discarded(config
, buf
, &ed
);
2883 return put_u64(ed
, arg
);
2885 case LTTNG_KERNEL_ABI_RING_BUFFER_COMPAT_GET_CONTENT_SIZE
:
2889 ret
= ops
->content_size(config
, buf
, &cs
);
2892 return put_u64(cs
, arg
);
2894 case LTTNG_KERNEL_ABI_RING_BUFFER_COMPAT_GET_PACKET_SIZE
:
2898 ret
= ops
->packet_size(config
, buf
, &ps
);
2901 return put_u64(ps
, arg
);
2903 case LTTNG_KERNEL_ABI_RING_BUFFER_COMPAT_GET_STREAM_ID
:
2907 ret
= ops
->stream_id(config
, buf
, &si
);
2910 return put_u64(si
, arg
);
2912 case LTTNG_KERNEL_ABI_RING_BUFFER_GET_CURRENT_TIMESTAMP
:
2916 ret
= ops
->current_timestamp(config
, buf
, &ts
);
2919 return put_u64(ts
, arg
);
2921 case LTTNG_KERNEL_ABI_RING_BUFFER_COMPAT_GET_SEQ_NUM
:
2925 ret
= ops
->sequence_number(config
, buf
, &seq
);
2928 return put_u64(seq
, arg
);
2930 case LTTNG_KERNEL_ABI_RING_BUFFER_COMPAT_INSTANCE_ID
:
2934 ret
= ops
->instance_id(config
, buf
, &id
);
2937 return put_u64(id
, arg
);
2940 return lib_ring_buffer_file_operations
.compat_ioctl(filp
,
2947 #endif /* CONFIG_COMPAT */
2949 static void lttng_stream_override_ring_buffer_fops(void)
2951 lttng_stream_ring_buffer_file_operations
.owner
= THIS_MODULE
;
2952 lttng_stream_ring_buffer_file_operations
.open
=
2953 lib_ring_buffer_file_operations
.open
;
2954 lttng_stream_ring_buffer_file_operations
.release
=
2955 lib_ring_buffer_file_operations
.release
;
2956 lttng_stream_ring_buffer_file_operations
.poll
=
2957 lib_ring_buffer_file_operations
.poll
;
2958 lttng_stream_ring_buffer_file_operations
.splice_read
=
2959 lib_ring_buffer_file_operations
.splice_read
;
2960 lttng_stream_ring_buffer_file_operations
.mmap
=
2961 lib_ring_buffer_file_operations
.mmap
;
2962 lttng_stream_ring_buffer_file_operations
.unlocked_ioctl
=
2963 lttng_stream_ring_buffer_ioctl
;
2964 lttng_stream_ring_buffer_file_operations
.llseek
=
2965 lib_ring_buffer_file_operations
.llseek
;
2966 #ifdef CONFIG_COMPAT
2967 lttng_stream_ring_buffer_file_operations
.compat_ioctl
=
2968 lttng_stream_ring_buffer_compat_ioctl
;
2972 int __init
lttng_abi_init(void)
2976 wrapper_vmalloc_sync_mappings();
2979 ret
= lttng_tp_mempool_init();
2984 lttng_proc_dentry
= proc_create_data("lttng", S_IRUSR
| S_IWUSR
, NULL
,
2985 <tng_proc_ops
, NULL
);
2987 if (!lttng_proc_dentry
) {
2988 printk(KERN_ERR
"LTTng: Error creating control file\n");
2992 lttng_stream_override_ring_buffer_fops();
2996 lttng_tp_mempool_destroy();
2997 lttng_clock_unref();
3001 /* No __exit annotation because used by init error path too. */
3002 void lttng_abi_exit(void)
3004 lttng_tp_mempool_destroy();
3005 lttng_clock_unref();
3006 if (lttng_proc_dentry
)
3007 remove_proc_entry("lttng", NULL
);