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_mappings() */
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
;
55 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(5,6,0))
56 static const struct proc_ops lttng_proc_ops
;
58 static const struct file_operations lttng_proc_ops
;
61 static const struct file_operations lttng_session_fops
;
62 static const struct file_operations lttng_channel_fops
;
63 static const struct file_operations lttng_metadata_fops
;
64 static const struct file_operations lttng_event_fops
;
65 static struct file_operations lttng_stream_ring_buffer_file_operations
;
67 static int put_u64(uint64_t val
, unsigned long arg
);
70 * Teardown management: opened file descriptors keep a refcount on the module,
71 * so it can only exit when all file descriptors are closed.
75 int lttng_abi_create_session(void)
77 struct lttng_session
*session
;
78 struct file
*session_file
;
81 session
= lttng_session_create();
84 session_fd
= lttng_get_unused_fd();
89 session_file
= anon_inode_getfile("[lttng_session]",
92 if (IS_ERR(session_file
)) {
93 ret
= PTR_ERR(session_file
);
96 session
->file
= session_file
;
97 fd_install(session_fd
, session_file
);
101 put_unused_fd(session_fd
);
103 lttng_session_destroy(session
);
108 int lttng_abi_tracepoint_list(void)
110 struct file
*tracepoint_list_file
;
113 file_fd
= lttng_get_unused_fd();
119 tracepoint_list_file
= anon_inode_getfile("[lttng_tracepoint_list]",
120 <tng_tracepoint_list_fops
,
122 if (IS_ERR(tracepoint_list_file
)) {
123 ret
= PTR_ERR(tracepoint_list_file
);
126 ret
= lttng_tracepoint_list_fops
.open(NULL
, tracepoint_list_file
);
129 fd_install(file_fd
, tracepoint_list_file
);
133 fput(tracepoint_list_file
);
135 put_unused_fd(file_fd
);
140 #ifndef CONFIG_HAVE_SYSCALL_TRACEPOINTS
142 int lttng_abi_syscall_list(void)
148 int lttng_abi_syscall_list(void)
150 struct file
*syscall_list_file
;
153 file_fd
= lttng_get_unused_fd();
159 syscall_list_file
= anon_inode_getfile("[lttng_syscall_list]",
160 <tng_syscall_list_fops
,
162 if (IS_ERR(syscall_list_file
)) {
163 ret
= PTR_ERR(syscall_list_file
);
166 ret
= lttng_syscall_list_fops
.open(NULL
, syscall_list_file
);
169 fd_install(file_fd
, syscall_list_file
);
173 fput(syscall_list_file
);
175 put_unused_fd(file_fd
);
182 void lttng_abi_tracer_version(struct lttng_kernel_tracer_version
*v
)
184 v
->major
= LTTNG_MODULES_MAJOR_VERSION
;
185 v
->minor
= LTTNG_MODULES_MINOR_VERSION
;
186 v
->patchlevel
= LTTNG_MODULES_PATCHLEVEL_VERSION
;
190 void lttng_abi_tracer_abi_version(struct lttng_kernel_tracer_abi_version
*v
)
192 v
->major
= LTTNG_MODULES_ABI_MAJOR_VERSION
;
193 v
->minor
= LTTNG_MODULES_ABI_MINOR_VERSION
;
197 long lttng_abi_add_context(struct file
*file
,
198 struct lttng_kernel_context
*context_param
,
199 struct lttng_ctx
**ctx
, struct lttng_session
*session
)
202 if (session
->been_active
)
205 switch (context_param
->ctx
) {
206 case LTTNG_KERNEL_CONTEXT_PID
:
207 return lttng_add_pid_to_ctx(ctx
);
208 case LTTNG_KERNEL_CONTEXT_PRIO
:
209 return lttng_add_prio_to_ctx(ctx
);
210 case LTTNG_KERNEL_CONTEXT_NICE
:
211 return lttng_add_nice_to_ctx(ctx
);
212 case LTTNG_KERNEL_CONTEXT_VPID
:
213 return lttng_add_vpid_to_ctx(ctx
);
214 case LTTNG_KERNEL_CONTEXT_TID
:
215 return lttng_add_tid_to_ctx(ctx
);
216 case LTTNG_KERNEL_CONTEXT_VTID
:
217 return lttng_add_vtid_to_ctx(ctx
);
218 case LTTNG_KERNEL_CONTEXT_PPID
:
219 return lttng_add_ppid_to_ctx(ctx
);
220 case LTTNG_KERNEL_CONTEXT_VPPID
:
221 return lttng_add_vppid_to_ctx(ctx
);
222 case LTTNG_KERNEL_CONTEXT_PERF_COUNTER
:
223 context_param
->u
.perf_counter
.name
[LTTNG_KERNEL_SYM_NAME_LEN
- 1] = '\0';
224 return lttng_add_perf_counter_to_ctx(context_param
->u
.perf_counter
.type
,
225 context_param
->u
.perf_counter
.config
,
226 context_param
->u
.perf_counter
.name
,
228 case LTTNG_KERNEL_CONTEXT_PROCNAME
:
229 return lttng_add_procname_to_ctx(ctx
);
230 case LTTNG_KERNEL_CONTEXT_HOSTNAME
:
231 return lttng_add_hostname_to_ctx(ctx
);
232 case LTTNG_KERNEL_CONTEXT_CPU_ID
:
233 return lttng_add_cpu_id_to_ctx(ctx
);
234 case LTTNG_KERNEL_CONTEXT_INTERRUPTIBLE
:
235 return lttng_add_interruptible_to_ctx(ctx
);
236 case LTTNG_KERNEL_CONTEXT_NEED_RESCHEDULE
:
237 return lttng_add_need_reschedule_to_ctx(ctx
);
238 case LTTNG_KERNEL_CONTEXT_PREEMPTIBLE
:
239 return lttng_add_preemptible_to_ctx(ctx
);
240 case LTTNG_KERNEL_CONTEXT_MIGRATABLE
:
241 return lttng_add_migratable_to_ctx(ctx
);
242 case LTTNG_KERNEL_CONTEXT_CALLSTACK_KERNEL
:
243 case LTTNG_KERNEL_CONTEXT_CALLSTACK_USER
:
244 return lttng_add_callstack_to_ctx(ctx
, context_param
->ctx
);
251 * lttng_ioctl - lttng syscall through ioctl
257 * This ioctl implements lttng commands:
258 * LTTNG_KERNEL_SESSION
259 * Returns a LTTng trace session file descriptor
260 * LTTNG_KERNEL_TRACER_VERSION
261 * Returns the LTTng kernel tracer version
262 * LTTNG_KERNEL_TRACEPOINT_LIST
263 * Returns a file descriptor listing available tracepoints
264 * LTTNG_KERNEL_WAIT_QUIESCENT
265 * Returns after all previously running probes have completed
266 * LTTNG_KERNEL_TRACER_ABI_VERSION
267 * Returns the LTTng kernel tracer ABI version
269 * The returned session will be deleted when its file descriptor is closed.
272 long lttng_ioctl(struct file
*file
, unsigned int cmd
, unsigned long arg
)
275 case LTTNG_KERNEL_OLD_SESSION
:
276 case LTTNG_KERNEL_SESSION
:
277 return lttng_abi_create_session();
278 case LTTNG_KERNEL_OLD_TRACER_VERSION
:
280 struct lttng_kernel_tracer_version v
;
281 struct lttng_kernel_old_tracer_version oldv
;
282 struct lttng_kernel_old_tracer_version
*uversion
=
283 (struct lttng_kernel_old_tracer_version __user
*) arg
;
285 lttng_abi_tracer_version(&v
);
286 oldv
.major
= v
.major
;
287 oldv
.minor
= v
.minor
;
288 oldv
.patchlevel
= v
.patchlevel
;
290 if (copy_to_user(uversion
, &oldv
, sizeof(oldv
)))
294 case LTTNG_KERNEL_TRACER_VERSION
:
296 struct lttng_kernel_tracer_version version
;
297 struct lttng_kernel_tracer_version
*uversion
=
298 (struct lttng_kernel_tracer_version __user
*) arg
;
300 lttng_abi_tracer_version(&version
);
302 if (copy_to_user(uversion
, &version
, sizeof(version
)))
306 case LTTNG_KERNEL_TRACER_ABI_VERSION
:
308 struct lttng_kernel_tracer_abi_version version
;
309 struct lttng_kernel_tracer_abi_version
*uversion
=
310 (struct lttng_kernel_tracer_abi_version __user
*) arg
;
312 lttng_abi_tracer_abi_version(&version
);
314 if (copy_to_user(uversion
, &version
, sizeof(version
)))
318 case LTTNG_KERNEL_OLD_TRACEPOINT_LIST
:
319 case LTTNG_KERNEL_TRACEPOINT_LIST
:
320 return lttng_abi_tracepoint_list();
321 case LTTNG_KERNEL_SYSCALL_LIST
:
322 return lttng_abi_syscall_list();
323 case LTTNG_KERNEL_OLD_WAIT_QUIESCENT
:
324 case LTTNG_KERNEL_WAIT_QUIESCENT
:
327 case LTTNG_KERNEL_OLD_CALIBRATE
:
329 struct lttng_kernel_old_calibrate __user
*ucalibrate
=
330 (struct lttng_kernel_old_calibrate __user
*) arg
;
331 struct lttng_kernel_old_calibrate old_calibrate
;
332 struct lttng_kernel_calibrate calibrate
;
335 if (copy_from_user(&old_calibrate
, ucalibrate
, sizeof(old_calibrate
)))
337 calibrate
.type
= old_calibrate
.type
;
338 ret
= lttng_calibrate(&calibrate
);
339 if (copy_to_user(ucalibrate
, &old_calibrate
, sizeof(old_calibrate
)))
343 case LTTNG_KERNEL_CALIBRATE
:
345 struct lttng_kernel_calibrate __user
*ucalibrate
=
346 (struct lttng_kernel_calibrate __user
*) arg
;
347 struct lttng_kernel_calibrate calibrate
;
350 if (copy_from_user(&calibrate
, ucalibrate
, sizeof(calibrate
)))
352 ret
= lttng_calibrate(&calibrate
);
353 if (copy_to_user(ucalibrate
, &calibrate
, sizeof(calibrate
)))
362 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(5,6,0))
363 static const struct proc_ops lttng_proc_ops
= {
364 .proc_ioctl
= lttng_ioctl
,
366 .proc_compat_ioctl
= lttng_ioctl
,
367 #endif /* CONFIG_COMPAT */
370 static const struct file_operations lttng_proc_ops
= {
371 .owner
= THIS_MODULE
,
372 .unlocked_ioctl
= lttng_ioctl
,
374 .compat_ioctl
= lttng_ioctl
,
375 #endif /* CONFIG_COMPAT */
380 int lttng_abi_create_channel(struct file
*session_file
,
381 struct lttng_kernel_channel
*chan_param
,
382 enum channel_type channel_type
)
384 struct lttng_session
*session
= session_file
->private_data
;
385 const struct file_operations
*fops
= NULL
;
386 const char *transport_name
;
387 struct lttng_channel
*chan
;
388 struct file
*chan_file
;
392 chan_fd
= lttng_get_unused_fd();
397 switch (channel_type
) {
398 case PER_CPU_CHANNEL
:
399 fops
= <tng_channel_fops
;
401 case METADATA_CHANNEL
:
402 fops
= <tng_metadata_fops
;
406 chan_file
= anon_inode_getfile("[lttng_channel]",
409 if (IS_ERR(chan_file
)) {
410 ret
= PTR_ERR(chan_file
);
413 switch (channel_type
) {
414 case PER_CPU_CHANNEL
:
415 if (chan_param
->output
== LTTNG_KERNEL_SPLICE
) {
416 transport_name
= chan_param
->overwrite
?
417 "relay-overwrite" : "relay-discard";
418 } else if (chan_param
->output
== LTTNG_KERNEL_MMAP
) {
419 transport_name
= chan_param
->overwrite
?
420 "relay-overwrite-mmap" : "relay-discard-mmap";
425 case METADATA_CHANNEL
:
426 if (chan_param
->output
== LTTNG_KERNEL_SPLICE
)
427 transport_name
= "relay-metadata";
428 else if (chan_param
->output
== LTTNG_KERNEL_MMAP
)
429 transport_name
= "relay-metadata-mmap";
434 transport_name
= "<unknown>";
437 if (!atomic_long_add_unless(&session_file
->f_count
, 1, LONG_MAX
)) {
442 * We tolerate no failure path after channel creation. It will stay
443 * invariant for the rest of the session.
445 chan
= lttng_channel_create(session
, transport_name
, NULL
,
446 chan_param
->subbuf_size
,
447 chan_param
->num_subbuf
,
448 chan_param
->switch_timer_interval
,
449 chan_param
->read_timer_interval
,
455 chan
->file
= chan_file
;
456 chan_file
->private_data
= chan
;
457 fd_install(chan_fd
, chan_file
);
462 atomic_long_dec(&session_file
->f_count
);
466 put_unused_fd(chan_fd
);
472 int lttng_abi_session_set_name(struct lttng_session
*session
,
473 struct lttng_kernel_session_name
*name
)
477 len
= strnlen(name
->name
, LTTNG_KERNEL_SESSION_NAME_LEN
);
479 if (len
== LTTNG_KERNEL_SESSION_NAME_LEN
) {
480 /* Name is too long/malformed */
484 strcpy(session
->name
, name
->name
);
489 int lttng_abi_session_set_creation_time(struct lttng_session
*session
,
490 struct lttng_kernel_session_creation_time
*time
)
494 len
= strnlen(time
->iso8601
, LTTNG_KERNEL_SESSION_CREATION_TIME_ISO8601_LEN
);
496 if (len
== LTTNG_KERNEL_SESSION_CREATION_TIME_ISO8601_LEN
) {
497 /* Time is too long/malformed */
501 strcpy(session
->creation_time
, time
->iso8601
);
506 * lttng_session_ioctl - lttng session fd ioctl
512 * This ioctl implements lttng commands:
513 * LTTNG_KERNEL_CHANNEL
514 * Returns a LTTng channel file descriptor
515 * LTTNG_KERNEL_ENABLE
516 * Enables tracing for a session (weak enable)
517 * LTTNG_KERNEL_DISABLE
518 * Disables tracing for a session (strong disable)
519 * LTTNG_KERNEL_METADATA
520 * Returns a LTTng metadata file descriptor
521 * LTTNG_KERNEL_SESSION_TRACK_PID
522 * Add PID to session tracker
523 * LTTNG_KERNEL_SESSION_UNTRACK_PID
524 * Remove PID from session tracker
526 * The returned channel will be deleted when its file descriptor is closed.
529 long lttng_session_ioctl(struct file
*file
, unsigned int cmd
, unsigned long arg
)
531 struct lttng_session
*session
= file
->private_data
;
532 struct lttng_kernel_channel chan_param
;
533 struct lttng_kernel_old_channel old_chan_param
;
536 case LTTNG_KERNEL_OLD_CHANNEL
:
538 if (copy_from_user(&old_chan_param
,
539 (struct lttng_kernel_old_channel __user
*) arg
,
540 sizeof(struct lttng_kernel_old_channel
)))
542 chan_param
.overwrite
= old_chan_param
.overwrite
;
543 chan_param
.subbuf_size
= old_chan_param
.subbuf_size
;
544 chan_param
.num_subbuf
= old_chan_param
.num_subbuf
;
545 chan_param
.switch_timer_interval
= old_chan_param
.switch_timer_interval
;
546 chan_param
.read_timer_interval
= old_chan_param
.read_timer_interval
;
547 chan_param
.output
= old_chan_param
.output
;
549 return lttng_abi_create_channel(file
, &chan_param
,
552 case LTTNG_KERNEL_CHANNEL
:
554 if (copy_from_user(&chan_param
,
555 (struct lttng_kernel_channel __user
*) arg
,
556 sizeof(struct lttng_kernel_channel
)))
558 return lttng_abi_create_channel(file
, &chan_param
,
561 case LTTNG_KERNEL_OLD_SESSION_START
:
562 case LTTNG_KERNEL_OLD_ENABLE
:
563 case LTTNG_KERNEL_SESSION_START
:
564 case LTTNG_KERNEL_ENABLE
:
565 return lttng_session_enable(session
);
566 case LTTNG_KERNEL_OLD_SESSION_STOP
:
567 case LTTNG_KERNEL_OLD_DISABLE
:
568 case LTTNG_KERNEL_SESSION_STOP
:
569 case LTTNG_KERNEL_DISABLE
:
570 return lttng_session_disable(session
);
571 case LTTNG_KERNEL_OLD_METADATA
:
573 if (copy_from_user(&old_chan_param
,
574 (struct lttng_kernel_old_channel __user
*) arg
,
575 sizeof(struct lttng_kernel_old_channel
)))
577 chan_param
.overwrite
= old_chan_param
.overwrite
;
578 chan_param
.subbuf_size
= old_chan_param
.subbuf_size
;
579 chan_param
.num_subbuf
= old_chan_param
.num_subbuf
;
580 chan_param
.switch_timer_interval
= old_chan_param
.switch_timer_interval
;
581 chan_param
.read_timer_interval
= old_chan_param
.read_timer_interval
;
582 chan_param
.output
= old_chan_param
.output
;
584 return lttng_abi_create_channel(file
, &chan_param
,
587 case LTTNG_KERNEL_METADATA
:
589 if (copy_from_user(&chan_param
,
590 (struct lttng_kernel_channel __user
*) arg
,
591 sizeof(struct lttng_kernel_channel
)))
593 return lttng_abi_create_channel(file
, &chan_param
,
596 case LTTNG_KERNEL_SESSION_TRACK_PID
:
597 return lttng_session_track_pid(session
, (int) arg
);
598 case LTTNG_KERNEL_SESSION_UNTRACK_PID
:
599 return lttng_session_untrack_pid(session
, (int) arg
);
600 case LTTNG_KERNEL_SESSION_LIST_TRACKER_PIDS
:
601 return lttng_session_list_tracker_pids(session
);
602 case LTTNG_KERNEL_SESSION_METADATA_REGEN
:
603 return lttng_session_metadata_regenerate(session
);
604 case LTTNG_KERNEL_SESSION_STATEDUMP
:
605 return lttng_session_statedump(session
);
606 case LTTNG_KERNEL_SESSION_SET_NAME
:
608 struct lttng_kernel_session_name name
;
610 if (copy_from_user(&name
,
611 (struct lttng_kernel_session_name __user
*) arg
,
612 sizeof(struct lttng_kernel_session_name
)))
614 return lttng_abi_session_set_name(session
, &name
);
616 case LTTNG_KERNEL_SESSION_SET_CREATION_TIME
:
618 struct lttng_kernel_session_creation_time time
;
620 if (copy_from_user(&time
,
621 (struct lttng_kernel_session_creation_time __user
*) arg
,
622 sizeof(struct lttng_kernel_session_creation_time
)))
624 return lttng_abi_session_set_creation_time(session
, &time
);
632 * Called when the last file reference is dropped.
634 * Big fat note: channels and events are invariant for the whole session after
635 * their creation. So this session destruction also destroys all channel and
636 * event structures specific to this session (they are not destroyed when their
637 * individual file is released).
640 int lttng_session_release(struct inode
*inode
, struct file
*file
)
642 struct lttng_session
*session
= file
->private_data
;
645 lttng_session_destroy(session
);
649 static const struct file_operations lttng_session_fops
= {
650 .owner
= THIS_MODULE
,
651 .release
= lttng_session_release
,
652 .unlocked_ioctl
= lttng_session_ioctl
,
654 .compat_ioctl
= lttng_session_ioctl
,
659 * lttng_metadata_ring_buffer_poll - LTTng ring buffer poll file operation
663 * Handles the poll operations for the metadata channels.
666 unsigned int lttng_metadata_ring_buffer_poll(struct file
*filp
,
669 struct lttng_metadata_stream
*stream
= filp
->private_data
;
670 struct lib_ring_buffer
*buf
= stream
->priv
;
672 unsigned int mask
= 0;
674 if (filp
->f_mode
& FMODE_READ
) {
675 poll_wait_set_exclusive(wait
);
676 poll_wait(filp
, &stream
->read_wait
, wait
);
678 finalized
= stream
->finalized
;
681 * lib_ring_buffer_is_finalized() contains a smp_rmb()
682 * ordering finalized load before offsets loads.
684 WARN_ON(atomic_long_read(&buf
->active_readers
) != 1);
689 mutex_lock(&stream
->metadata_cache
->lock
);
690 if (stream
->metadata_cache
->metadata_written
>
691 stream
->metadata_out
)
693 mutex_unlock(&stream
->metadata_cache
->lock
);
700 void lttng_metadata_ring_buffer_ioctl_put_next_subbuf(struct file
*filp
,
701 unsigned int cmd
, unsigned long arg
)
703 struct lttng_metadata_stream
*stream
= filp
->private_data
;
705 stream
->metadata_out
= stream
->metadata_in
;
709 * Reset the counter of how much metadata has been consumed to 0. That way,
710 * the consumer receives the content of the metadata cache unchanged. This is
711 * different from the metadata_regenerate where the offset from epoch is
712 * resampled, here we want the exact same content as the last time the metadata
713 * was generated. This command is only possible if all the metadata written
714 * in the cache has been output to the metadata stream to avoid corrupting the
717 * Return 0 on success, a negative value on error.
720 int lttng_metadata_cache_dump(struct lttng_metadata_stream
*stream
)
723 struct lttng_metadata_cache
*cache
= stream
->metadata_cache
;
725 mutex_lock(&cache
->lock
);
726 if (stream
->metadata_out
!= cache
->metadata_written
) {
730 stream
->metadata_out
= 0;
731 stream
->metadata_in
= 0;
732 wake_up_interruptible(&stream
->read_wait
);
736 mutex_unlock(&cache
->lock
);
741 long lttng_metadata_ring_buffer_ioctl(struct file
*filp
,
742 unsigned int cmd
, unsigned long arg
)
745 struct lttng_metadata_stream
*stream
= filp
->private_data
;
746 struct lib_ring_buffer
*buf
= stream
->priv
;
749 case RING_BUFFER_GET_NEXT_SUBBUF
:
751 struct lttng_metadata_stream
*stream
= filp
->private_data
;
752 struct lib_ring_buffer
*buf
= stream
->priv
;
753 struct channel
*chan
= buf
->backend
.chan
;
755 ret
= lttng_metadata_output_channel(stream
, chan
);
757 lib_ring_buffer_switch_slow(buf
, SWITCH_ACTIVE
);
763 case RING_BUFFER_GET_SUBBUF
:
766 * Random access is not allowed for metadata channel.
770 case RING_BUFFER_FLUSH_EMPTY
: /* Fall-through. */
771 case RING_BUFFER_FLUSH
:
773 struct lttng_metadata_stream
*stream
= filp
->private_data
;
774 struct lib_ring_buffer
*buf
= stream
->priv
;
775 struct channel
*chan
= buf
->backend
.chan
;
778 * Before doing the actual ring buffer flush, write up to one
779 * packet of metadata in the ring buffer.
781 ret
= lttng_metadata_output_channel(stream
, chan
);
786 case RING_BUFFER_GET_METADATA_VERSION
:
788 struct lttng_metadata_stream
*stream
= filp
->private_data
;
790 return put_u64(stream
->version
, arg
);
792 case RING_BUFFER_METADATA_CACHE_DUMP
:
794 struct lttng_metadata_stream
*stream
= filp
->private_data
;
796 return lttng_metadata_cache_dump(stream
);
801 /* PUT_SUBBUF is the one from lib ring buffer, unmodified. */
803 /* Performing lib ring buffer ioctl after our own. */
804 ret
= lib_ring_buffer_ioctl(filp
, cmd
, arg
, buf
);
809 case RING_BUFFER_PUT_NEXT_SUBBUF
:
811 lttng_metadata_ring_buffer_ioctl_put_next_subbuf(filp
,
824 long lttng_metadata_ring_buffer_compat_ioctl(struct file
*filp
,
825 unsigned int cmd
, unsigned long arg
)
828 struct lttng_metadata_stream
*stream
= filp
->private_data
;
829 struct lib_ring_buffer
*buf
= stream
->priv
;
832 case RING_BUFFER_GET_NEXT_SUBBUF
:
834 struct lttng_metadata_stream
*stream
= filp
->private_data
;
835 struct lib_ring_buffer
*buf
= stream
->priv
;
836 struct channel
*chan
= buf
->backend
.chan
;
838 ret
= lttng_metadata_output_channel(stream
, chan
);
840 lib_ring_buffer_switch_slow(buf
, SWITCH_ACTIVE
);
846 case RING_BUFFER_GET_SUBBUF
:
849 * Random access is not allowed for metadata channel.
853 case RING_BUFFER_FLUSH_EMPTY
: /* Fall-through. */
854 case RING_BUFFER_FLUSH
:
856 struct lttng_metadata_stream
*stream
= filp
->private_data
;
857 struct lib_ring_buffer
*buf
= stream
->priv
;
858 struct channel
*chan
= buf
->backend
.chan
;
861 * Before doing the actual ring buffer flush, write up to one
862 * packet of metadata in the ring buffer.
864 ret
= lttng_metadata_output_channel(stream
, chan
);
869 case RING_BUFFER_GET_METADATA_VERSION
:
871 struct lttng_metadata_stream
*stream
= filp
->private_data
;
873 return put_u64(stream
->version
, arg
);
875 case RING_BUFFER_METADATA_CACHE_DUMP
:
877 struct lttng_metadata_stream
*stream
= filp
->private_data
;
879 return lttng_metadata_cache_dump(stream
);
884 /* PUT_SUBBUF is the one from lib ring buffer, unmodified. */
886 /* Performing lib ring buffer ioctl after our own. */
887 ret
= lib_ring_buffer_compat_ioctl(filp
, cmd
, arg
, buf
);
892 case RING_BUFFER_PUT_NEXT_SUBBUF
:
894 lttng_metadata_ring_buffer_ioctl_put_next_subbuf(filp
,
907 * This is not used by anonymous file descriptors. This code is left
908 * there if we ever want to implement an inode with open() operation.
911 int lttng_metadata_ring_buffer_open(struct inode
*inode
, struct file
*file
)
913 struct lttng_metadata_stream
*stream
= inode
->i_private
;
914 struct lib_ring_buffer
*buf
= stream
->priv
;
916 file
->private_data
= buf
;
918 * Since life-time of metadata cache differs from that of
919 * session, we need to keep our own reference on the transport.
921 if (!try_module_get(stream
->transport
->owner
)) {
922 printk(KERN_WARNING
"LTT : Can't lock transport module.\n");
925 return lib_ring_buffer_open(inode
, file
, buf
);
929 int lttng_metadata_ring_buffer_release(struct inode
*inode
, struct file
*file
)
931 struct lttng_metadata_stream
*stream
= file
->private_data
;
932 struct lib_ring_buffer
*buf
= stream
->priv
;
934 kref_put(&stream
->metadata_cache
->refcount
, metadata_cache_destroy
);
935 module_put(stream
->transport
->owner
);
936 return lib_ring_buffer_release(inode
, file
, buf
);
940 ssize_t
lttng_metadata_ring_buffer_splice_read(struct file
*in
, loff_t
*ppos
,
941 struct pipe_inode_info
*pipe
, size_t len
,
944 struct lttng_metadata_stream
*stream
= in
->private_data
;
945 struct lib_ring_buffer
*buf
= stream
->priv
;
947 return lib_ring_buffer_splice_read(in
, ppos
, pipe
, len
,
952 int lttng_metadata_ring_buffer_mmap(struct file
*filp
,
953 struct vm_area_struct
*vma
)
955 struct lttng_metadata_stream
*stream
= filp
->private_data
;
956 struct lib_ring_buffer
*buf
= stream
->priv
;
958 return lib_ring_buffer_mmap(filp
, vma
, buf
);
962 const struct file_operations lttng_metadata_ring_buffer_file_operations
= {
963 .owner
= THIS_MODULE
,
964 .open
= lttng_metadata_ring_buffer_open
,
965 .release
= lttng_metadata_ring_buffer_release
,
966 .poll
= lttng_metadata_ring_buffer_poll
,
967 .splice_read
= lttng_metadata_ring_buffer_splice_read
,
968 .mmap
= lttng_metadata_ring_buffer_mmap
,
969 .unlocked_ioctl
= lttng_metadata_ring_buffer_ioctl
,
970 .llseek
= vfs_lib_ring_buffer_no_llseek
,
972 .compat_ioctl
= lttng_metadata_ring_buffer_compat_ioctl
,
977 int lttng_abi_create_stream_fd(struct file
*channel_file
, void *stream_priv
,
978 const struct file_operations
*fops
)
981 struct file
*stream_file
;
983 stream_fd
= lttng_get_unused_fd();
988 stream_file
= anon_inode_getfile("[lttng_stream]", fops
,
989 stream_priv
, O_RDWR
);
990 if (IS_ERR(stream_file
)) {
991 ret
= PTR_ERR(stream_file
);
995 * OPEN_FMODE, called within anon_inode_getfile/alloc_file, don't honor
996 * FMODE_LSEEK, FMODE_PREAD nor FMODE_PWRITE. We need to read from this
997 * file descriptor, so we set FMODE_PREAD here.
999 stream_file
->f_mode
|= FMODE_PREAD
;
1000 fd_install(stream_fd
, stream_file
);
1002 * The stream holds a reference to the channel within the generic ring
1003 * buffer library, so no need to hold a refcount on the channel and
1004 * session files here.
1009 put_unused_fd(stream_fd
);
1015 int lttng_abi_open_stream(struct file
*channel_file
)
1017 struct lttng_channel
*channel
= channel_file
->private_data
;
1018 struct lib_ring_buffer
*buf
;
1022 buf
= channel
->ops
->buffer_read_open(channel
->chan
);
1027 ret
= lttng_abi_create_stream_fd(channel_file
, stream_priv
,
1028 <tng_stream_ring_buffer_file_operations
);
1035 channel
->ops
->buffer_read_close(buf
);
1040 int lttng_abi_open_metadata_stream(struct file
*channel_file
)
1042 struct lttng_channel
*channel
= channel_file
->private_data
;
1043 struct lttng_session
*session
= channel
->session
;
1044 struct lib_ring_buffer
*buf
;
1046 struct lttng_metadata_stream
*metadata_stream
;
1049 buf
= channel
->ops
->buffer_read_open(channel
->chan
);
1053 metadata_stream
= kzalloc(sizeof(struct lttng_metadata_stream
),
1055 if (!metadata_stream
) {
1059 metadata_stream
->metadata_cache
= session
->metadata_cache
;
1060 init_waitqueue_head(&metadata_stream
->read_wait
);
1061 metadata_stream
->priv
= buf
;
1062 stream_priv
= metadata_stream
;
1063 metadata_stream
->transport
= channel
->transport
;
1066 * Since life-time of metadata cache differs from that of
1067 * session, we need to keep our own reference on the transport.
1069 if (!try_module_get(metadata_stream
->transport
->owner
)) {
1070 printk(KERN_WARNING
"LTT : Can't lock transport module.\n");
1075 if (!lttng_kref_get(&session
->metadata_cache
->refcount
)) {
1080 ret
= lttng_abi_create_stream_fd(channel_file
, stream_priv
,
1081 <tng_metadata_ring_buffer_file_operations
);
1085 list_add(&metadata_stream
->list
,
1086 &session
->metadata_cache
->metadata_stream
);
1090 kref_put(&session
->metadata_cache
->refcount
, metadata_cache_destroy
);
1092 module_put(metadata_stream
->transport
->owner
);
1094 kfree(metadata_stream
);
1096 channel
->ops
->buffer_read_close(buf
);
1101 int lttng_abi_create_event(struct file
*channel_file
,
1102 struct lttng_kernel_event
*event_param
)
1104 struct lttng_channel
*channel
= channel_file
->private_data
;
1106 struct file
*event_file
;
1109 event_param
->name
[LTTNG_KERNEL_SYM_NAME_LEN
- 1] = '\0';
1110 switch (event_param
->instrumentation
) {
1111 case LTTNG_KERNEL_KRETPROBE
:
1112 event_param
->u
.kretprobe
.symbol_name
[LTTNG_KERNEL_SYM_NAME_LEN
- 1] = '\0';
1114 case LTTNG_KERNEL_KPROBE
:
1115 event_param
->u
.kprobe
.symbol_name
[LTTNG_KERNEL_SYM_NAME_LEN
- 1] = '\0';
1117 case LTTNG_KERNEL_FUNCTION
:
1119 /* Not implemented. */
1124 event_fd
= lttng_get_unused_fd();
1129 event_file
= anon_inode_getfile("[lttng_event]",
1132 if (IS_ERR(event_file
)) {
1133 ret
= PTR_ERR(event_file
);
1136 /* The event holds a reference on the channel */
1137 if (!atomic_long_add_unless(&channel_file
->f_count
, 1, LONG_MAX
)) {
1139 goto refcount_error
;
1141 if (event_param
->instrumentation
== LTTNG_KERNEL_TRACEPOINT
1142 || event_param
->instrumentation
== LTTNG_KERNEL_SYSCALL
) {
1143 struct lttng_enabler
*enabler
;
1145 if (strutils_is_star_glob_pattern(event_param
->name
)) {
1147 * If the event name is a star globbing pattern,
1148 * we create the special star globbing enabler.
1150 enabler
= lttng_enabler_create(LTTNG_ENABLER_STAR_GLOB
,
1151 event_param
, channel
);
1153 enabler
= lttng_enabler_create(LTTNG_ENABLER_NAME
,
1154 event_param
, channel
);
1158 struct lttng_event
*event
;
1161 * We tolerate no failure path after event creation. It
1162 * will stay invariant for the rest of the session.
1164 event
= lttng_event_create(channel
, event_param
,
1166 event_param
->instrumentation
);
1167 WARN_ON_ONCE(!event
);
1168 if (IS_ERR(event
)) {
1169 ret
= PTR_ERR(event
);
1174 event_file
->private_data
= priv
;
1175 fd_install(event_fd
, event_file
);
1179 atomic_long_dec(&channel_file
->f_count
);
1183 put_unused_fd(event_fd
);
1189 * lttng_channel_ioctl - lttng syscall through ioctl
1195 * This ioctl implements lttng commands:
1196 * LTTNG_KERNEL_STREAM
1197 * Returns an event stream file descriptor or failure.
1198 * (typically, one event stream records events from one CPU)
1199 * LTTNG_KERNEL_EVENT
1200 * Returns an event file descriptor or failure.
1201 * LTTNG_KERNEL_CONTEXT
1202 * Prepend a context field to each event in the channel
1203 * LTTNG_KERNEL_ENABLE
1204 * Enable recording for events in this channel (weak enable)
1205 * LTTNG_KERNEL_DISABLE
1206 * Disable recording for events in this channel (strong disable)
1208 * Channel and event file descriptors also hold a reference on the session.
1211 long lttng_channel_ioctl(struct file
*file
, unsigned int cmd
, unsigned long arg
)
1213 struct lttng_channel
*channel
= file
->private_data
;
1216 case LTTNG_KERNEL_OLD_STREAM
:
1217 case LTTNG_KERNEL_STREAM
:
1218 return lttng_abi_open_stream(file
);
1219 case LTTNG_KERNEL_OLD_EVENT
:
1221 struct lttng_kernel_event
*uevent_param
;
1222 struct lttng_kernel_old_event
*old_uevent_param
;
1225 uevent_param
= kmalloc(sizeof(struct lttng_kernel_event
),
1227 if (!uevent_param
) {
1231 old_uevent_param
= kmalloc(
1232 sizeof(struct lttng_kernel_old_event
),
1234 if (!old_uevent_param
) {
1236 goto old_event_error_free_param
;
1238 if (copy_from_user(old_uevent_param
,
1239 (struct lttng_kernel_old_event __user
*) arg
,
1240 sizeof(struct lttng_kernel_old_event
))) {
1242 goto old_event_error_free_old_param
;
1245 memcpy(uevent_param
->name
, old_uevent_param
->name
,
1246 sizeof(uevent_param
->name
));
1247 uevent_param
->instrumentation
=
1248 old_uevent_param
->instrumentation
;
1250 switch (old_uevent_param
->instrumentation
) {
1251 case LTTNG_KERNEL_KPROBE
:
1252 uevent_param
->u
.kprobe
.addr
=
1253 old_uevent_param
->u
.kprobe
.addr
;
1254 uevent_param
->u
.kprobe
.offset
=
1255 old_uevent_param
->u
.kprobe
.offset
;
1256 memcpy(uevent_param
->u
.kprobe
.symbol_name
,
1257 old_uevent_param
->u
.kprobe
.symbol_name
,
1258 sizeof(uevent_param
->u
.kprobe
.symbol_name
));
1260 case LTTNG_KERNEL_KRETPROBE
:
1261 uevent_param
->u
.kretprobe
.addr
=
1262 old_uevent_param
->u
.kretprobe
.addr
;
1263 uevent_param
->u
.kretprobe
.offset
=
1264 old_uevent_param
->u
.kretprobe
.offset
;
1265 memcpy(uevent_param
->u
.kretprobe
.symbol_name
,
1266 old_uevent_param
->u
.kretprobe
.symbol_name
,
1267 sizeof(uevent_param
->u
.kretprobe
.symbol_name
));
1269 case LTTNG_KERNEL_FUNCTION
:
1271 /* Not implemented. */
1276 ret
= lttng_abi_create_event(file
, uevent_param
);
1278 old_event_error_free_old_param
:
1279 kfree(old_uevent_param
);
1280 old_event_error_free_param
:
1281 kfree(uevent_param
);
1285 case LTTNG_KERNEL_EVENT
:
1287 struct lttng_kernel_event uevent_param
;
1289 if (copy_from_user(&uevent_param
,
1290 (struct lttng_kernel_event __user
*) arg
,
1291 sizeof(uevent_param
)))
1293 return lttng_abi_create_event(file
, &uevent_param
);
1295 case LTTNG_KERNEL_OLD_CONTEXT
:
1297 struct lttng_kernel_context
*ucontext_param
;
1298 struct lttng_kernel_old_context
*old_ucontext_param
;
1301 ucontext_param
= kmalloc(sizeof(struct lttng_kernel_context
),
1303 if (!ucontext_param
) {
1307 old_ucontext_param
= kmalloc(sizeof(struct lttng_kernel_old_context
),
1309 if (!old_ucontext_param
) {
1311 goto old_ctx_error_free_param
;
1314 if (copy_from_user(old_ucontext_param
,
1315 (struct lttng_kernel_old_context __user
*) arg
,
1316 sizeof(struct lttng_kernel_old_context
))) {
1318 goto old_ctx_error_free_old_param
;
1320 ucontext_param
->ctx
= old_ucontext_param
->ctx
;
1321 memcpy(ucontext_param
->padding
, old_ucontext_param
->padding
,
1322 sizeof(ucontext_param
->padding
));
1323 /* only type that uses the union */
1324 if (old_ucontext_param
->ctx
== LTTNG_KERNEL_CONTEXT_PERF_COUNTER
) {
1325 ucontext_param
->u
.perf_counter
.type
=
1326 old_ucontext_param
->u
.perf_counter
.type
;
1327 ucontext_param
->u
.perf_counter
.config
=
1328 old_ucontext_param
->u
.perf_counter
.config
;
1329 memcpy(ucontext_param
->u
.perf_counter
.name
,
1330 old_ucontext_param
->u
.perf_counter
.name
,
1331 sizeof(ucontext_param
->u
.perf_counter
.name
));
1334 ret
= lttng_abi_add_context(file
,
1336 &channel
->ctx
, channel
->session
);
1338 old_ctx_error_free_old_param
:
1339 kfree(old_ucontext_param
);
1340 old_ctx_error_free_param
:
1341 kfree(ucontext_param
);
1345 case LTTNG_KERNEL_CONTEXT
:
1347 struct lttng_kernel_context ucontext_param
;
1349 if (copy_from_user(&ucontext_param
,
1350 (struct lttng_kernel_context __user
*) arg
,
1351 sizeof(ucontext_param
)))
1353 return lttng_abi_add_context(file
,
1355 &channel
->ctx
, channel
->session
);
1357 case LTTNG_KERNEL_OLD_ENABLE
:
1358 case LTTNG_KERNEL_ENABLE
:
1359 return lttng_channel_enable(channel
);
1360 case LTTNG_KERNEL_OLD_DISABLE
:
1361 case LTTNG_KERNEL_DISABLE
:
1362 return lttng_channel_disable(channel
);
1363 case LTTNG_KERNEL_SYSCALL_MASK
:
1364 return lttng_channel_syscall_mask(channel
,
1365 (struct lttng_kernel_syscall_mask __user
*) arg
);
1367 return -ENOIOCTLCMD
;
1372 * lttng_metadata_ioctl - lttng syscall through ioctl
1378 * This ioctl implements lttng commands:
1379 * LTTNG_KERNEL_STREAM
1380 * Returns an event stream file descriptor or failure.
1382 * Channel and event file descriptors also hold a reference on the session.
1385 long lttng_metadata_ioctl(struct file
*file
, unsigned int cmd
, unsigned long arg
)
1388 case LTTNG_KERNEL_OLD_STREAM
:
1389 case LTTNG_KERNEL_STREAM
:
1390 return lttng_abi_open_metadata_stream(file
);
1392 return -ENOIOCTLCMD
;
1397 * lttng_channel_poll - lttng stream addition/removal monitoring
1402 unsigned int lttng_channel_poll(struct file
*file
, poll_table
*wait
)
1404 struct lttng_channel
*channel
= file
->private_data
;
1405 unsigned int mask
= 0;
1407 if (file
->f_mode
& FMODE_READ
) {
1408 poll_wait_set_exclusive(wait
);
1409 poll_wait(file
, channel
->ops
->get_hp_wait_queue(channel
->chan
),
1412 if (channel
->ops
->is_disabled(channel
->chan
))
1414 if (channel
->ops
->is_finalized(channel
->chan
))
1416 if (channel
->ops
->buffer_has_read_closed_stream(channel
->chan
))
1417 return POLLIN
| POLLRDNORM
;
1425 int lttng_channel_release(struct inode
*inode
, struct file
*file
)
1427 struct lttng_channel
*channel
= file
->private_data
;
1430 fput(channel
->session
->file
);
1435 int lttng_metadata_channel_release(struct inode
*inode
, struct file
*file
)
1437 struct lttng_channel
*channel
= file
->private_data
;
1440 fput(channel
->session
->file
);
1441 lttng_metadata_channel_destroy(channel
);
1447 static const struct file_operations lttng_channel_fops
= {
1448 .owner
= THIS_MODULE
,
1449 .release
= lttng_channel_release
,
1450 .poll
= lttng_channel_poll
,
1451 .unlocked_ioctl
= lttng_channel_ioctl
,
1452 #ifdef CONFIG_COMPAT
1453 .compat_ioctl
= lttng_channel_ioctl
,
1457 static const struct file_operations lttng_metadata_fops
= {
1458 .owner
= THIS_MODULE
,
1459 .release
= lttng_metadata_channel_release
,
1460 .unlocked_ioctl
= lttng_metadata_ioctl
,
1461 #ifdef CONFIG_COMPAT
1462 .compat_ioctl
= lttng_metadata_ioctl
,
1467 * lttng_event_ioctl - lttng syscall through ioctl
1473 * This ioctl implements lttng commands:
1474 * LTTNG_KERNEL_CONTEXT
1475 * Prepend a context field to each record of this event
1476 * LTTNG_KERNEL_ENABLE
1477 * Enable recording for this event (weak enable)
1478 * LTTNG_KERNEL_DISABLE
1479 * Disable recording for this event (strong disable)
1482 long lttng_event_ioctl(struct file
*file
, unsigned int cmd
, unsigned long arg
)
1484 struct lttng_event
*event
;
1485 struct lttng_enabler
*enabler
;
1486 enum lttng_event_type
*evtype
= file
->private_data
;
1489 case LTTNG_KERNEL_OLD_CONTEXT
:
1491 /* Not implemented */
1494 case LTTNG_KERNEL_CONTEXT
:
1496 /* Not implemented */
1499 case LTTNG_KERNEL_OLD_ENABLE
:
1500 case LTTNG_KERNEL_ENABLE
:
1502 case LTTNG_TYPE_EVENT
:
1503 event
= file
->private_data
;
1504 return lttng_event_enable(event
);
1505 case LTTNG_TYPE_ENABLER
:
1506 enabler
= file
->private_data
;
1507 return lttng_enabler_enable(enabler
);
1512 case LTTNG_KERNEL_OLD_DISABLE
:
1513 case LTTNG_KERNEL_DISABLE
:
1515 case LTTNG_TYPE_EVENT
:
1516 event
= file
->private_data
;
1517 return lttng_event_disable(event
);
1518 case LTTNG_TYPE_ENABLER
:
1519 enabler
= file
->private_data
;
1520 return lttng_enabler_disable(enabler
);
1525 case LTTNG_KERNEL_FILTER
:
1527 case LTTNG_TYPE_EVENT
:
1529 case LTTNG_TYPE_ENABLER
:
1531 enabler
= file
->private_data
;
1532 return lttng_enabler_attach_bytecode(enabler
,
1533 (struct lttng_kernel_filter_bytecode __user
*) arg
);
1539 case LTTNG_KERNEL_ADD_CALLSITE
:
1541 case LTTNG_TYPE_EVENT
:
1542 event
= file
->private_data
;
1543 return lttng_event_add_callsite(event
,
1544 (struct lttng_kernel_event_callsite __user
*) arg
);
1545 case LTTNG_TYPE_ENABLER
:
1552 return -ENOIOCTLCMD
;
1557 int lttng_event_release(struct inode
*inode
, struct file
*file
)
1559 struct lttng_event
*event
;
1560 struct lttng_enabler
*enabler
;
1561 enum lttng_event_type
*evtype
= file
->private_data
;
1567 case LTTNG_TYPE_EVENT
:
1568 event
= file
->private_data
;
1570 fput(event
->chan
->file
);
1572 case LTTNG_TYPE_ENABLER
:
1573 enabler
= file
->private_data
;
1575 fput(enabler
->chan
->file
);
1585 /* TODO: filter control ioctl */
1586 static const struct file_operations lttng_event_fops
= {
1587 .owner
= THIS_MODULE
,
1588 .release
= lttng_event_release
,
1589 .unlocked_ioctl
= lttng_event_ioctl
,
1590 #ifdef CONFIG_COMPAT
1591 .compat_ioctl
= lttng_event_ioctl
,
1595 static int put_u64(uint64_t val
, unsigned long arg
)
1597 return put_user(val
, (uint64_t __user
*) arg
);
1600 static long lttng_stream_ring_buffer_ioctl(struct file
*filp
,
1601 unsigned int cmd
, unsigned long arg
)
1603 struct lib_ring_buffer
*buf
= filp
->private_data
;
1604 struct channel
*chan
= buf
->backend
.chan
;
1605 const struct lib_ring_buffer_config
*config
= &chan
->backend
.config
;
1606 const struct lttng_channel_ops
*ops
= chan
->backend
.priv_ops
;
1609 if (atomic_read(&chan
->record_disabled
))
1613 case LTTNG_RING_BUFFER_GET_TIMESTAMP_BEGIN
:
1617 ret
= ops
->timestamp_begin(config
, buf
, &ts
);
1620 return put_u64(ts
, arg
);
1622 case LTTNG_RING_BUFFER_GET_TIMESTAMP_END
:
1626 ret
= ops
->timestamp_end(config
, buf
, &ts
);
1629 return put_u64(ts
, arg
);
1631 case LTTNG_RING_BUFFER_GET_EVENTS_DISCARDED
:
1635 ret
= ops
->events_discarded(config
, buf
, &ed
);
1638 return put_u64(ed
, arg
);
1640 case LTTNG_RING_BUFFER_GET_CONTENT_SIZE
:
1644 ret
= ops
->content_size(config
, buf
, &cs
);
1647 return put_u64(cs
, arg
);
1649 case LTTNG_RING_BUFFER_GET_PACKET_SIZE
:
1653 ret
= ops
->packet_size(config
, buf
, &ps
);
1656 return put_u64(ps
, arg
);
1658 case LTTNG_RING_BUFFER_GET_STREAM_ID
:
1662 ret
= ops
->stream_id(config
, buf
, &si
);
1665 return put_u64(si
, arg
);
1667 case LTTNG_RING_BUFFER_GET_CURRENT_TIMESTAMP
:
1671 ret
= ops
->current_timestamp(config
, buf
, &ts
);
1674 return put_u64(ts
, arg
);
1676 case LTTNG_RING_BUFFER_GET_SEQ_NUM
:
1680 ret
= ops
->sequence_number(config
, buf
, &seq
);
1683 return put_u64(seq
, arg
);
1685 case LTTNG_RING_BUFFER_INSTANCE_ID
:
1689 ret
= ops
->instance_id(config
, buf
, &id
);
1692 return put_u64(id
, arg
);
1695 return lib_ring_buffer_file_operations
.unlocked_ioctl(filp
,
1703 #ifdef CONFIG_COMPAT
1704 static long lttng_stream_ring_buffer_compat_ioctl(struct file
*filp
,
1705 unsigned int cmd
, unsigned long arg
)
1707 struct lib_ring_buffer
*buf
= filp
->private_data
;
1708 struct channel
*chan
= buf
->backend
.chan
;
1709 const struct lib_ring_buffer_config
*config
= &chan
->backend
.config
;
1710 const struct lttng_channel_ops
*ops
= chan
->backend
.priv_ops
;
1713 if (atomic_read(&chan
->record_disabled
))
1717 case LTTNG_RING_BUFFER_COMPAT_GET_TIMESTAMP_BEGIN
:
1721 ret
= ops
->timestamp_begin(config
, buf
, &ts
);
1724 return put_u64(ts
, arg
);
1726 case LTTNG_RING_BUFFER_COMPAT_GET_TIMESTAMP_END
:
1730 ret
= ops
->timestamp_end(config
, buf
, &ts
);
1733 return put_u64(ts
, arg
);
1735 case LTTNG_RING_BUFFER_COMPAT_GET_EVENTS_DISCARDED
:
1739 ret
= ops
->events_discarded(config
, buf
, &ed
);
1742 return put_u64(ed
, arg
);
1744 case LTTNG_RING_BUFFER_COMPAT_GET_CONTENT_SIZE
:
1748 ret
= ops
->content_size(config
, buf
, &cs
);
1751 return put_u64(cs
, arg
);
1753 case LTTNG_RING_BUFFER_COMPAT_GET_PACKET_SIZE
:
1757 ret
= ops
->packet_size(config
, buf
, &ps
);
1760 return put_u64(ps
, arg
);
1762 case LTTNG_RING_BUFFER_COMPAT_GET_STREAM_ID
:
1766 ret
= ops
->stream_id(config
, buf
, &si
);
1769 return put_u64(si
, arg
);
1771 case LTTNG_RING_BUFFER_GET_CURRENT_TIMESTAMP
:
1775 ret
= ops
->current_timestamp(config
, buf
, &ts
);
1778 return put_u64(ts
, arg
);
1780 case LTTNG_RING_BUFFER_COMPAT_GET_SEQ_NUM
:
1784 ret
= ops
->sequence_number(config
, buf
, &seq
);
1787 return put_u64(seq
, arg
);
1789 case LTTNG_RING_BUFFER_COMPAT_INSTANCE_ID
:
1793 ret
= ops
->instance_id(config
, buf
, &id
);
1796 return put_u64(id
, arg
);
1799 return lib_ring_buffer_file_operations
.compat_ioctl(filp
,
1806 #endif /* CONFIG_COMPAT */
1808 static void lttng_stream_override_ring_buffer_fops(void)
1810 lttng_stream_ring_buffer_file_operations
.owner
= THIS_MODULE
;
1811 lttng_stream_ring_buffer_file_operations
.open
=
1812 lib_ring_buffer_file_operations
.open
;
1813 lttng_stream_ring_buffer_file_operations
.release
=
1814 lib_ring_buffer_file_operations
.release
;
1815 lttng_stream_ring_buffer_file_operations
.poll
=
1816 lib_ring_buffer_file_operations
.poll
;
1817 lttng_stream_ring_buffer_file_operations
.splice_read
=
1818 lib_ring_buffer_file_operations
.splice_read
;
1819 lttng_stream_ring_buffer_file_operations
.mmap
=
1820 lib_ring_buffer_file_operations
.mmap
;
1821 lttng_stream_ring_buffer_file_operations
.unlocked_ioctl
=
1822 lttng_stream_ring_buffer_ioctl
;
1823 lttng_stream_ring_buffer_file_operations
.llseek
=
1824 lib_ring_buffer_file_operations
.llseek
;
1825 #ifdef CONFIG_COMPAT
1826 lttng_stream_ring_buffer_file_operations
.compat_ioctl
=
1827 lttng_stream_ring_buffer_compat_ioctl
;
1831 int __init
lttng_abi_init(void)
1835 wrapper_vmalloc_sync_mappings();
1838 ret
= lttng_tp_mempool_init();
1843 lttng_proc_dentry
= proc_create_data("lttng", S_IRUSR
| S_IWUSR
, NULL
,
1844 <tng_proc_ops
, NULL
);
1846 if (!lttng_proc_dentry
) {
1847 printk(KERN_ERR
"Error creating LTTng control file\n");
1851 lttng_stream_override_ring_buffer_fops();
1855 lttng_tp_mempool_destroy();
1856 lttng_clock_unref();
1860 /* No __exit annotation because used by init error path too. */
1861 void lttng_abi_exit(void)
1863 lttng_tp_mempool_destroy();
1864 lttng_clock_unref();
1865 if (lttng_proc_dentry
)
1866 remove_proc_entry("lttng", NULL
);