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_mappings() */
34 #include <wrapper/ringbuffer/vfs.h>
35 #include <wrapper/ringbuffer/backend.h>
36 #include <wrapper/ringbuffer/frontend.h>
37 #include <wrapper/poll.h>
38 #include <wrapper/file.h>
39 #include <wrapper/kref.h>
40 #include <lttng-string-utils.h>
41 #include <lttng-abi.h>
42 #include <lttng-abi-old.h>
43 #include <lttng-events.h>
44 #include <lttng-tracer.h>
45 #include <lttng-tp-mempool.h>
46 #include <lib/ringbuffer/frontend_types.h>
49 * This is LTTng's own personal way to create a system call as an external
50 * module. We use ioctl() on /proc/lttng.
53 static struct proc_dir_entry
*lttng_proc_dentry
;
55 #if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(5,6,0))
56 static const struct proc_ops lttng_proc_ops
;
58 static const struct file_operations lttng_proc_ops
;
61 static const struct file_operations lttng_session_fops
;
62 static const struct file_operations lttng_channel_fops
;
63 static const struct file_operations lttng_metadata_fops
;
64 static const struct file_operations lttng_event_fops
;
65 static struct file_operations lttng_stream_ring_buffer_file_operations
;
67 static int put_u64(uint64_t val
, unsigned long arg
);
68 static int put_u32(uint32_t val
, unsigned long arg
);
71 * Teardown management: opened file descriptors keep a refcount on the module,
72 * so it can only exit when all file descriptors are closed.
76 int lttng_abi_create_session(void)
78 struct lttng_session
*session
;
79 struct file
*session_file
;
82 session
= lttng_session_create();
85 session_fd
= lttng_get_unused_fd();
90 session_file
= anon_inode_getfile("[lttng_session]",
93 if (IS_ERR(session_file
)) {
94 ret
= PTR_ERR(session_file
);
97 session
->file
= session_file
;
98 fd_install(session_fd
, session_file
);
102 put_unused_fd(session_fd
);
104 lttng_session_destroy(session
);
109 int lttng_abi_tracepoint_list(void)
111 struct file
*tracepoint_list_file
;
114 file_fd
= lttng_get_unused_fd();
120 tracepoint_list_file
= anon_inode_getfile("[lttng_tracepoint_list]",
121 <tng_tracepoint_list_fops
,
123 if (IS_ERR(tracepoint_list_file
)) {
124 ret
= PTR_ERR(tracepoint_list_file
);
127 ret
= lttng_tracepoint_list_fops
.open(NULL
, tracepoint_list_file
);
130 fd_install(file_fd
, tracepoint_list_file
);
134 fput(tracepoint_list_file
);
136 put_unused_fd(file_fd
);
141 #ifndef CONFIG_HAVE_SYSCALL_TRACEPOINTS
143 int lttng_abi_syscall_list(void)
149 int lttng_abi_syscall_list(void)
151 struct file
*syscall_list_file
;
154 file_fd
= lttng_get_unused_fd();
160 syscall_list_file
= anon_inode_getfile("[lttng_syscall_list]",
161 <tng_syscall_list_fops
,
163 if (IS_ERR(syscall_list_file
)) {
164 ret
= PTR_ERR(syscall_list_file
);
167 ret
= lttng_syscall_list_fops
.open(NULL
, syscall_list_file
);
170 fd_install(file_fd
, syscall_list_file
);
174 fput(syscall_list_file
);
176 put_unused_fd(file_fd
);
183 void lttng_abi_tracer_version(struct lttng_kernel_tracer_version
*v
)
185 v
->major
= LTTNG_MODULES_MAJOR_VERSION
;
186 v
->minor
= LTTNG_MODULES_MINOR_VERSION
;
187 v
->patchlevel
= LTTNG_MODULES_PATCHLEVEL_VERSION
;
191 void lttng_abi_tracer_abi_version(struct lttng_kernel_tracer_abi_version
*v
)
193 v
->major
= LTTNG_MODULES_ABI_MAJOR_VERSION
;
194 v
->minor
= LTTNG_MODULES_ABI_MINOR_VERSION
;
198 long lttng_abi_add_context(struct file
*file
,
199 struct lttng_kernel_context
*context_param
,
200 struct lttng_ctx
**ctx
, struct lttng_session
*session
)
203 if (session
->been_active
)
206 switch (context_param
->ctx
) {
207 case LTTNG_KERNEL_CONTEXT_PID
:
208 return lttng_add_pid_to_ctx(ctx
);
209 case LTTNG_KERNEL_CONTEXT_PRIO
:
210 return lttng_add_prio_to_ctx(ctx
);
211 case LTTNG_KERNEL_CONTEXT_NICE
:
212 return lttng_add_nice_to_ctx(ctx
);
213 case LTTNG_KERNEL_CONTEXT_VPID
:
214 return lttng_add_vpid_to_ctx(ctx
);
215 case LTTNG_KERNEL_CONTEXT_TID
:
216 return lttng_add_tid_to_ctx(ctx
);
217 case LTTNG_KERNEL_CONTEXT_VTID
:
218 return lttng_add_vtid_to_ctx(ctx
);
219 case LTTNG_KERNEL_CONTEXT_PPID
:
220 return lttng_add_ppid_to_ctx(ctx
);
221 case LTTNG_KERNEL_CONTEXT_VPPID
:
222 return lttng_add_vppid_to_ctx(ctx
);
223 case LTTNG_KERNEL_CONTEXT_PERF_COUNTER
:
224 context_param
->u
.perf_counter
.name
[LTTNG_KERNEL_SYM_NAME_LEN
- 1] = '\0';
225 return lttng_add_perf_counter_to_ctx(context_param
->u
.perf_counter
.type
,
226 context_param
->u
.perf_counter
.config
,
227 context_param
->u
.perf_counter
.name
,
229 case LTTNG_KERNEL_CONTEXT_PROCNAME
:
230 return lttng_add_procname_to_ctx(ctx
);
231 case LTTNG_KERNEL_CONTEXT_HOSTNAME
:
232 return lttng_add_hostname_to_ctx(ctx
);
233 case LTTNG_KERNEL_CONTEXT_CPU_ID
:
234 return lttng_add_cpu_id_to_ctx(ctx
);
235 case LTTNG_KERNEL_CONTEXT_INTERRUPTIBLE
:
236 return lttng_add_interruptible_to_ctx(ctx
);
237 case LTTNG_KERNEL_CONTEXT_NEED_RESCHEDULE
:
238 return lttng_add_need_reschedule_to_ctx(ctx
);
239 case LTTNG_KERNEL_CONTEXT_PREEMPTIBLE
:
240 return lttng_add_preemptible_to_ctx(ctx
);
241 case LTTNG_KERNEL_CONTEXT_MIGRATABLE
:
242 return lttng_add_migratable_to_ctx(ctx
);
243 case LTTNG_KERNEL_CONTEXT_CALLSTACK_KERNEL
:
244 case LTTNG_KERNEL_CONTEXT_CALLSTACK_USER
:
245 return lttng_add_callstack_to_ctx(ctx
, context_param
->ctx
);
252 * lttng_ioctl - lttng syscall through ioctl
258 * This ioctl implements lttng commands:
259 * LTTNG_KERNEL_SESSION
260 * Returns a LTTng trace session file descriptor
261 * LTTNG_KERNEL_TRACER_VERSION
262 * Returns the LTTng kernel tracer version
263 * LTTNG_KERNEL_TRACEPOINT_LIST
264 * Returns a file descriptor listing available tracepoints
265 * LTTNG_KERNEL_WAIT_QUIESCENT
266 * Returns after all previously running probes have completed
267 * LTTNG_KERNEL_TRACER_ABI_VERSION
268 * Returns the LTTng kernel tracer ABI version
270 * The returned session will be deleted when its file descriptor is closed.
273 long lttng_ioctl(struct file
*file
, unsigned int cmd
, unsigned long arg
)
276 case LTTNG_KERNEL_OLD_SESSION
:
277 case LTTNG_KERNEL_SESSION
:
278 return lttng_abi_create_session();
279 case LTTNG_KERNEL_OLD_TRACER_VERSION
:
281 struct lttng_kernel_tracer_version v
;
282 struct lttng_kernel_old_tracer_version oldv
;
283 struct lttng_kernel_old_tracer_version
*uversion
=
284 (struct lttng_kernel_old_tracer_version __user
*) arg
;
286 lttng_abi_tracer_version(&v
);
287 oldv
.major
= v
.major
;
288 oldv
.minor
= v
.minor
;
289 oldv
.patchlevel
= v
.patchlevel
;
291 if (copy_to_user(uversion
, &oldv
, sizeof(oldv
)))
295 case LTTNG_KERNEL_TRACER_VERSION
:
297 struct lttng_kernel_tracer_version version
;
298 struct lttng_kernel_tracer_version
*uversion
=
299 (struct lttng_kernel_tracer_version __user
*) arg
;
301 lttng_abi_tracer_version(&version
);
303 if (copy_to_user(uversion
, &version
, sizeof(version
)))
307 case LTTNG_KERNEL_TRACER_ABI_VERSION
:
309 struct lttng_kernel_tracer_abi_version version
;
310 struct lttng_kernel_tracer_abi_version
*uversion
=
311 (struct lttng_kernel_tracer_abi_version __user
*) arg
;
313 lttng_abi_tracer_abi_version(&version
);
315 if (copy_to_user(uversion
, &version
, sizeof(version
)))
319 case LTTNG_KERNEL_OLD_TRACEPOINT_LIST
:
320 case LTTNG_KERNEL_TRACEPOINT_LIST
:
321 return lttng_abi_tracepoint_list();
322 case LTTNG_KERNEL_SYSCALL_LIST
:
323 return lttng_abi_syscall_list();
324 case LTTNG_KERNEL_OLD_WAIT_QUIESCENT
:
325 case LTTNG_KERNEL_WAIT_QUIESCENT
:
328 case LTTNG_KERNEL_OLD_CALIBRATE
:
330 struct lttng_kernel_old_calibrate __user
*ucalibrate
=
331 (struct lttng_kernel_old_calibrate __user
*) arg
;
332 struct lttng_kernel_old_calibrate old_calibrate
;
333 struct lttng_kernel_calibrate calibrate
;
336 if (copy_from_user(&old_calibrate
, ucalibrate
, sizeof(old_calibrate
)))
338 calibrate
.type
= old_calibrate
.type
;
339 ret
= lttng_calibrate(&calibrate
);
340 if (copy_to_user(ucalibrate
, &old_calibrate
, sizeof(old_calibrate
)))
344 case LTTNG_KERNEL_CALIBRATE
:
346 struct lttng_kernel_calibrate __user
*ucalibrate
=
347 (struct lttng_kernel_calibrate __user
*) arg
;
348 struct lttng_kernel_calibrate calibrate
;
351 if (copy_from_user(&calibrate
, ucalibrate
, sizeof(calibrate
)))
353 ret
= lttng_calibrate(&calibrate
);
354 if (copy_to_user(ucalibrate
, &calibrate
, sizeof(calibrate
)))
363 #if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(5,6,0))
364 static const struct proc_ops lttng_proc_ops
= {
365 .proc_ioctl
= lttng_ioctl
,
367 .proc_compat_ioctl
= lttng_ioctl
,
368 #endif /* CONFIG_COMPAT */
371 static const struct file_operations lttng_proc_ops
= {
372 .owner
= THIS_MODULE
,
373 .unlocked_ioctl
= lttng_ioctl
,
375 .compat_ioctl
= lttng_ioctl
,
376 #endif /* CONFIG_COMPAT */
381 int lttng_abi_create_channel(struct file
*session_file
,
382 struct lttng_kernel_channel
*chan_param
,
383 enum channel_type channel_type
)
385 struct lttng_session
*session
= session_file
->private_data
;
386 const struct file_operations
*fops
= NULL
;
387 const char *transport_name
;
388 struct lttng_channel
*chan
;
389 struct file
*chan_file
;
393 chan_fd
= lttng_get_unused_fd();
398 switch (channel_type
) {
399 case PER_CPU_CHANNEL
:
400 fops
= <tng_channel_fops
;
402 case METADATA_CHANNEL
:
403 fops
= <tng_metadata_fops
;
407 chan_file
= anon_inode_getfile("[lttng_channel]",
410 if (IS_ERR(chan_file
)) {
411 ret
= PTR_ERR(chan_file
);
414 switch (channel_type
) {
415 case PER_CPU_CHANNEL
:
416 if (chan_param
->output
== LTTNG_KERNEL_SPLICE
) {
417 transport_name
= chan_param
->overwrite
?
418 "relay-overwrite" : "relay-discard";
419 } else if (chan_param
->output
== LTTNG_KERNEL_MMAP
) {
420 transport_name
= chan_param
->overwrite
?
421 "relay-overwrite-mmap" : "relay-discard-mmap";
426 case METADATA_CHANNEL
:
427 if (chan_param
->output
== LTTNG_KERNEL_SPLICE
)
428 transport_name
= "relay-metadata";
429 else if (chan_param
->output
== LTTNG_KERNEL_MMAP
)
430 transport_name
= "relay-metadata-mmap";
435 transport_name
= "<unknown>";
438 if (!atomic_long_add_unless(&session_file
->f_count
, 1, LONG_MAX
)) {
443 * We tolerate no failure path after channel creation. It will stay
444 * invariant for the rest of the session.
446 chan
= lttng_channel_create(session
, transport_name
, NULL
,
447 chan_param
->subbuf_size
,
448 chan_param
->num_subbuf
,
449 chan_param
->switch_timer_interval
,
450 chan_param
->read_timer_interval
,
456 chan
->file
= chan_file
;
457 chan_file
->private_data
= chan
;
458 fd_install(chan_fd
, chan_file
);
463 atomic_long_dec(&session_file
->f_count
);
467 put_unused_fd(chan_fd
);
473 int lttng_abi_session_set_name(struct lttng_session
*session
,
474 struct lttng_kernel_session_name
*name
)
478 len
= strnlen(name
->name
, LTTNG_KERNEL_SESSION_NAME_LEN
);
480 if (len
== LTTNG_KERNEL_SESSION_NAME_LEN
) {
481 /* Name is too long/malformed */
485 strcpy(session
->name
, name
->name
);
490 int lttng_abi_session_set_creation_time(struct lttng_session
*session
,
491 struct lttng_kernel_session_creation_time
*time
)
495 len
= strnlen(time
->iso8601
, LTTNG_KERNEL_SESSION_CREATION_TIME_ISO8601_LEN
);
497 if (len
== LTTNG_KERNEL_SESSION_CREATION_TIME_ISO8601_LEN
) {
498 /* Time is too long/malformed */
502 strcpy(session
->creation_time
, time
->iso8601
);
507 * lttng_session_ioctl - lttng session fd ioctl
513 * This ioctl implements lttng commands:
514 * LTTNG_KERNEL_CHANNEL
515 * Returns a LTTng channel file descriptor
516 * LTTNG_KERNEL_ENABLE
517 * Enables tracing for a session (weak enable)
518 * LTTNG_KERNEL_DISABLE
519 * Disables tracing for a session (strong disable)
520 * LTTNG_KERNEL_METADATA
521 * Returns a LTTng metadata file descriptor
522 * LTTNG_KERNEL_SESSION_TRACK_PID
523 * Add PID to session tracker
524 * LTTNG_KERNEL_SESSION_UNTRACK_PID
525 * Remove PID from session tracker
527 * The returned channel will be deleted when its file descriptor is closed.
530 long lttng_session_ioctl(struct file
*file
, unsigned int cmd
, unsigned long arg
)
532 struct lttng_session
*session
= file
->private_data
;
533 struct lttng_kernel_channel chan_param
;
534 struct lttng_kernel_old_channel old_chan_param
;
537 case LTTNG_KERNEL_OLD_CHANNEL
:
539 if (copy_from_user(&old_chan_param
,
540 (struct lttng_kernel_old_channel __user
*) arg
,
541 sizeof(struct lttng_kernel_old_channel
)))
543 chan_param
.overwrite
= old_chan_param
.overwrite
;
544 chan_param
.subbuf_size
= old_chan_param
.subbuf_size
;
545 chan_param
.num_subbuf
= old_chan_param
.num_subbuf
;
546 chan_param
.switch_timer_interval
= old_chan_param
.switch_timer_interval
;
547 chan_param
.read_timer_interval
= old_chan_param
.read_timer_interval
;
548 chan_param
.output
= old_chan_param
.output
;
550 return lttng_abi_create_channel(file
, &chan_param
,
553 case LTTNG_KERNEL_CHANNEL
:
555 if (copy_from_user(&chan_param
,
556 (struct lttng_kernel_channel __user
*) arg
,
557 sizeof(struct lttng_kernel_channel
)))
559 return lttng_abi_create_channel(file
, &chan_param
,
562 case LTTNG_KERNEL_OLD_SESSION_START
:
563 case LTTNG_KERNEL_OLD_ENABLE
:
564 case LTTNG_KERNEL_SESSION_START
:
565 case LTTNG_KERNEL_ENABLE
:
566 return lttng_session_enable(session
);
567 case LTTNG_KERNEL_OLD_SESSION_STOP
:
568 case LTTNG_KERNEL_OLD_DISABLE
:
569 case LTTNG_KERNEL_SESSION_STOP
:
570 case LTTNG_KERNEL_DISABLE
:
571 return lttng_session_disable(session
);
572 case LTTNG_KERNEL_OLD_METADATA
:
574 if (copy_from_user(&old_chan_param
,
575 (struct lttng_kernel_old_channel __user
*) arg
,
576 sizeof(struct lttng_kernel_old_channel
)))
578 chan_param
.overwrite
= old_chan_param
.overwrite
;
579 chan_param
.subbuf_size
= old_chan_param
.subbuf_size
;
580 chan_param
.num_subbuf
= old_chan_param
.num_subbuf
;
581 chan_param
.switch_timer_interval
= old_chan_param
.switch_timer_interval
;
582 chan_param
.read_timer_interval
= old_chan_param
.read_timer_interval
;
583 chan_param
.output
= old_chan_param
.output
;
585 return lttng_abi_create_channel(file
, &chan_param
,
588 case LTTNG_KERNEL_METADATA
:
590 if (copy_from_user(&chan_param
,
591 (struct lttng_kernel_channel __user
*) arg
,
592 sizeof(struct lttng_kernel_channel
)))
594 return lttng_abi_create_channel(file
, &chan_param
,
597 case LTTNG_KERNEL_SESSION_TRACK_PID
:
598 return lttng_session_track_pid(session
, (int) arg
);
599 case LTTNG_KERNEL_SESSION_UNTRACK_PID
:
600 return lttng_session_untrack_pid(session
, (int) arg
);
601 case LTTNG_KERNEL_SESSION_LIST_TRACKER_PIDS
:
602 return lttng_session_list_tracker_pids(session
);
603 case LTTNG_KERNEL_SESSION_METADATA_REGEN
:
604 return lttng_session_metadata_regenerate(session
);
605 case LTTNG_KERNEL_SESSION_STATEDUMP
:
606 return lttng_session_statedump(session
);
607 case LTTNG_KERNEL_SESSION_SET_NAME
:
609 struct lttng_kernel_session_name name
;
611 if (copy_from_user(&name
,
612 (struct lttng_kernel_session_name __user
*) arg
,
613 sizeof(struct lttng_kernel_session_name
)))
615 return lttng_abi_session_set_name(session
, &name
);
617 case LTTNG_KERNEL_SESSION_SET_CREATION_TIME
:
619 struct lttng_kernel_session_creation_time time
;
621 if (copy_from_user(&time
,
622 (struct lttng_kernel_session_creation_time __user
*) arg
,
623 sizeof(struct lttng_kernel_session_creation_time
)))
625 return lttng_abi_session_set_creation_time(session
, &time
);
633 * Called when the last file reference is dropped.
635 * Big fat note: channels and events are invariant for the whole session after
636 * their creation. So this session destruction also destroys all channel and
637 * event structures specific to this session (they are not destroyed when their
638 * individual file is released).
641 int lttng_session_release(struct inode
*inode
, struct file
*file
)
643 struct lttng_session
*session
= file
->private_data
;
646 lttng_session_destroy(session
);
650 static const struct file_operations lttng_session_fops
= {
651 .owner
= THIS_MODULE
,
652 .release
= lttng_session_release
,
653 .unlocked_ioctl
= lttng_session_ioctl
,
655 .compat_ioctl
= lttng_session_ioctl
,
660 * lttng_metadata_ring_buffer_poll - LTTng ring buffer poll file operation
664 * Handles the poll operations for the metadata channels.
667 unsigned int lttng_metadata_ring_buffer_poll(struct file
*filp
,
670 struct lttng_metadata_stream
*stream
= filp
->private_data
;
671 struct lib_ring_buffer
*buf
= stream
->priv
;
673 unsigned int mask
= 0;
675 if (filp
->f_mode
& FMODE_READ
) {
676 poll_wait_set_exclusive(wait
);
677 poll_wait(filp
, &stream
->read_wait
, wait
);
679 finalized
= stream
->finalized
;
682 * lib_ring_buffer_is_finalized() contains a smp_rmb()
683 * ordering finalized load before offsets loads.
685 WARN_ON(atomic_long_read(&buf
->active_readers
) != 1);
690 mutex_lock(&stream
->metadata_cache
->lock
);
691 if (stream
->metadata_cache
->metadata_written
>
692 stream
->metadata_out
)
694 mutex_unlock(&stream
->metadata_cache
->lock
);
701 void lttng_metadata_ring_buffer_ioctl_put_next_subbuf(struct file
*filp
,
702 unsigned int cmd
, unsigned long arg
)
704 struct lttng_metadata_stream
*stream
= filp
->private_data
;
706 stream
->metadata_out
= stream
->metadata_in
;
710 * Reset the counter of how much metadata has been consumed to 0. That way,
711 * the consumer receives the content of the metadata cache unchanged. This is
712 * different from the metadata_regenerate where the offset from epoch is
713 * resampled, here we want the exact same content as the last time the metadata
714 * was generated. This command is only possible if all the metadata written
715 * in the cache has been output to the metadata stream to avoid corrupting the
718 * Return 0 on success, a negative value on error.
721 int lttng_metadata_cache_dump(struct lttng_metadata_stream
*stream
)
724 struct lttng_metadata_cache
*cache
= stream
->metadata_cache
;
726 mutex_lock(&cache
->lock
);
727 if (stream
->metadata_out
!= cache
->metadata_written
) {
731 stream
->metadata_out
= 0;
732 stream
->metadata_in
= 0;
733 wake_up_interruptible(&stream
->read_wait
);
737 mutex_unlock(&cache
->lock
);
742 long lttng_metadata_ring_buffer_ioctl(struct file
*filp
,
743 unsigned int cmd
, unsigned long arg
)
746 struct lttng_metadata_stream
*stream
= filp
->private_data
;
747 struct lib_ring_buffer
*buf
= stream
->priv
;
751 if (cmd
== RING_BUFFER_GET_NEXT_SUBBUF_METADATA_CHECK
)
752 rb_cmd
= RING_BUFFER_GET_NEXT_SUBBUF
;
757 case RING_BUFFER_GET_NEXT_SUBBUF
:
759 struct lttng_metadata_stream
*stream
= filp
->private_data
;
760 struct lib_ring_buffer
*buf
= stream
->priv
;
761 struct channel
*chan
= buf
->backend
.chan
;
763 ret
= lttng_metadata_output_channel(stream
, chan
, NULL
);
765 lib_ring_buffer_switch_slow(buf
, SWITCH_ACTIVE
);
771 case RING_BUFFER_GET_SUBBUF
:
774 * Random access is not allowed for metadata channel.
778 case RING_BUFFER_FLUSH_EMPTY
: /* Fall-through. */
779 case RING_BUFFER_FLUSH
:
781 struct lttng_metadata_stream
*stream
= filp
->private_data
;
782 struct lib_ring_buffer
*buf
= stream
->priv
;
783 struct channel
*chan
= buf
->backend
.chan
;
786 * Before doing the actual ring buffer flush, write up to one
787 * packet of metadata in the ring buffer.
789 ret
= lttng_metadata_output_channel(stream
, chan
, NULL
);
794 case RING_BUFFER_GET_METADATA_VERSION
:
796 struct lttng_metadata_stream
*stream
= filp
->private_data
;
798 return put_u64(stream
->version
, arg
);
800 case RING_BUFFER_METADATA_CACHE_DUMP
:
802 struct lttng_metadata_stream
*stream
= filp
->private_data
;
804 return lttng_metadata_cache_dump(stream
);
806 case RING_BUFFER_GET_NEXT_SUBBUF_METADATA_CHECK
:
808 struct lttng_metadata_stream
*stream
= filp
->private_data
;
809 struct lib_ring_buffer
*buf
= stream
->priv
;
810 struct channel
*chan
= buf
->backend
.chan
;
812 ret
= lttng_metadata_output_channel(stream
, chan
, &coherent
);
814 lib_ring_buffer_switch_slow(buf
, SWITCH_ACTIVE
);
816 } else if (ret
< 0) {
824 /* PUT_SUBBUF is the one from lib ring buffer, unmodified. */
826 /* Performing lib ring buffer ioctl after our own. */
827 ret
= lib_ring_buffer_ioctl(filp
, rb_cmd
, arg
, buf
);
832 case RING_BUFFER_PUT_NEXT_SUBBUF
:
834 lttng_metadata_ring_buffer_ioctl_put_next_subbuf(filp
,
838 case RING_BUFFER_GET_NEXT_SUBBUF_METADATA_CHECK
:
840 return put_u32(coherent
, arg
);
851 long lttng_metadata_ring_buffer_compat_ioctl(struct file
*filp
,
852 unsigned int cmd
, unsigned long arg
)
855 struct lttng_metadata_stream
*stream
= filp
->private_data
;
856 struct lib_ring_buffer
*buf
= stream
->priv
;
860 if (cmd
== RING_BUFFER_GET_NEXT_SUBBUF_METADATA_CHECK
)
861 rb_cmd
= RING_BUFFER_GET_NEXT_SUBBUF
;
866 case RING_BUFFER_GET_NEXT_SUBBUF
:
868 struct lttng_metadata_stream
*stream
= filp
->private_data
;
869 struct lib_ring_buffer
*buf
= stream
->priv
;
870 struct channel
*chan
= buf
->backend
.chan
;
872 ret
= lttng_metadata_output_channel(stream
, chan
, NULL
);
874 lib_ring_buffer_switch_slow(buf
, SWITCH_ACTIVE
);
880 case RING_BUFFER_GET_SUBBUF
:
883 * Random access is not allowed for metadata channel.
887 case RING_BUFFER_FLUSH_EMPTY
: /* Fall-through. */
888 case RING_BUFFER_FLUSH
:
890 struct lttng_metadata_stream
*stream
= filp
->private_data
;
891 struct lib_ring_buffer
*buf
= stream
->priv
;
892 struct channel
*chan
= buf
->backend
.chan
;
895 * Before doing the actual ring buffer flush, write up to one
896 * packet of metadata in the ring buffer.
898 ret
= lttng_metadata_output_channel(stream
, chan
, NULL
);
903 case RING_BUFFER_GET_METADATA_VERSION
:
905 struct lttng_metadata_stream
*stream
= filp
->private_data
;
907 return put_u64(stream
->version
, arg
);
909 case RING_BUFFER_METADATA_CACHE_DUMP
:
911 struct lttng_metadata_stream
*stream
= filp
->private_data
;
913 return lttng_metadata_cache_dump(stream
);
915 case RING_BUFFER_GET_NEXT_SUBBUF_METADATA_CHECK
:
917 struct lttng_metadata_stream
*stream
= filp
->private_data
;
918 struct lib_ring_buffer
*buf
= stream
->priv
;
919 struct channel
*chan
= buf
->backend
.chan
;
921 ret
= lttng_metadata_output_channel(stream
, chan
, &coherent
);
923 lib_ring_buffer_switch_slow(buf
, SWITCH_ACTIVE
);
925 } else if (ret
< 0) {
933 /* PUT_SUBBUF is the one from lib ring buffer, unmodified. */
935 /* Performing lib ring buffer ioctl after our own. */
936 ret
= lib_ring_buffer_compat_ioctl(filp
, rb_cmd
, arg
, buf
);
941 case RING_BUFFER_PUT_NEXT_SUBBUF
:
943 lttng_metadata_ring_buffer_ioctl_put_next_subbuf(filp
,
947 case RING_BUFFER_GET_NEXT_SUBBUF_METADATA_CHECK
:
949 return put_u32(coherent
, arg
);
960 * This is not used by anonymous file descriptors. This code is left
961 * there if we ever want to implement an inode with open() operation.
964 int lttng_metadata_ring_buffer_open(struct inode
*inode
, struct file
*file
)
966 struct lttng_metadata_stream
*stream
= inode
->i_private
;
967 struct lib_ring_buffer
*buf
= stream
->priv
;
969 file
->private_data
= buf
;
971 * Since life-time of metadata cache differs from that of
972 * session, we need to keep our own reference on the transport.
974 if (!try_module_get(stream
->transport
->owner
)) {
975 printk(KERN_WARNING
"LTT : Can't lock transport module.\n");
978 return lib_ring_buffer_open(inode
, file
, buf
);
982 int lttng_metadata_ring_buffer_release(struct inode
*inode
, struct file
*file
)
984 struct lttng_metadata_stream
*stream
= file
->private_data
;
985 struct lib_ring_buffer
*buf
= stream
->priv
;
987 mutex_lock(&stream
->metadata_cache
->lock
);
988 list_del(&stream
->list
);
989 mutex_unlock(&stream
->metadata_cache
->lock
);
990 kref_put(&stream
->metadata_cache
->refcount
, metadata_cache_destroy
);
991 module_put(stream
->transport
->owner
);
993 return lib_ring_buffer_release(inode
, file
, buf
);
997 ssize_t
lttng_metadata_ring_buffer_splice_read(struct file
*in
, loff_t
*ppos
,
998 struct pipe_inode_info
*pipe
, size_t len
,
1001 struct lttng_metadata_stream
*stream
= in
->private_data
;
1002 struct lib_ring_buffer
*buf
= stream
->priv
;
1004 return lib_ring_buffer_splice_read(in
, ppos
, pipe
, len
,
1009 int lttng_metadata_ring_buffer_mmap(struct file
*filp
,
1010 struct vm_area_struct
*vma
)
1012 struct lttng_metadata_stream
*stream
= filp
->private_data
;
1013 struct lib_ring_buffer
*buf
= stream
->priv
;
1015 return lib_ring_buffer_mmap(filp
, vma
, buf
);
1019 const struct file_operations lttng_metadata_ring_buffer_file_operations
= {
1020 .owner
= THIS_MODULE
,
1021 .open
= lttng_metadata_ring_buffer_open
,
1022 .release
= lttng_metadata_ring_buffer_release
,
1023 .poll
= lttng_metadata_ring_buffer_poll
,
1024 .splice_read
= lttng_metadata_ring_buffer_splice_read
,
1025 .mmap
= lttng_metadata_ring_buffer_mmap
,
1026 .unlocked_ioctl
= lttng_metadata_ring_buffer_ioctl
,
1027 .llseek
= vfs_lib_ring_buffer_no_llseek
,
1028 #ifdef CONFIG_COMPAT
1029 .compat_ioctl
= lttng_metadata_ring_buffer_compat_ioctl
,
1034 int lttng_abi_create_stream_fd(struct file
*channel_file
, void *stream_priv
,
1035 const struct file_operations
*fops
)
1038 struct file
*stream_file
;
1040 stream_fd
= lttng_get_unused_fd();
1041 if (stream_fd
< 0) {
1045 stream_file
= anon_inode_getfile("[lttng_stream]", fops
,
1046 stream_priv
, O_RDWR
);
1047 if (IS_ERR(stream_file
)) {
1048 ret
= PTR_ERR(stream_file
);
1052 * OPEN_FMODE, called within anon_inode_getfile/alloc_file, don't honor
1053 * FMODE_LSEEK, FMODE_PREAD nor FMODE_PWRITE. We need to read from this
1054 * file descriptor, so we set FMODE_PREAD here.
1056 stream_file
->f_mode
|= FMODE_PREAD
;
1057 fd_install(stream_fd
, stream_file
);
1059 * The stream holds a reference to the channel within the generic ring
1060 * buffer library, so no need to hold a refcount on the channel and
1061 * session files here.
1066 put_unused_fd(stream_fd
);
1072 int lttng_abi_open_stream(struct file
*channel_file
)
1074 struct lttng_channel
*channel
= channel_file
->private_data
;
1075 struct lib_ring_buffer
*buf
;
1079 buf
= channel
->ops
->buffer_read_open(channel
->chan
);
1084 ret
= lttng_abi_create_stream_fd(channel_file
, stream_priv
,
1085 <tng_stream_ring_buffer_file_operations
);
1092 channel
->ops
->buffer_read_close(buf
);
1097 int lttng_abi_open_metadata_stream(struct file
*channel_file
)
1099 struct lttng_channel
*channel
= channel_file
->private_data
;
1100 struct lttng_session
*session
= channel
->session
;
1101 struct lib_ring_buffer
*buf
;
1103 struct lttng_metadata_stream
*metadata_stream
;
1106 buf
= channel
->ops
->buffer_read_open(channel
->chan
);
1110 metadata_stream
= kzalloc(sizeof(struct lttng_metadata_stream
),
1112 if (!metadata_stream
) {
1116 metadata_stream
->metadata_cache
= session
->metadata_cache
;
1117 init_waitqueue_head(&metadata_stream
->read_wait
);
1118 metadata_stream
->priv
= buf
;
1119 stream_priv
= metadata_stream
;
1120 metadata_stream
->transport
= channel
->transport
;
1121 /* Initial state is an empty metadata, considered as incoherent. */
1122 metadata_stream
->coherent
= false;
1125 * Since life-time of metadata cache differs from that of
1126 * session, we need to keep our own reference on the transport.
1128 if (!try_module_get(metadata_stream
->transport
->owner
)) {
1129 printk(KERN_WARNING
"LTT : Can't lock transport module.\n");
1134 if (!lttng_kref_get(&session
->metadata_cache
->refcount
)) {
1139 ret
= lttng_abi_create_stream_fd(channel_file
, stream_priv
,
1140 <tng_metadata_ring_buffer_file_operations
);
1144 mutex_lock(&session
->metadata_cache
->lock
);
1145 list_add(&metadata_stream
->list
,
1146 &session
->metadata_cache
->metadata_stream
);
1147 mutex_unlock(&session
->metadata_cache
->lock
);
1151 kref_put(&session
->metadata_cache
->refcount
, metadata_cache_destroy
);
1153 module_put(metadata_stream
->transport
->owner
);
1155 kfree(metadata_stream
);
1157 channel
->ops
->buffer_read_close(buf
);
1162 int lttng_abi_validate_event_param(struct lttng_kernel_event
*event_param
)
1164 /* Limit ABI to implemented features. */
1165 switch (event_param
->instrumentation
) {
1166 case LTTNG_KERNEL_SYSCALL
:
1167 switch (event_param
->u
.syscall
.entryexit
) {
1168 case LTTNG_KERNEL_SYSCALL_ENTRYEXIT
:
1173 switch (event_param
->u
.syscall
.abi
) {
1174 case LTTNG_KERNEL_SYSCALL_ABI_ALL
:
1179 switch (event_param
->u
.syscall
.match
) {
1180 case LTTNG_SYSCALL_MATCH_NAME
:
1187 case LTTNG_KERNEL_TRACEPOINT
: /* Fallthrough */
1188 case LTTNG_KERNEL_KPROBE
: /* Fallthrough */
1189 case LTTNG_KERNEL_KRETPROBE
: /* Fallthrough */
1190 case LTTNG_KERNEL_NOOP
: /* Fallthrough */
1191 case LTTNG_KERNEL_UPROBE
:
1194 case LTTNG_KERNEL_FUNCTION
: /* Fallthrough */
1202 int lttng_abi_create_event(struct file
*channel_file
,
1203 struct lttng_kernel_event
*event_param
)
1205 struct lttng_channel
*channel
= channel_file
->private_data
;
1207 struct file
*event_file
;
1210 event_param
->name
[LTTNG_KERNEL_SYM_NAME_LEN
- 1] = '\0';
1211 switch (event_param
->instrumentation
) {
1212 case LTTNG_KERNEL_KRETPROBE
:
1213 event_param
->u
.kretprobe
.symbol_name
[LTTNG_KERNEL_SYM_NAME_LEN
- 1] = '\0';
1215 case LTTNG_KERNEL_KPROBE
:
1216 event_param
->u
.kprobe
.symbol_name
[LTTNG_KERNEL_SYM_NAME_LEN
- 1] = '\0';
1218 case LTTNG_KERNEL_FUNCTION
:
1220 /* Not implemented. */
1225 event_fd
= lttng_get_unused_fd();
1230 event_file
= anon_inode_getfile("[lttng_event]",
1233 if (IS_ERR(event_file
)) {
1234 ret
= PTR_ERR(event_file
);
1237 /* The event holds a reference on the channel */
1238 if (!atomic_long_add_unless(&channel_file
->f_count
, 1, LONG_MAX
)) {
1240 goto refcount_error
;
1242 ret
= lttng_abi_validate_event_param(event_param
);
1245 if (event_param
->instrumentation
== LTTNG_KERNEL_TRACEPOINT
1246 || event_param
->instrumentation
== LTTNG_KERNEL_SYSCALL
) {
1247 struct lttng_enabler
*enabler
;
1249 if (strutils_is_star_glob_pattern(event_param
->name
)) {
1251 * If the event name is a star globbing pattern,
1252 * we create the special star globbing enabler.
1254 enabler
= lttng_enabler_create(LTTNG_ENABLER_STAR_GLOB
,
1255 event_param
, channel
);
1257 enabler
= lttng_enabler_create(LTTNG_ENABLER_NAME
,
1258 event_param
, channel
);
1262 struct lttng_event
*event
;
1265 * We tolerate no failure path after event creation. It
1266 * will stay invariant for the rest of the session.
1268 event
= lttng_event_create(channel
, event_param
,
1270 event_param
->instrumentation
);
1271 WARN_ON_ONCE(!event
);
1272 if (IS_ERR(event
)) {
1273 ret
= PTR_ERR(event
);
1278 event_file
->private_data
= priv
;
1279 fd_install(event_fd
, event_file
);
1283 atomic_long_dec(&channel_file
->f_count
);
1287 put_unused_fd(event_fd
);
1293 * lttng_channel_ioctl - lttng syscall through ioctl
1299 * This ioctl implements lttng commands:
1300 * LTTNG_KERNEL_STREAM
1301 * Returns an event stream file descriptor or failure.
1302 * (typically, one event stream records events from one CPU)
1303 * LTTNG_KERNEL_EVENT
1304 * Returns an event file descriptor or failure.
1305 * LTTNG_KERNEL_CONTEXT
1306 * Prepend a context field to each event in the channel
1307 * LTTNG_KERNEL_ENABLE
1308 * Enable recording for events in this channel (weak enable)
1309 * LTTNG_KERNEL_DISABLE
1310 * Disable recording for events in this channel (strong disable)
1312 * Channel and event file descriptors also hold a reference on the session.
1315 long lttng_channel_ioctl(struct file
*file
, unsigned int cmd
, unsigned long arg
)
1317 struct lttng_channel
*channel
= file
->private_data
;
1320 case LTTNG_KERNEL_OLD_STREAM
:
1321 case LTTNG_KERNEL_STREAM
:
1322 return lttng_abi_open_stream(file
);
1323 case LTTNG_KERNEL_OLD_EVENT
:
1325 struct lttng_kernel_event
*uevent_param
;
1326 struct lttng_kernel_old_event
*old_uevent_param
;
1329 uevent_param
= kmalloc(sizeof(struct lttng_kernel_event
),
1331 if (!uevent_param
) {
1335 old_uevent_param
= kmalloc(
1336 sizeof(struct lttng_kernel_old_event
),
1338 if (!old_uevent_param
) {
1340 goto old_event_error_free_param
;
1342 if (copy_from_user(old_uevent_param
,
1343 (struct lttng_kernel_old_event __user
*) arg
,
1344 sizeof(struct lttng_kernel_old_event
))) {
1346 goto old_event_error_free_old_param
;
1349 memcpy(uevent_param
->name
, old_uevent_param
->name
,
1350 sizeof(uevent_param
->name
));
1351 uevent_param
->instrumentation
=
1352 old_uevent_param
->instrumentation
;
1354 switch (old_uevent_param
->instrumentation
) {
1355 case LTTNG_KERNEL_KPROBE
:
1356 uevent_param
->u
.kprobe
.addr
=
1357 old_uevent_param
->u
.kprobe
.addr
;
1358 uevent_param
->u
.kprobe
.offset
=
1359 old_uevent_param
->u
.kprobe
.offset
;
1360 memcpy(uevent_param
->u
.kprobe
.symbol_name
,
1361 old_uevent_param
->u
.kprobe
.symbol_name
,
1362 sizeof(uevent_param
->u
.kprobe
.symbol_name
));
1364 case LTTNG_KERNEL_KRETPROBE
:
1365 uevent_param
->u
.kretprobe
.addr
=
1366 old_uevent_param
->u
.kretprobe
.addr
;
1367 uevent_param
->u
.kretprobe
.offset
=
1368 old_uevent_param
->u
.kretprobe
.offset
;
1369 memcpy(uevent_param
->u
.kretprobe
.symbol_name
,
1370 old_uevent_param
->u
.kretprobe
.symbol_name
,
1371 sizeof(uevent_param
->u
.kretprobe
.symbol_name
));
1373 case LTTNG_KERNEL_FUNCTION
:
1375 /* Not implemented. */
1380 ret
= lttng_abi_create_event(file
, uevent_param
);
1382 old_event_error_free_old_param
:
1383 kfree(old_uevent_param
);
1384 old_event_error_free_param
:
1385 kfree(uevent_param
);
1389 case LTTNG_KERNEL_EVENT
:
1391 struct lttng_kernel_event uevent_param
;
1393 if (copy_from_user(&uevent_param
,
1394 (struct lttng_kernel_event __user
*) arg
,
1395 sizeof(uevent_param
)))
1397 return lttng_abi_create_event(file
, &uevent_param
);
1399 case LTTNG_KERNEL_OLD_CONTEXT
:
1401 struct lttng_kernel_context
*ucontext_param
;
1402 struct lttng_kernel_old_context
*old_ucontext_param
;
1405 ucontext_param
= kmalloc(sizeof(struct lttng_kernel_context
),
1407 if (!ucontext_param
) {
1411 old_ucontext_param
= kmalloc(sizeof(struct lttng_kernel_old_context
),
1413 if (!old_ucontext_param
) {
1415 goto old_ctx_error_free_param
;
1418 if (copy_from_user(old_ucontext_param
,
1419 (struct lttng_kernel_old_context __user
*) arg
,
1420 sizeof(struct lttng_kernel_old_context
))) {
1422 goto old_ctx_error_free_old_param
;
1424 ucontext_param
->ctx
= old_ucontext_param
->ctx
;
1425 memcpy(ucontext_param
->padding
, old_ucontext_param
->padding
,
1426 sizeof(ucontext_param
->padding
));
1427 /* only type that uses the union */
1428 if (old_ucontext_param
->ctx
== LTTNG_KERNEL_CONTEXT_PERF_COUNTER
) {
1429 ucontext_param
->u
.perf_counter
.type
=
1430 old_ucontext_param
->u
.perf_counter
.type
;
1431 ucontext_param
->u
.perf_counter
.config
=
1432 old_ucontext_param
->u
.perf_counter
.config
;
1433 memcpy(ucontext_param
->u
.perf_counter
.name
,
1434 old_ucontext_param
->u
.perf_counter
.name
,
1435 sizeof(ucontext_param
->u
.perf_counter
.name
));
1438 ret
= lttng_abi_add_context(file
,
1440 &channel
->ctx
, channel
->session
);
1442 old_ctx_error_free_old_param
:
1443 kfree(old_ucontext_param
);
1444 old_ctx_error_free_param
:
1445 kfree(ucontext_param
);
1449 case LTTNG_KERNEL_CONTEXT
:
1451 struct lttng_kernel_context ucontext_param
;
1453 if (copy_from_user(&ucontext_param
,
1454 (struct lttng_kernel_context __user
*) arg
,
1455 sizeof(ucontext_param
)))
1457 return lttng_abi_add_context(file
,
1459 &channel
->ctx
, channel
->session
);
1461 case LTTNG_KERNEL_OLD_ENABLE
:
1462 case LTTNG_KERNEL_ENABLE
:
1463 return lttng_channel_enable(channel
);
1464 case LTTNG_KERNEL_OLD_DISABLE
:
1465 case LTTNG_KERNEL_DISABLE
:
1466 return lttng_channel_disable(channel
);
1467 case LTTNG_KERNEL_SYSCALL_MASK
:
1468 return lttng_channel_syscall_mask(channel
,
1469 (struct lttng_kernel_syscall_mask __user
*) arg
);
1471 return -ENOIOCTLCMD
;
1476 * lttng_metadata_ioctl - lttng syscall through ioctl
1482 * This ioctl implements lttng commands:
1483 * LTTNG_KERNEL_STREAM
1484 * Returns an event stream file descriptor or failure.
1486 * Channel and event file descriptors also hold a reference on the session.
1489 long lttng_metadata_ioctl(struct file
*file
, unsigned int cmd
, unsigned long arg
)
1492 case LTTNG_KERNEL_OLD_STREAM
:
1493 case LTTNG_KERNEL_STREAM
:
1494 return lttng_abi_open_metadata_stream(file
);
1496 return -ENOIOCTLCMD
;
1501 * lttng_channel_poll - lttng stream addition/removal monitoring
1506 unsigned int lttng_channel_poll(struct file
*file
, poll_table
*wait
)
1508 struct lttng_channel
*channel
= file
->private_data
;
1509 unsigned int mask
= 0;
1511 if (file
->f_mode
& FMODE_READ
) {
1512 poll_wait_set_exclusive(wait
);
1513 poll_wait(file
, channel
->ops
->get_hp_wait_queue(channel
->chan
),
1516 if (channel
->ops
->is_disabled(channel
->chan
))
1518 if (channel
->ops
->is_finalized(channel
->chan
))
1520 if (channel
->ops
->buffer_has_read_closed_stream(channel
->chan
))
1521 return POLLIN
| POLLRDNORM
;
1529 int lttng_channel_release(struct inode
*inode
, struct file
*file
)
1531 struct lttng_channel
*channel
= file
->private_data
;
1534 fput(channel
->session
->file
);
1539 int lttng_metadata_channel_release(struct inode
*inode
, struct file
*file
)
1541 struct lttng_channel
*channel
= file
->private_data
;
1544 fput(channel
->session
->file
);
1545 lttng_metadata_channel_destroy(channel
);
1551 static const struct file_operations lttng_channel_fops
= {
1552 .owner
= THIS_MODULE
,
1553 .release
= lttng_channel_release
,
1554 .poll
= lttng_channel_poll
,
1555 .unlocked_ioctl
= lttng_channel_ioctl
,
1556 #ifdef CONFIG_COMPAT
1557 .compat_ioctl
= lttng_channel_ioctl
,
1561 static const struct file_operations lttng_metadata_fops
= {
1562 .owner
= THIS_MODULE
,
1563 .release
= lttng_metadata_channel_release
,
1564 .unlocked_ioctl
= lttng_metadata_ioctl
,
1565 #ifdef CONFIG_COMPAT
1566 .compat_ioctl
= lttng_metadata_ioctl
,
1571 * lttng_event_ioctl - lttng syscall through ioctl
1577 * This ioctl implements lttng commands:
1578 * LTTNG_KERNEL_CONTEXT
1579 * Prepend a context field to each record of this event
1580 * LTTNG_KERNEL_ENABLE
1581 * Enable recording for this event (weak enable)
1582 * LTTNG_KERNEL_DISABLE
1583 * Disable recording for this event (strong disable)
1586 long lttng_event_ioctl(struct file
*file
, unsigned int cmd
, unsigned long arg
)
1588 struct lttng_event
*event
;
1589 struct lttng_enabler
*enabler
;
1590 enum lttng_event_type
*evtype
= file
->private_data
;
1593 case LTTNG_KERNEL_OLD_CONTEXT
:
1595 /* Not implemented */
1598 case LTTNG_KERNEL_CONTEXT
:
1600 /* Not implemented */
1603 case LTTNG_KERNEL_OLD_ENABLE
:
1604 case LTTNG_KERNEL_ENABLE
:
1606 case LTTNG_TYPE_EVENT
:
1607 event
= file
->private_data
;
1608 return lttng_event_enable(event
);
1609 case LTTNG_TYPE_ENABLER
:
1610 enabler
= file
->private_data
;
1611 return lttng_enabler_enable(enabler
);
1616 case LTTNG_KERNEL_OLD_DISABLE
:
1617 case LTTNG_KERNEL_DISABLE
:
1619 case LTTNG_TYPE_EVENT
:
1620 event
= file
->private_data
;
1621 return lttng_event_disable(event
);
1622 case LTTNG_TYPE_ENABLER
:
1623 enabler
= file
->private_data
;
1624 return lttng_enabler_disable(enabler
);
1629 case LTTNG_KERNEL_FILTER
:
1631 case LTTNG_TYPE_EVENT
:
1633 case LTTNG_TYPE_ENABLER
:
1635 enabler
= file
->private_data
;
1636 return lttng_enabler_attach_bytecode(enabler
,
1637 (struct lttng_kernel_filter_bytecode __user
*) arg
);
1643 case LTTNG_KERNEL_ADD_CALLSITE
:
1645 case LTTNG_TYPE_EVENT
:
1646 event
= file
->private_data
;
1647 return lttng_event_add_callsite(event
,
1648 (struct lttng_kernel_event_callsite __user
*) arg
);
1649 case LTTNG_TYPE_ENABLER
:
1656 return -ENOIOCTLCMD
;
1661 int lttng_event_release(struct inode
*inode
, struct file
*file
)
1663 struct lttng_event
*event
;
1664 struct lttng_enabler
*enabler
;
1665 enum lttng_event_type
*evtype
= file
->private_data
;
1671 case LTTNG_TYPE_EVENT
:
1672 event
= file
->private_data
;
1674 fput(event
->chan
->file
);
1676 case LTTNG_TYPE_ENABLER
:
1677 enabler
= file
->private_data
;
1679 fput(enabler
->chan
->file
);
1689 /* TODO: filter control ioctl */
1690 static const struct file_operations lttng_event_fops
= {
1691 .owner
= THIS_MODULE
,
1692 .release
= lttng_event_release
,
1693 .unlocked_ioctl
= lttng_event_ioctl
,
1694 #ifdef CONFIG_COMPAT
1695 .compat_ioctl
= lttng_event_ioctl
,
1699 static int put_u64(uint64_t val
, unsigned long arg
)
1701 return put_user(val
, (uint64_t __user
*) arg
);
1704 static int put_u32(uint32_t val
, unsigned long arg
)
1706 return put_user(val
, (uint32_t __user
*) arg
);
1709 static long lttng_stream_ring_buffer_ioctl(struct file
*filp
,
1710 unsigned int cmd
, unsigned long arg
)
1712 struct lib_ring_buffer
*buf
= filp
->private_data
;
1713 struct channel
*chan
= buf
->backend
.chan
;
1714 const struct lib_ring_buffer_config
*config
= &chan
->backend
.config
;
1715 const struct lttng_channel_ops
*ops
= chan
->backend
.priv_ops
;
1718 if (atomic_read(&chan
->record_disabled
))
1722 case LTTNG_RING_BUFFER_GET_TIMESTAMP_BEGIN
:
1726 ret
= ops
->timestamp_begin(config
, buf
, &ts
);
1729 return put_u64(ts
, arg
);
1731 case LTTNG_RING_BUFFER_GET_TIMESTAMP_END
:
1735 ret
= ops
->timestamp_end(config
, buf
, &ts
);
1738 return put_u64(ts
, arg
);
1740 case LTTNG_RING_BUFFER_GET_EVENTS_DISCARDED
:
1744 ret
= ops
->events_discarded(config
, buf
, &ed
);
1747 return put_u64(ed
, arg
);
1749 case LTTNG_RING_BUFFER_GET_CONTENT_SIZE
:
1753 ret
= ops
->content_size(config
, buf
, &cs
);
1756 return put_u64(cs
, arg
);
1758 case LTTNG_RING_BUFFER_GET_PACKET_SIZE
:
1762 ret
= ops
->packet_size(config
, buf
, &ps
);
1765 return put_u64(ps
, arg
);
1767 case LTTNG_RING_BUFFER_GET_STREAM_ID
:
1771 ret
= ops
->stream_id(config
, buf
, &si
);
1774 return put_u64(si
, arg
);
1776 case LTTNG_RING_BUFFER_GET_CURRENT_TIMESTAMP
:
1780 ret
= ops
->current_timestamp(config
, buf
, &ts
);
1783 return put_u64(ts
, arg
);
1785 case LTTNG_RING_BUFFER_GET_SEQ_NUM
:
1789 ret
= ops
->sequence_number(config
, buf
, &seq
);
1792 return put_u64(seq
, arg
);
1794 case LTTNG_RING_BUFFER_INSTANCE_ID
:
1798 ret
= ops
->instance_id(config
, buf
, &id
);
1801 return put_u64(id
, arg
);
1804 return lib_ring_buffer_file_operations
.unlocked_ioctl(filp
,
1812 #ifdef CONFIG_COMPAT
1813 static long lttng_stream_ring_buffer_compat_ioctl(struct file
*filp
,
1814 unsigned int cmd
, unsigned long arg
)
1816 struct lib_ring_buffer
*buf
= filp
->private_data
;
1817 struct channel
*chan
= buf
->backend
.chan
;
1818 const struct lib_ring_buffer_config
*config
= &chan
->backend
.config
;
1819 const struct lttng_channel_ops
*ops
= chan
->backend
.priv_ops
;
1822 if (atomic_read(&chan
->record_disabled
))
1826 case LTTNG_RING_BUFFER_COMPAT_GET_TIMESTAMP_BEGIN
:
1830 ret
= ops
->timestamp_begin(config
, buf
, &ts
);
1833 return put_u64(ts
, arg
);
1835 case LTTNG_RING_BUFFER_COMPAT_GET_TIMESTAMP_END
:
1839 ret
= ops
->timestamp_end(config
, buf
, &ts
);
1842 return put_u64(ts
, arg
);
1844 case LTTNG_RING_BUFFER_COMPAT_GET_EVENTS_DISCARDED
:
1848 ret
= ops
->events_discarded(config
, buf
, &ed
);
1851 return put_u64(ed
, arg
);
1853 case LTTNG_RING_BUFFER_COMPAT_GET_CONTENT_SIZE
:
1857 ret
= ops
->content_size(config
, buf
, &cs
);
1860 return put_u64(cs
, arg
);
1862 case LTTNG_RING_BUFFER_COMPAT_GET_PACKET_SIZE
:
1866 ret
= ops
->packet_size(config
, buf
, &ps
);
1869 return put_u64(ps
, arg
);
1871 case LTTNG_RING_BUFFER_COMPAT_GET_STREAM_ID
:
1875 ret
= ops
->stream_id(config
, buf
, &si
);
1878 return put_u64(si
, arg
);
1880 case LTTNG_RING_BUFFER_GET_CURRENT_TIMESTAMP
:
1884 ret
= ops
->current_timestamp(config
, buf
, &ts
);
1887 return put_u64(ts
, arg
);
1889 case LTTNG_RING_BUFFER_COMPAT_GET_SEQ_NUM
:
1893 ret
= ops
->sequence_number(config
, buf
, &seq
);
1896 return put_u64(seq
, arg
);
1898 case LTTNG_RING_BUFFER_COMPAT_INSTANCE_ID
:
1902 ret
= ops
->instance_id(config
, buf
, &id
);
1905 return put_u64(id
, arg
);
1908 return lib_ring_buffer_file_operations
.compat_ioctl(filp
,
1915 #endif /* CONFIG_COMPAT */
1917 static void lttng_stream_override_ring_buffer_fops(void)
1919 lttng_stream_ring_buffer_file_operations
.owner
= THIS_MODULE
;
1920 lttng_stream_ring_buffer_file_operations
.open
=
1921 lib_ring_buffer_file_operations
.open
;
1922 lttng_stream_ring_buffer_file_operations
.release
=
1923 lib_ring_buffer_file_operations
.release
;
1924 lttng_stream_ring_buffer_file_operations
.poll
=
1925 lib_ring_buffer_file_operations
.poll
;
1926 lttng_stream_ring_buffer_file_operations
.splice_read
=
1927 lib_ring_buffer_file_operations
.splice_read
;
1928 lttng_stream_ring_buffer_file_operations
.mmap
=
1929 lib_ring_buffer_file_operations
.mmap
;
1930 lttng_stream_ring_buffer_file_operations
.unlocked_ioctl
=
1931 lttng_stream_ring_buffer_ioctl
;
1932 lttng_stream_ring_buffer_file_operations
.llseek
=
1933 lib_ring_buffer_file_operations
.llseek
;
1934 #ifdef CONFIG_COMPAT
1935 lttng_stream_ring_buffer_file_operations
.compat_ioctl
=
1936 lttng_stream_ring_buffer_compat_ioctl
;
1940 int __init
lttng_abi_init(void)
1944 wrapper_vmalloc_sync_mappings();
1947 ret
= lttng_tp_mempool_init();
1952 lttng_proc_dentry
= proc_create_data("lttng", S_IRUSR
| S_IWUSR
, NULL
,
1953 <tng_proc_ops
, NULL
);
1955 if (!lttng_proc_dentry
) {
1956 printk(KERN_ERR
"Error creating LTTng control file\n");
1960 lttng_stream_override_ring_buffer_fops();
1964 lttng_tp_mempool_destroy();
1965 lttng_clock_unref();
1969 /* No __exit annotation because used by init error path too. */
1970 void lttng_abi_exit(void)
1972 lttng_tp_mempool_destroy();
1973 lttng_clock_unref();
1974 if (lttng_proc_dentry
)
1975 remove_proc_entry("lttng", NULL
);