6 * Copyright (C) 2010-2012 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; only
11 * version 2.1 of the License.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23 * Mimic system calls for:
24 * - session creation, returns a file descriptor or failure.
25 * - channel creation, returns a file descriptor or failure.
26 * - Operates on a session file descriptor
27 * - Takes all channel options as parameters.
28 * - stream get, returns a file descriptor or failure.
29 * - Operates on a channel file descriptor.
30 * - stream notifier get, returns a file descriptor or failure.
31 * - Operates on a channel file descriptor.
32 * - event creation, returns a file descriptor or failure.
33 * - Operates on a channel file descriptor
34 * - Takes an event name as parameter
35 * - Takes an instrumentation source as parameter
36 * - e.g. tracepoints, dynamic_probes...
37 * - Takes instrumentation source specific arguments.
40 #include <linux/module.h>
41 #include <linux/proc_fs.h>
42 #include <linux/anon_inodes.h>
43 #include <linux/file.h>
44 #include <linux/uaccess.h>
45 #include <linux/slab.h>
46 #include <linux/err.h>
47 #include <wrapper/vmalloc.h> /* for wrapper_vmalloc_sync_all() */
48 #include <wrapper/ringbuffer/vfs.h>
49 #include <wrapper/ringbuffer/backend.h>
50 #include <wrapper/ringbuffer/frontend.h>
51 #include <wrapper/poll.h>
52 #include <wrapper/file.h>
53 #include <wrapper/kref.h>
54 #include <lttng-abi.h>
55 #include <lttng-abi-old.h>
56 #include <lttng-events.h>
57 #include <lttng-tracer.h>
58 #include <lttng-tp-mempool.h>
59 #include <lib/ringbuffer/frontend_types.h>
62 * This is LTTng's own personal way to create a system call as an external
63 * module. We use ioctl() on /proc/lttng.
66 static struct proc_dir_entry
*lttng_proc_dentry
;
67 static const struct file_operations lttng_fops
;
68 static const struct file_operations lttng_session_fops
;
69 static const struct file_operations lttng_channel_fops
;
70 static const struct file_operations lttng_metadata_fops
;
71 static const struct file_operations lttng_event_fops
;
72 static struct file_operations lttng_stream_ring_buffer_file_operations
;
74 static int put_u64(uint64_t val
, unsigned long arg
);
77 * Teardown management: opened file descriptors keep a refcount on the module,
78 * so it can only exit when all file descriptors are closed.
82 int lttng_abi_create_session(void)
84 struct lttng_session
*session
;
85 struct file
*session_file
;
88 session
= lttng_session_create();
91 session_fd
= lttng_get_unused_fd();
96 session_file
= anon_inode_getfile("[lttng_session]",
99 if (IS_ERR(session_file
)) {
100 ret
= PTR_ERR(session_file
);
103 session
->file
= session_file
;
104 fd_install(session_fd
, session_file
);
108 put_unused_fd(session_fd
);
110 lttng_session_destroy(session
);
115 int lttng_abi_tracepoint_list(void)
117 struct file
*tracepoint_list_file
;
120 file_fd
= lttng_get_unused_fd();
126 tracepoint_list_file
= anon_inode_getfile("[lttng_tracepoint_list]",
127 <tng_tracepoint_list_fops
,
129 if (IS_ERR(tracepoint_list_file
)) {
130 ret
= PTR_ERR(tracepoint_list_file
);
133 ret
= lttng_tracepoint_list_fops
.open(NULL
, tracepoint_list_file
);
136 fd_install(file_fd
, tracepoint_list_file
);
140 fput(tracepoint_list_file
);
142 put_unused_fd(file_fd
);
147 #ifndef CONFIG_HAVE_SYSCALL_TRACEPOINTS
149 int lttng_abi_syscall_list(void)
155 int lttng_abi_syscall_list(void)
157 struct file
*syscall_list_file
;
160 file_fd
= lttng_get_unused_fd();
166 syscall_list_file
= anon_inode_getfile("[lttng_syscall_list]",
167 <tng_syscall_list_fops
,
169 if (IS_ERR(syscall_list_file
)) {
170 ret
= PTR_ERR(syscall_list_file
);
173 ret
= lttng_syscall_list_fops
.open(NULL
, syscall_list_file
);
176 fd_install(file_fd
, syscall_list_file
);
180 fput(syscall_list_file
);
182 put_unused_fd(file_fd
);
189 void lttng_abi_tracer_version(struct lttng_kernel_tracer_version
*v
)
191 v
->major
= LTTNG_MODULES_MAJOR_VERSION
;
192 v
->minor
= LTTNG_MODULES_MINOR_VERSION
;
193 v
->patchlevel
= LTTNG_MODULES_PATCHLEVEL_VERSION
;
197 void lttng_abi_tracer_abi_version(struct lttng_kernel_tracer_abi_version
*v
)
199 v
->major
= LTTNG_MODULES_ABI_MAJOR_VERSION
;
200 v
->minor
= LTTNG_MODULES_ABI_MINOR_VERSION
;
204 long lttng_abi_add_context(struct file
*file
,
205 struct lttng_kernel_context
*context_param
,
206 struct lttng_ctx
**ctx
, struct lttng_session
*session
)
209 if (session
->been_active
)
212 switch (context_param
->ctx
) {
213 case LTTNG_KERNEL_CONTEXT_PID
:
214 return lttng_add_pid_to_ctx(ctx
);
215 case LTTNG_KERNEL_CONTEXT_PRIO
:
216 return lttng_add_prio_to_ctx(ctx
);
217 case LTTNG_KERNEL_CONTEXT_NICE
:
218 return lttng_add_nice_to_ctx(ctx
);
219 case LTTNG_KERNEL_CONTEXT_VPID
:
220 return lttng_add_vpid_to_ctx(ctx
);
221 case LTTNG_KERNEL_CONTEXT_TID
:
222 return lttng_add_tid_to_ctx(ctx
);
223 case LTTNG_KERNEL_CONTEXT_VTID
:
224 return lttng_add_vtid_to_ctx(ctx
);
225 case LTTNG_KERNEL_CONTEXT_PPID
:
226 return lttng_add_ppid_to_ctx(ctx
);
227 case LTTNG_KERNEL_CONTEXT_VPPID
:
228 return lttng_add_vppid_to_ctx(ctx
);
229 case LTTNG_KERNEL_CONTEXT_PERF_COUNTER
:
230 context_param
->u
.perf_counter
.name
[LTTNG_KERNEL_SYM_NAME_LEN
- 1] = '\0';
231 return lttng_add_perf_counter_to_ctx(context_param
->u
.perf_counter
.type
,
232 context_param
->u
.perf_counter
.config
,
233 context_param
->u
.perf_counter
.name
,
235 case LTTNG_KERNEL_CONTEXT_PROCNAME
:
236 return lttng_add_procname_to_ctx(ctx
);
237 case LTTNG_KERNEL_CONTEXT_HOSTNAME
:
238 return lttng_add_hostname_to_ctx(ctx
);
239 case LTTNG_KERNEL_CONTEXT_CPU_ID
:
240 return lttng_add_cpu_id_to_ctx(ctx
);
241 case LTTNG_KERNEL_CONTEXT_INTERRUPTIBLE
:
242 return lttng_add_interruptible_to_ctx(ctx
);
243 case LTTNG_KERNEL_CONTEXT_NEED_RESCHEDULE
:
244 return lttng_add_need_reschedule_to_ctx(ctx
);
245 case LTTNG_KERNEL_CONTEXT_PREEMPTIBLE
:
246 return lttng_add_preemptible_to_ctx(ctx
);
247 case LTTNG_KERNEL_CONTEXT_MIGRATABLE
:
248 return lttng_add_migratable_to_ctx(ctx
);
255 * lttng_ioctl - lttng syscall through ioctl
261 * This ioctl implements lttng commands:
262 * LTTNG_KERNEL_SESSION
263 * Returns a LTTng trace session file descriptor
264 * LTTNG_KERNEL_TRACER_VERSION
265 * Returns the LTTng kernel tracer version
266 * LTTNG_KERNEL_TRACEPOINT_LIST
267 * Returns a file descriptor listing available tracepoints
268 * LTTNG_KERNEL_WAIT_QUIESCENT
269 * Returns after all previously running probes have completed
270 * LTTNG_KERNEL_TRACER_ABI_VERSION
271 * Returns the LTTng kernel tracer ABI version
273 * The returned session will be deleted when its file descriptor is closed.
276 long lttng_ioctl(struct file
*file
, unsigned int cmd
, unsigned long arg
)
279 case LTTNG_KERNEL_OLD_SESSION
:
280 case LTTNG_KERNEL_SESSION
:
281 return lttng_abi_create_session();
282 case LTTNG_KERNEL_OLD_TRACER_VERSION
:
284 struct lttng_kernel_tracer_version v
;
285 struct lttng_kernel_old_tracer_version oldv
;
286 struct lttng_kernel_old_tracer_version
*uversion
=
287 (struct lttng_kernel_old_tracer_version __user
*) arg
;
289 lttng_abi_tracer_version(&v
);
290 oldv
.major
= v
.major
;
291 oldv
.minor
= v
.minor
;
292 oldv
.patchlevel
= v
.patchlevel
;
294 if (copy_to_user(uversion
, &oldv
, sizeof(oldv
)))
298 case LTTNG_KERNEL_TRACER_VERSION
:
300 struct lttng_kernel_tracer_version version
;
301 struct lttng_kernel_tracer_version
*uversion
=
302 (struct lttng_kernel_tracer_version __user
*) arg
;
304 lttng_abi_tracer_version(&version
);
306 if (copy_to_user(uversion
, &version
, sizeof(version
)))
310 case LTTNG_KERNEL_TRACER_ABI_VERSION
:
312 struct lttng_kernel_tracer_abi_version version
;
313 struct lttng_kernel_tracer_abi_version
*uversion
=
314 (struct lttng_kernel_tracer_abi_version __user
*) arg
;
316 lttng_abi_tracer_abi_version(&version
);
318 if (copy_to_user(uversion
, &version
, sizeof(version
)))
322 case LTTNG_KERNEL_OLD_TRACEPOINT_LIST
:
323 case LTTNG_KERNEL_TRACEPOINT_LIST
:
324 return lttng_abi_tracepoint_list();
325 case LTTNG_KERNEL_SYSCALL_LIST
:
326 return lttng_abi_syscall_list();
327 case LTTNG_KERNEL_OLD_WAIT_QUIESCENT
:
328 case LTTNG_KERNEL_WAIT_QUIESCENT
:
331 case LTTNG_KERNEL_OLD_CALIBRATE
:
333 struct lttng_kernel_old_calibrate __user
*ucalibrate
=
334 (struct lttng_kernel_old_calibrate __user
*) arg
;
335 struct lttng_kernel_old_calibrate old_calibrate
;
336 struct lttng_kernel_calibrate calibrate
;
339 if (copy_from_user(&old_calibrate
, ucalibrate
, sizeof(old_calibrate
)))
341 calibrate
.type
= old_calibrate
.type
;
342 ret
= lttng_calibrate(&calibrate
);
343 if (copy_to_user(ucalibrate
, &old_calibrate
, sizeof(old_calibrate
)))
347 case LTTNG_KERNEL_CALIBRATE
:
349 struct lttng_kernel_calibrate __user
*ucalibrate
=
350 (struct lttng_kernel_calibrate __user
*) arg
;
351 struct lttng_kernel_calibrate calibrate
;
354 if (copy_from_user(&calibrate
, ucalibrate
, sizeof(calibrate
)))
356 ret
= lttng_calibrate(&calibrate
);
357 if (copy_to_user(ucalibrate
, &calibrate
, sizeof(calibrate
)))
366 static const struct file_operations lttng_fops
= {
367 .owner
= THIS_MODULE
,
368 .unlocked_ioctl
= lttng_ioctl
,
370 .compat_ioctl
= lttng_ioctl
,
375 int lttng_abi_create_channel(struct file
*session_file
,
376 struct lttng_kernel_channel
*chan_param
,
377 enum channel_type channel_type
)
379 struct lttng_session
*session
= session_file
->private_data
;
380 const struct file_operations
*fops
= NULL
;
381 const char *transport_name
;
382 struct lttng_channel
*chan
;
383 struct file
*chan_file
;
387 chan_fd
= lttng_get_unused_fd();
392 switch (channel_type
) {
393 case PER_CPU_CHANNEL
:
394 fops
= <tng_channel_fops
;
396 case METADATA_CHANNEL
:
397 fops
= <tng_metadata_fops
;
401 chan_file
= anon_inode_getfile("[lttng_channel]",
404 if (IS_ERR(chan_file
)) {
405 ret
= PTR_ERR(chan_file
);
408 switch (channel_type
) {
409 case PER_CPU_CHANNEL
:
410 if (chan_param
->output
== LTTNG_KERNEL_SPLICE
) {
411 transport_name
= chan_param
->overwrite
?
412 "relay-overwrite" : "relay-discard";
413 } else if (chan_param
->output
== LTTNG_KERNEL_MMAP
) {
414 transport_name
= chan_param
->overwrite
?
415 "relay-overwrite-mmap" : "relay-discard-mmap";
420 case METADATA_CHANNEL
:
421 if (chan_param
->output
== LTTNG_KERNEL_SPLICE
)
422 transport_name
= "relay-metadata";
423 else if (chan_param
->output
== LTTNG_KERNEL_MMAP
)
424 transport_name
= "relay-metadata-mmap";
429 transport_name
= "<unknown>";
432 if (atomic_long_add_unless(&session_file
->f_count
,
433 1, INT_MAX
) == INT_MAX
) {
437 * We tolerate no failure path after channel creation. It will stay
438 * invariant for the rest of the session.
440 chan
= lttng_channel_create(session
, transport_name
, NULL
,
441 chan_param
->subbuf_size
,
442 chan_param
->num_subbuf
,
443 chan_param
->switch_timer_interval
,
444 chan_param
->read_timer_interval
,
450 chan
->file
= chan_file
;
451 chan_file
->private_data
= chan
;
452 fd_install(chan_fd
, chan_file
);
457 atomic_long_dec(&session_file
->f_count
);
461 put_unused_fd(chan_fd
);
467 enum tracker_type
get_tracker_type(struct lttng_kernel_tracker_args
*tracker
)
469 switch (tracker
->type
) {
470 case LTTNG_KERNEL_TRACKER_PID
:
472 case LTTNG_KERNEL_TRACKER_VPID
:
474 case LTTNG_KERNEL_TRACKER_UID
:
476 case LTTNG_KERNEL_TRACKER_VUID
:
478 case LTTNG_KERNEL_TRACKER_GID
:
480 case LTTNG_KERNEL_TRACKER_VGID
:
483 return TRACKER_UNKNOWN
;
488 * lttng_session_ioctl - lttng session fd ioctl
494 * This ioctl implements lttng commands:
495 * LTTNG_KERNEL_CHANNEL
496 * Returns a LTTng channel file descriptor
497 * LTTNG_KERNEL_ENABLE
498 * Enables tracing for a session (weak enable)
499 * LTTNG_KERNEL_DISABLE
500 * Disables tracing for a session (strong disable)
501 * LTTNG_KERNEL_METADATA
502 * Returns a LTTng metadata file descriptor
503 * LTTNG_KERNEL_SESSION_TRACK_PID
504 * Add PID to session PID tracker
505 * LTTNG_KERNEL_SESSION_UNTRACK_PID
506 * Remove PID from session PID tracker
507 * LTTNG_KERNEL_SESSION_TRACK_ID
509 * LTTNG_KERNEL_SESSION_UNTRACK_ID
510 * Remove ID from tracker
512 * The returned channel will be deleted when its file descriptor is closed.
515 long lttng_session_ioctl(struct file
*file
, unsigned int cmd
, unsigned long arg
)
517 struct lttng_session
*session
= file
->private_data
;
520 case LTTNG_KERNEL_OLD_CHANNEL
:
522 struct lttng_kernel_channel chan_param
;
523 struct lttng_kernel_old_channel old_chan_param
;
525 if (copy_from_user(&old_chan_param
,
526 (struct lttng_kernel_old_channel __user
*) arg
,
527 sizeof(struct lttng_kernel_old_channel
)))
529 chan_param
.overwrite
= old_chan_param
.overwrite
;
530 chan_param
.subbuf_size
= old_chan_param
.subbuf_size
;
531 chan_param
.num_subbuf
= old_chan_param
.num_subbuf
;
532 chan_param
.switch_timer_interval
= old_chan_param
.switch_timer_interval
;
533 chan_param
.read_timer_interval
= old_chan_param
.read_timer_interval
;
534 chan_param
.output
= old_chan_param
.output
;
536 return lttng_abi_create_channel(file
, &chan_param
,
539 case LTTNG_KERNEL_CHANNEL
:
541 struct lttng_kernel_channel chan_param
;
543 if (copy_from_user(&chan_param
,
544 (struct lttng_kernel_channel __user
*) arg
,
545 sizeof(struct lttng_kernel_channel
)))
547 return lttng_abi_create_channel(file
, &chan_param
,
550 case LTTNG_KERNEL_OLD_SESSION_START
:
551 case LTTNG_KERNEL_OLD_ENABLE
:
552 case LTTNG_KERNEL_SESSION_START
:
553 case LTTNG_KERNEL_ENABLE
:
554 return lttng_session_enable(session
);
555 case LTTNG_KERNEL_OLD_SESSION_STOP
:
556 case LTTNG_KERNEL_OLD_DISABLE
:
557 case LTTNG_KERNEL_SESSION_STOP
:
558 case LTTNG_KERNEL_DISABLE
:
559 return lttng_session_disable(session
);
560 case LTTNG_KERNEL_OLD_METADATA
:
562 struct lttng_kernel_channel chan_param
;
563 struct lttng_kernel_old_channel old_chan_param
;
565 if (copy_from_user(&old_chan_param
,
566 (struct lttng_kernel_old_channel __user
*) arg
,
567 sizeof(struct lttng_kernel_old_channel
)))
569 chan_param
.overwrite
= old_chan_param
.overwrite
;
570 chan_param
.subbuf_size
= old_chan_param
.subbuf_size
;
571 chan_param
.num_subbuf
= old_chan_param
.num_subbuf
;
572 chan_param
.switch_timer_interval
= old_chan_param
.switch_timer_interval
;
573 chan_param
.read_timer_interval
= old_chan_param
.read_timer_interval
;
574 chan_param
.output
= old_chan_param
.output
;
576 return lttng_abi_create_channel(file
, &chan_param
,
579 case LTTNG_KERNEL_METADATA
:
581 struct lttng_kernel_channel chan_param
;
583 if (copy_from_user(&chan_param
,
584 (struct lttng_kernel_channel __user
*) arg
,
585 sizeof(struct lttng_kernel_channel
)))
587 return lttng_abi_create_channel(file
, &chan_param
,
590 case LTTNG_KERNEL_SESSION_TRACK_PID
:
591 return lttng_session_track_id(session
, TRACKER_PID
, (int) arg
);
592 case LTTNG_KERNEL_SESSION_UNTRACK_PID
:
593 return lttng_session_untrack_id(session
, TRACKER_PID
, (int) arg
);
594 case LTTNG_KERNEL_SESSION_TRACK_ID
:
596 struct lttng_kernel_tracker_args tracker
;
597 enum tracker_type tracker_type
;
599 if (copy_from_user(&tracker
,
600 (struct lttng_kernel_tracker_args __user
*) arg
,
601 sizeof(struct lttng_kernel_tracker_args
)))
603 tracker_type
= get_tracker_type(&tracker
);
604 if (tracker_type
== TRACKER_UNKNOWN
)
606 return lttng_session_track_id(session
, tracker_type
, tracker
.id
);
608 case LTTNG_KERNEL_SESSION_UNTRACK_ID
:
610 struct lttng_kernel_tracker_args tracker
;
611 enum tracker_type tracker_type
;
613 if (copy_from_user(&tracker
,
614 (struct lttng_kernel_tracker_args __user
*) arg
,
615 sizeof(struct lttng_kernel_tracker_args
)))
617 tracker_type
= get_tracker_type(&tracker
);
618 if (tracker_type
== TRACKER_UNKNOWN
)
620 return lttng_session_untrack_id(session
, tracker_type
,
623 case LTTNG_KERNEL_SESSION_LIST_TRACKER_PIDS
:
624 return lttng_session_list_tracker_ids(session
, TRACKER_PID
);
625 case LTTNG_KERNEL_SESSION_LIST_TRACKER_IDS
:
627 struct lttng_kernel_tracker_args tracker
;
628 enum tracker_type tracker_type
;
630 if (copy_from_user(&tracker
,
631 (struct lttng_kernel_tracker_args __user
*) arg
,
632 sizeof(struct lttng_kernel_tracker_args
)))
634 tracker_type
= get_tracker_type(&tracker
);
635 if (tracker_type
== TRACKER_UNKNOWN
)
637 return lttng_session_list_tracker_ids(session
, tracker_type
);
639 case LTTNG_KERNEL_SESSION_METADATA_REGEN
:
640 return lttng_session_metadata_regenerate(session
);
641 case LTTNG_KERNEL_SESSION_STATEDUMP
:
642 return lttng_session_statedump(session
);
649 * Called when the last file reference is dropped.
651 * Big fat note: channels and events are invariant for the whole session after
652 * their creation. So this session destruction also destroys all channel and
653 * event structures specific to this session (they are not destroyed when their
654 * individual file is released).
657 int lttng_session_release(struct inode
*inode
, struct file
*file
)
659 struct lttng_session
*session
= file
->private_data
;
662 lttng_session_destroy(session
);
666 static const struct file_operations lttng_session_fops
= {
667 .owner
= THIS_MODULE
,
668 .release
= lttng_session_release
,
669 .unlocked_ioctl
= lttng_session_ioctl
,
671 .compat_ioctl
= lttng_session_ioctl
,
676 * lttng_metadata_ring_buffer_poll - LTTng ring buffer poll file operation
680 * Handles the poll operations for the metadata channels.
683 unsigned int lttng_metadata_ring_buffer_poll(struct file
*filp
,
686 struct lttng_metadata_stream
*stream
= filp
->private_data
;
687 struct lib_ring_buffer
*buf
= stream
->priv
;
689 unsigned int mask
= 0;
691 if (filp
->f_mode
& FMODE_READ
) {
692 poll_wait_set_exclusive(wait
);
693 poll_wait(filp
, &stream
->read_wait
, wait
);
695 finalized
= stream
->finalized
;
698 * lib_ring_buffer_is_finalized() contains a smp_rmb()
699 * ordering finalized load before offsets loads.
701 WARN_ON(atomic_long_read(&buf
->active_readers
) != 1);
706 mutex_lock(&stream
->metadata_cache
->lock
);
707 if (stream
->metadata_cache
->metadata_written
>
708 stream
->metadata_out
)
710 mutex_unlock(&stream
->metadata_cache
->lock
);
717 void lttng_metadata_ring_buffer_ioctl_put_next_subbuf(struct file
*filp
,
718 unsigned int cmd
, unsigned long arg
)
720 struct lttng_metadata_stream
*stream
= filp
->private_data
;
722 stream
->metadata_out
= stream
->metadata_in
;
726 long lttng_metadata_ring_buffer_ioctl(struct file
*filp
,
727 unsigned int cmd
, unsigned long arg
)
730 struct lttng_metadata_stream
*stream
= filp
->private_data
;
731 struct lib_ring_buffer
*buf
= stream
->priv
;
734 case RING_BUFFER_GET_NEXT_SUBBUF
:
736 struct lttng_metadata_stream
*stream
= filp
->private_data
;
737 struct lib_ring_buffer
*buf
= stream
->priv
;
738 struct channel
*chan
= buf
->backend
.chan
;
740 ret
= lttng_metadata_output_channel(stream
, chan
);
742 lib_ring_buffer_switch_slow(buf
, SWITCH_ACTIVE
);
748 case RING_BUFFER_GET_SUBBUF
:
751 * Random access is not allowed for metadata channel.
755 case RING_BUFFER_FLUSH_EMPTY
: /* Fall-through. */
756 case RING_BUFFER_FLUSH
:
758 struct lttng_metadata_stream
*stream
= filp
->private_data
;
759 struct lib_ring_buffer
*buf
= stream
->priv
;
760 struct channel
*chan
= buf
->backend
.chan
;
763 * Before doing the actual ring buffer flush, write up to one
764 * packet of metadata in the ring buffer.
766 ret
= lttng_metadata_output_channel(stream
, chan
);
771 case RING_BUFFER_GET_METADATA_VERSION
:
773 struct lttng_metadata_stream
*stream
= filp
->private_data
;
775 return put_u64(stream
->version
, arg
);
780 /* PUT_SUBBUF is the one from lib ring buffer, unmodified. */
782 /* Performing lib ring buffer ioctl after our own. */
783 ret
= lib_ring_buffer_ioctl(filp
, cmd
, arg
, buf
);
788 case RING_BUFFER_PUT_NEXT_SUBBUF
:
790 lttng_metadata_ring_buffer_ioctl_put_next_subbuf(filp
,
803 long lttng_metadata_ring_buffer_compat_ioctl(struct file
*filp
,
804 unsigned int cmd
, unsigned long arg
)
807 struct lttng_metadata_stream
*stream
= filp
->private_data
;
808 struct lib_ring_buffer
*buf
= stream
->priv
;
811 case RING_BUFFER_GET_NEXT_SUBBUF
:
813 struct lttng_metadata_stream
*stream
= filp
->private_data
;
814 struct lib_ring_buffer
*buf
= stream
->priv
;
815 struct channel
*chan
= buf
->backend
.chan
;
817 ret
= lttng_metadata_output_channel(stream
, chan
);
819 lib_ring_buffer_switch_slow(buf
, SWITCH_ACTIVE
);
825 case RING_BUFFER_GET_SUBBUF
:
828 * Random access is not allowed for metadata channel.
832 case RING_BUFFER_FLUSH_EMPTY
: /* Fall-through. */
833 case RING_BUFFER_FLUSH
:
835 struct lttng_metadata_stream
*stream
= filp
->private_data
;
836 struct lib_ring_buffer
*buf
= stream
->priv
;
837 struct channel
*chan
= buf
->backend
.chan
;
840 * Before doing the actual ring buffer flush, write up to one
841 * packet of metadata in the ring buffer.
843 ret
= lttng_metadata_output_channel(stream
, chan
);
848 case RING_BUFFER_GET_METADATA_VERSION
:
850 struct lttng_metadata_stream
*stream
= filp
->private_data
;
852 return put_u64(stream
->version
, arg
);
857 /* PUT_SUBBUF is the one from lib ring buffer, unmodified. */
859 /* Performing lib ring buffer ioctl after our own. */
860 ret
= lib_ring_buffer_compat_ioctl(filp
, cmd
, arg
, buf
);
865 case RING_BUFFER_PUT_NEXT_SUBBUF
:
867 lttng_metadata_ring_buffer_ioctl_put_next_subbuf(filp
,
880 * This is not used by anonymous file descriptors. This code is left
881 * there if we ever want to implement an inode with open() operation.
884 int lttng_metadata_ring_buffer_open(struct inode
*inode
, struct file
*file
)
886 struct lttng_metadata_stream
*stream
= inode
->i_private
;
887 struct lib_ring_buffer
*buf
= stream
->priv
;
889 file
->private_data
= buf
;
891 * Since life-time of metadata cache differs from that of
892 * session, we need to keep our own reference on the transport.
894 if (!try_module_get(stream
->transport
->owner
)) {
895 printk(KERN_WARNING
"LTT : Can't lock transport module.\n");
898 return lib_ring_buffer_open(inode
, file
, buf
);
902 int lttng_metadata_ring_buffer_release(struct inode
*inode
, struct file
*file
)
904 struct lttng_metadata_stream
*stream
= file
->private_data
;
905 struct lib_ring_buffer
*buf
= stream
->priv
;
907 kref_put(&stream
->metadata_cache
->refcount
, metadata_cache_destroy
);
908 module_put(stream
->transport
->owner
);
909 return lib_ring_buffer_release(inode
, file
, buf
);
913 ssize_t
lttng_metadata_ring_buffer_splice_read(struct file
*in
, loff_t
*ppos
,
914 struct pipe_inode_info
*pipe
, size_t len
,
917 struct lttng_metadata_stream
*stream
= in
->private_data
;
918 struct lib_ring_buffer
*buf
= stream
->priv
;
920 return lib_ring_buffer_splice_read(in
, ppos
, pipe
, len
,
925 int lttng_metadata_ring_buffer_mmap(struct file
*filp
,
926 struct vm_area_struct
*vma
)
928 struct lttng_metadata_stream
*stream
= filp
->private_data
;
929 struct lib_ring_buffer
*buf
= stream
->priv
;
931 return lib_ring_buffer_mmap(filp
, vma
, buf
);
935 const struct file_operations lttng_metadata_ring_buffer_file_operations
= {
936 .owner
= THIS_MODULE
,
937 .open
= lttng_metadata_ring_buffer_open
,
938 .release
= lttng_metadata_ring_buffer_release
,
939 .poll
= lttng_metadata_ring_buffer_poll
,
940 .splice_read
= lttng_metadata_ring_buffer_splice_read
,
941 .mmap
= lttng_metadata_ring_buffer_mmap
,
942 .unlocked_ioctl
= lttng_metadata_ring_buffer_ioctl
,
943 .llseek
= vfs_lib_ring_buffer_no_llseek
,
945 .compat_ioctl
= lttng_metadata_ring_buffer_compat_ioctl
,
950 int lttng_abi_create_stream_fd(struct file
*channel_file
, void *stream_priv
,
951 const struct file_operations
*fops
)
954 struct file
*stream_file
;
956 stream_fd
= lttng_get_unused_fd();
961 stream_file
= anon_inode_getfile("[lttng_stream]", fops
,
962 stream_priv
, O_RDWR
);
963 if (IS_ERR(stream_file
)) {
964 ret
= PTR_ERR(stream_file
);
968 * OPEN_FMODE, called within anon_inode_getfile/alloc_file, don't honor
969 * FMODE_LSEEK, FMODE_PREAD nor FMODE_PWRITE. We need to read from this
970 * file descriptor, so we set FMODE_PREAD here.
972 stream_file
->f_mode
|= FMODE_PREAD
;
973 fd_install(stream_fd
, stream_file
);
975 * The stream holds a reference to the channel within the generic ring
976 * buffer library, so no need to hold a refcount on the channel and
977 * session files here.
982 put_unused_fd(stream_fd
);
988 int lttng_abi_open_stream(struct file
*channel_file
)
990 struct lttng_channel
*channel
= channel_file
->private_data
;
991 struct lib_ring_buffer
*buf
;
995 buf
= channel
->ops
->buffer_read_open(channel
->chan
);
1000 ret
= lttng_abi_create_stream_fd(channel_file
, stream_priv
,
1001 <tng_stream_ring_buffer_file_operations
);
1008 channel
->ops
->buffer_read_close(buf
);
1013 int lttng_abi_open_metadata_stream(struct file
*channel_file
)
1015 struct lttng_channel
*channel
= channel_file
->private_data
;
1016 struct lttng_session
*session
= channel
->session
;
1017 struct lib_ring_buffer
*buf
;
1019 struct lttng_metadata_stream
*metadata_stream
;
1022 buf
= channel
->ops
->buffer_read_open(channel
->chan
);
1026 metadata_stream
= kzalloc(sizeof(struct lttng_metadata_stream
),
1028 if (!metadata_stream
) {
1032 metadata_stream
->metadata_cache
= session
->metadata_cache
;
1033 init_waitqueue_head(&metadata_stream
->read_wait
);
1034 metadata_stream
->priv
= buf
;
1035 stream_priv
= metadata_stream
;
1036 metadata_stream
->transport
= channel
->transport
;
1039 * Since life-time of metadata cache differs from that of
1040 * session, we need to keep our own reference on the transport.
1042 if (!try_module_get(metadata_stream
->transport
->owner
)) {
1043 printk(KERN_WARNING
"LTT : Can't lock transport module.\n");
1048 if (!lttng_kref_get(&session
->metadata_cache
->refcount
)) {
1053 ret
= lttng_abi_create_stream_fd(channel_file
, stream_priv
,
1054 <tng_metadata_ring_buffer_file_operations
);
1058 list_add(&metadata_stream
->list
,
1059 &session
->metadata_cache
->metadata_stream
);
1063 kref_put(&session
->metadata_cache
->refcount
, metadata_cache_destroy
);
1065 module_put(metadata_stream
->transport
->owner
);
1067 kfree(metadata_stream
);
1069 channel
->ops
->buffer_read_close(buf
);
1074 int lttng_abi_create_event(struct file
*channel_file
,
1075 struct lttng_kernel_event
*event_param
)
1077 struct lttng_channel
*channel
= channel_file
->private_data
;
1079 struct file
*event_file
;
1082 event_param
->name
[LTTNG_KERNEL_SYM_NAME_LEN
- 1] = '\0';
1083 switch (event_param
->instrumentation
) {
1084 case LTTNG_KERNEL_KRETPROBE
:
1085 event_param
->u
.kretprobe
.symbol_name
[LTTNG_KERNEL_SYM_NAME_LEN
- 1] = '\0';
1087 case LTTNG_KERNEL_KPROBE
:
1088 event_param
->u
.kprobe
.symbol_name
[LTTNG_KERNEL_SYM_NAME_LEN
- 1] = '\0';
1090 case LTTNG_KERNEL_FUNCTION
:
1091 event_param
->u
.ftrace
.symbol_name
[LTTNG_KERNEL_SYM_NAME_LEN
- 1] = '\0';
1096 event_fd
= lttng_get_unused_fd();
1101 event_file
= anon_inode_getfile("[lttng_event]",
1104 if (IS_ERR(event_file
)) {
1105 ret
= PTR_ERR(event_file
);
1108 /* The event holds a reference on the channel */
1109 if (atomic_long_add_unless(&channel_file
->f_count
,
1110 1, INT_MAX
) == INT_MAX
) {
1112 goto refcount_error
;
1114 if (event_param
->instrumentation
== LTTNG_KERNEL_TRACEPOINT
1115 || event_param
->instrumentation
== LTTNG_KERNEL_SYSCALL
) {
1116 struct lttng_enabler
*enabler
;
1118 if (event_param
->name
[strlen(event_param
->name
) - 1] == '*') {
1119 enabler
= lttng_enabler_create(LTTNG_ENABLER_WILDCARD
,
1120 event_param
, channel
);
1122 enabler
= lttng_enabler_create(LTTNG_ENABLER_NAME
,
1123 event_param
, channel
);
1127 struct lttng_event
*event
;
1130 * We tolerate no failure path after event creation. It
1131 * will stay invariant for the rest of the session.
1133 event
= lttng_event_create(channel
, event_param
,
1135 event_param
->instrumentation
);
1136 WARN_ON_ONCE(!event
);
1137 if (IS_ERR(event
)) {
1138 ret
= PTR_ERR(event
);
1143 event_file
->private_data
= priv
;
1144 fd_install(event_fd
, event_file
);
1148 atomic_long_dec(&channel_file
->f_count
);
1152 put_unused_fd(event_fd
);
1158 * lttng_channel_ioctl - lttng syscall through ioctl
1164 * This ioctl implements lttng commands:
1165 * LTTNG_KERNEL_STREAM
1166 * Returns an event stream file descriptor or failure.
1167 * (typically, one event stream records events from one CPU)
1168 * LTTNG_KERNEL_EVENT
1169 * Returns an event file descriptor or failure.
1170 * LTTNG_KERNEL_CONTEXT
1171 * Prepend a context field to each event in the channel
1172 * LTTNG_KERNEL_ENABLE
1173 * Enable recording for events in this channel (weak enable)
1174 * LTTNG_KERNEL_DISABLE
1175 * Disable recording for events in this channel (strong disable)
1177 * Channel and event file descriptors also hold a reference on the session.
1180 long lttng_channel_ioctl(struct file
*file
, unsigned int cmd
, unsigned long arg
)
1182 struct lttng_channel
*channel
= file
->private_data
;
1185 case LTTNG_KERNEL_OLD_STREAM
:
1186 case LTTNG_KERNEL_STREAM
:
1187 return lttng_abi_open_stream(file
);
1188 case LTTNG_KERNEL_OLD_EVENT
:
1190 struct lttng_kernel_event
*uevent_param
;
1191 struct lttng_kernel_old_event
*old_uevent_param
;
1194 uevent_param
= kmalloc(sizeof(struct lttng_kernel_event
),
1196 if (!uevent_param
) {
1200 old_uevent_param
= kmalloc(
1201 sizeof(struct lttng_kernel_old_event
),
1203 if (!old_uevent_param
) {
1205 goto old_event_error_free_param
;
1207 if (copy_from_user(old_uevent_param
,
1208 (struct lttng_kernel_old_event __user
*) arg
,
1209 sizeof(struct lttng_kernel_old_event
))) {
1211 goto old_event_error_free_old_param
;
1214 memcpy(uevent_param
->name
, old_uevent_param
->name
,
1215 sizeof(uevent_param
->name
));
1216 uevent_param
->instrumentation
=
1217 old_uevent_param
->instrumentation
;
1219 switch (old_uevent_param
->instrumentation
) {
1220 case LTTNG_KERNEL_KPROBE
:
1221 uevent_param
->u
.kprobe
.addr
=
1222 old_uevent_param
->u
.kprobe
.addr
;
1223 uevent_param
->u
.kprobe
.offset
=
1224 old_uevent_param
->u
.kprobe
.offset
;
1225 memcpy(uevent_param
->u
.kprobe
.symbol_name
,
1226 old_uevent_param
->u
.kprobe
.symbol_name
,
1227 sizeof(uevent_param
->u
.kprobe
.symbol_name
));
1229 case LTTNG_KERNEL_KRETPROBE
:
1230 uevent_param
->u
.kretprobe
.addr
=
1231 old_uevent_param
->u
.kretprobe
.addr
;
1232 uevent_param
->u
.kretprobe
.offset
=
1233 old_uevent_param
->u
.kretprobe
.offset
;
1234 memcpy(uevent_param
->u
.kretprobe
.symbol_name
,
1235 old_uevent_param
->u
.kretprobe
.symbol_name
,
1236 sizeof(uevent_param
->u
.kretprobe
.symbol_name
));
1238 case LTTNG_KERNEL_FUNCTION
:
1239 memcpy(uevent_param
->u
.ftrace
.symbol_name
,
1240 old_uevent_param
->u
.ftrace
.symbol_name
,
1241 sizeof(uevent_param
->u
.ftrace
.symbol_name
));
1246 ret
= lttng_abi_create_event(file
, uevent_param
);
1248 old_event_error_free_old_param
:
1249 kfree(old_uevent_param
);
1250 old_event_error_free_param
:
1251 kfree(uevent_param
);
1255 case LTTNG_KERNEL_EVENT
:
1257 struct lttng_kernel_event uevent_param
;
1259 if (copy_from_user(&uevent_param
,
1260 (struct lttng_kernel_event __user
*) arg
,
1261 sizeof(uevent_param
)))
1263 return lttng_abi_create_event(file
, &uevent_param
);
1265 case LTTNG_KERNEL_OLD_CONTEXT
:
1267 struct lttng_kernel_context
*ucontext_param
;
1268 struct lttng_kernel_old_context
*old_ucontext_param
;
1271 ucontext_param
= kmalloc(sizeof(struct lttng_kernel_context
),
1273 if (!ucontext_param
) {
1277 old_ucontext_param
= kmalloc(sizeof(struct lttng_kernel_old_context
),
1279 if (!old_ucontext_param
) {
1281 goto old_ctx_error_free_param
;
1284 if (copy_from_user(old_ucontext_param
,
1285 (struct lttng_kernel_old_context __user
*) arg
,
1286 sizeof(struct lttng_kernel_old_context
))) {
1288 goto old_ctx_error_free_old_param
;
1290 ucontext_param
->ctx
= old_ucontext_param
->ctx
;
1291 memcpy(ucontext_param
->padding
, old_ucontext_param
->padding
,
1292 sizeof(ucontext_param
->padding
));
1293 /* only type that uses the union */
1294 if (old_ucontext_param
->ctx
== LTTNG_KERNEL_CONTEXT_PERF_COUNTER
) {
1295 ucontext_param
->u
.perf_counter
.type
=
1296 old_ucontext_param
->u
.perf_counter
.type
;
1297 ucontext_param
->u
.perf_counter
.config
=
1298 old_ucontext_param
->u
.perf_counter
.config
;
1299 memcpy(ucontext_param
->u
.perf_counter
.name
,
1300 old_ucontext_param
->u
.perf_counter
.name
,
1301 sizeof(ucontext_param
->u
.perf_counter
.name
));
1304 ret
= lttng_abi_add_context(file
,
1306 &channel
->ctx
, channel
->session
);
1308 old_ctx_error_free_old_param
:
1309 kfree(old_ucontext_param
);
1310 old_ctx_error_free_param
:
1311 kfree(ucontext_param
);
1315 case LTTNG_KERNEL_CONTEXT
:
1317 struct lttng_kernel_context ucontext_param
;
1319 if (copy_from_user(&ucontext_param
,
1320 (struct lttng_kernel_context __user
*) arg
,
1321 sizeof(ucontext_param
)))
1323 return lttng_abi_add_context(file
,
1325 &channel
->ctx
, channel
->session
);
1327 case LTTNG_KERNEL_OLD_ENABLE
:
1328 case LTTNG_KERNEL_ENABLE
:
1329 return lttng_channel_enable(channel
);
1330 case LTTNG_KERNEL_OLD_DISABLE
:
1331 case LTTNG_KERNEL_DISABLE
:
1332 return lttng_channel_disable(channel
);
1333 case LTTNG_KERNEL_SYSCALL_MASK
:
1334 return lttng_channel_syscall_mask(channel
,
1335 (struct lttng_kernel_syscall_mask __user
*) arg
);
1337 return -ENOIOCTLCMD
;
1343 * lttng_metadata_ioctl - lttng syscall through ioctl
1349 * This ioctl implements lttng commands:
1350 * LTTNG_KERNEL_STREAM
1351 * Returns an event stream file descriptor or failure.
1353 * Channel and event file descriptors also hold a reference on the session.
1356 long lttng_metadata_ioctl(struct file
*file
, unsigned int cmd
, unsigned long arg
)
1359 case LTTNG_KERNEL_OLD_STREAM
:
1360 case LTTNG_KERNEL_STREAM
:
1361 return lttng_abi_open_metadata_stream(file
);
1363 return -ENOIOCTLCMD
;
1368 * lttng_channel_poll - lttng stream addition/removal monitoring
1373 unsigned int lttng_channel_poll(struct file
*file
, poll_table
*wait
)
1375 struct lttng_channel
*channel
= file
->private_data
;
1376 unsigned int mask
= 0;
1378 if (file
->f_mode
& FMODE_READ
) {
1379 poll_wait_set_exclusive(wait
);
1380 poll_wait(file
, channel
->ops
->get_hp_wait_queue(channel
->chan
),
1383 if (channel
->ops
->is_disabled(channel
->chan
))
1385 if (channel
->ops
->is_finalized(channel
->chan
))
1387 if (channel
->ops
->buffer_has_read_closed_stream(channel
->chan
))
1388 return POLLIN
| POLLRDNORM
;
1396 int lttng_channel_release(struct inode
*inode
, struct file
*file
)
1398 struct lttng_channel
*channel
= file
->private_data
;
1401 fput(channel
->session
->file
);
1406 int lttng_metadata_channel_release(struct inode
*inode
, struct file
*file
)
1408 struct lttng_channel
*channel
= file
->private_data
;
1411 fput(channel
->session
->file
);
1412 lttng_metadata_channel_destroy(channel
);
1418 static const struct file_operations lttng_channel_fops
= {
1419 .owner
= THIS_MODULE
,
1420 .release
= lttng_channel_release
,
1421 .poll
= lttng_channel_poll
,
1422 .unlocked_ioctl
= lttng_channel_ioctl
,
1423 #ifdef CONFIG_COMPAT
1424 .compat_ioctl
= lttng_channel_ioctl
,
1428 static const struct file_operations lttng_metadata_fops
= {
1429 .owner
= THIS_MODULE
,
1430 .release
= lttng_metadata_channel_release
,
1431 .unlocked_ioctl
= lttng_metadata_ioctl
,
1432 #ifdef CONFIG_COMPAT
1433 .compat_ioctl
= lttng_metadata_ioctl
,
1438 * lttng_event_ioctl - lttng syscall through ioctl
1444 * This ioctl implements lttng commands:
1445 * LTTNG_KERNEL_CONTEXT
1446 * Prepend a context field to each record of this event
1447 * LTTNG_KERNEL_ENABLE
1448 * Enable recording for this event (weak enable)
1449 * LTTNG_KERNEL_DISABLE
1450 * Disable recording for this event (strong disable)
1453 long lttng_event_ioctl(struct file
*file
, unsigned int cmd
, unsigned long arg
)
1455 struct lttng_event
*event
;
1456 struct lttng_enabler
*enabler
;
1457 enum lttng_event_type
*evtype
= file
->private_data
;
1460 case LTTNG_KERNEL_OLD_CONTEXT
:
1462 /* Not implemented */
1465 case LTTNG_KERNEL_CONTEXT
:
1467 /* Not implemented */
1470 case LTTNG_KERNEL_OLD_ENABLE
:
1471 case LTTNG_KERNEL_ENABLE
:
1473 case LTTNG_TYPE_EVENT
:
1474 event
= file
->private_data
;
1475 return lttng_event_enable(event
);
1476 case LTTNG_TYPE_ENABLER
:
1477 enabler
= file
->private_data
;
1478 return lttng_enabler_enable(enabler
);
1483 case LTTNG_KERNEL_OLD_DISABLE
:
1484 case LTTNG_KERNEL_DISABLE
:
1486 case LTTNG_TYPE_EVENT
:
1487 event
= file
->private_data
;
1488 return lttng_event_disable(event
);
1489 case LTTNG_TYPE_ENABLER
:
1490 enabler
= file
->private_data
;
1491 return lttng_enabler_disable(enabler
);
1496 case LTTNG_KERNEL_FILTER
:
1498 case LTTNG_TYPE_EVENT
:
1500 case LTTNG_TYPE_ENABLER
:
1502 enabler
= file
->private_data
;
1503 return lttng_enabler_attach_bytecode(enabler
,
1504 (struct lttng_kernel_filter_bytecode __user
*) arg
);
1509 return -ENOIOCTLCMD
;
1514 int lttng_event_release(struct inode
*inode
, struct file
*file
)
1516 struct lttng_event
*event
;
1517 struct lttng_enabler
*enabler
;
1518 enum lttng_event_type
*evtype
= file
->private_data
;
1524 case LTTNG_TYPE_EVENT
:
1525 event
= file
->private_data
;
1527 fput(event
->chan
->file
);
1529 case LTTNG_TYPE_ENABLER
:
1530 enabler
= file
->private_data
;
1532 fput(enabler
->chan
->file
);
1542 /* TODO: filter control ioctl */
1543 static const struct file_operations lttng_event_fops
= {
1544 .owner
= THIS_MODULE
,
1545 .release
= lttng_event_release
,
1546 .unlocked_ioctl
= lttng_event_ioctl
,
1547 #ifdef CONFIG_COMPAT
1548 .compat_ioctl
= lttng_event_ioctl
,
1552 static int put_u64(uint64_t val
, unsigned long arg
)
1554 return put_user(val
, (uint64_t __user
*) arg
);
1557 static long lttng_stream_ring_buffer_ioctl(struct file
*filp
,
1558 unsigned int cmd
, unsigned long arg
)
1560 struct lib_ring_buffer
*buf
= filp
->private_data
;
1561 struct channel
*chan
= buf
->backend
.chan
;
1562 const struct lib_ring_buffer_config
*config
= &chan
->backend
.config
;
1563 const struct lttng_channel_ops
*ops
= chan
->backend
.priv_ops
;
1566 if (atomic_read(&chan
->record_disabled
))
1570 case LTTNG_RING_BUFFER_GET_TIMESTAMP_BEGIN
:
1574 ret
= ops
->timestamp_begin(config
, buf
, &ts
);
1577 return put_u64(ts
, arg
);
1579 case LTTNG_RING_BUFFER_GET_TIMESTAMP_END
:
1583 ret
= ops
->timestamp_end(config
, buf
, &ts
);
1586 return put_u64(ts
, arg
);
1588 case LTTNG_RING_BUFFER_GET_EVENTS_DISCARDED
:
1592 ret
= ops
->events_discarded(config
, buf
, &ed
);
1595 return put_u64(ed
, arg
);
1597 case LTTNG_RING_BUFFER_GET_CONTENT_SIZE
:
1601 ret
= ops
->content_size(config
, buf
, &cs
);
1604 return put_u64(cs
, arg
);
1606 case LTTNG_RING_BUFFER_GET_PACKET_SIZE
:
1610 ret
= ops
->packet_size(config
, buf
, &ps
);
1613 return put_u64(ps
, arg
);
1615 case LTTNG_RING_BUFFER_GET_STREAM_ID
:
1619 ret
= ops
->stream_id(config
, buf
, &si
);
1622 return put_u64(si
, arg
);
1624 case LTTNG_RING_BUFFER_GET_CURRENT_TIMESTAMP
:
1628 ret
= ops
->current_timestamp(config
, buf
, &ts
);
1631 return put_u64(ts
, arg
);
1633 case LTTNG_RING_BUFFER_GET_SEQ_NUM
:
1637 ret
= ops
->sequence_number(config
, buf
, &seq
);
1640 return put_u64(seq
, arg
);
1642 case LTTNG_RING_BUFFER_INSTANCE_ID
:
1646 ret
= ops
->instance_id(config
, buf
, &id
);
1649 return put_u64(id
, arg
);
1652 return lib_ring_buffer_file_operations
.unlocked_ioctl(filp
,
1660 #ifdef CONFIG_COMPAT
1661 static long lttng_stream_ring_buffer_compat_ioctl(struct file
*filp
,
1662 unsigned int cmd
, unsigned long arg
)
1664 struct lib_ring_buffer
*buf
= filp
->private_data
;
1665 struct channel
*chan
= buf
->backend
.chan
;
1666 const struct lib_ring_buffer_config
*config
= &chan
->backend
.config
;
1667 const struct lttng_channel_ops
*ops
= chan
->backend
.priv_ops
;
1670 if (atomic_read(&chan
->record_disabled
))
1674 case LTTNG_RING_BUFFER_COMPAT_GET_TIMESTAMP_BEGIN
:
1678 ret
= ops
->timestamp_begin(config
, buf
, &ts
);
1681 return put_u64(ts
, arg
);
1683 case LTTNG_RING_BUFFER_COMPAT_GET_TIMESTAMP_END
:
1687 ret
= ops
->timestamp_end(config
, buf
, &ts
);
1690 return put_u64(ts
, arg
);
1692 case LTTNG_RING_BUFFER_COMPAT_GET_EVENTS_DISCARDED
:
1696 ret
= ops
->events_discarded(config
, buf
, &ed
);
1699 return put_u64(ed
, arg
);
1701 case LTTNG_RING_BUFFER_COMPAT_GET_CONTENT_SIZE
:
1705 ret
= ops
->content_size(config
, buf
, &cs
);
1708 return put_u64(cs
, arg
);
1710 case LTTNG_RING_BUFFER_COMPAT_GET_PACKET_SIZE
:
1714 ret
= ops
->packet_size(config
, buf
, &ps
);
1717 return put_u64(ps
, arg
);
1719 case LTTNG_RING_BUFFER_COMPAT_GET_STREAM_ID
:
1723 ret
= ops
->stream_id(config
, buf
, &si
);
1726 return put_u64(si
, arg
);
1728 case LTTNG_RING_BUFFER_GET_CURRENT_TIMESTAMP
:
1732 ret
= ops
->current_timestamp(config
, buf
, &ts
);
1735 return put_u64(ts
, arg
);
1737 case LTTNG_RING_BUFFER_COMPAT_GET_SEQ_NUM
:
1741 ret
= ops
->sequence_number(config
, buf
, &seq
);
1744 return put_u64(seq
, arg
);
1746 case LTTNG_RING_BUFFER_COMPAT_INSTANCE_ID
:
1750 ret
= ops
->instance_id(config
, buf
, &id
);
1753 return put_u64(id
, arg
);
1756 return lib_ring_buffer_file_operations
.compat_ioctl(filp
,
1763 #endif /* CONFIG_COMPAT */
1765 static void lttng_stream_override_ring_buffer_fops(void)
1767 lttng_stream_ring_buffer_file_operations
.owner
= THIS_MODULE
;
1768 lttng_stream_ring_buffer_file_operations
.open
=
1769 lib_ring_buffer_file_operations
.open
;
1770 lttng_stream_ring_buffer_file_operations
.release
=
1771 lib_ring_buffer_file_operations
.release
;
1772 lttng_stream_ring_buffer_file_operations
.poll
=
1773 lib_ring_buffer_file_operations
.poll
;
1774 lttng_stream_ring_buffer_file_operations
.splice_read
=
1775 lib_ring_buffer_file_operations
.splice_read
;
1776 lttng_stream_ring_buffer_file_operations
.mmap
=
1777 lib_ring_buffer_file_operations
.mmap
;
1778 lttng_stream_ring_buffer_file_operations
.unlocked_ioctl
=
1779 lttng_stream_ring_buffer_ioctl
;
1780 lttng_stream_ring_buffer_file_operations
.llseek
=
1781 lib_ring_buffer_file_operations
.llseek
;
1782 #ifdef CONFIG_COMPAT
1783 lttng_stream_ring_buffer_file_operations
.compat_ioctl
=
1784 lttng_stream_ring_buffer_compat_ioctl
;
1788 int __init
lttng_abi_init(void)
1792 wrapper_vmalloc_sync_all();
1795 ret
= lttng_tp_mempool_init();
1800 lttng_proc_dentry
= proc_create_data("lttng", S_IRUSR
| S_IWUSR
, NULL
,
1803 if (!lttng_proc_dentry
) {
1804 printk(KERN_ERR
"Error creating LTTng control file\n");
1808 lttng_stream_override_ring_buffer_fops();
1812 lttng_tp_mempool_destroy();
1813 lttng_clock_unref();
1817 /* No __exit annotation because used by init error path too. */
1818 void lttng_abi_exit(void)
1820 lttng_tp_mempool_destroy();
1821 lttng_clock_unref();
1822 if (lttng_proc_dentry
)
1823 remove_proc_entry("lttng", NULL
);