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 * lttng_session_ioctl - lttng session fd ioctl
463 * This ioctl implements lttng commands:
464 * LTTNG_KERNEL_CHANNEL
465 * Returns a LTTng channel file descriptor
466 * LTTNG_KERNEL_ENABLE
467 * Enables tracing for a session (weak enable)
468 * LTTNG_KERNEL_DISABLE
469 * Disables tracing for a session (strong disable)
470 * LTTNG_KERNEL_METADATA
471 * Returns a LTTng metadata file descriptor
472 * LTTNG_KERNEL_SESSION_TRACK_PID
473 * Add PID to session tracker
474 * LTTNG_KERNEL_SESSION_UNTRACK_PID
475 * Remove PID from session tracker
477 * The returned channel will be deleted when its file descriptor is closed.
480 long lttng_session_ioctl(struct file
*file
, unsigned int cmd
, unsigned long arg
)
482 struct lttng_session
*session
= file
->private_data
;
485 case LTTNG_KERNEL_OLD_CHANNEL
:
487 struct lttng_kernel_channel chan_param
;
488 struct lttng_kernel_old_channel old_chan_param
;
490 if (copy_from_user(&old_chan_param
,
491 (struct lttng_kernel_old_channel __user
*) arg
,
492 sizeof(struct lttng_kernel_old_channel
)))
494 chan_param
.overwrite
= old_chan_param
.overwrite
;
495 chan_param
.subbuf_size
= old_chan_param
.subbuf_size
;
496 chan_param
.num_subbuf
= old_chan_param
.num_subbuf
;
497 chan_param
.switch_timer_interval
= old_chan_param
.switch_timer_interval
;
498 chan_param
.read_timer_interval
= old_chan_param
.read_timer_interval
;
499 chan_param
.output
= old_chan_param
.output
;
501 return lttng_abi_create_channel(file
, &chan_param
,
504 case LTTNG_KERNEL_CHANNEL
:
506 struct lttng_kernel_channel chan_param
;
508 if (copy_from_user(&chan_param
,
509 (struct lttng_kernel_channel __user
*) arg
,
510 sizeof(struct lttng_kernel_channel
)))
512 return lttng_abi_create_channel(file
, &chan_param
,
515 case LTTNG_KERNEL_OLD_SESSION_START
:
516 case LTTNG_KERNEL_OLD_ENABLE
:
517 case LTTNG_KERNEL_SESSION_START
:
518 case LTTNG_KERNEL_ENABLE
:
519 return lttng_session_enable(session
);
520 case LTTNG_KERNEL_OLD_SESSION_STOP
:
521 case LTTNG_KERNEL_OLD_DISABLE
:
522 case LTTNG_KERNEL_SESSION_STOP
:
523 case LTTNG_KERNEL_DISABLE
:
524 return lttng_session_disable(session
);
525 case LTTNG_KERNEL_OLD_METADATA
:
527 struct lttng_kernel_channel chan_param
;
528 struct lttng_kernel_old_channel old_chan_param
;
530 if (copy_from_user(&old_chan_param
,
531 (struct lttng_kernel_old_channel __user
*) arg
,
532 sizeof(struct lttng_kernel_old_channel
)))
534 chan_param
.overwrite
= old_chan_param
.overwrite
;
535 chan_param
.subbuf_size
= old_chan_param
.subbuf_size
;
536 chan_param
.num_subbuf
= old_chan_param
.num_subbuf
;
537 chan_param
.switch_timer_interval
= old_chan_param
.switch_timer_interval
;
538 chan_param
.read_timer_interval
= old_chan_param
.read_timer_interval
;
539 chan_param
.output
= old_chan_param
.output
;
541 return lttng_abi_create_channel(file
, &chan_param
,
544 case LTTNG_KERNEL_METADATA
:
546 struct lttng_kernel_channel chan_param
;
548 if (copy_from_user(&chan_param
,
549 (struct lttng_kernel_channel __user
*) arg
,
550 sizeof(struct lttng_kernel_channel
)))
552 return lttng_abi_create_channel(file
, &chan_param
,
555 case LTTNG_KERNEL_SESSION_TRACK_PID
:
556 return lttng_session_track_pid(session
, (int) arg
);
557 case LTTNG_KERNEL_SESSION_UNTRACK_PID
:
558 return lttng_session_untrack_pid(session
, (int) arg
);
559 case LTTNG_KERNEL_SESSION_LIST_TRACKER_PIDS
:
560 return lttng_session_list_tracker_pids(session
);
561 case LTTNG_KERNEL_SESSION_METADATA_REGEN
:
562 return lttng_session_metadata_regenerate(session
);
563 case LTTNG_KERNEL_SESSION_STATEDUMP
:
564 return lttng_session_statedump(session
);
571 * Called when the last file reference is dropped.
573 * Big fat note: channels and events are invariant for the whole session after
574 * their creation. So this session destruction also destroys all channel and
575 * event structures specific to this session (they are not destroyed when their
576 * individual file is released).
579 int lttng_session_release(struct inode
*inode
, struct file
*file
)
581 struct lttng_session
*session
= file
->private_data
;
584 lttng_session_destroy(session
);
588 static const struct file_operations lttng_session_fops
= {
589 .owner
= THIS_MODULE
,
590 .release
= lttng_session_release
,
591 .unlocked_ioctl
= lttng_session_ioctl
,
593 .compat_ioctl
= lttng_session_ioctl
,
598 * lttng_metadata_ring_buffer_poll - LTTng ring buffer poll file operation
602 * Handles the poll operations for the metadata channels.
605 unsigned int lttng_metadata_ring_buffer_poll(struct file
*filp
,
608 struct lttng_metadata_stream
*stream
= filp
->private_data
;
609 struct lib_ring_buffer
*buf
= stream
->priv
;
611 unsigned int mask
= 0;
613 if (filp
->f_mode
& FMODE_READ
) {
614 poll_wait_set_exclusive(wait
);
615 poll_wait(filp
, &stream
->read_wait
, wait
);
617 finalized
= stream
->finalized
;
620 * lib_ring_buffer_is_finalized() contains a smp_rmb()
621 * ordering finalized load before offsets loads.
623 WARN_ON(atomic_long_read(&buf
->active_readers
) != 1);
628 mutex_lock(&stream
->metadata_cache
->lock
);
629 if (stream
->metadata_cache
->metadata_written
>
630 stream
->metadata_out
)
632 mutex_unlock(&stream
->metadata_cache
->lock
);
639 void lttng_metadata_ring_buffer_ioctl_put_next_subbuf(struct file
*filp
,
640 unsigned int cmd
, unsigned long arg
)
642 struct lttng_metadata_stream
*stream
= filp
->private_data
;
644 stream
->metadata_out
= stream
->metadata_in
;
648 * Reset the counter of how much metadata has been consumed to 0. That way,
649 * the consumer receives the content of the metadata cache unchanged. This is
650 * different from the metadata_regenerate where the offset from epoch is
651 * resampled, here we want the exact same content as the last time the metadata
652 * was generated. This command is only possible if all the metadata written
653 * in the cache has been output to the metadata stream to avoid corrupting the
656 * Return 0 on success, a negative value on error.
659 int lttng_metadata_cache_dump(struct lttng_metadata_stream
*stream
)
662 struct lttng_metadata_cache
*cache
= stream
->metadata_cache
;
664 mutex_lock(&cache
->lock
);
665 if (stream
->metadata_out
!= cache
->metadata_written
) {
669 stream
->metadata_out
= 0;
670 stream
->metadata_in
= 0;
671 wake_up_interruptible(&stream
->read_wait
);
675 mutex_unlock(&cache
->lock
);
680 long lttng_metadata_ring_buffer_ioctl(struct file
*filp
,
681 unsigned int cmd
, unsigned long arg
)
684 struct lttng_metadata_stream
*stream
= filp
->private_data
;
685 struct lib_ring_buffer
*buf
= stream
->priv
;
688 case RING_BUFFER_GET_NEXT_SUBBUF
:
690 struct lttng_metadata_stream
*stream
= filp
->private_data
;
691 struct lib_ring_buffer
*buf
= stream
->priv
;
692 struct channel
*chan
= buf
->backend
.chan
;
694 ret
= lttng_metadata_output_channel(stream
, chan
);
696 lib_ring_buffer_switch_slow(buf
, SWITCH_ACTIVE
);
702 case RING_BUFFER_GET_SUBBUF
:
705 * Random access is not allowed for metadata channel.
709 case RING_BUFFER_FLUSH_EMPTY
: /* Fall-through. */
710 case RING_BUFFER_FLUSH
:
712 struct lttng_metadata_stream
*stream
= filp
->private_data
;
713 struct lib_ring_buffer
*buf
= stream
->priv
;
714 struct channel
*chan
= buf
->backend
.chan
;
717 * Before doing the actual ring buffer flush, write up to one
718 * packet of metadata in the ring buffer.
720 ret
= lttng_metadata_output_channel(stream
, chan
);
725 case RING_BUFFER_GET_METADATA_VERSION
:
727 struct lttng_metadata_stream
*stream
= filp
->private_data
;
729 return put_u64(stream
->version
, arg
);
731 case RING_BUFFER_METADATA_CACHE_DUMP
:
733 struct lttng_metadata_stream
*stream
= filp
->private_data
;
735 return lttng_metadata_cache_dump(stream
);
740 /* PUT_SUBBUF is the one from lib ring buffer, unmodified. */
742 /* Performing lib ring buffer ioctl after our own. */
743 ret
= lib_ring_buffer_ioctl(filp
, cmd
, arg
, buf
);
748 case RING_BUFFER_PUT_NEXT_SUBBUF
:
750 lttng_metadata_ring_buffer_ioctl_put_next_subbuf(filp
,
763 long lttng_metadata_ring_buffer_compat_ioctl(struct file
*filp
,
764 unsigned int cmd
, unsigned long arg
)
767 struct lttng_metadata_stream
*stream
= filp
->private_data
;
768 struct lib_ring_buffer
*buf
= stream
->priv
;
771 case RING_BUFFER_GET_NEXT_SUBBUF
:
773 struct lttng_metadata_stream
*stream
= filp
->private_data
;
774 struct lib_ring_buffer
*buf
= stream
->priv
;
775 struct channel
*chan
= buf
->backend
.chan
;
777 ret
= lttng_metadata_output_channel(stream
, chan
);
779 lib_ring_buffer_switch_slow(buf
, SWITCH_ACTIVE
);
785 case RING_BUFFER_GET_SUBBUF
:
788 * Random access is not allowed for metadata channel.
792 case RING_BUFFER_FLUSH_EMPTY
: /* Fall-through. */
793 case RING_BUFFER_FLUSH
:
795 struct lttng_metadata_stream
*stream
= filp
->private_data
;
796 struct lib_ring_buffer
*buf
= stream
->priv
;
797 struct channel
*chan
= buf
->backend
.chan
;
800 * Before doing the actual ring buffer flush, write up to one
801 * packet of metadata in the ring buffer.
803 ret
= lttng_metadata_output_channel(stream
, chan
);
808 case RING_BUFFER_GET_METADATA_VERSION
:
810 struct lttng_metadata_stream
*stream
= filp
->private_data
;
812 return put_u64(stream
->version
, arg
);
814 case RING_BUFFER_METADATA_CACHE_DUMP
:
816 struct lttng_metadata_stream
*stream
= filp
->private_data
;
818 return lttng_metadata_cache_dump(stream
);
823 /* PUT_SUBBUF is the one from lib ring buffer, unmodified. */
825 /* Performing lib ring buffer ioctl after our own. */
826 ret
= lib_ring_buffer_compat_ioctl(filp
, cmd
, arg
, buf
);
831 case RING_BUFFER_PUT_NEXT_SUBBUF
:
833 lttng_metadata_ring_buffer_ioctl_put_next_subbuf(filp
,
846 * This is not used by anonymous file descriptors. This code is left
847 * there if we ever want to implement an inode with open() operation.
850 int lttng_metadata_ring_buffer_open(struct inode
*inode
, struct file
*file
)
852 struct lttng_metadata_stream
*stream
= inode
->i_private
;
853 struct lib_ring_buffer
*buf
= stream
->priv
;
855 file
->private_data
= buf
;
857 * Since life-time of metadata cache differs from that of
858 * session, we need to keep our own reference on the transport.
860 if (!try_module_get(stream
->transport
->owner
)) {
861 printk(KERN_WARNING
"LTT : Can't lock transport module.\n");
864 return lib_ring_buffer_open(inode
, file
, buf
);
868 int lttng_metadata_ring_buffer_release(struct inode
*inode
, struct file
*file
)
870 struct lttng_metadata_stream
*stream
= file
->private_data
;
871 struct lib_ring_buffer
*buf
= stream
->priv
;
873 kref_put(&stream
->metadata_cache
->refcount
, metadata_cache_destroy
);
874 module_put(stream
->transport
->owner
);
875 return lib_ring_buffer_release(inode
, file
, buf
);
879 ssize_t
lttng_metadata_ring_buffer_splice_read(struct file
*in
, loff_t
*ppos
,
880 struct pipe_inode_info
*pipe
, size_t len
,
883 struct lttng_metadata_stream
*stream
= in
->private_data
;
884 struct lib_ring_buffer
*buf
= stream
->priv
;
886 return lib_ring_buffer_splice_read(in
, ppos
, pipe
, len
,
891 int lttng_metadata_ring_buffer_mmap(struct file
*filp
,
892 struct vm_area_struct
*vma
)
894 struct lttng_metadata_stream
*stream
= filp
->private_data
;
895 struct lib_ring_buffer
*buf
= stream
->priv
;
897 return lib_ring_buffer_mmap(filp
, vma
, buf
);
901 const struct file_operations lttng_metadata_ring_buffer_file_operations
= {
902 .owner
= THIS_MODULE
,
903 .open
= lttng_metadata_ring_buffer_open
,
904 .release
= lttng_metadata_ring_buffer_release
,
905 .poll
= lttng_metadata_ring_buffer_poll
,
906 .splice_read
= lttng_metadata_ring_buffer_splice_read
,
907 .mmap
= lttng_metadata_ring_buffer_mmap
,
908 .unlocked_ioctl
= lttng_metadata_ring_buffer_ioctl
,
909 .llseek
= vfs_lib_ring_buffer_no_llseek
,
911 .compat_ioctl
= lttng_metadata_ring_buffer_compat_ioctl
,
916 int lttng_abi_create_stream_fd(struct file
*channel_file
, void *stream_priv
,
917 const struct file_operations
*fops
)
920 struct file
*stream_file
;
922 stream_fd
= lttng_get_unused_fd();
927 stream_file
= anon_inode_getfile("[lttng_stream]", fops
,
928 stream_priv
, O_RDWR
);
929 if (IS_ERR(stream_file
)) {
930 ret
= PTR_ERR(stream_file
);
934 * OPEN_FMODE, called within anon_inode_getfile/alloc_file, don't honor
935 * FMODE_LSEEK, FMODE_PREAD nor FMODE_PWRITE. We need to read from this
936 * file descriptor, so we set FMODE_PREAD here.
938 stream_file
->f_mode
|= FMODE_PREAD
;
939 fd_install(stream_fd
, stream_file
);
941 * The stream holds a reference to the channel within the generic ring
942 * buffer library, so no need to hold a refcount on the channel and
943 * session files here.
948 put_unused_fd(stream_fd
);
954 int lttng_abi_open_stream(struct file
*channel_file
)
956 struct lttng_channel
*channel
= channel_file
->private_data
;
957 struct lib_ring_buffer
*buf
;
961 buf
= channel
->ops
->buffer_read_open(channel
->chan
);
966 ret
= lttng_abi_create_stream_fd(channel_file
, stream_priv
,
967 <tng_stream_ring_buffer_file_operations
);
974 channel
->ops
->buffer_read_close(buf
);
979 int lttng_abi_open_metadata_stream(struct file
*channel_file
)
981 struct lttng_channel
*channel
= channel_file
->private_data
;
982 struct lttng_session
*session
= channel
->session
;
983 struct lib_ring_buffer
*buf
;
985 struct lttng_metadata_stream
*metadata_stream
;
988 buf
= channel
->ops
->buffer_read_open(channel
->chan
);
992 metadata_stream
= kzalloc(sizeof(struct lttng_metadata_stream
),
994 if (!metadata_stream
) {
998 metadata_stream
->metadata_cache
= session
->metadata_cache
;
999 init_waitqueue_head(&metadata_stream
->read_wait
);
1000 metadata_stream
->priv
= buf
;
1001 stream_priv
= metadata_stream
;
1002 metadata_stream
->transport
= channel
->transport
;
1005 * Since life-time of metadata cache differs from that of
1006 * session, we need to keep our own reference on the transport.
1008 if (!try_module_get(metadata_stream
->transport
->owner
)) {
1009 printk(KERN_WARNING
"LTT : Can't lock transport module.\n");
1014 if (!lttng_kref_get(&session
->metadata_cache
->refcount
)) {
1019 ret
= lttng_abi_create_stream_fd(channel_file
, stream_priv
,
1020 <tng_metadata_ring_buffer_file_operations
);
1024 list_add(&metadata_stream
->list
,
1025 &session
->metadata_cache
->metadata_stream
);
1029 kref_put(&session
->metadata_cache
->refcount
, metadata_cache_destroy
);
1031 module_put(metadata_stream
->transport
->owner
);
1033 kfree(metadata_stream
);
1035 channel
->ops
->buffer_read_close(buf
);
1040 int lttng_abi_create_event(struct file
*channel_file
,
1041 struct lttng_kernel_event
*event_param
)
1043 struct lttng_channel
*channel
= channel_file
->private_data
;
1045 struct file
*event_file
;
1048 event_param
->name
[LTTNG_KERNEL_SYM_NAME_LEN
- 1] = '\0';
1049 switch (event_param
->instrumentation
) {
1050 case LTTNG_KERNEL_KRETPROBE
:
1051 event_param
->u
.kretprobe
.symbol_name
[LTTNG_KERNEL_SYM_NAME_LEN
- 1] = '\0';
1053 case LTTNG_KERNEL_KPROBE
:
1054 event_param
->u
.kprobe
.symbol_name
[LTTNG_KERNEL_SYM_NAME_LEN
- 1] = '\0';
1056 case LTTNG_KERNEL_FUNCTION
:
1057 event_param
->u
.ftrace
.symbol_name
[LTTNG_KERNEL_SYM_NAME_LEN
- 1] = '\0';
1062 event_fd
= lttng_get_unused_fd();
1067 event_file
= anon_inode_getfile("[lttng_event]",
1070 if (IS_ERR(event_file
)) {
1071 ret
= PTR_ERR(event_file
);
1074 /* The event holds a reference on the channel */
1075 if (!atomic_long_add_unless(&channel_file
->f_count
, 1, LONG_MAX
)) {
1077 goto refcount_error
;
1079 if (event_param
->instrumentation
== LTTNG_KERNEL_TRACEPOINT
1080 || event_param
->instrumentation
== LTTNG_KERNEL_SYSCALL
) {
1081 struct lttng_enabler
*enabler
;
1083 if (strutils_is_star_glob_pattern(event_param
->name
)) {
1085 * If the event name is a star globbing pattern,
1086 * we create the special star globbing enabler.
1088 enabler
= lttng_enabler_create(LTTNG_ENABLER_STAR_GLOB
,
1089 event_param
, channel
);
1091 enabler
= lttng_enabler_create(LTTNG_ENABLER_NAME
,
1092 event_param
, channel
);
1096 struct lttng_event
*event
;
1099 * We tolerate no failure path after event creation. It
1100 * will stay invariant for the rest of the session.
1102 event
= lttng_event_create(channel
, event_param
,
1104 event_param
->instrumentation
);
1105 WARN_ON_ONCE(!event
);
1106 if (IS_ERR(event
)) {
1107 ret
= PTR_ERR(event
);
1112 event_file
->private_data
= priv
;
1113 fd_install(event_fd
, event_file
);
1117 atomic_long_dec(&channel_file
->f_count
);
1121 put_unused_fd(event_fd
);
1127 * lttng_channel_ioctl - lttng syscall through ioctl
1133 * This ioctl implements lttng commands:
1134 * LTTNG_KERNEL_STREAM
1135 * Returns an event stream file descriptor or failure.
1136 * (typically, one event stream records events from one CPU)
1137 * LTTNG_KERNEL_EVENT
1138 * Returns an event file descriptor or failure.
1139 * LTTNG_KERNEL_CONTEXT
1140 * Prepend a context field to each event in the channel
1141 * LTTNG_KERNEL_ENABLE
1142 * Enable recording for events in this channel (weak enable)
1143 * LTTNG_KERNEL_DISABLE
1144 * Disable recording for events in this channel (strong disable)
1146 * Channel and event file descriptors also hold a reference on the session.
1149 long lttng_channel_ioctl(struct file
*file
, unsigned int cmd
, unsigned long arg
)
1151 struct lttng_channel
*channel
= file
->private_data
;
1154 case LTTNG_KERNEL_OLD_STREAM
:
1155 case LTTNG_KERNEL_STREAM
:
1156 return lttng_abi_open_stream(file
);
1157 case LTTNG_KERNEL_OLD_EVENT
:
1159 struct lttng_kernel_event
*uevent_param
;
1160 struct lttng_kernel_old_event
*old_uevent_param
;
1163 uevent_param
= kmalloc(sizeof(struct lttng_kernel_event
),
1165 if (!uevent_param
) {
1169 old_uevent_param
= kmalloc(
1170 sizeof(struct lttng_kernel_old_event
),
1172 if (!old_uevent_param
) {
1174 goto old_event_error_free_param
;
1176 if (copy_from_user(old_uevent_param
,
1177 (struct lttng_kernel_old_event __user
*) arg
,
1178 sizeof(struct lttng_kernel_old_event
))) {
1180 goto old_event_error_free_old_param
;
1183 memcpy(uevent_param
->name
, old_uevent_param
->name
,
1184 sizeof(uevent_param
->name
));
1185 uevent_param
->instrumentation
=
1186 old_uevent_param
->instrumentation
;
1188 switch (old_uevent_param
->instrumentation
) {
1189 case LTTNG_KERNEL_KPROBE
:
1190 uevent_param
->u
.kprobe
.addr
=
1191 old_uevent_param
->u
.kprobe
.addr
;
1192 uevent_param
->u
.kprobe
.offset
=
1193 old_uevent_param
->u
.kprobe
.offset
;
1194 memcpy(uevent_param
->u
.kprobe
.symbol_name
,
1195 old_uevent_param
->u
.kprobe
.symbol_name
,
1196 sizeof(uevent_param
->u
.kprobe
.symbol_name
));
1198 case LTTNG_KERNEL_KRETPROBE
:
1199 uevent_param
->u
.kretprobe
.addr
=
1200 old_uevent_param
->u
.kretprobe
.addr
;
1201 uevent_param
->u
.kretprobe
.offset
=
1202 old_uevent_param
->u
.kretprobe
.offset
;
1203 memcpy(uevent_param
->u
.kretprobe
.symbol_name
,
1204 old_uevent_param
->u
.kretprobe
.symbol_name
,
1205 sizeof(uevent_param
->u
.kretprobe
.symbol_name
));
1207 case LTTNG_KERNEL_FUNCTION
:
1208 memcpy(uevent_param
->u
.ftrace
.symbol_name
,
1209 old_uevent_param
->u
.ftrace
.symbol_name
,
1210 sizeof(uevent_param
->u
.ftrace
.symbol_name
));
1215 ret
= lttng_abi_create_event(file
, uevent_param
);
1217 old_event_error_free_old_param
:
1218 kfree(old_uevent_param
);
1219 old_event_error_free_param
:
1220 kfree(uevent_param
);
1224 case LTTNG_KERNEL_EVENT
:
1226 struct lttng_kernel_event uevent_param
;
1228 if (copy_from_user(&uevent_param
,
1229 (struct lttng_kernel_event __user
*) arg
,
1230 sizeof(uevent_param
)))
1232 return lttng_abi_create_event(file
, &uevent_param
);
1234 case LTTNG_KERNEL_OLD_CONTEXT
:
1236 struct lttng_kernel_context
*ucontext_param
;
1237 struct lttng_kernel_old_context
*old_ucontext_param
;
1240 ucontext_param
= kmalloc(sizeof(struct lttng_kernel_context
),
1242 if (!ucontext_param
) {
1246 old_ucontext_param
= kmalloc(sizeof(struct lttng_kernel_old_context
),
1248 if (!old_ucontext_param
) {
1250 goto old_ctx_error_free_param
;
1253 if (copy_from_user(old_ucontext_param
,
1254 (struct lttng_kernel_old_context __user
*) arg
,
1255 sizeof(struct lttng_kernel_old_context
))) {
1257 goto old_ctx_error_free_old_param
;
1259 ucontext_param
->ctx
= old_ucontext_param
->ctx
;
1260 memcpy(ucontext_param
->padding
, old_ucontext_param
->padding
,
1261 sizeof(ucontext_param
->padding
));
1262 /* only type that uses the union */
1263 if (old_ucontext_param
->ctx
== LTTNG_KERNEL_CONTEXT_PERF_COUNTER
) {
1264 ucontext_param
->u
.perf_counter
.type
=
1265 old_ucontext_param
->u
.perf_counter
.type
;
1266 ucontext_param
->u
.perf_counter
.config
=
1267 old_ucontext_param
->u
.perf_counter
.config
;
1268 memcpy(ucontext_param
->u
.perf_counter
.name
,
1269 old_ucontext_param
->u
.perf_counter
.name
,
1270 sizeof(ucontext_param
->u
.perf_counter
.name
));
1273 ret
= lttng_abi_add_context(file
,
1275 &channel
->ctx
, channel
->session
);
1277 old_ctx_error_free_old_param
:
1278 kfree(old_ucontext_param
);
1279 old_ctx_error_free_param
:
1280 kfree(ucontext_param
);
1284 case LTTNG_KERNEL_CONTEXT
:
1286 struct lttng_kernel_context ucontext_param
;
1288 if (copy_from_user(&ucontext_param
,
1289 (struct lttng_kernel_context __user
*) arg
,
1290 sizeof(ucontext_param
)))
1292 return lttng_abi_add_context(file
,
1294 &channel
->ctx
, channel
->session
);
1296 case LTTNG_KERNEL_OLD_ENABLE
:
1297 case LTTNG_KERNEL_ENABLE
:
1298 return lttng_channel_enable(channel
);
1299 case LTTNG_KERNEL_OLD_DISABLE
:
1300 case LTTNG_KERNEL_DISABLE
:
1301 return lttng_channel_disable(channel
);
1302 case LTTNG_KERNEL_SYSCALL_MASK
:
1303 return lttng_channel_syscall_mask(channel
,
1304 (struct lttng_kernel_syscall_mask __user
*) arg
);
1306 return -ENOIOCTLCMD
;
1311 * lttng_metadata_ioctl - lttng syscall through ioctl
1317 * This ioctl implements lttng commands:
1318 * LTTNG_KERNEL_STREAM
1319 * Returns an event stream file descriptor or failure.
1321 * Channel and event file descriptors also hold a reference on the session.
1324 long lttng_metadata_ioctl(struct file
*file
, unsigned int cmd
, unsigned long arg
)
1327 case LTTNG_KERNEL_OLD_STREAM
:
1328 case LTTNG_KERNEL_STREAM
:
1329 return lttng_abi_open_metadata_stream(file
);
1331 return -ENOIOCTLCMD
;
1336 * lttng_channel_poll - lttng stream addition/removal monitoring
1341 unsigned int lttng_channel_poll(struct file
*file
, poll_table
*wait
)
1343 struct lttng_channel
*channel
= file
->private_data
;
1344 unsigned int mask
= 0;
1346 if (file
->f_mode
& FMODE_READ
) {
1347 poll_wait_set_exclusive(wait
);
1348 poll_wait(file
, channel
->ops
->get_hp_wait_queue(channel
->chan
),
1351 if (channel
->ops
->is_disabled(channel
->chan
))
1353 if (channel
->ops
->is_finalized(channel
->chan
))
1355 if (channel
->ops
->buffer_has_read_closed_stream(channel
->chan
))
1356 return POLLIN
| POLLRDNORM
;
1364 int lttng_channel_release(struct inode
*inode
, struct file
*file
)
1366 struct lttng_channel
*channel
= file
->private_data
;
1369 fput(channel
->session
->file
);
1374 int lttng_metadata_channel_release(struct inode
*inode
, struct file
*file
)
1376 struct lttng_channel
*channel
= file
->private_data
;
1379 fput(channel
->session
->file
);
1380 lttng_metadata_channel_destroy(channel
);
1386 static const struct file_operations lttng_channel_fops
= {
1387 .owner
= THIS_MODULE
,
1388 .release
= lttng_channel_release
,
1389 .poll
= lttng_channel_poll
,
1390 .unlocked_ioctl
= lttng_channel_ioctl
,
1391 #ifdef CONFIG_COMPAT
1392 .compat_ioctl
= lttng_channel_ioctl
,
1396 static const struct file_operations lttng_metadata_fops
= {
1397 .owner
= THIS_MODULE
,
1398 .release
= lttng_metadata_channel_release
,
1399 .unlocked_ioctl
= lttng_metadata_ioctl
,
1400 #ifdef CONFIG_COMPAT
1401 .compat_ioctl
= lttng_metadata_ioctl
,
1406 * lttng_event_ioctl - lttng syscall through ioctl
1412 * This ioctl implements lttng commands:
1413 * LTTNG_KERNEL_CONTEXT
1414 * Prepend a context field to each record of this event
1415 * LTTNG_KERNEL_ENABLE
1416 * Enable recording for this event (weak enable)
1417 * LTTNG_KERNEL_DISABLE
1418 * Disable recording for this event (strong disable)
1421 long lttng_event_ioctl(struct file
*file
, unsigned int cmd
, unsigned long arg
)
1423 struct lttng_event
*event
;
1424 struct lttng_enabler
*enabler
;
1425 enum lttng_event_type
*evtype
= file
->private_data
;
1428 case LTTNG_KERNEL_OLD_CONTEXT
:
1430 /* Not implemented */
1433 case LTTNG_KERNEL_CONTEXT
:
1435 /* Not implemented */
1438 case LTTNG_KERNEL_OLD_ENABLE
:
1439 case LTTNG_KERNEL_ENABLE
:
1441 case LTTNG_TYPE_EVENT
:
1442 event
= file
->private_data
;
1443 return lttng_event_enable(event
);
1444 case LTTNG_TYPE_ENABLER
:
1445 enabler
= file
->private_data
;
1446 return lttng_enabler_enable(enabler
);
1451 case LTTNG_KERNEL_OLD_DISABLE
:
1452 case LTTNG_KERNEL_DISABLE
:
1454 case LTTNG_TYPE_EVENT
:
1455 event
= file
->private_data
;
1456 return lttng_event_disable(event
);
1457 case LTTNG_TYPE_ENABLER
:
1458 enabler
= file
->private_data
;
1459 return lttng_enabler_disable(enabler
);
1464 case LTTNG_KERNEL_FILTER
:
1466 case LTTNG_TYPE_EVENT
:
1468 case LTTNG_TYPE_ENABLER
:
1470 enabler
= file
->private_data
;
1471 return lttng_enabler_attach_bytecode(enabler
,
1472 (struct lttng_kernel_filter_bytecode __user
*) arg
);
1478 case LTTNG_KERNEL_ADD_CALLSITE
:
1480 case LTTNG_TYPE_EVENT
:
1481 event
= file
->private_data
;
1482 return lttng_event_add_callsite(event
,
1483 (struct lttng_kernel_event_callsite __user
*) arg
);
1484 case LTTNG_TYPE_ENABLER
:
1488 return -ENOIOCTLCMD
;
1493 int lttng_event_release(struct inode
*inode
, struct file
*file
)
1495 struct lttng_event
*event
;
1496 struct lttng_enabler
*enabler
;
1497 enum lttng_event_type
*evtype
= file
->private_data
;
1503 case LTTNG_TYPE_EVENT
:
1504 event
= file
->private_data
;
1506 fput(event
->chan
->file
);
1508 case LTTNG_TYPE_ENABLER
:
1509 enabler
= file
->private_data
;
1511 fput(enabler
->chan
->file
);
1521 /* TODO: filter control ioctl */
1522 static const struct file_operations lttng_event_fops
= {
1523 .owner
= THIS_MODULE
,
1524 .release
= lttng_event_release
,
1525 .unlocked_ioctl
= lttng_event_ioctl
,
1526 #ifdef CONFIG_COMPAT
1527 .compat_ioctl
= lttng_event_ioctl
,
1531 static int put_u64(uint64_t val
, unsigned long arg
)
1533 return put_user(val
, (uint64_t __user
*) arg
);
1536 static long lttng_stream_ring_buffer_ioctl(struct file
*filp
,
1537 unsigned int cmd
, unsigned long arg
)
1539 struct lib_ring_buffer
*buf
= filp
->private_data
;
1540 struct channel
*chan
= buf
->backend
.chan
;
1541 const struct lib_ring_buffer_config
*config
= &chan
->backend
.config
;
1542 const struct lttng_channel_ops
*ops
= chan
->backend
.priv_ops
;
1545 if (atomic_read(&chan
->record_disabled
))
1549 case LTTNG_RING_BUFFER_GET_TIMESTAMP_BEGIN
:
1553 ret
= ops
->timestamp_begin(config
, buf
, &ts
);
1556 return put_u64(ts
, arg
);
1558 case LTTNG_RING_BUFFER_GET_TIMESTAMP_END
:
1562 ret
= ops
->timestamp_end(config
, buf
, &ts
);
1565 return put_u64(ts
, arg
);
1567 case LTTNG_RING_BUFFER_GET_EVENTS_DISCARDED
:
1571 ret
= ops
->events_discarded(config
, buf
, &ed
);
1574 return put_u64(ed
, arg
);
1576 case LTTNG_RING_BUFFER_GET_CONTENT_SIZE
:
1580 ret
= ops
->content_size(config
, buf
, &cs
);
1583 return put_u64(cs
, arg
);
1585 case LTTNG_RING_BUFFER_GET_PACKET_SIZE
:
1589 ret
= ops
->packet_size(config
, buf
, &ps
);
1592 return put_u64(ps
, arg
);
1594 case LTTNG_RING_BUFFER_GET_STREAM_ID
:
1598 ret
= ops
->stream_id(config
, buf
, &si
);
1601 return put_u64(si
, arg
);
1603 case LTTNG_RING_BUFFER_GET_CURRENT_TIMESTAMP
:
1607 ret
= ops
->current_timestamp(config
, buf
, &ts
);
1610 return put_u64(ts
, arg
);
1612 case LTTNG_RING_BUFFER_GET_SEQ_NUM
:
1616 ret
= ops
->sequence_number(config
, buf
, &seq
);
1619 return put_u64(seq
, arg
);
1621 case LTTNG_RING_BUFFER_INSTANCE_ID
:
1625 ret
= ops
->instance_id(config
, buf
, &id
);
1628 return put_u64(id
, arg
);
1631 return lib_ring_buffer_file_operations
.unlocked_ioctl(filp
,
1639 #ifdef CONFIG_COMPAT
1640 static long lttng_stream_ring_buffer_compat_ioctl(struct file
*filp
,
1641 unsigned int cmd
, unsigned long arg
)
1643 struct lib_ring_buffer
*buf
= filp
->private_data
;
1644 struct channel
*chan
= buf
->backend
.chan
;
1645 const struct lib_ring_buffer_config
*config
= &chan
->backend
.config
;
1646 const struct lttng_channel_ops
*ops
= chan
->backend
.priv_ops
;
1649 if (atomic_read(&chan
->record_disabled
))
1653 case LTTNG_RING_BUFFER_COMPAT_GET_TIMESTAMP_BEGIN
:
1657 ret
= ops
->timestamp_begin(config
, buf
, &ts
);
1660 return put_u64(ts
, arg
);
1662 case LTTNG_RING_BUFFER_COMPAT_GET_TIMESTAMP_END
:
1666 ret
= ops
->timestamp_end(config
, buf
, &ts
);
1669 return put_u64(ts
, arg
);
1671 case LTTNG_RING_BUFFER_COMPAT_GET_EVENTS_DISCARDED
:
1675 ret
= ops
->events_discarded(config
, buf
, &ed
);
1678 return put_u64(ed
, arg
);
1680 case LTTNG_RING_BUFFER_COMPAT_GET_CONTENT_SIZE
:
1684 ret
= ops
->content_size(config
, buf
, &cs
);
1687 return put_u64(cs
, arg
);
1689 case LTTNG_RING_BUFFER_COMPAT_GET_PACKET_SIZE
:
1693 ret
= ops
->packet_size(config
, buf
, &ps
);
1696 return put_u64(ps
, arg
);
1698 case LTTNG_RING_BUFFER_COMPAT_GET_STREAM_ID
:
1702 ret
= ops
->stream_id(config
, buf
, &si
);
1705 return put_u64(si
, arg
);
1707 case LTTNG_RING_BUFFER_GET_CURRENT_TIMESTAMP
:
1711 ret
= ops
->current_timestamp(config
, buf
, &ts
);
1714 return put_u64(ts
, arg
);
1716 case LTTNG_RING_BUFFER_COMPAT_GET_SEQ_NUM
:
1720 ret
= ops
->sequence_number(config
, buf
, &seq
);
1723 return put_u64(seq
, arg
);
1725 case LTTNG_RING_BUFFER_COMPAT_INSTANCE_ID
:
1729 ret
= ops
->instance_id(config
, buf
, &id
);
1732 return put_u64(id
, arg
);
1735 return lib_ring_buffer_file_operations
.compat_ioctl(filp
,
1742 #endif /* CONFIG_COMPAT */
1744 static void lttng_stream_override_ring_buffer_fops(void)
1746 lttng_stream_ring_buffer_file_operations
.owner
= THIS_MODULE
;
1747 lttng_stream_ring_buffer_file_operations
.open
=
1748 lib_ring_buffer_file_operations
.open
;
1749 lttng_stream_ring_buffer_file_operations
.release
=
1750 lib_ring_buffer_file_operations
.release
;
1751 lttng_stream_ring_buffer_file_operations
.poll
=
1752 lib_ring_buffer_file_operations
.poll
;
1753 lttng_stream_ring_buffer_file_operations
.splice_read
=
1754 lib_ring_buffer_file_operations
.splice_read
;
1755 lttng_stream_ring_buffer_file_operations
.mmap
=
1756 lib_ring_buffer_file_operations
.mmap
;
1757 lttng_stream_ring_buffer_file_operations
.unlocked_ioctl
=
1758 lttng_stream_ring_buffer_ioctl
;
1759 lttng_stream_ring_buffer_file_operations
.llseek
=
1760 lib_ring_buffer_file_operations
.llseek
;
1761 #ifdef CONFIG_COMPAT
1762 lttng_stream_ring_buffer_file_operations
.compat_ioctl
=
1763 lttng_stream_ring_buffer_compat_ioctl
;
1767 int __init
lttng_abi_init(void)
1771 wrapper_vmalloc_sync_all();
1774 ret
= lttng_tp_mempool_init();
1779 lttng_proc_dentry
= proc_create_data("lttng", S_IRUSR
| S_IWUSR
, NULL
,
1782 if (!lttng_proc_dentry
) {
1783 printk(KERN_ERR
"Error creating LTTng control file\n");
1787 lttng_stream_override_ring_buffer_fops();
1791 lttng_tp_mempool_destroy();
1792 lttng_clock_unref();
1796 /* No __exit annotation because used by init error path too. */
1797 void lttng_abi_exit(void)
1799 lttng_tp_mempool_destroy();
1800 lttng_clock_unref();
1801 if (lttng_proc_dentry
)
1802 remove_proc_entry("lttng", NULL
);