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
, 1, LONG_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 * lttng_session_ioctl - lttng session fd ioctl
473 * This ioctl implements lttng commands:
474 * LTTNG_KERNEL_CHANNEL
475 * Returns a LTTng channel file descriptor
476 * LTTNG_KERNEL_ENABLE
477 * Enables tracing for a session (weak enable)
478 * LTTNG_KERNEL_DISABLE
479 * Disables tracing for a session (strong disable)
480 * LTTNG_KERNEL_METADATA
481 * Returns a LTTng metadata file descriptor
482 * LTTNG_KERNEL_SESSION_TRACK_PID
483 * Add PID to session tracker
484 * LTTNG_KERNEL_SESSION_UNTRACK_PID
485 * Remove PID from session tracker
487 * The returned channel will be deleted when its file descriptor is closed.
490 long lttng_session_ioctl(struct file
*file
, unsigned int cmd
, unsigned long arg
)
492 struct lttng_session
*session
= file
->private_data
;
493 struct lttng_kernel_channel chan_param
;
494 struct lttng_kernel_old_channel old_chan_param
;
497 case LTTNG_KERNEL_OLD_CHANNEL
:
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 if (copy_from_user(&chan_param
,
516 (struct lttng_kernel_channel __user
*) arg
,
517 sizeof(struct lttng_kernel_channel
)))
519 return lttng_abi_create_channel(file
, &chan_param
,
522 case LTTNG_KERNEL_OLD_SESSION_START
:
523 case LTTNG_KERNEL_OLD_ENABLE
:
524 case LTTNG_KERNEL_SESSION_START
:
525 case LTTNG_KERNEL_ENABLE
:
526 return lttng_session_enable(session
);
527 case LTTNG_KERNEL_OLD_SESSION_STOP
:
528 case LTTNG_KERNEL_OLD_DISABLE
:
529 case LTTNG_KERNEL_SESSION_STOP
:
530 case LTTNG_KERNEL_DISABLE
:
531 return lttng_session_disable(session
);
532 case LTTNG_KERNEL_OLD_METADATA
:
534 if (copy_from_user(&old_chan_param
,
535 (struct lttng_kernel_old_channel __user
*) arg
,
536 sizeof(struct lttng_kernel_old_channel
)))
538 chan_param
.overwrite
= old_chan_param
.overwrite
;
539 chan_param
.subbuf_size
= old_chan_param
.subbuf_size
;
540 chan_param
.num_subbuf
= old_chan_param
.num_subbuf
;
541 chan_param
.switch_timer_interval
= old_chan_param
.switch_timer_interval
;
542 chan_param
.read_timer_interval
= old_chan_param
.read_timer_interval
;
543 chan_param
.output
= old_chan_param
.output
;
545 return lttng_abi_create_channel(file
, &chan_param
,
548 case LTTNG_KERNEL_METADATA
:
550 if (copy_from_user(&chan_param
,
551 (struct lttng_kernel_channel __user
*) arg
,
552 sizeof(struct lttng_kernel_channel
)))
554 return lttng_abi_create_channel(file
, &chan_param
,
557 case LTTNG_KERNEL_SESSION_TRACK_PID
:
558 return lttng_session_track_pid(session
, (int) arg
);
559 case LTTNG_KERNEL_SESSION_UNTRACK_PID
:
560 return lttng_session_untrack_pid(session
, (int) arg
);
561 case LTTNG_KERNEL_SESSION_LIST_TRACKER_PIDS
:
562 return lttng_session_list_tracker_pids(session
);
563 case LTTNG_KERNEL_SESSION_METADATA_REGEN
:
564 return lttng_session_metadata_regenerate(session
);
565 case LTTNG_KERNEL_SESSION_STATEDUMP
:
566 return lttng_session_statedump(session
);
573 * Called when the last file reference is dropped.
575 * Big fat note: channels and events are invariant for the whole session after
576 * their creation. So this session destruction also destroys all channel and
577 * event structures specific to this session (they are not destroyed when their
578 * individual file is released).
581 int lttng_session_release(struct inode
*inode
, struct file
*file
)
583 struct lttng_session
*session
= file
->private_data
;
586 lttng_session_destroy(session
);
590 static const struct file_operations lttng_session_fops
= {
591 .owner
= THIS_MODULE
,
592 .release
= lttng_session_release
,
593 .unlocked_ioctl
= lttng_session_ioctl
,
595 .compat_ioctl
= lttng_session_ioctl
,
600 * lttng_metadata_ring_buffer_poll - LTTng ring buffer poll file operation
604 * Handles the poll operations for the metadata channels.
607 unsigned int lttng_metadata_ring_buffer_poll(struct file
*filp
,
610 struct lttng_metadata_stream
*stream
= filp
->private_data
;
611 struct lib_ring_buffer
*buf
= stream
->priv
;
613 unsigned int mask
= 0;
615 if (filp
->f_mode
& FMODE_READ
) {
616 poll_wait_set_exclusive(wait
);
617 poll_wait(filp
, &stream
->read_wait
, wait
);
619 finalized
= stream
->finalized
;
622 * lib_ring_buffer_is_finalized() contains a smp_rmb()
623 * ordering finalized load before offsets loads.
625 WARN_ON(atomic_long_read(&buf
->active_readers
) != 1);
630 mutex_lock(&stream
->metadata_cache
->lock
);
631 if (stream
->metadata_cache
->metadata_written
>
632 stream
->metadata_out
)
634 mutex_unlock(&stream
->metadata_cache
->lock
);
641 void lttng_metadata_ring_buffer_ioctl_put_next_subbuf(struct file
*filp
,
642 unsigned int cmd
, unsigned long arg
)
644 struct lttng_metadata_stream
*stream
= filp
->private_data
;
646 stream
->metadata_out
= stream
->metadata_in
;
650 long lttng_metadata_ring_buffer_ioctl(struct file
*filp
,
651 unsigned int cmd
, unsigned long arg
)
654 struct lttng_metadata_stream
*stream
= filp
->private_data
;
655 struct lib_ring_buffer
*buf
= stream
->priv
;
658 case RING_BUFFER_GET_NEXT_SUBBUF
:
660 struct lttng_metadata_stream
*stream
= filp
->private_data
;
661 struct lib_ring_buffer
*buf
= stream
->priv
;
662 struct channel
*chan
= buf
->backend
.chan
;
664 ret
= lttng_metadata_output_channel(stream
, chan
);
666 lib_ring_buffer_switch_slow(buf
, SWITCH_ACTIVE
);
672 case RING_BUFFER_GET_SUBBUF
:
675 * Random access is not allowed for metadata channel.
679 case RING_BUFFER_FLUSH_EMPTY
: /* Fall-through. */
680 case RING_BUFFER_FLUSH
:
682 struct lttng_metadata_stream
*stream
= filp
->private_data
;
683 struct lib_ring_buffer
*buf
= stream
->priv
;
684 struct channel
*chan
= buf
->backend
.chan
;
687 * Before doing the actual ring buffer flush, write up to one
688 * packet of metadata in the ring buffer.
690 ret
= lttng_metadata_output_channel(stream
, chan
);
695 case RING_BUFFER_GET_METADATA_VERSION
:
697 struct lttng_metadata_stream
*stream
= filp
->private_data
;
699 return put_u64(stream
->version
, arg
);
704 /* PUT_SUBBUF is the one from lib ring buffer, unmodified. */
706 /* Performing lib ring buffer ioctl after our own. */
707 ret
= lib_ring_buffer_ioctl(filp
, cmd
, arg
, buf
);
712 case RING_BUFFER_PUT_NEXT_SUBBUF
:
714 lttng_metadata_ring_buffer_ioctl_put_next_subbuf(filp
,
727 long lttng_metadata_ring_buffer_compat_ioctl(struct file
*filp
,
728 unsigned int cmd
, unsigned long arg
)
731 struct lttng_metadata_stream
*stream
= filp
->private_data
;
732 struct lib_ring_buffer
*buf
= stream
->priv
;
735 case RING_BUFFER_GET_NEXT_SUBBUF
:
737 struct lttng_metadata_stream
*stream
= filp
->private_data
;
738 struct lib_ring_buffer
*buf
= stream
->priv
;
739 struct channel
*chan
= buf
->backend
.chan
;
741 ret
= lttng_metadata_output_channel(stream
, chan
);
743 lib_ring_buffer_switch_slow(buf
, SWITCH_ACTIVE
);
749 case RING_BUFFER_GET_SUBBUF
:
752 * Random access is not allowed for metadata channel.
756 case RING_BUFFER_FLUSH_EMPTY
: /* Fall-through. */
757 case RING_BUFFER_FLUSH
:
759 struct lttng_metadata_stream
*stream
= filp
->private_data
;
760 struct lib_ring_buffer
*buf
= stream
->priv
;
761 struct channel
*chan
= buf
->backend
.chan
;
764 * Before doing the actual ring buffer flush, write up to one
765 * packet of metadata in the ring buffer.
767 ret
= lttng_metadata_output_channel(stream
, chan
);
772 case RING_BUFFER_GET_METADATA_VERSION
:
774 struct lttng_metadata_stream
*stream
= filp
->private_data
;
776 return put_u64(stream
->version
, arg
);
781 /* PUT_SUBBUF is the one from lib ring buffer, unmodified. */
783 /* Performing lib ring buffer ioctl after our own. */
784 ret
= lib_ring_buffer_compat_ioctl(filp
, cmd
, arg
, buf
);
789 case RING_BUFFER_PUT_NEXT_SUBBUF
:
791 lttng_metadata_ring_buffer_ioctl_put_next_subbuf(filp
,
804 * This is not used by anonymous file descriptors. This code is left
805 * there if we ever want to implement an inode with open() operation.
808 int lttng_metadata_ring_buffer_open(struct inode
*inode
, struct file
*file
)
810 struct lttng_metadata_stream
*stream
= inode
->i_private
;
811 struct lib_ring_buffer
*buf
= stream
->priv
;
813 file
->private_data
= buf
;
815 * Since life-time of metadata cache differs from that of
816 * session, we need to keep our own reference on the transport.
818 if (!try_module_get(stream
->transport
->owner
)) {
819 printk(KERN_WARNING
"LTT : Can't lock transport module.\n");
822 return lib_ring_buffer_open(inode
, file
, buf
);
826 int lttng_metadata_ring_buffer_release(struct inode
*inode
, struct file
*file
)
828 struct lttng_metadata_stream
*stream
= file
->private_data
;
829 struct lib_ring_buffer
*buf
= stream
->priv
;
831 kref_put(&stream
->metadata_cache
->refcount
, metadata_cache_destroy
);
832 module_put(stream
->transport
->owner
);
833 return lib_ring_buffer_release(inode
, file
, buf
);
837 ssize_t
lttng_metadata_ring_buffer_splice_read(struct file
*in
, loff_t
*ppos
,
838 struct pipe_inode_info
*pipe
, size_t len
,
841 struct lttng_metadata_stream
*stream
= in
->private_data
;
842 struct lib_ring_buffer
*buf
= stream
->priv
;
844 return lib_ring_buffer_splice_read(in
, ppos
, pipe
, len
,
849 int lttng_metadata_ring_buffer_mmap(struct file
*filp
,
850 struct vm_area_struct
*vma
)
852 struct lttng_metadata_stream
*stream
= filp
->private_data
;
853 struct lib_ring_buffer
*buf
= stream
->priv
;
855 return lib_ring_buffer_mmap(filp
, vma
, buf
);
859 const struct file_operations lttng_metadata_ring_buffer_file_operations
= {
860 .owner
= THIS_MODULE
,
861 .open
= lttng_metadata_ring_buffer_open
,
862 .release
= lttng_metadata_ring_buffer_release
,
863 .poll
= lttng_metadata_ring_buffer_poll
,
864 .splice_read
= lttng_metadata_ring_buffer_splice_read
,
865 .mmap
= lttng_metadata_ring_buffer_mmap
,
866 .unlocked_ioctl
= lttng_metadata_ring_buffer_ioctl
,
867 .llseek
= vfs_lib_ring_buffer_no_llseek
,
869 .compat_ioctl
= lttng_metadata_ring_buffer_compat_ioctl
,
874 int lttng_abi_create_stream_fd(struct file
*channel_file
, void *stream_priv
,
875 const struct file_operations
*fops
)
878 struct file
*stream_file
;
880 stream_fd
= lttng_get_unused_fd();
885 stream_file
= anon_inode_getfile("[lttng_stream]", fops
,
886 stream_priv
, O_RDWR
);
887 if (IS_ERR(stream_file
)) {
888 ret
= PTR_ERR(stream_file
);
892 * OPEN_FMODE, called within anon_inode_getfile/alloc_file, don't honor
893 * FMODE_LSEEK, FMODE_PREAD nor FMODE_PWRITE. We need to read from this
894 * file descriptor, so we set FMODE_PREAD here.
896 stream_file
->f_mode
|= FMODE_PREAD
;
897 fd_install(stream_fd
, stream_file
);
899 * The stream holds a reference to the channel within the generic ring
900 * buffer library, so no need to hold a refcount on the channel and
901 * session files here.
906 put_unused_fd(stream_fd
);
912 int lttng_abi_open_stream(struct file
*channel_file
)
914 struct lttng_channel
*channel
= channel_file
->private_data
;
915 struct lib_ring_buffer
*buf
;
919 buf
= channel
->ops
->buffer_read_open(channel
->chan
);
924 ret
= lttng_abi_create_stream_fd(channel_file
, stream_priv
,
925 <tng_stream_ring_buffer_file_operations
);
932 channel
->ops
->buffer_read_close(buf
);
937 int lttng_abi_open_metadata_stream(struct file
*channel_file
)
939 struct lttng_channel
*channel
= channel_file
->private_data
;
940 struct lttng_session
*session
= channel
->session
;
941 struct lib_ring_buffer
*buf
;
943 struct lttng_metadata_stream
*metadata_stream
;
946 buf
= channel
->ops
->buffer_read_open(channel
->chan
);
950 metadata_stream
= kzalloc(sizeof(struct lttng_metadata_stream
),
952 if (!metadata_stream
) {
956 metadata_stream
->metadata_cache
= session
->metadata_cache
;
957 init_waitqueue_head(&metadata_stream
->read_wait
);
958 metadata_stream
->priv
= buf
;
959 stream_priv
= metadata_stream
;
960 metadata_stream
->transport
= channel
->transport
;
963 * Since life-time of metadata cache differs from that of
964 * session, we need to keep our own reference on the transport.
966 if (!try_module_get(metadata_stream
->transport
->owner
)) {
967 printk(KERN_WARNING
"LTT : Can't lock transport module.\n");
972 if (!lttng_kref_get(&session
->metadata_cache
->refcount
)) {
977 ret
= lttng_abi_create_stream_fd(channel_file
, stream_priv
,
978 <tng_metadata_ring_buffer_file_operations
);
982 list_add(&metadata_stream
->list
,
983 &session
->metadata_cache
->metadata_stream
);
987 kref_put(&session
->metadata_cache
->refcount
, metadata_cache_destroy
);
989 module_put(metadata_stream
->transport
->owner
);
991 kfree(metadata_stream
);
993 channel
->ops
->buffer_read_close(buf
);
998 int lttng_abi_create_event(struct file
*channel_file
,
999 struct lttng_kernel_event
*event_param
)
1001 struct lttng_channel
*channel
= channel_file
->private_data
;
1003 struct file
*event_file
;
1006 event_param
->name
[LTTNG_KERNEL_SYM_NAME_LEN
- 1] = '\0';
1007 switch (event_param
->instrumentation
) {
1008 case LTTNG_KERNEL_KRETPROBE
:
1009 event_param
->u
.kretprobe
.symbol_name
[LTTNG_KERNEL_SYM_NAME_LEN
- 1] = '\0';
1011 case LTTNG_KERNEL_KPROBE
:
1012 event_param
->u
.kprobe
.symbol_name
[LTTNG_KERNEL_SYM_NAME_LEN
- 1] = '\0';
1014 case LTTNG_KERNEL_FUNCTION
:
1015 event_param
->u
.ftrace
.symbol_name
[LTTNG_KERNEL_SYM_NAME_LEN
- 1] = '\0';
1020 event_fd
= lttng_get_unused_fd();
1025 event_file
= anon_inode_getfile("[lttng_event]",
1028 if (IS_ERR(event_file
)) {
1029 ret
= PTR_ERR(event_file
);
1032 /* The event holds a reference on the channel */
1033 if (!atomic_long_add_unless(&channel_file
->f_count
, 1, LONG_MAX
)) {
1035 goto refcount_error
;
1037 if (event_param
->instrumentation
== LTTNG_KERNEL_TRACEPOINT
1038 || event_param
->instrumentation
== LTTNG_KERNEL_SYSCALL
) {
1039 struct lttng_enabler
*enabler
;
1041 if (event_param
->name
[strlen(event_param
->name
) - 1] == '*') {
1042 enabler
= lttng_enabler_create(LTTNG_ENABLER_WILDCARD
,
1043 event_param
, channel
);
1045 enabler
= lttng_enabler_create(LTTNG_ENABLER_NAME
,
1046 event_param
, channel
);
1050 struct lttng_event
*event
;
1053 * We tolerate no failure path after event creation. It
1054 * will stay invariant for the rest of the session.
1056 event
= lttng_event_create(channel
, event_param
,
1058 event_param
->instrumentation
);
1059 WARN_ON_ONCE(!event
);
1060 if (IS_ERR(event
)) {
1061 ret
= PTR_ERR(event
);
1066 event_file
->private_data
= priv
;
1067 fd_install(event_fd
, event_file
);
1071 atomic_long_dec(&channel_file
->f_count
);
1075 put_unused_fd(event_fd
);
1081 * lttng_channel_ioctl - lttng syscall through ioctl
1087 * This ioctl implements lttng commands:
1088 * LTTNG_KERNEL_STREAM
1089 * Returns an event stream file descriptor or failure.
1090 * (typically, one event stream records events from one CPU)
1091 * LTTNG_KERNEL_EVENT
1092 * Returns an event file descriptor or failure.
1093 * LTTNG_KERNEL_CONTEXT
1094 * Prepend a context field to each event in the channel
1095 * LTTNG_KERNEL_ENABLE
1096 * Enable recording for events in this channel (weak enable)
1097 * LTTNG_KERNEL_DISABLE
1098 * Disable recording for events in this channel (strong disable)
1100 * Channel and event file descriptors also hold a reference on the session.
1103 long lttng_channel_ioctl(struct file
*file
, unsigned int cmd
, unsigned long arg
)
1105 struct lttng_channel
*channel
= file
->private_data
;
1108 case LTTNG_KERNEL_OLD_STREAM
:
1109 case LTTNG_KERNEL_STREAM
:
1110 return lttng_abi_open_stream(file
);
1111 case LTTNG_KERNEL_OLD_EVENT
:
1113 struct lttng_kernel_event
*uevent_param
;
1114 struct lttng_kernel_old_event
*old_uevent_param
;
1117 uevent_param
= kmalloc(sizeof(struct lttng_kernel_event
),
1119 if (!uevent_param
) {
1123 old_uevent_param
= kmalloc(
1124 sizeof(struct lttng_kernel_old_event
),
1126 if (!old_uevent_param
) {
1128 goto old_event_error_free_param
;
1130 if (copy_from_user(old_uevent_param
,
1131 (struct lttng_kernel_old_event __user
*) arg
,
1132 sizeof(struct lttng_kernel_old_event
))) {
1134 goto old_event_error_free_old_param
;
1137 memcpy(uevent_param
->name
, old_uevent_param
->name
,
1138 sizeof(uevent_param
->name
));
1139 uevent_param
->instrumentation
=
1140 old_uevent_param
->instrumentation
;
1142 switch (old_uevent_param
->instrumentation
) {
1143 case LTTNG_KERNEL_KPROBE
:
1144 uevent_param
->u
.kprobe
.addr
=
1145 old_uevent_param
->u
.kprobe
.addr
;
1146 uevent_param
->u
.kprobe
.offset
=
1147 old_uevent_param
->u
.kprobe
.offset
;
1148 memcpy(uevent_param
->u
.kprobe
.symbol_name
,
1149 old_uevent_param
->u
.kprobe
.symbol_name
,
1150 sizeof(uevent_param
->u
.kprobe
.symbol_name
));
1152 case LTTNG_KERNEL_KRETPROBE
:
1153 uevent_param
->u
.kretprobe
.addr
=
1154 old_uevent_param
->u
.kretprobe
.addr
;
1155 uevent_param
->u
.kretprobe
.offset
=
1156 old_uevent_param
->u
.kretprobe
.offset
;
1157 memcpy(uevent_param
->u
.kretprobe
.symbol_name
,
1158 old_uevent_param
->u
.kretprobe
.symbol_name
,
1159 sizeof(uevent_param
->u
.kretprobe
.symbol_name
));
1161 case LTTNG_KERNEL_FUNCTION
:
1162 memcpy(uevent_param
->u
.ftrace
.symbol_name
,
1163 old_uevent_param
->u
.ftrace
.symbol_name
,
1164 sizeof(uevent_param
->u
.ftrace
.symbol_name
));
1169 ret
= lttng_abi_create_event(file
, uevent_param
);
1171 old_event_error_free_old_param
:
1172 kfree(old_uevent_param
);
1173 old_event_error_free_param
:
1174 kfree(uevent_param
);
1178 case LTTNG_KERNEL_EVENT
:
1180 struct lttng_kernel_event uevent_param
;
1182 if (copy_from_user(&uevent_param
,
1183 (struct lttng_kernel_event __user
*) arg
,
1184 sizeof(uevent_param
)))
1186 return lttng_abi_create_event(file
, &uevent_param
);
1188 case LTTNG_KERNEL_OLD_CONTEXT
:
1190 struct lttng_kernel_context
*ucontext_param
;
1191 struct lttng_kernel_old_context
*old_ucontext_param
;
1194 ucontext_param
= kmalloc(sizeof(struct lttng_kernel_context
),
1196 if (!ucontext_param
) {
1200 old_ucontext_param
= kmalloc(sizeof(struct lttng_kernel_old_context
),
1202 if (!old_ucontext_param
) {
1204 goto old_ctx_error_free_param
;
1207 if (copy_from_user(old_ucontext_param
,
1208 (struct lttng_kernel_old_context __user
*) arg
,
1209 sizeof(struct lttng_kernel_old_context
))) {
1211 goto old_ctx_error_free_old_param
;
1213 ucontext_param
->ctx
= old_ucontext_param
->ctx
;
1214 memcpy(ucontext_param
->padding
, old_ucontext_param
->padding
,
1215 sizeof(ucontext_param
->padding
));
1216 /* only type that uses the union */
1217 if (old_ucontext_param
->ctx
== LTTNG_KERNEL_CONTEXT_PERF_COUNTER
) {
1218 ucontext_param
->u
.perf_counter
.type
=
1219 old_ucontext_param
->u
.perf_counter
.type
;
1220 ucontext_param
->u
.perf_counter
.config
=
1221 old_ucontext_param
->u
.perf_counter
.config
;
1222 memcpy(ucontext_param
->u
.perf_counter
.name
,
1223 old_ucontext_param
->u
.perf_counter
.name
,
1224 sizeof(ucontext_param
->u
.perf_counter
.name
));
1227 ret
= lttng_abi_add_context(file
,
1229 &channel
->ctx
, channel
->session
);
1231 old_ctx_error_free_old_param
:
1232 kfree(old_ucontext_param
);
1233 old_ctx_error_free_param
:
1234 kfree(ucontext_param
);
1238 case LTTNG_KERNEL_CONTEXT
:
1240 struct lttng_kernel_context ucontext_param
;
1242 if (copy_from_user(&ucontext_param
,
1243 (struct lttng_kernel_context __user
*) arg
,
1244 sizeof(ucontext_param
)))
1246 return lttng_abi_add_context(file
,
1248 &channel
->ctx
, channel
->session
);
1250 case LTTNG_KERNEL_OLD_ENABLE
:
1251 case LTTNG_KERNEL_ENABLE
:
1252 return lttng_channel_enable(channel
);
1253 case LTTNG_KERNEL_OLD_DISABLE
:
1254 case LTTNG_KERNEL_DISABLE
:
1255 return lttng_channel_disable(channel
);
1256 case LTTNG_KERNEL_SYSCALL_MASK
:
1257 return lttng_channel_syscall_mask(channel
,
1258 (struct lttng_kernel_syscall_mask __user
*) arg
);
1260 return -ENOIOCTLCMD
;
1266 * lttng_metadata_ioctl - lttng syscall through ioctl
1272 * This ioctl implements lttng commands:
1273 * LTTNG_KERNEL_STREAM
1274 * Returns an event stream file descriptor or failure.
1276 * Channel and event file descriptors also hold a reference on the session.
1279 long lttng_metadata_ioctl(struct file
*file
, unsigned int cmd
, unsigned long arg
)
1282 case LTTNG_KERNEL_OLD_STREAM
:
1283 case LTTNG_KERNEL_STREAM
:
1284 return lttng_abi_open_metadata_stream(file
);
1286 return -ENOIOCTLCMD
;
1291 * lttng_channel_poll - lttng stream addition/removal monitoring
1296 unsigned int lttng_channel_poll(struct file
*file
, poll_table
*wait
)
1298 struct lttng_channel
*channel
= file
->private_data
;
1299 unsigned int mask
= 0;
1301 if (file
->f_mode
& FMODE_READ
) {
1302 poll_wait_set_exclusive(wait
);
1303 poll_wait(file
, channel
->ops
->get_hp_wait_queue(channel
->chan
),
1306 if (channel
->ops
->is_disabled(channel
->chan
))
1308 if (channel
->ops
->is_finalized(channel
->chan
))
1310 if (channel
->ops
->buffer_has_read_closed_stream(channel
->chan
))
1311 return POLLIN
| POLLRDNORM
;
1319 int lttng_channel_release(struct inode
*inode
, struct file
*file
)
1321 struct lttng_channel
*channel
= file
->private_data
;
1324 fput(channel
->session
->file
);
1329 int lttng_metadata_channel_release(struct inode
*inode
, struct file
*file
)
1331 struct lttng_channel
*channel
= file
->private_data
;
1334 fput(channel
->session
->file
);
1335 lttng_metadata_channel_destroy(channel
);
1341 static const struct file_operations lttng_channel_fops
= {
1342 .owner
= THIS_MODULE
,
1343 .release
= lttng_channel_release
,
1344 .poll
= lttng_channel_poll
,
1345 .unlocked_ioctl
= lttng_channel_ioctl
,
1346 #ifdef CONFIG_COMPAT
1347 .compat_ioctl
= lttng_channel_ioctl
,
1351 static const struct file_operations lttng_metadata_fops
= {
1352 .owner
= THIS_MODULE
,
1353 .release
= lttng_metadata_channel_release
,
1354 .unlocked_ioctl
= lttng_metadata_ioctl
,
1355 #ifdef CONFIG_COMPAT
1356 .compat_ioctl
= lttng_metadata_ioctl
,
1361 * lttng_event_ioctl - lttng syscall through ioctl
1367 * This ioctl implements lttng commands:
1368 * LTTNG_KERNEL_CONTEXT
1369 * Prepend a context field to each record of this event
1370 * LTTNG_KERNEL_ENABLE
1371 * Enable recording for this event (weak enable)
1372 * LTTNG_KERNEL_DISABLE
1373 * Disable recording for this event (strong disable)
1376 long lttng_event_ioctl(struct file
*file
, unsigned int cmd
, unsigned long arg
)
1378 struct lttng_event
*event
;
1379 struct lttng_enabler
*enabler
;
1380 enum lttng_event_type
*evtype
= file
->private_data
;
1383 case LTTNG_KERNEL_OLD_CONTEXT
:
1385 /* Not implemented */
1388 case LTTNG_KERNEL_CONTEXT
:
1390 /* Not implemented */
1393 case LTTNG_KERNEL_OLD_ENABLE
:
1394 case LTTNG_KERNEL_ENABLE
:
1396 case LTTNG_TYPE_EVENT
:
1397 event
= file
->private_data
;
1398 return lttng_event_enable(event
);
1399 case LTTNG_TYPE_ENABLER
:
1400 enabler
= file
->private_data
;
1401 return lttng_enabler_enable(enabler
);
1406 case LTTNG_KERNEL_OLD_DISABLE
:
1407 case LTTNG_KERNEL_DISABLE
:
1409 case LTTNG_TYPE_EVENT
:
1410 event
= file
->private_data
;
1411 return lttng_event_disable(event
);
1412 case LTTNG_TYPE_ENABLER
:
1413 enabler
= file
->private_data
;
1414 return lttng_enabler_disable(enabler
);
1419 case LTTNG_KERNEL_FILTER
:
1421 case LTTNG_TYPE_EVENT
:
1423 case LTTNG_TYPE_ENABLER
:
1425 enabler
= file
->private_data
;
1426 return lttng_enabler_attach_bytecode(enabler
,
1427 (struct lttng_kernel_filter_bytecode __user
*) arg
);
1432 return -ENOIOCTLCMD
;
1437 int lttng_event_release(struct inode
*inode
, struct file
*file
)
1439 struct lttng_event
*event
;
1440 struct lttng_enabler
*enabler
;
1441 enum lttng_event_type
*evtype
= file
->private_data
;
1447 case LTTNG_TYPE_EVENT
:
1448 event
= file
->private_data
;
1450 fput(event
->chan
->file
);
1452 case LTTNG_TYPE_ENABLER
:
1453 enabler
= file
->private_data
;
1455 fput(enabler
->chan
->file
);
1465 /* TODO: filter control ioctl */
1466 static const struct file_operations lttng_event_fops
= {
1467 .owner
= THIS_MODULE
,
1468 .release
= lttng_event_release
,
1469 .unlocked_ioctl
= lttng_event_ioctl
,
1470 #ifdef CONFIG_COMPAT
1471 .compat_ioctl
= lttng_event_ioctl
,
1475 static int put_u64(uint64_t val
, unsigned long arg
)
1477 return put_user(val
, (uint64_t __user
*) arg
);
1480 static long lttng_stream_ring_buffer_ioctl(struct file
*filp
,
1481 unsigned int cmd
, unsigned long arg
)
1483 struct lib_ring_buffer
*buf
= filp
->private_data
;
1484 struct channel
*chan
= buf
->backend
.chan
;
1485 const struct lib_ring_buffer_config
*config
= &chan
->backend
.config
;
1486 const struct lttng_channel_ops
*ops
= chan
->backend
.priv_ops
;
1489 if (atomic_read(&chan
->record_disabled
))
1493 case LTTNG_RING_BUFFER_GET_TIMESTAMP_BEGIN
:
1497 ret
= ops
->timestamp_begin(config
, buf
, &ts
);
1500 return put_u64(ts
, arg
);
1502 case LTTNG_RING_BUFFER_GET_TIMESTAMP_END
:
1506 ret
= ops
->timestamp_end(config
, buf
, &ts
);
1509 return put_u64(ts
, arg
);
1511 case LTTNG_RING_BUFFER_GET_EVENTS_DISCARDED
:
1515 ret
= ops
->events_discarded(config
, buf
, &ed
);
1518 return put_u64(ed
, arg
);
1520 case LTTNG_RING_BUFFER_GET_CONTENT_SIZE
:
1524 ret
= ops
->content_size(config
, buf
, &cs
);
1527 return put_u64(cs
, arg
);
1529 case LTTNG_RING_BUFFER_GET_PACKET_SIZE
:
1533 ret
= ops
->packet_size(config
, buf
, &ps
);
1536 return put_u64(ps
, arg
);
1538 case LTTNG_RING_BUFFER_GET_STREAM_ID
:
1542 ret
= ops
->stream_id(config
, buf
, &si
);
1545 return put_u64(si
, arg
);
1547 case LTTNG_RING_BUFFER_GET_CURRENT_TIMESTAMP
:
1551 ret
= ops
->current_timestamp(config
, buf
, &ts
);
1554 return put_u64(ts
, arg
);
1556 case LTTNG_RING_BUFFER_GET_SEQ_NUM
:
1560 ret
= ops
->sequence_number(config
, buf
, &seq
);
1563 return put_u64(seq
, arg
);
1565 case LTTNG_RING_BUFFER_INSTANCE_ID
:
1569 ret
= ops
->instance_id(config
, buf
, &id
);
1572 return put_u64(id
, arg
);
1575 return lib_ring_buffer_file_operations
.unlocked_ioctl(filp
,
1583 #ifdef CONFIG_COMPAT
1584 static long lttng_stream_ring_buffer_compat_ioctl(struct file
*filp
,
1585 unsigned int cmd
, unsigned long arg
)
1587 struct lib_ring_buffer
*buf
= filp
->private_data
;
1588 struct channel
*chan
= buf
->backend
.chan
;
1589 const struct lib_ring_buffer_config
*config
= &chan
->backend
.config
;
1590 const struct lttng_channel_ops
*ops
= chan
->backend
.priv_ops
;
1593 if (atomic_read(&chan
->record_disabled
))
1597 case LTTNG_RING_BUFFER_COMPAT_GET_TIMESTAMP_BEGIN
:
1601 ret
= ops
->timestamp_begin(config
, buf
, &ts
);
1604 return put_u64(ts
, arg
);
1606 case LTTNG_RING_BUFFER_COMPAT_GET_TIMESTAMP_END
:
1610 ret
= ops
->timestamp_end(config
, buf
, &ts
);
1613 return put_u64(ts
, arg
);
1615 case LTTNG_RING_BUFFER_COMPAT_GET_EVENTS_DISCARDED
:
1619 ret
= ops
->events_discarded(config
, buf
, &ed
);
1622 return put_u64(ed
, arg
);
1624 case LTTNG_RING_BUFFER_COMPAT_GET_CONTENT_SIZE
:
1628 ret
= ops
->content_size(config
, buf
, &cs
);
1631 return put_u64(cs
, arg
);
1633 case LTTNG_RING_BUFFER_COMPAT_GET_PACKET_SIZE
:
1637 ret
= ops
->packet_size(config
, buf
, &ps
);
1640 return put_u64(ps
, arg
);
1642 case LTTNG_RING_BUFFER_COMPAT_GET_STREAM_ID
:
1646 ret
= ops
->stream_id(config
, buf
, &si
);
1649 return put_u64(si
, arg
);
1651 case LTTNG_RING_BUFFER_GET_CURRENT_TIMESTAMP
:
1655 ret
= ops
->current_timestamp(config
, buf
, &ts
);
1658 return put_u64(ts
, arg
);
1660 case LTTNG_RING_BUFFER_COMPAT_GET_SEQ_NUM
:
1664 ret
= ops
->sequence_number(config
, buf
, &seq
);
1667 return put_u64(seq
, arg
);
1669 case LTTNG_RING_BUFFER_COMPAT_INSTANCE_ID
:
1673 ret
= ops
->instance_id(config
, buf
, &id
);
1676 return put_u64(id
, arg
);
1679 return lib_ring_buffer_file_operations
.compat_ioctl(filp
,
1686 #endif /* CONFIG_COMPAT */
1688 static void lttng_stream_override_ring_buffer_fops(void)
1690 lttng_stream_ring_buffer_file_operations
.owner
= THIS_MODULE
;
1691 lttng_stream_ring_buffer_file_operations
.open
=
1692 lib_ring_buffer_file_operations
.open
;
1693 lttng_stream_ring_buffer_file_operations
.release
=
1694 lib_ring_buffer_file_operations
.release
;
1695 lttng_stream_ring_buffer_file_operations
.poll
=
1696 lib_ring_buffer_file_operations
.poll
;
1697 lttng_stream_ring_buffer_file_operations
.splice_read
=
1698 lib_ring_buffer_file_operations
.splice_read
;
1699 lttng_stream_ring_buffer_file_operations
.mmap
=
1700 lib_ring_buffer_file_operations
.mmap
;
1701 lttng_stream_ring_buffer_file_operations
.unlocked_ioctl
=
1702 lttng_stream_ring_buffer_ioctl
;
1703 lttng_stream_ring_buffer_file_operations
.llseek
=
1704 lib_ring_buffer_file_operations
.llseek
;
1705 #ifdef CONFIG_COMPAT
1706 lttng_stream_ring_buffer_file_operations
.compat_ioctl
=
1707 lttng_stream_ring_buffer_compat_ioctl
;
1711 int __init
lttng_abi_init(void)
1715 wrapper_vmalloc_sync_all();
1718 ret
= lttng_tp_mempool_init();
1723 lttng_proc_dentry
= proc_create_data("lttng", S_IRUSR
| S_IWUSR
, NULL
,
1726 if (!lttng_proc_dentry
) {
1727 printk(KERN_ERR
"Error creating LTTng control file\n");
1731 lttng_stream_override_ring_buffer_fops();
1735 lttng_tp_mempool_destroy();
1736 lttng_clock_unref();
1740 /* No __exit annotation because used by init error path too. */
1741 void lttng_abi_exit(void)
1743 lttng_tp_mempool_destroy();
1744 lttng_clock_unref();
1745 if (lttng_proc_dentry
)
1746 remove_proc_entry("lttng", NULL
);