Add process priority (as shown in /proc) to context
[lttng-modules.git] / ltt-debugfs-abi.c
CommitLineData
baf20995
MD
1/*
2 * ltt-debugfs-abi.c
3 *
4 * Copyright 2010 (c) - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
5 *
6 * LTTng debugfs ABI
7 *
8 * Mimic system calls for:
9 * - session creation, returns a file descriptor or failure.
ad1c05e1
MD
10 * - channel creation, returns a file descriptor or failure.
11 * - Operates on a session file descriptor
12 * - Takes all channel options as parameters.
13 * - stream get, returns a file descriptor or failure.
14 * - Operates on a channel file descriptor.
15 * - stream notifier get, returns a file descriptor or failure.
16 * - Operates on a channel file descriptor.
17 * - event creation, returns a file descriptor or failure.
18 * - Operates on a channel file descriptor
19 * - Takes an event name as parameter
20 * - Takes an instrumentation source as parameter
21 * - e.g. tracepoints, dynamic_probes...
22 * - Takes instrumentation source specific arguments.
baf20995
MD
23 */
24
11b5a3c2 25#include <linux/module.h>
baf20995 26#include <linux/debugfs.h>
11b5a3c2
MD
27#include <linux/anon_inodes.h>
28#include <linux/file.h>
29#include <linux/uaccess.h>
30#include <linux/slab.h>
b13f3ebe 31#include "wrapper/vmalloc.h" /* for wrapper_vmalloc_sync_all() */
f3bc08c5 32#include "wrapper/ringbuffer/vfs.h"
11b5a3c2 33#include "ltt-debugfs-abi.h"
ad1c05e1 34#include "ltt-events.h"
80c16bcf 35#include "ltt-tracer.h"
baf20995
MD
36
37/*
38 * This is LTTng's own personal way to create a system call as an external
39 * module. We use ioctl() on /sys/kernel/debug/lttng.
40 */
41
42static struct dentry *lttng_dentry;
ad1c05e1
MD
43static const struct file_operations lttng_fops;
44static const struct file_operations lttng_session_fops;
45static const struct file_operations lttng_channel_fops;
5dbbdb43 46static const struct file_operations lttng_metadata_fops;
305d3e42 47static const struct file_operations lttng_event_fops;
baf20995 48
5dbbdb43
MD
49enum channel_type {
50 PER_CPU_CHANNEL,
5dbbdb43
MD
51 METADATA_CHANNEL,
52};
53
ad1c05e1 54static
baf20995
MD
55int lttng_abi_create_session(void)
56{
57 struct ltt_session *session;
c0e31d2e 58 struct file *session_file;
11b5a3c2 59 int session_fd, ret;
baf20995 60
653fe716 61 session = ltt_session_create();
baf20995
MD
62 if (!session)
63 return -ENOMEM;
1c25284c 64 session_fd = get_unused_fd();
baf20995
MD
65 if (session_fd < 0) {
66 ret = session_fd;
67 goto fd_error;
68 }
c0e31d2e 69 session_file = anon_inode_getfile("[lttng_session]",
ad1c05e1 70 &lttng_session_fops,
baf20995 71 session, O_RDWR);
c0e31d2e
MD
72 if (IS_ERR(session_file)) {
73 ret = PTR_ERR(session_file);
baf20995
MD
74 goto file_error;
75 }
c0e31d2e
MD
76 session->file = session_file;
77 fd_install(session_fd, session_file);
baf20995
MD
78 return session_fd;
79
80file_error:
81 put_unused_fd(session_fd);
82fd_error:
83 ltt_session_destroy(session);
84 return ret;
85}
86
271b6681
MD
87static
88int lttng_abi_tracepoint_list(void)
89{
90 struct file *tracepoint_list_file;
91 int file_fd, ret;
92
93 file_fd = get_unused_fd();
94 if (file_fd < 0) {
95 ret = file_fd;
96 goto fd_error;
97 }
30f18bf0 98
271b6681
MD
99 tracepoint_list_file = anon_inode_getfile("[lttng_session]",
100 &lttng_tracepoint_list_fops,
101 NULL, O_RDWR);
102 if (IS_ERR(tracepoint_list_file)) {
103 ret = PTR_ERR(tracepoint_list_file);
104 goto file_error;
105 }
30f18bf0
MD
106 ret = lttng_tracepoint_list_fops.open(NULL, tracepoint_list_file);
107 if (ret < 0)
108 goto open_error;
271b6681 109 fd_install(file_fd, tracepoint_list_file);
30f18bf0
MD
110 if (file_fd < 0) {
111 ret = file_fd;
112 goto fd_error;
113 }
271b6681
MD
114 return file_fd;
115
30f18bf0
MD
116open_error:
117 fput(tracepoint_list_file);
271b6681
MD
118file_error:
119 put_unused_fd(file_fd);
120fd_error:
121 return ret;
122}
123
80c16bcf
MD
124static
125long lttng_abi_tracer_version(struct file *file,
126 struct lttng_kernel_tracer_version __user *uversion_param)
127{
128 struct lttng_kernel_tracer_version v;
129
130 v.version = LTTNG_VERSION;
131 v.patchlevel = LTTNG_PATCHLEVEL;
132 v.sublevel = LTTNG_SUBLEVEL;
133
134 if (copy_to_user(uversion_param, &v, sizeof(v)))
135 return -EFAULT;
136 return 0;
137}
138
8070f5c0
MD
139static
140long lttng_abi_add_context(struct file *file,
141 struct lttng_kernel_context __user *ucontext_param,
142 struct lttng_ctx **ctx, struct ltt_session *session)
143{
144 struct lttng_kernel_context context_param;
145
146 if (session->been_active)
147 return -EPERM;
148
149 if (copy_from_user(&context_param, ucontext_param, sizeof(context_param)))
150 return -EFAULT;
151
152 switch (context_param.ctx) {
12a313a5 153 case LTTNG_KERNEL_CONTEXT_PID:
8070f5c0 154 return lttng_add_pid_to_ctx(ctx);
a8ad3613
MD
155 case LTTNG_KERNEL_CONTEXT_PRIO:
156 return lttng_add_prio_to_ctx(ctx);
12a313a5 157 case LTTNG_KERNEL_CONTEXT_PERF_COUNTER:
8070f5c0 158 return -ENOSYS;
25b2f99a
MD
159 case LTTNG_KERNEL_CONTEXT_COMM:
160 return lttng_add_comm_to_ctx(ctx);
8070f5c0
MD
161 default:
162 return -EINVAL;
163 }
164}
165
ad1c05e1
MD
166/**
167 * lttng_ioctl - lttng syscall through ioctl
168 *
c0e31d2e 169 * @file: the file
ad1c05e1
MD
170 * @cmd: the command
171 * @arg: command arg
172 *
173 * This ioctl implements lttng commands:
38d024ae 174 * LTTNG_KERNEL_SESSION
ad1c05e1 175 * Returns a LTTng trace session file descriptor
271b6681
MD
176 * LTTNG_KERNEL_TRACER_VERSION
177 * Returns the LTTng kernel tracer version
178 * LTTNG_KERNEL_TRACEPOINT_LIST
179 * Returns a file descriptor listing available tracepoints
ad1c05e1
MD
180 *
181 * The returned session will be deleted when its file descriptor is closed.
182 */
183static
c0e31d2e 184long lttng_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
ad1c05e1
MD
185{
186 switch (cmd) {
38d024ae 187 case LTTNG_KERNEL_SESSION:
ad1c05e1 188 return lttng_abi_create_session();
80c16bcf
MD
189 case LTTNG_KERNEL_TRACER_VERSION:
190 return lttng_abi_tracer_version(file,
191 (struct lttng_kernel_tracer_version __user *) arg);
271b6681
MD
192 case LTTNG_KERNEL_TRACEPOINT_LIST:
193 return lttng_abi_tracepoint_list();
ad1c05e1
MD
194 default:
195 return -ENOIOCTLCMD;
196 }
197}
198
ad1c05e1
MD
199static const struct file_operations lttng_fops = {
200 .unlocked_ioctl = lttng_ioctl,
201#ifdef CONFIG_COMPAT
03037b98 202 .compat_ioctl = lttng_ioctl,
ad1c05e1 203#endif
11b5a3c2 204};
ad1c05e1 205
5dbbdb43
MD
206/*
207 * We tolerate no failure in this function (if one happens, we print a dmesg
208 * error, but cannot return any error, because the channel information is
209 * invariant.
210 */
211static
212void lttng_metadata_create_events(struct file *channel_file)
213{
214 struct ltt_channel *channel = channel_file->private_data;
e70a4758 215 static struct lttng_kernel_event metadata_params = {
ab2277d6 216 .instrumentation = LTTNG_KERNEL_TRACEPOINT,
e70a4758
MD
217 .name = "lttng_metadata",
218 };
5dbbdb43
MD
219 struct ltt_event *event;
220 int ret;
5dbbdb43 221
5dbbdb43
MD
222 /*
223 * We tolerate no failure path after event creation. It will stay
224 * invariant for the rest of the session.
225 */
30bdb6e4 226 event = ltt_event_create(channel, &metadata_params, NULL);
5dbbdb43 227 if (!event) {
588e6a7f 228 ret = -EINVAL;
271b6681 229 goto create_error;
5dbbdb43
MD
230 }
231 return;
232
85a9ca7f 233create_error:
5dbbdb43
MD
234 WARN_ON(1);
235 return; /* not allowed to return error */
236}
237
238static
c0e31d2e 239int lttng_abi_create_channel(struct file *session_file,
38d024ae 240 struct lttng_kernel_channel __user *uchan_param,
5dbbdb43 241 enum channel_type channel_type)
baf20995 242{
c0e31d2e 243 struct ltt_session *session = session_file->private_data;
5dbbdb43
MD
244 const struct file_operations *fops;
245 const char *transport_name;
baf20995 246 struct ltt_channel *chan;
c0e31d2e 247 struct file *chan_file;
38d024ae 248 struct lttng_kernel_channel chan_param;
baf20995 249 int chan_fd;
ad1c05e1 250 int ret = 0;
baf20995 251
653fe716 252 if (copy_from_user(&chan_param, uchan_param, sizeof(chan_param)))
baf20995 253 return -EFAULT;
1c25284c 254 chan_fd = get_unused_fd();
baf20995
MD
255 if (chan_fd < 0) {
256 ret = chan_fd;
257 goto fd_error;
258 }
c0e31d2e 259 chan_file = anon_inode_getfile("[lttng_channel]",
ad1c05e1 260 &lttng_channel_fops,
03037b98 261 NULL, O_RDWR);
c0e31d2e
MD
262 if (IS_ERR(chan_file)) {
263 ret = PTR_ERR(chan_file);
baf20995
MD
264 goto file_error;
265 }
5dbbdb43
MD
266 switch (channel_type) {
267 case PER_CPU_CHANNEL:
268 transport_name = chan_param.overwrite ?
269 "relay-overwrite" : "relay-discard";
270 fops = &lttng_channel_fops;
271 break;
5dbbdb43 272 case METADATA_CHANNEL:
881833e3 273 transport_name = "relay-metadata";
5dbbdb43
MD
274 fops = &lttng_metadata_fops;
275 break;
276 default:
277 transport_name = "<unknown>";
278 break;
279 }
03037b98
MD
280 /*
281 * We tolerate no failure path after channel creation. It will stay
282 * invariant for the rest of the session.
283 */
5dbbdb43 284 chan = ltt_channel_create(session, transport_name, NULL,
11b5a3c2
MD
285 chan_param.subbuf_size,
286 chan_param.num_subbuf,
287 chan_param.switch_timer_interval,
288 chan_param.read_timer_interval);
03037b98 289 if (!chan) {
f3d01b96 290 ret = -EINVAL;
03037b98
MD
291 goto chan_error;
292 }
11b5a3c2 293 chan->file = chan_file;
c0e31d2e
MD
294 chan_file->private_data = chan;
295 fd_install(chan_fd, chan_file);
cd4bd11f 296 if (channel_type == METADATA_CHANNEL) {
cd4bd11f 297 session->metadata = chan;
4f1c3952 298 lttng_metadata_create_events(chan_file);
cd4bd11f 299 }
5dbbdb43 300
ad1c05e1 301 /* The channel created holds a reference on the session */
b0caa15a 302 atomic_long_inc(&session_file->f_count);
ad1c05e1 303
baf20995
MD
304 return chan_fd;
305
03037b98 306chan_error:
c0e31d2e 307 fput(chan_file);
baf20995
MD
308file_error:
309 put_unused_fd(chan_fd);
310fd_error:
baf20995
MD
311 return ret;
312}
313
314/**
ad1c05e1 315 * lttng_session_ioctl - lttng session fd ioctl
baf20995 316 *
c0e31d2e 317 * @file: the file
baf20995
MD
318 * @cmd: the command
319 * @arg: command arg
320 *
321 * This ioctl implements lttng commands:
38d024ae 322 * LTTNG_KERNEL_CHANNEL
baf20995 323 * Returns a LTTng channel file descriptor
8070f5c0
MD
324 * LTTNG_KERNEL_SESSION_START
325 * Starts tracing session
326 * LTTNG_KERNEL_SESSION_STOP
327 * Stops tracing session
328 * LTTNG_KERNEL_METADATA
329 * Returns a LTTng metadata file descriptor
ad1c05e1
MD
330 *
331 * The returned channel will be deleted when its file descriptor is closed.
332 */
333static
c0e31d2e 334long lttng_session_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
ad1c05e1 335{
c0e31d2e
MD
336 struct ltt_session *session = file->private_data;
337
ad1c05e1 338 switch (cmd) {
38d024ae 339 case LTTNG_KERNEL_CHANNEL:
5dbbdb43 340 return lttng_abi_create_channel(file,
38d024ae 341 (struct lttng_kernel_channel __user *) arg,
5dbbdb43 342 PER_CPU_CHANNEL);
38d024ae 343 case LTTNG_KERNEL_SESSION_START:
c0e31d2e 344 return ltt_session_start(session);
38d024ae 345 case LTTNG_KERNEL_SESSION_STOP:
c0e31d2e 346 return ltt_session_stop(session);
38d024ae 347 case LTTNG_KERNEL_METADATA:
5dbbdb43 348 return lttng_abi_create_channel(file,
38d024ae 349 (struct lttng_kernel_channel __user *) arg,
5dbbdb43 350 METADATA_CHANNEL);
ad1c05e1
MD
351 default:
352 return -ENOIOCTLCMD;
353 }
354}
355
03037b98
MD
356/*
357 * Called when the last file reference is dropped.
358 *
359 * Big fat note: channels and events are invariant for the whole session after
360 * their creation. So this session destruction also destroys all channel and
361 * event structures specific to this session (they are not destroyed when their
362 * individual file is released).
363 */
ad1c05e1 364static
03037b98 365int lttng_session_release(struct inode *inode, struct file *file)
ad1c05e1 366{
03037b98 367 struct ltt_session *session = file->private_data;
c269fff4
MD
368
369 if (session)
370 ltt_session_destroy(session);
11b5a3c2 371 return 0;
ad1c05e1 372}
ad1c05e1
MD
373
374static const struct file_operations lttng_session_fops = {
03037b98 375 .release = lttng_session_release,
ad1c05e1
MD
376 .unlocked_ioctl = lttng_session_ioctl,
377#ifdef CONFIG_COMPAT
03037b98 378 .compat_ioctl = lttng_session_ioctl,
ad1c05e1 379#endif
11b5a3c2 380};
ad1c05e1
MD
381
382static
c0e31d2e 383int lttng_abi_open_stream(struct file *channel_file)
ad1c05e1 384{
c0e31d2e 385 struct ltt_channel *channel = channel_file->private_data;
ad1c05e1
MD
386 struct lib_ring_buffer *buf;
387 int stream_fd, ret;
11b5a3c2 388 struct file *stream_file;
ad1c05e1 389
11b5a3c2 390 buf = channel->ops->buffer_read_open(channel->chan);
ad1c05e1
MD
391 if (!buf)
392 return -ENOENT;
393
1c25284c 394 stream_fd = get_unused_fd();
ad1c05e1
MD
395 if (stream_fd < 0) {
396 ret = stream_fd;
397 goto fd_error;
398 }
c0e31d2e 399 stream_file = anon_inode_getfile("[lttng_stream]",
7f57c73c 400 &lib_ring_buffer_file_operations,
ad1c05e1 401 buf, O_RDWR);
c0e31d2e
MD
402 if (IS_ERR(stream_file)) {
403 ret = PTR_ERR(stream_file);
ad1c05e1
MD
404 goto file_error;
405 }
409453cb
MD
406 /*
407 * OPEN_FMODE, called within anon_inode_getfile/alloc_file, don't honor
408 * FMODE_LSEEK, FMODE_PREAD nor FMODE_PWRITE. We need to read from this
409 * file descriptor, so we set FMODE_PREAD here.
410 */
d7b6f197 411 stream_file->f_mode |= FMODE_PREAD;
c0e31d2e 412 fd_install(stream_fd, stream_file);
dda6a249
MD
413 /*
414 * The stream holds a reference to the channel within the generic ring
415 * buffer library, so no need to hold a refcount on the channel and
416 * session files here.
417 */
ad1c05e1
MD
418 return stream_fd;
419
420file_error:
421 put_unused_fd(stream_fd);
422fd_error:
11b5a3c2 423 channel->ops->buffer_read_close(buf);
ad1c05e1
MD
424 return ret;
425}
426
653fe716 427static
c0e31d2e 428int lttng_abi_create_event(struct file *channel_file,
38d024ae 429 struct lttng_kernel_event __user *uevent_param)
653fe716 430{
c0e31d2e 431 struct ltt_channel *channel = channel_file->private_data;
653fe716 432 struct ltt_event *event;
38d024ae 433 struct lttng_kernel_event event_param;
653fe716 434 int event_fd, ret;
11b5a3c2 435 struct file *event_file;
653fe716
MD
436
437 if (copy_from_user(&event_param, uevent_param, sizeof(event_param)))
438 return -EFAULT;
30bdb6e4 439 event_param.name[LTTNG_SYM_NAME_LEN - 1] = '\0';
e0a7a7c4 440 switch (event_param.instrumentation) {
ab2277d6 441 case LTTNG_KERNEL_KPROBE:
e0a7a7c4
MD
442 event_param.u.kprobe.symbol_name[LTTNG_SYM_NAME_LEN - 1] = '\0';
443 break;
ab2277d6 444 case LTTNG_KERNEL_FUNCTION:
e0a7a7c4
MD
445 event_param.u.ftrace.symbol_name[LTTNG_SYM_NAME_LEN - 1] = '\0';
446 break;
447 default:
448 break;
449 }
1c25284c 450 event_fd = get_unused_fd();
653fe716
MD
451 if (event_fd < 0) {
452 ret = event_fd;
453 goto fd_error;
454 }
c0e31d2e 455 event_file = anon_inode_getfile("[lttng_event]",
3b923e5b 456 &lttng_event_fops,
03037b98 457 NULL, O_RDWR);
c0e31d2e
MD
458 if (IS_ERR(event_file)) {
459 ret = PTR_ERR(event_file);
653fe716
MD
460 goto file_error;
461 }
03037b98
MD
462 /*
463 * We tolerate no failure path after event creation. It will stay
464 * invariant for the rest of the session.
465 */
30bdb6e4 466 event = ltt_event_create(channel, &event_param, NULL);
03037b98 467 if (!event) {
271b6681 468 ret = -EINVAL;
d6d808f3 469 goto event_error;
03037b98 470 }
c0e31d2e
MD
471 event_file->private_data = event;
472 fd_install(event_fd, event_file);
653fe716 473 /* The event holds a reference on the channel */
b0caa15a 474 atomic_long_inc(&channel_file->f_count);
653fe716
MD
475 return event_fd;
476
03037b98 477event_error:
c0e31d2e 478 fput(event_file);
653fe716
MD
479file_error:
480 put_unused_fd(event_fd);
481fd_error:
653fe716
MD
482 return ret;
483}
ad1c05e1
MD
484
485/**
486 * lttng_channel_ioctl - lttng syscall through ioctl
487 *
c0e31d2e 488 * @file: the file
ad1c05e1
MD
489 * @cmd: the command
490 * @arg: command arg
491 *
492 * This ioctl implements lttng commands:
38d024ae 493 * LTTNG_KERNEL_STREAM
ad1c05e1
MD
494 * Returns an event stream file descriptor or failure.
495 * (typically, one event stream records events from one CPU)
38d024ae 496 * LTTNG_KERNEL_EVENT
ad1c05e1 497 * Returns an event file descriptor or failure.
8070f5c0
MD
498 * LTTNG_KERNEL_CONTEXT
499 * Prepend a context field to each event in the channel
baf20995 500 *
baf20995
MD
501 * Channel and event file descriptors also hold a reference on the session.
502 */
ad1c05e1 503static
c0e31d2e 504long lttng_channel_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
baf20995 505{
8070f5c0
MD
506 struct ltt_channel *channel = file->private_data;
507
baf20995 508 switch (cmd) {
38d024ae 509 case LTTNG_KERNEL_STREAM:
c0e31d2e 510 return lttng_abi_open_stream(file);
38d024ae
MD
511 case LTTNG_KERNEL_EVENT:
512 return lttng_abi_create_event(file, (struct lttng_kernel_event __user *) arg);
8070f5c0
MD
513 case LTTNG_KERNEL_CONTEXT:
514 return lttng_abi_add_context(file,
515 (struct lttng_kernel_context __user *) arg,
516 &channel->ctx, channel->session);
baf20995
MD
517 default:
518 return -ENOIOCTLCMD;
519 }
520}
521
5dbbdb43
MD
522/**
523 * lttng_metadata_ioctl - lttng syscall through ioctl
524 *
525 * @file: the file
526 * @cmd: the command
527 * @arg: command arg
528 *
529 * This ioctl implements lttng commands:
38d024ae 530 * LTTNG_KERNEL_STREAM
5dbbdb43
MD
531 * Returns an event stream file descriptor or failure.
532 *
533 * Channel and event file descriptors also hold a reference on the session.
534 */
535static
536long lttng_metadata_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
537{
538 switch (cmd) {
38d024ae 539 case LTTNG_KERNEL_STREAM:
5dbbdb43
MD
540 return lttng_abi_open_stream(file);
541 default:
542 return -ENOIOCTLCMD;
543 }
544}
545
3b923e5b
MD
546/* TODO: poll */
547#if 0
653fe716
MD
548/**
549 * lttng_channel_poll - lttng stream addition/removal monitoring
550 *
c0e31d2e 551 * @file: the file
653fe716
MD
552 * @wait: poll table
553 */
c0e31d2e 554unsigned int lttng_channel_poll(struct file *file, poll_table *wait)
653fe716 555{
c0e31d2e 556 struct ltt_channel *channel = file->private_data;
653fe716
MD
557 unsigned int mask = 0;
558
c0e31d2e 559 if (file->f_mode & FMODE_READ) {
653fe716 560 poll_wait_set_exclusive(wait);
c0e31d2e 561 poll_wait(file, &channel->notify_wait, wait);
653fe716
MD
562
563 /* TODO: identify when the channel is being finalized. */
564 if (finalized)
565 return POLLHUP;
566 else
567 return POLLIN | POLLRDNORM;
568 }
569 return mask;
570
571}
3b923e5b 572#endif //0
653fe716 573
0a84a57f
MD
574static
575int lttng_channel_release(struct inode *inode, struct file *file)
576{
577 struct ltt_channel *channel = file->private_data;
c269fff4
MD
578
579 if (channel)
580 fput(channel->session->file);
0a84a57f
MD
581 return 0;
582}
583
ad1c05e1 584static const struct file_operations lttng_channel_fops = {
03037b98 585 .release = lttng_channel_release,
3b923e5b
MD
586/* TODO */
587#if 0
653fe716 588 .poll = lttng_channel_poll,
3b923e5b 589#endif //0
ad1c05e1 590 .unlocked_ioctl = lttng_channel_ioctl,
baf20995 591#ifdef CONFIG_COMPAT
03037b98 592 .compat_ioctl = lttng_channel_ioctl,
baf20995 593#endif
11b5a3c2 594};
baf20995 595
5dbbdb43
MD
596static const struct file_operations lttng_metadata_fops = {
597 .release = lttng_channel_release,
598 .unlocked_ioctl = lttng_metadata_ioctl,
599#ifdef CONFIG_COMPAT
600 .compat_ioctl = lttng_metadata_ioctl,
601#endif
602};
603
8070f5c0
MD
604/**
605 * lttng_event_ioctl - lttng syscall through ioctl
606 *
607 * @file: the file
608 * @cmd: the command
609 * @arg: command arg
610 *
611 * This ioctl implements lttng commands:
612 * LTTNG_KERNEL_STREAM
613 * Returns an event stream file descriptor or failure.
614 * (typically, one event stream records events from one CPU)
615 * LTTNG_KERNEL_EVENT
616 * Returns an event file descriptor or failure.
617 * LTTNG_KERNEL_CONTEXT
618 * Prepend a context field to each record of this event
619 */
620static
621long lttng_event_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
622{
623 struct ltt_event *event = file->private_data;
624
625 switch (cmd) {
626 case LTTNG_KERNEL_CONTEXT:
627 return lttng_abi_add_context(file,
628 (struct lttng_kernel_context __user *) arg,
629 &event->ctx, event->chan->session);
630 default:
631 return -ENOIOCTLCMD;
632 }
633}
634
0a84a57f
MD
635static
636int lttng_event_release(struct inode *inode, struct file *file)
637{
638 struct ltt_event *event = file->private_data;
c269fff4 639
aa7c23a9 640 if (event)
c269fff4 641 fput(event->chan->file);
0a84a57f
MD
642 return 0;
643}
644
3b923e5b 645/* TODO: filter control ioctl */
0a84a57f
MD
646static const struct file_operations lttng_event_fops = {
647 .release = lttng_event_release,
8070f5c0
MD
648 .unlocked_ioctl = lttng_event_ioctl,
649#ifdef CONFIG_COMPAT
650 .compat_ioctl = lttng_event_ioctl,
651#endif
11b5a3c2 652};
0a84a57f 653
1c25284c 654int __init ltt_debugfs_abi_init(void)
baf20995
MD
655{
656 int ret = 0;
657
6d2a620c 658 wrapper_vmalloc_sync_all();
11b5a3c2 659 lttng_dentry = debugfs_create_file("lttng", S_IWUSR, NULL, NULL,
f3d01b96 660 &lttng_fops);
11b5a3c2 661 if (IS_ERR(lttng_dentry) || !lttng_dentry) {
baf20995
MD
662 printk(KERN_ERR "Error creating LTTng control file\n");
663 ret = -ENOMEM;
664 goto error;
665 }
666error:
667 return ret;
668}
669
1c25284c 670void __exit ltt_debugfs_abi_exit(void)
baf20995 671{
11b5a3c2 672 debugfs_remove(lttng_dentry);
baf20995 673}
This page took 0.060453 seconds and 4 git commands to generate.