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 int lttng_abi_session_set_name(struct lttng_session
*session
,
472 struct lttng_kernel_session_name
*name
)
476 len
= strnlen(name
->name
, LTTNG_KERNEL_SESSION_NAME_LEN
);
478 if (len
== LTTNG_KERNEL_SESSION_NAME_LEN
) {
479 /* Name is too long/malformed */
483 strcpy(session
->name
, name
->name
);
488 int lttng_abi_session_set_creation_time(struct lttng_session
*session
,
489 struct lttng_kernel_session_creation_time
*time
)
493 len
= strnlen(time
->iso8601
, LTTNG_KERNEL_SESSION_CREATION_TIME_ISO8601_LEN
);
495 if (len
== LTTNG_KERNEL_SESSION_CREATION_TIME_ISO8601_LEN
) {
496 /* Time is too long/malformed */
500 strcpy(session
->creation_time
, time
->iso8601
);
505 * lttng_session_ioctl - lttng session fd ioctl
511 * This ioctl implements lttng commands:
512 * LTTNG_KERNEL_CHANNEL
513 * Returns a LTTng channel file descriptor
514 * LTTNG_KERNEL_ENABLE
515 * Enables tracing for a session (weak enable)
516 * LTTNG_KERNEL_DISABLE
517 * Disables tracing for a session (strong disable)
518 * LTTNG_KERNEL_METADATA
519 * Returns a LTTng metadata file descriptor
520 * LTTNG_KERNEL_SESSION_TRACK_PID
521 * Add PID to session tracker
522 * LTTNG_KERNEL_SESSION_UNTRACK_PID
523 * Remove PID from session tracker
525 * The returned channel will be deleted when its file descriptor is closed.
528 long lttng_session_ioctl(struct file
*file
, unsigned int cmd
, unsigned long arg
)
530 struct lttng_session
*session
= file
->private_data
;
531 struct lttng_kernel_channel chan_param
;
532 struct lttng_kernel_old_channel old_chan_param
;
535 case LTTNG_KERNEL_OLD_CHANNEL
:
537 if (copy_from_user(&old_chan_param
,
538 (struct lttng_kernel_old_channel __user
*) arg
,
539 sizeof(struct lttng_kernel_old_channel
)))
541 chan_param
.overwrite
= old_chan_param
.overwrite
;
542 chan_param
.subbuf_size
= old_chan_param
.subbuf_size
;
543 chan_param
.num_subbuf
= old_chan_param
.num_subbuf
;
544 chan_param
.switch_timer_interval
= old_chan_param
.switch_timer_interval
;
545 chan_param
.read_timer_interval
= old_chan_param
.read_timer_interval
;
546 chan_param
.output
= old_chan_param
.output
;
548 return lttng_abi_create_channel(file
, &chan_param
,
551 case LTTNG_KERNEL_CHANNEL
:
553 if (copy_from_user(&chan_param
,
554 (struct lttng_kernel_channel __user
*) arg
,
555 sizeof(struct lttng_kernel_channel
)))
557 return lttng_abi_create_channel(file
, &chan_param
,
560 case LTTNG_KERNEL_OLD_SESSION_START
:
561 case LTTNG_KERNEL_OLD_ENABLE
:
562 case LTTNG_KERNEL_SESSION_START
:
563 case LTTNG_KERNEL_ENABLE
:
564 return lttng_session_enable(session
);
565 case LTTNG_KERNEL_OLD_SESSION_STOP
:
566 case LTTNG_KERNEL_OLD_DISABLE
:
567 case LTTNG_KERNEL_SESSION_STOP
:
568 case LTTNG_KERNEL_DISABLE
:
569 return lttng_session_disable(session
);
570 case LTTNG_KERNEL_OLD_METADATA
:
572 if (copy_from_user(&old_chan_param
,
573 (struct lttng_kernel_old_channel __user
*) arg
,
574 sizeof(struct lttng_kernel_old_channel
)))
576 chan_param
.overwrite
= old_chan_param
.overwrite
;
577 chan_param
.subbuf_size
= old_chan_param
.subbuf_size
;
578 chan_param
.num_subbuf
= old_chan_param
.num_subbuf
;
579 chan_param
.switch_timer_interval
= old_chan_param
.switch_timer_interval
;
580 chan_param
.read_timer_interval
= old_chan_param
.read_timer_interval
;
581 chan_param
.output
= old_chan_param
.output
;
583 return lttng_abi_create_channel(file
, &chan_param
,
586 case LTTNG_KERNEL_METADATA
:
588 if (copy_from_user(&chan_param
,
589 (struct lttng_kernel_channel __user
*) arg
,
590 sizeof(struct lttng_kernel_channel
)))
592 return lttng_abi_create_channel(file
, &chan_param
,
595 case LTTNG_KERNEL_SESSION_TRACK_PID
:
596 return lttng_session_track_pid(session
, (int) arg
);
597 case LTTNG_KERNEL_SESSION_UNTRACK_PID
:
598 return lttng_session_untrack_pid(session
, (int) arg
);
599 case LTTNG_KERNEL_SESSION_LIST_TRACKER_PIDS
:
600 return lttng_session_list_tracker_pids(session
);
601 case LTTNG_KERNEL_SESSION_METADATA_REGEN
:
602 return lttng_session_metadata_regenerate(session
);
603 case LTTNG_KERNEL_SESSION_STATEDUMP
:
604 return lttng_session_statedump(session
);
605 case LTTNG_KERNEL_SESSION_SET_NAME
:
607 struct lttng_kernel_session_name name
;
609 if (copy_from_user(&name
,
610 (struct lttng_kernel_session_name __user
*) arg
,
611 sizeof(struct lttng_kernel_session_name
)))
613 return lttng_abi_session_set_name(session
, &name
);
615 case LTTNG_KERNEL_SESSION_SET_CREATION_TIME
:
617 struct lttng_kernel_session_creation_time time
;
619 if (copy_from_user(&time
,
620 (struct lttng_kernel_session_creation_time __user
*) arg
,
621 sizeof(struct lttng_kernel_session_creation_time
)))
623 return lttng_abi_session_set_creation_time(session
, &time
);
631 * Called when the last file reference is dropped.
633 * Big fat note: channels and events are invariant for the whole session after
634 * their creation. So this session destruction also destroys all channel and
635 * event structures specific to this session (they are not destroyed when their
636 * individual file is released).
639 int lttng_session_release(struct inode
*inode
, struct file
*file
)
641 struct lttng_session
*session
= file
->private_data
;
644 lttng_session_destroy(session
);
648 static const struct file_operations lttng_session_fops
= {
649 .owner
= THIS_MODULE
,
650 .release
= lttng_session_release
,
651 .unlocked_ioctl
= lttng_session_ioctl
,
653 .compat_ioctl
= lttng_session_ioctl
,
658 * lttng_metadata_ring_buffer_poll - LTTng ring buffer poll file operation
662 * Handles the poll operations for the metadata channels.
665 unsigned int lttng_metadata_ring_buffer_poll(struct file
*filp
,
668 struct lttng_metadata_stream
*stream
= filp
->private_data
;
669 struct lib_ring_buffer
*buf
= stream
->priv
;
671 unsigned int mask
= 0;
673 if (filp
->f_mode
& FMODE_READ
) {
674 poll_wait_set_exclusive(wait
);
675 poll_wait(filp
, &stream
->read_wait
, wait
);
677 finalized
= stream
->finalized
;
680 * lib_ring_buffer_is_finalized() contains a smp_rmb()
681 * ordering finalized load before offsets loads.
683 WARN_ON(atomic_long_read(&buf
->active_readers
) != 1);
688 mutex_lock(&stream
->metadata_cache
->lock
);
689 if (stream
->metadata_cache
->metadata_written
>
690 stream
->metadata_out
)
692 mutex_unlock(&stream
->metadata_cache
->lock
);
699 void lttng_metadata_ring_buffer_ioctl_put_next_subbuf(struct file
*filp
,
700 unsigned int cmd
, unsigned long arg
)
702 struct lttng_metadata_stream
*stream
= filp
->private_data
;
704 stream
->metadata_out
= stream
->metadata_in
;
708 * Reset the counter of how much metadata has been consumed to 0. That way,
709 * the consumer receives the content of the metadata cache unchanged. This is
710 * different from the metadata_regenerate where the offset from epoch is
711 * resampled, here we want the exact same content as the last time the metadata
712 * was generated. This command is only possible if all the metadata written
713 * in the cache has been output to the metadata stream to avoid corrupting the
716 * Return 0 on success, a negative value on error.
719 int lttng_metadata_cache_dump(struct lttng_metadata_stream
*stream
)
722 struct lttng_metadata_cache
*cache
= stream
->metadata_cache
;
724 mutex_lock(&cache
->lock
);
725 if (stream
->metadata_out
!= cache
->metadata_written
) {
729 stream
->metadata_out
= 0;
730 stream
->metadata_in
= 0;
731 wake_up_interruptible(&stream
->read_wait
);
735 mutex_unlock(&cache
->lock
);
740 long lttng_metadata_ring_buffer_ioctl(struct file
*filp
,
741 unsigned int cmd
, unsigned long arg
)
744 struct lttng_metadata_stream
*stream
= filp
->private_data
;
745 struct lib_ring_buffer
*buf
= stream
->priv
;
748 case RING_BUFFER_GET_NEXT_SUBBUF
:
750 struct lttng_metadata_stream
*stream
= filp
->private_data
;
751 struct lib_ring_buffer
*buf
= stream
->priv
;
752 struct channel
*chan
= buf
->backend
.chan
;
754 ret
= lttng_metadata_output_channel(stream
, chan
);
756 lib_ring_buffer_switch_slow(buf
, SWITCH_ACTIVE
);
762 case RING_BUFFER_GET_SUBBUF
:
765 * Random access is not allowed for metadata channel.
769 case RING_BUFFER_FLUSH_EMPTY
: /* Fall-through. */
770 case RING_BUFFER_FLUSH
:
772 struct lttng_metadata_stream
*stream
= filp
->private_data
;
773 struct lib_ring_buffer
*buf
= stream
->priv
;
774 struct channel
*chan
= buf
->backend
.chan
;
777 * Before doing the actual ring buffer flush, write up to one
778 * packet of metadata in the ring buffer.
780 ret
= lttng_metadata_output_channel(stream
, chan
);
785 case RING_BUFFER_GET_METADATA_VERSION
:
787 struct lttng_metadata_stream
*stream
= filp
->private_data
;
789 return put_u64(stream
->version
, arg
);
791 case RING_BUFFER_METADATA_CACHE_DUMP
:
793 struct lttng_metadata_stream
*stream
= filp
->private_data
;
795 return lttng_metadata_cache_dump(stream
);
800 /* PUT_SUBBUF is the one from lib ring buffer, unmodified. */
802 /* Performing lib ring buffer ioctl after our own. */
803 ret
= lib_ring_buffer_ioctl(filp
, cmd
, arg
, buf
);
808 case RING_BUFFER_PUT_NEXT_SUBBUF
:
810 lttng_metadata_ring_buffer_ioctl_put_next_subbuf(filp
,
823 long lttng_metadata_ring_buffer_compat_ioctl(struct file
*filp
,
824 unsigned int cmd
, unsigned long arg
)
827 struct lttng_metadata_stream
*stream
= filp
->private_data
;
828 struct lib_ring_buffer
*buf
= stream
->priv
;
831 case RING_BUFFER_GET_NEXT_SUBBUF
:
833 struct lttng_metadata_stream
*stream
= filp
->private_data
;
834 struct lib_ring_buffer
*buf
= stream
->priv
;
835 struct channel
*chan
= buf
->backend
.chan
;
837 ret
= lttng_metadata_output_channel(stream
, chan
);
839 lib_ring_buffer_switch_slow(buf
, SWITCH_ACTIVE
);
845 case RING_BUFFER_GET_SUBBUF
:
848 * Random access is not allowed for metadata channel.
852 case RING_BUFFER_FLUSH_EMPTY
: /* Fall-through. */
853 case RING_BUFFER_FLUSH
:
855 struct lttng_metadata_stream
*stream
= filp
->private_data
;
856 struct lib_ring_buffer
*buf
= stream
->priv
;
857 struct channel
*chan
= buf
->backend
.chan
;
860 * Before doing the actual ring buffer flush, write up to one
861 * packet of metadata in the ring buffer.
863 ret
= lttng_metadata_output_channel(stream
, chan
);
868 case RING_BUFFER_GET_METADATA_VERSION
:
870 struct lttng_metadata_stream
*stream
= filp
->private_data
;
872 return put_u64(stream
->version
, arg
);
874 case RING_BUFFER_METADATA_CACHE_DUMP
:
876 struct lttng_metadata_stream
*stream
= filp
->private_data
;
878 return lttng_metadata_cache_dump(stream
);
883 /* PUT_SUBBUF is the one from lib ring buffer, unmodified. */
885 /* Performing lib ring buffer ioctl after our own. */
886 ret
= lib_ring_buffer_compat_ioctl(filp
, cmd
, arg
, buf
);
891 case RING_BUFFER_PUT_NEXT_SUBBUF
:
893 lttng_metadata_ring_buffer_ioctl_put_next_subbuf(filp
,
906 * This is not used by anonymous file descriptors. This code is left
907 * there if we ever want to implement an inode with open() operation.
910 int lttng_metadata_ring_buffer_open(struct inode
*inode
, struct file
*file
)
912 struct lttng_metadata_stream
*stream
= inode
->i_private
;
913 struct lib_ring_buffer
*buf
= stream
->priv
;
915 file
->private_data
= buf
;
917 * Since life-time of metadata cache differs from that of
918 * session, we need to keep our own reference on the transport.
920 if (!try_module_get(stream
->transport
->owner
)) {
921 printk(KERN_WARNING
"LTT : Can't lock transport module.\n");
924 return lib_ring_buffer_open(inode
, file
, buf
);
928 int lttng_metadata_ring_buffer_release(struct inode
*inode
, struct file
*file
)
930 struct lttng_metadata_stream
*stream
= file
->private_data
;
931 struct lib_ring_buffer
*buf
= stream
->priv
;
933 kref_put(&stream
->metadata_cache
->refcount
, metadata_cache_destroy
);
934 module_put(stream
->transport
->owner
);
935 return lib_ring_buffer_release(inode
, file
, buf
);
939 ssize_t
lttng_metadata_ring_buffer_splice_read(struct file
*in
, loff_t
*ppos
,
940 struct pipe_inode_info
*pipe
, size_t len
,
943 struct lttng_metadata_stream
*stream
= in
->private_data
;
944 struct lib_ring_buffer
*buf
= stream
->priv
;
946 return lib_ring_buffer_splice_read(in
, ppos
, pipe
, len
,
951 int lttng_metadata_ring_buffer_mmap(struct file
*filp
,
952 struct vm_area_struct
*vma
)
954 struct lttng_metadata_stream
*stream
= filp
->private_data
;
955 struct lib_ring_buffer
*buf
= stream
->priv
;
957 return lib_ring_buffer_mmap(filp
, vma
, buf
);
961 const struct file_operations lttng_metadata_ring_buffer_file_operations
= {
962 .owner
= THIS_MODULE
,
963 .open
= lttng_metadata_ring_buffer_open
,
964 .release
= lttng_metadata_ring_buffer_release
,
965 .poll
= lttng_metadata_ring_buffer_poll
,
966 .splice_read
= lttng_metadata_ring_buffer_splice_read
,
967 .mmap
= lttng_metadata_ring_buffer_mmap
,
968 .unlocked_ioctl
= lttng_metadata_ring_buffer_ioctl
,
969 .llseek
= vfs_lib_ring_buffer_no_llseek
,
971 .compat_ioctl
= lttng_metadata_ring_buffer_compat_ioctl
,
976 int lttng_abi_create_stream_fd(struct file
*channel_file
, void *stream_priv
,
977 const struct file_operations
*fops
)
980 struct file
*stream_file
;
982 stream_fd
= lttng_get_unused_fd();
987 stream_file
= anon_inode_getfile("[lttng_stream]", fops
,
988 stream_priv
, O_RDWR
);
989 if (IS_ERR(stream_file
)) {
990 ret
= PTR_ERR(stream_file
);
994 * OPEN_FMODE, called within anon_inode_getfile/alloc_file, don't honor
995 * FMODE_LSEEK, FMODE_PREAD nor FMODE_PWRITE. We need to read from this
996 * file descriptor, so we set FMODE_PREAD here.
998 stream_file
->f_mode
|= FMODE_PREAD
;
999 fd_install(stream_fd
, stream_file
);
1001 * The stream holds a reference to the channel within the generic ring
1002 * buffer library, so no need to hold a refcount on the channel and
1003 * session files here.
1008 put_unused_fd(stream_fd
);
1014 int lttng_abi_open_stream(struct file
*channel_file
)
1016 struct lttng_channel
*channel
= channel_file
->private_data
;
1017 struct lib_ring_buffer
*buf
;
1021 buf
= channel
->ops
->buffer_read_open(channel
->chan
);
1026 ret
= lttng_abi_create_stream_fd(channel_file
, stream_priv
,
1027 <tng_stream_ring_buffer_file_operations
);
1034 channel
->ops
->buffer_read_close(buf
);
1039 int lttng_abi_open_metadata_stream(struct file
*channel_file
)
1041 struct lttng_channel
*channel
= channel_file
->private_data
;
1042 struct lttng_session
*session
= channel
->session
;
1043 struct lib_ring_buffer
*buf
;
1045 struct lttng_metadata_stream
*metadata_stream
;
1048 buf
= channel
->ops
->buffer_read_open(channel
->chan
);
1052 metadata_stream
= kzalloc(sizeof(struct lttng_metadata_stream
),
1054 if (!metadata_stream
) {
1058 metadata_stream
->metadata_cache
= session
->metadata_cache
;
1059 init_waitqueue_head(&metadata_stream
->read_wait
);
1060 metadata_stream
->priv
= buf
;
1061 stream_priv
= metadata_stream
;
1062 metadata_stream
->transport
= channel
->transport
;
1065 * Since life-time of metadata cache differs from that of
1066 * session, we need to keep our own reference on the transport.
1068 if (!try_module_get(metadata_stream
->transport
->owner
)) {
1069 printk(KERN_WARNING
"LTT : Can't lock transport module.\n");
1074 if (!lttng_kref_get(&session
->metadata_cache
->refcount
)) {
1079 ret
= lttng_abi_create_stream_fd(channel_file
, stream_priv
,
1080 <tng_metadata_ring_buffer_file_operations
);
1084 list_add(&metadata_stream
->list
,
1085 &session
->metadata_cache
->metadata_stream
);
1089 kref_put(&session
->metadata_cache
->refcount
, metadata_cache_destroy
);
1091 module_put(metadata_stream
->transport
->owner
);
1093 kfree(metadata_stream
);
1095 channel
->ops
->buffer_read_close(buf
);
1100 int lttng_abi_create_event(struct file
*channel_file
,
1101 struct lttng_kernel_event
*event_param
)
1103 struct lttng_channel
*channel
= channel_file
->private_data
;
1105 struct file
*event_file
;
1108 event_param
->name
[LTTNG_KERNEL_SYM_NAME_LEN
- 1] = '\0';
1109 switch (event_param
->instrumentation
) {
1110 case LTTNG_KERNEL_KRETPROBE
:
1111 event_param
->u
.kretprobe
.symbol_name
[LTTNG_KERNEL_SYM_NAME_LEN
- 1] = '\0';
1113 case LTTNG_KERNEL_KPROBE
:
1114 event_param
->u
.kprobe
.symbol_name
[LTTNG_KERNEL_SYM_NAME_LEN
- 1] = '\0';
1116 case LTTNG_KERNEL_FUNCTION
:
1117 event_param
->u
.ftrace
.symbol_name
[LTTNG_KERNEL_SYM_NAME_LEN
- 1] = '\0';
1122 event_fd
= lttng_get_unused_fd();
1127 event_file
= anon_inode_getfile("[lttng_event]",
1130 if (IS_ERR(event_file
)) {
1131 ret
= PTR_ERR(event_file
);
1134 /* The event holds a reference on the channel */
1135 if (!atomic_long_add_unless(&channel_file
->f_count
, 1, LONG_MAX
)) {
1137 goto refcount_error
;
1139 if (event_param
->instrumentation
== LTTNG_KERNEL_TRACEPOINT
1140 || event_param
->instrumentation
== LTTNG_KERNEL_SYSCALL
) {
1141 struct lttng_enabler
*enabler
;
1143 if (strutils_is_star_glob_pattern(event_param
->name
)) {
1145 * If the event name is a star globbing pattern,
1146 * we create the special star globbing enabler.
1148 enabler
= lttng_enabler_create(LTTNG_ENABLER_STAR_GLOB
,
1149 event_param
, channel
);
1151 enabler
= lttng_enabler_create(LTTNG_ENABLER_NAME
,
1152 event_param
, channel
);
1156 struct lttng_event
*event
;
1159 * We tolerate no failure path after event creation. It
1160 * will stay invariant for the rest of the session.
1162 event
= lttng_event_create(channel
, event_param
,
1164 event_param
->instrumentation
);
1165 WARN_ON_ONCE(!event
);
1166 if (IS_ERR(event
)) {
1167 ret
= PTR_ERR(event
);
1172 event_file
->private_data
= priv
;
1173 fd_install(event_fd
, event_file
);
1177 atomic_long_dec(&channel_file
->f_count
);
1181 put_unused_fd(event_fd
);
1187 * lttng_channel_ioctl - lttng syscall through ioctl
1193 * This ioctl implements lttng commands:
1194 * LTTNG_KERNEL_STREAM
1195 * Returns an event stream file descriptor or failure.
1196 * (typically, one event stream records events from one CPU)
1197 * LTTNG_KERNEL_EVENT
1198 * Returns an event file descriptor or failure.
1199 * LTTNG_KERNEL_CONTEXT
1200 * Prepend a context field to each event in the channel
1201 * LTTNG_KERNEL_ENABLE
1202 * Enable recording for events in this channel (weak enable)
1203 * LTTNG_KERNEL_DISABLE
1204 * Disable recording for events in this channel (strong disable)
1206 * Channel and event file descriptors also hold a reference on the session.
1209 long lttng_channel_ioctl(struct file
*file
, unsigned int cmd
, unsigned long arg
)
1211 struct lttng_channel
*channel
= file
->private_data
;
1214 case LTTNG_KERNEL_OLD_STREAM
:
1215 case LTTNG_KERNEL_STREAM
:
1216 return lttng_abi_open_stream(file
);
1217 case LTTNG_KERNEL_OLD_EVENT
:
1219 struct lttng_kernel_event
*uevent_param
;
1220 struct lttng_kernel_old_event
*old_uevent_param
;
1223 uevent_param
= kmalloc(sizeof(struct lttng_kernel_event
),
1225 if (!uevent_param
) {
1229 old_uevent_param
= kmalloc(
1230 sizeof(struct lttng_kernel_old_event
),
1232 if (!old_uevent_param
) {
1234 goto old_event_error_free_param
;
1236 if (copy_from_user(old_uevent_param
,
1237 (struct lttng_kernel_old_event __user
*) arg
,
1238 sizeof(struct lttng_kernel_old_event
))) {
1240 goto old_event_error_free_old_param
;
1243 memcpy(uevent_param
->name
, old_uevent_param
->name
,
1244 sizeof(uevent_param
->name
));
1245 uevent_param
->instrumentation
=
1246 old_uevent_param
->instrumentation
;
1248 switch (old_uevent_param
->instrumentation
) {
1249 case LTTNG_KERNEL_KPROBE
:
1250 uevent_param
->u
.kprobe
.addr
=
1251 old_uevent_param
->u
.kprobe
.addr
;
1252 uevent_param
->u
.kprobe
.offset
=
1253 old_uevent_param
->u
.kprobe
.offset
;
1254 memcpy(uevent_param
->u
.kprobe
.symbol_name
,
1255 old_uevent_param
->u
.kprobe
.symbol_name
,
1256 sizeof(uevent_param
->u
.kprobe
.symbol_name
));
1258 case LTTNG_KERNEL_KRETPROBE
:
1259 uevent_param
->u
.kretprobe
.addr
=
1260 old_uevent_param
->u
.kretprobe
.addr
;
1261 uevent_param
->u
.kretprobe
.offset
=
1262 old_uevent_param
->u
.kretprobe
.offset
;
1263 memcpy(uevent_param
->u
.kretprobe
.symbol_name
,
1264 old_uevent_param
->u
.kretprobe
.symbol_name
,
1265 sizeof(uevent_param
->u
.kretprobe
.symbol_name
));
1267 case LTTNG_KERNEL_FUNCTION
:
1268 memcpy(uevent_param
->u
.ftrace
.symbol_name
,
1269 old_uevent_param
->u
.ftrace
.symbol_name
,
1270 sizeof(uevent_param
->u
.ftrace
.symbol_name
));
1275 ret
= lttng_abi_create_event(file
, uevent_param
);
1277 old_event_error_free_old_param
:
1278 kfree(old_uevent_param
);
1279 old_event_error_free_param
:
1280 kfree(uevent_param
);
1284 case LTTNG_KERNEL_EVENT
:
1286 struct lttng_kernel_event uevent_param
;
1288 if (copy_from_user(&uevent_param
,
1289 (struct lttng_kernel_event __user
*) arg
,
1290 sizeof(uevent_param
)))
1292 return lttng_abi_create_event(file
, &uevent_param
);
1294 case LTTNG_KERNEL_OLD_CONTEXT
:
1296 struct lttng_kernel_context
*ucontext_param
;
1297 struct lttng_kernel_old_context
*old_ucontext_param
;
1300 ucontext_param
= kmalloc(sizeof(struct lttng_kernel_context
),
1302 if (!ucontext_param
) {
1306 old_ucontext_param
= kmalloc(sizeof(struct lttng_kernel_old_context
),
1308 if (!old_ucontext_param
) {
1310 goto old_ctx_error_free_param
;
1313 if (copy_from_user(old_ucontext_param
,
1314 (struct lttng_kernel_old_context __user
*) arg
,
1315 sizeof(struct lttng_kernel_old_context
))) {
1317 goto old_ctx_error_free_old_param
;
1319 ucontext_param
->ctx
= old_ucontext_param
->ctx
;
1320 memcpy(ucontext_param
->padding
, old_ucontext_param
->padding
,
1321 sizeof(ucontext_param
->padding
));
1322 /* only type that uses the union */
1323 if (old_ucontext_param
->ctx
== LTTNG_KERNEL_CONTEXT_PERF_COUNTER
) {
1324 ucontext_param
->u
.perf_counter
.type
=
1325 old_ucontext_param
->u
.perf_counter
.type
;
1326 ucontext_param
->u
.perf_counter
.config
=
1327 old_ucontext_param
->u
.perf_counter
.config
;
1328 memcpy(ucontext_param
->u
.perf_counter
.name
,
1329 old_ucontext_param
->u
.perf_counter
.name
,
1330 sizeof(ucontext_param
->u
.perf_counter
.name
));
1333 ret
= lttng_abi_add_context(file
,
1335 &channel
->ctx
, channel
->session
);
1337 old_ctx_error_free_old_param
:
1338 kfree(old_ucontext_param
);
1339 old_ctx_error_free_param
:
1340 kfree(ucontext_param
);
1344 case LTTNG_KERNEL_CONTEXT
:
1346 struct lttng_kernel_context ucontext_param
;
1348 if (copy_from_user(&ucontext_param
,
1349 (struct lttng_kernel_context __user
*) arg
,
1350 sizeof(ucontext_param
)))
1352 return lttng_abi_add_context(file
,
1354 &channel
->ctx
, channel
->session
);
1356 case LTTNG_KERNEL_OLD_ENABLE
:
1357 case LTTNG_KERNEL_ENABLE
:
1358 return lttng_channel_enable(channel
);
1359 case LTTNG_KERNEL_OLD_DISABLE
:
1360 case LTTNG_KERNEL_DISABLE
:
1361 return lttng_channel_disable(channel
);
1362 case LTTNG_KERNEL_SYSCALL_MASK
:
1363 return lttng_channel_syscall_mask(channel
,
1364 (struct lttng_kernel_syscall_mask __user
*) arg
);
1366 return -ENOIOCTLCMD
;
1371 * lttng_metadata_ioctl - lttng syscall through ioctl
1377 * This ioctl implements lttng commands:
1378 * LTTNG_KERNEL_STREAM
1379 * Returns an event stream file descriptor or failure.
1381 * Channel and event file descriptors also hold a reference on the session.
1384 long lttng_metadata_ioctl(struct file
*file
, unsigned int cmd
, unsigned long arg
)
1387 case LTTNG_KERNEL_OLD_STREAM
:
1388 case LTTNG_KERNEL_STREAM
:
1389 return lttng_abi_open_metadata_stream(file
);
1391 return -ENOIOCTLCMD
;
1396 * lttng_channel_poll - lttng stream addition/removal monitoring
1401 unsigned int lttng_channel_poll(struct file
*file
, poll_table
*wait
)
1403 struct lttng_channel
*channel
= file
->private_data
;
1404 unsigned int mask
= 0;
1406 if (file
->f_mode
& FMODE_READ
) {
1407 poll_wait_set_exclusive(wait
);
1408 poll_wait(file
, channel
->ops
->get_hp_wait_queue(channel
->chan
),
1411 if (channel
->ops
->is_disabled(channel
->chan
))
1413 if (channel
->ops
->is_finalized(channel
->chan
))
1415 if (channel
->ops
->buffer_has_read_closed_stream(channel
->chan
))
1416 return POLLIN
| POLLRDNORM
;
1424 int lttng_channel_release(struct inode
*inode
, struct file
*file
)
1426 struct lttng_channel
*channel
= file
->private_data
;
1429 fput(channel
->session
->file
);
1434 int lttng_metadata_channel_release(struct inode
*inode
, struct file
*file
)
1436 struct lttng_channel
*channel
= file
->private_data
;
1439 fput(channel
->session
->file
);
1440 lttng_metadata_channel_destroy(channel
);
1446 static const struct file_operations lttng_channel_fops
= {
1447 .owner
= THIS_MODULE
,
1448 .release
= lttng_channel_release
,
1449 .poll
= lttng_channel_poll
,
1450 .unlocked_ioctl
= lttng_channel_ioctl
,
1451 #ifdef CONFIG_COMPAT
1452 .compat_ioctl
= lttng_channel_ioctl
,
1456 static const struct file_operations lttng_metadata_fops
= {
1457 .owner
= THIS_MODULE
,
1458 .release
= lttng_metadata_channel_release
,
1459 .unlocked_ioctl
= lttng_metadata_ioctl
,
1460 #ifdef CONFIG_COMPAT
1461 .compat_ioctl
= lttng_metadata_ioctl
,
1466 * lttng_event_ioctl - lttng syscall through ioctl
1472 * This ioctl implements lttng commands:
1473 * LTTNG_KERNEL_CONTEXT
1474 * Prepend a context field to each record of this event
1475 * LTTNG_KERNEL_ENABLE
1476 * Enable recording for this event (weak enable)
1477 * LTTNG_KERNEL_DISABLE
1478 * Disable recording for this event (strong disable)
1481 long lttng_event_ioctl(struct file
*file
, unsigned int cmd
, unsigned long arg
)
1483 struct lttng_event
*event
;
1484 struct lttng_enabler
*enabler
;
1485 enum lttng_event_type
*evtype
= file
->private_data
;
1488 case LTTNG_KERNEL_OLD_CONTEXT
:
1490 /* Not implemented */
1493 case LTTNG_KERNEL_CONTEXT
:
1495 /* Not implemented */
1498 case LTTNG_KERNEL_OLD_ENABLE
:
1499 case LTTNG_KERNEL_ENABLE
:
1501 case LTTNG_TYPE_EVENT
:
1502 event
= file
->private_data
;
1503 return lttng_event_enable(event
);
1504 case LTTNG_TYPE_ENABLER
:
1505 enabler
= file
->private_data
;
1506 return lttng_enabler_enable(enabler
);
1511 case LTTNG_KERNEL_OLD_DISABLE
:
1512 case LTTNG_KERNEL_DISABLE
:
1514 case LTTNG_TYPE_EVENT
:
1515 event
= file
->private_data
;
1516 return lttng_event_disable(event
);
1517 case LTTNG_TYPE_ENABLER
:
1518 enabler
= file
->private_data
;
1519 return lttng_enabler_disable(enabler
);
1524 case LTTNG_KERNEL_FILTER
:
1526 case LTTNG_TYPE_EVENT
:
1528 case LTTNG_TYPE_ENABLER
:
1530 enabler
= file
->private_data
;
1531 return lttng_enabler_attach_bytecode(enabler
,
1532 (struct lttng_kernel_filter_bytecode __user
*) arg
);
1538 case LTTNG_KERNEL_ADD_CALLSITE
:
1540 case LTTNG_TYPE_EVENT
:
1541 event
= file
->private_data
;
1542 return lttng_event_add_callsite(event
,
1543 (struct lttng_kernel_event_callsite __user
*) arg
);
1544 case LTTNG_TYPE_ENABLER
:
1548 return -ENOIOCTLCMD
;
1553 int lttng_event_release(struct inode
*inode
, struct file
*file
)
1555 struct lttng_event
*event
;
1556 struct lttng_enabler
*enabler
;
1557 enum lttng_event_type
*evtype
= file
->private_data
;
1563 case LTTNG_TYPE_EVENT
:
1564 event
= file
->private_data
;
1566 fput(event
->chan
->file
);
1568 case LTTNG_TYPE_ENABLER
:
1569 enabler
= file
->private_data
;
1571 fput(enabler
->chan
->file
);
1581 /* TODO: filter control ioctl */
1582 static const struct file_operations lttng_event_fops
= {
1583 .owner
= THIS_MODULE
,
1584 .release
= lttng_event_release
,
1585 .unlocked_ioctl
= lttng_event_ioctl
,
1586 #ifdef CONFIG_COMPAT
1587 .compat_ioctl
= lttng_event_ioctl
,
1591 static int put_u64(uint64_t val
, unsigned long arg
)
1593 return put_user(val
, (uint64_t __user
*) arg
);
1596 static long lttng_stream_ring_buffer_ioctl(struct file
*filp
,
1597 unsigned int cmd
, unsigned long arg
)
1599 struct lib_ring_buffer
*buf
= filp
->private_data
;
1600 struct channel
*chan
= buf
->backend
.chan
;
1601 const struct lib_ring_buffer_config
*config
= &chan
->backend
.config
;
1602 const struct lttng_channel_ops
*ops
= chan
->backend
.priv_ops
;
1605 if (atomic_read(&chan
->record_disabled
))
1609 case LTTNG_RING_BUFFER_GET_TIMESTAMP_BEGIN
:
1613 ret
= ops
->timestamp_begin(config
, buf
, &ts
);
1616 return put_u64(ts
, arg
);
1618 case LTTNG_RING_BUFFER_GET_TIMESTAMP_END
:
1622 ret
= ops
->timestamp_end(config
, buf
, &ts
);
1625 return put_u64(ts
, arg
);
1627 case LTTNG_RING_BUFFER_GET_EVENTS_DISCARDED
:
1631 ret
= ops
->events_discarded(config
, buf
, &ed
);
1634 return put_u64(ed
, arg
);
1636 case LTTNG_RING_BUFFER_GET_CONTENT_SIZE
:
1640 ret
= ops
->content_size(config
, buf
, &cs
);
1643 return put_u64(cs
, arg
);
1645 case LTTNG_RING_BUFFER_GET_PACKET_SIZE
:
1649 ret
= ops
->packet_size(config
, buf
, &ps
);
1652 return put_u64(ps
, arg
);
1654 case LTTNG_RING_BUFFER_GET_STREAM_ID
:
1658 ret
= ops
->stream_id(config
, buf
, &si
);
1661 return put_u64(si
, arg
);
1663 case LTTNG_RING_BUFFER_GET_CURRENT_TIMESTAMP
:
1667 ret
= ops
->current_timestamp(config
, buf
, &ts
);
1670 return put_u64(ts
, arg
);
1672 case LTTNG_RING_BUFFER_GET_SEQ_NUM
:
1676 ret
= ops
->sequence_number(config
, buf
, &seq
);
1679 return put_u64(seq
, arg
);
1681 case LTTNG_RING_BUFFER_INSTANCE_ID
:
1685 ret
= ops
->instance_id(config
, buf
, &id
);
1688 return put_u64(id
, arg
);
1691 return lib_ring_buffer_file_operations
.unlocked_ioctl(filp
,
1699 #ifdef CONFIG_COMPAT
1700 static long lttng_stream_ring_buffer_compat_ioctl(struct file
*filp
,
1701 unsigned int cmd
, unsigned long arg
)
1703 struct lib_ring_buffer
*buf
= filp
->private_data
;
1704 struct channel
*chan
= buf
->backend
.chan
;
1705 const struct lib_ring_buffer_config
*config
= &chan
->backend
.config
;
1706 const struct lttng_channel_ops
*ops
= chan
->backend
.priv_ops
;
1709 if (atomic_read(&chan
->record_disabled
))
1713 case LTTNG_RING_BUFFER_COMPAT_GET_TIMESTAMP_BEGIN
:
1717 ret
= ops
->timestamp_begin(config
, buf
, &ts
);
1720 return put_u64(ts
, arg
);
1722 case LTTNG_RING_BUFFER_COMPAT_GET_TIMESTAMP_END
:
1726 ret
= ops
->timestamp_end(config
, buf
, &ts
);
1729 return put_u64(ts
, arg
);
1731 case LTTNG_RING_BUFFER_COMPAT_GET_EVENTS_DISCARDED
:
1735 ret
= ops
->events_discarded(config
, buf
, &ed
);
1738 return put_u64(ed
, arg
);
1740 case LTTNG_RING_BUFFER_COMPAT_GET_CONTENT_SIZE
:
1744 ret
= ops
->content_size(config
, buf
, &cs
);
1747 return put_u64(cs
, arg
);
1749 case LTTNG_RING_BUFFER_COMPAT_GET_PACKET_SIZE
:
1753 ret
= ops
->packet_size(config
, buf
, &ps
);
1756 return put_u64(ps
, arg
);
1758 case LTTNG_RING_BUFFER_COMPAT_GET_STREAM_ID
:
1762 ret
= ops
->stream_id(config
, buf
, &si
);
1765 return put_u64(si
, arg
);
1767 case LTTNG_RING_BUFFER_GET_CURRENT_TIMESTAMP
:
1771 ret
= ops
->current_timestamp(config
, buf
, &ts
);
1774 return put_u64(ts
, arg
);
1776 case LTTNG_RING_BUFFER_COMPAT_GET_SEQ_NUM
:
1780 ret
= ops
->sequence_number(config
, buf
, &seq
);
1783 return put_u64(seq
, arg
);
1785 case LTTNG_RING_BUFFER_COMPAT_INSTANCE_ID
:
1789 ret
= ops
->instance_id(config
, buf
, &id
);
1792 return put_u64(id
, arg
);
1795 return lib_ring_buffer_file_operations
.compat_ioctl(filp
,
1802 #endif /* CONFIG_COMPAT */
1804 static void lttng_stream_override_ring_buffer_fops(void)
1806 lttng_stream_ring_buffer_file_operations
.owner
= THIS_MODULE
;
1807 lttng_stream_ring_buffer_file_operations
.open
=
1808 lib_ring_buffer_file_operations
.open
;
1809 lttng_stream_ring_buffer_file_operations
.release
=
1810 lib_ring_buffer_file_operations
.release
;
1811 lttng_stream_ring_buffer_file_operations
.poll
=
1812 lib_ring_buffer_file_operations
.poll
;
1813 lttng_stream_ring_buffer_file_operations
.splice_read
=
1814 lib_ring_buffer_file_operations
.splice_read
;
1815 lttng_stream_ring_buffer_file_operations
.mmap
=
1816 lib_ring_buffer_file_operations
.mmap
;
1817 lttng_stream_ring_buffer_file_operations
.unlocked_ioctl
=
1818 lttng_stream_ring_buffer_ioctl
;
1819 lttng_stream_ring_buffer_file_operations
.llseek
=
1820 lib_ring_buffer_file_operations
.llseek
;
1821 #ifdef CONFIG_COMPAT
1822 lttng_stream_ring_buffer_file_operations
.compat_ioctl
=
1823 lttng_stream_ring_buffer_compat_ioctl
;
1827 int __init
lttng_abi_init(void)
1831 wrapper_vmalloc_sync_all();
1834 ret
= lttng_tp_mempool_init();
1839 lttng_proc_dentry
= proc_create_data("lttng", S_IRUSR
| S_IWUSR
, NULL
,
1842 if (!lttng_proc_dentry
) {
1843 printk(KERN_ERR
"Error creating LTTng control file\n");
1847 lttng_stream_override_ring_buffer_fops();
1851 lttng_tp_mempool_destroy();
1852 lttng_clock_unref();
1856 /* No __exit annotation because used by init error path too. */
1857 void lttng_abi_exit(void)
1859 lttng_tp_mempool_destroy();
1860 lttng_clock_unref();
1861 if (lttng_proc_dentry
)
1862 remove_proc_entry("lttng", NULL
);