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 <asm/barrier.h>
27 #include <linux/module.h>
28 #include <linux/proc_fs.h>
29 #include <linux/anon_inodes.h>
30 #include <linux/file.h>
31 #include <linux/uaccess.h>
32 #include <linux/slab.h>
33 #include <linux/err.h>
34 #include <wrapper/vmalloc.h> /* for wrapper_vmalloc_sync_mappings() */
35 #include <ringbuffer/vfs.h>
36 #include <ringbuffer/backend.h>
37 #include <ringbuffer/frontend.h>
38 #include <wrapper/compiler_attributes.h>
39 #include <wrapper/poll.h>
40 #include <wrapper/kref.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_kernel_session
*session
;
95 struct file
*session_file
;
98 session
= lttng_session_create();
101 session_fd
= get_unused_fd_flags(0);
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
->priv
->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
= get_unused_fd_flags(0);
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
= get_unused_fd_flags(0);
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
= get_unused_fd_flags(0);
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_kernel_session
*session
)
265 if (session
->priv
->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_kernel_session
*session
= session_file
->private_data
;
492 const struct file_operations
*fops
= NULL
;
493 const char *transport_name
;
494 struct lttng_kernel_channel_buffer
*chan
;
495 struct file
*chan_file
;
499 chan_fd
= get_unused_fd_flags(0);
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_buffer_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
->priv
->parent
.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_kernel_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
->priv
->name
, name
->name
);
596 int lttng_abi_session_set_creation_time(struct lttng_kernel_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
->priv
->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
)))
652 if (local_counter_read
.index
.number_dimensions
> LTTNG_KERNEL_ABI_COUNTER_DIMENSION_MAX
)
655 /* Cast all indexes into size_t. */
656 for (i
= 0; i
< local_counter_read
.index
.number_dimensions
; i
++)
657 indexes
[i
] = (size_t) local_counter_read
.index
.dimension_indexes
[i
];
658 cpu
= local_counter_read
.cpu
;
660 ret
= lttng_kernel_counter_read(counter
, indexes
, cpu
, &value
,
661 &overflow
, &underflow
);
664 local_counter_read
.value
.value
= value
;
665 local_counter_read
.value
.overflow
= overflow
;
666 local_counter_read
.value
.underflow
= underflow
;
668 if (copy_to_user(&ucounter_read
->value
, &local_counter_read
.value
,
669 sizeof(local_counter_read
.value
)))
674 case LTTNG_KERNEL_ABI_COUNTER_AGGREGATE
:
676 struct lttng_kernel_abi_counter_aggregate local_counter_aggregate
;
677 struct lttng_kernel_abi_counter_aggregate __user
*ucounter_aggregate
=
678 (struct lttng_kernel_abi_counter_aggregate __user
*) arg
;
679 bool overflow
, underflow
;
683 if (copy_from_user(&local_counter_aggregate
, ucounter_aggregate
,
684 sizeof(local_counter_aggregate
)))
686 if (validate_zeroed_padding(local_counter_aggregate
.padding
,
687 sizeof(local_counter_aggregate
.padding
)))
689 if (local_counter_aggregate
.index
.number_dimensions
> LTTNG_KERNEL_ABI_COUNTER_DIMENSION_MAX
)
692 /* Cast all indexes into size_t. */
693 for (i
= 0; i
< local_counter_aggregate
.index
.number_dimensions
; i
++)
694 indexes
[i
] = (size_t) local_counter_aggregate
.index
.dimension_indexes
[i
];
696 ret
= lttng_kernel_counter_aggregate(counter
, indexes
, &value
,
697 &overflow
, &underflow
);
700 local_counter_aggregate
.value
.value
= value
;
701 local_counter_aggregate
.value
.overflow
= overflow
;
702 local_counter_aggregate
.value
.underflow
= underflow
;
704 if (copy_to_user(&ucounter_aggregate
->value
, &local_counter_aggregate
.value
,
705 sizeof(local_counter_aggregate
.value
)))
710 case LTTNG_KERNEL_ABI_COUNTER_CLEAR
:
712 struct lttng_kernel_abi_counter_clear local_counter_clear
;
713 struct lttng_kernel_abi_counter_clear __user
*ucounter_clear
=
714 (struct lttng_kernel_abi_counter_clear __user
*) arg
;
716 if (copy_from_user(&local_counter_clear
, ucounter_clear
,
717 sizeof(local_counter_clear
)))
719 if (validate_zeroed_padding(local_counter_clear
.padding
,
720 sizeof(local_counter_clear
.padding
)))
722 if (local_counter_clear
.index
.number_dimensions
> LTTNG_KERNEL_ABI_COUNTER_DIMENSION_MAX
)
725 /* Cast all indexes into size_t. */
726 for (i
= 0; i
< local_counter_clear
.index
.number_dimensions
; i
++)
727 indexes
[i
] = (size_t) local_counter_clear
.index
.dimension_indexes
[i
];
729 return lttng_kernel_counter_clear(counter
, indexes
);
736 static const struct file_operations lttng_counter_fops
= {
737 .owner
= THIS_MODULE
,
738 .release
= lttng_counter_release
,
739 .unlocked_ioctl
= lttng_counter_ioctl
,
741 .compat_ioctl
= lttng_counter_ioctl
,
747 enum tracker_type
get_tracker_type(struct lttng_kernel_abi_tracker_args
*tracker
)
749 switch (tracker
->type
) {
750 case LTTNG_KERNEL_ABI_TRACKER_PID
:
752 case LTTNG_KERNEL_ABI_TRACKER_VPID
:
754 case LTTNG_KERNEL_ABI_TRACKER_UID
:
756 case LTTNG_KERNEL_ABI_TRACKER_VUID
:
758 case LTTNG_KERNEL_ABI_TRACKER_GID
:
760 case LTTNG_KERNEL_ABI_TRACKER_VGID
:
763 return TRACKER_UNKNOWN
;
768 * lttng_session_ioctl - lttng session fd ioctl
774 * This ioctl implements lttng commands:
775 * LTTNG_KERNEL_ABI_CHANNEL
776 * Returns a LTTng channel file descriptor
777 * LTTNG_KERNEL_ABI_ENABLE
778 * Enables tracing for a session (weak enable)
779 * LTTNG_KERNEL_ABI_DISABLE
780 * Disables tracing for a session (strong disable)
781 * LTTNG_KERNEL_ABI_METADATA
782 * Returns a LTTng metadata file descriptor
783 * LTTNG_KERNEL_ABI_SESSION_TRACK_PID
784 * Add PID to session PID tracker
785 * LTTNG_KERNEL_ABI_SESSION_UNTRACK_PID
786 * Remove PID from session PID tracker
787 * LTTNG_KERNEL_ABI_SESSION_TRACK_ID
789 * LTTNG_KERNEL_ABI_SESSION_UNTRACK_ID
790 * Remove ID from tracker
792 * The returned channel will be deleted when its file descriptor is closed.
795 long lttng_session_ioctl(struct file
*file
, unsigned int cmd
, unsigned long arg
)
797 struct lttng_kernel_session
*session
= file
->private_data
;
798 struct lttng_kernel_abi_channel chan_param
;
799 struct lttng_kernel_abi_old_channel old_chan_param
;
802 * Handle backward compatibility. OLD commands have wrong
803 * directions, replace them by the correct direction.
806 case LTTNG_KERNEL_ABI_OLD_SESSION_TRACK_PID
:
807 cmd
= LTTNG_KERNEL_ABI_SESSION_TRACK_PID
;
809 case LTTNG_KERNEL_ABI_OLD_SESSION_UNTRACK_PID
:
810 cmd
= LTTNG_KERNEL_ABI_SESSION_UNTRACK_PID
;
812 case LTTNG_KERNEL_ABI_OLD_SESSION_TRACK_ID
:
813 cmd
= LTTNG_KERNEL_ABI_SESSION_TRACK_ID
;
815 case LTTNG_KERNEL_ABI_OLD_SESSION_UNTRACK_ID
:
816 cmd
= LTTNG_KERNEL_ABI_SESSION_UNTRACK_ID
;
818 case LTTNG_KERNEL_ABI_OLD_SESSION_LIST_TRACKER_IDS
:
819 cmd
= LTTNG_KERNEL_ABI_SESSION_LIST_TRACKER_IDS
;
821 case LTTNG_KERNEL_ABI_OLD_SESSION_SET_NAME
:
822 cmd
= LTTNG_KERNEL_ABI_SESSION_SET_NAME
;
824 case LTTNG_KERNEL_ABI_OLD_SESSION_SET_CREATION_TIME
:
825 cmd
= LTTNG_KERNEL_ABI_SESSION_SET_CREATION_TIME
;
833 case LTTNG_KERNEL_ABI_OLD_CHANNEL
:
835 if (copy_from_user(&old_chan_param
,
836 (struct lttng_kernel_abi_old_channel __user
*) arg
,
837 sizeof(struct lttng_kernel_abi_old_channel
)))
839 chan_param
.overwrite
= old_chan_param
.overwrite
;
840 chan_param
.subbuf_size
= old_chan_param
.subbuf_size
;
841 chan_param
.num_subbuf
= old_chan_param
.num_subbuf
;
842 chan_param
.switch_timer_interval
= old_chan_param
.switch_timer_interval
;
843 chan_param
.read_timer_interval
= old_chan_param
.read_timer_interval
;
844 chan_param
.output
= old_chan_param
.output
;
846 return lttng_abi_create_channel(file
, &chan_param
,
849 case LTTNG_KERNEL_ABI_CHANNEL
:
851 if (copy_from_user(&chan_param
,
852 (struct lttng_kernel_abi_channel __user
*) arg
,
853 sizeof(struct lttng_kernel_abi_channel
)))
855 return lttng_abi_create_channel(file
, &chan_param
,
858 case LTTNG_KERNEL_ABI_OLD_SESSION_START
:
859 case LTTNG_KERNEL_ABI_OLD_ENABLE
:
860 case LTTNG_KERNEL_ABI_SESSION_START
:
861 case LTTNG_KERNEL_ABI_ENABLE
:
862 return lttng_session_enable(session
);
863 case LTTNG_KERNEL_ABI_OLD_SESSION_STOP
:
864 case LTTNG_KERNEL_ABI_OLD_DISABLE
:
865 case LTTNG_KERNEL_ABI_SESSION_STOP
:
866 case LTTNG_KERNEL_ABI_DISABLE
:
867 return lttng_session_disable(session
);
868 case LTTNG_KERNEL_ABI_OLD_METADATA
:
870 if (copy_from_user(&old_chan_param
,
871 (struct lttng_kernel_abi_old_channel __user
*) arg
,
872 sizeof(struct lttng_kernel_abi_old_channel
)))
874 chan_param
.overwrite
= old_chan_param
.overwrite
;
875 chan_param
.subbuf_size
= old_chan_param
.subbuf_size
;
876 chan_param
.num_subbuf
= old_chan_param
.num_subbuf
;
877 chan_param
.switch_timer_interval
= old_chan_param
.switch_timer_interval
;
878 chan_param
.read_timer_interval
= old_chan_param
.read_timer_interval
;
879 chan_param
.output
= old_chan_param
.output
;
881 return lttng_abi_create_channel(file
, &chan_param
,
884 case LTTNG_KERNEL_ABI_METADATA
:
886 if (copy_from_user(&chan_param
,
887 (struct lttng_kernel_abi_channel __user
*) arg
,
888 sizeof(struct lttng_kernel_abi_channel
)))
890 return lttng_abi_create_channel(file
, &chan_param
,
893 case LTTNG_KERNEL_ABI_SESSION_TRACK_PID
:
894 return lttng_session_track_id(session
, TRACKER_PID
, (int) arg
);
895 case LTTNG_KERNEL_ABI_SESSION_UNTRACK_PID
:
896 return lttng_session_untrack_id(session
, TRACKER_PID
, (int) arg
);
897 case LTTNG_KERNEL_ABI_SESSION_TRACK_ID
:
899 struct lttng_kernel_abi_tracker_args tracker
;
900 enum tracker_type tracker_type
;
902 if (copy_from_user(&tracker
,
903 (struct lttng_kernel_abi_tracker_args __user
*) arg
,
904 sizeof(struct lttng_kernel_abi_tracker_args
)))
906 tracker_type
= get_tracker_type(&tracker
);
907 if (tracker_type
== TRACKER_UNKNOWN
)
909 return lttng_session_track_id(session
, tracker_type
, tracker
.id
);
911 case LTTNG_KERNEL_ABI_SESSION_UNTRACK_ID
:
913 struct lttng_kernel_abi_tracker_args tracker
;
914 enum tracker_type tracker_type
;
916 if (copy_from_user(&tracker
,
917 (struct lttng_kernel_abi_tracker_args __user
*) arg
,
918 sizeof(struct lttng_kernel_abi_tracker_args
)))
920 tracker_type
= get_tracker_type(&tracker
);
921 if (tracker_type
== TRACKER_UNKNOWN
)
923 return lttng_session_untrack_id(session
, tracker_type
,
926 case LTTNG_KERNEL_ABI_SESSION_LIST_TRACKER_PIDS
:
927 return lttng_session_list_tracker_ids(session
, TRACKER_PID
);
928 case LTTNG_KERNEL_ABI_SESSION_LIST_TRACKER_IDS
:
930 struct lttng_kernel_abi_tracker_args tracker
;
931 enum tracker_type tracker_type
;
933 if (copy_from_user(&tracker
,
934 (struct lttng_kernel_abi_tracker_args __user
*) arg
,
935 sizeof(struct lttng_kernel_abi_tracker_args
)))
937 tracker_type
= get_tracker_type(&tracker
);
938 if (tracker_type
== TRACKER_UNKNOWN
)
940 return lttng_session_list_tracker_ids(session
, tracker_type
);
942 case LTTNG_KERNEL_ABI_SESSION_METADATA_REGEN
:
943 return lttng_session_metadata_regenerate(session
);
944 case LTTNG_KERNEL_ABI_SESSION_STATEDUMP
:
945 return lttng_session_statedump(session
);
946 case LTTNG_KERNEL_ABI_SESSION_SET_NAME
:
948 struct lttng_kernel_abi_session_name name
;
950 if (copy_from_user(&name
,
951 (struct lttng_kernel_abi_session_name __user
*) arg
,
952 sizeof(struct lttng_kernel_abi_session_name
)))
954 return lttng_abi_session_set_name(session
, &name
);
956 case LTTNG_KERNEL_ABI_SESSION_SET_CREATION_TIME
:
958 struct lttng_kernel_abi_session_creation_time time
;
960 if (copy_from_user(&time
,
961 (struct lttng_kernel_abi_session_creation_time __user
*) arg
,
962 sizeof(struct lttng_kernel_abi_session_creation_time
)))
964 return lttng_abi_session_set_creation_time(session
, &time
);
972 * Called when the last file reference is dropped.
974 * Big fat note: channels and events are invariant for the whole session after
975 * their creation. So this session destruction also destroys all channel and
976 * event structures specific to this session (they are not destroyed when their
977 * individual file is released).
980 int lttng_session_release(struct inode
*inode
, struct file
*file
)
982 struct lttng_kernel_session
*session
= file
->private_data
;
985 lttng_session_destroy(session
);
989 static const struct file_operations lttng_session_fops
= {
990 .owner
= THIS_MODULE
,
991 .release
= lttng_session_release
,
992 .unlocked_ioctl
= lttng_session_ioctl
,
994 .compat_ioctl
= lttng_session_ioctl
,
999 * When encountering empty buffer, flush current sub-buffer if non-empty
1000 * and retry (if new data available to read after flush).
1003 ssize_t
lttng_event_notifier_group_notif_read(struct file
*filp
, char __user
*user_buf
,
1004 size_t count
, loff_t
*ppos
)
1006 struct lttng_event_notifier_group
*event_notifier_group
= filp
->private_data
;
1007 struct lttng_kernel_ring_buffer_channel
*chan
= event_notifier_group
->chan
;
1008 struct lttng_kernel_ring_buffer
*buf
= event_notifier_group
->buf
;
1009 ssize_t read_count
= 0, len
;
1013 if (!lttng_access_ok(VERIFY_WRITE
, user_buf
, count
))
1016 /* Finish copy of previous record */
1019 len
= chan
->iter
.len_left
;
1020 read_offset
= *ppos
;
1025 while (read_count
< count
) {
1026 size_t copy_len
, space_left
;
1028 len
= lib_ring_buffer_get_next_record(chan
, buf
);
1032 * Check if buffer is finalized (end of file).
1034 if (len
== -ENODATA
) {
1035 /* A 0 read_count will tell about end of file */
1038 if (filp
->f_flags
& O_NONBLOCK
) {
1040 read_count
= -EAGAIN
;
1046 * No data available at the moment, return what
1053 * Wait for returned len to be >= 0 or -ENODATA.
1055 error
= wait_event_interruptible(
1056 event_notifier_group
->read_wait
,
1057 ((len
= lib_ring_buffer_get_next_record(
1058 chan
, buf
)), len
!= -EAGAIN
));
1059 CHAN_WARN_ON(chan
, len
== -EBUSY
);
1064 CHAN_WARN_ON(chan
, len
< 0 && len
!= -ENODATA
);
1068 read_offset
= buf
->iter
.read_offset
;
1070 space_left
= count
- read_count
;
1071 if (len
<= space_left
) {
1073 chan
->iter
.len_left
= 0;
1076 copy_len
= space_left
;
1077 chan
->iter
.len_left
= len
- copy_len
;
1078 *ppos
= read_offset
+ copy_len
;
1080 if (__lib_ring_buffer_copy_to_user(&buf
->backend
, read_offset
,
1081 &user_buf
[read_count
],
1084 * Leave the len_left and ppos values at their current
1085 * state, as we currently have a valid event to read.
1089 read_count
+= copy_len
;
1095 chan
->iter
.len_left
= 0;
1099 lib_ring_buffer_put_current_record(buf
);
1104 * If the ring buffer is non empty (even just a partial subbuffer), return that
1105 * there is data available. Perform a ring buffer flush if we encounter a
1106 * non-empty ring buffer which does not have any consumeable subbuffer available.
1109 unsigned int lttng_event_notifier_group_notif_poll(struct file
*filp
,
1112 unsigned int mask
= 0;
1113 struct lttng_event_notifier_group
*event_notifier_group
= filp
->private_data
;
1114 struct lttng_kernel_ring_buffer_channel
*chan
= event_notifier_group
->chan
;
1115 struct lttng_kernel_ring_buffer
*buf
= event_notifier_group
->buf
;
1116 const struct lttng_kernel_ring_buffer_config
*config
= &chan
->backend
.config
;
1117 int finalized
, disabled
;
1118 unsigned long consumed
, offset
;
1119 size_t subbuffer_header_size
= config
->cb
.subbuffer_header_size();
1121 if (filp
->f_mode
& FMODE_READ
) {
1122 poll_wait_set_exclusive(wait
);
1123 poll_wait(filp
, &event_notifier_group
->read_wait
, wait
);
1125 finalized
= lib_ring_buffer_is_finalized(config
, buf
);
1126 disabled
= lib_ring_buffer_channel_is_disabled(chan
);
1129 * lib_ring_buffer_is_finalized() contains a smp_rmb() ordering
1130 * finalized load before offsets loads.
1132 WARN_ON(atomic_long_read(&buf
->active_readers
) != 1);
1137 offset
= lib_ring_buffer_get_offset(config
, buf
);
1138 consumed
= lib_ring_buffer_get_consumed(config
, buf
);
1141 * If there is no buffer available to consume.
1143 if (subbuf_trunc(offset
, chan
) - subbuf_trunc(consumed
, chan
) == 0) {
1145 * If there is a non-empty subbuffer, flush and try again.
1147 if (subbuf_offset(offset
, chan
) > subbuffer_header_size
) {
1148 lib_ring_buffer_switch_remote(buf
);
1156 * The memory barriers
1157 * __wait_event()/wake_up_interruptible() take
1158 * care of "raw_spin_is_locked" memory ordering.
1160 if (raw_spin_is_locked(&buf
->raw_tick_nohz_spinlock
))
1166 if (subbuf_trunc(offset
, chan
) - subbuf_trunc(consumed
, chan
)
1167 >= chan
->backend
.buf_size
)
1168 return POLLPRI
| POLLRDBAND
;
1170 return POLLIN
| POLLRDNORM
;
1178 * lttng_event_notifier_group_notif_open - event_notifier ring buffer open file operation
1179 * @inode: opened inode
1180 * @file: opened file
1182 * Open implementation. Makes sure only one open instance of a buffer is
1183 * done at a given moment.
1185 static int lttng_event_notifier_group_notif_open(struct inode
*inode
, struct file
*file
)
1187 struct lttng_event_notifier_group
*event_notifier_group
= inode
->i_private
;
1188 struct lttng_kernel_ring_buffer
*buf
= event_notifier_group
->buf
;
1190 file
->private_data
= event_notifier_group
;
1191 return lib_ring_buffer_open(inode
, file
, buf
);
1195 * lttng_event_notifier_group_notif_release - event_notifier ring buffer release file operation
1196 * @inode: opened inode
1197 * @file: opened file
1199 * Release implementation.
1201 static int lttng_event_notifier_group_notif_release(struct inode
*inode
, struct file
*file
)
1203 struct lttng_event_notifier_group
*event_notifier_group
= file
->private_data
;
1204 struct lttng_kernel_ring_buffer
*buf
= event_notifier_group
->buf
;
1207 ret
= lib_ring_buffer_release(inode
, file
, buf
);
1210 fput(event_notifier_group
->file
);
1214 static const struct file_operations lttng_event_notifier_group_notif_fops
= {
1215 .owner
= THIS_MODULE
,
1216 .open
= lttng_event_notifier_group_notif_open
,
1217 .release
= lttng_event_notifier_group_notif_release
,
1218 .read
= lttng_event_notifier_group_notif_read
,
1219 .poll
= lttng_event_notifier_group_notif_poll
,
1223 * lttng_metadata_ring_buffer_poll - LTTng ring buffer poll file operation
1227 * Handles the poll operations for the metadata channels.
1230 unsigned int lttng_metadata_ring_buffer_poll(struct file
*filp
,
1233 struct lttng_metadata_stream
*stream
= filp
->private_data
;
1234 struct lttng_kernel_ring_buffer
*buf
= stream
->priv
;
1236 unsigned int mask
= 0;
1238 if (filp
->f_mode
& FMODE_READ
) {
1239 poll_wait_set_exclusive(wait
);
1240 poll_wait(filp
, &stream
->read_wait
, wait
);
1242 finalized
= stream
->finalized
;
1245 * lib_ring_buffer_is_finalized() contains a smp_rmb()
1246 * ordering finalized load before offsets loads.
1248 WARN_ON(atomic_long_read(&buf
->active_readers
) != 1);
1253 mutex_lock(&stream
->metadata_cache
->lock
);
1254 if (stream
->metadata_cache
->metadata_written
>
1255 stream
->metadata_out
)
1257 mutex_unlock(&stream
->metadata_cache
->lock
);
1264 void lttng_metadata_ring_buffer_ioctl_put_next_subbuf(struct file
*filp
,
1265 unsigned int cmd
, unsigned long arg
)
1267 struct lttng_metadata_stream
*stream
= filp
->private_data
;
1269 stream
->metadata_out
= stream
->metadata_in
;
1273 * Reset the counter of how much metadata has been consumed to 0. That way,
1274 * the consumer receives the content of the metadata cache unchanged. This is
1275 * different from the metadata_regenerate where the offset from epoch is
1276 * resampled, here we want the exact same content as the last time the metadata
1277 * was generated. This command is only possible if all the metadata written
1278 * in the cache has been output to the metadata stream to avoid corrupting the
1281 * Return 0 on success, a negative value on error.
1284 int lttng_metadata_cache_dump(struct lttng_metadata_stream
*stream
)
1287 struct lttng_metadata_cache
*cache
= stream
->metadata_cache
;
1289 mutex_lock(&cache
->lock
);
1290 if (stream
->metadata_out
!= cache
->metadata_written
) {
1294 stream
->metadata_out
= 0;
1295 stream
->metadata_in
= 0;
1296 wake_up_interruptible(&stream
->read_wait
);
1300 mutex_unlock(&cache
->lock
);
1305 long lttng_metadata_ring_buffer_ioctl(struct file
*filp
,
1306 unsigned int cmd
, unsigned long arg
)
1309 struct lttng_metadata_stream
*stream
= filp
->private_data
;
1310 struct lttng_kernel_ring_buffer
*buf
= stream
->priv
;
1311 unsigned int rb_cmd
;
1314 if (cmd
== LTTNG_KERNEL_ABI_RING_BUFFER_GET_NEXT_SUBBUF_METADATA_CHECK
)
1315 rb_cmd
= LTTNG_KERNEL_ABI_RING_BUFFER_GET_NEXT_SUBBUF
;
1320 case LTTNG_KERNEL_ABI_RING_BUFFER_GET_NEXT_SUBBUF
:
1322 struct lttng_metadata_stream
*stream
= filp
->private_data
;
1323 struct lttng_kernel_ring_buffer
*buf
= stream
->priv
;
1324 struct lttng_kernel_ring_buffer_channel
*chan
= buf
->backend
.chan
;
1326 ret
= lttng_metadata_output_channel(stream
, chan
, NULL
);
1328 lib_ring_buffer_switch_slow(buf
, SWITCH_ACTIVE
);
1334 case LTTNG_KERNEL_ABI_RING_BUFFER_GET_SUBBUF
:
1337 * Random access is not allowed for metadata channel.
1341 case LTTNG_KERNEL_ABI_RING_BUFFER_FLUSH_EMPTY
:
1343 case LTTNG_KERNEL_ABI_RING_BUFFER_FLUSH
:
1345 struct lttng_metadata_stream
*stream
= filp
->private_data
;
1346 struct lttng_kernel_ring_buffer
*buf
= stream
->priv
;
1347 struct lttng_kernel_ring_buffer_channel
*chan
= buf
->backend
.chan
;
1350 * Before doing the actual ring buffer flush, write up to one
1351 * packet of metadata in the ring buffer.
1353 ret
= lttng_metadata_output_channel(stream
, chan
, NULL
);
1358 case LTTNG_KERNEL_ABI_RING_BUFFER_GET_METADATA_VERSION
:
1360 struct lttng_metadata_stream
*stream
= filp
->private_data
;
1362 return put_u64(stream
->version
, arg
);
1364 case LTTNG_KERNEL_ABI_RING_BUFFER_METADATA_CACHE_DUMP
:
1366 struct lttng_metadata_stream
*stream
= filp
->private_data
;
1368 return lttng_metadata_cache_dump(stream
);
1370 case LTTNG_KERNEL_ABI_RING_BUFFER_GET_NEXT_SUBBUF_METADATA_CHECK
:
1372 struct lttng_metadata_stream
*stream
= filp
->private_data
;
1373 struct lttng_kernel_ring_buffer
*buf
= stream
->priv
;
1374 struct lttng_kernel_ring_buffer_channel
*chan
= buf
->backend
.chan
;
1376 ret
= lttng_metadata_output_channel(stream
, chan
, &coherent
);
1378 lib_ring_buffer_switch_slow(buf
, SWITCH_ACTIVE
);
1380 } else if (ret
< 0) {
1388 /* PUT_SUBBUF is the one from lib ring buffer, unmodified. */
1390 /* Performing lib ring buffer ioctl after our own. */
1391 ret
= lib_ring_buffer_ioctl(filp
, rb_cmd
, arg
, buf
);
1396 case LTTNG_KERNEL_ABI_RING_BUFFER_PUT_NEXT_SUBBUF
:
1398 lttng_metadata_ring_buffer_ioctl_put_next_subbuf(filp
,
1402 case LTTNG_KERNEL_ABI_RING_BUFFER_GET_NEXT_SUBBUF_METADATA_CHECK
:
1404 return put_u32(coherent
, arg
);
1413 #ifdef CONFIG_COMPAT
1415 long lttng_metadata_ring_buffer_compat_ioctl(struct file
*filp
,
1416 unsigned int cmd
, unsigned long arg
)
1419 struct lttng_metadata_stream
*stream
= filp
->private_data
;
1420 struct lttng_kernel_ring_buffer
*buf
= stream
->priv
;
1421 unsigned int rb_cmd
;
1424 if (cmd
== LTTNG_KERNEL_ABI_RING_BUFFER_GET_NEXT_SUBBUF_METADATA_CHECK
)
1425 rb_cmd
= LTTNG_KERNEL_ABI_RING_BUFFER_GET_NEXT_SUBBUF
;
1430 case LTTNG_KERNEL_ABI_RING_BUFFER_GET_NEXT_SUBBUF
:
1432 struct lttng_metadata_stream
*stream
= filp
->private_data
;
1433 struct lttng_kernel_ring_buffer
*buf
= stream
->priv
;
1434 struct lttng_kernel_ring_buffer_channel
*chan
= buf
->backend
.chan
;
1436 ret
= lttng_metadata_output_channel(stream
, chan
, NULL
);
1438 lib_ring_buffer_switch_slow(buf
, SWITCH_ACTIVE
);
1444 case LTTNG_KERNEL_ABI_RING_BUFFER_GET_SUBBUF
:
1447 * Random access is not allowed for metadata channel.
1451 case LTTNG_KERNEL_ABI_RING_BUFFER_FLUSH_EMPTY
:
1453 case LTTNG_KERNEL_ABI_RING_BUFFER_FLUSH
:
1455 struct lttng_metadata_stream
*stream
= filp
->private_data
;
1456 struct lttng_kernel_ring_buffer
*buf
= stream
->priv
;
1457 struct lttng_kernel_ring_buffer_channel
*chan
= buf
->backend
.chan
;
1460 * Before doing the actual ring buffer flush, write up to one
1461 * packet of metadata in the ring buffer.
1463 ret
= lttng_metadata_output_channel(stream
, chan
, NULL
);
1468 case LTTNG_KERNEL_ABI_RING_BUFFER_GET_METADATA_VERSION
:
1470 struct lttng_metadata_stream
*stream
= filp
->private_data
;
1472 return put_u64(stream
->version
, arg
);
1474 case LTTNG_KERNEL_ABI_RING_BUFFER_METADATA_CACHE_DUMP
:
1476 struct lttng_metadata_stream
*stream
= filp
->private_data
;
1478 return lttng_metadata_cache_dump(stream
);
1480 case LTTNG_KERNEL_ABI_RING_BUFFER_GET_NEXT_SUBBUF_METADATA_CHECK
:
1482 struct lttng_metadata_stream
*stream
= filp
->private_data
;
1483 struct lttng_kernel_ring_buffer
*buf
= stream
->priv
;
1484 struct lttng_kernel_ring_buffer_channel
*chan
= buf
->backend
.chan
;
1486 ret
= lttng_metadata_output_channel(stream
, chan
, &coherent
);
1488 lib_ring_buffer_switch_slow(buf
, SWITCH_ACTIVE
);
1490 } else if (ret
< 0) {
1498 /* PUT_SUBBUF is the one from lib ring buffer, unmodified. */
1500 /* Performing lib ring buffer ioctl after our own. */
1501 ret
= lib_ring_buffer_compat_ioctl(filp
, rb_cmd
, arg
, buf
);
1506 case LTTNG_KERNEL_ABI_RING_BUFFER_PUT_NEXT_SUBBUF
:
1508 lttng_metadata_ring_buffer_ioctl_put_next_subbuf(filp
,
1512 case LTTNG_KERNEL_ABI_RING_BUFFER_GET_NEXT_SUBBUF_METADATA_CHECK
:
1514 return put_u32(coherent
, arg
);
1525 * This is not used by anonymous file descriptors. This code is left
1526 * there if we ever want to implement an inode with open() operation.
1529 int lttng_metadata_ring_buffer_open(struct inode
*inode
, struct file
*file
)
1531 struct lttng_metadata_stream
*stream
= inode
->i_private
;
1532 struct lttng_kernel_ring_buffer
*buf
= stream
->priv
;
1534 file
->private_data
= buf
;
1536 * Since life-time of metadata cache differs from that of
1537 * session, we need to keep our own reference on the transport.
1539 if (!try_module_get(stream
->transport
->owner
)) {
1540 printk(KERN_WARNING
"LTTng: Can't lock transport module.\n");
1543 return lib_ring_buffer_open(inode
, file
, buf
);
1547 int lttng_metadata_ring_buffer_release(struct inode
*inode
, struct file
*file
)
1549 struct lttng_metadata_stream
*stream
= file
->private_data
;
1550 struct lttng_kernel_ring_buffer
*buf
= stream
->priv
;
1552 mutex_lock(&stream
->metadata_cache
->lock
);
1553 list_del(&stream
->list
);
1554 mutex_unlock(&stream
->metadata_cache
->lock
);
1555 kref_put(&stream
->metadata_cache
->refcount
, metadata_cache_destroy
);
1556 module_put(stream
->transport
->owner
);
1558 return lib_ring_buffer_release(inode
, file
, buf
);
1562 ssize_t
lttng_metadata_ring_buffer_splice_read(struct file
*in
, loff_t
*ppos
,
1563 struct pipe_inode_info
*pipe
, size_t len
,
1566 struct lttng_metadata_stream
*stream
= in
->private_data
;
1567 struct lttng_kernel_ring_buffer
*buf
= stream
->priv
;
1569 return lib_ring_buffer_splice_read(in
, ppos
, pipe
, len
,
1574 int lttng_metadata_ring_buffer_mmap(struct file
*filp
,
1575 struct vm_area_struct
*vma
)
1577 struct lttng_metadata_stream
*stream
= filp
->private_data
;
1578 struct lttng_kernel_ring_buffer
*buf
= stream
->priv
;
1580 return lib_ring_buffer_mmap(filp
, vma
, buf
);
1584 const struct file_operations lttng_metadata_ring_buffer_file_operations
= {
1585 .owner
= THIS_MODULE
,
1586 .open
= lttng_metadata_ring_buffer_open
,
1587 .release
= lttng_metadata_ring_buffer_release
,
1588 .poll
= lttng_metadata_ring_buffer_poll
,
1589 .splice_read
= lttng_metadata_ring_buffer_splice_read
,
1590 .mmap
= lttng_metadata_ring_buffer_mmap
,
1591 .unlocked_ioctl
= lttng_metadata_ring_buffer_ioctl
,
1592 .llseek
= vfs_lib_ring_buffer_no_llseek
,
1593 #ifdef CONFIG_COMPAT
1594 .compat_ioctl
= lttng_metadata_ring_buffer_compat_ioctl
,
1599 int lttng_abi_create_stream_fd(struct file
*channel_file
, void *stream_priv
,
1600 const struct file_operations
*fops
, const char *name
)
1603 struct file
*stream_file
;
1605 stream_fd
= get_unused_fd_flags(0);
1606 if (stream_fd
< 0) {
1610 stream_file
= anon_inode_getfile(name
, fops
, stream_priv
, O_RDWR
);
1611 if (IS_ERR(stream_file
)) {
1612 ret
= PTR_ERR(stream_file
);
1616 * OPEN_FMODE, called within anon_inode_getfile/alloc_file, don't honor
1617 * FMODE_LSEEK, FMODE_PREAD nor FMODE_PWRITE. We need to read from this
1618 * file descriptor, so we set FMODE_PREAD here.
1620 stream_file
->f_mode
|= FMODE_PREAD
;
1621 fd_install(stream_fd
, stream_file
);
1623 * The stream holds a reference to the channel within the generic ring
1624 * buffer library, so no need to hold a refcount on the channel and
1625 * session files here.
1630 put_unused_fd(stream_fd
);
1636 int lttng_abi_open_stream(struct file
*channel_file
)
1638 struct lttng_kernel_channel_buffer
*channel
= channel_file
->private_data
;
1639 struct lttng_kernel_ring_buffer
*buf
;
1643 buf
= channel
->ops
->priv
->buffer_read_open(channel
->priv
->rb_chan
);
1648 ret
= lttng_abi_create_stream_fd(channel_file
, stream_priv
,
1649 <tng_stream_ring_buffer_file_operations
,
1657 channel
->ops
->priv
->buffer_read_close(buf
);
1662 int lttng_abi_open_metadata_stream(struct file
*channel_file
)
1664 struct lttng_kernel_channel_buffer
*channel
= channel_file
->private_data
;
1665 struct lttng_kernel_session
*session
= channel
->parent
.session
;
1666 struct lttng_kernel_ring_buffer
*buf
;
1668 struct lttng_metadata_stream
*metadata_stream
;
1671 buf
= channel
->ops
->priv
->buffer_read_open(channel
->priv
->rb_chan
);
1675 metadata_stream
= kzalloc(sizeof(struct lttng_metadata_stream
),
1677 if (!metadata_stream
) {
1681 metadata_stream
->metadata_cache
= session
->priv
->metadata_cache
;
1682 init_waitqueue_head(&metadata_stream
->read_wait
);
1683 metadata_stream
->priv
= buf
;
1684 stream_priv
= metadata_stream
;
1685 metadata_stream
->transport
= channel
->priv
->transport
;
1686 /* Initial state is an empty metadata, considered as incoherent. */
1687 metadata_stream
->coherent
= false;
1690 * Since life-time of metadata cache differs from that of
1691 * session, we need to keep our own reference on the transport.
1693 if (!try_module_get(metadata_stream
->transport
->owner
)) {
1694 printk(KERN_WARNING
"LTTng: Can't lock transport module.\n");
1699 if (!lttng_kref_get(&session
->priv
->metadata_cache
->refcount
)) {
1704 ret
= lttng_abi_create_stream_fd(channel_file
, stream_priv
,
1705 <tng_metadata_ring_buffer_file_operations
,
1706 "[lttng_metadata_stream]");
1710 mutex_lock(&session
->priv
->metadata_cache
->lock
);
1711 list_add(&metadata_stream
->list
,
1712 &session
->priv
->metadata_cache
->metadata_stream
);
1713 mutex_unlock(&session
->priv
->metadata_cache
->lock
);
1717 kref_put(&session
->priv
->metadata_cache
->refcount
, metadata_cache_destroy
);
1719 module_put(metadata_stream
->transport
->owner
);
1721 kfree(metadata_stream
);
1723 channel
->ops
->priv
->buffer_read_close(buf
);
1728 int lttng_abi_open_event_notifier_group_stream(struct file
*notif_file
)
1730 struct lttng_event_notifier_group
*event_notifier_group
= notif_file
->private_data
;
1731 struct lttng_kernel_ring_buffer_channel
*chan
= event_notifier_group
->chan
;
1732 struct lttng_kernel_ring_buffer
*buf
;
1736 buf
= event_notifier_group
->ops
->priv
->buffer_read_open(chan
);
1740 /* The event_notifier notification fd holds a reference on the event_notifier group */
1741 if (!atomic_long_add_unless(¬if_file
->f_count
, 1, LONG_MAX
)) {
1743 goto refcount_error
;
1745 event_notifier_group
->buf
= buf
;
1746 stream_priv
= event_notifier_group
;
1747 ret
= lttng_abi_create_stream_fd(notif_file
, stream_priv
,
1748 <tng_event_notifier_group_notif_fops
,
1749 "[lttng_event_notifier_stream]");
1756 atomic_long_dec(¬if_file
->f_count
);
1758 event_notifier_group
->ops
->priv
->buffer_read_close(buf
);
1763 int lttng_abi_validate_event_param(struct lttng_kernel_abi_event
*event_param
)
1765 /* Limit ABI to implemented features. */
1766 switch (event_param
->instrumentation
) {
1767 case LTTNG_KERNEL_ABI_SYSCALL
:
1768 switch (event_param
->u
.syscall
.entryexit
) {
1769 case LTTNG_KERNEL_ABI_SYSCALL_ENTRY
:
1771 case LTTNG_KERNEL_ABI_SYSCALL_EXIT
:
1773 case LTTNG_KERNEL_ABI_SYSCALL_ENTRYEXIT
:
1778 switch (event_param
->u
.syscall
.abi
) {
1779 case LTTNG_KERNEL_ABI_SYSCALL_ABI_ALL
:
1784 switch (event_param
->u
.syscall
.match
) {
1785 case LTTNG_KERNEL_ABI_SYSCALL_MATCH_NAME
:
1792 case LTTNG_KERNEL_ABI_KRETPROBE
:
1793 switch (event_param
->u
.kretprobe
.entryexit
) {
1794 case LTTNG_KERNEL_ABI_SYSCALL_ENTRYEXIT
:
1796 case LTTNG_KERNEL_ABI_SYSCALL_ENTRY
:
1798 case LTTNG_KERNEL_ABI_SYSCALL_EXIT
:
1805 case LTTNG_KERNEL_ABI_TRACEPOINT
:
1807 case LTTNG_KERNEL_ABI_KPROBE
:
1809 case LTTNG_KERNEL_ABI_UPROBE
:
1812 case LTTNG_KERNEL_ABI_FUNCTION
:
1814 case LTTNG_KERNEL_ABI_NOOP
:
1823 int lttng_abi_create_event(struct file
*channel_file
,
1824 struct lttng_kernel_abi_event
*event_param
)
1826 const struct file_operations
*fops
;
1827 struct lttng_kernel_channel_buffer
*channel
= channel_file
->private_data
;
1829 struct file
*event_file
;
1832 event_param
->name
[LTTNG_KERNEL_ABI_SYM_NAME_LEN
- 1] = '\0';
1833 switch (event_param
->instrumentation
) {
1834 case LTTNG_KERNEL_ABI_KRETPROBE
:
1835 event_param
->u
.kretprobe
.symbol_name
[LTTNG_KERNEL_ABI_SYM_NAME_LEN
- 1] = '\0';
1837 case LTTNG_KERNEL_ABI_KPROBE
:
1838 event_param
->u
.kprobe
.symbol_name
[LTTNG_KERNEL_ABI_SYM_NAME_LEN
- 1] = '\0';
1840 case LTTNG_KERNEL_ABI_FUNCTION
:
1842 /* Not implemented. */
1848 switch (event_param
->instrumentation
) {
1849 case LTTNG_KERNEL_ABI_TRACEPOINT
:
1851 case LTTNG_KERNEL_ABI_SYSCALL
:
1852 fops
= <tng_event_recorder_enabler_fops
;
1854 case LTTNG_KERNEL_ABI_KPROBE
:
1856 case LTTNG_KERNEL_ABI_KRETPROBE
:
1858 case LTTNG_KERNEL_ABI_UPROBE
:
1859 fops
= <tng_event_recorder_event_fops
;
1862 case LTTNG_KERNEL_ABI_FUNCTION
:
1864 case LTTNG_KERNEL_ABI_NOOP
:
1870 event_fd
= get_unused_fd_flags(0);
1875 event_file
= anon_inode_getfile("[lttng_event]",
1876 fops
, NULL
, O_RDWR
);
1877 if (IS_ERR(event_file
)) {
1878 ret
= PTR_ERR(event_file
);
1881 /* The event holds a reference on the channel */
1882 if (!atomic_long_add_unless(&channel_file
->f_count
, 1, LONG_MAX
)) {
1884 goto refcount_error
;
1886 ret
= lttng_abi_validate_event_param(event_param
);
1890 switch (event_param
->instrumentation
) {
1891 case LTTNG_KERNEL_ABI_TRACEPOINT
:
1893 case LTTNG_KERNEL_ABI_SYSCALL
:
1895 struct lttng_event_recorder_enabler
*event_enabler
;
1897 if (strutils_is_star_glob_pattern(event_param
->name
)) {
1899 * If the event name is a star globbing pattern,
1900 * we create the special star globbing enabler.
1902 event_enabler
= lttng_event_recorder_enabler_create(LTTNG_ENABLER_FORMAT_STAR_GLOB
,
1903 event_param
, channel
);
1905 event_enabler
= lttng_event_recorder_enabler_create(LTTNG_ENABLER_FORMAT_NAME
,
1906 event_param
, channel
);
1909 lttng_event_enabler_session_add(channel
->parent
.session
, event_enabler
);
1910 priv
= event_enabler
;
1914 case LTTNG_KERNEL_ABI_KPROBE
:
1916 case LTTNG_KERNEL_ABI_KRETPROBE
:
1918 case LTTNG_KERNEL_ABI_UPROBE
:
1920 struct lttng_kernel_event_common
*event
;
1921 struct lttng_event_recorder_enabler
*event_enabler
;
1923 event_enabler
= lttng_event_recorder_enabler_create(LTTNG_ENABLER_FORMAT_NAME
,
1924 event_param
, channel
);
1925 if (!event_enabler
) {
1930 * We tolerate no failure path after event creation. It
1931 * will stay invariant for the rest of the session.
1933 event
= lttng_kernel_event_create(&event_enabler
->parent
, NULL
);
1934 WARN_ON_ONCE(IS_ERR(event
));
1935 lttng_event_enabler_destroy(&event_enabler
->parent
);
1936 if (IS_ERR(event
)) {
1937 ret
= PTR_ERR(event
);
1940 priv
= container_of(event
, struct lttng_kernel_event_recorder
, parent
);
1944 case LTTNG_KERNEL_ABI_FUNCTION
:
1946 case LTTNG_KERNEL_ABI_NOOP
:
1952 event_file
->private_data
= priv
;
1953 fd_install(event_fd
, event_file
);
1957 atomic_long_dec(&channel_file
->f_count
);
1961 put_unused_fd(event_fd
);
1967 long lttng_event_notifier_event_ioctl(struct file
*file
, unsigned int cmd
, unsigned long arg
)
1969 struct lttng_kernel_event_notifier
*event_notifier
= file
->private_data
;
1972 case LTTNG_KERNEL_ABI_ENABLE
:
1973 return lttng_event_enable(&event_notifier
->parent
);
1974 case LTTNG_KERNEL_ABI_DISABLE
:
1975 return lttng_event_disable(&event_notifier
->parent
);
1976 case LTTNG_KERNEL_ABI_FILTER
:
1978 case LTTNG_KERNEL_ABI_CAPTURE
:
1980 case LTTNG_KERNEL_ABI_ADD_CALLSITE
:
1981 return lttng_event_add_callsite(&event_notifier
->parent
,
1982 (struct lttng_kernel_abi_event_callsite __user
*) arg
);
1984 return -ENOIOCTLCMD
;
1989 long lttng_event_notifier_enabler_ioctl(struct file
*file
, unsigned int cmd
, unsigned long arg
)
1991 struct lttng_event_notifier_enabler
*event_notifier_enabler
= file
->private_data
;
1994 case LTTNG_KERNEL_ABI_ENABLE
:
1995 return lttng_event_enabler_enable(&event_notifier_enabler
->parent
);
1996 case LTTNG_KERNEL_ABI_DISABLE
:
1997 return lttng_event_enabler_disable(&event_notifier_enabler
->parent
);
1998 case LTTNG_KERNEL_ABI_FILTER
:
1999 return lttng_event_enabler_attach_filter_bytecode(&event_notifier_enabler
->parent
,
2000 (struct lttng_kernel_abi_filter_bytecode __user
*) arg
);
2001 case LTTNG_KERNEL_ABI_CAPTURE
:
2002 return lttng_event_notifier_enabler_attach_capture_bytecode(
2003 event_notifier_enabler
,
2004 (struct lttng_kernel_abi_capture_bytecode __user
*) arg
);
2005 case LTTNG_KERNEL_ABI_ADD_CALLSITE
:
2008 return -ENOIOCTLCMD
;
2013 int lttng_event_notifier_event_release(struct inode
*inode
, struct file
*file
)
2015 struct lttng_kernel_event_notifier
*event_notifier
= file
->private_data
;
2018 fput(event_notifier
->priv
->group
->file
);
2023 int lttng_event_notifier_enabler_release(struct inode
*inode
, struct file
*file
)
2025 struct lttng_event_notifier_enabler
*event_notifier_enabler
= file
->private_data
;
2027 if (event_notifier_enabler
)
2028 fput(event_notifier_enabler
->group
->file
);
2032 static const struct file_operations lttng_event_notifier_event_fops
= {
2033 .owner
= THIS_MODULE
,
2034 .release
= lttng_event_notifier_event_release
,
2035 .unlocked_ioctl
= lttng_event_notifier_event_ioctl
,
2036 #ifdef CONFIG_COMPAT
2037 .compat_ioctl
= lttng_event_notifier_event_ioctl
,
2041 static const struct file_operations lttng_event_notifier_enabler_fops
= {
2042 .owner
= THIS_MODULE
,
2043 .release
= lttng_event_notifier_enabler_release
,
2044 .unlocked_ioctl
= lttng_event_notifier_enabler_ioctl
,
2045 #ifdef CONFIG_COMPAT
2046 .compat_ioctl
= lttng_event_notifier_enabler_ioctl
,
2051 int lttng_abi_create_event_notifier(struct file
*event_notifier_group_file
,
2052 struct lttng_kernel_abi_event_notifier
*event_notifier_param
)
2054 struct lttng_event_notifier_group
*event_notifier_group
=
2055 event_notifier_group_file
->private_data
;
2056 const struct file_operations
*fops
;
2057 int event_notifier_fd
, ret
;
2058 struct file
*event_notifier_file
;
2061 switch (event_notifier_param
->event
.instrumentation
) {
2062 case LTTNG_KERNEL_ABI_TRACEPOINT
:
2063 case LTTNG_KERNEL_ABI_UPROBE
:
2065 case LTTNG_KERNEL_ABI_KPROBE
:
2066 event_notifier_param
->event
.u
.kprobe
.symbol_name
[LTTNG_KERNEL_ABI_SYM_NAME_LEN
- 1] = '\0';
2068 case LTTNG_KERNEL_ABI_SYSCALL
:
2070 case LTTNG_KERNEL_ABI_KRETPROBE
:
2071 /* Placing an event notifier on kretprobe is not supported. */
2072 case LTTNG_KERNEL_ABI_FUNCTION
:
2073 case LTTNG_KERNEL_ABI_NOOP
:
2079 switch (event_notifier_param
->event
.instrumentation
) {
2080 case LTTNG_KERNEL_ABI_TRACEPOINT
:
2082 case LTTNG_KERNEL_ABI_SYSCALL
:
2083 fops
= <tng_event_notifier_enabler_fops
;
2085 case LTTNG_KERNEL_ABI_KPROBE
:
2087 case LTTNG_KERNEL_ABI_KRETPROBE
:
2089 case LTTNG_KERNEL_ABI_UPROBE
:
2090 fops
= <tng_event_notifier_event_fops
;
2093 case LTTNG_KERNEL_ABI_FUNCTION
:
2095 case LTTNG_KERNEL_ABI_NOOP
:
2102 event_notifier_param
->event
.name
[LTTNG_KERNEL_ABI_SYM_NAME_LEN
- 1] = '\0';
2104 event_notifier_fd
= get_unused_fd_flags(0);
2105 if (event_notifier_fd
< 0) {
2106 ret
= event_notifier_fd
;
2110 event_notifier_file
= anon_inode_getfile("[lttng_event_notifier]",
2111 fops
, NULL
, O_RDWR
);
2112 if (IS_ERR(event_notifier_file
)) {
2113 ret
= PTR_ERR(event_notifier_file
);
2117 /* The event notifier holds a reference on the event notifier group. */
2118 if (!atomic_long_add_unless(&event_notifier_group_file
->f_count
, 1, LONG_MAX
)) {
2120 goto refcount_error
;
2123 ret
= lttng_abi_validate_event_param(&event_notifier_param
->event
);
2125 goto event_notifier_error
;
2127 switch (event_notifier_param
->event
.instrumentation
) {
2128 case LTTNG_KERNEL_ABI_TRACEPOINT
:
2130 case LTTNG_KERNEL_ABI_SYSCALL
:
2132 struct lttng_event_notifier_enabler
*enabler
;
2134 if (strutils_is_star_glob_pattern(event_notifier_param
->event
.name
)) {
2136 * If the event name is a star globbing pattern,
2137 * we create the special star globbing enabler.
2139 enabler
= lttng_event_notifier_enabler_create(
2140 LTTNG_ENABLER_FORMAT_STAR_GLOB
,
2141 event_notifier_param
,
2142 event_notifier_group
);
2144 enabler
= lttng_event_notifier_enabler_create(
2145 LTTNG_ENABLER_FORMAT_NAME
,
2146 event_notifier_param
,
2147 event_notifier_group
);
2150 lttng_event_notifier_enabler_group_add(event_notifier_group
, enabler
);
2155 case LTTNG_KERNEL_ABI_KPROBE
:
2157 case LTTNG_KERNEL_ABI_KRETPROBE
:
2159 case LTTNG_KERNEL_ABI_UPROBE
:
2161 struct lttng_kernel_event_common
*event
;
2162 struct lttng_event_notifier_enabler
*event_notifier_enabler
;
2164 event_notifier_enabler
= lttng_event_notifier_enabler_create(LTTNG_ENABLER_FORMAT_NAME
,
2165 event_notifier_param
, event_notifier_group
);
2166 if (!event_notifier_enabler
) {
2168 goto event_notifier_error
;
2170 event
= lttng_kernel_event_create(&event_notifier_enabler
->parent
, NULL
);
2171 WARN_ON_ONCE(IS_ERR(event
));
2172 lttng_event_enabler_destroy(&event_notifier_enabler
->parent
);
2173 if (IS_ERR(event
)) {
2174 ret
= PTR_ERR(event
);
2175 goto event_notifier_error
;
2177 priv
= container_of(event
, struct lttng_kernel_event_notifier
, parent
);
2181 case LTTNG_KERNEL_ABI_FUNCTION
:
2183 case LTTNG_KERNEL_ABI_NOOP
:
2187 goto event_notifier_error
;
2189 event_notifier_file
->private_data
= priv
;
2190 fd_install(event_notifier_fd
, event_notifier_file
);
2191 return event_notifier_fd
;
2193 event_notifier_error
:
2194 atomic_long_dec(&event_notifier_group_file
->f_count
);
2196 fput(event_notifier_file
);
2198 put_unused_fd(event_notifier_fd
);
2205 long lttng_abi_event_notifier_group_create_error_counter(
2206 struct file
*event_notifier_group_file
,
2207 const struct lttng_kernel_abi_counter_conf
*error_counter_conf
)
2209 int counter_fd
, ret
;
2210 char *counter_transport_name
;
2212 struct lttng_counter
*counter
= NULL
;
2213 struct file
*counter_file
;
2214 struct lttng_event_notifier_group
*event_notifier_group
=
2215 (struct lttng_event_notifier_group
*) event_notifier_group_file
->private_data
;
2217 if (error_counter_conf
->arithmetic
!= LTTNG_KERNEL_ABI_COUNTER_ARITHMETIC_MODULAR
) {
2218 printk(KERN_ERR
"LTTng: event_notifier: Error counter of the wrong arithmetic type.\n");
2222 if (error_counter_conf
->number_dimensions
!= 1) {
2223 printk(KERN_ERR
"LTTng: event_notifier: Error counter has more than one dimension.\n");
2227 switch (error_counter_conf
->bitness
) {
2228 case LTTNG_KERNEL_ABI_COUNTER_BITNESS_64
:
2229 counter_transport_name
= "counter-per-cpu-64-modular";
2231 case LTTNG_KERNEL_ABI_COUNTER_BITNESS_32
:
2232 counter_transport_name
= "counter-per-cpu-32-modular";
2239 * Lock sessions to provide mutual exclusion against concurrent
2240 * modification of event_notifier group, which would result in
2241 * overwriting the error counter if set concurrently.
2243 lttng_lock_sessions();
2245 if (event_notifier_group
->error_counter
) {
2246 printk(KERN_ERR
"Error counter already created in event_notifier group\n");
2251 counter_fd
= get_unused_fd_flags(0);
2252 if (counter_fd
< 0) {
2257 counter_file
= anon_inode_getfile("[lttng_counter]",
2258 <tng_counter_fops
,
2260 if (IS_ERR(counter_file
)) {
2261 ret
= PTR_ERR(counter_file
);
2265 counter_len
= error_counter_conf
->dimensions
[0].size
;
2267 if (!atomic_long_add_unless(&event_notifier_group_file
->f_count
, 1, LONG_MAX
)) {
2269 goto refcount_error
;
2272 counter
= lttng_kernel_counter_create(counter_transport_name
,
2279 event_notifier_group
->error_counter_len
= counter_len
;
2281 * store-release to publish error counter matches load-acquire
2282 * in record_error. Ensures the counter is created and the
2283 * error_counter_len is set before they are used.
2285 smp_store_release(&event_notifier_group
->error_counter
, counter
);
2287 counter
->file
= counter_file
;
2288 counter
->owner
= event_notifier_group
->file
;
2289 counter_file
->private_data
= counter
;
2290 /* Ownership transferred. */
2293 fd_install(counter_fd
, counter_file
);
2294 lttng_unlock_sessions();
2299 atomic_long_dec(&event_notifier_group_file
->f_count
);
2303 put_unused_fd(counter_fd
);
2305 lttng_unlock_sessions();
2310 long lttng_event_notifier_group_ioctl(struct file
*file
, unsigned int cmd
,
2314 case LTTNG_KERNEL_ABI_EVENT_NOTIFIER_GROUP_NOTIFICATION_FD
:
2316 return lttng_abi_open_event_notifier_group_stream(file
);
2318 case LTTNG_KERNEL_ABI_EVENT_NOTIFIER_CREATE
:
2320 struct lttng_kernel_abi_event_notifier uevent_notifier_param
;
2322 if (copy_from_user(&uevent_notifier_param
,
2323 (struct lttng_kernel_abi_event_notifier __user
*) arg
,
2324 sizeof(uevent_notifier_param
)))
2326 return lttng_abi_create_event_notifier(file
, &uevent_notifier_param
);
2328 case LTTNG_KERNEL_ABI_COUNTER
:
2330 struct lttng_kernel_abi_counter_conf uerror_counter_conf
;
2332 if (copy_from_user(&uerror_counter_conf
,
2333 (struct lttng_kernel_abi_counter_conf __user
*) arg
,
2334 sizeof(uerror_counter_conf
)))
2336 return lttng_abi_event_notifier_group_create_error_counter(file
,
2337 &uerror_counter_conf
);
2340 return -ENOIOCTLCMD
;
2346 int lttng_event_notifier_group_release(struct inode
*inode
, struct file
*file
)
2348 struct lttng_event_notifier_group
*event_notifier_group
=
2351 if (event_notifier_group
)
2352 lttng_event_notifier_group_destroy(event_notifier_group
);
2356 static const struct file_operations lttng_event_notifier_group_fops
= {
2357 .owner
= THIS_MODULE
,
2358 .release
= lttng_event_notifier_group_release
,
2359 .unlocked_ioctl
= lttng_event_notifier_group_ioctl
,
2360 #ifdef CONFIG_COMPAT
2361 .compat_ioctl
= lttng_event_notifier_group_ioctl
,
2366 * lttng_channel_ioctl - lttng syscall through ioctl
2372 * This ioctl implements lttng commands:
2373 * LTTNG_KERNEL_ABI_STREAM
2374 * Returns an event stream file descriptor or failure.
2375 * (typically, one event stream records events from one CPU)
2376 * LTTNG_KERNEL_ABI_EVENT
2377 * Returns an event file descriptor or failure.
2378 * LTTNG_KERNEL_ABI_CONTEXT
2379 * Prepend a context field to each event in the channel
2380 * LTTNG_KERNEL_ABI_ENABLE
2381 * Enable recording for events in this channel (weak enable)
2382 * LTTNG_KERNEL_ABI_DISABLE
2383 * Disable recording for events in this channel (strong disable)
2385 * Channel and event file descriptors also hold a reference on the session.
2388 long lttng_channel_ioctl(struct file
*file
, unsigned int cmd
, unsigned long arg
)
2390 struct lttng_kernel_channel_buffer
*channel
= file
->private_data
;
2393 case LTTNG_KERNEL_ABI_OLD_STREAM
:
2394 case LTTNG_KERNEL_ABI_STREAM
:
2395 return lttng_abi_open_stream(file
);
2396 case LTTNG_KERNEL_ABI_OLD_EVENT
:
2398 struct lttng_kernel_abi_event
*uevent_param
;
2399 struct lttng_kernel_abi_old_event
*old_uevent_param
;
2402 uevent_param
= kmalloc(sizeof(struct lttng_kernel_abi_event
),
2404 if (!uevent_param
) {
2408 old_uevent_param
= kmalloc(
2409 sizeof(struct lttng_kernel_abi_old_event
),
2411 if (!old_uevent_param
) {
2413 goto old_event_error_free_param
;
2415 if (copy_from_user(old_uevent_param
,
2416 (struct lttng_kernel_abi_old_event __user
*) arg
,
2417 sizeof(struct lttng_kernel_abi_old_event
))) {
2419 goto old_event_error_free_old_param
;
2422 memcpy(uevent_param
->name
, old_uevent_param
->name
,
2423 sizeof(uevent_param
->name
));
2424 uevent_param
->instrumentation
=
2425 old_uevent_param
->instrumentation
;
2427 switch (old_uevent_param
->instrumentation
) {
2428 case LTTNG_KERNEL_ABI_KPROBE
:
2429 uevent_param
->u
.kprobe
.addr
=
2430 old_uevent_param
->u
.kprobe
.addr
;
2431 uevent_param
->u
.kprobe
.offset
=
2432 old_uevent_param
->u
.kprobe
.offset
;
2433 memcpy(uevent_param
->u
.kprobe
.symbol_name
,
2434 old_uevent_param
->u
.kprobe
.symbol_name
,
2435 sizeof(uevent_param
->u
.kprobe
.symbol_name
));
2437 case LTTNG_KERNEL_ABI_KRETPROBE
:
2438 uevent_param
->u
.kretprobe
.addr
=
2439 old_uevent_param
->u
.kretprobe
.addr
;
2440 uevent_param
->u
.kretprobe
.offset
=
2441 old_uevent_param
->u
.kretprobe
.offset
;
2442 memcpy(uevent_param
->u
.kretprobe
.symbol_name
,
2443 old_uevent_param
->u
.kretprobe
.symbol_name
,
2444 sizeof(uevent_param
->u
.kretprobe
.symbol_name
));
2446 case LTTNG_KERNEL_ABI_FUNCTION
:
2448 /* Not implemented. */
2453 ret
= lttng_abi_create_event(file
, uevent_param
);
2455 old_event_error_free_old_param
:
2456 kfree(old_uevent_param
);
2457 old_event_error_free_param
:
2458 kfree(uevent_param
);
2462 case LTTNG_KERNEL_ABI_EVENT
:
2464 struct lttng_kernel_abi_event uevent_param
;
2466 if (copy_from_user(&uevent_param
,
2467 (struct lttng_kernel_abi_event __user
*) arg
,
2468 sizeof(uevent_param
)))
2470 return lttng_abi_create_event(file
, &uevent_param
);
2472 case LTTNG_KERNEL_ABI_OLD_CONTEXT
:
2474 struct lttng_kernel_abi_context
*ucontext_param
;
2475 struct lttng_kernel_abi_old_context
*old_ucontext_param
;
2478 ucontext_param
= kmalloc(sizeof(struct lttng_kernel_abi_context
),
2480 if (!ucontext_param
) {
2484 old_ucontext_param
= kmalloc(sizeof(struct lttng_kernel_abi_old_context
),
2486 if (!old_ucontext_param
) {
2488 goto old_ctx_error_free_param
;
2491 if (copy_from_user(old_ucontext_param
,
2492 (struct lttng_kernel_abi_old_context __user
*) arg
,
2493 sizeof(struct lttng_kernel_abi_old_context
))) {
2495 goto old_ctx_error_free_old_param
;
2497 ucontext_param
->ctx
= old_ucontext_param
->ctx
;
2498 memcpy(ucontext_param
->padding
, old_ucontext_param
->padding
,
2499 sizeof(ucontext_param
->padding
));
2500 /* only type that uses the union */
2501 if (old_ucontext_param
->ctx
== LTTNG_KERNEL_ABI_CONTEXT_PERF_COUNTER
) {
2502 ucontext_param
->u
.perf_counter
.type
=
2503 old_ucontext_param
->u
.perf_counter
.type
;
2504 ucontext_param
->u
.perf_counter
.config
=
2505 old_ucontext_param
->u
.perf_counter
.config
;
2506 memcpy(ucontext_param
->u
.perf_counter
.name
,
2507 old_ucontext_param
->u
.perf_counter
.name
,
2508 sizeof(ucontext_param
->u
.perf_counter
.name
));
2511 ret
= lttng_abi_add_context(file
,
2513 &channel
->priv
->ctx
, channel
->parent
.session
);
2515 old_ctx_error_free_old_param
:
2516 kfree(old_ucontext_param
);
2517 old_ctx_error_free_param
:
2518 kfree(ucontext_param
);
2522 case LTTNG_KERNEL_ABI_CONTEXT
:
2524 struct lttng_kernel_abi_context ucontext_param
;
2526 if (copy_from_user(&ucontext_param
,
2527 (struct lttng_kernel_abi_context __user
*) arg
,
2528 sizeof(ucontext_param
)))
2530 return lttng_abi_add_context(file
,
2532 &channel
->priv
->ctx
, channel
->parent
.session
);
2534 case LTTNG_KERNEL_ABI_OLD_ENABLE
:
2535 case LTTNG_KERNEL_ABI_ENABLE
:
2536 return lttng_channel_enable(&channel
->parent
);
2537 case LTTNG_KERNEL_ABI_OLD_DISABLE
:
2538 case LTTNG_KERNEL_ABI_DISABLE
:
2539 return lttng_channel_disable(&channel
->parent
);
2540 case LTTNG_KERNEL_ABI_SYSCALL_MASK
:
2541 return lttng_syscall_table_get_active_mask(&channel
->priv
->parent
.syscall_table
,
2542 (struct lttng_kernel_abi_syscall_mask __user
*) arg
);
2544 return -ENOIOCTLCMD
;
2549 * lttng_metadata_ioctl - lttng syscall through ioctl
2555 * This ioctl implements lttng commands:
2556 * LTTNG_KERNEL_ABI_STREAM
2557 * Returns an event stream file descriptor or failure.
2559 * Channel and event file descriptors also hold a reference on the session.
2562 long lttng_metadata_ioctl(struct file
*file
, unsigned int cmd
, unsigned long arg
)
2565 case LTTNG_KERNEL_ABI_OLD_STREAM
:
2566 case LTTNG_KERNEL_ABI_STREAM
:
2567 return lttng_abi_open_metadata_stream(file
);
2569 return -ENOIOCTLCMD
;
2574 * lttng_channel_poll - lttng stream addition/removal monitoring
2579 unsigned int lttng_channel_poll(struct file
*file
, poll_table
*wait
)
2581 struct lttng_kernel_channel_buffer
*channel
= file
->private_data
;
2582 unsigned int mask
= 0;
2584 if (file
->f_mode
& FMODE_READ
) {
2585 poll_wait_set_exclusive(wait
);
2586 poll_wait(file
, channel
->ops
->priv
->get_hp_wait_queue(channel
->priv
->rb_chan
),
2589 if (channel
->ops
->priv
->is_disabled(channel
->priv
->rb_chan
))
2591 if (channel
->ops
->priv
->is_finalized(channel
->priv
->rb_chan
))
2593 if (channel
->ops
->priv
->buffer_has_read_closed_stream(channel
->priv
->rb_chan
))
2594 return POLLIN
| POLLRDNORM
;
2602 int lttng_channel_release(struct inode
*inode
, struct file
*file
)
2604 struct lttng_kernel_channel_buffer
*channel
= file
->private_data
;
2607 fput(channel
->parent
.session
->priv
->file
);
2612 int lttng_metadata_channel_release(struct inode
*inode
, struct file
*file
)
2614 struct lttng_kernel_channel_buffer
*channel
= file
->private_data
;
2617 fput(channel
->parent
.session
->priv
->file
);
2618 lttng_metadata_channel_destroy(channel
);
2624 static const struct file_operations lttng_channel_fops
= {
2625 .owner
= THIS_MODULE
,
2626 .release
= lttng_channel_release
,
2627 .poll
= lttng_channel_poll
,
2628 .unlocked_ioctl
= lttng_channel_ioctl
,
2629 #ifdef CONFIG_COMPAT
2630 .compat_ioctl
= lttng_channel_ioctl
,
2634 static const struct file_operations lttng_metadata_fops
= {
2635 .owner
= THIS_MODULE
,
2636 .release
= lttng_metadata_channel_release
,
2637 .unlocked_ioctl
= lttng_metadata_ioctl
,
2638 #ifdef CONFIG_COMPAT
2639 .compat_ioctl
= lttng_metadata_ioctl
,
2644 * lttng_event_recorder_event_ioctl - lttng syscall through ioctl
2650 * This ioctl implements lttng commands:
2651 * LTTNG_KERNEL_ABI_CONTEXT
2652 * Prepend a context field to each record of this event
2653 * LTTNG_KERNEL_ABI_ENABLE
2654 * Enable recording for this event (weak enable)
2655 * LTTNG_KERNEL_ABI_DISABLE
2656 * Disable recording for this event (strong disable)
2659 long lttng_event_recorder_event_ioctl(struct file
*file
, unsigned int cmd
, unsigned long arg
)
2661 struct lttng_kernel_event_recorder
*event_recorder
= file
->private_data
;
2664 case LTTNG_KERNEL_ABI_OLD_CONTEXT
:
2666 /* Not implemented */
2669 case LTTNG_KERNEL_ABI_CONTEXT
:
2671 /* Not implemented */
2674 case LTTNG_KERNEL_ABI_OLD_ENABLE
:
2675 case LTTNG_KERNEL_ABI_ENABLE
:
2676 return lttng_event_enable(&event_recorder
->parent
);
2677 case LTTNG_KERNEL_ABI_OLD_DISABLE
:
2678 case LTTNG_KERNEL_ABI_DISABLE
:
2679 return lttng_event_disable(&event_recorder
->parent
);
2680 case LTTNG_KERNEL_ABI_FILTER
:
2682 case LTTNG_KERNEL_ABI_ADD_CALLSITE
:
2683 return lttng_event_add_callsite(&event_recorder
->parent
,
2684 (struct lttng_kernel_abi_event_callsite __user
*) arg
);
2686 return -ENOIOCTLCMD
;
2691 * lttng_event_recorder_enabler_ioctl - lttng syscall through ioctl
2697 * This ioctl implements lttng commands:
2698 * LTTNG_KERNEL_ABI_CONTEXT
2699 * Prepend a context field to each record of this event
2700 * LTTNG_KERNEL_ABI_ENABLE
2701 * Enable recording for this event (weak enable)
2702 * LTTNG_KERNEL_ABI_DISABLE
2703 * Disable recording for this event (strong disable)
2706 long lttng_event_recorder_enabler_ioctl(struct file
*file
, unsigned int cmd
, unsigned long arg
)
2708 struct lttng_event_recorder_enabler
*event_enabler
= file
->private_data
;
2711 case LTTNG_KERNEL_ABI_OLD_CONTEXT
:
2713 /* Not implemented */
2716 case LTTNG_KERNEL_ABI_CONTEXT
:
2718 /* Not implemented */
2721 case LTTNG_KERNEL_ABI_OLD_ENABLE
:
2722 case LTTNG_KERNEL_ABI_ENABLE
:
2723 return lttng_event_enabler_enable(&event_enabler
->parent
);
2724 case LTTNG_KERNEL_ABI_OLD_DISABLE
:
2725 case LTTNG_KERNEL_ABI_DISABLE
:
2726 return lttng_event_enabler_disable(&event_enabler
->parent
);
2727 case LTTNG_KERNEL_ABI_FILTER
:
2728 return lttng_event_enabler_attach_filter_bytecode(&event_enabler
->parent
,
2729 (struct lttng_kernel_abi_filter_bytecode __user
*) arg
);
2730 case LTTNG_KERNEL_ABI_ADD_CALLSITE
:
2733 return -ENOIOCTLCMD
;
2738 int lttng_event_recorder_event_release(struct inode
*inode
, struct file
*file
)
2740 struct lttng_kernel_event_recorder
*event
= file
->private_data
;
2743 fput(event
->chan
->priv
->parent
.file
);
2748 int lttng_event_recorder_enabler_release(struct inode
*inode
, struct file
*file
)
2750 struct lttng_event_recorder_enabler
*event_enabler
= file
->private_data
;
2753 fput(event_enabler
->chan
->priv
->parent
.file
);
2757 static const struct file_operations lttng_event_recorder_event_fops
= {
2758 .owner
= THIS_MODULE
,
2759 .release
= lttng_event_recorder_event_release
,
2760 .unlocked_ioctl
= lttng_event_recorder_event_ioctl
,
2761 #ifdef CONFIG_COMPAT
2762 .compat_ioctl
= lttng_event_recorder_event_ioctl
,
2766 static const struct file_operations lttng_event_recorder_enabler_fops
= {
2767 .owner
= THIS_MODULE
,
2768 .release
= lttng_event_recorder_enabler_release
,
2769 .unlocked_ioctl
= lttng_event_recorder_enabler_ioctl
,
2770 #ifdef CONFIG_COMPAT
2771 .compat_ioctl
= lttng_event_recorder_enabler_ioctl
,
2775 static int put_u64(uint64_t val
, unsigned long arg
)
2777 return put_user(val
, (uint64_t __user
*) arg
);
2780 static int put_u32(uint32_t val
, unsigned long arg
)
2782 return put_user(val
, (uint32_t __user
*) arg
);
2785 static long lttng_stream_ring_buffer_ioctl(struct file
*filp
,
2786 unsigned int cmd
, unsigned long arg
)
2788 struct lttng_kernel_ring_buffer
*buf
= filp
->private_data
;
2789 struct lttng_kernel_ring_buffer_channel
*chan
= buf
->backend
.chan
;
2790 const struct lttng_kernel_ring_buffer_config
*config
= &chan
->backend
.config
;
2791 const struct lttng_kernel_channel_buffer_ops
*ops
= chan
->backend
.priv_ops
;
2794 if (atomic_read(&chan
->record_disabled
))
2798 case LTTNG_KERNEL_ABI_RING_BUFFER_GET_TIMESTAMP_BEGIN
:
2802 ret
= ops
->priv
->timestamp_begin(config
, buf
, &ts
);
2805 return put_u64(ts
, arg
);
2807 case LTTNG_KERNEL_ABI_RING_BUFFER_GET_TIMESTAMP_END
:
2811 ret
= ops
->priv
->timestamp_end(config
, buf
, &ts
);
2814 return put_u64(ts
, arg
);
2816 case LTTNG_KERNEL_ABI_RING_BUFFER_GET_EVENTS_DISCARDED
:
2820 ret
= ops
->priv
->events_discarded(config
, buf
, &ed
);
2823 return put_u64(ed
, arg
);
2825 case LTTNG_KERNEL_ABI_RING_BUFFER_GET_CONTENT_SIZE
:
2829 ret
= ops
->priv
->content_size(config
, buf
, &cs
);
2832 return put_u64(cs
, arg
);
2834 case LTTNG_KERNEL_ABI_RING_BUFFER_GET_PACKET_SIZE
:
2838 ret
= ops
->priv
->packet_size(config
, buf
, &ps
);
2841 return put_u64(ps
, arg
);
2843 case LTTNG_KERNEL_ABI_RING_BUFFER_GET_STREAM_ID
:
2847 ret
= ops
->priv
->stream_id(config
, buf
, &si
);
2850 return put_u64(si
, arg
);
2852 case LTTNG_KERNEL_ABI_RING_BUFFER_GET_CURRENT_TIMESTAMP
:
2856 ret
= ops
->priv
->current_timestamp(config
, buf
, &ts
);
2859 return put_u64(ts
, arg
);
2861 case LTTNG_KERNEL_ABI_RING_BUFFER_GET_SEQ_NUM
:
2865 ret
= ops
->priv
->sequence_number(config
, buf
, &seq
);
2868 return put_u64(seq
, arg
);
2870 case LTTNG_KERNEL_ABI_RING_BUFFER_INSTANCE_ID
:
2874 ret
= ops
->priv
->instance_id(config
, buf
, &id
);
2877 return put_u64(id
, arg
);
2880 return lib_ring_buffer_file_operations
.unlocked_ioctl(filp
,
2888 #ifdef CONFIG_COMPAT
2889 static long lttng_stream_ring_buffer_compat_ioctl(struct file
*filp
,
2890 unsigned int cmd
, unsigned long arg
)
2892 struct lttng_kernel_ring_buffer
*buf
= filp
->private_data
;
2893 struct lttng_kernel_ring_buffer_channel
*chan
= buf
->backend
.chan
;
2894 const struct lttng_kernel_ring_buffer_config
*config
= &chan
->backend
.config
;
2895 const struct lttng_kernel_channel_buffer_ops
*ops
= chan
->backend
.priv_ops
;
2898 if (atomic_read(&chan
->record_disabled
))
2902 case LTTNG_KERNEL_ABI_RING_BUFFER_COMPAT_GET_TIMESTAMP_BEGIN
:
2906 ret
= ops
->priv
->timestamp_begin(config
, buf
, &ts
);
2909 return put_u64(ts
, arg
);
2911 case LTTNG_KERNEL_ABI_RING_BUFFER_COMPAT_GET_TIMESTAMP_END
:
2915 ret
= ops
->priv
->timestamp_end(config
, buf
, &ts
);
2918 return put_u64(ts
, arg
);
2920 case LTTNG_KERNEL_ABI_RING_BUFFER_COMPAT_GET_EVENTS_DISCARDED
:
2924 ret
= ops
->priv
->events_discarded(config
, buf
, &ed
);
2927 return put_u64(ed
, arg
);
2929 case LTTNG_KERNEL_ABI_RING_BUFFER_COMPAT_GET_CONTENT_SIZE
:
2933 ret
= ops
->priv
->content_size(config
, buf
, &cs
);
2936 return put_u64(cs
, arg
);
2938 case LTTNG_KERNEL_ABI_RING_BUFFER_COMPAT_GET_PACKET_SIZE
:
2942 ret
= ops
->priv
->packet_size(config
, buf
, &ps
);
2945 return put_u64(ps
, arg
);
2947 case LTTNG_KERNEL_ABI_RING_BUFFER_COMPAT_GET_STREAM_ID
:
2951 ret
= ops
->priv
->stream_id(config
, buf
, &si
);
2954 return put_u64(si
, arg
);
2956 case LTTNG_KERNEL_ABI_RING_BUFFER_GET_CURRENT_TIMESTAMP
:
2960 ret
= ops
->priv
->current_timestamp(config
, buf
, &ts
);
2963 return put_u64(ts
, arg
);
2965 case LTTNG_KERNEL_ABI_RING_BUFFER_COMPAT_GET_SEQ_NUM
:
2969 ret
= ops
->priv
->sequence_number(config
, buf
, &seq
);
2972 return put_u64(seq
, arg
);
2974 case LTTNG_KERNEL_ABI_RING_BUFFER_COMPAT_INSTANCE_ID
:
2978 ret
= ops
->priv
->instance_id(config
, buf
, &id
);
2981 return put_u64(id
, arg
);
2984 return lib_ring_buffer_file_operations
.compat_ioctl(filp
,
2991 #endif /* CONFIG_COMPAT */
2993 static void lttng_stream_override_ring_buffer_fops(void)
2995 lttng_stream_ring_buffer_file_operations
.owner
= THIS_MODULE
;
2996 lttng_stream_ring_buffer_file_operations
.open
=
2997 lib_ring_buffer_file_operations
.open
;
2998 lttng_stream_ring_buffer_file_operations
.release
=
2999 lib_ring_buffer_file_operations
.release
;
3000 lttng_stream_ring_buffer_file_operations
.poll
=
3001 lib_ring_buffer_file_operations
.poll
;
3002 lttng_stream_ring_buffer_file_operations
.splice_read
=
3003 lib_ring_buffer_file_operations
.splice_read
;
3004 lttng_stream_ring_buffer_file_operations
.mmap
=
3005 lib_ring_buffer_file_operations
.mmap
;
3006 lttng_stream_ring_buffer_file_operations
.unlocked_ioctl
=
3007 lttng_stream_ring_buffer_ioctl
;
3008 lttng_stream_ring_buffer_file_operations
.llseek
=
3009 lib_ring_buffer_file_operations
.llseek
;
3010 #ifdef CONFIG_COMPAT
3011 lttng_stream_ring_buffer_file_operations
.compat_ioctl
=
3012 lttng_stream_ring_buffer_compat_ioctl
;
3016 int __init
lttng_abi_init(void)
3020 wrapper_vmalloc_sync_mappings();
3023 ret
= lttng_tp_mempool_init();
3028 lttng_proc_dentry
= proc_create_data("lttng", S_IRUSR
| S_IWUSR
, NULL
,
3029 <tng_proc_ops
, NULL
);
3031 if (!lttng_proc_dentry
) {
3032 printk(KERN_ERR
"LTTng: Error creating control file\n");
3036 lttng_stream_override_ring_buffer_fops();
3040 lttng_tp_mempool_destroy();
3041 lttng_clock_unref();
3045 /* No __exit annotation because used by init error path too. */
3046 void lttng_abi_exit(void)
3048 lttng_tp_mempool_destroy();
3049 lttng_clock_unref();
3050 if (lttng_proc_dentry
)
3051 remove_proc_entry("lttng", NULL
);