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
);
239 case LTTNG_KERNEL_CONTEXT_CGROUP_NS
:
240 return lttng_add_cgroup_ns_to_ctx(ctx
);
241 case LTTNG_KERNEL_CONTEXT_IPC_NS
:
242 return lttng_add_ipc_ns_to_ctx(ctx
);
243 case LTTNG_KERNEL_CONTEXT_MNT_NS
:
244 return lttng_add_mnt_ns_to_ctx(ctx
);
245 case LTTNG_KERNEL_CONTEXT_NET_NS
:
246 return lttng_add_net_ns_to_ctx(ctx
);
247 case LTTNG_KERNEL_CONTEXT_PID_NS
:
248 return lttng_add_pid_ns_to_ctx(ctx
);
249 case LTTNG_KERNEL_CONTEXT_USER_NS
:
250 return lttng_add_user_ns_to_ctx(ctx
);
251 case LTTNG_KERNEL_CONTEXT_UTS_NS
:
252 return lttng_add_uts_ns_to_ctx(ctx
);
259 * lttng_ioctl - lttng syscall through ioctl
265 * This ioctl implements lttng commands:
266 * LTTNG_KERNEL_SESSION
267 * Returns a LTTng trace session file descriptor
268 * LTTNG_KERNEL_TRACER_VERSION
269 * Returns the LTTng kernel tracer version
270 * LTTNG_KERNEL_TRACEPOINT_LIST
271 * Returns a file descriptor listing available tracepoints
272 * LTTNG_KERNEL_WAIT_QUIESCENT
273 * Returns after all previously running probes have completed
274 * LTTNG_KERNEL_TRACER_ABI_VERSION
275 * Returns the LTTng kernel tracer ABI version
277 * The returned session will be deleted when its file descriptor is closed.
280 long lttng_ioctl(struct file
*file
, unsigned int cmd
, unsigned long arg
)
283 case LTTNG_KERNEL_OLD_SESSION
:
284 case LTTNG_KERNEL_SESSION
:
285 return lttng_abi_create_session();
286 case LTTNG_KERNEL_OLD_TRACER_VERSION
:
288 struct lttng_kernel_tracer_version v
;
289 struct lttng_kernel_old_tracer_version oldv
;
290 struct lttng_kernel_old_tracer_version
*uversion
=
291 (struct lttng_kernel_old_tracer_version __user
*) arg
;
293 lttng_abi_tracer_version(&v
);
294 oldv
.major
= v
.major
;
295 oldv
.minor
= v
.minor
;
296 oldv
.patchlevel
= v
.patchlevel
;
298 if (copy_to_user(uversion
, &oldv
, sizeof(oldv
)))
302 case LTTNG_KERNEL_TRACER_VERSION
:
304 struct lttng_kernel_tracer_version version
;
305 struct lttng_kernel_tracer_version
*uversion
=
306 (struct lttng_kernel_tracer_version __user
*) arg
;
308 lttng_abi_tracer_version(&version
);
310 if (copy_to_user(uversion
, &version
, sizeof(version
)))
314 case LTTNG_KERNEL_TRACER_ABI_VERSION
:
316 struct lttng_kernel_tracer_abi_version version
;
317 struct lttng_kernel_tracer_abi_version
*uversion
=
318 (struct lttng_kernel_tracer_abi_version __user
*) arg
;
320 lttng_abi_tracer_abi_version(&version
);
322 if (copy_to_user(uversion
, &version
, sizeof(version
)))
326 case LTTNG_KERNEL_OLD_TRACEPOINT_LIST
:
327 case LTTNG_KERNEL_TRACEPOINT_LIST
:
328 return lttng_abi_tracepoint_list();
329 case LTTNG_KERNEL_SYSCALL_LIST
:
330 return lttng_abi_syscall_list();
331 case LTTNG_KERNEL_OLD_WAIT_QUIESCENT
:
332 case LTTNG_KERNEL_WAIT_QUIESCENT
:
335 case LTTNG_KERNEL_OLD_CALIBRATE
:
337 struct lttng_kernel_old_calibrate __user
*ucalibrate
=
338 (struct lttng_kernel_old_calibrate __user
*) arg
;
339 struct lttng_kernel_old_calibrate old_calibrate
;
340 struct lttng_kernel_calibrate calibrate
;
343 if (copy_from_user(&old_calibrate
, ucalibrate
, sizeof(old_calibrate
)))
345 calibrate
.type
= old_calibrate
.type
;
346 ret
= lttng_calibrate(&calibrate
);
347 if (copy_to_user(ucalibrate
, &old_calibrate
, sizeof(old_calibrate
)))
351 case LTTNG_KERNEL_CALIBRATE
:
353 struct lttng_kernel_calibrate __user
*ucalibrate
=
354 (struct lttng_kernel_calibrate __user
*) arg
;
355 struct lttng_kernel_calibrate calibrate
;
358 if (copy_from_user(&calibrate
, ucalibrate
, sizeof(calibrate
)))
360 ret
= lttng_calibrate(&calibrate
);
361 if (copy_to_user(ucalibrate
, &calibrate
, sizeof(calibrate
)))
370 static const struct file_operations lttng_fops
= {
371 .owner
= THIS_MODULE
,
372 .unlocked_ioctl
= lttng_ioctl
,
374 .compat_ioctl
= lttng_ioctl
,
379 int lttng_abi_create_channel(struct file
*session_file
,
380 struct lttng_kernel_channel
*chan_param
,
381 enum channel_type channel_type
)
383 struct lttng_session
*session
= session_file
->private_data
;
384 const struct file_operations
*fops
= NULL
;
385 const char *transport_name
;
386 struct lttng_channel
*chan
;
387 struct file
*chan_file
;
391 chan_fd
= lttng_get_unused_fd();
396 switch (channel_type
) {
397 case PER_CPU_CHANNEL
:
398 fops
= <tng_channel_fops
;
400 case METADATA_CHANNEL
:
401 fops
= <tng_metadata_fops
;
405 chan_file
= anon_inode_getfile("[lttng_channel]",
408 if (IS_ERR(chan_file
)) {
409 ret
= PTR_ERR(chan_file
);
412 switch (channel_type
) {
413 case PER_CPU_CHANNEL
:
414 if (chan_param
->output
== LTTNG_KERNEL_SPLICE
) {
415 transport_name
= chan_param
->overwrite
?
416 "relay-overwrite" : "relay-discard";
417 } else if (chan_param
->output
== LTTNG_KERNEL_MMAP
) {
418 transport_name
= chan_param
->overwrite
?
419 "relay-overwrite-mmap" : "relay-discard-mmap";
424 case METADATA_CHANNEL
:
425 if (chan_param
->output
== LTTNG_KERNEL_SPLICE
)
426 transport_name
= "relay-metadata";
427 else if (chan_param
->output
== LTTNG_KERNEL_MMAP
)
428 transport_name
= "relay-metadata-mmap";
433 transport_name
= "<unknown>";
436 if (!atomic_long_add_unless(&session_file
->f_count
, 1, LONG_MAX
)) {
441 * We tolerate no failure path after channel creation. It will stay
442 * invariant for the rest of the session.
444 chan
= lttng_channel_create(session
, transport_name
, NULL
,
445 chan_param
->subbuf_size
,
446 chan_param
->num_subbuf
,
447 chan_param
->switch_timer_interval
,
448 chan_param
->read_timer_interval
,
454 chan
->file
= chan_file
;
455 chan_file
->private_data
= chan
;
456 fd_install(chan_fd
, chan_file
);
461 atomic_long_dec(&session_file
->f_count
);
465 put_unused_fd(chan_fd
);
471 * lttng_session_ioctl - lttng session fd ioctl
477 * This ioctl implements lttng commands:
478 * LTTNG_KERNEL_CHANNEL
479 * Returns a LTTng channel file descriptor
480 * LTTNG_KERNEL_ENABLE
481 * Enables tracing for a session (weak enable)
482 * LTTNG_KERNEL_DISABLE
483 * Disables tracing for a session (strong disable)
484 * LTTNG_KERNEL_METADATA
485 * Returns a LTTng metadata file descriptor
486 * LTTNG_KERNEL_SESSION_TRACK_PID
487 * Add PID to session tracker
488 * LTTNG_KERNEL_SESSION_UNTRACK_PID
489 * Remove PID from session tracker
491 * The returned channel will be deleted when its file descriptor is closed.
494 long lttng_session_ioctl(struct file
*file
, unsigned int cmd
, unsigned long arg
)
496 struct lttng_session
*session
= file
->private_data
;
499 case LTTNG_KERNEL_OLD_CHANNEL
:
501 struct lttng_kernel_channel chan_param
;
502 struct lttng_kernel_old_channel old_chan_param
;
504 if (copy_from_user(&old_chan_param
,
505 (struct lttng_kernel_old_channel __user
*) arg
,
506 sizeof(struct lttng_kernel_old_channel
)))
508 chan_param
.overwrite
= old_chan_param
.overwrite
;
509 chan_param
.subbuf_size
= old_chan_param
.subbuf_size
;
510 chan_param
.num_subbuf
= old_chan_param
.num_subbuf
;
511 chan_param
.switch_timer_interval
= old_chan_param
.switch_timer_interval
;
512 chan_param
.read_timer_interval
= old_chan_param
.read_timer_interval
;
513 chan_param
.output
= old_chan_param
.output
;
515 return lttng_abi_create_channel(file
, &chan_param
,
518 case LTTNG_KERNEL_CHANNEL
:
520 struct lttng_kernel_channel chan_param
;
522 if (copy_from_user(&chan_param
,
523 (struct lttng_kernel_channel __user
*) arg
,
524 sizeof(struct lttng_kernel_channel
)))
526 return lttng_abi_create_channel(file
, &chan_param
,
529 case LTTNG_KERNEL_OLD_SESSION_START
:
530 case LTTNG_KERNEL_OLD_ENABLE
:
531 case LTTNG_KERNEL_SESSION_START
:
532 case LTTNG_KERNEL_ENABLE
:
533 return lttng_session_enable(session
);
534 case LTTNG_KERNEL_OLD_SESSION_STOP
:
535 case LTTNG_KERNEL_OLD_DISABLE
:
536 case LTTNG_KERNEL_SESSION_STOP
:
537 case LTTNG_KERNEL_DISABLE
:
538 return lttng_session_disable(session
);
539 case LTTNG_KERNEL_OLD_METADATA
:
541 struct lttng_kernel_channel chan_param
;
542 struct lttng_kernel_old_channel old_chan_param
;
544 if (copy_from_user(&old_chan_param
,
545 (struct lttng_kernel_old_channel __user
*) arg
,
546 sizeof(struct lttng_kernel_old_channel
)))
548 chan_param
.overwrite
= old_chan_param
.overwrite
;
549 chan_param
.subbuf_size
= old_chan_param
.subbuf_size
;
550 chan_param
.num_subbuf
= old_chan_param
.num_subbuf
;
551 chan_param
.switch_timer_interval
= old_chan_param
.switch_timer_interval
;
552 chan_param
.read_timer_interval
= old_chan_param
.read_timer_interval
;
553 chan_param
.output
= old_chan_param
.output
;
555 return lttng_abi_create_channel(file
, &chan_param
,
558 case LTTNG_KERNEL_METADATA
:
560 struct lttng_kernel_channel chan_param
;
562 if (copy_from_user(&chan_param
,
563 (struct lttng_kernel_channel __user
*) arg
,
564 sizeof(struct lttng_kernel_channel
)))
566 return lttng_abi_create_channel(file
, &chan_param
,
569 case LTTNG_KERNEL_SESSION_TRACK_PID
:
570 return lttng_session_track_pid(session
, (int) arg
);
571 case LTTNG_KERNEL_SESSION_UNTRACK_PID
:
572 return lttng_session_untrack_pid(session
, (int) arg
);
573 case LTTNG_KERNEL_SESSION_LIST_TRACKER_PIDS
:
574 return lttng_session_list_tracker_pids(session
);
575 case LTTNG_KERNEL_SESSION_METADATA_REGEN
:
576 return lttng_session_metadata_regenerate(session
);
577 case LTTNG_KERNEL_SESSION_STATEDUMP
:
578 return lttng_session_statedump(session
);
585 * Called when the last file reference is dropped.
587 * Big fat note: channels and events are invariant for the whole session after
588 * their creation. So this session destruction also destroys all channel and
589 * event structures specific to this session (they are not destroyed when their
590 * individual file is released).
593 int lttng_session_release(struct inode
*inode
, struct file
*file
)
595 struct lttng_session
*session
= file
->private_data
;
598 lttng_session_destroy(session
);
602 static const struct file_operations lttng_session_fops
= {
603 .owner
= THIS_MODULE
,
604 .release
= lttng_session_release
,
605 .unlocked_ioctl
= lttng_session_ioctl
,
607 .compat_ioctl
= lttng_session_ioctl
,
612 * lttng_metadata_ring_buffer_poll - LTTng ring buffer poll file operation
616 * Handles the poll operations for the metadata channels.
619 unsigned int lttng_metadata_ring_buffer_poll(struct file
*filp
,
622 struct lttng_metadata_stream
*stream
= filp
->private_data
;
623 struct lib_ring_buffer
*buf
= stream
->priv
;
625 unsigned int mask
= 0;
627 if (filp
->f_mode
& FMODE_READ
) {
628 poll_wait_set_exclusive(wait
);
629 poll_wait(filp
, &stream
->read_wait
, wait
);
631 finalized
= stream
->finalized
;
634 * lib_ring_buffer_is_finalized() contains a smp_rmb()
635 * ordering finalized load before offsets loads.
637 WARN_ON(atomic_long_read(&buf
->active_readers
) != 1);
642 mutex_lock(&stream
->metadata_cache
->lock
);
643 if (stream
->metadata_cache
->metadata_written
>
644 stream
->metadata_out
)
646 mutex_unlock(&stream
->metadata_cache
->lock
);
653 void lttng_metadata_ring_buffer_ioctl_put_next_subbuf(struct file
*filp
,
654 unsigned int cmd
, unsigned long arg
)
656 struct lttng_metadata_stream
*stream
= filp
->private_data
;
658 stream
->metadata_out
= stream
->metadata_in
;
662 * Reset the counter of how much metadata has been consumed to 0. That way,
663 * the consumer receives the content of the metadata cache unchanged. This is
664 * different from the metadata_regenerate where the offset from epoch is
665 * resampled, here we want the exact same content as the last time the metadata
666 * was generated. This command is only possible if all the metadata written
667 * in the cache has been output to the metadata stream to avoid corrupting the
670 * Return 0 on success, a negative value on error.
673 int lttng_metadata_cache_dump(struct lttng_metadata_stream
*stream
)
676 struct lttng_metadata_cache
*cache
= stream
->metadata_cache
;
678 mutex_lock(&cache
->lock
);
679 if (stream
->metadata_out
!= cache
->metadata_written
) {
683 stream
->metadata_out
= 0;
684 stream
->metadata_in
= 0;
685 wake_up_interruptible(&stream
->read_wait
);
689 mutex_unlock(&cache
->lock
);
694 long lttng_metadata_ring_buffer_ioctl(struct file
*filp
,
695 unsigned int cmd
, unsigned long arg
)
698 struct lttng_metadata_stream
*stream
= filp
->private_data
;
699 struct lib_ring_buffer
*buf
= stream
->priv
;
702 case RING_BUFFER_GET_NEXT_SUBBUF
:
704 struct lttng_metadata_stream
*stream
= filp
->private_data
;
705 struct lib_ring_buffer
*buf
= stream
->priv
;
706 struct channel
*chan
= buf
->backend
.chan
;
708 ret
= lttng_metadata_output_channel(stream
, chan
);
710 lib_ring_buffer_switch_slow(buf
, SWITCH_ACTIVE
);
716 case RING_BUFFER_GET_SUBBUF
:
719 * Random access is not allowed for metadata channel.
723 case RING_BUFFER_FLUSH_EMPTY
: /* Fall-through. */
724 case RING_BUFFER_FLUSH
:
726 struct lttng_metadata_stream
*stream
= filp
->private_data
;
727 struct lib_ring_buffer
*buf
= stream
->priv
;
728 struct channel
*chan
= buf
->backend
.chan
;
731 * Before doing the actual ring buffer flush, write up to one
732 * packet of metadata in the ring buffer.
734 ret
= lttng_metadata_output_channel(stream
, chan
);
739 case RING_BUFFER_GET_METADATA_VERSION
:
741 struct lttng_metadata_stream
*stream
= filp
->private_data
;
743 return put_u64(stream
->version
, arg
);
745 case RING_BUFFER_METADATA_CACHE_DUMP
:
747 struct lttng_metadata_stream
*stream
= filp
->private_data
;
749 return lttng_metadata_cache_dump(stream
);
754 /* PUT_SUBBUF is the one from lib ring buffer, unmodified. */
756 /* Performing lib ring buffer ioctl after our own. */
757 ret
= lib_ring_buffer_ioctl(filp
, cmd
, arg
, buf
);
762 case RING_BUFFER_PUT_NEXT_SUBBUF
:
764 lttng_metadata_ring_buffer_ioctl_put_next_subbuf(filp
,
777 long lttng_metadata_ring_buffer_compat_ioctl(struct file
*filp
,
778 unsigned int cmd
, unsigned long arg
)
781 struct lttng_metadata_stream
*stream
= filp
->private_data
;
782 struct lib_ring_buffer
*buf
= stream
->priv
;
785 case RING_BUFFER_GET_NEXT_SUBBUF
:
787 struct lttng_metadata_stream
*stream
= filp
->private_data
;
788 struct lib_ring_buffer
*buf
= stream
->priv
;
789 struct channel
*chan
= buf
->backend
.chan
;
791 ret
= lttng_metadata_output_channel(stream
, chan
);
793 lib_ring_buffer_switch_slow(buf
, SWITCH_ACTIVE
);
799 case RING_BUFFER_GET_SUBBUF
:
802 * Random access is not allowed for metadata channel.
806 case RING_BUFFER_FLUSH_EMPTY
: /* Fall-through. */
807 case RING_BUFFER_FLUSH
:
809 struct lttng_metadata_stream
*stream
= filp
->private_data
;
810 struct lib_ring_buffer
*buf
= stream
->priv
;
811 struct channel
*chan
= buf
->backend
.chan
;
814 * Before doing the actual ring buffer flush, write up to one
815 * packet of metadata in the ring buffer.
817 ret
= lttng_metadata_output_channel(stream
, chan
);
822 case RING_BUFFER_GET_METADATA_VERSION
:
824 struct lttng_metadata_stream
*stream
= filp
->private_data
;
826 return put_u64(stream
->version
, arg
);
828 case RING_BUFFER_METADATA_CACHE_DUMP
:
830 struct lttng_metadata_stream
*stream
= filp
->private_data
;
832 return lttng_metadata_cache_dump(stream
);
837 /* PUT_SUBBUF is the one from lib ring buffer, unmodified. */
839 /* Performing lib ring buffer ioctl after our own. */
840 ret
= lib_ring_buffer_compat_ioctl(filp
, cmd
, arg
, buf
);
845 case RING_BUFFER_PUT_NEXT_SUBBUF
:
847 lttng_metadata_ring_buffer_ioctl_put_next_subbuf(filp
,
860 * This is not used by anonymous file descriptors. This code is left
861 * there if we ever want to implement an inode with open() operation.
864 int lttng_metadata_ring_buffer_open(struct inode
*inode
, struct file
*file
)
866 struct lttng_metadata_stream
*stream
= inode
->i_private
;
867 struct lib_ring_buffer
*buf
= stream
->priv
;
869 file
->private_data
= buf
;
871 * Since life-time of metadata cache differs from that of
872 * session, we need to keep our own reference on the transport.
874 if (!try_module_get(stream
->transport
->owner
)) {
875 printk(KERN_WARNING
"LTT : Can't lock transport module.\n");
878 return lib_ring_buffer_open(inode
, file
, buf
);
882 int lttng_metadata_ring_buffer_release(struct inode
*inode
, struct file
*file
)
884 struct lttng_metadata_stream
*stream
= file
->private_data
;
885 struct lib_ring_buffer
*buf
= stream
->priv
;
887 kref_put(&stream
->metadata_cache
->refcount
, metadata_cache_destroy
);
888 module_put(stream
->transport
->owner
);
889 return lib_ring_buffer_release(inode
, file
, buf
);
893 ssize_t
lttng_metadata_ring_buffer_splice_read(struct file
*in
, loff_t
*ppos
,
894 struct pipe_inode_info
*pipe
, size_t len
,
897 struct lttng_metadata_stream
*stream
= in
->private_data
;
898 struct lib_ring_buffer
*buf
= stream
->priv
;
900 return lib_ring_buffer_splice_read(in
, ppos
, pipe
, len
,
905 int lttng_metadata_ring_buffer_mmap(struct file
*filp
,
906 struct vm_area_struct
*vma
)
908 struct lttng_metadata_stream
*stream
= filp
->private_data
;
909 struct lib_ring_buffer
*buf
= stream
->priv
;
911 return lib_ring_buffer_mmap(filp
, vma
, buf
);
915 const struct file_operations lttng_metadata_ring_buffer_file_operations
= {
916 .owner
= THIS_MODULE
,
917 .open
= lttng_metadata_ring_buffer_open
,
918 .release
= lttng_metadata_ring_buffer_release
,
919 .poll
= lttng_metadata_ring_buffer_poll
,
920 .splice_read
= lttng_metadata_ring_buffer_splice_read
,
921 .mmap
= lttng_metadata_ring_buffer_mmap
,
922 .unlocked_ioctl
= lttng_metadata_ring_buffer_ioctl
,
923 .llseek
= vfs_lib_ring_buffer_no_llseek
,
925 .compat_ioctl
= lttng_metadata_ring_buffer_compat_ioctl
,
930 int lttng_abi_create_stream_fd(struct file
*channel_file
, void *stream_priv
,
931 const struct file_operations
*fops
)
934 struct file
*stream_file
;
936 stream_fd
= lttng_get_unused_fd();
941 stream_file
= anon_inode_getfile("[lttng_stream]", fops
,
942 stream_priv
, O_RDWR
);
943 if (IS_ERR(stream_file
)) {
944 ret
= PTR_ERR(stream_file
);
948 * OPEN_FMODE, called within anon_inode_getfile/alloc_file, don't honor
949 * FMODE_LSEEK, FMODE_PREAD nor FMODE_PWRITE. We need to read from this
950 * file descriptor, so we set FMODE_PREAD here.
952 stream_file
->f_mode
|= FMODE_PREAD
;
953 fd_install(stream_fd
, stream_file
);
955 * The stream holds a reference to the channel within the generic ring
956 * buffer library, so no need to hold a refcount on the channel and
957 * session files here.
962 put_unused_fd(stream_fd
);
968 int lttng_abi_open_stream(struct file
*channel_file
)
970 struct lttng_channel
*channel
= channel_file
->private_data
;
971 struct lib_ring_buffer
*buf
;
975 buf
= channel
->ops
->buffer_read_open(channel
->chan
);
980 ret
= lttng_abi_create_stream_fd(channel_file
, stream_priv
,
981 <tng_stream_ring_buffer_file_operations
);
988 channel
->ops
->buffer_read_close(buf
);
993 int lttng_abi_open_metadata_stream(struct file
*channel_file
)
995 struct lttng_channel
*channel
= channel_file
->private_data
;
996 struct lttng_session
*session
= channel
->session
;
997 struct lib_ring_buffer
*buf
;
999 struct lttng_metadata_stream
*metadata_stream
;
1002 buf
= channel
->ops
->buffer_read_open(channel
->chan
);
1006 metadata_stream
= kzalloc(sizeof(struct lttng_metadata_stream
),
1008 if (!metadata_stream
) {
1012 metadata_stream
->metadata_cache
= session
->metadata_cache
;
1013 init_waitqueue_head(&metadata_stream
->read_wait
);
1014 metadata_stream
->priv
= buf
;
1015 stream_priv
= metadata_stream
;
1016 metadata_stream
->transport
= channel
->transport
;
1019 * Since life-time of metadata cache differs from that of
1020 * session, we need to keep our own reference on the transport.
1022 if (!try_module_get(metadata_stream
->transport
->owner
)) {
1023 printk(KERN_WARNING
"LTT : Can't lock transport module.\n");
1028 if (!lttng_kref_get(&session
->metadata_cache
->refcount
)) {
1033 ret
= lttng_abi_create_stream_fd(channel_file
, stream_priv
,
1034 <tng_metadata_ring_buffer_file_operations
);
1038 list_add(&metadata_stream
->list
,
1039 &session
->metadata_cache
->metadata_stream
);
1043 kref_put(&session
->metadata_cache
->refcount
, metadata_cache_destroy
);
1045 module_put(metadata_stream
->transport
->owner
);
1047 kfree(metadata_stream
);
1049 channel
->ops
->buffer_read_close(buf
);
1054 int lttng_abi_create_event(struct file
*channel_file
,
1055 struct lttng_kernel_event
*event_param
)
1057 struct lttng_channel
*channel
= channel_file
->private_data
;
1059 struct file
*event_file
;
1062 event_param
->name
[LTTNG_KERNEL_SYM_NAME_LEN
- 1] = '\0';
1063 switch (event_param
->instrumentation
) {
1064 case LTTNG_KERNEL_KRETPROBE
:
1065 event_param
->u
.kretprobe
.symbol_name
[LTTNG_KERNEL_SYM_NAME_LEN
- 1] = '\0';
1067 case LTTNG_KERNEL_KPROBE
:
1068 event_param
->u
.kprobe
.symbol_name
[LTTNG_KERNEL_SYM_NAME_LEN
- 1] = '\0';
1070 case LTTNG_KERNEL_FUNCTION
:
1071 event_param
->u
.ftrace
.symbol_name
[LTTNG_KERNEL_SYM_NAME_LEN
- 1] = '\0';
1076 event_fd
= lttng_get_unused_fd();
1081 event_file
= anon_inode_getfile("[lttng_event]",
1084 if (IS_ERR(event_file
)) {
1085 ret
= PTR_ERR(event_file
);
1088 /* The event holds a reference on the channel */
1089 if (!atomic_long_add_unless(&channel_file
->f_count
, 1, LONG_MAX
)) {
1091 goto refcount_error
;
1093 if (event_param
->instrumentation
== LTTNG_KERNEL_TRACEPOINT
1094 || event_param
->instrumentation
== LTTNG_KERNEL_SYSCALL
) {
1095 struct lttng_enabler
*enabler
;
1097 if (strutils_is_star_glob_pattern(event_param
->name
)) {
1099 * If the event name is a star globbing pattern,
1100 * we create the special star globbing enabler.
1102 enabler
= lttng_enabler_create(LTTNG_ENABLER_STAR_GLOB
,
1103 event_param
, channel
);
1105 enabler
= lttng_enabler_create(LTTNG_ENABLER_NAME
,
1106 event_param
, channel
);
1110 struct lttng_event
*event
;
1113 * We tolerate no failure path after event creation. It
1114 * will stay invariant for the rest of the session.
1116 event
= lttng_event_create(channel
, event_param
,
1118 event_param
->instrumentation
);
1119 WARN_ON_ONCE(!event
);
1120 if (IS_ERR(event
)) {
1121 ret
= PTR_ERR(event
);
1126 event_file
->private_data
= priv
;
1127 fd_install(event_fd
, event_file
);
1131 atomic_long_dec(&channel_file
->f_count
);
1135 put_unused_fd(event_fd
);
1141 * lttng_channel_ioctl - lttng syscall through ioctl
1147 * This ioctl implements lttng commands:
1148 * LTTNG_KERNEL_STREAM
1149 * Returns an event stream file descriptor or failure.
1150 * (typically, one event stream records events from one CPU)
1151 * LTTNG_KERNEL_EVENT
1152 * Returns an event file descriptor or failure.
1153 * LTTNG_KERNEL_CONTEXT
1154 * Prepend a context field to each event in the channel
1155 * LTTNG_KERNEL_ENABLE
1156 * Enable recording for events in this channel (weak enable)
1157 * LTTNG_KERNEL_DISABLE
1158 * Disable recording for events in this channel (strong disable)
1160 * Channel and event file descriptors also hold a reference on the session.
1163 long lttng_channel_ioctl(struct file
*file
, unsigned int cmd
, unsigned long arg
)
1165 struct lttng_channel
*channel
= file
->private_data
;
1168 case LTTNG_KERNEL_OLD_STREAM
:
1169 case LTTNG_KERNEL_STREAM
:
1170 return lttng_abi_open_stream(file
);
1171 case LTTNG_KERNEL_OLD_EVENT
:
1173 struct lttng_kernel_event
*uevent_param
;
1174 struct lttng_kernel_old_event
*old_uevent_param
;
1177 uevent_param
= kmalloc(sizeof(struct lttng_kernel_event
),
1179 if (!uevent_param
) {
1183 old_uevent_param
= kmalloc(
1184 sizeof(struct lttng_kernel_old_event
),
1186 if (!old_uevent_param
) {
1188 goto old_event_error_free_param
;
1190 if (copy_from_user(old_uevent_param
,
1191 (struct lttng_kernel_old_event __user
*) arg
,
1192 sizeof(struct lttng_kernel_old_event
))) {
1194 goto old_event_error_free_old_param
;
1197 memcpy(uevent_param
->name
, old_uevent_param
->name
,
1198 sizeof(uevent_param
->name
));
1199 uevent_param
->instrumentation
=
1200 old_uevent_param
->instrumentation
;
1202 switch (old_uevent_param
->instrumentation
) {
1203 case LTTNG_KERNEL_KPROBE
:
1204 uevent_param
->u
.kprobe
.addr
=
1205 old_uevent_param
->u
.kprobe
.addr
;
1206 uevent_param
->u
.kprobe
.offset
=
1207 old_uevent_param
->u
.kprobe
.offset
;
1208 memcpy(uevent_param
->u
.kprobe
.symbol_name
,
1209 old_uevent_param
->u
.kprobe
.symbol_name
,
1210 sizeof(uevent_param
->u
.kprobe
.symbol_name
));
1212 case LTTNG_KERNEL_KRETPROBE
:
1213 uevent_param
->u
.kretprobe
.addr
=
1214 old_uevent_param
->u
.kretprobe
.addr
;
1215 uevent_param
->u
.kretprobe
.offset
=
1216 old_uevent_param
->u
.kretprobe
.offset
;
1217 memcpy(uevent_param
->u
.kretprobe
.symbol_name
,
1218 old_uevent_param
->u
.kretprobe
.symbol_name
,
1219 sizeof(uevent_param
->u
.kretprobe
.symbol_name
));
1221 case LTTNG_KERNEL_FUNCTION
:
1222 memcpy(uevent_param
->u
.ftrace
.symbol_name
,
1223 old_uevent_param
->u
.ftrace
.symbol_name
,
1224 sizeof(uevent_param
->u
.ftrace
.symbol_name
));
1229 ret
= lttng_abi_create_event(file
, uevent_param
);
1231 old_event_error_free_old_param
:
1232 kfree(old_uevent_param
);
1233 old_event_error_free_param
:
1234 kfree(uevent_param
);
1238 case LTTNG_KERNEL_EVENT
:
1240 struct lttng_kernel_event uevent_param
;
1242 if (copy_from_user(&uevent_param
,
1243 (struct lttng_kernel_event __user
*) arg
,
1244 sizeof(uevent_param
)))
1246 return lttng_abi_create_event(file
, &uevent_param
);
1248 case LTTNG_KERNEL_OLD_CONTEXT
:
1250 struct lttng_kernel_context
*ucontext_param
;
1251 struct lttng_kernel_old_context
*old_ucontext_param
;
1254 ucontext_param
= kmalloc(sizeof(struct lttng_kernel_context
),
1256 if (!ucontext_param
) {
1260 old_ucontext_param
= kmalloc(sizeof(struct lttng_kernel_old_context
),
1262 if (!old_ucontext_param
) {
1264 goto old_ctx_error_free_param
;
1267 if (copy_from_user(old_ucontext_param
,
1268 (struct lttng_kernel_old_context __user
*) arg
,
1269 sizeof(struct lttng_kernel_old_context
))) {
1271 goto old_ctx_error_free_old_param
;
1273 ucontext_param
->ctx
= old_ucontext_param
->ctx
;
1274 memcpy(ucontext_param
->padding
, old_ucontext_param
->padding
,
1275 sizeof(ucontext_param
->padding
));
1276 /* only type that uses the union */
1277 if (old_ucontext_param
->ctx
== LTTNG_KERNEL_CONTEXT_PERF_COUNTER
) {
1278 ucontext_param
->u
.perf_counter
.type
=
1279 old_ucontext_param
->u
.perf_counter
.type
;
1280 ucontext_param
->u
.perf_counter
.config
=
1281 old_ucontext_param
->u
.perf_counter
.config
;
1282 memcpy(ucontext_param
->u
.perf_counter
.name
,
1283 old_ucontext_param
->u
.perf_counter
.name
,
1284 sizeof(ucontext_param
->u
.perf_counter
.name
));
1287 ret
= lttng_abi_add_context(file
,
1289 &channel
->ctx
, channel
->session
);
1291 old_ctx_error_free_old_param
:
1292 kfree(old_ucontext_param
);
1293 old_ctx_error_free_param
:
1294 kfree(ucontext_param
);
1298 case LTTNG_KERNEL_CONTEXT
:
1300 struct lttng_kernel_context ucontext_param
;
1302 if (copy_from_user(&ucontext_param
,
1303 (struct lttng_kernel_context __user
*) arg
,
1304 sizeof(ucontext_param
)))
1306 return lttng_abi_add_context(file
,
1308 &channel
->ctx
, channel
->session
);
1310 case LTTNG_KERNEL_OLD_ENABLE
:
1311 case LTTNG_KERNEL_ENABLE
:
1312 return lttng_channel_enable(channel
);
1313 case LTTNG_KERNEL_OLD_DISABLE
:
1314 case LTTNG_KERNEL_DISABLE
:
1315 return lttng_channel_disable(channel
);
1316 case LTTNG_KERNEL_SYSCALL_MASK
:
1317 return lttng_channel_syscall_mask(channel
,
1318 (struct lttng_kernel_syscall_mask __user
*) arg
);
1320 return -ENOIOCTLCMD
;
1325 * lttng_metadata_ioctl - lttng syscall through ioctl
1331 * This ioctl implements lttng commands:
1332 * LTTNG_KERNEL_STREAM
1333 * Returns an event stream file descriptor or failure.
1335 * Channel and event file descriptors also hold a reference on the session.
1338 long lttng_metadata_ioctl(struct file
*file
, unsigned int cmd
, unsigned long arg
)
1341 case LTTNG_KERNEL_OLD_STREAM
:
1342 case LTTNG_KERNEL_STREAM
:
1343 return lttng_abi_open_metadata_stream(file
);
1345 return -ENOIOCTLCMD
;
1350 * lttng_channel_poll - lttng stream addition/removal monitoring
1355 unsigned int lttng_channel_poll(struct file
*file
, poll_table
*wait
)
1357 struct lttng_channel
*channel
= file
->private_data
;
1358 unsigned int mask
= 0;
1360 if (file
->f_mode
& FMODE_READ
) {
1361 poll_wait_set_exclusive(wait
);
1362 poll_wait(file
, channel
->ops
->get_hp_wait_queue(channel
->chan
),
1365 if (channel
->ops
->is_disabled(channel
->chan
))
1367 if (channel
->ops
->is_finalized(channel
->chan
))
1369 if (channel
->ops
->buffer_has_read_closed_stream(channel
->chan
))
1370 return POLLIN
| POLLRDNORM
;
1378 int lttng_channel_release(struct inode
*inode
, struct file
*file
)
1380 struct lttng_channel
*channel
= file
->private_data
;
1383 fput(channel
->session
->file
);
1388 int lttng_metadata_channel_release(struct inode
*inode
, struct file
*file
)
1390 struct lttng_channel
*channel
= file
->private_data
;
1393 fput(channel
->session
->file
);
1394 lttng_metadata_channel_destroy(channel
);
1400 static const struct file_operations lttng_channel_fops
= {
1401 .owner
= THIS_MODULE
,
1402 .release
= lttng_channel_release
,
1403 .poll
= lttng_channel_poll
,
1404 .unlocked_ioctl
= lttng_channel_ioctl
,
1405 #ifdef CONFIG_COMPAT
1406 .compat_ioctl
= lttng_channel_ioctl
,
1410 static const struct file_operations lttng_metadata_fops
= {
1411 .owner
= THIS_MODULE
,
1412 .release
= lttng_metadata_channel_release
,
1413 .unlocked_ioctl
= lttng_metadata_ioctl
,
1414 #ifdef CONFIG_COMPAT
1415 .compat_ioctl
= lttng_metadata_ioctl
,
1420 * lttng_event_ioctl - lttng syscall through ioctl
1426 * This ioctl implements lttng commands:
1427 * LTTNG_KERNEL_CONTEXT
1428 * Prepend a context field to each record of this event
1429 * LTTNG_KERNEL_ENABLE
1430 * Enable recording for this event (weak enable)
1431 * LTTNG_KERNEL_DISABLE
1432 * Disable recording for this event (strong disable)
1435 long lttng_event_ioctl(struct file
*file
, unsigned int cmd
, unsigned long arg
)
1437 struct lttng_event
*event
;
1438 struct lttng_enabler
*enabler
;
1439 enum lttng_event_type
*evtype
= file
->private_data
;
1442 case LTTNG_KERNEL_OLD_CONTEXT
:
1444 /* Not implemented */
1447 case LTTNG_KERNEL_CONTEXT
:
1449 /* Not implemented */
1452 case LTTNG_KERNEL_OLD_ENABLE
:
1453 case LTTNG_KERNEL_ENABLE
:
1455 case LTTNG_TYPE_EVENT
:
1456 event
= file
->private_data
;
1457 return lttng_event_enable(event
);
1458 case LTTNG_TYPE_ENABLER
:
1459 enabler
= file
->private_data
;
1460 return lttng_enabler_enable(enabler
);
1465 case LTTNG_KERNEL_OLD_DISABLE
:
1466 case LTTNG_KERNEL_DISABLE
:
1468 case LTTNG_TYPE_EVENT
:
1469 event
= file
->private_data
;
1470 return lttng_event_disable(event
);
1471 case LTTNG_TYPE_ENABLER
:
1472 enabler
= file
->private_data
;
1473 return lttng_enabler_disable(enabler
);
1478 case LTTNG_KERNEL_FILTER
:
1480 case LTTNG_TYPE_EVENT
:
1482 case LTTNG_TYPE_ENABLER
:
1484 enabler
= file
->private_data
;
1485 return lttng_enabler_attach_bytecode(enabler
,
1486 (struct lttng_kernel_filter_bytecode __user
*) arg
);
1492 case LTTNG_KERNEL_ADD_CALLSITE
:
1494 case LTTNG_TYPE_EVENT
:
1495 event
= file
->private_data
;
1496 return lttng_event_add_callsite(event
,
1497 (struct lttng_kernel_event_callsite __user
*) arg
);
1498 case LTTNG_TYPE_ENABLER
:
1502 return -ENOIOCTLCMD
;
1507 int lttng_event_release(struct inode
*inode
, struct file
*file
)
1509 struct lttng_event
*event
;
1510 struct lttng_enabler
*enabler
;
1511 enum lttng_event_type
*evtype
= file
->private_data
;
1517 case LTTNG_TYPE_EVENT
:
1518 event
= file
->private_data
;
1520 fput(event
->chan
->file
);
1522 case LTTNG_TYPE_ENABLER
:
1523 enabler
= file
->private_data
;
1525 fput(enabler
->chan
->file
);
1535 /* TODO: filter control ioctl */
1536 static const struct file_operations lttng_event_fops
= {
1537 .owner
= THIS_MODULE
,
1538 .release
= lttng_event_release
,
1539 .unlocked_ioctl
= lttng_event_ioctl
,
1540 #ifdef CONFIG_COMPAT
1541 .compat_ioctl
= lttng_event_ioctl
,
1545 static int put_u64(uint64_t val
, unsigned long arg
)
1547 return put_user(val
, (uint64_t __user
*) arg
);
1550 static long lttng_stream_ring_buffer_ioctl(struct file
*filp
,
1551 unsigned int cmd
, unsigned long arg
)
1553 struct lib_ring_buffer
*buf
= filp
->private_data
;
1554 struct channel
*chan
= buf
->backend
.chan
;
1555 const struct lib_ring_buffer_config
*config
= &chan
->backend
.config
;
1556 const struct lttng_channel_ops
*ops
= chan
->backend
.priv_ops
;
1559 if (atomic_read(&chan
->record_disabled
))
1563 case LTTNG_RING_BUFFER_GET_TIMESTAMP_BEGIN
:
1567 ret
= ops
->timestamp_begin(config
, buf
, &ts
);
1570 return put_u64(ts
, arg
);
1572 case LTTNG_RING_BUFFER_GET_TIMESTAMP_END
:
1576 ret
= ops
->timestamp_end(config
, buf
, &ts
);
1579 return put_u64(ts
, arg
);
1581 case LTTNG_RING_BUFFER_GET_EVENTS_DISCARDED
:
1585 ret
= ops
->events_discarded(config
, buf
, &ed
);
1588 return put_u64(ed
, arg
);
1590 case LTTNG_RING_BUFFER_GET_CONTENT_SIZE
:
1594 ret
= ops
->content_size(config
, buf
, &cs
);
1597 return put_u64(cs
, arg
);
1599 case LTTNG_RING_BUFFER_GET_PACKET_SIZE
:
1603 ret
= ops
->packet_size(config
, buf
, &ps
);
1606 return put_u64(ps
, arg
);
1608 case LTTNG_RING_BUFFER_GET_STREAM_ID
:
1612 ret
= ops
->stream_id(config
, buf
, &si
);
1615 return put_u64(si
, arg
);
1617 case LTTNG_RING_BUFFER_GET_CURRENT_TIMESTAMP
:
1621 ret
= ops
->current_timestamp(config
, buf
, &ts
);
1624 return put_u64(ts
, arg
);
1626 case LTTNG_RING_BUFFER_GET_SEQ_NUM
:
1630 ret
= ops
->sequence_number(config
, buf
, &seq
);
1633 return put_u64(seq
, arg
);
1635 case LTTNG_RING_BUFFER_INSTANCE_ID
:
1639 ret
= ops
->instance_id(config
, buf
, &id
);
1642 return put_u64(id
, arg
);
1645 return lib_ring_buffer_file_operations
.unlocked_ioctl(filp
,
1653 #ifdef CONFIG_COMPAT
1654 static long lttng_stream_ring_buffer_compat_ioctl(struct file
*filp
,
1655 unsigned int cmd
, unsigned long arg
)
1657 struct lib_ring_buffer
*buf
= filp
->private_data
;
1658 struct channel
*chan
= buf
->backend
.chan
;
1659 const struct lib_ring_buffer_config
*config
= &chan
->backend
.config
;
1660 const struct lttng_channel_ops
*ops
= chan
->backend
.priv_ops
;
1663 if (atomic_read(&chan
->record_disabled
))
1667 case LTTNG_RING_BUFFER_COMPAT_GET_TIMESTAMP_BEGIN
:
1671 ret
= ops
->timestamp_begin(config
, buf
, &ts
);
1674 return put_u64(ts
, arg
);
1676 case LTTNG_RING_BUFFER_COMPAT_GET_TIMESTAMP_END
:
1680 ret
= ops
->timestamp_end(config
, buf
, &ts
);
1683 return put_u64(ts
, arg
);
1685 case LTTNG_RING_BUFFER_COMPAT_GET_EVENTS_DISCARDED
:
1689 ret
= ops
->events_discarded(config
, buf
, &ed
);
1692 return put_u64(ed
, arg
);
1694 case LTTNG_RING_BUFFER_COMPAT_GET_CONTENT_SIZE
:
1698 ret
= ops
->content_size(config
, buf
, &cs
);
1701 return put_u64(cs
, arg
);
1703 case LTTNG_RING_BUFFER_COMPAT_GET_PACKET_SIZE
:
1707 ret
= ops
->packet_size(config
, buf
, &ps
);
1710 return put_u64(ps
, arg
);
1712 case LTTNG_RING_BUFFER_COMPAT_GET_STREAM_ID
:
1716 ret
= ops
->stream_id(config
, buf
, &si
);
1719 return put_u64(si
, arg
);
1721 case LTTNG_RING_BUFFER_GET_CURRENT_TIMESTAMP
:
1725 ret
= ops
->current_timestamp(config
, buf
, &ts
);
1728 return put_u64(ts
, arg
);
1730 case LTTNG_RING_BUFFER_COMPAT_GET_SEQ_NUM
:
1734 ret
= ops
->sequence_number(config
, buf
, &seq
);
1737 return put_u64(seq
, arg
);
1739 case LTTNG_RING_BUFFER_COMPAT_INSTANCE_ID
:
1743 ret
= ops
->instance_id(config
, buf
, &id
);
1746 return put_u64(id
, arg
);
1749 return lib_ring_buffer_file_operations
.compat_ioctl(filp
,
1756 #endif /* CONFIG_COMPAT */
1758 static void lttng_stream_override_ring_buffer_fops(void)
1760 lttng_stream_ring_buffer_file_operations
.owner
= THIS_MODULE
;
1761 lttng_stream_ring_buffer_file_operations
.open
=
1762 lib_ring_buffer_file_operations
.open
;
1763 lttng_stream_ring_buffer_file_operations
.release
=
1764 lib_ring_buffer_file_operations
.release
;
1765 lttng_stream_ring_buffer_file_operations
.poll
=
1766 lib_ring_buffer_file_operations
.poll
;
1767 lttng_stream_ring_buffer_file_operations
.splice_read
=
1768 lib_ring_buffer_file_operations
.splice_read
;
1769 lttng_stream_ring_buffer_file_operations
.mmap
=
1770 lib_ring_buffer_file_operations
.mmap
;
1771 lttng_stream_ring_buffer_file_operations
.unlocked_ioctl
=
1772 lttng_stream_ring_buffer_ioctl
;
1773 lttng_stream_ring_buffer_file_operations
.llseek
=
1774 lib_ring_buffer_file_operations
.llseek
;
1775 #ifdef CONFIG_COMPAT
1776 lttng_stream_ring_buffer_file_operations
.compat_ioctl
=
1777 lttng_stream_ring_buffer_compat_ioctl
;
1781 int __init
lttng_abi_init(void)
1785 wrapper_vmalloc_sync_all();
1788 ret
= lttng_tp_mempool_init();
1793 lttng_proc_dentry
= proc_create_data("lttng", S_IRUSR
| S_IWUSR
, NULL
,
1796 if (!lttng_proc_dentry
) {
1797 printk(KERN_ERR
"Error creating LTTng control file\n");
1801 lttng_stream_override_ring_buffer_fops();
1805 lttng_tp_mempool_destroy();
1806 lttng_clock_unref();
1810 /* No __exit annotation because used by init error path too. */
1811 void lttng_abi_exit(void)
1813 lttng_tp_mempool_destroy();
1814 lttng_clock_unref();
1815 if (lttng_proc_dentry
)
1816 remove_proc_entry("lttng", NULL
);