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
;
68 static const struct file_operations lttng_fops
;
69 static const struct file_operations lttng_session_fops
;
70 static const struct file_operations lttng_channel_fops
;
71 static const struct file_operations lttng_metadata_fops
;
72 static const struct file_operations lttng_event_fops
;
73 static struct file_operations lttng_stream_ring_buffer_file_operations
;
75 static int put_u64(uint64_t val
, unsigned long arg
);
78 * Teardown management: opened file descriptors keep a refcount on the module,
79 * so it can only exit when all file descriptors are closed.
83 int lttng_abi_create_session(void)
85 struct lttng_session
*session
;
86 struct file
*session_file
;
89 session
= lttng_session_create();
92 session_fd
= lttng_get_unused_fd();
97 session_file
= anon_inode_getfile("[lttng_session]",
100 if (IS_ERR(session_file
)) {
101 ret
= PTR_ERR(session_file
);
104 session
->file
= session_file
;
105 fd_install(session_fd
, session_file
);
109 put_unused_fd(session_fd
);
111 lttng_session_destroy(session
);
116 int lttng_abi_tracepoint_list(void)
118 struct file
*tracepoint_list_file
;
121 file_fd
= lttng_get_unused_fd();
127 tracepoint_list_file
= anon_inode_getfile("[lttng_tracepoint_list]",
128 <tng_tracepoint_list_fops
,
130 if (IS_ERR(tracepoint_list_file
)) {
131 ret
= PTR_ERR(tracepoint_list_file
);
134 ret
= lttng_tracepoint_list_fops
.open(NULL
, tracepoint_list_file
);
137 fd_install(file_fd
, tracepoint_list_file
);
141 fput(tracepoint_list_file
);
143 put_unused_fd(file_fd
);
148 #ifndef CONFIG_HAVE_SYSCALL_TRACEPOINTS
150 int lttng_abi_syscall_list(void)
156 int lttng_abi_syscall_list(void)
158 struct file
*syscall_list_file
;
161 file_fd
= lttng_get_unused_fd();
167 syscall_list_file
= anon_inode_getfile("[lttng_syscall_list]",
168 <tng_syscall_list_fops
,
170 if (IS_ERR(syscall_list_file
)) {
171 ret
= PTR_ERR(syscall_list_file
);
174 ret
= lttng_syscall_list_fops
.open(NULL
, syscall_list_file
);
177 fd_install(file_fd
, syscall_list_file
);
181 fput(syscall_list_file
);
183 put_unused_fd(file_fd
);
190 void lttng_abi_tracer_version(struct lttng_kernel_tracer_version
*v
)
192 v
->major
= LTTNG_MODULES_MAJOR_VERSION
;
193 v
->minor
= LTTNG_MODULES_MINOR_VERSION
;
194 v
->patchlevel
= LTTNG_MODULES_PATCHLEVEL_VERSION
;
198 void lttng_abi_tracer_abi_version(struct lttng_kernel_tracer_abi_version
*v
)
200 v
->major
= LTTNG_MODULES_ABI_MAJOR_VERSION
;
201 v
->minor
= LTTNG_MODULES_ABI_MINOR_VERSION
;
205 long lttng_abi_add_context(struct file
*file
,
206 struct lttng_kernel_context
*context_param
,
207 struct lttng_ctx
**ctx
, struct lttng_session
*session
)
210 if (session
->been_active
)
213 switch (context_param
->ctx
) {
214 case LTTNG_KERNEL_CONTEXT_PID
:
215 return lttng_add_pid_to_ctx(ctx
);
216 case LTTNG_KERNEL_CONTEXT_PRIO
:
217 return lttng_add_prio_to_ctx(ctx
);
218 case LTTNG_KERNEL_CONTEXT_NICE
:
219 return lttng_add_nice_to_ctx(ctx
);
220 case LTTNG_KERNEL_CONTEXT_VPID
:
221 return lttng_add_vpid_to_ctx(ctx
);
222 case LTTNG_KERNEL_CONTEXT_TID
:
223 return lttng_add_tid_to_ctx(ctx
);
224 case LTTNG_KERNEL_CONTEXT_VTID
:
225 return lttng_add_vtid_to_ctx(ctx
);
226 case LTTNG_KERNEL_CONTEXT_PPID
:
227 return lttng_add_ppid_to_ctx(ctx
);
228 case LTTNG_KERNEL_CONTEXT_VPPID
:
229 return lttng_add_vppid_to_ctx(ctx
);
230 case LTTNG_KERNEL_CONTEXT_PERF_COUNTER
:
231 context_param
->u
.perf_counter
.name
[LTTNG_KERNEL_SYM_NAME_LEN
- 1] = '\0';
232 return lttng_add_perf_counter_to_ctx(context_param
->u
.perf_counter
.type
,
233 context_param
->u
.perf_counter
.config
,
234 context_param
->u
.perf_counter
.name
,
236 case LTTNG_KERNEL_CONTEXT_PROCNAME
:
237 return lttng_add_procname_to_ctx(ctx
);
238 case LTTNG_KERNEL_CONTEXT_HOSTNAME
:
239 return lttng_add_hostname_to_ctx(ctx
);
240 case LTTNG_KERNEL_CONTEXT_CPU_ID
:
241 return lttng_add_cpu_id_to_ctx(ctx
);
242 case LTTNG_KERNEL_CONTEXT_INTERRUPTIBLE
:
243 return lttng_add_interruptible_to_ctx(ctx
);
244 case LTTNG_KERNEL_CONTEXT_NEED_RESCHEDULE
:
245 return lttng_add_need_reschedule_to_ctx(ctx
);
246 case LTTNG_KERNEL_CONTEXT_PREEMPTIBLE
:
247 return lttng_add_preemptible_to_ctx(ctx
);
248 case LTTNG_KERNEL_CONTEXT_MIGRATABLE
:
249 return lttng_add_migratable_to_ctx(ctx
);
256 * lttng_ioctl - lttng syscall through ioctl
262 * This ioctl implements lttng commands:
263 * LTTNG_KERNEL_SESSION
264 * Returns a LTTng trace session file descriptor
265 * LTTNG_KERNEL_TRACER_VERSION
266 * Returns the LTTng kernel tracer version
267 * LTTNG_KERNEL_TRACEPOINT_LIST
268 * Returns a file descriptor listing available tracepoints
269 * LTTNG_KERNEL_WAIT_QUIESCENT
270 * Returns after all previously running probes have completed
271 * LTTNG_KERNEL_TRACER_ABI_VERSION
272 * Returns the LTTng kernel tracer ABI version
274 * The returned session will be deleted when its file descriptor is closed.
277 long lttng_ioctl(struct file
*file
, unsigned int cmd
, unsigned long arg
)
280 case LTTNG_KERNEL_OLD_SESSION
:
281 case LTTNG_KERNEL_SESSION
:
282 return lttng_abi_create_session();
283 case LTTNG_KERNEL_OLD_TRACER_VERSION
:
285 struct lttng_kernel_tracer_version v
;
286 struct lttng_kernel_old_tracer_version oldv
;
287 struct lttng_kernel_old_tracer_version
*uversion
=
288 (struct lttng_kernel_old_tracer_version __user
*) arg
;
290 lttng_abi_tracer_version(&v
);
291 oldv
.major
= v
.major
;
292 oldv
.minor
= v
.minor
;
293 oldv
.patchlevel
= v
.patchlevel
;
295 if (copy_to_user(uversion
, &oldv
, sizeof(oldv
)))
299 case LTTNG_KERNEL_TRACER_VERSION
:
301 struct lttng_kernel_tracer_version version
;
302 struct lttng_kernel_tracer_version
*uversion
=
303 (struct lttng_kernel_tracer_version __user
*) arg
;
305 lttng_abi_tracer_version(&version
);
307 if (copy_to_user(uversion
, &version
, sizeof(version
)))
311 case LTTNG_KERNEL_TRACER_ABI_VERSION
:
313 struct lttng_kernel_tracer_abi_version version
;
314 struct lttng_kernel_tracer_abi_version
*uversion
=
315 (struct lttng_kernel_tracer_abi_version __user
*) arg
;
317 lttng_abi_tracer_abi_version(&version
);
319 if (copy_to_user(uversion
, &version
, sizeof(version
)))
323 case LTTNG_KERNEL_OLD_TRACEPOINT_LIST
:
324 case LTTNG_KERNEL_TRACEPOINT_LIST
:
325 return lttng_abi_tracepoint_list();
326 case LTTNG_KERNEL_SYSCALL_LIST
:
327 return lttng_abi_syscall_list();
328 case LTTNG_KERNEL_OLD_WAIT_QUIESCENT
:
329 case LTTNG_KERNEL_WAIT_QUIESCENT
:
332 case LTTNG_KERNEL_OLD_CALIBRATE
:
334 struct lttng_kernel_old_calibrate __user
*ucalibrate
=
335 (struct lttng_kernel_old_calibrate __user
*) arg
;
336 struct lttng_kernel_old_calibrate old_calibrate
;
337 struct lttng_kernel_calibrate calibrate
;
340 if (copy_from_user(&old_calibrate
, ucalibrate
, sizeof(old_calibrate
)))
342 calibrate
.type
= old_calibrate
.type
;
343 ret
= lttng_calibrate(&calibrate
);
344 if (copy_to_user(ucalibrate
, &old_calibrate
, sizeof(old_calibrate
)))
348 case LTTNG_KERNEL_CALIBRATE
:
350 struct lttng_kernel_calibrate __user
*ucalibrate
=
351 (struct lttng_kernel_calibrate __user
*) arg
;
352 struct lttng_kernel_calibrate calibrate
;
355 if (copy_from_user(&calibrate
, ucalibrate
, sizeof(calibrate
)))
357 ret
= lttng_calibrate(&calibrate
);
358 if (copy_to_user(ucalibrate
, &calibrate
, sizeof(calibrate
)))
367 static const struct file_operations lttng_fops
= {
368 .owner
= THIS_MODULE
,
369 .unlocked_ioctl
= lttng_ioctl
,
371 .compat_ioctl
= lttng_ioctl
,
376 int lttng_abi_create_channel(struct file
*session_file
,
377 struct lttng_kernel_channel
*chan_param
,
378 enum channel_type channel_type
)
380 struct lttng_session
*session
= session_file
->private_data
;
381 const struct file_operations
*fops
= NULL
;
382 const char *transport_name
;
383 struct lttng_channel
*chan
;
384 struct file
*chan_file
;
388 chan_fd
= lttng_get_unused_fd();
393 switch (channel_type
) {
394 case PER_CPU_CHANNEL
:
395 fops
= <tng_channel_fops
;
397 case METADATA_CHANNEL
:
398 fops
= <tng_metadata_fops
;
402 chan_file
= anon_inode_getfile("[lttng_channel]",
405 if (IS_ERR(chan_file
)) {
406 ret
= PTR_ERR(chan_file
);
409 switch (channel_type
) {
410 case PER_CPU_CHANNEL
:
411 if (chan_param
->output
== LTTNG_KERNEL_SPLICE
) {
412 transport_name
= chan_param
->overwrite
?
413 "relay-overwrite" : "relay-discard";
414 } else if (chan_param
->output
== LTTNG_KERNEL_MMAP
) {
415 transport_name
= chan_param
->overwrite
?
416 "relay-overwrite-mmap" : "relay-discard-mmap";
421 case METADATA_CHANNEL
:
422 if (chan_param
->output
== LTTNG_KERNEL_SPLICE
)
423 transport_name
= "relay-metadata";
424 else if (chan_param
->output
== LTTNG_KERNEL_MMAP
)
425 transport_name
= "relay-metadata-mmap";
430 transport_name
= "<unknown>";
433 if (atomic_long_add_unless(&session_file
->f_count
,
434 1, INT_MAX
) == INT_MAX
) {
438 * We tolerate no failure path after channel creation. It will stay
439 * invariant for the rest of the session.
441 chan
= lttng_channel_create(session
, transport_name
, NULL
,
442 chan_param
->subbuf_size
,
443 chan_param
->num_subbuf
,
444 chan_param
->switch_timer_interval
,
445 chan_param
->read_timer_interval
,
451 chan
->file
= chan_file
;
452 chan_file
->private_data
= chan
;
453 fd_install(chan_fd
, chan_file
);
458 atomic_long_dec(&session_file
->f_count
);
462 put_unused_fd(chan_fd
);
468 * lttng_session_ioctl - lttng session fd ioctl
474 * This ioctl implements lttng commands:
475 * LTTNG_KERNEL_CHANNEL
476 * Returns a LTTng channel file descriptor
477 * LTTNG_KERNEL_ENABLE
478 * Enables tracing for a session (weak enable)
479 * LTTNG_KERNEL_DISABLE
480 * Disables tracing for a session (strong disable)
481 * LTTNG_KERNEL_METADATA
482 * Returns a LTTng metadata file descriptor
483 * LTTNG_KERNEL_SESSION_TRACK_PID
484 * Add PID to session tracker
485 * LTTNG_KERNEL_SESSION_UNTRACK_PID
486 * Remove PID from session tracker
488 * The returned channel will be deleted when its file descriptor is closed.
491 long lttng_session_ioctl(struct file
*file
, unsigned int cmd
, unsigned long arg
)
493 struct lttng_session
*session
= file
->private_data
;
496 case LTTNG_KERNEL_OLD_CHANNEL
:
498 struct lttng_kernel_channel chan_param
;
499 struct lttng_kernel_old_channel old_chan_param
;
501 if (copy_from_user(&old_chan_param
,
502 (struct lttng_kernel_old_channel __user
*) arg
,
503 sizeof(struct lttng_kernel_old_channel
)))
505 chan_param
.overwrite
= old_chan_param
.overwrite
;
506 chan_param
.subbuf_size
= old_chan_param
.subbuf_size
;
507 chan_param
.num_subbuf
= old_chan_param
.num_subbuf
;
508 chan_param
.switch_timer_interval
= old_chan_param
.switch_timer_interval
;
509 chan_param
.read_timer_interval
= old_chan_param
.read_timer_interval
;
510 chan_param
.output
= old_chan_param
.output
;
512 return lttng_abi_create_channel(file
, &chan_param
,
515 case LTTNG_KERNEL_CHANNEL
:
517 struct lttng_kernel_channel chan_param
;
519 if (copy_from_user(&chan_param
,
520 (struct lttng_kernel_channel __user
*) arg
,
521 sizeof(struct lttng_kernel_channel
)))
523 return lttng_abi_create_channel(file
, &chan_param
,
526 case LTTNG_KERNEL_OLD_SESSION_START
:
527 case LTTNG_KERNEL_OLD_ENABLE
:
528 case LTTNG_KERNEL_SESSION_START
:
529 case LTTNG_KERNEL_ENABLE
:
530 return lttng_session_enable(session
);
531 case LTTNG_KERNEL_OLD_SESSION_STOP
:
532 case LTTNG_KERNEL_OLD_DISABLE
:
533 case LTTNG_KERNEL_SESSION_STOP
:
534 case LTTNG_KERNEL_DISABLE
:
535 return lttng_session_disable(session
);
536 case LTTNG_KERNEL_OLD_METADATA
:
538 struct lttng_kernel_channel chan_param
;
539 struct lttng_kernel_old_channel old_chan_param
;
541 if (copy_from_user(&old_chan_param
,
542 (struct lttng_kernel_old_channel __user
*) arg
,
543 sizeof(struct lttng_kernel_old_channel
)))
545 chan_param
.overwrite
= old_chan_param
.overwrite
;
546 chan_param
.subbuf_size
= old_chan_param
.subbuf_size
;
547 chan_param
.num_subbuf
= old_chan_param
.num_subbuf
;
548 chan_param
.switch_timer_interval
= old_chan_param
.switch_timer_interval
;
549 chan_param
.read_timer_interval
= old_chan_param
.read_timer_interval
;
550 chan_param
.output
= old_chan_param
.output
;
552 return lttng_abi_create_channel(file
, &chan_param
,
555 case LTTNG_KERNEL_METADATA
:
557 struct lttng_kernel_channel chan_param
;
559 if (copy_from_user(&chan_param
,
560 (struct lttng_kernel_channel __user
*) arg
,
561 sizeof(struct lttng_kernel_channel
)))
563 return lttng_abi_create_channel(file
, &chan_param
,
566 case LTTNG_KERNEL_SESSION_TRACK_PID
:
567 return lttng_session_track_pid(session
, (int) arg
);
568 case LTTNG_KERNEL_SESSION_UNTRACK_PID
:
569 return lttng_session_untrack_pid(session
, (int) arg
);
570 case LTTNG_KERNEL_SESSION_LIST_TRACKER_PIDS
:
571 return lttng_session_list_tracker_pids(session
);
572 case LTTNG_KERNEL_SESSION_METADATA_REGEN
:
573 return lttng_session_metadata_regenerate(session
);
574 case LTTNG_KERNEL_SESSION_STATEDUMP
:
575 return lttng_session_statedump(session
);
582 * Called when the last file reference is dropped.
584 * Big fat note: channels and events are invariant for the whole session after
585 * their creation. So this session destruction also destroys all channel and
586 * event structures specific to this session (they are not destroyed when their
587 * individual file is released).
590 int lttng_session_release(struct inode
*inode
, struct file
*file
)
592 struct lttng_session
*session
= file
->private_data
;
595 lttng_session_destroy(session
);
599 static const struct file_operations lttng_session_fops
= {
600 .owner
= THIS_MODULE
,
601 .release
= lttng_session_release
,
602 .unlocked_ioctl
= lttng_session_ioctl
,
604 .compat_ioctl
= lttng_session_ioctl
,
609 * lttng_metadata_ring_buffer_poll - LTTng ring buffer poll file operation
613 * Handles the poll operations for the metadata channels.
616 unsigned int lttng_metadata_ring_buffer_poll(struct file
*filp
,
619 struct lttng_metadata_stream
*stream
= filp
->private_data
;
620 struct lib_ring_buffer
*buf
= stream
->priv
;
622 unsigned int mask
= 0;
624 if (filp
->f_mode
& FMODE_READ
) {
625 poll_wait_set_exclusive(wait
);
626 poll_wait(filp
, &stream
->read_wait
, wait
);
628 finalized
= stream
->finalized
;
631 * lib_ring_buffer_is_finalized() contains a smp_rmb()
632 * ordering finalized load before offsets loads.
634 WARN_ON(atomic_long_read(&buf
->active_readers
) != 1);
639 mutex_lock(&stream
->metadata_cache
->lock
);
640 if (stream
->metadata_cache
->metadata_written
>
641 stream
->metadata_out
)
643 mutex_unlock(&stream
->metadata_cache
->lock
);
650 void lttng_metadata_ring_buffer_ioctl_put_next_subbuf(struct file
*filp
,
651 unsigned int cmd
, unsigned long arg
)
653 struct lttng_metadata_stream
*stream
= filp
->private_data
;
655 stream
->metadata_out
= stream
->metadata_in
;
659 * Reset the counter of how much metadata has been consumed to 0. That way,
660 * the consumer receives the content of the metadata cache unchanged. This is
661 * different from the metadata_regenerate where the offset from epoch is
662 * resampled, here we want the exact same content as the last time the metadata
663 * was generated. This command is only possible if all the metadata written
664 * in the cache has been output to the metadata stream to avoid corrupting the
667 * Return 0 on success, a negative value on error.
670 int lttng_metadata_cache_dump(struct lttng_metadata_stream
*stream
)
673 struct lttng_metadata_cache
*cache
= stream
->metadata_cache
;
675 mutex_lock(&cache
->lock
);
676 if (stream
->metadata_out
!= cache
->metadata_written
) {
680 stream
->metadata_out
= 0;
681 stream
->metadata_in
= 0;
682 wake_up_interruptible(&stream
->read_wait
);
686 mutex_unlock(&cache
->lock
);
691 long lttng_metadata_ring_buffer_ioctl(struct file
*filp
,
692 unsigned int cmd
, unsigned long arg
)
695 struct lttng_metadata_stream
*stream
= filp
->private_data
;
696 struct lib_ring_buffer
*buf
= stream
->priv
;
699 case RING_BUFFER_GET_NEXT_SUBBUF
:
701 struct lttng_metadata_stream
*stream
= filp
->private_data
;
702 struct lib_ring_buffer
*buf
= stream
->priv
;
703 struct channel
*chan
= buf
->backend
.chan
;
705 ret
= lttng_metadata_output_channel(stream
, chan
);
707 lib_ring_buffer_switch_slow(buf
, SWITCH_ACTIVE
);
713 case RING_BUFFER_GET_SUBBUF
:
716 * Random access is not allowed for metadata channel.
720 case RING_BUFFER_FLUSH_EMPTY
: /* Fall-through. */
721 case RING_BUFFER_FLUSH
:
723 struct lttng_metadata_stream
*stream
= filp
->private_data
;
724 struct lib_ring_buffer
*buf
= stream
->priv
;
725 struct channel
*chan
= buf
->backend
.chan
;
728 * Before doing the actual ring buffer flush, write up to one
729 * packet of metadata in the ring buffer.
731 ret
= lttng_metadata_output_channel(stream
, chan
);
736 case RING_BUFFER_GET_METADATA_VERSION
:
738 struct lttng_metadata_stream
*stream
= filp
->private_data
;
740 return put_u64(stream
->version
, arg
);
742 case RING_BUFFER_METADATA_CACHE_DUMP
:
744 struct lttng_metadata_stream
*stream
= filp
->private_data
;
746 return lttng_metadata_cache_dump(stream
);
751 /* PUT_SUBBUF is the one from lib ring buffer, unmodified. */
753 /* Performing lib ring buffer ioctl after our own. */
754 ret
= lib_ring_buffer_ioctl(filp
, cmd
, arg
, buf
);
759 case RING_BUFFER_PUT_NEXT_SUBBUF
:
761 lttng_metadata_ring_buffer_ioctl_put_next_subbuf(filp
,
774 long lttng_metadata_ring_buffer_compat_ioctl(struct file
*filp
,
775 unsigned int cmd
, unsigned long arg
)
778 struct lttng_metadata_stream
*stream
= filp
->private_data
;
779 struct lib_ring_buffer
*buf
= stream
->priv
;
782 case RING_BUFFER_GET_NEXT_SUBBUF
:
784 struct lttng_metadata_stream
*stream
= filp
->private_data
;
785 struct lib_ring_buffer
*buf
= stream
->priv
;
786 struct channel
*chan
= buf
->backend
.chan
;
788 ret
= lttng_metadata_output_channel(stream
, chan
);
790 lib_ring_buffer_switch_slow(buf
, SWITCH_ACTIVE
);
796 case RING_BUFFER_GET_SUBBUF
:
799 * Random access is not allowed for metadata channel.
803 case RING_BUFFER_FLUSH_EMPTY
: /* Fall-through. */
804 case RING_BUFFER_FLUSH
:
806 struct lttng_metadata_stream
*stream
= filp
->private_data
;
807 struct lib_ring_buffer
*buf
= stream
->priv
;
808 struct channel
*chan
= buf
->backend
.chan
;
811 * Before doing the actual ring buffer flush, write up to one
812 * packet of metadata in the ring buffer.
814 ret
= lttng_metadata_output_channel(stream
, chan
);
819 case RING_BUFFER_GET_METADATA_VERSION
:
821 struct lttng_metadata_stream
*stream
= filp
->private_data
;
823 return put_u64(stream
->version
, arg
);
825 case RING_BUFFER_METADATA_CACHE_DUMP
:
827 struct lttng_metadata_stream
*stream
= filp
->private_data
;
829 return lttng_metadata_cache_dump(stream
);
834 /* PUT_SUBBUF is the one from lib ring buffer, unmodified. */
836 /* Performing lib ring buffer ioctl after our own. */
837 ret
= lib_ring_buffer_compat_ioctl(filp
, cmd
, arg
, buf
);
842 case RING_BUFFER_PUT_NEXT_SUBBUF
:
844 lttng_metadata_ring_buffer_ioctl_put_next_subbuf(filp
,
857 * This is not used by anonymous file descriptors. This code is left
858 * there if we ever want to implement an inode with open() operation.
861 int lttng_metadata_ring_buffer_open(struct inode
*inode
, struct file
*file
)
863 struct lttng_metadata_stream
*stream
= inode
->i_private
;
864 struct lib_ring_buffer
*buf
= stream
->priv
;
866 file
->private_data
= buf
;
868 * Since life-time of metadata cache differs from that of
869 * session, we need to keep our own reference on the transport.
871 if (!try_module_get(stream
->transport
->owner
)) {
872 printk(KERN_WARNING
"LTT : Can't lock transport module.\n");
875 return lib_ring_buffer_open(inode
, file
, buf
);
879 int lttng_metadata_ring_buffer_release(struct inode
*inode
, struct file
*file
)
881 struct lttng_metadata_stream
*stream
= file
->private_data
;
882 struct lib_ring_buffer
*buf
= stream
->priv
;
884 kref_put(&stream
->metadata_cache
->refcount
, metadata_cache_destroy
);
885 module_put(stream
->transport
->owner
);
886 return lib_ring_buffer_release(inode
, file
, buf
);
890 ssize_t
lttng_metadata_ring_buffer_splice_read(struct file
*in
, loff_t
*ppos
,
891 struct pipe_inode_info
*pipe
, size_t len
,
894 struct lttng_metadata_stream
*stream
= in
->private_data
;
895 struct lib_ring_buffer
*buf
= stream
->priv
;
897 return lib_ring_buffer_splice_read(in
, ppos
, pipe
, len
,
902 int lttng_metadata_ring_buffer_mmap(struct file
*filp
,
903 struct vm_area_struct
*vma
)
905 struct lttng_metadata_stream
*stream
= filp
->private_data
;
906 struct lib_ring_buffer
*buf
= stream
->priv
;
908 return lib_ring_buffer_mmap(filp
, vma
, buf
);
912 const struct file_operations lttng_metadata_ring_buffer_file_operations
= {
913 .owner
= THIS_MODULE
,
914 .open
= lttng_metadata_ring_buffer_open
,
915 .release
= lttng_metadata_ring_buffer_release
,
916 .poll
= lttng_metadata_ring_buffer_poll
,
917 .splice_read
= lttng_metadata_ring_buffer_splice_read
,
918 .mmap
= lttng_metadata_ring_buffer_mmap
,
919 .unlocked_ioctl
= lttng_metadata_ring_buffer_ioctl
,
920 .llseek
= vfs_lib_ring_buffer_no_llseek
,
922 .compat_ioctl
= lttng_metadata_ring_buffer_compat_ioctl
,
927 int lttng_abi_create_stream_fd(struct file
*channel_file
, void *stream_priv
,
928 const struct file_operations
*fops
)
931 struct file
*stream_file
;
933 stream_fd
= lttng_get_unused_fd();
938 stream_file
= anon_inode_getfile("[lttng_stream]", fops
,
939 stream_priv
, O_RDWR
);
940 if (IS_ERR(stream_file
)) {
941 ret
= PTR_ERR(stream_file
);
945 * OPEN_FMODE, called within anon_inode_getfile/alloc_file, don't honor
946 * FMODE_LSEEK, FMODE_PREAD nor FMODE_PWRITE. We need to read from this
947 * file descriptor, so we set FMODE_PREAD here.
949 stream_file
->f_mode
|= FMODE_PREAD
;
950 fd_install(stream_fd
, stream_file
);
952 * The stream holds a reference to the channel within the generic ring
953 * buffer library, so no need to hold a refcount on the channel and
954 * session files here.
959 put_unused_fd(stream_fd
);
965 int lttng_abi_open_stream(struct file
*channel_file
)
967 struct lttng_channel
*channel
= channel_file
->private_data
;
968 struct lib_ring_buffer
*buf
;
972 buf
= channel
->ops
->buffer_read_open(channel
->chan
);
977 ret
= lttng_abi_create_stream_fd(channel_file
, stream_priv
,
978 <tng_stream_ring_buffer_file_operations
);
985 channel
->ops
->buffer_read_close(buf
);
990 int lttng_abi_open_metadata_stream(struct file
*channel_file
)
992 struct lttng_channel
*channel
= channel_file
->private_data
;
993 struct lttng_session
*session
= channel
->session
;
994 struct lib_ring_buffer
*buf
;
996 struct lttng_metadata_stream
*metadata_stream
;
999 buf
= channel
->ops
->buffer_read_open(channel
->chan
);
1003 metadata_stream
= kzalloc(sizeof(struct lttng_metadata_stream
),
1005 if (!metadata_stream
) {
1009 metadata_stream
->metadata_cache
= session
->metadata_cache
;
1010 init_waitqueue_head(&metadata_stream
->read_wait
);
1011 metadata_stream
->priv
= buf
;
1012 stream_priv
= metadata_stream
;
1013 metadata_stream
->transport
= channel
->transport
;
1016 * Since life-time of metadata cache differs from that of
1017 * session, we need to keep our own reference on the transport.
1019 if (!try_module_get(metadata_stream
->transport
->owner
)) {
1020 printk(KERN_WARNING
"LTT : Can't lock transport module.\n");
1025 if (!lttng_kref_get(&session
->metadata_cache
->refcount
)) {
1030 ret
= lttng_abi_create_stream_fd(channel_file
, stream_priv
,
1031 <tng_metadata_ring_buffer_file_operations
);
1035 list_add(&metadata_stream
->list
,
1036 &session
->metadata_cache
->metadata_stream
);
1040 kref_put(&session
->metadata_cache
->refcount
, metadata_cache_destroy
);
1042 module_put(metadata_stream
->transport
->owner
);
1044 kfree(metadata_stream
);
1046 channel
->ops
->buffer_read_close(buf
);
1051 int lttng_abi_create_event(struct file
*channel_file
,
1052 struct lttng_kernel_event
*event_param
)
1054 struct lttng_channel
*channel
= channel_file
->private_data
;
1056 struct file
*event_file
;
1059 event_param
->name
[LTTNG_KERNEL_SYM_NAME_LEN
- 1] = '\0';
1060 switch (event_param
->instrumentation
) {
1061 case LTTNG_KERNEL_KRETPROBE
:
1062 event_param
->u
.kretprobe
.symbol_name
[LTTNG_KERNEL_SYM_NAME_LEN
- 1] = '\0';
1064 case LTTNG_KERNEL_KPROBE
:
1065 event_param
->u
.kprobe
.symbol_name
[LTTNG_KERNEL_SYM_NAME_LEN
- 1] = '\0';
1067 case LTTNG_KERNEL_FUNCTION
:
1068 event_param
->u
.ftrace
.symbol_name
[LTTNG_KERNEL_SYM_NAME_LEN
- 1] = '\0';
1073 event_fd
= lttng_get_unused_fd();
1078 event_file
= anon_inode_getfile("[lttng_event]",
1081 if (IS_ERR(event_file
)) {
1082 ret
= PTR_ERR(event_file
);
1085 /* The event holds a reference on the channel */
1086 if (atomic_long_add_unless(&channel_file
->f_count
,
1087 1, INT_MAX
) == INT_MAX
) {
1089 goto refcount_error
;
1091 if (event_param
->instrumentation
== LTTNG_KERNEL_TRACEPOINT
1092 || event_param
->instrumentation
== LTTNG_KERNEL_SYSCALL
) {
1093 struct lttng_enabler
*enabler
;
1095 if (strutils_is_star_glob_pattern(event_param
->name
)) {
1097 * If the event name is a star globbing pattern,
1098 * we create the special star globbing enabler.
1100 enabler
= lttng_enabler_create(LTTNG_ENABLER_STAR_GLOB
,
1101 event_param
, channel
);
1103 enabler
= lttng_enabler_create(LTTNG_ENABLER_NAME
,
1104 event_param
, channel
);
1108 struct lttng_event
*event
;
1111 * We tolerate no failure path after event creation. It
1112 * will stay invariant for the rest of the session.
1114 event
= lttng_event_create(channel
, event_param
,
1116 event_param
->instrumentation
);
1117 WARN_ON_ONCE(!event
);
1118 if (IS_ERR(event
)) {
1119 ret
= PTR_ERR(event
);
1124 event_file
->private_data
= priv
;
1125 fd_install(event_fd
, event_file
);
1129 atomic_long_dec(&channel_file
->f_count
);
1133 put_unused_fd(event_fd
);
1139 * lttng_channel_ioctl - lttng syscall through ioctl
1145 * This ioctl implements lttng commands:
1146 * LTTNG_KERNEL_STREAM
1147 * Returns an event stream file descriptor or failure.
1148 * (typically, one event stream records events from one CPU)
1149 * LTTNG_KERNEL_EVENT
1150 * Returns an event file descriptor or failure.
1151 * LTTNG_KERNEL_CONTEXT
1152 * Prepend a context field to each event in the channel
1153 * LTTNG_KERNEL_ENABLE
1154 * Enable recording for events in this channel (weak enable)
1155 * LTTNG_KERNEL_DISABLE
1156 * Disable recording for events in this channel (strong disable)
1158 * Channel and event file descriptors also hold a reference on the session.
1161 long lttng_channel_ioctl(struct file
*file
, unsigned int cmd
, unsigned long arg
)
1163 struct lttng_channel
*channel
= file
->private_data
;
1166 case LTTNG_KERNEL_OLD_STREAM
:
1167 case LTTNG_KERNEL_STREAM
:
1168 return lttng_abi_open_stream(file
);
1169 case LTTNG_KERNEL_OLD_EVENT
:
1171 struct lttng_kernel_event
*uevent_param
;
1172 struct lttng_kernel_old_event
*old_uevent_param
;
1175 uevent_param
= kmalloc(sizeof(struct lttng_kernel_event
),
1177 if (!uevent_param
) {
1181 old_uevent_param
= kmalloc(
1182 sizeof(struct lttng_kernel_old_event
),
1184 if (!old_uevent_param
) {
1186 goto old_event_error_free_param
;
1188 if (copy_from_user(old_uevent_param
,
1189 (struct lttng_kernel_old_event __user
*) arg
,
1190 sizeof(struct lttng_kernel_old_event
))) {
1192 goto old_event_error_free_old_param
;
1195 memcpy(uevent_param
->name
, old_uevent_param
->name
,
1196 sizeof(uevent_param
->name
));
1197 uevent_param
->instrumentation
=
1198 old_uevent_param
->instrumentation
;
1200 switch (old_uevent_param
->instrumentation
) {
1201 case LTTNG_KERNEL_KPROBE
:
1202 uevent_param
->u
.kprobe
.addr
=
1203 old_uevent_param
->u
.kprobe
.addr
;
1204 uevent_param
->u
.kprobe
.offset
=
1205 old_uevent_param
->u
.kprobe
.offset
;
1206 memcpy(uevent_param
->u
.kprobe
.symbol_name
,
1207 old_uevent_param
->u
.kprobe
.symbol_name
,
1208 sizeof(uevent_param
->u
.kprobe
.symbol_name
));
1210 case LTTNG_KERNEL_KRETPROBE
:
1211 uevent_param
->u
.kretprobe
.addr
=
1212 old_uevent_param
->u
.kretprobe
.addr
;
1213 uevent_param
->u
.kretprobe
.offset
=
1214 old_uevent_param
->u
.kretprobe
.offset
;
1215 memcpy(uevent_param
->u
.kretprobe
.symbol_name
,
1216 old_uevent_param
->u
.kretprobe
.symbol_name
,
1217 sizeof(uevent_param
->u
.kretprobe
.symbol_name
));
1219 case LTTNG_KERNEL_FUNCTION
:
1220 memcpy(uevent_param
->u
.ftrace
.symbol_name
,
1221 old_uevent_param
->u
.ftrace
.symbol_name
,
1222 sizeof(uevent_param
->u
.ftrace
.symbol_name
));
1227 ret
= lttng_abi_create_event(file
, uevent_param
);
1229 old_event_error_free_old_param
:
1230 kfree(old_uevent_param
);
1231 old_event_error_free_param
:
1232 kfree(uevent_param
);
1236 case LTTNG_KERNEL_EVENT
:
1238 struct lttng_kernel_event uevent_param
;
1240 if (copy_from_user(&uevent_param
,
1241 (struct lttng_kernel_event __user
*) arg
,
1242 sizeof(uevent_param
)))
1244 return lttng_abi_create_event(file
, &uevent_param
);
1246 case LTTNG_KERNEL_OLD_CONTEXT
:
1248 struct lttng_kernel_context
*ucontext_param
;
1249 struct lttng_kernel_old_context
*old_ucontext_param
;
1252 ucontext_param
= kmalloc(sizeof(struct lttng_kernel_context
),
1254 if (!ucontext_param
) {
1258 old_ucontext_param
= kmalloc(sizeof(struct lttng_kernel_old_context
),
1260 if (!old_ucontext_param
) {
1262 goto old_ctx_error_free_param
;
1265 if (copy_from_user(old_ucontext_param
,
1266 (struct lttng_kernel_old_context __user
*) arg
,
1267 sizeof(struct lttng_kernel_old_context
))) {
1269 goto old_ctx_error_free_old_param
;
1271 ucontext_param
->ctx
= old_ucontext_param
->ctx
;
1272 memcpy(ucontext_param
->padding
, old_ucontext_param
->padding
,
1273 sizeof(ucontext_param
->padding
));
1274 /* only type that uses the union */
1275 if (old_ucontext_param
->ctx
== LTTNG_KERNEL_CONTEXT_PERF_COUNTER
) {
1276 ucontext_param
->u
.perf_counter
.type
=
1277 old_ucontext_param
->u
.perf_counter
.type
;
1278 ucontext_param
->u
.perf_counter
.config
=
1279 old_ucontext_param
->u
.perf_counter
.config
;
1280 memcpy(ucontext_param
->u
.perf_counter
.name
,
1281 old_ucontext_param
->u
.perf_counter
.name
,
1282 sizeof(ucontext_param
->u
.perf_counter
.name
));
1285 ret
= lttng_abi_add_context(file
,
1287 &channel
->ctx
, channel
->session
);
1289 old_ctx_error_free_old_param
:
1290 kfree(old_ucontext_param
);
1291 old_ctx_error_free_param
:
1292 kfree(ucontext_param
);
1296 case LTTNG_KERNEL_CONTEXT
:
1298 struct lttng_kernel_context ucontext_param
;
1300 if (copy_from_user(&ucontext_param
,
1301 (struct lttng_kernel_context __user
*) arg
,
1302 sizeof(ucontext_param
)))
1304 return lttng_abi_add_context(file
,
1306 &channel
->ctx
, channel
->session
);
1308 case LTTNG_KERNEL_OLD_ENABLE
:
1309 case LTTNG_KERNEL_ENABLE
:
1310 return lttng_channel_enable(channel
);
1311 case LTTNG_KERNEL_OLD_DISABLE
:
1312 case LTTNG_KERNEL_DISABLE
:
1313 return lttng_channel_disable(channel
);
1314 case LTTNG_KERNEL_SYSCALL_MASK
:
1315 return lttng_channel_syscall_mask(channel
,
1316 (struct lttng_kernel_syscall_mask __user
*) arg
);
1318 return -ENOIOCTLCMD
;
1324 * lttng_metadata_ioctl - lttng syscall through ioctl
1330 * This ioctl implements lttng commands:
1331 * LTTNG_KERNEL_STREAM
1332 * Returns an event stream file descriptor or failure.
1334 * Channel and event file descriptors also hold a reference on the session.
1337 long lttng_metadata_ioctl(struct file
*file
, unsigned int cmd
, unsigned long arg
)
1340 case LTTNG_KERNEL_OLD_STREAM
:
1341 case LTTNG_KERNEL_STREAM
:
1342 return lttng_abi_open_metadata_stream(file
);
1344 return -ENOIOCTLCMD
;
1349 * lttng_channel_poll - lttng stream addition/removal monitoring
1354 unsigned int lttng_channel_poll(struct file
*file
, poll_table
*wait
)
1356 struct lttng_channel
*channel
= file
->private_data
;
1357 unsigned int mask
= 0;
1359 if (file
->f_mode
& FMODE_READ
) {
1360 poll_wait_set_exclusive(wait
);
1361 poll_wait(file
, channel
->ops
->get_hp_wait_queue(channel
->chan
),
1364 if (channel
->ops
->is_disabled(channel
->chan
))
1366 if (channel
->ops
->is_finalized(channel
->chan
))
1368 if (channel
->ops
->buffer_has_read_closed_stream(channel
->chan
))
1369 return POLLIN
| POLLRDNORM
;
1377 int lttng_channel_release(struct inode
*inode
, struct file
*file
)
1379 struct lttng_channel
*channel
= file
->private_data
;
1382 fput(channel
->session
->file
);
1387 int lttng_metadata_channel_release(struct inode
*inode
, struct file
*file
)
1389 struct lttng_channel
*channel
= file
->private_data
;
1392 fput(channel
->session
->file
);
1393 lttng_metadata_channel_destroy(channel
);
1399 static const struct file_operations lttng_channel_fops
= {
1400 .owner
= THIS_MODULE
,
1401 .release
= lttng_channel_release
,
1402 .poll
= lttng_channel_poll
,
1403 .unlocked_ioctl
= lttng_channel_ioctl
,
1404 #ifdef CONFIG_COMPAT
1405 .compat_ioctl
= lttng_channel_ioctl
,
1409 static const struct file_operations lttng_metadata_fops
= {
1410 .owner
= THIS_MODULE
,
1411 .release
= lttng_metadata_channel_release
,
1412 .unlocked_ioctl
= lttng_metadata_ioctl
,
1413 #ifdef CONFIG_COMPAT
1414 .compat_ioctl
= lttng_metadata_ioctl
,
1419 * lttng_event_ioctl - lttng syscall through ioctl
1425 * This ioctl implements lttng commands:
1426 * LTTNG_KERNEL_CONTEXT
1427 * Prepend a context field to each record of this event
1428 * LTTNG_KERNEL_ENABLE
1429 * Enable recording for this event (weak enable)
1430 * LTTNG_KERNEL_DISABLE
1431 * Disable recording for this event (strong disable)
1434 long lttng_event_ioctl(struct file
*file
, unsigned int cmd
, unsigned long arg
)
1436 struct lttng_event
*event
;
1437 struct lttng_enabler
*enabler
;
1438 enum lttng_event_type
*evtype
= file
->private_data
;
1441 case LTTNG_KERNEL_OLD_CONTEXT
:
1443 /* Not implemented */
1446 case LTTNG_KERNEL_CONTEXT
:
1448 /* Not implemented */
1451 case LTTNG_KERNEL_OLD_ENABLE
:
1452 case LTTNG_KERNEL_ENABLE
:
1454 case LTTNG_TYPE_EVENT
:
1455 event
= file
->private_data
;
1456 return lttng_event_enable(event
);
1457 case LTTNG_TYPE_ENABLER
:
1458 enabler
= file
->private_data
;
1459 return lttng_enabler_enable(enabler
);
1464 case LTTNG_KERNEL_OLD_DISABLE
:
1465 case LTTNG_KERNEL_DISABLE
:
1467 case LTTNG_TYPE_EVENT
:
1468 event
= file
->private_data
;
1469 return lttng_event_disable(event
);
1470 case LTTNG_TYPE_ENABLER
:
1471 enabler
= file
->private_data
;
1472 return lttng_enabler_disable(enabler
);
1477 case LTTNG_KERNEL_FILTER
:
1479 case LTTNG_TYPE_EVENT
:
1481 case LTTNG_TYPE_ENABLER
:
1483 enabler
= file
->private_data
;
1484 return lttng_enabler_attach_bytecode(enabler
,
1485 (struct lttng_kernel_filter_bytecode __user
*) arg
);
1490 return -ENOIOCTLCMD
;
1495 int lttng_event_release(struct inode
*inode
, struct file
*file
)
1497 struct lttng_event
*event
;
1498 struct lttng_enabler
*enabler
;
1499 enum lttng_event_type
*evtype
= file
->private_data
;
1505 case LTTNG_TYPE_EVENT
:
1506 event
= file
->private_data
;
1508 fput(event
->chan
->file
);
1510 case LTTNG_TYPE_ENABLER
:
1511 enabler
= file
->private_data
;
1513 fput(enabler
->chan
->file
);
1523 /* TODO: filter control ioctl */
1524 static const struct file_operations lttng_event_fops
= {
1525 .owner
= THIS_MODULE
,
1526 .release
= lttng_event_release
,
1527 .unlocked_ioctl
= lttng_event_ioctl
,
1528 #ifdef CONFIG_COMPAT
1529 .compat_ioctl
= lttng_event_ioctl
,
1533 static int put_u64(uint64_t val
, unsigned long arg
)
1535 return put_user(val
, (uint64_t __user
*) arg
);
1538 static long lttng_stream_ring_buffer_ioctl(struct file
*filp
,
1539 unsigned int cmd
, unsigned long arg
)
1541 struct lib_ring_buffer
*buf
= filp
->private_data
;
1542 struct channel
*chan
= buf
->backend
.chan
;
1543 const struct lib_ring_buffer_config
*config
= &chan
->backend
.config
;
1544 const struct lttng_channel_ops
*ops
= chan
->backend
.priv_ops
;
1547 if (atomic_read(&chan
->record_disabled
))
1551 case LTTNG_RING_BUFFER_GET_TIMESTAMP_BEGIN
:
1555 ret
= ops
->timestamp_begin(config
, buf
, &ts
);
1558 return put_u64(ts
, arg
);
1560 case LTTNG_RING_BUFFER_GET_TIMESTAMP_END
:
1564 ret
= ops
->timestamp_end(config
, buf
, &ts
);
1567 return put_u64(ts
, arg
);
1569 case LTTNG_RING_BUFFER_GET_EVENTS_DISCARDED
:
1573 ret
= ops
->events_discarded(config
, buf
, &ed
);
1576 return put_u64(ed
, arg
);
1578 case LTTNG_RING_BUFFER_GET_CONTENT_SIZE
:
1582 ret
= ops
->content_size(config
, buf
, &cs
);
1585 return put_u64(cs
, arg
);
1587 case LTTNG_RING_BUFFER_GET_PACKET_SIZE
:
1591 ret
= ops
->packet_size(config
, buf
, &ps
);
1594 return put_u64(ps
, arg
);
1596 case LTTNG_RING_BUFFER_GET_STREAM_ID
:
1600 ret
= ops
->stream_id(config
, buf
, &si
);
1603 return put_u64(si
, arg
);
1605 case LTTNG_RING_BUFFER_GET_CURRENT_TIMESTAMP
:
1609 ret
= ops
->current_timestamp(config
, buf
, &ts
);
1612 return put_u64(ts
, arg
);
1614 case LTTNG_RING_BUFFER_GET_SEQ_NUM
:
1618 ret
= ops
->sequence_number(config
, buf
, &seq
);
1621 return put_u64(seq
, arg
);
1623 case LTTNG_RING_BUFFER_INSTANCE_ID
:
1627 ret
= ops
->instance_id(config
, buf
, &id
);
1630 return put_u64(id
, arg
);
1633 return lib_ring_buffer_file_operations
.unlocked_ioctl(filp
,
1641 #ifdef CONFIG_COMPAT
1642 static long lttng_stream_ring_buffer_compat_ioctl(struct file
*filp
,
1643 unsigned int cmd
, unsigned long arg
)
1645 struct lib_ring_buffer
*buf
= filp
->private_data
;
1646 struct channel
*chan
= buf
->backend
.chan
;
1647 const struct lib_ring_buffer_config
*config
= &chan
->backend
.config
;
1648 const struct lttng_channel_ops
*ops
= chan
->backend
.priv_ops
;
1651 if (atomic_read(&chan
->record_disabled
))
1655 case LTTNG_RING_BUFFER_COMPAT_GET_TIMESTAMP_BEGIN
:
1659 ret
= ops
->timestamp_begin(config
, buf
, &ts
);
1662 return put_u64(ts
, arg
);
1664 case LTTNG_RING_BUFFER_COMPAT_GET_TIMESTAMP_END
:
1668 ret
= ops
->timestamp_end(config
, buf
, &ts
);
1671 return put_u64(ts
, arg
);
1673 case LTTNG_RING_BUFFER_COMPAT_GET_EVENTS_DISCARDED
:
1677 ret
= ops
->events_discarded(config
, buf
, &ed
);
1680 return put_u64(ed
, arg
);
1682 case LTTNG_RING_BUFFER_COMPAT_GET_CONTENT_SIZE
:
1686 ret
= ops
->content_size(config
, buf
, &cs
);
1689 return put_u64(cs
, arg
);
1691 case LTTNG_RING_BUFFER_COMPAT_GET_PACKET_SIZE
:
1695 ret
= ops
->packet_size(config
, buf
, &ps
);
1698 return put_u64(ps
, arg
);
1700 case LTTNG_RING_BUFFER_COMPAT_GET_STREAM_ID
:
1704 ret
= ops
->stream_id(config
, buf
, &si
);
1707 return put_u64(si
, arg
);
1709 case LTTNG_RING_BUFFER_GET_CURRENT_TIMESTAMP
:
1713 ret
= ops
->current_timestamp(config
, buf
, &ts
);
1716 return put_u64(ts
, arg
);
1718 case LTTNG_RING_BUFFER_COMPAT_GET_SEQ_NUM
:
1722 ret
= ops
->sequence_number(config
, buf
, &seq
);
1725 return put_u64(seq
, arg
);
1727 case LTTNG_RING_BUFFER_COMPAT_INSTANCE_ID
:
1731 ret
= ops
->instance_id(config
, buf
, &id
);
1734 return put_u64(id
, arg
);
1737 return lib_ring_buffer_file_operations
.compat_ioctl(filp
,
1744 #endif /* CONFIG_COMPAT */
1746 static void lttng_stream_override_ring_buffer_fops(void)
1748 lttng_stream_ring_buffer_file_operations
.owner
= THIS_MODULE
;
1749 lttng_stream_ring_buffer_file_operations
.open
=
1750 lib_ring_buffer_file_operations
.open
;
1751 lttng_stream_ring_buffer_file_operations
.release
=
1752 lib_ring_buffer_file_operations
.release
;
1753 lttng_stream_ring_buffer_file_operations
.poll
=
1754 lib_ring_buffer_file_operations
.poll
;
1755 lttng_stream_ring_buffer_file_operations
.splice_read
=
1756 lib_ring_buffer_file_operations
.splice_read
;
1757 lttng_stream_ring_buffer_file_operations
.mmap
=
1758 lib_ring_buffer_file_operations
.mmap
;
1759 lttng_stream_ring_buffer_file_operations
.unlocked_ioctl
=
1760 lttng_stream_ring_buffer_ioctl
;
1761 lttng_stream_ring_buffer_file_operations
.llseek
=
1762 lib_ring_buffer_file_operations
.llseek
;
1763 #ifdef CONFIG_COMPAT
1764 lttng_stream_ring_buffer_file_operations
.compat_ioctl
=
1765 lttng_stream_ring_buffer_compat_ioctl
;
1769 int __init
lttng_abi_init(void)
1773 wrapper_vmalloc_sync_all();
1776 ret
= lttng_tp_mempool_init();
1781 lttng_proc_dentry
= proc_create_data("lttng", S_IRUSR
| S_IWUSR
, NULL
,
1784 if (!lttng_proc_dentry
) {
1785 printk(KERN_ERR
"Error creating LTTng control file\n");
1789 lttng_stream_override_ring_buffer_fops();
1793 lttng_tp_mempool_destroy();
1794 lttng_clock_unref();
1798 /* No __exit annotation because used by init error path too. */
1799 void lttng_abi_exit(void)
1801 lttng_tp_mempool_destroy();
1802 lttng_clock_unref();
1803 if (lttng_proc_dentry
)
1804 remove_proc_entry("lttng", NULL
);