1 /* SPDX-License-Identifier: (GPL-2.0-only or LGPL-2.1-only)
7 * Copyright (C) 2010-2012 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
9 * Mimic system calls for:
10 * - session creation, returns a file descriptor or failure.
11 * - channel creation, returns a file descriptor or failure.
12 * - Operates on a session file descriptor
13 * - Takes all channel options as parameters.
14 * - stream get, returns a file descriptor or failure.
15 * - Operates on a channel file descriptor.
16 * - stream notifier get, returns a file descriptor or failure.
17 * - Operates on a channel file descriptor.
18 * - event creation, returns a file descriptor or failure.
19 * - Operates on a channel file descriptor
20 * - Takes an event name as parameter
21 * - Takes an instrumentation source as parameter
22 * - e.g. tracepoints, dynamic_probes...
23 * - Takes instrumentation source specific arguments.
26 #include <asm/barrier.h>
27 #include <linux/module.h>
28 #include <linux/proc_fs.h>
29 #include <linux/anon_inodes.h>
30 #include <linux/file.h>
31 #include <linux/uaccess.h>
32 #include <linux/slab.h>
33 #include <linux/err.h>
34 #include <wrapper/vmalloc.h> /* for wrapper_vmalloc_sync_mappings() */
35 #include <ringbuffer/vfs.h>
36 #include <ringbuffer/backend.h>
37 #include <ringbuffer/frontend.h>
38 #include <wrapper/compiler_attributes.h>
39 #include <wrapper/poll.h>
40 #include <wrapper/file.h>
41 #include <wrapper/kref.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_buffer_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
)))
653 if (local_counter_read
.index
.number_dimensions
> LTTNG_KERNEL_ABI_COUNTER_DIMENSION_MAX
)
656 /* Cast all indexes into size_t. */
657 for (i
= 0; i
< local_counter_read
.index
.number_dimensions
; i
++)
658 indexes
[i
] = (size_t) local_counter_read
.index
.dimension_indexes
[i
];
659 cpu
= local_counter_read
.cpu
;
661 ret
= lttng_kernel_counter_read(counter
, indexes
, cpu
, &value
,
662 &overflow
, &underflow
);
665 local_counter_read
.value
.value
= value
;
666 local_counter_read
.value
.overflow
= overflow
;
667 local_counter_read
.value
.underflow
= underflow
;
669 if (copy_to_user(&ucounter_read
->value
, &local_counter_read
.value
,
670 sizeof(local_counter_read
.value
)))
675 case LTTNG_KERNEL_ABI_COUNTER_AGGREGATE
:
677 struct lttng_kernel_abi_counter_aggregate local_counter_aggregate
;
678 struct lttng_kernel_abi_counter_aggregate __user
*ucounter_aggregate
=
679 (struct lttng_kernel_abi_counter_aggregate __user
*) arg
;
680 bool overflow
, underflow
;
684 if (copy_from_user(&local_counter_aggregate
, ucounter_aggregate
,
685 sizeof(local_counter_aggregate
)))
687 if (validate_zeroed_padding(local_counter_aggregate
.padding
,
688 sizeof(local_counter_aggregate
.padding
)))
690 if (local_counter_aggregate
.index
.number_dimensions
> LTTNG_KERNEL_ABI_COUNTER_DIMENSION_MAX
)
693 /* Cast all indexes into size_t. */
694 for (i
= 0; i
< local_counter_aggregate
.index
.number_dimensions
; i
++)
695 indexes
[i
] = (size_t) local_counter_aggregate
.index
.dimension_indexes
[i
];
697 ret
= lttng_kernel_counter_aggregate(counter
, indexes
, &value
,
698 &overflow
, &underflow
);
701 local_counter_aggregate
.value
.value
= value
;
702 local_counter_aggregate
.value
.overflow
= overflow
;
703 local_counter_aggregate
.value
.underflow
= underflow
;
705 if (copy_to_user(&ucounter_aggregate
->value
, &local_counter_aggregate
.value
,
706 sizeof(local_counter_aggregate
.value
)))
711 case LTTNG_KERNEL_ABI_COUNTER_CLEAR
:
713 struct lttng_kernel_abi_counter_clear local_counter_clear
;
714 struct lttng_kernel_abi_counter_clear __user
*ucounter_clear
=
715 (struct lttng_kernel_abi_counter_clear __user
*) arg
;
717 if (copy_from_user(&local_counter_clear
, ucounter_clear
,
718 sizeof(local_counter_clear
)))
720 if (validate_zeroed_padding(local_counter_clear
.padding
,
721 sizeof(local_counter_clear
.padding
)))
723 if (local_counter_clear
.index
.number_dimensions
> LTTNG_KERNEL_ABI_COUNTER_DIMENSION_MAX
)
726 /* Cast all indexes into size_t. */
727 for (i
= 0; i
< local_counter_clear
.index
.number_dimensions
; i
++)
728 indexes
[i
] = (size_t) local_counter_clear
.index
.dimension_indexes
[i
];
730 return lttng_kernel_counter_clear(counter
, indexes
);
737 static const struct file_operations lttng_counter_fops
= {
738 .owner
= THIS_MODULE
,
739 .release
= lttng_counter_release
,
740 .unlocked_ioctl
= lttng_counter_ioctl
,
742 .compat_ioctl
= lttng_counter_ioctl
,
748 enum tracker_type
get_tracker_type(struct lttng_kernel_abi_tracker_args
*tracker
)
750 switch (tracker
->type
) {
751 case LTTNG_KERNEL_ABI_TRACKER_PID
:
753 case LTTNG_KERNEL_ABI_TRACKER_VPID
:
755 case LTTNG_KERNEL_ABI_TRACKER_UID
:
757 case LTTNG_KERNEL_ABI_TRACKER_VUID
:
759 case LTTNG_KERNEL_ABI_TRACKER_GID
:
761 case LTTNG_KERNEL_ABI_TRACKER_VGID
:
764 return TRACKER_UNKNOWN
;
769 * lttng_session_ioctl - lttng session fd ioctl
775 * This ioctl implements lttng commands:
776 * LTTNG_KERNEL_ABI_CHANNEL
777 * Returns a LTTng channel file descriptor
778 * LTTNG_KERNEL_ABI_ENABLE
779 * Enables tracing for a session (weak enable)
780 * LTTNG_KERNEL_ABI_DISABLE
781 * Disables tracing for a session (strong disable)
782 * LTTNG_KERNEL_ABI_METADATA
783 * Returns a LTTng metadata file descriptor
784 * LTTNG_KERNEL_ABI_SESSION_TRACK_PID
785 * Add PID to session PID tracker
786 * LTTNG_KERNEL_ABI_SESSION_UNTRACK_PID
787 * Remove PID from session PID tracker
788 * LTTNG_KERNEL_ABI_SESSION_TRACK_ID
790 * LTTNG_KERNEL_ABI_SESSION_UNTRACK_ID
791 * Remove ID from tracker
793 * The returned channel will be deleted when its file descriptor is closed.
796 long lttng_session_ioctl(struct file
*file
, unsigned int cmd
, unsigned long arg
)
798 struct lttng_kernel_session
*session
= file
->private_data
;
799 struct lttng_kernel_abi_channel chan_param
;
800 struct lttng_kernel_abi_old_channel old_chan_param
;
803 * Handle backward compatibility. OLD commands have wrong
804 * directions, replace them by the correct direction.
807 case LTTNG_KERNEL_ABI_OLD_SESSION_TRACK_PID
:
808 cmd
= LTTNG_KERNEL_ABI_SESSION_TRACK_PID
;
810 case LTTNG_KERNEL_ABI_OLD_SESSION_UNTRACK_PID
:
811 cmd
= LTTNG_KERNEL_ABI_SESSION_UNTRACK_PID
;
813 case LTTNG_KERNEL_ABI_OLD_SESSION_TRACK_ID
:
814 cmd
= LTTNG_KERNEL_ABI_SESSION_TRACK_ID
;
816 case LTTNG_KERNEL_ABI_OLD_SESSION_UNTRACK_ID
:
817 cmd
= LTTNG_KERNEL_ABI_SESSION_UNTRACK_ID
;
819 case LTTNG_KERNEL_ABI_OLD_SESSION_LIST_TRACKER_IDS
:
820 cmd
= LTTNG_KERNEL_ABI_SESSION_LIST_TRACKER_IDS
;
822 case LTTNG_KERNEL_ABI_OLD_SESSION_SET_NAME
:
823 cmd
= LTTNG_KERNEL_ABI_SESSION_SET_NAME
;
825 case LTTNG_KERNEL_ABI_OLD_SESSION_SET_CREATION_TIME
:
826 cmd
= LTTNG_KERNEL_ABI_SESSION_SET_CREATION_TIME
;
834 case LTTNG_KERNEL_ABI_OLD_CHANNEL
:
836 if (copy_from_user(&old_chan_param
,
837 (struct lttng_kernel_abi_old_channel __user
*) arg
,
838 sizeof(struct lttng_kernel_abi_old_channel
)))
840 chan_param
.overwrite
= old_chan_param
.overwrite
;
841 chan_param
.subbuf_size
= old_chan_param
.subbuf_size
;
842 chan_param
.num_subbuf
= old_chan_param
.num_subbuf
;
843 chan_param
.switch_timer_interval
= old_chan_param
.switch_timer_interval
;
844 chan_param
.read_timer_interval
= old_chan_param
.read_timer_interval
;
845 chan_param
.output
= old_chan_param
.output
;
847 return lttng_abi_create_channel(file
, &chan_param
,
850 case LTTNG_KERNEL_ABI_CHANNEL
:
852 if (copy_from_user(&chan_param
,
853 (struct lttng_kernel_abi_channel __user
*) arg
,
854 sizeof(struct lttng_kernel_abi_channel
)))
856 return lttng_abi_create_channel(file
, &chan_param
,
859 case LTTNG_KERNEL_ABI_OLD_SESSION_START
:
860 case LTTNG_KERNEL_ABI_OLD_ENABLE
:
861 case LTTNG_KERNEL_ABI_SESSION_START
:
862 case LTTNG_KERNEL_ABI_ENABLE
:
863 return lttng_session_enable(session
);
864 case LTTNG_KERNEL_ABI_OLD_SESSION_STOP
:
865 case LTTNG_KERNEL_ABI_OLD_DISABLE
:
866 case LTTNG_KERNEL_ABI_SESSION_STOP
:
867 case LTTNG_KERNEL_ABI_DISABLE
:
868 return lttng_session_disable(session
);
869 case LTTNG_KERNEL_ABI_OLD_METADATA
:
871 if (copy_from_user(&old_chan_param
,
872 (struct lttng_kernel_abi_old_channel __user
*) arg
,
873 sizeof(struct lttng_kernel_abi_old_channel
)))
875 chan_param
.overwrite
= old_chan_param
.overwrite
;
876 chan_param
.subbuf_size
= old_chan_param
.subbuf_size
;
877 chan_param
.num_subbuf
= old_chan_param
.num_subbuf
;
878 chan_param
.switch_timer_interval
= old_chan_param
.switch_timer_interval
;
879 chan_param
.read_timer_interval
= old_chan_param
.read_timer_interval
;
880 chan_param
.output
= old_chan_param
.output
;
882 return lttng_abi_create_channel(file
, &chan_param
,
885 case LTTNG_KERNEL_ABI_METADATA
:
887 if (copy_from_user(&chan_param
,
888 (struct lttng_kernel_abi_channel __user
*) arg
,
889 sizeof(struct lttng_kernel_abi_channel
)))
891 return lttng_abi_create_channel(file
, &chan_param
,
894 case LTTNG_KERNEL_ABI_SESSION_TRACK_PID
:
895 return lttng_session_track_id(session
, TRACKER_PID
, (int) arg
);
896 case LTTNG_KERNEL_ABI_SESSION_UNTRACK_PID
:
897 return lttng_session_untrack_id(session
, TRACKER_PID
, (int) arg
);
898 case LTTNG_KERNEL_ABI_SESSION_TRACK_ID
:
900 struct lttng_kernel_abi_tracker_args tracker
;
901 enum tracker_type tracker_type
;
903 if (copy_from_user(&tracker
,
904 (struct lttng_kernel_abi_tracker_args __user
*) arg
,
905 sizeof(struct lttng_kernel_abi_tracker_args
)))
907 tracker_type
= get_tracker_type(&tracker
);
908 if (tracker_type
== TRACKER_UNKNOWN
)
910 return lttng_session_track_id(session
, tracker_type
, tracker
.id
);
912 case LTTNG_KERNEL_ABI_SESSION_UNTRACK_ID
:
914 struct lttng_kernel_abi_tracker_args tracker
;
915 enum tracker_type tracker_type
;
917 if (copy_from_user(&tracker
,
918 (struct lttng_kernel_abi_tracker_args __user
*) arg
,
919 sizeof(struct lttng_kernel_abi_tracker_args
)))
921 tracker_type
= get_tracker_type(&tracker
);
922 if (tracker_type
== TRACKER_UNKNOWN
)
924 return lttng_session_untrack_id(session
, tracker_type
,
927 case LTTNG_KERNEL_ABI_SESSION_LIST_TRACKER_PIDS
:
928 return lttng_session_list_tracker_ids(session
, TRACKER_PID
);
929 case LTTNG_KERNEL_ABI_SESSION_LIST_TRACKER_IDS
:
931 struct lttng_kernel_abi_tracker_args tracker
;
932 enum tracker_type tracker_type
;
934 if (copy_from_user(&tracker
,
935 (struct lttng_kernel_abi_tracker_args __user
*) arg
,
936 sizeof(struct lttng_kernel_abi_tracker_args
)))
938 tracker_type
= get_tracker_type(&tracker
);
939 if (tracker_type
== TRACKER_UNKNOWN
)
941 return lttng_session_list_tracker_ids(session
, tracker_type
);
943 case LTTNG_KERNEL_ABI_SESSION_METADATA_REGEN
:
944 return lttng_session_metadata_regenerate(session
);
945 case LTTNG_KERNEL_ABI_SESSION_STATEDUMP
:
946 return lttng_session_statedump(session
);
947 case LTTNG_KERNEL_ABI_SESSION_SET_NAME
:
949 struct lttng_kernel_abi_session_name name
;
951 if (copy_from_user(&name
,
952 (struct lttng_kernel_abi_session_name __user
*) arg
,
953 sizeof(struct lttng_kernel_abi_session_name
)))
955 return lttng_abi_session_set_name(session
, &name
);
957 case LTTNG_KERNEL_ABI_SESSION_SET_CREATION_TIME
:
959 struct lttng_kernel_abi_session_creation_time time
;
961 if (copy_from_user(&time
,
962 (struct lttng_kernel_abi_session_creation_time __user
*) arg
,
963 sizeof(struct lttng_kernel_abi_session_creation_time
)))
965 return lttng_abi_session_set_creation_time(session
, &time
);
973 * Called when the last file reference is dropped.
975 * Big fat note: channels and events are invariant for the whole session after
976 * their creation. So this session destruction also destroys all channel and
977 * event structures specific to this session (they are not destroyed when their
978 * individual file is released).
981 int lttng_session_release(struct inode
*inode
, struct file
*file
)
983 struct lttng_kernel_session
*session
= file
->private_data
;
986 lttng_session_destroy(session
);
990 static const struct file_operations lttng_session_fops
= {
991 .owner
= THIS_MODULE
,
992 .release
= lttng_session_release
,
993 .unlocked_ioctl
= lttng_session_ioctl
,
995 .compat_ioctl
= lttng_session_ioctl
,
1000 * When encountering empty buffer, flush current sub-buffer if non-empty
1001 * and retry (if new data available to read after flush).
1004 ssize_t
lttng_event_notifier_group_notif_read(struct file
*filp
, char __user
*user_buf
,
1005 size_t count
, loff_t
*ppos
)
1007 struct lttng_event_notifier_group
*event_notifier_group
= filp
->private_data
;
1008 struct lttng_kernel_ring_buffer_channel
*chan
= event_notifier_group
->chan
;
1009 struct lttng_kernel_ring_buffer
*buf
= event_notifier_group
->buf
;
1010 ssize_t read_count
= 0, len
;
1014 if (!lttng_access_ok(VERIFY_WRITE
, user_buf
, count
))
1017 /* Finish copy of previous record */
1020 len
= chan
->iter
.len_left
;
1021 read_offset
= *ppos
;
1026 while (read_count
< count
) {
1027 size_t copy_len
, space_left
;
1029 len
= lib_ring_buffer_get_next_record(chan
, buf
);
1033 * Check if buffer is finalized (end of file).
1035 if (len
== -ENODATA
) {
1036 /* A 0 read_count will tell about end of file */
1039 if (filp
->f_flags
& O_NONBLOCK
) {
1041 read_count
= -EAGAIN
;
1047 * No data available at the moment, return what
1054 * Wait for returned len to be >= 0 or -ENODATA.
1056 error
= wait_event_interruptible(
1057 event_notifier_group
->read_wait
,
1058 ((len
= lib_ring_buffer_get_next_record(
1059 chan
, buf
)), len
!= -EAGAIN
));
1060 CHAN_WARN_ON(chan
, len
== -EBUSY
);
1065 CHAN_WARN_ON(chan
, len
< 0 && len
!= -ENODATA
);
1069 read_offset
= buf
->iter
.read_offset
;
1071 space_left
= count
- read_count
;
1072 if (len
<= space_left
) {
1074 chan
->iter
.len_left
= 0;
1077 copy_len
= space_left
;
1078 chan
->iter
.len_left
= len
- copy_len
;
1079 *ppos
= read_offset
+ copy_len
;
1081 if (__lib_ring_buffer_copy_to_user(&buf
->backend
, read_offset
,
1082 &user_buf
[read_count
],
1085 * Leave the len_left and ppos values at their current
1086 * state, as we currently have a valid event to read.
1090 read_count
+= copy_len
;
1096 chan
->iter
.len_left
= 0;
1100 lib_ring_buffer_put_current_record(buf
);
1105 * If the ring buffer is non empty (even just a partial subbuffer), return that
1106 * there is data available. Perform a ring buffer flush if we encounter a
1107 * non-empty ring buffer which does not have any consumeable subbuffer available.
1110 unsigned int lttng_event_notifier_group_notif_poll(struct file
*filp
,
1113 unsigned int mask
= 0;
1114 struct lttng_event_notifier_group
*event_notifier_group
= filp
->private_data
;
1115 struct lttng_kernel_ring_buffer_channel
*chan
= event_notifier_group
->chan
;
1116 struct lttng_kernel_ring_buffer
*buf
= event_notifier_group
->buf
;
1117 const struct lttng_kernel_ring_buffer_config
*config
= &chan
->backend
.config
;
1118 int finalized
, disabled
;
1119 unsigned long consumed
, offset
;
1120 size_t subbuffer_header_size
= config
->cb
.subbuffer_header_size();
1122 if (filp
->f_mode
& FMODE_READ
) {
1123 poll_wait_set_exclusive(wait
);
1124 poll_wait(filp
, &event_notifier_group
->read_wait
, wait
);
1126 finalized
= lib_ring_buffer_is_finalized(config
, buf
);
1127 disabled
= lib_ring_buffer_channel_is_disabled(chan
);
1130 * lib_ring_buffer_is_finalized() contains a smp_rmb() ordering
1131 * finalized load before offsets loads.
1133 WARN_ON(atomic_long_read(&buf
->active_readers
) != 1);
1138 offset
= lib_ring_buffer_get_offset(config
, buf
);
1139 consumed
= lib_ring_buffer_get_consumed(config
, buf
);
1142 * If there is no buffer available to consume.
1144 if (subbuf_trunc(offset
, chan
) - subbuf_trunc(consumed
, chan
) == 0) {
1146 * If there is a non-empty subbuffer, flush and try again.
1148 if (subbuf_offset(offset
, chan
) > subbuffer_header_size
) {
1149 lib_ring_buffer_switch_remote(buf
);
1157 * The memory barriers
1158 * __wait_event()/wake_up_interruptible() take
1159 * care of "raw_spin_is_locked" memory ordering.
1161 if (raw_spin_is_locked(&buf
->raw_tick_nohz_spinlock
))
1167 if (subbuf_trunc(offset
, chan
) - subbuf_trunc(consumed
, chan
)
1168 >= chan
->backend
.buf_size
)
1169 return POLLPRI
| POLLRDBAND
;
1171 return POLLIN
| POLLRDNORM
;
1179 * lttng_event_notifier_group_notif_open - event_notifier ring buffer open file operation
1180 * @inode: opened inode
1181 * @file: opened file
1183 * Open implementation. Makes sure only one open instance of a buffer is
1184 * done at a given moment.
1186 static int lttng_event_notifier_group_notif_open(struct inode
*inode
, struct file
*file
)
1188 struct lttng_event_notifier_group
*event_notifier_group
= inode
->i_private
;
1189 struct lttng_kernel_ring_buffer
*buf
= event_notifier_group
->buf
;
1191 file
->private_data
= event_notifier_group
;
1192 return lib_ring_buffer_open(inode
, file
, buf
);
1196 * lttng_event_notifier_group_notif_release - event_notifier ring buffer release file operation
1197 * @inode: opened inode
1198 * @file: opened file
1200 * Release implementation.
1202 static int lttng_event_notifier_group_notif_release(struct inode
*inode
, struct file
*file
)
1204 struct lttng_event_notifier_group
*event_notifier_group
= file
->private_data
;
1205 struct lttng_kernel_ring_buffer
*buf
= event_notifier_group
->buf
;
1208 ret
= lib_ring_buffer_release(inode
, file
, buf
);
1211 fput(event_notifier_group
->file
);
1215 static const struct file_operations lttng_event_notifier_group_notif_fops
= {
1216 .owner
= THIS_MODULE
,
1217 .open
= lttng_event_notifier_group_notif_open
,
1218 .release
= lttng_event_notifier_group_notif_release
,
1219 .read
= lttng_event_notifier_group_notif_read
,
1220 .poll
= lttng_event_notifier_group_notif_poll
,
1224 * lttng_metadata_ring_buffer_poll - LTTng ring buffer poll file operation
1228 * Handles the poll operations for the metadata channels.
1231 unsigned int lttng_metadata_ring_buffer_poll(struct file
*filp
,
1234 struct lttng_metadata_stream
*stream
= filp
->private_data
;
1235 struct lttng_kernel_ring_buffer
*buf
= stream
->priv
;
1237 unsigned int mask
= 0;
1239 if (filp
->f_mode
& FMODE_READ
) {
1240 poll_wait_set_exclusive(wait
);
1241 poll_wait(filp
, &stream
->read_wait
, wait
);
1243 finalized
= stream
->finalized
;
1246 * lib_ring_buffer_is_finalized() contains a smp_rmb()
1247 * ordering finalized load before offsets loads.
1249 WARN_ON(atomic_long_read(&buf
->active_readers
) != 1);
1254 mutex_lock(&stream
->metadata_cache
->lock
);
1255 if (stream
->metadata_cache
->metadata_written
>
1256 stream
->metadata_out
)
1258 mutex_unlock(&stream
->metadata_cache
->lock
);
1265 void lttng_metadata_ring_buffer_ioctl_put_next_subbuf(struct file
*filp
,
1266 unsigned int cmd
, unsigned long arg
)
1268 struct lttng_metadata_stream
*stream
= filp
->private_data
;
1270 stream
->metadata_out
= stream
->metadata_in
;
1274 * Reset the counter of how much metadata has been consumed to 0. That way,
1275 * the consumer receives the content of the metadata cache unchanged. This is
1276 * different from the metadata_regenerate where the offset from epoch is
1277 * resampled, here we want the exact same content as the last time the metadata
1278 * was generated. This command is only possible if all the metadata written
1279 * in the cache has been output to the metadata stream to avoid corrupting the
1282 * Return 0 on success, a negative value on error.
1285 int lttng_metadata_cache_dump(struct lttng_metadata_stream
*stream
)
1288 struct lttng_metadata_cache
*cache
= stream
->metadata_cache
;
1290 mutex_lock(&cache
->lock
);
1291 if (stream
->metadata_out
!= cache
->metadata_written
) {
1295 stream
->metadata_out
= 0;
1296 stream
->metadata_in
= 0;
1297 wake_up_interruptible(&stream
->read_wait
);
1301 mutex_unlock(&cache
->lock
);
1306 long lttng_metadata_ring_buffer_ioctl(struct file
*filp
,
1307 unsigned int cmd
, unsigned long arg
)
1310 struct lttng_metadata_stream
*stream
= filp
->private_data
;
1311 struct lttng_kernel_ring_buffer
*buf
= stream
->priv
;
1312 unsigned int rb_cmd
;
1315 if (cmd
== LTTNG_KERNEL_ABI_RING_BUFFER_GET_NEXT_SUBBUF_METADATA_CHECK
)
1316 rb_cmd
= LTTNG_KERNEL_ABI_RING_BUFFER_GET_NEXT_SUBBUF
;
1321 case LTTNG_KERNEL_ABI_RING_BUFFER_GET_NEXT_SUBBUF
:
1323 struct lttng_metadata_stream
*stream
= filp
->private_data
;
1324 struct lttng_kernel_ring_buffer
*buf
= stream
->priv
;
1325 struct lttng_kernel_ring_buffer_channel
*chan
= buf
->backend
.chan
;
1327 ret
= lttng_metadata_output_channel(stream
, chan
, NULL
);
1329 lib_ring_buffer_switch_slow(buf
, SWITCH_ACTIVE
);
1335 case LTTNG_KERNEL_ABI_RING_BUFFER_GET_SUBBUF
:
1338 * Random access is not allowed for metadata channel.
1342 case LTTNG_KERNEL_ABI_RING_BUFFER_FLUSH_EMPTY
:
1344 case LTTNG_KERNEL_ABI_RING_BUFFER_FLUSH
:
1346 struct lttng_metadata_stream
*stream
= filp
->private_data
;
1347 struct lttng_kernel_ring_buffer
*buf
= stream
->priv
;
1348 struct lttng_kernel_ring_buffer_channel
*chan
= buf
->backend
.chan
;
1351 * Before doing the actual ring buffer flush, write up to one
1352 * packet of metadata in the ring buffer.
1354 ret
= lttng_metadata_output_channel(stream
, chan
, NULL
);
1359 case LTTNG_KERNEL_ABI_RING_BUFFER_GET_METADATA_VERSION
:
1361 struct lttng_metadata_stream
*stream
= filp
->private_data
;
1363 return put_u64(stream
->version
, arg
);
1365 case LTTNG_KERNEL_ABI_RING_BUFFER_METADATA_CACHE_DUMP
:
1367 struct lttng_metadata_stream
*stream
= filp
->private_data
;
1369 return lttng_metadata_cache_dump(stream
);
1371 case LTTNG_KERNEL_ABI_RING_BUFFER_GET_NEXT_SUBBUF_METADATA_CHECK
:
1373 struct lttng_metadata_stream
*stream
= filp
->private_data
;
1374 struct lttng_kernel_ring_buffer
*buf
= stream
->priv
;
1375 struct lttng_kernel_ring_buffer_channel
*chan
= buf
->backend
.chan
;
1377 ret
= lttng_metadata_output_channel(stream
, chan
, &coherent
);
1379 lib_ring_buffer_switch_slow(buf
, SWITCH_ACTIVE
);
1381 } else if (ret
< 0) {
1389 /* PUT_SUBBUF is the one from lib ring buffer, unmodified. */
1391 /* Performing lib ring buffer ioctl after our own. */
1392 ret
= lib_ring_buffer_ioctl(filp
, rb_cmd
, arg
, buf
);
1397 case LTTNG_KERNEL_ABI_RING_BUFFER_PUT_NEXT_SUBBUF
:
1399 lttng_metadata_ring_buffer_ioctl_put_next_subbuf(filp
,
1403 case LTTNG_KERNEL_ABI_RING_BUFFER_GET_NEXT_SUBBUF_METADATA_CHECK
:
1405 return put_u32(coherent
, arg
);
1414 #ifdef CONFIG_COMPAT
1416 long lttng_metadata_ring_buffer_compat_ioctl(struct file
*filp
,
1417 unsigned int cmd
, unsigned long arg
)
1420 struct lttng_metadata_stream
*stream
= filp
->private_data
;
1421 struct lttng_kernel_ring_buffer
*buf
= stream
->priv
;
1422 unsigned int rb_cmd
;
1425 if (cmd
== LTTNG_KERNEL_ABI_RING_BUFFER_GET_NEXT_SUBBUF_METADATA_CHECK
)
1426 rb_cmd
= LTTNG_KERNEL_ABI_RING_BUFFER_GET_NEXT_SUBBUF
;
1431 case LTTNG_KERNEL_ABI_RING_BUFFER_GET_NEXT_SUBBUF
:
1433 struct lttng_metadata_stream
*stream
= filp
->private_data
;
1434 struct lttng_kernel_ring_buffer
*buf
= stream
->priv
;
1435 struct lttng_kernel_ring_buffer_channel
*chan
= buf
->backend
.chan
;
1437 ret
= lttng_metadata_output_channel(stream
, chan
, NULL
);
1439 lib_ring_buffer_switch_slow(buf
, SWITCH_ACTIVE
);
1445 case LTTNG_KERNEL_ABI_RING_BUFFER_GET_SUBBUF
:
1448 * Random access is not allowed for metadata channel.
1452 case LTTNG_KERNEL_ABI_RING_BUFFER_FLUSH_EMPTY
:
1454 case LTTNG_KERNEL_ABI_RING_BUFFER_FLUSH
:
1456 struct lttng_metadata_stream
*stream
= filp
->private_data
;
1457 struct lttng_kernel_ring_buffer
*buf
= stream
->priv
;
1458 struct lttng_kernel_ring_buffer_channel
*chan
= buf
->backend
.chan
;
1461 * Before doing the actual ring buffer flush, write up to one
1462 * packet of metadata in the ring buffer.
1464 ret
= lttng_metadata_output_channel(stream
, chan
, NULL
);
1469 case LTTNG_KERNEL_ABI_RING_BUFFER_GET_METADATA_VERSION
:
1471 struct lttng_metadata_stream
*stream
= filp
->private_data
;
1473 return put_u64(stream
->version
, arg
);
1475 case LTTNG_KERNEL_ABI_RING_BUFFER_METADATA_CACHE_DUMP
:
1477 struct lttng_metadata_stream
*stream
= filp
->private_data
;
1479 return lttng_metadata_cache_dump(stream
);
1481 case LTTNG_KERNEL_ABI_RING_BUFFER_GET_NEXT_SUBBUF_METADATA_CHECK
:
1483 struct lttng_metadata_stream
*stream
= filp
->private_data
;
1484 struct lttng_kernel_ring_buffer
*buf
= stream
->priv
;
1485 struct lttng_kernel_ring_buffer_channel
*chan
= buf
->backend
.chan
;
1487 ret
= lttng_metadata_output_channel(stream
, chan
, &coherent
);
1489 lib_ring_buffer_switch_slow(buf
, SWITCH_ACTIVE
);
1491 } else if (ret
< 0) {
1499 /* PUT_SUBBUF is the one from lib ring buffer, unmodified. */
1501 /* Performing lib ring buffer ioctl after our own. */
1502 ret
= lib_ring_buffer_compat_ioctl(filp
, rb_cmd
, arg
, buf
);
1507 case LTTNG_KERNEL_ABI_RING_BUFFER_PUT_NEXT_SUBBUF
:
1509 lttng_metadata_ring_buffer_ioctl_put_next_subbuf(filp
,
1513 case LTTNG_KERNEL_ABI_RING_BUFFER_GET_NEXT_SUBBUF_METADATA_CHECK
:
1515 return put_u32(coherent
, arg
);
1526 * This is not used by anonymous file descriptors. This code is left
1527 * there if we ever want to implement an inode with open() operation.
1530 int lttng_metadata_ring_buffer_open(struct inode
*inode
, struct file
*file
)
1532 struct lttng_metadata_stream
*stream
= inode
->i_private
;
1533 struct lttng_kernel_ring_buffer
*buf
= stream
->priv
;
1535 file
->private_data
= buf
;
1537 * Since life-time of metadata cache differs from that of
1538 * session, we need to keep our own reference on the transport.
1540 if (!try_module_get(stream
->transport
->owner
)) {
1541 printk(KERN_WARNING
"LTTng: Can't lock transport module.\n");
1544 return lib_ring_buffer_open(inode
, file
, buf
);
1548 int lttng_metadata_ring_buffer_release(struct inode
*inode
, struct file
*file
)
1550 struct lttng_metadata_stream
*stream
= file
->private_data
;
1551 struct lttng_kernel_ring_buffer
*buf
= stream
->priv
;
1553 mutex_lock(&stream
->metadata_cache
->lock
);
1554 list_del(&stream
->list
);
1555 mutex_unlock(&stream
->metadata_cache
->lock
);
1556 kref_put(&stream
->metadata_cache
->refcount
, metadata_cache_destroy
);
1557 module_put(stream
->transport
->owner
);
1559 return lib_ring_buffer_release(inode
, file
, buf
);
1563 ssize_t
lttng_metadata_ring_buffer_splice_read(struct file
*in
, loff_t
*ppos
,
1564 struct pipe_inode_info
*pipe
, size_t len
,
1567 struct lttng_metadata_stream
*stream
= in
->private_data
;
1568 struct lttng_kernel_ring_buffer
*buf
= stream
->priv
;
1570 return lib_ring_buffer_splice_read(in
, ppos
, pipe
, len
,
1575 int lttng_metadata_ring_buffer_mmap(struct file
*filp
,
1576 struct vm_area_struct
*vma
)
1578 struct lttng_metadata_stream
*stream
= filp
->private_data
;
1579 struct lttng_kernel_ring_buffer
*buf
= stream
->priv
;
1581 return lib_ring_buffer_mmap(filp
, vma
, buf
);
1585 const struct file_operations lttng_metadata_ring_buffer_file_operations
= {
1586 .owner
= THIS_MODULE
,
1587 .open
= lttng_metadata_ring_buffer_open
,
1588 .release
= lttng_metadata_ring_buffer_release
,
1589 .poll
= lttng_metadata_ring_buffer_poll
,
1590 .splice_read
= lttng_metadata_ring_buffer_splice_read
,
1591 .mmap
= lttng_metadata_ring_buffer_mmap
,
1592 .unlocked_ioctl
= lttng_metadata_ring_buffer_ioctl
,
1593 .llseek
= vfs_lib_ring_buffer_no_llseek
,
1594 #ifdef CONFIG_COMPAT
1595 .compat_ioctl
= lttng_metadata_ring_buffer_compat_ioctl
,
1600 int lttng_abi_create_stream_fd(struct file
*channel_file
, void *stream_priv
,
1601 const struct file_operations
*fops
, const char *name
)
1604 struct file
*stream_file
;
1606 stream_fd
= lttng_get_unused_fd();
1607 if (stream_fd
< 0) {
1611 stream_file
= anon_inode_getfile(name
, fops
, stream_priv
, O_RDWR
);
1612 if (IS_ERR(stream_file
)) {
1613 ret
= PTR_ERR(stream_file
);
1617 * OPEN_FMODE, called within anon_inode_getfile/alloc_file, don't honor
1618 * FMODE_LSEEK, FMODE_PREAD nor FMODE_PWRITE. We need to read from this
1619 * file descriptor, so we set FMODE_PREAD here.
1621 stream_file
->f_mode
|= FMODE_PREAD
;
1622 fd_install(stream_fd
, stream_file
);
1624 * The stream holds a reference to the channel within the generic ring
1625 * buffer library, so no need to hold a refcount on the channel and
1626 * session files here.
1631 put_unused_fd(stream_fd
);
1637 int lttng_abi_open_stream(struct file
*channel_file
)
1639 struct lttng_kernel_channel_buffer
*channel
= channel_file
->private_data
;
1640 struct lttng_kernel_ring_buffer
*buf
;
1644 buf
= channel
->ops
->priv
->buffer_read_open(channel
->priv
->rb_chan
);
1649 ret
= lttng_abi_create_stream_fd(channel_file
, stream_priv
,
1650 <tng_stream_ring_buffer_file_operations
,
1658 channel
->ops
->priv
->buffer_read_close(buf
);
1663 int lttng_abi_open_metadata_stream(struct file
*channel_file
)
1665 struct lttng_kernel_channel_buffer
*channel
= channel_file
->private_data
;
1666 struct lttng_kernel_session
*session
= channel
->parent
.session
;
1667 struct lttng_kernel_ring_buffer
*buf
;
1669 struct lttng_metadata_stream
*metadata_stream
;
1672 buf
= channel
->ops
->priv
->buffer_read_open(channel
->priv
->rb_chan
);
1676 metadata_stream
= kzalloc(sizeof(struct lttng_metadata_stream
),
1678 if (!metadata_stream
) {
1682 metadata_stream
->metadata_cache
= session
->priv
->metadata_cache
;
1683 init_waitqueue_head(&metadata_stream
->read_wait
);
1684 metadata_stream
->priv
= buf
;
1685 stream_priv
= metadata_stream
;
1686 metadata_stream
->transport
= channel
->priv
->transport
;
1687 /* Initial state is an empty metadata, considered as incoherent. */
1688 metadata_stream
->coherent
= false;
1691 * Since life-time of metadata cache differs from that of
1692 * session, we need to keep our own reference on the transport.
1694 if (!try_module_get(metadata_stream
->transport
->owner
)) {
1695 printk(KERN_WARNING
"LTTng: Can't lock transport module.\n");
1700 if (!lttng_kref_get(&session
->priv
->metadata_cache
->refcount
)) {
1705 ret
= lttng_abi_create_stream_fd(channel_file
, stream_priv
,
1706 <tng_metadata_ring_buffer_file_operations
,
1707 "[lttng_metadata_stream]");
1711 mutex_lock(&session
->priv
->metadata_cache
->lock
);
1712 list_add(&metadata_stream
->list
,
1713 &session
->priv
->metadata_cache
->metadata_stream
);
1714 mutex_unlock(&session
->priv
->metadata_cache
->lock
);
1718 kref_put(&session
->priv
->metadata_cache
->refcount
, metadata_cache_destroy
);
1720 module_put(metadata_stream
->transport
->owner
);
1722 kfree(metadata_stream
);
1724 channel
->ops
->priv
->buffer_read_close(buf
);
1729 int lttng_abi_open_event_notifier_group_stream(struct file
*notif_file
)
1731 struct lttng_event_notifier_group
*event_notifier_group
= notif_file
->private_data
;
1732 struct lttng_kernel_ring_buffer_channel
*chan
= event_notifier_group
->chan
;
1733 struct lttng_kernel_ring_buffer
*buf
;
1737 buf
= event_notifier_group
->ops
->priv
->buffer_read_open(chan
);
1741 /* The event_notifier notification fd holds a reference on the event_notifier group */
1742 if (!atomic_long_add_unless(¬if_file
->f_count
, 1, LONG_MAX
)) {
1744 goto refcount_error
;
1746 event_notifier_group
->buf
= buf
;
1747 stream_priv
= event_notifier_group
;
1748 ret
= lttng_abi_create_stream_fd(notif_file
, stream_priv
,
1749 <tng_event_notifier_group_notif_fops
,
1750 "[lttng_event_notifier_stream]");
1757 atomic_long_dec(¬if_file
->f_count
);
1759 event_notifier_group
->ops
->priv
->buffer_read_close(buf
);
1764 int lttng_abi_validate_event_param(struct lttng_kernel_abi_event
*event_param
)
1766 /* Limit ABI to implemented features. */
1767 switch (event_param
->instrumentation
) {
1768 case LTTNG_KERNEL_ABI_SYSCALL
:
1769 switch (event_param
->u
.syscall
.entryexit
) {
1770 case LTTNG_KERNEL_ABI_SYSCALL_ENTRY
:
1772 case LTTNG_KERNEL_ABI_SYSCALL_EXIT
:
1774 case LTTNG_KERNEL_ABI_SYSCALL_ENTRYEXIT
:
1779 switch (event_param
->u
.syscall
.abi
) {
1780 case LTTNG_KERNEL_ABI_SYSCALL_ABI_ALL
:
1785 switch (event_param
->u
.syscall
.match
) {
1786 case LTTNG_KERNEL_ABI_SYSCALL_MATCH_NAME
:
1793 case LTTNG_KERNEL_ABI_KRETPROBE
:
1794 switch (event_param
->u
.kretprobe
.entryexit
) {
1795 case LTTNG_KERNEL_ABI_SYSCALL_ENTRYEXIT
:
1797 case LTTNG_KERNEL_ABI_SYSCALL_ENTRY
:
1799 case LTTNG_KERNEL_ABI_SYSCALL_EXIT
:
1806 case LTTNG_KERNEL_ABI_TRACEPOINT
:
1808 case LTTNG_KERNEL_ABI_KPROBE
:
1810 case LTTNG_KERNEL_ABI_UPROBE
:
1813 case LTTNG_KERNEL_ABI_FUNCTION
:
1815 case LTTNG_KERNEL_ABI_NOOP
:
1824 int lttng_abi_create_event(struct file
*channel_file
,
1825 struct lttng_kernel_abi_event
*event_param
)
1827 const struct file_operations
*fops
;
1828 struct lttng_kernel_channel_buffer
*channel
= channel_file
->private_data
;
1830 struct file
*event_file
;
1833 event_param
->name
[LTTNG_KERNEL_ABI_SYM_NAME_LEN
- 1] = '\0';
1834 switch (event_param
->instrumentation
) {
1835 case LTTNG_KERNEL_ABI_KRETPROBE
:
1836 event_param
->u
.kretprobe
.symbol_name
[LTTNG_KERNEL_ABI_SYM_NAME_LEN
- 1] = '\0';
1838 case LTTNG_KERNEL_ABI_KPROBE
:
1839 event_param
->u
.kprobe
.symbol_name
[LTTNG_KERNEL_ABI_SYM_NAME_LEN
- 1] = '\0';
1841 case LTTNG_KERNEL_ABI_FUNCTION
:
1843 /* Not implemented. */
1849 switch (event_param
->instrumentation
) {
1850 case LTTNG_KERNEL_ABI_TRACEPOINT
:
1852 case LTTNG_KERNEL_ABI_SYSCALL
:
1853 fops
= <tng_event_recorder_enabler_fops
;
1855 case LTTNG_KERNEL_ABI_KPROBE
:
1857 case LTTNG_KERNEL_ABI_KRETPROBE
:
1859 case LTTNG_KERNEL_ABI_UPROBE
:
1860 fops
= <tng_event_recorder_event_fops
;
1863 case LTTNG_KERNEL_ABI_FUNCTION
:
1865 case LTTNG_KERNEL_ABI_NOOP
:
1871 event_fd
= lttng_get_unused_fd();
1876 event_file
= anon_inode_getfile("[lttng_event]",
1877 fops
, NULL
, O_RDWR
);
1878 if (IS_ERR(event_file
)) {
1879 ret
= PTR_ERR(event_file
);
1882 /* The event holds a reference on the channel */
1883 if (!atomic_long_add_unless(&channel_file
->f_count
, 1, LONG_MAX
)) {
1885 goto refcount_error
;
1887 ret
= lttng_abi_validate_event_param(event_param
);
1891 switch (event_param
->instrumentation
) {
1892 case LTTNG_KERNEL_ABI_TRACEPOINT
:
1894 case LTTNG_KERNEL_ABI_SYSCALL
:
1896 struct lttng_event_recorder_enabler
*event_enabler
;
1898 if (strutils_is_star_glob_pattern(event_param
->name
)) {
1900 * If the event name is a star globbing pattern,
1901 * we create the special star globbing enabler.
1903 event_enabler
= lttng_event_recorder_enabler_create(LTTNG_ENABLER_FORMAT_STAR_GLOB
,
1904 event_param
, channel
);
1906 event_enabler
= lttng_event_recorder_enabler_create(LTTNG_ENABLER_FORMAT_NAME
,
1907 event_param
, channel
);
1910 lttng_event_enabler_session_add(channel
->parent
.session
, event_enabler
);
1911 priv
= event_enabler
;
1915 case LTTNG_KERNEL_ABI_KPROBE
:
1917 case LTTNG_KERNEL_ABI_KRETPROBE
:
1919 case LTTNG_KERNEL_ABI_UPROBE
:
1921 struct lttng_kernel_event_common
*event
;
1922 struct lttng_event_recorder_enabler
*event_enabler
;
1924 event_enabler
= lttng_event_recorder_enabler_create(LTTNG_ENABLER_FORMAT_NAME
,
1925 event_param
, channel
);
1926 if (!event_enabler
) {
1931 * We tolerate no failure path after event creation. It
1932 * will stay invariant for the rest of the session.
1934 event
= lttng_kernel_event_create(&event_enabler
->parent
, NULL
);
1935 WARN_ON_ONCE(IS_ERR(event
));
1936 lttng_event_enabler_destroy(&event_enabler
->parent
);
1937 if (IS_ERR(event
)) {
1938 ret
= PTR_ERR(event
);
1941 priv
= container_of(event
, struct lttng_kernel_event_recorder
, parent
);
1945 case LTTNG_KERNEL_ABI_FUNCTION
:
1947 case LTTNG_KERNEL_ABI_NOOP
:
1953 event_file
->private_data
= priv
;
1954 fd_install(event_fd
, event_file
);
1958 atomic_long_dec(&channel_file
->f_count
);
1962 put_unused_fd(event_fd
);
1968 long lttng_event_notifier_event_ioctl(struct file
*file
, unsigned int cmd
, unsigned long arg
)
1970 struct lttng_kernel_event_notifier
*event_notifier
= file
->private_data
;
1973 case LTTNG_KERNEL_ABI_ENABLE
:
1974 return lttng_event_enable(&event_notifier
->parent
);
1975 case LTTNG_KERNEL_ABI_DISABLE
:
1976 return lttng_event_disable(&event_notifier
->parent
);
1977 case LTTNG_KERNEL_ABI_FILTER
:
1979 case LTTNG_KERNEL_ABI_CAPTURE
:
1981 case LTTNG_KERNEL_ABI_ADD_CALLSITE
:
1982 return lttng_event_add_callsite(&event_notifier
->parent
,
1983 (struct lttng_kernel_abi_event_callsite __user
*) arg
);
1985 return -ENOIOCTLCMD
;
1990 long lttng_event_notifier_enabler_ioctl(struct file
*file
, unsigned int cmd
, unsigned long arg
)
1992 struct lttng_event_notifier_enabler
*event_notifier_enabler
= file
->private_data
;
1995 case LTTNG_KERNEL_ABI_ENABLE
:
1996 return lttng_event_enabler_enable(&event_notifier_enabler
->parent
);
1997 case LTTNG_KERNEL_ABI_DISABLE
:
1998 return lttng_event_enabler_disable(&event_notifier_enabler
->parent
);
1999 case LTTNG_KERNEL_ABI_FILTER
:
2000 return lttng_event_enabler_attach_filter_bytecode(&event_notifier_enabler
->parent
,
2001 (struct lttng_kernel_abi_filter_bytecode __user
*) arg
);
2002 case LTTNG_KERNEL_ABI_CAPTURE
:
2003 return lttng_event_notifier_enabler_attach_capture_bytecode(
2004 event_notifier_enabler
,
2005 (struct lttng_kernel_abi_capture_bytecode __user
*) arg
);
2006 case LTTNG_KERNEL_ABI_ADD_CALLSITE
:
2009 return -ENOIOCTLCMD
;
2014 int lttng_event_notifier_event_release(struct inode
*inode
, struct file
*file
)
2016 struct lttng_kernel_event_notifier
*event_notifier
= file
->private_data
;
2019 fput(event_notifier
->priv
->group
->file
);
2024 int lttng_event_notifier_enabler_release(struct inode
*inode
, struct file
*file
)
2026 struct lttng_event_notifier_enabler
*event_notifier_enabler
= file
->private_data
;
2028 if (event_notifier_enabler
)
2029 fput(event_notifier_enabler
->group
->file
);
2033 static const struct file_operations lttng_event_notifier_event_fops
= {
2034 .owner
= THIS_MODULE
,
2035 .release
= lttng_event_notifier_event_release
,
2036 .unlocked_ioctl
= lttng_event_notifier_event_ioctl
,
2037 #ifdef CONFIG_COMPAT
2038 .compat_ioctl
= lttng_event_notifier_event_ioctl
,
2042 static const struct file_operations lttng_event_notifier_enabler_fops
= {
2043 .owner
= THIS_MODULE
,
2044 .release
= lttng_event_notifier_enabler_release
,
2045 .unlocked_ioctl
= lttng_event_notifier_enabler_ioctl
,
2046 #ifdef CONFIG_COMPAT
2047 .compat_ioctl
= lttng_event_notifier_enabler_ioctl
,
2052 int lttng_abi_create_event_notifier(struct file
*event_notifier_group_file
,
2053 struct lttng_kernel_abi_event_notifier
*event_notifier_param
)
2055 struct lttng_event_notifier_group
*event_notifier_group
=
2056 event_notifier_group_file
->private_data
;
2057 const struct file_operations
*fops
;
2058 int event_notifier_fd
, ret
;
2059 struct file
*event_notifier_file
;
2062 switch (event_notifier_param
->event
.instrumentation
) {
2063 case LTTNG_KERNEL_ABI_TRACEPOINT
:
2064 case LTTNG_KERNEL_ABI_UPROBE
:
2066 case LTTNG_KERNEL_ABI_KPROBE
:
2067 event_notifier_param
->event
.u
.kprobe
.symbol_name
[LTTNG_KERNEL_ABI_SYM_NAME_LEN
- 1] = '\0';
2069 case LTTNG_KERNEL_ABI_SYSCALL
:
2071 case LTTNG_KERNEL_ABI_KRETPROBE
:
2072 /* Placing an event notifier on kretprobe is not supported. */
2073 case LTTNG_KERNEL_ABI_FUNCTION
:
2074 case LTTNG_KERNEL_ABI_NOOP
:
2080 switch (event_notifier_param
->event
.instrumentation
) {
2081 case LTTNG_KERNEL_ABI_TRACEPOINT
:
2083 case LTTNG_KERNEL_ABI_SYSCALL
:
2084 fops
= <tng_event_notifier_enabler_fops
;
2086 case LTTNG_KERNEL_ABI_KPROBE
:
2088 case LTTNG_KERNEL_ABI_KRETPROBE
:
2090 case LTTNG_KERNEL_ABI_UPROBE
:
2091 fops
= <tng_event_notifier_event_fops
;
2094 case LTTNG_KERNEL_ABI_FUNCTION
:
2096 case LTTNG_KERNEL_ABI_NOOP
:
2103 event_notifier_param
->event
.name
[LTTNG_KERNEL_ABI_SYM_NAME_LEN
- 1] = '\0';
2105 event_notifier_fd
= lttng_get_unused_fd();
2106 if (event_notifier_fd
< 0) {
2107 ret
= event_notifier_fd
;
2111 event_notifier_file
= anon_inode_getfile("[lttng_event_notifier]",
2112 fops
, NULL
, O_RDWR
);
2113 if (IS_ERR(event_notifier_file
)) {
2114 ret
= PTR_ERR(event_notifier_file
);
2118 /* The event notifier holds a reference on the event notifier group. */
2119 if (!atomic_long_add_unless(&event_notifier_group_file
->f_count
, 1, LONG_MAX
)) {
2121 goto refcount_error
;
2124 ret
= lttng_abi_validate_event_param(&event_notifier_param
->event
);
2126 goto event_notifier_error
;
2128 switch (event_notifier_param
->event
.instrumentation
) {
2129 case LTTNG_KERNEL_ABI_TRACEPOINT
:
2131 case LTTNG_KERNEL_ABI_SYSCALL
:
2133 struct lttng_event_notifier_enabler
*enabler
;
2135 if (strutils_is_star_glob_pattern(event_notifier_param
->event
.name
)) {
2137 * If the event name is a star globbing pattern,
2138 * we create the special star globbing enabler.
2140 enabler
= lttng_event_notifier_enabler_create(
2141 LTTNG_ENABLER_FORMAT_STAR_GLOB
,
2142 event_notifier_param
,
2143 event_notifier_group
);
2145 enabler
= lttng_event_notifier_enabler_create(
2146 LTTNG_ENABLER_FORMAT_NAME
,
2147 event_notifier_param
,
2148 event_notifier_group
);
2151 lttng_event_notifier_enabler_group_add(event_notifier_group
, enabler
);
2156 case LTTNG_KERNEL_ABI_KPROBE
:
2158 case LTTNG_KERNEL_ABI_KRETPROBE
:
2160 case LTTNG_KERNEL_ABI_UPROBE
:
2162 struct lttng_kernel_event_common
*event
;
2163 struct lttng_event_notifier_enabler
*event_notifier_enabler
;
2165 event_notifier_enabler
= lttng_event_notifier_enabler_create(LTTNG_ENABLER_FORMAT_NAME
,
2166 event_notifier_param
, event_notifier_group
);
2167 if (!event_notifier_enabler
) {
2169 goto event_notifier_error
;
2171 event
= lttng_kernel_event_create(&event_notifier_enabler
->parent
, NULL
);
2172 WARN_ON_ONCE(IS_ERR(event
));
2173 lttng_event_enabler_destroy(&event_notifier_enabler
->parent
);
2174 if (IS_ERR(event
)) {
2175 ret
= PTR_ERR(event
);
2176 goto event_notifier_error
;
2178 priv
= container_of(event
, struct lttng_kernel_event_notifier
, parent
);
2182 case LTTNG_KERNEL_ABI_FUNCTION
:
2184 case LTTNG_KERNEL_ABI_NOOP
:
2188 goto event_notifier_error
;
2190 event_notifier_file
->private_data
= priv
;
2191 fd_install(event_notifier_fd
, event_notifier_file
);
2192 return event_notifier_fd
;
2194 event_notifier_error
:
2195 atomic_long_dec(&event_notifier_group_file
->f_count
);
2197 fput(event_notifier_file
);
2199 put_unused_fd(event_notifier_fd
);
2206 long lttng_abi_event_notifier_group_create_error_counter(
2207 struct file
*event_notifier_group_file
,
2208 const struct lttng_kernel_abi_counter_conf
*error_counter_conf
)
2210 int counter_fd
, ret
;
2211 char *counter_transport_name
;
2213 struct lttng_counter
*counter
= NULL
;
2214 struct file
*counter_file
;
2215 struct lttng_event_notifier_group
*event_notifier_group
=
2216 (struct lttng_event_notifier_group
*) event_notifier_group_file
->private_data
;
2218 if (error_counter_conf
->arithmetic
!= LTTNG_KERNEL_ABI_COUNTER_ARITHMETIC_MODULAR
) {
2219 printk(KERN_ERR
"LTTng: event_notifier: Error counter of the wrong arithmetic type.\n");
2223 if (error_counter_conf
->number_dimensions
!= 1) {
2224 printk(KERN_ERR
"LTTng: event_notifier: Error counter has more than one dimension.\n");
2228 switch (error_counter_conf
->bitness
) {
2229 case LTTNG_KERNEL_ABI_COUNTER_BITNESS_64
:
2230 counter_transport_name
= "counter-per-cpu-64-modular";
2232 case LTTNG_KERNEL_ABI_COUNTER_BITNESS_32
:
2233 counter_transport_name
= "counter-per-cpu-32-modular";
2240 * Lock sessions to provide mutual exclusion against concurrent
2241 * modification of event_notifier group, which would result in
2242 * overwriting the error counter if set concurrently.
2244 lttng_lock_sessions();
2246 if (event_notifier_group
->error_counter
) {
2247 printk(KERN_ERR
"Error counter already created in event_notifier group\n");
2252 counter_fd
= lttng_get_unused_fd();
2253 if (counter_fd
< 0) {
2258 counter_file
= anon_inode_getfile("[lttng_counter]",
2259 <tng_counter_fops
,
2261 if (IS_ERR(counter_file
)) {
2262 ret
= PTR_ERR(counter_file
);
2266 counter_len
= error_counter_conf
->dimensions
[0].size
;
2268 if (!atomic_long_add_unless(&event_notifier_group_file
->f_count
, 1, LONG_MAX
)) {
2270 goto refcount_error
;
2273 counter
= lttng_kernel_counter_create(counter_transport_name
,
2280 event_notifier_group
->error_counter_len
= counter_len
;
2282 * store-release to publish error counter matches load-acquire
2283 * in record_error. Ensures the counter is created and the
2284 * error_counter_len is set before they are used.
2286 smp_store_release(&event_notifier_group
->error_counter
, counter
);
2288 counter
->file
= counter_file
;
2289 counter
->owner
= event_notifier_group
->file
;
2290 counter_file
->private_data
= counter
;
2291 /* Ownership transferred. */
2294 fd_install(counter_fd
, counter_file
);
2295 lttng_unlock_sessions();
2300 atomic_long_dec(&event_notifier_group_file
->f_count
);
2304 put_unused_fd(counter_fd
);
2306 lttng_unlock_sessions();
2311 long lttng_event_notifier_group_ioctl(struct file
*file
, unsigned int cmd
,
2315 case LTTNG_KERNEL_ABI_EVENT_NOTIFIER_GROUP_NOTIFICATION_FD
:
2317 return lttng_abi_open_event_notifier_group_stream(file
);
2319 case LTTNG_KERNEL_ABI_EVENT_NOTIFIER_CREATE
:
2321 struct lttng_kernel_abi_event_notifier uevent_notifier_param
;
2323 if (copy_from_user(&uevent_notifier_param
,
2324 (struct lttng_kernel_abi_event_notifier __user
*) arg
,
2325 sizeof(uevent_notifier_param
)))
2327 return lttng_abi_create_event_notifier(file
, &uevent_notifier_param
);
2329 case LTTNG_KERNEL_ABI_COUNTER
:
2331 struct lttng_kernel_abi_counter_conf uerror_counter_conf
;
2333 if (copy_from_user(&uerror_counter_conf
,
2334 (struct lttng_kernel_abi_counter_conf __user
*) arg
,
2335 sizeof(uerror_counter_conf
)))
2337 return lttng_abi_event_notifier_group_create_error_counter(file
,
2338 &uerror_counter_conf
);
2341 return -ENOIOCTLCMD
;
2347 int lttng_event_notifier_group_release(struct inode
*inode
, struct file
*file
)
2349 struct lttng_event_notifier_group
*event_notifier_group
=
2352 if (event_notifier_group
)
2353 lttng_event_notifier_group_destroy(event_notifier_group
);
2357 static const struct file_operations lttng_event_notifier_group_fops
= {
2358 .owner
= THIS_MODULE
,
2359 .release
= lttng_event_notifier_group_release
,
2360 .unlocked_ioctl
= lttng_event_notifier_group_ioctl
,
2361 #ifdef CONFIG_COMPAT
2362 .compat_ioctl
= lttng_event_notifier_group_ioctl
,
2367 * lttng_channel_ioctl - lttng syscall through ioctl
2373 * This ioctl implements lttng commands:
2374 * LTTNG_KERNEL_ABI_STREAM
2375 * Returns an event stream file descriptor or failure.
2376 * (typically, one event stream records events from one CPU)
2377 * LTTNG_KERNEL_ABI_EVENT
2378 * Returns an event file descriptor or failure.
2379 * LTTNG_KERNEL_ABI_CONTEXT
2380 * Prepend a context field to each event in the channel
2381 * LTTNG_KERNEL_ABI_ENABLE
2382 * Enable recording for events in this channel (weak enable)
2383 * LTTNG_KERNEL_ABI_DISABLE
2384 * Disable recording for events in this channel (strong disable)
2386 * Channel and event file descriptors also hold a reference on the session.
2389 long lttng_channel_ioctl(struct file
*file
, unsigned int cmd
, unsigned long arg
)
2391 struct lttng_kernel_channel_buffer
*channel
= file
->private_data
;
2394 case LTTNG_KERNEL_ABI_OLD_STREAM
:
2395 case LTTNG_KERNEL_ABI_STREAM
:
2396 return lttng_abi_open_stream(file
);
2397 case LTTNG_KERNEL_ABI_OLD_EVENT
:
2399 struct lttng_kernel_abi_event
*uevent_param
;
2400 struct lttng_kernel_abi_old_event
*old_uevent_param
;
2403 uevent_param
= kmalloc(sizeof(struct lttng_kernel_abi_event
),
2405 if (!uevent_param
) {
2409 old_uevent_param
= kmalloc(
2410 sizeof(struct lttng_kernel_abi_old_event
),
2412 if (!old_uevent_param
) {
2414 goto old_event_error_free_param
;
2416 if (copy_from_user(old_uevent_param
,
2417 (struct lttng_kernel_abi_old_event __user
*) arg
,
2418 sizeof(struct lttng_kernel_abi_old_event
))) {
2420 goto old_event_error_free_old_param
;
2423 memcpy(uevent_param
->name
, old_uevent_param
->name
,
2424 sizeof(uevent_param
->name
));
2425 uevent_param
->instrumentation
=
2426 old_uevent_param
->instrumentation
;
2428 switch (old_uevent_param
->instrumentation
) {
2429 case LTTNG_KERNEL_ABI_KPROBE
:
2430 uevent_param
->u
.kprobe
.addr
=
2431 old_uevent_param
->u
.kprobe
.addr
;
2432 uevent_param
->u
.kprobe
.offset
=
2433 old_uevent_param
->u
.kprobe
.offset
;
2434 memcpy(uevent_param
->u
.kprobe
.symbol_name
,
2435 old_uevent_param
->u
.kprobe
.symbol_name
,
2436 sizeof(uevent_param
->u
.kprobe
.symbol_name
));
2438 case LTTNG_KERNEL_ABI_KRETPROBE
:
2439 uevent_param
->u
.kretprobe
.addr
=
2440 old_uevent_param
->u
.kretprobe
.addr
;
2441 uevent_param
->u
.kretprobe
.offset
=
2442 old_uevent_param
->u
.kretprobe
.offset
;
2443 memcpy(uevent_param
->u
.kretprobe
.symbol_name
,
2444 old_uevent_param
->u
.kretprobe
.symbol_name
,
2445 sizeof(uevent_param
->u
.kretprobe
.symbol_name
));
2447 case LTTNG_KERNEL_ABI_FUNCTION
:
2449 /* Not implemented. */
2454 ret
= lttng_abi_create_event(file
, uevent_param
);
2456 old_event_error_free_old_param
:
2457 kfree(old_uevent_param
);
2458 old_event_error_free_param
:
2459 kfree(uevent_param
);
2463 case LTTNG_KERNEL_ABI_EVENT
:
2465 struct lttng_kernel_abi_event uevent_param
;
2467 if (copy_from_user(&uevent_param
,
2468 (struct lttng_kernel_abi_event __user
*) arg
,
2469 sizeof(uevent_param
)))
2471 return lttng_abi_create_event(file
, &uevent_param
);
2473 case LTTNG_KERNEL_ABI_OLD_CONTEXT
:
2475 struct lttng_kernel_abi_context
*ucontext_param
;
2476 struct lttng_kernel_abi_old_context
*old_ucontext_param
;
2479 ucontext_param
= kmalloc(sizeof(struct lttng_kernel_abi_context
),
2481 if (!ucontext_param
) {
2485 old_ucontext_param
= kmalloc(sizeof(struct lttng_kernel_abi_old_context
),
2487 if (!old_ucontext_param
) {
2489 goto old_ctx_error_free_param
;
2492 if (copy_from_user(old_ucontext_param
,
2493 (struct lttng_kernel_abi_old_context __user
*) arg
,
2494 sizeof(struct lttng_kernel_abi_old_context
))) {
2496 goto old_ctx_error_free_old_param
;
2498 ucontext_param
->ctx
= old_ucontext_param
->ctx
;
2499 memcpy(ucontext_param
->padding
, old_ucontext_param
->padding
,
2500 sizeof(ucontext_param
->padding
));
2501 /* only type that uses the union */
2502 if (old_ucontext_param
->ctx
== LTTNG_KERNEL_ABI_CONTEXT_PERF_COUNTER
) {
2503 ucontext_param
->u
.perf_counter
.type
=
2504 old_ucontext_param
->u
.perf_counter
.type
;
2505 ucontext_param
->u
.perf_counter
.config
=
2506 old_ucontext_param
->u
.perf_counter
.config
;
2507 memcpy(ucontext_param
->u
.perf_counter
.name
,
2508 old_ucontext_param
->u
.perf_counter
.name
,
2509 sizeof(ucontext_param
->u
.perf_counter
.name
));
2512 ret
= lttng_abi_add_context(file
,
2514 &channel
->priv
->ctx
, channel
->parent
.session
);
2516 old_ctx_error_free_old_param
:
2517 kfree(old_ucontext_param
);
2518 old_ctx_error_free_param
:
2519 kfree(ucontext_param
);
2523 case LTTNG_KERNEL_ABI_CONTEXT
:
2525 struct lttng_kernel_abi_context ucontext_param
;
2527 if (copy_from_user(&ucontext_param
,
2528 (struct lttng_kernel_abi_context __user
*) arg
,
2529 sizeof(ucontext_param
)))
2531 return lttng_abi_add_context(file
,
2533 &channel
->priv
->ctx
, channel
->parent
.session
);
2535 case LTTNG_KERNEL_ABI_OLD_ENABLE
:
2536 case LTTNG_KERNEL_ABI_ENABLE
:
2537 return lttng_channel_enable(&channel
->parent
);
2538 case LTTNG_KERNEL_ABI_OLD_DISABLE
:
2539 case LTTNG_KERNEL_ABI_DISABLE
:
2540 return lttng_channel_disable(&channel
->parent
);
2541 case LTTNG_KERNEL_ABI_SYSCALL_MASK
:
2542 return lttng_syscall_table_get_active_mask(&channel
->priv
->parent
.syscall_table
,
2543 (struct lttng_kernel_abi_syscall_mask __user
*) arg
);
2545 return -ENOIOCTLCMD
;
2550 * lttng_metadata_ioctl - lttng syscall through ioctl
2556 * This ioctl implements lttng commands:
2557 * LTTNG_KERNEL_ABI_STREAM
2558 * Returns an event stream file descriptor or failure.
2560 * Channel and event file descriptors also hold a reference on the session.
2563 long lttng_metadata_ioctl(struct file
*file
, unsigned int cmd
, unsigned long arg
)
2566 case LTTNG_KERNEL_ABI_OLD_STREAM
:
2567 case LTTNG_KERNEL_ABI_STREAM
:
2568 return lttng_abi_open_metadata_stream(file
);
2570 return -ENOIOCTLCMD
;
2575 * lttng_channel_poll - lttng stream addition/removal monitoring
2580 unsigned int lttng_channel_poll(struct file
*file
, poll_table
*wait
)
2582 struct lttng_kernel_channel_buffer
*channel
= file
->private_data
;
2583 unsigned int mask
= 0;
2585 if (file
->f_mode
& FMODE_READ
) {
2586 poll_wait_set_exclusive(wait
);
2587 poll_wait(file
, channel
->ops
->priv
->get_hp_wait_queue(channel
->priv
->rb_chan
),
2590 if (channel
->ops
->priv
->is_disabled(channel
->priv
->rb_chan
))
2592 if (channel
->ops
->priv
->is_finalized(channel
->priv
->rb_chan
))
2594 if (channel
->ops
->priv
->buffer_has_read_closed_stream(channel
->priv
->rb_chan
))
2595 return POLLIN
| POLLRDNORM
;
2603 int lttng_channel_release(struct inode
*inode
, struct file
*file
)
2605 struct lttng_kernel_channel_buffer
*channel
= file
->private_data
;
2608 fput(channel
->parent
.session
->priv
->file
);
2613 int lttng_metadata_channel_release(struct inode
*inode
, struct file
*file
)
2615 struct lttng_kernel_channel_buffer
*channel
= file
->private_data
;
2618 fput(channel
->parent
.session
->priv
->file
);
2619 lttng_metadata_channel_destroy(channel
);
2625 static const struct file_operations lttng_channel_fops
= {
2626 .owner
= THIS_MODULE
,
2627 .release
= lttng_channel_release
,
2628 .poll
= lttng_channel_poll
,
2629 .unlocked_ioctl
= lttng_channel_ioctl
,
2630 #ifdef CONFIG_COMPAT
2631 .compat_ioctl
= lttng_channel_ioctl
,
2635 static const struct file_operations lttng_metadata_fops
= {
2636 .owner
= THIS_MODULE
,
2637 .release
= lttng_metadata_channel_release
,
2638 .unlocked_ioctl
= lttng_metadata_ioctl
,
2639 #ifdef CONFIG_COMPAT
2640 .compat_ioctl
= lttng_metadata_ioctl
,
2645 * lttng_event_recorder_event_ioctl - lttng syscall through ioctl
2651 * This ioctl implements lttng commands:
2652 * LTTNG_KERNEL_ABI_CONTEXT
2653 * Prepend a context field to each record of this event
2654 * LTTNG_KERNEL_ABI_ENABLE
2655 * Enable recording for this event (weak enable)
2656 * LTTNG_KERNEL_ABI_DISABLE
2657 * Disable recording for this event (strong disable)
2660 long lttng_event_recorder_event_ioctl(struct file
*file
, unsigned int cmd
, unsigned long arg
)
2662 struct lttng_kernel_event_recorder
*event_recorder
= file
->private_data
;
2665 case LTTNG_KERNEL_ABI_OLD_CONTEXT
:
2667 /* Not implemented */
2670 case LTTNG_KERNEL_ABI_CONTEXT
:
2672 /* Not implemented */
2675 case LTTNG_KERNEL_ABI_OLD_ENABLE
:
2676 case LTTNG_KERNEL_ABI_ENABLE
:
2677 return lttng_event_enable(&event_recorder
->parent
);
2678 case LTTNG_KERNEL_ABI_OLD_DISABLE
:
2679 case LTTNG_KERNEL_ABI_DISABLE
:
2680 return lttng_event_disable(&event_recorder
->parent
);
2681 case LTTNG_KERNEL_ABI_FILTER
:
2683 case LTTNG_KERNEL_ABI_ADD_CALLSITE
:
2684 return lttng_event_add_callsite(&event_recorder
->parent
,
2685 (struct lttng_kernel_abi_event_callsite __user
*) arg
);
2687 return -ENOIOCTLCMD
;
2692 * lttng_event_recorder_enabler_ioctl - lttng syscall through ioctl
2698 * This ioctl implements lttng commands:
2699 * LTTNG_KERNEL_ABI_CONTEXT
2700 * Prepend a context field to each record of this event
2701 * LTTNG_KERNEL_ABI_ENABLE
2702 * Enable recording for this event (weak enable)
2703 * LTTNG_KERNEL_ABI_DISABLE
2704 * Disable recording for this event (strong disable)
2707 long lttng_event_recorder_enabler_ioctl(struct file
*file
, unsigned int cmd
, unsigned long arg
)
2709 struct lttng_event_recorder_enabler
*event_enabler
= file
->private_data
;
2712 case LTTNG_KERNEL_ABI_OLD_CONTEXT
:
2714 /* Not implemented */
2717 case LTTNG_KERNEL_ABI_CONTEXT
:
2719 /* Not implemented */
2722 case LTTNG_KERNEL_ABI_OLD_ENABLE
:
2723 case LTTNG_KERNEL_ABI_ENABLE
:
2724 return lttng_event_enabler_enable(&event_enabler
->parent
);
2725 case LTTNG_KERNEL_ABI_OLD_DISABLE
:
2726 case LTTNG_KERNEL_ABI_DISABLE
:
2727 return lttng_event_enabler_disable(&event_enabler
->parent
);
2728 case LTTNG_KERNEL_ABI_FILTER
:
2729 return lttng_event_enabler_attach_filter_bytecode(&event_enabler
->parent
,
2730 (struct lttng_kernel_abi_filter_bytecode __user
*) arg
);
2731 case LTTNG_KERNEL_ABI_ADD_CALLSITE
:
2734 return -ENOIOCTLCMD
;
2739 int lttng_event_recorder_event_release(struct inode
*inode
, struct file
*file
)
2741 struct lttng_kernel_event_recorder
*event
= file
->private_data
;
2744 fput(event
->chan
->priv
->parent
.file
);
2749 int lttng_event_recorder_enabler_release(struct inode
*inode
, struct file
*file
)
2751 struct lttng_event_recorder_enabler
*event_enabler
= file
->private_data
;
2754 fput(event_enabler
->chan
->priv
->parent
.file
);
2758 static const struct file_operations lttng_event_recorder_event_fops
= {
2759 .owner
= THIS_MODULE
,
2760 .release
= lttng_event_recorder_event_release
,
2761 .unlocked_ioctl
= lttng_event_recorder_event_ioctl
,
2762 #ifdef CONFIG_COMPAT
2763 .compat_ioctl
= lttng_event_recorder_event_ioctl
,
2767 static const struct file_operations lttng_event_recorder_enabler_fops
= {
2768 .owner
= THIS_MODULE
,
2769 .release
= lttng_event_recorder_enabler_release
,
2770 .unlocked_ioctl
= lttng_event_recorder_enabler_ioctl
,
2771 #ifdef CONFIG_COMPAT
2772 .compat_ioctl
= lttng_event_recorder_enabler_ioctl
,
2776 static int put_u64(uint64_t val
, unsigned long arg
)
2778 return put_user(val
, (uint64_t __user
*) arg
);
2781 static int put_u32(uint32_t val
, unsigned long arg
)
2783 return put_user(val
, (uint32_t __user
*) arg
);
2786 static long lttng_stream_ring_buffer_ioctl(struct file
*filp
,
2787 unsigned int cmd
, unsigned long arg
)
2789 struct lttng_kernel_ring_buffer
*buf
= filp
->private_data
;
2790 struct lttng_kernel_ring_buffer_channel
*chan
= buf
->backend
.chan
;
2791 const struct lttng_kernel_ring_buffer_config
*config
= &chan
->backend
.config
;
2792 const struct lttng_kernel_channel_buffer_ops
*ops
= chan
->backend
.priv_ops
;
2795 if (atomic_read(&chan
->record_disabled
))
2799 case LTTNG_KERNEL_ABI_RING_BUFFER_GET_TIMESTAMP_BEGIN
:
2803 ret
= ops
->priv
->timestamp_begin(config
, buf
, &ts
);
2806 return put_u64(ts
, arg
);
2808 case LTTNG_KERNEL_ABI_RING_BUFFER_GET_TIMESTAMP_END
:
2812 ret
= ops
->priv
->timestamp_end(config
, buf
, &ts
);
2815 return put_u64(ts
, arg
);
2817 case LTTNG_KERNEL_ABI_RING_BUFFER_GET_EVENTS_DISCARDED
:
2821 ret
= ops
->priv
->events_discarded(config
, buf
, &ed
);
2824 return put_u64(ed
, arg
);
2826 case LTTNG_KERNEL_ABI_RING_BUFFER_GET_CONTENT_SIZE
:
2830 ret
= ops
->priv
->content_size(config
, buf
, &cs
);
2833 return put_u64(cs
, arg
);
2835 case LTTNG_KERNEL_ABI_RING_BUFFER_GET_PACKET_SIZE
:
2839 ret
= ops
->priv
->packet_size(config
, buf
, &ps
);
2842 return put_u64(ps
, arg
);
2844 case LTTNG_KERNEL_ABI_RING_BUFFER_GET_STREAM_ID
:
2848 ret
= ops
->priv
->stream_id(config
, buf
, &si
);
2851 return put_u64(si
, arg
);
2853 case LTTNG_KERNEL_ABI_RING_BUFFER_GET_CURRENT_TIMESTAMP
:
2857 ret
= ops
->priv
->current_timestamp(config
, buf
, &ts
);
2860 return put_u64(ts
, arg
);
2862 case LTTNG_KERNEL_ABI_RING_BUFFER_GET_SEQ_NUM
:
2866 ret
= ops
->priv
->sequence_number(config
, buf
, &seq
);
2869 return put_u64(seq
, arg
);
2871 case LTTNG_KERNEL_ABI_RING_BUFFER_INSTANCE_ID
:
2875 ret
= ops
->priv
->instance_id(config
, buf
, &id
);
2878 return put_u64(id
, arg
);
2881 return lib_ring_buffer_file_operations
.unlocked_ioctl(filp
,
2889 #ifdef CONFIG_COMPAT
2890 static long lttng_stream_ring_buffer_compat_ioctl(struct file
*filp
,
2891 unsigned int cmd
, unsigned long arg
)
2893 struct lttng_kernel_ring_buffer
*buf
= filp
->private_data
;
2894 struct lttng_kernel_ring_buffer_channel
*chan
= buf
->backend
.chan
;
2895 const struct lttng_kernel_ring_buffer_config
*config
= &chan
->backend
.config
;
2896 const struct lttng_kernel_channel_buffer_ops
*ops
= chan
->backend
.priv_ops
;
2899 if (atomic_read(&chan
->record_disabled
))
2903 case LTTNG_KERNEL_ABI_RING_BUFFER_COMPAT_GET_TIMESTAMP_BEGIN
:
2907 ret
= ops
->priv
->timestamp_begin(config
, buf
, &ts
);
2910 return put_u64(ts
, arg
);
2912 case LTTNG_KERNEL_ABI_RING_BUFFER_COMPAT_GET_TIMESTAMP_END
:
2916 ret
= ops
->priv
->timestamp_end(config
, buf
, &ts
);
2919 return put_u64(ts
, arg
);
2921 case LTTNG_KERNEL_ABI_RING_BUFFER_COMPAT_GET_EVENTS_DISCARDED
:
2925 ret
= ops
->priv
->events_discarded(config
, buf
, &ed
);
2928 return put_u64(ed
, arg
);
2930 case LTTNG_KERNEL_ABI_RING_BUFFER_COMPAT_GET_CONTENT_SIZE
:
2934 ret
= ops
->priv
->content_size(config
, buf
, &cs
);
2937 return put_u64(cs
, arg
);
2939 case LTTNG_KERNEL_ABI_RING_BUFFER_COMPAT_GET_PACKET_SIZE
:
2943 ret
= ops
->priv
->packet_size(config
, buf
, &ps
);
2946 return put_u64(ps
, arg
);
2948 case LTTNG_KERNEL_ABI_RING_BUFFER_COMPAT_GET_STREAM_ID
:
2952 ret
= ops
->priv
->stream_id(config
, buf
, &si
);
2955 return put_u64(si
, arg
);
2957 case LTTNG_KERNEL_ABI_RING_BUFFER_GET_CURRENT_TIMESTAMP
:
2961 ret
= ops
->priv
->current_timestamp(config
, buf
, &ts
);
2964 return put_u64(ts
, arg
);
2966 case LTTNG_KERNEL_ABI_RING_BUFFER_COMPAT_GET_SEQ_NUM
:
2970 ret
= ops
->priv
->sequence_number(config
, buf
, &seq
);
2973 return put_u64(seq
, arg
);
2975 case LTTNG_KERNEL_ABI_RING_BUFFER_COMPAT_INSTANCE_ID
:
2979 ret
= ops
->priv
->instance_id(config
, buf
, &id
);
2982 return put_u64(id
, arg
);
2985 return lib_ring_buffer_file_operations
.compat_ioctl(filp
,
2992 #endif /* CONFIG_COMPAT */
2994 static void lttng_stream_override_ring_buffer_fops(void)
2996 lttng_stream_ring_buffer_file_operations
.owner
= THIS_MODULE
;
2997 lttng_stream_ring_buffer_file_operations
.open
=
2998 lib_ring_buffer_file_operations
.open
;
2999 lttng_stream_ring_buffer_file_operations
.release
=
3000 lib_ring_buffer_file_operations
.release
;
3001 lttng_stream_ring_buffer_file_operations
.poll
=
3002 lib_ring_buffer_file_operations
.poll
;
3003 lttng_stream_ring_buffer_file_operations
.splice_read
=
3004 lib_ring_buffer_file_operations
.splice_read
;
3005 lttng_stream_ring_buffer_file_operations
.mmap
=
3006 lib_ring_buffer_file_operations
.mmap
;
3007 lttng_stream_ring_buffer_file_operations
.unlocked_ioctl
=
3008 lttng_stream_ring_buffer_ioctl
;
3009 lttng_stream_ring_buffer_file_operations
.llseek
=
3010 lib_ring_buffer_file_operations
.llseek
;
3011 #ifdef CONFIG_COMPAT
3012 lttng_stream_ring_buffer_file_operations
.compat_ioctl
=
3013 lttng_stream_ring_buffer_compat_ioctl
;
3017 int __init
lttng_abi_init(void)
3021 wrapper_vmalloc_sync_mappings();
3024 ret
= lttng_tp_mempool_init();
3029 lttng_proc_dentry
= proc_create_data("lttng", S_IRUSR
| S_IWUSR
, NULL
,
3030 <tng_proc_ops
, NULL
);
3032 if (!lttng_proc_dentry
) {
3033 printk(KERN_ERR
"LTTng: Error creating control file\n");
3037 lttng_stream_override_ring_buffer_fops();
3041 lttng_tp_mempool_destroy();
3042 lttng_clock_unref();
3046 /* No __exit annotation because used by init error path too. */
3047 void lttng_abi_exit(void)
3049 lttng_tp_mempool_destroy();
3050 lttng_clock_unref();
3051 if (lttng_proc_dentry
)
3052 remove_proc_entry("lttng", NULL
);