6 * Copyright (C) 2010-2012 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; only
11 * version 2.1 of the License.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23 * Mimic system calls for:
24 * - session creation, returns a file descriptor or failure.
25 * - channel creation, returns a file descriptor or failure.
26 * - Operates on a session file descriptor
27 * - Takes all channel options as parameters.
28 * - stream get, returns a file descriptor or failure.
29 * - Operates on a channel file descriptor.
30 * - stream notifier get, returns a file descriptor or failure.
31 * - Operates on a channel file descriptor.
32 * - event creation, returns a file descriptor or failure.
33 * - Operates on a channel file descriptor
34 * - Takes an event name as parameter
35 * - Takes an instrumentation source as parameter
36 * - e.g. tracepoints, dynamic_probes...
37 * - Takes instrumentation source specific arguments.
40 #include <linux/module.h>
41 #include <linux/proc_fs.h>
42 #include <linux/anon_inodes.h>
43 #include <linux/file.h>
44 #include <linux/uaccess.h>
45 #include <linux/slab.h>
46 #include <linux/err.h>
47 #include <wrapper/vmalloc.h> /* for wrapper_vmalloc_sync_all() */
48 #include <wrapper/ringbuffer/vfs.h>
49 #include <wrapper/ringbuffer/backend.h>
50 #include <wrapper/ringbuffer/frontend.h>
51 #include <wrapper/poll.h>
52 #include <wrapper/file.h>
53 #include <wrapper/kref.h>
54 #include <lttng-string-utils.h>
55 #include <lttng-abi.h>
56 #include <lttng-abi-old.h>
57 #include <lttng-events.h>
58 #include <lttng-tracer.h>
59 #include <lttng-tp-mempool.h>
60 #include <lib/ringbuffer/frontend_types.h>
63 * This is LTTng's own personal way to create a system call as an external
64 * module. We use ioctl() on /proc/lttng.
67 static struct proc_dir_entry
*lttng_proc_dentry
;
69 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(5,6,0))
70 static const struct proc_ops lttng_proc_ops
;
72 static const struct file_operations lttng_proc_ops
;
75 static const struct file_operations lttng_session_fops
;
76 static const struct file_operations lttng_channel_fops
;
77 static const struct file_operations lttng_metadata_fops
;
78 static const struct file_operations lttng_event_fops
;
79 static struct file_operations lttng_stream_ring_buffer_file_operations
;
81 static int put_u64(uint64_t val
, unsigned long arg
);
84 * Teardown management: opened file descriptors keep a refcount on the module,
85 * so it can only exit when all file descriptors are closed.
89 int lttng_abi_create_session(void)
91 struct lttng_session
*session
;
92 struct file
*session_file
;
95 session
= lttng_session_create();
98 session_fd
= lttng_get_unused_fd();
103 session_file
= anon_inode_getfile("[lttng_session]",
106 if (IS_ERR(session_file
)) {
107 ret
= PTR_ERR(session_file
);
110 session
->file
= session_file
;
111 fd_install(session_fd
, session_file
);
115 put_unused_fd(session_fd
);
117 lttng_session_destroy(session
);
122 int lttng_abi_tracepoint_list(void)
124 struct file
*tracepoint_list_file
;
127 file_fd
= lttng_get_unused_fd();
133 tracepoint_list_file
= anon_inode_getfile("[lttng_tracepoint_list]",
134 <tng_tracepoint_list_fops
,
136 if (IS_ERR(tracepoint_list_file
)) {
137 ret
= PTR_ERR(tracepoint_list_file
);
140 ret
= lttng_tracepoint_list_fops
.open(NULL
, tracepoint_list_file
);
143 fd_install(file_fd
, tracepoint_list_file
);
147 fput(tracepoint_list_file
);
149 put_unused_fd(file_fd
);
154 #ifndef CONFIG_HAVE_SYSCALL_TRACEPOINTS
156 int lttng_abi_syscall_list(void)
162 int lttng_abi_syscall_list(void)
164 struct file
*syscall_list_file
;
167 file_fd
= lttng_get_unused_fd();
173 syscall_list_file
= anon_inode_getfile("[lttng_syscall_list]",
174 <tng_syscall_list_fops
,
176 if (IS_ERR(syscall_list_file
)) {
177 ret
= PTR_ERR(syscall_list_file
);
180 ret
= lttng_syscall_list_fops
.open(NULL
, syscall_list_file
);
183 fd_install(file_fd
, syscall_list_file
);
187 fput(syscall_list_file
);
189 put_unused_fd(file_fd
);
196 void lttng_abi_tracer_version(struct lttng_kernel_tracer_version
*v
)
198 v
->major
= LTTNG_MODULES_MAJOR_VERSION
;
199 v
->minor
= LTTNG_MODULES_MINOR_VERSION
;
200 v
->patchlevel
= LTTNG_MODULES_PATCHLEVEL_VERSION
;
204 void lttng_abi_tracer_abi_version(struct lttng_kernel_tracer_abi_version
*v
)
206 v
->major
= LTTNG_MODULES_ABI_MAJOR_VERSION
;
207 v
->minor
= LTTNG_MODULES_ABI_MINOR_VERSION
;
211 long lttng_abi_add_context(struct file
*file
,
212 struct lttng_kernel_context
*context_param
,
213 struct lttng_ctx
**ctx
, struct lttng_session
*session
)
216 if (session
->been_active
)
219 switch (context_param
->ctx
) {
220 case LTTNG_KERNEL_CONTEXT_PID
:
221 return lttng_add_pid_to_ctx(ctx
);
222 case LTTNG_KERNEL_CONTEXT_PRIO
:
223 return lttng_add_prio_to_ctx(ctx
);
224 case LTTNG_KERNEL_CONTEXT_NICE
:
225 return lttng_add_nice_to_ctx(ctx
);
226 case LTTNG_KERNEL_CONTEXT_VPID
:
227 return lttng_add_vpid_to_ctx(ctx
);
228 case LTTNG_KERNEL_CONTEXT_TID
:
229 return lttng_add_tid_to_ctx(ctx
);
230 case LTTNG_KERNEL_CONTEXT_VTID
:
231 return lttng_add_vtid_to_ctx(ctx
);
232 case LTTNG_KERNEL_CONTEXT_PPID
:
233 return lttng_add_ppid_to_ctx(ctx
);
234 case LTTNG_KERNEL_CONTEXT_VPPID
:
235 return lttng_add_vppid_to_ctx(ctx
);
236 case LTTNG_KERNEL_CONTEXT_PERF_COUNTER
:
237 context_param
->u
.perf_counter
.name
[LTTNG_KERNEL_SYM_NAME_LEN
- 1] = '\0';
238 return lttng_add_perf_counter_to_ctx(context_param
->u
.perf_counter
.type
,
239 context_param
->u
.perf_counter
.config
,
240 context_param
->u
.perf_counter
.name
,
242 case LTTNG_KERNEL_CONTEXT_PROCNAME
:
243 return lttng_add_procname_to_ctx(ctx
);
244 case LTTNG_KERNEL_CONTEXT_HOSTNAME
:
245 return lttng_add_hostname_to_ctx(ctx
);
246 case LTTNG_KERNEL_CONTEXT_CPU_ID
:
247 return lttng_add_cpu_id_to_ctx(ctx
);
248 case LTTNG_KERNEL_CONTEXT_INTERRUPTIBLE
:
249 return lttng_add_interruptible_to_ctx(ctx
);
250 case LTTNG_KERNEL_CONTEXT_NEED_RESCHEDULE
:
251 return lttng_add_need_reschedule_to_ctx(ctx
);
252 case LTTNG_KERNEL_CONTEXT_PREEMPTIBLE
:
253 return lttng_add_preemptible_to_ctx(ctx
);
254 case LTTNG_KERNEL_CONTEXT_MIGRATABLE
:
255 return lttng_add_migratable_to_ctx(ctx
);
262 * lttng_ioctl - lttng syscall through ioctl
268 * This ioctl implements lttng commands:
269 * LTTNG_KERNEL_SESSION
270 * Returns a LTTng trace session file descriptor
271 * LTTNG_KERNEL_TRACER_VERSION
272 * Returns the LTTng kernel tracer version
273 * LTTNG_KERNEL_TRACEPOINT_LIST
274 * Returns a file descriptor listing available tracepoints
275 * LTTNG_KERNEL_WAIT_QUIESCENT
276 * Returns after all previously running probes have completed
277 * LTTNG_KERNEL_TRACER_ABI_VERSION
278 * Returns the LTTng kernel tracer ABI version
280 * The returned session will be deleted when its file descriptor is closed.
283 long lttng_ioctl(struct file
*file
, unsigned int cmd
, unsigned long arg
)
286 case LTTNG_KERNEL_OLD_SESSION
:
287 case LTTNG_KERNEL_SESSION
:
288 return lttng_abi_create_session();
289 case LTTNG_KERNEL_OLD_TRACER_VERSION
:
291 struct lttng_kernel_tracer_version v
;
292 struct lttng_kernel_old_tracer_version oldv
;
293 struct lttng_kernel_old_tracer_version
*uversion
=
294 (struct lttng_kernel_old_tracer_version __user
*) arg
;
296 lttng_abi_tracer_version(&v
);
297 oldv
.major
= v
.major
;
298 oldv
.minor
= v
.minor
;
299 oldv
.patchlevel
= v
.patchlevel
;
301 if (copy_to_user(uversion
, &oldv
, sizeof(oldv
)))
305 case LTTNG_KERNEL_TRACER_VERSION
:
307 struct lttng_kernel_tracer_version version
;
308 struct lttng_kernel_tracer_version
*uversion
=
309 (struct lttng_kernel_tracer_version __user
*) arg
;
311 lttng_abi_tracer_version(&version
);
313 if (copy_to_user(uversion
, &version
, sizeof(version
)))
317 case LTTNG_KERNEL_TRACER_ABI_VERSION
:
319 struct lttng_kernel_tracer_abi_version version
;
320 struct lttng_kernel_tracer_abi_version
*uversion
=
321 (struct lttng_kernel_tracer_abi_version __user
*) arg
;
323 lttng_abi_tracer_abi_version(&version
);
325 if (copy_to_user(uversion
, &version
, sizeof(version
)))
329 case LTTNG_KERNEL_OLD_TRACEPOINT_LIST
:
330 case LTTNG_KERNEL_TRACEPOINT_LIST
:
331 return lttng_abi_tracepoint_list();
332 case LTTNG_KERNEL_SYSCALL_LIST
:
333 return lttng_abi_syscall_list();
334 case LTTNG_KERNEL_OLD_WAIT_QUIESCENT
:
335 case LTTNG_KERNEL_WAIT_QUIESCENT
:
338 case LTTNG_KERNEL_OLD_CALIBRATE
:
340 struct lttng_kernel_old_calibrate __user
*ucalibrate
=
341 (struct lttng_kernel_old_calibrate __user
*) arg
;
342 struct lttng_kernel_old_calibrate old_calibrate
;
343 struct lttng_kernel_calibrate calibrate
;
346 if (copy_from_user(&old_calibrate
, ucalibrate
, sizeof(old_calibrate
)))
348 calibrate
.type
= old_calibrate
.type
;
349 ret
= lttng_calibrate(&calibrate
);
350 if (copy_to_user(ucalibrate
, &old_calibrate
, sizeof(old_calibrate
)))
354 case LTTNG_KERNEL_CALIBRATE
:
356 struct lttng_kernel_calibrate __user
*ucalibrate
=
357 (struct lttng_kernel_calibrate __user
*) arg
;
358 struct lttng_kernel_calibrate calibrate
;
361 if (copy_from_user(&calibrate
, ucalibrate
, sizeof(calibrate
)))
363 ret
= lttng_calibrate(&calibrate
);
364 if (copy_to_user(ucalibrate
, &calibrate
, sizeof(calibrate
)))
373 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(5,6,0))
374 static const struct proc_ops lttng_proc_ops
= {
375 .proc_ioctl
= lttng_ioctl
,
377 .proc_compat_ioctl
= lttng_ioctl
,
378 #endif /* CONFIG_COMPAT */
381 static const struct file_operations lttng_proc_ops
= {
382 .owner
= THIS_MODULE
,
383 .unlocked_ioctl
= lttng_ioctl
,
385 .compat_ioctl
= lttng_ioctl
,
386 #endif /* CONFIG_COMPAT */
391 int lttng_abi_create_channel(struct file
*session_file
,
392 struct lttng_kernel_channel
*chan_param
,
393 enum channel_type channel_type
)
395 struct lttng_session
*session
= session_file
->private_data
;
396 const struct file_operations
*fops
= NULL
;
397 const char *transport_name
;
398 struct lttng_channel
*chan
;
399 struct file
*chan_file
;
403 chan_fd
= lttng_get_unused_fd();
408 switch (channel_type
) {
409 case PER_CPU_CHANNEL
:
410 fops
= <tng_channel_fops
;
412 case METADATA_CHANNEL
:
413 fops
= <tng_metadata_fops
;
417 chan_file
= anon_inode_getfile("[lttng_channel]",
420 if (IS_ERR(chan_file
)) {
421 ret
= PTR_ERR(chan_file
);
424 switch (channel_type
) {
425 case PER_CPU_CHANNEL
:
426 if (chan_param
->output
== LTTNG_KERNEL_SPLICE
) {
427 transport_name
= chan_param
->overwrite
?
428 "relay-overwrite" : "relay-discard";
429 } else if (chan_param
->output
== LTTNG_KERNEL_MMAP
) {
430 transport_name
= chan_param
->overwrite
?
431 "relay-overwrite-mmap" : "relay-discard-mmap";
436 case METADATA_CHANNEL
:
437 if (chan_param
->output
== LTTNG_KERNEL_SPLICE
)
438 transport_name
= "relay-metadata";
439 else if (chan_param
->output
== LTTNG_KERNEL_MMAP
)
440 transport_name
= "relay-metadata-mmap";
445 transport_name
= "<unknown>";
448 if (!atomic_long_add_unless(&session_file
->f_count
, 1, LONG_MAX
)) {
453 * We tolerate no failure path after channel creation. It will stay
454 * invariant for the rest of the session.
456 chan
= lttng_channel_create(session
, transport_name
, NULL
,
457 chan_param
->subbuf_size
,
458 chan_param
->num_subbuf
,
459 chan_param
->switch_timer_interval
,
460 chan_param
->read_timer_interval
,
466 chan
->file
= chan_file
;
467 chan_file
->private_data
= chan
;
468 fd_install(chan_fd
, chan_file
);
473 atomic_long_dec(&session_file
->f_count
);
477 put_unused_fd(chan_fd
);
483 * lttng_session_ioctl - lttng session fd ioctl
489 * This ioctl implements lttng commands:
490 * LTTNG_KERNEL_CHANNEL
491 * Returns a LTTng channel file descriptor
492 * LTTNG_KERNEL_ENABLE
493 * Enables tracing for a session (weak enable)
494 * LTTNG_KERNEL_DISABLE
495 * Disables tracing for a session (strong disable)
496 * LTTNG_KERNEL_METADATA
497 * Returns a LTTng metadata file descriptor
498 * LTTNG_KERNEL_SESSION_TRACK_PID
499 * Add PID to session tracker
500 * LTTNG_KERNEL_SESSION_UNTRACK_PID
501 * Remove PID from session tracker
503 * The returned channel will be deleted when its file descriptor is closed.
506 long lttng_session_ioctl(struct file
*file
, unsigned int cmd
, unsigned long arg
)
508 struct lttng_session
*session
= file
->private_data
;
509 struct lttng_kernel_channel chan_param
;
510 struct lttng_kernel_old_channel old_chan_param
;
513 case LTTNG_KERNEL_OLD_CHANNEL
:
515 if (copy_from_user(&old_chan_param
,
516 (struct lttng_kernel_old_channel __user
*) arg
,
517 sizeof(struct lttng_kernel_old_channel
)))
519 chan_param
.overwrite
= old_chan_param
.overwrite
;
520 chan_param
.subbuf_size
= old_chan_param
.subbuf_size
;
521 chan_param
.num_subbuf
= old_chan_param
.num_subbuf
;
522 chan_param
.switch_timer_interval
= old_chan_param
.switch_timer_interval
;
523 chan_param
.read_timer_interval
= old_chan_param
.read_timer_interval
;
524 chan_param
.output
= old_chan_param
.output
;
526 return lttng_abi_create_channel(file
, &chan_param
,
529 case LTTNG_KERNEL_CHANNEL
:
531 if (copy_from_user(&chan_param
,
532 (struct lttng_kernel_channel __user
*) arg
,
533 sizeof(struct lttng_kernel_channel
)))
535 return lttng_abi_create_channel(file
, &chan_param
,
538 case LTTNG_KERNEL_OLD_SESSION_START
:
539 case LTTNG_KERNEL_OLD_ENABLE
:
540 case LTTNG_KERNEL_SESSION_START
:
541 case LTTNG_KERNEL_ENABLE
:
542 return lttng_session_enable(session
);
543 case LTTNG_KERNEL_OLD_SESSION_STOP
:
544 case LTTNG_KERNEL_OLD_DISABLE
:
545 case LTTNG_KERNEL_SESSION_STOP
:
546 case LTTNG_KERNEL_DISABLE
:
547 return lttng_session_disable(session
);
548 case LTTNG_KERNEL_OLD_METADATA
:
550 if (copy_from_user(&old_chan_param
,
551 (struct lttng_kernel_old_channel __user
*) arg
,
552 sizeof(struct lttng_kernel_old_channel
)))
554 chan_param
.overwrite
= old_chan_param
.overwrite
;
555 chan_param
.subbuf_size
= old_chan_param
.subbuf_size
;
556 chan_param
.num_subbuf
= old_chan_param
.num_subbuf
;
557 chan_param
.switch_timer_interval
= old_chan_param
.switch_timer_interval
;
558 chan_param
.read_timer_interval
= old_chan_param
.read_timer_interval
;
559 chan_param
.output
= old_chan_param
.output
;
561 return lttng_abi_create_channel(file
, &chan_param
,
564 case LTTNG_KERNEL_METADATA
:
566 if (copy_from_user(&chan_param
,
567 (struct lttng_kernel_channel __user
*) arg
,
568 sizeof(struct lttng_kernel_channel
)))
570 return lttng_abi_create_channel(file
, &chan_param
,
573 case LTTNG_KERNEL_SESSION_TRACK_PID
:
574 return lttng_session_track_pid(session
, (int) arg
);
575 case LTTNG_KERNEL_SESSION_UNTRACK_PID
:
576 return lttng_session_untrack_pid(session
, (int) arg
);
577 case LTTNG_KERNEL_SESSION_LIST_TRACKER_PIDS
:
578 return lttng_session_list_tracker_pids(session
);
579 case LTTNG_KERNEL_SESSION_METADATA_REGEN
:
580 return lttng_session_metadata_regenerate(session
);
581 case LTTNG_KERNEL_SESSION_STATEDUMP
:
582 return lttng_session_statedump(session
);
589 * Called when the last file reference is dropped.
591 * Big fat note: channels and events are invariant for the whole session after
592 * their creation. So this session destruction also destroys all channel and
593 * event structures specific to this session (they are not destroyed when their
594 * individual file is released).
597 int lttng_session_release(struct inode
*inode
, struct file
*file
)
599 struct lttng_session
*session
= file
->private_data
;
602 lttng_session_destroy(session
);
606 static const struct file_operations lttng_session_fops
= {
607 .owner
= THIS_MODULE
,
608 .release
= lttng_session_release
,
609 .unlocked_ioctl
= lttng_session_ioctl
,
611 .compat_ioctl
= lttng_session_ioctl
,
616 * lttng_metadata_ring_buffer_poll - LTTng ring buffer poll file operation
620 * Handles the poll operations for the metadata channels.
623 unsigned int lttng_metadata_ring_buffer_poll(struct file
*filp
,
626 struct lttng_metadata_stream
*stream
= filp
->private_data
;
627 struct lib_ring_buffer
*buf
= stream
->priv
;
629 unsigned int mask
= 0;
631 if (filp
->f_mode
& FMODE_READ
) {
632 poll_wait_set_exclusive(wait
);
633 poll_wait(filp
, &stream
->read_wait
, wait
);
635 finalized
= stream
->finalized
;
638 * lib_ring_buffer_is_finalized() contains a smp_rmb()
639 * ordering finalized load before offsets loads.
641 WARN_ON(atomic_long_read(&buf
->active_readers
) != 1);
646 mutex_lock(&stream
->metadata_cache
->lock
);
647 if (stream
->metadata_cache
->metadata_written
>
648 stream
->metadata_out
)
650 mutex_unlock(&stream
->metadata_cache
->lock
);
657 void lttng_metadata_ring_buffer_ioctl_put_next_subbuf(struct file
*filp
,
658 unsigned int cmd
, unsigned long arg
)
660 struct lttng_metadata_stream
*stream
= filp
->private_data
;
662 stream
->metadata_out
= stream
->metadata_in
;
666 long lttng_metadata_ring_buffer_ioctl(struct file
*filp
,
667 unsigned int cmd
, unsigned long arg
)
670 struct lttng_metadata_stream
*stream
= filp
->private_data
;
671 struct lib_ring_buffer
*buf
= stream
->priv
;
674 case RING_BUFFER_GET_NEXT_SUBBUF
:
676 struct lttng_metadata_stream
*stream
= filp
->private_data
;
677 struct lib_ring_buffer
*buf
= stream
->priv
;
678 struct channel
*chan
= buf
->backend
.chan
;
680 ret
= lttng_metadata_output_channel(stream
, chan
);
682 lib_ring_buffer_switch_slow(buf
, SWITCH_ACTIVE
);
688 case RING_BUFFER_GET_SUBBUF
:
691 * Random access is not allowed for metadata channel.
695 case RING_BUFFER_FLUSH_EMPTY
: /* Fall-through. */
696 case RING_BUFFER_FLUSH
:
698 struct lttng_metadata_stream
*stream
= filp
->private_data
;
699 struct lib_ring_buffer
*buf
= stream
->priv
;
700 struct channel
*chan
= buf
->backend
.chan
;
703 * Before doing the actual ring buffer flush, write up to one
704 * packet of metadata in the ring buffer.
706 ret
= lttng_metadata_output_channel(stream
, chan
);
711 case RING_BUFFER_GET_METADATA_VERSION
:
713 struct lttng_metadata_stream
*stream
= filp
->private_data
;
715 return put_u64(stream
->version
, arg
);
720 /* PUT_SUBBUF is the one from lib ring buffer, unmodified. */
722 /* Performing lib ring buffer ioctl after our own. */
723 ret
= lib_ring_buffer_ioctl(filp
, cmd
, arg
, buf
);
728 case RING_BUFFER_PUT_NEXT_SUBBUF
:
730 lttng_metadata_ring_buffer_ioctl_put_next_subbuf(filp
,
743 long lttng_metadata_ring_buffer_compat_ioctl(struct file
*filp
,
744 unsigned int cmd
, unsigned long arg
)
747 struct lttng_metadata_stream
*stream
= filp
->private_data
;
748 struct lib_ring_buffer
*buf
= stream
->priv
;
751 case RING_BUFFER_GET_NEXT_SUBBUF
:
753 struct lttng_metadata_stream
*stream
= filp
->private_data
;
754 struct lib_ring_buffer
*buf
= stream
->priv
;
755 struct channel
*chan
= buf
->backend
.chan
;
757 ret
= lttng_metadata_output_channel(stream
, chan
);
759 lib_ring_buffer_switch_slow(buf
, SWITCH_ACTIVE
);
765 case RING_BUFFER_GET_SUBBUF
:
768 * Random access is not allowed for metadata channel.
772 case RING_BUFFER_FLUSH_EMPTY
: /* Fall-through. */
773 case RING_BUFFER_FLUSH
:
775 struct lttng_metadata_stream
*stream
= filp
->private_data
;
776 struct lib_ring_buffer
*buf
= stream
->priv
;
777 struct channel
*chan
= buf
->backend
.chan
;
780 * Before doing the actual ring buffer flush, write up to one
781 * packet of metadata in the ring buffer.
783 ret
= lttng_metadata_output_channel(stream
, chan
);
788 case RING_BUFFER_GET_METADATA_VERSION
:
790 struct lttng_metadata_stream
*stream
= filp
->private_data
;
792 return put_u64(stream
->version
, arg
);
797 /* PUT_SUBBUF is the one from lib ring buffer, unmodified. */
799 /* Performing lib ring buffer ioctl after our own. */
800 ret
= lib_ring_buffer_compat_ioctl(filp
, cmd
, arg
, buf
);
805 case RING_BUFFER_PUT_NEXT_SUBBUF
:
807 lttng_metadata_ring_buffer_ioctl_put_next_subbuf(filp
,
820 * This is not used by anonymous file descriptors. This code is left
821 * there if we ever want to implement an inode with open() operation.
824 int lttng_metadata_ring_buffer_open(struct inode
*inode
, struct file
*file
)
826 struct lttng_metadata_stream
*stream
= inode
->i_private
;
827 struct lib_ring_buffer
*buf
= stream
->priv
;
829 file
->private_data
= buf
;
831 * Since life-time of metadata cache differs from that of
832 * session, we need to keep our own reference on the transport.
834 if (!try_module_get(stream
->transport
->owner
)) {
835 printk(KERN_WARNING
"LTT : Can't lock transport module.\n");
838 return lib_ring_buffer_open(inode
, file
, buf
);
842 int lttng_metadata_ring_buffer_release(struct inode
*inode
, struct file
*file
)
844 struct lttng_metadata_stream
*stream
= file
->private_data
;
845 struct lib_ring_buffer
*buf
= stream
->priv
;
847 kref_put(&stream
->metadata_cache
->refcount
, metadata_cache_destroy
);
848 module_put(stream
->transport
->owner
);
849 return lib_ring_buffer_release(inode
, file
, buf
);
853 ssize_t
lttng_metadata_ring_buffer_splice_read(struct file
*in
, loff_t
*ppos
,
854 struct pipe_inode_info
*pipe
, size_t len
,
857 struct lttng_metadata_stream
*stream
= in
->private_data
;
858 struct lib_ring_buffer
*buf
= stream
->priv
;
860 return lib_ring_buffer_splice_read(in
, ppos
, pipe
, len
,
865 int lttng_metadata_ring_buffer_mmap(struct file
*filp
,
866 struct vm_area_struct
*vma
)
868 struct lttng_metadata_stream
*stream
= filp
->private_data
;
869 struct lib_ring_buffer
*buf
= stream
->priv
;
871 return lib_ring_buffer_mmap(filp
, vma
, buf
);
875 const struct file_operations lttng_metadata_ring_buffer_file_operations
= {
876 .owner
= THIS_MODULE
,
877 .open
= lttng_metadata_ring_buffer_open
,
878 .release
= lttng_metadata_ring_buffer_release
,
879 .poll
= lttng_metadata_ring_buffer_poll
,
880 .splice_read
= lttng_metadata_ring_buffer_splice_read
,
881 .mmap
= lttng_metadata_ring_buffer_mmap
,
882 .unlocked_ioctl
= lttng_metadata_ring_buffer_ioctl
,
883 .llseek
= vfs_lib_ring_buffer_no_llseek
,
885 .compat_ioctl
= lttng_metadata_ring_buffer_compat_ioctl
,
890 int lttng_abi_create_stream_fd(struct file
*channel_file
, void *stream_priv
,
891 const struct file_operations
*fops
)
894 struct file
*stream_file
;
896 stream_fd
= lttng_get_unused_fd();
901 stream_file
= anon_inode_getfile("[lttng_stream]", fops
,
902 stream_priv
, O_RDWR
);
903 if (IS_ERR(stream_file
)) {
904 ret
= PTR_ERR(stream_file
);
908 * OPEN_FMODE, called within anon_inode_getfile/alloc_file, don't honor
909 * FMODE_LSEEK, FMODE_PREAD nor FMODE_PWRITE. We need to read from this
910 * file descriptor, so we set FMODE_PREAD here.
912 stream_file
->f_mode
|= FMODE_PREAD
;
913 fd_install(stream_fd
, stream_file
);
915 * The stream holds a reference to the channel within the generic ring
916 * buffer library, so no need to hold a refcount on the channel and
917 * session files here.
922 put_unused_fd(stream_fd
);
928 int lttng_abi_open_stream(struct file
*channel_file
)
930 struct lttng_channel
*channel
= channel_file
->private_data
;
931 struct lib_ring_buffer
*buf
;
935 buf
= channel
->ops
->buffer_read_open(channel
->chan
);
940 ret
= lttng_abi_create_stream_fd(channel_file
, stream_priv
,
941 <tng_stream_ring_buffer_file_operations
);
948 channel
->ops
->buffer_read_close(buf
);
953 int lttng_abi_open_metadata_stream(struct file
*channel_file
)
955 struct lttng_channel
*channel
= channel_file
->private_data
;
956 struct lttng_session
*session
= channel
->session
;
957 struct lib_ring_buffer
*buf
;
959 struct lttng_metadata_stream
*metadata_stream
;
962 buf
= channel
->ops
->buffer_read_open(channel
->chan
);
966 metadata_stream
= kzalloc(sizeof(struct lttng_metadata_stream
),
968 if (!metadata_stream
) {
972 metadata_stream
->metadata_cache
= session
->metadata_cache
;
973 init_waitqueue_head(&metadata_stream
->read_wait
);
974 metadata_stream
->priv
= buf
;
975 stream_priv
= metadata_stream
;
976 metadata_stream
->transport
= channel
->transport
;
979 * Since life-time of metadata cache differs from that of
980 * session, we need to keep our own reference on the transport.
982 if (!try_module_get(metadata_stream
->transport
->owner
)) {
983 printk(KERN_WARNING
"LTT : Can't lock transport module.\n");
988 if (!lttng_kref_get(&session
->metadata_cache
->refcount
)) {
993 ret
= lttng_abi_create_stream_fd(channel_file
, stream_priv
,
994 <tng_metadata_ring_buffer_file_operations
);
998 list_add(&metadata_stream
->list
,
999 &session
->metadata_cache
->metadata_stream
);
1003 kref_put(&session
->metadata_cache
->refcount
, metadata_cache_destroy
);
1005 module_put(metadata_stream
->transport
->owner
);
1007 kfree(metadata_stream
);
1009 channel
->ops
->buffer_read_close(buf
);
1014 int lttng_abi_create_event(struct file
*channel_file
,
1015 struct lttng_kernel_event
*event_param
)
1017 struct lttng_channel
*channel
= channel_file
->private_data
;
1019 struct file
*event_file
;
1022 event_param
->name
[LTTNG_KERNEL_SYM_NAME_LEN
- 1] = '\0';
1023 switch (event_param
->instrumentation
) {
1024 case LTTNG_KERNEL_KRETPROBE
:
1025 event_param
->u
.kretprobe
.symbol_name
[LTTNG_KERNEL_SYM_NAME_LEN
- 1] = '\0';
1027 case LTTNG_KERNEL_KPROBE
:
1028 event_param
->u
.kprobe
.symbol_name
[LTTNG_KERNEL_SYM_NAME_LEN
- 1] = '\0';
1030 case LTTNG_KERNEL_FUNCTION
:
1031 event_param
->u
.ftrace
.symbol_name
[LTTNG_KERNEL_SYM_NAME_LEN
- 1] = '\0';
1036 event_fd
= lttng_get_unused_fd();
1041 event_file
= anon_inode_getfile("[lttng_event]",
1044 if (IS_ERR(event_file
)) {
1045 ret
= PTR_ERR(event_file
);
1048 /* The event holds a reference on the channel */
1049 if (!atomic_long_add_unless(&channel_file
->f_count
, 1, LONG_MAX
)) {
1051 goto refcount_error
;
1053 if (event_param
->instrumentation
== LTTNG_KERNEL_TRACEPOINT
1054 || event_param
->instrumentation
== LTTNG_KERNEL_SYSCALL
) {
1055 struct lttng_enabler
*enabler
;
1057 if (strutils_is_star_glob_pattern(event_param
->name
)) {
1059 * If the event name is a star globbing pattern,
1060 * we create the special star globbing enabler.
1062 enabler
= lttng_enabler_create(LTTNG_ENABLER_STAR_GLOB
,
1063 event_param
, channel
);
1065 enabler
= lttng_enabler_create(LTTNG_ENABLER_NAME
,
1066 event_param
, channel
);
1070 struct lttng_event
*event
;
1073 * We tolerate no failure path after event creation. It
1074 * will stay invariant for the rest of the session.
1076 event
= lttng_event_create(channel
, event_param
,
1078 event_param
->instrumentation
);
1079 WARN_ON_ONCE(!event
);
1080 if (IS_ERR(event
)) {
1081 ret
= PTR_ERR(event
);
1086 event_file
->private_data
= priv
;
1087 fd_install(event_fd
, event_file
);
1091 atomic_long_dec(&channel_file
->f_count
);
1095 put_unused_fd(event_fd
);
1101 * lttng_channel_ioctl - lttng syscall through ioctl
1107 * This ioctl implements lttng commands:
1108 * LTTNG_KERNEL_STREAM
1109 * Returns an event stream file descriptor or failure.
1110 * (typically, one event stream records events from one CPU)
1111 * LTTNG_KERNEL_EVENT
1112 * Returns an event file descriptor or failure.
1113 * LTTNG_KERNEL_CONTEXT
1114 * Prepend a context field to each event in the channel
1115 * LTTNG_KERNEL_ENABLE
1116 * Enable recording for events in this channel (weak enable)
1117 * LTTNG_KERNEL_DISABLE
1118 * Disable recording for events in this channel (strong disable)
1120 * Channel and event file descriptors also hold a reference on the session.
1123 long lttng_channel_ioctl(struct file
*file
, unsigned int cmd
, unsigned long arg
)
1125 struct lttng_channel
*channel
= file
->private_data
;
1128 case LTTNG_KERNEL_OLD_STREAM
:
1129 case LTTNG_KERNEL_STREAM
:
1130 return lttng_abi_open_stream(file
);
1131 case LTTNG_KERNEL_OLD_EVENT
:
1133 struct lttng_kernel_event
*uevent_param
;
1134 struct lttng_kernel_old_event
*old_uevent_param
;
1137 uevent_param
= kmalloc(sizeof(struct lttng_kernel_event
),
1139 if (!uevent_param
) {
1143 old_uevent_param
= kmalloc(
1144 sizeof(struct lttng_kernel_old_event
),
1146 if (!old_uevent_param
) {
1148 goto old_event_error_free_param
;
1150 if (copy_from_user(old_uevent_param
,
1151 (struct lttng_kernel_old_event __user
*) arg
,
1152 sizeof(struct lttng_kernel_old_event
))) {
1154 goto old_event_error_free_old_param
;
1157 memcpy(uevent_param
->name
, old_uevent_param
->name
,
1158 sizeof(uevent_param
->name
));
1159 uevent_param
->instrumentation
=
1160 old_uevent_param
->instrumentation
;
1162 switch (old_uevent_param
->instrumentation
) {
1163 case LTTNG_KERNEL_KPROBE
:
1164 uevent_param
->u
.kprobe
.addr
=
1165 old_uevent_param
->u
.kprobe
.addr
;
1166 uevent_param
->u
.kprobe
.offset
=
1167 old_uevent_param
->u
.kprobe
.offset
;
1168 memcpy(uevent_param
->u
.kprobe
.symbol_name
,
1169 old_uevent_param
->u
.kprobe
.symbol_name
,
1170 sizeof(uevent_param
->u
.kprobe
.symbol_name
));
1172 case LTTNG_KERNEL_KRETPROBE
:
1173 uevent_param
->u
.kretprobe
.addr
=
1174 old_uevent_param
->u
.kretprobe
.addr
;
1175 uevent_param
->u
.kretprobe
.offset
=
1176 old_uevent_param
->u
.kretprobe
.offset
;
1177 memcpy(uevent_param
->u
.kretprobe
.symbol_name
,
1178 old_uevent_param
->u
.kretprobe
.symbol_name
,
1179 sizeof(uevent_param
->u
.kretprobe
.symbol_name
));
1181 case LTTNG_KERNEL_FUNCTION
:
1182 memcpy(uevent_param
->u
.ftrace
.symbol_name
,
1183 old_uevent_param
->u
.ftrace
.symbol_name
,
1184 sizeof(uevent_param
->u
.ftrace
.symbol_name
));
1189 ret
= lttng_abi_create_event(file
, uevent_param
);
1191 old_event_error_free_old_param
:
1192 kfree(old_uevent_param
);
1193 old_event_error_free_param
:
1194 kfree(uevent_param
);
1198 case LTTNG_KERNEL_EVENT
:
1200 struct lttng_kernel_event uevent_param
;
1202 if (copy_from_user(&uevent_param
,
1203 (struct lttng_kernel_event __user
*) arg
,
1204 sizeof(uevent_param
)))
1206 return lttng_abi_create_event(file
, &uevent_param
);
1208 case LTTNG_KERNEL_OLD_CONTEXT
:
1210 struct lttng_kernel_context
*ucontext_param
;
1211 struct lttng_kernel_old_context
*old_ucontext_param
;
1214 ucontext_param
= kmalloc(sizeof(struct lttng_kernel_context
),
1216 if (!ucontext_param
) {
1220 old_ucontext_param
= kmalloc(sizeof(struct lttng_kernel_old_context
),
1222 if (!old_ucontext_param
) {
1224 goto old_ctx_error_free_param
;
1227 if (copy_from_user(old_ucontext_param
,
1228 (struct lttng_kernel_old_context __user
*) arg
,
1229 sizeof(struct lttng_kernel_old_context
))) {
1231 goto old_ctx_error_free_old_param
;
1233 ucontext_param
->ctx
= old_ucontext_param
->ctx
;
1234 memcpy(ucontext_param
->padding
, old_ucontext_param
->padding
,
1235 sizeof(ucontext_param
->padding
));
1236 /* only type that uses the union */
1237 if (old_ucontext_param
->ctx
== LTTNG_KERNEL_CONTEXT_PERF_COUNTER
) {
1238 ucontext_param
->u
.perf_counter
.type
=
1239 old_ucontext_param
->u
.perf_counter
.type
;
1240 ucontext_param
->u
.perf_counter
.config
=
1241 old_ucontext_param
->u
.perf_counter
.config
;
1242 memcpy(ucontext_param
->u
.perf_counter
.name
,
1243 old_ucontext_param
->u
.perf_counter
.name
,
1244 sizeof(ucontext_param
->u
.perf_counter
.name
));
1247 ret
= lttng_abi_add_context(file
,
1249 &channel
->ctx
, channel
->session
);
1251 old_ctx_error_free_old_param
:
1252 kfree(old_ucontext_param
);
1253 old_ctx_error_free_param
:
1254 kfree(ucontext_param
);
1258 case LTTNG_KERNEL_CONTEXT
:
1260 struct lttng_kernel_context ucontext_param
;
1262 if (copy_from_user(&ucontext_param
,
1263 (struct lttng_kernel_context __user
*) arg
,
1264 sizeof(ucontext_param
)))
1266 return lttng_abi_add_context(file
,
1268 &channel
->ctx
, channel
->session
);
1270 case LTTNG_KERNEL_OLD_ENABLE
:
1271 case LTTNG_KERNEL_ENABLE
:
1272 return lttng_channel_enable(channel
);
1273 case LTTNG_KERNEL_OLD_DISABLE
:
1274 case LTTNG_KERNEL_DISABLE
:
1275 return lttng_channel_disable(channel
);
1276 case LTTNG_KERNEL_SYSCALL_MASK
:
1277 return lttng_channel_syscall_mask(channel
,
1278 (struct lttng_kernel_syscall_mask __user
*) arg
);
1280 return -ENOIOCTLCMD
;
1286 * lttng_metadata_ioctl - lttng syscall through ioctl
1292 * This ioctl implements lttng commands:
1293 * LTTNG_KERNEL_STREAM
1294 * Returns an event stream file descriptor or failure.
1296 * Channel and event file descriptors also hold a reference on the session.
1299 long lttng_metadata_ioctl(struct file
*file
, unsigned int cmd
, unsigned long arg
)
1302 case LTTNG_KERNEL_OLD_STREAM
:
1303 case LTTNG_KERNEL_STREAM
:
1304 return lttng_abi_open_metadata_stream(file
);
1306 return -ENOIOCTLCMD
;
1311 * lttng_channel_poll - lttng stream addition/removal monitoring
1316 unsigned int lttng_channel_poll(struct file
*file
, poll_table
*wait
)
1318 struct lttng_channel
*channel
= file
->private_data
;
1319 unsigned int mask
= 0;
1321 if (file
->f_mode
& FMODE_READ
) {
1322 poll_wait_set_exclusive(wait
);
1323 poll_wait(file
, channel
->ops
->get_hp_wait_queue(channel
->chan
),
1326 if (channel
->ops
->is_disabled(channel
->chan
))
1328 if (channel
->ops
->is_finalized(channel
->chan
))
1330 if (channel
->ops
->buffer_has_read_closed_stream(channel
->chan
))
1331 return POLLIN
| POLLRDNORM
;
1339 int lttng_channel_release(struct inode
*inode
, struct file
*file
)
1341 struct lttng_channel
*channel
= file
->private_data
;
1344 fput(channel
->session
->file
);
1349 int lttng_metadata_channel_release(struct inode
*inode
, struct file
*file
)
1351 struct lttng_channel
*channel
= file
->private_data
;
1354 fput(channel
->session
->file
);
1355 lttng_metadata_channel_destroy(channel
);
1361 static const struct file_operations lttng_channel_fops
= {
1362 .owner
= THIS_MODULE
,
1363 .release
= lttng_channel_release
,
1364 .poll
= lttng_channel_poll
,
1365 .unlocked_ioctl
= lttng_channel_ioctl
,
1366 #ifdef CONFIG_COMPAT
1367 .compat_ioctl
= lttng_channel_ioctl
,
1371 static const struct file_operations lttng_metadata_fops
= {
1372 .owner
= THIS_MODULE
,
1373 .release
= lttng_metadata_channel_release
,
1374 .unlocked_ioctl
= lttng_metadata_ioctl
,
1375 #ifdef CONFIG_COMPAT
1376 .compat_ioctl
= lttng_metadata_ioctl
,
1381 * lttng_event_ioctl - lttng syscall through ioctl
1387 * This ioctl implements lttng commands:
1388 * LTTNG_KERNEL_CONTEXT
1389 * Prepend a context field to each record of this event
1390 * LTTNG_KERNEL_ENABLE
1391 * Enable recording for this event (weak enable)
1392 * LTTNG_KERNEL_DISABLE
1393 * Disable recording for this event (strong disable)
1396 long lttng_event_ioctl(struct file
*file
, unsigned int cmd
, unsigned long arg
)
1398 struct lttng_event
*event
;
1399 struct lttng_enabler
*enabler
;
1400 enum lttng_event_type
*evtype
= file
->private_data
;
1403 case LTTNG_KERNEL_OLD_CONTEXT
:
1405 /* Not implemented */
1408 case LTTNG_KERNEL_CONTEXT
:
1410 /* Not implemented */
1413 case LTTNG_KERNEL_OLD_ENABLE
:
1414 case LTTNG_KERNEL_ENABLE
:
1416 case LTTNG_TYPE_EVENT
:
1417 event
= file
->private_data
;
1418 return lttng_event_enable(event
);
1419 case LTTNG_TYPE_ENABLER
:
1420 enabler
= file
->private_data
;
1421 return lttng_enabler_enable(enabler
);
1426 case LTTNG_KERNEL_OLD_DISABLE
:
1427 case LTTNG_KERNEL_DISABLE
:
1429 case LTTNG_TYPE_EVENT
:
1430 event
= file
->private_data
;
1431 return lttng_event_disable(event
);
1432 case LTTNG_TYPE_ENABLER
:
1433 enabler
= file
->private_data
;
1434 return lttng_enabler_disable(enabler
);
1439 case LTTNG_KERNEL_FILTER
:
1441 case LTTNG_TYPE_EVENT
:
1443 case LTTNG_TYPE_ENABLER
:
1445 enabler
= file
->private_data
;
1446 return lttng_enabler_attach_bytecode(enabler
,
1447 (struct lttng_kernel_filter_bytecode __user
*) arg
);
1452 return -ENOIOCTLCMD
;
1457 int lttng_event_release(struct inode
*inode
, struct file
*file
)
1459 struct lttng_event
*event
;
1460 struct lttng_enabler
*enabler
;
1461 enum lttng_event_type
*evtype
= file
->private_data
;
1467 case LTTNG_TYPE_EVENT
:
1468 event
= file
->private_data
;
1470 fput(event
->chan
->file
);
1472 case LTTNG_TYPE_ENABLER
:
1473 enabler
= file
->private_data
;
1475 fput(enabler
->chan
->file
);
1485 /* TODO: filter control ioctl */
1486 static const struct file_operations lttng_event_fops
= {
1487 .owner
= THIS_MODULE
,
1488 .release
= lttng_event_release
,
1489 .unlocked_ioctl
= lttng_event_ioctl
,
1490 #ifdef CONFIG_COMPAT
1491 .compat_ioctl
= lttng_event_ioctl
,
1495 static int put_u64(uint64_t val
, unsigned long arg
)
1497 return put_user(val
, (uint64_t __user
*) arg
);
1500 static long lttng_stream_ring_buffer_ioctl(struct file
*filp
,
1501 unsigned int cmd
, unsigned long arg
)
1503 struct lib_ring_buffer
*buf
= filp
->private_data
;
1504 struct channel
*chan
= buf
->backend
.chan
;
1505 const struct lib_ring_buffer_config
*config
= &chan
->backend
.config
;
1506 const struct lttng_channel_ops
*ops
= chan
->backend
.priv_ops
;
1509 if (atomic_read(&chan
->record_disabled
))
1513 case LTTNG_RING_BUFFER_GET_TIMESTAMP_BEGIN
:
1517 ret
= ops
->timestamp_begin(config
, buf
, &ts
);
1520 return put_u64(ts
, arg
);
1522 case LTTNG_RING_BUFFER_GET_TIMESTAMP_END
:
1526 ret
= ops
->timestamp_end(config
, buf
, &ts
);
1529 return put_u64(ts
, arg
);
1531 case LTTNG_RING_BUFFER_GET_EVENTS_DISCARDED
:
1535 ret
= ops
->events_discarded(config
, buf
, &ed
);
1538 return put_u64(ed
, arg
);
1540 case LTTNG_RING_BUFFER_GET_CONTENT_SIZE
:
1544 ret
= ops
->content_size(config
, buf
, &cs
);
1547 return put_u64(cs
, arg
);
1549 case LTTNG_RING_BUFFER_GET_PACKET_SIZE
:
1553 ret
= ops
->packet_size(config
, buf
, &ps
);
1556 return put_u64(ps
, arg
);
1558 case LTTNG_RING_BUFFER_GET_STREAM_ID
:
1562 ret
= ops
->stream_id(config
, buf
, &si
);
1565 return put_u64(si
, arg
);
1567 case LTTNG_RING_BUFFER_GET_CURRENT_TIMESTAMP
:
1571 ret
= ops
->current_timestamp(config
, buf
, &ts
);
1574 return put_u64(ts
, arg
);
1576 case LTTNG_RING_BUFFER_GET_SEQ_NUM
:
1580 ret
= ops
->sequence_number(config
, buf
, &seq
);
1583 return put_u64(seq
, arg
);
1585 case LTTNG_RING_BUFFER_INSTANCE_ID
:
1589 ret
= ops
->instance_id(config
, buf
, &id
);
1592 return put_u64(id
, arg
);
1595 return lib_ring_buffer_file_operations
.unlocked_ioctl(filp
,
1603 #ifdef CONFIG_COMPAT
1604 static long lttng_stream_ring_buffer_compat_ioctl(struct file
*filp
,
1605 unsigned int cmd
, unsigned long arg
)
1607 struct lib_ring_buffer
*buf
= filp
->private_data
;
1608 struct channel
*chan
= buf
->backend
.chan
;
1609 const struct lib_ring_buffer_config
*config
= &chan
->backend
.config
;
1610 const struct lttng_channel_ops
*ops
= chan
->backend
.priv_ops
;
1613 if (atomic_read(&chan
->record_disabled
))
1617 case LTTNG_RING_BUFFER_COMPAT_GET_TIMESTAMP_BEGIN
:
1621 ret
= ops
->timestamp_begin(config
, buf
, &ts
);
1624 return put_u64(ts
, arg
);
1626 case LTTNG_RING_BUFFER_COMPAT_GET_TIMESTAMP_END
:
1630 ret
= ops
->timestamp_end(config
, buf
, &ts
);
1633 return put_u64(ts
, arg
);
1635 case LTTNG_RING_BUFFER_COMPAT_GET_EVENTS_DISCARDED
:
1639 ret
= ops
->events_discarded(config
, buf
, &ed
);
1642 return put_u64(ed
, arg
);
1644 case LTTNG_RING_BUFFER_COMPAT_GET_CONTENT_SIZE
:
1648 ret
= ops
->content_size(config
, buf
, &cs
);
1651 return put_u64(cs
, arg
);
1653 case LTTNG_RING_BUFFER_COMPAT_GET_PACKET_SIZE
:
1657 ret
= ops
->packet_size(config
, buf
, &ps
);
1660 return put_u64(ps
, arg
);
1662 case LTTNG_RING_BUFFER_COMPAT_GET_STREAM_ID
:
1666 ret
= ops
->stream_id(config
, buf
, &si
);
1669 return put_u64(si
, arg
);
1671 case LTTNG_RING_BUFFER_GET_CURRENT_TIMESTAMP
:
1675 ret
= ops
->current_timestamp(config
, buf
, &ts
);
1678 return put_u64(ts
, arg
);
1680 case LTTNG_RING_BUFFER_COMPAT_GET_SEQ_NUM
:
1684 ret
= ops
->sequence_number(config
, buf
, &seq
);
1687 return put_u64(seq
, arg
);
1689 case LTTNG_RING_BUFFER_COMPAT_INSTANCE_ID
:
1693 ret
= ops
->instance_id(config
, buf
, &id
);
1696 return put_u64(id
, arg
);
1699 return lib_ring_buffer_file_operations
.compat_ioctl(filp
,
1706 #endif /* CONFIG_COMPAT */
1708 static void lttng_stream_override_ring_buffer_fops(void)
1710 lttng_stream_ring_buffer_file_operations
.owner
= THIS_MODULE
;
1711 lttng_stream_ring_buffer_file_operations
.open
=
1712 lib_ring_buffer_file_operations
.open
;
1713 lttng_stream_ring_buffer_file_operations
.release
=
1714 lib_ring_buffer_file_operations
.release
;
1715 lttng_stream_ring_buffer_file_operations
.poll
=
1716 lib_ring_buffer_file_operations
.poll
;
1717 lttng_stream_ring_buffer_file_operations
.splice_read
=
1718 lib_ring_buffer_file_operations
.splice_read
;
1719 lttng_stream_ring_buffer_file_operations
.mmap
=
1720 lib_ring_buffer_file_operations
.mmap
;
1721 lttng_stream_ring_buffer_file_operations
.unlocked_ioctl
=
1722 lttng_stream_ring_buffer_ioctl
;
1723 lttng_stream_ring_buffer_file_operations
.llseek
=
1724 lib_ring_buffer_file_operations
.llseek
;
1725 #ifdef CONFIG_COMPAT
1726 lttng_stream_ring_buffer_file_operations
.compat_ioctl
=
1727 lttng_stream_ring_buffer_compat_ioctl
;
1731 int __init
lttng_abi_init(void)
1735 wrapper_vmalloc_sync_all();
1738 ret
= lttng_tp_mempool_init();
1743 lttng_proc_dentry
= proc_create_data("lttng", S_IRUSR
| S_IWUSR
, NULL
,
1744 <tng_proc_ops
, NULL
);
1746 if (!lttng_proc_dentry
) {
1747 printk(KERN_ERR
"Error creating LTTng control file\n");
1751 lttng_stream_override_ring_buffer_fops();
1755 lttng_tp_mempool_destroy();
1756 lttng_clock_unref();
1760 /* No __exit annotation because used by init error path too. */
1761 void lttng_abi_exit(void)
1763 lttng_tp_mempool_destroy();
1764 lttng_clock_unref();
1765 if (lttng_proc_dentry
)
1766 remove_proc_entry("lttng", NULL
);