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