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 <linux/kref.h>
34 #include <wrapper/ringbuffer/vfs.h>
35 #include <wrapper/ringbuffer/backend.h>
36 #include <wrapper/ringbuffer/frontend.h>
37 #include <wrapper/file.h>
38 #include <lttng-string-utils.h>
39 #include <lttng-abi.h>
40 #include <lttng-abi-old.h>
41 #include <lttng-events.h>
42 #include <lttng-tracer.h>
43 #include <lttng-tp-mempool.h>
44 #include <lib/ringbuffer/frontend_types.h>
47 * This is LTTng's own personal way to create a system call as an external
48 * module. We use ioctl() on /proc/lttng.
51 static struct proc_dir_entry
*lttng_proc_dentry
;
53 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(5,6,0))
54 static const struct proc_ops lttng_proc_ops
;
56 static const struct file_operations lttng_proc_ops
;
59 static const struct file_operations lttng_session_fops
;
60 static const struct file_operations lttng_channel_fops
;
61 static const struct file_operations lttng_metadata_fops
;
62 static const struct file_operations lttng_event_fops
;
63 static struct file_operations lttng_stream_ring_buffer_file_operations
;
65 static int put_u64(uint64_t val
, unsigned long arg
);
68 * Teardown management: opened file descriptors keep a refcount on the module,
69 * so it can only exit when all file descriptors are closed.
73 int lttng_abi_create_session(void)
75 struct lttng_session
*session
;
76 struct file
*session_file
;
79 session
= lttng_session_create();
82 session_fd
= lttng_get_unused_fd();
87 session_file
= anon_inode_getfile("[lttng_session]",
90 if (IS_ERR(session_file
)) {
91 ret
= PTR_ERR(session_file
);
94 session
->file
= session_file
;
95 fd_install(session_fd
, session_file
);
99 put_unused_fd(session_fd
);
101 lttng_session_destroy(session
);
106 int lttng_abi_tracepoint_list(void)
108 struct file
*tracepoint_list_file
;
111 file_fd
= lttng_get_unused_fd();
117 tracepoint_list_file
= anon_inode_getfile("[lttng_tracepoint_list]",
118 <tng_tracepoint_list_fops
,
120 if (IS_ERR(tracepoint_list_file
)) {
121 ret
= PTR_ERR(tracepoint_list_file
);
124 ret
= lttng_tracepoint_list_fops
.open(NULL
, tracepoint_list_file
);
127 fd_install(file_fd
, tracepoint_list_file
);
131 fput(tracepoint_list_file
);
133 put_unused_fd(file_fd
);
138 #ifndef CONFIG_HAVE_SYSCALL_TRACEPOINTS
140 int lttng_abi_syscall_list(void)
146 int lttng_abi_syscall_list(void)
148 struct file
*syscall_list_file
;
151 file_fd
= lttng_get_unused_fd();
157 syscall_list_file
= anon_inode_getfile("[lttng_syscall_list]",
158 <tng_syscall_list_fops
,
160 if (IS_ERR(syscall_list_file
)) {
161 ret
= PTR_ERR(syscall_list_file
);
164 ret
= lttng_syscall_list_fops
.open(NULL
, syscall_list_file
);
167 fd_install(file_fd
, syscall_list_file
);
171 fput(syscall_list_file
);
173 put_unused_fd(file_fd
);
180 void lttng_abi_tracer_version(struct lttng_kernel_tracer_version
*v
)
182 v
->major
= LTTNG_MODULES_MAJOR_VERSION
;
183 v
->minor
= LTTNG_MODULES_MINOR_VERSION
;
184 v
->patchlevel
= LTTNG_MODULES_PATCHLEVEL_VERSION
;
188 void lttng_abi_tracer_abi_version(struct lttng_kernel_tracer_abi_version
*v
)
190 v
->major
= LTTNG_MODULES_ABI_MAJOR_VERSION
;
191 v
->minor
= LTTNG_MODULES_ABI_MINOR_VERSION
;
195 long lttng_abi_add_context(struct file
*file
,
196 struct lttng_kernel_context
*context_param
,
197 struct lttng_ctx
**ctx
, struct lttng_session
*session
)
200 if (session
->been_active
)
203 switch (context_param
->ctx
) {
204 case LTTNG_KERNEL_CONTEXT_PID
:
205 return lttng_add_pid_to_ctx(ctx
);
206 case LTTNG_KERNEL_CONTEXT_PRIO
:
207 return lttng_add_prio_to_ctx(ctx
);
208 case LTTNG_KERNEL_CONTEXT_NICE
:
209 return lttng_add_nice_to_ctx(ctx
);
210 case LTTNG_KERNEL_CONTEXT_VPID
:
211 return lttng_add_vpid_to_ctx(ctx
);
212 case LTTNG_KERNEL_CONTEXT_TID
:
213 return lttng_add_tid_to_ctx(ctx
);
214 case LTTNG_KERNEL_CONTEXT_VTID
:
215 return lttng_add_vtid_to_ctx(ctx
);
216 case LTTNG_KERNEL_CONTEXT_PPID
:
217 return lttng_add_ppid_to_ctx(ctx
);
218 case LTTNG_KERNEL_CONTEXT_VPPID
:
219 return lttng_add_vppid_to_ctx(ctx
);
220 case LTTNG_KERNEL_CONTEXT_PERF_COUNTER
:
221 context_param
->u
.perf_counter
.name
[LTTNG_KERNEL_SYM_NAME_LEN
- 1] = '\0';
222 return lttng_add_perf_counter_to_ctx(context_param
->u
.perf_counter
.type
,
223 context_param
->u
.perf_counter
.config
,
224 context_param
->u
.perf_counter
.name
,
226 case LTTNG_KERNEL_CONTEXT_PROCNAME
:
227 return lttng_add_procname_to_ctx(ctx
);
228 case LTTNG_KERNEL_CONTEXT_HOSTNAME
:
229 return lttng_add_hostname_to_ctx(ctx
);
230 case LTTNG_KERNEL_CONTEXT_CPU_ID
:
231 return lttng_add_cpu_id_to_ctx(ctx
);
232 case LTTNG_KERNEL_CONTEXT_INTERRUPTIBLE
:
233 return lttng_add_interruptible_to_ctx(ctx
);
234 case LTTNG_KERNEL_CONTEXT_NEED_RESCHEDULE
:
235 return lttng_add_need_reschedule_to_ctx(ctx
);
236 case LTTNG_KERNEL_CONTEXT_PREEMPTIBLE
:
237 return lttng_add_preemptible_to_ctx(ctx
);
238 case LTTNG_KERNEL_CONTEXT_MIGRATABLE
:
239 return lttng_add_migratable_to_ctx(ctx
);
240 case LTTNG_KERNEL_CONTEXT_CALLSTACK_KERNEL
:
241 case LTTNG_KERNEL_CONTEXT_CALLSTACK_USER
:
242 return lttng_add_callstack_to_ctx(ctx
, context_param
->ctx
);
243 case LTTNG_KERNEL_CONTEXT_CGROUP_NS
:
244 return lttng_add_cgroup_ns_to_ctx(ctx
);
245 case LTTNG_KERNEL_CONTEXT_IPC_NS
:
246 return lttng_add_ipc_ns_to_ctx(ctx
);
247 case LTTNG_KERNEL_CONTEXT_MNT_NS
:
248 return lttng_add_mnt_ns_to_ctx(ctx
);
249 case LTTNG_KERNEL_CONTEXT_NET_NS
:
250 return lttng_add_net_ns_to_ctx(ctx
);
251 case LTTNG_KERNEL_CONTEXT_PID_NS
:
252 return lttng_add_pid_ns_to_ctx(ctx
);
253 case LTTNG_KERNEL_CONTEXT_USER_NS
:
254 return lttng_add_user_ns_to_ctx(ctx
);
255 case LTTNG_KERNEL_CONTEXT_UTS_NS
:
256 return lttng_add_uts_ns_to_ctx(ctx
);
257 case LTTNG_KERNEL_CONTEXT_UID
:
258 return lttng_add_uid_to_ctx(ctx
);
259 case LTTNG_KERNEL_CONTEXT_EUID
:
260 return lttng_add_euid_to_ctx(ctx
);
261 case LTTNG_KERNEL_CONTEXT_SUID
:
262 return lttng_add_suid_to_ctx(ctx
);
263 case LTTNG_KERNEL_CONTEXT_GID
:
264 return lttng_add_gid_to_ctx(ctx
);
265 case LTTNG_KERNEL_CONTEXT_EGID
:
266 return lttng_add_egid_to_ctx(ctx
);
267 case LTTNG_KERNEL_CONTEXT_SGID
:
268 return lttng_add_sgid_to_ctx(ctx
);
269 case LTTNG_KERNEL_CONTEXT_VUID
:
270 return lttng_add_vuid_to_ctx(ctx
);
271 case LTTNG_KERNEL_CONTEXT_VEUID
:
272 return lttng_add_veuid_to_ctx(ctx
);
273 case LTTNG_KERNEL_CONTEXT_VSUID
:
274 return lttng_add_vsuid_to_ctx(ctx
);
275 case LTTNG_KERNEL_CONTEXT_VGID
:
276 return lttng_add_vgid_to_ctx(ctx
);
277 case LTTNG_KERNEL_CONTEXT_VEGID
:
278 return lttng_add_vegid_to_ctx(ctx
);
279 case LTTNG_KERNEL_CONTEXT_VSGID
:
280 return lttng_add_vsgid_to_ctx(ctx
);
287 * lttng_ioctl - lttng syscall through ioctl
293 * This ioctl implements lttng commands:
294 * LTTNG_KERNEL_SESSION
295 * Returns a LTTng trace session file descriptor
296 * LTTNG_KERNEL_TRACER_VERSION
297 * Returns the LTTng kernel tracer version
298 * LTTNG_KERNEL_TRACEPOINT_LIST
299 * Returns a file descriptor listing available tracepoints
300 * LTTNG_KERNEL_WAIT_QUIESCENT
301 * Returns after all previously running probes have completed
302 * LTTNG_KERNEL_TRACER_ABI_VERSION
303 * Returns the LTTng kernel tracer ABI version
305 * The returned session will be deleted when its file descriptor is closed.
308 long lttng_ioctl(struct file
*file
, unsigned int cmd
, unsigned long arg
)
311 case LTTNG_KERNEL_OLD_SESSION
:
312 case LTTNG_KERNEL_SESSION
:
313 return lttng_abi_create_session();
314 case LTTNG_KERNEL_OLD_TRACER_VERSION
:
316 struct lttng_kernel_tracer_version v
;
317 struct lttng_kernel_old_tracer_version oldv
;
318 struct lttng_kernel_old_tracer_version
*uversion
=
319 (struct lttng_kernel_old_tracer_version __user
*) arg
;
321 lttng_abi_tracer_version(&v
);
322 oldv
.major
= v
.major
;
323 oldv
.minor
= v
.minor
;
324 oldv
.patchlevel
= v
.patchlevel
;
326 if (copy_to_user(uversion
, &oldv
, sizeof(oldv
)))
330 case LTTNG_KERNEL_TRACER_VERSION
:
332 struct lttng_kernel_tracer_version version
;
333 struct lttng_kernel_tracer_version
*uversion
=
334 (struct lttng_kernel_tracer_version __user
*) arg
;
336 lttng_abi_tracer_version(&version
);
338 if (copy_to_user(uversion
, &version
, sizeof(version
)))
342 case LTTNG_KERNEL_TRACER_ABI_VERSION
:
344 struct lttng_kernel_tracer_abi_version version
;
345 struct lttng_kernel_tracer_abi_version
*uversion
=
346 (struct lttng_kernel_tracer_abi_version __user
*) arg
;
348 lttng_abi_tracer_abi_version(&version
);
350 if (copy_to_user(uversion
, &version
, sizeof(version
)))
354 case LTTNG_KERNEL_OLD_TRACEPOINT_LIST
:
355 case LTTNG_KERNEL_TRACEPOINT_LIST
:
356 return lttng_abi_tracepoint_list();
357 case LTTNG_KERNEL_SYSCALL_LIST
:
358 return lttng_abi_syscall_list();
359 case LTTNG_KERNEL_OLD_WAIT_QUIESCENT
:
360 case LTTNG_KERNEL_WAIT_QUIESCENT
:
363 case LTTNG_KERNEL_OLD_CALIBRATE
:
365 struct lttng_kernel_old_calibrate __user
*ucalibrate
=
366 (struct lttng_kernel_old_calibrate __user
*) arg
;
367 struct lttng_kernel_old_calibrate old_calibrate
;
368 struct lttng_kernel_calibrate calibrate
;
371 if (copy_from_user(&old_calibrate
, ucalibrate
, sizeof(old_calibrate
)))
373 calibrate
.type
= old_calibrate
.type
;
374 ret
= lttng_calibrate(&calibrate
);
375 if (copy_to_user(ucalibrate
, &old_calibrate
, sizeof(old_calibrate
)))
379 case LTTNG_KERNEL_CALIBRATE
:
381 struct lttng_kernel_calibrate __user
*ucalibrate
=
382 (struct lttng_kernel_calibrate __user
*) arg
;
383 struct lttng_kernel_calibrate calibrate
;
386 if (copy_from_user(&calibrate
, ucalibrate
, sizeof(calibrate
)))
388 ret
= lttng_calibrate(&calibrate
);
389 if (copy_to_user(ucalibrate
, &calibrate
, sizeof(calibrate
)))
398 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(5,6,0))
399 static const struct proc_ops lttng_proc_ops
= {
400 .proc_ioctl
= lttng_ioctl
,
402 .proc_compat_ioctl
= lttng_ioctl
,
403 #endif /* CONFIG_COMPAT */
406 static const struct file_operations lttng_proc_ops
= {
407 .owner
= THIS_MODULE
,
408 .unlocked_ioctl
= lttng_ioctl
,
410 .compat_ioctl
= lttng_ioctl
,
411 #endif /* CONFIG_COMPAT */
416 int lttng_abi_create_channel(struct file
*session_file
,
417 struct lttng_kernel_channel
*chan_param
,
418 enum channel_type channel_type
)
420 struct lttng_session
*session
= session_file
->private_data
;
421 const struct file_operations
*fops
= NULL
;
422 const char *transport_name
;
423 struct lttng_channel
*chan
;
424 struct file
*chan_file
;
428 chan_fd
= lttng_get_unused_fd();
433 switch (channel_type
) {
434 case PER_CPU_CHANNEL
:
435 fops
= <tng_channel_fops
;
437 case METADATA_CHANNEL
:
438 fops
= <tng_metadata_fops
;
442 chan_file
= anon_inode_getfile("[lttng_channel]",
445 if (IS_ERR(chan_file
)) {
446 ret
= PTR_ERR(chan_file
);
449 switch (channel_type
) {
450 case PER_CPU_CHANNEL
:
451 if (chan_param
->output
== LTTNG_KERNEL_SPLICE
) {
452 transport_name
= chan_param
->overwrite
?
453 "relay-overwrite" : "relay-discard";
454 } else if (chan_param
->output
== LTTNG_KERNEL_MMAP
) {
455 transport_name
= chan_param
->overwrite
?
456 "relay-overwrite-mmap" : "relay-discard-mmap";
461 case METADATA_CHANNEL
:
462 if (chan_param
->output
== LTTNG_KERNEL_SPLICE
)
463 transport_name
= "relay-metadata";
464 else if (chan_param
->output
== LTTNG_KERNEL_MMAP
)
465 transport_name
= "relay-metadata-mmap";
470 transport_name
= "<unknown>";
473 if (!atomic_long_add_unless(&session_file
->f_count
, 1, LONG_MAX
)) {
478 * We tolerate no failure path after channel creation. It will stay
479 * invariant for the rest of the session.
481 chan
= lttng_channel_create(session
, transport_name
, NULL
,
482 chan_param
->subbuf_size
,
483 chan_param
->num_subbuf
,
484 chan_param
->switch_timer_interval
,
485 chan_param
->read_timer_interval
,
491 chan
->file
= chan_file
;
492 chan_file
->private_data
= chan
;
493 fd_install(chan_fd
, chan_file
);
498 atomic_long_dec(&session_file
->f_count
);
502 put_unused_fd(chan_fd
);
508 int lttng_abi_session_set_name(struct lttng_session
*session
,
509 struct lttng_kernel_session_name
*name
)
513 len
= strnlen(name
->name
, LTTNG_KERNEL_SESSION_NAME_LEN
);
515 if (len
== LTTNG_KERNEL_SESSION_NAME_LEN
) {
516 /* Name is too long/malformed */
520 strcpy(session
->name
, name
->name
);
525 int lttng_abi_session_set_creation_time(struct lttng_session
*session
,
526 struct lttng_kernel_session_creation_time
*time
)
530 len
= strnlen(time
->iso8601
, LTTNG_KERNEL_SESSION_CREATION_TIME_ISO8601_LEN
);
532 if (len
== LTTNG_KERNEL_SESSION_CREATION_TIME_ISO8601_LEN
) {
533 /* Time is too long/malformed */
537 strcpy(session
->creation_time
, time
->iso8601
);
542 enum tracker_type
get_tracker_type(struct lttng_kernel_tracker_args
*tracker
)
544 switch (tracker
->type
) {
545 case LTTNG_KERNEL_TRACKER_PID
:
547 case LTTNG_KERNEL_TRACKER_VPID
:
549 case LTTNG_KERNEL_TRACKER_UID
:
551 case LTTNG_KERNEL_TRACKER_VUID
:
553 case LTTNG_KERNEL_TRACKER_GID
:
555 case LTTNG_KERNEL_TRACKER_VGID
:
558 return TRACKER_UNKNOWN
;
563 * lttng_session_ioctl - lttng session fd ioctl
569 * This ioctl implements lttng commands:
570 * LTTNG_KERNEL_CHANNEL
571 * Returns a LTTng channel file descriptor
572 * LTTNG_KERNEL_ENABLE
573 * Enables tracing for a session (weak enable)
574 * LTTNG_KERNEL_DISABLE
575 * Disables tracing for a session (strong disable)
576 * LTTNG_KERNEL_METADATA
577 * Returns a LTTng metadata file descriptor
578 * LTTNG_KERNEL_SESSION_TRACK_PID
579 * Add PID to session PID tracker
580 * LTTNG_KERNEL_SESSION_UNTRACK_PID
581 * Remove PID from session PID tracker
582 * LTTNG_KERNEL_SESSION_TRACK_ID
584 * LTTNG_KERNEL_SESSION_UNTRACK_ID
585 * Remove ID from tracker
587 * The returned channel will be deleted when its file descriptor is closed.
590 long lttng_session_ioctl(struct file
*file
, unsigned int cmd
, unsigned long arg
)
592 struct lttng_session
*session
= file
->private_data
;
593 struct lttng_kernel_channel chan_param
;
594 struct lttng_kernel_old_channel old_chan_param
;
597 case LTTNG_KERNEL_OLD_CHANNEL
:
599 if (copy_from_user(&old_chan_param
,
600 (struct lttng_kernel_old_channel __user
*) arg
,
601 sizeof(struct lttng_kernel_old_channel
)))
603 chan_param
.overwrite
= old_chan_param
.overwrite
;
604 chan_param
.subbuf_size
= old_chan_param
.subbuf_size
;
605 chan_param
.num_subbuf
= old_chan_param
.num_subbuf
;
606 chan_param
.switch_timer_interval
= old_chan_param
.switch_timer_interval
;
607 chan_param
.read_timer_interval
= old_chan_param
.read_timer_interval
;
608 chan_param
.output
= old_chan_param
.output
;
610 return lttng_abi_create_channel(file
, &chan_param
,
613 case LTTNG_KERNEL_CHANNEL
:
615 if (copy_from_user(&chan_param
,
616 (struct lttng_kernel_channel __user
*) arg
,
617 sizeof(struct lttng_kernel_channel
)))
619 return lttng_abi_create_channel(file
, &chan_param
,
622 case LTTNG_KERNEL_OLD_SESSION_START
:
623 case LTTNG_KERNEL_OLD_ENABLE
:
624 case LTTNG_KERNEL_SESSION_START
:
625 case LTTNG_KERNEL_ENABLE
:
626 return lttng_session_enable(session
);
627 case LTTNG_KERNEL_OLD_SESSION_STOP
:
628 case LTTNG_KERNEL_OLD_DISABLE
:
629 case LTTNG_KERNEL_SESSION_STOP
:
630 case LTTNG_KERNEL_DISABLE
:
631 return lttng_session_disable(session
);
632 case LTTNG_KERNEL_OLD_METADATA
:
634 if (copy_from_user(&old_chan_param
,
635 (struct lttng_kernel_old_channel __user
*) arg
,
636 sizeof(struct lttng_kernel_old_channel
)))
638 chan_param
.overwrite
= old_chan_param
.overwrite
;
639 chan_param
.subbuf_size
= old_chan_param
.subbuf_size
;
640 chan_param
.num_subbuf
= old_chan_param
.num_subbuf
;
641 chan_param
.switch_timer_interval
= old_chan_param
.switch_timer_interval
;
642 chan_param
.read_timer_interval
= old_chan_param
.read_timer_interval
;
643 chan_param
.output
= old_chan_param
.output
;
645 return lttng_abi_create_channel(file
, &chan_param
,
648 case LTTNG_KERNEL_METADATA
:
650 if (copy_from_user(&chan_param
,
651 (struct lttng_kernel_channel __user
*) arg
,
652 sizeof(struct lttng_kernel_channel
)))
654 return lttng_abi_create_channel(file
, &chan_param
,
657 case LTTNG_KERNEL_SESSION_TRACK_PID
:
658 return lttng_session_track_id(session
, TRACKER_PID
, (int) arg
);
659 case LTTNG_KERNEL_SESSION_UNTRACK_PID
:
660 return lttng_session_untrack_id(session
, TRACKER_PID
, (int) arg
);
661 case LTTNG_KERNEL_SESSION_TRACK_ID
:
663 struct lttng_kernel_tracker_args tracker
;
664 enum tracker_type tracker_type
;
666 if (copy_from_user(&tracker
,
667 (struct lttng_kernel_tracker_args __user
*) arg
,
668 sizeof(struct lttng_kernel_tracker_args
)))
670 tracker_type
= get_tracker_type(&tracker
);
671 if (tracker_type
== TRACKER_UNKNOWN
)
673 return lttng_session_track_id(session
, tracker_type
, tracker
.id
);
675 case LTTNG_KERNEL_SESSION_UNTRACK_ID
:
677 struct lttng_kernel_tracker_args tracker
;
678 enum tracker_type tracker_type
;
680 if (copy_from_user(&tracker
,
681 (struct lttng_kernel_tracker_args __user
*) arg
,
682 sizeof(struct lttng_kernel_tracker_args
)))
684 tracker_type
= get_tracker_type(&tracker
);
685 if (tracker_type
== TRACKER_UNKNOWN
)
687 return lttng_session_untrack_id(session
, tracker_type
,
690 case LTTNG_KERNEL_SESSION_LIST_TRACKER_PIDS
:
691 return lttng_session_list_tracker_ids(session
, TRACKER_PID
);
692 case LTTNG_KERNEL_SESSION_LIST_TRACKER_IDS
:
694 struct lttng_kernel_tracker_args tracker
;
695 enum tracker_type tracker_type
;
697 if (copy_from_user(&tracker
,
698 (struct lttng_kernel_tracker_args __user
*) arg
,
699 sizeof(struct lttng_kernel_tracker_args
)))
701 tracker_type
= get_tracker_type(&tracker
);
702 if (tracker_type
== TRACKER_UNKNOWN
)
704 return lttng_session_list_tracker_ids(session
, tracker_type
);
706 case LTTNG_KERNEL_SESSION_METADATA_REGEN
:
707 return lttng_session_metadata_regenerate(session
);
708 case LTTNG_KERNEL_SESSION_STATEDUMP
:
709 return lttng_session_statedump(session
);
710 case LTTNG_KERNEL_SESSION_SET_NAME
:
712 struct lttng_kernel_session_name name
;
714 if (copy_from_user(&name
,
715 (struct lttng_kernel_session_name __user
*) arg
,
716 sizeof(struct lttng_kernel_session_name
)))
718 return lttng_abi_session_set_name(session
, &name
);
720 case LTTNG_KERNEL_SESSION_SET_CREATION_TIME
:
722 struct lttng_kernel_session_creation_time time
;
724 if (copy_from_user(&time
,
725 (struct lttng_kernel_session_creation_time __user
*) arg
,
726 sizeof(struct lttng_kernel_session_creation_time
)))
728 return lttng_abi_session_set_creation_time(session
, &time
);
736 * Called when the last file reference is dropped.
738 * Big fat note: channels and events are invariant for the whole session after
739 * their creation. So this session destruction also destroys all channel and
740 * event structures specific to this session (they are not destroyed when their
741 * individual file is released).
744 int lttng_session_release(struct inode
*inode
, struct file
*file
)
746 struct lttng_session
*session
= file
->private_data
;
749 lttng_session_destroy(session
);
753 static const struct file_operations lttng_session_fops
= {
754 .owner
= THIS_MODULE
,
755 .release
= lttng_session_release
,
756 .unlocked_ioctl
= lttng_session_ioctl
,
758 .compat_ioctl
= lttng_session_ioctl
,
763 * lttng_metadata_ring_buffer_poll - LTTng ring buffer poll file operation
767 * Handles the poll operations for the metadata channels.
770 unsigned int lttng_metadata_ring_buffer_poll(struct file
*filp
,
773 struct lttng_metadata_stream
*stream
= filp
->private_data
;
774 struct lib_ring_buffer
*buf
= stream
->priv
;
776 unsigned int mask
= 0;
778 if (filp
->f_mode
& FMODE_READ
) {
779 poll_wait(filp
, &stream
->read_wait
, wait
);
781 finalized
= stream
->finalized
;
784 * lib_ring_buffer_is_finalized() contains a smp_rmb()
785 * ordering finalized load before offsets loads.
787 WARN_ON(atomic_long_read(&buf
->active_readers
) != 1);
792 mutex_lock(&stream
->metadata_cache
->lock
);
793 if (stream
->metadata_cache
->metadata_written
>
794 stream
->metadata_out
)
796 mutex_unlock(&stream
->metadata_cache
->lock
);
803 void lttng_metadata_ring_buffer_ioctl_put_next_subbuf(struct file
*filp
,
804 unsigned int cmd
, unsigned long arg
)
806 struct lttng_metadata_stream
*stream
= filp
->private_data
;
808 stream
->metadata_out
= stream
->metadata_in
;
812 * Reset the counter of how much metadata has been consumed to 0. That way,
813 * the consumer receives the content of the metadata cache unchanged. This is
814 * different from the metadata_regenerate where the offset from epoch is
815 * resampled, here we want the exact same content as the last time the metadata
816 * was generated. This command is only possible if all the metadata written
817 * in the cache has been output to the metadata stream to avoid corrupting the
820 * Return 0 on success, a negative value on error.
823 int lttng_metadata_cache_dump(struct lttng_metadata_stream
*stream
)
826 struct lttng_metadata_cache
*cache
= stream
->metadata_cache
;
828 mutex_lock(&cache
->lock
);
829 if (stream
->metadata_out
!= cache
->metadata_written
) {
833 stream
->metadata_out
= 0;
834 stream
->metadata_in
= 0;
835 wake_up_interruptible(&stream
->read_wait
);
839 mutex_unlock(&cache
->lock
);
844 long lttng_metadata_ring_buffer_ioctl(struct file
*filp
,
845 unsigned int cmd
, unsigned long arg
)
848 struct lttng_metadata_stream
*stream
= filp
->private_data
;
849 struct lib_ring_buffer
*buf
= stream
->priv
;
852 case RING_BUFFER_GET_NEXT_SUBBUF
:
854 struct lttng_metadata_stream
*stream
= filp
->private_data
;
855 struct lib_ring_buffer
*buf
= stream
->priv
;
856 struct channel
*chan
= buf
->backend
.chan
;
858 ret
= lttng_metadata_output_channel(stream
, chan
);
860 lib_ring_buffer_switch_slow(buf
, SWITCH_ACTIVE
);
866 case RING_BUFFER_GET_SUBBUF
:
869 * Random access is not allowed for metadata channel.
873 case RING_BUFFER_FLUSH_EMPTY
: /* Fall-through. */
874 case RING_BUFFER_FLUSH
:
876 struct lttng_metadata_stream
*stream
= filp
->private_data
;
877 struct lib_ring_buffer
*buf
= stream
->priv
;
878 struct channel
*chan
= buf
->backend
.chan
;
881 * Before doing the actual ring buffer flush, write up to one
882 * packet of metadata in the ring buffer.
884 ret
= lttng_metadata_output_channel(stream
, chan
);
889 case RING_BUFFER_GET_METADATA_VERSION
:
891 struct lttng_metadata_stream
*stream
= filp
->private_data
;
893 return put_u64(stream
->version
, arg
);
895 case RING_BUFFER_METADATA_CACHE_DUMP
:
897 struct lttng_metadata_stream
*stream
= filp
->private_data
;
899 return lttng_metadata_cache_dump(stream
);
904 /* PUT_SUBBUF is the one from lib ring buffer, unmodified. */
906 /* Performing lib ring buffer ioctl after our own. */
907 ret
= lib_ring_buffer_ioctl(filp
, cmd
, arg
, buf
);
912 case RING_BUFFER_PUT_NEXT_SUBBUF
:
914 lttng_metadata_ring_buffer_ioctl_put_next_subbuf(filp
,
927 long lttng_metadata_ring_buffer_compat_ioctl(struct file
*filp
,
928 unsigned int cmd
, unsigned long arg
)
931 struct lttng_metadata_stream
*stream
= filp
->private_data
;
932 struct lib_ring_buffer
*buf
= stream
->priv
;
935 case RING_BUFFER_GET_NEXT_SUBBUF
:
937 struct lttng_metadata_stream
*stream
= filp
->private_data
;
938 struct lib_ring_buffer
*buf
= stream
->priv
;
939 struct channel
*chan
= buf
->backend
.chan
;
941 ret
= lttng_metadata_output_channel(stream
, chan
);
943 lib_ring_buffer_switch_slow(buf
, SWITCH_ACTIVE
);
949 case RING_BUFFER_GET_SUBBUF
:
952 * Random access is not allowed for metadata channel.
956 case RING_BUFFER_FLUSH_EMPTY
: /* Fall-through. */
957 case RING_BUFFER_FLUSH
:
959 struct lttng_metadata_stream
*stream
= filp
->private_data
;
960 struct lib_ring_buffer
*buf
= stream
->priv
;
961 struct channel
*chan
= buf
->backend
.chan
;
964 * Before doing the actual ring buffer flush, write up to one
965 * packet of metadata in the ring buffer.
967 ret
= lttng_metadata_output_channel(stream
, chan
);
972 case RING_BUFFER_GET_METADATA_VERSION
:
974 struct lttng_metadata_stream
*stream
= filp
->private_data
;
976 return put_u64(stream
->version
, arg
);
978 case RING_BUFFER_METADATA_CACHE_DUMP
:
980 struct lttng_metadata_stream
*stream
= filp
->private_data
;
982 return lttng_metadata_cache_dump(stream
);
987 /* PUT_SUBBUF is the one from lib ring buffer, unmodified. */
989 /* Performing lib ring buffer ioctl after our own. */
990 ret
= lib_ring_buffer_compat_ioctl(filp
, cmd
, arg
, buf
);
995 case RING_BUFFER_PUT_NEXT_SUBBUF
:
997 lttng_metadata_ring_buffer_ioctl_put_next_subbuf(filp
,
1010 * This is not used by anonymous file descriptors. This code is left
1011 * there if we ever want to implement an inode with open() operation.
1014 int lttng_metadata_ring_buffer_open(struct inode
*inode
, struct file
*file
)
1016 struct lttng_metadata_stream
*stream
= inode
->i_private
;
1017 struct lib_ring_buffer
*buf
= stream
->priv
;
1019 file
->private_data
= buf
;
1021 * Since life-time of metadata cache differs from that of
1022 * session, we need to keep our own reference on the transport.
1024 if (!try_module_get(stream
->transport
->owner
)) {
1025 printk(KERN_WARNING
"LTT : Can't lock transport module.\n");
1028 return lib_ring_buffer_open(inode
, file
, buf
);
1032 int lttng_metadata_ring_buffer_release(struct inode
*inode
, struct file
*file
)
1034 struct lttng_metadata_stream
*stream
= file
->private_data
;
1035 struct lib_ring_buffer
*buf
= stream
->priv
;
1037 kref_put(&stream
->metadata_cache
->refcount
, metadata_cache_destroy
);
1038 module_put(stream
->transport
->owner
);
1039 return lib_ring_buffer_release(inode
, file
, buf
);
1043 ssize_t
lttng_metadata_ring_buffer_splice_read(struct file
*in
, loff_t
*ppos
,
1044 struct pipe_inode_info
*pipe
, size_t len
,
1047 struct lttng_metadata_stream
*stream
= in
->private_data
;
1048 struct lib_ring_buffer
*buf
= stream
->priv
;
1050 return lib_ring_buffer_splice_read(in
, ppos
, pipe
, len
,
1055 int lttng_metadata_ring_buffer_mmap(struct file
*filp
,
1056 struct vm_area_struct
*vma
)
1058 struct lttng_metadata_stream
*stream
= filp
->private_data
;
1059 struct lib_ring_buffer
*buf
= stream
->priv
;
1061 return lib_ring_buffer_mmap(filp
, vma
, buf
);
1065 const struct file_operations lttng_metadata_ring_buffer_file_operations
= {
1066 .owner
= THIS_MODULE
,
1067 .open
= lttng_metadata_ring_buffer_open
,
1068 .release
= lttng_metadata_ring_buffer_release
,
1069 .poll
= lttng_metadata_ring_buffer_poll
,
1070 .splice_read
= lttng_metadata_ring_buffer_splice_read
,
1071 .mmap
= lttng_metadata_ring_buffer_mmap
,
1072 .unlocked_ioctl
= lttng_metadata_ring_buffer_ioctl
,
1073 .llseek
= vfs_lib_ring_buffer_no_llseek
,
1074 #ifdef CONFIG_COMPAT
1075 .compat_ioctl
= lttng_metadata_ring_buffer_compat_ioctl
,
1080 int lttng_abi_create_stream_fd(struct file
*channel_file
, void *stream_priv
,
1081 const struct file_operations
*fops
)
1084 struct file
*stream_file
;
1086 stream_fd
= lttng_get_unused_fd();
1087 if (stream_fd
< 0) {
1091 stream_file
= anon_inode_getfile("[lttng_stream]", fops
,
1092 stream_priv
, O_RDWR
);
1093 if (IS_ERR(stream_file
)) {
1094 ret
= PTR_ERR(stream_file
);
1098 * OPEN_FMODE, called within anon_inode_getfile/alloc_file, don't honor
1099 * FMODE_LSEEK, FMODE_PREAD nor FMODE_PWRITE. We need to read from this
1100 * file descriptor, so we set FMODE_PREAD here.
1102 stream_file
->f_mode
|= FMODE_PREAD
;
1103 fd_install(stream_fd
, stream_file
);
1105 * The stream holds a reference to the channel within the generic ring
1106 * buffer library, so no need to hold a refcount on the channel and
1107 * session files here.
1112 put_unused_fd(stream_fd
);
1118 int lttng_abi_open_stream(struct file
*channel_file
)
1120 struct lttng_channel
*channel
= channel_file
->private_data
;
1121 struct lib_ring_buffer
*buf
;
1125 buf
= channel
->ops
->buffer_read_open(channel
->chan
);
1130 ret
= lttng_abi_create_stream_fd(channel_file
, stream_priv
,
1131 <tng_stream_ring_buffer_file_operations
);
1138 channel
->ops
->buffer_read_close(buf
);
1143 int lttng_abi_open_metadata_stream(struct file
*channel_file
)
1145 struct lttng_channel
*channel
= channel_file
->private_data
;
1146 struct lttng_session
*session
= channel
->session
;
1147 struct lib_ring_buffer
*buf
;
1149 struct lttng_metadata_stream
*metadata_stream
;
1152 buf
= channel
->ops
->buffer_read_open(channel
->chan
);
1156 metadata_stream
= kzalloc(sizeof(struct lttng_metadata_stream
),
1158 if (!metadata_stream
) {
1162 metadata_stream
->metadata_cache
= session
->metadata_cache
;
1163 init_waitqueue_head(&metadata_stream
->read_wait
);
1164 metadata_stream
->priv
= buf
;
1165 stream_priv
= metadata_stream
;
1166 metadata_stream
->transport
= channel
->transport
;
1169 * Since life-time of metadata cache differs from that of
1170 * session, we need to keep our own reference on the transport.
1172 if (!try_module_get(metadata_stream
->transport
->owner
)) {
1173 printk(KERN_WARNING
"LTT : Can't lock transport module.\n");
1178 kref_get(&session
->metadata_cache
->refcount
);
1179 ret
= lttng_abi_create_stream_fd(channel_file
, stream_priv
,
1180 <tng_metadata_ring_buffer_file_operations
);
1184 list_add(&metadata_stream
->list
,
1185 &session
->metadata_cache
->metadata_stream
);
1189 kref_put(&session
->metadata_cache
->refcount
, metadata_cache_destroy
);
1190 module_put(metadata_stream
->transport
->owner
);
1192 kfree(metadata_stream
);
1194 channel
->ops
->buffer_read_close(buf
);
1199 int lttng_abi_create_event(struct file
*channel_file
,
1200 struct lttng_kernel_event
*event_param
)
1202 struct lttng_channel
*channel
= channel_file
->private_data
;
1204 struct file
*event_file
;
1207 event_param
->name
[LTTNG_KERNEL_SYM_NAME_LEN
- 1] = '\0';
1208 switch (event_param
->instrumentation
) {
1209 case LTTNG_KERNEL_KRETPROBE
:
1210 event_param
->u
.kretprobe
.symbol_name
[LTTNG_KERNEL_SYM_NAME_LEN
- 1] = '\0';
1212 case LTTNG_KERNEL_KPROBE
:
1213 event_param
->u
.kprobe
.symbol_name
[LTTNG_KERNEL_SYM_NAME_LEN
- 1] = '\0';
1215 case LTTNG_KERNEL_FUNCTION
:
1217 /* Not implemented. */
1222 event_fd
= lttng_get_unused_fd();
1227 event_file
= anon_inode_getfile("[lttng_event]",
1230 if (IS_ERR(event_file
)) {
1231 ret
= PTR_ERR(event_file
);
1234 /* The event holds a reference on the channel */
1235 if (!atomic_long_add_unless(&channel_file
->f_count
, 1, LONG_MAX
)) {
1237 goto refcount_error
;
1239 if (event_param
->instrumentation
== LTTNG_KERNEL_TRACEPOINT
1240 || event_param
->instrumentation
== LTTNG_KERNEL_SYSCALL
) {
1241 struct lttng_enabler
*enabler
;
1243 if (strutils_is_star_glob_pattern(event_param
->name
)) {
1245 * If the event name is a star globbing pattern,
1246 * we create the special star globbing enabler.
1248 enabler
= lttng_enabler_create(LTTNG_ENABLER_STAR_GLOB
,
1249 event_param
, channel
);
1251 enabler
= lttng_enabler_create(LTTNG_ENABLER_NAME
,
1252 event_param
, channel
);
1256 struct lttng_event
*event
;
1259 * We tolerate no failure path after event creation. It
1260 * will stay invariant for the rest of the session.
1262 event
= lttng_event_create(channel
, event_param
,
1264 event_param
->instrumentation
);
1265 WARN_ON_ONCE(!event
);
1266 if (IS_ERR(event
)) {
1267 ret
= PTR_ERR(event
);
1272 event_file
->private_data
= priv
;
1273 fd_install(event_fd
, event_file
);
1277 atomic_long_dec(&channel_file
->f_count
);
1281 put_unused_fd(event_fd
);
1287 * lttng_channel_ioctl - lttng syscall through ioctl
1293 * This ioctl implements lttng commands:
1294 * LTTNG_KERNEL_STREAM
1295 * Returns an event stream file descriptor or failure.
1296 * (typically, one event stream records events from one CPU)
1297 * LTTNG_KERNEL_EVENT
1298 * Returns an event file descriptor or failure.
1299 * LTTNG_KERNEL_CONTEXT
1300 * Prepend a context field to each event in the channel
1301 * LTTNG_KERNEL_ENABLE
1302 * Enable recording for events in this channel (weak enable)
1303 * LTTNG_KERNEL_DISABLE
1304 * Disable recording for events in this channel (strong disable)
1306 * Channel and event file descriptors also hold a reference on the session.
1309 long lttng_channel_ioctl(struct file
*file
, unsigned int cmd
, unsigned long arg
)
1311 struct lttng_channel
*channel
= file
->private_data
;
1314 case LTTNG_KERNEL_OLD_STREAM
:
1315 case LTTNG_KERNEL_STREAM
:
1316 return lttng_abi_open_stream(file
);
1317 case LTTNG_KERNEL_OLD_EVENT
:
1319 struct lttng_kernel_event
*uevent_param
;
1320 struct lttng_kernel_old_event
*old_uevent_param
;
1323 uevent_param
= kmalloc(sizeof(struct lttng_kernel_event
),
1325 if (!uevent_param
) {
1329 old_uevent_param
= kmalloc(
1330 sizeof(struct lttng_kernel_old_event
),
1332 if (!old_uevent_param
) {
1334 goto old_event_error_free_param
;
1336 if (copy_from_user(old_uevent_param
,
1337 (struct lttng_kernel_old_event __user
*) arg
,
1338 sizeof(struct lttng_kernel_old_event
))) {
1340 goto old_event_error_free_old_param
;
1343 memcpy(uevent_param
->name
, old_uevent_param
->name
,
1344 sizeof(uevent_param
->name
));
1345 uevent_param
->instrumentation
=
1346 old_uevent_param
->instrumentation
;
1348 switch (old_uevent_param
->instrumentation
) {
1349 case LTTNG_KERNEL_KPROBE
:
1350 uevent_param
->u
.kprobe
.addr
=
1351 old_uevent_param
->u
.kprobe
.addr
;
1352 uevent_param
->u
.kprobe
.offset
=
1353 old_uevent_param
->u
.kprobe
.offset
;
1354 memcpy(uevent_param
->u
.kprobe
.symbol_name
,
1355 old_uevent_param
->u
.kprobe
.symbol_name
,
1356 sizeof(uevent_param
->u
.kprobe
.symbol_name
));
1358 case LTTNG_KERNEL_KRETPROBE
:
1359 uevent_param
->u
.kretprobe
.addr
=
1360 old_uevent_param
->u
.kretprobe
.addr
;
1361 uevent_param
->u
.kretprobe
.offset
=
1362 old_uevent_param
->u
.kretprobe
.offset
;
1363 memcpy(uevent_param
->u
.kretprobe
.symbol_name
,
1364 old_uevent_param
->u
.kretprobe
.symbol_name
,
1365 sizeof(uevent_param
->u
.kretprobe
.symbol_name
));
1367 case LTTNG_KERNEL_FUNCTION
:
1369 /* Not implemented. */
1374 ret
= lttng_abi_create_event(file
, uevent_param
);
1376 old_event_error_free_old_param
:
1377 kfree(old_uevent_param
);
1378 old_event_error_free_param
:
1379 kfree(uevent_param
);
1383 case LTTNG_KERNEL_EVENT
:
1385 struct lttng_kernel_event uevent_param
;
1387 if (copy_from_user(&uevent_param
,
1388 (struct lttng_kernel_event __user
*) arg
,
1389 sizeof(uevent_param
)))
1391 return lttng_abi_create_event(file
, &uevent_param
);
1393 case LTTNG_KERNEL_OLD_CONTEXT
:
1395 struct lttng_kernel_context
*ucontext_param
;
1396 struct lttng_kernel_old_context
*old_ucontext_param
;
1399 ucontext_param
= kmalloc(sizeof(struct lttng_kernel_context
),
1401 if (!ucontext_param
) {
1405 old_ucontext_param
= kmalloc(sizeof(struct lttng_kernel_old_context
),
1407 if (!old_ucontext_param
) {
1409 goto old_ctx_error_free_param
;
1412 if (copy_from_user(old_ucontext_param
,
1413 (struct lttng_kernel_old_context __user
*) arg
,
1414 sizeof(struct lttng_kernel_old_context
))) {
1416 goto old_ctx_error_free_old_param
;
1418 ucontext_param
->ctx
= old_ucontext_param
->ctx
;
1419 memcpy(ucontext_param
->padding
, old_ucontext_param
->padding
,
1420 sizeof(ucontext_param
->padding
));
1421 /* only type that uses the union */
1422 if (old_ucontext_param
->ctx
== LTTNG_KERNEL_CONTEXT_PERF_COUNTER
) {
1423 ucontext_param
->u
.perf_counter
.type
=
1424 old_ucontext_param
->u
.perf_counter
.type
;
1425 ucontext_param
->u
.perf_counter
.config
=
1426 old_ucontext_param
->u
.perf_counter
.config
;
1427 memcpy(ucontext_param
->u
.perf_counter
.name
,
1428 old_ucontext_param
->u
.perf_counter
.name
,
1429 sizeof(ucontext_param
->u
.perf_counter
.name
));
1432 ret
= lttng_abi_add_context(file
,
1434 &channel
->ctx
, channel
->session
);
1436 old_ctx_error_free_old_param
:
1437 kfree(old_ucontext_param
);
1438 old_ctx_error_free_param
:
1439 kfree(ucontext_param
);
1443 case LTTNG_KERNEL_CONTEXT
:
1445 struct lttng_kernel_context ucontext_param
;
1447 if (copy_from_user(&ucontext_param
,
1448 (struct lttng_kernel_context __user
*) arg
,
1449 sizeof(ucontext_param
)))
1451 return lttng_abi_add_context(file
,
1453 &channel
->ctx
, channel
->session
);
1455 case LTTNG_KERNEL_OLD_ENABLE
:
1456 case LTTNG_KERNEL_ENABLE
:
1457 return lttng_channel_enable(channel
);
1458 case LTTNG_KERNEL_OLD_DISABLE
:
1459 case LTTNG_KERNEL_DISABLE
:
1460 return lttng_channel_disable(channel
);
1461 case LTTNG_KERNEL_SYSCALL_MASK
:
1462 return lttng_channel_syscall_mask(channel
,
1463 (struct lttng_kernel_syscall_mask __user
*) arg
);
1465 return -ENOIOCTLCMD
;
1470 * lttng_metadata_ioctl - lttng syscall through ioctl
1476 * This ioctl implements lttng commands:
1477 * LTTNG_KERNEL_STREAM
1478 * Returns an event stream file descriptor or failure.
1480 * Channel and event file descriptors also hold a reference on the session.
1483 long lttng_metadata_ioctl(struct file
*file
, unsigned int cmd
, unsigned long arg
)
1486 case LTTNG_KERNEL_OLD_STREAM
:
1487 case LTTNG_KERNEL_STREAM
:
1488 return lttng_abi_open_metadata_stream(file
);
1490 return -ENOIOCTLCMD
;
1495 * lttng_channel_poll - lttng stream addition/removal monitoring
1500 unsigned int lttng_channel_poll(struct file
*file
, poll_table
*wait
)
1502 struct lttng_channel
*channel
= file
->private_data
;
1503 unsigned int mask
= 0;
1505 if (file
->f_mode
& FMODE_READ
) {
1506 poll_wait(file
, channel
->ops
->get_hp_wait_queue(channel
->chan
),
1509 if (channel
->ops
->is_disabled(channel
->chan
))
1511 if (channel
->ops
->is_finalized(channel
->chan
))
1513 if (channel
->ops
->buffer_has_read_closed_stream(channel
->chan
))
1514 return POLLIN
| POLLRDNORM
;
1522 int lttng_channel_release(struct inode
*inode
, struct file
*file
)
1524 struct lttng_channel
*channel
= file
->private_data
;
1527 fput(channel
->session
->file
);
1532 int lttng_metadata_channel_release(struct inode
*inode
, struct file
*file
)
1534 struct lttng_channel
*channel
= file
->private_data
;
1537 fput(channel
->session
->file
);
1538 lttng_metadata_channel_destroy(channel
);
1544 static const struct file_operations lttng_channel_fops
= {
1545 .owner
= THIS_MODULE
,
1546 .release
= lttng_channel_release
,
1547 .poll
= lttng_channel_poll
,
1548 .unlocked_ioctl
= lttng_channel_ioctl
,
1549 #ifdef CONFIG_COMPAT
1550 .compat_ioctl
= lttng_channel_ioctl
,
1554 static const struct file_operations lttng_metadata_fops
= {
1555 .owner
= THIS_MODULE
,
1556 .release
= lttng_metadata_channel_release
,
1557 .unlocked_ioctl
= lttng_metadata_ioctl
,
1558 #ifdef CONFIG_COMPAT
1559 .compat_ioctl
= lttng_metadata_ioctl
,
1564 * lttng_event_ioctl - lttng syscall through ioctl
1570 * This ioctl implements lttng commands:
1571 * LTTNG_KERNEL_CONTEXT
1572 * Prepend a context field to each record of this event
1573 * LTTNG_KERNEL_ENABLE
1574 * Enable recording for this event (weak enable)
1575 * LTTNG_KERNEL_DISABLE
1576 * Disable recording for this event (strong disable)
1579 long lttng_event_ioctl(struct file
*file
, unsigned int cmd
, unsigned long arg
)
1581 struct lttng_event
*event
;
1582 struct lttng_enabler
*enabler
;
1583 enum lttng_event_type
*evtype
= file
->private_data
;
1586 case LTTNG_KERNEL_OLD_CONTEXT
:
1588 /* Not implemented */
1591 case LTTNG_KERNEL_CONTEXT
:
1593 /* Not implemented */
1596 case LTTNG_KERNEL_OLD_ENABLE
:
1597 case LTTNG_KERNEL_ENABLE
:
1599 case LTTNG_TYPE_EVENT
:
1600 event
= file
->private_data
;
1601 return lttng_event_enable(event
);
1602 case LTTNG_TYPE_ENABLER
:
1603 enabler
= file
->private_data
;
1604 return lttng_enabler_enable(enabler
);
1609 case LTTNG_KERNEL_OLD_DISABLE
:
1610 case LTTNG_KERNEL_DISABLE
:
1612 case LTTNG_TYPE_EVENT
:
1613 event
= file
->private_data
;
1614 return lttng_event_disable(event
);
1615 case LTTNG_TYPE_ENABLER
:
1616 enabler
= file
->private_data
;
1617 return lttng_enabler_disable(enabler
);
1622 case LTTNG_KERNEL_FILTER
:
1624 case LTTNG_TYPE_EVENT
:
1626 case LTTNG_TYPE_ENABLER
:
1628 enabler
= file
->private_data
;
1629 return lttng_enabler_attach_bytecode(enabler
,
1630 (struct lttng_kernel_filter_bytecode __user
*) arg
);
1636 case LTTNG_KERNEL_ADD_CALLSITE
:
1638 case LTTNG_TYPE_EVENT
:
1639 event
= file
->private_data
;
1640 return lttng_event_add_callsite(event
,
1641 (struct lttng_kernel_event_callsite __user
*) arg
);
1642 case LTTNG_TYPE_ENABLER
:
1649 return -ENOIOCTLCMD
;
1654 int lttng_event_release(struct inode
*inode
, struct file
*file
)
1656 struct lttng_event
*event
;
1657 struct lttng_enabler
*enabler
;
1658 enum lttng_event_type
*evtype
= file
->private_data
;
1664 case LTTNG_TYPE_EVENT
:
1665 event
= file
->private_data
;
1667 fput(event
->chan
->file
);
1669 case LTTNG_TYPE_ENABLER
:
1670 enabler
= file
->private_data
;
1672 fput(enabler
->chan
->file
);
1682 /* TODO: filter control ioctl */
1683 static const struct file_operations lttng_event_fops
= {
1684 .owner
= THIS_MODULE
,
1685 .release
= lttng_event_release
,
1686 .unlocked_ioctl
= lttng_event_ioctl
,
1687 #ifdef CONFIG_COMPAT
1688 .compat_ioctl
= lttng_event_ioctl
,
1692 static int put_u64(uint64_t val
, unsigned long arg
)
1694 return put_user(val
, (uint64_t __user
*) arg
);
1697 static long lttng_stream_ring_buffer_ioctl(struct file
*filp
,
1698 unsigned int cmd
, unsigned long arg
)
1700 struct lib_ring_buffer
*buf
= filp
->private_data
;
1701 struct channel
*chan
= buf
->backend
.chan
;
1702 const struct lib_ring_buffer_config
*config
= &chan
->backend
.config
;
1703 const struct lttng_channel_ops
*ops
= chan
->backend
.priv_ops
;
1706 if (atomic_read(&chan
->record_disabled
))
1710 case LTTNG_RING_BUFFER_GET_TIMESTAMP_BEGIN
:
1714 ret
= ops
->timestamp_begin(config
, buf
, &ts
);
1717 return put_u64(ts
, arg
);
1719 case LTTNG_RING_BUFFER_GET_TIMESTAMP_END
:
1723 ret
= ops
->timestamp_end(config
, buf
, &ts
);
1726 return put_u64(ts
, arg
);
1728 case LTTNG_RING_BUFFER_GET_EVENTS_DISCARDED
:
1732 ret
= ops
->events_discarded(config
, buf
, &ed
);
1735 return put_u64(ed
, arg
);
1737 case LTTNG_RING_BUFFER_GET_CONTENT_SIZE
:
1741 ret
= ops
->content_size(config
, buf
, &cs
);
1744 return put_u64(cs
, arg
);
1746 case LTTNG_RING_BUFFER_GET_PACKET_SIZE
:
1750 ret
= ops
->packet_size(config
, buf
, &ps
);
1753 return put_u64(ps
, arg
);
1755 case LTTNG_RING_BUFFER_GET_STREAM_ID
:
1759 ret
= ops
->stream_id(config
, buf
, &si
);
1762 return put_u64(si
, arg
);
1764 case LTTNG_RING_BUFFER_GET_CURRENT_TIMESTAMP
:
1768 ret
= ops
->current_timestamp(config
, buf
, &ts
);
1771 return put_u64(ts
, arg
);
1773 case LTTNG_RING_BUFFER_GET_SEQ_NUM
:
1777 ret
= ops
->sequence_number(config
, buf
, &seq
);
1780 return put_u64(seq
, arg
);
1782 case LTTNG_RING_BUFFER_INSTANCE_ID
:
1786 ret
= ops
->instance_id(config
, buf
, &id
);
1789 return put_u64(id
, arg
);
1792 return lib_ring_buffer_file_operations
.unlocked_ioctl(filp
,
1800 #ifdef CONFIG_COMPAT
1801 static long lttng_stream_ring_buffer_compat_ioctl(struct file
*filp
,
1802 unsigned int cmd
, unsigned long arg
)
1804 struct lib_ring_buffer
*buf
= filp
->private_data
;
1805 struct channel
*chan
= buf
->backend
.chan
;
1806 const struct lib_ring_buffer_config
*config
= &chan
->backend
.config
;
1807 const struct lttng_channel_ops
*ops
= chan
->backend
.priv_ops
;
1810 if (atomic_read(&chan
->record_disabled
))
1814 case LTTNG_RING_BUFFER_COMPAT_GET_TIMESTAMP_BEGIN
:
1818 ret
= ops
->timestamp_begin(config
, buf
, &ts
);
1821 return put_u64(ts
, arg
);
1823 case LTTNG_RING_BUFFER_COMPAT_GET_TIMESTAMP_END
:
1827 ret
= ops
->timestamp_end(config
, buf
, &ts
);
1830 return put_u64(ts
, arg
);
1832 case LTTNG_RING_BUFFER_COMPAT_GET_EVENTS_DISCARDED
:
1836 ret
= ops
->events_discarded(config
, buf
, &ed
);
1839 return put_u64(ed
, arg
);
1841 case LTTNG_RING_BUFFER_COMPAT_GET_CONTENT_SIZE
:
1845 ret
= ops
->content_size(config
, buf
, &cs
);
1848 return put_u64(cs
, arg
);
1850 case LTTNG_RING_BUFFER_COMPAT_GET_PACKET_SIZE
:
1854 ret
= ops
->packet_size(config
, buf
, &ps
);
1857 return put_u64(ps
, arg
);
1859 case LTTNG_RING_BUFFER_COMPAT_GET_STREAM_ID
:
1863 ret
= ops
->stream_id(config
, buf
, &si
);
1866 return put_u64(si
, arg
);
1868 case LTTNG_RING_BUFFER_GET_CURRENT_TIMESTAMP
:
1872 ret
= ops
->current_timestamp(config
, buf
, &ts
);
1875 return put_u64(ts
, arg
);
1877 case LTTNG_RING_BUFFER_COMPAT_GET_SEQ_NUM
:
1881 ret
= ops
->sequence_number(config
, buf
, &seq
);
1884 return put_u64(seq
, arg
);
1886 case LTTNG_RING_BUFFER_COMPAT_INSTANCE_ID
:
1890 ret
= ops
->instance_id(config
, buf
, &id
);
1893 return put_u64(id
, arg
);
1896 return lib_ring_buffer_file_operations
.compat_ioctl(filp
,
1903 #endif /* CONFIG_COMPAT */
1905 static void lttng_stream_override_ring_buffer_fops(void)
1907 lttng_stream_ring_buffer_file_operations
.owner
= THIS_MODULE
;
1908 lttng_stream_ring_buffer_file_operations
.open
=
1909 lib_ring_buffer_file_operations
.open
;
1910 lttng_stream_ring_buffer_file_operations
.release
=
1911 lib_ring_buffer_file_operations
.release
;
1912 lttng_stream_ring_buffer_file_operations
.poll
=
1913 lib_ring_buffer_file_operations
.poll
;
1914 lttng_stream_ring_buffer_file_operations
.splice_read
=
1915 lib_ring_buffer_file_operations
.splice_read
;
1916 lttng_stream_ring_buffer_file_operations
.mmap
=
1917 lib_ring_buffer_file_operations
.mmap
;
1918 lttng_stream_ring_buffer_file_operations
.unlocked_ioctl
=
1919 lttng_stream_ring_buffer_ioctl
;
1920 lttng_stream_ring_buffer_file_operations
.llseek
=
1921 lib_ring_buffer_file_operations
.llseek
;
1922 #ifdef CONFIG_COMPAT
1923 lttng_stream_ring_buffer_file_operations
.compat_ioctl
=
1924 lttng_stream_ring_buffer_compat_ioctl
;
1928 int __init
lttng_abi_init(void)
1934 ret
= lttng_tp_mempool_init();
1939 lttng_proc_dentry
= proc_create_data("lttng", S_IRUSR
| S_IWUSR
, NULL
,
1940 <tng_proc_ops
, NULL
);
1942 if (!lttng_proc_dentry
) {
1943 printk(KERN_ERR
"Error creating LTTng control file\n");
1947 lttng_stream_override_ring_buffer_fops();
1951 lttng_tp_mempool_destroy();
1952 lttng_clock_unref();
1956 /* No __exit annotation because used by init error path too. */
1957 void lttng_abi_exit(void)
1959 lttng_tp_mempool_destroy();
1960 lttng_clock_unref();
1961 if (lttng_proc_dentry
)
1962 remove_proc_entry("lttng", NULL
);