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
);
125 void event_notifier_send_notification_work_wakeup(struct irq_work
*entry
)
127 struct lttng_event_notifier_group
*event_notifier_group
=
128 container_of(entry
, struct lttng_event_notifier_group
,
130 wake_up_interruptible(&event_notifier_group
->read_wait
);
134 int lttng_abi_create_event_notifier_group(void)
136 struct lttng_event_notifier_group
*event_notifier_group
;
137 struct file
*event_notifier_group_file
;
138 int event_notifier_group_fd
, ret
;
140 event_notifier_group
= lttng_event_notifier_group_create();
141 if (!event_notifier_group
)
144 event_notifier_group_fd
= lttng_get_unused_fd();
145 if (event_notifier_group_fd
< 0) {
146 ret
= event_notifier_group_fd
;
149 event_notifier_group_file
= anon_inode_getfile("[lttng_event_notifier_group]",
150 <tng_event_notifier_group_fops
,
151 event_notifier_group
, O_RDWR
);
152 if (IS_ERR(event_notifier_group_file
)) {
153 ret
= PTR_ERR(event_notifier_group_file
);
157 event_notifier_group
->file
= event_notifier_group_file
;
158 init_waitqueue_head(&event_notifier_group
->read_wait
);
159 init_irq_work(&event_notifier_group
->wakeup_pending
,
160 event_notifier_send_notification_work_wakeup
);
161 fd_install(event_notifier_group_fd
, event_notifier_group_file
);
162 return event_notifier_group_fd
;
165 put_unused_fd(event_notifier_group_fd
);
167 lttng_event_notifier_group_destroy(event_notifier_group
);
172 int lttng_abi_tracepoint_list(void)
174 struct file
*tracepoint_list_file
;
177 file_fd
= lttng_get_unused_fd();
183 tracepoint_list_file
= anon_inode_getfile("[lttng_tracepoint_list]",
184 <tng_tracepoint_list_fops
,
186 if (IS_ERR(tracepoint_list_file
)) {
187 ret
= PTR_ERR(tracepoint_list_file
);
190 ret
= lttng_tracepoint_list_fops
.open(NULL
, tracepoint_list_file
);
193 fd_install(file_fd
, tracepoint_list_file
);
197 fput(tracepoint_list_file
);
199 put_unused_fd(file_fd
);
204 #ifndef CONFIG_HAVE_SYSCALL_TRACEPOINTS
206 int lttng_abi_syscall_list(void)
212 int lttng_abi_syscall_list(void)
214 struct file
*syscall_list_file
;
217 file_fd
= lttng_get_unused_fd();
223 syscall_list_file
= anon_inode_getfile("[lttng_syscall_list]",
224 <tng_syscall_list_fops
,
226 if (IS_ERR(syscall_list_file
)) {
227 ret
= PTR_ERR(syscall_list_file
);
230 ret
= lttng_syscall_list_fops
.open(NULL
, syscall_list_file
);
233 fd_install(file_fd
, syscall_list_file
);
237 fput(syscall_list_file
);
239 put_unused_fd(file_fd
);
246 void lttng_abi_tracer_version(struct lttng_kernel_abi_tracer_version
*v
)
248 v
->major
= LTTNG_MODULES_MAJOR_VERSION
;
249 v
->minor
= LTTNG_MODULES_MINOR_VERSION
;
250 v
->patchlevel
= LTTNG_MODULES_PATCHLEVEL_VERSION
;
254 void lttng_abi_tracer_abi_version(struct lttng_kernel_abi_tracer_abi_version
*v
)
256 v
->major
= LTTNG_KERNEL_ABI_MAJOR_VERSION
;
257 v
->minor
= LTTNG_KERNEL_ABI_MINOR_VERSION
;
261 long lttng_abi_add_context(struct file
*file
,
262 struct lttng_kernel_abi_context
*context_param
,
263 struct lttng_kernel_ctx
**ctx
, struct lttng_kernel_session
*session
)
266 if (session
->priv
->been_active
)
269 switch (context_param
->ctx
) {
270 case LTTNG_KERNEL_ABI_CONTEXT_PID
:
271 return lttng_add_pid_to_ctx(ctx
);
272 case LTTNG_KERNEL_ABI_CONTEXT_PRIO
:
273 return lttng_add_prio_to_ctx(ctx
);
274 case LTTNG_KERNEL_ABI_CONTEXT_NICE
:
275 return lttng_add_nice_to_ctx(ctx
);
276 case LTTNG_KERNEL_ABI_CONTEXT_VPID
:
277 return lttng_add_vpid_to_ctx(ctx
);
278 case LTTNG_KERNEL_ABI_CONTEXT_TID
:
279 return lttng_add_tid_to_ctx(ctx
);
280 case LTTNG_KERNEL_ABI_CONTEXT_VTID
:
281 return lttng_add_vtid_to_ctx(ctx
);
282 case LTTNG_KERNEL_ABI_CONTEXT_PPID
:
283 return lttng_add_ppid_to_ctx(ctx
);
284 case LTTNG_KERNEL_ABI_CONTEXT_VPPID
:
285 return lttng_add_vppid_to_ctx(ctx
);
286 case LTTNG_KERNEL_ABI_CONTEXT_PERF_COUNTER
:
287 context_param
->u
.perf_counter
.name
[LTTNG_KERNEL_ABI_SYM_NAME_LEN
- 1] = '\0';
288 return lttng_add_perf_counter_to_ctx(context_param
->u
.perf_counter
.type
,
289 context_param
->u
.perf_counter
.config
,
290 context_param
->u
.perf_counter
.name
,
292 case LTTNG_KERNEL_ABI_CONTEXT_PROCNAME
:
293 return lttng_add_procname_to_ctx(ctx
);
294 case LTTNG_KERNEL_ABI_CONTEXT_HOSTNAME
:
295 return lttng_add_hostname_to_ctx(ctx
);
296 case LTTNG_KERNEL_ABI_CONTEXT_CPU_ID
:
297 return lttng_add_cpu_id_to_ctx(ctx
);
298 case LTTNG_KERNEL_ABI_CONTEXT_INTERRUPTIBLE
:
299 return lttng_add_interruptible_to_ctx(ctx
);
300 case LTTNG_KERNEL_ABI_CONTEXT_NEED_RESCHEDULE
:
301 return lttng_add_need_reschedule_to_ctx(ctx
);
302 case LTTNG_KERNEL_ABI_CONTEXT_PREEMPTIBLE
:
303 return lttng_add_preemptible_to_ctx(ctx
);
304 case LTTNG_KERNEL_ABI_CONTEXT_MIGRATABLE
:
305 return lttng_add_migratable_to_ctx(ctx
);
306 case LTTNG_KERNEL_ABI_CONTEXT_CALLSTACK_KERNEL
:
307 case LTTNG_KERNEL_ABI_CONTEXT_CALLSTACK_USER
:
308 return lttng_add_callstack_to_ctx(ctx
, context_param
->ctx
);
309 case LTTNG_KERNEL_ABI_CONTEXT_CGROUP_NS
:
310 return lttng_add_cgroup_ns_to_ctx(ctx
);
311 case LTTNG_KERNEL_ABI_CONTEXT_IPC_NS
:
312 return lttng_add_ipc_ns_to_ctx(ctx
);
313 case LTTNG_KERNEL_ABI_CONTEXT_MNT_NS
:
314 return lttng_add_mnt_ns_to_ctx(ctx
);
315 case LTTNG_KERNEL_ABI_CONTEXT_NET_NS
:
316 return lttng_add_net_ns_to_ctx(ctx
);
317 case LTTNG_KERNEL_ABI_CONTEXT_PID_NS
:
318 return lttng_add_pid_ns_to_ctx(ctx
);
319 case LTTNG_KERNEL_ABI_CONTEXT_USER_NS
:
320 return lttng_add_user_ns_to_ctx(ctx
);
321 case LTTNG_KERNEL_ABI_CONTEXT_UTS_NS
:
322 return lttng_add_uts_ns_to_ctx(ctx
);
323 case LTTNG_KERNEL_ABI_CONTEXT_UID
:
324 return lttng_add_uid_to_ctx(ctx
);
325 case LTTNG_KERNEL_ABI_CONTEXT_EUID
:
326 return lttng_add_euid_to_ctx(ctx
);
327 case LTTNG_KERNEL_ABI_CONTEXT_SUID
:
328 return lttng_add_suid_to_ctx(ctx
);
329 case LTTNG_KERNEL_ABI_CONTEXT_GID
:
330 return lttng_add_gid_to_ctx(ctx
);
331 case LTTNG_KERNEL_ABI_CONTEXT_EGID
:
332 return lttng_add_egid_to_ctx(ctx
);
333 case LTTNG_KERNEL_ABI_CONTEXT_SGID
:
334 return lttng_add_sgid_to_ctx(ctx
);
335 case LTTNG_KERNEL_ABI_CONTEXT_VUID
:
336 return lttng_add_vuid_to_ctx(ctx
);
337 case LTTNG_KERNEL_ABI_CONTEXT_VEUID
:
338 return lttng_add_veuid_to_ctx(ctx
);
339 case LTTNG_KERNEL_ABI_CONTEXT_VSUID
:
340 return lttng_add_vsuid_to_ctx(ctx
);
341 case LTTNG_KERNEL_ABI_CONTEXT_VGID
:
342 return lttng_add_vgid_to_ctx(ctx
);
343 case LTTNG_KERNEL_ABI_CONTEXT_VEGID
:
344 return lttng_add_vegid_to_ctx(ctx
);
345 case LTTNG_KERNEL_ABI_CONTEXT_VSGID
:
346 return lttng_add_vsgid_to_ctx(ctx
);
347 case LTTNG_KERNEL_ABI_CONTEXT_TIME_NS
:
348 return lttng_add_time_ns_to_ctx(ctx
);
355 * lttng_ioctl - lttng syscall through ioctl
361 * This ioctl implements lttng commands:
362 * LTTNG_KERNEL_ABI_SESSION
363 * Returns a LTTng trace session file descriptor
364 * LTTNG_KERNEL_ABI_TRACER_VERSION
365 * Returns the LTTng kernel tracer version
366 * LTTNG_KERNEL_ABI_TRACEPOINT_LIST
367 * Returns a file descriptor listing available tracepoints
368 * LTTNG_KERNEL_ABI_WAIT_QUIESCENT
369 * Returns after all previously running probes have completed
370 * LTTNG_KERNEL_ABI_TRACER_ABI_VERSION
371 * Returns the LTTng kernel tracer ABI version
372 * LTTNG_KERNEL_ABI_EVENT_NOTIFIER_GROUP_CREATE
373 * Returns a LTTng event notifier group file descriptor
375 * The returned session will be deleted when its file descriptor is closed.
378 long lttng_ioctl(struct file
*file
, unsigned int cmd
, unsigned long arg
)
381 case LTTNG_KERNEL_ABI_OLD_SESSION
:
382 case LTTNG_KERNEL_ABI_SESSION
:
383 return lttng_abi_create_session();
384 case LTTNG_KERNEL_ABI_EVENT_NOTIFIER_GROUP_CREATE
:
385 return lttng_abi_create_event_notifier_group();
386 case LTTNG_KERNEL_ABI_OLD_TRACER_VERSION
:
388 struct lttng_kernel_abi_tracer_version v
;
389 struct lttng_kernel_abi_old_tracer_version oldv
;
390 struct lttng_kernel_abi_old_tracer_version
*uversion
=
391 (struct lttng_kernel_abi_old_tracer_version __user
*) arg
;
393 lttng_abi_tracer_version(&v
);
394 oldv
.major
= v
.major
;
395 oldv
.minor
= v
.minor
;
396 oldv
.patchlevel
= v
.patchlevel
;
398 if (copy_to_user(uversion
, &oldv
, sizeof(oldv
)))
402 case LTTNG_KERNEL_ABI_TRACER_VERSION
:
404 struct lttng_kernel_abi_tracer_version version
;
405 struct lttng_kernel_abi_tracer_version
*uversion
=
406 (struct lttng_kernel_abi_tracer_version __user
*) arg
;
408 lttng_abi_tracer_version(&version
);
410 if (copy_to_user(uversion
, &version
, sizeof(version
)))
414 case LTTNG_KERNEL_ABI_TRACER_ABI_VERSION
:
416 struct lttng_kernel_abi_tracer_abi_version version
;
417 struct lttng_kernel_abi_tracer_abi_version
*uversion
=
418 (struct lttng_kernel_abi_tracer_abi_version __user
*) arg
;
420 lttng_abi_tracer_abi_version(&version
);
422 if (copy_to_user(uversion
, &version
, sizeof(version
)))
426 case LTTNG_KERNEL_ABI_OLD_TRACEPOINT_LIST
:
427 case LTTNG_KERNEL_ABI_TRACEPOINT_LIST
:
428 return lttng_abi_tracepoint_list();
429 case LTTNG_KERNEL_ABI_SYSCALL_LIST
:
430 return lttng_abi_syscall_list();
431 case LTTNG_KERNEL_ABI_OLD_WAIT_QUIESCENT
:
432 case LTTNG_KERNEL_ABI_WAIT_QUIESCENT
:
435 case LTTNG_KERNEL_ABI_OLD_CALIBRATE
:
437 struct lttng_kernel_abi_old_calibrate __user
*ucalibrate
=
438 (struct lttng_kernel_abi_old_calibrate __user
*) arg
;
439 struct lttng_kernel_abi_old_calibrate old_calibrate
;
440 struct lttng_kernel_abi_calibrate calibrate
;
443 if (copy_from_user(&old_calibrate
, ucalibrate
, sizeof(old_calibrate
)))
445 calibrate
.type
= old_calibrate
.type
;
446 ret
= lttng_calibrate(&calibrate
);
447 if (copy_to_user(ucalibrate
, &old_calibrate
, sizeof(old_calibrate
)))
451 case LTTNG_KERNEL_ABI_CALIBRATE
:
453 struct lttng_kernel_abi_calibrate __user
*ucalibrate
=
454 (struct lttng_kernel_abi_calibrate __user
*) arg
;
455 struct lttng_kernel_abi_calibrate calibrate
;
458 if (copy_from_user(&calibrate
, ucalibrate
, sizeof(calibrate
)))
460 ret
= lttng_calibrate(&calibrate
);
461 if (copy_to_user(ucalibrate
, &calibrate
, sizeof(calibrate
)))
470 #if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(5,6,0))
471 static const struct proc_ops lttng_proc_ops
= {
472 .proc_ioctl
= lttng_ioctl
,
474 .proc_compat_ioctl
= lttng_ioctl
,
475 #endif /* CONFIG_COMPAT */
478 static const struct file_operations lttng_proc_ops
= {
479 .owner
= THIS_MODULE
,
480 .unlocked_ioctl
= lttng_ioctl
,
482 .compat_ioctl
= lttng_ioctl
,
483 #endif /* CONFIG_COMPAT */
488 int lttng_abi_create_channel(struct file
*session_file
,
489 struct lttng_kernel_abi_channel
*chan_param
,
490 enum channel_type channel_type
)
492 struct lttng_kernel_session
*session
= session_file
->private_data
;
493 const struct file_operations
*fops
= NULL
;
494 const char *transport_name
;
495 struct lttng_kernel_channel_buffer
*chan
;
496 struct file
*chan_file
;
500 chan_fd
= lttng_get_unused_fd();
505 switch (channel_type
) {
506 case PER_CPU_CHANNEL
:
507 fops
= <tng_channel_fops
;
509 case METADATA_CHANNEL
:
510 fops
= <tng_metadata_fops
;
514 chan_file
= anon_inode_getfile("[lttng_channel]",
517 if (IS_ERR(chan_file
)) {
518 ret
= PTR_ERR(chan_file
);
521 switch (channel_type
) {
522 case PER_CPU_CHANNEL
:
523 if (chan_param
->output
== LTTNG_KERNEL_ABI_SPLICE
) {
524 transport_name
= chan_param
->overwrite
?
525 "relay-overwrite" : "relay-discard";
526 } else if (chan_param
->output
== LTTNG_KERNEL_ABI_MMAP
) {
527 transport_name
= chan_param
->overwrite
?
528 "relay-overwrite-mmap" : "relay-discard-mmap";
533 case METADATA_CHANNEL
:
534 if (chan_param
->output
== LTTNG_KERNEL_ABI_SPLICE
)
535 transport_name
= "relay-metadata";
536 else if (chan_param
->output
== LTTNG_KERNEL_ABI_MMAP
)
537 transport_name
= "relay-metadata-mmap";
542 transport_name
= "<unknown>";
545 if (!atomic_long_add_unless(&session_file
->f_count
, 1, LONG_MAX
)) {
550 * We tolerate no failure path after channel creation. It will stay
551 * invariant for the rest of the session.
553 chan
= lttng_channel_create(session
, transport_name
, NULL
,
554 chan_param
->subbuf_size
,
555 chan_param
->num_subbuf
,
556 chan_param
->switch_timer_interval
,
557 chan_param
->read_timer_interval
,
563 chan
->priv
->parent
.file
= chan_file
;
564 chan_file
->private_data
= chan
;
565 fd_install(chan_fd
, chan_file
);
570 atomic_long_dec(&session_file
->f_count
);
574 put_unused_fd(chan_fd
);
580 int lttng_abi_session_set_name(struct lttng_kernel_session
*session
,
581 struct lttng_kernel_abi_session_name
*name
)
585 len
= strnlen(name
->name
, LTTNG_KERNEL_ABI_SESSION_NAME_LEN
);
587 if (len
== LTTNG_KERNEL_ABI_SESSION_NAME_LEN
) {
588 /* Name is too long/malformed */
592 strcpy(session
->priv
->name
, name
->name
);
597 int lttng_abi_session_set_creation_time(struct lttng_kernel_session
*session
,
598 struct lttng_kernel_abi_session_creation_time
*time
)
602 len
= strnlen(time
->iso8601
, LTTNG_KERNEL_ABI_SESSION_CREATION_TIME_ISO8601_LEN
);
604 if (len
== LTTNG_KERNEL_ABI_SESSION_CREATION_TIME_ISO8601_LEN
) {
605 /* Time is too long/malformed */
609 strcpy(session
->priv
->creation_time
, time
->iso8601
);
614 int lttng_counter_release(struct inode
*inode
, struct file
*file
)
616 struct lttng_counter
*counter
= file
->private_data
;
620 * Do not destroy the counter itself. Wait of the owner
621 * (event_notifier group) to be destroyed.
623 fput(counter
->owner
);
630 long lttng_counter_ioctl(struct file
*file
, unsigned int cmd
, unsigned long arg
)
632 struct lttng_counter
*counter
= file
->private_data
;
633 size_t indexes
[LTTNG_KERNEL_ABI_COUNTER_DIMENSION_MAX
] = { 0 };
637 case LTTNG_KERNEL_ABI_COUNTER_READ
:
639 struct lttng_kernel_abi_counter_read local_counter_read
;
640 struct lttng_kernel_abi_counter_read __user
*ucounter_read
=
641 (struct lttng_kernel_abi_counter_read __user
*) arg
;
642 bool overflow
, underflow
;
647 if (copy_from_user(&local_counter_read
, ucounter_read
,
648 sizeof(local_counter_read
)))
650 if (validate_zeroed_padding(local_counter_read
.padding
,
651 sizeof(local_counter_read
.padding
)))
654 /* Cast all indexes into size_t. */
655 for (i
= 0; i
< local_counter_read
.index
.number_dimensions
; i
++)
656 indexes
[i
] = (size_t) local_counter_read
.index
.dimension_indexes
[i
];
657 cpu
= local_counter_read
.cpu
;
659 ret
= lttng_kernel_counter_read(counter
, indexes
, cpu
, &value
,
660 &overflow
, &underflow
);
663 local_counter_read
.value
.value
= value
;
664 local_counter_read
.value
.overflow
= overflow
;
665 local_counter_read
.value
.underflow
= underflow
;
667 if (copy_to_user(&ucounter_read
->value
, &local_counter_read
.value
,
668 sizeof(local_counter_read
.value
)))
673 case LTTNG_KERNEL_ABI_COUNTER_AGGREGATE
:
675 struct lttng_kernel_abi_counter_aggregate local_counter_aggregate
;
676 struct lttng_kernel_abi_counter_aggregate __user
*ucounter_aggregate
=
677 (struct lttng_kernel_abi_counter_aggregate __user
*) arg
;
678 bool overflow
, underflow
;
682 if (copy_from_user(&local_counter_aggregate
, ucounter_aggregate
,
683 sizeof(local_counter_aggregate
)))
685 if (validate_zeroed_padding(local_counter_aggregate
.padding
,
686 sizeof(local_counter_aggregate
.padding
)))
689 /* Cast all indexes into size_t. */
690 for (i
= 0; i
< local_counter_aggregate
.index
.number_dimensions
; i
++)
691 indexes
[i
] = (size_t) local_counter_aggregate
.index
.dimension_indexes
[i
];
693 ret
= lttng_kernel_counter_aggregate(counter
, indexes
, &value
,
694 &overflow
, &underflow
);
697 local_counter_aggregate
.value
.value
= value
;
698 local_counter_aggregate
.value
.overflow
= overflow
;
699 local_counter_aggregate
.value
.underflow
= underflow
;
701 if (copy_to_user(&ucounter_aggregate
->value
, &local_counter_aggregate
.value
,
702 sizeof(local_counter_aggregate
.value
)))
707 case LTTNG_KERNEL_ABI_COUNTER_CLEAR
:
709 struct lttng_kernel_abi_counter_clear local_counter_clear
;
710 struct lttng_kernel_abi_counter_clear __user
*ucounter_clear
=
711 (struct lttng_kernel_abi_counter_clear __user
*) arg
;
713 if (copy_from_user(&local_counter_clear
, ucounter_clear
,
714 sizeof(local_counter_clear
)))
716 if (validate_zeroed_padding(local_counter_clear
.padding
,
717 sizeof(local_counter_clear
.padding
)))
720 /* Cast all indexes into size_t. */
721 for (i
= 0; i
< local_counter_clear
.index
.number_dimensions
; i
++)
722 indexes
[i
] = (size_t) local_counter_clear
.index
.dimension_indexes
[i
];
724 return lttng_kernel_counter_clear(counter
, indexes
);
732 static const struct file_operations lttng_counter_fops
= {
733 .owner
= THIS_MODULE
,
734 .release
= lttng_counter_release
,
735 .unlocked_ioctl
= lttng_counter_ioctl
,
737 .compat_ioctl
= lttng_counter_ioctl
,
743 enum tracker_type
get_tracker_type(struct lttng_kernel_abi_tracker_args
*tracker
)
745 switch (tracker
->type
) {
746 case LTTNG_KERNEL_ABI_TRACKER_PID
:
748 case LTTNG_KERNEL_ABI_TRACKER_VPID
:
750 case LTTNG_KERNEL_ABI_TRACKER_UID
:
752 case LTTNG_KERNEL_ABI_TRACKER_VUID
:
754 case LTTNG_KERNEL_ABI_TRACKER_GID
:
756 case LTTNG_KERNEL_ABI_TRACKER_VGID
:
759 return TRACKER_UNKNOWN
;
764 * lttng_session_ioctl - lttng session fd ioctl
770 * This ioctl implements lttng commands:
771 * LTTNG_KERNEL_ABI_CHANNEL
772 * Returns a LTTng channel file descriptor
773 * LTTNG_KERNEL_ABI_ENABLE
774 * Enables tracing for a session (weak enable)
775 * LTTNG_KERNEL_ABI_DISABLE
776 * Disables tracing for a session (strong disable)
777 * LTTNG_KERNEL_ABI_METADATA
778 * Returns a LTTng metadata file descriptor
779 * LTTNG_KERNEL_ABI_SESSION_TRACK_PID
780 * Add PID to session PID tracker
781 * LTTNG_KERNEL_ABI_SESSION_UNTRACK_PID
782 * Remove PID from session PID tracker
783 * LTTNG_KERNEL_ABI_SESSION_TRACK_ID
785 * LTTNG_KERNEL_ABI_SESSION_UNTRACK_ID
786 * Remove ID from tracker
788 * The returned channel will be deleted when its file descriptor is closed.
791 long lttng_session_ioctl(struct file
*file
, unsigned int cmd
, unsigned long arg
)
793 struct lttng_kernel_session
*session
= file
->private_data
;
794 struct lttng_kernel_abi_channel chan_param
;
795 struct lttng_kernel_abi_old_channel old_chan_param
;
798 * Handle backward compatibility. OLD commands have wrong
799 * directions, replace them by the correct direction.
802 case LTTNG_KERNEL_ABI_OLD_SESSION_TRACK_PID
:
803 cmd
= LTTNG_KERNEL_ABI_SESSION_TRACK_PID
;
805 case LTTNG_KERNEL_ABI_OLD_SESSION_UNTRACK_PID
:
806 cmd
= LTTNG_KERNEL_ABI_SESSION_UNTRACK_PID
;
808 case LTTNG_KERNEL_ABI_OLD_SESSION_TRACK_ID
:
809 cmd
= LTTNG_KERNEL_ABI_SESSION_TRACK_ID
;
811 case LTTNG_KERNEL_ABI_OLD_SESSION_UNTRACK_ID
:
812 cmd
= LTTNG_KERNEL_ABI_SESSION_UNTRACK_ID
;
814 case LTTNG_KERNEL_ABI_OLD_SESSION_LIST_TRACKER_IDS
:
815 cmd
= LTTNG_KERNEL_ABI_SESSION_LIST_TRACKER_IDS
;
817 case LTTNG_KERNEL_ABI_OLD_SESSION_SET_NAME
:
818 cmd
= LTTNG_KERNEL_ABI_SESSION_SET_NAME
;
820 case LTTNG_KERNEL_ABI_OLD_SESSION_SET_CREATION_TIME
:
821 cmd
= LTTNG_KERNEL_ABI_SESSION_SET_CREATION_TIME
;
829 case LTTNG_KERNEL_ABI_OLD_CHANNEL
:
831 if (copy_from_user(&old_chan_param
,
832 (struct lttng_kernel_abi_old_channel __user
*) arg
,
833 sizeof(struct lttng_kernel_abi_old_channel
)))
835 chan_param
.overwrite
= old_chan_param
.overwrite
;
836 chan_param
.subbuf_size
= old_chan_param
.subbuf_size
;
837 chan_param
.num_subbuf
= old_chan_param
.num_subbuf
;
838 chan_param
.switch_timer_interval
= old_chan_param
.switch_timer_interval
;
839 chan_param
.read_timer_interval
= old_chan_param
.read_timer_interval
;
840 chan_param
.output
= old_chan_param
.output
;
842 return lttng_abi_create_channel(file
, &chan_param
,
845 case LTTNG_KERNEL_ABI_CHANNEL
:
847 if (copy_from_user(&chan_param
,
848 (struct lttng_kernel_abi_channel __user
*) arg
,
849 sizeof(struct lttng_kernel_abi_channel
)))
851 return lttng_abi_create_channel(file
, &chan_param
,
854 case LTTNG_KERNEL_ABI_OLD_SESSION_START
:
855 case LTTNG_KERNEL_ABI_OLD_ENABLE
:
856 case LTTNG_KERNEL_ABI_SESSION_START
:
857 case LTTNG_KERNEL_ABI_ENABLE
:
858 return lttng_session_enable(session
);
859 case LTTNG_KERNEL_ABI_OLD_SESSION_STOP
:
860 case LTTNG_KERNEL_ABI_OLD_DISABLE
:
861 case LTTNG_KERNEL_ABI_SESSION_STOP
:
862 case LTTNG_KERNEL_ABI_DISABLE
:
863 return lttng_session_disable(session
);
864 case LTTNG_KERNEL_ABI_OLD_METADATA
:
866 if (copy_from_user(&old_chan_param
,
867 (struct lttng_kernel_abi_old_channel __user
*) arg
,
868 sizeof(struct lttng_kernel_abi_old_channel
)))
870 chan_param
.overwrite
= old_chan_param
.overwrite
;
871 chan_param
.subbuf_size
= old_chan_param
.subbuf_size
;
872 chan_param
.num_subbuf
= old_chan_param
.num_subbuf
;
873 chan_param
.switch_timer_interval
= old_chan_param
.switch_timer_interval
;
874 chan_param
.read_timer_interval
= old_chan_param
.read_timer_interval
;
875 chan_param
.output
= old_chan_param
.output
;
877 return lttng_abi_create_channel(file
, &chan_param
,
880 case LTTNG_KERNEL_ABI_METADATA
:
882 if (copy_from_user(&chan_param
,
883 (struct lttng_kernel_abi_channel __user
*) arg
,
884 sizeof(struct lttng_kernel_abi_channel
)))
886 return lttng_abi_create_channel(file
, &chan_param
,
889 case LTTNG_KERNEL_ABI_SESSION_TRACK_PID
:
890 return lttng_session_track_id(session
, TRACKER_PID
, (int) arg
);
891 case LTTNG_KERNEL_ABI_SESSION_UNTRACK_PID
:
892 return lttng_session_untrack_id(session
, TRACKER_PID
, (int) arg
);
893 case LTTNG_KERNEL_ABI_SESSION_TRACK_ID
:
895 struct lttng_kernel_abi_tracker_args tracker
;
896 enum tracker_type tracker_type
;
898 if (copy_from_user(&tracker
,
899 (struct lttng_kernel_abi_tracker_args __user
*) arg
,
900 sizeof(struct lttng_kernel_abi_tracker_args
)))
902 tracker_type
= get_tracker_type(&tracker
);
903 if (tracker_type
== TRACKER_UNKNOWN
)
905 return lttng_session_track_id(session
, tracker_type
, tracker
.id
);
907 case LTTNG_KERNEL_ABI_SESSION_UNTRACK_ID
:
909 struct lttng_kernel_abi_tracker_args tracker
;
910 enum tracker_type tracker_type
;
912 if (copy_from_user(&tracker
,
913 (struct lttng_kernel_abi_tracker_args __user
*) arg
,
914 sizeof(struct lttng_kernel_abi_tracker_args
)))
916 tracker_type
= get_tracker_type(&tracker
);
917 if (tracker_type
== TRACKER_UNKNOWN
)
919 return lttng_session_untrack_id(session
, tracker_type
,
922 case LTTNG_KERNEL_ABI_SESSION_LIST_TRACKER_PIDS
:
923 return lttng_session_list_tracker_ids(session
, TRACKER_PID
);
924 case LTTNG_KERNEL_ABI_SESSION_LIST_TRACKER_IDS
:
926 struct lttng_kernel_abi_tracker_args tracker
;
927 enum tracker_type tracker_type
;
929 if (copy_from_user(&tracker
,
930 (struct lttng_kernel_abi_tracker_args __user
*) arg
,
931 sizeof(struct lttng_kernel_abi_tracker_args
)))
933 tracker_type
= get_tracker_type(&tracker
);
934 if (tracker_type
== TRACKER_UNKNOWN
)
936 return lttng_session_list_tracker_ids(session
, tracker_type
);
938 case LTTNG_KERNEL_ABI_SESSION_METADATA_REGEN
:
939 return lttng_session_metadata_regenerate(session
);
940 case LTTNG_KERNEL_ABI_SESSION_STATEDUMP
:
941 return lttng_session_statedump(session
);
942 case LTTNG_KERNEL_ABI_SESSION_SET_NAME
:
944 struct lttng_kernel_abi_session_name name
;
946 if (copy_from_user(&name
,
947 (struct lttng_kernel_abi_session_name __user
*) arg
,
948 sizeof(struct lttng_kernel_abi_session_name
)))
950 return lttng_abi_session_set_name(session
, &name
);
952 case LTTNG_KERNEL_ABI_SESSION_SET_CREATION_TIME
:
954 struct lttng_kernel_abi_session_creation_time time
;
956 if (copy_from_user(&time
,
957 (struct lttng_kernel_abi_session_creation_time __user
*) arg
,
958 sizeof(struct lttng_kernel_abi_session_creation_time
)))
960 return lttng_abi_session_set_creation_time(session
, &time
);
968 * Called when the last file reference is dropped.
970 * Big fat note: channels and events are invariant for the whole session after
971 * their creation. So this session destruction also destroys all channel and
972 * event structures specific to this session (they are not destroyed when their
973 * individual file is released).
976 int lttng_session_release(struct inode
*inode
, struct file
*file
)
978 struct lttng_kernel_session
*session
= file
->private_data
;
981 lttng_session_destroy(session
);
985 static const struct file_operations lttng_session_fops
= {
986 .owner
= THIS_MODULE
,
987 .release
= lttng_session_release
,
988 .unlocked_ioctl
= lttng_session_ioctl
,
990 .compat_ioctl
= lttng_session_ioctl
,
995 * When encountering empty buffer, flush current sub-buffer if non-empty
996 * and retry (if new data available to read after flush).
999 ssize_t
lttng_event_notifier_group_notif_read(struct file
*filp
, char __user
*user_buf
,
1000 size_t count
, loff_t
*ppos
)
1002 struct lttng_event_notifier_group
*event_notifier_group
= filp
->private_data
;
1003 struct lttng_kernel_ring_buffer_channel
*chan
= event_notifier_group
->chan
;
1004 struct lttng_kernel_ring_buffer
*buf
= event_notifier_group
->buf
;
1005 ssize_t read_count
= 0, len
;
1009 if (!lttng_access_ok(VERIFY_WRITE
, user_buf
, count
))
1012 /* Finish copy of previous record */
1014 if (read_count
< count
) {
1015 len
= chan
->iter
.len_left
;
1016 read_offset
= *ppos
;
1021 while (read_count
< count
) {
1022 size_t copy_len
, space_left
;
1024 len
= lib_ring_buffer_get_next_record(chan
, buf
);
1028 * Check if buffer is finalized (end of file).
1030 if (len
== -ENODATA
) {
1031 /* A 0 read_count will tell about end of file */
1034 if (filp
->f_flags
& O_NONBLOCK
) {
1036 read_count
= -EAGAIN
;
1042 * No data available at the moment, return what
1049 * Wait for returned len to be >= 0 or -ENODATA.
1051 error
= wait_event_interruptible(
1052 event_notifier_group
->read_wait
,
1053 ((len
= lib_ring_buffer_get_next_record(
1054 chan
, buf
)), len
!= -EAGAIN
));
1055 CHAN_WARN_ON(chan
, len
== -EBUSY
);
1060 CHAN_WARN_ON(chan
, len
< 0 && len
!= -ENODATA
);
1064 read_offset
= buf
->iter
.read_offset
;
1066 space_left
= count
- read_count
;
1067 if (len
<= space_left
) {
1069 chan
->iter
.len_left
= 0;
1072 copy_len
= space_left
;
1073 chan
->iter
.len_left
= len
- copy_len
;
1074 *ppos
= read_offset
+ copy_len
;
1076 if (__lib_ring_buffer_copy_to_user(&buf
->backend
, read_offset
,
1077 &user_buf
[read_count
],
1080 * Leave the len_left and ppos values at their current
1081 * state, as we currently have a valid event to read.
1085 read_count
+= copy_len
;
1091 chan
->iter
.len_left
= 0;
1094 lib_ring_buffer_put_current_record(buf
);
1099 * If the ring buffer is non empty (even just a partial subbuffer), return that
1100 * there is data available. Perform a ring buffer flush if we encounter a
1101 * non-empty ring buffer which does not have any consumeable subbuffer available.
1104 unsigned int lttng_event_notifier_group_notif_poll(struct file
*filp
,
1107 unsigned int mask
= 0;
1108 struct lttng_event_notifier_group
*event_notifier_group
= filp
->private_data
;
1109 struct lttng_kernel_ring_buffer_channel
*chan
= event_notifier_group
->chan
;
1110 struct lttng_kernel_ring_buffer
*buf
= event_notifier_group
->buf
;
1111 const struct lttng_kernel_ring_buffer_config
*config
= &chan
->backend
.config
;
1112 int finalized
, disabled
;
1113 unsigned long consumed
, offset
;
1114 size_t subbuffer_header_size
= config
->cb
.subbuffer_header_size();
1116 if (filp
->f_mode
& FMODE_READ
) {
1117 poll_wait_set_exclusive(wait
);
1118 poll_wait(filp
, &event_notifier_group
->read_wait
, wait
);
1120 finalized
= lib_ring_buffer_is_finalized(config
, buf
);
1121 disabled
= lib_ring_buffer_channel_is_disabled(chan
);
1124 * lib_ring_buffer_is_finalized() contains a smp_rmb() ordering
1125 * finalized load before offsets loads.
1127 WARN_ON(atomic_long_read(&buf
->active_readers
) != 1);
1132 offset
= lib_ring_buffer_get_offset(config
, buf
);
1133 consumed
= lib_ring_buffer_get_consumed(config
, buf
);
1136 * If there is no buffer available to consume.
1138 if (subbuf_trunc(offset
, chan
) - subbuf_trunc(consumed
, chan
) == 0) {
1140 * If there is a non-empty subbuffer, flush and try again.
1142 if (subbuf_offset(offset
, chan
) > subbuffer_header_size
) {
1143 lib_ring_buffer_switch_remote(buf
);
1151 * The memory barriers
1152 * __wait_event()/wake_up_interruptible() take
1153 * care of "raw_spin_is_locked" memory ordering.
1155 if (raw_spin_is_locked(&buf
->raw_tick_nohz_spinlock
))
1161 if (subbuf_trunc(offset
, chan
) - subbuf_trunc(consumed
, chan
)
1162 >= chan
->backend
.buf_size
)
1163 return POLLPRI
| POLLRDBAND
;
1165 return POLLIN
| POLLRDNORM
;
1173 * lttng_event_notifier_group_notif_open - event_notifier ring buffer open file operation
1174 * @inode: opened inode
1175 * @file: opened file
1177 * Open implementation. Makes sure only one open instance of a buffer is
1178 * done at a given moment.
1180 static int lttng_event_notifier_group_notif_open(struct inode
*inode
, struct file
*file
)
1182 struct lttng_event_notifier_group
*event_notifier_group
= inode
->i_private
;
1183 struct lttng_kernel_ring_buffer
*buf
= event_notifier_group
->buf
;
1185 file
->private_data
= event_notifier_group
;
1186 return lib_ring_buffer_open(inode
, file
, buf
);
1190 * lttng_event_notifier_group_notif_release - event_notifier ring buffer release file operation
1191 * @inode: opened inode
1192 * @file: opened file
1194 * Release implementation.
1196 static int lttng_event_notifier_group_notif_release(struct inode
*inode
, struct file
*file
)
1198 struct lttng_event_notifier_group
*event_notifier_group
= file
->private_data
;
1199 struct lttng_kernel_ring_buffer
*buf
= event_notifier_group
->buf
;
1202 ret
= lib_ring_buffer_release(inode
, file
, buf
);
1205 fput(event_notifier_group
->file
);
1209 static const struct file_operations lttng_event_notifier_group_notif_fops
= {
1210 .owner
= THIS_MODULE
,
1211 .open
= lttng_event_notifier_group_notif_open
,
1212 .release
= lttng_event_notifier_group_notif_release
,
1213 .read
= lttng_event_notifier_group_notif_read
,
1214 .poll
= lttng_event_notifier_group_notif_poll
,
1218 * lttng_metadata_ring_buffer_poll - LTTng ring buffer poll file operation
1222 * Handles the poll operations for the metadata channels.
1225 unsigned int lttng_metadata_ring_buffer_poll(struct file
*filp
,
1228 struct lttng_metadata_stream
*stream
= filp
->private_data
;
1229 struct lttng_kernel_ring_buffer
*buf
= stream
->priv
;
1231 unsigned int mask
= 0;
1233 if (filp
->f_mode
& FMODE_READ
) {
1234 poll_wait_set_exclusive(wait
);
1235 poll_wait(filp
, &stream
->read_wait
, wait
);
1237 finalized
= stream
->finalized
;
1240 * lib_ring_buffer_is_finalized() contains a smp_rmb()
1241 * ordering finalized load before offsets loads.
1243 WARN_ON(atomic_long_read(&buf
->active_readers
) != 1);
1248 mutex_lock(&stream
->metadata_cache
->lock
);
1249 if (stream
->metadata_cache
->metadata_written
>
1250 stream
->metadata_out
)
1252 mutex_unlock(&stream
->metadata_cache
->lock
);
1259 void lttng_metadata_ring_buffer_ioctl_put_next_subbuf(struct file
*filp
,
1260 unsigned int cmd
, unsigned long arg
)
1262 struct lttng_metadata_stream
*stream
= filp
->private_data
;
1264 stream
->metadata_out
= stream
->metadata_in
;
1268 * Reset the counter of how much metadata has been consumed to 0. That way,
1269 * the consumer receives the content of the metadata cache unchanged. This is
1270 * different from the metadata_regenerate where the offset from epoch is
1271 * resampled, here we want the exact same content as the last time the metadata
1272 * was generated. This command is only possible if all the metadata written
1273 * in the cache has been output to the metadata stream to avoid corrupting the
1276 * Return 0 on success, a negative value on error.
1279 int lttng_metadata_cache_dump(struct lttng_metadata_stream
*stream
)
1282 struct lttng_metadata_cache
*cache
= stream
->metadata_cache
;
1284 mutex_lock(&cache
->lock
);
1285 if (stream
->metadata_out
!= cache
->metadata_written
) {
1289 stream
->metadata_out
= 0;
1290 stream
->metadata_in
= 0;
1291 wake_up_interruptible(&stream
->read_wait
);
1295 mutex_unlock(&cache
->lock
);
1300 long lttng_metadata_ring_buffer_ioctl(struct file
*filp
,
1301 unsigned int cmd
, unsigned long arg
)
1304 struct lttng_metadata_stream
*stream
= filp
->private_data
;
1305 struct lttng_kernel_ring_buffer
*buf
= stream
->priv
;
1306 unsigned int rb_cmd
;
1309 if (cmd
== LTTNG_KERNEL_ABI_RING_BUFFER_GET_NEXT_SUBBUF_METADATA_CHECK
)
1310 rb_cmd
= LTTNG_KERNEL_ABI_RING_BUFFER_GET_NEXT_SUBBUF
;
1315 case LTTNG_KERNEL_ABI_RING_BUFFER_GET_NEXT_SUBBUF
:
1317 struct lttng_metadata_stream
*stream
= filp
->private_data
;
1318 struct lttng_kernel_ring_buffer
*buf
= stream
->priv
;
1319 struct lttng_kernel_ring_buffer_channel
*chan
= buf
->backend
.chan
;
1321 ret
= lttng_metadata_output_channel(stream
, chan
, NULL
);
1323 lib_ring_buffer_switch_slow(buf
, SWITCH_ACTIVE
);
1329 case LTTNG_KERNEL_ABI_RING_BUFFER_GET_SUBBUF
:
1332 * Random access is not allowed for metadata channel.
1336 case LTTNG_KERNEL_ABI_RING_BUFFER_FLUSH_EMPTY
:
1338 case LTTNG_KERNEL_ABI_RING_BUFFER_FLUSH
:
1340 struct lttng_metadata_stream
*stream
= filp
->private_data
;
1341 struct lttng_kernel_ring_buffer
*buf
= stream
->priv
;
1342 struct lttng_kernel_ring_buffer_channel
*chan
= buf
->backend
.chan
;
1345 * Before doing the actual ring buffer flush, write up to one
1346 * packet of metadata in the ring buffer.
1348 ret
= lttng_metadata_output_channel(stream
, chan
, NULL
);
1353 case LTTNG_KERNEL_ABI_RING_BUFFER_GET_METADATA_VERSION
:
1355 struct lttng_metadata_stream
*stream
= filp
->private_data
;
1357 return put_u64(stream
->version
, arg
);
1359 case LTTNG_KERNEL_ABI_RING_BUFFER_METADATA_CACHE_DUMP
:
1361 struct lttng_metadata_stream
*stream
= filp
->private_data
;
1363 return lttng_metadata_cache_dump(stream
);
1365 case LTTNG_KERNEL_ABI_RING_BUFFER_GET_NEXT_SUBBUF_METADATA_CHECK
:
1367 struct lttng_metadata_stream
*stream
= filp
->private_data
;
1368 struct lttng_kernel_ring_buffer
*buf
= stream
->priv
;
1369 struct lttng_kernel_ring_buffer_channel
*chan
= buf
->backend
.chan
;
1371 ret
= lttng_metadata_output_channel(stream
, chan
, &coherent
);
1373 lib_ring_buffer_switch_slow(buf
, SWITCH_ACTIVE
);
1375 } else if (ret
< 0) {
1383 /* PUT_SUBBUF is the one from lib ring buffer, unmodified. */
1385 /* Performing lib ring buffer ioctl after our own. */
1386 ret
= lib_ring_buffer_ioctl(filp
, rb_cmd
, arg
, buf
);
1391 case LTTNG_KERNEL_ABI_RING_BUFFER_PUT_NEXT_SUBBUF
:
1393 lttng_metadata_ring_buffer_ioctl_put_next_subbuf(filp
,
1397 case LTTNG_KERNEL_ABI_RING_BUFFER_GET_NEXT_SUBBUF_METADATA_CHECK
:
1399 return put_u32(coherent
, arg
);
1408 #ifdef CONFIG_COMPAT
1410 long lttng_metadata_ring_buffer_compat_ioctl(struct file
*filp
,
1411 unsigned int cmd
, unsigned long arg
)
1414 struct lttng_metadata_stream
*stream
= filp
->private_data
;
1415 struct lttng_kernel_ring_buffer
*buf
= stream
->priv
;
1416 unsigned int rb_cmd
;
1419 if (cmd
== LTTNG_KERNEL_ABI_RING_BUFFER_GET_NEXT_SUBBUF_METADATA_CHECK
)
1420 rb_cmd
= LTTNG_KERNEL_ABI_RING_BUFFER_GET_NEXT_SUBBUF
;
1425 case LTTNG_KERNEL_ABI_RING_BUFFER_GET_NEXT_SUBBUF
:
1427 struct lttng_metadata_stream
*stream
= filp
->private_data
;
1428 struct lttng_kernel_ring_buffer
*buf
= stream
->priv
;
1429 struct lttng_kernel_ring_buffer_channel
*chan
= buf
->backend
.chan
;
1431 ret
= lttng_metadata_output_channel(stream
, chan
, NULL
);
1433 lib_ring_buffer_switch_slow(buf
, SWITCH_ACTIVE
);
1439 case LTTNG_KERNEL_ABI_RING_BUFFER_GET_SUBBUF
:
1442 * Random access is not allowed for metadata channel.
1446 case LTTNG_KERNEL_ABI_RING_BUFFER_FLUSH_EMPTY
:
1448 case LTTNG_KERNEL_ABI_RING_BUFFER_FLUSH
:
1450 struct lttng_metadata_stream
*stream
= filp
->private_data
;
1451 struct lttng_kernel_ring_buffer
*buf
= stream
->priv
;
1452 struct lttng_kernel_ring_buffer_channel
*chan
= buf
->backend
.chan
;
1455 * Before doing the actual ring buffer flush, write up to one
1456 * packet of metadata in the ring buffer.
1458 ret
= lttng_metadata_output_channel(stream
, chan
, NULL
);
1463 case LTTNG_KERNEL_ABI_RING_BUFFER_GET_METADATA_VERSION
:
1465 struct lttng_metadata_stream
*stream
= filp
->private_data
;
1467 return put_u64(stream
->version
, arg
);
1469 case LTTNG_KERNEL_ABI_RING_BUFFER_METADATA_CACHE_DUMP
:
1471 struct lttng_metadata_stream
*stream
= filp
->private_data
;
1473 return lttng_metadata_cache_dump(stream
);
1475 case LTTNG_KERNEL_ABI_RING_BUFFER_GET_NEXT_SUBBUF_METADATA_CHECK
:
1477 struct lttng_metadata_stream
*stream
= filp
->private_data
;
1478 struct lttng_kernel_ring_buffer
*buf
= stream
->priv
;
1479 struct lttng_kernel_ring_buffer_channel
*chan
= buf
->backend
.chan
;
1481 ret
= lttng_metadata_output_channel(stream
, chan
, &coherent
);
1483 lib_ring_buffer_switch_slow(buf
, SWITCH_ACTIVE
);
1485 } else if (ret
< 0) {
1493 /* PUT_SUBBUF is the one from lib ring buffer, unmodified. */
1495 /* Performing lib ring buffer ioctl after our own. */
1496 ret
= lib_ring_buffer_compat_ioctl(filp
, rb_cmd
, arg
, buf
);
1501 case LTTNG_KERNEL_ABI_RING_BUFFER_PUT_NEXT_SUBBUF
:
1503 lttng_metadata_ring_buffer_ioctl_put_next_subbuf(filp
,
1507 case LTTNG_KERNEL_ABI_RING_BUFFER_GET_NEXT_SUBBUF_METADATA_CHECK
:
1509 return put_u32(coherent
, arg
);
1520 * This is not used by anonymous file descriptors. This code is left
1521 * there if we ever want to implement an inode with open() operation.
1524 int lttng_metadata_ring_buffer_open(struct inode
*inode
, struct file
*file
)
1526 struct lttng_metadata_stream
*stream
= inode
->i_private
;
1527 struct lttng_kernel_ring_buffer
*buf
= stream
->priv
;
1529 file
->private_data
= buf
;
1531 * Since life-time of metadata cache differs from that of
1532 * session, we need to keep our own reference on the transport.
1534 if (!try_module_get(stream
->transport
->owner
)) {
1535 printk(KERN_WARNING
"LTTng: Can't lock transport module.\n");
1538 return lib_ring_buffer_open(inode
, file
, buf
);
1542 int lttng_metadata_ring_buffer_release(struct inode
*inode
, struct file
*file
)
1544 struct lttng_metadata_stream
*stream
= file
->private_data
;
1545 struct lttng_kernel_ring_buffer
*buf
= stream
->priv
;
1547 mutex_lock(&stream
->metadata_cache
->lock
);
1548 list_del(&stream
->list
);
1549 mutex_unlock(&stream
->metadata_cache
->lock
);
1550 kref_put(&stream
->metadata_cache
->refcount
, metadata_cache_destroy
);
1551 module_put(stream
->transport
->owner
);
1553 return lib_ring_buffer_release(inode
, file
, buf
);
1557 ssize_t
lttng_metadata_ring_buffer_splice_read(struct file
*in
, loff_t
*ppos
,
1558 struct pipe_inode_info
*pipe
, size_t len
,
1561 struct lttng_metadata_stream
*stream
= in
->private_data
;
1562 struct lttng_kernel_ring_buffer
*buf
= stream
->priv
;
1564 return lib_ring_buffer_splice_read(in
, ppos
, pipe
, len
,
1569 int lttng_metadata_ring_buffer_mmap(struct file
*filp
,
1570 struct vm_area_struct
*vma
)
1572 struct lttng_metadata_stream
*stream
= filp
->private_data
;
1573 struct lttng_kernel_ring_buffer
*buf
= stream
->priv
;
1575 return lib_ring_buffer_mmap(filp
, vma
, buf
);
1579 const struct file_operations lttng_metadata_ring_buffer_file_operations
= {
1580 .owner
= THIS_MODULE
,
1581 .open
= lttng_metadata_ring_buffer_open
,
1582 .release
= lttng_metadata_ring_buffer_release
,
1583 .poll
= lttng_metadata_ring_buffer_poll
,
1584 .splice_read
= lttng_metadata_ring_buffer_splice_read
,
1585 .mmap
= lttng_metadata_ring_buffer_mmap
,
1586 .unlocked_ioctl
= lttng_metadata_ring_buffer_ioctl
,
1587 .llseek
= vfs_lib_ring_buffer_no_llseek
,
1588 #ifdef CONFIG_COMPAT
1589 .compat_ioctl
= lttng_metadata_ring_buffer_compat_ioctl
,
1594 int lttng_abi_create_stream_fd(struct file
*channel_file
, void *stream_priv
,
1595 const struct file_operations
*fops
, const char *name
)
1598 struct file
*stream_file
;
1600 stream_fd
= lttng_get_unused_fd();
1601 if (stream_fd
< 0) {
1605 stream_file
= anon_inode_getfile(name
, fops
, stream_priv
, O_RDWR
);
1606 if (IS_ERR(stream_file
)) {
1607 ret
= PTR_ERR(stream_file
);
1611 * OPEN_FMODE, called within anon_inode_getfile/alloc_file, don't honor
1612 * FMODE_LSEEK, FMODE_PREAD nor FMODE_PWRITE. We need to read from this
1613 * file descriptor, so we set FMODE_PREAD here.
1615 stream_file
->f_mode
|= FMODE_PREAD
;
1616 fd_install(stream_fd
, stream_file
);
1618 * The stream holds a reference to the channel within the generic ring
1619 * buffer library, so no need to hold a refcount on the channel and
1620 * session files here.
1625 put_unused_fd(stream_fd
);
1631 int lttng_abi_open_stream(struct file
*channel_file
)
1633 struct lttng_kernel_channel_buffer
*channel
= channel_file
->private_data
;
1634 struct lttng_kernel_ring_buffer
*buf
;
1638 buf
= channel
->ops
->priv
->buffer_read_open(channel
->priv
->rb_chan
);
1643 ret
= lttng_abi_create_stream_fd(channel_file
, stream_priv
,
1644 <tng_stream_ring_buffer_file_operations
,
1652 channel
->ops
->priv
->buffer_read_close(buf
);
1657 int lttng_abi_open_metadata_stream(struct file
*channel_file
)
1659 struct lttng_kernel_channel_buffer
*channel
= channel_file
->private_data
;
1660 struct lttng_kernel_session
*session
= channel
->parent
.session
;
1661 struct lttng_kernel_ring_buffer
*buf
;
1663 struct lttng_metadata_stream
*metadata_stream
;
1666 buf
= channel
->ops
->priv
->buffer_read_open(channel
->priv
->rb_chan
);
1670 metadata_stream
= kzalloc(sizeof(struct lttng_metadata_stream
),
1672 if (!metadata_stream
) {
1676 metadata_stream
->metadata_cache
= session
->priv
->metadata_cache
;
1677 init_waitqueue_head(&metadata_stream
->read_wait
);
1678 metadata_stream
->priv
= buf
;
1679 stream_priv
= metadata_stream
;
1680 metadata_stream
->transport
= channel
->priv
->transport
;
1681 /* Initial state is an empty metadata, considered as incoherent. */
1682 metadata_stream
->coherent
= false;
1685 * Since life-time of metadata cache differs from that of
1686 * session, we need to keep our own reference on the transport.
1688 if (!try_module_get(metadata_stream
->transport
->owner
)) {
1689 printk(KERN_WARNING
"LTTng: Can't lock transport module.\n");
1694 if (!lttng_kref_get(&session
->priv
->metadata_cache
->refcount
)) {
1699 ret
= lttng_abi_create_stream_fd(channel_file
, stream_priv
,
1700 <tng_metadata_ring_buffer_file_operations
,
1701 "[lttng_metadata_stream]");
1705 mutex_lock(&session
->priv
->metadata_cache
->lock
);
1706 list_add(&metadata_stream
->list
,
1707 &session
->priv
->metadata_cache
->metadata_stream
);
1708 mutex_unlock(&session
->priv
->metadata_cache
->lock
);
1712 kref_put(&session
->priv
->metadata_cache
->refcount
, metadata_cache_destroy
);
1714 module_put(metadata_stream
->transport
->owner
);
1716 kfree(metadata_stream
);
1718 channel
->ops
->priv
->buffer_read_close(buf
);
1723 int lttng_abi_open_event_notifier_group_stream(struct file
*notif_file
)
1725 struct lttng_event_notifier_group
*event_notifier_group
= notif_file
->private_data
;
1726 struct lttng_kernel_ring_buffer_channel
*chan
= event_notifier_group
->chan
;
1727 struct lttng_kernel_ring_buffer
*buf
;
1731 buf
= event_notifier_group
->ops
->priv
->buffer_read_open(chan
);
1735 /* The event_notifier notification fd holds a reference on the event_notifier group */
1736 if (!atomic_long_add_unless(¬if_file
->f_count
, 1, LONG_MAX
)) {
1738 goto refcount_error
;
1740 event_notifier_group
->buf
= buf
;
1741 stream_priv
= event_notifier_group
;
1742 ret
= lttng_abi_create_stream_fd(notif_file
, stream_priv
,
1743 <tng_event_notifier_group_notif_fops
,
1744 "[lttng_event_notifier_stream]");
1751 atomic_long_dec(¬if_file
->f_count
);
1753 event_notifier_group
->ops
->priv
->buffer_read_close(buf
);
1758 int lttng_abi_validate_event_param(struct lttng_kernel_abi_event
*event_param
)
1760 /* Limit ABI to implemented features. */
1761 switch (event_param
->instrumentation
) {
1762 case LTTNG_KERNEL_ABI_SYSCALL
:
1763 switch (event_param
->u
.syscall
.entryexit
) {
1764 case LTTNG_KERNEL_ABI_SYSCALL_ENTRY
:
1766 case LTTNG_KERNEL_ABI_SYSCALL_EXIT
:
1768 case LTTNG_KERNEL_ABI_SYSCALL_ENTRYEXIT
:
1773 switch (event_param
->u
.syscall
.abi
) {
1774 case LTTNG_KERNEL_ABI_SYSCALL_ABI_ALL
:
1779 switch (event_param
->u
.syscall
.match
) {
1780 case LTTNG_KERNEL_ABI_SYSCALL_MATCH_NAME
:
1787 case LTTNG_KERNEL_ABI_KRETPROBE
:
1788 switch (event_param
->u
.kretprobe
.entryexit
) {
1789 case LTTNG_KERNEL_ABI_SYSCALL_ENTRYEXIT
:
1791 case LTTNG_KERNEL_ABI_SYSCALL_ENTRY
:
1793 case LTTNG_KERNEL_ABI_SYSCALL_EXIT
:
1800 case LTTNG_KERNEL_ABI_TRACEPOINT
:
1802 case LTTNG_KERNEL_ABI_KPROBE
:
1804 case LTTNG_KERNEL_ABI_UPROBE
:
1807 case LTTNG_KERNEL_ABI_FUNCTION
:
1809 case LTTNG_KERNEL_ABI_NOOP
:
1818 int lttng_abi_create_event(struct file
*channel_file
,
1819 struct lttng_kernel_abi_event
*event_param
)
1821 const struct file_operations
*fops
;
1822 struct lttng_kernel_channel_buffer
*channel
= channel_file
->private_data
;
1824 struct file
*event_file
;
1827 event_param
->name
[LTTNG_KERNEL_ABI_SYM_NAME_LEN
- 1] = '\0';
1828 switch (event_param
->instrumentation
) {
1829 case LTTNG_KERNEL_ABI_KRETPROBE
:
1830 event_param
->u
.kretprobe
.symbol_name
[LTTNG_KERNEL_ABI_SYM_NAME_LEN
- 1] = '\0';
1832 case LTTNG_KERNEL_ABI_KPROBE
:
1833 event_param
->u
.kprobe
.symbol_name
[LTTNG_KERNEL_ABI_SYM_NAME_LEN
- 1] = '\0';
1835 case LTTNG_KERNEL_ABI_FUNCTION
:
1837 /* Not implemented. */
1843 switch (event_param
->instrumentation
) {
1844 case LTTNG_KERNEL_ABI_TRACEPOINT
:
1846 case LTTNG_KERNEL_ABI_SYSCALL
:
1847 fops
= <tng_event_recorder_enabler_fops
;
1849 case LTTNG_KERNEL_ABI_KPROBE
:
1851 case LTTNG_KERNEL_ABI_KRETPROBE
:
1853 case LTTNG_KERNEL_ABI_UPROBE
:
1854 fops
= <tng_event_recorder_event_fops
;
1857 case LTTNG_KERNEL_ABI_FUNCTION
:
1859 case LTTNG_KERNEL_ABI_NOOP
:
1865 event_fd
= lttng_get_unused_fd();
1870 event_file
= anon_inode_getfile("[lttng_event]",
1871 fops
, NULL
, O_RDWR
);
1872 if (IS_ERR(event_file
)) {
1873 ret
= PTR_ERR(event_file
);
1876 /* The event holds a reference on the channel */
1877 if (!atomic_long_add_unless(&channel_file
->f_count
, 1, LONG_MAX
)) {
1879 goto refcount_error
;
1881 ret
= lttng_abi_validate_event_param(event_param
);
1885 switch (event_param
->instrumentation
) {
1886 case LTTNG_KERNEL_ABI_TRACEPOINT
:
1888 case LTTNG_KERNEL_ABI_SYSCALL
:
1890 struct lttng_event_enabler
*event_enabler
;
1892 if (strutils_is_star_glob_pattern(event_param
->name
)) {
1894 * If the event name is a star globbing pattern,
1895 * we create the special star globbing enabler.
1897 event_enabler
= lttng_event_enabler_create(LTTNG_ENABLER_FORMAT_STAR_GLOB
,
1898 event_param
, channel
);
1900 event_enabler
= lttng_event_enabler_create(LTTNG_ENABLER_FORMAT_NAME
,
1901 event_param
, channel
);
1904 lttng_event_enabler_session_add(channel
->parent
.session
, event_enabler
);
1905 priv
= event_enabler
;
1909 case LTTNG_KERNEL_ABI_KPROBE
:
1911 case LTTNG_KERNEL_ABI_KRETPROBE
:
1913 case LTTNG_KERNEL_ABI_UPROBE
:
1915 struct lttng_kernel_event_recorder
*event
;
1916 struct lttng_event_enabler
*event_enabler
;
1918 event_enabler
= lttng_event_enabler_create(LTTNG_ENABLER_FORMAT_NAME
,
1919 event_param
, channel
);
1920 if (!event_enabler
) {
1925 * We tolerate no failure path after event creation. It
1926 * will stay invariant for the rest of the session.
1928 event
= lttng_kernel_event_recorder_create(event_enabler
, NULL
);
1929 WARN_ON_ONCE(!event
);
1930 lttng_event_enabler_destroy(event_enabler
);
1931 if (IS_ERR(event
)) {
1932 ret
= PTR_ERR(event
);
1939 case LTTNG_KERNEL_ABI_FUNCTION
:
1941 case LTTNG_KERNEL_ABI_NOOP
:
1947 event_file
->private_data
= priv
;
1948 fd_install(event_fd
, event_file
);
1952 atomic_long_dec(&channel_file
->f_count
);
1956 put_unused_fd(event_fd
);
1962 long lttng_event_notifier_event_ioctl(struct file
*file
, unsigned int cmd
, unsigned long arg
)
1964 struct lttng_kernel_event_notifier
*event_notifier
= file
->private_data
;
1967 case LTTNG_KERNEL_ABI_ENABLE
:
1968 return lttng_event_enable(&event_notifier
->parent
);
1969 case LTTNG_KERNEL_ABI_DISABLE
:
1970 return lttng_event_disable(&event_notifier
->parent
);
1971 case LTTNG_KERNEL_ABI_FILTER
:
1973 case LTTNG_KERNEL_ABI_CAPTURE
:
1975 case LTTNG_KERNEL_ABI_ADD_CALLSITE
:
1976 return lttng_event_add_callsite(&event_notifier
->parent
,
1977 (struct lttng_kernel_abi_event_callsite __user
*) arg
);
1979 return -ENOIOCTLCMD
;
1984 long lttng_event_notifier_enabler_ioctl(struct file
*file
, unsigned int cmd
, unsigned long arg
)
1986 struct lttng_event_notifier_enabler
*event_notifier_enabler
= file
->private_data
;
1989 case LTTNG_KERNEL_ABI_ENABLE
:
1990 return lttng_event_notifier_enabler_enable(event_notifier_enabler
);
1991 case LTTNG_KERNEL_ABI_DISABLE
:
1992 return lttng_event_notifier_enabler_disable(event_notifier_enabler
);
1993 case LTTNG_KERNEL_ABI_FILTER
:
1994 return lttng_event_notifier_enabler_attach_filter_bytecode(
1995 event_notifier_enabler
,
1996 (struct lttng_kernel_abi_filter_bytecode __user
*) arg
);
1997 case LTTNG_KERNEL_ABI_CAPTURE
:
1998 return lttng_event_notifier_enabler_attach_capture_bytecode(
1999 event_notifier_enabler
,
2000 (struct lttng_kernel_abi_capture_bytecode __user
*) arg
);
2001 case LTTNG_KERNEL_ABI_ADD_CALLSITE
:
2004 return -ENOIOCTLCMD
;
2009 int lttng_event_notifier_event_release(struct inode
*inode
, struct file
*file
)
2011 struct lttng_kernel_event_notifier
*event_notifier
= file
->private_data
;
2014 fput(event_notifier
->priv
->group
->file
);
2019 int lttng_event_notifier_enabler_release(struct inode
*inode
, struct file
*file
)
2021 struct lttng_event_notifier_enabler
*event_notifier_enabler
= file
->private_data
;
2023 if (event_notifier_enabler
)
2024 fput(event_notifier_enabler
->group
->file
);
2028 static const struct file_operations lttng_event_notifier_event_fops
= {
2029 .owner
= THIS_MODULE
,
2030 .release
= lttng_event_notifier_event_release
,
2031 .unlocked_ioctl
= lttng_event_notifier_event_ioctl
,
2032 #ifdef CONFIG_COMPAT
2033 .compat_ioctl
= lttng_event_notifier_event_ioctl
,
2037 static const struct file_operations lttng_event_notifier_enabler_fops
= {
2038 .owner
= THIS_MODULE
,
2039 .release
= lttng_event_notifier_enabler_release
,
2040 .unlocked_ioctl
= lttng_event_notifier_enabler_ioctl
,
2041 #ifdef CONFIG_COMPAT
2042 .compat_ioctl
= lttng_event_notifier_enabler_ioctl
,
2047 int lttng_abi_create_event_notifier(struct file
*event_notifier_group_file
,
2048 struct lttng_kernel_abi_event_notifier
*event_notifier_param
)
2050 struct lttng_event_notifier_group
*event_notifier_group
=
2051 event_notifier_group_file
->private_data
;
2052 const struct file_operations
*fops
;
2053 int event_notifier_fd
, ret
;
2054 struct file
*event_notifier_file
;
2057 switch (event_notifier_param
->event
.instrumentation
) {
2058 case LTTNG_KERNEL_ABI_TRACEPOINT
:
2059 case LTTNG_KERNEL_ABI_UPROBE
:
2061 case LTTNG_KERNEL_ABI_KPROBE
:
2062 event_notifier_param
->event
.u
.kprobe
.symbol_name
[LTTNG_KERNEL_ABI_SYM_NAME_LEN
- 1] = '\0';
2064 case LTTNG_KERNEL_ABI_SYSCALL
:
2066 case LTTNG_KERNEL_ABI_KRETPROBE
:
2067 /* Placing an event notifier on kretprobe is not supported. */
2068 case LTTNG_KERNEL_ABI_FUNCTION
:
2069 case LTTNG_KERNEL_ABI_NOOP
:
2075 switch (event_notifier_param
->event
.instrumentation
) {
2076 case LTTNG_KERNEL_ABI_TRACEPOINT
:
2078 case LTTNG_KERNEL_ABI_SYSCALL
:
2079 fops
= <tng_event_notifier_enabler_fops
;
2081 case LTTNG_KERNEL_ABI_KPROBE
:
2083 case LTTNG_KERNEL_ABI_KRETPROBE
:
2085 case LTTNG_KERNEL_ABI_UPROBE
:
2086 fops
= <tng_event_notifier_event_fops
;
2089 case LTTNG_KERNEL_ABI_FUNCTION
:
2091 case LTTNG_KERNEL_ABI_NOOP
:
2098 event_notifier_param
->event
.name
[LTTNG_KERNEL_ABI_SYM_NAME_LEN
- 1] = '\0';
2100 event_notifier_fd
= lttng_get_unused_fd();
2101 if (event_notifier_fd
< 0) {
2102 ret
= event_notifier_fd
;
2106 event_notifier_file
= anon_inode_getfile("[lttng_event_notifier]",
2107 fops
, NULL
, O_RDWR
);
2108 if (IS_ERR(event_notifier_file
)) {
2109 ret
= PTR_ERR(event_notifier_file
);
2113 /* The event notifier holds a reference on the event notifier group. */
2114 if (!atomic_long_add_unless(&event_notifier_group_file
->f_count
, 1, LONG_MAX
)) {
2116 goto refcount_error
;
2119 ret
= lttng_abi_validate_event_param(&event_notifier_param
->event
);
2121 goto event_notifier_error
;
2123 switch (event_notifier_param
->event
.instrumentation
) {
2124 case LTTNG_KERNEL_ABI_TRACEPOINT
:
2126 case LTTNG_KERNEL_ABI_SYSCALL
:
2128 struct lttng_event_notifier_enabler
*enabler
;
2130 if (strutils_is_star_glob_pattern(event_notifier_param
->event
.name
)) {
2132 * If the event name is a star globbing pattern,
2133 * we create the special star globbing enabler.
2135 enabler
= lttng_event_notifier_enabler_create(
2136 event_notifier_group
,
2137 LTTNG_ENABLER_FORMAT_STAR_GLOB
,
2138 event_notifier_param
);
2140 enabler
= lttng_event_notifier_enabler_create(
2141 event_notifier_group
,
2142 LTTNG_ENABLER_FORMAT_NAME
,
2143 event_notifier_param
);
2149 case LTTNG_KERNEL_ABI_KPROBE
:
2151 case LTTNG_KERNEL_ABI_KRETPROBE
:
2153 case LTTNG_KERNEL_ABI_UPROBE
:
2155 struct lttng_kernel_event_notifier
*event_notifier
;
2158 * We tolerate no failure path after event notifier creation.
2159 * It will stay invariant for the rest of the session.
2161 event_notifier
= lttng_event_notifier_create(NULL
,
2162 event_notifier_param
->event
.token
,
2163 event_notifier_param
->error_counter_index
,
2164 event_notifier_group
,
2165 event_notifier_param
,
2166 event_notifier_param
->event
.instrumentation
);
2167 WARN_ON_ONCE(!event_notifier
);
2168 if (IS_ERR(event_notifier
)) {
2169 ret
= PTR_ERR(event_notifier
);
2170 goto event_notifier_error
;
2172 priv
= event_notifier
;
2176 case LTTNG_KERNEL_ABI_FUNCTION
:
2178 case LTTNG_KERNEL_ABI_NOOP
:
2182 goto event_notifier_error
;
2184 event_notifier_file
->private_data
= priv
;
2185 fd_install(event_notifier_fd
, event_notifier_file
);
2186 return event_notifier_fd
;
2188 event_notifier_error
:
2189 atomic_long_dec(&event_notifier_group_file
->f_count
);
2191 fput(event_notifier_file
);
2193 put_unused_fd(event_notifier_fd
);
2200 long lttng_abi_event_notifier_group_create_error_counter(
2201 struct file
*event_notifier_group_file
,
2202 const struct lttng_kernel_abi_counter_conf
*error_counter_conf
)
2204 int counter_fd
, ret
;
2205 char *counter_transport_name
;
2207 struct lttng_counter
*counter
= NULL
;
2208 struct file
*counter_file
;
2209 struct lttng_event_notifier_group
*event_notifier_group
=
2210 (struct lttng_event_notifier_group
*) event_notifier_group_file
->private_data
;
2212 if (error_counter_conf
->arithmetic
!= LTTNG_KERNEL_ABI_COUNTER_ARITHMETIC_MODULAR
) {
2213 printk(KERN_ERR
"LTTng: event_notifier: Error counter of the wrong arithmetic type.\n");
2217 if (error_counter_conf
->number_dimensions
!= 1) {
2218 printk(KERN_ERR
"LTTng: event_notifier: Error counter has more than one dimension.\n");
2222 switch (error_counter_conf
->bitness
) {
2223 case LTTNG_KERNEL_ABI_COUNTER_BITNESS_64
:
2224 counter_transport_name
= "counter-per-cpu-64-modular";
2226 case LTTNG_KERNEL_ABI_COUNTER_BITNESS_32
:
2227 counter_transport_name
= "counter-per-cpu-32-modular";
2234 * Lock sessions to provide mutual exclusion against concurrent
2235 * modification of event_notifier group, which would result in
2236 * overwriting the error counter if set concurrently.
2238 lttng_lock_sessions();
2240 if (event_notifier_group
->error_counter
) {
2241 printk(KERN_ERR
"Error counter already created in event_notifier group\n");
2246 counter_fd
= lttng_get_unused_fd();
2247 if (counter_fd
< 0) {
2252 counter_file
= anon_inode_getfile("[lttng_counter]",
2253 <tng_counter_fops
,
2255 if (IS_ERR(counter_file
)) {
2256 ret
= PTR_ERR(counter_file
);
2260 counter_len
= error_counter_conf
->dimensions
[0].size
;
2262 if (!atomic_long_add_unless(&event_notifier_group_file
->f_count
, 1, LONG_MAX
)) {
2264 goto refcount_error
;
2267 counter
= lttng_kernel_counter_create(counter_transport_name
,
2274 event_notifier_group
->error_counter_len
= counter_len
;
2276 * store-release to publish error counter matches load-acquire
2277 * in record_error. Ensures the counter is created and the
2278 * error_counter_len is set before they are used.
2280 lttng_smp_store_release(&event_notifier_group
->error_counter
, counter
);
2282 counter
->file
= counter_file
;
2283 counter
->owner
= event_notifier_group
->file
;
2284 counter_file
->private_data
= counter
;
2285 /* Ownership transferred. */
2288 fd_install(counter_fd
, counter_file
);
2289 lttng_unlock_sessions();
2294 atomic_long_dec(&event_notifier_group_file
->f_count
);
2298 put_unused_fd(counter_fd
);
2300 lttng_unlock_sessions();
2305 long lttng_event_notifier_group_ioctl(struct file
*file
, unsigned int cmd
,
2309 case LTTNG_KERNEL_ABI_EVENT_NOTIFIER_GROUP_NOTIFICATION_FD
:
2311 return lttng_abi_open_event_notifier_group_stream(file
);
2313 case LTTNG_KERNEL_ABI_EVENT_NOTIFIER_CREATE
:
2315 struct lttng_kernel_abi_event_notifier uevent_notifier_param
;
2317 if (copy_from_user(&uevent_notifier_param
,
2318 (struct lttng_kernel_abi_event_notifier __user
*) arg
,
2319 sizeof(uevent_notifier_param
)))
2321 return lttng_abi_create_event_notifier(file
, &uevent_notifier_param
);
2323 case LTTNG_KERNEL_ABI_COUNTER
:
2325 struct lttng_kernel_abi_counter_conf uerror_counter_conf
;
2327 if (copy_from_user(&uerror_counter_conf
,
2328 (struct lttng_kernel_abi_counter_conf __user
*) arg
,
2329 sizeof(uerror_counter_conf
)))
2331 return lttng_abi_event_notifier_group_create_error_counter(file
,
2332 &uerror_counter_conf
);
2335 return -ENOIOCTLCMD
;
2341 int lttng_event_notifier_group_release(struct inode
*inode
, struct file
*file
)
2343 struct lttng_event_notifier_group
*event_notifier_group
=
2346 if (event_notifier_group
)
2347 lttng_event_notifier_group_destroy(event_notifier_group
);
2351 static const struct file_operations lttng_event_notifier_group_fops
= {
2352 .owner
= THIS_MODULE
,
2353 .release
= lttng_event_notifier_group_release
,
2354 .unlocked_ioctl
= lttng_event_notifier_group_ioctl
,
2355 #ifdef CONFIG_COMPAT
2356 .compat_ioctl
= lttng_event_notifier_group_ioctl
,
2361 * lttng_channel_ioctl - lttng syscall through ioctl
2367 * This ioctl implements lttng commands:
2368 * LTTNG_KERNEL_ABI_STREAM
2369 * Returns an event stream file descriptor or failure.
2370 * (typically, one event stream records events from one CPU)
2371 * LTTNG_KERNEL_ABI_EVENT
2372 * Returns an event file descriptor or failure.
2373 * LTTNG_KERNEL_ABI_CONTEXT
2374 * Prepend a context field to each event in the channel
2375 * LTTNG_KERNEL_ABI_ENABLE
2376 * Enable recording for events in this channel (weak enable)
2377 * LTTNG_KERNEL_ABI_DISABLE
2378 * Disable recording for events in this channel (strong disable)
2380 * Channel and event file descriptors also hold a reference on the session.
2383 long lttng_channel_ioctl(struct file
*file
, unsigned int cmd
, unsigned long arg
)
2385 struct lttng_kernel_channel_buffer
*channel
= file
->private_data
;
2388 case LTTNG_KERNEL_ABI_OLD_STREAM
:
2389 case LTTNG_KERNEL_ABI_STREAM
:
2390 return lttng_abi_open_stream(file
);
2391 case LTTNG_KERNEL_ABI_OLD_EVENT
:
2393 struct lttng_kernel_abi_event
*uevent_param
;
2394 struct lttng_kernel_abi_old_event
*old_uevent_param
;
2397 uevent_param
= kmalloc(sizeof(struct lttng_kernel_abi_event
),
2399 if (!uevent_param
) {
2403 old_uevent_param
= kmalloc(
2404 sizeof(struct lttng_kernel_abi_old_event
),
2406 if (!old_uevent_param
) {
2408 goto old_event_error_free_param
;
2410 if (copy_from_user(old_uevent_param
,
2411 (struct lttng_kernel_abi_old_event __user
*) arg
,
2412 sizeof(struct lttng_kernel_abi_old_event
))) {
2414 goto old_event_error_free_old_param
;
2417 memcpy(uevent_param
->name
, old_uevent_param
->name
,
2418 sizeof(uevent_param
->name
));
2419 uevent_param
->instrumentation
=
2420 old_uevent_param
->instrumentation
;
2422 switch (old_uevent_param
->instrumentation
) {
2423 case LTTNG_KERNEL_ABI_KPROBE
:
2424 uevent_param
->u
.kprobe
.addr
=
2425 old_uevent_param
->u
.kprobe
.addr
;
2426 uevent_param
->u
.kprobe
.offset
=
2427 old_uevent_param
->u
.kprobe
.offset
;
2428 memcpy(uevent_param
->u
.kprobe
.symbol_name
,
2429 old_uevent_param
->u
.kprobe
.symbol_name
,
2430 sizeof(uevent_param
->u
.kprobe
.symbol_name
));
2432 case LTTNG_KERNEL_ABI_KRETPROBE
:
2433 uevent_param
->u
.kretprobe
.addr
=
2434 old_uevent_param
->u
.kretprobe
.addr
;
2435 uevent_param
->u
.kretprobe
.offset
=
2436 old_uevent_param
->u
.kretprobe
.offset
;
2437 memcpy(uevent_param
->u
.kretprobe
.symbol_name
,
2438 old_uevent_param
->u
.kretprobe
.symbol_name
,
2439 sizeof(uevent_param
->u
.kretprobe
.symbol_name
));
2441 case LTTNG_KERNEL_ABI_FUNCTION
:
2443 /* Not implemented. */
2448 ret
= lttng_abi_create_event(file
, uevent_param
);
2450 old_event_error_free_old_param
:
2451 kfree(old_uevent_param
);
2452 old_event_error_free_param
:
2453 kfree(uevent_param
);
2457 case LTTNG_KERNEL_ABI_EVENT
:
2459 struct lttng_kernel_abi_event uevent_param
;
2461 if (copy_from_user(&uevent_param
,
2462 (struct lttng_kernel_abi_event __user
*) arg
,
2463 sizeof(uevent_param
)))
2465 return lttng_abi_create_event(file
, &uevent_param
);
2467 case LTTNG_KERNEL_ABI_OLD_CONTEXT
:
2469 struct lttng_kernel_abi_context
*ucontext_param
;
2470 struct lttng_kernel_abi_old_context
*old_ucontext_param
;
2473 ucontext_param
= kmalloc(sizeof(struct lttng_kernel_abi_context
),
2475 if (!ucontext_param
) {
2479 old_ucontext_param
= kmalloc(sizeof(struct lttng_kernel_abi_old_context
),
2481 if (!old_ucontext_param
) {
2483 goto old_ctx_error_free_param
;
2486 if (copy_from_user(old_ucontext_param
,
2487 (struct lttng_kernel_abi_old_context __user
*) arg
,
2488 sizeof(struct lttng_kernel_abi_old_context
))) {
2490 goto old_ctx_error_free_old_param
;
2492 ucontext_param
->ctx
= old_ucontext_param
->ctx
;
2493 memcpy(ucontext_param
->padding
, old_ucontext_param
->padding
,
2494 sizeof(ucontext_param
->padding
));
2495 /* only type that uses the union */
2496 if (old_ucontext_param
->ctx
== LTTNG_KERNEL_ABI_CONTEXT_PERF_COUNTER
) {
2497 ucontext_param
->u
.perf_counter
.type
=
2498 old_ucontext_param
->u
.perf_counter
.type
;
2499 ucontext_param
->u
.perf_counter
.config
=
2500 old_ucontext_param
->u
.perf_counter
.config
;
2501 memcpy(ucontext_param
->u
.perf_counter
.name
,
2502 old_ucontext_param
->u
.perf_counter
.name
,
2503 sizeof(ucontext_param
->u
.perf_counter
.name
));
2506 ret
= lttng_abi_add_context(file
,
2508 &channel
->priv
->ctx
, channel
->parent
.session
);
2510 old_ctx_error_free_old_param
:
2511 kfree(old_ucontext_param
);
2512 old_ctx_error_free_param
:
2513 kfree(ucontext_param
);
2517 case LTTNG_KERNEL_ABI_CONTEXT
:
2519 struct lttng_kernel_abi_context ucontext_param
;
2521 if (copy_from_user(&ucontext_param
,
2522 (struct lttng_kernel_abi_context __user
*) arg
,
2523 sizeof(ucontext_param
)))
2525 return lttng_abi_add_context(file
,
2527 &channel
->priv
->ctx
, channel
->parent
.session
);
2529 case LTTNG_KERNEL_ABI_OLD_ENABLE
:
2530 case LTTNG_KERNEL_ABI_ENABLE
:
2531 return lttng_channel_enable(channel
);
2532 case LTTNG_KERNEL_ABI_OLD_DISABLE
:
2533 case LTTNG_KERNEL_ABI_DISABLE
:
2534 return lttng_channel_disable(channel
);
2535 case LTTNG_KERNEL_ABI_SYSCALL_MASK
:
2536 return lttng_channel_syscall_mask(channel
,
2537 (struct lttng_kernel_abi_syscall_mask __user
*) arg
);
2539 return -ENOIOCTLCMD
;
2544 * lttng_metadata_ioctl - lttng syscall through ioctl
2550 * This ioctl implements lttng commands:
2551 * LTTNG_KERNEL_ABI_STREAM
2552 * Returns an event stream file descriptor or failure.
2554 * Channel and event file descriptors also hold a reference on the session.
2557 long lttng_metadata_ioctl(struct file
*file
, unsigned int cmd
, unsigned long arg
)
2560 case LTTNG_KERNEL_ABI_OLD_STREAM
:
2561 case LTTNG_KERNEL_ABI_STREAM
:
2562 return lttng_abi_open_metadata_stream(file
);
2564 return -ENOIOCTLCMD
;
2569 * lttng_channel_poll - lttng stream addition/removal monitoring
2574 unsigned int lttng_channel_poll(struct file
*file
, poll_table
*wait
)
2576 struct lttng_kernel_channel_buffer
*channel
= file
->private_data
;
2577 unsigned int mask
= 0;
2579 if (file
->f_mode
& FMODE_READ
) {
2580 poll_wait_set_exclusive(wait
);
2581 poll_wait(file
, channel
->ops
->priv
->get_hp_wait_queue(channel
->priv
->rb_chan
),
2584 if (channel
->ops
->priv
->is_disabled(channel
->priv
->rb_chan
))
2586 if (channel
->ops
->priv
->is_finalized(channel
->priv
->rb_chan
))
2588 if (channel
->ops
->priv
->buffer_has_read_closed_stream(channel
->priv
->rb_chan
))
2589 return POLLIN
| POLLRDNORM
;
2597 int lttng_channel_release(struct inode
*inode
, struct file
*file
)
2599 struct lttng_kernel_channel_buffer
*channel
= file
->private_data
;
2602 fput(channel
->parent
.session
->priv
->file
);
2607 int lttng_metadata_channel_release(struct inode
*inode
, struct file
*file
)
2609 struct lttng_kernel_channel_buffer
*channel
= file
->private_data
;
2612 fput(channel
->parent
.session
->priv
->file
);
2613 lttng_metadata_channel_destroy(channel
);
2619 static const struct file_operations lttng_channel_fops
= {
2620 .owner
= THIS_MODULE
,
2621 .release
= lttng_channel_release
,
2622 .poll
= lttng_channel_poll
,
2623 .unlocked_ioctl
= lttng_channel_ioctl
,
2624 #ifdef CONFIG_COMPAT
2625 .compat_ioctl
= lttng_channel_ioctl
,
2629 static const struct file_operations lttng_metadata_fops
= {
2630 .owner
= THIS_MODULE
,
2631 .release
= lttng_metadata_channel_release
,
2632 .unlocked_ioctl
= lttng_metadata_ioctl
,
2633 #ifdef CONFIG_COMPAT
2634 .compat_ioctl
= lttng_metadata_ioctl
,
2639 * lttng_event_recorder_event_ioctl - lttng syscall through ioctl
2645 * This ioctl implements lttng commands:
2646 * LTTNG_KERNEL_ABI_CONTEXT
2647 * Prepend a context field to each record of this event
2648 * LTTNG_KERNEL_ABI_ENABLE
2649 * Enable recording for this event (weak enable)
2650 * LTTNG_KERNEL_ABI_DISABLE
2651 * Disable recording for this event (strong disable)
2654 long lttng_event_recorder_event_ioctl(struct file
*file
, unsigned int cmd
, unsigned long arg
)
2656 struct lttng_kernel_event_recorder
*event_recorder
= file
->private_data
;
2659 case LTTNG_KERNEL_ABI_OLD_CONTEXT
:
2661 /* Not implemented */
2664 case LTTNG_KERNEL_ABI_CONTEXT
:
2666 /* Not implemented */
2669 case LTTNG_KERNEL_ABI_OLD_ENABLE
:
2670 case LTTNG_KERNEL_ABI_ENABLE
:
2671 return lttng_event_enable(&event_recorder
->parent
);
2672 case LTTNG_KERNEL_ABI_OLD_DISABLE
:
2673 case LTTNG_KERNEL_ABI_DISABLE
:
2674 return lttng_event_disable(&event_recorder
->parent
);
2675 case LTTNG_KERNEL_ABI_FILTER
:
2677 case LTTNG_KERNEL_ABI_ADD_CALLSITE
:
2678 return lttng_event_add_callsite(&event_recorder
->parent
,
2679 (struct lttng_kernel_abi_event_callsite __user
*) arg
);
2681 return -ENOIOCTLCMD
;
2686 * lttng_event_recorder_enabler_ioctl - lttng syscall through ioctl
2692 * This ioctl implements lttng commands:
2693 * LTTNG_KERNEL_ABI_CONTEXT
2694 * Prepend a context field to each record of this event
2695 * LTTNG_KERNEL_ABI_ENABLE
2696 * Enable recording for this event (weak enable)
2697 * LTTNG_KERNEL_ABI_DISABLE
2698 * Disable recording for this event (strong disable)
2701 long lttng_event_recorder_enabler_ioctl(struct file
*file
, unsigned int cmd
, unsigned long arg
)
2703 struct lttng_event_enabler
*event_enabler
= file
->private_data
;
2706 case LTTNG_KERNEL_ABI_OLD_CONTEXT
:
2708 /* Not implemented */
2711 case LTTNG_KERNEL_ABI_CONTEXT
:
2713 /* Not implemented */
2716 case LTTNG_KERNEL_ABI_OLD_ENABLE
:
2717 case LTTNG_KERNEL_ABI_ENABLE
:
2718 return lttng_event_enabler_enable(event_enabler
);
2719 case LTTNG_KERNEL_ABI_OLD_DISABLE
:
2720 case LTTNG_KERNEL_ABI_DISABLE
:
2721 return lttng_event_enabler_disable(event_enabler
);
2722 case LTTNG_KERNEL_ABI_FILTER
:
2723 return lttng_event_enabler_attach_filter_bytecode(
2725 (struct lttng_kernel_abi_filter_bytecode __user
*) arg
);
2726 case LTTNG_KERNEL_ABI_ADD_CALLSITE
:
2729 return -ENOIOCTLCMD
;
2734 int lttng_event_recorder_event_release(struct inode
*inode
, struct file
*file
)
2736 struct lttng_kernel_event_recorder
*event
= file
->private_data
;
2739 fput(event
->chan
->priv
->parent
.file
);
2744 int lttng_event_recorder_enabler_release(struct inode
*inode
, struct file
*file
)
2746 struct lttng_event_enabler
*event_enabler
= file
->private_data
;
2749 fput(event_enabler
->chan
->priv
->parent
.file
);
2753 static const struct file_operations lttng_event_recorder_event_fops
= {
2754 .owner
= THIS_MODULE
,
2755 .release
= lttng_event_recorder_event_release
,
2756 .unlocked_ioctl
= lttng_event_recorder_event_ioctl
,
2757 #ifdef CONFIG_COMPAT
2758 .compat_ioctl
= lttng_event_recorder_event_ioctl
,
2762 static const struct file_operations lttng_event_recorder_enabler_fops
= {
2763 .owner
= THIS_MODULE
,
2764 .release
= lttng_event_recorder_enabler_release
,
2765 .unlocked_ioctl
= lttng_event_recorder_enabler_ioctl
,
2766 #ifdef CONFIG_COMPAT
2767 .compat_ioctl
= lttng_event_recorder_enabler_ioctl
,
2771 static int put_u64(uint64_t val
, unsigned long arg
)
2773 return put_user(val
, (uint64_t __user
*) arg
);
2776 static int put_u32(uint32_t val
, unsigned long arg
)
2778 return put_user(val
, (uint32_t __user
*) arg
);
2781 static long lttng_stream_ring_buffer_ioctl(struct file
*filp
,
2782 unsigned int cmd
, unsigned long arg
)
2784 struct lttng_kernel_ring_buffer
*buf
= filp
->private_data
;
2785 struct lttng_kernel_ring_buffer_channel
*chan
= buf
->backend
.chan
;
2786 const struct lttng_kernel_ring_buffer_config
*config
= &chan
->backend
.config
;
2787 const struct lttng_kernel_channel_buffer_ops
*ops
= chan
->backend
.priv_ops
;
2790 if (atomic_read(&chan
->record_disabled
))
2794 case LTTNG_KERNEL_ABI_RING_BUFFER_GET_TIMESTAMP_BEGIN
:
2798 ret
= ops
->priv
->timestamp_begin(config
, buf
, &ts
);
2801 return put_u64(ts
, arg
);
2803 case LTTNG_KERNEL_ABI_RING_BUFFER_GET_TIMESTAMP_END
:
2807 ret
= ops
->priv
->timestamp_end(config
, buf
, &ts
);
2810 return put_u64(ts
, arg
);
2812 case LTTNG_KERNEL_ABI_RING_BUFFER_GET_EVENTS_DISCARDED
:
2816 ret
= ops
->priv
->events_discarded(config
, buf
, &ed
);
2819 return put_u64(ed
, arg
);
2821 case LTTNG_KERNEL_ABI_RING_BUFFER_GET_CONTENT_SIZE
:
2825 ret
= ops
->priv
->content_size(config
, buf
, &cs
);
2828 return put_u64(cs
, arg
);
2830 case LTTNG_KERNEL_ABI_RING_BUFFER_GET_PACKET_SIZE
:
2834 ret
= ops
->priv
->packet_size(config
, buf
, &ps
);
2837 return put_u64(ps
, arg
);
2839 case LTTNG_KERNEL_ABI_RING_BUFFER_GET_STREAM_ID
:
2843 ret
= ops
->priv
->stream_id(config
, buf
, &si
);
2846 return put_u64(si
, arg
);
2848 case LTTNG_KERNEL_ABI_RING_BUFFER_GET_CURRENT_TIMESTAMP
:
2852 ret
= ops
->priv
->current_timestamp(config
, buf
, &ts
);
2855 return put_u64(ts
, arg
);
2857 case LTTNG_KERNEL_ABI_RING_BUFFER_GET_SEQ_NUM
:
2861 ret
= ops
->priv
->sequence_number(config
, buf
, &seq
);
2864 return put_u64(seq
, arg
);
2866 case LTTNG_KERNEL_ABI_RING_BUFFER_INSTANCE_ID
:
2870 ret
= ops
->priv
->instance_id(config
, buf
, &id
);
2873 return put_u64(id
, arg
);
2876 return lib_ring_buffer_file_operations
.unlocked_ioctl(filp
,
2884 #ifdef CONFIG_COMPAT
2885 static long lttng_stream_ring_buffer_compat_ioctl(struct file
*filp
,
2886 unsigned int cmd
, unsigned long arg
)
2888 struct lttng_kernel_ring_buffer
*buf
= filp
->private_data
;
2889 struct lttng_kernel_ring_buffer_channel
*chan
= buf
->backend
.chan
;
2890 const struct lttng_kernel_ring_buffer_config
*config
= &chan
->backend
.config
;
2891 const struct lttng_kernel_channel_buffer_ops
*ops
= chan
->backend
.priv_ops
;
2894 if (atomic_read(&chan
->record_disabled
))
2898 case LTTNG_KERNEL_ABI_RING_BUFFER_COMPAT_GET_TIMESTAMP_BEGIN
:
2902 ret
= ops
->priv
->timestamp_begin(config
, buf
, &ts
);
2905 return put_u64(ts
, arg
);
2907 case LTTNG_KERNEL_ABI_RING_BUFFER_COMPAT_GET_TIMESTAMP_END
:
2911 ret
= ops
->priv
->timestamp_end(config
, buf
, &ts
);
2914 return put_u64(ts
, arg
);
2916 case LTTNG_KERNEL_ABI_RING_BUFFER_COMPAT_GET_EVENTS_DISCARDED
:
2920 ret
= ops
->priv
->events_discarded(config
, buf
, &ed
);
2923 return put_u64(ed
, arg
);
2925 case LTTNG_KERNEL_ABI_RING_BUFFER_COMPAT_GET_CONTENT_SIZE
:
2929 ret
= ops
->priv
->content_size(config
, buf
, &cs
);
2932 return put_u64(cs
, arg
);
2934 case LTTNG_KERNEL_ABI_RING_BUFFER_COMPAT_GET_PACKET_SIZE
:
2938 ret
= ops
->priv
->packet_size(config
, buf
, &ps
);
2941 return put_u64(ps
, arg
);
2943 case LTTNG_KERNEL_ABI_RING_BUFFER_COMPAT_GET_STREAM_ID
:
2947 ret
= ops
->priv
->stream_id(config
, buf
, &si
);
2950 return put_u64(si
, arg
);
2952 case LTTNG_KERNEL_ABI_RING_BUFFER_GET_CURRENT_TIMESTAMP
:
2956 ret
= ops
->priv
->current_timestamp(config
, buf
, &ts
);
2959 return put_u64(ts
, arg
);
2961 case LTTNG_KERNEL_ABI_RING_BUFFER_COMPAT_GET_SEQ_NUM
:
2965 ret
= ops
->priv
->sequence_number(config
, buf
, &seq
);
2968 return put_u64(seq
, arg
);
2970 case LTTNG_KERNEL_ABI_RING_BUFFER_COMPAT_INSTANCE_ID
:
2974 ret
= ops
->priv
->instance_id(config
, buf
, &id
);
2977 return put_u64(id
, arg
);
2980 return lib_ring_buffer_file_operations
.compat_ioctl(filp
,
2987 #endif /* CONFIG_COMPAT */
2989 static void lttng_stream_override_ring_buffer_fops(void)
2991 lttng_stream_ring_buffer_file_operations
.owner
= THIS_MODULE
;
2992 lttng_stream_ring_buffer_file_operations
.open
=
2993 lib_ring_buffer_file_operations
.open
;
2994 lttng_stream_ring_buffer_file_operations
.release
=
2995 lib_ring_buffer_file_operations
.release
;
2996 lttng_stream_ring_buffer_file_operations
.poll
=
2997 lib_ring_buffer_file_operations
.poll
;
2998 lttng_stream_ring_buffer_file_operations
.splice_read
=
2999 lib_ring_buffer_file_operations
.splice_read
;
3000 lttng_stream_ring_buffer_file_operations
.mmap
=
3001 lib_ring_buffer_file_operations
.mmap
;
3002 lttng_stream_ring_buffer_file_operations
.unlocked_ioctl
=
3003 lttng_stream_ring_buffer_ioctl
;
3004 lttng_stream_ring_buffer_file_operations
.llseek
=
3005 lib_ring_buffer_file_operations
.llseek
;
3006 #ifdef CONFIG_COMPAT
3007 lttng_stream_ring_buffer_file_operations
.compat_ioctl
=
3008 lttng_stream_ring_buffer_compat_ioctl
;
3012 int __init
lttng_abi_init(void)
3016 wrapper_vmalloc_sync_mappings();
3019 ret
= lttng_tp_mempool_init();
3024 lttng_proc_dentry
= proc_create_data("lttng", S_IRUSR
| S_IWUSR
, NULL
,
3025 <tng_proc_ops
, NULL
);
3027 if (!lttng_proc_dentry
) {
3028 printk(KERN_ERR
"LTTng: Error creating control file\n");
3032 lttng_stream_override_ring_buffer_fops();
3036 lttng_tp_mempool_destroy();
3037 lttng_clock_unref();
3041 /* No __exit annotation because used by init error path too. */
3042 void lttng_abi_exit(void)
3044 lttng_tp_mempool_destroy();
3045 lttng_clock_unref();
3046 if (lttng_proc_dentry
)
3047 remove_proc_entry("lttng", NULL
);