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
;
517 struct lttng_kernel_channel chan_param
;
518 struct lttng_kernel_old_channel old_chan_param
;
521 case LTTNG_KERNEL_OLD_CHANNEL
:
523 if (copy_from_user(&old_chan_param
,
524 (struct lttng_kernel_old_channel __user
*) arg
,
525 sizeof(struct lttng_kernel_old_channel
)))
527 chan_param
.overwrite
= old_chan_param
.overwrite
;
528 chan_param
.subbuf_size
= old_chan_param
.subbuf_size
;
529 chan_param
.num_subbuf
= old_chan_param
.num_subbuf
;
530 chan_param
.switch_timer_interval
= old_chan_param
.switch_timer_interval
;
531 chan_param
.read_timer_interval
= old_chan_param
.read_timer_interval
;
532 chan_param
.output
= old_chan_param
.output
;
534 return lttng_abi_create_channel(file
, &chan_param
,
537 case LTTNG_KERNEL_CHANNEL
:
539 if (copy_from_user(&chan_param
,
540 (struct lttng_kernel_channel __user
*) arg
,
541 sizeof(struct lttng_kernel_channel
)))
543 return lttng_abi_create_channel(file
, &chan_param
,
546 case LTTNG_KERNEL_OLD_SESSION_START
:
547 case LTTNG_KERNEL_OLD_ENABLE
:
548 case LTTNG_KERNEL_SESSION_START
:
549 case LTTNG_KERNEL_ENABLE
:
550 return lttng_session_enable(session
);
551 case LTTNG_KERNEL_OLD_SESSION_STOP
:
552 case LTTNG_KERNEL_OLD_DISABLE
:
553 case LTTNG_KERNEL_SESSION_STOP
:
554 case LTTNG_KERNEL_DISABLE
:
555 return lttng_session_disable(session
);
556 case LTTNG_KERNEL_OLD_METADATA
:
558 if (copy_from_user(&old_chan_param
,
559 (struct lttng_kernel_old_channel __user
*) arg
,
560 sizeof(struct lttng_kernel_old_channel
)))
562 chan_param
.overwrite
= old_chan_param
.overwrite
;
563 chan_param
.subbuf_size
= old_chan_param
.subbuf_size
;
564 chan_param
.num_subbuf
= old_chan_param
.num_subbuf
;
565 chan_param
.switch_timer_interval
= old_chan_param
.switch_timer_interval
;
566 chan_param
.read_timer_interval
= old_chan_param
.read_timer_interval
;
567 chan_param
.output
= old_chan_param
.output
;
569 return lttng_abi_create_channel(file
, &chan_param
,
572 case LTTNG_KERNEL_METADATA
:
574 if (copy_from_user(&chan_param
,
575 (struct lttng_kernel_channel __user
*) arg
,
576 sizeof(struct lttng_kernel_channel
)))
578 return lttng_abi_create_channel(file
, &chan_param
,
581 case LTTNG_KERNEL_SESSION_TRACK_PID
:
582 return lttng_session_track_pid(session
, (int) arg
);
583 case LTTNG_KERNEL_SESSION_UNTRACK_PID
:
584 return lttng_session_untrack_pid(session
, (int) arg
);
585 case LTTNG_KERNEL_SESSION_LIST_TRACKER_PIDS
:
586 return lttng_session_list_tracker_pids(session
);
587 case LTTNG_KERNEL_SESSION_METADATA_REGEN
:
588 return lttng_session_metadata_regenerate(session
);
589 case LTTNG_KERNEL_SESSION_STATEDUMP
:
590 return lttng_session_statedump(session
);
591 case LTTNG_KERNEL_SESSION_SET_NAME
:
593 struct lttng_kernel_session_name name
;
595 if (copy_from_user(&name
,
596 (struct lttng_kernel_session_name __user
*) arg
,
597 sizeof(struct lttng_kernel_session_name
)))
599 return lttng_abi_session_set_name(session
, &name
);
601 case LTTNG_KERNEL_SESSION_SET_CREATION_TIME
:
603 struct lttng_kernel_session_creation_time time
;
605 if (copy_from_user(&time
,
606 (struct lttng_kernel_session_creation_time __user
*) arg
,
607 sizeof(struct lttng_kernel_session_creation_time
)))
609 return lttng_abi_session_set_creation_time(session
, &time
);
617 * Called when the last file reference is dropped.
619 * Big fat note: channels and events are invariant for the whole session after
620 * their creation. So this session destruction also destroys all channel and
621 * event structures specific to this session (they are not destroyed when their
622 * individual file is released).
625 int lttng_session_release(struct inode
*inode
, struct file
*file
)
627 struct lttng_session
*session
= file
->private_data
;
630 lttng_session_destroy(session
);
634 static const struct file_operations lttng_session_fops
= {
635 .owner
= THIS_MODULE
,
636 .release
= lttng_session_release
,
637 .unlocked_ioctl
= lttng_session_ioctl
,
639 .compat_ioctl
= lttng_session_ioctl
,
644 * lttng_metadata_ring_buffer_poll - LTTng ring buffer poll file operation
648 * Handles the poll operations for the metadata channels.
651 unsigned int lttng_metadata_ring_buffer_poll(struct file
*filp
,
654 struct lttng_metadata_stream
*stream
= filp
->private_data
;
655 struct lib_ring_buffer
*buf
= stream
->priv
;
657 unsigned int mask
= 0;
659 if (filp
->f_mode
& FMODE_READ
) {
660 poll_wait_set_exclusive(wait
);
661 poll_wait(filp
, &stream
->read_wait
, wait
);
663 finalized
= stream
->finalized
;
666 * lib_ring_buffer_is_finalized() contains a smp_rmb()
667 * ordering finalized load before offsets loads.
669 WARN_ON(atomic_long_read(&buf
->active_readers
) != 1);
674 mutex_lock(&stream
->metadata_cache
->lock
);
675 if (stream
->metadata_cache
->metadata_written
>
676 stream
->metadata_out
)
678 mutex_unlock(&stream
->metadata_cache
->lock
);
685 void lttng_metadata_ring_buffer_ioctl_put_next_subbuf(struct file
*filp
,
686 unsigned int cmd
, unsigned long arg
)
688 struct lttng_metadata_stream
*stream
= filp
->private_data
;
690 stream
->metadata_out
= stream
->metadata_in
;
694 * Reset the counter of how much metadata has been consumed to 0. That way,
695 * the consumer receives the content of the metadata cache unchanged. This is
696 * different from the metadata_regenerate where the offset from epoch is
697 * resampled, here we want the exact same content as the last time the metadata
698 * was generated. This command is only possible if all the metadata written
699 * in the cache has been output to the metadata stream to avoid corrupting the
702 * Return 0 on success, a negative value on error.
705 int lttng_metadata_cache_dump(struct lttng_metadata_stream
*stream
)
708 struct lttng_metadata_cache
*cache
= stream
->metadata_cache
;
710 mutex_lock(&cache
->lock
);
711 if (stream
->metadata_out
!= cache
->metadata_written
) {
715 stream
->metadata_out
= 0;
716 stream
->metadata_in
= 0;
717 wake_up_interruptible(&stream
->read_wait
);
721 mutex_unlock(&cache
->lock
);
726 long lttng_metadata_ring_buffer_ioctl(struct file
*filp
,
727 unsigned int cmd
, unsigned long arg
)
730 struct lttng_metadata_stream
*stream
= filp
->private_data
;
731 struct lib_ring_buffer
*buf
= stream
->priv
;
734 case RING_BUFFER_GET_NEXT_SUBBUF
:
736 struct lttng_metadata_stream
*stream
= filp
->private_data
;
737 struct lib_ring_buffer
*buf
= stream
->priv
;
738 struct channel
*chan
= buf
->backend
.chan
;
740 ret
= lttng_metadata_output_channel(stream
, chan
);
742 lib_ring_buffer_switch_slow(buf
, SWITCH_ACTIVE
);
748 case RING_BUFFER_GET_SUBBUF
:
751 * Random access is not allowed for metadata channel.
755 case RING_BUFFER_FLUSH_EMPTY
: /* Fall-through. */
756 case RING_BUFFER_FLUSH
:
758 struct lttng_metadata_stream
*stream
= filp
->private_data
;
759 struct lib_ring_buffer
*buf
= stream
->priv
;
760 struct channel
*chan
= buf
->backend
.chan
;
763 * Before doing the actual ring buffer flush, write up to one
764 * packet of metadata in the ring buffer.
766 ret
= lttng_metadata_output_channel(stream
, chan
);
771 case RING_BUFFER_GET_METADATA_VERSION
:
773 struct lttng_metadata_stream
*stream
= filp
->private_data
;
775 return put_u64(stream
->version
, arg
);
777 case RING_BUFFER_METADATA_CACHE_DUMP
:
779 struct lttng_metadata_stream
*stream
= filp
->private_data
;
781 return lttng_metadata_cache_dump(stream
);
786 /* PUT_SUBBUF is the one from lib ring buffer, unmodified. */
788 /* Performing lib ring buffer ioctl after our own. */
789 ret
= lib_ring_buffer_ioctl(filp
, cmd
, arg
, buf
);
794 case RING_BUFFER_PUT_NEXT_SUBBUF
:
796 lttng_metadata_ring_buffer_ioctl_put_next_subbuf(filp
,
809 long lttng_metadata_ring_buffer_compat_ioctl(struct file
*filp
,
810 unsigned int cmd
, unsigned long arg
)
813 struct lttng_metadata_stream
*stream
= filp
->private_data
;
814 struct lib_ring_buffer
*buf
= stream
->priv
;
817 case RING_BUFFER_GET_NEXT_SUBBUF
:
819 struct lttng_metadata_stream
*stream
= filp
->private_data
;
820 struct lib_ring_buffer
*buf
= stream
->priv
;
821 struct channel
*chan
= buf
->backend
.chan
;
823 ret
= lttng_metadata_output_channel(stream
, chan
);
825 lib_ring_buffer_switch_slow(buf
, SWITCH_ACTIVE
);
831 case RING_BUFFER_GET_SUBBUF
:
834 * Random access is not allowed for metadata channel.
838 case RING_BUFFER_FLUSH_EMPTY
: /* Fall-through. */
839 case RING_BUFFER_FLUSH
:
841 struct lttng_metadata_stream
*stream
= filp
->private_data
;
842 struct lib_ring_buffer
*buf
= stream
->priv
;
843 struct channel
*chan
= buf
->backend
.chan
;
846 * Before doing the actual ring buffer flush, write up to one
847 * packet of metadata in the ring buffer.
849 ret
= lttng_metadata_output_channel(stream
, chan
);
854 case RING_BUFFER_GET_METADATA_VERSION
:
856 struct lttng_metadata_stream
*stream
= filp
->private_data
;
858 return put_u64(stream
->version
, arg
);
860 case RING_BUFFER_METADATA_CACHE_DUMP
:
862 struct lttng_metadata_stream
*stream
= filp
->private_data
;
864 return lttng_metadata_cache_dump(stream
);
869 /* PUT_SUBBUF is the one from lib ring buffer, unmodified. */
871 /* Performing lib ring buffer ioctl after our own. */
872 ret
= lib_ring_buffer_compat_ioctl(filp
, cmd
, arg
, buf
);
877 case RING_BUFFER_PUT_NEXT_SUBBUF
:
879 lttng_metadata_ring_buffer_ioctl_put_next_subbuf(filp
,
892 * This is not used by anonymous file descriptors. This code is left
893 * there if we ever want to implement an inode with open() operation.
896 int lttng_metadata_ring_buffer_open(struct inode
*inode
, struct file
*file
)
898 struct lttng_metadata_stream
*stream
= inode
->i_private
;
899 struct lib_ring_buffer
*buf
= stream
->priv
;
901 file
->private_data
= buf
;
903 * Since life-time of metadata cache differs from that of
904 * session, we need to keep our own reference on the transport.
906 if (!try_module_get(stream
->transport
->owner
)) {
907 printk(KERN_WARNING
"LTT : Can't lock transport module.\n");
910 return lib_ring_buffer_open(inode
, file
, buf
);
914 int lttng_metadata_ring_buffer_release(struct inode
*inode
, struct file
*file
)
916 struct lttng_metadata_stream
*stream
= file
->private_data
;
917 struct lib_ring_buffer
*buf
= stream
->priv
;
919 kref_put(&stream
->metadata_cache
->refcount
, metadata_cache_destroy
);
920 module_put(stream
->transport
->owner
);
921 return lib_ring_buffer_release(inode
, file
, buf
);
925 ssize_t
lttng_metadata_ring_buffer_splice_read(struct file
*in
, loff_t
*ppos
,
926 struct pipe_inode_info
*pipe
, size_t len
,
929 struct lttng_metadata_stream
*stream
= in
->private_data
;
930 struct lib_ring_buffer
*buf
= stream
->priv
;
932 return lib_ring_buffer_splice_read(in
, ppos
, pipe
, len
,
937 int lttng_metadata_ring_buffer_mmap(struct file
*filp
,
938 struct vm_area_struct
*vma
)
940 struct lttng_metadata_stream
*stream
= filp
->private_data
;
941 struct lib_ring_buffer
*buf
= stream
->priv
;
943 return lib_ring_buffer_mmap(filp
, vma
, buf
);
947 const struct file_operations lttng_metadata_ring_buffer_file_operations
= {
948 .owner
= THIS_MODULE
,
949 .open
= lttng_metadata_ring_buffer_open
,
950 .release
= lttng_metadata_ring_buffer_release
,
951 .poll
= lttng_metadata_ring_buffer_poll
,
952 .splice_read
= lttng_metadata_ring_buffer_splice_read
,
953 .mmap
= lttng_metadata_ring_buffer_mmap
,
954 .unlocked_ioctl
= lttng_metadata_ring_buffer_ioctl
,
955 .llseek
= vfs_lib_ring_buffer_no_llseek
,
957 .compat_ioctl
= lttng_metadata_ring_buffer_compat_ioctl
,
962 int lttng_abi_create_stream_fd(struct file
*channel_file
, void *stream_priv
,
963 const struct file_operations
*fops
)
966 struct file
*stream_file
;
968 stream_fd
= lttng_get_unused_fd();
973 stream_file
= anon_inode_getfile("[lttng_stream]", fops
,
974 stream_priv
, O_RDWR
);
975 if (IS_ERR(stream_file
)) {
976 ret
= PTR_ERR(stream_file
);
980 * OPEN_FMODE, called within anon_inode_getfile/alloc_file, don't honor
981 * FMODE_LSEEK, FMODE_PREAD nor FMODE_PWRITE. We need to read from this
982 * file descriptor, so we set FMODE_PREAD here.
984 stream_file
->f_mode
|= FMODE_PREAD
;
985 fd_install(stream_fd
, stream_file
);
987 * The stream holds a reference to the channel within the generic ring
988 * buffer library, so no need to hold a refcount on the channel and
989 * session files here.
994 put_unused_fd(stream_fd
);
1000 int lttng_abi_open_stream(struct file
*channel_file
)
1002 struct lttng_channel
*channel
= channel_file
->private_data
;
1003 struct lib_ring_buffer
*buf
;
1007 buf
= channel
->ops
->buffer_read_open(channel
->chan
);
1012 ret
= lttng_abi_create_stream_fd(channel_file
, stream_priv
,
1013 <tng_stream_ring_buffer_file_operations
);
1020 channel
->ops
->buffer_read_close(buf
);
1025 int lttng_abi_open_metadata_stream(struct file
*channel_file
)
1027 struct lttng_channel
*channel
= channel_file
->private_data
;
1028 struct lttng_session
*session
= channel
->session
;
1029 struct lib_ring_buffer
*buf
;
1031 struct lttng_metadata_stream
*metadata_stream
;
1034 buf
= channel
->ops
->buffer_read_open(channel
->chan
);
1038 metadata_stream
= kzalloc(sizeof(struct lttng_metadata_stream
),
1040 if (!metadata_stream
) {
1044 metadata_stream
->metadata_cache
= session
->metadata_cache
;
1045 init_waitqueue_head(&metadata_stream
->read_wait
);
1046 metadata_stream
->priv
= buf
;
1047 stream_priv
= metadata_stream
;
1048 metadata_stream
->transport
= channel
->transport
;
1051 * Since life-time of metadata cache differs from that of
1052 * session, we need to keep our own reference on the transport.
1054 if (!try_module_get(metadata_stream
->transport
->owner
)) {
1055 printk(KERN_WARNING
"LTT : Can't lock transport module.\n");
1060 if (!lttng_kref_get(&session
->metadata_cache
->refcount
)) {
1065 ret
= lttng_abi_create_stream_fd(channel_file
, stream_priv
,
1066 <tng_metadata_ring_buffer_file_operations
);
1070 list_add(&metadata_stream
->list
,
1071 &session
->metadata_cache
->metadata_stream
);
1075 kref_put(&session
->metadata_cache
->refcount
, metadata_cache_destroy
);
1077 module_put(metadata_stream
->transport
->owner
);
1079 kfree(metadata_stream
);
1081 channel
->ops
->buffer_read_close(buf
);
1086 int lttng_abi_create_event(struct file
*channel_file
,
1087 struct lttng_kernel_event
*event_param
)
1089 struct lttng_channel
*channel
= channel_file
->private_data
;
1091 struct file
*event_file
;
1094 event_param
->name
[LTTNG_KERNEL_SYM_NAME_LEN
- 1] = '\0';
1095 switch (event_param
->instrumentation
) {
1096 case LTTNG_KERNEL_KRETPROBE
:
1097 event_param
->u
.kretprobe
.symbol_name
[LTTNG_KERNEL_SYM_NAME_LEN
- 1] = '\0';
1099 case LTTNG_KERNEL_KPROBE
:
1100 event_param
->u
.kprobe
.symbol_name
[LTTNG_KERNEL_SYM_NAME_LEN
- 1] = '\0';
1102 case LTTNG_KERNEL_FUNCTION
:
1103 event_param
->u
.ftrace
.symbol_name
[LTTNG_KERNEL_SYM_NAME_LEN
- 1] = '\0';
1108 event_fd
= lttng_get_unused_fd();
1113 event_file
= anon_inode_getfile("[lttng_event]",
1116 if (IS_ERR(event_file
)) {
1117 ret
= PTR_ERR(event_file
);
1120 /* The event holds a reference on the channel */
1121 if (!atomic_long_add_unless(&channel_file
->f_count
, 1, LONG_MAX
)) {
1123 goto refcount_error
;
1125 if (event_param
->instrumentation
== LTTNG_KERNEL_TRACEPOINT
1126 || event_param
->instrumentation
== LTTNG_KERNEL_SYSCALL
) {
1127 struct lttng_enabler
*enabler
;
1129 if (strutils_is_star_glob_pattern(event_param
->name
)) {
1131 * If the event name is a star globbing pattern,
1132 * we create the special star globbing enabler.
1134 enabler
= lttng_enabler_create(LTTNG_ENABLER_STAR_GLOB
,
1135 event_param
, channel
);
1137 enabler
= lttng_enabler_create(LTTNG_ENABLER_NAME
,
1138 event_param
, channel
);
1142 struct lttng_event
*event
;
1145 * We tolerate no failure path after event creation. It
1146 * will stay invariant for the rest of the session.
1148 event
= lttng_event_create(channel
, event_param
,
1150 event_param
->instrumentation
);
1151 WARN_ON_ONCE(!event
);
1152 if (IS_ERR(event
)) {
1153 ret
= PTR_ERR(event
);
1158 event_file
->private_data
= priv
;
1159 fd_install(event_fd
, event_file
);
1163 atomic_long_dec(&channel_file
->f_count
);
1167 put_unused_fd(event_fd
);
1173 * lttng_channel_ioctl - lttng syscall through ioctl
1179 * This ioctl implements lttng commands:
1180 * LTTNG_KERNEL_STREAM
1181 * Returns an event stream file descriptor or failure.
1182 * (typically, one event stream records events from one CPU)
1183 * LTTNG_KERNEL_EVENT
1184 * Returns an event file descriptor or failure.
1185 * LTTNG_KERNEL_CONTEXT
1186 * Prepend a context field to each event in the channel
1187 * LTTNG_KERNEL_ENABLE
1188 * Enable recording for events in this channel (weak enable)
1189 * LTTNG_KERNEL_DISABLE
1190 * Disable recording for events in this channel (strong disable)
1192 * Channel and event file descriptors also hold a reference on the session.
1195 long lttng_channel_ioctl(struct file
*file
, unsigned int cmd
, unsigned long arg
)
1197 struct lttng_channel
*channel
= file
->private_data
;
1200 case LTTNG_KERNEL_OLD_STREAM
:
1201 case LTTNG_KERNEL_STREAM
:
1202 return lttng_abi_open_stream(file
);
1203 case LTTNG_KERNEL_OLD_EVENT
:
1205 struct lttng_kernel_event
*uevent_param
;
1206 struct lttng_kernel_old_event
*old_uevent_param
;
1209 uevent_param
= kmalloc(sizeof(struct lttng_kernel_event
),
1211 if (!uevent_param
) {
1215 old_uevent_param
= kmalloc(
1216 sizeof(struct lttng_kernel_old_event
),
1218 if (!old_uevent_param
) {
1220 goto old_event_error_free_param
;
1222 if (copy_from_user(old_uevent_param
,
1223 (struct lttng_kernel_old_event __user
*) arg
,
1224 sizeof(struct lttng_kernel_old_event
))) {
1226 goto old_event_error_free_old_param
;
1229 memcpy(uevent_param
->name
, old_uevent_param
->name
,
1230 sizeof(uevent_param
->name
));
1231 uevent_param
->instrumentation
=
1232 old_uevent_param
->instrumentation
;
1234 switch (old_uevent_param
->instrumentation
) {
1235 case LTTNG_KERNEL_KPROBE
:
1236 uevent_param
->u
.kprobe
.addr
=
1237 old_uevent_param
->u
.kprobe
.addr
;
1238 uevent_param
->u
.kprobe
.offset
=
1239 old_uevent_param
->u
.kprobe
.offset
;
1240 memcpy(uevent_param
->u
.kprobe
.symbol_name
,
1241 old_uevent_param
->u
.kprobe
.symbol_name
,
1242 sizeof(uevent_param
->u
.kprobe
.symbol_name
));
1244 case LTTNG_KERNEL_KRETPROBE
:
1245 uevent_param
->u
.kretprobe
.addr
=
1246 old_uevent_param
->u
.kretprobe
.addr
;
1247 uevent_param
->u
.kretprobe
.offset
=
1248 old_uevent_param
->u
.kretprobe
.offset
;
1249 memcpy(uevent_param
->u
.kretprobe
.symbol_name
,
1250 old_uevent_param
->u
.kretprobe
.symbol_name
,
1251 sizeof(uevent_param
->u
.kretprobe
.symbol_name
));
1253 case LTTNG_KERNEL_FUNCTION
:
1254 memcpy(uevent_param
->u
.ftrace
.symbol_name
,
1255 old_uevent_param
->u
.ftrace
.symbol_name
,
1256 sizeof(uevent_param
->u
.ftrace
.symbol_name
));
1261 ret
= lttng_abi_create_event(file
, uevent_param
);
1263 old_event_error_free_old_param
:
1264 kfree(old_uevent_param
);
1265 old_event_error_free_param
:
1266 kfree(uevent_param
);
1270 case LTTNG_KERNEL_EVENT
:
1272 struct lttng_kernel_event uevent_param
;
1274 if (copy_from_user(&uevent_param
,
1275 (struct lttng_kernel_event __user
*) arg
,
1276 sizeof(uevent_param
)))
1278 return lttng_abi_create_event(file
, &uevent_param
);
1280 case LTTNG_KERNEL_OLD_CONTEXT
:
1282 struct lttng_kernel_context
*ucontext_param
;
1283 struct lttng_kernel_old_context
*old_ucontext_param
;
1286 ucontext_param
= kmalloc(sizeof(struct lttng_kernel_context
),
1288 if (!ucontext_param
) {
1292 old_ucontext_param
= kmalloc(sizeof(struct lttng_kernel_old_context
),
1294 if (!old_ucontext_param
) {
1296 goto old_ctx_error_free_param
;
1299 if (copy_from_user(old_ucontext_param
,
1300 (struct lttng_kernel_old_context __user
*) arg
,
1301 sizeof(struct lttng_kernel_old_context
))) {
1303 goto old_ctx_error_free_old_param
;
1305 ucontext_param
->ctx
= old_ucontext_param
->ctx
;
1306 memcpy(ucontext_param
->padding
, old_ucontext_param
->padding
,
1307 sizeof(ucontext_param
->padding
));
1308 /* only type that uses the union */
1309 if (old_ucontext_param
->ctx
== LTTNG_KERNEL_CONTEXT_PERF_COUNTER
) {
1310 ucontext_param
->u
.perf_counter
.type
=
1311 old_ucontext_param
->u
.perf_counter
.type
;
1312 ucontext_param
->u
.perf_counter
.config
=
1313 old_ucontext_param
->u
.perf_counter
.config
;
1314 memcpy(ucontext_param
->u
.perf_counter
.name
,
1315 old_ucontext_param
->u
.perf_counter
.name
,
1316 sizeof(ucontext_param
->u
.perf_counter
.name
));
1319 ret
= lttng_abi_add_context(file
,
1321 &channel
->ctx
, channel
->session
);
1323 old_ctx_error_free_old_param
:
1324 kfree(old_ucontext_param
);
1325 old_ctx_error_free_param
:
1326 kfree(ucontext_param
);
1330 case LTTNG_KERNEL_CONTEXT
:
1332 struct lttng_kernel_context ucontext_param
;
1334 if (copy_from_user(&ucontext_param
,
1335 (struct lttng_kernel_context __user
*) arg
,
1336 sizeof(ucontext_param
)))
1338 return lttng_abi_add_context(file
,
1340 &channel
->ctx
, channel
->session
);
1342 case LTTNG_KERNEL_OLD_ENABLE
:
1343 case LTTNG_KERNEL_ENABLE
:
1344 return lttng_channel_enable(channel
);
1345 case LTTNG_KERNEL_OLD_DISABLE
:
1346 case LTTNG_KERNEL_DISABLE
:
1347 return lttng_channel_disable(channel
);
1348 case LTTNG_KERNEL_SYSCALL_MASK
:
1349 return lttng_channel_syscall_mask(channel
,
1350 (struct lttng_kernel_syscall_mask __user
*) arg
);
1352 return -ENOIOCTLCMD
;
1357 * lttng_metadata_ioctl - lttng syscall through ioctl
1363 * This ioctl implements lttng commands:
1364 * LTTNG_KERNEL_STREAM
1365 * Returns an event stream file descriptor or failure.
1367 * Channel and event file descriptors also hold a reference on the session.
1370 long lttng_metadata_ioctl(struct file
*file
, unsigned int cmd
, unsigned long arg
)
1373 case LTTNG_KERNEL_OLD_STREAM
:
1374 case LTTNG_KERNEL_STREAM
:
1375 return lttng_abi_open_metadata_stream(file
);
1377 return -ENOIOCTLCMD
;
1382 * lttng_channel_poll - lttng stream addition/removal monitoring
1387 unsigned int lttng_channel_poll(struct file
*file
, poll_table
*wait
)
1389 struct lttng_channel
*channel
= file
->private_data
;
1390 unsigned int mask
= 0;
1392 if (file
->f_mode
& FMODE_READ
) {
1393 poll_wait_set_exclusive(wait
);
1394 poll_wait(file
, channel
->ops
->get_hp_wait_queue(channel
->chan
),
1397 if (channel
->ops
->is_disabled(channel
->chan
))
1399 if (channel
->ops
->is_finalized(channel
->chan
))
1401 if (channel
->ops
->buffer_has_read_closed_stream(channel
->chan
))
1402 return POLLIN
| POLLRDNORM
;
1410 int lttng_channel_release(struct inode
*inode
, struct file
*file
)
1412 struct lttng_channel
*channel
= file
->private_data
;
1415 fput(channel
->session
->file
);
1420 int lttng_metadata_channel_release(struct inode
*inode
, struct file
*file
)
1422 struct lttng_channel
*channel
= file
->private_data
;
1425 fput(channel
->session
->file
);
1426 lttng_metadata_channel_destroy(channel
);
1432 static const struct file_operations lttng_channel_fops
= {
1433 .owner
= THIS_MODULE
,
1434 .release
= lttng_channel_release
,
1435 .poll
= lttng_channel_poll
,
1436 .unlocked_ioctl
= lttng_channel_ioctl
,
1437 #ifdef CONFIG_COMPAT
1438 .compat_ioctl
= lttng_channel_ioctl
,
1442 static const struct file_operations lttng_metadata_fops
= {
1443 .owner
= THIS_MODULE
,
1444 .release
= lttng_metadata_channel_release
,
1445 .unlocked_ioctl
= lttng_metadata_ioctl
,
1446 #ifdef CONFIG_COMPAT
1447 .compat_ioctl
= lttng_metadata_ioctl
,
1452 * lttng_event_ioctl - lttng syscall through ioctl
1458 * This ioctl implements lttng commands:
1459 * LTTNG_KERNEL_CONTEXT
1460 * Prepend a context field to each record of this event
1461 * LTTNG_KERNEL_ENABLE
1462 * Enable recording for this event (weak enable)
1463 * LTTNG_KERNEL_DISABLE
1464 * Disable recording for this event (strong disable)
1467 long lttng_event_ioctl(struct file
*file
, unsigned int cmd
, unsigned long arg
)
1469 struct lttng_event
*event
;
1470 struct lttng_enabler
*enabler
;
1471 enum lttng_event_type
*evtype
= file
->private_data
;
1474 case LTTNG_KERNEL_OLD_CONTEXT
:
1476 /* Not implemented */
1479 case LTTNG_KERNEL_CONTEXT
:
1481 /* Not implemented */
1484 case LTTNG_KERNEL_OLD_ENABLE
:
1485 case LTTNG_KERNEL_ENABLE
:
1487 case LTTNG_TYPE_EVENT
:
1488 event
= file
->private_data
;
1489 return lttng_event_enable(event
);
1490 case LTTNG_TYPE_ENABLER
:
1491 enabler
= file
->private_data
;
1492 return lttng_enabler_enable(enabler
);
1497 case LTTNG_KERNEL_OLD_DISABLE
:
1498 case LTTNG_KERNEL_DISABLE
:
1500 case LTTNG_TYPE_EVENT
:
1501 event
= file
->private_data
;
1502 return lttng_event_disable(event
);
1503 case LTTNG_TYPE_ENABLER
:
1504 enabler
= file
->private_data
;
1505 return lttng_enabler_disable(enabler
);
1510 case LTTNG_KERNEL_FILTER
:
1512 case LTTNG_TYPE_EVENT
:
1514 case LTTNG_TYPE_ENABLER
:
1516 enabler
= file
->private_data
;
1517 return lttng_enabler_attach_bytecode(enabler
,
1518 (struct lttng_kernel_filter_bytecode __user
*) arg
);
1524 case LTTNG_KERNEL_ADD_CALLSITE
:
1526 case LTTNG_TYPE_EVENT
:
1527 event
= file
->private_data
;
1528 return lttng_event_add_callsite(event
,
1529 (struct lttng_kernel_event_callsite __user
*) arg
);
1530 case LTTNG_TYPE_ENABLER
:
1534 return -ENOIOCTLCMD
;
1539 int lttng_event_release(struct inode
*inode
, struct file
*file
)
1541 struct lttng_event
*event
;
1542 struct lttng_enabler
*enabler
;
1543 enum lttng_event_type
*evtype
= file
->private_data
;
1549 case LTTNG_TYPE_EVENT
:
1550 event
= file
->private_data
;
1552 fput(event
->chan
->file
);
1554 case LTTNG_TYPE_ENABLER
:
1555 enabler
= file
->private_data
;
1557 fput(enabler
->chan
->file
);
1567 /* TODO: filter control ioctl */
1568 static const struct file_operations lttng_event_fops
= {
1569 .owner
= THIS_MODULE
,
1570 .release
= lttng_event_release
,
1571 .unlocked_ioctl
= lttng_event_ioctl
,
1572 #ifdef CONFIG_COMPAT
1573 .compat_ioctl
= lttng_event_ioctl
,
1577 static int put_u64(uint64_t val
, unsigned long arg
)
1579 return put_user(val
, (uint64_t __user
*) arg
);
1582 static long lttng_stream_ring_buffer_ioctl(struct file
*filp
,
1583 unsigned int cmd
, unsigned long arg
)
1585 struct lib_ring_buffer
*buf
= filp
->private_data
;
1586 struct channel
*chan
= buf
->backend
.chan
;
1587 const struct lib_ring_buffer_config
*config
= &chan
->backend
.config
;
1588 const struct lttng_channel_ops
*ops
= chan
->backend
.priv_ops
;
1591 if (atomic_read(&chan
->record_disabled
))
1595 case LTTNG_RING_BUFFER_GET_TIMESTAMP_BEGIN
:
1599 ret
= ops
->timestamp_begin(config
, buf
, &ts
);
1602 return put_u64(ts
, arg
);
1604 case LTTNG_RING_BUFFER_GET_TIMESTAMP_END
:
1608 ret
= ops
->timestamp_end(config
, buf
, &ts
);
1611 return put_u64(ts
, arg
);
1613 case LTTNG_RING_BUFFER_GET_EVENTS_DISCARDED
:
1617 ret
= ops
->events_discarded(config
, buf
, &ed
);
1620 return put_u64(ed
, arg
);
1622 case LTTNG_RING_BUFFER_GET_CONTENT_SIZE
:
1626 ret
= ops
->content_size(config
, buf
, &cs
);
1629 return put_u64(cs
, arg
);
1631 case LTTNG_RING_BUFFER_GET_PACKET_SIZE
:
1635 ret
= ops
->packet_size(config
, buf
, &ps
);
1638 return put_u64(ps
, arg
);
1640 case LTTNG_RING_BUFFER_GET_STREAM_ID
:
1644 ret
= ops
->stream_id(config
, buf
, &si
);
1647 return put_u64(si
, arg
);
1649 case LTTNG_RING_BUFFER_GET_CURRENT_TIMESTAMP
:
1653 ret
= ops
->current_timestamp(config
, buf
, &ts
);
1656 return put_u64(ts
, arg
);
1658 case LTTNG_RING_BUFFER_GET_SEQ_NUM
:
1662 ret
= ops
->sequence_number(config
, buf
, &seq
);
1665 return put_u64(seq
, arg
);
1667 case LTTNG_RING_BUFFER_INSTANCE_ID
:
1671 ret
= ops
->instance_id(config
, buf
, &id
);
1674 return put_u64(id
, arg
);
1677 return lib_ring_buffer_file_operations
.unlocked_ioctl(filp
,
1685 #ifdef CONFIG_COMPAT
1686 static long lttng_stream_ring_buffer_compat_ioctl(struct file
*filp
,
1687 unsigned int cmd
, unsigned long arg
)
1689 struct lib_ring_buffer
*buf
= filp
->private_data
;
1690 struct channel
*chan
= buf
->backend
.chan
;
1691 const struct lib_ring_buffer_config
*config
= &chan
->backend
.config
;
1692 const struct lttng_channel_ops
*ops
= chan
->backend
.priv_ops
;
1695 if (atomic_read(&chan
->record_disabled
))
1699 case LTTNG_RING_BUFFER_COMPAT_GET_TIMESTAMP_BEGIN
:
1703 ret
= ops
->timestamp_begin(config
, buf
, &ts
);
1706 return put_u64(ts
, arg
);
1708 case LTTNG_RING_BUFFER_COMPAT_GET_TIMESTAMP_END
:
1712 ret
= ops
->timestamp_end(config
, buf
, &ts
);
1715 return put_u64(ts
, arg
);
1717 case LTTNG_RING_BUFFER_COMPAT_GET_EVENTS_DISCARDED
:
1721 ret
= ops
->events_discarded(config
, buf
, &ed
);
1724 return put_u64(ed
, arg
);
1726 case LTTNG_RING_BUFFER_COMPAT_GET_CONTENT_SIZE
:
1730 ret
= ops
->content_size(config
, buf
, &cs
);
1733 return put_u64(cs
, arg
);
1735 case LTTNG_RING_BUFFER_COMPAT_GET_PACKET_SIZE
:
1739 ret
= ops
->packet_size(config
, buf
, &ps
);
1742 return put_u64(ps
, arg
);
1744 case LTTNG_RING_BUFFER_COMPAT_GET_STREAM_ID
:
1748 ret
= ops
->stream_id(config
, buf
, &si
);
1751 return put_u64(si
, arg
);
1753 case LTTNG_RING_BUFFER_GET_CURRENT_TIMESTAMP
:
1757 ret
= ops
->current_timestamp(config
, buf
, &ts
);
1760 return put_u64(ts
, arg
);
1762 case LTTNG_RING_BUFFER_COMPAT_GET_SEQ_NUM
:
1766 ret
= ops
->sequence_number(config
, buf
, &seq
);
1769 return put_u64(seq
, arg
);
1771 case LTTNG_RING_BUFFER_COMPAT_INSTANCE_ID
:
1775 ret
= ops
->instance_id(config
, buf
, &id
);
1778 return put_u64(id
, arg
);
1781 return lib_ring_buffer_file_operations
.compat_ioctl(filp
,
1788 #endif /* CONFIG_COMPAT */
1790 static void lttng_stream_override_ring_buffer_fops(void)
1792 lttng_stream_ring_buffer_file_operations
.owner
= THIS_MODULE
;
1793 lttng_stream_ring_buffer_file_operations
.open
=
1794 lib_ring_buffer_file_operations
.open
;
1795 lttng_stream_ring_buffer_file_operations
.release
=
1796 lib_ring_buffer_file_operations
.release
;
1797 lttng_stream_ring_buffer_file_operations
.poll
=
1798 lib_ring_buffer_file_operations
.poll
;
1799 lttng_stream_ring_buffer_file_operations
.splice_read
=
1800 lib_ring_buffer_file_operations
.splice_read
;
1801 lttng_stream_ring_buffer_file_operations
.mmap
=
1802 lib_ring_buffer_file_operations
.mmap
;
1803 lttng_stream_ring_buffer_file_operations
.unlocked_ioctl
=
1804 lttng_stream_ring_buffer_ioctl
;
1805 lttng_stream_ring_buffer_file_operations
.llseek
=
1806 lib_ring_buffer_file_operations
.llseek
;
1807 #ifdef CONFIG_COMPAT
1808 lttng_stream_ring_buffer_file_operations
.compat_ioctl
=
1809 lttng_stream_ring_buffer_compat_ioctl
;
1813 int __init
lttng_abi_init(void)
1817 wrapper_vmalloc_sync_all();
1820 ret
= lttng_tp_mempool_init();
1825 lttng_proc_dentry
= proc_create_data("lttng", S_IRUSR
| S_IWUSR
, NULL
,
1828 if (!lttng_proc_dentry
) {
1829 printk(KERN_ERR
"Error creating LTTng control file\n");
1833 lttng_stream_override_ring_buffer_fops();
1837 lttng_tp_mempool_destroy();
1838 lttng_clock_unref();
1842 /* No __exit annotation because used by init error path too. */
1843 void lttng_abi_exit(void)
1845 lttng_tp_mempool_destroy();
1846 lttng_clock_unref();
1847 if (lttng_proc_dentry
)
1848 remove_proc_entry("lttng", NULL
);