1 /* SPDX-License-Identifier: (GPL-2.0 or LGPL-2.1)
7 * Copyright (C) 2010-2012 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
9 * Mimic system calls for:
10 * - session creation, returns a file descriptor or failure.
11 * - channel creation, returns a file descriptor or failure.
12 * - Operates on a session file descriptor
13 * - Takes all channel options as parameters.
14 * - stream get, returns a file descriptor or failure.
15 * - Operates on a channel file descriptor.
16 * - stream notifier get, returns a file descriptor or failure.
17 * - Operates on a channel file descriptor.
18 * - event creation, returns a file descriptor or failure.
19 * - Operates on a channel file descriptor
20 * - Takes an event name as parameter
21 * - Takes an instrumentation source as parameter
22 * - e.g. tracepoints, dynamic_probes...
23 * - Takes instrumentation source specific arguments.
26 #include <linux/module.h>
27 #include <linux/proc_fs.h>
28 #include <linux/anon_inodes.h>
29 #include <linux/file.h>
30 #include <linux/uaccess.h>
31 #include <linux/slab.h>
32 #include <linux/err.h>
33 #include <wrapper/vmalloc.h> /* for wrapper_vmalloc_sync_all() */
34 #include <wrapper/ringbuffer/vfs.h>
35 #include <wrapper/ringbuffer/backend.h>
36 #include <wrapper/ringbuffer/frontend.h>
37 #include <wrapper/poll.h>
38 #include <wrapper/file.h>
39 #include <wrapper/kref.h>
40 #include <lttng-string-utils.h>
41 #include <lttng-abi.h>
42 #include <lttng-abi-old.h>
43 #include <lttng-events.h>
44 #include <lttng-tracer.h>
45 #include <lttng-tp-mempool.h>
46 #include <lib/ringbuffer/frontend_types.h>
49 * This is LTTng's own personal way to create a system call as an external
50 * module. We use ioctl() on /proc/lttng.
53 static struct proc_dir_entry
*lttng_proc_dentry
;
55 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(5,6,0))
56 static const struct proc_ops lttng_proc_ops
;
58 static const struct file_operations lttng_proc_ops
;
61 static const struct file_operations lttng_session_fops
;
62 static const struct file_operations lttng_channel_fops
;
63 static const struct file_operations lttng_metadata_fops
;
64 static const struct file_operations lttng_event_fops
;
65 static struct file_operations lttng_stream_ring_buffer_file_operations
;
67 static int put_u64(uint64_t val
, unsigned long arg
);
70 * Teardown management: opened file descriptors keep a refcount on the module,
71 * so it can only exit when all file descriptors are closed.
75 int lttng_abi_create_session(void)
77 struct lttng_session
*session
;
78 struct file
*session_file
;
81 session
= lttng_session_create();
84 session_fd
= lttng_get_unused_fd();
89 session_file
= anon_inode_getfile("[lttng_session]",
92 if (IS_ERR(session_file
)) {
93 ret
= PTR_ERR(session_file
);
96 session
->file
= session_file
;
97 fd_install(session_fd
, session_file
);
101 put_unused_fd(session_fd
);
103 lttng_session_destroy(session
);
108 int lttng_abi_tracepoint_list(void)
110 struct file
*tracepoint_list_file
;
113 file_fd
= lttng_get_unused_fd();
119 tracepoint_list_file
= anon_inode_getfile("[lttng_tracepoint_list]",
120 <tng_tracepoint_list_fops
,
122 if (IS_ERR(tracepoint_list_file
)) {
123 ret
= PTR_ERR(tracepoint_list_file
);
126 ret
= lttng_tracepoint_list_fops
.open(NULL
, tracepoint_list_file
);
129 fd_install(file_fd
, tracepoint_list_file
);
133 fput(tracepoint_list_file
);
135 put_unused_fd(file_fd
);
140 #ifndef CONFIG_HAVE_SYSCALL_TRACEPOINTS
142 int lttng_abi_syscall_list(void)
148 int lttng_abi_syscall_list(void)
150 struct file
*syscall_list_file
;
153 file_fd
= lttng_get_unused_fd();
159 syscall_list_file
= anon_inode_getfile("[lttng_syscall_list]",
160 <tng_syscall_list_fops
,
162 if (IS_ERR(syscall_list_file
)) {
163 ret
= PTR_ERR(syscall_list_file
);
166 ret
= lttng_syscall_list_fops
.open(NULL
, syscall_list_file
);
169 fd_install(file_fd
, syscall_list_file
);
173 fput(syscall_list_file
);
175 put_unused_fd(file_fd
);
182 void lttng_abi_tracer_version(struct lttng_kernel_tracer_version
*v
)
184 v
->major
= LTTNG_MODULES_MAJOR_VERSION
;
185 v
->minor
= LTTNG_MODULES_MINOR_VERSION
;
186 v
->patchlevel
= LTTNG_MODULES_PATCHLEVEL_VERSION
;
190 void lttng_abi_tracer_abi_version(struct lttng_kernel_tracer_abi_version
*v
)
192 v
->major
= LTTNG_MODULES_ABI_MAJOR_VERSION
;
193 v
->minor
= LTTNG_MODULES_ABI_MINOR_VERSION
;
197 long lttng_abi_add_context(struct file
*file
,
198 struct lttng_kernel_context
*context_param
,
199 struct lttng_ctx
**ctx
, struct lttng_session
*session
)
202 if (session
->been_active
)
205 switch (context_param
->ctx
) {
206 case LTTNG_KERNEL_CONTEXT_PID
:
207 return lttng_add_pid_to_ctx(ctx
);
208 case LTTNG_KERNEL_CONTEXT_PRIO
:
209 return lttng_add_prio_to_ctx(ctx
);
210 case LTTNG_KERNEL_CONTEXT_NICE
:
211 return lttng_add_nice_to_ctx(ctx
);
212 case LTTNG_KERNEL_CONTEXT_VPID
:
213 return lttng_add_vpid_to_ctx(ctx
);
214 case LTTNG_KERNEL_CONTEXT_TID
:
215 return lttng_add_tid_to_ctx(ctx
);
216 case LTTNG_KERNEL_CONTEXT_VTID
:
217 return lttng_add_vtid_to_ctx(ctx
);
218 case LTTNG_KERNEL_CONTEXT_PPID
:
219 return lttng_add_ppid_to_ctx(ctx
);
220 case LTTNG_KERNEL_CONTEXT_VPPID
:
221 return lttng_add_vppid_to_ctx(ctx
);
222 case LTTNG_KERNEL_CONTEXT_PERF_COUNTER
:
223 context_param
->u
.perf_counter
.name
[LTTNG_KERNEL_SYM_NAME_LEN
- 1] = '\0';
224 return lttng_add_perf_counter_to_ctx(context_param
->u
.perf_counter
.type
,
225 context_param
->u
.perf_counter
.config
,
226 context_param
->u
.perf_counter
.name
,
228 case LTTNG_KERNEL_CONTEXT_PROCNAME
:
229 return lttng_add_procname_to_ctx(ctx
);
230 case LTTNG_KERNEL_CONTEXT_HOSTNAME
:
231 return lttng_add_hostname_to_ctx(ctx
);
232 case LTTNG_KERNEL_CONTEXT_CPU_ID
:
233 return lttng_add_cpu_id_to_ctx(ctx
);
234 case LTTNG_KERNEL_CONTEXT_INTERRUPTIBLE
:
235 return lttng_add_interruptible_to_ctx(ctx
);
236 case LTTNG_KERNEL_CONTEXT_NEED_RESCHEDULE
:
237 return lttng_add_need_reschedule_to_ctx(ctx
);
238 case LTTNG_KERNEL_CONTEXT_PREEMPTIBLE
:
239 return lttng_add_preemptible_to_ctx(ctx
);
240 case LTTNG_KERNEL_CONTEXT_MIGRATABLE
:
241 return lttng_add_migratable_to_ctx(ctx
);
242 case LTTNG_KERNEL_CONTEXT_CALLSTACK_KERNEL
:
243 case LTTNG_KERNEL_CONTEXT_CALLSTACK_USER
:
244 return lttng_add_callstack_to_ctx(ctx
, context_param
->ctx
);
245 case LTTNG_KERNEL_CONTEXT_CGROUP_NS
:
246 return lttng_add_cgroup_ns_to_ctx(ctx
);
247 case LTTNG_KERNEL_CONTEXT_IPC_NS
:
248 return lttng_add_ipc_ns_to_ctx(ctx
);
249 case LTTNG_KERNEL_CONTEXT_MNT_NS
:
250 return lttng_add_mnt_ns_to_ctx(ctx
);
251 case LTTNG_KERNEL_CONTEXT_NET_NS
:
252 return lttng_add_net_ns_to_ctx(ctx
);
253 case LTTNG_KERNEL_CONTEXT_PID_NS
:
254 return lttng_add_pid_ns_to_ctx(ctx
);
255 case LTTNG_KERNEL_CONTEXT_USER_NS
:
256 return lttng_add_user_ns_to_ctx(ctx
);
257 case LTTNG_KERNEL_CONTEXT_UTS_NS
:
258 return lttng_add_uts_ns_to_ctx(ctx
);
259 case LTTNG_KERNEL_CONTEXT_UID
:
260 return lttng_add_uid_to_ctx(ctx
);
261 case LTTNG_KERNEL_CONTEXT_EUID
:
262 return lttng_add_euid_to_ctx(ctx
);
263 case LTTNG_KERNEL_CONTEXT_SUID
:
264 return lttng_add_suid_to_ctx(ctx
);
265 case LTTNG_KERNEL_CONTEXT_GID
:
266 return lttng_add_gid_to_ctx(ctx
);
267 case LTTNG_KERNEL_CONTEXT_EGID
:
268 return lttng_add_egid_to_ctx(ctx
);
269 case LTTNG_KERNEL_CONTEXT_SGID
:
270 return lttng_add_sgid_to_ctx(ctx
);
271 case LTTNG_KERNEL_CONTEXT_VUID
:
272 return lttng_add_vuid_to_ctx(ctx
);
273 case LTTNG_KERNEL_CONTEXT_VEUID
:
274 return lttng_add_veuid_to_ctx(ctx
);
275 case LTTNG_KERNEL_CONTEXT_VSUID
:
276 return lttng_add_vsuid_to_ctx(ctx
);
277 case LTTNG_KERNEL_CONTEXT_VGID
:
278 return lttng_add_vgid_to_ctx(ctx
);
279 case LTTNG_KERNEL_CONTEXT_VEGID
:
280 return lttng_add_vegid_to_ctx(ctx
);
281 case LTTNG_KERNEL_CONTEXT_VSGID
:
282 return lttng_add_vsgid_to_ctx(ctx
);
289 * lttng_ioctl - lttng syscall through ioctl
295 * This ioctl implements lttng commands:
296 * LTTNG_KERNEL_SESSION
297 * Returns a LTTng trace session file descriptor
298 * LTTNG_KERNEL_TRACER_VERSION
299 * Returns the LTTng kernel tracer version
300 * LTTNG_KERNEL_TRACEPOINT_LIST
301 * Returns a file descriptor listing available tracepoints
302 * LTTNG_KERNEL_WAIT_QUIESCENT
303 * Returns after all previously running probes have completed
304 * LTTNG_KERNEL_TRACER_ABI_VERSION
305 * Returns the LTTng kernel tracer ABI version
307 * The returned session will be deleted when its file descriptor is closed.
310 long lttng_ioctl(struct file
*file
, unsigned int cmd
, unsigned long arg
)
313 case LTTNG_KERNEL_OLD_SESSION
:
314 case LTTNG_KERNEL_SESSION
:
315 return lttng_abi_create_session();
316 case LTTNG_KERNEL_OLD_TRACER_VERSION
:
318 struct lttng_kernel_tracer_version v
;
319 struct lttng_kernel_old_tracer_version oldv
;
320 struct lttng_kernel_old_tracer_version
*uversion
=
321 (struct lttng_kernel_old_tracer_version __user
*) arg
;
323 lttng_abi_tracer_version(&v
);
324 oldv
.major
= v
.major
;
325 oldv
.minor
= v
.minor
;
326 oldv
.patchlevel
= v
.patchlevel
;
328 if (copy_to_user(uversion
, &oldv
, sizeof(oldv
)))
332 case LTTNG_KERNEL_TRACER_VERSION
:
334 struct lttng_kernel_tracer_version version
;
335 struct lttng_kernel_tracer_version
*uversion
=
336 (struct lttng_kernel_tracer_version __user
*) arg
;
338 lttng_abi_tracer_version(&version
);
340 if (copy_to_user(uversion
, &version
, sizeof(version
)))
344 case LTTNG_KERNEL_TRACER_ABI_VERSION
:
346 struct lttng_kernel_tracer_abi_version version
;
347 struct lttng_kernel_tracer_abi_version
*uversion
=
348 (struct lttng_kernel_tracer_abi_version __user
*) arg
;
350 lttng_abi_tracer_abi_version(&version
);
352 if (copy_to_user(uversion
, &version
, sizeof(version
)))
356 case LTTNG_KERNEL_OLD_TRACEPOINT_LIST
:
357 case LTTNG_KERNEL_TRACEPOINT_LIST
:
358 return lttng_abi_tracepoint_list();
359 case LTTNG_KERNEL_SYSCALL_LIST
:
360 return lttng_abi_syscall_list();
361 case LTTNG_KERNEL_OLD_WAIT_QUIESCENT
:
362 case LTTNG_KERNEL_WAIT_QUIESCENT
:
365 case LTTNG_KERNEL_OLD_CALIBRATE
:
367 struct lttng_kernel_old_calibrate __user
*ucalibrate
=
368 (struct lttng_kernel_old_calibrate __user
*) arg
;
369 struct lttng_kernel_old_calibrate old_calibrate
;
370 struct lttng_kernel_calibrate calibrate
;
373 if (copy_from_user(&old_calibrate
, ucalibrate
, sizeof(old_calibrate
)))
375 calibrate
.type
= old_calibrate
.type
;
376 ret
= lttng_calibrate(&calibrate
);
377 if (copy_to_user(ucalibrate
, &old_calibrate
, sizeof(old_calibrate
)))
381 case LTTNG_KERNEL_CALIBRATE
:
383 struct lttng_kernel_calibrate __user
*ucalibrate
=
384 (struct lttng_kernel_calibrate __user
*) arg
;
385 struct lttng_kernel_calibrate calibrate
;
388 if (copy_from_user(&calibrate
, ucalibrate
, sizeof(calibrate
)))
390 ret
= lttng_calibrate(&calibrate
);
391 if (copy_to_user(ucalibrate
, &calibrate
, sizeof(calibrate
)))
400 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(5,6,0))
401 static const struct proc_ops lttng_proc_ops
= {
402 .proc_ioctl
= lttng_ioctl
,
404 .proc_compat_ioctl
= lttng_ioctl
,
405 #endif /* CONFIG_COMPAT */
408 static const struct file_operations lttng_proc_ops
= {
409 .owner
= THIS_MODULE
,
410 .unlocked_ioctl
= lttng_ioctl
,
412 .compat_ioctl
= lttng_ioctl
,
413 #endif /* CONFIG_COMPAT */
418 int lttng_abi_create_channel(struct file
*session_file
,
419 struct lttng_kernel_channel
*chan_param
,
420 enum channel_type channel_type
)
422 struct lttng_session
*session
= session_file
->private_data
;
423 const struct file_operations
*fops
= NULL
;
424 const char *transport_name
;
425 struct lttng_channel
*chan
;
426 struct file
*chan_file
;
430 chan_fd
= lttng_get_unused_fd();
435 switch (channel_type
) {
436 case PER_CPU_CHANNEL
:
437 fops
= <tng_channel_fops
;
439 case METADATA_CHANNEL
:
440 fops
= <tng_metadata_fops
;
444 chan_file
= anon_inode_getfile("[lttng_channel]",
447 if (IS_ERR(chan_file
)) {
448 ret
= PTR_ERR(chan_file
);
451 switch (channel_type
) {
452 case PER_CPU_CHANNEL
:
453 if (chan_param
->output
== LTTNG_KERNEL_SPLICE
) {
454 transport_name
= chan_param
->overwrite
?
455 "relay-overwrite" : "relay-discard";
456 } else if (chan_param
->output
== LTTNG_KERNEL_MMAP
) {
457 transport_name
= chan_param
->overwrite
?
458 "relay-overwrite-mmap" : "relay-discard-mmap";
463 case METADATA_CHANNEL
:
464 if (chan_param
->output
== LTTNG_KERNEL_SPLICE
)
465 transport_name
= "relay-metadata";
466 else if (chan_param
->output
== LTTNG_KERNEL_MMAP
)
467 transport_name
= "relay-metadata-mmap";
472 transport_name
= "<unknown>";
475 if (!atomic_long_add_unless(&session_file
->f_count
, 1, LONG_MAX
)) {
480 * We tolerate no failure path after channel creation. It will stay
481 * invariant for the rest of the session.
483 chan
= lttng_channel_create(session
, transport_name
, NULL
,
484 chan_param
->subbuf_size
,
485 chan_param
->num_subbuf
,
486 chan_param
->switch_timer_interval
,
487 chan_param
->read_timer_interval
,
493 chan
->file
= chan_file
;
494 chan_file
->private_data
= chan
;
495 fd_install(chan_fd
, chan_file
);
500 atomic_long_dec(&session_file
->f_count
);
504 put_unused_fd(chan_fd
);
510 int lttng_abi_session_set_name(struct lttng_session
*session
,
511 struct lttng_kernel_session_name
*name
)
515 len
= strnlen(name
->name
, LTTNG_KERNEL_SESSION_NAME_LEN
);
517 if (len
== LTTNG_KERNEL_SESSION_NAME_LEN
) {
518 /* Name is too long/malformed */
522 strcpy(session
->name
, name
->name
);
527 int lttng_abi_session_set_creation_time(struct lttng_session
*session
,
528 struct lttng_kernel_session_creation_time
*time
)
532 len
= strnlen(time
->iso8601
, LTTNG_KERNEL_SESSION_CREATION_TIME_ISO8601_LEN
);
534 if (len
== LTTNG_KERNEL_SESSION_CREATION_TIME_ISO8601_LEN
) {
535 /* Time is too long/malformed */
539 strcpy(session
->creation_time
, time
->iso8601
);
544 enum tracker_type
get_tracker_type(struct lttng_kernel_tracker_args
*tracker
)
546 switch (tracker
->type
) {
547 case LTTNG_KERNEL_TRACKER_PID
:
549 case LTTNG_KERNEL_TRACKER_VPID
:
551 case LTTNG_KERNEL_TRACKER_UID
:
553 case LTTNG_KERNEL_TRACKER_VUID
:
555 case LTTNG_KERNEL_TRACKER_GID
:
557 case LTTNG_KERNEL_TRACKER_VGID
:
560 return TRACKER_UNKNOWN
;
565 * lttng_session_ioctl - lttng session fd ioctl
571 * This ioctl implements lttng commands:
572 * LTTNG_KERNEL_CHANNEL
573 * Returns a LTTng channel file descriptor
574 * LTTNG_KERNEL_ENABLE
575 * Enables tracing for a session (weak enable)
576 * LTTNG_KERNEL_DISABLE
577 * Disables tracing for a session (strong disable)
578 * LTTNG_KERNEL_METADATA
579 * Returns a LTTng metadata file descriptor
580 * LTTNG_KERNEL_SESSION_TRACK_PID
581 * Add PID to session PID tracker
582 * LTTNG_KERNEL_SESSION_UNTRACK_PID
583 * Remove PID from session PID tracker
584 * LTTNG_KERNEL_SESSION_TRACK_ID
586 * LTTNG_KERNEL_SESSION_UNTRACK_ID
587 * Remove ID from tracker
589 * The returned channel will be deleted when its file descriptor is closed.
592 long lttng_session_ioctl(struct file
*file
, unsigned int cmd
, unsigned long arg
)
594 struct lttng_session
*session
= file
->private_data
;
595 struct lttng_kernel_channel chan_param
;
596 struct lttng_kernel_old_channel old_chan_param
;
599 case LTTNG_KERNEL_OLD_CHANNEL
:
601 if (copy_from_user(&old_chan_param
,
602 (struct lttng_kernel_old_channel __user
*) arg
,
603 sizeof(struct lttng_kernel_old_channel
)))
605 chan_param
.overwrite
= old_chan_param
.overwrite
;
606 chan_param
.subbuf_size
= old_chan_param
.subbuf_size
;
607 chan_param
.num_subbuf
= old_chan_param
.num_subbuf
;
608 chan_param
.switch_timer_interval
= old_chan_param
.switch_timer_interval
;
609 chan_param
.read_timer_interval
= old_chan_param
.read_timer_interval
;
610 chan_param
.output
= old_chan_param
.output
;
612 return lttng_abi_create_channel(file
, &chan_param
,
615 case LTTNG_KERNEL_CHANNEL
:
617 if (copy_from_user(&chan_param
,
618 (struct lttng_kernel_channel __user
*) arg
,
619 sizeof(struct lttng_kernel_channel
)))
621 return lttng_abi_create_channel(file
, &chan_param
,
624 case LTTNG_KERNEL_OLD_SESSION_START
:
625 case LTTNG_KERNEL_OLD_ENABLE
:
626 case LTTNG_KERNEL_SESSION_START
:
627 case LTTNG_KERNEL_ENABLE
:
628 return lttng_session_enable(session
);
629 case LTTNG_KERNEL_OLD_SESSION_STOP
:
630 case LTTNG_KERNEL_OLD_DISABLE
:
631 case LTTNG_KERNEL_SESSION_STOP
:
632 case LTTNG_KERNEL_DISABLE
:
633 return lttng_session_disable(session
);
634 case LTTNG_KERNEL_OLD_METADATA
:
636 if (copy_from_user(&old_chan_param
,
637 (struct lttng_kernel_old_channel __user
*) arg
,
638 sizeof(struct lttng_kernel_old_channel
)))
640 chan_param
.overwrite
= old_chan_param
.overwrite
;
641 chan_param
.subbuf_size
= old_chan_param
.subbuf_size
;
642 chan_param
.num_subbuf
= old_chan_param
.num_subbuf
;
643 chan_param
.switch_timer_interval
= old_chan_param
.switch_timer_interval
;
644 chan_param
.read_timer_interval
= old_chan_param
.read_timer_interval
;
645 chan_param
.output
= old_chan_param
.output
;
647 return lttng_abi_create_channel(file
, &chan_param
,
650 case LTTNG_KERNEL_METADATA
:
652 if (copy_from_user(&chan_param
,
653 (struct lttng_kernel_channel __user
*) arg
,
654 sizeof(struct lttng_kernel_channel
)))
656 return lttng_abi_create_channel(file
, &chan_param
,
659 case LTTNG_KERNEL_SESSION_TRACK_PID
:
660 return lttng_session_track_id(session
, TRACKER_PID
, (int) arg
);
661 case LTTNG_KERNEL_SESSION_UNTRACK_PID
:
662 return lttng_session_untrack_id(session
, TRACKER_PID
, (int) arg
);
663 case LTTNG_KERNEL_SESSION_TRACK_ID
:
665 struct lttng_kernel_tracker_args tracker
;
666 enum tracker_type tracker_type
;
668 if (copy_from_user(&tracker
,
669 (struct lttng_kernel_tracker_args __user
*) arg
,
670 sizeof(struct lttng_kernel_tracker_args
)))
672 tracker_type
= get_tracker_type(&tracker
);
673 if (tracker_type
== TRACKER_UNKNOWN
)
675 return lttng_session_track_id(session
, tracker_type
, tracker
.id
);
677 case LTTNG_KERNEL_SESSION_UNTRACK_ID
:
679 struct lttng_kernel_tracker_args tracker
;
680 enum tracker_type tracker_type
;
682 if (copy_from_user(&tracker
,
683 (struct lttng_kernel_tracker_args __user
*) arg
,
684 sizeof(struct lttng_kernel_tracker_args
)))
686 tracker_type
= get_tracker_type(&tracker
);
687 if (tracker_type
== TRACKER_UNKNOWN
)
689 return lttng_session_untrack_id(session
, tracker_type
,
692 case LTTNG_KERNEL_SESSION_LIST_TRACKER_PIDS
:
693 return lttng_session_list_tracker_ids(session
, TRACKER_PID
);
694 case LTTNG_KERNEL_SESSION_LIST_TRACKER_IDS
:
696 struct lttng_kernel_tracker_args tracker
;
697 enum tracker_type tracker_type
;
699 if (copy_from_user(&tracker
,
700 (struct lttng_kernel_tracker_args __user
*) arg
,
701 sizeof(struct lttng_kernel_tracker_args
)))
703 tracker_type
= get_tracker_type(&tracker
);
704 if (tracker_type
== TRACKER_UNKNOWN
)
706 return lttng_session_list_tracker_ids(session
, tracker_type
);
708 case LTTNG_KERNEL_SESSION_METADATA_REGEN
:
709 return lttng_session_metadata_regenerate(session
);
710 case LTTNG_KERNEL_SESSION_STATEDUMP
:
711 return lttng_session_statedump(session
);
712 case LTTNG_KERNEL_SESSION_SET_NAME
:
714 struct lttng_kernel_session_name name
;
716 if (copy_from_user(&name
,
717 (struct lttng_kernel_session_name __user
*) arg
,
718 sizeof(struct lttng_kernel_session_name
)))
720 return lttng_abi_session_set_name(session
, &name
);
722 case LTTNG_KERNEL_SESSION_SET_CREATION_TIME
:
724 struct lttng_kernel_session_creation_time time
;
726 if (copy_from_user(&time
,
727 (struct lttng_kernel_session_creation_time __user
*) arg
,
728 sizeof(struct lttng_kernel_session_creation_time
)))
730 return lttng_abi_session_set_creation_time(session
, &time
);
738 * Called when the last file reference is dropped.
740 * Big fat note: channels and events are invariant for the whole session after
741 * their creation. So this session destruction also destroys all channel and
742 * event structures specific to this session (they are not destroyed when their
743 * individual file is released).
746 int lttng_session_release(struct inode
*inode
, struct file
*file
)
748 struct lttng_session
*session
= file
->private_data
;
751 lttng_session_destroy(session
);
755 static const struct file_operations lttng_session_fops
= {
756 .owner
= THIS_MODULE
,
757 .release
= lttng_session_release
,
758 .unlocked_ioctl
= lttng_session_ioctl
,
760 .compat_ioctl
= lttng_session_ioctl
,
765 * lttng_metadata_ring_buffer_poll - LTTng ring buffer poll file operation
769 * Handles the poll operations for the metadata channels.
772 unsigned int lttng_metadata_ring_buffer_poll(struct file
*filp
,
775 struct lttng_metadata_stream
*stream
= filp
->private_data
;
776 struct lib_ring_buffer
*buf
= stream
->priv
;
778 unsigned int mask
= 0;
780 if (filp
->f_mode
& FMODE_READ
) {
781 poll_wait_set_exclusive(wait
);
782 poll_wait(filp
, &stream
->read_wait
, wait
);
784 finalized
= stream
->finalized
;
787 * lib_ring_buffer_is_finalized() contains a smp_rmb()
788 * ordering finalized load before offsets loads.
790 WARN_ON(atomic_long_read(&buf
->active_readers
) != 1);
795 mutex_lock(&stream
->metadata_cache
->lock
);
796 if (stream
->metadata_cache
->metadata_written
>
797 stream
->metadata_out
)
799 mutex_unlock(&stream
->metadata_cache
->lock
);
806 void lttng_metadata_ring_buffer_ioctl_put_next_subbuf(struct file
*filp
,
807 unsigned int cmd
, unsigned long arg
)
809 struct lttng_metadata_stream
*stream
= filp
->private_data
;
811 stream
->metadata_out
= stream
->metadata_in
;
815 * Reset the counter of how much metadata has been consumed to 0. That way,
816 * the consumer receives the content of the metadata cache unchanged. This is
817 * different from the metadata_regenerate where the offset from epoch is
818 * resampled, here we want the exact same content as the last time the metadata
819 * was generated. This command is only possible if all the metadata written
820 * in the cache has been output to the metadata stream to avoid corrupting the
823 * Return 0 on success, a negative value on error.
826 int lttng_metadata_cache_dump(struct lttng_metadata_stream
*stream
)
829 struct lttng_metadata_cache
*cache
= stream
->metadata_cache
;
831 mutex_lock(&cache
->lock
);
832 if (stream
->metadata_out
!= cache
->metadata_written
) {
836 stream
->metadata_out
= 0;
837 stream
->metadata_in
= 0;
838 wake_up_interruptible(&stream
->read_wait
);
842 mutex_unlock(&cache
->lock
);
847 long lttng_metadata_ring_buffer_ioctl(struct file
*filp
,
848 unsigned int cmd
, unsigned long arg
)
851 struct lttng_metadata_stream
*stream
= filp
->private_data
;
852 struct lib_ring_buffer
*buf
= stream
->priv
;
855 case RING_BUFFER_GET_NEXT_SUBBUF
:
857 struct lttng_metadata_stream
*stream
= filp
->private_data
;
858 struct lib_ring_buffer
*buf
= stream
->priv
;
859 struct channel
*chan
= buf
->backend
.chan
;
861 ret
= lttng_metadata_output_channel(stream
, chan
);
863 lib_ring_buffer_switch_slow(buf
, SWITCH_ACTIVE
);
869 case RING_BUFFER_GET_SUBBUF
:
872 * Random access is not allowed for metadata channel.
876 case RING_BUFFER_FLUSH_EMPTY
: /* Fall-through. */
877 case RING_BUFFER_FLUSH
:
879 struct lttng_metadata_stream
*stream
= filp
->private_data
;
880 struct lib_ring_buffer
*buf
= stream
->priv
;
881 struct channel
*chan
= buf
->backend
.chan
;
884 * Before doing the actual ring buffer flush, write up to one
885 * packet of metadata in the ring buffer.
887 ret
= lttng_metadata_output_channel(stream
, chan
);
892 case RING_BUFFER_GET_METADATA_VERSION
:
894 struct lttng_metadata_stream
*stream
= filp
->private_data
;
896 return put_u64(stream
->version
, arg
);
898 case RING_BUFFER_METADATA_CACHE_DUMP
:
900 struct lttng_metadata_stream
*stream
= filp
->private_data
;
902 return lttng_metadata_cache_dump(stream
);
907 /* PUT_SUBBUF is the one from lib ring buffer, unmodified. */
909 /* Performing lib ring buffer ioctl after our own. */
910 ret
= lib_ring_buffer_ioctl(filp
, cmd
, arg
, buf
);
915 case RING_BUFFER_PUT_NEXT_SUBBUF
:
917 lttng_metadata_ring_buffer_ioctl_put_next_subbuf(filp
,
930 long lttng_metadata_ring_buffer_compat_ioctl(struct file
*filp
,
931 unsigned int cmd
, unsigned long arg
)
934 struct lttng_metadata_stream
*stream
= filp
->private_data
;
935 struct lib_ring_buffer
*buf
= stream
->priv
;
938 case RING_BUFFER_GET_NEXT_SUBBUF
:
940 struct lttng_metadata_stream
*stream
= filp
->private_data
;
941 struct lib_ring_buffer
*buf
= stream
->priv
;
942 struct channel
*chan
= buf
->backend
.chan
;
944 ret
= lttng_metadata_output_channel(stream
, chan
);
946 lib_ring_buffer_switch_slow(buf
, SWITCH_ACTIVE
);
952 case RING_BUFFER_GET_SUBBUF
:
955 * Random access is not allowed for metadata channel.
959 case RING_BUFFER_FLUSH_EMPTY
: /* Fall-through. */
960 case RING_BUFFER_FLUSH
:
962 struct lttng_metadata_stream
*stream
= filp
->private_data
;
963 struct lib_ring_buffer
*buf
= stream
->priv
;
964 struct channel
*chan
= buf
->backend
.chan
;
967 * Before doing the actual ring buffer flush, write up to one
968 * packet of metadata in the ring buffer.
970 ret
= lttng_metadata_output_channel(stream
, chan
);
975 case RING_BUFFER_GET_METADATA_VERSION
:
977 struct lttng_metadata_stream
*stream
= filp
->private_data
;
979 return put_u64(stream
->version
, arg
);
981 case RING_BUFFER_METADATA_CACHE_DUMP
:
983 struct lttng_metadata_stream
*stream
= filp
->private_data
;
985 return lttng_metadata_cache_dump(stream
);
990 /* PUT_SUBBUF is the one from lib ring buffer, unmodified. */
992 /* Performing lib ring buffer ioctl after our own. */
993 ret
= lib_ring_buffer_compat_ioctl(filp
, cmd
, arg
, buf
);
998 case RING_BUFFER_PUT_NEXT_SUBBUF
:
1000 lttng_metadata_ring_buffer_ioctl_put_next_subbuf(filp
,
1013 * This is not used by anonymous file descriptors. This code is left
1014 * there if we ever want to implement an inode with open() operation.
1017 int lttng_metadata_ring_buffer_open(struct inode
*inode
, struct file
*file
)
1019 struct lttng_metadata_stream
*stream
= inode
->i_private
;
1020 struct lib_ring_buffer
*buf
= stream
->priv
;
1022 file
->private_data
= buf
;
1024 * Since life-time of metadata cache differs from that of
1025 * session, we need to keep our own reference on the transport.
1027 if (!try_module_get(stream
->transport
->owner
)) {
1028 printk(KERN_WARNING
"LTT : Can't lock transport module.\n");
1031 return lib_ring_buffer_open(inode
, file
, buf
);
1035 int lttng_metadata_ring_buffer_release(struct inode
*inode
, struct file
*file
)
1037 struct lttng_metadata_stream
*stream
= file
->private_data
;
1038 struct lib_ring_buffer
*buf
= stream
->priv
;
1040 kref_put(&stream
->metadata_cache
->refcount
, metadata_cache_destroy
);
1041 module_put(stream
->transport
->owner
);
1042 return lib_ring_buffer_release(inode
, file
, buf
);
1046 ssize_t
lttng_metadata_ring_buffer_splice_read(struct file
*in
, loff_t
*ppos
,
1047 struct pipe_inode_info
*pipe
, size_t len
,
1050 struct lttng_metadata_stream
*stream
= in
->private_data
;
1051 struct lib_ring_buffer
*buf
= stream
->priv
;
1053 return lib_ring_buffer_splice_read(in
, ppos
, pipe
, len
,
1058 int lttng_metadata_ring_buffer_mmap(struct file
*filp
,
1059 struct vm_area_struct
*vma
)
1061 struct lttng_metadata_stream
*stream
= filp
->private_data
;
1062 struct lib_ring_buffer
*buf
= stream
->priv
;
1064 return lib_ring_buffer_mmap(filp
, vma
, buf
);
1068 const struct file_operations lttng_metadata_ring_buffer_file_operations
= {
1069 .owner
= THIS_MODULE
,
1070 .open
= lttng_metadata_ring_buffer_open
,
1071 .release
= lttng_metadata_ring_buffer_release
,
1072 .poll
= lttng_metadata_ring_buffer_poll
,
1073 .splice_read
= lttng_metadata_ring_buffer_splice_read
,
1074 .mmap
= lttng_metadata_ring_buffer_mmap
,
1075 .unlocked_ioctl
= lttng_metadata_ring_buffer_ioctl
,
1076 .llseek
= vfs_lib_ring_buffer_no_llseek
,
1077 #ifdef CONFIG_COMPAT
1078 .compat_ioctl
= lttng_metadata_ring_buffer_compat_ioctl
,
1083 int lttng_abi_create_stream_fd(struct file
*channel_file
, void *stream_priv
,
1084 const struct file_operations
*fops
)
1087 struct file
*stream_file
;
1089 stream_fd
= lttng_get_unused_fd();
1090 if (stream_fd
< 0) {
1094 stream_file
= anon_inode_getfile("[lttng_stream]", fops
,
1095 stream_priv
, O_RDWR
);
1096 if (IS_ERR(stream_file
)) {
1097 ret
= PTR_ERR(stream_file
);
1101 * OPEN_FMODE, called within anon_inode_getfile/alloc_file, don't honor
1102 * FMODE_LSEEK, FMODE_PREAD nor FMODE_PWRITE. We need to read from this
1103 * file descriptor, so we set FMODE_PREAD here.
1105 stream_file
->f_mode
|= FMODE_PREAD
;
1106 fd_install(stream_fd
, stream_file
);
1108 * The stream holds a reference to the channel within the generic ring
1109 * buffer library, so no need to hold a refcount on the channel and
1110 * session files here.
1115 put_unused_fd(stream_fd
);
1121 int lttng_abi_open_stream(struct file
*channel_file
)
1123 struct lttng_channel
*channel
= channel_file
->private_data
;
1124 struct lib_ring_buffer
*buf
;
1128 buf
= channel
->ops
->buffer_read_open(channel
->chan
);
1133 ret
= lttng_abi_create_stream_fd(channel_file
, stream_priv
,
1134 <tng_stream_ring_buffer_file_operations
);
1141 channel
->ops
->buffer_read_close(buf
);
1146 int lttng_abi_open_metadata_stream(struct file
*channel_file
)
1148 struct lttng_channel
*channel
= channel_file
->private_data
;
1149 struct lttng_session
*session
= channel
->session
;
1150 struct lib_ring_buffer
*buf
;
1152 struct lttng_metadata_stream
*metadata_stream
;
1155 buf
= channel
->ops
->buffer_read_open(channel
->chan
);
1159 metadata_stream
= kzalloc(sizeof(struct lttng_metadata_stream
),
1161 if (!metadata_stream
) {
1165 metadata_stream
->metadata_cache
= session
->metadata_cache
;
1166 init_waitqueue_head(&metadata_stream
->read_wait
);
1167 metadata_stream
->priv
= buf
;
1168 stream_priv
= metadata_stream
;
1169 metadata_stream
->transport
= channel
->transport
;
1172 * Since life-time of metadata cache differs from that of
1173 * session, we need to keep our own reference on the transport.
1175 if (!try_module_get(metadata_stream
->transport
->owner
)) {
1176 printk(KERN_WARNING
"LTT : Can't lock transport module.\n");
1181 if (!lttng_kref_get(&session
->metadata_cache
->refcount
)) {
1186 ret
= lttng_abi_create_stream_fd(channel_file
, stream_priv
,
1187 <tng_metadata_ring_buffer_file_operations
);
1191 list_add(&metadata_stream
->list
,
1192 &session
->metadata_cache
->metadata_stream
);
1196 kref_put(&session
->metadata_cache
->refcount
, metadata_cache_destroy
);
1198 module_put(metadata_stream
->transport
->owner
);
1200 kfree(metadata_stream
);
1202 channel
->ops
->buffer_read_close(buf
);
1207 int lttng_abi_create_event(struct file
*channel_file
,
1208 struct lttng_kernel_event
*event_param
)
1210 struct lttng_channel
*channel
= channel_file
->private_data
;
1212 struct file
*event_file
;
1215 event_param
->name
[LTTNG_KERNEL_SYM_NAME_LEN
- 1] = '\0';
1216 switch (event_param
->instrumentation
) {
1217 case LTTNG_KERNEL_KRETPROBE
:
1218 event_param
->u
.kretprobe
.symbol_name
[LTTNG_KERNEL_SYM_NAME_LEN
- 1] = '\0';
1220 case LTTNG_KERNEL_KPROBE
:
1221 event_param
->u
.kprobe
.symbol_name
[LTTNG_KERNEL_SYM_NAME_LEN
- 1] = '\0';
1223 case LTTNG_KERNEL_FUNCTION
:
1224 event_param
->u
.ftrace
.symbol_name
[LTTNG_KERNEL_SYM_NAME_LEN
- 1] = '\0';
1229 event_fd
= lttng_get_unused_fd();
1234 event_file
= anon_inode_getfile("[lttng_event]",
1237 if (IS_ERR(event_file
)) {
1238 ret
= PTR_ERR(event_file
);
1241 /* The event holds a reference on the channel */
1242 if (!atomic_long_add_unless(&channel_file
->f_count
, 1, LONG_MAX
)) {
1244 goto refcount_error
;
1246 if (event_param
->instrumentation
== LTTNG_KERNEL_TRACEPOINT
1247 || event_param
->instrumentation
== LTTNG_KERNEL_SYSCALL
) {
1248 struct lttng_enabler
*enabler
;
1250 if (strutils_is_star_glob_pattern(event_param
->name
)) {
1252 * If the event name is a star globbing pattern,
1253 * we create the special star globbing enabler.
1255 enabler
= lttng_enabler_create(LTTNG_ENABLER_STAR_GLOB
,
1256 event_param
, channel
);
1258 enabler
= lttng_enabler_create(LTTNG_ENABLER_NAME
,
1259 event_param
, channel
);
1263 struct lttng_event
*event
;
1266 * We tolerate no failure path after event creation. It
1267 * will stay invariant for the rest of the session.
1269 event
= lttng_event_create(channel
, event_param
,
1271 event_param
->instrumentation
);
1272 WARN_ON_ONCE(!event
);
1273 if (IS_ERR(event
)) {
1274 ret
= PTR_ERR(event
);
1279 event_file
->private_data
= priv
;
1280 fd_install(event_fd
, event_file
);
1284 atomic_long_dec(&channel_file
->f_count
);
1288 put_unused_fd(event_fd
);
1294 * lttng_channel_ioctl - lttng syscall through ioctl
1300 * This ioctl implements lttng commands:
1301 * LTTNG_KERNEL_STREAM
1302 * Returns an event stream file descriptor or failure.
1303 * (typically, one event stream records events from one CPU)
1304 * LTTNG_KERNEL_EVENT
1305 * Returns an event file descriptor or failure.
1306 * LTTNG_KERNEL_CONTEXT
1307 * Prepend a context field to each event in the channel
1308 * LTTNG_KERNEL_ENABLE
1309 * Enable recording for events in this channel (weak enable)
1310 * LTTNG_KERNEL_DISABLE
1311 * Disable recording for events in this channel (strong disable)
1313 * Channel and event file descriptors also hold a reference on the session.
1316 long lttng_channel_ioctl(struct file
*file
, unsigned int cmd
, unsigned long arg
)
1318 struct lttng_channel
*channel
= file
->private_data
;
1321 case LTTNG_KERNEL_OLD_STREAM
:
1322 case LTTNG_KERNEL_STREAM
:
1323 return lttng_abi_open_stream(file
);
1324 case LTTNG_KERNEL_OLD_EVENT
:
1326 struct lttng_kernel_event
*uevent_param
;
1327 struct lttng_kernel_old_event
*old_uevent_param
;
1330 uevent_param
= kmalloc(sizeof(struct lttng_kernel_event
),
1332 if (!uevent_param
) {
1336 old_uevent_param
= kmalloc(
1337 sizeof(struct lttng_kernel_old_event
),
1339 if (!old_uevent_param
) {
1341 goto old_event_error_free_param
;
1343 if (copy_from_user(old_uevent_param
,
1344 (struct lttng_kernel_old_event __user
*) arg
,
1345 sizeof(struct lttng_kernel_old_event
))) {
1347 goto old_event_error_free_old_param
;
1350 memcpy(uevent_param
->name
, old_uevent_param
->name
,
1351 sizeof(uevent_param
->name
));
1352 uevent_param
->instrumentation
=
1353 old_uevent_param
->instrumentation
;
1355 switch (old_uevent_param
->instrumentation
) {
1356 case LTTNG_KERNEL_KPROBE
:
1357 uevent_param
->u
.kprobe
.addr
=
1358 old_uevent_param
->u
.kprobe
.addr
;
1359 uevent_param
->u
.kprobe
.offset
=
1360 old_uevent_param
->u
.kprobe
.offset
;
1361 memcpy(uevent_param
->u
.kprobe
.symbol_name
,
1362 old_uevent_param
->u
.kprobe
.symbol_name
,
1363 sizeof(uevent_param
->u
.kprobe
.symbol_name
));
1365 case LTTNG_KERNEL_KRETPROBE
:
1366 uevent_param
->u
.kretprobe
.addr
=
1367 old_uevent_param
->u
.kretprobe
.addr
;
1368 uevent_param
->u
.kretprobe
.offset
=
1369 old_uevent_param
->u
.kretprobe
.offset
;
1370 memcpy(uevent_param
->u
.kretprobe
.symbol_name
,
1371 old_uevent_param
->u
.kretprobe
.symbol_name
,
1372 sizeof(uevent_param
->u
.kretprobe
.symbol_name
));
1374 case LTTNG_KERNEL_FUNCTION
:
1375 memcpy(uevent_param
->u
.ftrace
.symbol_name
,
1376 old_uevent_param
->u
.ftrace
.symbol_name
,
1377 sizeof(uevent_param
->u
.ftrace
.symbol_name
));
1382 ret
= lttng_abi_create_event(file
, uevent_param
);
1384 old_event_error_free_old_param
:
1385 kfree(old_uevent_param
);
1386 old_event_error_free_param
:
1387 kfree(uevent_param
);
1391 case LTTNG_KERNEL_EVENT
:
1393 struct lttng_kernel_event uevent_param
;
1395 if (copy_from_user(&uevent_param
,
1396 (struct lttng_kernel_event __user
*) arg
,
1397 sizeof(uevent_param
)))
1399 return lttng_abi_create_event(file
, &uevent_param
);
1401 case LTTNG_KERNEL_OLD_CONTEXT
:
1403 struct lttng_kernel_context
*ucontext_param
;
1404 struct lttng_kernel_old_context
*old_ucontext_param
;
1407 ucontext_param
= kmalloc(sizeof(struct lttng_kernel_context
),
1409 if (!ucontext_param
) {
1413 old_ucontext_param
= kmalloc(sizeof(struct lttng_kernel_old_context
),
1415 if (!old_ucontext_param
) {
1417 goto old_ctx_error_free_param
;
1420 if (copy_from_user(old_ucontext_param
,
1421 (struct lttng_kernel_old_context __user
*) arg
,
1422 sizeof(struct lttng_kernel_old_context
))) {
1424 goto old_ctx_error_free_old_param
;
1426 ucontext_param
->ctx
= old_ucontext_param
->ctx
;
1427 memcpy(ucontext_param
->padding
, old_ucontext_param
->padding
,
1428 sizeof(ucontext_param
->padding
));
1429 /* only type that uses the union */
1430 if (old_ucontext_param
->ctx
== LTTNG_KERNEL_CONTEXT_PERF_COUNTER
) {
1431 ucontext_param
->u
.perf_counter
.type
=
1432 old_ucontext_param
->u
.perf_counter
.type
;
1433 ucontext_param
->u
.perf_counter
.config
=
1434 old_ucontext_param
->u
.perf_counter
.config
;
1435 memcpy(ucontext_param
->u
.perf_counter
.name
,
1436 old_ucontext_param
->u
.perf_counter
.name
,
1437 sizeof(ucontext_param
->u
.perf_counter
.name
));
1440 ret
= lttng_abi_add_context(file
,
1442 &channel
->ctx
, channel
->session
);
1444 old_ctx_error_free_old_param
:
1445 kfree(old_ucontext_param
);
1446 old_ctx_error_free_param
:
1447 kfree(ucontext_param
);
1451 case LTTNG_KERNEL_CONTEXT
:
1453 struct lttng_kernel_context ucontext_param
;
1455 if (copy_from_user(&ucontext_param
,
1456 (struct lttng_kernel_context __user
*) arg
,
1457 sizeof(ucontext_param
)))
1459 return lttng_abi_add_context(file
,
1461 &channel
->ctx
, channel
->session
);
1463 case LTTNG_KERNEL_OLD_ENABLE
:
1464 case LTTNG_KERNEL_ENABLE
:
1465 return lttng_channel_enable(channel
);
1466 case LTTNG_KERNEL_OLD_DISABLE
:
1467 case LTTNG_KERNEL_DISABLE
:
1468 return lttng_channel_disable(channel
);
1469 case LTTNG_KERNEL_SYSCALL_MASK
:
1470 return lttng_channel_syscall_mask(channel
,
1471 (struct lttng_kernel_syscall_mask __user
*) arg
);
1473 return -ENOIOCTLCMD
;
1478 * lttng_metadata_ioctl - lttng syscall through ioctl
1484 * This ioctl implements lttng commands:
1485 * LTTNG_KERNEL_STREAM
1486 * Returns an event stream file descriptor or failure.
1488 * Channel and event file descriptors also hold a reference on the session.
1491 long lttng_metadata_ioctl(struct file
*file
, unsigned int cmd
, unsigned long arg
)
1494 case LTTNG_KERNEL_OLD_STREAM
:
1495 case LTTNG_KERNEL_STREAM
:
1496 return lttng_abi_open_metadata_stream(file
);
1498 return -ENOIOCTLCMD
;
1503 * lttng_channel_poll - lttng stream addition/removal monitoring
1508 unsigned int lttng_channel_poll(struct file
*file
, poll_table
*wait
)
1510 struct lttng_channel
*channel
= file
->private_data
;
1511 unsigned int mask
= 0;
1513 if (file
->f_mode
& FMODE_READ
) {
1514 poll_wait_set_exclusive(wait
);
1515 poll_wait(file
, channel
->ops
->get_hp_wait_queue(channel
->chan
),
1518 if (channel
->ops
->is_disabled(channel
->chan
))
1520 if (channel
->ops
->is_finalized(channel
->chan
))
1522 if (channel
->ops
->buffer_has_read_closed_stream(channel
->chan
))
1523 return POLLIN
| POLLRDNORM
;
1531 int lttng_channel_release(struct inode
*inode
, struct file
*file
)
1533 struct lttng_channel
*channel
= file
->private_data
;
1536 fput(channel
->session
->file
);
1541 int lttng_metadata_channel_release(struct inode
*inode
, struct file
*file
)
1543 struct lttng_channel
*channel
= file
->private_data
;
1546 fput(channel
->session
->file
);
1547 lttng_metadata_channel_destroy(channel
);
1553 static const struct file_operations lttng_channel_fops
= {
1554 .owner
= THIS_MODULE
,
1555 .release
= lttng_channel_release
,
1556 .poll
= lttng_channel_poll
,
1557 .unlocked_ioctl
= lttng_channel_ioctl
,
1558 #ifdef CONFIG_COMPAT
1559 .compat_ioctl
= lttng_channel_ioctl
,
1563 static const struct file_operations lttng_metadata_fops
= {
1564 .owner
= THIS_MODULE
,
1565 .release
= lttng_metadata_channel_release
,
1566 .unlocked_ioctl
= lttng_metadata_ioctl
,
1567 #ifdef CONFIG_COMPAT
1568 .compat_ioctl
= lttng_metadata_ioctl
,
1573 * lttng_event_ioctl - lttng syscall through ioctl
1579 * This ioctl implements lttng commands:
1580 * LTTNG_KERNEL_CONTEXT
1581 * Prepend a context field to each record of this event
1582 * LTTNG_KERNEL_ENABLE
1583 * Enable recording for this event (weak enable)
1584 * LTTNG_KERNEL_DISABLE
1585 * Disable recording for this event (strong disable)
1588 long lttng_event_ioctl(struct file
*file
, unsigned int cmd
, unsigned long arg
)
1590 struct lttng_event
*event
;
1591 struct lttng_enabler
*enabler
;
1592 enum lttng_event_type
*evtype
= file
->private_data
;
1595 case LTTNG_KERNEL_OLD_CONTEXT
:
1597 /* Not implemented */
1600 case LTTNG_KERNEL_CONTEXT
:
1602 /* Not implemented */
1605 case LTTNG_KERNEL_OLD_ENABLE
:
1606 case LTTNG_KERNEL_ENABLE
:
1608 case LTTNG_TYPE_EVENT
:
1609 event
= file
->private_data
;
1610 return lttng_event_enable(event
);
1611 case LTTNG_TYPE_ENABLER
:
1612 enabler
= file
->private_data
;
1613 return lttng_enabler_enable(enabler
);
1618 case LTTNG_KERNEL_OLD_DISABLE
:
1619 case LTTNG_KERNEL_DISABLE
:
1621 case LTTNG_TYPE_EVENT
:
1622 event
= file
->private_data
;
1623 return lttng_event_disable(event
);
1624 case LTTNG_TYPE_ENABLER
:
1625 enabler
= file
->private_data
;
1626 return lttng_enabler_disable(enabler
);
1631 case LTTNG_KERNEL_FILTER
:
1633 case LTTNG_TYPE_EVENT
:
1635 case LTTNG_TYPE_ENABLER
:
1637 enabler
= file
->private_data
;
1638 return lttng_enabler_attach_bytecode(enabler
,
1639 (struct lttng_kernel_filter_bytecode __user
*) arg
);
1645 case LTTNG_KERNEL_ADD_CALLSITE
:
1647 case LTTNG_TYPE_EVENT
:
1648 event
= file
->private_data
;
1649 return lttng_event_add_callsite(event
,
1650 (struct lttng_kernel_event_callsite __user
*) arg
);
1651 case LTTNG_TYPE_ENABLER
:
1658 return -ENOIOCTLCMD
;
1663 int lttng_event_release(struct inode
*inode
, struct file
*file
)
1665 struct lttng_event
*event
;
1666 struct lttng_enabler
*enabler
;
1667 enum lttng_event_type
*evtype
= file
->private_data
;
1673 case LTTNG_TYPE_EVENT
:
1674 event
= file
->private_data
;
1676 fput(event
->chan
->file
);
1678 case LTTNG_TYPE_ENABLER
:
1679 enabler
= file
->private_data
;
1681 fput(enabler
->chan
->file
);
1691 /* TODO: filter control ioctl */
1692 static const struct file_operations lttng_event_fops
= {
1693 .owner
= THIS_MODULE
,
1694 .release
= lttng_event_release
,
1695 .unlocked_ioctl
= lttng_event_ioctl
,
1696 #ifdef CONFIG_COMPAT
1697 .compat_ioctl
= lttng_event_ioctl
,
1701 static int put_u64(uint64_t val
, unsigned long arg
)
1703 return put_user(val
, (uint64_t __user
*) arg
);
1706 static long lttng_stream_ring_buffer_ioctl(struct file
*filp
,
1707 unsigned int cmd
, unsigned long arg
)
1709 struct lib_ring_buffer
*buf
= filp
->private_data
;
1710 struct channel
*chan
= buf
->backend
.chan
;
1711 const struct lib_ring_buffer_config
*config
= &chan
->backend
.config
;
1712 const struct lttng_channel_ops
*ops
= chan
->backend
.priv_ops
;
1715 if (atomic_read(&chan
->record_disabled
))
1719 case LTTNG_RING_BUFFER_GET_TIMESTAMP_BEGIN
:
1723 ret
= ops
->timestamp_begin(config
, buf
, &ts
);
1726 return put_u64(ts
, arg
);
1728 case LTTNG_RING_BUFFER_GET_TIMESTAMP_END
:
1732 ret
= ops
->timestamp_end(config
, buf
, &ts
);
1735 return put_u64(ts
, arg
);
1737 case LTTNG_RING_BUFFER_GET_EVENTS_DISCARDED
:
1741 ret
= ops
->events_discarded(config
, buf
, &ed
);
1744 return put_u64(ed
, arg
);
1746 case LTTNG_RING_BUFFER_GET_CONTENT_SIZE
:
1750 ret
= ops
->content_size(config
, buf
, &cs
);
1753 return put_u64(cs
, arg
);
1755 case LTTNG_RING_BUFFER_GET_PACKET_SIZE
:
1759 ret
= ops
->packet_size(config
, buf
, &ps
);
1762 return put_u64(ps
, arg
);
1764 case LTTNG_RING_BUFFER_GET_STREAM_ID
:
1768 ret
= ops
->stream_id(config
, buf
, &si
);
1771 return put_u64(si
, arg
);
1773 case LTTNG_RING_BUFFER_GET_CURRENT_TIMESTAMP
:
1777 ret
= ops
->current_timestamp(config
, buf
, &ts
);
1780 return put_u64(ts
, arg
);
1782 case LTTNG_RING_BUFFER_GET_SEQ_NUM
:
1786 ret
= ops
->sequence_number(config
, buf
, &seq
);
1789 return put_u64(seq
, arg
);
1791 case LTTNG_RING_BUFFER_INSTANCE_ID
:
1795 ret
= ops
->instance_id(config
, buf
, &id
);
1798 return put_u64(id
, arg
);
1801 return lib_ring_buffer_file_operations
.unlocked_ioctl(filp
,
1809 #ifdef CONFIG_COMPAT
1810 static long lttng_stream_ring_buffer_compat_ioctl(struct file
*filp
,
1811 unsigned int cmd
, unsigned long arg
)
1813 struct lib_ring_buffer
*buf
= filp
->private_data
;
1814 struct channel
*chan
= buf
->backend
.chan
;
1815 const struct lib_ring_buffer_config
*config
= &chan
->backend
.config
;
1816 const struct lttng_channel_ops
*ops
= chan
->backend
.priv_ops
;
1819 if (atomic_read(&chan
->record_disabled
))
1823 case LTTNG_RING_BUFFER_COMPAT_GET_TIMESTAMP_BEGIN
:
1827 ret
= ops
->timestamp_begin(config
, buf
, &ts
);
1830 return put_u64(ts
, arg
);
1832 case LTTNG_RING_BUFFER_COMPAT_GET_TIMESTAMP_END
:
1836 ret
= ops
->timestamp_end(config
, buf
, &ts
);
1839 return put_u64(ts
, arg
);
1841 case LTTNG_RING_BUFFER_COMPAT_GET_EVENTS_DISCARDED
:
1845 ret
= ops
->events_discarded(config
, buf
, &ed
);
1848 return put_u64(ed
, arg
);
1850 case LTTNG_RING_BUFFER_COMPAT_GET_CONTENT_SIZE
:
1854 ret
= ops
->content_size(config
, buf
, &cs
);
1857 return put_u64(cs
, arg
);
1859 case LTTNG_RING_BUFFER_COMPAT_GET_PACKET_SIZE
:
1863 ret
= ops
->packet_size(config
, buf
, &ps
);
1866 return put_u64(ps
, arg
);
1868 case LTTNG_RING_BUFFER_COMPAT_GET_STREAM_ID
:
1872 ret
= ops
->stream_id(config
, buf
, &si
);
1875 return put_u64(si
, arg
);
1877 case LTTNG_RING_BUFFER_GET_CURRENT_TIMESTAMP
:
1881 ret
= ops
->current_timestamp(config
, buf
, &ts
);
1884 return put_u64(ts
, arg
);
1886 case LTTNG_RING_BUFFER_COMPAT_GET_SEQ_NUM
:
1890 ret
= ops
->sequence_number(config
, buf
, &seq
);
1893 return put_u64(seq
, arg
);
1895 case LTTNG_RING_BUFFER_COMPAT_INSTANCE_ID
:
1899 ret
= ops
->instance_id(config
, buf
, &id
);
1902 return put_u64(id
, arg
);
1905 return lib_ring_buffer_file_operations
.compat_ioctl(filp
,
1912 #endif /* CONFIG_COMPAT */
1914 static void lttng_stream_override_ring_buffer_fops(void)
1916 lttng_stream_ring_buffer_file_operations
.owner
= THIS_MODULE
;
1917 lttng_stream_ring_buffer_file_operations
.open
=
1918 lib_ring_buffer_file_operations
.open
;
1919 lttng_stream_ring_buffer_file_operations
.release
=
1920 lib_ring_buffer_file_operations
.release
;
1921 lttng_stream_ring_buffer_file_operations
.poll
=
1922 lib_ring_buffer_file_operations
.poll
;
1923 lttng_stream_ring_buffer_file_operations
.splice_read
=
1924 lib_ring_buffer_file_operations
.splice_read
;
1925 lttng_stream_ring_buffer_file_operations
.mmap
=
1926 lib_ring_buffer_file_operations
.mmap
;
1927 lttng_stream_ring_buffer_file_operations
.unlocked_ioctl
=
1928 lttng_stream_ring_buffer_ioctl
;
1929 lttng_stream_ring_buffer_file_operations
.llseek
=
1930 lib_ring_buffer_file_operations
.llseek
;
1931 #ifdef CONFIG_COMPAT
1932 lttng_stream_ring_buffer_file_operations
.compat_ioctl
=
1933 lttng_stream_ring_buffer_compat_ioctl
;
1937 int __init
lttng_abi_init(void)
1941 wrapper_vmalloc_sync_all();
1944 ret
= lttng_tp_mempool_init();
1949 lttng_proc_dentry
= proc_create_data("lttng", S_IRUSR
| S_IWUSR
, NULL
,
1950 <tng_proc_ops
, NULL
);
1952 if (!lttng_proc_dentry
) {
1953 printk(KERN_ERR
"Error creating LTTng control file\n");
1957 lttng_stream_override_ring_buffer_fops();
1961 lttng_tp_mempool_destroy();
1962 lttng_clock_unref();
1966 /* No __exit annotation because used by init error path too. */
1967 void lttng_abi_exit(void)
1969 lttng_tp_mempool_destroy();
1970 lttng_clock_unref();
1971 if (lttng_proc_dentry
)
1972 remove_proc_entry("lttng", NULL
);