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 <lib/ringbuffer/frontend_types.h>
61 * This is LTTng's own personal way to create a system call as an external
62 * module. We use ioctl() on /proc/lttng.
65 static struct proc_dir_entry
*lttng_proc_dentry
;
66 static const struct file_operations lttng_fops
;
67 static const struct file_operations lttng_session_fops
;
68 static const struct file_operations lttng_channel_fops
;
69 static const struct file_operations lttng_metadata_fops
;
70 static const struct file_operations lttng_event_fops
;
71 static struct file_operations lttng_stream_ring_buffer_file_operations
;
73 static int put_u64(uint64_t val
, unsigned long arg
);
76 * Teardown management: opened file descriptors keep a refcount on the module,
77 * so it can only exit when all file descriptors are closed.
81 int lttng_abi_create_session(void)
83 struct lttng_session
*session
;
84 struct file
*session_file
;
87 session
= lttng_session_create();
90 session_fd
= lttng_get_unused_fd();
95 session_file
= anon_inode_getfile("[lttng_session]",
98 if (IS_ERR(session_file
)) {
99 ret
= PTR_ERR(session_file
);
102 session
->file
= session_file
;
103 fd_install(session_fd
, session_file
);
107 put_unused_fd(session_fd
);
109 lttng_session_destroy(session
);
114 int lttng_abi_tracepoint_list(void)
116 struct file
*tracepoint_list_file
;
119 file_fd
= lttng_get_unused_fd();
125 tracepoint_list_file
= anon_inode_getfile("[lttng_tracepoint_list]",
126 <tng_tracepoint_list_fops
,
128 if (IS_ERR(tracepoint_list_file
)) {
129 ret
= PTR_ERR(tracepoint_list_file
);
132 ret
= lttng_tracepoint_list_fops
.open(NULL
, tracepoint_list_file
);
135 fd_install(file_fd
, tracepoint_list_file
);
139 fput(tracepoint_list_file
);
141 put_unused_fd(file_fd
);
146 #ifndef CONFIG_HAVE_SYSCALL_TRACEPOINTS
148 int lttng_abi_syscall_list(void)
154 int lttng_abi_syscall_list(void)
156 struct file
*syscall_list_file
;
159 file_fd
= lttng_get_unused_fd();
165 syscall_list_file
= anon_inode_getfile("[lttng_syscall_list]",
166 <tng_syscall_list_fops
,
168 if (IS_ERR(syscall_list_file
)) {
169 ret
= PTR_ERR(syscall_list_file
);
172 ret
= lttng_syscall_list_fops
.open(NULL
, syscall_list_file
);
175 fd_install(file_fd
, syscall_list_file
);
179 fput(syscall_list_file
);
181 put_unused_fd(file_fd
);
188 void lttng_abi_tracer_version(struct lttng_kernel_tracer_version
*v
)
190 v
->major
= LTTNG_MODULES_MAJOR_VERSION
;
191 v
->minor
= LTTNG_MODULES_MINOR_VERSION
;
192 v
->patchlevel
= LTTNG_MODULES_PATCHLEVEL_VERSION
;
196 void lttng_abi_tracer_abi_version(struct lttng_kernel_tracer_abi_version
*v
)
198 v
->major
= LTTNG_MODULES_ABI_MAJOR_VERSION
;
199 v
->minor
= LTTNG_MODULES_ABI_MINOR_VERSION
;
203 long lttng_abi_add_context(struct file
*file
,
204 struct lttng_kernel_context
*context_param
,
205 struct lttng_ctx
**ctx
, struct lttng_session
*session
)
208 if (session
->been_active
)
211 switch (context_param
->ctx
) {
212 case LTTNG_KERNEL_CONTEXT_PID
:
213 return lttng_add_pid_to_ctx(ctx
);
214 case LTTNG_KERNEL_CONTEXT_PRIO
:
215 return lttng_add_prio_to_ctx(ctx
);
216 case LTTNG_KERNEL_CONTEXT_NICE
:
217 return lttng_add_nice_to_ctx(ctx
);
218 case LTTNG_KERNEL_CONTEXT_VPID
:
219 return lttng_add_vpid_to_ctx(ctx
);
220 case LTTNG_KERNEL_CONTEXT_TID
:
221 return lttng_add_tid_to_ctx(ctx
);
222 case LTTNG_KERNEL_CONTEXT_VTID
:
223 return lttng_add_vtid_to_ctx(ctx
);
224 case LTTNG_KERNEL_CONTEXT_PPID
:
225 return lttng_add_ppid_to_ctx(ctx
);
226 case LTTNG_KERNEL_CONTEXT_VPPID
:
227 return lttng_add_vppid_to_ctx(ctx
);
228 case LTTNG_KERNEL_CONTEXT_PERF_COUNTER
:
229 context_param
->u
.perf_counter
.name
[LTTNG_KERNEL_SYM_NAME_LEN
- 1] = '\0';
230 return lttng_add_perf_counter_to_ctx(context_param
->u
.perf_counter
.type
,
231 context_param
->u
.perf_counter
.config
,
232 context_param
->u
.perf_counter
.name
,
234 case LTTNG_KERNEL_CONTEXT_PROCNAME
:
235 return lttng_add_procname_to_ctx(ctx
);
236 case LTTNG_KERNEL_CONTEXT_HOSTNAME
:
237 return lttng_add_hostname_to_ctx(ctx
);
238 case LTTNG_KERNEL_CONTEXT_CPU_ID
:
239 return lttng_add_cpu_id_to_ctx(ctx
);
240 case LTTNG_KERNEL_CONTEXT_INTERRUPTIBLE
:
241 return lttng_add_interruptible_to_ctx(ctx
);
242 case LTTNG_KERNEL_CONTEXT_NEED_RESCHEDULE
:
243 return lttng_add_need_reschedule_to_ctx(ctx
);
244 case LTTNG_KERNEL_CONTEXT_PREEMPTIBLE
:
245 return lttng_add_preemptible_to_ctx(ctx
);
246 case LTTNG_KERNEL_CONTEXT_MIGRATABLE
:
247 return lttng_add_migratable_to_ctx(ctx
);
254 * lttng_ioctl - lttng syscall through ioctl
260 * This ioctl implements lttng commands:
261 * LTTNG_KERNEL_SESSION
262 * Returns a LTTng trace session file descriptor
263 * LTTNG_KERNEL_TRACER_VERSION
264 * Returns the LTTng kernel tracer version
265 * LTTNG_KERNEL_TRACEPOINT_LIST
266 * Returns a file descriptor listing available tracepoints
267 * LTTNG_KERNEL_WAIT_QUIESCENT
268 * Returns after all previously running probes have completed
269 * LTTNG_KERNEL_TRACER_ABI_VERSION
270 * Returns the LTTng kernel tracer ABI version
272 * The returned session will be deleted when its file descriptor is closed.
275 long lttng_ioctl(struct file
*file
, unsigned int cmd
, unsigned long arg
)
278 case LTTNG_KERNEL_OLD_SESSION
:
279 case LTTNG_KERNEL_SESSION
:
280 return lttng_abi_create_session();
281 case LTTNG_KERNEL_OLD_TRACER_VERSION
:
283 struct lttng_kernel_tracer_version v
;
284 struct lttng_kernel_old_tracer_version oldv
;
285 struct lttng_kernel_old_tracer_version
*uversion
=
286 (struct lttng_kernel_old_tracer_version __user
*) arg
;
288 lttng_abi_tracer_version(&v
);
289 oldv
.major
= v
.major
;
290 oldv
.minor
= v
.minor
;
291 oldv
.patchlevel
= v
.patchlevel
;
293 if (copy_to_user(uversion
, &oldv
, sizeof(oldv
)))
297 case LTTNG_KERNEL_TRACER_VERSION
:
299 struct lttng_kernel_tracer_version version
;
300 struct lttng_kernel_tracer_version
*uversion
=
301 (struct lttng_kernel_tracer_version __user
*) arg
;
303 lttng_abi_tracer_version(&version
);
305 if (copy_to_user(uversion
, &version
, sizeof(version
)))
309 case LTTNG_KERNEL_TRACER_ABI_VERSION
:
311 struct lttng_kernel_tracer_abi_version version
;
312 struct lttng_kernel_tracer_abi_version
*uversion
=
313 (struct lttng_kernel_tracer_abi_version __user
*) arg
;
315 lttng_abi_tracer_abi_version(&version
);
317 if (copy_to_user(uversion
, &version
, sizeof(version
)))
321 case LTTNG_KERNEL_OLD_TRACEPOINT_LIST
:
322 case LTTNG_KERNEL_TRACEPOINT_LIST
:
323 return lttng_abi_tracepoint_list();
324 case LTTNG_KERNEL_SYSCALL_LIST
:
325 return lttng_abi_syscall_list();
326 case LTTNG_KERNEL_OLD_WAIT_QUIESCENT
:
327 case LTTNG_KERNEL_WAIT_QUIESCENT
:
330 case LTTNG_KERNEL_OLD_CALIBRATE
:
332 struct lttng_kernel_old_calibrate __user
*ucalibrate
=
333 (struct lttng_kernel_old_calibrate __user
*) arg
;
334 struct lttng_kernel_old_calibrate old_calibrate
;
335 struct lttng_kernel_calibrate calibrate
;
338 if (copy_from_user(&old_calibrate
, ucalibrate
, sizeof(old_calibrate
)))
340 calibrate
.type
= old_calibrate
.type
;
341 ret
= lttng_calibrate(&calibrate
);
342 if (copy_to_user(ucalibrate
, &old_calibrate
, sizeof(old_calibrate
)))
346 case LTTNG_KERNEL_CALIBRATE
:
348 struct lttng_kernel_calibrate __user
*ucalibrate
=
349 (struct lttng_kernel_calibrate __user
*) arg
;
350 struct lttng_kernel_calibrate calibrate
;
353 if (copy_from_user(&calibrate
, ucalibrate
, sizeof(calibrate
)))
355 ret
= lttng_calibrate(&calibrate
);
356 if (copy_to_user(ucalibrate
, &calibrate
, sizeof(calibrate
)))
365 static const struct file_operations lttng_fops
= {
366 .owner
= THIS_MODULE
,
367 .unlocked_ioctl
= lttng_ioctl
,
369 .compat_ioctl
= lttng_ioctl
,
374 int lttng_abi_create_channel(struct file
*session_file
,
375 struct lttng_kernel_channel
*chan_param
,
376 enum channel_type channel_type
)
378 struct lttng_session
*session
= session_file
->private_data
;
379 const struct file_operations
*fops
= NULL
;
380 const char *transport_name
;
381 struct lttng_channel
*chan
;
382 struct file
*chan_file
;
386 chan_fd
= lttng_get_unused_fd();
391 switch (channel_type
) {
392 case PER_CPU_CHANNEL
:
393 fops
= <tng_channel_fops
;
395 case METADATA_CHANNEL
:
396 fops
= <tng_metadata_fops
;
400 chan_file
= anon_inode_getfile("[lttng_channel]",
403 if (IS_ERR(chan_file
)) {
404 ret
= PTR_ERR(chan_file
);
407 switch (channel_type
) {
408 case PER_CPU_CHANNEL
:
409 if (chan_param
->output
== LTTNG_KERNEL_SPLICE
) {
410 transport_name
= chan_param
->overwrite
?
411 "relay-overwrite" : "relay-discard";
412 } else if (chan_param
->output
== LTTNG_KERNEL_MMAP
) {
413 transport_name
= chan_param
->overwrite
?
414 "relay-overwrite-mmap" : "relay-discard-mmap";
419 case METADATA_CHANNEL
:
420 if (chan_param
->output
== LTTNG_KERNEL_SPLICE
)
421 transport_name
= "relay-metadata";
422 else if (chan_param
->output
== LTTNG_KERNEL_MMAP
)
423 transport_name
= "relay-metadata-mmap";
428 transport_name
= "<unknown>";
431 if (atomic_long_add_unless(&session_file
->f_count
,
432 1, INT_MAX
) == INT_MAX
) {
436 * We tolerate no failure path after channel creation. It will stay
437 * invariant for the rest of the session.
439 chan
= lttng_channel_create(session
, transport_name
, NULL
,
440 chan_param
->subbuf_size
,
441 chan_param
->num_subbuf
,
442 chan_param
->switch_timer_interval
,
443 chan_param
->read_timer_interval
,
449 chan
->file
= chan_file
;
450 chan_file
->private_data
= chan
;
451 fd_install(chan_fd
, chan_file
);
456 atomic_long_dec(&session_file
->f_count
);
460 put_unused_fd(chan_fd
);
466 * lttng_session_ioctl - lttng session fd ioctl
472 * This ioctl implements lttng commands:
473 * LTTNG_KERNEL_CHANNEL
474 * Returns a LTTng channel file descriptor
475 * LTTNG_KERNEL_ENABLE
476 * Enables tracing for a session (weak enable)
477 * LTTNG_KERNEL_DISABLE
478 * Disables tracing for a session (strong disable)
479 * LTTNG_KERNEL_METADATA
480 * Returns a LTTng metadata file descriptor
481 * LTTNG_KERNEL_SESSION_TRACK_PID
482 * Add PID to session tracker
483 * LTTNG_KERNEL_SESSION_UNTRACK_PID
484 * Remove PID from session tracker
486 * The returned channel will be deleted when its file descriptor is closed.
489 long lttng_session_ioctl(struct file
*file
, unsigned int cmd
, unsigned long arg
)
491 struct lttng_session
*session
= file
->private_data
;
494 case LTTNG_KERNEL_OLD_CHANNEL
:
496 struct lttng_kernel_channel chan_param
;
497 struct lttng_kernel_old_channel old_chan_param
;
499 if (copy_from_user(&old_chan_param
,
500 (struct lttng_kernel_old_channel __user
*) arg
,
501 sizeof(struct lttng_kernel_old_channel
)))
503 chan_param
.overwrite
= old_chan_param
.overwrite
;
504 chan_param
.subbuf_size
= old_chan_param
.subbuf_size
;
505 chan_param
.num_subbuf
= old_chan_param
.num_subbuf
;
506 chan_param
.switch_timer_interval
= old_chan_param
.switch_timer_interval
;
507 chan_param
.read_timer_interval
= old_chan_param
.read_timer_interval
;
508 chan_param
.output
= old_chan_param
.output
;
510 return lttng_abi_create_channel(file
, &chan_param
,
513 case LTTNG_KERNEL_CHANNEL
:
515 struct lttng_kernel_channel chan_param
;
517 if (copy_from_user(&chan_param
,
518 (struct lttng_kernel_channel __user
*) arg
,
519 sizeof(struct lttng_kernel_channel
)))
521 return lttng_abi_create_channel(file
, &chan_param
,
524 case LTTNG_KERNEL_OLD_SESSION_START
:
525 case LTTNG_KERNEL_OLD_ENABLE
:
526 case LTTNG_KERNEL_SESSION_START
:
527 case LTTNG_KERNEL_ENABLE
:
528 return lttng_session_enable(session
);
529 case LTTNG_KERNEL_OLD_SESSION_STOP
:
530 case LTTNG_KERNEL_OLD_DISABLE
:
531 case LTTNG_KERNEL_SESSION_STOP
:
532 case LTTNG_KERNEL_DISABLE
:
533 return lttng_session_disable(session
);
534 case LTTNG_KERNEL_OLD_METADATA
:
536 struct lttng_kernel_channel chan_param
;
537 struct lttng_kernel_old_channel old_chan_param
;
539 if (copy_from_user(&old_chan_param
,
540 (struct lttng_kernel_old_channel __user
*) arg
,
541 sizeof(struct lttng_kernel_old_channel
)))
543 chan_param
.overwrite
= old_chan_param
.overwrite
;
544 chan_param
.subbuf_size
= old_chan_param
.subbuf_size
;
545 chan_param
.num_subbuf
= old_chan_param
.num_subbuf
;
546 chan_param
.switch_timer_interval
= old_chan_param
.switch_timer_interval
;
547 chan_param
.read_timer_interval
= old_chan_param
.read_timer_interval
;
548 chan_param
.output
= old_chan_param
.output
;
550 return lttng_abi_create_channel(file
, &chan_param
,
553 case LTTNG_KERNEL_METADATA
:
555 struct lttng_kernel_channel chan_param
;
557 if (copy_from_user(&chan_param
,
558 (struct lttng_kernel_channel __user
*) arg
,
559 sizeof(struct lttng_kernel_channel
)))
561 return lttng_abi_create_channel(file
, &chan_param
,
564 case LTTNG_KERNEL_SESSION_TRACK_PID
:
565 return lttng_session_track_pid(session
, (int) arg
);
566 case LTTNG_KERNEL_SESSION_UNTRACK_PID
:
567 return lttng_session_untrack_pid(session
, (int) arg
);
568 case LTTNG_KERNEL_SESSION_LIST_TRACKER_PIDS
:
569 return lttng_session_list_tracker_pids(session
);
570 case LTTNG_KERNEL_SESSION_METADATA_REGEN
:
571 return lttng_session_metadata_regenerate(session
);
572 case LTTNG_KERNEL_SESSION_STATEDUMP
:
573 return lttng_session_statedump(session
);
580 * Called when the last file reference is dropped.
582 * Big fat note: channels and events are invariant for the whole session after
583 * their creation. So this session destruction also destroys all channel and
584 * event structures specific to this session (they are not destroyed when their
585 * individual file is released).
588 int lttng_session_release(struct inode
*inode
, struct file
*file
)
590 struct lttng_session
*session
= file
->private_data
;
593 lttng_session_destroy(session
);
597 static const struct file_operations lttng_session_fops
= {
598 .owner
= THIS_MODULE
,
599 .release
= lttng_session_release
,
600 .unlocked_ioctl
= lttng_session_ioctl
,
602 .compat_ioctl
= lttng_session_ioctl
,
607 * lttng_metadata_ring_buffer_poll - LTTng ring buffer poll file operation
611 * Handles the poll operations for the metadata channels.
614 unsigned int lttng_metadata_ring_buffer_poll(struct file
*filp
,
617 struct lttng_metadata_stream
*stream
= filp
->private_data
;
618 struct lib_ring_buffer
*buf
= stream
->priv
;
620 unsigned int mask
= 0;
622 if (filp
->f_mode
& FMODE_READ
) {
623 poll_wait_set_exclusive(wait
);
624 poll_wait(filp
, &stream
->read_wait
, wait
);
626 finalized
= stream
->finalized
;
629 * lib_ring_buffer_is_finalized() contains a smp_rmb()
630 * ordering finalized load before offsets loads.
632 WARN_ON(atomic_long_read(&buf
->active_readers
) != 1);
637 mutex_lock(&stream
->metadata_cache
->lock
);
638 if (stream
->metadata_cache
->metadata_written
>
639 stream
->metadata_out
)
641 mutex_unlock(&stream
->metadata_cache
->lock
);
648 void lttng_metadata_ring_buffer_ioctl_put_next_subbuf(struct file
*filp
,
649 unsigned int cmd
, unsigned long arg
)
651 struct lttng_metadata_stream
*stream
= filp
->private_data
;
653 stream
->metadata_out
= stream
->metadata_in
;
657 long lttng_metadata_ring_buffer_ioctl(struct file
*filp
,
658 unsigned int cmd
, unsigned long arg
)
661 struct lttng_metadata_stream
*stream
= filp
->private_data
;
662 struct lib_ring_buffer
*buf
= stream
->priv
;
665 case RING_BUFFER_GET_NEXT_SUBBUF
:
667 struct lttng_metadata_stream
*stream
= filp
->private_data
;
668 struct lib_ring_buffer
*buf
= stream
->priv
;
669 struct channel
*chan
= buf
->backend
.chan
;
671 ret
= lttng_metadata_output_channel(stream
, chan
);
673 lib_ring_buffer_switch_slow(buf
, SWITCH_ACTIVE
);
679 case RING_BUFFER_GET_SUBBUF
:
682 * Random access is not allowed for metadata channel.
686 case RING_BUFFER_FLUSH
:
688 struct lttng_metadata_stream
*stream
= filp
->private_data
;
689 struct lib_ring_buffer
*buf
= stream
->priv
;
690 struct channel
*chan
= buf
->backend
.chan
;
693 * Before doing the actual ring buffer flush, write up to one
694 * packet of metadata in the ring buffer.
696 ret
= lttng_metadata_output_channel(stream
, chan
);
701 case RING_BUFFER_GET_METADATA_VERSION
:
703 struct lttng_metadata_stream
*stream
= filp
->private_data
;
705 return put_u64(stream
->version
, arg
);
707 case RING_BUFFER_SNAPSHOT
:
710 * Force the buffer to quiescent so the ring buffer
711 * don't attempt to perform a SWITCH_FLUSH, which would
712 * desynchronize the client accounting of the amount of
713 * data available in the buffer from the ring buffer
716 buf
->quiescent
= true;
722 /* PUT_SUBBUF is the one from lib ring buffer, unmodified. */
724 /* Performing lib ring buffer ioctl after our own. */
725 ret
= lib_ring_buffer_ioctl(filp
, cmd
, arg
, buf
);
730 case RING_BUFFER_PUT_NEXT_SUBBUF
:
732 lttng_metadata_ring_buffer_ioctl_put_next_subbuf(filp
,
745 long lttng_metadata_ring_buffer_compat_ioctl(struct file
*filp
,
746 unsigned int cmd
, unsigned long arg
)
749 struct lttng_metadata_stream
*stream
= filp
->private_data
;
750 struct lib_ring_buffer
*buf
= stream
->priv
;
753 case RING_BUFFER_GET_NEXT_SUBBUF
:
755 struct lttng_metadata_stream
*stream
= filp
->private_data
;
756 struct lib_ring_buffer
*buf
= stream
->priv
;
757 struct channel
*chan
= buf
->backend
.chan
;
759 ret
= lttng_metadata_output_channel(stream
, chan
);
761 lib_ring_buffer_switch_slow(buf
, SWITCH_ACTIVE
);
767 case RING_BUFFER_GET_SUBBUF
:
770 * Random access is not allowed for metadata channel.
774 case RING_BUFFER_FLUSH
:
776 struct lttng_metadata_stream
*stream
= filp
->private_data
;
777 struct lib_ring_buffer
*buf
= stream
->priv
;
778 struct channel
*chan
= buf
->backend
.chan
;
781 * Before doing the actual ring buffer flush, write up to one
782 * packet of metadata in the ring buffer.
784 ret
= lttng_metadata_output_channel(stream
, chan
);
789 case RING_BUFFER_GET_METADATA_VERSION
:
791 struct lttng_metadata_stream
*stream
= filp
->private_data
;
793 return put_u64(stream
->version
, arg
);
795 case RING_BUFFER_SNAPSHOT
:
798 * Force the buffer to quiescent so the ring buffer
799 * don't attempt to perform a SWITCH_FLUSH, which would
800 * desynchronize the client accounting of the amount of
801 * data available in the buffer from the ring buffer
804 buf
->quiescent
= true;
810 /* PUT_SUBBUF is the one from lib ring buffer, unmodified. */
812 /* Performing lib ring buffer ioctl after our own. */
813 ret
= lib_ring_buffer_compat_ioctl(filp
, cmd
, arg
, buf
);
818 case RING_BUFFER_PUT_NEXT_SUBBUF
:
820 lttng_metadata_ring_buffer_ioctl_put_next_subbuf(filp
,
833 * This is not used by anonymous file descriptors. This code is left
834 * there if we ever want to implement an inode with open() operation.
837 int lttng_metadata_ring_buffer_open(struct inode
*inode
, struct file
*file
)
839 struct lttng_metadata_stream
*stream
= inode
->i_private
;
840 struct lib_ring_buffer
*buf
= stream
->priv
;
842 file
->private_data
= buf
;
844 * Since life-time of metadata cache differs from that of
845 * session, we need to keep our own reference on the transport.
847 if (!try_module_get(stream
->transport
->owner
)) {
848 printk(KERN_WARNING
"LTT : Can't lock transport module.\n");
851 return lib_ring_buffer_open(inode
, file
, buf
);
855 int lttng_metadata_ring_buffer_release(struct inode
*inode
, struct file
*file
)
857 struct lttng_metadata_stream
*stream
= file
->private_data
;
858 struct lib_ring_buffer
*buf
= stream
->priv
;
860 kref_put(&stream
->metadata_cache
->refcount
, metadata_cache_destroy
);
861 module_put(stream
->transport
->owner
);
862 return lib_ring_buffer_release(inode
, file
, buf
);
866 ssize_t
lttng_metadata_ring_buffer_splice_read(struct file
*in
, loff_t
*ppos
,
867 struct pipe_inode_info
*pipe
, size_t len
,
870 struct lttng_metadata_stream
*stream
= in
->private_data
;
871 struct lib_ring_buffer
*buf
= stream
->priv
;
873 return lib_ring_buffer_splice_read(in
, ppos
, pipe
, len
,
878 int lttng_metadata_ring_buffer_mmap(struct file
*filp
,
879 struct vm_area_struct
*vma
)
881 struct lttng_metadata_stream
*stream
= filp
->private_data
;
882 struct lib_ring_buffer
*buf
= stream
->priv
;
884 return lib_ring_buffer_mmap(filp
, vma
, buf
);
888 const struct file_operations lttng_metadata_ring_buffer_file_operations
= {
889 .owner
= THIS_MODULE
,
890 .open
= lttng_metadata_ring_buffer_open
,
891 .release
= lttng_metadata_ring_buffer_release
,
892 .poll
= lttng_metadata_ring_buffer_poll
,
893 .splice_read
= lttng_metadata_ring_buffer_splice_read
,
894 .mmap
= lttng_metadata_ring_buffer_mmap
,
895 .unlocked_ioctl
= lttng_metadata_ring_buffer_ioctl
,
896 .llseek
= vfs_lib_ring_buffer_no_llseek
,
898 .compat_ioctl
= lttng_metadata_ring_buffer_compat_ioctl
,
903 int lttng_abi_create_stream_fd(struct file
*channel_file
, void *stream_priv
,
904 const struct file_operations
*fops
)
907 struct file
*stream_file
;
909 stream_fd
= lttng_get_unused_fd();
914 stream_file
= anon_inode_getfile("[lttng_stream]", fops
,
915 stream_priv
, O_RDWR
);
916 if (IS_ERR(stream_file
)) {
917 ret
= PTR_ERR(stream_file
);
921 * OPEN_FMODE, called within anon_inode_getfile/alloc_file, don't honor
922 * FMODE_LSEEK, FMODE_PREAD nor FMODE_PWRITE. We need to read from this
923 * file descriptor, so we set FMODE_PREAD here.
925 stream_file
->f_mode
|= FMODE_PREAD
;
926 fd_install(stream_fd
, stream_file
);
928 * The stream holds a reference to the channel within the generic ring
929 * buffer library, so no need to hold a refcount on the channel and
930 * session files here.
935 put_unused_fd(stream_fd
);
941 int lttng_abi_open_stream(struct file
*channel_file
)
943 struct lttng_channel
*channel
= channel_file
->private_data
;
944 struct lib_ring_buffer
*buf
;
948 buf
= channel
->ops
->buffer_read_open(channel
->chan
);
953 ret
= lttng_abi_create_stream_fd(channel_file
, stream_priv
,
954 <tng_stream_ring_buffer_file_operations
);
961 channel
->ops
->buffer_read_close(buf
);
966 int lttng_abi_open_metadata_stream(struct file
*channel_file
)
968 struct lttng_channel
*channel
= channel_file
->private_data
;
969 struct lttng_session
*session
= channel
->session
;
970 struct lib_ring_buffer
*buf
;
972 struct lttng_metadata_stream
*metadata_stream
;
975 buf
= channel
->ops
->buffer_read_open(channel
->chan
);
979 metadata_stream
= kzalloc(sizeof(struct lttng_metadata_stream
),
981 if (!metadata_stream
) {
985 metadata_stream
->metadata_cache
= session
->metadata_cache
;
986 init_waitqueue_head(&metadata_stream
->read_wait
);
987 metadata_stream
->priv
= buf
;
988 stream_priv
= metadata_stream
;
989 metadata_stream
->transport
= channel
->transport
;
992 * Since life-time of metadata cache differs from that of
993 * session, we need to keep our own reference on the transport.
995 if (!try_module_get(metadata_stream
->transport
->owner
)) {
996 printk(KERN_WARNING
"LTT : Can't lock transport module.\n");
1001 if (!lttng_kref_get(&session
->metadata_cache
->refcount
)) {
1006 ret
= lttng_abi_create_stream_fd(channel_file
, stream_priv
,
1007 <tng_metadata_ring_buffer_file_operations
);
1011 list_add(&metadata_stream
->list
,
1012 &session
->metadata_cache
->metadata_stream
);
1016 kref_put(&session
->metadata_cache
->refcount
, metadata_cache_destroy
);
1018 module_put(metadata_stream
->transport
->owner
);
1020 kfree(metadata_stream
);
1022 channel
->ops
->buffer_read_close(buf
);
1027 int lttng_abi_create_event(struct file
*channel_file
,
1028 struct lttng_kernel_event
*event_param
)
1030 struct lttng_channel
*channel
= channel_file
->private_data
;
1032 struct file
*event_file
;
1035 event_param
->name
[LTTNG_KERNEL_SYM_NAME_LEN
- 1] = '\0';
1036 switch (event_param
->instrumentation
) {
1037 case LTTNG_KERNEL_KRETPROBE
:
1038 event_param
->u
.kretprobe
.symbol_name
[LTTNG_KERNEL_SYM_NAME_LEN
- 1] = '\0';
1040 case LTTNG_KERNEL_KPROBE
:
1041 event_param
->u
.kprobe
.symbol_name
[LTTNG_KERNEL_SYM_NAME_LEN
- 1] = '\0';
1043 case LTTNG_KERNEL_FUNCTION
:
1044 event_param
->u
.ftrace
.symbol_name
[LTTNG_KERNEL_SYM_NAME_LEN
- 1] = '\0';
1049 event_fd
= lttng_get_unused_fd();
1054 event_file
= anon_inode_getfile("[lttng_event]",
1057 if (IS_ERR(event_file
)) {
1058 ret
= PTR_ERR(event_file
);
1061 /* The event holds a reference on the channel */
1062 if (atomic_long_add_unless(&channel_file
->f_count
,
1063 1, INT_MAX
) == INT_MAX
) {
1065 goto refcount_error
;
1067 if (event_param
->instrumentation
== LTTNG_KERNEL_TRACEPOINT
1068 || event_param
->instrumentation
== LTTNG_KERNEL_SYSCALL
) {
1069 struct lttng_enabler
*enabler
;
1071 if (event_param
->name
[strlen(event_param
->name
) - 1] == '*') {
1072 enabler
= lttng_enabler_create(LTTNG_ENABLER_WILDCARD
,
1073 event_param
, channel
);
1075 enabler
= lttng_enabler_create(LTTNG_ENABLER_NAME
,
1076 event_param
, channel
);
1080 struct lttng_event
*event
;
1083 * We tolerate no failure path after event creation. It
1084 * will stay invariant for the rest of the session.
1086 event
= lttng_event_create(channel
, event_param
,
1088 event_param
->instrumentation
);
1089 WARN_ON_ONCE(!event
);
1090 if (IS_ERR(event
)) {
1091 ret
= PTR_ERR(event
);
1096 event_file
->private_data
= priv
;
1097 fd_install(event_fd
, event_file
);
1101 atomic_long_dec(&channel_file
->f_count
);
1105 put_unused_fd(event_fd
);
1111 * lttng_channel_ioctl - lttng syscall through ioctl
1117 * This ioctl implements lttng commands:
1118 * LTTNG_KERNEL_STREAM
1119 * Returns an event stream file descriptor or failure.
1120 * (typically, one event stream records events from one CPU)
1121 * LTTNG_KERNEL_EVENT
1122 * Returns an event file descriptor or failure.
1123 * LTTNG_KERNEL_CONTEXT
1124 * Prepend a context field to each event in the channel
1125 * LTTNG_KERNEL_ENABLE
1126 * Enable recording for events in this channel (weak enable)
1127 * LTTNG_KERNEL_DISABLE
1128 * Disable recording for events in this channel (strong disable)
1130 * Channel and event file descriptors also hold a reference on the session.
1133 long lttng_channel_ioctl(struct file
*file
, unsigned int cmd
, unsigned long arg
)
1135 struct lttng_channel
*channel
= file
->private_data
;
1138 case LTTNG_KERNEL_OLD_STREAM
:
1139 case LTTNG_KERNEL_STREAM
:
1140 return lttng_abi_open_stream(file
);
1141 case LTTNG_KERNEL_OLD_EVENT
:
1143 struct lttng_kernel_event
*uevent_param
;
1144 struct lttng_kernel_old_event
*old_uevent_param
;
1147 uevent_param
= kmalloc(sizeof(struct lttng_kernel_event
),
1149 if (!uevent_param
) {
1153 old_uevent_param
= kmalloc(
1154 sizeof(struct lttng_kernel_old_event
),
1156 if (!old_uevent_param
) {
1158 goto old_event_error_free_param
;
1160 if (copy_from_user(old_uevent_param
,
1161 (struct lttng_kernel_old_event __user
*) arg
,
1162 sizeof(struct lttng_kernel_old_event
))) {
1164 goto old_event_error_free_old_param
;
1167 memcpy(uevent_param
->name
, old_uevent_param
->name
,
1168 sizeof(uevent_param
->name
));
1169 uevent_param
->instrumentation
=
1170 old_uevent_param
->instrumentation
;
1172 switch (old_uevent_param
->instrumentation
) {
1173 case LTTNG_KERNEL_KPROBE
:
1174 uevent_param
->u
.kprobe
.addr
=
1175 old_uevent_param
->u
.kprobe
.addr
;
1176 uevent_param
->u
.kprobe
.offset
=
1177 old_uevent_param
->u
.kprobe
.offset
;
1178 memcpy(uevent_param
->u
.kprobe
.symbol_name
,
1179 old_uevent_param
->u
.kprobe
.symbol_name
,
1180 sizeof(uevent_param
->u
.kprobe
.symbol_name
));
1182 case LTTNG_KERNEL_KRETPROBE
:
1183 uevent_param
->u
.kretprobe
.addr
=
1184 old_uevent_param
->u
.kretprobe
.addr
;
1185 uevent_param
->u
.kretprobe
.offset
=
1186 old_uevent_param
->u
.kretprobe
.offset
;
1187 memcpy(uevent_param
->u
.kretprobe
.symbol_name
,
1188 old_uevent_param
->u
.kretprobe
.symbol_name
,
1189 sizeof(uevent_param
->u
.kretprobe
.symbol_name
));
1191 case LTTNG_KERNEL_FUNCTION
:
1192 memcpy(uevent_param
->u
.ftrace
.symbol_name
,
1193 old_uevent_param
->u
.ftrace
.symbol_name
,
1194 sizeof(uevent_param
->u
.ftrace
.symbol_name
));
1199 ret
= lttng_abi_create_event(file
, uevent_param
);
1201 old_event_error_free_old_param
:
1202 kfree(old_uevent_param
);
1203 old_event_error_free_param
:
1204 kfree(uevent_param
);
1208 case LTTNG_KERNEL_EVENT
:
1210 struct lttng_kernel_event uevent_param
;
1212 if (copy_from_user(&uevent_param
,
1213 (struct lttng_kernel_event __user
*) arg
,
1214 sizeof(uevent_param
)))
1216 return lttng_abi_create_event(file
, &uevent_param
);
1218 case LTTNG_KERNEL_OLD_CONTEXT
:
1220 struct lttng_kernel_context
*ucontext_param
;
1221 struct lttng_kernel_old_context
*old_ucontext_param
;
1224 ucontext_param
= kmalloc(sizeof(struct lttng_kernel_context
),
1226 if (!ucontext_param
) {
1230 old_ucontext_param
= kmalloc(sizeof(struct lttng_kernel_old_context
),
1232 if (!old_ucontext_param
) {
1234 goto old_ctx_error_free_param
;
1237 if (copy_from_user(old_ucontext_param
,
1238 (struct lttng_kernel_old_context __user
*) arg
,
1239 sizeof(struct lttng_kernel_old_context
))) {
1241 goto old_ctx_error_free_old_param
;
1243 ucontext_param
->ctx
= old_ucontext_param
->ctx
;
1244 memcpy(ucontext_param
->padding
, old_ucontext_param
->padding
,
1245 sizeof(ucontext_param
->padding
));
1246 /* only type that uses the union */
1247 if (old_ucontext_param
->ctx
== LTTNG_KERNEL_CONTEXT_PERF_COUNTER
) {
1248 ucontext_param
->u
.perf_counter
.type
=
1249 old_ucontext_param
->u
.perf_counter
.type
;
1250 ucontext_param
->u
.perf_counter
.config
=
1251 old_ucontext_param
->u
.perf_counter
.config
;
1252 memcpy(ucontext_param
->u
.perf_counter
.name
,
1253 old_ucontext_param
->u
.perf_counter
.name
,
1254 sizeof(ucontext_param
->u
.perf_counter
.name
));
1257 ret
= lttng_abi_add_context(file
,
1259 &channel
->ctx
, channel
->session
);
1261 old_ctx_error_free_old_param
:
1262 kfree(old_ucontext_param
);
1263 old_ctx_error_free_param
:
1264 kfree(ucontext_param
);
1268 case LTTNG_KERNEL_CONTEXT
:
1270 struct lttng_kernel_context ucontext_param
;
1272 if (copy_from_user(&ucontext_param
,
1273 (struct lttng_kernel_context __user
*) arg
,
1274 sizeof(ucontext_param
)))
1276 return lttng_abi_add_context(file
,
1278 &channel
->ctx
, channel
->session
);
1280 case LTTNG_KERNEL_OLD_ENABLE
:
1281 case LTTNG_KERNEL_ENABLE
:
1282 return lttng_channel_enable(channel
);
1283 case LTTNG_KERNEL_OLD_DISABLE
:
1284 case LTTNG_KERNEL_DISABLE
:
1285 return lttng_channel_disable(channel
);
1286 case LTTNG_KERNEL_SYSCALL_MASK
:
1287 return lttng_channel_syscall_mask(channel
,
1288 (struct lttng_kernel_syscall_mask __user
*) arg
);
1290 return -ENOIOCTLCMD
;
1296 * lttng_metadata_ioctl - lttng syscall through ioctl
1302 * This ioctl implements lttng commands:
1303 * LTTNG_KERNEL_STREAM
1304 * Returns an event stream file descriptor or failure.
1306 * Channel and event file descriptors also hold a reference on the session.
1309 long lttng_metadata_ioctl(struct file
*file
, unsigned int cmd
, unsigned long arg
)
1312 case LTTNG_KERNEL_OLD_STREAM
:
1313 case LTTNG_KERNEL_STREAM
:
1314 return lttng_abi_open_metadata_stream(file
);
1316 return -ENOIOCTLCMD
;
1321 * lttng_channel_poll - lttng stream addition/removal monitoring
1326 unsigned int lttng_channel_poll(struct file
*file
, poll_table
*wait
)
1328 struct lttng_channel
*channel
= file
->private_data
;
1329 unsigned int mask
= 0;
1331 if (file
->f_mode
& FMODE_READ
) {
1332 poll_wait_set_exclusive(wait
);
1333 poll_wait(file
, channel
->ops
->get_hp_wait_queue(channel
->chan
),
1336 if (channel
->ops
->is_disabled(channel
->chan
))
1338 if (channel
->ops
->is_finalized(channel
->chan
))
1340 if (channel
->ops
->buffer_has_read_closed_stream(channel
->chan
))
1341 return POLLIN
| POLLRDNORM
;
1349 int lttng_channel_release(struct inode
*inode
, struct file
*file
)
1351 struct lttng_channel
*channel
= file
->private_data
;
1354 fput(channel
->session
->file
);
1359 int lttng_metadata_channel_release(struct inode
*inode
, struct file
*file
)
1361 struct lttng_channel
*channel
= file
->private_data
;
1364 fput(channel
->session
->file
);
1365 lttng_metadata_channel_destroy(channel
);
1371 static const struct file_operations lttng_channel_fops
= {
1372 .owner
= THIS_MODULE
,
1373 .release
= lttng_channel_release
,
1374 .poll
= lttng_channel_poll
,
1375 .unlocked_ioctl
= lttng_channel_ioctl
,
1376 #ifdef CONFIG_COMPAT
1377 .compat_ioctl
= lttng_channel_ioctl
,
1381 static const struct file_operations lttng_metadata_fops
= {
1382 .owner
= THIS_MODULE
,
1383 .release
= lttng_metadata_channel_release
,
1384 .unlocked_ioctl
= lttng_metadata_ioctl
,
1385 #ifdef CONFIG_COMPAT
1386 .compat_ioctl
= lttng_metadata_ioctl
,
1391 * lttng_event_ioctl - lttng syscall through ioctl
1397 * This ioctl implements lttng commands:
1398 * LTTNG_KERNEL_CONTEXT
1399 * Prepend a context field to each record of this event
1400 * LTTNG_KERNEL_ENABLE
1401 * Enable recording for this event (weak enable)
1402 * LTTNG_KERNEL_DISABLE
1403 * Disable recording for this event (strong disable)
1406 long lttng_event_ioctl(struct file
*file
, unsigned int cmd
, unsigned long arg
)
1408 struct lttng_event
*event
;
1409 struct lttng_enabler
*enabler
;
1410 enum lttng_event_type
*evtype
= file
->private_data
;
1413 case LTTNG_KERNEL_OLD_CONTEXT
:
1415 /* Not implemented */
1418 case LTTNG_KERNEL_CONTEXT
:
1420 /* Not implemented */
1423 case LTTNG_KERNEL_OLD_ENABLE
:
1424 case LTTNG_KERNEL_ENABLE
:
1426 case LTTNG_TYPE_EVENT
:
1427 event
= file
->private_data
;
1428 return lttng_event_enable(event
);
1429 case LTTNG_TYPE_ENABLER
:
1430 enabler
= file
->private_data
;
1431 return lttng_enabler_enable(enabler
);
1436 case LTTNG_KERNEL_OLD_DISABLE
:
1437 case LTTNG_KERNEL_DISABLE
:
1439 case LTTNG_TYPE_EVENT
:
1440 event
= file
->private_data
;
1441 return lttng_event_disable(event
);
1442 case LTTNG_TYPE_ENABLER
:
1443 enabler
= file
->private_data
;
1444 return lttng_enabler_disable(enabler
);
1449 case LTTNG_KERNEL_FILTER
:
1451 case LTTNG_TYPE_EVENT
:
1453 case LTTNG_TYPE_ENABLER
:
1455 enabler
= file
->private_data
;
1456 return lttng_enabler_attach_bytecode(enabler
,
1457 (struct lttng_kernel_filter_bytecode __user
*) arg
);
1462 return -ENOIOCTLCMD
;
1467 int lttng_event_release(struct inode
*inode
, struct file
*file
)
1469 struct lttng_event
*event
;
1470 struct lttng_enabler
*enabler
;
1471 enum lttng_event_type
*evtype
= file
->private_data
;
1477 case LTTNG_TYPE_EVENT
:
1478 event
= file
->private_data
;
1480 fput(event
->chan
->file
);
1482 case LTTNG_TYPE_ENABLER
:
1483 enabler
= file
->private_data
;
1485 fput(enabler
->chan
->file
);
1495 /* TODO: filter control ioctl */
1496 static const struct file_operations lttng_event_fops
= {
1497 .owner
= THIS_MODULE
,
1498 .release
= lttng_event_release
,
1499 .unlocked_ioctl
= lttng_event_ioctl
,
1500 #ifdef CONFIG_COMPAT
1501 .compat_ioctl
= lttng_event_ioctl
,
1505 static int put_u64(uint64_t val
, unsigned long arg
)
1507 return put_user(val
, (uint64_t __user
*) arg
);
1510 static long lttng_stream_ring_buffer_ioctl(struct file
*filp
,
1511 unsigned int cmd
, unsigned long arg
)
1513 struct lib_ring_buffer
*buf
= filp
->private_data
;
1514 struct channel
*chan
= buf
->backend
.chan
;
1515 const struct lib_ring_buffer_config
*config
= &chan
->backend
.config
;
1516 const struct lttng_channel_ops
*ops
= chan
->backend
.priv_ops
;
1519 if (atomic_read(&chan
->record_disabled
))
1523 case LTTNG_RING_BUFFER_GET_TIMESTAMP_BEGIN
:
1527 ret
= ops
->timestamp_begin(config
, buf
, &ts
);
1530 return put_u64(ts
, arg
);
1532 case LTTNG_RING_BUFFER_GET_TIMESTAMP_END
:
1536 ret
= ops
->timestamp_end(config
, buf
, &ts
);
1539 return put_u64(ts
, arg
);
1541 case LTTNG_RING_BUFFER_GET_EVENTS_DISCARDED
:
1545 ret
= ops
->events_discarded(config
, buf
, &ed
);
1548 return put_u64(ed
, arg
);
1550 case LTTNG_RING_BUFFER_GET_CONTENT_SIZE
:
1554 ret
= ops
->content_size(config
, buf
, &cs
);
1557 return put_u64(cs
, arg
);
1559 case LTTNG_RING_BUFFER_GET_PACKET_SIZE
:
1563 ret
= ops
->packet_size(config
, buf
, &ps
);
1566 return put_u64(ps
, arg
);
1568 case LTTNG_RING_BUFFER_GET_STREAM_ID
:
1572 ret
= ops
->stream_id(config
, buf
, &si
);
1575 return put_u64(si
, arg
);
1577 case LTTNG_RING_BUFFER_GET_CURRENT_TIMESTAMP
:
1581 ret
= ops
->current_timestamp(config
, buf
, &ts
);
1584 return put_u64(ts
, arg
);
1586 case LTTNG_RING_BUFFER_GET_SEQ_NUM
:
1590 ret
= ops
->sequence_number(config
, buf
, &seq
);
1593 return put_u64(seq
, arg
);
1595 case LTTNG_RING_BUFFER_INSTANCE_ID
:
1599 ret
= ops
->instance_id(config
, buf
, &id
);
1602 return put_u64(id
, arg
);
1605 return lib_ring_buffer_file_operations
.unlocked_ioctl(filp
,
1613 #ifdef CONFIG_COMPAT
1614 static long lttng_stream_ring_buffer_compat_ioctl(struct file
*filp
,
1615 unsigned int cmd
, unsigned long arg
)
1617 struct lib_ring_buffer
*buf
= filp
->private_data
;
1618 struct channel
*chan
= buf
->backend
.chan
;
1619 const struct lib_ring_buffer_config
*config
= &chan
->backend
.config
;
1620 const struct lttng_channel_ops
*ops
= chan
->backend
.priv_ops
;
1623 if (atomic_read(&chan
->record_disabled
))
1627 case LTTNG_RING_BUFFER_COMPAT_GET_TIMESTAMP_BEGIN
:
1631 ret
= ops
->timestamp_begin(config
, buf
, &ts
);
1634 return put_u64(ts
, arg
);
1636 case LTTNG_RING_BUFFER_COMPAT_GET_TIMESTAMP_END
:
1640 ret
= ops
->timestamp_end(config
, buf
, &ts
);
1643 return put_u64(ts
, arg
);
1645 case LTTNG_RING_BUFFER_COMPAT_GET_EVENTS_DISCARDED
:
1649 ret
= ops
->events_discarded(config
, buf
, &ed
);
1652 return put_u64(ed
, arg
);
1654 case LTTNG_RING_BUFFER_COMPAT_GET_CONTENT_SIZE
:
1658 ret
= ops
->content_size(config
, buf
, &cs
);
1661 return put_u64(cs
, arg
);
1663 case LTTNG_RING_BUFFER_COMPAT_GET_PACKET_SIZE
:
1667 ret
= ops
->packet_size(config
, buf
, &ps
);
1670 return put_u64(ps
, arg
);
1672 case LTTNG_RING_BUFFER_COMPAT_GET_STREAM_ID
:
1676 ret
= ops
->stream_id(config
, buf
, &si
);
1679 return put_u64(si
, arg
);
1681 case LTTNG_RING_BUFFER_GET_CURRENT_TIMESTAMP
:
1685 ret
= ops
->current_timestamp(config
, buf
, &ts
);
1688 return put_u64(ts
, arg
);
1690 case LTTNG_RING_BUFFER_COMPAT_GET_SEQ_NUM
:
1694 ret
= ops
->sequence_number(config
, buf
, &seq
);
1697 return put_u64(seq
, arg
);
1699 case LTTNG_RING_BUFFER_COMPAT_INSTANCE_ID
:
1703 ret
= ops
->instance_id(config
, buf
, &id
);
1706 return put_u64(id
, arg
);
1709 return lib_ring_buffer_file_operations
.compat_ioctl(filp
,
1716 #endif /* CONFIG_COMPAT */
1718 static void lttng_stream_override_ring_buffer_fops(void)
1720 lttng_stream_ring_buffer_file_operations
.owner
= THIS_MODULE
;
1721 lttng_stream_ring_buffer_file_operations
.open
=
1722 lib_ring_buffer_file_operations
.open
;
1723 lttng_stream_ring_buffer_file_operations
.release
=
1724 lib_ring_buffer_file_operations
.release
;
1725 lttng_stream_ring_buffer_file_operations
.poll
=
1726 lib_ring_buffer_file_operations
.poll
;
1727 lttng_stream_ring_buffer_file_operations
.splice_read
=
1728 lib_ring_buffer_file_operations
.splice_read
;
1729 lttng_stream_ring_buffer_file_operations
.mmap
=
1730 lib_ring_buffer_file_operations
.mmap
;
1731 lttng_stream_ring_buffer_file_operations
.unlocked_ioctl
=
1732 lttng_stream_ring_buffer_ioctl
;
1733 lttng_stream_ring_buffer_file_operations
.llseek
=
1734 lib_ring_buffer_file_operations
.llseek
;
1735 #ifdef CONFIG_COMPAT
1736 lttng_stream_ring_buffer_file_operations
.compat_ioctl
=
1737 lttng_stream_ring_buffer_compat_ioctl
;
1741 int __init
lttng_abi_init(void)
1745 wrapper_vmalloc_sync_all();
1747 lttng_proc_dentry
= proc_create_data("lttng", S_IRUSR
| S_IWUSR
, NULL
,
1750 if (!lttng_proc_dentry
) {
1751 printk(KERN_ERR
"Error creating LTTng control file\n");
1755 lttng_stream_override_ring_buffer_fops();
1759 lttng_clock_unref();
1763 /* No __exit annotation because used by init error path too. */
1764 void lttng_abi_exit(void)
1766 lttng_clock_unref();
1767 if (lttng_proc_dentry
)
1768 remove_proc_entry("lttng", NULL
);