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/compiler_attributes.h>
38 #include <wrapper/poll.h>
39 #include <wrapper/file.h>
40 #include <wrapper/kref.h>
41 #include <wrapper/barrier.h>
42 #include <lttng/string-utils.h>
43 #include <lttng/abi.h>
44 #include <lttng/abi-old.h>
45 #include <lttng/events.h>
46 #include <lttng/events-internal.h>
47 #include <lttng/tracer.h>
48 #include <lttng/tp-mempool.h>
49 #include <ringbuffer/frontend_types.h>
50 #include <ringbuffer/iterator.h>
53 * This is LTTng's own personal way to create a system call as an external
54 * module. We use ioctl() on /proc/lttng.
57 static struct proc_dir_entry
*lttng_proc_dentry
;
59 #if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(5,6,0))
60 static const struct proc_ops lttng_proc_ops
;
62 static const struct file_operations lttng_proc_ops
;
65 static const struct file_operations lttng_session_fops
;
66 static const struct file_operations lttng_event_notifier_group_fops
;
67 static const struct file_operations lttng_channel_fops
;
68 static const struct file_operations lttng_metadata_fops
;
69 static const struct file_operations lttng_event_recorder_event_fops
;
70 static const struct file_operations lttng_event_recorder_enabler_fops
;
71 static struct file_operations lttng_stream_ring_buffer_file_operations
;
73 static int put_u64(uint64_t val
, unsigned long arg
);
74 static int put_u32(uint32_t val
, unsigned long arg
);
76 static int validate_zeroed_padding(char *p
, size_t len
)
80 for (i
= 0; i
< len
; i
++) {
88 * Teardown management: opened file descriptors keep a refcount on the module,
89 * so it can only exit when all file descriptors are closed.
93 int lttng_abi_create_session(void)
95 struct lttng_kernel_session
*session
;
96 struct file
*session_file
;
99 session
= lttng_session_create();
102 session_fd
= lttng_get_unused_fd();
103 if (session_fd
< 0) {
107 session_file
= anon_inode_getfile("[lttng_session]",
110 if (IS_ERR(session_file
)) {
111 ret
= PTR_ERR(session_file
);
114 session
->priv
->file
= session_file
;
115 fd_install(session_fd
, session_file
);
119 put_unused_fd(session_fd
);
121 lttng_session_destroy(session
);
126 void event_notifier_send_notification_work_wakeup(struct irq_work
*entry
)
128 struct lttng_event_notifier_group
*event_notifier_group
=
129 container_of(entry
, struct lttng_event_notifier_group
,
131 wake_up_interruptible(&event_notifier_group
->read_wait
);
135 int lttng_abi_create_event_notifier_group(void)
137 struct lttng_event_notifier_group
*event_notifier_group
;
138 struct file
*event_notifier_group_file
;
139 int event_notifier_group_fd
, ret
;
141 event_notifier_group
= lttng_event_notifier_group_create();
142 if (!event_notifier_group
)
145 event_notifier_group_fd
= lttng_get_unused_fd();
146 if (event_notifier_group_fd
< 0) {
147 ret
= event_notifier_group_fd
;
150 event_notifier_group_file
= anon_inode_getfile("[lttng_event_notifier_group]",
151 <tng_event_notifier_group_fops
,
152 event_notifier_group
, O_RDWR
);
153 if (IS_ERR(event_notifier_group_file
)) {
154 ret
= PTR_ERR(event_notifier_group_file
);
158 event_notifier_group
->file
= event_notifier_group_file
;
159 init_waitqueue_head(&event_notifier_group
->read_wait
);
160 init_irq_work(&event_notifier_group
->wakeup_pending
,
161 event_notifier_send_notification_work_wakeup
);
162 fd_install(event_notifier_group_fd
, event_notifier_group_file
);
163 return event_notifier_group_fd
;
166 put_unused_fd(event_notifier_group_fd
);
168 lttng_event_notifier_group_destroy(event_notifier_group
);
173 int lttng_abi_tracepoint_list(void)
175 struct file
*tracepoint_list_file
;
178 file_fd
= lttng_get_unused_fd();
184 tracepoint_list_file
= anon_inode_getfile("[lttng_tracepoint_list]",
185 <tng_tracepoint_list_fops
,
187 if (IS_ERR(tracepoint_list_file
)) {
188 ret
= PTR_ERR(tracepoint_list_file
);
191 ret
= lttng_tracepoint_list_fops
.open(NULL
, tracepoint_list_file
);
194 fd_install(file_fd
, tracepoint_list_file
);
198 fput(tracepoint_list_file
);
200 put_unused_fd(file_fd
);
205 #ifndef CONFIG_HAVE_SYSCALL_TRACEPOINTS
207 int lttng_abi_syscall_list(void)
213 int lttng_abi_syscall_list(void)
215 struct file
*syscall_list_file
;
218 file_fd
= lttng_get_unused_fd();
224 syscall_list_file
= anon_inode_getfile("[lttng_syscall_list]",
225 <tng_syscall_list_fops
,
227 if (IS_ERR(syscall_list_file
)) {
228 ret
= PTR_ERR(syscall_list_file
);
231 ret
= lttng_syscall_list_fops
.open(NULL
, syscall_list_file
);
234 fd_install(file_fd
, syscall_list_file
);
238 fput(syscall_list_file
);
240 put_unused_fd(file_fd
);
247 void lttng_abi_tracer_version(struct lttng_kernel_abi_tracer_version
*v
)
249 v
->major
= LTTNG_MODULES_MAJOR_VERSION
;
250 v
->minor
= LTTNG_MODULES_MINOR_VERSION
;
251 v
->patchlevel
= LTTNG_MODULES_PATCHLEVEL_VERSION
;
255 void lttng_abi_tracer_abi_version(struct lttng_kernel_abi_tracer_abi_version
*v
)
257 v
->major
= LTTNG_KERNEL_ABI_MAJOR_VERSION
;
258 v
->minor
= LTTNG_KERNEL_ABI_MINOR_VERSION
;
262 long lttng_abi_add_context(struct file
*file
,
263 struct lttng_kernel_abi_context
*context_param
,
264 struct lttng_kernel_ctx
**ctx
, struct lttng_kernel_session
*session
)
267 if (session
->priv
->been_active
)
270 switch (context_param
->ctx
) {
271 case LTTNG_KERNEL_ABI_CONTEXT_PID
:
272 return lttng_add_pid_to_ctx(ctx
);
273 case LTTNG_KERNEL_ABI_CONTEXT_PRIO
:
274 return lttng_add_prio_to_ctx(ctx
);
275 case LTTNG_KERNEL_ABI_CONTEXT_NICE
:
276 return lttng_add_nice_to_ctx(ctx
);
277 case LTTNG_KERNEL_ABI_CONTEXT_VPID
:
278 return lttng_add_vpid_to_ctx(ctx
);
279 case LTTNG_KERNEL_ABI_CONTEXT_TID
:
280 return lttng_add_tid_to_ctx(ctx
);
281 case LTTNG_KERNEL_ABI_CONTEXT_VTID
:
282 return lttng_add_vtid_to_ctx(ctx
);
283 case LTTNG_KERNEL_ABI_CONTEXT_PPID
:
284 return lttng_add_ppid_to_ctx(ctx
);
285 case LTTNG_KERNEL_ABI_CONTEXT_VPPID
:
286 return lttng_add_vppid_to_ctx(ctx
);
287 case LTTNG_KERNEL_ABI_CONTEXT_PERF_COUNTER
:
288 context_param
->u
.perf_counter
.name
[LTTNG_KERNEL_ABI_SYM_NAME_LEN
- 1] = '\0';
289 return lttng_add_perf_counter_to_ctx(context_param
->u
.perf_counter
.type
,
290 context_param
->u
.perf_counter
.config
,
291 context_param
->u
.perf_counter
.name
,
293 case LTTNG_KERNEL_ABI_CONTEXT_PROCNAME
:
294 return lttng_add_procname_to_ctx(ctx
);
295 case LTTNG_KERNEL_ABI_CONTEXT_HOSTNAME
:
296 return lttng_add_hostname_to_ctx(ctx
);
297 case LTTNG_KERNEL_ABI_CONTEXT_CPU_ID
:
298 return lttng_add_cpu_id_to_ctx(ctx
);
299 case LTTNG_KERNEL_ABI_CONTEXT_INTERRUPTIBLE
:
300 return lttng_add_interruptible_to_ctx(ctx
);
301 case LTTNG_KERNEL_ABI_CONTEXT_NEED_RESCHEDULE
:
302 return lttng_add_need_reschedule_to_ctx(ctx
);
303 case LTTNG_KERNEL_ABI_CONTEXT_PREEMPTIBLE
:
304 return lttng_add_preemptible_to_ctx(ctx
);
305 case LTTNG_KERNEL_ABI_CONTEXT_MIGRATABLE
:
306 return lttng_add_migratable_to_ctx(ctx
);
307 case LTTNG_KERNEL_ABI_CONTEXT_CALLSTACK_KERNEL
:
308 case LTTNG_KERNEL_ABI_CONTEXT_CALLSTACK_USER
:
309 return lttng_add_callstack_to_ctx(ctx
, context_param
->ctx
);
310 case LTTNG_KERNEL_ABI_CONTEXT_CGROUP_NS
:
311 return lttng_add_cgroup_ns_to_ctx(ctx
);
312 case LTTNG_KERNEL_ABI_CONTEXT_IPC_NS
:
313 return lttng_add_ipc_ns_to_ctx(ctx
);
314 case LTTNG_KERNEL_ABI_CONTEXT_MNT_NS
:
315 return lttng_add_mnt_ns_to_ctx(ctx
);
316 case LTTNG_KERNEL_ABI_CONTEXT_NET_NS
:
317 return lttng_add_net_ns_to_ctx(ctx
);
318 case LTTNG_KERNEL_ABI_CONTEXT_PID_NS
:
319 return lttng_add_pid_ns_to_ctx(ctx
);
320 case LTTNG_KERNEL_ABI_CONTEXT_USER_NS
:
321 return lttng_add_user_ns_to_ctx(ctx
);
322 case LTTNG_KERNEL_ABI_CONTEXT_UTS_NS
:
323 return lttng_add_uts_ns_to_ctx(ctx
);
324 case LTTNG_KERNEL_ABI_CONTEXT_UID
:
325 return lttng_add_uid_to_ctx(ctx
);
326 case LTTNG_KERNEL_ABI_CONTEXT_EUID
:
327 return lttng_add_euid_to_ctx(ctx
);
328 case LTTNG_KERNEL_ABI_CONTEXT_SUID
:
329 return lttng_add_suid_to_ctx(ctx
);
330 case LTTNG_KERNEL_ABI_CONTEXT_GID
:
331 return lttng_add_gid_to_ctx(ctx
);
332 case LTTNG_KERNEL_ABI_CONTEXT_EGID
:
333 return lttng_add_egid_to_ctx(ctx
);
334 case LTTNG_KERNEL_ABI_CONTEXT_SGID
:
335 return lttng_add_sgid_to_ctx(ctx
);
336 case LTTNG_KERNEL_ABI_CONTEXT_VUID
:
337 return lttng_add_vuid_to_ctx(ctx
);
338 case LTTNG_KERNEL_ABI_CONTEXT_VEUID
:
339 return lttng_add_veuid_to_ctx(ctx
);
340 case LTTNG_KERNEL_ABI_CONTEXT_VSUID
:
341 return lttng_add_vsuid_to_ctx(ctx
);
342 case LTTNG_KERNEL_ABI_CONTEXT_VGID
:
343 return lttng_add_vgid_to_ctx(ctx
);
344 case LTTNG_KERNEL_ABI_CONTEXT_VEGID
:
345 return lttng_add_vegid_to_ctx(ctx
);
346 case LTTNG_KERNEL_ABI_CONTEXT_VSGID
:
347 return lttng_add_vsgid_to_ctx(ctx
);
348 case LTTNG_KERNEL_ABI_CONTEXT_TIME_NS
:
349 return lttng_add_time_ns_to_ctx(ctx
);
356 * lttng_ioctl - lttng syscall through ioctl
362 * This ioctl implements lttng commands:
363 * LTTNG_KERNEL_ABI_SESSION
364 * Returns a LTTng trace session file descriptor
365 * LTTNG_KERNEL_ABI_TRACER_VERSION
366 * Returns the LTTng kernel tracer version
367 * LTTNG_KERNEL_ABI_TRACEPOINT_LIST
368 * Returns a file descriptor listing available tracepoints
369 * LTTNG_KERNEL_ABI_WAIT_QUIESCENT
370 * Returns after all previously running probes have completed
371 * LTTNG_KERNEL_ABI_TRACER_ABI_VERSION
372 * Returns the LTTng kernel tracer ABI version
373 * LTTNG_KERNEL_ABI_EVENT_NOTIFIER_GROUP_CREATE
374 * Returns a LTTng event notifier group file descriptor
376 * The returned session will be deleted when its file descriptor is closed.
379 long lttng_ioctl(struct file
*file
, unsigned int cmd
, unsigned long arg
)
382 case LTTNG_KERNEL_ABI_OLD_SESSION
:
383 case LTTNG_KERNEL_ABI_SESSION
:
384 return lttng_abi_create_session();
385 case LTTNG_KERNEL_ABI_EVENT_NOTIFIER_GROUP_CREATE
:
386 return lttng_abi_create_event_notifier_group();
387 case LTTNG_KERNEL_ABI_OLD_TRACER_VERSION
:
389 struct lttng_kernel_abi_tracer_version v
;
390 struct lttng_kernel_abi_old_tracer_version oldv
;
391 struct lttng_kernel_abi_old_tracer_version
*uversion
=
392 (struct lttng_kernel_abi_old_tracer_version __user
*) arg
;
394 lttng_abi_tracer_version(&v
);
395 oldv
.major
= v
.major
;
396 oldv
.minor
= v
.minor
;
397 oldv
.patchlevel
= v
.patchlevel
;
399 if (copy_to_user(uversion
, &oldv
, sizeof(oldv
)))
403 case LTTNG_KERNEL_ABI_TRACER_VERSION
:
405 struct lttng_kernel_abi_tracer_version version
;
406 struct lttng_kernel_abi_tracer_version
*uversion
=
407 (struct lttng_kernel_abi_tracer_version __user
*) arg
;
409 lttng_abi_tracer_version(&version
);
411 if (copy_to_user(uversion
, &version
, sizeof(version
)))
415 case LTTNG_KERNEL_ABI_TRACER_ABI_VERSION
:
417 struct lttng_kernel_abi_tracer_abi_version version
;
418 struct lttng_kernel_abi_tracer_abi_version
*uversion
=
419 (struct lttng_kernel_abi_tracer_abi_version __user
*) arg
;
421 lttng_abi_tracer_abi_version(&version
);
423 if (copy_to_user(uversion
, &version
, sizeof(version
)))
427 case LTTNG_KERNEL_ABI_OLD_TRACEPOINT_LIST
:
428 case LTTNG_KERNEL_ABI_TRACEPOINT_LIST
:
429 return lttng_abi_tracepoint_list();
430 case LTTNG_KERNEL_ABI_SYSCALL_LIST
:
431 return lttng_abi_syscall_list();
432 case LTTNG_KERNEL_ABI_OLD_WAIT_QUIESCENT
:
433 case LTTNG_KERNEL_ABI_WAIT_QUIESCENT
:
436 case LTTNG_KERNEL_ABI_OLD_CALIBRATE
:
438 struct lttng_kernel_abi_old_calibrate __user
*ucalibrate
=
439 (struct lttng_kernel_abi_old_calibrate __user
*) arg
;
440 struct lttng_kernel_abi_old_calibrate old_calibrate
;
441 struct lttng_kernel_abi_calibrate calibrate
;
444 if (copy_from_user(&old_calibrate
, ucalibrate
, sizeof(old_calibrate
)))
446 calibrate
.type
= old_calibrate
.type
;
447 ret
= lttng_calibrate(&calibrate
);
448 if (copy_to_user(ucalibrate
, &old_calibrate
, sizeof(old_calibrate
)))
452 case LTTNG_KERNEL_ABI_CALIBRATE
:
454 struct lttng_kernel_abi_calibrate __user
*ucalibrate
=
455 (struct lttng_kernel_abi_calibrate __user
*) arg
;
456 struct lttng_kernel_abi_calibrate calibrate
;
459 if (copy_from_user(&calibrate
, ucalibrate
, sizeof(calibrate
)))
461 ret
= lttng_calibrate(&calibrate
);
462 if (copy_to_user(ucalibrate
, &calibrate
, sizeof(calibrate
)))
471 #if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(5,6,0))
472 static const struct proc_ops lttng_proc_ops
= {
473 .proc_ioctl
= lttng_ioctl
,
475 .proc_compat_ioctl
= lttng_ioctl
,
476 #endif /* CONFIG_COMPAT */
479 static const struct file_operations lttng_proc_ops
= {
480 .owner
= THIS_MODULE
,
481 .unlocked_ioctl
= lttng_ioctl
,
483 .compat_ioctl
= lttng_ioctl
,
484 #endif /* CONFIG_COMPAT */
489 int lttng_abi_create_channel(struct file
*session_file
,
490 struct lttng_kernel_abi_channel
*chan_param
,
491 enum channel_type channel_type
)
493 struct lttng_kernel_session
*session
= session_file
->private_data
;
494 const struct file_operations
*fops
= NULL
;
495 const char *transport_name
;
496 struct lttng_kernel_channel_buffer
*chan
;
497 struct file
*chan_file
;
501 chan_fd
= lttng_get_unused_fd();
506 switch (channel_type
) {
507 case PER_CPU_CHANNEL
:
508 fops
= <tng_channel_fops
;
510 case METADATA_CHANNEL
:
511 fops
= <tng_metadata_fops
;
515 chan_file
= anon_inode_getfile("[lttng_channel]",
518 if (IS_ERR(chan_file
)) {
519 ret
= PTR_ERR(chan_file
);
522 switch (channel_type
) {
523 case PER_CPU_CHANNEL
:
524 if (chan_param
->output
== LTTNG_KERNEL_ABI_SPLICE
) {
525 transport_name
= chan_param
->overwrite
?
526 "relay-overwrite" : "relay-discard";
527 } else if (chan_param
->output
== LTTNG_KERNEL_ABI_MMAP
) {
528 transport_name
= chan_param
->overwrite
?
529 "relay-overwrite-mmap" : "relay-discard-mmap";
534 case METADATA_CHANNEL
:
535 if (chan_param
->output
== LTTNG_KERNEL_ABI_SPLICE
)
536 transport_name
= "relay-metadata";
537 else if (chan_param
->output
== LTTNG_KERNEL_ABI_MMAP
)
538 transport_name
= "relay-metadata-mmap";
543 transport_name
= "<unknown>";
546 if (!atomic_long_add_unless(&session_file
->f_count
, 1, LONG_MAX
)) {
551 * We tolerate no failure path after channel creation. It will stay
552 * invariant for the rest of the session.
554 chan
= lttng_channel_create(session
, transport_name
, NULL
,
555 chan_param
->subbuf_size
,
556 chan_param
->num_subbuf
,
557 chan_param
->switch_timer_interval
,
558 chan_param
->read_timer_interval
,
564 chan
->priv
->parent
.file
= chan_file
;
565 chan_file
->private_data
= chan
;
566 fd_install(chan_fd
, chan_file
);
571 atomic_long_dec(&session_file
->f_count
);
575 put_unused_fd(chan_fd
);
581 int lttng_abi_session_set_name(struct lttng_kernel_session
*session
,
582 struct lttng_kernel_abi_session_name
*name
)
586 len
= strnlen(name
->name
, LTTNG_KERNEL_ABI_SESSION_NAME_LEN
);
588 if (len
== LTTNG_KERNEL_ABI_SESSION_NAME_LEN
) {
589 /* Name is too long/malformed */
593 strcpy(session
->priv
->name
, name
->name
);
598 int lttng_abi_session_set_creation_time(struct lttng_kernel_session
*session
,
599 struct lttng_kernel_abi_session_creation_time
*time
)
603 len
= strnlen(time
->iso8601
, LTTNG_KERNEL_ABI_SESSION_CREATION_TIME_ISO8601_LEN
);
605 if (len
== LTTNG_KERNEL_ABI_SESSION_CREATION_TIME_ISO8601_LEN
) {
606 /* Time is too long/malformed */
610 strcpy(session
->priv
->creation_time
, time
->iso8601
);
615 int lttng_counter_release(struct inode
*inode
, struct file
*file
)
617 struct lttng_counter
*counter
= file
->private_data
;
621 * Do not destroy the counter itself. Wait of the owner
622 * (event_notifier group) to be destroyed.
624 fput(counter
->owner
);
631 long lttng_counter_ioctl(struct file
*file
, unsigned int cmd
, unsigned long arg
)
633 struct lttng_counter
*counter
= file
->private_data
;
634 size_t indexes
[LTTNG_KERNEL_ABI_COUNTER_DIMENSION_MAX
] = { 0 };
638 case LTTNG_KERNEL_ABI_COUNTER_READ
:
640 struct lttng_kernel_abi_counter_read local_counter_read
;
641 struct lttng_kernel_abi_counter_read __user
*ucounter_read
=
642 (struct lttng_kernel_abi_counter_read __user
*) arg
;
643 bool overflow
, underflow
;
648 if (copy_from_user(&local_counter_read
, ucounter_read
,
649 sizeof(local_counter_read
)))
651 if (validate_zeroed_padding(local_counter_read
.padding
,
652 sizeof(local_counter_read
.padding
)))
654 if (local_counter_read
.index
.number_dimensions
> LTTNG_KERNEL_ABI_COUNTER_DIMENSION_MAX
)
657 /* Cast all indexes into size_t. */
658 for (i
= 0; i
< local_counter_read
.index
.number_dimensions
; i
++)
659 indexes
[i
] = (size_t) local_counter_read
.index
.dimension_indexes
[i
];
660 cpu
= local_counter_read
.cpu
;
662 ret
= lttng_kernel_counter_read(counter
, indexes
, cpu
, &value
,
663 &overflow
, &underflow
);
666 local_counter_read
.value
.value
= value
;
667 local_counter_read
.value
.overflow
= overflow
;
668 local_counter_read
.value
.underflow
= underflow
;
670 if (copy_to_user(&ucounter_read
->value
, &local_counter_read
.value
,
671 sizeof(local_counter_read
.value
)))
676 case LTTNG_KERNEL_ABI_COUNTER_AGGREGATE
:
678 struct lttng_kernel_abi_counter_aggregate local_counter_aggregate
;
679 struct lttng_kernel_abi_counter_aggregate __user
*ucounter_aggregate
=
680 (struct lttng_kernel_abi_counter_aggregate __user
*) arg
;
681 bool overflow
, underflow
;
685 if (copy_from_user(&local_counter_aggregate
, ucounter_aggregate
,
686 sizeof(local_counter_aggregate
)))
688 if (validate_zeroed_padding(local_counter_aggregate
.padding
,
689 sizeof(local_counter_aggregate
.padding
)))
691 if (local_counter_aggregate
.index
.number_dimensions
> LTTNG_KERNEL_ABI_COUNTER_DIMENSION_MAX
)
694 /* Cast all indexes into size_t. */
695 for (i
= 0; i
< local_counter_aggregate
.index
.number_dimensions
; i
++)
696 indexes
[i
] = (size_t) local_counter_aggregate
.index
.dimension_indexes
[i
];
698 ret
= lttng_kernel_counter_aggregate(counter
, indexes
, &value
,
699 &overflow
, &underflow
);
702 local_counter_aggregate
.value
.value
= value
;
703 local_counter_aggregate
.value
.overflow
= overflow
;
704 local_counter_aggregate
.value
.underflow
= underflow
;
706 if (copy_to_user(&ucounter_aggregate
->value
, &local_counter_aggregate
.value
,
707 sizeof(local_counter_aggregate
.value
)))
712 case LTTNG_KERNEL_ABI_COUNTER_CLEAR
:
714 struct lttng_kernel_abi_counter_clear local_counter_clear
;
715 struct lttng_kernel_abi_counter_clear __user
*ucounter_clear
=
716 (struct lttng_kernel_abi_counter_clear __user
*) arg
;
718 if (copy_from_user(&local_counter_clear
, ucounter_clear
,
719 sizeof(local_counter_clear
)))
721 if (validate_zeroed_padding(local_counter_clear
.padding
,
722 sizeof(local_counter_clear
.padding
)))
724 if (local_counter_clear
.index
.number_dimensions
> LTTNG_KERNEL_ABI_COUNTER_DIMENSION_MAX
)
727 /* Cast all indexes into size_t. */
728 for (i
= 0; i
< local_counter_clear
.index
.number_dimensions
; i
++)
729 indexes
[i
] = (size_t) local_counter_clear
.index
.dimension_indexes
[i
];
731 return lttng_kernel_counter_clear(counter
, indexes
);
738 static const struct file_operations lttng_counter_fops
= {
739 .owner
= THIS_MODULE
,
740 .release
= lttng_counter_release
,
741 .unlocked_ioctl
= lttng_counter_ioctl
,
743 .compat_ioctl
= lttng_counter_ioctl
,
749 enum tracker_type
get_tracker_type(struct lttng_kernel_abi_tracker_args
*tracker
)
751 switch (tracker
->type
) {
752 case LTTNG_KERNEL_ABI_TRACKER_PID
:
754 case LTTNG_KERNEL_ABI_TRACKER_VPID
:
756 case LTTNG_KERNEL_ABI_TRACKER_UID
:
758 case LTTNG_KERNEL_ABI_TRACKER_VUID
:
760 case LTTNG_KERNEL_ABI_TRACKER_GID
:
762 case LTTNG_KERNEL_ABI_TRACKER_VGID
:
765 return TRACKER_UNKNOWN
;
770 * lttng_session_ioctl - lttng session fd ioctl
776 * This ioctl implements lttng commands:
777 * LTTNG_KERNEL_ABI_CHANNEL
778 * Returns a LTTng channel file descriptor
779 * LTTNG_KERNEL_ABI_ENABLE
780 * Enables tracing for a session (weak enable)
781 * LTTNG_KERNEL_ABI_DISABLE
782 * Disables tracing for a session (strong disable)
783 * LTTNG_KERNEL_ABI_METADATA
784 * Returns a LTTng metadata file descriptor
785 * LTTNG_KERNEL_ABI_SESSION_TRACK_PID
786 * Add PID to session PID tracker
787 * LTTNG_KERNEL_ABI_SESSION_UNTRACK_PID
788 * Remove PID from session PID tracker
789 * LTTNG_KERNEL_ABI_SESSION_TRACK_ID
791 * LTTNG_KERNEL_ABI_SESSION_UNTRACK_ID
792 * Remove ID from tracker
794 * The returned channel will be deleted when its file descriptor is closed.
797 long lttng_session_ioctl(struct file
*file
, unsigned int cmd
, unsigned long arg
)
799 struct lttng_kernel_session
*session
= file
->private_data
;
800 struct lttng_kernel_abi_channel chan_param
;
801 struct lttng_kernel_abi_old_channel old_chan_param
;
804 * Handle backward compatibility. OLD commands have wrong
805 * directions, replace them by the correct direction.
808 case LTTNG_KERNEL_ABI_OLD_SESSION_TRACK_PID
:
809 cmd
= LTTNG_KERNEL_ABI_SESSION_TRACK_PID
;
811 case LTTNG_KERNEL_ABI_OLD_SESSION_UNTRACK_PID
:
812 cmd
= LTTNG_KERNEL_ABI_SESSION_UNTRACK_PID
;
814 case LTTNG_KERNEL_ABI_OLD_SESSION_TRACK_ID
:
815 cmd
= LTTNG_KERNEL_ABI_SESSION_TRACK_ID
;
817 case LTTNG_KERNEL_ABI_OLD_SESSION_UNTRACK_ID
:
818 cmd
= LTTNG_KERNEL_ABI_SESSION_UNTRACK_ID
;
820 case LTTNG_KERNEL_ABI_OLD_SESSION_LIST_TRACKER_IDS
:
821 cmd
= LTTNG_KERNEL_ABI_SESSION_LIST_TRACKER_IDS
;
823 case LTTNG_KERNEL_ABI_OLD_SESSION_SET_NAME
:
824 cmd
= LTTNG_KERNEL_ABI_SESSION_SET_NAME
;
826 case LTTNG_KERNEL_ABI_OLD_SESSION_SET_CREATION_TIME
:
827 cmd
= LTTNG_KERNEL_ABI_SESSION_SET_CREATION_TIME
;
835 case LTTNG_KERNEL_ABI_OLD_CHANNEL
:
837 if (copy_from_user(&old_chan_param
,
838 (struct lttng_kernel_abi_old_channel __user
*) arg
,
839 sizeof(struct lttng_kernel_abi_old_channel
)))
841 chan_param
.overwrite
= old_chan_param
.overwrite
;
842 chan_param
.subbuf_size
= old_chan_param
.subbuf_size
;
843 chan_param
.num_subbuf
= old_chan_param
.num_subbuf
;
844 chan_param
.switch_timer_interval
= old_chan_param
.switch_timer_interval
;
845 chan_param
.read_timer_interval
= old_chan_param
.read_timer_interval
;
846 chan_param
.output
= old_chan_param
.output
;
848 return lttng_abi_create_channel(file
, &chan_param
,
851 case LTTNG_KERNEL_ABI_CHANNEL
:
853 if (copy_from_user(&chan_param
,
854 (struct lttng_kernel_abi_channel __user
*) arg
,
855 sizeof(struct lttng_kernel_abi_channel
)))
857 return lttng_abi_create_channel(file
, &chan_param
,
860 case LTTNG_KERNEL_ABI_OLD_SESSION_START
:
861 case LTTNG_KERNEL_ABI_OLD_ENABLE
:
862 case LTTNG_KERNEL_ABI_SESSION_START
:
863 case LTTNG_KERNEL_ABI_ENABLE
:
864 return lttng_session_enable(session
);
865 case LTTNG_KERNEL_ABI_OLD_SESSION_STOP
:
866 case LTTNG_KERNEL_ABI_OLD_DISABLE
:
867 case LTTNG_KERNEL_ABI_SESSION_STOP
:
868 case LTTNG_KERNEL_ABI_DISABLE
:
869 return lttng_session_disable(session
);
870 case LTTNG_KERNEL_ABI_OLD_METADATA
:
872 if (copy_from_user(&old_chan_param
,
873 (struct lttng_kernel_abi_old_channel __user
*) arg
,
874 sizeof(struct lttng_kernel_abi_old_channel
)))
876 chan_param
.overwrite
= old_chan_param
.overwrite
;
877 chan_param
.subbuf_size
= old_chan_param
.subbuf_size
;
878 chan_param
.num_subbuf
= old_chan_param
.num_subbuf
;
879 chan_param
.switch_timer_interval
= old_chan_param
.switch_timer_interval
;
880 chan_param
.read_timer_interval
= old_chan_param
.read_timer_interval
;
881 chan_param
.output
= old_chan_param
.output
;
883 return lttng_abi_create_channel(file
, &chan_param
,
886 case LTTNG_KERNEL_ABI_METADATA
:
888 if (copy_from_user(&chan_param
,
889 (struct lttng_kernel_abi_channel __user
*) arg
,
890 sizeof(struct lttng_kernel_abi_channel
)))
892 return lttng_abi_create_channel(file
, &chan_param
,
895 case LTTNG_KERNEL_ABI_SESSION_TRACK_PID
:
896 return lttng_session_track_id(session
, TRACKER_PID
, (int) arg
);
897 case LTTNG_KERNEL_ABI_SESSION_UNTRACK_PID
:
898 return lttng_session_untrack_id(session
, TRACKER_PID
, (int) arg
);
899 case LTTNG_KERNEL_ABI_SESSION_TRACK_ID
:
901 struct lttng_kernel_abi_tracker_args tracker
;
902 enum tracker_type tracker_type
;
904 if (copy_from_user(&tracker
,
905 (struct lttng_kernel_abi_tracker_args __user
*) arg
,
906 sizeof(struct lttng_kernel_abi_tracker_args
)))
908 tracker_type
= get_tracker_type(&tracker
);
909 if (tracker_type
== TRACKER_UNKNOWN
)
911 return lttng_session_track_id(session
, tracker_type
, tracker
.id
);
913 case LTTNG_KERNEL_ABI_SESSION_UNTRACK_ID
:
915 struct lttng_kernel_abi_tracker_args tracker
;
916 enum tracker_type tracker_type
;
918 if (copy_from_user(&tracker
,
919 (struct lttng_kernel_abi_tracker_args __user
*) arg
,
920 sizeof(struct lttng_kernel_abi_tracker_args
)))
922 tracker_type
= get_tracker_type(&tracker
);
923 if (tracker_type
== TRACKER_UNKNOWN
)
925 return lttng_session_untrack_id(session
, tracker_type
,
928 case LTTNG_KERNEL_ABI_SESSION_LIST_TRACKER_PIDS
:
929 return lttng_session_list_tracker_ids(session
, TRACKER_PID
);
930 case LTTNG_KERNEL_ABI_SESSION_LIST_TRACKER_IDS
:
932 struct lttng_kernel_abi_tracker_args tracker
;
933 enum tracker_type tracker_type
;
935 if (copy_from_user(&tracker
,
936 (struct lttng_kernel_abi_tracker_args __user
*) arg
,
937 sizeof(struct lttng_kernel_abi_tracker_args
)))
939 tracker_type
= get_tracker_type(&tracker
);
940 if (tracker_type
== TRACKER_UNKNOWN
)
942 return lttng_session_list_tracker_ids(session
, tracker_type
);
944 case LTTNG_KERNEL_ABI_SESSION_METADATA_REGEN
:
945 return lttng_session_metadata_regenerate(session
);
946 case LTTNG_KERNEL_ABI_SESSION_STATEDUMP
:
947 return lttng_session_statedump(session
);
948 case LTTNG_KERNEL_ABI_SESSION_SET_NAME
:
950 struct lttng_kernel_abi_session_name name
;
952 if (copy_from_user(&name
,
953 (struct lttng_kernel_abi_session_name __user
*) arg
,
954 sizeof(struct lttng_kernel_abi_session_name
)))
956 return lttng_abi_session_set_name(session
, &name
);
958 case LTTNG_KERNEL_ABI_SESSION_SET_CREATION_TIME
:
960 struct lttng_kernel_abi_session_creation_time time
;
962 if (copy_from_user(&time
,
963 (struct lttng_kernel_abi_session_creation_time __user
*) arg
,
964 sizeof(struct lttng_kernel_abi_session_creation_time
)))
966 return lttng_abi_session_set_creation_time(session
, &time
);
974 * Called when the last file reference is dropped.
976 * Big fat note: channels and events are invariant for the whole session after
977 * their creation. So this session destruction also destroys all channel and
978 * event structures specific to this session (they are not destroyed when their
979 * individual file is released).
982 int lttng_session_release(struct inode
*inode
, struct file
*file
)
984 struct lttng_kernel_session
*session
= file
->private_data
;
987 lttng_session_destroy(session
);
991 static const struct file_operations lttng_session_fops
= {
992 .owner
= THIS_MODULE
,
993 .release
= lttng_session_release
,
994 .unlocked_ioctl
= lttng_session_ioctl
,
996 .compat_ioctl
= lttng_session_ioctl
,
1001 * When encountering empty buffer, flush current sub-buffer if non-empty
1002 * and retry (if new data available to read after flush).
1005 ssize_t
lttng_event_notifier_group_notif_read(struct file
*filp
, char __user
*user_buf
,
1006 size_t count
, loff_t
*ppos
)
1008 struct lttng_event_notifier_group
*event_notifier_group
= filp
->private_data
;
1009 struct lttng_kernel_ring_buffer_channel
*chan
= event_notifier_group
->chan
;
1010 struct lttng_kernel_ring_buffer
*buf
= event_notifier_group
->buf
;
1011 ssize_t read_count
= 0, len
;
1015 if (!lttng_access_ok(VERIFY_WRITE
, user_buf
, count
))
1018 /* Finish copy of previous record */
1021 len
= chan
->iter
.len_left
;
1022 read_offset
= *ppos
;
1027 while (read_count
< count
) {
1028 size_t copy_len
, space_left
;
1030 len
= lib_ring_buffer_get_next_record(chan
, buf
);
1034 * Check if buffer is finalized (end of file).
1036 if (len
== -ENODATA
) {
1037 /* A 0 read_count will tell about end of file */
1040 if (filp
->f_flags
& O_NONBLOCK
) {
1042 read_count
= -EAGAIN
;
1048 * No data available at the moment, return what
1055 * Wait for returned len to be >= 0 or -ENODATA.
1057 error
= wait_event_interruptible(
1058 event_notifier_group
->read_wait
,
1059 ((len
= lib_ring_buffer_get_next_record(
1060 chan
, buf
)), len
!= -EAGAIN
));
1061 CHAN_WARN_ON(chan
, len
== -EBUSY
);
1066 CHAN_WARN_ON(chan
, len
< 0 && len
!= -ENODATA
);
1070 read_offset
= buf
->iter
.read_offset
;
1072 space_left
= count
- read_count
;
1073 if (len
<= space_left
) {
1075 chan
->iter
.len_left
= 0;
1078 copy_len
= space_left
;
1079 chan
->iter
.len_left
= len
- copy_len
;
1080 *ppos
= read_offset
+ copy_len
;
1082 if (__lib_ring_buffer_copy_to_user(&buf
->backend
, read_offset
,
1083 &user_buf
[read_count
],
1086 * Leave the len_left and ppos values at their current
1087 * state, as we currently have a valid event to read.
1091 read_count
+= copy_len
;
1097 chan
->iter
.len_left
= 0;
1101 lib_ring_buffer_put_current_record(buf
);
1106 * If the ring buffer is non empty (even just a partial subbuffer), return that
1107 * there is data available. Perform a ring buffer flush if we encounter a
1108 * non-empty ring buffer which does not have any consumeable subbuffer available.
1111 unsigned int lttng_event_notifier_group_notif_poll(struct file
*filp
,
1114 unsigned int mask
= 0;
1115 struct lttng_event_notifier_group
*event_notifier_group
= filp
->private_data
;
1116 struct lttng_kernel_ring_buffer_channel
*chan
= event_notifier_group
->chan
;
1117 struct lttng_kernel_ring_buffer
*buf
= event_notifier_group
->buf
;
1118 const struct lttng_kernel_ring_buffer_config
*config
= &chan
->backend
.config
;
1119 int finalized
, disabled
;
1120 unsigned long consumed
, offset
;
1121 size_t subbuffer_header_size
= config
->cb
.subbuffer_header_size();
1123 if (filp
->f_mode
& FMODE_READ
) {
1124 poll_wait_set_exclusive(wait
);
1125 poll_wait(filp
, &event_notifier_group
->read_wait
, wait
);
1127 finalized
= lib_ring_buffer_is_finalized(config
, buf
);
1128 disabled
= lib_ring_buffer_channel_is_disabled(chan
);
1131 * lib_ring_buffer_is_finalized() contains a smp_rmb() ordering
1132 * finalized load before offsets loads.
1134 WARN_ON(atomic_long_read(&buf
->active_readers
) != 1);
1139 offset
= lib_ring_buffer_get_offset(config
, buf
);
1140 consumed
= lib_ring_buffer_get_consumed(config
, buf
);
1143 * If there is no buffer available to consume.
1145 if (subbuf_trunc(offset
, chan
) - subbuf_trunc(consumed
, chan
) == 0) {
1147 * If there is a non-empty subbuffer, flush and try again.
1149 if (subbuf_offset(offset
, chan
) > subbuffer_header_size
) {
1150 lib_ring_buffer_switch_remote(buf
);
1158 * The memory barriers
1159 * __wait_event()/wake_up_interruptible() take
1160 * care of "raw_spin_is_locked" memory ordering.
1162 if (raw_spin_is_locked(&buf
->raw_tick_nohz_spinlock
))
1168 if (subbuf_trunc(offset
, chan
) - subbuf_trunc(consumed
, chan
)
1169 >= chan
->backend
.buf_size
)
1170 return POLLPRI
| POLLRDBAND
;
1172 return POLLIN
| POLLRDNORM
;
1180 * lttng_event_notifier_group_notif_open - event_notifier ring buffer open file operation
1181 * @inode: opened inode
1182 * @file: opened file
1184 * Open implementation. Makes sure only one open instance of a buffer is
1185 * done at a given moment.
1187 static int lttng_event_notifier_group_notif_open(struct inode
*inode
, struct file
*file
)
1189 struct lttng_event_notifier_group
*event_notifier_group
= inode
->i_private
;
1190 struct lttng_kernel_ring_buffer
*buf
= event_notifier_group
->buf
;
1192 file
->private_data
= event_notifier_group
;
1193 return lib_ring_buffer_open(inode
, file
, buf
);
1197 * lttng_event_notifier_group_notif_release - event_notifier ring buffer release file operation
1198 * @inode: opened inode
1199 * @file: opened file
1201 * Release implementation.
1203 static int lttng_event_notifier_group_notif_release(struct inode
*inode
, struct file
*file
)
1205 struct lttng_event_notifier_group
*event_notifier_group
= file
->private_data
;
1206 struct lttng_kernel_ring_buffer
*buf
= event_notifier_group
->buf
;
1209 ret
= lib_ring_buffer_release(inode
, file
, buf
);
1212 fput(event_notifier_group
->file
);
1216 static const struct file_operations lttng_event_notifier_group_notif_fops
= {
1217 .owner
= THIS_MODULE
,
1218 .open
= lttng_event_notifier_group_notif_open
,
1219 .release
= lttng_event_notifier_group_notif_release
,
1220 .read
= lttng_event_notifier_group_notif_read
,
1221 .poll
= lttng_event_notifier_group_notif_poll
,
1225 * lttng_metadata_ring_buffer_poll - LTTng ring buffer poll file operation
1229 * Handles the poll operations for the metadata channels.
1232 unsigned int lttng_metadata_ring_buffer_poll(struct file
*filp
,
1235 struct lttng_metadata_stream
*stream
= filp
->private_data
;
1236 struct lttng_kernel_ring_buffer
*buf
= stream
->priv
;
1238 unsigned int mask
= 0;
1240 if (filp
->f_mode
& FMODE_READ
) {
1241 poll_wait_set_exclusive(wait
);
1242 poll_wait(filp
, &stream
->read_wait
, wait
);
1244 finalized
= stream
->finalized
;
1247 * lib_ring_buffer_is_finalized() contains a smp_rmb()
1248 * ordering finalized load before offsets loads.
1250 WARN_ON(atomic_long_read(&buf
->active_readers
) != 1);
1255 mutex_lock(&stream
->metadata_cache
->lock
);
1256 if (stream
->metadata_cache
->metadata_written
>
1257 stream
->metadata_out
)
1259 mutex_unlock(&stream
->metadata_cache
->lock
);
1266 void lttng_metadata_ring_buffer_ioctl_put_next_subbuf(struct file
*filp
,
1267 unsigned int cmd
, unsigned long arg
)
1269 struct lttng_metadata_stream
*stream
= filp
->private_data
;
1271 stream
->metadata_out
= stream
->metadata_in
;
1275 * Reset the counter of how much metadata has been consumed to 0. That way,
1276 * the consumer receives the content of the metadata cache unchanged. This is
1277 * different from the metadata_regenerate where the offset from epoch is
1278 * resampled, here we want the exact same content as the last time the metadata
1279 * was generated. This command is only possible if all the metadata written
1280 * in the cache has been output to the metadata stream to avoid corrupting the
1283 * Return 0 on success, a negative value on error.
1286 int lttng_metadata_cache_dump(struct lttng_metadata_stream
*stream
)
1289 struct lttng_metadata_cache
*cache
= stream
->metadata_cache
;
1291 mutex_lock(&cache
->lock
);
1292 if (stream
->metadata_out
!= cache
->metadata_written
) {
1296 stream
->metadata_out
= 0;
1297 stream
->metadata_in
= 0;
1298 wake_up_interruptible(&stream
->read_wait
);
1302 mutex_unlock(&cache
->lock
);
1307 long lttng_metadata_ring_buffer_ioctl(struct file
*filp
,
1308 unsigned int cmd
, unsigned long arg
)
1311 struct lttng_metadata_stream
*stream
= filp
->private_data
;
1312 struct lttng_kernel_ring_buffer
*buf
= stream
->priv
;
1313 unsigned int rb_cmd
;
1316 if (cmd
== LTTNG_KERNEL_ABI_RING_BUFFER_GET_NEXT_SUBBUF_METADATA_CHECK
)
1317 rb_cmd
= LTTNG_KERNEL_ABI_RING_BUFFER_GET_NEXT_SUBBUF
;
1322 case LTTNG_KERNEL_ABI_RING_BUFFER_GET_NEXT_SUBBUF
:
1324 struct lttng_metadata_stream
*stream
= filp
->private_data
;
1325 struct lttng_kernel_ring_buffer
*buf
= stream
->priv
;
1326 struct lttng_kernel_ring_buffer_channel
*chan
= buf
->backend
.chan
;
1328 ret
= lttng_metadata_output_channel(stream
, chan
, NULL
);
1330 lib_ring_buffer_switch_slow(buf
, SWITCH_ACTIVE
);
1336 case LTTNG_KERNEL_ABI_RING_BUFFER_GET_SUBBUF
:
1339 * Random access is not allowed for metadata channel.
1343 case LTTNG_KERNEL_ABI_RING_BUFFER_FLUSH_EMPTY
:
1345 case LTTNG_KERNEL_ABI_RING_BUFFER_FLUSH
:
1347 struct lttng_metadata_stream
*stream
= filp
->private_data
;
1348 struct lttng_kernel_ring_buffer
*buf
= stream
->priv
;
1349 struct lttng_kernel_ring_buffer_channel
*chan
= buf
->backend
.chan
;
1352 * Before doing the actual ring buffer flush, write up to one
1353 * packet of metadata in the ring buffer.
1355 ret
= lttng_metadata_output_channel(stream
, chan
, NULL
);
1360 case LTTNG_KERNEL_ABI_RING_BUFFER_GET_METADATA_VERSION
:
1362 struct lttng_metadata_stream
*stream
= filp
->private_data
;
1364 return put_u64(stream
->version
, arg
);
1366 case LTTNG_KERNEL_ABI_RING_BUFFER_METADATA_CACHE_DUMP
:
1368 struct lttng_metadata_stream
*stream
= filp
->private_data
;
1370 return lttng_metadata_cache_dump(stream
);
1372 case LTTNG_KERNEL_ABI_RING_BUFFER_GET_NEXT_SUBBUF_METADATA_CHECK
:
1374 struct lttng_metadata_stream
*stream
= filp
->private_data
;
1375 struct lttng_kernel_ring_buffer
*buf
= stream
->priv
;
1376 struct lttng_kernel_ring_buffer_channel
*chan
= buf
->backend
.chan
;
1378 ret
= lttng_metadata_output_channel(stream
, chan
, &coherent
);
1380 lib_ring_buffer_switch_slow(buf
, SWITCH_ACTIVE
);
1382 } else if (ret
< 0) {
1390 /* PUT_SUBBUF is the one from lib ring buffer, unmodified. */
1392 /* Performing lib ring buffer ioctl after our own. */
1393 ret
= lib_ring_buffer_ioctl(filp
, rb_cmd
, arg
, buf
);
1398 case LTTNG_KERNEL_ABI_RING_BUFFER_PUT_NEXT_SUBBUF
:
1400 lttng_metadata_ring_buffer_ioctl_put_next_subbuf(filp
,
1404 case LTTNG_KERNEL_ABI_RING_BUFFER_GET_NEXT_SUBBUF_METADATA_CHECK
:
1406 return put_u32(coherent
, arg
);
1415 #ifdef CONFIG_COMPAT
1417 long lttng_metadata_ring_buffer_compat_ioctl(struct file
*filp
,
1418 unsigned int cmd
, unsigned long arg
)
1421 struct lttng_metadata_stream
*stream
= filp
->private_data
;
1422 struct lttng_kernel_ring_buffer
*buf
= stream
->priv
;
1423 unsigned int rb_cmd
;
1426 if (cmd
== LTTNG_KERNEL_ABI_RING_BUFFER_GET_NEXT_SUBBUF_METADATA_CHECK
)
1427 rb_cmd
= LTTNG_KERNEL_ABI_RING_BUFFER_GET_NEXT_SUBBUF
;
1432 case LTTNG_KERNEL_ABI_RING_BUFFER_GET_NEXT_SUBBUF
:
1434 struct lttng_metadata_stream
*stream
= filp
->private_data
;
1435 struct lttng_kernel_ring_buffer
*buf
= stream
->priv
;
1436 struct lttng_kernel_ring_buffer_channel
*chan
= buf
->backend
.chan
;
1438 ret
= lttng_metadata_output_channel(stream
, chan
, NULL
);
1440 lib_ring_buffer_switch_slow(buf
, SWITCH_ACTIVE
);
1446 case LTTNG_KERNEL_ABI_RING_BUFFER_GET_SUBBUF
:
1449 * Random access is not allowed for metadata channel.
1453 case LTTNG_KERNEL_ABI_RING_BUFFER_FLUSH_EMPTY
:
1455 case LTTNG_KERNEL_ABI_RING_BUFFER_FLUSH
:
1457 struct lttng_metadata_stream
*stream
= filp
->private_data
;
1458 struct lttng_kernel_ring_buffer
*buf
= stream
->priv
;
1459 struct lttng_kernel_ring_buffer_channel
*chan
= buf
->backend
.chan
;
1462 * Before doing the actual ring buffer flush, write up to one
1463 * packet of metadata in the ring buffer.
1465 ret
= lttng_metadata_output_channel(stream
, chan
, NULL
);
1470 case LTTNG_KERNEL_ABI_RING_BUFFER_GET_METADATA_VERSION
:
1472 struct lttng_metadata_stream
*stream
= filp
->private_data
;
1474 return put_u64(stream
->version
, arg
);
1476 case LTTNG_KERNEL_ABI_RING_BUFFER_METADATA_CACHE_DUMP
:
1478 struct lttng_metadata_stream
*stream
= filp
->private_data
;
1480 return lttng_metadata_cache_dump(stream
);
1482 case LTTNG_KERNEL_ABI_RING_BUFFER_GET_NEXT_SUBBUF_METADATA_CHECK
:
1484 struct lttng_metadata_stream
*stream
= filp
->private_data
;
1485 struct lttng_kernel_ring_buffer
*buf
= stream
->priv
;
1486 struct lttng_kernel_ring_buffer_channel
*chan
= buf
->backend
.chan
;
1488 ret
= lttng_metadata_output_channel(stream
, chan
, &coherent
);
1490 lib_ring_buffer_switch_slow(buf
, SWITCH_ACTIVE
);
1492 } else if (ret
< 0) {
1500 /* PUT_SUBBUF is the one from lib ring buffer, unmodified. */
1502 /* Performing lib ring buffer ioctl after our own. */
1503 ret
= lib_ring_buffer_compat_ioctl(filp
, rb_cmd
, arg
, buf
);
1508 case LTTNG_KERNEL_ABI_RING_BUFFER_PUT_NEXT_SUBBUF
:
1510 lttng_metadata_ring_buffer_ioctl_put_next_subbuf(filp
,
1514 case LTTNG_KERNEL_ABI_RING_BUFFER_GET_NEXT_SUBBUF_METADATA_CHECK
:
1516 return put_u32(coherent
, arg
);
1527 * This is not used by anonymous file descriptors. This code is left
1528 * there if we ever want to implement an inode with open() operation.
1531 int lttng_metadata_ring_buffer_open(struct inode
*inode
, struct file
*file
)
1533 struct lttng_metadata_stream
*stream
= inode
->i_private
;
1534 struct lttng_kernel_ring_buffer
*buf
= stream
->priv
;
1536 file
->private_data
= buf
;
1538 * Since life-time of metadata cache differs from that of
1539 * session, we need to keep our own reference on the transport.
1541 if (!try_module_get(stream
->transport
->owner
)) {
1542 printk(KERN_WARNING
"LTTng: Can't lock transport module.\n");
1545 return lib_ring_buffer_open(inode
, file
, buf
);
1549 int lttng_metadata_ring_buffer_release(struct inode
*inode
, struct file
*file
)
1551 struct lttng_metadata_stream
*stream
= file
->private_data
;
1552 struct lttng_kernel_ring_buffer
*buf
= stream
->priv
;
1554 mutex_lock(&stream
->metadata_cache
->lock
);
1555 list_del(&stream
->list
);
1556 mutex_unlock(&stream
->metadata_cache
->lock
);
1557 kref_put(&stream
->metadata_cache
->refcount
, metadata_cache_destroy
);
1558 module_put(stream
->transport
->owner
);
1560 return lib_ring_buffer_release(inode
, file
, buf
);
1564 ssize_t
lttng_metadata_ring_buffer_splice_read(struct file
*in
, loff_t
*ppos
,
1565 struct pipe_inode_info
*pipe
, size_t len
,
1568 struct lttng_metadata_stream
*stream
= in
->private_data
;
1569 struct lttng_kernel_ring_buffer
*buf
= stream
->priv
;
1571 return lib_ring_buffer_splice_read(in
, ppos
, pipe
, len
,
1576 int lttng_metadata_ring_buffer_mmap(struct file
*filp
,
1577 struct vm_area_struct
*vma
)
1579 struct lttng_metadata_stream
*stream
= filp
->private_data
;
1580 struct lttng_kernel_ring_buffer
*buf
= stream
->priv
;
1582 return lib_ring_buffer_mmap(filp
, vma
, buf
);
1586 const struct file_operations lttng_metadata_ring_buffer_file_operations
= {
1587 .owner
= THIS_MODULE
,
1588 .open
= lttng_metadata_ring_buffer_open
,
1589 .release
= lttng_metadata_ring_buffer_release
,
1590 .poll
= lttng_metadata_ring_buffer_poll
,
1591 .splice_read
= lttng_metadata_ring_buffer_splice_read
,
1592 .mmap
= lttng_metadata_ring_buffer_mmap
,
1593 .unlocked_ioctl
= lttng_metadata_ring_buffer_ioctl
,
1594 .llseek
= vfs_lib_ring_buffer_no_llseek
,
1595 #ifdef CONFIG_COMPAT
1596 .compat_ioctl
= lttng_metadata_ring_buffer_compat_ioctl
,
1601 int lttng_abi_create_stream_fd(struct file
*channel_file
, void *stream_priv
,
1602 const struct file_operations
*fops
, const char *name
)
1605 struct file
*stream_file
;
1607 stream_fd
= lttng_get_unused_fd();
1608 if (stream_fd
< 0) {
1612 stream_file
= anon_inode_getfile(name
, fops
, stream_priv
, O_RDWR
);
1613 if (IS_ERR(stream_file
)) {
1614 ret
= PTR_ERR(stream_file
);
1618 * OPEN_FMODE, called within anon_inode_getfile/alloc_file, don't honor
1619 * FMODE_LSEEK, FMODE_PREAD nor FMODE_PWRITE. We need to read from this
1620 * file descriptor, so we set FMODE_PREAD here.
1622 stream_file
->f_mode
|= FMODE_PREAD
;
1623 fd_install(stream_fd
, stream_file
);
1625 * The stream holds a reference to the channel within the generic ring
1626 * buffer library, so no need to hold a refcount on the channel and
1627 * session files here.
1632 put_unused_fd(stream_fd
);
1638 int lttng_abi_open_stream(struct file
*channel_file
)
1640 struct lttng_kernel_channel_buffer
*channel
= channel_file
->private_data
;
1641 struct lttng_kernel_ring_buffer
*buf
;
1645 buf
= channel
->ops
->priv
->buffer_read_open(channel
->priv
->rb_chan
);
1650 ret
= lttng_abi_create_stream_fd(channel_file
, stream_priv
,
1651 <tng_stream_ring_buffer_file_operations
,
1659 channel
->ops
->priv
->buffer_read_close(buf
);
1664 int lttng_abi_open_metadata_stream(struct file
*channel_file
)
1666 struct lttng_kernel_channel_buffer
*channel
= channel_file
->private_data
;
1667 struct lttng_kernel_session
*session
= channel
->parent
.session
;
1668 struct lttng_kernel_ring_buffer
*buf
;
1670 struct lttng_metadata_stream
*metadata_stream
;
1673 buf
= channel
->ops
->priv
->buffer_read_open(channel
->priv
->rb_chan
);
1677 metadata_stream
= kzalloc(sizeof(struct lttng_metadata_stream
),
1679 if (!metadata_stream
) {
1683 metadata_stream
->metadata_cache
= session
->priv
->metadata_cache
;
1684 init_waitqueue_head(&metadata_stream
->read_wait
);
1685 metadata_stream
->priv
= buf
;
1686 stream_priv
= metadata_stream
;
1687 metadata_stream
->transport
= channel
->priv
->transport
;
1688 /* Initial state is an empty metadata, considered as incoherent. */
1689 metadata_stream
->coherent
= false;
1692 * Since life-time of metadata cache differs from that of
1693 * session, we need to keep our own reference on the transport.
1695 if (!try_module_get(metadata_stream
->transport
->owner
)) {
1696 printk(KERN_WARNING
"LTTng: Can't lock transport module.\n");
1701 if (!lttng_kref_get(&session
->priv
->metadata_cache
->refcount
)) {
1706 ret
= lttng_abi_create_stream_fd(channel_file
, stream_priv
,
1707 <tng_metadata_ring_buffer_file_operations
,
1708 "[lttng_metadata_stream]");
1712 mutex_lock(&session
->priv
->metadata_cache
->lock
);
1713 list_add(&metadata_stream
->list
,
1714 &session
->priv
->metadata_cache
->metadata_stream
);
1715 mutex_unlock(&session
->priv
->metadata_cache
->lock
);
1719 kref_put(&session
->priv
->metadata_cache
->refcount
, metadata_cache_destroy
);
1721 module_put(metadata_stream
->transport
->owner
);
1723 kfree(metadata_stream
);
1725 channel
->ops
->priv
->buffer_read_close(buf
);
1730 int lttng_abi_open_event_notifier_group_stream(struct file
*notif_file
)
1732 struct lttng_event_notifier_group
*event_notifier_group
= notif_file
->private_data
;
1733 struct lttng_kernel_ring_buffer_channel
*chan
= event_notifier_group
->chan
;
1734 struct lttng_kernel_ring_buffer
*buf
;
1738 buf
= event_notifier_group
->ops
->priv
->buffer_read_open(chan
);
1742 /* The event_notifier notification fd holds a reference on the event_notifier group */
1743 if (!atomic_long_add_unless(¬if_file
->f_count
, 1, LONG_MAX
)) {
1745 goto refcount_error
;
1747 event_notifier_group
->buf
= buf
;
1748 stream_priv
= event_notifier_group
;
1749 ret
= lttng_abi_create_stream_fd(notif_file
, stream_priv
,
1750 <tng_event_notifier_group_notif_fops
,
1751 "[lttng_event_notifier_stream]");
1758 atomic_long_dec(¬if_file
->f_count
);
1760 event_notifier_group
->ops
->priv
->buffer_read_close(buf
);
1765 int lttng_abi_validate_event_param(struct lttng_kernel_abi_event
*event_param
)
1767 /* Limit ABI to implemented features. */
1768 switch (event_param
->instrumentation
) {
1769 case LTTNG_KERNEL_ABI_SYSCALL
:
1770 switch (event_param
->u
.syscall
.entryexit
) {
1771 case LTTNG_KERNEL_ABI_SYSCALL_ENTRY
:
1773 case LTTNG_KERNEL_ABI_SYSCALL_EXIT
:
1775 case LTTNG_KERNEL_ABI_SYSCALL_ENTRYEXIT
:
1780 switch (event_param
->u
.syscall
.abi
) {
1781 case LTTNG_KERNEL_ABI_SYSCALL_ABI_ALL
:
1786 switch (event_param
->u
.syscall
.match
) {
1787 case LTTNG_KERNEL_ABI_SYSCALL_MATCH_NAME
:
1794 case LTTNG_KERNEL_ABI_KRETPROBE
:
1795 switch (event_param
->u
.kretprobe
.entryexit
) {
1796 case LTTNG_KERNEL_ABI_SYSCALL_ENTRYEXIT
:
1798 case LTTNG_KERNEL_ABI_SYSCALL_ENTRY
:
1800 case LTTNG_KERNEL_ABI_SYSCALL_EXIT
:
1807 case LTTNG_KERNEL_ABI_TRACEPOINT
:
1809 case LTTNG_KERNEL_ABI_KPROBE
:
1811 case LTTNG_KERNEL_ABI_UPROBE
:
1814 case LTTNG_KERNEL_ABI_FUNCTION
:
1816 case LTTNG_KERNEL_ABI_NOOP
:
1825 int lttng_abi_create_event(struct file
*channel_file
,
1826 struct lttng_kernel_abi_event
*event_param
)
1828 const struct file_operations
*fops
;
1829 struct lttng_kernel_channel_buffer
*channel
= channel_file
->private_data
;
1831 struct file
*event_file
;
1834 event_param
->name
[LTTNG_KERNEL_ABI_SYM_NAME_LEN
- 1] = '\0';
1835 switch (event_param
->instrumentation
) {
1836 case LTTNG_KERNEL_ABI_KRETPROBE
:
1837 event_param
->u
.kretprobe
.symbol_name
[LTTNG_KERNEL_ABI_SYM_NAME_LEN
- 1] = '\0';
1839 case LTTNG_KERNEL_ABI_KPROBE
:
1840 event_param
->u
.kprobe
.symbol_name
[LTTNG_KERNEL_ABI_SYM_NAME_LEN
- 1] = '\0';
1842 case LTTNG_KERNEL_ABI_FUNCTION
:
1844 /* Not implemented. */
1850 switch (event_param
->instrumentation
) {
1851 case LTTNG_KERNEL_ABI_TRACEPOINT
:
1853 case LTTNG_KERNEL_ABI_SYSCALL
:
1854 fops
= <tng_event_recorder_enabler_fops
;
1856 case LTTNG_KERNEL_ABI_KPROBE
:
1858 case LTTNG_KERNEL_ABI_KRETPROBE
:
1860 case LTTNG_KERNEL_ABI_UPROBE
:
1861 fops
= <tng_event_recorder_event_fops
;
1864 case LTTNG_KERNEL_ABI_FUNCTION
:
1866 case LTTNG_KERNEL_ABI_NOOP
:
1872 event_fd
= lttng_get_unused_fd();
1877 event_file
= anon_inode_getfile("[lttng_event]",
1878 fops
, NULL
, O_RDWR
);
1879 if (IS_ERR(event_file
)) {
1880 ret
= PTR_ERR(event_file
);
1883 /* The event holds a reference on the channel */
1884 if (!atomic_long_add_unless(&channel_file
->f_count
, 1, LONG_MAX
)) {
1886 goto refcount_error
;
1888 ret
= lttng_abi_validate_event_param(event_param
);
1892 switch (event_param
->instrumentation
) {
1893 case LTTNG_KERNEL_ABI_TRACEPOINT
:
1895 case LTTNG_KERNEL_ABI_SYSCALL
:
1897 struct lttng_event_enabler
*event_enabler
;
1899 if (strutils_is_star_glob_pattern(event_param
->name
)) {
1901 * If the event name is a star globbing pattern,
1902 * we create the special star globbing enabler.
1904 event_enabler
= lttng_event_enabler_create(LTTNG_ENABLER_FORMAT_STAR_GLOB
,
1905 event_param
, channel
);
1907 event_enabler
= lttng_event_enabler_create(LTTNG_ENABLER_FORMAT_NAME
,
1908 event_param
, channel
);
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_recorder
*event
;
1923 * We tolerate no failure path after event creation. It
1924 * will stay invariant for the rest of the session.
1926 event
= lttng_kernel_event_recorder_create(channel
, event_param
,
1927 NULL
, event_param
->instrumentation
);
1928 WARN_ON_ONCE(!event
);
1929 if (IS_ERR(event
)) {
1930 ret
= PTR_ERR(event
);
1937 case LTTNG_KERNEL_ABI_FUNCTION
:
1939 case LTTNG_KERNEL_ABI_NOOP
:
1945 event_file
->private_data
= priv
;
1946 fd_install(event_fd
, event_file
);
1950 atomic_long_dec(&channel_file
->f_count
);
1954 put_unused_fd(event_fd
);
1960 long lttng_event_notifier_event_ioctl(struct file
*file
, unsigned int cmd
, unsigned long arg
)
1962 struct lttng_kernel_event_notifier
*event_notifier
= file
->private_data
;
1965 case LTTNG_KERNEL_ABI_ENABLE
:
1966 return lttng_event_enable(&event_notifier
->parent
);
1967 case LTTNG_KERNEL_ABI_DISABLE
:
1968 return lttng_event_disable(&event_notifier
->parent
);
1969 case LTTNG_KERNEL_ABI_FILTER
:
1971 case LTTNG_KERNEL_ABI_CAPTURE
:
1973 case LTTNG_KERNEL_ABI_ADD_CALLSITE
:
1974 return lttng_event_add_callsite(&event_notifier
->parent
,
1975 (struct lttng_kernel_abi_event_callsite __user
*) arg
);
1977 return -ENOIOCTLCMD
;
1982 long lttng_event_notifier_enabler_ioctl(struct file
*file
, unsigned int cmd
, unsigned long arg
)
1984 struct lttng_event_notifier_enabler
*event_notifier_enabler
= file
->private_data
;
1987 case LTTNG_KERNEL_ABI_ENABLE
:
1988 return lttng_event_notifier_enabler_enable(event_notifier_enabler
);
1989 case LTTNG_KERNEL_ABI_DISABLE
:
1990 return lttng_event_notifier_enabler_disable(event_notifier_enabler
);
1991 case LTTNG_KERNEL_ABI_FILTER
:
1992 return lttng_event_notifier_enabler_attach_filter_bytecode(
1993 event_notifier_enabler
,
1994 (struct lttng_kernel_abi_filter_bytecode __user
*) arg
);
1995 case LTTNG_KERNEL_ABI_CAPTURE
:
1996 return lttng_event_notifier_enabler_attach_capture_bytecode(
1997 event_notifier_enabler
,
1998 (struct lttng_kernel_abi_capture_bytecode __user
*) arg
);
1999 case LTTNG_KERNEL_ABI_ADD_CALLSITE
:
2002 return -ENOIOCTLCMD
;
2007 int lttng_event_notifier_event_release(struct inode
*inode
, struct file
*file
)
2009 struct lttng_kernel_event_notifier
*event_notifier
= file
->private_data
;
2012 fput(event_notifier
->priv
->group
->file
);
2017 int lttng_event_notifier_enabler_release(struct inode
*inode
, struct file
*file
)
2019 struct lttng_event_notifier_enabler
*event_notifier_enabler
= file
->private_data
;
2021 if (event_notifier_enabler
)
2022 fput(event_notifier_enabler
->group
->file
);
2026 static const struct file_operations lttng_event_notifier_event_fops
= {
2027 .owner
= THIS_MODULE
,
2028 .release
= lttng_event_notifier_event_release
,
2029 .unlocked_ioctl
= lttng_event_notifier_event_ioctl
,
2030 #ifdef CONFIG_COMPAT
2031 .compat_ioctl
= lttng_event_notifier_event_ioctl
,
2035 static const struct file_operations lttng_event_notifier_enabler_fops
= {
2036 .owner
= THIS_MODULE
,
2037 .release
= lttng_event_notifier_enabler_release
,
2038 .unlocked_ioctl
= lttng_event_notifier_enabler_ioctl
,
2039 #ifdef CONFIG_COMPAT
2040 .compat_ioctl
= lttng_event_notifier_enabler_ioctl
,
2045 int lttng_abi_create_event_notifier(struct file
*event_notifier_group_file
,
2046 struct lttng_kernel_abi_event_notifier
*event_notifier_param
)
2048 struct lttng_event_notifier_group
*event_notifier_group
=
2049 event_notifier_group_file
->private_data
;
2050 const struct file_operations
*fops
;
2051 int event_notifier_fd
, ret
;
2052 struct file
*event_notifier_file
;
2055 switch (event_notifier_param
->event
.instrumentation
) {
2056 case LTTNG_KERNEL_ABI_TRACEPOINT
:
2057 case LTTNG_KERNEL_ABI_UPROBE
:
2059 case LTTNG_KERNEL_ABI_KPROBE
:
2060 event_notifier_param
->event
.u
.kprobe
.symbol_name
[LTTNG_KERNEL_ABI_SYM_NAME_LEN
- 1] = '\0';
2062 case LTTNG_KERNEL_ABI_SYSCALL
:
2064 case LTTNG_KERNEL_ABI_KRETPROBE
:
2065 /* Placing an event notifier on kretprobe is not supported. */
2066 case LTTNG_KERNEL_ABI_FUNCTION
:
2067 case LTTNG_KERNEL_ABI_NOOP
:
2073 switch (event_notifier_param
->event
.instrumentation
) {
2074 case LTTNG_KERNEL_ABI_TRACEPOINT
:
2076 case LTTNG_KERNEL_ABI_SYSCALL
:
2077 fops
= <tng_event_notifier_enabler_fops
;
2079 case LTTNG_KERNEL_ABI_KPROBE
:
2081 case LTTNG_KERNEL_ABI_KRETPROBE
:
2083 case LTTNG_KERNEL_ABI_UPROBE
:
2084 fops
= <tng_event_notifier_event_fops
;
2087 case LTTNG_KERNEL_ABI_FUNCTION
:
2089 case LTTNG_KERNEL_ABI_NOOP
:
2096 event_notifier_param
->event
.name
[LTTNG_KERNEL_ABI_SYM_NAME_LEN
- 1] = '\0';
2098 event_notifier_fd
= lttng_get_unused_fd();
2099 if (event_notifier_fd
< 0) {
2100 ret
= event_notifier_fd
;
2104 event_notifier_file
= anon_inode_getfile("[lttng_event_notifier]",
2105 fops
, NULL
, O_RDWR
);
2106 if (IS_ERR(event_notifier_file
)) {
2107 ret
= PTR_ERR(event_notifier_file
);
2111 /* The event notifier holds a reference on the event notifier group. */
2112 if (!atomic_long_add_unless(&event_notifier_group_file
->f_count
, 1, LONG_MAX
)) {
2114 goto refcount_error
;
2117 ret
= lttng_abi_validate_event_param(&event_notifier_param
->event
);
2119 goto event_notifier_error
;
2121 switch (event_notifier_param
->event
.instrumentation
) {
2122 case LTTNG_KERNEL_ABI_TRACEPOINT
:
2124 case LTTNG_KERNEL_ABI_SYSCALL
:
2126 struct lttng_event_notifier_enabler
*enabler
;
2128 if (strutils_is_star_glob_pattern(event_notifier_param
->event
.name
)) {
2130 * If the event name is a star globbing pattern,
2131 * we create the special star globbing enabler.
2133 enabler
= lttng_event_notifier_enabler_create(
2134 event_notifier_group
,
2135 LTTNG_ENABLER_FORMAT_STAR_GLOB
,
2136 event_notifier_param
);
2138 enabler
= lttng_event_notifier_enabler_create(
2139 event_notifier_group
,
2140 LTTNG_ENABLER_FORMAT_NAME
,
2141 event_notifier_param
);
2147 case LTTNG_KERNEL_ABI_KPROBE
:
2149 case LTTNG_KERNEL_ABI_KRETPROBE
:
2151 case LTTNG_KERNEL_ABI_UPROBE
:
2153 struct lttng_kernel_event_notifier
*event_notifier
;
2156 * We tolerate no failure path after event notifier creation.
2157 * It will stay invariant for the rest of the session.
2159 event_notifier
= lttng_event_notifier_create(NULL
,
2160 event_notifier_param
->event
.token
,
2161 event_notifier_param
->error_counter_index
,
2162 event_notifier_group
,
2163 event_notifier_param
,
2164 event_notifier_param
->event
.instrumentation
);
2165 WARN_ON_ONCE(!event_notifier
);
2166 if (IS_ERR(event_notifier
)) {
2167 ret
= PTR_ERR(event_notifier
);
2168 goto event_notifier_error
;
2170 priv
= event_notifier
;
2174 case LTTNG_KERNEL_ABI_FUNCTION
:
2176 case LTTNG_KERNEL_ABI_NOOP
:
2180 goto event_notifier_error
;
2182 event_notifier_file
->private_data
= priv
;
2183 fd_install(event_notifier_fd
, event_notifier_file
);
2184 return event_notifier_fd
;
2186 event_notifier_error
:
2187 atomic_long_dec(&event_notifier_group_file
->f_count
);
2189 fput(event_notifier_file
);
2191 put_unused_fd(event_notifier_fd
);
2198 long lttng_abi_event_notifier_group_create_error_counter(
2199 struct file
*event_notifier_group_file
,
2200 const struct lttng_kernel_abi_counter_conf
*error_counter_conf
)
2202 int counter_fd
, ret
;
2203 char *counter_transport_name
;
2205 struct lttng_counter
*counter
= NULL
;
2206 struct file
*counter_file
;
2207 struct lttng_event_notifier_group
*event_notifier_group
=
2208 (struct lttng_event_notifier_group
*) event_notifier_group_file
->private_data
;
2210 if (error_counter_conf
->arithmetic
!= LTTNG_KERNEL_ABI_COUNTER_ARITHMETIC_MODULAR
) {
2211 printk(KERN_ERR
"LTTng: event_notifier: Error counter of the wrong arithmetic type.\n");
2215 if (error_counter_conf
->number_dimensions
!= 1) {
2216 printk(KERN_ERR
"LTTng: event_notifier: Error counter has more than one dimension.\n");
2220 switch (error_counter_conf
->bitness
) {
2221 case LTTNG_KERNEL_ABI_COUNTER_BITNESS_64
:
2222 counter_transport_name
= "counter-per-cpu-64-modular";
2224 case LTTNG_KERNEL_ABI_COUNTER_BITNESS_32
:
2225 counter_transport_name
= "counter-per-cpu-32-modular";
2232 * Lock sessions to provide mutual exclusion against concurrent
2233 * modification of event_notifier group, which would result in
2234 * overwriting the error counter if set concurrently.
2236 lttng_lock_sessions();
2238 if (event_notifier_group
->error_counter
) {
2239 printk(KERN_ERR
"Error counter already created in event_notifier group\n");
2244 counter_fd
= lttng_get_unused_fd();
2245 if (counter_fd
< 0) {
2250 counter_file
= anon_inode_getfile("[lttng_counter]",
2251 <tng_counter_fops
,
2253 if (IS_ERR(counter_file
)) {
2254 ret
= PTR_ERR(counter_file
);
2258 counter_len
= error_counter_conf
->dimensions
[0].size
;
2260 if (!atomic_long_add_unless(&event_notifier_group_file
->f_count
, 1, LONG_MAX
)) {
2262 goto refcount_error
;
2265 counter
= lttng_kernel_counter_create(counter_transport_name
,
2272 event_notifier_group
->error_counter_len
= counter_len
;
2274 * store-release to publish error counter matches load-acquire
2275 * in record_error. Ensures the counter is created and the
2276 * error_counter_len is set before they are used.
2278 lttng_smp_store_release(&event_notifier_group
->error_counter
, counter
);
2280 counter
->file
= counter_file
;
2281 counter
->owner
= event_notifier_group
->file
;
2282 counter_file
->private_data
= counter
;
2283 /* Ownership transferred. */
2286 fd_install(counter_fd
, counter_file
);
2287 lttng_unlock_sessions();
2292 atomic_long_dec(&event_notifier_group_file
->f_count
);
2296 put_unused_fd(counter_fd
);
2298 lttng_unlock_sessions();
2303 long lttng_event_notifier_group_ioctl(struct file
*file
, unsigned int cmd
,
2307 case LTTNG_KERNEL_ABI_EVENT_NOTIFIER_GROUP_NOTIFICATION_FD
:
2309 return lttng_abi_open_event_notifier_group_stream(file
);
2311 case LTTNG_KERNEL_ABI_EVENT_NOTIFIER_CREATE
:
2313 struct lttng_kernel_abi_event_notifier uevent_notifier_param
;
2315 if (copy_from_user(&uevent_notifier_param
,
2316 (struct lttng_kernel_abi_event_notifier __user
*) arg
,
2317 sizeof(uevent_notifier_param
)))
2319 return lttng_abi_create_event_notifier(file
, &uevent_notifier_param
);
2321 case LTTNG_KERNEL_ABI_COUNTER
:
2323 struct lttng_kernel_abi_counter_conf uerror_counter_conf
;
2325 if (copy_from_user(&uerror_counter_conf
,
2326 (struct lttng_kernel_abi_counter_conf __user
*) arg
,
2327 sizeof(uerror_counter_conf
)))
2329 return lttng_abi_event_notifier_group_create_error_counter(file
,
2330 &uerror_counter_conf
);
2333 return -ENOIOCTLCMD
;
2339 int lttng_event_notifier_group_release(struct inode
*inode
, struct file
*file
)
2341 struct lttng_event_notifier_group
*event_notifier_group
=
2344 if (event_notifier_group
)
2345 lttng_event_notifier_group_destroy(event_notifier_group
);
2349 static const struct file_operations lttng_event_notifier_group_fops
= {
2350 .owner
= THIS_MODULE
,
2351 .release
= lttng_event_notifier_group_release
,
2352 .unlocked_ioctl
= lttng_event_notifier_group_ioctl
,
2353 #ifdef CONFIG_COMPAT
2354 .compat_ioctl
= lttng_event_notifier_group_ioctl
,
2359 * lttng_channel_ioctl - lttng syscall through ioctl
2365 * This ioctl implements lttng commands:
2366 * LTTNG_KERNEL_ABI_STREAM
2367 * Returns an event stream file descriptor or failure.
2368 * (typically, one event stream records events from one CPU)
2369 * LTTNG_KERNEL_ABI_EVENT
2370 * Returns an event file descriptor or failure.
2371 * LTTNG_KERNEL_ABI_CONTEXT
2372 * Prepend a context field to each event in the channel
2373 * LTTNG_KERNEL_ABI_ENABLE
2374 * Enable recording for events in this channel (weak enable)
2375 * LTTNG_KERNEL_ABI_DISABLE
2376 * Disable recording for events in this channel (strong disable)
2378 * Channel and event file descriptors also hold a reference on the session.
2381 long lttng_channel_ioctl(struct file
*file
, unsigned int cmd
, unsigned long arg
)
2383 struct lttng_kernel_channel_buffer
*channel
= file
->private_data
;
2386 case LTTNG_KERNEL_ABI_OLD_STREAM
:
2387 case LTTNG_KERNEL_ABI_STREAM
:
2388 return lttng_abi_open_stream(file
);
2389 case LTTNG_KERNEL_ABI_OLD_EVENT
:
2391 struct lttng_kernel_abi_event
*uevent_param
;
2392 struct lttng_kernel_abi_old_event
*old_uevent_param
;
2395 uevent_param
= kmalloc(sizeof(struct lttng_kernel_abi_event
),
2397 if (!uevent_param
) {
2401 old_uevent_param
= kmalloc(
2402 sizeof(struct lttng_kernel_abi_old_event
),
2404 if (!old_uevent_param
) {
2406 goto old_event_error_free_param
;
2408 if (copy_from_user(old_uevent_param
,
2409 (struct lttng_kernel_abi_old_event __user
*) arg
,
2410 sizeof(struct lttng_kernel_abi_old_event
))) {
2412 goto old_event_error_free_old_param
;
2415 memcpy(uevent_param
->name
, old_uevent_param
->name
,
2416 sizeof(uevent_param
->name
));
2417 uevent_param
->instrumentation
=
2418 old_uevent_param
->instrumentation
;
2420 switch (old_uevent_param
->instrumentation
) {
2421 case LTTNG_KERNEL_ABI_KPROBE
:
2422 uevent_param
->u
.kprobe
.addr
=
2423 old_uevent_param
->u
.kprobe
.addr
;
2424 uevent_param
->u
.kprobe
.offset
=
2425 old_uevent_param
->u
.kprobe
.offset
;
2426 memcpy(uevent_param
->u
.kprobe
.symbol_name
,
2427 old_uevent_param
->u
.kprobe
.symbol_name
,
2428 sizeof(uevent_param
->u
.kprobe
.symbol_name
));
2430 case LTTNG_KERNEL_ABI_KRETPROBE
:
2431 uevent_param
->u
.kretprobe
.addr
=
2432 old_uevent_param
->u
.kretprobe
.addr
;
2433 uevent_param
->u
.kretprobe
.offset
=
2434 old_uevent_param
->u
.kretprobe
.offset
;
2435 memcpy(uevent_param
->u
.kretprobe
.symbol_name
,
2436 old_uevent_param
->u
.kretprobe
.symbol_name
,
2437 sizeof(uevent_param
->u
.kretprobe
.symbol_name
));
2439 case LTTNG_KERNEL_ABI_FUNCTION
:
2441 /* Not implemented. */
2446 ret
= lttng_abi_create_event(file
, uevent_param
);
2448 old_event_error_free_old_param
:
2449 kfree(old_uevent_param
);
2450 old_event_error_free_param
:
2451 kfree(uevent_param
);
2455 case LTTNG_KERNEL_ABI_EVENT
:
2457 struct lttng_kernel_abi_event uevent_param
;
2459 if (copy_from_user(&uevent_param
,
2460 (struct lttng_kernel_abi_event __user
*) arg
,
2461 sizeof(uevent_param
)))
2463 return lttng_abi_create_event(file
, &uevent_param
);
2465 case LTTNG_KERNEL_ABI_OLD_CONTEXT
:
2467 struct lttng_kernel_abi_context
*ucontext_param
;
2468 struct lttng_kernel_abi_old_context
*old_ucontext_param
;
2471 ucontext_param
= kmalloc(sizeof(struct lttng_kernel_abi_context
),
2473 if (!ucontext_param
) {
2477 old_ucontext_param
= kmalloc(sizeof(struct lttng_kernel_abi_old_context
),
2479 if (!old_ucontext_param
) {
2481 goto old_ctx_error_free_param
;
2484 if (copy_from_user(old_ucontext_param
,
2485 (struct lttng_kernel_abi_old_context __user
*) arg
,
2486 sizeof(struct lttng_kernel_abi_old_context
))) {
2488 goto old_ctx_error_free_old_param
;
2490 ucontext_param
->ctx
= old_ucontext_param
->ctx
;
2491 memcpy(ucontext_param
->padding
, old_ucontext_param
->padding
,
2492 sizeof(ucontext_param
->padding
));
2493 /* only type that uses the union */
2494 if (old_ucontext_param
->ctx
== LTTNG_KERNEL_ABI_CONTEXT_PERF_COUNTER
) {
2495 ucontext_param
->u
.perf_counter
.type
=
2496 old_ucontext_param
->u
.perf_counter
.type
;
2497 ucontext_param
->u
.perf_counter
.config
=
2498 old_ucontext_param
->u
.perf_counter
.config
;
2499 memcpy(ucontext_param
->u
.perf_counter
.name
,
2500 old_ucontext_param
->u
.perf_counter
.name
,
2501 sizeof(ucontext_param
->u
.perf_counter
.name
));
2504 ret
= lttng_abi_add_context(file
,
2506 &channel
->priv
->ctx
, channel
->parent
.session
);
2508 old_ctx_error_free_old_param
:
2509 kfree(old_ucontext_param
);
2510 old_ctx_error_free_param
:
2511 kfree(ucontext_param
);
2515 case LTTNG_KERNEL_ABI_CONTEXT
:
2517 struct lttng_kernel_abi_context ucontext_param
;
2519 if (copy_from_user(&ucontext_param
,
2520 (struct lttng_kernel_abi_context __user
*) arg
,
2521 sizeof(ucontext_param
)))
2523 return lttng_abi_add_context(file
,
2525 &channel
->priv
->ctx
, channel
->parent
.session
);
2527 case LTTNG_KERNEL_ABI_OLD_ENABLE
:
2528 case LTTNG_KERNEL_ABI_ENABLE
:
2529 return lttng_channel_enable(channel
);
2530 case LTTNG_KERNEL_ABI_OLD_DISABLE
:
2531 case LTTNG_KERNEL_ABI_DISABLE
:
2532 return lttng_channel_disable(channel
);
2533 case LTTNG_KERNEL_ABI_SYSCALL_MASK
:
2534 return lttng_channel_syscall_mask(channel
,
2535 (struct lttng_kernel_abi_syscall_mask __user
*) arg
);
2537 return -ENOIOCTLCMD
;
2542 * lttng_metadata_ioctl - lttng syscall through ioctl
2548 * This ioctl implements lttng commands:
2549 * LTTNG_KERNEL_ABI_STREAM
2550 * Returns an event stream file descriptor or failure.
2552 * Channel and event file descriptors also hold a reference on the session.
2555 long lttng_metadata_ioctl(struct file
*file
, unsigned int cmd
, unsigned long arg
)
2558 case LTTNG_KERNEL_ABI_OLD_STREAM
:
2559 case LTTNG_KERNEL_ABI_STREAM
:
2560 return lttng_abi_open_metadata_stream(file
);
2562 return -ENOIOCTLCMD
;
2567 * lttng_channel_poll - lttng stream addition/removal monitoring
2573 unsigned int lttng_channel_poll(struct file
*file
, poll_table
*wait
)
2575 struct lttng_kernel_channel_buffer
*channel
= file
->private_data
;
2576 unsigned int mask
= 0;
2578 if (file
->f_mode
& FMODE_READ
) {
2579 poll_wait_set_exclusive(wait
);
2580 poll_wait(file
, channel
->ops
->priv
->get_hp_wait_queue(channel
->priv
->rb_chan
),
2583 if (channel
->ops
->priv
->is_disabled(channel
->priv
->rb_chan
))
2585 if (channel
->ops
->priv
->is_finalized(channel
->priv
->rb_chan
))
2587 if (channel
->ops
->priv
->buffer_has_read_closed_stream(channel
->priv
->rb_chan
))
2588 return POLLIN
| POLLRDNORM
;
2596 int lttng_channel_release(struct inode
*inode
, struct file
*file
)
2598 struct lttng_kernel_channel_buffer
*channel
= file
->private_data
;
2601 fput(channel
->parent
.session
->priv
->file
);
2606 int lttng_metadata_channel_release(struct inode
*inode
, struct file
*file
)
2608 struct lttng_kernel_channel_buffer
*channel
= file
->private_data
;
2611 fput(channel
->parent
.session
->priv
->file
);
2612 lttng_metadata_channel_destroy(channel
);
2618 static const struct file_operations lttng_channel_fops
= {
2619 .owner
= THIS_MODULE
,
2620 .release
= lttng_channel_release
,
2621 .poll
= lttng_channel_poll
,
2622 .unlocked_ioctl
= lttng_channel_ioctl
,
2623 #ifdef CONFIG_COMPAT
2624 .compat_ioctl
= lttng_channel_ioctl
,
2628 static const struct file_operations lttng_metadata_fops
= {
2629 .owner
= THIS_MODULE
,
2630 .release
= lttng_metadata_channel_release
,
2631 .unlocked_ioctl
= lttng_metadata_ioctl
,
2632 #ifdef CONFIG_COMPAT
2633 .compat_ioctl
= lttng_metadata_ioctl
,
2638 * lttng_event_recorder_event_ioctl - lttng syscall through ioctl
2644 * This ioctl implements lttng commands:
2645 * LTTNG_KERNEL_ABI_CONTEXT
2646 * Prepend a context field to each record of this event
2647 * LTTNG_KERNEL_ABI_ENABLE
2648 * Enable recording for this event (weak enable)
2649 * LTTNG_KERNEL_ABI_DISABLE
2650 * Disable recording for this event (strong disable)
2653 long lttng_event_recorder_event_ioctl(struct file
*file
, unsigned int cmd
, unsigned long arg
)
2655 struct lttng_kernel_event_recorder
*event_recorder
= file
->private_data
;
2658 case LTTNG_KERNEL_ABI_OLD_CONTEXT
:
2660 /* Not implemented */
2663 case LTTNG_KERNEL_ABI_CONTEXT
:
2665 /* Not implemented */
2668 case LTTNG_KERNEL_ABI_OLD_ENABLE
:
2669 case LTTNG_KERNEL_ABI_ENABLE
:
2670 return lttng_event_enable(&event_recorder
->parent
);
2671 case LTTNG_KERNEL_ABI_OLD_DISABLE
:
2672 case LTTNG_KERNEL_ABI_DISABLE
:
2673 return lttng_event_disable(&event_recorder
->parent
);
2674 case LTTNG_KERNEL_ABI_FILTER
:
2676 case LTTNG_KERNEL_ABI_ADD_CALLSITE
:
2677 return lttng_event_add_callsite(&event_recorder
->parent
,
2678 (struct lttng_kernel_abi_event_callsite __user
*) arg
);
2680 return -ENOIOCTLCMD
;
2685 * lttng_event_recorder_enabler_ioctl - lttng syscall through ioctl
2691 * This ioctl implements lttng commands:
2692 * LTTNG_KERNEL_ABI_CONTEXT
2693 * Prepend a context field to each record of this event
2694 * LTTNG_KERNEL_ABI_ENABLE
2695 * Enable recording for this event (weak enable)
2696 * LTTNG_KERNEL_ABI_DISABLE
2697 * Disable recording for this event (strong disable)
2700 long lttng_event_recorder_enabler_ioctl(struct file
*file
, unsigned int cmd
, unsigned long arg
)
2702 struct lttng_event_enabler
*event_enabler
= file
->private_data
;
2705 case LTTNG_KERNEL_ABI_OLD_CONTEXT
:
2707 /* Not implemented */
2710 case LTTNG_KERNEL_ABI_CONTEXT
:
2712 /* Not implemented */
2715 case LTTNG_KERNEL_ABI_OLD_ENABLE
:
2716 case LTTNG_KERNEL_ABI_ENABLE
:
2717 return lttng_event_enabler_enable(event_enabler
);
2718 case LTTNG_KERNEL_ABI_OLD_DISABLE
:
2719 case LTTNG_KERNEL_ABI_DISABLE
:
2720 return lttng_event_enabler_disable(event_enabler
);
2721 case LTTNG_KERNEL_ABI_FILTER
:
2722 return lttng_event_enabler_attach_filter_bytecode(
2724 (struct lttng_kernel_abi_filter_bytecode __user
*) arg
);
2725 case LTTNG_KERNEL_ABI_ADD_CALLSITE
:
2728 return -ENOIOCTLCMD
;
2733 int lttng_event_recorder_event_release(struct inode
*inode
, struct file
*file
)
2735 struct lttng_kernel_event_recorder
*event
= file
->private_data
;
2738 fput(event
->chan
->priv
->parent
.file
);
2743 int lttng_event_recorder_enabler_release(struct inode
*inode
, struct file
*file
)
2745 struct lttng_event_enabler
*event_enabler
= file
->private_data
;
2748 fput(event_enabler
->chan
->priv
->parent
.file
);
2752 static const struct file_operations lttng_event_recorder_event_fops
= {
2753 .owner
= THIS_MODULE
,
2754 .release
= lttng_event_recorder_event_release
,
2755 .unlocked_ioctl
= lttng_event_recorder_event_ioctl
,
2756 #ifdef CONFIG_COMPAT
2757 .compat_ioctl
= lttng_event_recorder_event_ioctl
,
2761 static const struct file_operations lttng_event_recorder_enabler_fops
= {
2762 .owner
= THIS_MODULE
,
2763 .release
= lttng_event_recorder_enabler_release
,
2764 .unlocked_ioctl
= lttng_event_recorder_enabler_ioctl
,
2765 #ifdef CONFIG_COMPAT
2766 .compat_ioctl
= lttng_event_recorder_enabler_ioctl
,
2770 static int put_u64(uint64_t val
, unsigned long arg
)
2772 return put_user(val
, (uint64_t __user
*) arg
);
2775 static int put_u32(uint32_t val
, unsigned long arg
)
2777 return put_user(val
, (uint32_t __user
*) arg
);
2780 static long lttng_stream_ring_buffer_ioctl(struct file
*filp
,
2781 unsigned int cmd
, unsigned long arg
)
2783 struct lttng_kernel_ring_buffer
*buf
= filp
->private_data
;
2784 struct lttng_kernel_ring_buffer_channel
*chan
= buf
->backend
.chan
;
2785 const struct lttng_kernel_ring_buffer_config
*config
= &chan
->backend
.config
;
2786 const struct lttng_kernel_channel_buffer_ops
*ops
= chan
->backend
.priv_ops
;
2789 if (atomic_read(&chan
->record_disabled
))
2793 case LTTNG_KERNEL_ABI_RING_BUFFER_GET_TIMESTAMP_BEGIN
:
2797 ret
= ops
->priv
->timestamp_begin(config
, buf
, &ts
);
2800 return put_u64(ts
, arg
);
2802 case LTTNG_KERNEL_ABI_RING_BUFFER_GET_TIMESTAMP_END
:
2806 ret
= ops
->priv
->timestamp_end(config
, buf
, &ts
);
2809 return put_u64(ts
, arg
);
2811 case LTTNG_KERNEL_ABI_RING_BUFFER_GET_EVENTS_DISCARDED
:
2815 ret
= ops
->priv
->events_discarded(config
, buf
, &ed
);
2818 return put_u64(ed
, arg
);
2820 case LTTNG_KERNEL_ABI_RING_BUFFER_GET_CONTENT_SIZE
:
2824 ret
= ops
->priv
->content_size(config
, buf
, &cs
);
2827 return put_u64(cs
, arg
);
2829 case LTTNG_KERNEL_ABI_RING_BUFFER_GET_PACKET_SIZE
:
2833 ret
= ops
->priv
->packet_size(config
, buf
, &ps
);
2836 return put_u64(ps
, arg
);
2838 case LTTNG_KERNEL_ABI_RING_BUFFER_GET_STREAM_ID
:
2842 ret
= ops
->priv
->stream_id(config
, buf
, &si
);
2845 return put_u64(si
, arg
);
2847 case LTTNG_KERNEL_ABI_RING_BUFFER_GET_CURRENT_TIMESTAMP
:
2851 ret
= ops
->priv
->current_timestamp(config
, buf
, &ts
);
2854 return put_u64(ts
, arg
);
2856 case LTTNG_KERNEL_ABI_RING_BUFFER_GET_SEQ_NUM
:
2860 ret
= ops
->priv
->sequence_number(config
, buf
, &seq
);
2863 return put_u64(seq
, arg
);
2865 case LTTNG_KERNEL_ABI_RING_BUFFER_INSTANCE_ID
:
2869 ret
= ops
->priv
->instance_id(config
, buf
, &id
);
2872 return put_u64(id
, arg
);
2875 return lib_ring_buffer_file_operations
.unlocked_ioctl(filp
,
2883 #ifdef CONFIG_COMPAT
2884 static long lttng_stream_ring_buffer_compat_ioctl(struct file
*filp
,
2885 unsigned int cmd
, unsigned long arg
)
2887 struct lttng_kernel_ring_buffer
*buf
= filp
->private_data
;
2888 struct lttng_kernel_ring_buffer_channel
*chan
= buf
->backend
.chan
;
2889 const struct lttng_kernel_ring_buffer_config
*config
= &chan
->backend
.config
;
2890 const struct lttng_kernel_channel_buffer_ops
*ops
= chan
->backend
.priv_ops
;
2893 if (atomic_read(&chan
->record_disabled
))
2897 case LTTNG_KERNEL_ABI_RING_BUFFER_COMPAT_GET_TIMESTAMP_BEGIN
:
2901 ret
= ops
->priv
->timestamp_begin(config
, buf
, &ts
);
2904 return put_u64(ts
, arg
);
2906 case LTTNG_KERNEL_ABI_RING_BUFFER_COMPAT_GET_TIMESTAMP_END
:
2910 ret
= ops
->priv
->timestamp_end(config
, buf
, &ts
);
2913 return put_u64(ts
, arg
);
2915 case LTTNG_KERNEL_ABI_RING_BUFFER_COMPAT_GET_EVENTS_DISCARDED
:
2919 ret
= ops
->priv
->events_discarded(config
, buf
, &ed
);
2922 return put_u64(ed
, arg
);
2924 case LTTNG_KERNEL_ABI_RING_BUFFER_COMPAT_GET_CONTENT_SIZE
:
2928 ret
= ops
->priv
->content_size(config
, buf
, &cs
);
2931 return put_u64(cs
, arg
);
2933 case LTTNG_KERNEL_ABI_RING_BUFFER_COMPAT_GET_PACKET_SIZE
:
2937 ret
= ops
->priv
->packet_size(config
, buf
, &ps
);
2940 return put_u64(ps
, arg
);
2942 case LTTNG_KERNEL_ABI_RING_BUFFER_COMPAT_GET_STREAM_ID
:
2946 ret
= ops
->priv
->stream_id(config
, buf
, &si
);
2949 return put_u64(si
, arg
);
2951 case LTTNG_KERNEL_ABI_RING_BUFFER_GET_CURRENT_TIMESTAMP
:
2955 ret
= ops
->priv
->current_timestamp(config
, buf
, &ts
);
2958 return put_u64(ts
, arg
);
2960 case LTTNG_KERNEL_ABI_RING_BUFFER_COMPAT_GET_SEQ_NUM
:
2964 ret
= ops
->priv
->sequence_number(config
, buf
, &seq
);
2967 return put_u64(seq
, arg
);
2969 case LTTNG_KERNEL_ABI_RING_BUFFER_COMPAT_INSTANCE_ID
:
2973 ret
= ops
->priv
->instance_id(config
, buf
, &id
);
2976 return put_u64(id
, arg
);
2979 return lib_ring_buffer_file_operations
.compat_ioctl(filp
,
2986 #endif /* CONFIG_COMPAT */
2988 static void lttng_stream_override_ring_buffer_fops(void)
2990 lttng_stream_ring_buffer_file_operations
.owner
= THIS_MODULE
;
2991 lttng_stream_ring_buffer_file_operations
.open
=
2992 lib_ring_buffer_file_operations
.open
;
2993 lttng_stream_ring_buffer_file_operations
.release
=
2994 lib_ring_buffer_file_operations
.release
;
2995 lttng_stream_ring_buffer_file_operations
.poll
=
2996 lib_ring_buffer_file_operations
.poll
;
2997 lttng_stream_ring_buffer_file_operations
.splice_read
=
2998 lib_ring_buffer_file_operations
.splice_read
;
2999 lttng_stream_ring_buffer_file_operations
.mmap
=
3000 lib_ring_buffer_file_operations
.mmap
;
3001 lttng_stream_ring_buffer_file_operations
.unlocked_ioctl
=
3002 lttng_stream_ring_buffer_ioctl
;
3003 lttng_stream_ring_buffer_file_operations
.llseek
=
3004 lib_ring_buffer_file_operations
.llseek
;
3005 #ifdef CONFIG_COMPAT
3006 lttng_stream_ring_buffer_file_operations
.compat_ioctl
=
3007 lttng_stream_ring_buffer_compat_ioctl
;
3011 int __init
lttng_abi_init(void)
3015 wrapper_vmalloc_sync_mappings();
3018 ret
= lttng_tp_mempool_init();
3023 lttng_proc_dentry
= proc_create_data("lttng", S_IRUSR
| S_IWUSR
, NULL
,
3024 <tng_proc_ops
, NULL
);
3026 if (!lttng_proc_dentry
) {
3027 printk(KERN_ERR
"LTTng: Error creating control file\n");
3031 lttng_stream_override_ring_buffer_fops();
3035 lttng_tp_mempool_destroy();
3036 lttng_clock_unref();
3040 /* No __exit annotation because used by init error path too. */
3041 void lttng_abi_exit(void)
3043 lttng_tp_mempool_destroy();
3044 lttng_clock_unref();
3045 if (lttng_proc_dentry
)
3046 remove_proc_entry("lttng", NULL
);