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 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(5,6,0))
53 static const struct proc_ops lttng_proc_ops
;
55 static const struct file_operations lttng_proc_ops
;
58 static const struct file_operations lttng_session_fops
;
59 static const struct file_operations lttng_channel_fops
;
60 static const struct file_operations lttng_metadata_fops
;
61 static const struct file_operations lttng_event_fops
;
62 static struct file_operations lttng_stream_ring_buffer_file_operations
;
64 static int put_u64(uint64_t val
, unsigned long arg
);
67 * Teardown management: opened file descriptors keep a refcount on the module,
68 * so it can only exit when all file descriptors are closed.
72 int lttng_abi_create_session(void)
74 struct lttng_session
*session
;
75 struct file
*session_file
;
78 session
= lttng_session_create();
81 session_fd
= get_unused_fd_flags(0);
86 session_file
= anon_inode_getfile("[lttng_session]",
89 if (IS_ERR(session_file
)) {
90 ret
= PTR_ERR(session_file
);
93 session
->file
= session_file
;
94 fd_install(session_fd
, session_file
);
98 put_unused_fd(session_fd
);
100 lttng_session_destroy(session
);
105 int lttng_abi_tracepoint_list(void)
107 struct file
*tracepoint_list_file
;
110 file_fd
= get_unused_fd_flags(0);
116 tracepoint_list_file
= anon_inode_getfile("[lttng_tracepoint_list]",
117 <tng_tracepoint_list_fops
,
119 if (IS_ERR(tracepoint_list_file
)) {
120 ret
= PTR_ERR(tracepoint_list_file
);
123 ret
= lttng_tracepoint_list_fops
.open(NULL
, tracepoint_list_file
);
126 fd_install(file_fd
, tracepoint_list_file
);
130 fput(tracepoint_list_file
);
132 put_unused_fd(file_fd
);
137 #ifndef CONFIG_HAVE_SYSCALL_TRACEPOINTS
139 int lttng_abi_syscall_list(void)
145 int lttng_abi_syscall_list(void)
147 struct file
*syscall_list_file
;
150 file_fd
= get_unused_fd_flags(0);
156 syscall_list_file
= anon_inode_getfile("[lttng_syscall_list]",
157 <tng_syscall_list_fops
,
159 if (IS_ERR(syscall_list_file
)) {
160 ret
= PTR_ERR(syscall_list_file
);
163 ret
= lttng_syscall_list_fops
.open(NULL
, syscall_list_file
);
166 fd_install(file_fd
, syscall_list_file
);
170 fput(syscall_list_file
);
172 put_unused_fd(file_fd
);
179 void lttng_abi_tracer_version(struct lttng_kernel_tracer_version
*v
)
181 v
->major
= LTTNG_MODULES_MAJOR_VERSION
;
182 v
->minor
= LTTNG_MODULES_MINOR_VERSION
;
183 v
->patchlevel
= LTTNG_MODULES_PATCHLEVEL_VERSION
;
187 void lttng_abi_tracer_abi_version(struct lttng_kernel_tracer_abi_version
*v
)
189 v
->major
= LTTNG_MODULES_ABI_MAJOR_VERSION
;
190 v
->minor
= LTTNG_MODULES_ABI_MINOR_VERSION
;
194 long lttng_abi_add_context(struct file
*file
,
195 struct lttng_kernel_context
*context_param
,
196 struct lttng_ctx
**ctx
, struct lttng_session
*session
)
199 if (session
->been_active
)
202 switch (context_param
->ctx
) {
203 case LTTNG_KERNEL_CONTEXT_PID
:
204 return lttng_add_pid_to_ctx(ctx
);
205 case LTTNG_KERNEL_CONTEXT_PRIO
:
206 return lttng_add_prio_to_ctx(ctx
);
207 case LTTNG_KERNEL_CONTEXT_NICE
:
208 return lttng_add_nice_to_ctx(ctx
);
209 case LTTNG_KERNEL_CONTEXT_VPID
:
210 return lttng_add_vpid_to_ctx(ctx
);
211 case LTTNG_KERNEL_CONTEXT_TID
:
212 return lttng_add_tid_to_ctx(ctx
);
213 case LTTNG_KERNEL_CONTEXT_VTID
:
214 return lttng_add_vtid_to_ctx(ctx
);
215 case LTTNG_KERNEL_CONTEXT_PPID
:
216 return lttng_add_ppid_to_ctx(ctx
);
217 case LTTNG_KERNEL_CONTEXT_VPPID
:
218 return lttng_add_vppid_to_ctx(ctx
);
219 case LTTNG_KERNEL_CONTEXT_PERF_COUNTER
:
220 context_param
->u
.perf_counter
.name
[LTTNG_KERNEL_SYM_NAME_LEN
- 1] = '\0';
221 return lttng_add_perf_counter_to_ctx(context_param
->u
.perf_counter
.type
,
222 context_param
->u
.perf_counter
.config
,
223 context_param
->u
.perf_counter
.name
,
225 case LTTNG_KERNEL_CONTEXT_PROCNAME
:
226 return lttng_add_procname_to_ctx(ctx
);
227 case LTTNG_KERNEL_CONTEXT_HOSTNAME
:
228 return lttng_add_hostname_to_ctx(ctx
);
229 case LTTNG_KERNEL_CONTEXT_CPU_ID
:
230 return lttng_add_cpu_id_to_ctx(ctx
);
231 case LTTNG_KERNEL_CONTEXT_INTERRUPTIBLE
:
232 return lttng_add_interruptible_to_ctx(ctx
);
233 case LTTNG_KERNEL_CONTEXT_NEED_RESCHEDULE
:
234 return lttng_add_need_reschedule_to_ctx(ctx
);
235 case LTTNG_KERNEL_CONTEXT_PREEMPTIBLE
:
236 return lttng_add_preemptible_to_ctx(ctx
);
237 case LTTNG_KERNEL_CONTEXT_MIGRATABLE
:
238 return lttng_add_migratable_to_ctx(ctx
);
239 case LTTNG_KERNEL_CONTEXT_CALLSTACK_KERNEL
:
240 case LTTNG_KERNEL_CONTEXT_CALLSTACK_USER
:
241 return lttng_add_callstack_to_ctx(ctx
, context_param
->ctx
);
242 case LTTNG_KERNEL_CONTEXT_CGROUP_NS
:
243 return lttng_add_cgroup_ns_to_ctx(ctx
);
244 case LTTNG_KERNEL_CONTEXT_IPC_NS
:
245 return lttng_add_ipc_ns_to_ctx(ctx
);
246 case LTTNG_KERNEL_CONTEXT_MNT_NS
:
247 return lttng_add_mnt_ns_to_ctx(ctx
);
248 case LTTNG_KERNEL_CONTEXT_NET_NS
:
249 return lttng_add_net_ns_to_ctx(ctx
);
250 case LTTNG_KERNEL_CONTEXT_PID_NS
:
251 return lttng_add_pid_ns_to_ctx(ctx
);
252 case LTTNG_KERNEL_CONTEXT_USER_NS
:
253 return lttng_add_user_ns_to_ctx(ctx
);
254 case LTTNG_KERNEL_CONTEXT_UTS_NS
:
255 return lttng_add_uts_ns_to_ctx(ctx
);
256 case LTTNG_KERNEL_CONTEXT_UID
:
257 return lttng_add_uid_to_ctx(ctx
);
258 case LTTNG_KERNEL_CONTEXT_EUID
:
259 return lttng_add_euid_to_ctx(ctx
);
260 case LTTNG_KERNEL_CONTEXT_SUID
:
261 return lttng_add_suid_to_ctx(ctx
);
262 case LTTNG_KERNEL_CONTEXT_GID
:
263 return lttng_add_gid_to_ctx(ctx
);
264 case LTTNG_KERNEL_CONTEXT_EGID
:
265 return lttng_add_egid_to_ctx(ctx
);
266 case LTTNG_KERNEL_CONTEXT_SGID
:
267 return lttng_add_sgid_to_ctx(ctx
);
268 case LTTNG_KERNEL_CONTEXT_VUID
:
269 return lttng_add_vuid_to_ctx(ctx
);
270 case LTTNG_KERNEL_CONTEXT_VEUID
:
271 return lttng_add_veuid_to_ctx(ctx
);
272 case LTTNG_KERNEL_CONTEXT_VSUID
:
273 return lttng_add_vsuid_to_ctx(ctx
);
274 case LTTNG_KERNEL_CONTEXT_VGID
:
275 return lttng_add_vgid_to_ctx(ctx
);
276 case LTTNG_KERNEL_CONTEXT_VEGID
:
277 return lttng_add_vegid_to_ctx(ctx
);
278 case LTTNG_KERNEL_CONTEXT_VSGID
:
279 return lttng_add_vsgid_to_ctx(ctx
);
286 * lttng_ioctl - lttng syscall through ioctl
292 * This ioctl implements lttng commands:
293 * LTTNG_KERNEL_SESSION
294 * Returns a LTTng trace session file descriptor
295 * LTTNG_KERNEL_TRACER_VERSION
296 * Returns the LTTng kernel tracer version
297 * LTTNG_KERNEL_TRACEPOINT_LIST
298 * Returns a file descriptor listing available tracepoints
299 * LTTNG_KERNEL_WAIT_QUIESCENT
300 * Returns after all previously running probes have completed
301 * LTTNG_KERNEL_TRACER_ABI_VERSION
302 * Returns the LTTng kernel tracer ABI version
304 * The returned session will be deleted when its file descriptor is closed.
307 long lttng_ioctl(struct file
*file
, unsigned int cmd
, unsigned long arg
)
310 case LTTNG_KERNEL_OLD_SESSION
:
311 case LTTNG_KERNEL_SESSION
:
312 return lttng_abi_create_session();
313 case LTTNG_KERNEL_OLD_TRACER_VERSION
:
315 struct lttng_kernel_tracer_version v
;
316 struct lttng_kernel_old_tracer_version oldv
;
317 struct lttng_kernel_old_tracer_version
*uversion
=
318 (struct lttng_kernel_old_tracer_version __user
*) arg
;
320 lttng_abi_tracer_version(&v
);
321 oldv
.major
= v
.major
;
322 oldv
.minor
= v
.minor
;
323 oldv
.patchlevel
= v
.patchlevel
;
325 if (copy_to_user(uversion
, &oldv
, sizeof(oldv
)))
329 case LTTNG_KERNEL_TRACER_VERSION
:
331 struct lttng_kernel_tracer_version version
;
332 struct lttng_kernel_tracer_version
*uversion
=
333 (struct lttng_kernel_tracer_version __user
*) arg
;
335 lttng_abi_tracer_version(&version
);
337 if (copy_to_user(uversion
, &version
, sizeof(version
)))
341 case LTTNG_KERNEL_TRACER_ABI_VERSION
:
343 struct lttng_kernel_tracer_abi_version version
;
344 struct lttng_kernel_tracer_abi_version
*uversion
=
345 (struct lttng_kernel_tracer_abi_version __user
*) arg
;
347 lttng_abi_tracer_abi_version(&version
);
349 if (copy_to_user(uversion
, &version
, sizeof(version
)))
353 case LTTNG_KERNEL_OLD_TRACEPOINT_LIST
:
354 case LTTNG_KERNEL_TRACEPOINT_LIST
:
355 return lttng_abi_tracepoint_list();
356 case LTTNG_KERNEL_SYSCALL_LIST
:
357 return lttng_abi_syscall_list();
358 case LTTNG_KERNEL_OLD_WAIT_QUIESCENT
:
359 case LTTNG_KERNEL_WAIT_QUIESCENT
:
362 case LTTNG_KERNEL_OLD_CALIBRATE
:
364 struct lttng_kernel_old_calibrate __user
*ucalibrate
=
365 (struct lttng_kernel_old_calibrate __user
*) arg
;
366 struct lttng_kernel_old_calibrate old_calibrate
;
367 struct lttng_kernel_calibrate calibrate
;
370 if (copy_from_user(&old_calibrate
, ucalibrate
, sizeof(old_calibrate
)))
372 calibrate
.type
= old_calibrate
.type
;
373 ret
= lttng_calibrate(&calibrate
);
374 if (copy_to_user(ucalibrate
, &old_calibrate
, sizeof(old_calibrate
)))
378 case LTTNG_KERNEL_CALIBRATE
:
380 struct lttng_kernel_calibrate __user
*ucalibrate
=
381 (struct lttng_kernel_calibrate __user
*) arg
;
382 struct lttng_kernel_calibrate calibrate
;
385 if (copy_from_user(&calibrate
, ucalibrate
, sizeof(calibrate
)))
387 ret
= lttng_calibrate(&calibrate
);
388 if (copy_to_user(ucalibrate
, &calibrate
, sizeof(calibrate
)))
397 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(5,6,0))
398 static const struct proc_ops lttng_proc_ops
= {
399 .proc_ioctl
= lttng_ioctl
,
401 .proc_compat_ioctl
= lttng_ioctl
,
402 #endif /* CONFIG_COMPAT */
405 static const struct file_operations lttng_proc_ops
= {
406 .owner
= THIS_MODULE
,
407 .unlocked_ioctl
= lttng_ioctl
,
409 .compat_ioctl
= lttng_ioctl
,
410 #endif /* CONFIG_COMPAT */
415 int lttng_abi_create_channel(struct file
*session_file
,
416 struct lttng_kernel_channel
*chan_param
,
417 enum channel_type channel_type
)
419 struct lttng_session
*session
= session_file
->private_data
;
420 const struct file_operations
*fops
= NULL
;
421 const char *transport_name
;
422 struct lttng_channel
*chan
;
423 struct file
*chan_file
;
427 chan_fd
= get_unused_fd_flags(0);
432 switch (channel_type
) {
433 case PER_CPU_CHANNEL
:
434 fops
= <tng_channel_fops
;
436 case METADATA_CHANNEL
:
437 fops
= <tng_metadata_fops
;
441 chan_file
= anon_inode_getfile("[lttng_channel]",
444 if (IS_ERR(chan_file
)) {
445 ret
= PTR_ERR(chan_file
);
448 switch (channel_type
) {
449 case PER_CPU_CHANNEL
:
450 if (chan_param
->output
== LTTNG_KERNEL_SPLICE
) {
451 transport_name
= chan_param
->overwrite
?
452 "relay-overwrite" : "relay-discard";
453 } else if (chan_param
->output
== LTTNG_KERNEL_MMAP
) {
454 transport_name
= chan_param
->overwrite
?
455 "relay-overwrite-mmap" : "relay-discard-mmap";
460 case METADATA_CHANNEL
:
461 if (chan_param
->output
== LTTNG_KERNEL_SPLICE
)
462 transport_name
= "relay-metadata";
463 else if (chan_param
->output
== LTTNG_KERNEL_MMAP
)
464 transport_name
= "relay-metadata-mmap";
469 transport_name
= "<unknown>";
472 if (!atomic_long_add_unless(&session_file
->f_count
, 1, LONG_MAX
)) {
477 * We tolerate no failure path after channel creation. It will stay
478 * invariant for the rest of the session.
480 chan
= lttng_channel_create(session
, transport_name
, NULL
,
481 chan_param
->subbuf_size
,
482 chan_param
->num_subbuf
,
483 chan_param
->switch_timer_interval
,
484 chan_param
->read_timer_interval
,
490 chan
->file
= chan_file
;
491 chan_file
->private_data
= chan
;
492 fd_install(chan_fd
, chan_file
);
497 atomic_long_dec(&session_file
->f_count
);
501 put_unused_fd(chan_fd
);
507 int lttng_abi_session_set_name(struct lttng_session
*session
,
508 struct lttng_kernel_session_name
*name
)
512 len
= strnlen(name
->name
, LTTNG_KERNEL_SESSION_NAME_LEN
);
514 if (len
== LTTNG_KERNEL_SESSION_NAME_LEN
) {
515 /* Name is too long/malformed */
519 strcpy(session
->name
, name
->name
);
524 int lttng_abi_session_set_creation_time(struct lttng_session
*session
,
525 struct lttng_kernel_session_creation_time
*time
)
529 len
= strnlen(time
->iso8601
, LTTNG_KERNEL_SESSION_CREATION_TIME_ISO8601_LEN
);
531 if (len
== LTTNG_KERNEL_SESSION_CREATION_TIME_ISO8601_LEN
) {
532 /* Time is too long/malformed */
536 strcpy(session
->creation_time
, time
->iso8601
);
541 enum tracker_type
get_tracker_type(struct lttng_kernel_tracker_args
*tracker
)
543 switch (tracker
->type
) {
544 case LTTNG_KERNEL_TRACKER_PID
:
546 case LTTNG_KERNEL_TRACKER_VPID
:
548 case LTTNG_KERNEL_TRACKER_UID
:
550 case LTTNG_KERNEL_TRACKER_VUID
:
552 case LTTNG_KERNEL_TRACKER_GID
:
554 case LTTNG_KERNEL_TRACKER_VGID
:
557 return TRACKER_UNKNOWN
;
562 * lttng_session_ioctl - lttng session fd ioctl
568 * This ioctl implements lttng commands:
569 * LTTNG_KERNEL_CHANNEL
570 * Returns a LTTng channel file descriptor
571 * LTTNG_KERNEL_ENABLE
572 * Enables tracing for a session (weak enable)
573 * LTTNG_KERNEL_DISABLE
574 * Disables tracing for a session (strong disable)
575 * LTTNG_KERNEL_METADATA
576 * Returns a LTTng metadata file descriptor
577 * LTTNG_KERNEL_SESSION_TRACK_PID
578 * Add PID to session PID tracker
579 * LTTNG_KERNEL_SESSION_UNTRACK_PID
580 * Remove PID from session PID tracker
581 * LTTNG_KERNEL_SESSION_TRACK_ID
583 * LTTNG_KERNEL_SESSION_UNTRACK_ID
584 * Remove ID from tracker
586 * The returned channel will be deleted when its file descriptor is closed.
589 long lttng_session_ioctl(struct file
*file
, unsigned int cmd
, unsigned long arg
)
591 struct lttng_session
*session
= file
->private_data
;
592 struct lttng_kernel_channel chan_param
;
593 struct lttng_kernel_old_channel old_chan_param
;
596 case LTTNG_KERNEL_OLD_CHANNEL
:
598 if (copy_from_user(&old_chan_param
,
599 (struct lttng_kernel_old_channel __user
*) arg
,
600 sizeof(struct lttng_kernel_old_channel
)))
602 chan_param
.overwrite
= old_chan_param
.overwrite
;
603 chan_param
.subbuf_size
= old_chan_param
.subbuf_size
;
604 chan_param
.num_subbuf
= old_chan_param
.num_subbuf
;
605 chan_param
.switch_timer_interval
= old_chan_param
.switch_timer_interval
;
606 chan_param
.read_timer_interval
= old_chan_param
.read_timer_interval
;
607 chan_param
.output
= old_chan_param
.output
;
609 return lttng_abi_create_channel(file
, &chan_param
,
612 case LTTNG_KERNEL_CHANNEL
:
614 if (copy_from_user(&chan_param
,
615 (struct lttng_kernel_channel __user
*) arg
,
616 sizeof(struct lttng_kernel_channel
)))
618 return lttng_abi_create_channel(file
, &chan_param
,
621 case LTTNG_KERNEL_OLD_SESSION_START
:
622 case LTTNG_KERNEL_OLD_ENABLE
:
623 case LTTNG_KERNEL_SESSION_START
:
624 case LTTNG_KERNEL_ENABLE
:
625 return lttng_session_enable(session
);
626 case LTTNG_KERNEL_OLD_SESSION_STOP
:
627 case LTTNG_KERNEL_OLD_DISABLE
:
628 case LTTNG_KERNEL_SESSION_STOP
:
629 case LTTNG_KERNEL_DISABLE
:
630 return lttng_session_disable(session
);
631 case LTTNG_KERNEL_OLD_METADATA
:
633 if (copy_from_user(&old_chan_param
,
634 (struct lttng_kernel_old_channel __user
*) arg
,
635 sizeof(struct lttng_kernel_old_channel
)))
637 chan_param
.overwrite
= old_chan_param
.overwrite
;
638 chan_param
.subbuf_size
= old_chan_param
.subbuf_size
;
639 chan_param
.num_subbuf
= old_chan_param
.num_subbuf
;
640 chan_param
.switch_timer_interval
= old_chan_param
.switch_timer_interval
;
641 chan_param
.read_timer_interval
= old_chan_param
.read_timer_interval
;
642 chan_param
.output
= old_chan_param
.output
;
644 return lttng_abi_create_channel(file
, &chan_param
,
647 case LTTNG_KERNEL_METADATA
:
649 if (copy_from_user(&chan_param
,
650 (struct lttng_kernel_channel __user
*) arg
,
651 sizeof(struct lttng_kernel_channel
)))
653 return lttng_abi_create_channel(file
, &chan_param
,
656 case LTTNG_KERNEL_SESSION_TRACK_PID
:
657 return lttng_session_track_id(session
, TRACKER_PID
, (int) arg
);
658 case LTTNG_KERNEL_SESSION_UNTRACK_PID
:
659 return lttng_session_untrack_id(session
, TRACKER_PID
, (int) arg
);
660 case LTTNG_KERNEL_SESSION_TRACK_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_track_id(session
, tracker_type
, tracker
.id
);
674 case LTTNG_KERNEL_SESSION_UNTRACK_ID
:
676 struct lttng_kernel_tracker_args tracker
;
677 enum tracker_type tracker_type
;
679 if (copy_from_user(&tracker
,
680 (struct lttng_kernel_tracker_args __user
*) arg
,
681 sizeof(struct lttng_kernel_tracker_args
)))
683 tracker_type
= get_tracker_type(&tracker
);
684 if (tracker_type
== TRACKER_UNKNOWN
)
686 return lttng_session_untrack_id(session
, tracker_type
,
689 case LTTNG_KERNEL_SESSION_LIST_TRACKER_PIDS
:
690 return lttng_session_list_tracker_ids(session
, TRACKER_PID
);
691 case LTTNG_KERNEL_SESSION_LIST_TRACKER_IDS
:
693 struct lttng_kernel_tracker_args tracker
;
694 enum tracker_type tracker_type
;
696 if (copy_from_user(&tracker
,
697 (struct lttng_kernel_tracker_args __user
*) arg
,
698 sizeof(struct lttng_kernel_tracker_args
)))
700 tracker_type
= get_tracker_type(&tracker
);
701 if (tracker_type
== TRACKER_UNKNOWN
)
703 return lttng_session_list_tracker_ids(session
, tracker_type
);
705 case LTTNG_KERNEL_SESSION_METADATA_REGEN
:
706 return lttng_session_metadata_regenerate(session
);
707 case LTTNG_KERNEL_SESSION_STATEDUMP
:
708 return lttng_session_statedump(session
);
709 case LTTNG_KERNEL_SESSION_SET_NAME
:
711 struct lttng_kernel_session_name name
;
713 if (copy_from_user(&name
,
714 (struct lttng_kernel_session_name __user
*) arg
,
715 sizeof(struct lttng_kernel_session_name
)))
717 return lttng_abi_session_set_name(session
, &name
);
719 case LTTNG_KERNEL_SESSION_SET_CREATION_TIME
:
721 struct lttng_kernel_session_creation_time time
;
723 if (copy_from_user(&time
,
724 (struct lttng_kernel_session_creation_time __user
*) arg
,
725 sizeof(struct lttng_kernel_session_creation_time
)))
727 return lttng_abi_session_set_creation_time(session
, &time
);
735 * Called when the last file reference is dropped.
737 * Big fat note: channels and events are invariant for the whole session after
738 * their creation. So this session destruction also destroys all channel and
739 * event structures specific to this session (they are not destroyed when their
740 * individual file is released).
743 int lttng_session_release(struct inode
*inode
, struct file
*file
)
745 struct lttng_session
*session
= file
->private_data
;
748 lttng_session_destroy(session
);
752 static const struct file_operations lttng_session_fops
= {
753 .owner
= THIS_MODULE
,
754 .release
= lttng_session_release
,
755 .unlocked_ioctl
= lttng_session_ioctl
,
757 .compat_ioctl
= lttng_session_ioctl
,
762 * lttng_metadata_ring_buffer_poll - LTTng ring buffer poll file operation
766 * Handles the poll operations for the metadata channels.
769 unsigned int lttng_metadata_ring_buffer_poll(struct file
*filp
,
772 struct lttng_metadata_stream
*stream
= filp
->private_data
;
773 struct lib_ring_buffer
*buf
= stream
->priv
;
775 unsigned int mask
= 0;
777 if (filp
->f_mode
& FMODE_READ
) {
778 poll_wait(filp
, &stream
->read_wait
, wait
);
780 finalized
= stream
->finalized
;
783 * lib_ring_buffer_is_finalized() contains a smp_rmb()
784 * ordering finalized load before offsets loads.
786 WARN_ON(atomic_long_read(&buf
->active_readers
) != 1);
791 mutex_lock(&stream
->metadata_cache
->lock
);
792 if (stream
->metadata_cache
->metadata_written
>
793 stream
->metadata_out
)
795 mutex_unlock(&stream
->metadata_cache
->lock
);
802 void lttng_metadata_ring_buffer_ioctl_put_next_subbuf(struct file
*filp
,
803 unsigned int cmd
, unsigned long arg
)
805 struct lttng_metadata_stream
*stream
= filp
->private_data
;
807 stream
->metadata_out
= stream
->metadata_in
;
811 * Reset the counter of how much metadata has been consumed to 0. That way,
812 * the consumer receives the content of the metadata cache unchanged. This is
813 * different from the metadata_regenerate where the offset from epoch is
814 * resampled, here we want the exact same content as the last time the metadata
815 * was generated. This command is only possible if all the metadata written
816 * in the cache has been output to the metadata stream to avoid corrupting the
819 * Return 0 on success, a negative value on error.
822 int lttng_metadata_cache_dump(struct lttng_metadata_stream
*stream
)
825 struct lttng_metadata_cache
*cache
= stream
->metadata_cache
;
827 mutex_lock(&cache
->lock
);
828 if (stream
->metadata_out
!= cache
->metadata_written
) {
832 stream
->metadata_out
= 0;
833 stream
->metadata_in
= 0;
834 wake_up_interruptible(&stream
->read_wait
);
838 mutex_unlock(&cache
->lock
);
843 long lttng_metadata_ring_buffer_ioctl(struct file
*filp
,
844 unsigned int cmd
, unsigned long arg
)
847 struct lttng_metadata_stream
*stream
= filp
->private_data
;
848 struct lib_ring_buffer
*buf
= stream
->priv
;
851 case RING_BUFFER_GET_NEXT_SUBBUF
:
853 struct lttng_metadata_stream
*stream
= filp
->private_data
;
854 struct lib_ring_buffer
*buf
= stream
->priv
;
855 struct channel
*chan
= buf
->backend
.chan
;
857 ret
= lttng_metadata_output_channel(stream
, chan
);
859 lib_ring_buffer_switch_slow(buf
, SWITCH_ACTIVE
);
865 case RING_BUFFER_GET_SUBBUF
:
868 * Random access is not allowed for metadata channel.
872 case RING_BUFFER_FLUSH_EMPTY
: /* Fall-through. */
873 case RING_BUFFER_FLUSH
:
875 struct lttng_metadata_stream
*stream
= filp
->private_data
;
876 struct lib_ring_buffer
*buf
= stream
->priv
;
877 struct channel
*chan
= buf
->backend
.chan
;
880 * Before doing the actual ring buffer flush, write up to one
881 * packet of metadata in the ring buffer.
883 ret
= lttng_metadata_output_channel(stream
, chan
);
888 case RING_BUFFER_GET_METADATA_VERSION
:
890 struct lttng_metadata_stream
*stream
= filp
->private_data
;
892 return put_u64(stream
->version
, arg
);
894 case RING_BUFFER_METADATA_CACHE_DUMP
:
896 struct lttng_metadata_stream
*stream
= filp
->private_data
;
898 return lttng_metadata_cache_dump(stream
);
903 /* PUT_SUBBUF is the one from lib ring buffer, unmodified. */
905 /* Performing lib ring buffer ioctl after our own. */
906 ret
= lib_ring_buffer_ioctl(filp
, cmd
, arg
, buf
);
911 case RING_BUFFER_PUT_NEXT_SUBBUF
:
913 lttng_metadata_ring_buffer_ioctl_put_next_subbuf(filp
,
926 long lttng_metadata_ring_buffer_compat_ioctl(struct file
*filp
,
927 unsigned int cmd
, unsigned long arg
)
930 struct lttng_metadata_stream
*stream
= filp
->private_data
;
931 struct lib_ring_buffer
*buf
= stream
->priv
;
934 case RING_BUFFER_GET_NEXT_SUBBUF
:
936 struct lttng_metadata_stream
*stream
= filp
->private_data
;
937 struct lib_ring_buffer
*buf
= stream
->priv
;
938 struct channel
*chan
= buf
->backend
.chan
;
940 ret
= lttng_metadata_output_channel(stream
, chan
);
942 lib_ring_buffer_switch_slow(buf
, SWITCH_ACTIVE
);
948 case RING_BUFFER_GET_SUBBUF
:
951 * Random access is not allowed for metadata channel.
955 case RING_BUFFER_FLUSH_EMPTY
: /* Fall-through. */
956 case RING_BUFFER_FLUSH
:
958 struct lttng_metadata_stream
*stream
= filp
->private_data
;
959 struct lib_ring_buffer
*buf
= stream
->priv
;
960 struct channel
*chan
= buf
->backend
.chan
;
963 * Before doing the actual ring buffer flush, write up to one
964 * packet of metadata in the ring buffer.
966 ret
= lttng_metadata_output_channel(stream
, chan
);
971 case RING_BUFFER_GET_METADATA_VERSION
:
973 struct lttng_metadata_stream
*stream
= filp
->private_data
;
975 return put_u64(stream
->version
, arg
);
977 case RING_BUFFER_METADATA_CACHE_DUMP
:
979 struct lttng_metadata_stream
*stream
= filp
->private_data
;
981 return lttng_metadata_cache_dump(stream
);
986 /* PUT_SUBBUF is the one from lib ring buffer, unmodified. */
988 /* Performing lib ring buffer ioctl after our own. */
989 ret
= lib_ring_buffer_compat_ioctl(filp
, cmd
, arg
, buf
);
994 case RING_BUFFER_PUT_NEXT_SUBBUF
:
996 lttng_metadata_ring_buffer_ioctl_put_next_subbuf(filp
,
1009 * This is not used by anonymous file descriptors. This code is left
1010 * there if we ever want to implement an inode with open() operation.
1013 int lttng_metadata_ring_buffer_open(struct inode
*inode
, struct file
*file
)
1015 struct lttng_metadata_stream
*stream
= inode
->i_private
;
1016 struct lib_ring_buffer
*buf
= stream
->priv
;
1018 file
->private_data
= buf
;
1020 * Since life-time of metadata cache differs from that of
1021 * session, we need to keep our own reference on the transport.
1023 if (!try_module_get(stream
->transport
->owner
)) {
1024 printk(KERN_WARNING
"LTT : Can't lock transport module.\n");
1027 return lib_ring_buffer_open(inode
, file
, buf
);
1031 int lttng_metadata_ring_buffer_release(struct inode
*inode
, struct file
*file
)
1033 struct lttng_metadata_stream
*stream
= file
->private_data
;
1034 struct lib_ring_buffer
*buf
= stream
->priv
;
1036 kref_put(&stream
->metadata_cache
->refcount
, metadata_cache_destroy
);
1037 module_put(stream
->transport
->owner
);
1038 return lib_ring_buffer_release(inode
, file
, buf
);
1042 ssize_t
lttng_metadata_ring_buffer_splice_read(struct file
*in
, loff_t
*ppos
,
1043 struct pipe_inode_info
*pipe
, size_t len
,
1046 struct lttng_metadata_stream
*stream
= in
->private_data
;
1047 struct lib_ring_buffer
*buf
= stream
->priv
;
1049 return lib_ring_buffer_splice_read(in
, ppos
, pipe
, len
,
1054 int lttng_metadata_ring_buffer_mmap(struct file
*filp
,
1055 struct vm_area_struct
*vma
)
1057 struct lttng_metadata_stream
*stream
= filp
->private_data
;
1058 struct lib_ring_buffer
*buf
= stream
->priv
;
1060 return lib_ring_buffer_mmap(filp
, vma
, buf
);
1064 const struct file_operations lttng_metadata_ring_buffer_file_operations
= {
1065 .owner
= THIS_MODULE
,
1066 .open
= lttng_metadata_ring_buffer_open
,
1067 .release
= lttng_metadata_ring_buffer_release
,
1068 .poll
= lttng_metadata_ring_buffer_poll
,
1069 .splice_read
= lttng_metadata_ring_buffer_splice_read
,
1070 .mmap
= lttng_metadata_ring_buffer_mmap
,
1071 .unlocked_ioctl
= lttng_metadata_ring_buffer_ioctl
,
1072 .llseek
= vfs_lib_ring_buffer_no_llseek
,
1073 #ifdef CONFIG_COMPAT
1074 .compat_ioctl
= lttng_metadata_ring_buffer_compat_ioctl
,
1079 int lttng_abi_create_stream_fd(struct file
*channel_file
, void *stream_priv
,
1080 const struct file_operations
*fops
)
1083 struct file
*stream_file
;
1085 stream_fd
= get_unused_fd_flags(0);
1086 if (stream_fd
< 0) {
1090 stream_file
= anon_inode_getfile("[lttng_stream]", fops
,
1091 stream_priv
, O_RDWR
);
1092 if (IS_ERR(stream_file
)) {
1093 ret
= PTR_ERR(stream_file
);
1097 * OPEN_FMODE, called within anon_inode_getfile/alloc_file, don't honor
1098 * FMODE_LSEEK, FMODE_PREAD nor FMODE_PWRITE. We need to read from this
1099 * file descriptor, so we set FMODE_PREAD here.
1101 stream_file
->f_mode
|= FMODE_PREAD
;
1102 fd_install(stream_fd
, stream_file
);
1104 * The stream holds a reference to the channel within the generic ring
1105 * buffer library, so no need to hold a refcount on the channel and
1106 * session files here.
1111 put_unused_fd(stream_fd
);
1117 int lttng_abi_open_stream(struct file
*channel_file
)
1119 struct lttng_channel
*channel
= channel_file
->private_data
;
1120 struct lib_ring_buffer
*buf
;
1124 buf
= channel
->ops
->buffer_read_open(channel
->chan
);
1129 ret
= lttng_abi_create_stream_fd(channel_file
, stream_priv
,
1130 <tng_stream_ring_buffer_file_operations
);
1137 channel
->ops
->buffer_read_close(buf
);
1142 int lttng_abi_open_metadata_stream(struct file
*channel_file
)
1144 struct lttng_channel
*channel
= channel_file
->private_data
;
1145 struct lttng_session
*session
= channel
->session
;
1146 struct lib_ring_buffer
*buf
;
1148 struct lttng_metadata_stream
*metadata_stream
;
1151 buf
= channel
->ops
->buffer_read_open(channel
->chan
);
1155 metadata_stream
= kzalloc(sizeof(struct lttng_metadata_stream
),
1157 if (!metadata_stream
) {
1161 metadata_stream
->metadata_cache
= session
->metadata_cache
;
1162 init_waitqueue_head(&metadata_stream
->read_wait
);
1163 metadata_stream
->priv
= buf
;
1164 stream_priv
= metadata_stream
;
1165 metadata_stream
->transport
= channel
->transport
;
1168 * Since life-time of metadata cache differs from that of
1169 * session, we need to keep our own reference on the transport.
1171 if (!try_module_get(metadata_stream
->transport
->owner
)) {
1172 printk(KERN_WARNING
"LTT : Can't lock transport module.\n");
1177 kref_get(&session
->metadata_cache
->refcount
);
1178 ret
= lttng_abi_create_stream_fd(channel_file
, stream_priv
,
1179 <tng_metadata_ring_buffer_file_operations
);
1183 list_add(&metadata_stream
->list
,
1184 &session
->metadata_cache
->metadata_stream
);
1188 kref_put(&session
->metadata_cache
->refcount
, metadata_cache_destroy
);
1189 module_put(metadata_stream
->transport
->owner
);
1191 kfree(metadata_stream
);
1193 channel
->ops
->buffer_read_close(buf
);
1198 int lttng_abi_create_event(struct file
*channel_file
,
1199 struct lttng_kernel_event
*event_param
)
1201 struct lttng_channel
*channel
= channel_file
->private_data
;
1203 struct file
*event_file
;
1206 event_param
->name
[LTTNG_KERNEL_SYM_NAME_LEN
- 1] = '\0';
1207 switch (event_param
->instrumentation
) {
1208 case LTTNG_KERNEL_KRETPROBE
:
1209 event_param
->u
.kretprobe
.symbol_name
[LTTNG_KERNEL_SYM_NAME_LEN
- 1] = '\0';
1211 case LTTNG_KERNEL_KPROBE
:
1212 event_param
->u
.kprobe
.symbol_name
[LTTNG_KERNEL_SYM_NAME_LEN
- 1] = '\0';
1214 case LTTNG_KERNEL_FUNCTION
:
1216 /* Not implemented. */
1221 event_fd
= get_unused_fd_flags(0);
1226 event_file
= anon_inode_getfile("[lttng_event]",
1229 if (IS_ERR(event_file
)) {
1230 ret
= PTR_ERR(event_file
);
1233 /* The event holds a reference on the channel */
1234 if (!atomic_long_add_unless(&channel_file
->f_count
, 1, LONG_MAX
)) {
1236 goto refcount_error
;
1238 if (event_param
->instrumentation
== LTTNG_KERNEL_TRACEPOINT
1239 || event_param
->instrumentation
== LTTNG_KERNEL_SYSCALL
) {
1240 struct lttng_enabler
*enabler
;
1242 if (strutils_is_star_glob_pattern(event_param
->name
)) {
1244 * If the event name is a star globbing pattern,
1245 * we create the special star globbing enabler.
1247 enabler
= lttng_enabler_create(LTTNG_ENABLER_STAR_GLOB
,
1248 event_param
, channel
);
1250 enabler
= lttng_enabler_create(LTTNG_ENABLER_NAME
,
1251 event_param
, channel
);
1255 struct lttng_event
*event
;
1258 * We tolerate no failure path after event creation. It
1259 * will stay invariant for the rest of the session.
1261 event
= lttng_event_create(channel
, event_param
,
1263 event_param
->instrumentation
);
1264 WARN_ON_ONCE(!event
);
1265 if (IS_ERR(event
)) {
1266 ret
= PTR_ERR(event
);
1271 event_file
->private_data
= priv
;
1272 fd_install(event_fd
, event_file
);
1276 atomic_long_dec(&channel_file
->f_count
);
1280 put_unused_fd(event_fd
);
1286 * lttng_channel_ioctl - lttng syscall through ioctl
1292 * This ioctl implements lttng commands:
1293 * LTTNG_KERNEL_STREAM
1294 * Returns an event stream file descriptor or failure.
1295 * (typically, one event stream records events from one CPU)
1296 * LTTNG_KERNEL_EVENT
1297 * Returns an event file descriptor or failure.
1298 * LTTNG_KERNEL_CONTEXT
1299 * Prepend a context field to each event in the channel
1300 * LTTNG_KERNEL_ENABLE
1301 * Enable recording for events in this channel (weak enable)
1302 * LTTNG_KERNEL_DISABLE
1303 * Disable recording for events in this channel (strong disable)
1305 * Channel and event file descriptors also hold a reference on the session.
1308 long lttng_channel_ioctl(struct file
*file
, unsigned int cmd
, unsigned long arg
)
1310 struct lttng_channel
*channel
= file
->private_data
;
1313 case LTTNG_KERNEL_OLD_STREAM
:
1314 case LTTNG_KERNEL_STREAM
:
1315 return lttng_abi_open_stream(file
);
1316 case LTTNG_KERNEL_OLD_EVENT
:
1318 struct lttng_kernel_event
*uevent_param
;
1319 struct lttng_kernel_old_event
*old_uevent_param
;
1322 uevent_param
= kmalloc(sizeof(struct lttng_kernel_event
),
1324 if (!uevent_param
) {
1328 old_uevent_param
= kmalloc(
1329 sizeof(struct lttng_kernel_old_event
),
1331 if (!old_uevent_param
) {
1333 goto old_event_error_free_param
;
1335 if (copy_from_user(old_uevent_param
,
1336 (struct lttng_kernel_old_event __user
*) arg
,
1337 sizeof(struct lttng_kernel_old_event
))) {
1339 goto old_event_error_free_old_param
;
1342 memcpy(uevent_param
->name
, old_uevent_param
->name
,
1343 sizeof(uevent_param
->name
));
1344 uevent_param
->instrumentation
=
1345 old_uevent_param
->instrumentation
;
1347 switch (old_uevent_param
->instrumentation
) {
1348 case LTTNG_KERNEL_KPROBE
:
1349 uevent_param
->u
.kprobe
.addr
=
1350 old_uevent_param
->u
.kprobe
.addr
;
1351 uevent_param
->u
.kprobe
.offset
=
1352 old_uevent_param
->u
.kprobe
.offset
;
1353 memcpy(uevent_param
->u
.kprobe
.symbol_name
,
1354 old_uevent_param
->u
.kprobe
.symbol_name
,
1355 sizeof(uevent_param
->u
.kprobe
.symbol_name
));
1357 case LTTNG_KERNEL_KRETPROBE
:
1358 uevent_param
->u
.kretprobe
.addr
=
1359 old_uevent_param
->u
.kretprobe
.addr
;
1360 uevent_param
->u
.kretprobe
.offset
=
1361 old_uevent_param
->u
.kretprobe
.offset
;
1362 memcpy(uevent_param
->u
.kretprobe
.symbol_name
,
1363 old_uevent_param
->u
.kretprobe
.symbol_name
,
1364 sizeof(uevent_param
->u
.kretprobe
.symbol_name
));
1366 case LTTNG_KERNEL_FUNCTION
:
1368 /* Not implemented. */
1373 ret
= lttng_abi_create_event(file
, uevent_param
);
1375 old_event_error_free_old_param
:
1376 kfree(old_uevent_param
);
1377 old_event_error_free_param
:
1378 kfree(uevent_param
);
1382 case LTTNG_KERNEL_EVENT
:
1384 struct lttng_kernel_event uevent_param
;
1386 if (copy_from_user(&uevent_param
,
1387 (struct lttng_kernel_event __user
*) arg
,
1388 sizeof(uevent_param
)))
1390 return lttng_abi_create_event(file
, &uevent_param
);
1392 case LTTNG_KERNEL_OLD_CONTEXT
:
1394 struct lttng_kernel_context
*ucontext_param
;
1395 struct lttng_kernel_old_context
*old_ucontext_param
;
1398 ucontext_param
= kmalloc(sizeof(struct lttng_kernel_context
),
1400 if (!ucontext_param
) {
1404 old_ucontext_param
= kmalloc(sizeof(struct lttng_kernel_old_context
),
1406 if (!old_ucontext_param
) {
1408 goto old_ctx_error_free_param
;
1411 if (copy_from_user(old_ucontext_param
,
1412 (struct lttng_kernel_old_context __user
*) arg
,
1413 sizeof(struct lttng_kernel_old_context
))) {
1415 goto old_ctx_error_free_old_param
;
1417 ucontext_param
->ctx
= old_ucontext_param
->ctx
;
1418 memcpy(ucontext_param
->padding
, old_ucontext_param
->padding
,
1419 sizeof(ucontext_param
->padding
));
1420 /* only type that uses the union */
1421 if (old_ucontext_param
->ctx
== LTTNG_KERNEL_CONTEXT_PERF_COUNTER
) {
1422 ucontext_param
->u
.perf_counter
.type
=
1423 old_ucontext_param
->u
.perf_counter
.type
;
1424 ucontext_param
->u
.perf_counter
.config
=
1425 old_ucontext_param
->u
.perf_counter
.config
;
1426 memcpy(ucontext_param
->u
.perf_counter
.name
,
1427 old_ucontext_param
->u
.perf_counter
.name
,
1428 sizeof(ucontext_param
->u
.perf_counter
.name
));
1431 ret
= lttng_abi_add_context(file
,
1433 &channel
->ctx
, channel
->session
);
1435 old_ctx_error_free_old_param
:
1436 kfree(old_ucontext_param
);
1437 old_ctx_error_free_param
:
1438 kfree(ucontext_param
);
1442 case LTTNG_KERNEL_CONTEXT
:
1444 struct lttng_kernel_context ucontext_param
;
1446 if (copy_from_user(&ucontext_param
,
1447 (struct lttng_kernel_context __user
*) arg
,
1448 sizeof(ucontext_param
)))
1450 return lttng_abi_add_context(file
,
1452 &channel
->ctx
, channel
->session
);
1454 case LTTNG_KERNEL_OLD_ENABLE
:
1455 case LTTNG_KERNEL_ENABLE
:
1456 return lttng_channel_enable(channel
);
1457 case LTTNG_KERNEL_OLD_DISABLE
:
1458 case LTTNG_KERNEL_DISABLE
:
1459 return lttng_channel_disable(channel
);
1460 case LTTNG_KERNEL_SYSCALL_MASK
:
1461 return lttng_channel_syscall_mask(channel
,
1462 (struct lttng_kernel_syscall_mask __user
*) arg
);
1464 return -ENOIOCTLCMD
;
1469 * lttng_metadata_ioctl - lttng syscall through ioctl
1475 * This ioctl implements lttng commands:
1476 * LTTNG_KERNEL_STREAM
1477 * Returns an event stream file descriptor or failure.
1479 * Channel and event file descriptors also hold a reference on the session.
1482 long lttng_metadata_ioctl(struct file
*file
, unsigned int cmd
, unsigned long arg
)
1485 case LTTNG_KERNEL_OLD_STREAM
:
1486 case LTTNG_KERNEL_STREAM
:
1487 return lttng_abi_open_metadata_stream(file
);
1489 return -ENOIOCTLCMD
;
1494 * lttng_channel_poll - lttng stream addition/removal monitoring
1499 unsigned int lttng_channel_poll(struct file
*file
, poll_table
*wait
)
1501 struct lttng_channel
*channel
= file
->private_data
;
1502 unsigned int mask
= 0;
1504 if (file
->f_mode
& FMODE_READ
) {
1505 poll_wait(file
, channel
->ops
->get_hp_wait_queue(channel
->chan
),
1508 if (channel
->ops
->is_disabled(channel
->chan
))
1510 if (channel
->ops
->is_finalized(channel
->chan
))
1512 if (channel
->ops
->buffer_has_read_closed_stream(channel
->chan
))
1513 return POLLIN
| POLLRDNORM
;
1521 int lttng_channel_release(struct inode
*inode
, struct file
*file
)
1523 struct lttng_channel
*channel
= file
->private_data
;
1526 fput(channel
->session
->file
);
1531 int lttng_metadata_channel_release(struct inode
*inode
, struct file
*file
)
1533 struct lttng_channel
*channel
= file
->private_data
;
1536 fput(channel
->session
->file
);
1537 lttng_metadata_channel_destroy(channel
);
1543 static const struct file_operations lttng_channel_fops
= {
1544 .owner
= THIS_MODULE
,
1545 .release
= lttng_channel_release
,
1546 .poll
= lttng_channel_poll
,
1547 .unlocked_ioctl
= lttng_channel_ioctl
,
1548 #ifdef CONFIG_COMPAT
1549 .compat_ioctl
= lttng_channel_ioctl
,
1553 static const struct file_operations lttng_metadata_fops
= {
1554 .owner
= THIS_MODULE
,
1555 .release
= lttng_metadata_channel_release
,
1556 .unlocked_ioctl
= lttng_metadata_ioctl
,
1557 #ifdef CONFIG_COMPAT
1558 .compat_ioctl
= lttng_metadata_ioctl
,
1563 * lttng_event_ioctl - lttng syscall through ioctl
1569 * This ioctl implements lttng commands:
1570 * LTTNG_KERNEL_CONTEXT
1571 * Prepend a context field to each record of this event
1572 * LTTNG_KERNEL_ENABLE
1573 * Enable recording for this event (weak enable)
1574 * LTTNG_KERNEL_DISABLE
1575 * Disable recording for this event (strong disable)
1578 long lttng_event_ioctl(struct file
*file
, unsigned int cmd
, unsigned long arg
)
1580 struct lttng_event
*event
;
1581 struct lttng_enabler
*enabler
;
1582 enum lttng_event_type
*evtype
= file
->private_data
;
1585 case LTTNG_KERNEL_OLD_CONTEXT
:
1587 /* Not implemented */
1590 case LTTNG_KERNEL_CONTEXT
:
1592 /* Not implemented */
1595 case LTTNG_KERNEL_OLD_ENABLE
:
1596 case LTTNG_KERNEL_ENABLE
:
1598 case LTTNG_TYPE_EVENT
:
1599 event
= file
->private_data
;
1600 return lttng_event_enable(event
);
1601 case LTTNG_TYPE_ENABLER
:
1602 enabler
= file
->private_data
;
1603 return lttng_enabler_enable(enabler
);
1608 case LTTNG_KERNEL_OLD_DISABLE
:
1609 case LTTNG_KERNEL_DISABLE
:
1611 case LTTNG_TYPE_EVENT
:
1612 event
= file
->private_data
;
1613 return lttng_event_disable(event
);
1614 case LTTNG_TYPE_ENABLER
:
1615 enabler
= file
->private_data
;
1616 return lttng_enabler_disable(enabler
);
1621 case LTTNG_KERNEL_FILTER
:
1623 case LTTNG_TYPE_EVENT
:
1625 case LTTNG_TYPE_ENABLER
:
1627 enabler
= file
->private_data
;
1628 return lttng_enabler_attach_bytecode(enabler
,
1629 (struct lttng_kernel_filter_bytecode __user
*) arg
);
1635 case LTTNG_KERNEL_ADD_CALLSITE
:
1637 case LTTNG_TYPE_EVENT
:
1638 event
= file
->private_data
;
1639 return lttng_event_add_callsite(event
,
1640 (struct lttng_kernel_event_callsite __user
*) arg
);
1641 case LTTNG_TYPE_ENABLER
:
1648 return -ENOIOCTLCMD
;
1653 int lttng_event_release(struct inode
*inode
, struct file
*file
)
1655 struct lttng_event
*event
;
1656 struct lttng_enabler
*enabler
;
1657 enum lttng_event_type
*evtype
= file
->private_data
;
1663 case LTTNG_TYPE_EVENT
:
1664 event
= file
->private_data
;
1666 fput(event
->chan
->file
);
1668 case LTTNG_TYPE_ENABLER
:
1669 enabler
= file
->private_data
;
1671 fput(enabler
->chan
->file
);
1681 /* TODO: filter control ioctl */
1682 static const struct file_operations lttng_event_fops
= {
1683 .owner
= THIS_MODULE
,
1684 .release
= lttng_event_release
,
1685 .unlocked_ioctl
= lttng_event_ioctl
,
1686 #ifdef CONFIG_COMPAT
1687 .compat_ioctl
= lttng_event_ioctl
,
1691 static int put_u64(uint64_t val
, unsigned long arg
)
1693 return put_user(val
, (uint64_t __user
*) arg
);
1696 static long lttng_stream_ring_buffer_ioctl(struct file
*filp
,
1697 unsigned int cmd
, unsigned long arg
)
1699 struct lib_ring_buffer
*buf
= filp
->private_data
;
1700 struct channel
*chan
= buf
->backend
.chan
;
1701 const struct lib_ring_buffer_config
*config
= &chan
->backend
.config
;
1702 const struct lttng_channel_ops
*ops
= chan
->backend
.priv_ops
;
1705 if (atomic_read(&chan
->record_disabled
))
1709 case LTTNG_RING_BUFFER_GET_TIMESTAMP_BEGIN
:
1713 ret
= ops
->timestamp_begin(config
, buf
, &ts
);
1716 return put_u64(ts
, arg
);
1718 case LTTNG_RING_BUFFER_GET_TIMESTAMP_END
:
1722 ret
= ops
->timestamp_end(config
, buf
, &ts
);
1725 return put_u64(ts
, arg
);
1727 case LTTNG_RING_BUFFER_GET_EVENTS_DISCARDED
:
1731 ret
= ops
->events_discarded(config
, buf
, &ed
);
1734 return put_u64(ed
, arg
);
1736 case LTTNG_RING_BUFFER_GET_CONTENT_SIZE
:
1740 ret
= ops
->content_size(config
, buf
, &cs
);
1743 return put_u64(cs
, arg
);
1745 case LTTNG_RING_BUFFER_GET_PACKET_SIZE
:
1749 ret
= ops
->packet_size(config
, buf
, &ps
);
1752 return put_u64(ps
, arg
);
1754 case LTTNG_RING_BUFFER_GET_STREAM_ID
:
1758 ret
= ops
->stream_id(config
, buf
, &si
);
1761 return put_u64(si
, arg
);
1763 case LTTNG_RING_BUFFER_GET_CURRENT_TIMESTAMP
:
1767 ret
= ops
->current_timestamp(config
, buf
, &ts
);
1770 return put_u64(ts
, arg
);
1772 case LTTNG_RING_BUFFER_GET_SEQ_NUM
:
1776 ret
= ops
->sequence_number(config
, buf
, &seq
);
1779 return put_u64(seq
, arg
);
1781 case LTTNG_RING_BUFFER_INSTANCE_ID
:
1785 ret
= ops
->instance_id(config
, buf
, &id
);
1788 return put_u64(id
, arg
);
1791 return lib_ring_buffer_file_operations
.unlocked_ioctl(filp
,
1799 #ifdef CONFIG_COMPAT
1800 static long lttng_stream_ring_buffer_compat_ioctl(struct file
*filp
,
1801 unsigned int cmd
, unsigned long arg
)
1803 struct lib_ring_buffer
*buf
= filp
->private_data
;
1804 struct channel
*chan
= buf
->backend
.chan
;
1805 const struct lib_ring_buffer_config
*config
= &chan
->backend
.config
;
1806 const struct lttng_channel_ops
*ops
= chan
->backend
.priv_ops
;
1809 if (atomic_read(&chan
->record_disabled
))
1813 case LTTNG_RING_BUFFER_COMPAT_GET_TIMESTAMP_BEGIN
:
1817 ret
= ops
->timestamp_begin(config
, buf
, &ts
);
1820 return put_u64(ts
, arg
);
1822 case LTTNG_RING_BUFFER_COMPAT_GET_TIMESTAMP_END
:
1826 ret
= ops
->timestamp_end(config
, buf
, &ts
);
1829 return put_u64(ts
, arg
);
1831 case LTTNG_RING_BUFFER_COMPAT_GET_EVENTS_DISCARDED
:
1835 ret
= ops
->events_discarded(config
, buf
, &ed
);
1838 return put_u64(ed
, arg
);
1840 case LTTNG_RING_BUFFER_COMPAT_GET_CONTENT_SIZE
:
1844 ret
= ops
->content_size(config
, buf
, &cs
);
1847 return put_u64(cs
, arg
);
1849 case LTTNG_RING_BUFFER_COMPAT_GET_PACKET_SIZE
:
1853 ret
= ops
->packet_size(config
, buf
, &ps
);
1856 return put_u64(ps
, arg
);
1858 case LTTNG_RING_BUFFER_COMPAT_GET_STREAM_ID
:
1862 ret
= ops
->stream_id(config
, buf
, &si
);
1865 return put_u64(si
, arg
);
1867 case LTTNG_RING_BUFFER_GET_CURRENT_TIMESTAMP
:
1871 ret
= ops
->current_timestamp(config
, buf
, &ts
);
1874 return put_u64(ts
, arg
);
1876 case LTTNG_RING_BUFFER_COMPAT_GET_SEQ_NUM
:
1880 ret
= ops
->sequence_number(config
, buf
, &seq
);
1883 return put_u64(seq
, arg
);
1885 case LTTNG_RING_BUFFER_COMPAT_INSTANCE_ID
:
1889 ret
= ops
->instance_id(config
, buf
, &id
);
1892 return put_u64(id
, arg
);
1895 return lib_ring_buffer_file_operations
.compat_ioctl(filp
,
1902 #endif /* CONFIG_COMPAT */
1904 static void lttng_stream_override_ring_buffer_fops(void)
1906 lttng_stream_ring_buffer_file_operations
.owner
= THIS_MODULE
;
1907 lttng_stream_ring_buffer_file_operations
.open
=
1908 lib_ring_buffer_file_operations
.open
;
1909 lttng_stream_ring_buffer_file_operations
.release
=
1910 lib_ring_buffer_file_operations
.release
;
1911 lttng_stream_ring_buffer_file_operations
.poll
=
1912 lib_ring_buffer_file_operations
.poll
;
1913 lttng_stream_ring_buffer_file_operations
.splice_read
=
1914 lib_ring_buffer_file_operations
.splice_read
;
1915 lttng_stream_ring_buffer_file_operations
.mmap
=
1916 lib_ring_buffer_file_operations
.mmap
;
1917 lttng_stream_ring_buffer_file_operations
.unlocked_ioctl
=
1918 lttng_stream_ring_buffer_ioctl
;
1919 lttng_stream_ring_buffer_file_operations
.llseek
=
1920 lib_ring_buffer_file_operations
.llseek
;
1921 #ifdef CONFIG_COMPAT
1922 lttng_stream_ring_buffer_file_operations
.compat_ioctl
=
1923 lttng_stream_ring_buffer_compat_ioctl
;
1927 int __init
lttng_abi_init(void)
1933 ret
= lttng_tp_mempool_init();
1938 lttng_proc_dentry
= proc_create_data("lttng", S_IRUSR
| S_IWUSR
, NULL
,
1939 <tng_proc_ops
, NULL
);
1941 if (!lttng_proc_dentry
) {
1942 printk(KERN_ERR
"Error creating LTTng control file\n");
1946 lttng_stream_override_ring_buffer_fops();
1950 lttng_tp_mempool_destroy();
1951 lttng_clock_unref();
1955 /* No __exit annotation because used by init error path too. */
1956 void lttng_abi_exit(void)
1958 lttng_tp_mempool_destroy();
1959 lttng_clock_unref();
1960 if (lttng_proc_dentry
)
1961 remove_proc_entry("lttng", NULL
);