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
);
245 * lttng_ioctl - lttng syscall through ioctl
251 * This ioctl implements lttng commands:
252 * LTTNG_KERNEL_SESSION
253 * Returns a LTTng trace session file descriptor
254 * LTTNG_KERNEL_TRACER_VERSION
255 * Returns the LTTng kernel tracer version
256 * LTTNG_KERNEL_TRACEPOINT_LIST
257 * Returns a file descriptor listing available tracepoints
258 * LTTNG_KERNEL_WAIT_QUIESCENT
259 * Returns after all previously running probes have completed
260 * LTTNG_KERNEL_TRACER_ABI_VERSION
261 * Returns the LTTng kernel tracer ABI version
263 * The returned session will be deleted when its file descriptor is closed.
266 long lttng_ioctl(struct file
*file
, unsigned int cmd
, unsigned long arg
)
269 case LTTNG_KERNEL_OLD_SESSION
:
270 case LTTNG_KERNEL_SESSION
:
271 return lttng_abi_create_session();
272 case LTTNG_KERNEL_OLD_TRACER_VERSION
:
274 struct lttng_kernel_tracer_version v
;
275 struct lttng_kernel_old_tracer_version oldv
;
276 struct lttng_kernel_old_tracer_version
*uversion
=
277 (struct lttng_kernel_old_tracer_version __user
*) arg
;
279 lttng_abi_tracer_version(&v
);
280 oldv
.major
= v
.major
;
281 oldv
.minor
= v
.minor
;
282 oldv
.patchlevel
= v
.patchlevel
;
284 if (copy_to_user(uversion
, &oldv
, sizeof(oldv
)))
288 case LTTNG_KERNEL_TRACER_VERSION
:
290 struct lttng_kernel_tracer_version version
;
291 struct lttng_kernel_tracer_version
*uversion
=
292 (struct lttng_kernel_tracer_version __user
*) arg
;
294 lttng_abi_tracer_version(&version
);
296 if (copy_to_user(uversion
, &version
, sizeof(version
)))
300 case LTTNG_KERNEL_TRACER_ABI_VERSION
:
302 struct lttng_kernel_tracer_abi_version version
;
303 struct lttng_kernel_tracer_abi_version
*uversion
=
304 (struct lttng_kernel_tracer_abi_version __user
*) arg
;
306 lttng_abi_tracer_abi_version(&version
);
308 if (copy_to_user(uversion
, &version
, sizeof(version
)))
312 case LTTNG_KERNEL_OLD_TRACEPOINT_LIST
:
313 case LTTNG_KERNEL_TRACEPOINT_LIST
:
314 return lttng_abi_tracepoint_list();
315 case LTTNG_KERNEL_SYSCALL_LIST
:
316 return lttng_abi_syscall_list();
317 case LTTNG_KERNEL_OLD_WAIT_QUIESCENT
:
318 case LTTNG_KERNEL_WAIT_QUIESCENT
:
321 case LTTNG_KERNEL_OLD_CALIBRATE
:
323 struct lttng_kernel_old_calibrate __user
*ucalibrate
=
324 (struct lttng_kernel_old_calibrate __user
*) arg
;
325 struct lttng_kernel_old_calibrate old_calibrate
;
326 struct lttng_kernel_calibrate calibrate
;
329 if (copy_from_user(&old_calibrate
, ucalibrate
, sizeof(old_calibrate
)))
331 calibrate
.type
= old_calibrate
.type
;
332 ret
= lttng_calibrate(&calibrate
);
333 if (copy_to_user(ucalibrate
, &old_calibrate
, sizeof(old_calibrate
)))
337 case LTTNG_KERNEL_CALIBRATE
:
339 struct lttng_kernel_calibrate __user
*ucalibrate
=
340 (struct lttng_kernel_calibrate __user
*) arg
;
341 struct lttng_kernel_calibrate calibrate
;
344 if (copy_from_user(&calibrate
, ucalibrate
, sizeof(calibrate
)))
346 ret
= lttng_calibrate(&calibrate
);
347 if (copy_to_user(ucalibrate
, &calibrate
, sizeof(calibrate
)))
356 static const struct file_operations lttng_fops
= {
357 .owner
= THIS_MODULE
,
358 .unlocked_ioctl
= lttng_ioctl
,
360 .compat_ioctl
= lttng_ioctl
,
365 int lttng_abi_create_channel(struct file
*session_file
,
366 struct lttng_kernel_channel
*chan_param
,
367 enum channel_type channel_type
)
369 struct lttng_session
*session
= session_file
->private_data
;
370 const struct file_operations
*fops
= NULL
;
371 const char *transport_name
;
372 struct lttng_channel
*chan
;
373 struct file
*chan_file
;
377 chan_fd
= lttng_get_unused_fd();
382 switch (channel_type
) {
383 case PER_CPU_CHANNEL
:
384 fops
= <tng_channel_fops
;
386 case METADATA_CHANNEL
:
387 fops
= <tng_metadata_fops
;
391 chan_file
= anon_inode_getfile("[lttng_channel]",
394 if (IS_ERR(chan_file
)) {
395 ret
= PTR_ERR(chan_file
);
398 switch (channel_type
) {
399 case PER_CPU_CHANNEL
:
400 if (chan_param
->output
== LTTNG_KERNEL_SPLICE
) {
401 transport_name
= chan_param
->overwrite
?
402 "relay-overwrite" : "relay-discard";
403 } else if (chan_param
->output
== LTTNG_KERNEL_MMAP
) {
404 transport_name
= chan_param
->overwrite
?
405 "relay-overwrite-mmap" : "relay-discard-mmap";
410 case METADATA_CHANNEL
:
411 if (chan_param
->output
== LTTNG_KERNEL_SPLICE
)
412 transport_name
= "relay-metadata";
413 else if (chan_param
->output
== LTTNG_KERNEL_MMAP
)
414 transport_name
= "relay-metadata-mmap";
419 transport_name
= "<unknown>";
422 if (!atomic_long_add_unless(&session_file
->f_count
, 1, LONG_MAX
)) {
427 * We tolerate no failure path after channel creation. It will stay
428 * invariant for the rest of the session.
430 chan
= lttng_channel_create(session
, transport_name
, NULL
,
431 chan_param
->subbuf_size
,
432 chan_param
->num_subbuf
,
433 chan_param
->switch_timer_interval
,
434 chan_param
->read_timer_interval
,
440 chan
->file
= chan_file
;
441 chan_file
->private_data
= chan
;
442 fd_install(chan_fd
, chan_file
);
447 atomic_long_dec(&session_file
->f_count
);
451 put_unused_fd(chan_fd
);
457 int lttng_abi_session_set_name(struct lttng_session
*session
,
458 struct lttng_kernel_session_name
*name
)
462 len
= strnlen(name
->name
, LTTNG_KERNEL_SESSION_NAME_LEN
);
464 if (len
== LTTNG_KERNEL_SESSION_NAME_LEN
) {
465 /* Name is too long/malformed */
469 strcpy(session
->name
, name
->name
);
474 int lttng_abi_session_set_creation_time(struct lttng_session
*session
,
475 struct lttng_kernel_session_creation_time
*time
)
479 len
= strnlen(time
->iso8601
, LTTNG_KERNEL_SESSION_CREATION_TIME_ISO8601_LEN
);
481 if (len
== LTTNG_KERNEL_SESSION_CREATION_TIME_ISO8601_LEN
) {
482 /* Time is too long/malformed */
486 strcpy(session
->creation_time
, time
->iso8601
);
491 * lttng_session_ioctl - lttng session fd ioctl
497 * This ioctl implements lttng commands:
498 * LTTNG_KERNEL_CHANNEL
499 * Returns a LTTng channel file descriptor
500 * LTTNG_KERNEL_ENABLE
501 * Enables tracing for a session (weak enable)
502 * LTTNG_KERNEL_DISABLE
503 * Disables tracing for a session (strong disable)
504 * LTTNG_KERNEL_METADATA
505 * Returns a LTTng metadata file descriptor
506 * LTTNG_KERNEL_SESSION_TRACK_PID
507 * Add PID to session tracker
508 * LTTNG_KERNEL_SESSION_UNTRACK_PID
509 * Remove PID from session tracker
511 * The returned channel will be deleted when its file descriptor is closed.
514 long lttng_session_ioctl(struct file
*file
, unsigned int cmd
, unsigned long arg
)
516 struct lttng_session
*session
= file
->private_data
;
519 case LTTNG_KERNEL_OLD_CHANNEL
:
521 struct lttng_kernel_channel chan_param
;
522 struct lttng_kernel_old_channel old_chan_param
;
524 if (copy_from_user(&old_chan_param
,
525 (struct lttng_kernel_old_channel __user
*) arg
,
526 sizeof(struct lttng_kernel_old_channel
)))
528 chan_param
.overwrite
= old_chan_param
.overwrite
;
529 chan_param
.subbuf_size
= old_chan_param
.subbuf_size
;
530 chan_param
.num_subbuf
= old_chan_param
.num_subbuf
;
531 chan_param
.switch_timer_interval
= old_chan_param
.switch_timer_interval
;
532 chan_param
.read_timer_interval
= old_chan_param
.read_timer_interval
;
533 chan_param
.output
= old_chan_param
.output
;
535 return lttng_abi_create_channel(file
, &chan_param
,
538 case LTTNG_KERNEL_CHANNEL
:
540 struct lttng_kernel_channel chan_param
;
542 if (copy_from_user(&chan_param
,
543 (struct lttng_kernel_channel __user
*) arg
,
544 sizeof(struct lttng_kernel_channel
)))
546 return lttng_abi_create_channel(file
, &chan_param
,
549 case LTTNG_KERNEL_OLD_SESSION_START
:
550 case LTTNG_KERNEL_OLD_ENABLE
:
551 case LTTNG_KERNEL_SESSION_START
:
552 case LTTNG_KERNEL_ENABLE
:
553 return lttng_session_enable(session
);
554 case LTTNG_KERNEL_OLD_SESSION_STOP
:
555 case LTTNG_KERNEL_OLD_DISABLE
:
556 case LTTNG_KERNEL_SESSION_STOP
:
557 case LTTNG_KERNEL_DISABLE
:
558 return lttng_session_disable(session
);
559 case LTTNG_KERNEL_OLD_METADATA
:
561 struct lttng_kernel_channel chan_param
;
562 struct lttng_kernel_old_channel old_chan_param
;
564 if (copy_from_user(&old_chan_param
,
565 (struct lttng_kernel_old_channel __user
*) arg
,
566 sizeof(struct lttng_kernel_old_channel
)))
568 chan_param
.overwrite
= old_chan_param
.overwrite
;
569 chan_param
.subbuf_size
= old_chan_param
.subbuf_size
;
570 chan_param
.num_subbuf
= old_chan_param
.num_subbuf
;
571 chan_param
.switch_timer_interval
= old_chan_param
.switch_timer_interval
;
572 chan_param
.read_timer_interval
= old_chan_param
.read_timer_interval
;
573 chan_param
.output
= old_chan_param
.output
;
575 return lttng_abi_create_channel(file
, &chan_param
,
578 case LTTNG_KERNEL_METADATA
:
580 struct lttng_kernel_channel chan_param
;
582 if (copy_from_user(&chan_param
,
583 (struct lttng_kernel_channel __user
*) arg
,
584 sizeof(struct lttng_kernel_channel
)))
586 return lttng_abi_create_channel(file
, &chan_param
,
589 case LTTNG_KERNEL_SESSION_TRACK_PID
:
590 return lttng_session_track_pid(session
, (int) arg
);
591 case LTTNG_KERNEL_SESSION_UNTRACK_PID
:
592 return lttng_session_untrack_pid(session
, (int) arg
);
593 case LTTNG_KERNEL_SESSION_LIST_TRACKER_PIDS
:
594 return lttng_session_list_tracker_pids(session
);
595 case LTTNG_KERNEL_SESSION_METADATA_REGEN
:
596 return lttng_session_metadata_regenerate(session
);
597 case LTTNG_KERNEL_SESSION_STATEDUMP
:
598 return lttng_session_statedump(session
);
599 case LTTNG_KERNEL_SESSION_SET_NAME
:
601 struct lttng_kernel_session_name name
;
603 if (copy_from_user(&name
,
604 (struct lttng_kernel_session_name __user
*) arg
,
605 sizeof(struct lttng_kernel_session_name
)))
607 return lttng_abi_session_set_name(session
, &name
);
609 case LTTNG_KERNEL_SESSION_SET_CREATION_TIME
:
611 struct lttng_kernel_session_creation_time time
;
613 if (copy_from_user(&time
,
614 (struct lttng_kernel_session_creation_time __user
*) arg
,
615 sizeof(struct lttng_kernel_session_creation_time
)))
617 return lttng_abi_session_set_creation_time(session
, &time
);
625 * Called when the last file reference is dropped.
627 * Big fat note: channels and events are invariant for the whole session after
628 * their creation. So this session destruction also destroys all channel and
629 * event structures specific to this session (they are not destroyed when their
630 * individual file is released).
633 int lttng_session_release(struct inode
*inode
, struct file
*file
)
635 struct lttng_session
*session
= file
->private_data
;
638 lttng_session_destroy(session
);
642 static const struct file_operations lttng_session_fops
= {
643 .owner
= THIS_MODULE
,
644 .release
= lttng_session_release
,
645 .unlocked_ioctl
= lttng_session_ioctl
,
647 .compat_ioctl
= lttng_session_ioctl
,
652 * lttng_metadata_ring_buffer_poll - LTTng ring buffer poll file operation
656 * Handles the poll operations for the metadata channels.
659 unsigned int lttng_metadata_ring_buffer_poll(struct file
*filp
,
662 struct lttng_metadata_stream
*stream
= filp
->private_data
;
663 struct lib_ring_buffer
*buf
= stream
->priv
;
665 unsigned int mask
= 0;
667 if (filp
->f_mode
& FMODE_READ
) {
668 poll_wait_set_exclusive(wait
);
669 poll_wait(filp
, &stream
->read_wait
, wait
);
671 finalized
= stream
->finalized
;
674 * lib_ring_buffer_is_finalized() contains a smp_rmb()
675 * ordering finalized load before offsets loads.
677 WARN_ON(atomic_long_read(&buf
->active_readers
) != 1);
682 mutex_lock(&stream
->metadata_cache
->lock
);
683 if (stream
->metadata_cache
->metadata_written
>
684 stream
->metadata_out
)
686 mutex_unlock(&stream
->metadata_cache
->lock
);
693 void lttng_metadata_ring_buffer_ioctl_put_next_subbuf(struct file
*filp
,
694 unsigned int cmd
, unsigned long arg
)
696 struct lttng_metadata_stream
*stream
= filp
->private_data
;
698 stream
->metadata_out
= stream
->metadata_in
;
702 * Reset the counter of how much metadata has been consumed to 0. That way,
703 * the consumer receives the content of the metadata cache unchanged. This is
704 * different from the metadata_regenerate where the offset from epoch is
705 * resampled, here we want the exact same content as the last time the metadata
706 * was generated. This command is only possible if all the metadata written
707 * in the cache has been output to the metadata stream to avoid corrupting the
710 * Return 0 on success, a negative value on error.
713 int lttng_metadata_cache_dump(struct lttng_metadata_stream
*stream
)
716 struct lttng_metadata_cache
*cache
= stream
->metadata_cache
;
718 mutex_lock(&cache
->lock
);
719 if (stream
->metadata_out
!= cache
->metadata_written
) {
723 stream
->metadata_out
= 0;
724 stream
->metadata_in
= 0;
725 wake_up_interruptible(&stream
->read_wait
);
729 mutex_unlock(&cache
->lock
);
734 long lttng_metadata_ring_buffer_ioctl(struct file
*filp
,
735 unsigned int cmd
, unsigned long arg
)
738 struct lttng_metadata_stream
*stream
= filp
->private_data
;
739 struct lib_ring_buffer
*buf
= stream
->priv
;
742 case RING_BUFFER_GET_NEXT_SUBBUF
:
744 struct lttng_metadata_stream
*stream
= filp
->private_data
;
745 struct lib_ring_buffer
*buf
= stream
->priv
;
746 struct channel
*chan
= buf
->backend
.chan
;
748 ret
= lttng_metadata_output_channel(stream
, chan
);
750 lib_ring_buffer_switch_slow(buf
, SWITCH_ACTIVE
);
756 case RING_BUFFER_GET_SUBBUF
:
759 * Random access is not allowed for metadata channel.
763 case RING_BUFFER_FLUSH_EMPTY
: /* Fall-through. */
764 case RING_BUFFER_FLUSH
:
766 struct lttng_metadata_stream
*stream
= filp
->private_data
;
767 struct lib_ring_buffer
*buf
= stream
->priv
;
768 struct channel
*chan
= buf
->backend
.chan
;
771 * Before doing the actual ring buffer flush, write up to one
772 * packet of metadata in the ring buffer.
774 ret
= lttng_metadata_output_channel(stream
, chan
);
779 case RING_BUFFER_GET_METADATA_VERSION
:
781 struct lttng_metadata_stream
*stream
= filp
->private_data
;
783 return put_u64(stream
->version
, arg
);
785 case RING_BUFFER_METADATA_CACHE_DUMP
:
787 struct lttng_metadata_stream
*stream
= filp
->private_data
;
789 return lttng_metadata_cache_dump(stream
);
794 /* PUT_SUBBUF is the one from lib ring buffer, unmodified. */
796 /* Performing lib ring buffer ioctl after our own. */
797 ret
= lib_ring_buffer_ioctl(filp
, cmd
, arg
, buf
);
802 case RING_BUFFER_PUT_NEXT_SUBBUF
:
804 lttng_metadata_ring_buffer_ioctl_put_next_subbuf(filp
,
817 long lttng_metadata_ring_buffer_compat_ioctl(struct file
*filp
,
818 unsigned int cmd
, unsigned long arg
)
821 struct lttng_metadata_stream
*stream
= filp
->private_data
;
822 struct lib_ring_buffer
*buf
= stream
->priv
;
825 case RING_BUFFER_GET_NEXT_SUBBUF
:
827 struct lttng_metadata_stream
*stream
= filp
->private_data
;
828 struct lib_ring_buffer
*buf
= stream
->priv
;
829 struct channel
*chan
= buf
->backend
.chan
;
831 ret
= lttng_metadata_output_channel(stream
, chan
);
833 lib_ring_buffer_switch_slow(buf
, SWITCH_ACTIVE
);
839 case RING_BUFFER_GET_SUBBUF
:
842 * Random access is not allowed for metadata channel.
846 case RING_BUFFER_FLUSH_EMPTY
: /* Fall-through. */
847 case RING_BUFFER_FLUSH
:
849 struct lttng_metadata_stream
*stream
= filp
->private_data
;
850 struct lib_ring_buffer
*buf
= stream
->priv
;
851 struct channel
*chan
= buf
->backend
.chan
;
854 * Before doing the actual ring buffer flush, write up to one
855 * packet of metadata in the ring buffer.
857 ret
= lttng_metadata_output_channel(stream
, chan
);
862 case RING_BUFFER_GET_METADATA_VERSION
:
864 struct lttng_metadata_stream
*stream
= filp
->private_data
;
866 return put_u64(stream
->version
, arg
);
868 case RING_BUFFER_METADATA_CACHE_DUMP
:
870 struct lttng_metadata_stream
*stream
= filp
->private_data
;
872 return lttng_metadata_cache_dump(stream
);
877 /* PUT_SUBBUF is the one from lib ring buffer, unmodified. */
879 /* Performing lib ring buffer ioctl after our own. */
880 ret
= lib_ring_buffer_compat_ioctl(filp
, cmd
, arg
, buf
);
885 case RING_BUFFER_PUT_NEXT_SUBBUF
:
887 lttng_metadata_ring_buffer_ioctl_put_next_subbuf(filp
,
900 * This is not used by anonymous file descriptors. This code is left
901 * there if we ever want to implement an inode with open() operation.
904 int lttng_metadata_ring_buffer_open(struct inode
*inode
, struct file
*file
)
906 struct lttng_metadata_stream
*stream
= inode
->i_private
;
907 struct lib_ring_buffer
*buf
= stream
->priv
;
909 file
->private_data
= buf
;
911 * Since life-time of metadata cache differs from that of
912 * session, we need to keep our own reference on the transport.
914 if (!try_module_get(stream
->transport
->owner
)) {
915 printk(KERN_WARNING
"LTT : Can't lock transport module.\n");
918 return lib_ring_buffer_open(inode
, file
, buf
);
922 int lttng_metadata_ring_buffer_release(struct inode
*inode
, struct file
*file
)
924 struct lttng_metadata_stream
*stream
= file
->private_data
;
925 struct lib_ring_buffer
*buf
= stream
->priv
;
927 kref_put(&stream
->metadata_cache
->refcount
, metadata_cache_destroy
);
928 module_put(stream
->transport
->owner
);
929 return lib_ring_buffer_release(inode
, file
, buf
);
933 ssize_t
lttng_metadata_ring_buffer_splice_read(struct file
*in
, loff_t
*ppos
,
934 struct pipe_inode_info
*pipe
, size_t len
,
937 struct lttng_metadata_stream
*stream
= in
->private_data
;
938 struct lib_ring_buffer
*buf
= stream
->priv
;
940 return lib_ring_buffer_splice_read(in
, ppos
, pipe
, len
,
945 int lttng_metadata_ring_buffer_mmap(struct file
*filp
,
946 struct vm_area_struct
*vma
)
948 struct lttng_metadata_stream
*stream
= filp
->private_data
;
949 struct lib_ring_buffer
*buf
= stream
->priv
;
951 return lib_ring_buffer_mmap(filp
, vma
, buf
);
955 const struct file_operations lttng_metadata_ring_buffer_file_operations
= {
956 .owner
= THIS_MODULE
,
957 .open
= lttng_metadata_ring_buffer_open
,
958 .release
= lttng_metadata_ring_buffer_release
,
959 .poll
= lttng_metadata_ring_buffer_poll
,
960 .splice_read
= lttng_metadata_ring_buffer_splice_read
,
961 .mmap
= lttng_metadata_ring_buffer_mmap
,
962 .unlocked_ioctl
= lttng_metadata_ring_buffer_ioctl
,
963 .llseek
= vfs_lib_ring_buffer_no_llseek
,
965 .compat_ioctl
= lttng_metadata_ring_buffer_compat_ioctl
,
970 int lttng_abi_create_stream_fd(struct file
*channel_file
, void *stream_priv
,
971 const struct file_operations
*fops
)
974 struct file
*stream_file
;
976 stream_fd
= lttng_get_unused_fd();
981 stream_file
= anon_inode_getfile("[lttng_stream]", fops
,
982 stream_priv
, O_RDWR
);
983 if (IS_ERR(stream_file
)) {
984 ret
= PTR_ERR(stream_file
);
988 * OPEN_FMODE, called within anon_inode_getfile/alloc_file, don't honor
989 * FMODE_LSEEK, FMODE_PREAD nor FMODE_PWRITE. We need to read from this
990 * file descriptor, so we set FMODE_PREAD here.
992 stream_file
->f_mode
|= FMODE_PREAD
;
993 fd_install(stream_fd
, stream_file
);
995 * The stream holds a reference to the channel within the generic ring
996 * buffer library, so no need to hold a refcount on the channel and
997 * session files here.
1002 put_unused_fd(stream_fd
);
1008 int lttng_abi_open_stream(struct file
*channel_file
)
1010 struct lttng_channel
*channel
= channel_file
->private_data
;
1011 struct lib_ring_buffer
*buf
;
1015 buf
= channel
->ops
->buffer_read_open(channel
->chan
);
1020 ret
= lttng_abi_create_stream_fd(channel_file
, stream_priv
,
1021 <tng_stream_ring_buffer_file_operations
);
1028 channel
->ops
->buffer_read_close(buf
);
1033 int lttng_abi_open_metadata_stream(struct file
*channel_file
)
1035 struct lttng_channel
*channel
= channel_file
->private_data
;
1036 struct lttng_session
*session
= channel
->session
;
1037 struct lib_ring_buffer
*buf
;
1039 struct lttng_metadata_stream
*metadata_stream
;
1042 buf
= channel
->ops
->buffer_read_open(channel
->chan
);
1046 metadata_stream
= kzalloc(sizeof(struct lttng_metadata_stream
),
1048 if (!metadata_stream
) {
1052 metadata_stream
->metadata_cache
= session
->metadata_cache
;
1053 init_waitqueue_head(&metadata_stream
->read_wait
);
1054 metadata_stream
->priv
= buf
;
1055 stream_priv
= metadata_stream
;
1056 metadata_stream
->transport
= channel
->transport
;
1059 * Since life-time of metadata cache differs from that of
1060 * session, we need to keep our own reference on the transport.
1062 if (!try_module_get(metadata_stream
->transport
->owner
)) {
1063 printk(KERN_WARNING
"LTT : Can't lock transport module.\n");
1068 if (!lttng_kref_get(&session
->metadata_cache
->refcount
)) {
1073 ret
= lttng_abi_create_stream_fd(channel_file
, stream_priv
,
1074 <tng_metadata_ring_buffer_file_operations
);
1078 list_add(&metadata_stream
->list
,
1079 &session
->metadata_cache
->metadata_stream
);
1083 kref_put(&session
->metadata_cache
->refcount
, metadata_cache_destroy
);
1085 module_put(metadata_stream
->transport
->owner
);
1087 kfree(metadata_stream
);
1089 channel
->ops
->buffer_read_close(buf
);
1094 int lttng_abi_create_event(struct file
*channel_file
,
1095 struct lttng_kernel_event
*event_param
)
1097 struct lttng_channel
*channel
= channel_file
->private_data
;
1099 struct file
*event_file
;
1102 event_param
->name
[LTTNG_KERNEL_SYM_NAME_LEN
- 1] = '\0';
1103 switch (event_param
->instrumentation
) {
1104 case LTTNG_KERNEL_KRETPROBE
:
1105 event_param
->u
.kretprobe
.symbol_name
[LTTNG_KERNEL_SYM_NAME_LEN
- 1] = '\0';
1107 case LTTNG_KERNEL_KPROBE
:
1108 event_param
->u
.kprobe
.symbol_name
[LTTNG_KERNEL_SYM_NAME_LEN
- 1] = '\0';
1110 case LTTNG_KERNEL_FUNCTION
:
1111 event_param
->u
.ftrace
.symbol_name
[LTTNG_KERNEL_SYM_NAME_LEN
- 1] = '\0';
1116 event_fd
= lttng_get_unused_fd();
1121 event_file
= anon_inode_getfile("[lttng_event]",
1124 if (IS_ERR(event_file
)) {
1125 ret
= PTR_ERR(event_file
);
1128 /* The event holds a reference on the channel */
1129 if (!atomic_long_add_unless(&channel_file
->f_count
, 1, LONG_MAX
)) {
1131 goto refcount_error
;
1133 if (event_param
->instrumentation
== LTTNG_KERNEL_TRACEPOINT
1134 || event_param
->instrumentation
== LTTNG_KERNEL_SYSCALL
) {
1135 struct lttng_enabler
*enabler
;
1137 if (strutils_is_star_glob_pattern(event_param
->name
)) {
1139 * If the event name is a star globbing pattern,
1140 * we create the special star globbing enabler.
1142 enabler
= lttng_enabler_create(LTTNG_ENABLER_STAR_GLOB
,
1143 event_param
, channel
);
1145 enabler
= lttng_enabler_create(LTTNG_ENABLER_NAME
,
1146 event_param
, channel
);
1150 struct lttng_event
*event
;
1153 * We tolerate no failure path after event creation. It
1154 * will stay invariant for the rest of the session.
1156 event
= lttng_event_create(channel
, event_param
,
1158 event_param
->instrumentation
);
1159 WARN_ON_ONCE(!event
);
1160 if (IS_ERR(event
)) {
1161 ret
= PTR_ERR(event
);
1166 event_file
->private_data
= priv
;
1167 fd_install(event_fd
, event_file
);
1171 atomic_long_dec(&channel_file
->f_count
);
1175 put_unused_fd(event_fd
);
1181 * lttng_channel_ioctl - lttng syscall through ioctl
1187 * This ioctl implements lttng commands:
1188 * LTTNG_KERNEL_STREAM
1189 * Returns an event stream file descriptor or failure.
1190 * (typically, one event stream records events from one CPU)
1191 * LTTNG_KERNEL_EVENT
1192 * Returns an event file descriptor or failure.
1193 * LTTNG_KERNEL_CONTEXT
1194 * Prepend a context field to each event in the channel
1195 * LTTNG_KERNEL_ENABLE
1196 * Enable recording for events in this channel (weak enable)
1197 * LTTNG_KERNEL_DISABLE
1198 * Disable recording for events in this channel (strong disable)
1200 * Channel and event file descriptors also hold a reference on the session.
1203 long lttng_channel_ioctl(struct file
*file
, unsigned int cmd
, unsigned long arg
)
1205 struct lttng_channel
*channel
= file
->private_data
;
1208 case LTTNG_KERNEL_OLD_STREAM
:
1209 case LTTNG_KERNEL_STREAM
:
1210 return lttng_abi_open_stream(file
);
1211 case LTTNG_KERNEL_OLD_EVENT
:
1213 struct lttng_kernel_event
*uevent_param
;
1214 struct lttng_kernel_old_event
*old_uevent_param
;
1217 uevent_param
= kmalloc(sizeof(struct lttng_kernel_event
),
1219 if (!uevent_param
) {
1223 old_uevent_param
= kmalloc(
1224 sizeof(struct lttng_kernel_old_event
),
1226 if (!old_uevent_param
) {
1228 goto old_event_error_free_param
;
1230 if (copy_from_user(old_uevent_param
,
1231 (struct lttng_kernel_old_event __user
*) arg
,
1232 sizeof(struct lttng_kernel_old_event
))) {
1234 goto old_event_error_free_old_param
;
1237 memcpy(uevent_param
->name
, old_uevent_param
->name
,
1238 sizeof(uevent_param
->name
));
1239 uevent_param
->instrumentation
=
1240 old_uevent_param
->instrumentation
;
1242 switch (old_uevent_param
->instrumentation
) {
1243 case LTTNG_KERNEL_KPROBE
:
1244 uevent_param
->u
.kprobe
.addr
=
1245 old_uevent_param
->u
.kprobe
.addr
;
1246 uevent_param
->u
.kprobe
.offset
=
1247 old_uevent_param
->u
.kprobe
.offset
;
1248 memcpy(uevent_param
->u
.kprobe
.symbol_name
,
1249 old_uevent_param
->u
.kprobe
.symbol_name
,
1250 sizeof(uevent_param
->u
.kprobe
.symbol_name
));
1252 case LTTNG_KERNEL_KRETPROBE
:
1253 uevent_param
->u
.kretprobe
.addr
=
1254 old_uevent_param
->u
.kretprobe
.addr
;
1255 uevent_param
->u
.kretprobe
.offset
=
1256 old_uevent_param
->u
.kretprobe
.offset
;
1257 memcpy(uevent_param
->u
.kretprobe
.symbol_name
,
1258 old_uevent_param
->u
.kretprobe
.symbol_name
,
1259 sizeof(uevent_param
->u
.kretprobe
.symbol_name
));
1261 case LTTNG_KERNEL_FUNCTION
:
1262 memcpy(uevent_param
->u
.ftrace
.symbol_name
,
1263 old_uevent_param
->u
.ftrace
.symbol_name
,
1264 sizeof(uevent_param
->u
.ftrace
.symbol_name
));
1269 ret
= lttng_abi_create_event(file
, uevent_param
);
1271 old_event_error_free_old_param
:
1272 kfree(old_uevent_param
);
1273 old_event_error_free_param
:
1274 kfree(uevent_param
);
1278 case LTTNG_KERNEL_EVENT
:
1280 struct lttng_kernel_event uevent_param
;
1282 if (copy_from_user(&uevent_param
,
1283 (struct lttng_kernel_event __user
*) arg
,
1284 sizeof(uevent_param
)))
1286 return lttng_abi_create_event(file
, &uevent_param
);
1288 case LTTNG_KERNEL_OLD_CONTEXT
:
1290 struct lttng_kernel_context
*ucontext_param
;
1291 struct lttng_kernel_old_context
*old_ucontext_param
;
1294 ucontext_param
= kmalloc(sizeof(struct lttng_kernel_context
),
1296 if (!ucontext_param
) {
1300 old_ucontext_param
= kmalloc(sizeof(struct lttng_kernel_old_context
),
1302 if (!old_ucontext_param
) {
1304 goto old_ctx_error_free_param
;
1307 if (copy_from_user(old_ucontext_param
,
1308 (struct lttng_kernel_old_context __user
*) arg
,
1309 sizeof(struct lttng_kernel_old_context
))) {
1311 goto old_ctx_error_free_old_param
;
1313 ucontext_param
->ctx
= old_ucontext_param
->ctx
;
1314 memcpy(ucontext_param
->padding
, old_ucontext_param
->padding
,
1315 sizeof(ucontext_param
->padding
));
1316 /* only type that uses the union */
1317 if (old_ucontext_param
->ctx
== LTTNG_KERNEL_CONTEXT_PERF_COUNTER
) {
1318 ucontext_param
->u
.perf_counter
.type
=
1319 old_ucontext_param
->u
.perf_counter
.type
;
1320 ucontext_param
->u
.perf_counter
.config
=
1321 old_ucontext_param
->u
.perf_counter
.config
;
1322 memcpy(ucontext_param
->u
.perf_counter
.name
,
1323 old_ucontext_param
->u
.perf_counter
.name
,
1324 sizeof(ucontext_param
->u
.perf_counter
.name
));
1327 ret
= lttng_abi_add_context(file
,
1329 &channel
->ctx
, channel
->session
);
1331 old_ctx_error_free_old_param
:
1332 kfree(old_ucontext_param
);
1333 old_ctx_error_free_param
:
1334 kfree(ucontext_param
);
1338 case LTTNG_KERNEL_CONTEXT
:
1340 struct lttng_kernel_context ucontext_param
;
1342 if (copy_from_user(&ucontext_param
,
1343 (struct lttng_kernel_context __user
*) arg
,
1344 sizeof(ucontext_param
)))
1346 return lttng_abi_add_context(file
,
1348 &channel
->ctx
, channel
->session
);
1350 case LTTNG_KERNEL_OLD_ENABLE
:
1351 case LTTNG_KERNEL_ENABLE
:
1352 return lttng_channel_enable(channel
);
1353 case LTTNG_KERNEL_OLD_DISABLE
:
1354 case LTTNG_KERNEL_DISABLE
:
1355 return lttng_channel_disable(channel
);
1356 case LTTNG_KERNEL_SYSCALL_MASK
:
1357 return lttng_channel_syscall_mask(channel
,
1358 (struct lttng_kernel_syscall_mask __user
*) arg
);
1360 return -ENOIOCTLCMD
;
1365 * lttng_metadata_ioctl - lttng syscall through ioctl
1371 * This ioctl implements lttng commands:
1372 * LTTNG_KERNEL_STREAM
1373 * Returns an event stream file descriptor or failure.
1375 * Channel and event file descriptors also hold a reference on the session.
1378 long lttng_metadata_ioctl(struct file
*file
, unsigned int cmd
, unsigned long arg
)
1381 case LTTNG_KERNEL_OLD_STREAM
:
1382 case LTTNG_KERNEL_STREAM
:
1383 return lttng_abi_open_metadata_stream(file
);
1385 return -ENOIOCTLCMD
;
1390 * lttng_channel_poll - lttng stream addition/removal monitoring
1395 unsigned int lttng_channel_poll(struct file
*file
, poll_table
*wait
)
1397 struct lttng_channel
*channel
= file
->private_data
;
1398 unsigned int mask
= 0;
1400 if (file
->f_mode
& FMODE_READ
) {
1401 poll_wait_set_exclusive(wait
);
1402 poll_wait(file
, channel
->ops
->get_hp_wait_queue(channel
->chan
),
1405 if (channel
->ops
->is_disabled(channel
->chan
))
1407 if (channel
->ops
->is_finalized(channel
->chan
))
1409 if (channel
->ops
->buffer_has_read_closed_stream(channel
->chan
))
1410 return POLLIN
| POLLRDNORM
;
1418 int lttng_channel_release(struct inode
*inode
, struct file
*file
)
1420 struct lttng_channel
*channel
= file
->private_data
;
1423 fput(channel
->session
->file
);
1428 int lttng_metadata_channel_release(struct inode
*inode
, struct file
*file
)
1430 struct lttng_channel
*channel
= file
->private_data
;
1433 fput(channel
->session
->file
);
1434 lttng_metadata_channel_destroy(channel
);
1440 static const struct file_operations lttng_channel_fops
= {
1441 .owner
= THIS_MODULE
,
1442 .release
= lttng_channel_release
,
1443 .poll
= lttng_channel_poll
,
1444 .unlocked_ioctl
= lttng_channel_ioctl
,
1445 #ifdef CONFIG_COMPAT
1446 .compat_ioctl
= lttng_channel_ioctl
,
1450 static const struct file_operations lttng_metadata_fops
= {
1451 .owner
= THIS_MODULE
,
1452 .release
= lttng_metadata_channel_release
,
1453 .unlocked_ioctl
= lttng_metadata_ioctl
,
1454 #ifdef CONFIG_COMPAT
1455 .compat_ioctl
= lttng_metadata_ioctl
,
1460 * lttng_event_ioctl - lttng syscall through ioctl
1466 * This ioctl implements lttng commands:
1467 * LTTNG_KERNEL_CONTEXT
1468 * Prepend a context field to each record of this event
1469 * LTTNG_KERNEL_ENABLE
1470 * Enable recording for this event (weak enable)
1471 * LTTNG_KERNEL_DISABLE
1472 * Disable recording for this event (strong disable)
1475 long lttng_event_ioctl(struct file
*file
, unsigned int cmd
, unsigned long arg
)
1477 struct lttng_event
*event
;
1478 struct lttng_enabler
*enabler
;
1479 enum lttng_event_type
*evtype
= file
->private_data
;
1482 case LTTNG_KERNEL_OLD_CONTEXT
:
1484 /* Not implemented */
1487 case LTTNG_KERNEL_CONTEXT
:
1489 /* Not implemented */
1492 case LTTNG_KERNEL_OLD_ENABLE
:
1493 case LTTNG_KERNEL_ENABLE
:
1495 case LTTNG_TYPE_EVENT
:
1496 event
= file
->private_data
;
1497 return lttng_event_enable(event
);
1498 case LTTNG_TYPE_ENABLER
:
1499 enabler
= file
->private_data
;
1500 return lttng_enabler_enable(enabler
);
1505 case LTTNG_KERNEL_OLD_DISABLE
:
1506 case LTTNG_KERNEL_DISABLE
:
1508 case LTTNG_TYPE_EVENT
:
1509 event
= file
->private_data
;
1510 return lttng_event_disable(event
);
1511 case LTTNG_TYPE_ENABLER
:
1512 enabler
= file
->private_data
;
1513 return lttng_enabler_disable(enabler
);
1518 case LTTNG_KERNEL_FILTER
:
1520 case LTTNG_TYPE_EVENT
:
1522 case LTTNG_TYPE_ENABLER
:
1524 enabler
= file
->private_data
;
1525 return lttng_enabler_attach_bytecode(enabler
,
1526 (struct lttng_kernel_filter_bytecode __user
*) arg
);
1532 case LTTNG_KERNEL_ADD_CALLSITE
:
1534 case LTTNG_TYPE_EVENT
:
1535 event
= file
->private_data
;
1536 return lttng_event_add_callsite(event
,
1537 (struct lttng_kernel_event_callsite __user
*) arg
);
1538 case LTTNG_TYPE_ENABLER
:
1542 return -ENOIOCTLCMD
;
1547 int lttng_event_release(struct inode
*inode
, struct file
*file
)
1549 struct lttng_event
*event
;
1550 struct lttng_enabler
*enabler
;
1551 enum lttng_event_type
*evtype
= file
->private_data
;
1557 case LTTNG_TYPE_EVENT
:
1558 event
= file
->private_data
;
1560 fput(event
->chan
->file
);
1562 case LTTNG_TYPE_ENABLER
:
1563 enabler
= file
->private_data
;
1565 fput(enabler
->chan
->file
);
1575 /* TODO: filter control ioctl */
1576 static const struct file_operations lttng_event_fops
= {
1577 .owner
= THIS_MODULE
,
1578 .release
= lttng_event_release
,
1579 .unlocked_ioctl
= lttng_event_ioctl
,
1580 #ifdef CONFIG_COMPAT
1581 .compat_ioctl
= lttng_event_ioctl
,
1585 static int put_u64(uint64_t val
, unsigned long arg
)
1587 return put_user(val
, (uint64_t __user
*) arg
);
1590 static long lttng_stream_ring_buffer_ioctl(struct file
*filp
,
1591 unsigned int cmd
, unsigned long arg
)
1593 struct lib_ring_buffer
*buf
= filp
->private_data
;
1594 struct channel
*chan
= buf
->backend
.chan
;
1595 const struct lib_ring_buffer_config
*config
= &chan
->backend
.config
;
1596 const struct lttng_channel_ops
*ops
= chan
->backend
.priv_ops
;
1599 if (atomic_read(&chan
->record_disabled
))
1603 case LTTNG_RING_BUFFER_GET_TIMESTAMP_BEGIN
:
1607 ret
= ops
->timestamp_begin(config
, buf
, &ts
);
1610 return put_u64(ts
, arg
);
1612 case LTTNG_RING_BUFFER_GET_TIMESTAMP_END
:
1616 ret
= ops
->timestamp_end(config
, buf
, &ts
);
1619 return put_u64(ts
, arg
);
1621 case LTTNG_RING_BUFFER_GET_EVENTS_DISCARDED
:
1625 ret
= ops
->events_discarded(config
, buf
, &ed
);
1628 return put_u64(ed
, arg
);
1630 case LTTNG_RING_BUFFER_GET_CONTENT_SIZE
:
1634 ret
= ops
->content_size(config
, buf
, &cs
);
1637 return put_u64(cs
, arg
);
1639 case LTTNG_RING_BUFFER_GET_PACKET_SIZE
:
1643 ret
= ops
->packet_size(config
, buf
, &ps
);
1646 return put_u64(ps
, arg
);
1648 case LTTNG_RING_BUFFER_GET_STREAM_ID
:
1652 ret
= ops
->stream_id(config
, buf
, &si
);
1655 return put_u64(si
, arg
);
1657 case LTTNG_RING_BUFFER_GET_CURRENT_TIMESTAMP
:
1661 ret
= ops
->current_timestamp(config
, buf
, &ts
);
1664 return put_u64(ts
, arg
);
1666 case LTTNG_RING_BUFFER_GET_SEQ_NUM
:
1670 ret
= ops
->sequence_number(config
, buf
, &seq
);
1673 return put_u64(seq
, arg
);
1675 case LTTNG_RING_BUFFER_INSTANCE_ID
:
1679 ret
= ops
->instance_id(config
, buf
, &id
);
1682 return put_u64(id
, arg
);
1685 return lib_ring_buffer_file_operations
.unlocked_ioctl(filp
,
1693 #ifdef CONFIG_COMPAT
1694 static long lttng_stream_ring_buffer_compat_ioctl(struct file
*filp
,
1695 unsigned int cmd
, unsigned long arg
)
1697 struct lib_ring_buffer
*buf
= filp
->private_data
;
1698 struct channel
*chan
= buf
->backend
.chan
;
1699 const struct lib_ring_buffer_config
*config
= &chan
->backend
.config
;
1700 const struct lttng_channel_ops
*ops
= chan
->backend
.priv_ops
;
1703 if (atomic_read(&chan
->record_disabled
))
1707 case LTTNG_RING_BUFFER_COMPAT_GET_TIMESTAMP_BEGIN
:
1711 ret
= ops
->timestamp_begin(config
, buf
, &ts
);
1714 return put_u64(ts
, arg
);
1716 case LTTNG_RING_BUFFER_COMPAT_GET_TIMESTAMP_END
:
1720 ret
= ops
->timestamp_end(config
, buf
, &ts
);
1723 return put_u64(ts
, arg
);
1725 case LTTNG_RING_BUFFER_COMPAT_GET_EVENTS_DISCARDED
:
1729 ret
= ops
->events_discarded(config
, buf
, &ed
);
1732 return put_u64(ed
, arg
);
1734 case LTTNG_RING_BUFFER_COMPAT_GET_CONTENT_SIZE
:
1738 ret
= ops
->content_size(config
, buf
, &cs
);
1741 return put_u64(cs
, arg
);
1743 case LTTNG_RING_BUFFER_COMPAT_GET_PACKET_SIZE
:
1747 ret
= ops
->packet_size(config
, buf
, &ps
);
1750 return put_u64(ps
, arg
);
1752 case LTTNG_RING_BUFFER_COMPAT_GET_STREAM_ID
:
1756 ret
= ops
->stream_id(config
, buf
, &si
);
1759 return put_u64(si
, arg
);
1761 case LTTNG_RING_BUFFER_GET_CURRENT_TIMESTAMP
:
1765 ret
= ops
->current_timestamp(config
, buf
, &ts
);
1768 return put_u64(ts
, arg
);
1770 case LTTNG_RING_BUFFER_COMPAT_GET_SEQ_NUM
:
1774 ret
= ops
->sequence_number(config
, buf
, &seq
);
1777 return put_u64(seq
, arg
);
1779 case LTTNG_RING_BUFFER_COMPAT_INSTANCE_ID
:
1783 ret
= ops
->instance_id(config
, buf
, &id
);
1786 return put_u64(id
, arg
);
1789 return lib_ring_buffer_file_operations
.compat_ioctl(filp
,
1796 #endif /* CONFIG_COMPAT */
1798 static void lttng_stream_override_ring_buffer_fops(void)
1800 lttng_stream_ring_buffer_file_operations
.owner
= THIS_MODULE
;
1801 lttng_stream_ring_buffer_file_operations
.open
=
1802 lib_ring_buffer_file_operations
.open
;
1803 lttng_stream_ring_buffer_file_operations
.release
=
1804 lib_ring_buffer_file_operations
.release
;
1805 lttng_stream_ring_buffer_file_operations
.poll
=
1806 lib_ring_buffer_file_operations
.poll
;
1807 lttng_stream_ring_buffer_file_operations
.splice_read
=
1808 lib_ring_buffer_file_operations
.splice_read
;
1809 lttng_stream_ring_buffer_file_operations
.mmap
=
1810 lib_ring_buffer_file_operations
.mmap
;
1811 lttng_stream_ring_buffer_file_operations
.unlocked_ioctl
=
1812 lttng_stream_ring_buffer_ioctl
;
1813 lttng_stream_ring_buffer_file_operations
.llseek
=
1814 lib_ring_buffer_file_operations
.llseek
;
1815 #ifdef CONFIG_COMPAT
1816 lttng_stream_ring_buffer_file_operations
.compat_ioctl
=
1817 lttng_stream_ring_buffer_compat_ioctl
;
1821 int __init
lttng_abi_init(void)
1825 wrapper_vmalloc_sync_all();
1828 ret
= lttng_tp_mempool_init();
1833 lttng_proc_dentry
= proc_create_data("lttng", S_IRUSR
| S_IWUSR
, NULL
,
1836 if (!lttng_proc_dentry
) {
1837 printk(KERN_ERR
"Error creating LTTng control file\n");
1841 lttng_stream_override_ring_buffer_fops();
1845 lttng_tp_mempool_destroy();
1846 lttng_clock_unref();
1850 /* No __exit annotation because used by init error path too. */
1851 void lttng_abi_exit(void)
1853 lttng_tp_mempool_destroy();
1854 lttng_clock_unref();
1855 if (lttng_proc_dentry
)
1856 remove_proc_entry("lttng", NULL
);