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 * lttng_session_ioctl - lttng session fd ioctl
480 * This ioctl implements lttng commands:
481 * LTTNG_KERNEL_CHANNEL
482 * Returns a LTTng channel file descriptor
483 * LTTNG_KERNEL_ENABLE
484 * Enables tracing for a session (weak enable)
485 * LTTNG_KERNEL_DISABLE
486 * Disables tracing for a session (strong disable)
487 * LTTNG_KERNEL_METADATA
488 * Returns a LTTng metadata file descriptor
489 * LTTNG_KERNEL_SESSION_TRACK_PID
490 * Add PID to session tracker
491 * LTTNG_KERNEL_SESSION_UNTRACK_PID
492 * Remove PID from session tracker
494 * The returned channel will be deleted when its file descriptor is closed.
497 long lttng_session_ioctl(struct file
*file
, unsigned int cmd
, unsigned long arg
)
499 struct lttng_session
*session
= file
->private_data
;
502 case LTTNG_KERNEL_OLD_CHANNEL
:
504 struct lttng_kernel_channel chan_param
;
505 struct lttng_kernel_old_channel old_chan_param
;
507 if (copy_from_user(&old_chan_param
,
508 (struct lttng_kernel_old_channel __user
*) arg
,
509 sizeof(struct lttng_kernel_old_channel
)))
511 chan_param
.overwrite
= old_chan_param
.overwrite
;
512 chan_param
.subbuf_size
= old_chan_param
.subbuf_size
;
513 chan_param
.num_subbuf
= old_chan_param
.num_subbuf
;
514 chan_param
.switch_timer_interval
= old_chan_param
.switch_timer_interval
;
515 chan_param
.read_timer_interval
= old_chan_param
.read_timer_interval
;
516 chan_param
.output
= old_chan_param
.output
;
518 return lttng_abi_create_channel(file
, &chan_param
,
521 case LTTNG_KERNEL_CHANNEL
:
523 struct lttng_kernel_channel chan_param
;
525 if (copy_from_user(&chan_param
,
526 (struct lttng_kernel_channel __user
*) arg
,
527 sizeof(struct lttng_kernel_channel
)))
529 return lttng_abi_create_channel(file
, &chan_param
,
532 case LTTNG_KERNEL_OLD_SESSION_START
:
533 case LTTNG_KERNEL_OLD_ENABLE
:
534 case LTTNG_KERNEL_SESSION_START
:
535 case LTTNG_KERNEL_ENABLE
:
536 return lttng_session_enable(session
);
537 case LTTNG_KERNEL_OLD_SESSION_STOP
:
538 case LTTNG_KERNEL_OLD_DISABLE
:
539 case LTTNG_KERNEL_SESSION_STOP
:
540 case LTTNG_KERNEL_DISABLE
:
541 return lttng_session_disable(session
);
542 case LTTNG_KERNEL_OLD_METADATA
:
544 struct lttng_kernel_channel chan_param
;
545 struct lttng_kernel_old_channel old_chan_param
;
547 if (copy_from_user(&old_chan_param
,
548 (struct lttng_kernel_old_channel __user
*) arg
,
549 sizeof(struct lttng_kernel_old_channel
)))
551 chan_param
.overwrite
= old_chan_param
.overwrite
;
552 chan_param
.subbuf_size
= old_chan_param
.subbuf_size
;
553 chan_param
.num_subbuf
= old_chan_param
.num_subbuf
;
554 chan_param
.switch_timer_interval
= old_chan_param
.switch_timer_interval
;
555 chan_param
.read_timer_interval
= old_chan_param
.read_timer_interval
;
556 chan_param
.output
= old_chan_param
.output
;
558 return lttng_abi_create_channel(file
, &chan_param
,
561 case LTTNG_KERNEL_METADATA
:
563 struct lttng_kernel_channel chan_param
;
565 if (copy_from_user(&chan_param
,
566 (struct lttng_kernel_channel __user
*) arg
,
567 sizeof(struct lttng_kernel_channel
)))
569 return lttng_abi_create_channel(file
, &chan_param
,
572 case LTTNG_KERNEL_SESSION_TRACK_PID
:
573 return lttng_session_track_pid(session
, (int) arg
);
574 case LTTNG_KERNEL_SESSION_UNTRACK_PID
:
575 return lttng_session_untrack_pid(session
, (int) arg
);
576 case LTTNG_KERNEL_SESSION_LIST_TRACKER_PIDS
:
577 return lttng_session_list_tracker_pids(session
);
578 case LTTNG_KERNEL_SESSION_METADATA_REGEN
:
579 return lttng_session_metadata_regenerate(session
);
580 case LTTNG_KERNEL_SESSION_STATEDUMP
:
581 return lttng_session_statedump(session
);
582 case LTTNG_KERNEL_SESSION_SET_NAME
:
584 struct lttng_kernel_session_name name
;
586 if (copy_from_user(&name
,
587 (struct lttng_kernel_session_name __user
*) arg
,
588 sizeof(struct lttng_kernel_session_name
)))
590 return lttng_abi_session_set_name(session
, &name
);
598 * Called when the last file reference is dropped.
600 * Big fat note: channels and events are invariant for the whole session after
601 * their creation. So this session destruction also destroys all channel and
602 * event structures specific to this session (they are not destroyed when their
603 * individual file is released).
606 int lttng_session_release(struct inode
*inode
, struct file
*file
)
608 struct lttng_session
*session
= file
->private_data
;
611 lttng_session_destroy(session
);
615 static const struct file_operations lttng_session_fops
= {
616 .owner
= THIS_MODULE
,
617 .release
= lttng_session_release
,
618 .unlocked_ioctl
= lttng_session_ioctl
,
620 .compat_ioctl
= lttng_session_ioctl
,
625 * lttng_metadata_ring_buffer_poll - LTTng ring buffer poll file operation
629 * Handles the poll operations for the metadata channels.
632 unsigned int lttng_metadata_ring_buffer_poll(struct file
*filp
,
635 struct lttng_metadata_stream
*stream
= filp
->private_data
;
636 struct lib_ring_buffer
*buf
= stream
->priv
;
638 unsigned int mask
= 0;
640 if (filp
->f_mode
& FMODE_READ
) {
641 poll_wait_set_exclusive(wait
);
642 poll_wait(filp
, &stream
->read_wait
, wait
);
644 finalized
= stream
->finalized
;
647 * lib_ring_buffer_is_finalized() contains a smp_rmb()
648 * ordering finalized load before offsets loads.
650 WARN_ON(atomic_long_read(&buf
->active_readers
) != 1);
655 mutex_lock(&stream
->metadata_cache
->lock
);
656 if (stream
->metadata_cache
->metadata_written
>
657 stream
->metadata_out
)
659 mutex_unlock(&stream
->metadata_cache
->lock
);
666 void lttng_metadata_ring_buffer_ioctl_put_next_subbuf(struct file
*filp
,
667 unsigned int cmd
, unsigned long arg
)
669 struct lttng_metadata_stream
*stream
= filp
->private_data
;
671 stream
->metadata_out
= stream
->metadata_in
;
675 * Reset the counter of how much metadata has been consumed to 0. That way,
676 * the consumer receives the content of the metadata cache unchanged. This is
677 * different from the metadata_regenerate where the offset from epoch is
678 * resampled, here we want the exact same content as the last time the metadata
679 * was generated. This command is only possible if all the metadata written
680 * in the cache has been output to the metadata stream to avoid corrupting the
683 * Return 0 on success, a negative value on error.
686 int lttng_metadata_cache_dump(struct lttng_metadata_stream
*stream
)
689 struct lttng_metadata_cache
*cache
= stream
->metadata_cache
;
691 mutex_lock(&cache
->lock
);
692 if (stream
->metadata_out
!= cache
->metadata_written
) {
696 stream
->metadata_out
= 0;
697 stream
->metadata_in
= 0;
698 wake_up_interruptible(&stream
->read_wait
);
702 mutex_unlock(&cache
->lock
);
707 long lttng_metadata_ring_buffer_ioctl(struct file
*filp
,
708 unsigned int cmd
, unsigned long arg
)
711 struct lttng_metadata_stream
*stream
= filp
->private_data
;
712 struct lib_ring_buffer
*buf
= stream
->priv
;
715 case RING_BUFFER_GET_NEXT_SUBBUF
:
717 struct lttng_metadata_stream
*stream
= filp
->private_data
;
718 struct lib_ring_buffer
*buf
= stream
->priv
;
719 struct channel
*chan
= buf
->backend
.chan
;
721 ret
= lttng_metadata_output_channel(stream
, chan
);
723 lib_ring_buffer_switch_slow(buf
, SWITCH_ACTIVE
);
729 case RING_BUFFER_GET_SUBBUF
:
732 * Random access is not allowed for metadata channel.
736 case RING_BUFFER_FLUSH_EMPTY
: /* Fall-through. */
737 case RING_BUFFER_FLUSH
:
739 struct lttng_metadata_stream
*stream
= filp
->private_data
;
740 struct lib_ring_buffer
*buf
= stream
->priv
;
741 struct channel
*chan
= buf
->backend
.chan
;
744 * Before doing the actual ring buffer flush, write up to one
745 * packet of metadata in the ring buffer.
747 ret
= lttng_metadata_output_channel(stream
, chan
);
752 case RING_BUFFER_GET_METADATA_VERSION
:
754 struct lttng_metadata_stream
*stream
= filp
->private_data
;
756 return put_u64(stream
->version
, arg
);
758 case RING_BUFFER_METADATA_CACHE_DUMP
:
760 struct lttng_metadata_stream
*stream
= filp
->private_data
;
762 return lttng_metadata_cache_dump(stream
);
767 /* PUT_SUBBUF is the one from lib ring buffer, unmodified. */
769 /* Performing lib ring buffer ioctl after our own. */
770 ret
= lib_ring_buffer_ioctl(filp
, cmd
, arg
, buf
);
775 case RING_BUFFER_PUT_NEXT_SUBBUF
:
777 lttng_metadata_ring_buffer_ioctl_put_next_subbuf(filp
,
790 long lttng_metadata_ring_buffer_compat_ioctl(struct file
*filp
,
791 unsigned int cmd
, unsigned long arg
)
794 struct lttng_metadata_stream
*stream
= filp
->private_data
;
795 struct lib_ring_buffer
*buf
= stream
->priv
;
798 case RING_BUFFER_GET_NEXT_SUBBUF
:
800 struct lttng_metadata_stream
*stream
= filp
->private_data
;
801 struct lib_ring_buffer
*buf
= stream
->priv
;
802 struct channel
*chan
= buf
->backend
.chan
;
804 ret
= lttng_metadata_output_channel(stream
, chan
);
806 lib_ring_buffer_switch_slow(buf
, SWITCH_ACTIVE
);
812 case RING_BUFFER_GET_SUBBUF
:
815 * Random access is not allowed for metadata channel.
819 case RING_BUFFER_FLUSH_EMPTY
: /* Fall-through. */
820 case RING_BUFFER_FLUSH
:
822 struct lttng_metadata_stream
*stream
= filp
->private_data
;
823 struct lib_ring_buffer
*buf
= stream
->priv
;
824 struct channel
*chan
= buf
->backend
.chan
;
827 * Before doing the actual ring buffer flush, write up to one
828 * packet of metadata in the ring buffer.
830 ret
= lttng_metadata_output_channel(stream
, chan
);
835 case RING_BUFFER_GET_METADATA_VERSION
:
837 struct lttng_metadata_stream
*stream
= filp
->private_data
;
839 return put_u64(stream
->version
, arg
);
841 case RING_BUFFER_METADATA_CACHE_DUMP
:
843 struct lttng_metadata_stream
*stream
= filp
->private_data
;
845 return lttng_metadata_cache_dump(stream
);
850 /* PUT_SUBBUF is the one from lib ring buffer, unmodified. */
852 /* Performing lib ring buffer ioctl after our own. */
853 ret
= lib_ring_buffer_compat_ioctl(filp
, cmd
, arg
, buf
);
858 case RING_BUFFER_PUT_NEXT_SUBBUF
:
860 lttng_metadata_ring_buffer_ioctl_put_next_subbuf(filp
,
873 * This is not used by anonymous file descriptors. This code is left
874 * there if we ever want to implement an inode with open() operation.
877 int lttng_metadata_ring_buffer_open(struct inode
*inode
, struct file
*file
)
879 struct lttng_metadata_stream
*stream
= inode
->i_private
;
880 struct lib_ring_buffer
*buf
= stream
->priv
;
882 file
->private_data
= buf
;
884 * Since life-time of metadata cache differs from that of
885 * session, we need to keep our own reference on the transport.
887 if (!try_module_get(stream
->transport
->owner
)) {
888 printk(KERN_WARNING
"LTT : Can't lock transport module.\n");
891 return lib_ring_buffer_open(inode
, file
, buf
);
895 int lttng_metadata_ring_buffer_release(struct inode
*inode
, struct file
*file
)
897 struct lttng_metadata_stream
*stream
= file
->private_data
;
898 struct lib_ring_buffer
*buf
= stream
->priv
;
900 kref_put(&stream
->metadata_cache
->refcount
, metadata_cache_destroy
);
901 module_put(stream
->transport
->owner
);
902 return lib_ring_buffer_release(inode
, file
, buf
);
906 ssize_t
lttng_metadata_ring_buffer_splice_read(struct file
*in
, loff_t
*ppos
,
907 struct pipe_inode_info
*pipe
, size_t len
,
910 struct lttng_metadata_stream
*stream
= in
->private_data
;
911 struct lib_ring_buffer
*buf
= stream
->priv
;
913 return lib_ring_buffer_splice_read(in
, ppos
, pipe
, len
,
918 int lttng_metadata_ring_buffer_mmap(struct file
*filp
,
919 struct vm_area_struct
*vma
)
921 struct lttng_metadata_stream
*stream
= filp
->private_data
;
922 struct lib_ring_buffer
*buf
= stream
->priv
;
924 return lib_ring_buffer_mmap(filp
, vma
, buf
);
928 const struct file_operations lttng_metadata_ring_buffer_file_operations
= {
929 .owner
= THIS_MODULE
,
930 .open
= lttng_metadata_ring_buffer_open
,
931 .release
= lttng_metadata_ring_buffer_release
,
932 .poll
= lttng_metadata_ring_buffer_poll
,
933 .splice_read
= lttng_metadata_ring_buffer_splice_read
,
934 .mmap
= lttng_metadata_ring_buffer_mmap
,
935 .unlocked_ioctl
= lttng_metadata_ring_buffer_ioctl
,
936 .llseek
= vfs_lib_ring_buffer_no_llseek
,
938 .compat_ioctl
= lttng_metadata_ring_buffer_compat_ioctl
,
943 int lttng_abi_create_stream_fd(struct file
*channel_file
, void *stream_priv
,
944 const struct file_operations
*fops
)
947 struct file
*stream_file
;
949 stream_fd
= lttng_get_unused_fd();
954 stream_file
= anon_inode_getfile("[lttng_stream]", fops
,
955 stream_priv
, O_RDWR
);
956 if (IS_ERR(stream_file
)) {
957 ret
= PTR_ERR(stream_file
);
961 * OPEN_FMODE, called within anon_inode_getfile/alloc_file, don't honor
962 * FMODE_LSEEK, FMODE_PREAD nor FMODE_PWRITE. We need to read from this
963 * file descriptor, so we set FMODE_PREAD here.
965 stream_file
->f_mode
|= FMODE_PREAD
;
966 fd_install(stream_fd
, stream_file
);
968 * The stream holds a reference to the channel within the generic ring
969 * buffer library, so no need to hold a refcount on the channel and
970 * session files here.
975 put_unused_fd(stream_fd
);
981 int lttng_abi_open_stream(struct file
*channel_file
)
983 struct lttng_channel
*channel
= channel_file
->private_data
;
984 struct lib_ring_buffer
*buf
;
988 buf
= channel
->ops
->buffer_read_open(channel
->chan
);
993 ret
= lttng_abi_create_stream_fd(channel_file
, stream_priv
,
994 <tng_stream_ring_buffer_file_operations
);
1001 channel
->ops
->buffer_read_close(buf
);
1006 int lttng_abi_open_metadata_stream(struct file
*channel_file
)
1008 struct lttng_channel
*channel
= channel_file
->private_data
;
1009 struct lttng_session
*session
= channel
->session
;
1010 struct lib_ring_buffer
*buf
;
1012 struct lttng_metadata_stream
*metadata_stream
;
1015 buf
= channel
->ops
->buffer_read_open(channel
->chan
);
1019 metadata_stream
= kzalloc(sizeof(struct lttng_metadata_stream
),
1021 if (!metadata_stream
) {
1025 metadata_stream
->metadata_cache
= session
->metadata_cache
;
1026 init_waitqueue_head(&metadata_stream
->read_wait
);
1027 metadata_stream
->priv
= buf
;
1028 stream_priv
= metadata_stream
;
1029 metadata_stream
->transport
= channel
->transport
;
1032 * Since life-time of metadata cache differs from that of
1033 * session, we need to keep our own reference on the transport.
1035 if (!try_module_get(metadata_stream
->transport
->owner
)) {
1036 printk(KERN_WARNING
"LTT : Can't lock transport module.\n");
1041 if (!lttng_kref_get(&session
->metadata_cache
->refcount
)) {
1046 ret
= lttng_abi_create_stream_fd(channel_file
, stream_priv
,
1047 <tng_metadata_ring_buffer_file_operations
);
1051 list_add(&metadata_stream
->list
,
1052 &session
->metadata_cache
->metadata_stream
);
1056 kref_put(&session
->metadata_cache
->refcount
, metadata_cache_destroy
);
1058 module_put(metadata_stream
->transport
->owner
);
1060 kfree(metadata_stream
);
1062 channel
->ops
->buffer_read_close(buf
);
1067 int lttng_abi_create_event(struct file
*channel_file
,
1068 struct lttng_kernel_event
*event_param
)
1070 struct lttng_channel
*channel
= channel_file
->private_data
;
1072 struct file
*event_file
;
1075 event_param
->name
[LTTNG_KERNEL_SYM_NAME_LEN
- 1] = '\0';
1076 switch (event_param
->instrumentation
) {
1077 case LTTNG_KERNEL_KRETPROBE
:
1078 event_param
->u
.kretprobe
.symbol_name
[LTTNG_KERNEL_SYM_NAME_LEN
- 1] = '\0';
1080 case LTTNG_KERNEL_KPROBE
:
1081 event_param
->u
.kprobe
.symbol_name
[LTTNG_KERNEL_SYM_NAME_LEN
- 1] = '\0';
1083 case LTTNG_KERNEL_FUNCTION
:
1084 event_param
->u
.ftrace
.symbol_name
[LTTNG_KERNEL_SYM_NAME_LEN
- 1] = '\0';
1089 event_fd
= lttng_get_unused_fd();
1094 event_file
= anon_inode_getfile("[lttng_event]",
1097 if (IS_ERR(event_file
)) {
1098 ret
= PTR_ERR(event_file
);
1101 /* The event holds a reference on the channel */
1102 if (!atomic_long_add_unless(&channel_file
->f_count
, 1, LONG_MAX
)) {
1104 goto refcount_error
;
1106 if (event_param
->instrumentation
== LTTNG_KERNEL_TRACEPOINT
1107 || event_param
->instrumentation
== LTTNG_KERNEL_SYSCALL
) {
1108 struct lttng_enabler
*enabler
;
1110 if (strutils_is_star_glob_pattern(event_param
->name
)) {
1112 * If the event name is a star globbing pattern,
1113 * we create the special star globbing enabler.
1115 enabler
= lttng_enabler_create(LTTNG_ENABLER_STAR_GLOB
,
1116 event_param
, channel
);
1118 enabler
= lttng_enabler_create(LTTNG_ENABLER_NAME
,
1119 event_param
, channel
);
1123 struct lttng_event
*event
;
1126 * We tolerate no failure path after event creation. It
1127 * will stay invariant for the rest of the session.
1129 event
= lttng_event_create(channel
, event_param
,
1131 event_param
->instrumentation
);
1132 WARN_ON_ONCE(!event
);
1133 if (IS_ERR(event
)) {
1134 ret
= PTR_ERR(event
);
1139 event_file
->private_data
= priv
;
1140 fd_install(event_fd
, event_file
);
1144 atomic_long_dec(&channel_file
->f_count
);
1148 put_unused_fd(event_fd
);
1154 * lttng_channel_ioctl - lttng syscall through ioctl
1160 * This ioctl implements lttng commands:
1161 * LTTNG_KERNEL_STREAM
1162 * Returns an event stream file descriptor or failure.
1163 * (typically, one event stream records events from one CPU)
1164 * LTTNG_KERNEL_EVENT
1165 * Returns an event file descriptor or failure.
1166 * LTTNG_KERNEL_CONTEXT
1167 * Prepend a context field to each event in the channel
1168 * LTTNG_KERNEL_ENABLE
1169 * Enable recording for events in this channel (weak enable)
1170 * LTTNG_KERNEL_DISABLE
1171 * Disable recording for events in this channel (strong disable)
1173 * Channel and event file descriptors also hold a reference on the session.
1176 long lttng_channel_ioctl(struct file
*file
, unsigned int cmd
, unsigned long arg
)
1178 struct lttng_channel
*channel
= file
->private_data
;
1181 case LTTNG_KERNEL_OLD_STREAM
:
1182 case LTTNG_KERNEL_STREAM
:
1183 return lttng_abi_open_stream(file
);
1184 case LTTNG_KERNEL_OLD_EVENT
:
1186 struct lttng_kernel_event
*uevent_param
;
1187 struct lttng_kernel_old_event
*old_uevent_param
;
1190 uevent_param
= kmalloc(sizeof(struct lttng_kernel_event
),
1192 if (!uevent_param
) {
1196 old_uevent_param
= kmalloc(
1197 sizeof(struct lttng_kernel_old_event
),
1199 if (!old_uevent_param
) {
1201 goto old_event_error_free_param
;
1203 if (copy_from_user(old_uevent_param
,
1204 (struct lttng_kernel_old_event __user
*) arg
,
1205 sizeof(struct lttng_kernel_old_event
))) {
1207 goto old_event_error_free_old_param
;
1210 memcpy(uevent_param
->name
, old_uevent_param
->name
,
1211 sizeof(uevent_param
->name
));
1212 uevent_param
->instrumentation
=
1213 old_uevent_param
->instrumentation
;
1215 switch (old_uevent_param
->instrumentation
) {
1216 case LTTNG_KERNEL_KPROBE
:
1217 uevent_param
->u
.kprobe
.addr
=
1218 old_uevent_param
->u
.kprobe
.addr
;
1219 uevent_param
->u
.kprobe
.offset
=
1220 old_uevent_param
->u
.kprobe
.offset
;
1221 memcpy(uevent_param
->u
.kprobe
.symbol_name
,
1222 old_uevent_param
->u
.kprobe
.symbol_name
,
1223 sizeof(uevent_param
->u
.kprobe
.symbol_name
));
1225 case LTTNG_KERNEL_KRETPROBE
:
1226 uevent_param
->u
.kretprobe
.addr
=
1227 old_uevent_param
->u
.kretprobe
.addr
;
1228 uevent_param
->u
.kretprobe
.offset
=
1229 old_uevent_param
->u
.kretprobe
.offset
;
1230 memcpy(uevent_param
->u
.kretprobe
.symbol_name
,
1231 old_uevent_param
->u
.kretprobe
.symbol_name
,
1232 sizeof(uevent_param
->u
.kretprobe
.symbol_name
));
1234 case LTTNG_KERNEL_FUNCTION
:
1235 memcpy(uevent_param
->u
.ftrace
.symbol_name
,
1236 old_uevent_param
->u
.ftrace
.symbol_name
,
1237 sizeof(uevent_param
->u
.ftrace
.symbol_name
));
1242 ret
= lttng_abi_create_event(file
, uevent_param
);
1244 old_event_error_free_old_param
:
1245 kfree(old_uevent_param
);
1246 old_event_error_free_param
:
1247 kfree(uevent_param
);
1251 case LTTNG_KERNEL_EVENT
:
1253 struct lttng_kernel_event uevent_param
;
1255 if (copy_from_user(&uevent_param
,
1256 (struct lttng_kernel_event __user
*) arg
,
1257 sizeof(uevent_param
)))
1259 return lttng_abi_create_event(file
, &uevent_param
);
1261 case LTTNG_KERNEL_OLD_CONTEXT
:
1263 struct lttng_kernel_context
*ucontext_param
;
1264 struct lttng_kernel_old_context
*old_ucontext_param
;
1267 ucontext_param
= kmalloc(sizeof(struct lttng_kernel_context
),
1269 if (!ucontext_param
) {
1273 old_ucontext_param
= kmalloc(sizeof(struct lttng_kernel_old_context
),
1275 if (!old_ucontext_param
) {
1277 goto old_ctx_error_free_param
;
1280 if (copy_from_user(old_ucontext_param
,
1281 (struct lttng_kernel_old_context __user
*) arg
,
1282 sizeof(struct lttng_kernel_old_context
))) {
1284 goto old_ctx_error_free_old_param
;
1286 ucontext_param
->ctx
= old_ucontext_param
->ctx
;
1287 memcpy(ucontext_param
->padding
, old_ucontext_param
->padding
,
1288 sizeof(ucontext_param
->padding
));
1289 /* only type that uses the union */
1290 if (old_ucontext_param
->ctx
== LTTNG_KERNEL_CONTEXT_PERF_COUNTER
) {
1291 ucontext_param
->u
.perf_counter
.type
=
1292 old_ucontext_param
->u
.perf_counter
.type
;
1293 ucontext_param
->u
.perf_counter
.config
=
1294 old_ucontext_param
->u
.perf_counter
.config
;
1295 memcpy(ucontext_param
->u
.perf_counter
.name
,
1296 old_ucontext_param
->u
.perf_counter
.name
,
1297 sizeof(ucontext_param
->u
.perf_counter
.name
));
1300 ret
= lttng_abi_add_context(file
,
1302 &channel
->ctx
, channel
->session
);
1304 old_ctx_error_free_old_param
:
1305 kfree(old_ucontext_param
);
1306 old_ctx_error_free_param
:
1307 kfree(ucontext_param
);
1311 case LTTNG_KERNEL_CONTEXT
:
1313 struct lttng_kernel_context ucontext_param
;
1315 if (copy_from_user(&ucontext_param
,
1316 (struct lttng_kernel_context __user
*) arg
,
1317 sizeof(ucontext_param
)))
1319 return lttng_abi_add_context(file
,
1321 &channel
->ctx
, channel
->session
);
1323 case LTTNG_KERNEL_OLD_ENABLE
:
1324 case LTTNG_KERNEL_ENABLE
:
1325 return lttng_channel_enable(channel
);
1326 case LTTNG_KERNEL_OLD_DISABLE
:
1327 case LTTNG_KERNEL_DISABLE
:
1328 return lttng_channel_disable(channel
);
1329 case LTTNG_KERNEL_SYSCALL_MASK
:
1330 return lttng_channel_syscall_mask(channel
,
1331 (struct lttng_kernel_syscall_mask __user
*) arg
);
1333 return -ENOIOCTLCMD
;
1338 * lttng_metadata_ioctl - lttng syscall through ioctl
1344 * This ioctl implements lttng commands:
1345 * LTTNG_KERNEL_STREAM
1346 * Returns an event stream file descriptor or failure.
1348 * Channel and event file descriptors also hold a reference on the session.
1351 long lttng_metadata_ioctl(struct file
*file
, unsigned int cmd
, unsigned long arg
)
1354 case LTTNG_KERNEL_OLD_STREAM
:
1355 case LTTNG_KERNEL_STREAM
:
1356 return lttng_abi_open_metadata_stream(file
);
1358 return -ENOIOCTLCMD
;
1363 * lttng_channel_poll - lttng stream addition/removal monitoring
1368 unsigned int lttng_channel_poll(struct file
*file
, poll_table
*wait
)
1370 struct lttng_channel
*channel
= file
->private_data
;
1371 unsigned int mask
= 0;
1373 if (file
->f_mode
& FMODE_READ
) {
1374 poll_wait_set_exclusive(wait
);
1375 poll_wait(file
, channel
->ops
->get_hp_wait_queue(channel
->chan
),
1378 if (channel
->ops
->is_disabled(channel
->chan
))
1380 if (channel
->ops
->is_finalized(channel
->chan
))
1382 if (channel
->ops
->buffer_has_read_closed_stream(channel
->chan
))
1383 return POLLIN
| POLLRDNORM
;
1391 int lttng_channel_release(struct inode
*inode
, struct file
*file
)
1393 struct lttng_channel
*channel
= file
->private_data
;
1396 fput(channel
->session
->file
);
1401 int lttng_metadata_channel_release(struct inode
*inode
, struct file
*file
)
1403 struct lttng_channel
*channel
= file
->private_data
;
1406 fput(channel
->session
->file
);
1407 lttng_metadata_channel_destroy(channel
);
1413 static const struct file_operations lttng_channel_fops
= {
1414 .owner
= THIS_MODULE
,
1415 .release
= lttng_channel_release
,
1416 .poll
= lttng_channel_poll
,
1417 .unlocked_ioctl
= lttng_channel_ioctl
,
1418 #ifdef CONFIG_COMPAT
1419 .compat_ioctl
= lttng_channel_ioctl
,
1423 static const struct file_operations lttng_metadata_fops
= {
1424 .owner
= THIS_MODULE
,
1425 .release
= lttng_metadata_channel_release
,
1426 .unlocked_ioctl
= lttng_metadata_ioctl
,
1427 #ifdef CONFIG_COMPAT
1428 .compat_ioctl
= lttng_metadata_ioctl
,
1433 * lttng_event_ioctl - lttng syscall through ioctl
1439 * This ioctl implements lttng commands:
1440 * LTTNG_KERNEL_CONTEXT
1441 * Prepend a context field to each record of this event
1442 * LTTNG_KERNEL_ENABLE
1443 * Enable recording for this event (weak enable)
1444 * LTTNG_KERNEL_DISABLE
1445 * Disable recording for this event (strong disable)
1448 long lttng_event_ioctl(struct file
*file
, unsigned int cmd
, unsigned long arg
)
1450 struct lttng_event
*event
;
1451 struct lttng_enabler
*enabler
;
1452 enum lttng_event_type
*evtype
= file
->private_data
;
1455 case LTTNG_KERNEL_OLD_CONTEXT
:
1457 /* Not implemented */
1460 case LTTNG_KERNEL_CONTEXT
:
1462 /* Not implemented */
1465 case LTTNG_KERNEL_OLD_ENABLE
:
1466 case LTTNG_KERNEL_ENABLE
:
1468 case LTTNG_TYPE_EVENT
:
1469 event
= file
->private_data
;
1470 return lttng_event_enable(event
);
1471 case LTTNG_TYPE_ENABLER
:
1472 enabler
= file
->private_data
;
1473 return lttng_enabler_enable(enabler
);
1478 case LTTNG_KERNEL_OLD_DISABLE
:
1479 case LTTNG_KERNEL_DISABLE
:
1481 case LTTNG_TYPE_EVENT
:
1482 event
= file
->private_data
;
1483 return lttng_event_disable(event
);
1484 case LTTNG_TYPE_ENABLER
:
1485 enabler
= file
->private_data
;
1486 return lttng_enabler_disable(enabler
);
1491 case LTTNG_KERNEL_FILTER
:
1493 case LTTNG_TYPE_EVENT
:
1495 case LTTNG_TYPE_ENABLER
:
1497 enabler
= file
->private_data
;
1498 return lttng_enabler_attach_bytecode(enabler
,
1499 (struct lttng_kernel_filter_bytecode __user
*) arg
);
1505 case LTTNG_KERNEL_ADD_CALLSITE
:
1507 case LTTNG_TYPE_EVENT
:
1508 event
= file
->private_data
;
1509 return lttng_event_add_callsite(event
,
1510 (struct lttng_kernel_event_callsite __user
*) arg
);
1511 case LTTNG_TYPE_ENABLER
:
1515 return -ENOIOCTLCMD
;
1520 int lttng_event_release(struct inode
*inode
, struct file
*file
)
1522 struct lttng_event
*event
;
1523 struct lttng_enabler
*enabler
;
1524 enum lttng_event_type
*evtype
= file
->private_data
;
1530 case LTTNG_TYPE_EVENT
:
1531 event
= file
->private_data
;
1533 fput(event
->chan
->file
);
1535 case LTTNG_TYPE_ENABLER
:
1536 enabler
= file
->private_data
;
1538 fput(enabler
->chan
->file
);
1548 /* TODO: filter control ioctl */
1549 static const struct file_operations lttng_event_fops
= {
1550 .owner
= THIS_MODULE
,
1551 .release
= lttng_event_release
,
1552 .unlocked_ioctl
= lttng_event_ioctl
,
1553 #ifdef CONFIG_COMPAT
1554 .compat_ioctl
= lttng_event_ioctl
,
1558 static int put_u64(uint64_t val
, unsigned long arg
)
1560 return put_user(val
, (uint64_t __user
*) arg
);
1563 static long lttng_stream_ring_buffer_ioctl(struct file
*filp
,
1564 unsigned int cmd
, unsigned long arg
)
1566 struct lib_ring_buffer
*buf
= filp
->private_data
;
1567 struct channel
*chan
= buf
->backend
.chan
;
1568 const struct lib_ring_buffer_config
*config
= &chan
->backend
.config
;
1569 const struct lttng_channel_ops
*ops
= chan
->backend
.priv_ops
;
1572 if (atomic_read(&chan
->record_disabled
))
1576 case LTTNG_RING_BUFFER_GET_TIMESTAMP_BEGIN
:
1580 ret
= ops
->timestamp_begin(config
, buf
, &ts
);
1583 return put_u64(ts
, arg
);
1585 case LTTNG_RING_BUFFER_GET_TIMESTAMP_END
:
1589 ret
= ops
->timestamp_end(config
, buf
, &ts
);
1592 return put_u64(ts
, arg
);
1594 case LTTNG_RING_BUFFER_GET_EVENTS_DISCARDED
:
1598 ret
= ops
->events_discarded(config
, buf
, &ed
);
1601 return put_u64(ed
, arg
);
1603 case LTTNG_RING_BUFFER_GET_CONTENT_SIZE
:
1607 ret
= ops
->content_size(config
, buf
, &cs
);
1610 return put_u64(cs
, arg
);
1612 case LTTNG_RING_BUFFER_GET_PACKET_SIZE
:
1616 ret
= ops
->packet_size(config
, buf
, &ps
);
1619 return put_u64(ps
, arg
);
1621 case LTTNG_RING_BUFFER_GET_STREAM_ID
:
1625 ret
= ops
->stream_id(config
, buf
, &si
);
1628 return put_u64(si
, arg
);
1630 case LTTNG_RING_BUFFER_GET_CURRENT_TIMESTAMP
:
1634 ret
= ops
->current_timestamp(config
, buf
, &ts
);
1637 return put_u64(ts
, arg
);
1639 case LTTNG_RING_BUFFER_GET_SEQ_NUM
:
1643 ret
= ops
->sequence_number(config
, buf
, &seq
);
1646 return put_u64(seq
, arg
);
1648 case LTTNG_RING_BUFFER_INSTANCE_ID
:
1652 ret
= ops
->instance_id(config
, buf
, &id
);
1655 return put_u64(id
, arg
);
1658 return lib_ring_buffer_file_operations
.unlocked_ioctl(filp
,
1666 #ifdef CONFIG_COMPAT
1667 static long lttng_stream_ring_buffer_compat_ioctl(struct file
*filp
,
1668 unsigned int cmd
, unsigned long arg
)
1670 struct lib_ring_buffer
*buf
= filp
->private_data
;
1671 struct channel
*chan
= buf
->backend
.chan
;
1672 const struct lib_ring_buffer_config
*config
= &chan
->backend
.config
;
1673 const struct lttng_channel_ops
*ops
= chan
->backend
.priv_ops
;
1676 if (atomic_read(&chan
->record_disabled
))
1680 case LTTNG_RING_BUFFER_COMPAT_GET_TIMESTAMP_BEGIN
:
1684 ret
= ops
->timestamp_begin(config
, buf
, &ts
);
1687 return put_u64(ts
, arg
);
1689 case LTTNG_RING_BUFFER_COMPAT_GET_TIMESTAMP_END
:
1693 ret
= ops
->timestamp_end(config
, buf
, &ts
);
1696 return put_u64(ts
, arg
);
1698 case LTTNG_RING_BUFFER_COMPAT_GET_EVENTS_DISCARDED
:
1702 ret
= ops
->events_discarded(config
, buf
, &ed
);
1705 return put_u64(ed
, arg
);
1707 case LTTNG_RING_BUFFER_COMPAT_GET_CONTENT_SIZE
:
1711 ret
= ops
->content_size(config
, buf
, &cs
);
1714 return put_u64(cs
, arg
);
1716 case LTTNG_RING_BUFFER_COMPAT_GET_PACKET_SIZE
:
1720 ret
= ops
->packet_size(config
, buf
, &ps
);
1723 return put_u64(ps
, arg
);
1725 case LTTNG_RING_BUFFER_COMPAT_GET_STREAM_ID
:
1729 ret
= ops
->stream_id(config
, buf
, &si
);
1732 return put_u64(si
, arg
);
1734 case LTTNG_RING_BUFFER_GET_CURRENT_TIMESTAMP
:
1738 ret
= ops
->current_timestamp(config
, buf
, &ts
);
1741 return put_u64(ts
, arg
);
1743 case LTTNG_RING_BUFFER_COMPAT_GET_SEQ_NUM
:
1747 ret
= ops
->sequence_number(config
, buf
, &seq
);
1750 return put_u64(seq
, arg
);
1752 case LTTNG_RING_BUFFER_COMPAT_INSTANCE_ID
:
1756 ret
= ops
->instance_id(config
, buf
, &id
);
1759 return put_u64(id
, arg
);
1762 return lib_ring_buffer_file_operations
.compat_ioctl(filp
,
1769 #endif /* CONFIG_COMPAT */
1771 static void lttng_stream_override_ring_buffer_fops(void)
1773 lttng_stream_ring_buffer_file_operations
.owner
= THIS_MODULE
;
1774 lttng_stream_ring_buffer_file_operations
.open
=
1775 lib_ring_buffer_file_operations
.open
;
1776 lttng_stream_ring_buffer_file_operations
.release
=
1777 lib_ring_buffer_file_operations
.release
;
1778 lttng_stream_ring_buffer_file_operations
.poll
=
1779 lib_ring_buffer_file_operations
.poll
;
1780 lttng_stream_ring_buffer_file_operations
.splice_read
=
1781 lib_ring_buffer_file_operations
.splice_read
;
1782 lttng_stream_ring_buffer_file_operations
.mmap
=
1783 lib_ring_buffer_file_operations
.mmap
;
1784 lttng_stream_ring_buffer_file_operations
.unlocked_ioctl
=
1785 lttng_stream_ring_buffer_ioctl
;
1786 lttng_stream_ring_buffer_file_operations
.llseek
=
1787 lib_ring_buffer_file_operations
.llseek
;
1788 #ifdef CONFIG_COMPAT
1789 lttng_stream_ring_buffer_file_operations
.compat_ioctl
=
1790 lttng_stream_ring_buffer_compat_ioctl
;
1794 int __init
lttng_abi_init(void)
1798 wrapper_vmalloc_sync_all();
1801 ret
= lttng_tp_mempool_init();
1806 lttng_proc_dentry
= proc_create_data("lttng", S_IRUSR
| S_IWUSR
, NULL
,
1809 if (!lttng_proc_dentry
) {
1810 printk(KERN_ERR
"Error creating LTTng control file\n");
1814 lttng_stream_override_ring_buffer_fops();
1818 lttng_tp_mempool_destroy();
1819 lttng_clock_unref();
1823 /* No __exit annotation because used by init error path too. */
1824 void lttng_abi_exit(void)
1826 lttng_tp_mempool_destroy();
1827 lttng_clock_unref();
1828 if (lttng_proc_dentry
)
1829 remove_proc_entry("lttng", NULL
);