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 "wrapper/vmalloc.h" /* for wrapper_vmalloc_sync_all() */
47 #include "wrapper/ringbuffer/vfs.h"
48 #include "wrapper/poll.h"
49 #include "lttng-abi.h"
50 #include "lttng-abi-old.h"
51 #include "lttng-events.h"
52 #include "lttng-tracer.h"
55 * This is LTTng's own personal way to create a system call as an external
56 * module. We use ioctl() on /proc/lttng.
59 static struct proc_dir_entry
*lttng_proc_dentry
;
60 static const struct file_operations lttng_fops
;
61 static const struct file_operations lttng_session_fops
;
62 static const struct file_operations lttng_channel_fops
;
63 static const struct file_operations lttng_metadata_fops
;
64 static const struct file_operations lttng_event_fops
;
67 * Teardown management: opened file descriptors keep a refcount on the module,
68 * so it can only exit when all file descriptors are closed.
77 int lttng_abi_create_session(void)
79 struct lttng_session
*session
;
80 struct file
*session_file
;
83 session
= lttng_session_create();
86 session_fd
= get_unused_fd();
91 session_file
= anon_inode_getfile("[lttng_session]",
94 if (IS_ERR(session_file
)) {
95 ret
= PTR_ERR(session_file
);
98 session
->file
= session_file
;
99 fd_install(session_fd
, session_file
);
103 put_unused_fd(session_fd
);
105 lttng_session_destroy(session
);
110 int lttng_abi_tracepoint_list(void)
112 struct file
*tracepoint_list_file
;
115 file_fd
= get_unused_fd();
121 tracepoint_list_file
= anon_inode_getfile("[lttng_session]",
122 <tng_tracepoint_list_fops
,
124 if (IS_ERR(tracepoint_list_file
)) {
125 ret
= PTR_ERR(tracepoint_list_file
);
128 ret
= lttng_tracepoint_list_fops
.open(NULL
, tracepoint_list_file
);
131 fd_install(file_fd
, tracepoint_list_file
);
139 fput(tracepoint_list_file
);
141 put_unused_fd(file_fd
);
147 void lttng_abi_tracer_version(struct lttng_kernel_tracer_version
*v
)
149 v
->major
= LTTNG_MODULES_MAJOR_VERSION
;
150 v
->minor
= LTTNG_MODULES_MINOR_VERSION
;
151 v
->patchlevel
= LTTNG_MODULES_PATCHLEVEL_VERSION
;
155 long lttng_abi_add_context(struct file
*file
,
156 struct lttng_kernel_context
*context_param
,
157 struct lttng_ctx
**ctx
, struct lttng_session
*session
)
160 if (session
->been_active
)
163 switch (context_param
->ctx
) {
164 case LTTNG_KERNEL_CONTEXT_PID
:
165 return lttng_add_pid_to_ctx(ctx
);
166 case LTTNG_KERNEL_CONTEXT_PRIO
:
167 return lttng_add_prio_to_ctx(ctx
);
168 case LTTNG_KERNEL_CONTEXT_NICE
:
169 return lttng_add_nice_to_ctx(ctx
);
170 case LTTNG_KERNEL_CONTEXT_VPID
:
171 return lttng_add_vpid_to_ctx(ctx
);
172 case LTTNG_KERNEL_CONTEXT_TID
:
173 return lttng_add_tid_to_ctx(ctx
);
174 case LTTNG_KERNEL_CONTEXT_VTID
:
175 return lttng_add_vtid_to_ctx(ctx
);
176 case LTTNG_KERNEL_CONTEXT_PPID
:
177 return lttng_add_ppid_to_ctx(ctx
);
178 case LTTNG_KERNEL_CONTEXT_VPPID
:
179 return lttng_add_vppid_to_ctx(ctx
);
180 case LTTNG_KERNEL_CONTEXT_PERF_COUNTER
:
181 context_param
->u
.perf_counter
.name
[LTTNG_KERNEL_SYM_NAME_LEN
- 1] = '\0';
182 return lttng_add_perf_counter_to_ctx(context_param
->u
.perf_counter
.type
,
183 context_param
->u
.perf_counter
.config
,
184 context_param
->u
.perf_counter
.name
,
186 case LTTNG_KERNEL_CONTEXT_PROCNAME
:
187 return lttng_add_procname_to_ctx(ctx
);
188 case LTTNG_KERNEL_CONTEXT_HOSTNAME
:
189 return lttng_add_hostname_to_ctx(ctx
);
196 * lttng_ioctl - lttng syscall through ioctl
202 * This ioctl implements lttng commands:
203 * LTTNG_KERNEL_SESSION
204 * Returns a LTTng trace session file descriptor
205 * LTTNG_KERNEL_TRACER_VERSION
206 * Returns the LTTng kernel tracer version
207 * LTTNG_KERNEL_TRACEPOINT_LIST
208 * Returns a file descriptor listing available tracepoints
209 * LTTNG_KERNEL_WAIT_QUIESCENT
210 * Returns after all previously running probes have completed
212 * The returned session will be deleted when its file descriptor is closed.
215 long lttng_ioctl(struct file
*file
, unsigned int cmd
, unsigned long arg
)
218 case LTTNG_KERNEL_OLD_SESSION
:
219 case LTTNG_KERNEL_SESSION
:
220 return lttng_abi_create_session();
221 case LTTNG_KERNEL_OLD_TRACER_VERSION
:
223 struct lttng_kernel_tracer_version v
;
224 struct lttng_kernel_old_tracer_version oldv
;
225 struct lttng_kernel_old_tracer_version
*uversion
=
226 (struct lttng_kernel_old_tracer_version __user
*) arg
;
228 lttng_abi_tracer_version(&v
);
229 oldv
.major
= v
.major
;
230 oldv
.minor
= v
.minor
;
231 oldv
.patchlevel
= v
.patchlevel
;
233 if (copy_to_user(uversion
, &oldv
, sizeof(oldv
)))
237 case LTTNG_KERNEL_TRACER_VERSION
:
239 struct lttng_kernel_tracer_version version
;
240 struct lttng_kernel_tracer_version
*uversion
=
241 (struct lttng_kernel_tracer_version __user
*) arg
;
243 lttng_abi_tracer_version(&version
);
245 if (copy_to_user(uversion
, &version
, sizeof(version
)))
249 case LTTNG_KERNEL_OLD_TRACEPOINT_LIST
:
250 case LTTNG_KERNEL_TRACEPOINT_LIST
:
251 return lttng_abi_tracepoint_list();
252 case LTTNG_KERNEL_OLD_WAIT_QUIESCENT
:
253 case LTTNG_KERNEL_WAIT_QUIESCENT
:
256 case LTTNG_KERNEL_OLD_CALIBRATE
:
258 struct lttng_kernel_old_calibrate __user
*ucalibrate
=
259 (struct lttng_kernel_old_calibrate __user
*) arg
;
260 struct lttng_kernel_old_calibrate old_calibrate
;
261 struct lttng_kernel_calibrate calibrate
;
264 if (copy_from_user(&old_calibrate
, ucalibrate
, sizeof(old_calibrate
)))
266 calibrate
.type
= old_calibrate
.type
;
267 ret
= lttng_calibrate(&calibrate
);
268 if (copy_to_user(ucalibrate
, &old_calibrate
, sizeof(old_calibrate
)))
272 case LTTNG_KERNEL_CALIBRATE
:
274 struct lttng_kernel_calibrate __user
*ucalibrate
=
275 (struct lttng_kernel_calibrate __user
*) arg
;
276 struct lttng_kernel_calibrate calibrate
;
279 if (copy_from_user(&calibrate
, ucalibrate
, sizeof(calibrate
)))
281 ret
= lttng_calibrate(&calibrate
);
282 if (copy_to_user(ucalibrate
, &calibrate
, sizeof(calibrate
)))
291 static const struct file_operations lttng_fops
= {
292 .owner
= THIS_MODULE
,
293 .unlocked_ioctl
= lttng_ioctl
,
295 .compat_ioctl
= lttng_ioctl
,
300 * We tolerate no failure in this function (if one happens, we print a dmesg
301 * error, but cannot return any error, because the channel information is
305 void lttng_metadata_create_events(struct file
*channel_file
)
307 struct lttng_channel
*channel
= channel_file
->private_data
;
308 static struct lttng_kernel_event metadata_params
= {
309 .instrumentation
= LTTNG_KERNEL_TRACEPOINT
,
310 .name
= "lttng_metadata",
312 struct lttng_event
*event
;
315 * We tolerate no failure path after event creation. It will stay
316 * invariant for the rest of the session.
318 event
= lttng_event_create(channel
, &metadata_params
, NULL
, NULL
);
326 return; /* not allowed to return error */
330 int lttng_abi_create_channel(struct file
*session_file
,
331 struct lttng_kernel_channel
*chan_param
,
332 enum channel_type channel_type
)
334 struct lttng_session
*session
= session_file
->private_data
;
335 const struct file_operations
*fops
= NULL
;
336 const char *transport_name
;
337 struct lttng_channel
*chan
;
338 struct file
*chan_file
;
342 chan_fd
= get_unused_fd();
347 switch (channel_type
) {
348 case PER_CPU_CHANNEL
:
349 fops
= <tng_channel_fops
;
351 case METADATA_CHANNEL
:
352 fops
= <tng_metadata_fops
;
356 chan_file
= anon_inode_getfile("[lttng_channel]",
359 if (IS_ERR(chan_file
)) {
360 ret
= PTR_ERR(chan_file
);
363 switch (channel_type
) {
364 case PER_CPU_CHANNEL
:
365 if (chan_param
->output
== LTTNG_KERNEL_SPLICE
) {
366 transport_name
= chan_param
->overwrite
?
367 "relay-overwrite" : "relay-discard";
368 } else if (chan_param
->output
== LTTNG_KERNEL_MMAP
) {
369 transport_name
= chan_param
->overwrite
?
370 "relay-overwrite-mmap" : "relay-discard-mmap";
375 case METADATA_CHANNEL
:
376 if (chan_param
->output
== LTTNG_KERNEL_SPLICE
)
377 transport_name
= "relay-metadata";
378 else if (chan_param
->output
== LTTNG_KERNEL_MMAP
)
379 transport_name
= "relay-metadata-mmap";
384 transport_name
= "<unknown>";
388 * We tolerate no failure path after channel creation. It will stay
389 * invariant for the rest of the session.
391 chan
= lttng_channel_create(session
, transport_name
, NULL
,
392 chan_param
->subbuf_size
,
393 chan_param
->num_subbuf
,
394 chan_param
->switch_timer_interval
,
395 chan_param
->read_timer_interval
);
400 chan
->file
= chan_file
;
401 chan_file
->private_data
= chan
;
402 fd_install(chan_fd
, chan_file
);
403 if (channel_type
== METADATA_CHANNEL
) {
404 session
->metadata
= chan
;
405 lttng_metadata_create_events(chan_file
);
408 /* The channel created holds a reference on the session */
409 atomic_long_inc(&session_file
->f_count
);
416 put_unused_fd(chan_fd
);
422 * lttng_session_ioctl - lttng session fd ioctl
428 * This ioctl implements lttng commands:
429 * LTTNG_KERNEL_CHANNEL
430 * Returns a LTTng channel file descriptor
431 * LTTNG_KERNEL_ENABLE
432 * Enables tracing for a session (weak enable)
433 * LTTNG_KERNEL_DISABLE
434 * Disables tracing for a session (strong disable)
435 * LTTNG_KERNEL_METADATA
436 * Returns a LTTng metadata file descriptor
438 * The returned channel will be deleted when its file descriptor is closed.
441 long lttng_session_ioctl(struct file
*file
, unsigned int cmd
, unsigned long arg
)
443 struct lttng_session
*session
= file
->private_data
;
446 case LTTNG_KERNEL_OLD_CHANNEL
:
448 struct lttng_kernel_channel chan_param
;
449 struct lttng_kernel_old_channel old_chan_param
;
451 if (copy_from_user(&old_chan_param
,
452 (struct lttng_kernel_old_channel __user
*) arg
,
453 sizeof(struct lttng_kernel_old_channel
)))
455 chan_param
.overwrite
= old_chan_param
.overwrite
;
456 chan_param
.subbuf_size
= old_chan_param
.subbuf_size
;
457 chan_param
.num_subbuf
= old_chan_param
.num_subbuf
;
458 chan_param
.switch_timer_interval
= old_chan_param
.switch_timer_interval
;
459 chan_param
.read_timer_interval
= old_chan_param
.read_timer_interval
;
460 chan_param
.output
= old_chan_param
.output
;
462 return lttng_abi_create_channel(file
, &chan_param
,
465 case LTTNG_KERNEL_CHANNEL
:
467 struct lttng_kernel_channel chan_param
;
469 if (copy_from_user(&chan_param
,
470 (struct lttng_kernel_channel __user
*) arg
,
471 sizeof(struct lttng_kernel_channel
)))
473 return lttng_abi_create_channel(file
, &chan_param
,
476 case LTTNG_KERNEL_OLD_SESSION_START
:
477 case LTTNG_KERNEL_OLD_ENABLE
:
478 case LTTNG_KERNEL_SESSION_START
:
479 case LTTNG_KERNEL_ENABLE
:
480 return lttng_session_enable(session
);
481 case LTTNG_KERNEL_OLD_SESSION_STOP
:
482 case LTTNG_KERNEL_OLD_DISABLE
:
483 case LTTNG_KERNEL_SESSION_STOP
:
484 case LTTNG_KERNEL_DISABLE
:
485 return lttng_session_disable(session
);
486 case LTTNG_KERNEL_OLD_METADATA
:
488 struct lttng_kernel_channel chan_param
;
489 struct lttng_kernel_old_channel old_chan_param
;
491 if (copy_from_user(&old_chan_param
,
492 (struct lttng_kernel_old_channel __user
*) arg
,
493 sizeof(struct lttng_kernel_old_channel
)))
495 chan_param
.overwrite
= old_chan_param
.overwrite
;
496 chan_param
.subbuf_size
= old_chan_param
.subbuf_size
;
497 chan_param
.num_subbuf
= old_chan_param
.num_subbuf
;
498 chan_param
.switch_timer_interval
= old_chan_param
.switch_timer_interval
;
499 chan_param
.read_timer_interval
= old_chan_param
.read_timer_interval
;
500 chan_param
.output
= old_chan_param
.output
;
502 return lttng_abi_create_channel(file
, &chan_param
,
505 case LTTNG_KERNEL_METADATA
:
507 struct lttng_kernel_channel chan_param
;
509 if (copy_from_user(&chan_param
,
510 (struct lttng_kernel_channel __user
*) arg
,
511 sizeof(struct lttng_kernel_channel
)))
513 return lttng_abi_create_channel(file
, &chan_param
,
522 * Called when the last file reference is dropped.
524 * Big fat note: channels and events are invariant for the whole session after
525 * their creation. So this session destruction also destroys all channel and
526 * event structures specific to this session (they are not destroyed when their
527 * individual file is released).
530 int lttng_session_release(struct inode
*inode
, struct file
*file
)
532 struct lttng_session
*session
= file
->private_data
;
535 lttng_session_destroy(session
);
539 static const struct file_operations lttng_session_fops
= {
540 .owner
= THIS_MODULE
,
541 .release
= lttng_session_release
,
542 .unlocked_ioctl
= lttng_session_ioctl
,
544 .compat_ioctl
= lttng_session_ioctl
,
549 int lttng_abi_open_stream(struct file
*channel_file
)
551 struct lttng_channel
*channel
= channel_file
->private_data
;
552 struct lib_ring_buffer
*buf
;
554 struct file
*stream_file
;
556 buf
= channel
->ops
->buffer_read_open(channel
->chan
);
560 stream_fd
= get_unused_fd();
565 stream_file
= anon_inode_getfile("[lttng_stream]",
566 &lib_ring_buffer_file_operations
,
568 if (IS_ERR(stream_file
)) {
569 ret
= PTR_ERR(stream_file
);
573 * OPEN_FMODE, called within anon_inode_getfile/alloc_file, don't honor
574 * FMODE_LSEEK, FMODE_PREAD nor FMODE_PWRITE. We need to read from this
575 * file descriptor, so we set FMODE_PREAD here.
577 stream_file
->f_mode
|= FMODE_PREAD
;
578 fd_install(stream_fd
, stream_file
);
580 * The stream holds a reference to the channel within the generic ring
581 * buffer library, so no need to hold a refcount on the channel and
582 * session files here.
587 put_unused_fd(stream_fd
);
589 channel
->ops
->buffer_read_close(buf
);
594 int lttng_abi_create_event(struct file
*channel_file
,
595 struct lttng_kernel_event
*event_param
)
597 struct lttng_channel
*channel
= channel_file
->private_data
;
598 struct lttng_event
*event
;
600 struct file
*event_file
;
602 event_param
->name
[LTTNG_KERNEL_SYM_NAME_LEN
- 1] = '\0';
603 switch (event_param
->instrumentation
) {
604 case LTTNG_KERNEL_KRETPROBE
:
605 event_param
->u
.kretprobe
.symbol_name
[LTTNG_KERNEL_SYM_NAME_LEN
- 1] = '\0';
607 case LTTNG_KERNEL_KPROBE
:
608 event_param
->u
.kprobe
.symbol_name
[LTTNG_KERNEL_SYM_NAME_LEN
- 1] = '\0';
610 case LTTNG_KERNEL_FUNCTION
:
611 event_param
->u
.ftrace
.symbol_name
[LTTNG_KERNEL_SYM_NAME_LEN
- 1] = '\0';
616 switch (event_param
->instrumentation
) {
618 event_fd
= get_unused_fd();
623 event_file
= anon_inode_getfile("[lttng_event]",
626 if (IS_ERR(event_file
)) {
627 ret
= PTR_ERR(event_file
);
631 * We tolerate no failure path after event creation. It
632 * will stay invariant for the rest of the session.
634 event
= lttng_event_create(channel
, event_param
, NULL
, NULL
);
639 event_file
->private_data
= event
;
640 fd_install(event_fd
, event_file
);
641 /* The event holds a reference on the channel */
642 atomic_long_inc(&channel_file
->f_count
);
644 case LTTNG_KERNEL_SYSCALL
:
646 * Only all-syscall tracing supported for now.
648 if (event_param
->name
[0] != '\0')
650 ret
= lttng_syscalls_register(channel
, NULL
);
661 put_unused_fd(event_fd
);
667 * lttng_channel_ioctl - lttng syscall through ioctl
673 * This ioctl implements lttng commands:
674 * LTTNG_KERNEL_STREAM
675 * Returns an event stream file descriptor or failure.
676 * (typically, one event stream records events from one CPU)
678 * Returns an event file descriptor or failure.
679 * LTTNG_KERNEL_CONTEXT
680 * Prepend a context field to each event in the channel
681 * LTTNG_KERNEL_ENABLE
682 * Enable recording for events in this channel (weak enable)
683 * LTTNG_KERNEL_DISABLE
684 * Disable recording for events in this channel (strong disable)
686 * Channel and event file descriptors also hold a reference on the session.
689 long lttng_channel_ioctl(struct file
*file
, unsigned int cmd
, unsigned long arg
)
691 struct lttng_channel
*channel
= file
->private_data
;
694 case LTTNG_KERNEL_OLD_STREAM
:
695 case LTTNG_KERNEL_STREAM
:
696 return lttng_abi_open_stream(file
);
697 case LTTNG_KERNEL_OLD_EVENT
:
699 struct lttng_kernel_event
*uevent_param
;
700 struct lttng_kernel_old_event
*old_uevent_param
;
703 uevent_param
= kmalloc(sizeof(struct lttng_kernel_event
),
709 old_uevent_param
= kmalloc(
710 sizeof(struct lttng_kernel_old_event
),
712 if (!old_uevent_param
) {
714 goto old_event_error_free_param
;
716 if (copy_from_user(old_uevent_param
,
717 (struct lttng_kernel_old_event __user
*) arg
,
718 sizeof(struct lttng_kernel_old_event
))) {
720 goto old_event_error_free_old_param
;
723 memcpy(uevent_param
->name
, old_uevent_param
->name
,
724 sizeof(uevent_param
->name
));
725 uevent_param
->instrumentation
=
726 old_uevent_param
->instrumentation
;
728 switch (old_uevent_param
->instrumentation
) {
729 case LTTNG_KERNEL_KPROBE
:
730 uevent_param
->u
.kprobe
.addr
=
731 old_uevent_param
->u
.kprobe
.addr
;
732 uevent_param
->u
.kprobe
.offset
=
733 old_uevent_param
->u
.kprobe
.offset
;
734 memcpy(uevent_param
->u
.kprobe
.symbol_name
,
735 old_uevent_param
->u
.kprobe
.symbol_name
,
736 sizeof(uevent_param
->u
.kprobe
.symbol_name
));
738 case LTTNG_KERNEL_KRETPROBE
:
739 uevent_param
->u
.kretprobe
.addr
=
740 old_uevent_param
->u
.kretprobe
.addr
;
741 uevent_param
->u
.kretprobe
.offset
=
742 old_uevent_param
->u
.kretprobe
.offset
;
743 memcpy(uevent_param
->u
.kretprobe
.symbol_name
,
744 old_uevent_param
->u
.kretprobe
.symbol_name
,
745 sizeof(uevent_param
->u
.kretprobe
.symbol_name
));
747 case LTTNG_KERNEL_FUNCTION
:
748 memcpy(uevent_param
->u
.ftrace
.symbol_name
,
749 old_uevent_param
->u
.ftrace
.symbol_name
,
750 sizeof(uevent_param
->u
.ftrace
.symbol_name
));
755 ret
= lttng_abi_create_event(file
, uevent_param
);
757 old_event_error_free_old_param
:
758 kfree(old_uevent_param
);
759 old_event_error_free_param
:
764 case LTTNG_KERNEL_EVENT
:
766 struct lttng_kernel_event uevent_param
;
768 if (copy_from_user(&uevent_param
,
769 (struct lttng_kernel_event __user
*) arg
,
770 sizeof(uevent_param
)))
772 return lttng_abi_create_event(file
, &uevent_param
);
774 case LTTNG_KERNEL_OLD_CONTEXT
:
776 struct lttng_kernel_context
*ucontext_param
;
777 struct lttng_kernel_old_context
*old_ucontext_param
;
780 ucontext_param
= kmalloc(sizeof(struct lttng_kernel_context
),
782 if (!ucontext_param
) {
786 old_ucontext_param
= kmalloc(sizeof(struct lttng_kernel_old_context
),
788 if (!old_ucontext_param
) {
790 goto old_ctx_error_free_param
;
793 if (copy_from_user(old_ucontext_param
,
794 (struct lttng_kernel_old_context __user
*) arg
,
795 sizeof(struct lttng_kernel_old_context
))) {
797 goto old_ctx_error_free_old_param
;
799 ucontext_param
->ctx
= old_ucontext_param
->ctx
;
800 memcpy(ucontext_param
->padding
, old_ucontext_param
->padding
,
801 sizeof(ucontext_param
->padding
));
802 /* only type that uses the union */
803 if (old_ucontext_param
->ctx
== LTTNG_KERNEL_CONTEXT_PERF_COUNTER
) {
804 ucontext_param
->u
.perf_counter
.type
=
805 old_ucontext_param
->u
.perf_counter
.type
;
806 ucontext_param
->u
.perf_counter
.config
=
807 old_ucontext_param
->u
.perf_counter
.config
;
808 memcpy(ucontext_param
->u
.perf_counter
.name
,
809 old_ucontext_param
->u
.perf_counter
.name
,
810 sizeof(ucontext_param
->u
.perf_counter
.name
));
813 ret
= lttng_abi_add_context(file
,
815 &channel
->ctx
, channel
->session
);
817 old_ctx_error_free_old_param
:
818 kfree(old_ucontext_param
);
819 old_ctx_error_free_param
:
820 kfree(ucontext_param
);
824 case LTTNG_KERNEL_CONTEXT
:
826 struct lttng_kernel_context ucontext_param
;
828 if (copy_from_user(&ucontext_param
,
829 (struct lttng_kernel_context __user
*) arg
,
830 sizeof(ucontext_param
)))
832 return lttng_abi_add_context(file
,
834 &channel
->ctx
, channel
->session
);
836 case LTTNG_KERNEL_OLD_ENABLE
:
837 case LTTNG_KERNEL_ENABLE
:
838 return lttng_channel_enable(channel
);
839 case LTTNG_KERNEL_OLD_DISABLE
:
840 case LTTNG_KERNEL_DISABLE
:
841 return lttng_channel_disable(channel
);
849 * lttng_metadata_ioctl - lttng syscall through ioctl
855 * This ioctl implements lttng commands:
856 * LTTNG_KERNEL_STREAM
857 * Returns an event stream file descriptor or failure.
859 * Channel and event file descriptors also hold a reference on the session.
862 long lttng_metadata_ioctl(struct file
*file
, unsigned int cmd
, unsigned long arg
)
865 case LTTNG_KERNEL_OLD_STREAM
:
866 case LTTNG_KERNEL_STREAM
:
867 return lttng_abi_open_stream(file
);
874 * lttng_channel_poll - lttng stream addition/removal monitoring
879 unsigned int lttng_channel_poll(struct file
*file
, poll_table
*wait
)
881 struct lttng_channel
*channel
= file
->private_data
;
882 unsigned int mask
= 0;
884 if (file
->f_mode
& FMODE_READ
) {
885 poll_wait_set_exclusive(wait
);
886 poll_wait(file
, channel
->ops
->get_hp_wait_queue(channel
->chan
),
889 if (channel
->ops
->is_disabled(channel
->chan
))
891 if (channel
->ops
->is_finalized(channel
->chan
))
893 if (channel
->ops
->buffer_has_read_closed_stream(channel
->chan
))
894 return POLLIN
| POLLRDNORM
;
902 int lttng_channel_release(struct inode
*inode
, struct file
*file
)
904 struct lttng_channel
*channel
= file
->private_data
;
907 fput(channel
->session
->file
);
911 static const struct file_operations lttng_channel_fops
= {
912 .owner
= THIS_MODULE
,
913 .release
= lttng_channel_release
,
914 .poll
= lttng_channel_poll
,
915 .unlocked_ioctl
= lttng_channel_ioctl
,
917 .compat_ioctl
= lttng_channel_ioctl
,
921 static const struct file_operations lttng_metadata_fops
= {
922 .owner
= THIS_MODULE
,
923 .release
= lttng_channel_release
,
924 .unlocked_ioctl
= lttng_metadata_ioctl
,
926 .compat_ioctl
= lttng_metadata_ioctl
,
931 * lttng_event_ioctl - lttng syscall through ioctl
937 * This ioctl implements lttng commands:
938 * LTTNG_KERNEL_CONTEXT
939 * Prepend a context field to each record of this event
940 * LTTNG_KERNEL_ENABLE
941 * Enable recording for this event (weak enable)
942 * LTTNG_KERNEL_DISABLE
943 * Disable recording for this event (strong disable)
946 long lttng_event_ioctl(struct file
*file
, unsigned int cmd
, unsigned long arg
)
948 struct lttng_event
*event
= file
->private_data
;
951 case LTTNG_KERNEL_OLD_CONTEXT
:
953 struct lttng_kernel_context
*ucontext_param
;
954 struct lttng_kernel_old_context
*old_ucontext_param
;
957 ucontext_param
= kmalloc(sizeof(struct lttng_kernel_context
),
959 if (!ucontext_param
) {
963 old_ucontext_param
= kmalloc(sizeof(struct lttng_kernel_old_context
),
965 if (!old_ucontext_param
) {
967 goto old_ctx_error_free_param
;
970 if (copy_from_user(old_ucontext_param
,
971 (struct lttng_kernel_old_context __user
*) arg
,
972 sizeof(struct lttng_kernel_old_context
))) {
974 goto old_ctx_error_free_old_param
;
976 ucontext_param
->ctx
= old_ucontext_param
->ctx
;
977 memcpy(ucontext_param
->padding
, old_ucontext_param
->padding
,
978 sizeof(ucontext_param
->padding
));
979 /* only type that uses the union */
980 if (old_ucontext_param
->ctx
== LTTNG_KERNEL_CONTEXT_PERF_COUNTER
) {
981 ucontext_param
->u
.perf_counter
.type
=
982 old_ucontext_param
->u
.perf_counter
.type
;
983 ucontext_param
->u
.perf_counter
.config
=
984 old_ucontext_param
->u
.perf_counter
.config
;
985 memcpy(ucontext_param
->u
.perf_counter
.name
,
986 old_ucontext_param
->u
.perf_counter
.name
,
987 sizeof(ucontext_param
->u
.perf_counter
.name
));
990 ret
= lttng_abi_add_context(file
,
992 &event
->ctx
, event
->chan
->session
);
994 old_ctx_error_free_old_param
:
995 kfree(old_ucontext_param
);
996 old_ctx_error_free_param
:
997 kfree(ucontext_param
);
1001 case LTTNG_KERNEL_CONTEXT
:
1003 struct lttng_kernel_context ucontext_param
;
1005 if (copy_from_user(&ucontext_param
,
1006 (struct lttng_kernel_context __user
*) arg
,
1007 sizeof(ucontext_param
)))
1009 return lttng_abi_add_context(file
,
1011 &event
->ctx
, event
->chan
->session
);
1013 case LTTNG_KERNEL_OLD_ENABLE
:
1014 case LTTNG_KERNEL_ENABLE
:
1015 return lttng_event_enable(event
);
1016 case LTTNG_KERNEL_OLD_DISABLE
:
1017 case LTTNG_KERNEL_DISABLE
:
1018 return lttng_event_disable(event
);
1020 return -ENOIOCTLCMD
;
1025 int lttng_event_release(struct inode
*inode
, struct file
*file
)
1027 struct lttng_event
*event
= file
->private_data
;
1030 fput(event
->chan
->file
);
1034 /* TODO: filter control ioctl */
1035 static const struct file_operations lttng_event_fops
= {
1036 .owner
= THIS_MODULE
,
1037 .release
= lttng_event_release
,
1038 .unlocked_ioctl
= lttng_event_ioctl
,
1039 #ifdef CONFIG_COMPAT
1040 .compat_ioctl
= lttng_event_ioctl
,
1044 int __init
lttng_abi_init(void)
1048 wrapper_vmalloc_sync_all();
1049 lttng_proc_dentry
= proc_create_data("lttng", S_IRUSR
| S_IWUSR
, NULL
,
1052 if (!lttng_proc_dentry
) {
1053 printk(KERN_ERR
"Error creating LTTng control file\n");
1061 void __exit
lttng_abi_exit(void)
1063 if (lttng_proc_dentry
)
1064 remove_proc_entry("lttng", NULL
);