1 /* SPDX-License-Identifier: (GPL-2.0 or LGPL-2.1)
7 * Copyright (C) 2010-2012 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
9 * Mimic system calls for:
10 * - session creation, returns a file descriptor or failure.
11 * - channel creation, returns a file descriptor or failure.
12 * - Operates on a session file descriptor
13 * - Takes all channel options as parameters.
14 * - stream get, returns a file descriptor or failure.
15 * - Operates on a channel file descriptor.
16 * - stream notifier get, returns a file descriptor or failure.
17 * - Operates on a channel file descriptor.
18 * - event creation, returns a file descriptor or failure.
19 * - Operates on a channel file descriptor
20 * - Takes an event name as parameter
21 * - Takes an instrumentation source as parameter
22 * - e.g. tracepoints, dynamic_probes...
23 * - Takes instrumentation source specific arguments.
26 #include <linux/module.h>
27 #include <linux/proc_fs.h>
28 #include <linux/anon_inodes.h>
29 #include <linux/file.h>
30 #include <linux/uaccess.h>
31 #include <linux/slab.h>
32 #include <linux/err.h>
33 #include <wrapper/vmalloc.h> /* for wrapper_vmalloc_sync_all() */
34 #include <wrapper/ringbuffer/vfs.h>
35 #include <wrapper/ringbuffer/backend.h>
36 #include <wrapper/ringbuffer/frontend.h>
37 #include <wrapper/poll.h>
38 #include <wrapper/file.h>
39 #include <wrapper/kref.h>
40 #include <lttng-string-utils.h>
41 #include <lttng-abi.h>
42 #include <lttng-abi-old.h>
43 #include <lttng-events.h>
44 #include <lttng-tracer.h>
45 #include <lttng-tp-mempool.h>
46 #include <lib/ringbuffer/frontend_types.h>
49 * This is LTTng's own personal way to create a system call as an external
50 * module. We use ioctl() on /proc/lttng.
53 static struct proc_dir_entry
*lttng_proc_dentry
;
54 static const struct file_operations lttng_fops
;
55 static const struct file_operations lttng_session_fops
;
56 static const struct file_operations lttng_channel_fops
;
57 static const struct file_operations lttng_metadata_fops
;
58 static const struct file_operations lttng_event_fops
;
59 static struct file_operations lttng_stream_ring_buffer_file_operations
;
61 static int put_u64(uint64_t val
, unsigned long arg
);
64 * Teardown management: opened file descriptors keep a refcount on the module,
65 * so it can only exit when all file descriptors are closed.
69 int lttng_abi_create_session(void)
71 struct lttng_session
*session
;
72 struct file
*session_file
;
75 session
= lttng_session_create();
78 session_fd
= lttng_get_unused_fd();
83 session_file
= anon_inode_getfile("[lttng_session]",
86 if (IS_ERR(session_file
)) {
87 ret
= PTR_ERR(session_file
);
90 session
->file
= session_file
;
91 fd_install(session_fd
, session_file
);
95 put_unused_fd(session_fd
);
97 lttng_session_destroy(session
);
102 int lttng_abi_tracepoint_list(void)
104 struct file
*tracepoint_list_file
;
107 file_fd
= lttng_get_unused_fd();
113 tracepoint_list_file
= anon_inode_getfile("[lttng_tracepoint_list]",
114 <tng_tracepoint_list_fops
,
116 if (IS_ERR(tracepoint_list_file
)) {
117 ret
= PTR_ERR(tracepoint_list_file
);
120 ret
= lttng_tracepoint_list_fops
.open(NULL
, tracepoint_list_file
);
123 fd_install(file_fd
, tracepoint_list_file
);
127 fput(tracepoint_list_file
);
129 put_unused_fd(file_fd
);
134 #ifndef CONFIG_HAVE_SYSCALL_TRACEPOINTS
136 int lttng_abi_syscall_list(void)
142 int lttng_abi_syscall_list(void)
144 struct file
*syscall_list_file
;
147 file_fd
= lttng_get_unused_fd();
153 syscall_list_file
= anon_inode_getfile("[lttng_syscall_list]",
154 <tng_syscall_list_fops
,
156 if (IS_ERR(syscall_list_file
)) {
157 ret
= PTR_ERR(syscall_list_file
);
160 ret
= lttng_syscall_list_fops
.open(NULL
, syscall_list_file
);
163 fd_install(file_fd
, syscall_list_file
);
167 fput(syscall_list_file
);
169 put_unused_fd(file_fd
);
176 void lttng_abi_tracer_version(struct lttng_kernel_tracer_version
*v
)
178 v
->major
= LTTNG_MODULES_MAJOR_VERSION
;
179 v
->minor
= LTTNG_MODULES_MINOR_VERSION
;
180 v
->patchlevel
= LTTNG_MODULES_PATCHLEVEL_VERSION
;
184 void lttng_abi_tracer_abi_version(struct lttng_kernel_tracer_abi_version
*v
)
186 v
->major
= LTTNG_MODULES_ABI_MAJOR_VERSION
;
187 v
->minor
= LTTNG_MODULES_ABI_MINOR_VERSION
;
191 long lttng_abi_add_context(struct file
*file
,
192 struct lttng_kernel_context
*context_param
,
193 struct lttng_ctx
**ctx
, struct lttng_session
*session
)
196 if (session
->been_active
)
199 switch (context_param
->ctx
) {
200 case LTTNG_KERNEL_CONTEXT_PID
:
201 return lttng_add_pid_to_ctx(ctx
);
202 case LTTNG_KERNEL_CONTEXT_PRIO
:
203 return lttng_add_prio_to_ctx(ctx
);
204 case LTTNG_KERNEL_CONTEXT_NICE
:
205 return lttng_add_nice_to_ctx(ctx
);
206 case LTTNG_KERNEL_CONTEXT_VPID
:
207 return lttng_add_vpid_to_ctx(ctx
);
208 case LTTNG_KERNEL_CONTEXT_TID
:
209 return lttng_add_tid_to_ctx(ctx
);
210 case LTTNG_KERNEL_CONTEXT_VTID
:
211 return lttng_add_vtid_to_ctx(ctx
);
212 case LTTNG_KERNEL_CONTEXT_PPID
:
213 return lttng_add_ppid_to_ctx(ctx
);
214 case LTTNG_KERNEL_CONTEXT_VPPID
:
215 return lttng_add_vppid_to_ctx(ctx
);
216 case LTTNG_KERNEL_CONTEXT_PERF_COUNTER
:
217 context_param
->u
.perf_counter
.name
[LTTNG_KERNEL_SYM_NAME_LEN
- 1] = '\0';
218 return lttng_add_perf_counter_to_ctx(context_param
->u
.perf_counter
.type
,
219 context_param
->u
.perf_counter
.config
,
220 context_param
->u
.perf_counter
.name
,
222 case LTTNG_KERNEL_CONTEXT_PROCNAME
:
223 return lttng_add_procname_to_ctx(ctx
);
224 case LTTNG_KERNEL_CONTEXT_HOSTNAME
:
225 return lttng_add_hostname_to_ctx(ctx
);
226 case LTTNG_KERNEL_CONTEXT_CPU_ID
:
227 return lttng_add_cpu_id_to_ctx(ctx
);
228 case LTTNG_KERNEL_CONTEXT_INTERRUPTIBLE
:
229 return lttng_add_interruptible_to_ctx(ctx
);
230 case LTTNG_KERNEL_CONTEXT_NEED_RESCHEDULE
:
231 return lttng_add_need_reschedule_to_ctx(ctx
);
232 case LTTNG_KERNEL_CONTEXT_PREEMPTIBLE
:
233 return lttng_add_preemptible_to_ctx(ctx
);
234 case LTTNG_KERNEL_CONTEXT_MIGRATABLE
:
235 return lttng_add_migratable_to_ctx(ctx
);
236 case LTTNG_KERNEL_CONTEXT_CALLSTACK_KERNEL
:
237 case LTTNG_KERNEL_CONTEXT_CALLSTACK_USER
:
238 return lttng_add_callstack_to_ctx(ctx
, context_param
->ctx
);
239 case LTTNG_KERNEL_CONTEXT_CGROUP_NS
:
240 return lttng_add_cgroup_ns_to_ctx(ctx
);
241 case LTTNG_KERNEL_CONTEXT_IPC_NS
:
242 return lttng_add_ipc_ns_to_ctx(ctx
);
243 case LTTNG_KERNEL_CONTEXT_MNT_NS
:
244 return lttng_add_mnt_ns_to_ctx(ctx
);
245 case LTTNG_KERNEL_CONTEXT_NET_NS
:
246 return lttng_add_net_ns_to_ctx(ctx
);
247 case LTTNG_KERNEL_CONTEXT_PID_NS
:
248 return lttng_add_pid_ns_to_ctx(ctx
);
249 case LTTNG_KERNEL_CONTEXT_USER_NS
:
250 return lttng_add_user_ns_to_ctx(ctx
);
251 case LTTNG_KERNEL_CONTEXT_UTS_NS
:
252 return lttng_add_uts_ns_to_ctx(ctx
);
253 case LTTNG_KERNEL_CONTEXT_UID
:
254 return lttng_add_uid_to_ctx(ctx
);
255 case LTTNG_KERNEL_CONTEXT_EUID
:
256 return lttng_add_euid_to_ctx(ctx
);
257 case LTTNG_KERNEL_CONTEXT_SUID
:
258 return lttng_add_suid_to_ctx(ctx
);
259 case LTTNG_KERNEL_CONTEXT_GID
:
260 return lttng_add_gid_to_ctx(ctx
);
261 case LTTNG_KERNEL_CONTEXT_EGID
:
262 return lttng_add_egid_to_ctx(ctx
);
263 case LTTNG_KERNEL_CONTEXT_SGID
:
264 return lttng_add_sgid_to_ctx(ctx
);
265 case LTTNG_KERNEL_CONTEXT_VUID
:
266 return lttng_add_vuid_to_ctx(ctx
);
267 case LTTNG_KERNEL_CONTEXT_VEUID
:
268 return lttng_add_veuid_to_ctx(ctx
);
269 case LTTNG_KERNEL_CONTEXT_VSUID
:
270 return lttng_add_vsuid_to_ctx(ctx
);
271 case LTTNG_KERNEL_CONTEXT_VGID
:
272 return lttng_add_vgid_to_ctx(ctx
);
273 case LTTNG_KERNEL_CONTEXT_VEGID
:
274 return lttng_add_vegid_to_ctx(ctx
);
275 case LTTNG_KERNEL_CONTEXT_VSGID
:
276 return lttng_add_vsgid_to_ctx(ctx
);
283 * lttng_ioctl - lttng syscall through ioctl
289 * This ioctl implements lttng commands:
290 * LTTNG_KERNEL_SESSION
291 * Returns a LTTng trace session file descriptor
292 * LTTNG_KERNEL_TRACER_VERSION
293 * Returns the LTTng kernel tracer version
294 * LTTNG_KERNEL_TRACEPOINT_LIST
295 * Returns a file descriptor listing available tracepoints
296 * LTTNG_KERNEL_WAIT_QUIESCENT
297 * Returns after all previously running probes have completed
298 * LTTNG_KERNEL_TRACER_ABI_VERSION
299 * Returns the LTTng kernel tracer ABI version
301 * The returned session will be deleted when its file descriptor is closed.
304 long lttng_ioctl(struct file
*file
, unsigned int cmd
, unsigned long arg
)
307 case LTTNG_KERNEL_OLD_SESSION
:
308 case LTTNG_KERNEL_SESSION
:
309 return lttng_abi_create_session();
310 case LTTNG_KERNEL_OLD_TRACER_VERSION
:
312 struct lttng_kernel_tracer_version v
;
313 struct lttng_kernel_old_tracer_version oldv
;
314 struct lttng_kernel_old_tracer_version
*uversion
=
315 (struct lttng_kernel_old_tracer_version __user
*) arg
;
317 lttng_abi_tracer_version(&v
);
318 oldv
.major
= v
.major
;
319 oldv
.minor
= v
.minor
;
320 oldv
.patchlevel
= v
.patchlevel
;
322 if (copy_to_user(uversion
, &oldv
, sizeof(oldv
)))
326 case LTTNG_KERNEL_TRACER_VERSION
:
328 struct lttng_kernel_tracer_version version
;
329 struct lttng_kernel_tracer_version
*uversion
=
330 (struct lttng_kernel_tracer_version __user
*) arg
;
332 lttng_abi_tracer_version(&version
);
334 if (copy_to_user(uversion
, &version
, sizeof(version
)))
338 case LTTNG_KERNEL_TRACER_ABI_VERSION
:
340 struct lttng_kernel_tracer_abi_version version
;
341 struct lttng_kernel_tracer_abi_version
*uversion
=
342 (struct lttng_kernel_tracer_abi_version __user
*) arg
;
344 lttng_abi_tracer_abi_version(&version
);
346 if (copy_to_user(uversion
, &version
, sizeof(version
)))
350 case LTTNG_KERNEL_OLD_TRACEPOINT_LIST
:
351 case LTTNG_KERNEL_TRACEPOINT_LIST
:
352 return lttng_abi_tracepoint_list();
353 case LTTNG_KERNEL_SYSCALL_LIST
:
354 return lttng_abi_syscall_list();
355 case LTTNG_KERNEL_OLD_WAIT_QUIESCENT
:
356 case LTTNG_KERNEL_WAIT_QUIESCENT
:
359 case LTTNG_KERNEL_OLD_CALIBRATE
:
361 struct lttng_kernel_old_calibrate __user
*ucalibrate
=
362 (struct lttng_kernel_old_calibrate __user
*) arg
;
363 struct lttng_kernel_old_calibrate old_calibrate
;
364 struct lttng_kernel_calibrate calibrate
;
367 if (copy_from_user(&old_calibrate
, ucalibrate
, sizeof(old_calibrate
)))
369 calibrate
.type
= old_calibrate
.type
;
370 ret
= lttng_calibrate(&calibrate
);
371 if (copy_to_user(ucalibrate
, &old_calibrate
, sizeof(old_calibrate
)))
375 case LTTNG_KERNEL_CALIBRATE
:
377 struct lttng_kernel_calibrate __user
*ucalibrate
=
378 (struct lttng_kernel_calibrate __user
*) arg
;
379 struct lttng_kernel_calibrate calibrate
;
382 if (copy_from_user(&calibrate
, ucalibrate
, sizeof(calibrate
)))
384 ret
= lttng_calibrate(&calibrate
);
385 if (copy_to_user(ucalibrate
, &calibrate
, sizeof(calibrate
)))
394 static const struct file_operations lttng_fops
= {
395 .owner
= THIS_MODULE
,
396 .unlocked_ioctl
= lttng_ioctl
,
398 .compat_ioctl
= lttng_ioctl
,
403 int lttng_abi_create_channel(struct file
*session_file
,
404 struct lttng_kernel_channel
*chan_param
,
405 enum channel_type channel_type
)
407 struct lttng_session
*session
= session_file
->private_data
;
408 const struct file_operations
*fops
= NULL
;
409 const char *transport_name
;
410 struct lttng_channel
*chan
;
411 struct file
*chan_file
;
415 chan_fd
= lttng_get_unused_fd();
420 switch (channel_type
) {
421 case PER_CPU_CHANNEL
:
422 fops
= <tng_channel_fops
;
424 case METADATA_CHANNEL
:
425 fops
= <tng_metadata_fops
;
429 chan_file
= anon_inode_getfile("[lttng_channel]",
432 if (IS_ERR(chan_file
)) {
433 ret
= PTR_ERR(chan_file
);
436 switch (channel_type
) {
437 case PER_CPU_CHANNEL
:
438 if (chan_param
->output
== LTTNG_KERNEL_SPLICE
) {
439 transport_name
= chan_param
->overwrite
?
440 "relay-overwrite" : "relay-discard";
441 } else if (chan_param
->output
== LTTNG_KERNEL_MMAP
) {
442 transport_name
= chan_param
->overwrite
?
443 "relay-overwrite-mmap" : "relay-discard-mmap";
448 case METADATA_CHANNEL
:
449 if (chan_param
->output
== LTTNG_KERNEL_SPLICE
)
450 transport_name
= "relay-metadata";
451 else if (chan_param
->output
== LTTNG_KERNEL_MMAP
)
452 transport_name
= "relay-metadata-mmap";
457 transport_name
= "<unknown>";
460 if (!atomic_long_add_unless(&session_file
->f_count
, 1, LONG_MAX
)) {
465 * We tolerate no failure path after channel creation. It will stay
466 * invariant for the rest of the session.
468 chan
= lttng_channel_create(session
, transport_name
, NULL
,
469 chan_param
->subbuf_size
,
470 chan_param
->num_subbuf
,
471 chan_param
->switch_timer_interval
,
472 chan_param
->read_timer_interval
,
478 chan
->file
= chan_file
;
479 chan_file
->private_data
= chan
;
480 fd_install(chan_fd
, chan_file
);
485 atomic_long_dec(&session_file
->f_count
);
489 put_unused_fd(chan_fd
);
495 int lttng_abi_session_set_name(struct lttng_session
*session
,
496 struct lttng_kernel_session_name
*name
)
500 len
= strnlen(name
->name
, LTTNG_KERNEL_SESSION_NAME_LEN
);
502 if (len
== LTTNG_KERNEL_SESSION_NAME_LEN
) {
503 /* Name is too long/malformed */
507 strcpy(session
->name
, name
->name
);
512 int lttng_abi_session_set_creation_time(struct lttng_session
*session
,
513 struct lttng_kernel_session_creation_time
*time
)
517 len
= strnlen(time
->iso8601
, LTTNG_KERNEL_SESSION_CREATION_TIME_ISO8601_LEN
);
519 if (len
== LTTNG_KERNEL_SESSION_CREATION_TIME_ISO8601_LEN
) {
520 /* Time is too long/malformed */
524 strcpy(session
->creation_time
, time
->iso8601
);
529 enum tracker_type
get_tracker_type(struct lttng_kernel_tracker_args
*tracker
)
531 switch (tracker
->type
) {
532 case LTTNG_KERNEL_TRACKER_PID
:
534 case LTTNG_KERNEL_TRACKER_VPID
:
536 case LTTNG_KERNEL_TRACKER_UID
:
538 case LTTNG_KERNEL_TRACKER_VUID
:
540 case LTTNG_KERNEL_TRACKER_GID
:
542 case LTTNG_KERNEL_TRACKER_VGID
:
545 return TRACKER_UNKNOWN
;
550 * lttng_session_ioctl - lttng session fd ioctl
556 * This ioctl implements lttng commands:
557 * LTTNG_KERNEL_CHANNEL
558 * Returns a LTTng channel file descriptor
559 * LTTNG_KERNEL_ENABLE
560 * Enables tracing for a session (weak enable)
561 * LTTNG_KERNEL_DISABLE
562 * Disables tracing for a session (strong disable)
563 * LTTNG_KERNEL_METADATA
564 * Returns a LTTng metadata file descriptor
565 * LTTNG_KERNEL_SESSION_TRACK_PID
566 * Add PID to session PID tracker
567 * LTTNG_KERNEL_SESSION_UNTRACK_PID
568 * Remove PID from session PID tracker
569 * LTTNG_KERNEL_SESSION_TRACK_ID
571 * LTTNG_KERNEL_SESSION_UNTRACK_ID
572 * Remove ID from tracker
574 * The returned channel will be deleted when its file descriptor is closed.
577 long lttng_session_ioctl(struct file
*file
, unsigned int cmd
, unsigned long arg
)
579 struct lttng_session
*session
= file
->private_data
;
580 struct lttng_kernel_channel chan_param
;
581 struct lttng_kernel_old_channel old_chan_param
;
584 case LTTNG_KERNEL_OLD_CHANNEL
:
586 if (copy_from_user(&old_chan_param
,
587 (struct lttng_kernel_old_channel __user
*) arg
,
588 sizeof(struct lttng_kernel_old_channel
)))
590 chan_param
.overwrite
= old_chan_param
.overwrite
;
591 chan_param
.subbuf_size
= old_chan_param
.subbuf_size
;
592 chan_param
.num_subbuf
= old_chan_param
.num_subbuf
;
593 chan_param
.switch_timer_interval
= old_chan_param
.switch_timer_interval
;
594 chan_param
.read_timer_interval
= old_chan_param
.read_timer_interval
;
595 chan_param
.output
= old_chan_param
.output
;
597 return lttng_abi_create_channel(file
, &chan_param
,
600 case LTTNG_KERNEL_CHANNEL
:
602 if (copy_from_user(&chan_param
,
603 (struct lttng_kernel_channel __user
*) arg
,
604 sizeof(struct lttng_kernel_channel
)))
606 return lttng_abi_create_channel(file
, &chan_param
,
609 case LTTNG_KERNEL_OLD_SESSION_START
:
610 case LTTNG_KERNEL_OLD_ENABLE
:
611 case LTTNG_KERNEL_SESSION_START
:
612 case LTTNG_KERNEL_ENABLE
:
613 return lttng_session_enable(session
);
614 case LTTNG_KERNEL_OLD_SESSION_STOP
:
615 case LTTNG_KERNEL_OLD_DISABLE
:
616 case LTTNG_KERNEL_SESSION_STOP
:
617 case LTTNG_KERNEL_DISABLE
:
618 return lttng_session_disable(session
);
619 case LTTNG_KERNEL_OLD_METADATA
:
621 if (copy_from_user(&old_chan_param
,
622 (struct lttng_kernel_old_channel __user
*) arg
,
623 sizeof(struct lttng_kernel_old_channel
)))
625 chan_param
.overwrite
= old_chan_param
.overwrite
;
626 chan_param
.subbuf_size
= old_chan_param
.subbuf_size
;
627 chan_param
.num_subbuf
= old_chan_param
.num_subbuf
;
628 chan_param
.switch_timer_interval
= old_chan_param
.switch_timer_interval
;
629 chan_param
.read_timer_interval
= old_chan_param
.read_timer_interval
;
630 chan_param
.output
= old_chan_param
.output
;
632 return lttng_abi_create_channel(file
, &chan_param
,
635 case LTTNG_KERNEL_METADATA
:
637 if (copy_from_user(&chan_param
,
638 (struct lttng_kernel_channel __user
*) arg
,
639 sizeof(struct lttng_kernel_channel
)))
641 return lttng_abi_create_channel(file
, &chan_param
,
644 case LTTNG_KERNEL_SESSION_TRACK_PID
:
645 return lttng_session_track_id(session
, TRACKER_PID
, (int) arg
);
646 case LTTNG_KERNEL_SESSION_UNTRACK_PID
:
647 return lttng_session_untrack_id(session
, TRACKER_PID
, (int) arg
);
648 case LTTNG_KERNEL_SESSION_TRACK_ID
:
650 struct lttng_kernel_tracker_args tracker
;
651 enum tracker_type tracker_type
;
653 if (copy_from_user(&tracker
,
654 (struct lttng_kernel_tracker_args __user
*) arg
,
655 sizeof(struct lttng_kernel_tracker_args
)))
657 tracker_type
= get_tracker_type(&tracker
);
658 if (tracker_type
== TRACKER_UNKNOWN
)
660 return lttng_session_track_id(session
, tracker_type
, tracker
.id
);
662 case LTTNG_KERNEL_SESSION_UNTRACK_ID
:
664 struct lttng_kernel_tracker_args tracker
;
665 enum tracker_type tracker_type
;
667 if (copy_from_user(&tracker
,
668 (struct lttng_kernel_tracker_args __user
*) arg
,
669 sizeof(struct lttng_kernel_tracker_args
)))
671 tracker_type
= get_tracker_type(&tracker
);
672 if (tracker_type
== TRACKER_UNKNOWN
)
674 return lttng_session_untrack_id(session
, tracker_type
,
677 case LTTNG_KERNEL_SESSION_LIST_TRACKER_PIDS
:
678 return lttng_session_list_tracker_ids(session
, TRACKER_PID
);
679 case LTTNG_KERNEL_SESSION_LIST_TRACKER_IDS
:
681 struct lttng_kernel_tracker_args tracker
;
682 enum tracker_type tracker_type
;
684 if (copy_from_user(&tracker
,
685 (struct lttng_kernel_tracker_args __user
*) arg
,
686 sizeof(struct lttng_kernel_tracker_args
)))
688 tracker_type
= get_tracker_type(&tracker
);
689 if (tracker_type
== TRACKER_UNKNOWN
)
691 return lttng_session_list_tracker_ids(session
, tracker_type
);
693 case LTTNG_KERNEL_SESSION_METADATA_REGEN
:
694 return lttng_session_metadata_regenerate(session
);
695 case LTTNG_KERNEL_SESSION_STATEDUMP
:
696 return lttng_session_statedump(session
);
697 case LTTNG_KERNEL_SESSION_SET_NAME
:
699 struct lttng_kernel_session_name name
;
701 if (copy_from_user(&name
,
702 (struct lttng_kernel_session_name __user
*) arg
,
703 sizeof(struct lttng_kernel_session_name
)))
705 return lttng_abi_session_set_name(session
, &name
);
707 case LTTNG_KERNEL_SESSION_SET_CREATION_TIME
:
709 struct lttng_kernel_session_creation_time time
;
711 if (copy_from_user(&time
,
712 (struct lttng_kernel_session_creation_time __user
*) arg
,
713 sizeof(struct lttng_kernel_session_creation_time
)))
715 return lttng_abi_session_set_creation_time(session
, &time
);
723 * Called when the last file reference is dropped.
725 * Big fat note: channels and events are invariant for the whole session after
726 * their creation. So this session destruction also destroys all channel and
727 * event structures specific to this session (they are not destroyed when their
728 * individual file is released).
731 int lttng_session_release(struct inode
*inode
, struct file
*file
)
733 struct lttng_session
*session
= file
->private_data
;
736 lttng_session_destroy(session
);
740 static const struct file_operations lttng_session_fops
= {
741 .owner
= THIS_MODULE
,
742 .release
= lttng_session_release
,
743 .unlocked_ioctl
= lttng_session_ioctl
,
745 .compat_ioctl
= lttng_session_ioctl
,
750 * lttng_metadata_ring_buffer_poll - LTTng ring buffer poll file operation
754 * Handles the poll operations for the metadata channels.
757 unsigned int lttng_metadata_ring_buffer_poll(struct file
*filp
,
760 struct lttng_metadata_stream
*stream
= filp
->private_data
;
761 struct lib_ring_buffer
*buf
= stream
->priv
;
763 unsigned int mask
= 0;
765 if (filp
->f_mode
& FMODE_READ
) {
766 poll_wait_set_exclusive(wait
);
767 poll_wait(filp
, &stream
->read_wait
, wait
);
769 finalized
= stream
->finalized
;
772 * lib_ring_buffer_is_finalized() contains a smp_rmb()
773 * ordering finalized load before offsets loads.
775 WARN_ON(atomic_long_read(&buf
->active_readers
) != 1);
780 mutex_lock(&stream
->metadata_cache
->lock
);
781 if (stream
->metadata_cache
->metadata_written
>
782 stream
->metadata_out
)
784 mutex_unlock(&stream
->metadata_cache
->lock
);
791 void lttng_metadata_ring_buffer_ioctl_put_next_subbuf(struct file
*filp
,
792 unsigned int cmd
, unsigned long arg
)
794 struct lttng_metadata_stream
*stream
= filp
->private_data
;
796 stream
->metadata_out
= stream
->metadata_in
;
800 * Reset the counter of how much metadata has been consumed to 0. That way,
801 * the consumer receives the content of the metadata cache unchanged. This is
802 * different from the metadata_regenerate where the offset from epoch is
803 * resampled, here we want the exact same content as the last time the metadata
804 * was generated. This command is only possible if all the metadata written
805 * in the cache has been output to the metadata stream to avoid corrupting the
808 * Return 0 on success, a negative value on error.
811 int lttng_metadata_cache_dump(struct lttng_metadata_stream
*stream
)
814 struct lttng_metadata_cache
*cache
= stream
->metadata_cache
;
816 mutex_lock(&cache
->lock
);
817 if (stream
->metadata_out
!= cache
->metadata_written
) {
821 stream
->metadata_out
= 0;
822 stream
->metadata_in
= 0;
823 wake_up_interruptible(&stream
->read_wait
);
827 mutex_unlock(&cache
->lock
);
832 long lttng_metadata_ring_buffer_ioctl(struct file
*filp
,
833 unsigned int cmd
, unsigned long arg
)
836 struct lttng_metadata_stream
*stream
= filp
->private_data
;
837 struct lib_ring_buffer
*buf
= stream
->priv
;
840 case RING_BUFFER_GET_NEXT_SUBBUF
:
842 struct lttng_metadata_stream
*stream
= filp
->private_data
;
843 struct lib_ring_buffer
*buf
= stream
->priv
;
844 struct channel
*chan
= buf
->backend
.chan
;
846 ret
= lttng_metadata_output_channel(stream
, chan
);
848 lib_ring_buffer_switch_slow(buf
, SWITCH_ACTIVE
);
854 case RING_BUFFER_GET_SUBBUF
:
857 * Random access is not allowed for metadata channel.
861 case RING_BUFFER_FLUSH_EMPTY
: /* Fall-through. */
862 case RING_BUFFER_FLUSH
:
864 struct lttng_metadata_stream
*stream
= filp
->private_data
;
865 struct lib_ring_buffer
*buf
= stream
->priv
;
866 struct channel
*chan
= buf
->backend
.chan
;
869 * Before doing the actual ring buffer flush, write up to one
870 * packet of metadata in the ring buffer.
872 ret
= lttng_metadata_output_channel(stream
, chan
);
877 case RING_BUFFER_GET_METADATA_VERSION
:
879 struct lttng_metadata_stream
*stream
= filp
->private_data
;
881 return put_u64(stream
->version
, arg
);
883 case RING_BUFFER_METADATA_CACHE_DUMP
:
885 struct lttng_metadata_stream
*stream
= filp
->private_data
;
887 return lttng_metadata_cache_dump(stream
);
892 /* PUT_SUBBUF is the one from lib ring buffer, unmodified. */
894 /* Performing lib ring buffer ioctl after our own. */
895 ret
= lib_ring_buffer_ioctl(filp
, cmd
, arg
, buf
);
900 case RING_BUFFER_PUT_NEXT_SUBBUF
:
902 lttng_metadata_ring_buffer_ioctl_put_next_subbuf(filp
,
915 long lttng_metadata_ring_buffer_compat_ioctl(struct file
*filp
,
916 unsigned int cmd
, unsigned long arg
)
919 struct lttng_metadata_stream
*stream
= filp
->private_data
;
920 struct lib_ring_buffer
*buf
= stream
->priv
;
923 case RING_BUFFER_GET_NEXT_SUBBUF
:
925 struct lttng_metadata_stream
*stream
= filp
->private_data
;
926 struct lib_ring_buffer
*buf
= stream
->priv
;
927 struct channel
*chan
= buf
->backend
.chan
;
929 ret
= lttng_metadata_output_channel(stream
, chan
);
931 lib_ring_buffer_switch_slow(buf
, SWITCH_ACTIVE
);
937 case RING_BUFFER_GET_SUBBUF
:
940 * Random access is not allowed for metadata channel.
944 case RING_BUFFER_FLUSH_EMPTY
: /* Fall-through. */
945 case RING_BUFFER_FLUSH
:
947 struct lttng_metadata_stream
*stream
= filp
->private_data
;
948 struct lib_ring_buffer
*buf
= stream
->priv
;
949 struct channel
*chan
= buf
->backend
.chan
;
952 * Before doing the actual ring buffer flush, write up to one
953 * packet of metadata in the ring buffer.
955 ret
= lttng_metadata_output_channel(stream
, chan
);
960 case RING_BUFFER_GET_METADATA_VERSION
:
962 struct lttng_metadata_stream
*stream
= filp
->private_data
;
964 return put_u64(stream
->version
, arg
);
966 case RING_BUFFER_METADATA_CACHE_DUMP
:
968 struct lttng_metadata_stream
*stream
= filp
->private_data
;
970 return lttng_metadata_cache_dump(stream
);
975 /* PUT_SUBBUF is the one from lib ring buffer, unmodified. */
977 /* Performing lib ring buffer ioctl after our own. */
978 ret
= lib_ring_buffer_compat_ioctl(filp
, cmd
, arg
, buf
);
983 case RING_BUFFER_PUT_NEXT_SUBBUF
:
985 lttng_metadata_ring_buffer_ioctl_put_next_subbuf(filp
,
998 * This is not used by anonymous file descriptors. This code is left
999 * there if we ever want to implement an inode with open() operation.
1002 int lttng_metadata_ring_buffer_open(struct inode
*inode
, struct file
*file
)
1004 struct lttng_metadata_stream
*stream
= inode
->i_private
;
1005 struct lib_ring_buffer
*buf
= stream
->priv
;
1007 file
->private_data
= buf
;
1009 * Since life-time of metadata cache differs from that of
1010 * session, we need to keep our own reference on the transport.
1012 if (!try_module_get(stream
->transport
->owner
)) {
1013 printk(KERN_WARNING
"LTT : Can't lock transport module.\n");
1016 return lib_ring_buffer_open(inode
, file
, buf
);
1020 int lttng_metadata_ring_buffer_release(struct inode
*inode
, struct file
*file
)
1022 struct lttng_metadata_stream
*stream
= file
->private_data
;
1023 struct lib_ring_buffer
*buf
= stream
->priv
;
1025 kref_put(&stream
->metadata_cache
->refcount
, metadata_cache_destroy
);
1026 module_put(stream
->transport
->owner
);
1027 return lib_ring_buffer_release(inode
, file
, buf
);
1031 ssize_t
lttng_metadata_ring_buffer_splice_read(struct file
*in
, loff_t
*ppos
,
1032 struct pipe_inode_info
*pipe
, size_t len
,
1035 struct lttng_metadata_stream
*stream
= in
->private_data
;
1036 struct lib_ring_buffer
*buf
= stream
->priv
;
1038 return lib_ring_buffer_splice_read(in
, ppos
, pipe
, len
,
1043 int lttng_metadata_ring_buffer_mmap(struct file
*filp
,
1044 struct vm_area_struct
*vma
)
1046 struct lttng_metadata_stream
*stream
= filp
->private_data
;
1047 struct lib_ring_buffer
*buf
= stream
->priv
;
1049 return lib_ring_buffer_mmap(filp
, vma
, buf
);
1053 const struct file_operations lttng_metadata_ring_buffer_file_operations
= {
1054 .owner
= THIS_MODULE
,
1055 .open
= lttng_metadata_ring_buffer_open
,
1056 .release
= lttng_metadata_ring_buffer_release
,
1057 .poll
= lttng_metadata_ring_buffer_poll
,
1058 .splice_read
= lttng_metadata_ring_buffer_splice_read
,
1059 .mmap
= lttng_metadata_ring_buffer_mmap
,
1060 .unlocked_ioctl
= lttng_metadata_ring_buffer_ioctl
,
1061 .llseek
= vfs_lib_ring_buffer_no_llseek
,
1062 #ifdef CONFIG_COMPAT
1063 .compat_ioctl
= lttng_metadata_ring_buffer_compat_ioctl
,
1068 int lttng_abi_create_stream_fd(struct file
*channel_file
, void *stream_priv
,
1069 const struct file_operations
*fops
)
1072 struct file
*stream_file
;
1074 stream_fd
= lttng_get_unused_fd();
1075 if (stream_fd
< 0) {
1079 stream_file
= anon_inode_getfile("[lttng_stream]", fops
,
1080 stream_priv
, O_RDWR
);
1081 if (IS_ERR(stream_file
)) {
1082 ret
= PTR_ERR(stream_file
);
1086 * OPEN_FMODE, called within anon_inode_getfile/alloc_file, don't honor
1087 * FMODE_LSEEK, FMODE_PREAD nor FMODE_PWRITE. We need to read from this
1088 * file descriptor, so we set FMODE_PREAD here.
1090 stream_file
->f_mode
|= FMODE_PREAD
;
1091 fd_install(stream_fd
, stream_file
);
1093 * The stream holds a reference to the channel within the generic ring
1094 * buffer library, so no need to hold a refcount on the channel and
1095 * session files here.
1100 put_unused_fd(stream_fd
);
1106 int lttng_abi_open_stream(struct file
*channel_file
)
1108 struct lttng_channel
*channel
= channel_file
->private_data
;
1109 struct lib_ring_buffer
*buf
;
1113 buf
= channel
->ops
->buffer_read_open(channel
->chan
);
1118 ret
= lttng_abi_create_stream_fd(channel_file
, stream_priv
,
1119 <tng_stream_ring_buffer_file_operations
);
1126 channel
->ops
->buffer_read_close(buf
);
1131 int lttng_abi_open_metadata_stream(struct file
*channel_file
)
1133 struct lttng_channel
*channel
= channel_file
->private_data
;
1134 struct lttng_session
*session
= channel
->session
;
1135 struct lib_ring_buffer
*buf
;
1137 struct lttng_metadata_stream
*metadata_stream
;
1140 buf
= channel
->ops
->buffer_read_open(channel
->chan
);
1144 metadata_stream
= kzalloc(sizeof(struct lttng_metadata_stream
),
1146 if (!metadata_stream
) {
1150 metadata_stream
->metadata_cache
= session
->metadata_cache
;
1151 init_waitqueue_head(&metadata_stream
->read_wait
);
1152 metadata_stream
->priv
= buf
;
1153 stream_priv
= metadata_stream
;
1154 metadata_stream
->transport
= channel
->transport
;
1157 * Since life-time of metadata cache differs from that of
1158 * session, we need to keep our own reference on the transport.
1160 if (!try_module_get(metadata_stream
->transport
->owner
)) {
1161 printk(KERN_WARNING
"LTT : Can't lock transport module.\n");
1166 if (!lttng_kref_get(&session
->metadata_cache
->refcount
)) {
1171 ret
= lttng_abi_create_stream_fd(channel_file
, stream_priv
,
1172 <tng_metadata_ring_buffer_file_operations
);
1176 list_add(&metadata_stream
->list
,
1177 &session
->metadata_cache
->metadata_stream
);
1181 kref_put(&session
->metadata_cache
->refcount
, metadata_cache_destroy
);
1183 module_put(metadata_stream
->transport
->owner
);
1185 kfree(metadata_stream
);
1187 channel
->ops
->buffer_read_close(buf
);
1192 int lttng_abi_create_event(struct file
*channel_file
,
1193 struct lttng_kernel_event
*event_param
)
1195 struct lttng_channel
*channel
= channel_file
->private_data
;
1197 struct file
*event_file
;
1200 event_param
->name
[LTTNG_KERNEL_SYM_NAME_LEN
- 1] = '\0';
1201 switch (event_param
->instrumentation
) {
1202 case LTTNG_KERNEL_KRETPROBE
:
1203 event_param
->u
.kretprobe
.symbol_name
[LTTNG_KERNEL_SYM_NAME_LEN
- 1] = '\0';
1205 case LTTNG_KERNEL_KPROBE
:
1206 event_param
->u
.kprobe
.symbol_name
[LTTNG_KERNEL_SYM_NAME_LEN
- 1] = '\0';
1208 case LTTNG_KERNEL_FUNCTION
:
1209 event_param
->u
.ftrace
.symbol_name
[LTTNG_KERNEL_SYM_NAME_LEN
- 1] = '\0';
1214 event_fd
= lttng_get_unused_fd();
1219 event_file
= anon_inode_getfile("[lttng_event]",
1222 if (IS_ERR(event_file
)) {
1223 ret
= PTR_ERR(event_file
);
1226 /* The event holds a reference on the channel */
1227 if (!atomic_long_add_unless(&channel_file
->f_count
, 1, LONG_MAX
)) {
1229 goto refcount_error
;
1231 if (event_param
->instrumentation
== LTTNG_KERNEL_TRACEPOINT
1232 || event_param
->instrumentation
== LTTNG_KERNEL_SYSCALL
) {
1233 struct lttng_enabler
*enabler
;
1235 if (strutils_is_star_glob_pattern(event_param
->name
)) {
1237 * If the event name is a star globbing pattern,
1238 * we create the special star globbing enabler.
1240 enabler
= lttng_enabler_create(LTTNG_ENABLER_STAR_GLOB
,
1241 event_param
, channel
);
1243 enabler
= lttng_enabler_create(LTTNG_ENABLER_NAME
,
1244 event_param
, channel
);
1248 struct lttng_event
*event
;
1251 * We tolerate no failure path after event creation. It
1252 * will stay invariant for the rest of the session.
1254 event
= lttng_event_create(channel
, event_param
,
1256 event_param
->instrumentation
);
1257 WARN_ON_ONCE(!event
);
1258 if (IS_ERR(event
)) {
1259 ret
= PTR_ERR(event
);
1264 event_file
->private_data
= priv
;
1265 fd_install(event_fd
, event_file
);
1269 atomic_long_dec(&channel_file
->f_count
);
1273 put_unused_fd(event_fd
);
1279 * lttng_channel_ioctl - lttng syscall through ioctl
1285 * This ioctl implements lttng commands:
1286 * LTTNG_KERNEL_STREAM
1287 * Returns an event stream file descriptor or failure.
1288 * (typically, one event stream records events from one CPU)
1289 * LTTNG_KERNEL_EVENT
1290 * Returns an event file descriptor or failure.
1291 * LTTNG_KERNEL_CONTEXT
1292 * Prepend a context field to each event in the channel
1293 * LTTNG_KERNEL_ENABLE
1294 * Enable recording for events in this channel (weak enable)
1295 * LTTNG_KERNEL_DISABLE
1296 * Disable recording for events in this channel (strong disable)
1298 * Channel and event file descriptors also hold a reference on the session.
1301 long lttng_channel_ioctl(struct file
*file
, unsigned int cmd
, unsigned long arg
)
1303 struct lttng_channel
*channel
= file
->private_data
;
1306 case LTTNG_KERNEL_OLD_STREAM
:
1307 case LTTNG_KERNEL_STREAM
:
1308 return lttng_abi_open_stream(file
);
1309 case LTTNG_KERNEL_OLD_EVENT
:
1311 struct lttng_kernel_event
*uevent_param
;
1312 struct lttng_kernel_old_event
*old_uevent_param
;
1315 uevent_param
= kmalloc(sizeof(struct lttng_kernel_event
),
1317 if (!uevent_param
) {
1321 old_uevent_param
= kmalloc(
1322 sizeof(struct lttng_kernel_old_event
),
1324 if (!old_uevent_param
) {
1326 goto old_event_error_free_param
;
1328 if (copy_from_user(old_uevent_param
,
1329 (struct lttng_kernel_old_event __user
*) arg
,
1330 sizeof(struct lttng_kernel_old_event
))) {
1332 goto old_event_error_free_old_param
;
1335 memcpy(uevent_param
->name
, old_uevent_param
->name
,
1336 sizeof(uevent_param
->name
));
1337 uevent_param
->instrumentation
=
1338 old_uevent_param
->instrumentation
;
1340 switch (old_uevent_param
->instrumentation
) {
1341 case LTTNG_KERNEL_KPROBE
:
1342 uevent_param
->u
.kprobe
.addr
=
1343 old_uevent_param
->u
.kprobe
.addr
;
1344 uevent_param
->u
.kprobe
.offset
=
1345 old_uevent_param
->u
.kprobe
.offset
;
1346 memcpy(uevent_param
->u
.kprobe
.symbol_name
,
1347 old_uevent_param
->u
.kprobe
.symbol_name
,
1348 sizeof(uevent_param
->u
.kprobe
.symbol_name
));
1350 case LTTNG_KERNEL_KRETPROBE
:
1351 uevent_param
->u
.kretprobe
.addr
=
1352 old_uevent_param
->u
.kretprobe
.addr
;
1353 uevent_param
->u
.kretprobe
.offset
=
1354 old_uevent_param
->u
.kretprobe
.offset
;
1355 memcpy(uevent_param
->u
.kretprobe
.symbol_name
,
1356 old_uevent_param
->u
.kretprobe
.symbol_name
,
1357 sizeof(uevent_param
->u
.kretprobe
.symbol_name
));
1359 case LTTNG_KERNEL_FUNCTION
:
1360 memcpy(uevent_param
->u
.ftrace
.symbol_name
,
1361 old_uevent_param
->u
.ftrace
.symbol_name
,
1362 sizeof(uevent_param
->u
.ftrace
.symbol_name
));
1367 ret
= lttng_abi_create_event(file
, uevent_param
);
1369 old_event_error_free_old_param
:
1370 kfree(old_uevent_param
);
1371 old_event_error_free_param
:
1372 kfree(uevent_param
);
1376 case LTTNG_KERNEL_EVENT
:
1378 struct lttng_kernel_event uevent_param
;
1380 if (copy_from_user(&uevent_param
,
1381 (struct lttng_kernel_event __user
*) arg
,
1382 sizeof(uevent_param
)))
1384 return lttng_abi_create_event(file
, &uevent_param
);
1386 case LTTNG_KERNEL_OLD_CONTEXT
:
1388 struct lttng_kernel_context
*ucontext_param
;
1389 struct lttng_kernel_old_context
*old_ucontext_param
;
1392 ucontext_param
= kmalloc(sizeof(struct lttng_kernel_context
),
1394 if (!ucontext_param
) {
1398 old_ucontext_param
= kmalloc(sizeof(struct lttng_kernel_old_context
),
1400 if (!old_ucontext_param
) {
1402 goto old_ctx_error_free_param
;
1405 if (copy_from_user(old_ucontext_param
,
1406 (struct lttng_kernel_old_context __user
*) arg
,
1407 sizeof(struct lttng_kernel_old_context
))) {
1409 goto old_ctx_error_free_old_param
;
1411 ucontext_param
->ctx
= old_ucontext_param
->ctx
;
1412 memcpy(ucontext_param
->padding
, old_ucontext_param
->padding
,
1413 sizeof(ucontext_param
->padding
));
1414 /* only type that uses the union */
1415 if (old_ucontext_param
->ctx
== LTTNG_KERNEL_CONTEXT_PERF_COUNTER
) {
1416 ucontext_param
->u
.perf_counter
.type
=
1417 old_ucontext_param
->u
.perf_counter
.type
;
1418 ucontext_param
->u
.perf_counter
.config
=
1419 old_ucontext_param
->u
.perf_counter
.config
;
1420 memcpy(ucontext_param
->u
.perf_counter
.name
,
1421 old_ucontext_param
->u
.perf_counter
.name
,
1422 sizeof(ucontext_param
->u
.perf_counter
.name
));
1425 ret
= lttng_abi_add_context(file
,
1427 &channel
->ctx
, channel
->session
);
1429 old_ctx_error_free_old_param
:
1430 kfree(old_ucontext_param
);
1431 old_ctx_error_free_param
:
1432 kfree(ucontext_param
);
1436 case LTTNG_KERNEL_CONTEXT
:
1438 struct lttng_kernel_context ucontext_param
;
1440 if (copy_from_user(&ucontext_param
,
1441 (struct lttng_kernel_context __user
*) arg
,
1442 sizeof(ucontext_param
)))
1444 return lttng_abi_add_context(file
,
1446 &channel
->ctx
, channel
->session
);
1448 case LTTNG_KERNEL_OLD_ENABLE
:
1449 case LTTNG_KERNEL_ENABLE
:
1450 return lttng_channel_enable(channel
);
1451 case LTTNG_KERNEL_OLD_DISABLE
:
1452 case LTTNG_KERNEL_DISABLE
:
1453 return lttng_channel_disable(channel
);
1454 case LTTNG_KERNEL_SYSCALL_MASK
:
1455 return lttng_channel_syscall_mask(channel
,
1456 (struct lttng_kernel_syscall_mask __user
*) arg
);
1458 return -ENOIOCTLCMD
;
1463 * lttng_metadata_ioctl - lttng syscall through ioctl
1469 * This ioctl implements lttng commands:
1470 * LTTNG_KERNEL_STREAM
1471 * Returns an event stream file descriptor or failure.
1473 * Channel and event file descriptors also hold a reference on the session.
1476 long lttng_metadata_ioctl(struct file
*file
, unsigned int cmd
, unsigned long arg
)
1479 case LTTNG_KERNEL_OLD_STREAM
:
1480 case LTTNG_KERNEL_STREAM
:
1481 return lttng_abi_open_metadata_stream(file
);
1483 return -ENOIOCTLCMD
;
1488 * lttng_channel_poll - lttng stream addition/removal monitoring
1493 unsigned int lttng_channel_poll(struct file
*file
, poll_table
*wait
)
1495 struct lttng_channel
*channel
= file
->private_data
;
1496 unsigned int mask
= 0;
1498 if (file
->f_mode
& FMODE_READ
) {
1499 poll_wait_set_exclusive(wait
);
1500 poll_wait(file
, channel
->ops
->get_hp_wait_queue(channel
->chan
),
1503 if (channel
->ops
->is_disabled(channel
->chan
))
1505 if (channel
->ops
->is_finalized(channel
->chan
))
1507 if (channel
->ops
->buffer_has_read_closed_stream(channel
->chan
))
1508 return POLLIN
| POLLRDNORM
;
1516 int lttng_channel_release(struct inode
*inode
, struct file
*file
)
1518 struct lttng_channel
*channel
= file
->private_data
;
1521 fput(channel
->session
->file
);
1526 int lttng_metadata_channel_release(struct inode
*inode
, struct file
*file
)
1528 struct lttng_channel
*channel
= file
->private_data
;
1531 fput(channel
->session
->file
);
1532 lttng_metadata_channel_destroy(channel
);
1538 static const struct file_operations lttng_channel_fops
= {
1539 .owner
= THIS_MODULE
,
1540 .release
= lttng_channel_release
,
1541 .poll
= lttng_channel_poll
,
1542 .unlocked_ioctl
= lttng_channel_ioctl
,
1543 #ifdef CONFIG_COMPAT
1544 .compat_ioctl
= lttng_channel_ioctl
,
1548 static const struct file_operations lttng_metadata_fops
= {
1549 .owner
= THIS_MODULE
,
1550 .release
= lttng_metadata_channel_release
,
1551 .unlocked_ioctl
= lttng_metadata_ioctl
,
1552 #ifdef CONFIG_COMPAT
1553 .compat_ioctl
= lttng_metadata_ioctl
,
1558 * lttng_event_ioctl - lttng syscall through ioctl
1564 * This ioctl implements lttng commands:
1565 * LTTNG_KERNEL_CONTEXT
1566 * Prepend a context field to each record of this event
1567 * LTTNG_KERNEL_ENABLE
1568 * Enable recording for this event (weak enable)
1569 * LTTNG_KERNEL_DISABLE
1570 * Disable recording for this event (strong disable)
1573 long lttng_event_ioctl(struct file
*file
, unsigned int cmd
, unsigned long arg
)
1575 struct lttng_event
*event
;
1576 struct lttng_enabler
*enabler
;
1577 enum lttng_event_type
*evtype
= file
->private_data
;
1580 case LTTNG_KERNEL_OLD_CONTEXT
:
1582 /* Not implemented */
1585 case LTTNG_KERNEL_CONTEXT
:
1587 /* Not implemented */
1590 case LTTNG_KERNEL_OLD_ENABLE
:
1591 case LTTNG_KERNEL_ENABLE
:
1593 case LTTNG_TYPE_EVENT
:
1594 event
= file
->private_data
;
1595 return lttng_event_enable(event
);
1596 case LTTNG_TYPE_ENABLER
:
1597 enabler
= file
->private_data
;
1598 return lttng_enabler_enable(enabler
);
1603 case LTTNG_KERNEL_OLD_DISABLE
:
1604 case LTTNG_KERNEL_DISABLE
:
1606 case LTTNG_TYPE_EVENT
:
1607 event
= file
->private_data
;
1608 return lttng_event_disable(event
);
1609 case LTTNG_TYPE_ENABLER
:
1610 enabler
= file
->private_data
;
1611 return lttng_enabler_disable(enabler
);
1616 case LTTNG_KERNEL_FILTER
:
1618 case LTTNG_TYPE_EVENT
:
1620 case LTTNG_TYPE_ENABLER
:
1622 enabler
= file
->private_data
;
1623 return lttng_enabler_attach_bytecode(enabler
,
1624 (struct lttng_kernel_filter_bytecode __user
*) arg
);
1630 case LTTNG_KERNEL_ADD_CALLSITE
:
1632 case LTTNG_TYPE_EVENT
:
1633 event
= file
->private_data
;
1634 return lttng_event_add_callsite(event
,
1635 (struct lttng_kernel_event_callsite __user
*) arg
);
1636 case LTTNG_TYPE_ENABLER
:
1643 return -ENOIOCTLCMD
;
1648 int lttng_event_release(struct inode
*inode
, struct file
*file
)
1650 struct lttng_event
*event
;
1651 struct lttng_enabler
*enabler
;
1652 enum lttng_event_type
*evtype
= file
->private_data
;
1658 case LTTNG_TYPE_EVENT
:
1659 event
= file
->private_data
;
1661 fput(event
->chan
->file
);
1663 case LTTNG_TYPE_ENABLER
:
1664 enabler
= file
->private_data
;
1666 fput(enabler
->chan
->file
);
1676 /* TODO: filter control ioctl */
1677 static const struct file_operations lttng_event_fops
= {
1678 .owner
= THIS_MODULE
,
1679 .release
= lttng_event_release
,
1680 .unlocked_ioctl
= lttng_event_ioctl
,
1681 #ifdef CONFIG_COMPAT
1682 .compat_ioctl
= lttng_event_ioctl
,
1686 static int put_u64(uint64_t val
, unsigned long arg
)
1688 return put_user(val
, (uint64_t __user
*) arg
);
1691 static long lttng_stream_ring_buffer_ioctl(struct file
*filp
,
1692 unsigned int cmd
, unsigned long arg
)
1694 struct lib_ring_buffer
*buf
= filp
->private_data
;
1695 struct channel
*chan
= buf
->backend
.chan
;
1696 const struct lib_ring_buffer_config
*config
= &chan
->backend
.config
;
1697 const struct lttng_channel_ops
*ops
= chan
->backend
.priv_ops
;
1700 if (atomic_read(&chan
->record_disabled
))
1704 case LTTNG_RING_BUFFER_GET_TIMESTAMP_BEGIN
:
1708 ret
= ops
->timestamp_begin(config
, buf
, &ts
);
1711 return put_u64(ts
, arg
);
1713 case LTTNG_RING_BUFFER_GET_TIMESTAMP_END
:
1717 ret
= ops
->timestamp_end(config
, buf
, &ts
);
1720 return put_u64(ts
, arg
);
1722 case LTTNG_RING_BUFFER_GET_EVENTS_DISCARDED
:
1726 ret
= ops
->events_discarded(config
, buf
, &ed
);
1729 return put_u64(ed
, arg
);
1731 case LTTNG_RING_BUFFER_GET_CONTENT_SIZE
:
1735 ret
= ops
->content_size(config
, buf
, &cs
);
1738 return put_u64(cs
, arg
);
1740 case LTTNG_RING_BUFFER_GET_PACKET_SIZE
:
1744 ret
= ops
->packet_size(config
, buf
, &ps
);
1747 return put_u64(ps
, arg
);
1749 case LTTNG_RING_BUFFER_GET_STREAM_ID
:
1753 ret
= ops
->stream_id(config
, buf
, &si
);
1756 return put_u64(si
, arg
);
1758 case LTTNG_RING_BUFFER_GET_CURRENT_TIMESTAMP
:
1762 ret
= ops
->current_timestamp(config
, buf
, &ts
);
1765 return put_u64(ts
, arg
);
1767 case LTTNG_RING_BUFFER_GET_SEQ_NUM
:
1771 ret
= ops
->sequence_number(config
, buf
, &seq
);
1774 return put_u64(seq
, arg
);
1776 case LTTNG_RING_BUFFER_INSTANCE_ID
:
1780 ret
= ops
->instance_id(config
, buf
, &id
);
1783 return put_u64(id
, arg
);
1786 return lib_ring_buffer_file_operations
.unlocked_ioctl(filp
,
1794 #ifdef CONFIG_COMPAT
1795 static long lttng_stream_ring_buffer_compat_ioctl(struct file
*filp
,
1796 unsigned int cmd
, unsigned long arg
)
1798 struct lib_ring_buffer
*buf
= filp
->private_data
;
1799 struct channel
*chan
= buf
->backend
.chan
;
1800 const struct lib_ring_buffer_config
*config
= &chan
->backend
.config
;
1801 const struct lttng_channel_ops
*ops
= chan
->backend
.priv_ops
;
1804 if (atomic_read(&chan
->record_disabled
))
1808 case LTTNG_RING_BUFFER_COMPAT_GET_TIMESTAMP_BEGIN
:
1812 ret
= ops
->timestamp_begin(config
, buf
, &ts
);
1815 return put_u64(ts
, arg
);
1817 case LTTNG_RING_BUFFER_COMPAT_GET_TIMESTAMP_END
:
1821 ret
= ops
->timestamp_end(config
, buf
, &ts
);
1824 return put_u64(ts
, arg
);
1826 case LTTNG_RING_BUFFER_COMPAT_GET_EVENTS_DISCARDED
:
1830 ret
= ops
->events_discarded(config
, buf
, &ed
);
1833 return put_u64(ed
, arg
);
1835 case LTTNG_RING_BUFFER_COMPAT_GET_CONTENT_SIZE
:
1839 ret
= ops
->content_size(config
, buf
, &cs
);
1842 return put_u64(cs
, arg
);
1844 case LTTNG_RING_BUFFER_COMPAT_GET_PACKET_SIZE
:
1848 ret
= ops
->packet_size(config
, buf
, &ps
);
1851 return put_u64(ps
, arg
);
1853 case LTTNG_RING_BUFFER_COMPAT_GET_STREAM_ID
:
1857 ret
= ops
->stream_id(config
, buf
, &si
);
1860 return put_u64(si
, arg
);
1862 case LTTNG_RING_BUFFER_GET_CURRENT_TIMESTAMP
:
1866 ret
= ops
->current_timestamp(config
, buf
, &ts
);
1869 return put_u64(ts
, arg
);
1871 case LTTNG_RING_BUFFER_COMPAT_GET_SEQ_NUM
:
1875 ret
= ops
->sequence_number(config
, buf
, &seq
);
1878 return put_u64(seq
, arg
);
1880 case LTTNG_RING_BUFFER_COMPAT_INSTANCE_ID
:
1884 ret
= ops
->instance_id(config
, buf
, &id
);
1887 return put_u64(id
, arg
);
1890 return lib_ring_buffer_file_operations
.compat_ioctl(filp
,
1897 #endif /* CONFIG_COMPAT */
1899 static void lttng_stream_override_ring_buffer_fops(void)
1901 lttng_stream_ring_buffer_file_operations
.owner
= THIS_MODULE
;
1902 lttng_stream_ring_buffer_file_operations
.open
=
1903 lib_ring_buffer_file_operations
.open
;
1904 lttng_stream_ring_buffer_file_operations
.release
=
1905 lib_ring_buffer_file_operations
.release
;
1906 lttng_stream_ring_buffer_file_operations
.poll
=
1907 lib_ring_buffer_file_operations
.poll
;
1908 lttng_stream_ring_buffer_file_operations
.splice_read
=
1909 lib_ring_buffer_file_operations
.splice_read
;
1910 lttng_stream_ring_buffer_file_operations
.mmap
=
1911 lib_ring_buffer_file_operations
.mmap
;
1912 lttng_stream_ring_buffer_file_operations
.unlocked_ioctl
=
1913 lttng_stream_ring_buffer_ioctl
;
1914 lttng_stream_ring_buffer_file_operations
.llseek
=
1915 lib_ring_buffer_file_operations
.llseek
;
1916 #ifdef CONFIG_COMPAT
1917 lttng_stream_ring_buffer_file_operations
.compat_ioctl
=
1918 lttng_stream_ring_buffer_compat_ioctl
;
1922 int __init
lttng_abi_init(void)
1926 wrapper_vmalloc_sync_all();
1929 ret
= lttng_tp_mempool_init();
1934 lttng_proc_dentry
= proc_create_data("lttng", S_IRUSR
| S_IWUSR
, NULL
,
1937 if (!lttng_proc_dentry
) {
1938 printk(KERN_ERR
"Error creating LTTng control file\n");
1942 lttng_stream_override_ring_buffer_fops();
1946 lttng_tp_mempool_destroy();
1947 lttng_clock_unref();
1951 /* No __exit annotation because used by init error path too. */
1952 void lttng_abi_exit(void)
1954 lttng_tp_mempool_destroy();
1955 lttng_clock_unref();
1956 if (lttng_proc_dentry
)
1957 remove_proc_entry("lttng", NULL
);