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 int lttng_abi_create_channel(struct file
*session_file
,
301 struct lttng_kernel_channel
*chan_param
,
302 enum channel_type channel_type
)
304 struct lttng_session
*session
= session_file
->private_data
;
305 const struct file_operations
*fops
= NULL
;
306 const char *transport_name
;
307 struct lttng_channel
*chan
;
308 struct file
*chan_file
;
312 chan_fd
= get_unused_fd();
317 switch (channel_type
) {
318 case PER_CPU_CHANNEL
:
319 fops
= <tng_channel_fops
;
321 case METADATA_CHANNEL
:
322 fops
= <tng_metadata_fops
;
326 chan_file
= anon_inode_getfile("[lttng_channel]",
329 if (IS_ERR(chan_file
)) {
330 ret
= PTR_ERR(chan_file
);
333 switch (channel_type
) {
334 case PER_CPU_CHANNEL
:
335 if (chan_param
->output
== LTTNG_KERNEL_SPLICE
) {
336 transport_name
= chan_param
->overwrite
?
337 "relay-overwrite" : "relay-discard";
338 } else if (chan_param
->output
== LTTNG_KERNEL_MMAP
) {
339 transport_name
= chan_param
->overwrite
?
340 "relay-overwrite-mmap" : "relay-discard-mmap";
345 case METADATA_CHANNEL
:
346 if (chan_param
->output
== LTTNG_KERNEL_SPLICE
)
347 transport_name
= "relay-metadata";
348 else if (chan_param
->output
== LTTNG_KERNEL_MMAP
)
349 transport_name
= "relay-metadata-mmap";
354 transport_name
= "<unknown>";
358 * We tolerate no failure path after channel creation. It will stay
359 * invariant for the rest of the session.
361 chan
= lttng_channel_create(session
, transport_name
, NULL
,
362 chan_param
->subbuf_size
,
363 chan_param
->num_subbuf
,
364 chan_param
->switch_timer_interval
,
365 chan_param
->read_timer_interval
);
370 chan
->file
= chan_file
;
371 chan_file
->private_data
= chan
;
372 fd_install(chan_fd
, chan_file
);
373 if (channel_type
== METADATA_CHANNEL
) {
374 session
->metadata
= chan
;
377 /* The channel created holds a reference on the session */
378 atomic_long_inc(&session_file
->f_count
);
385 put_unused_fd(chan_fd
);
391 * lttng_session_ioctl - lttng session fd ioctl
397 * This ioctl implements lttng commands:
398 * LTTNG_KERNEL_CHANNEL
399 * Returns a LTTng channel file descriptor
400 * LTTNG_KERNEL_ENABLE
401 * Enables tracing for a session (weak enable)
402 * LTTNG_KERNEL_DISABLE
403 * Disables tracing for a session (strong disable)
404 * LTTNG_KERNEL_METADATA
405 * Returns a LTTng metadata file descriptor
407 * The returned channel will be deleted when its file descriptor is closed.
410 long lttng_session_ioctl(struct file
*file
, unsigned int cmd
, unsigned long arg
)
412 struct lttng_session
*session
= file
->private_data
;
415 case LTTNG_KERNEL_OLD_CHANNEL
:
417 struct lttng_kernel_channel chan_param
;
418 struct lttng_kernel_old_channel old_chan_param
;
420 if (copy_from_user(&old_chan_param
,
421 (struct lttng_kernel_old_channel __user
*) arg
,
422 sizeof(struct lttng_kernel_old_channel
)))
424 chan_param
.overwrite
= old_chan_param
.overwrite
;
425 chan_param
.subbuf_size
= old_chan_param
.subbuf_size
;
426 chan_param
.num_subbuf
= old_chan_param
.num_subbuf
;
427 chan_param
.switch_timer_interval
= old_chan_param
.switch_timer_interval
;
428 chan_param
.read_timer_interval
= old_chan_param
.read_timer_interval
;
429 chan_param
.output
= old_chan_param
.output
;
431 return lttng_abi_create_channel(file
, &chan_param
,
434 case LTTNG_KERNEL_CHANNEL
:
436 struct lttng_kernel_channel chan_param
;
438 if (copy_from_user(&chan_param
,
439 (struct lttng_kernel_channel __user
*) arg
,
440 sizeof(struct lttng_kernel_channel
)))
442 return lttng_abi_create_channel(file
, &chan_param
,
445 case LTTNG_KERNEL_OLD_SESSION_START
:
446 case LTTNG_KERNEL_OLD_ENABLE
:
447 case LTTNG_KERNEL_SESSION_START
:
448 case LTTNG_KERNEL_ENABLE
:
449 return lttng_session_enable(session
);
450 case LTTNG_KERNEL_OLD_SESSION_STOP
:
451 case LTTNG_KERNEL_OLD_DISABLE
:
452 case LTTNG_KERNEL_SESSION_STOP
:
453 case LTTNG_KERNEL_DISABLE
:
454 return lttng_session_disable(session
);
455 case LTTNG_KERNEL_OLD_METADATA
:
457 struct lttng_kernel_channel chan_param
;
458 struct lttng_kernel_old_channel old_chan_param
;
460 if (copy_from_user(&old_chan_param
,
461 (struct lttng_kernel_old_channel __user
*) arg
,
462 sizeof(struct lttng_kernel_old_channel
)))
464 chan_param
.overwrite
= old_chan_param
.overwrite
;
465 chan_param
.subbuf_size
= old_chan_param
.subbuf_size
;
466 chan_param
.num_subbuf
= old_chan_param
.num_subbuf
;
467 chan_param
.switch_timer_interval
= old_chan_param
.switch_timer_interval
;
468 chan_param
.read_timer_interval
= old_chan_param
.read_timer_interval
;
469 chan_param
.output
= old_chan_param
.output
;
471 return lttng_abi_create_channel(file
, &chan_param
,
474 case LTTNG_KERNEL_METADATA
:
476 struct lttng_kernel_channel chan_param
;
478 if (copy_from_user(&chan_param
,
479 (struct lttng_kernel_channel __user
*) arg
,
480 sizeof(struct lttng_kernel_channel
)))
482 return lttng_abi_create_channel(file
, &chan_param
,
491 * Called when the last file reference is dropped.
493 * Big fat note: channels and events are invariant for the whole session after
494 * their creation. So this session destruction also destroys all channel and
495 * event structures specific to this session (they are not destroyed when their
496 * individual file is released).
499 int lttng_session_release(struct inode
*inode
, struct file
*file
)
501 struct lttng_session
*session
= file
->private_data
;
504 lttng_session_destroy(session
);
508 static const struct file_operations lttng_session_fops
= {
509 .owner
= THIS_MODULE
,
510 .release
= lttng_session_release
,
511 .unlocked_ioctl
= lttng_session_ioctl
,
513 .compat_ioctl
= lttng_session_ioctl
,
518 int lttng_abi_open_stream(struct file
*channel_file
)
520 struct lttng_channel
*channel
= channel_file
->private_data
;
521 struct lib_ring_buffer
*buf
;
523 struct file
*stream_file
;
525 buf
= channel
->ops
->buffer_read_open(channel
->chan
);
529 stream_fd
= get_unused_fd();
534 stream_file
= anon_inode_getfile("[lttng_stream]",
535 &lib_ring_buffer_file_operations
,
537 if (IS_ERR(stream_file
)) {
538 ret
= PTR_ERR(stream_file
);
542 * OPEN_FMODE, called within anon_inode_getfile/alloc_file, don't honor
543 * FMODE_LSEEK, FMODE_PREAD nor FMODE_PWRITE. We need to read from this
544 * file descriptor, so we set FMODE_PREAD here.
546 stream_file
->f_mode
|= FMODE_PREAD
;
547 fd_install(stream_fd
, stream_file
);
549 * The stream holds a reference to the channel within the generic ring
550 * buffer library, so no need to hold a refcount on the channel and
551 * session files here.
556 put_unused_fd(stream_fd
);
558 channel
->ops
->buffer_read_close(buf
);
563 int lttng_abi_create_event(struct file
*channel_file
,
564 struct lttng_kernel_event
*event_param
)
566 struct lttng_channel
*channel
= channel_file
->private_data
;
567 struct lttng_event
*event
;
569 struct file
*event_file
;
571 event_param
->name
[LTTNG_KERNEL_SYM_NAME_LEN
- 1] = '\0';
572 switch (event_param
->instrumentation
) {
573 case LTTNG_KERNEL_KRETPROBE
:
574 event_param
->u
.kretprobe
.symbol_name
[LTTNG_KERNEL_SYM_NAME_LEN
- 1] = '\0';
576 case LTTNG_KERNEL_KPROBE
:
577 event_param
->u
.kprobe
.symbol_name
[LTTNG_KERNEL_SYM_NAME_LEN
- 1] = '\0';
579 case LTTNG_KERNEL_FUNCTION
:
580 event_param
->u
.ftrace
.symbol_name
[LTTNG_KERNEL_SYM_NAME_LEN
- 1] = '\0';
585 switch (event_param
->instrumentation
) {
587 event_fd
= get_unused_fd();
592 event_file
= anon_inode_getfile("[lttng_event]",
595 if (IS_ERR(event_file
)) {
596 ret
= PTR_ERR(event_file
);
600 * We tolerate no failure path after event creation. It
601 * will stay invariant for the rest of the session.
603 event
= lttng_event_create(channel
, event_param
, NULL
, NULL
);
608 event_file
->private_data
= event
;
609 fd_install(event_fd
, event_file
);
610 /* The event holds a reference on the channel */
611 atomic_long_inc(&channel_file
->f_count
);
613 case LTTNG_KERNEL_SYSCALL
:
615 * Only all-syscall tracing supported for now.
617 if (event_param
->name
[0] != '\0')
619 ret
= lttng_syscalls_register(channel
, NULL
);
630 put_unused_fd(event_fd
);
636 * lttng_channel_ioctl - lttng syscall through ioctl
642 * This ioctl implements lttng commands:
643 * LTTNG_KERNEL_STREAM
644 * Returns an event stream file descriptor or failure.
645 * (typically, one event stream records events from one CPU)
647 * Returns an event file descriptor or failure.
648 * LTTNG_KERNEL_CONTEXT
649 * Prepend a context field to each event in the channel
650 * LTTNG_KERNEL_ENABLE
651 * Enable recording for events in this channel (weak enable)
652 * LTTNG_KERNEL_DISABLE
653 * Disable recording for events in this channel (strong disable)
655 * Channel and event file descriptors also hold a reference on the session.
658 long lttng_channel_ioctl(struct file
*file
, unsigned int cmd
, unsigned long arg
)
660 struct lttng_channel
*channel
= file
->private_data
;
663 case LTTNG_KERNEL_OLD_STREAM
:
664 case LTTNG_KERNEL_STREAM
:
665 return lttng_abi_open_stream(file
);
666 case LTTNG_KERNEL_OLD_EVENT
:
668 struct lttng_kernel_event
*uevent_param
;
669 struct lttng_kernel_old_event
*old_uevent_param
;
672 uevent_param
= kmalloc(sizeof(struct lttng_kernel_event
),
678 old_uevent_param
= kmalloc(
679 sizeof(struct lttng_kernel_old_event
),
681 if (!old_uevent_param
) {
683 goto old_event_error_free_param
;
685 if (copy_from_user(old_uevent_param
,
686 (struct lttng_kernel_old_event __user
*) arg
,
687 sizeof(struct lttng_kernel_old_event
))) {
689 goto old_event_error_free_old_param
;
692 memcpy(uevent_param
->name
, old_uevent_param
->name
,
693 sizeof(uevent_param
->name
));
694 uevent_param
->instrumentation
=
695 old_uevent_param
->instrumentation
;
697 switch (old_uevent_param
->instrumentation
) {
698 case LTTNG_KERNEL_KPROBE
:
699 uevent_param
->u
.kprobe
.addr
=
700 old_uevent_param
->u
.kprobe
.addr
;
701 uevent_param
->u
.kprobe
.offset
=
702 old_uevent_param
->u
.kprobe
.offset
;
703 memcpy(uevent_param
->u
.kprobe
.symbol_name
,
704 old_uevent_param
->u
.kprobe
.symbol_name
,
705 sizeof(uevent_param
->u
.kprobe
.symbol_name
));
707 case LTTNG_KERNEL_KRETPROBE
:
708 uevent_param
->u
.kretprobe
.addr
=
709 old_uevent_param
->u
.kretprobe
.addr
;
710 uevent_param
->u
.kretprobe
.offset
=
711 old_uevent_param
->u
.kretprobe
.offset
;
712 memcpy(uevent_param
->u
.kretprobe
.symbol_name
,
713 old_uevent_param
->u
.kretprobe
.symbol_name
,
714 sizeof(uevent_param
->u
.kretprobe
.symbol_name
));
716 case LTTNG_KERNEL_FUNCTION
:
717 memcpy(uevent_param
->u
.ftrace
.symbol_name
,
718 old_uevent_param
->u
.ftrace
.symbol_name
,
719 sizeof(uevent_param
->u
.ftrace
.symbol_name
));
724 ret
= lttng_abi_create_event(file
, uevent_param
);
726 old_event_error_free_old_param
:
727 kfree(old_uevent_param
);
728 old_event_error_free_param
:
733 case LTTNG_KERNEL_EVENT
:
735 struct lttng_kernel_event uevent_param
;
737 if (copy_from_user(&uevent_param
,
738 (struct lttng_kernel_event __user
*) arg
,
739 sizeof(uevent_param
)))
741 return lttng_abi_create_event(file
, &uevent_param
);
743 case LTTNG_KERNEL_OLD_CONTEXT
:
745 struct lttng_kernel_context
*ucontext_param
;
746 struct lttng_kernel_old_context
*old_ucontext_param
;
749 ucontext_param
= kmalloc(sizeof(struct lttng_kernel_context
),
751 if (!ucontext_param
) {
755 old_ucontext_param
= kmalloc(sizeof(struct lttng_kernel_old_context
),
757 if (!old_ucontext_param
) {
759 goto old_ctx_error_free_param
;
762 if (copy_from_user(old_ucontext_param
,
763 (struct lttng_kernel_old_context __user
*) arg
,
764 sizeof(struct lttng_kernel_old_context
))) {
766 goto old_ctx_error_free_old_param
;
768 ucontext_param
->ctx
= old_ucontext_param
->ctx
;
769 memcpy(ucontext_param
->padding
, old_ucontext_param
->padding
,
770 sizeof(ucontext_param
->padding
));
771 /* only type that uses the union */
772 if (old_ucontext_param
->ctx
== LTTNG_KERNEL_CONTEXT_PERF_COUNTER
) {
773 ucontext_param
->u
.perf_counter
.type
=
774 old_ucontext_param
->u
.perf_counter
.type
;
775 ucontext_param
->u
.perf_counter
.config
=
776 old_ucontext_param
->u
.perf_counter
.config
;
777 memcpy(ucontext_param
->u
.perf_counter
.name
,
778 old_ucontext_param
->u
.perf_counter
.name
,
779 sizeof(ucontext_param
->u
.perf_counter
.name
));
782 ret
= lttng_abi_add_context(file
,
784 &channel
->ctx
, channel
->session
);
786 old_ctx_error_free_old_param
:
787 kfree(old_ucontext_param
);
788 old_ctx_error_free_param
:
789 kfree(ucontext_param
);
793 case LTTNG_KERNEL_CONTEXT
:
795 struct lttng_kernel_context ucontext_param
;
797 if (copy_from_user(&ucontext_param
,
798 (struct lttng_kernel_context __user
*) arg
,
799 sizeof(ucontext_param
)))
801 return lttng_abi_add_context(file
,
803 &channel
->ctx
, channel
->session
);
805 case LTTNG_KERNEL_OLD_ENABLE
:
806 case LTTNG_KERNEL_ENABLE
:
807 return lttng_channel_enable(channel
);
808 case LTTNG_KERNEL_OLD_DISABLE
:
809 case LTTNG_KERNEL_DISABLE
:
810 return lttng_channel_disable(channel
);
818 * lttng_metadata_ioctl - lttng syscall through ioctl
824 * This ioctl implements lttng commands:
825 * LTTNG_KERNEL_STREAM
826 * Returns an event stream file descriptor or failure.
828 * Channel and event file descriptors also hold a reference on the session.
831 long lttng_metadata_ioctl(struct file
*file
, unsigned int cmd
, unsigned long arg
)
834 case LTTNG_KERNEL_OLD_STREAM
:
835 case LTTNG_KERNEL_STREAM
:
836 return lttng_abi_open_stream(file
);
843 * lttng_channel_poll - lttng stream addition/removal monitoring
848 unsigned int lttng_channel_poll(struct file
*file
, poll_table
*wait
)
850 struct lttng_channel
*channel
= file
->private_data
;
851 unsigned int mask
= 0;
853 if (file
->f_mode
& FMODE_READ
) {
854 poll_wait_set_exclusive(wait
);
855 poll_wait(file
, channel
->ops
->get_hp_wait_queue(channel
->chan
),
858 if (channel
->ops
->is_disabled(channel
->chan
))
860 if (channel
->ops
->is_finalized(channel
->chan
))
862 if (channel
->ops
->buffer_has_read_closed_stream(channel
->chan
))
863 return POLLIN
| POLLRDNORM
;
871 int lttng_channel_release(struct inode
*inode
, struct file
*file
)
873 struct lttng_channel
*channel
= file
->private_data
;
876 fput(channel
->session
->file
);
880 static const struct file_operations lttng_channel_fops
= {
881 .owner
= THIS_MODULE
,
882 .release
= lttng_channel_release
,
883 .poll
= lttng_channel_poll
,
884 .unlocked_ioctl
= lttng_channel_ioctl
,
886 .compat_ioctl
= lttng_channel_ioctl
,
890 static const struct file_operations lttng_metadata_fops
= {
891 .owner
= THIS_MODULE
,
892 .release
= lttng_channel_release
,
893 .unlocked_ioctl
= lttng_metadata_ioctl
,
895 .compat_ioctl
= lttng_metadata_ioctl
,
900 * lttng_event_ioctl - lttng syscall through ioctl
906 * This ioctl implements lttng commands:
907 * LTTNG_KERNEL_CONTEXT
908 * Prepend a context field to each record of this event
909 * LTTNG_KERNEL_ENABLE
910 * Enable recording for this event (weak enable)
911 * LTTNG_KERNEL_DISABLE
912 * Disable recording for this event (strong disable)
915 long lttng_event_ioctl(struct file
*file
, unsigned int cmd
, unsigned long arg
)
917 struct lttng_event
*event
= file
->private_data
;
920 case LTTNG_KERNEL_OLD_CONTEXT
:
922 struct lttng_kernel_context
*ucontext_param
;
923 struct lttng_kernel_old_context
*old_ucontext_param
;
926 ucontext_param
= kmalloc(sizeof(struct lttng_kernel_context
),
928 if (!ucontext_param
) {
932 old_ucontext_param
= kmalloc(sizeof(struct lttng_kernel_old_context
),
934 if (!old_ucontext_param
) {
936 goto old_ctx_error_free_param
;
939 if (copy_from_user(old_ucontext_param
,
940 (struct lttng_kernel_old_context __user
*) arg
,
941 sizeof(struct lttng_kernel_old_context
))) {
943 goto old_ctx_error_free_old_param
;
945 ucontext_param
->ctx
= old_ucontext_param
->ctx
;
946 memcpy(ucontext_param
->padding
, old_ucontext_param
->padding
,
947 sizeof(ucontext_param
->padding
));
948 /* only type that uses the union */
949 if (old_ucontext_param
->ctx
== LTTNG_KERNEL_CONTEXT_PERF_COUNTER
) {
950 ucontext_param
->u
.perf_counter
.type
=
951 old_ucontext_param
->u
.perf_counter
.type
;
952 ucontext_param
->u
.perf_counter
.config
=
953 old_ucontext_param
->u
.perf_counter
.config
;
954 memcpy(ucontext_param
->u
.perf_counter
.name
,
955 old_ucontext_param
->u
.perf_counter
.name
,
956 sizeof(ucontext_param
->u
.perf_counter
.name
));
959 ret
= lttng_abi_add_context(file
,
961 &event
->ctx
, event
->chan
->session
);
963 old_ctx_error_free_old_param
:
964 kfree(old_ucontext_param
);
965 old_ctx_error_free_param
:
966 kfree(ucontext_param
);
970 case LTTNG_KERNEL_CONTEXT
:
972 struct lttng_kernel_context ucontext_param
;
974 if (copy_from_user(&ucontext_param
,
975 (struct lttng_kernel_context __user
*) arg
,
976 sizeof(ucontext_param
)))
978 return lttng_abi_add_context(file
,
980 &event
->ctx
, event
->chan
->session
);
982 case LTTNG_KERNEL_OLD_ENABLE
:
983 case LTTNG_KERNEL_ENABLE
:
984 return lttng_event_enable(event
);
985 case LTTNG_KERNEL_OLD_DISABLE
:
986 case LTTNG_KERNEL_DISABLE
:
987 return lttng_event_disable(event
);
994 int lttng_event_release(struct inode
*inode
, struct file
*file
)
996 struct lttng_event
*event
= file
->private_data
;
999 fput(event
->chan
->file
);
1003 /* TODO: filter control ioctl */
1004 static const struct file_operations lttng_event_fops
= {
1005 .owner
= THIS_MODULE
,
1006 .release
= lttng_event_release
,
1007 .unlocked_ioctl
= lttng_event_ioctl
,
1008 #ifdef CONFIG_COMPAT
1009 .compat_ioctl
= lttng_event_ioctl
,
1013 int __init
lttng_abi_init(void)
1017 wrapper_vmalloc_sync_all();
1018 lttng_proc_dentry
= proc_create_data("lttng", S_IRUSR
| S_IWUSR
, NULL
,
1021 if (!lttng_proc_dentry
) {
1022 printk(KERN_ERR
"Error creating LTTng control file\n");
1030 void __exit
lttng_abi_exit(void)
1032 if (lttng_proc_dentry
)
1033 remove_proc_entry("lttng", NULL
);