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 <lttng-string-utils.h>
38 #include <lttng-abi.h>
39 #include <lttng-abi-old.h>
40 #include <lttng-events.h>
41 #include <lttng-tracer.h>
42 #include <lttng-tp-mempool.h>
43 #include <lib/ringbuffer/frontend_types.h>
46 * This is LTTng's own personal way to create a system call as an external
47 * module. We use ioctl() on /proc/lttng.
50 static struct proc_dir_entry
*lttng_proc_dentry
;
52 static const struct proc_ops lttng_proc_ops
;
54 static const struct file_operations lttng_session_fops
;
55 static const struct file_operations lttng_channel_fops
;
56 static const struct file_operations lttng_metadata_fops
;
57 static const struct file_operations lttng_event_fops
;
58 static struct file_operations lttng_stream_ring_buffer_file_operations
;
60 static int put_u64(uint64_t val
, unsigned long arg
);
63 * Teardown management: opened file descriptors keep a refcount on the module,
64 * so it can only exit when all file descriptors are closed.
68 int lttng_abi_create_session(void)
70 struct lttng_session
*session
;
71 struct file
*session_file
;
74 session
= lttng_session_create();
77 session_fd
= get_unused_fd_flags(0);
82 session_file
= anon_inode_getfile("[lttng_session]",
85 if (IS_ERR(session_file
)) {
86 ret
= PTR_ERR(session_file
);
89 session
->file
= session_file
;
90 fd_install(session_fd
, session_file
);
94 put_unused_fd(session_fd
);
96 lttng_session_destroy(session
);
101 int lttng_abi_tracepoint_list(void)
103 struct file
*tracepoint_list_file
;
106 file_fd
= get_unused_fd_flags(0);
112 tracepoint_list_file
= anon_inode_getfile("[lttng_tracepoint_list]",
113 <tng_tracepoint_list_fops
,
115 if (IS_ERR(tracepoint_list_file
)) {
116 ret
= PTR_ERR(tracepoint_list_file
);
119 ret
= lttng_tracepoint_list_fops
.open(NULL
, tracepoint_list_file
);
122 fd_install(file_fd
, tracepoint_list_file
);
126 fput(tracepoint_list_file
);
128 put_unused_fd(file_fd
);
133 #ifndef CONFIG_HAVE_SYSCALL_TRACEPOINTS
135 int lttng_abi_syscall_list(void)
141 int lttng_abi_syscall_list(void)
143 struct file
*syscall_list_file
;
146 file_fd
= get_unused_fd_flags(0);
152 syscall_list_file
= anon_inode_getfile("[lttng_syscall_list]",
153 <tng_syscall_list_fops
,
155 if (IS_ERR(syscall_list_file
)) {
156 ret
= PTR_ERR(syscall_list_file
);
159 ret
= lttng_syscall_list_fops
.open(NULL
, syscall_list_file
);
162 fd_install(file_fd
, syscall_list_file
);
166 fput(syscall_list_file
);
168 put_unused_fd(file_fd
);
175 void lttng_abi_tracer_version(struct lttng_kernel_tracer_version
*v
)
177 v
->major
= LTTNG_MODULES_MAJOR_VERSION
;
178 v
->minor
= LTTNG_MODULES_MINOR_VERSION
;
179 v
->patchlevel
= LTTNG_MODULES_PATCHLEVEL_VERSION
;
183 void lttng_abi_tracer_abi_version(struct lttng_kernel_tracer_abi_version
*v
)
185 v
->major
= LTTNG_MODULES_ABI_MAJOR_VERSION
;
186 v
->minor
= LTTNG_MODULES_ABI_MINOR_VERSION
;
190 long lttng_abi_add_context(struct file
*file
,
191 struct lttng_kernel_context
*context_param
,
192 struct lttng_ctx
**ctx
, struct lttng_session
*session
)
195 if (session
->been_active
)
198 switch (context_param
->ctx
) {
199 case LTTNG_KERNEL_CONTEXT_PID
:
200 return lttng_add_pid_to_ctx(ctx
);
201 case LTTNG_KERNEL_CONTEXT_PRIO
:
202 return lttng_add_prio_to_ctx(ctx
);
203 case LTTNG_KERNEL_CONTEXT_NICE
:
204 return lttng_add_nice_to_ctx(ctx
);
205 case LTTNG_KERNEL_CONTEXT_VPID
:
206 return lttng_add_vpid_to_ctx(ctx
);
207 case LTTNG_KERNEL_CONTEXT_TID
:
208 return lttng_add_tid_to_ctx(ctx
);
209 case LTTNG_KERNEL_CONTEXT_VTID
:
210 return lttng_add_vtid_to_ctx(ctx
);
211 case LTTNG_KERNEL_CONTEXT_PPID
:
212 return lttng_add_ppid_to_ctx(ctx
);
213 case LTTNG_KERNEL_CONTEXT_VPPID
:
214 return lttng_add_vppid_to_ctx(ctx
);
215 case LTTNG_KERNEL_CONTEXT_PERF_COUNTER
:
216 context_param
->u
.perf_counter
.name
[LTTNG_KERNEL_SYM_NAME_LEN
- 1] = '\0';
217 return lttng_add_perf_counter_to_ctx(context_param
->u
.perf_counter
.type
,
218 context_param
->u
.perf_counter
.config
,
219 context_param
->u
.perf_counter
.name
,
221 case LTTNG_KERNEL_CONTEXT_PROCNAME
:
222 return lttng_add_procname_to_ctx(ctx
);
223 case LTTNG_KERNEL_CONTEXT_HOSTNAME
:
224 return lttng_add_hostname_to_ctx(ctx
);
225 case LTTNG_KERNEL_CONTEXT_CPU_ID
:
226 return lttng_add_cpu_id_to_ctx(ctx
);
227 case LTTNG_KERNEL_CONTEXT_INTERRUPTIBLE
:
228 return lttng_add_interruptible_to_ctx(ctx
);
229 case LTTNG_KERNEL_CONTEXT_NEED_RESCHEDULE
:
230 return lttng_add_need_reschedule_to_ctx(ctx
);
231 case LTTNG_KERNEL_CONTEXT_PREEMPTIBLE
:
232 return lttng_add_preemptible_to_ctx(ctx
);
233 case LTTNG_KERNEL_CONTEXT_MIGRATABLE
:
234 return lttng_add_migratable_to_ctx(ctx
);
235 case LTTNG_KERNEL_CONTEXT_CALLSTACK_KERNEL
:
236 case LTTNG_KERNEL_CONTEXT_CALLSTACK_USER
:
237 return lttng_add_callstack_to_ctx(ctx
, context_param
->ctx
);
238 case LTTNG_KERNEL_CONTEXT_CGROUP_NS
:
239 return lttng_add_cgroup_ns_to_ctx(ctx
);
240 case LTTNG_KERNEL_CONTEXT_IPC_NS
:
241 return lttng_add_ipc_ns_to_ctx(ctx
);
242 case LTTNG_KERNEL_CONTEXT_MNT_NS
:
243 return lttng_add_mnt_ns_to_ctx(ctx
);
244 case LTTNG_KERNEL_CONTEXT_NET_NS
:
245 return lttng_add_net_ns_to_ctx(ctx
);
246 case LTTNG_KERNEL_CONTEXT_PID_NS
:
247 return lttng_add_pid_ns_to_ctx(ctx
);
248 case LTTNG_KERNEL_CONTEXT_USER_NS
:
249 return lttng_add_user_ns_to_ctx(ctx
);
250 case LTTNG_KERNEL_CONTEXT_UTS_NS
:
251 return lttng_add_uts_ns_to_ctx(ctx
);
252 case LTTNG_KERNEL_CONTEXT_UID
:
253 return lttng_add_uid_to_ctx(ctx
);
254 case LTTNG_KERNEL_CONTEXT_EUID
:
255 return lttng_add_euid_to_ctx(ctx
);
256 case LTTNG_KERNEL_CONTEXT_SUID
:
257 return lttng_add_suid_to_ctx(ctx
);
258 case LTTNG_KERNEL_CONTEXT_GID
:
259 return lttng_add_gid_to_ctx(ctx
);
260 case LTTNG_KERNEL_CONTEXT_EGID
:
261 return lttng_add_egid_to_ctx(ctx
);
262 case LTTNG_KERNEL_CONTEXT_SGID
:
263 return lttng_add_sgid_to_ctx(ctx
);
264 case LTTNG_KERNEL_CONTEXT_VUID
:
265 return lttng_add_vuid_to_ctx(ctx
);
266 case LTTNG_KERNEL_CONTEXT_VEUID
:
267 return lttng_add_veuid_to_ctx(ctx
);
268 case LTTNG_KERNEL_CONTEXT_VSUID
:
269 return lttng_add_vsuid_to_ctx(ctx
);
270 case LTTNG_KERNEL_CONTEXT_VGID
:
271 return lttng_add_vgid_to_ctx(ctx
);
272 case LTTNG_KERNEL_CONTEXT_VEGID
:
273 return lttng_add_vegid_to_ctx(ctx
);
274 case LTTNG_KERNEL_CONTEXT_VSGID
:
275 return lttng_add_vsgid_to_ctx(ctx
);
282 * lttng_ioctl - lttng syscall through ioctl
288 * This ioctl implements lttng commands:
289 * LTTNG_KERNEL_SESSION
290 * Returns a LTTng trace session file descriptor
291 * LTTNG_KERNEL_TRACER_VERSION
292 * Returns the LTTng kernel tracer version
293 * LTTNG_KERNEL_TRACEPOINT_LIST
294 * Returns a file descriptor listing available tracepoints
295 * LTTNG_KERNEL_WAIT_QUIESCENT
296 * Returns after all previously running probes have completed
297 * LTTNG_KERNEL_TRACER_ABI_VERSION
298 * Returns the LTTng kernel tracer ABI version
300 * The returned session will be deleted when its file descriptor is closed.
303 long lttng_ioctl(struct file
*file
, unsigned int cmd
, unsigned long arg
)
306 case LTTNG_KERNEL_OLD_SESSION
:
307 case LTTNG_KERNEL_SESSION
:
308 return lttng_abi_create_session();
309 case LTTNG_KERNEL_OLD_TRACER_VERSION
:
311 struct lttng_kernel_tracer_version v
;
312 struct lttng_kernel_old_tracer_version oldv
;
313 struct lttng_kernel_old_tracer_version
*uversion
=
314 (struct lttng_kernel_old_tracer_version __user
*) arg
;
316 lttng_abi_tracer_version(&v
);
317 oldv
.major
= v
.major
;
318 oldv
.minor
= v
.minor
;
319 oldv
.patchlevel
= v
.patchlevel
;
321 if (copy_to_user(uversion
, &oldv
, sizeof(oldv
)))
325 case LTTNG_KERNEL_TRACER_VERSION
:
327 struct lttng_kernel_tracer_version version
;
328 struct lttng_kernel_tracer_version
*uversion
=
329 (struct lttng_kernel_tracer_version __user
*) arg
;
331 lttng_abi_tracer_version(&version
);
333 if (copy_to_user(uversion
, &version
, sizeof(version
)))
337 case LTTNG_KERNEL_TRACER_ABI_VERSION
:
339 struct lttng_kernel_tracer_abi_version version
;
340 struct lttng_kernel_tracer_abi_version
*uversion
=
341 (struct lttng_kernel_tracer_abi_version __user
*) arg
;
343 lttng_abi_tracer_abi_version(&version
);
345 if (copy_to_user(uversion
, &version
, sizeof(version
)))
349 case LTTNG_KERNEL_OLD_TRACEPOINT_LIST
:
350 case LTTNG_KERNEL_TRACEPOINT_LIST
:
351 return lttng_abi_tracepoint_list();
352 case LTTNG_KERNEL_SYSCALL_LIST
:
353 return lttng_abi_syscall_list();
354 case LTTNG_KERNEL_OLD_WAIT_QUIESCENT
:
355 case LTTNG_KERNEL_WAIT_QUIESCENT
:
358 case LTTNG_KERNEL_OLD_CALIBRATE
:
360 struct lttng_kernel_old_calibrate __user
*ucalibrate
=
361 (struct lttng_kernel_old_calibrate __user
*) arg
;
362 struct lttng_kernel_old_calibrate old_calibrate
;
363 struct lttng_kernel_calibrate calibrate
;
366 if (copy_from_user(&old_calibrate
, ucalibrate
, sizeof(old_calibrate
)))
368 calibrate
.type
= old_calibrate
.type
;
369 ret
= lttng_calibrate(&calibrate
);
370 if (copy_to_user(ucalibrate
, &old_calibrate
, sizeof(old_calibrate
)))
374 case LTTNG_KERNEL_CALIBRATE
:
376 struct lttng_kernel_calibrate __user
*ucalibrate
=
377 (struct lttng_kernel_calibrate __user
*) arg
;
378 struct lttng_kernel_calibrate calibrate
;
381 if (copy_from_user(&calibrate
, ucalibrate
, sizeof(calibrate
)))
383 ret
= lttng_calibrate(&calibrate
);
384 if (copy_to_user(ucalibrate
, &calibrate
, sizeof(calibrate
)))
393 static const struct proc_ops lttng_proc_ops
= {
394 .proc_ioctl
= lttng_ioctl
,
396 .proc_compat_ioctl
= lttng_ioctl
,
397 #endif /* CONFIG_COMPAT */
401 int lttng_abi_create_channel(struct file
*session_file
,
402 struct lttng_kernel_channel
*chan_param
,
403 enum channel_type channel_type
)
405 struct lttng_session
*session
= session_file
->private_data
;
406 const struct file_operations
*fops
= NULL
;
407 const char *transport_name
;
408 struct lttng_channel
*chan
;
409 struct file
*chan_file
;
413 chan_fd
= get_unused_fd_flags(0);
418 switch (channel_type
) {
419 case PER_CPU_CHANNEL
:
420 fops
= <tng_channel_fops
;
422 case METADATA_CHANNEL
:
423 fops
= <tng_metadata_fops
;
427 chan_file
= anon_inode_getfile("[lttng_channel]",
430 if (IS_ERR(chan_file
)) {
431 ret
= PTR_ERR(chan_file
);
434 switch (channel_type
) {
435 case PER_CPU_CHANNEL
:
436 if (chan_param
->output
== LTTNG_KERNEL_SPLICE
) {
437 transport_name
= chan_param
->overwrite
?
438 "relay-overwrite" : "relay-discard";
439 } else if (chan_param
->output
== LTTNG_KERNEL_MMAP
) {
440 transport_name
= chan_param
->overwrite
?
441 "relay-overwrite-mmap" : "relay-discard-mmap";
446 case METADATA_CHANNEL
:
447 if (chan_param
->output
== LTTNG_KERNEL_SPLICE
)
448 transport_name
= "relay-metadata";
449 else if (chan_param
->output
== LTTNG_KERNEL_MMAP
)
450 transport_name
= "relay-metadata-mmap";
455 transport_name
= "<unknown>";
458 if (!atomic_long_add_unless(&session_file
->f_count
, 1, LONG_MAX
)) {
463 * We tolerate no failure path after channel creation. It will stay
464 * invariant for the rest of the session.
466 chan
= lttng_channel_create(session
, transport_name
, NULL
,
467 chan_param
->subbuf_size
,
468 chan_param
->num_subbuf
,
469 chan_param
->switch_timer_interval
,
470 chan_param
->read_timer_interval
,
476 chan
->file
= chan_file
;
477 chan_file
->private_data
= chan
;
478 fd_install(chan_fd
, chan_file
);
483 atomic_long_dec(&session_file
->f_count
);
487 put_unused_fd(chan_fd
);
493 int lttng_abi_session_set_name(struct lttng_session
*session
,
494 struct lttng_kernel_session_name
*name
)
498 len
= strnlen(name
->name
, LTTNG_KERNEL_SESSION_NAME_LEN
);
500 if (len
== LTTNG_KERNEL_SESSION_NAME_LEN
) {
501 /* Name is too long/malformed */
505 strcpy(session
->name
, name
->name
);
510 int lttng_abi_session_set_creation_time(struct lttng_session
*session
,
511 struct lttng_kernel_session_creation_time
*time
)
515 len
= strnlen(time
->iso8601
, LTTNG_KERNEL_SESSION_CREATION_TIME_ISO8601_LEN
);
517 if (len
== LTTNG_KERNEL_SESSION_CREATION_TIME_ISO8601_LEN
) {
518 /* Time is too long/malformed */
522 strcpy(session
->creation_time
, time
->iso8601
);
527 enum tracker_type
get_tracker_type(struct lttng_kernel_tracker_args
*tracker
)
529 switch (tracker
->type
) {
530 case LTTNG_KERNEL_TRACKER_PID
:
532 case LTTNG_KERNEL_TRACKER_VPID
:
534 case LTTNG_KERNEL_TRACKER_UID
:
536 case LTTNG_KERNEL_TRACKER_VUID
:
538 case LTTNG_KERNEL_TRACKER_GID
:
540 case LTTNG_KERNEL_TRACKER_VGID
:
543 return TRACKER_UNKNOWN
;
548 * lttng_session_ioctl - lttng session fd ioctl
554 * This ioctl implements lttng commands:
555 * LTTNG_KERNEL_CHANNEL
556 * Returns a LTTng channel file descriptor
557 * LTTNG_KERNEL_ENABLE
558 * Enables tracing for a session (weak enable)
559 * LTTNG_KERNEL_DISABLE
560 * Disables tracing for a session (strong disable)
561 * LTTNG_KERNEL_METADATA
562 * Returns a LTTng metadata file descriptor
563 * LTTNG_KERNEL_SESSION_TRACK_PID
564 * Add PID to session PID tracker
565 * LTTNG_KERNEL_SESSION_UNTRACK_PID
566 * Remove PID from session PID tracker
567 * LTTNG_KERNEL_SESSION_TRACK_ID
569 * LTTNG_KERNEL_SESSION_UNTRACK_ID
570 * Remove ID from tracker
572 * The returned channel will be deleted when its file descriptor is closed.
575 long lttng_session_ioctl(struct file
*file
, unsigned int cmd
, unsigned long arg
)
577 struct lttng_session
*session
= file
->private_data
;
578 struct lttng_kernel_channel chan_param
;
579 struct lttng_kernel_old_channel old_chan_param
;
582 case LTTNG_KERNEL_OLD_CHANNEL
:
584 if (copy_from_user(&old_chan_param
,
585 (struct lttng_kernel_old_channel __user
*) arg
,
586 sizeof(struct lttng_kernel_old_channel
)))
588 chan_param
.overwrite
= old_chan_param
.overwrite
;
589 chan_param
.subbuf_size
= old_chan_param
.subbuf_size
;
590 chan_param
.num_subbuf
= old_chan_param
.num_subbuf
;
591 chan_param
.switch_timer_interval
= old_chan_param
.switch_timer_interval
;
592 chan_param
.read_timer_interval
= old_chan_param
.read_timer_interval
;
593 chan_param
.output
= old_chan_param
.output
;
595 return lttng_abi_create_channel(file
, &chan_param
,
598 case LTTNG_KERNEL_CHANNEL
:
600 if (copy_from_user(&chan_param
,
601 (struct lttng_kernel_channel __user
*) arg
,
602 sizeof(struct lttng_kernel_channel
)))
604 return lttng_abi_create_channel(file
, &chan_param
,
607 case LTTNG_KERNEL_OLD_SESSION_START
:
608 case LTTNG_KERNEL_OLD_ENABLE
:
609 case LTTNG_KERNEL_SESSION_START
:
610 case LTTNG_KERNEL_ENABLE
:
611 return lttng_session_enable(session
);
612 case LTTNG_KERNEL_OLD_SESSION_STOP
:
613 case LTTNG_KERNEL_OLD_DISABLE
:
614 case LTTNG_KERNEL_SESSION_STOP
:
615 case LTTNG_KERNEL_DISABLE
:
616 return lttng_session_disable(session
);
617 case LTTNG_KERNEL_OLD_METADATA
:
619 if (copy_from_user(&old_chan_param
,
620 (struct lttng_kernel_old_channel __user
*) arg
,
621 sizeof(struct lttng_kernel_old_channel
)))
623 chan_param
.overwrite
= old_chan_param
.overwrite
;
624 chan_param
.subbuf_size
= old_chan_param
.subbuf_size
;
625 chan_param
.num_subbuf
= old_chan_param
.num_subbuf
;
626 chan_param
.switch_timer_interval
= old_chan_param
.switch_timer_interval
;
627 chan_param
.read_timer_interval
= old_chan_param
.read_timer_interval
;
628 chan_param
.output
= old_chan_param
.output
;
630 return lttng_abi_create_channel(file
, &chan_param
,
633 case LTTNG_KERNEL_METADATA
:
635 if (copy_from_user(&chan_param
,
636 (struct lttng_kernel_channel __user
*) arg
,
637 sizeof(struct lttng_kernel_channel
)))
639 return lttng_abi_create_channel(file
, &chan_param
,
642 case LTTNG_KERNEL_SESSION_TRACK_PID
:
643 return lttng_session_track_id(session
, TRACKER_PID
, (int) arg
);
644 case LTTNG_KERNEL_SESSION_UNTRACK_PID
:
645 return lttng_session_untrack_id(session
, TRACKER_PID
, (int) arg
);
646 case LTTNG_KERNEL_SESSION_TRACK_ID
:
648 struct lttng_kernel_tracker_args tracker
;
649 enum tracker_type tracker_type
;
651 if (copy_from_user(&tracker
,
652 (struct lttng_kernel_tracker_args __user
*) arg
,
653 sizeof(struct lttng_kernel_tracker_args
)))
655 tracker_type
= get_tracker_type(&tracker
);
656 if (tracker_type
== TRACKER_UNKNOWN
)
658 return lttng_session_track_id(session
, tracker_type
, tracker
.id
);
660 case LTTNG_KERNEL_SESSION_UNTRACK_ID
:
662 struct lttng_kernel_tracker_args tracker
;
663 enum tracker_type tracker_type
;
665 if (copy_from_user(&tracker
,
666 (struct lttng_kernel_tracker_args __user
*) arg
,
667 sizeof(struct lttng_kernel_tracker_args
)))
669 tracker_type
= get_tracker_type(&tracker
);
670 if (tracker_type
== TRACKER_UNKNOWN
)
672 return lttng_session_untrack_id(session
, tracker_type
,
675 case LTTNG_KERNEL_SESSION_LIST_TRACKER_PIDS
:
676 return lttng_session_list_tracker_ids(session
, TRACKER_PID
);
677 case LTTNG_KERNEL_SESSION_LIST_TRACKER_IDS
:
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_list_tracker_ids(session
, tracker_type
);
691 case LTTNG_KERNEL_SESSION_METADATA_REGEN
:
692 return lttng_session_metadata_regenerate(session
);
693 case LTTNG_KERNEL_SESSION_STATEDUMP
:
694 return lttng_session_statedump(session
);
695 case LTTNG_KERNEL_SESSION_SET_NAME
:
697 struct lttng_kernel_session_name name
;
699 if (copy_from_user(&name
,
700 (struct lttng_kernel_session_name __user
*) arg
,
701 sizeof(struct lttng_kernel_session_name
)))
703 return lttng_abi_session_set_name(session
, &name
);
705 case LTTNG_KERNEL_SESSION_SET_CREATION_TIME
:
707 struct lttng_kernel_session_creation_time time
;
709 if (copy_from_user(&time
,
710 (struct lttng_kernel_session_creation_time __user
*) arg
,
711 sizeof(struct lttng_kernel_session_creation_time
)))
713 return lttng_abi_session_set_creation_time(session
, &time
);
721 * Called when the last file reference is dropped.
723 * Big fat note: channels and events are invariant for the whole session after
724 * their creation. So this session destruction also destroys all channel and
725 * event structures specific to this session (they are not destroyed when their
726 * individual file is released).
729 int lttng_session_release(struct inode
*inode
, struct file
*file
)
731 struct lttng_session
*session
= file
->private_data
;
734 lttng_session_destroy(session
);
738 static const struct file_operations lttng_session_fops
= {
739 .owner
= THIS_MODULE
,
740 .release
= lttng_session_release
,
741 .unlocked_ioctl
= lttng_session_ioctl
,
743 .compat_ioctl
= lttng_session_ioctl
,
748 * lttng_metadata_ring_buffer_poll - LTTng ring buffer poll file operation
752 * Handles the poll operations for the metadata channels.
755 unsigned int lttng_metadata_ring_buffer_poll(struct file
*filp
,
758 struct lttng_metadata_stream
*stream
= filp
->private_data
;
759 struct lib_ring_buffer
*buf
= stream
->priv
;
761 unsigned int mask
= 0;
763 if (filp
->f_mode
& FMODE_READ
) {
764 poll_wait(filp
, &stream
->read_wait
, wait
);
766 finalized
= stream
->finalized
;
769 * lib_ring_buffer_is_finalized() contains a smp_rmb()
770 * ordering finalized load before offsets loads.
772 WARN_ON(atomic_long_read(&buf
->active_readers
) != 1);
777 mutex_lock(&stream
->metadata_cache
->lock
);
778 if (stream
->metadata_cache
->metadata_written
>
779 stream
->metadata_out
)
781 mutex_unlock(&stream
->metadata_cache
->lock
);
788 void lttng_metadata_ring_buffer_ioctl_put_next_subbuf(struct file
*filp
,
789 unsigned int cmd
, unsigned long arg
)
791 struct lttng_metadata_stream
*stream
= filp
->private_data
;
793 stream
->metadata_out
= stream
->metadata_in
;
797 * Reset the counter of how much metadata has been consumed to 0. That way,
798 * the consumer receives the content of the metadata cache unchanged. This is
799 * different from the metadata_regenerate where the offset from epoch is
800 * resampled, here we want the exact same content as the last time the metadata
801 * was generated. This command is only possible if all the metadata written
802 * in the cache has been output to the metadata stream to avoid corrupting the
805 * Return 0 on success, a negative value on error.
808 int lttng_metadata_cache_dump(struct lttng_metadata_stream
*stream
)
811 struct lttng_metadata_cache
*cache
= stream
->metadata_cache
;
813 mutex_lock(&cache
->lock
);
814 if (stream
->metadata_out
!= cache
->metadata_written
) {
818 stream
->metadata_out
= 0;
819 stream
->metadata_in
= 0;
820 wake_up_interruptible(&stream
->read_wait
);
824 mutex_unlock(&cache
->lock
);
829 long lttng_metadata_ring_buffer_ioctl(struct file
*filp
,
830 unsigned int cmd
, unsigned long arg
)
833 struct lttng_metadata_stream
*stream
= filp
->private_data
;
834 struct lib_ring_buffer
*buf
= stream
->priv
;
837 case RING_BUFFER_GET_NEXT_SUBBUF
:
839 struct lttng_metadata_stream
*stream
= filp
->private_data
;
840 struct lib_ring_buffer
*buf
= stream
->priv
;
841 struct channel
*chan
= buf
->backend
.chan
;
843 ret
= lttng_metadata_output_channel(stream
, chan
);
845 lib_ring_buffer_switch_slow(buf
, SWITCH_ACTIVE
);
851 case RING_BUFFER_GET_SUBBUF
:
854 * Random access is not allowed for metadata channel.
858 case RING_BUFFER_FLUSH_EMPTY
: /* Fall-through. */
859 case RING_BUFFER_FLUSH
:
861 struct lttng_metadata_stream
*stream
= filp
->private_data
;
862 struct lib_ring_buffer
*buf
= stream
->priv
;
863 struct channel
*chan
= buf
->backend
.chan
;
866 * Before doing the actual ring buffer flush, write up to one
867 * packet of metadata in the ring buffer.
869 ret
= lttng_metadata_output_channel(stream
, chan
);
874 case RING_BUFFER_GET_METADATA_VERSION
:
876 struct lttng_metadata_stream
*stream
= filp
->private_data
;
878 return put_u64(stream
->version
, arg
);
880 case RING_BUFFER_METADATA_CACHE_DUMP
:
882 struct lttng_metadata_stream
*stream
= filp
->private_data
;
884 return lttng_metadata_cache_dump(stream
);
889 /* PUT_SUBBUF is the one from lib ring buffer, unmodified. */
891 /* Performing lib ring buffer ioctl after our own. */
892 ret
= lib_ring_buffer_ioctl(filp
, cmd
, arg
, buf
);
897 case RING_BUFFER_PUT_NEXT_SUBBUF
:
899 lttng_metadata_ring_buffer_ioctl_put_next_subbuf(filp
,
912 long lttng_metadata_ring_buffer_compat_ioctl(struct file
*filp
,
913 unsigned int cmd
, unsigned long arg
)
916 struct lttng_metadata_stream
*stream
= filp
->private_data
;
917 struct lib_ring_buffer
*buf
= stream
->priv
;
920 case RING_BUFFER_GET_NEXT_SUBBUF
:
922 struct lttng_metadata_stream
*stream
= filp
->private_data
;
923 struct lib_ring_buffer
*buf
= stream
->priv
;
924 struct channel
*chan
= buf
->backend
.chan
;
926 ret
= lttng_metadata_output_channel(stream
, chan
);
928 lib_ring_buffer_switch_slow(buf
, SWITCH_ACTIVE
);
934 case RING_BUFFER_GET_SUBBUF
:
937 * Random access is not allowed for metadata channel.
941 case RING_BUFFER_FLUSH_EMPTY
: /* Fall-through. */
942 case RING_BUFFER_FLUSH
:
944 struct lttng_metadata_stream
*stream
= filp
->private_data
;
945 struct lib_ring_buffer
*buf
= stream
->priv
;
946 struct channel
*chan
= buf
->backend
.chan
;
949 * Before doing the actual ring buffer flush, write up to one
950 * packet of metadata in the ring buffer.
952 ret
= lttng_metadata_output_channel(stream
, chan
);
957 case RING_BUFFER_GET_METADATA_VERSION
:
959 struct lttng_metadata_stream
*stream
= filp
->private_data
;
961 return put_u64(stream
->version
, arg
);
963 case RING_BUFFER_METADATA_CACHE_DUMP
:
965 struct lttng_metadata_stream
*stream
= filp
->private_data
;
967 return lttng_metadata_cache_dump(stream
);
972 /* PUT_SUBBUF is the one from lib ring buffer, unmodified. */
974 /* Performing lib ring buffer ioctl after our own. */
975 ret
= lib_ring_buffer_compat_ioctl(filp
, cmd
, arg
, buf
);
980 case RING_BUFFER_PUT_NEXT_SUBBUF
:
982 lttng_metadata_ring_buffer_ioctl_put_next_subbuf(filp
,
995 * This is not used by anonymous file descriptors. This code is left
996 * there if we ever want to implement an inode with open() operation.
999 int lttng_metadata_ring_buffer_open(struct inode
*inode
, struct file
*file
)
1001 struct lttng_metadata_stream
*stream
= inode
->i_private
;
1002 struct lib_ring_buffer
*buf
= stream
->priv
;
1004 file
->private_data
= buf
;
1006 * Since life-time of metadata cache differs from that of
1007 * session, we need to keep our own reference on the transport.
1009 if (!try_module_get(stream
->transport
->owner
)) {
1010 printk(KERN_WARNING
"LTT : Can't lock transport module.\n");
1013 return lib_ring_buffer_open(inode
, file
, buf
);
1017 int lttng_metadata_ring_buffer_release(struct inode
*inode
, struct file
*file
)
1019 struct lttng_metadata_stream
*stream
= file
->private_data
;
1020 struct lib_ring_buffer
*buf
= stream
->priv
;
1022 kref_put(&stream
->metadata_cache
->refcount
, metadata_cache_destroy
);
1023 module_put(stream
->transport
->owner
);
1024 return lib_ring_buffer_release(inode
, file
, buf
);
1028 ssize_t
lttng_metadata_ring_buffer_splice_read(struct file
*in
, loff_t
*ppos
,
1029 struct pipe_inode_info
*pipe
, size_t len
,
1032 struct lttng_metadata_stream
*stream
= in
->private_data
;
1033 struct lib_ring_buffer
*buf
= stream
->priv
;
1035 return lib_ring_buffer_splice_read(in
, ppos
, pipe
, len
,
1040 int lttng_metadata_ring_buffer_mmap(struct file
*filp
,
1041 struct vm_area_struct
*vma
)
1043 struct lttng_metadata_stream
*stream
= filp
->private_data
;
1044 struct lib_ring_buffer
*buf
= stream
->priv
;
1046 return lib_ring_buffer_mmap(filp
, vma
, buf
);
1050 const struct file_operations lttng_metadata_ring_buffer_file_operations
= {
1051 .owner
= THIS_MODULE
,
1052 .open
= lttng_metadata_ring_buffer_open
,
1053 .release
= lttng_metadata_ring_buffer_release
,
1054 .poll
= lttng_metadata_ring_buffer_poll
,
1055 .splice_read
= lttng_metadata_ring_buffer_splice_read
,
1056 .mmap
= lttng_metadata_ring_buffer_mmap
,
1057 .unlocked_ioctl
= lttng_metadata_ring_buffer_ioctl
,
1058 .llseek
= vfs_lib_ring_buffer_no_llseek
,
1059 #ifdef CONFIG_COMPAT
1060 .compat_ioctl
= lttng_metadata_ring_buffer_compat_ioctl
,
1065 int lttng_abi_create_stream_fd(struct file
*channel_file
, void *stream_priv
,
1066 const struct file_operations
*fops
)
1069 struct file
*stream_file
;
1071 stream_fd
= get_unused_fd_flags(0);
1072 if (stream_fd
< 0) {
1076 stream_file
= anon_inode_getfile("[lttng_stream]", fops
,
1077 stream_priv
, O_RDWR
);
1078 if (IS_ERR(stream_file
)) {
1079 ret
= PTR_ERR(stream_file
);
1083 * OPEN_FMODE, called within anon_inode_getfile/alloc_file, don't honor
1084 * FMODE_LSEEK, FMODE_PREAD nor FMODE_PWRITE. We need to read from this
1085 * file descriptor, so we set FMODE_PREAD here.
1087 stream_file
->f_mode
|= FMODE_PREAD
;
1088 fd_install(stream_fd
, stream_file
);
1090 * The stream holds a reference to the channel within the generic ring
1091 * buffer library, so no need to hold a refcount on the channel and
1092 * session files here.
1097 put_unused_fd(stream_fd
);
1103 int lttng_abi_open_stream(struct file
*channel_file
)
1105 struct lttng_channel
*channel
= channel_file
->private_data
;
1106 struct lib_ring_buffer
*buf
;
1110 buf
= channel
->ops
->buffer_read_open(channel
->chan
);
1115 ret
= lttng_abi_create_stream_fd(channel_file
, stream_priv
,
1116 <tng_stream_ring_buffer_file_operations
);
1123 channel
->ops
->buffer_read_close(buf
);
1128 int lttng_abi_open_metadata_stream(struct file
*channel_file
)
1130 struct lttng_channel
*channel
= channel_file
->private_data
;
1131 struct lttng_session
*session
= channel
->session
;
1132 struct lib_ring_buffer
*buf
;
1134 struct lttng_metadata_stream
*metadata_stream
;
1137 buf
= channel
->ops
->buffer_read_open(channel
->chan
);
1141 metadata_stream
= kzalloc(sizeof(struct lttng_metadata_stream
),
1143 if (!metadata_stream
) {
1147 metadata_stream
->metadata_cache
= session
->metadata_cache
;
1148 init_waitqueue_head(&metadata_stream
->read_wait
);
1149 metadata_stream
->priv
= buf
;
1150 stream_priv
= metadata_stream
;
1151 metadata_stream
->transport
= channel
->transport
;
1154 * Since life-time of metadata cache differs from that of
1155 * session, we need to keep our own reference on the transport.
1157 if (!try_module_get(metadata_stream
->transport
->owner
)) {
1158 printk(KERN_WARNING
"LTT : Can't lock transport module.\n");
1163 kref_get(&session
->metadata_cache
->refcount
);
1164 ret
= lttng_abi_create_stream_fd(channel_file
, stream_priv
,
1165 <tng_metadata_ring_buffer_file_operations
);
1169 list_add(&metadata_stream
->list
,
1170 &session
->metadata_cache
->metadata_stream
);
1174 kref_put(&session
->metadata_cache
->refcount
, metadata_cache_destroy
);
1175 module_put(metadata_stream
->transport
->owner
);
1177 kfree(metadata_stream
);
1179 channel
->ops
->buffer_read_close(buf
);
1184 int lttng_abi_create_event(struct file
*channel_file
,
1185 struct lttng_kernel_event
*event_param
)
1187 struct lttng_channel
*channel
= channel_file
->private_data
;
1189 struct file
*event_file
;
1192 event_param
->name
[LTTNG_KERNEL_SYM_NAME_LEN
- 1] = '\0';
1193 switch (event_param
->instrumentation
) {
1194 case LTTNG_KERNEL_KRETPROBE
:
1195 event_param
->u
.kretprobe
.symbol_name
[LTTNG_KERNEL_SYM_NAME_LEN
- 1] = '\0';
1197 case LTTNG_KERNEL_KPROBE
:
1198 event_param
->u
.kprobe
.symbol_name
[LTTNG_KERNEL_SYM_NAME_LEN
- 1] = '\0';
1200 case LTTNG_KERNEL_FUNCTION
:
1202 /* Not implemented. */
1207 event_fd
= get_unused_fd_flags(0);
1212 event_file
= anon_inode_getfile("[lttng_event]",
1215 if (IS_ERR(event_file
)) {
1216 ret
= PTR_ERR(event_file
);
1219 /* The event holds a reference on the channel */
1220 if (!atomic_long_add_unless(&channel_file
->f_count
, 1, LONG_MAX
)) {
1222 goto refcount_error
;
1224 if (event_param
->instrumentation
== LTTNG_KERNEL_TRACEPOINT
1225 || event_param
->instrumentation
== LTTNG_KERNEL_SYSCALL
) {
1226 struct lttng_enabler
*enabler
;
1228 if (strutils_is_star_glob_pattern(event_param
->name
)) {
1230 * If the event name is a star globbing pattern,
1231 * we create the special star globbing enabler.
1233 enabler
= lttng_enabler_create(LTTNG_ENABLER_STAR_GLOB
,
1234 event_param
, channel
);
1236 enabler
= lttng_enabler_create(LTTNG_ENABLER_NAME
,
1237 event_param
, channel
);
1241 struct lttng_event
*event
;
1244 * We tolerate no failure path after event creation. It
1245 * will stay invariant for the rest of the session.
1247 event
= lttng_event_create(channel
, event_param
,
1249 event_param
->instrumentation
);
1250 WARN_ON_ONCE(!event
);
1251 if (IS_ERR(event
)) {
1252 ret
= PTR_ERR(event
);
1257 event_file
->private_data
= priv
;
1258 fd_install(event_fd
, event_file
);
1262 atomic_long_dec(&channel_file
->f_count
);
1266 put_unused_fd(event_fd
);
1272 * lttng_channel_ioctl - lttng syscall through ioctl
1278 * This ioctl implements lttng commands:
1279 * LTTNG_KERNEL_STREAM
1280 * Returns an event stream file descriptor or failure.
1281 * (typically, one event stream records events from one CPU)
1282 * LTTNG_KERNEL_EVENT
1283 * Returns an event file descriptor or failure.
1284 * LTTNG_KERNEL_CONTEXT
1285 * Prepend a context field to each event in the channel
1286 * LTTNG_KERNEL_ENABLE
1287 * Enable recording for events in this channel (weak enable)
1288 * LTTNG_KERNEL_DISABLE
1289 * Disable recording for events in this channel (strong disable)
1291 * Channel and event file descriptors also hold a reference on the session.
1294 long lttng_channel_ioctl(struct file
*file
, unsigned int cmd
, unsigned long arg
)
1296 struct lttng_channel
*channel
= file
->private_data
;
1299 case LTTNG_KERNEL_OLD_STREAM
:
1300 case LTTNG_KERNEL_STREAM
:
1301 return lttng_abi_open_stream(file
);
1302 case LTTNG_KERNEL_OLD_EVENT
:
1304 struct lttng_kernel_event
*uevent_param
;
1305 struct lttng_kernel_old_event
*old_uevent_param
;
1308 uevent_param
= kmalloc(sizeof(struct lttng_kernel_event
),
1310 if (!uevent_param
) {
1314 old_uevent_param
= kmalloc(
1315 sizeof(struct lttng_kernel_old_event
),
1317 if (!old_uevent_param
) {
1319 goto old_event_error_free_param
;
1321 if (copy_from_user(old_uevent_param
,
1322 (struct lttng_kernel_old_event __user
*) arg
,
1323 sizeof(struct lttng_kernel_old_event
))) {
1325 goto old_event_error_free_old_param
;
1328 memcpy(uevent_param
->name
, old_uevent_param
->name
,
1329 sizeof(uevent_param
->name
));
1330 uevent_param
->instrumentation
=
1331 old_uevent_param
->instrumentation
;
1333 switch (old_uevent_param
->instrumentation
) {
1334 case LTTNG_KERNEL_KPROBE
:
1335 uevent_param
->u
.kprobe
.addr
=
1336 old_uevent_param
->u
.kprobe
.addr
;
1337 uevent_param
->u
.kprobe
.offset
=
1338 old_uevent_param
->u
.kprobe
.offset
;
1339 memcpy(uevent_param
->u
.kprobe
.symbol_name
,
1340 old_uevent_param
->u
.kprobe
.symbol_name
,
1341 sizeof(uevent_param
->u
.kprobe
.symbol_name
));
1343 case LTTNG_KERNEL_KRETPROBE
:
1344 uevent_param
->u
.kretprobe
.addr
=
1345 old_uevent_param
->u
.kretprobe
.addr
;
1346 uevent_param
->u
.kretprobe
.offset
=
1347 old_uevent_param
->u
.kretprobe
.offset
;
1348 memcpy(uevent_param
->u
.kretprobe
.symbol_name
,
1349 old_uevent_param
->u
.kretprobe
.symbol_name
,
1350 sizeof(uevent_param
->u
.kretprobe
.symbol_name
));
1352 case LTTNG_KERNEL_FUNCTION
:
1354 /* Not implemented. */
1359 ret
= lttng_abi_create_event(file
, uevent_param
);
1361 old_event_error_free_old_param
:
1362 kfree(old_uevent_param
);
1363 old_event_error_free_param
:
1364 kfree(uevent_param
);
1368 case LTTNG_KERNEL_EVENT
:
1370 struct lttng_kernel_event uevent_param
;
1372 if (copy_from_user(&uevent_param
,
1373 (struct lttng_kernel_event __user
*) arg
,
1374 sizeof(uevent_param
)))
1376 return lttng_abi_create_event(file
, &uevent_param
);
1378 case LTTNG_KERNEL_OLD_CONTEXT
:
1380 struct lttng_kernel_context
*ucontext_param
;
1381 struct lttng_kernel_old_context
*old_ucontext_param
;
1384 ucontext_param
= kmalloc(sizeof(struct lttng_kernel_context
),
1386 if (!ucontext_param
) {
1390 old_ucontext_param
= kmalloc(sizeof(struct lttng_kernel_old_context
),
1392 if (!old_ucontext_param
) {
1394 goto old_ctx_error_free_param
;
1397 if (copy_from_user(old_ucontext_param
,
1398 (struct lttng_kernel_old_context __user
*) arg
,
1399 sizeof(struct lttng_kernel_old_context
))) {
1401 goto old_ctx_error_free_old_param
;
1403 ucontext_param
->ctx
= old_ucontext_param
->ctx
;
1404 memcpy(ucontext_param
->padding
, old_ucontext_param
->padding
,
1405 sizeof(ucontext_param
->padding
));
1406 /* only type that uses the union */
1407 if (old_ucontext_param
->ctx
== LTTNG_KERNEL_CONTEXT_PERF_COUNTER
) {
1408 ucontext_param
->u
.perf_counter
.type
=
1409 old_ucontext_param
->u
.perf_counter
.type
;
1410 ucontext_param
->u
.perf_counter
.config
=
1411 old_ucontext_param
->u
.perf_counter
.config
;
1412 memcpy(ucontext_param
->u
.perf_counter
.name
,
1413 old_ucontext_param
->u
.perf_counter
.name
,
1414 sizeof(ucontext_param
->u
.perf_counter
.name
));
1417 ret
= lttng_abi_add_context(file
,
1419 &channel
->ctx
, channel
->session
);
1421 old_ctx_error_free_old_param
:
1422 kfree(old_ucontext_param
);
1423 old_ctx_error_free_param
:
1424 kfree(ucontext_param
);
1428 case LTTNG_KERNEL_CONTEXT
:
1430 struct lttng_kernel_context ucontext_param
;
1432 if (copy_from_user(&ucontext_param
,
1433 (struct lttng_kernel_context __user
*) arg
,
1434 sizeof(ucontext_param
)))
1436 return lttng_abi_add_context(file
,
1438 &channel
->ctx
, channel
->session
);
1440 case LTTNG_KERNEL_OLD_ENABLE
:
1441 case LTTNG_KERNEL_ENABLE
:
1442 return lttng_channel_enable(channel
);
1443 case LTTNG_KERNEL_OLD_DISABLE
:
1444 case LTTNG_KERNEL_DISABLE
:
1445 return lttng_channel_disable(channel
);
1446 case LTTNG_KERNEL_SYSCALL_MASK
:
1447 return lttng_channel_syscall_mask(channel
,
1448 (struct lttng_kernel_syscall_mask __user
*) arg
);
1450 return -ENOIOCTLCMD
;
1455 * lttng_metadata_ioctl - lttng syscall through ioctl
1461 * This ioctl implements lttng commands:
1462 * LTTNG_KERNEL_STREAM
1463 * Returns an event stream file descriptor or failure.
1465 * Channel and event file descriptors also hold a reference on the session.
1468 long lttng_metadata_ioctl(struct file
*file
, unsigned int cmd
, unsigned long arg
)
1471 case LTTNG_KERNEL_OLD_STREAM
:
1472 case LTTNG_KERNEL_STREAM
:
1473 return lttng_abi_open_metadata_stream(file
);
1475 return -ENOIOCTLCMD
;
1480 * lttng_channel_poll - lttng stream addition/removal monitoring
1485 unsigned int lttng_channel_poll(struct file
*file
, poll_table
*wait
)
1487 struct lttng_channel
*channel
= file
->private_data
;
1488 unsigned int mask
= 0;
1490 if (file
->f_mode
& FMODE_READ
) {
1491 poll_wait(file
, channel
->ops
->get_hp_wait_queue(channel
->chan
),
1494 if (channel
->ops
->is_disabled(channel
->chan
))
1496 if (channel
->ops
->is_finalized(channel
->chan
))
1498 if (channel
->ops
->buffer_has_read_closed_stream(channel
->chan
))
1499 return POLLIN
| POLLRDNORM
;
1507 int lttng_channel_release(struct inode
*inode
, struct file
*file
)
1509 struct lttng_channel
*channel
= file
->private_data
;
1512 fput(channel
->session
->file
);
1517 int lttng_metadata_channel_release(struct inode
*inode
, struct file
*file
)
1519 struct lttng_channel
*channel
= file
->private_data
;
1522 fput(channel
->session
->file
);
1523 lttng_metadata_channel_destroy(channel
);
1529 static const struct file_operations lttng_channel_fops
= {
1530 .owner
= THIS_MODULE
,
1531 .release
= lttng_channel_release
,
1532 .poll
= lttng_channel_poll
,
1533 .unlocked_ioctl
= lttng_channel_ioctl
,
1534 #ifdef CONFIG_COMPAT
1535 .compat_ioctl
= lttng_channel_ioctl
,
1539 static const struct file_operations lttng_metadata_fops
= {
1540 .owner
= THIS_MODULE
,
1541 .release
= lttng_metadata_channel_release
,
1542 .unlocked_ioctl
= lttng_metadata_ioctl
,
1543 #ifdef CONFIG_COMPAT
1544 .compat_ioctl
= lttng_metadata_ioctl
,
1549 * lttng_event_ioctl - lttng syscall through ioctl
1555 * This ioctl implements lttng commands:
1556 * LTTNG_KERNEL_CONTEXT
1557 * Prepend a context field to each record of this event
1558 * LTTNG_KERNEL_ENABLE
1559 * Enable recording for this event (weak enable)
1560 * LTTNG_KERNEL_DISABLE
1561 * Disable recording for this event (strong disable)
1564 long lttng_event_ioctl(struct file
*file
, unsigned int cmd
, unsigned long arg
)
1566 struct lttng_event
*event
;
1567 struct lttng_enabler
*enabler
;
1568 enum lttng_event_type
*evtype
= file
->private_data
;
1571 case LTTNG_KERNEL_OLD_CONTEXT
:
1573 /* Not implemented */
1576 case LTTNG_KERNEL_CONTEXT
:
1578 /* Not implemented */
1581 case LTTNG_KERNEL_OLD_ENABLE
:
1582 case LTTNG_KERNEL_ENABLE
:
1584 case LTTNG_TYPE_EVENT
:
1585 event
= file
->private_data
;
1586 return lttng_event_enable(event
);
1587 case LTTNG_TYPE_ENABLER
:
1588 enabler
= file
->private_data
;
1589 return lttng_enabler_enable(enabler
);
1594 case LTTNG_KERNEL_OLD_DISABLE
:
1595 case LTTNG_KERNEL_DISABLE
:
1597 case LTTNG_TYPE_EVENT
:
1598 event
= file
->private_data
;
1599 return lttng_event_disable(event
);
1600 case LTTNG_TYPE_ENABLER
:
1601 enabler
= file
->private_data
;
1602 return lttng_enabler_disable(enabler
);
1607 case LTTNG_KERNEL_FILTER
:
1609 case LTTNG_TYPE_EVENT
:
1611 case LTTNG_TYPE_ENABLER
:
1613 enabler
= file
->private_data
;
1614 return lttng_enabler_attach_bytecode(enabler
,
1615 (struct lttng_kernel_filter_bytecode __user
*) arg
);
1621 case LTTNG_KERNEL_ADD_CALLSITE
:
1623 case LTTNG_TYPE_EVENT
:
1624 event
= file
->private_data
;
1625 return lttng_event_add_callsite(event
,
1626 (struct lttng_kernel_event_callsite __user
*) arg
);
1627 case LTTNG_TYPE_ENABLER
:
1634 return -ENOIOCTLCMD
;
1639 int lttng_event_release(struct inode
*inode
, struct file
*file
)
1641 struct lttng_event
*event
;
1642 struct lttng_enabler
*enabler
;
1643 enum lttng_event_type
*evtype
= file
->private_data
;
1649 case LTTNG_TYPE_EVENT
:
1650 event
= file
->private_data
;
1652 fput(event
->chan
->file
);
1654 case LTTNG_TYPE_ENABLER
:
1655 enabler
= file
->private_data
;
1657 fput(enabler
->chan
->file
);
1667 /* TODO: filter control ioctl */
1668 static const struct file_operations lttng_event_fops
= {
1669 .owner
= THIS_MODULE
,
1670 .release
= lttng_event_release
,
1671 .unlocked_ioctl
= lttng_event_ioctl
,
1672 #ifdef CONFIG_COMPAT
1673 .compat_ioctl
= lttng_event_ioctl
,
1677 static int put_u64(uint64_t val
, unsigned long arg
)
1679 return put_user(val
, (uint64_t __user
*) arg
);
1682 static long lttng_stream_ring_buffer_ioctl(struct file
*filp
,
1683 unsigned int cmd
, unsigned long arg
)
1685 struct lib_ring_buffer
*buf
= filp
->private_data
;
1686 struct channel
*chan
= buf
->backend
.chan
;
1687 const struct lib_ring_buffer_config
*config
= &chan
->backend
.config
;
1688 const struct lttng_channel_ops
*ops
= chan
->backend
.priv_ops
;
1691 if (atomic_read(&chan
->record_disabled
))
1695 case LTTNG_RING_BUFFER_GET_TIMESTAMP_BEGIN
:
1699 ret
= ops
->timestamp_begin(config
, buf
, &ts
);
1702 return put_u64(ts
, arg
);
1704 case LTTNG_RING_BUFFER_GET_TIMESTAMP_END
:
1708 ret
= ops
->timestamp_end(config
, buf
, &ts
);
1711 return put_u64(ts
, arg
);
1713 case LTTNG_RING_BUFFER_GET_EVENTS_DISCARDED
:
1717 ret
= ops
->events_discarded(config
, buf
, &ed
);
1720 return put_u64(ed
, arg
);
1722 case LTTNG_RING_BUFFER_GET_CONTENT_SIZE
:
1726 ret
= ops
->content_size(config
, buf
, &cs
);
1729 return put_u64(cs
, arg
);
1731 case LTTNG_RING_BUFFER_GET_PACKET_SIZE
:
1735 ret
= ops
->packet_size(config
, buf
, &ps
);
1738 return put_u64(ps
, arg
);
1740 case LTTNG_RING_BUFFER_GET_STREAM_ID
:
1744 ret
= ops
->stream_id(config
, buf
, &si
);
1747 return put_u64(si
, arg
);
1749 case LTTNG_RING_BUFFER_GET_CURRENT_TIMESTAMP
:
1753 ret
= ops
->current_timestamp(config
, buf
, &ts
);
1756 return put_u64(ts
, arg
);
1758 case LTTNG_RING_BUFFER_GET_SEQ_NUM
:
1762 ret
= ops
->sequence_number(config
, buf
, &seq
);
1765 return put_u64(seq
, arg
);
1767 case LTTNG_RING_BUFFER_INSTANCE_ID
:
1771 ret
= ops
->instance_id(config
, buf
, &id
);
1774 return put_u64(id
, arg
);
1777 return lib_ring_buffer_file_operations
.unlocked_ioctl(filp
,
1785 #ifdef CONFIG_COMPAT
1786 static long lttng_stream_ring_buffer_compat_ioctl(struct file
*filp
,
1787 unsigned int cmd
, unsigned long arg
)
1789 struct lib_ring_buffer
*buf
= filp
->private_data
;
1790 struct channel
*chan
= buf
->backend
.chan
;
1791 const struct lib_ring_buffer_config
*config
= &chan
->backend
.config
;
1792 const struct lttng_channel_ops
*ops
= chan
->backend
.priv_ops
;
1795 if (atomic_read(&chan
->record_disabled
))
1799 case LTTNG_RING_BUFFER_COMPAT_GET_TIMESTAMP_BEGIN
:
1803 ret
= ops
->timestamp_begin(config
, buf
, &ts
);
1806 return put_u64(ts
, arg
);
1808 case LTTNG_RING_BUFFER_COMPAT_GET_TIMESTAMP_END
:
1812 ret
= ops
->timestamp_end(config
, buf
, &ts
);
1815 return put_u64(ts
, arg
);
1817 case LTTNG_RING_BUFFER_COMPAT_GET_EVENTS_DISCARDED
:
1821 ret
= ops
->events_discarded(config
, buf
, &ed
);
1824 return put_u64(ed
, arg
);
1826 case LTTNG_RING_BUFFER_COMPAT_GET_CONTENT_SIZE
:
1830 ret
= ops
->content_size(config
, buf
, &cs
);
1833 return put_u64(cs
, arg
);
1835 case LTTNG_RING_BUFFER_COMPAT_GET_PACKET_SIZE
:
1839 ret
= ops
->packet_size(config
, buf
, &ps
);
1842 return put_u64(ps
, arg
);
1844 case LTTNG_RING_BUFFER_COMPAT_GET_STREAM_ID
:
1848 ret
= ops
->stream_id(config
, buf
, &si
);
1851 return put_u64(si
, arg
);
1853 case LTTNG_RING_BUFFER_GET_CURRENT_TIMESTAMP
:
1857 ret
= ops
->current_timestamp(config
, buf
, &ts
);
1860 return put_u64(ts
, arg
);
1862 case LTTNG_RING_BUFFER_COMPAT_GET_SEQ_NUM
:
1866 ret
= ops
->sequence_number(config
, buf
, &seq
);
1869 return put_u64(seq
, arg
);
1871 case LTTNG_RING_BUFFER_COMPAT_INSTANCE_ID
:
1875 ret
= ops
->instance_id(config
, buf
, &id
);
1878 return put_u64(id
, arg
);
1881 return lib_ring_buffer_file_operations
.compat_ioctl(filp
,
1888 #endif /* CONFIG_COMPAT */
1890 static void lttng_stream_override_ring_buffer_fops(void)
1892 lttng_stream_ring_buffer_file_operations
.owner
= THIS_MODULE
;
1893 lttng_stream_ring_buffer_file_operations
.open
=
1894 lib_ring_buffer_file_operations
.open
;
1895 lttng_stream_ring_buffer_file_operations
.release
=
1896 lib_ring_buffer_file_operations
.release
;
1897 lttng_stream_ring_buffer_file_operations
.poll
=
1898 lib_ring_buffer_file_operations
.poll
;
1899 lttng_stream_ring_buffer_file_operations
.splice_read
=
1900 lib_ring_buffer_file_operations
.splice_read
;
1901 lttng_stream_ring_buffer_file_operations
.mmap
=
1902 lib_ring_buffer_file_operations
.mmap
;
1903 lttng_stream_ring_buffer_file_operations
.unlocked_ioctl
=
1904 lttng_stream_ring_buffer_ioctl
;
1905 lttng_stream_ring_buffer_file_operations
.llseek
=
1906 lib_ring_buffer_file_operations
.llseek
;
1907 #ifdef CONFIG_COMPAT
1908 lttng_stream_ring_buffer_file_operations
.compat_ioctl
=
1909 lttng_stream_ring_buffer_compat_ioctl
;
1913 int __init
lttng_abi_init(void)
1919 ret
= lttng_tp_mempool_init();
1924 lttng_proc_dentry
= proc_create_data("lttng", S_IRUSR
| S_IWUSR
, NULL
,
1925 <tng_proc_ops
, NULL
);
1927 if (!lttng_proc_dentry
) {
1928 printk(KERN_ERR
"Error creating LTTng control file\n");
1932 lttng_stream_override_ring_buffer_fops();
1936 lttng_tp_mempool_destroy();
1937 lttng_clock_unref();
1941 /* No __exit annotation because used by init error path too. */
1942 void lttng_abi_exit(void)
1944 lttng_tp_mempool_destroy();
1945 lttng_clock_unref();
1946 if (lttng_proc_dentry
)
1947 remove_proc_entry("lttng", NULL
);