ID tracker: implement vpid/uid/vuid/gid/vgid trackers
[deliverable/lttng-modules.git] / lttng-abi.c
CommitLineData
baf20995 1/*
e8951e63 2 * lttng-abi.c
baf20995 3 *
e8951e63 4 * LTTng ABI
baf20995 5 *
886d51a3
MD
6 * Copyright (C) 2010-2012 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
7 *
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.
12 *
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.
17 *
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
21 *
22 *
baf20995
MD
23 * Mimic system calls for:
24 * - session creation, returns a file descriptor or failure.
ad1c05e1
MD
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.
baf20995
MD
38 */
39
11b5a3c2 40#include <linux/module.h>
e6a17f26 41#include <linux/proc_fs.h>
11b5a3c2
MD
42#include <linux/anon_inodes.h>
43#include <linux/file.h>
44#include <linux/uaccess.h>
45#include <linux/slab.h>
abc0446a 46#include <linux/err.h>
241ae9a8
MD
47#include <wrapper/vmalloc.h> /* for wrapper_vmalloc_sync_all() */
48#include <wrapper/ringbuffer/vfs.h>
49#include <wrapper/ringbuffer/backend.h>
50#include <wrapper/ringbuffer/frontend.h>
51#include <wrapper/poll.h>
52#include <wrapper/file.h>
53#include <wrapper/kref.h>
54#include <lttng-abi.h>
55#include <lttng-abi-old.h>
56#include <lttng-events.h>
57#include <lttng-tracer.h>
140a62b0 58#include <lttng-tp-mempool.h>
241ae9a8 59#include <lib/ringbuffer/frontend_types.h>
baf20995
MD
60
61/*
62 * This is LTTng's own personal way to create a system call as an external
80996790 63 * module. We use ioctl() on /proc/lttng.
baf20995
MD
64 */
65
e6a17f26 66static struct proc_dir_entry *lttng_proc_dentry;
ad1c05e1
MD
67static const struct file_operations lttng_fops;
68static const struct file_operations lttng_session_fops;
69static const struct file_operations lttng_channel_fops;
5dbbdb43 70static const struct file_operations lttng_metadata_fops;
305d3e42 71static const struct file_operations lttng_event_fops;
ed8d02d6 72static struct file_operations lttng_stream_ring_buffer_file_operations;
baf20995 73
9616f0bf
JD
74static int put_u64(uint64_t val, unsigned long arg);
75
a33c9927
MD
76/*
77 * Teardown management: opened file descriptors keep a refcount on the module,
78 * so it can only exit when all file descriptors are closed.
79 */
80
ad1c05e1 81static
baf20995
MD
82int lttng_abi_create_session(void)
83{
a90917c3 84 struct lttng_session *session;
c0e31d2e 85 struct file *session_file;
11b5a3c2 86 int session_fd, ret;
baf20995 87
a90917c3 88 session = lttng_session_create();
baf20995
MD
89 if (!session)
90 return -ENOMEM;
4ac10b76 91 session_fd = lttng_get_unused_fd();
baf20995
MD
92 if (session_fd < 0) {
93 ret = session_fd;
94 goto fd_error;
95 }
c0e31d2e 96 session_file = anon_inode_getfile("[lttng_session]",
ad1c05e1 97 &lttng_session_fops,
baf20995 98 session, O_RDWR);
c0e31d2e
MD
99 if (IS_ERR(session_file)) {
100 ret = PTR_ERR(session_file);
baf20995
MD
101 goto file_error;
102 }
c0e31d2e
MD
103 session->file = session_file;
104 fd_install(session_fd, session_file);
baf20995
MD
105 return session_fd;
106
107file_error:
108 put_unused_fd(session_fd);
109fd_error:
a90917c3 110 lttng_session_destroy(session);
baf20995
MD
111 return ret;
112}
113
271b6681
MD
114static
115int lttng_abi_tracepoint_list(void)
116{
117 struct file *tracepoint_list_file;
118 int file_fd, ret;
119
4ac10b76 120 file_fd = lttng_get_unused_fd();
271b6681
MD
121 if (file_fd < 0) {
122 ret = file_fd;
123 goto fd_error;
124 }
30f18bf0 125
8ee099b6 126 tracepoint_list_file = anon_inode_getfile("[lttng_tracepoint_list]",
271b6681
MD
127 &lttng_tracepoint_list_fops,
128 NULL, O_RDWR);
129 if (IS_ERR(tracepoint_list_file)) {
130 ret = PTR_ERR(tracepoint_list_file);
131 goto file_error;
132 }
30f18bf0
MD
133 ret = lttng_tracepoint_list_fops.open(NULL, tracepoint_list_file);
134 if (ret < 0)
135 goto open_error;
271b6681
MD
136 fd_install(file_fd, tracepoint_list_file);
137 return file_fd;
138
30f18bf0
MD
139open_error:
140 fput(tracepoint_list_file);
271b6681
MD
141file_error:
142 put_unused_fd(file_fd);
143fd_error:
144 return ret;
145}
146
f127e61e
MD
147#ifndef CONFIG_HAVE_SYSCALL_TRACEPOINTS
148static inline
149int lttng_abi_syscall_list(void)
150{
151 return -ENOSYS;
152}
153#else
154static
155int lttng_abi_syscall_list(void)
156{
157 struct file *syscall_list_file;
158 int file_fd, ret;
159
160 file_fd = lttng_get_unused_fd();
161 if (file_fd < 0) {
162 ret = file_fd;
163 goto fd_error;
164 }
165
166 syscall_list_file = anon_inode_getfile("[lttng_syscall_list]",
167 &lttng_syscall_list_fops,
168 NULL, O_RDWR);
169 if (IS_ERR(syscall_list_file)) {
170 ret = PTR_ERR(syscall_list_file);
171 goto file_error;
172 }
173 ret = lttng_syscall_list_fops.open(NULL, syscall_list_file);
174 if (ret < 0)
175 goto open_error;
176 fd_install(file_fd, syscall_list_file);
f127e61e
MD
177 return file_fd;
178
179open_error:
180 fput(syscall_list_file);
181file_error:
182 put_unused_fd(file_fd);
183fd_error:
184 return ret;
185}
186#endif
187
80c16bcf 188static
6dccd6c1 189void lttng_abi_tracer_version(struct lttng_kernel_tracer_version *v)
80c16bcf 190{
6dccd6c1
JD
191 v->major = LTTNG_MODULES_MAJOR_VERSION;
192 v->minor = LTTNG_MODULES_MINOR_VERSION;
193 v->patchlevel = LTTNG_MODULES_PATCHLEVEL_VERSION;
80c16bcf
MD
194}
195
42cabb80
MD
196static
197void lttng_abi_tracer_abi_version(struct lttng_kernel_tracer_abi_version *v)
198{
199 v->major = LTTNG_MODULES_ABI_MAJOR_VERSION;
200 v->minor = LTTNG_MODULES_ABI_MINOR_VERSION;
201}
202
8070f5c0
MD
203static
204long lttng_abi_add_context(struct file *file,
6dccd6c1 205 struct lttng_kernel_context *context_param,
a90917c3 206 struct lttng_ctx **ctx, struct lttng_session *session)
8070f5c0 207{
8070f5c0
MD
208
209 if (session->been_active)
210 return -EPERM;
211
6dccd6c1 212 switch (context_param->ctx) {
12a313a5 213 case LTTNG_KERNEL_CONTEXT_PID:
8070f5c0 214 return lttng_add_pid_to_ctx(ctx);
a8ad3613
MD
215 case LTTNG_KERNEL_CONTEXT_PRIO:
216 return lttng_add_prio_to_ctx(ctx);
53f1f0ca
MD
217 case LTTNG_KERNEL_CONTEXT_NICE:
218 return lttng_add_nice_to_ctx(ctx);
b64bc438
MD
219 case LTTNG_KERNEL_CONTEXT_VPID:
220 return lttng_add_vpid_to_ctx(ctx);
221 case LTTNG_KERNEL_CONTEXT_TID:
222 return lttng_add_tid_to_ctx(ctx);
223 case LTTNG_KERNEL_CONTEXT_VTID:
224 return lttng_add_vtid_to_ctx(ctx);
225 case LTTNG_KERNEL_CONTEXT_PPID:
226 return lttng_add_ppid_to_ctx(ctx);
227 case LTTNG_KERNEL_CONTEXT_VPPID:
228 return lttng_add_vppid_to_ctx(ctx);
12a313a5 229 case LTTNG_KERNEL_CONTEXT_PERF_COUNTER:
6dccd6c1
JD
230 context_param->u.perf_counter.name[LTTNG_KERNEL_SYM_NAME_LEN - 1] = '\0';
231 return lttng_add_perf_counter_to_ctx(context_param->u.perf_counter.type,
232 context_param->u.perf_counter.config,
233 context_param->u.perf_counter.name,
c24a0d71 234 ctx);
a2563e83
MD
235 case LTTNG_KERNEL_CONTEXT_PROCNAME:
236 return lttng_add_procname_to_ctx(ctx);
975da2c0
JD
237 case LTTNG_KERNEL_CONTEXT_HOSTNAME:
238 return lttng_add_hostname_to_ctx(ctx);
b3699d90
MD
239 case LTTNG_KERNEL_CONTEXT_CPU_ID:
240 return lttng_add_cpu_id_to_ctx(ctx);
79150a49
JD
241 case LTTNG_KERNEL_CONTEXT_INTERRUPTIBLE:
242 return lttng_add_interruptible_to_ctx(ctx);
243 case LTTNG_KERNEL_CONTEXT_NEED_RESCHEDULE:
244 return lttng_add_need_reschedule_to_ctx(ctx);
245 case LTTNG_KERNEL_CONTEXT_PREEMPTIBLE:
246 return lttng_add_preemptible_to_ctx(ctx);
247 case LTTNG_KERNEL_CONTEXT_MIGRATABLE:
248 return lttng_add_migratable_to_ctx(ctx);
8070f5c0
MD
249 default:
250 return -EINVAL;
251 }
252}
253
ad1c05e1
MD
254/**
255 * lttng_ioctl - lttng syscall through ioctl
256 *
c0e31d2e 257 * @file: the file
ad1c05e1
MD
258 * @cmd: the command
259 * @arg: command arg
260 *
261 * This ioctl implements lttng commands:
38d024ae 262 * LTTNG_KERNEL_SESSION
ad1c05e1 263 * Returns a LTTng trace session file descriptor
271b6681
MD
264 * LTTNG_KERNEL_TRACER_VERSION
265 * Returns the LTTng kernel tracer version
266 * LTTNG_KERNEL_TRACEPOINT_LIST
267 * Returns a file descriptor listing available tracepoints
360f38ea
MD
268 * LTTNG_KERNEL_WAIT_QUIESCENT
269 * Returns after all previously running probes have completed
42cabb80
MD
270 * LTTNG_KERNEL_TRACER_ABI_VERSION
271 * Returns the LTTng kernel tracer ABI version
ad1c05e1
MD
272 *
273 * The returned session will be deleted when its file descriptor is closed.
274 */
275static
c0e31d2e 276long lttng_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
ad1c05e1
MD
277{
278 switch (cmd) {
6dccd6c1 279 case LTTNG_KERNEL_OLD_SESSION:
38d024ae 280 case LTTNG_KERNEL_SESSION:
ad1c05e1 281 return lttng_abi_create_session();
6dccd6c1
JD
282 case LTTNG_KERNEL_OLD_TRACER_VERSION:
283 {
284 struct lttng_kernel_tracer_version v;
285 struct lttng_kernel_old_tracer_version oldv;
286 struct lttng_kernel_old_tracer_version *uversion =
287 (struct lttng_kernel_old_tracer_version __user *) arg;
288
289 lttng_abi_tracer_version(&v);
290 oldv.major = v.major;
291 oldv.minor = v.minor;
292 oldv.patchlevel = v.patchlevel;
293
294 if (copy_to_user(uversion, &oldv, sizeof(oldv)))
295 return -EFAULT;
296 return 0;
297 }
80c16bcf 298 case LTTNG_KERNEL_TRACER_VERSION:
6dccd6c1
JD
299 {
300 struct lttng_kernel_tracer_version version;
301 struct lttng_kernel_tracer_version *uversion =
302 (struct lttng_kernel_tracer_version __user *) arg;
303
304 lttng_abi_tracer_version(&version);
42cabb80
MD
305
306 if (copy_to_user(uversion, &version, sizeof(version)))
307 return -EFAULT;
308 return 0;
309 }
310 case LTTNG_KERNEL_TRACER_ABI_VERSION:
311 {
312 struct lttng_kernel_tracer_abi_version version;
313 struct lttng_kernel_tracer_abi_version *uversion =
314 (struct lttng_kernel_tracer_abi_version __user *) arg;
315
316 lttng_abi_tracer_abi_version(&version);
317
6dccd6c1
JD
318 if (copy_to_user(uversion, &version, sizeof(version)))
319 return -EFAULT;
320 return 0;
321 }
322 case LTTNG_KERNEL_OLD_TRACEPOINT_LIST:
271b6681
MD
323 case LTTNG_KERNEL_TRACEPOINT_LIST:
324 return lttng_abi_tracepoint_list();
2d2464bd
MD
325 case LTTNG_KERNEL_SYSCALL_LIST:
326 return lttng_abi_syscall_list();
6dccd6c1 327 case LTTNG_KERNEL_OLD_WAIT_QUIESCENT:
5f7f9078
MD
328 case LTTNG_KERNEL_WAIT_QUIESCENT:
329 synchronize_trace();
330 return 0;
6dccd6c1
JD
331 case LTTNG_KERNEL_OLD_CALIBRATE:
332 {
333 struct lttng_kernel_old_calibrate __user *ucalibrate =
334 (struct lttng_kernel_old_calibrate __user *) arg;
335 struct lttng_kernel_old_calibrate old_calibrate;
336 struct lttng_kernel_calibrate calibrate;
337 int ret;
338
339 if (copy_from_user(&old_calibrate, ucalibrate, sizeof(old_calibrate)))
340 return -EFAULT;
341 calibrate.type = old_calibrate.type;
342 ret = lttng_calibrate(&calibrate);
343 if (copy_to_user(ucalibrate, &old_calibrate, sizeof(old_calibrate)))
344 return -EFAULT;
345 return ret;
346 }
57105fc2
MD
347 case LTTNG_KERNEL_CALIBRATE:
348 {
3db41b2c
MD
349 struct lttng_kernel_calibrate __user *ucalibrate =
350 (struct lttng_kernel_calibrate __user *) arg;
351 struct lttng_kernel_calibrate calibrate;
57105fc2
MD
352 int ret;
353
354 if (copy_from_user(&calibrate, ucalibrate, sizeof(calibrate)))
355 return -EFAULT;
356 ret = lttng_calibrate(&calibrate);
357 if (copy_to_user(ucalibrate, &calibrate, sizeof(calibrate)))
358 return -EFAULT;
359 return ret;
360 }
ad1c05e1
MD
361 default:
362 return -ENOIOCTLCMD;
363 }
364}
365
ad1c05e1 366static const struct file_operations lttng_fops = {
a33c9927 367 .owner = THIS_MODULE,
ad1c05e1
MD
368 .unlocked_ioctl = lttng_ioctl,
369#ifdef CONFIG_COMPAT
03037b98 370 .compat_ioctl = lttng_ioctl,
ad1c05e1 371#endif
11b5a3c2 372};
ad1c05e1 373
5dbbdb43 374static
c0e31d2e 375int lttng_abi_create_channel(struct file *session_file,
6dccd6c1 376 struct lttng_kernel_channel *chan_param,
5dbbdb43 377 enum channel_type channel_type)
baf20995 378{
a90917c3 379 struct lttng_session *session = session_file->private_data;
88dfd899 380 const struct file_operations *fops = NULL;
5dbbdb43 381 const char *transport_name;
a90917c3 382 struct lttng_channel *chan;
c0e31d2e 383 struct file *chan_file;
baf20995 384 int chan_fd;
ad1c05e1 385 int ret = 0;
baf20995 386
4ac10b76 387 chan_fd = lttng_get_unused_fd();
baf20995
MD
388 if (chan_fd < 0) {
389 ret = chan_fd;
390 goto fd_error;
391 }
88dfd899
MD
392 switch (channel_type) {
393 case PER_CPU_CHANNEL:
394 fops = &lttng_channel_fops;
395 break;
396 case METADATA_CHANNEL:
397 fops = &lttng_metadata_fops;
398 break;
399 }
400
c0e31d2e 401 chan_file = anon_inode_getfile("[lttng_channel]",
88dfd899 402 fops,
03037b98 403 NULL, O_RDWR);
c0e31d2e
MD
404 if (IS_ERR(chan_file)) {
405 ret = PTR_ERR(chan_file);
baf20995
MD
406 goto file_error;
407 }
5dbbdb43
MD
408 switch (channel_type) {
409 case PER_CPU_CHANNEL:
6dccd6c1
JD
410 if (chan_param->output == LTTNG_KERNEL_SPLICE) {
411 transport_name = chan_param->overwrite ?
96ba7208 412 "relay-overwrite" : "relay-discard";
6dccd6c1
JD
413 } else if (chan_param->output == LTTNG_KERNEL_MMAP) {
414 transport_name = chan_param->overwrite ?
96ba7208
JD
415 "relay-overwrite-mmap" : "relay-discard-mmap";
416 } else {
417 return -EINVAL;
418 }
5dbbdb43 419 break;
5dbbdb43 420 case METADATA_CHANNEL:
6dccd6c1 421 if (chan_param->output == LTTNG_KERNEL_SPLICE)
96ba7208 422 transport_name = "relay-metadata";
6dccd6c1 423 else if (chan_param->output == LTTNG_KERNEL_MMAP)
96ba7208
JD
424 transport_name = "relay-metadata-mmap";
425 else
426 return -EINVAL;
5dbbdb43
MD
427 break;
428 default:
429 transport_name = "<unknown>";
430 break;
431 }
9c1f4643
MD
432 if (atomic_long_add_unless(&session_file->f_count,
433 1, INT_MAX) == INT_MAX) {
434 goto refcount_error;
435 }
03037b98
MD
436 /*
437 * We tolerate no failure path after channel creation. It will stay
438 * invariant for the rest of the session.
439 */
a90917c3 440 chan = lttng_channel_create(session, transport_name, NULL,
6dccd6c1
JD
441 chan_param->subbuf_size,
442 chan_param->num_subbuf,
443 chan_param->switch_timer_interval,
d83004aa
JD
444 chan_param->read_timer_interval,
445 channel_type);
03037b98 446 if (!chan) {
f3d01b96 447 ret = -EINVAL;
03037b98
MD
448 goto chan_error;
449 }
11b5a3c2 450 chan->file = chan_file;
c0e31d2e
MD
451 chan_file->private_data = chan;
452 fd_install(chan_fd, chan_file);
ad1c05e1 453
baf20995
MD
454 return chan_fd;
455
03037b98 456chan_error:
9c1f4643
MD
457 atomic_long_dec(&session_file->f_count);
458refcount_error:
c0e31d2e 459 fput(chan_file);
baf20995
MD
460file_error:
461 put_unused_fd(chan_fd);
462fd_error:
baf20995
MD
463 return ret;
464}
465
6599a4eb
MD
466static
467enum tracker_type get_tracker_type(struct lttng_kernel_tracker_args *tracker)
468{
469 switch (tracker->type) {
470 case LTTNG_KERNEL_TRACKER_PID:
471 return TRACKER_PID;
472 case LTTNG_KERNEL_TRACKER_VPID:
473 return TRACKER_VPID;
474 case LTTNG_KERNEL_TRACKER_UID:
475 return TRACKER_UID;
476 case LTTNG_KERNEL_TRACKER_VUID:
477 return TRACKER_VUID;
478 case LTTNG_KERNEL_TRACKER_GID:
479 return TRACKER_GID;
480 case LTTNG_KERNEL_TRACKER_VGID:
481 return TRACKER_VGID;
482 default:
483 return TRACKER_UNKNOWN;
484 }
485}
486
baf20995 487/**
ad1c05e1 488 * lttng_session_ioctl - lttng session fd ioctl
baf20995 489 *
c0e31d2e 490 * @file: the file
baf20995
MD
491 * @cmd: the command
492 * @arg: command arg
493 *
494 * This ioctl implements lttng commands:
38d024ae 495 * LTTNG_KERNEL_CHANNEL
baf20995 496 * Returns a LTTng channel file descriptor
e64957da
MD
497 * LTTNG_KERNEL_ENABLE
498 * Enables tracing for a session (weak enable)
499 * LTTNG_KERNEL_DISABLE
500 * Disables tracing for a session (strong disable)
8070f5c0
MD
501 * LTTNG_KERNEL_METADATA
502 * Returns a LTTng metadata file descriptor
e0130fab 503 * LTTNG_KERNEL_SESSION_TRACK_PID
6599a4eb 504 * Add PID to session PID tracker
e0130fab 505 * LTTNG_KERNEL_SESSION_UNTRACK_PID
6599a4eb
MD
506 * Remove PID from session PID tracker
507 * LTTNG_KERNEL_SESSION_TRACK_ID
508 * Add ID to tracker
509 * LTTNG_KERNEL_SESSION_UNTRACK_ID
510 * Remove ID from tracker
ad1c05e1
MD
511 *
512 * The returned channel will be deleted when its file descriptor is closed.
513 */
514static
c0e31d2e 515long lttng_session_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
ad1c05e1 516{
a90917c3 517 struct lttng_session *session = file->private_data;
c0e31d2e 518
ad1c05e1 519 switch (cmd) {
6dccd6c1
JD
520 case LTTNG_KERNEL_OLD_CHANNEL:
521 {
522 struct lttng_kernel_channel chan_param;
523 struct lttng_kernel_old_channel old_chan_param;
524
525 if (copy_from_user(&old_chan_param,
526 (struct lttng_kernel_old_channel __user *) arg,
527 sizeof(struct lttng_kernel_old_channel)))
528 return -EFAULT;
529 chan_param.overwrite = old_chan_param.overwrite;
530 chan_param.subbuf_size = old_chan_param.subbuf_size;
531 chan_param.num_subbuf = old_chan_param.num_subbuf;
532 chan_param.switch_timer_interval = old_chan_param.switch_timer_interval;
533 chan_param.read_timer_interval = old_chan_param.read_timer_interval;
534 chan_param.output = old_chan_param.output;
535
536 return lttng_abi_create_channel(file, &chan_param,
537 PER_CPU_CHANNEL);
538 }
38d024ae 539 case LTTNG_KERNEL_CHANNEL:
6dccd6c1
JD
540 {
541 struct lttng_kernel_channel chan_param;
542
543 if (copy_from_user(&chan_param,
38d024ae 544 (struct lttng_kernel_channel __user *) arg,
6dccd6c1
JD
545 sizeof(struct lttng_kernel_channel)))
546 return -EFAULT;
547 return lttng_abi_create_channel(file, &chan_param,
5dbbdb43 548 PER_CPU_CHANNEL);
6dccd6c1
JD
549 }
550 case LTTNG_KERNEL_OLD_SESSION_START:
551 case LTTNG_KERNEL_OLD_ENABLE:
38d024ae 552 case LTTNG_KERNEL_SESSION_START:
e64957da 553 case LTTNG_KERNEL_ENABLE:
a90917c3 554 return lttng_session_enable(session);
6dccd6c1
JD
555 case LTTNG_KERNEL_OLD_SESSION_STOP:
556 case LTTNG_KERNEL_OLD_DISABLE:
38d024ae 557 case LTTNG_KERNEL_SESSION_STOP:
e64957da 558 case LTTNG_KERNEL_DISABLE:
a90917c3 559 return lttng_session_disable(session);
6dccd6c1
JD
560 case LTTNG_KERNEL_OLD_METADATA:
561 {
562 struct lttng_kernel_channel chan_param;
563 struct lttng_kernel_old_channel old_chan_param;
564
565 if (copy_from_user(&old_chan_param,
566 (struct lttng_kernel_old_channel __user *) arg,
567 sizeof(struct lttng_kernel_old_channel)))
568 return -EFAULT;
569 chan_param.overwrite = old_chan_param.overwrite;
570 chan_param.subbuf_size = old_chan_param.subbuf_size;
571 chan_param.num_subbuf = old_chan_param.num_subbuf;
572 chan_param.switch_timer_interval = old_chan_param.switch_timer_interval;
573 chan_param.read_timer_interval = old_chan_param.read_timer_interval;
574 chan_param.output = old_chan_param.output;
575
576 return lttng_abi_create_channel(file, &chan_param,
577 METADATA_CHANNEL);
578 }
38d024ae 579 case LTTNG_KERNEL_METADATA:
6dccd6c1
JD
580 {
581 struct lttng_kernel_channel chan_param;
582
583 if (copy_from_user(&chan_param,
584 (struct lttng_kernel_channel __user *) arg,
585 sizeof(struct lttng_kernel_channel)))
586 return -EFAULT;
587 return lttng_abi_create_channel(file, &chan_param,
5dbbdb43 588 METADATA_CHANNEL);
6dccd6c1 589 }
e0130fab 590 case LTTNG_KERNEL_SESSION_TRACK_PID:
6599a4eb 591 return lttng_session_track_id(session, TRACKER_PID, (int) arg);
e0130fab 592 case LTTNG_KERNEL_SESSION_UNTRACK_PID:
6599a4eb
MD
593 return lttng_session_untrack_id(session, TRACKER_PID, (int) arg);
594 case LTTNG_KERNEL_SESSION_TRACK_ID:
595 {
596 struct lttng_kernel_tracker_args tracker;
597 enum tracker_type tracker_type;
598
599 if (copy_from_user(&tracker,
600 (struct lttng_kernel_tracker_args __user *) arg,
601 sizeof(struct lttng_kernel_tracker_args)))
602 return -EFAULT;
603 tracker_type = get_tracker_type(&tracker);
604 if (tracker_type == TRACKER_UNKNOWN)
605 return -EINVAL;
606 return lttng_session_track_id(session, tracker_type, tracker.id);
607 }
608 case LTTNG_KERNEL_SESSION_UNTRACK_ID:
609 {
610 struct lttng_kernel_tracker_args tracker;
611 enum tracker_type tracker_type;
612
613 if (copy_from_user(&tracker,
614 (struct lttng_kernel_tracker_args __user *) arg,
615 sizeof(struct lttng_kernel_tracker_args)))
616 return -EFAULT;
617 tracker_type = get_tracker_type(&tracker);
618 if (tracker_type == TRACKER_UNKNOWN)
619 return -EINVAL;
620 return lttng_session_untrack_id(session, tracker_type,
621 tracker.id);
622 }
7e6f9ef6 623 case LTTNG_KERNEL_SESSION_LIST_TRACKER_PIDS:
6599a4eb
MD
624 return lttng_session_list_tracker_ids(session, TRACKER_PID);
625 case LTTNG_KERNEL_SESSION_LIST_TRACKER_IDS:
626 {
627 struct lttng_kernel_tracker_args tracker;
628 enum tracker_type tracker_type;
629
630 if (copy_from_user(&tracker,
631 (struct lttng_kernel_tracker_args __user *) arg,
632 sizeof(struct lttng_kernel_tracker_args)))
633 return -EFAULT;
634 tracker_type = get_tracker_type(&tracker);
635 if (tracker_type == TRACKER_UNKNOWN)
636 return -EINVAL;
637 return lttng_session_list_tracker_ids(session, tracker_type);
638 }
9616f0bf
JD
639 case LTTNG_KERNEL_SESSION_METADATA_REGEN:
640 return lttng_session_metadata_regenerate(session);
601252cf
MD
641 case LTTNG_KERNEL_SESSION_STATEDUMP:
642 return lttng_session_statedump(session);
ad1c05e1
MD
643 default:
644 return -ENOIOCTLCMD;
645 }
646}
647
03037b98
MD
648/*
649 * Called when the last file reference is dropped.
650 *
651 * Big fat note: channels and events are invariant for the whole session after
652 * their creation. So this session destruction also destroys all channel and
653 * event structures specific to this session (they are not destroyed when their
654 * individual file is released).
655 */
ad1c05e1 656static
03037b98 657int lttng_session_release(struct inode *inode, struct file *file)
ad1c05e1 658{
a90917c3 659 struct lttng_session *session = file->private_data;
c269fff4
MD
660
661 if (session)
a90917c3 662 lttng_session_destroy(session);
11b5a3c2 663 return 0;
ad1c05e1 664}
ad1c05e1
MD
665
666static const struct file_operations lttng_session_fops = {
a33c9927 667 .owner = THIS_MODULE,
03037b98 668 .release = lttng_session_release,
ad1c05e1
MD
669 .unlocked_ioctl = lttng_session_ioctl,
670#ifdef CONFIG_COMPAT
03037b98 671 .compat_ioctl = lttng_session_ioctl,
ad1c05e1 672#endif
11b5a3c2 673};
ad1c05e1 674
d83004aa
JD
675/**
676 * lttng_metadata_ring_buffer_poll - LTTng ring buffer poll file operation
677 * @filp: the file
678 * @wait: poll table
679 *
680 * Handles the poll operations for the metadata channels.
681 */
ad1c05e1 682static
d83004aa
JD
683unsigned int lttng_metadata_ring_buffer_poll(struct file *filp,
684 poll_table *wait)
685{
686 struct lttng_metadata_stream *stream = filp->private_data;
687 struct lib_ring_buffer *buf = stream->priv;
688 int finalized;
689 unsigned int mask = 0;
690
691 if (filp->f_mode & FMODE_READ) {
692 poll_wait_set_exclusive(wait);
693 poll_wait(filp, &stream->read_wait, wait);
694
695 finalized = stream->finalized;
696
697 /*
698 * lib_ring_buffer_is_finalized() contains a smp_rmb()
699 * ordering finalized load before offsets loads.
700 */
701 WARN_ON(atomic_long_read(&buf->active_readers) != 1);
702
703 if (finalized)
704 mask |= POLLHUP;
705
92d9f5e6 706 mutex_lock(&stream->metadata_cache->lock);
d83004aa 707 if (stream->metadata_cache->metadata_written >
f613e3e6 708 stream->metadata_out)
d83004aa 709 mask |= POLLIN;
92d9f5e6 710 mutex_unlock(&stream->metadata_cache->lock);
d83004aa
JD
711 }
712
713 return mask;
714}
715
f613e3e6
MD
716static
717void lttng_metadata_ring_buffer_ioctl_put_next_subbuf(struct file *filp,
718 unsigned int cmd, unsigned long arg)
719{
720 struct lttng_metadata_stream *stream = filp->private_data;
721
722 stream->metadata_out = stream->metadata_in;
723}
724
d83004aa
JD
725static
726long lttng_metadata_ring_buffer_ioctl(struct file *filp,
727 unsigned int cmd, unsigned long arg)
728{
729 int ret;
730 struct lttng_metadata_stream *stream = filp->private_data;
731 struct lib_ring_buffer *buf = stream->priv;
732
733 switch (cmd) {
d83004aa
JD
734 case RING_BUFFER_GET_NEXT_SUBBUF:
735 {
35097f36
JD
736 struct lttng_metadata_stream *stream = filp->private_data;
737 struct lib_ring_buffer *buf = stream->priv;
738 struct channel *chan = buf->backend.chan;
739
740 ret = lttng_metadata_output_channel(stream, chan);
741 if (ret > 0) {
742 lib_ring_buffer_switch_slow(buf, SWITCH_ACTIVE);
743 ret = 0;
744 } else if (ret < 0)
d83004aa
JD
745 goto err;
746 break;
747 }
f613e3e6
MD
748 case RING_BUFFER_GET_SUBBUF:
749 {
750 /*
751 * Random access is not allowed for metadata channel.
752 */
753 return -ENOSYS;
754 }
67e891fb 755 case RING_BUFFER_FLUSH_EMPTY: /* Fall-through. */
35097f36
JD
756 case RING_BUFFER_FLUSH:
757 {
758 struct lttng_metadata_stream *stream = filp->private_data;
759 struct lib_ring_buffer *buf = stream->priv;
760 struct channel *chan = buf->backend.chan;
761
762 /*
763 * Before doing the actual ring buffer flush, write up to one
764 * packet of metadata in the ring buffer.
765 */
766 ret = lttng_metadata_output_channel(stream, chan);
767 if (ret < 0)
768 goto err;
769 break;
770 }
9616f0bf
JD
771 case RING_BUFFER_GET_METADATA_VERSION:
772 {
773 struct lttng_metadata_stream *stream = filp->private_data;
774
775 return put_u64(stream->version, arg);
776 }
d83004aa
JD
777 default:
778 break;
779 }
f613e3e6
MD
780 /* PUT_SUBBUF is the one from lib ring buffer, unmodified. */
781
d83004aa 782 /* Performing lib ring buffer ioctl after our own. */
f613e3e6
MD
783 ret = lib_ring_buffer_ioctl(filp, cmd, arg, buf);
784 if (ret < 0)
785 goto err;
d83004aa 786
f613e3e6
MD
787 switch (cmd) {
788 case RING_BUFFER_PUT_NEXT_SUBBUF:
789 {
790 lttng_metadata_ring_buffer_ioctl_put_next_subbuf(filp,
791 cmd, arg);
792 break;
793 }
794 default:
795 break;
796 }
d83004aa
JD
797err:
798 return ret;
799}
800
aeb9064d 801#ifdef CONFIG_COMPAT
d83004aa
JD
802static
803long lttng_metadata_ring_buffer_compat_ioctl(struct file *filp,
804 unsigned int cmd, unsigned long arg)
805{
806 int ret;
807 struct lttng_metadata_stream *stream = filp->private_data;
808 struct lib_ring_buffer *buf = stream->priv;
809
810 switch (cmd) {
d83004aa
JD
811 case RING_BUFFER_GET_NEXT_SUBBUF:
812 {
35097f36
JD
813 struct lttng_metadata_stream *stream = filp->private_data;
814 struct lib_ring_buffer *buf = stream->priv;
815 struct channel *chan = buf->backend.chan;
816
817 ret = lttng_metadata_output_channel(stream, chan);
818 if (ret > 0) {
819 lib_ring_buffer_switch_slow(buf, SWITCH_ACTIVE);
820 ret = 0;
821 } else if (ret < 0)
d83004aa
JD
822 goto err;
823 break;
824 }
f613e3e6
MD
825 case RING_BUFFER_GET_SUBBUF:
826 {
827 /*
828 * Random access is not allowed for metadata channel.
829 */
830 return -ENOSYS;
831 }
67e891fb 832 case RING_BUFFER_FLUSH_EMPTY: /* Fall-through. */
96c55c2f
MD
833 case RING_BUFFER_FLUSH:
834 {
835 struct lttng_metadata_stream *stream = filp->private_data;
836 struct lib_ring_buffer *buf = stream->priv;
837 struct channel *chan = buf->backend.chan;
838
839 /*
840 * Before doing the actual ring buffer flush, write up to one
841 * packet of metadata in the ring buffer.
842 */
843 ret = lttng_metadata_output_channel(stream, chan);
844 if (ret < 0)
845 goto err;
846 break;
847 }
848 case RING_BUFFER_GET_METADATA_VERSION:
849 {
850 struct lttng_metadata_stream *stream = filp->private_data;
851
852 return put_u64(stream->version, arg);
853 }
d83004aa
JD
854 default:
855 break;
856 }
f613e3e6
MD
857 /* PUT_SUBBUF is the one from lib ring buffer, unmodified. */
858
d83004aa 859 /* Performing lib ring buffer ioctl after our own. */
f613e3e6
MD
860 ret = lib_ring_buffer_compat_ioctl(filp, cmd, arg, buf);
861 if (ret < 0)
862 goto err;
d83004aa 863
f613e3e6
MD
864 switch (cmd) {
865 case RING_BUFFER_PUT_NEXT_SUBBUF:
866 {
867 lttng_metadata_ring_buffer_ioctl_put_next_subbuf(filp,
868 cmd, arg);
869 break;
870 }
871 default:
872 break;
873 }
d83004aa
JD
874err:
875 return ret;
876}
aeb9064d 877#endif
d83004aa 878
b3b8072b
MD
879/*
880 * This is not used by anonymous file descriptors. This code is left
881 * there if we ever want to implement an inode with open() operation.
882 */
d83004aa
JD
883static
884int lttng_metadata_ring_buffer_open(struct inode *inode, struct file *file)
885{
886 struct lttng_metadata_stream *stream = inode->i_private;
887 struct lib_ring_buffer *buf = stream->priv;
888
889 file->private_data = buf;
b3b8072b
MD
890 /*
891 * Since life-time of metadata cache differs from that of
892 * session, we need to keep our own reference on the transport.
893 */
894 if (!try_module_get(stream->transport->owner)) {
895 printk(KERN_WARNING "LTT : Can't lock transport module.\n");
896 return -EBUSY;
897 }
d83004aa
JD
898 return lib_ring_buffer_open(inode, file, buf);
899}
900
901static
902int lttng_metadata_ring_buffer_release(struct inode *inode, struct file *file)
903{
904 struct lttng_metadata_stream *stream = file->private_data;
905 struct lib_ring_buffer *buf = stream->priv;
906
907 kref_put(&stream->metadata_cache->refcount, metadata_cache_destroy);
b3b8072b 908 module_put(stream->transport->owner);
d83004aa
JD
909 return lib_ring_buffer_release(inode, file, buf);
910}
911
912static
913ssize_t lttng_metadata_ring_buffer_splice_read(struct file *in, loff_t *ppos,
914 struct pipe_inode_info *pipe, size_t len,
915 unsigned int flags)
916{
917 struct lttng_metadata_stream *stream = in->private_data;
918 struct lib_ring_buffer *buf = stream->priv;
919
920 return lib_ring_buffer_splice_read(in, ppos, pipe, len,
921 flags, buf);
922}
923
924static
925int lttng_metadata_ring_buffer_mmap(struct file *filp,
926 struct vm_area_struct *vma)
927{
928 struct lttng_metadata_stream *stream = filp->private_data;
929 struct lib_ring_buffer *buf = stream->priv;
930
931 return lib_ring_buffer_mmap(filp, vma, buf);
932}
933
934static
935const struct file_operations lttng_metadata_ring_buffer_file_operations = {
936 .owner = THIS_MODULE,
937 .open = lttng_metadata_ring_buffer_open,
938 .release = lttng_metadata_ring_buffer_release,
939 .poll = lttng_metadata_ring_buffer_poll,
940 .splice_read = lttng_metadata_ring_buffer_splice_read,
941 .mmap = lttng_metadata_ring_buffer_mmap,
942 .unlocked_ioctl = lttng_metadata_ring_buffer_ioctl,
943 .llseek = vfs_lib_ring_buffer_no_llseek,
944#ifdef CONFIG_COMPAT
945 .compat_ioctl = lttng_metadata_ring_buffer_compat_ioctl,
946#endif
947};
948
949static
950int lttng_abi_create_stream_fd(struct file *channel_file, void *stream_priv,
951 const struct file_operations *fops)
ad1c05e1 952{
ad1c05e1 953 int stream_fd, ret;
11b5a3c2 954 struct file *stream_file;
ad1c05e1 955
4ac10b76 956 stream_fd = lttng_get_unused_fd();
ad1c05e1
MD
957 if (stream_fd < 0) {
958 ret = stream_fd;
959 goto fd_error;
960 }
d83004aa
JD
961 stream_file = anon_inode_getfile("[lttng_stream]", fops,
962 stream_priv, O_RDWR);
c0e31d2e
MD
963 if (IS_ERR(stream_file)) {
964 ret = PTR_ERR(stream_file);
ad1c05e1
MD
965 goto file_error;
966 }
409453cb
MD
967 /*
968 * OPEN_FMODE, called within anon_inode_getfile/alloc_file, don't honor
969 * FMODE_LSEEK, FMODE_PREAD nor FMODE_PWRITE. We need to read from this
970 * file descriptor, so we set FMODE_PREAD here.
971 */
d7b6f197 972 stream_file->f_mode |= FMODE_PREAD;
c0e31d2e 973 fd_install(stream_fd, stream_file);
dda6a249
MD
974 /*
975 * The stream holds a reference to the channel within the generic ring
976 * buffer library, so no need to hold a refcount on the channel and
977 * session files here.
978 */
ad1c05e1
MD
979 return stream_fd;
980
981file_error:
982 put_unused_fd(stream_fd);
d83004aa
JD
983fd_error:
984 return ret;
985}
986
987static
988int lttng_abi_open_stream(struct file *channel_file)
989{
990 struct lttng_channel *channel = channel_file->private_data;
991 struct lib_ring_buffer *buf;
992 int ret;
993 void *stream_priv;
994
995 buf = channel->ops->buffer_read_open(channel->chan);
996 if (!buf)
997 return -ENOENT;
998
999 stream_priv = buf;
1000 ret = lttng_abi_create_stream_fd(channel_file, stream_priv,
ed8d02d6 1001 &lttng_stream_ring_buffer_file_operations);
d83004aa
JD
1002 if (ret < 0)
1003 goto fd_error;
1004
1005 return ret;
1006
1007fd_error:
1008 channel->ops->buffer_read_close(buf);
1009 return ret;
1010}
1011
1012static
1013int lttng_abi_open_metadata_stream(struct file *channel_file)
1014{
1015 struct lttng_channel *channel = channel_file->private_data;
1016 struct lttng_session *session = channel->session;
1017 struct lib_ring_buffer *buf;
1018 int ret;
1019 struct lttng_metadata_stream *metadata_stream;
1020 void *stream_priv;
1021
1022 buf = channel->ops->buffer_read_open(channel->chan);
1023 if (!buf)
1024 return -ENOENT;
1025
1026 metadata_stream = kzalloc(sizeof(struct lttng_metadata_stream),
1027 GFP_KERNEL);
b3b8072b
MD
1028 if (!metadata_stream) {
1029 ret = -ENOMEM;
1030 goto nomem;
1031 }
d83004aa
JD
1032 metadata_stream->metadata_cache = session->metadata_cache;
1033 init_waitqueue_head(&metadata_stream->read_wait);
1034 metadata_stream->priv = buf;
1035 stream_priv = metadata_stream;
b3b8072b
MD
1036 metadata_stream->transport = channel->transport;
1037
1038 /*
1039 * Since life-time of metadata cache differs from that of
1040 * session, we need to keep our own reference on the transport.
1041 */
1042 if (!try_module_get(metadata_stream->transport->owner)) {
1043 printk(KERN_WARNING "LTT : Can't lock transport module.\n");
1044 ret = -EINVAL;
1045 goto notransport;
1046 }
1047
715b31b7
FD
1048 if (!lttng_kref_get(&session->metadata_cache->refcount)) {
1049 ret = -EOVERFLOW;
9c1f4643 1050 goto kref_error;
715b31b7
FD
1051 }
1052
d83004aa
JD
1053 ret = lttng_abi_create_stream_fd(channel_file, stream_priv,
1054 &lttng_metadata_ring_buffer_file_operations);
1055 if (ret < 0)
1056 goto fd_error;
1057
d83004aa
JD
1058 list_add(&metadata_stream->list,
1059 &session->metadata_cache->metadata_stream);
1060 return ret;
1061
ad1c05e1 1062fd_error:
9c1f4643
MD
1063 kref_put(&session->metadata_cache->refcount, metadata_cache_destroy);
1064kref_error:
b3b8072b
MD
1065 module_put(metadata_stream->transport->owner);
1066notransport:
1067 kfree(metadata_stream);
1068nomem:
11b5a3c2 1069 channel->ops->buffer_read_close(buf);
ad1c05e1
MD
1070 return ret;
1071}
1072
653fe716 1073static
c0e31d2e 1074int lttng_abi_create_event(struct file *channel_file,
6dccd6c1 1075 struct lttng_kernel_event *event_param)
653fe716 1076{
a90917c3 1077 struct lttng_channel *channel = channel_file->private_data;
653fe716 1078 int event_fd, ret;
11b5a3c2 1079 struct file *event_file;
3c997079 1080 void *priv;
653fe716 1081
6dccd6c1
JD
1082 event_param->name[LTTNG_KERNEL_SYM_NAME_LEN - 1] = '\0';
1083 switch (event_param->instrumentation) {
7371f44c 1084 case LTTNG_KERNEL_KRETPROBE:
6dccd6c1 1085 event_param->u.kretprobe.symbol_name[LTTNG_KERNEL_SYM_NAME_LEN - 1] = '\0';
7371f44c 1086 break;
ab2277d6 1087 case LTTNG_KERNEL_KPROBE:
6dccd6c1 1088 event_param->u.kprobe.symbol_name[LTTNG_KERNEL_SYM_NAME_LEN - 1] = '\0';
e0a7a7c4 1089 break;
ab2277d6 1090 case LTTNG_KERNEL_FUNCTION:
6dccd6c1 1091 event_param->u.ftrace.symbol_name[LTTNG_KERNEL_SYM_NAME_LEN - 1] = '\0';
e0a7a7c4
MD
1092 break;
1093 default:
1094 break;
1095 }
33a39a3c
MD
1096 event_fd = lttng_get_unused_fd();
1097 if (event_fd < 0) {
1098 ret = event_fd;
1099 goto fd_error;
1100 }
1101 event_file = anon_inode_getfile("[lttng_event]",
1102 &lttng_event_fops,
1103 NULL, O_RDWR);
1104 if (IS_ERR(event_file)) {
1105 ret = PTR_ERR(event_file);
1106 goto file_error;
1107 }
9c1f4643
MD
1108 /* The event holds a reference on the channel */
1109 if (atomic_long_add_unless(&channel_file->f_count,
1110 1, INT_MAX) == INT_MAX) {
0d2c717f 1111 ret = -EOVERFLOW;
9c1f4643
MD
1112 goto refcount_error;
1113 }
33a39a3c
MD
1114 if (event_param->instrumentation == LTTNG_KERNEL_TRACEPOINT
1115 || event_param->instrumentation == LTTNG_KERNEL_SYSCALL) {
1116 struct lttng_enabler *enabler;
1117
1118 if (event_param->name[strlen(event_param->name) - 1] == '*') {
1119 enabler = lttng_enabler_create(LTTNG_ENABLER_WILDCARD,
1120 event_param, channel);
3c997079 1121 } else {
33a39a3c
MD
1122 enabler = lttng_enabler_create(LTTNG_ENABLER_NAME,
1123 event_param, channel);
1ec65de1 1124 }
33a39a3c
MD
1125 priv = enabler;
1126 } else {
1127 struct lttng_event *event;
4ee2453d 1128
33a39a3c
MD
1129 /*
1130 * We tolerate no failure path after event creation. It
1131 * will stay invariant for the rest of the session.
1132 */
1133 event = lttng_event_create(channel, event_param,
1134 NULL, NULL,
1135 event_param->instrumentation);
1136 WARN_ON_ONCE(!event);
1137 if (IS_ERR(event)) {
1138 ret = PTR_ERR(event);
1139 goto event_error;
80f87dd2 1140 }
33a39a3c 1141 priv = event;
03037b98 1142 }
33a39a3c
MD
1143 event_file->private_data = priv;
1144 fd_install(event_fd, event_file);
653fe716
MD
1145 return event_fd;
1146
03037b98 1147event_error:
9c1f4643
MD
1148 atomic_long_dec(&channel_file->f_count);
1149refcount_error:
c0e31d2e 1150 fput(event_file);
653fe716
MD
1151file_error:
1152 put_unused_fd(event_fd);
1153fd_error:
653fe716
MD
1154 return ret;
1155}
ad1c05e1
MD
1156
1157/**
1158 * lttng_channel_ioctl - lttng syscall through ioctl
1159 *
c0e31d2e 1160 * @file: the file
ad1c05e1
MD
1161 * @cmd: the command
1162 * @arg: command arg
1163 *
1164 * This ioctl implements lttng commands:
38d024ae 1165 * LTTNG_KERNEL_STREAM
ad1c05e1
MD
1166 * Returns an event stream file descriptor or failure.
1167 * (typically, one event stream records events from one CPU)
38d024ae 1168 * LTTNG_KERNEL_EVENT
ad1c05e1 1169 * Returns an event file descriptor or failure.
8070f5c0
MD
1170 * LTTNG_KERNEL_CONTEXT
1171 * Prepend a context field to each event in the channel
e64957da
MD
1172 * LTTNG_KERNEL_ENABLE
1173 * Enable recording for events in this channel (weak enable)
1174 * LTTNG_KERNEL_DISABLE
1175 * Disable recording for events in this channel (strong disable)
baf20995 1176 *
baf20995
MD
1177 * Channel and event file descriptors also hold a reference on the session.
1178 */
ad1c05e1 1179static
c0e31d2e 1180long lttng_channel_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
baf20995 1181{
a90917c3 1182 struct lttng_channel *channel = file->private_data;
8070f5c0 1183
baf20995 1184 switch (cmd) {
6dccd6c1 1185 case LTTNG_KERNEL_OLD_STREAM:
38d024ae 1186 case LTTNG_KERNEL_STREAM:
c0e31d2e 1187 return lttng_abi_open_stream(file);
6dccd6c1
JD
1188 case LTTNG_KERNEL_OLD_EVENT:
1189 {
1190 struct lttng_kernel_event *uevent_param;
1191 struct lttng_kernel_old_event *old_uevent_param;
1192 int ret;
1193
1194 uevent_param = kmalloc(sizeof(struct lttng_kernel_event),
1195 GFP_KERNEL);
1196 if (!uevent_param) {
1197 ret = -ENOMEM;
1198 goto old_event_end;
1199 }
1200 old_uevent_param = kmalloc(
1201 sizeof(struct lttng_kernel_old_event),
1202 GFP_KERNEL);
1203 if (!old_uevent_param) {
1204 ret = -ENOMEM;
1205 goto old_event_error_free_param;
1206 }
1207 if (copy_from_user(old_uevent_param,
1208 (struct lttng_kernel_old_event __user *) arg,
1209 sizeof(struct lttng_kernel_old_event))) {
1210 ret = -EFAULT;
1211 goto old_event_error_free_old_param;
1212 }
1213
1214 memcpy(uevent_param->name, old_uevent_param->name,
1215 sizeof(uevent_param->name));
1216 uevent_param->instrumentation =
1217 old_uevent_param->instrumentation;
1218
1219 switch (old_uevent_param->instrumentation) {
1220 case LTTNG_KERNEL_KPROBE:
1221 uevent_param->u.kprobe.addr =
1222 old_uevent_param->u.kprobe.addr;
1223 uevent_param->u.kprobe.offset =
1224 old_uevent_param->u.kprobe.offset;
1225 memcpy(uevent_param->u.kprobe.symbol_name,
1226 old_uevent_param->u.kprobe.symbol_name,
1227 sizeof(uevent_param->u.kprobe.symbol_name));
1228 break;
1229 case LTTNG_KERNEL_KRETPROBE:
1230 uevent_param->u.kretprobe.addr =
1231 old_uevent_param->u.kretprobe.addr;
1232 uevent_param->u.kretprobe.offset =
1233 old_uevent_param->u.kretprobe.offset;
1234 memcpy(uevent_param->u.kretprobe.symbol_name,
1235 old_uevent_param->u.kretprobe.symbol_name,
1236 sizeof(uevent_param->u.kretprobe.symbol_name));
1237 break;
1238 case LTTNG_KERNEL_FUNCTION:
1239 memcpy(uevent_param->u.ftrace.symbol_name,
1240 old_uevent_param->u.ftrace.symbol_name,
1241 sizeof(uevent_param->u.ftrace.symbol_name));
1242 break;
1243 default:
1244 break;
1245 }
1246 ret = lttng_abi_create_event(file, uevent_param);
1247
1248old_event_error_free_old_param:
1249 kfree(old_uevent_param);
1250old_event_error_free_param:
1251 kfree(uevent_param);
1252old_event_end:
1253 return ret;
1254 }
38d024ae 1255 case LTTNG_KERNEL_EVENT:
6dccd6c1
JD
1256 {
1257 struct lttng_kernel_event uevent_param;
1258
1259 if (copy_from_user(&uevent_param,
1260 (struct lttng_kernel_event __user *) arg,
1261 sizeof(uevent_param)))
1262 return -EFAULT;
1263 return lttng_abi_create_event(file, &uevent_param);
1264 }
1265 case LTTNG_KERNEL_OLD_CONTEXT:
1266 {
1267 struct lttng_kernel_context *ucontext_param;
1268 struct lttng_kernel_old_context *old_ucontext_param;
1269 int ret;
1270
1271 ucontext_param = kmalloc(sizeof(struct lttng_kernel_context),
1272 GFP_KERNEL);
1273 if (!ucontext_param) {
1274 ret = -ENOMEM;
1275 goto old_ctx_end;
1276 }
1277 old_ucontext_param = kmalloc(sizeof(struct lttng_kernel_old_context),
1278 GFP_KERNEL);
1279 if (!old_ucontext_param) {
1280 ret = -ENOMEM;
1281 goto old_ctx_error_free_param;
1282 }
1283
1284 if (copy_from_user(old_ucontext_param,
1285 (struct lttng_kernel_old_context __user *) arg,
1286 sizeof(struct lttng_kernel_old_context))) {
1287 ret = -EFAULT;
1288 goto old_ctx_error_free_old_param;
1289 }
1290 ucontext_param->ctx = old_ucontext_param->ctx;
1291 memcpy(ucontext_param->padding, old_ucontext_param->padding,
1292 sizeof(ucontext_param->padding));
1293 /* only type that uses the union */
1294 if (old_ucontext_param->ctx == LTTNG_KERNEL_CONTEXT_PERF_COUNTER) {
1295 ucontext_param->u.perf_counter.type =
1296 old_ucontext_param->u.perf_counter.type;
1297 ucontext_param->u.perf_counter.config =
1298 old_ucontext_param->u.perf_counter.config;
1299 memcpy(ucontext_param->u.perf_counter.name,
1300 old_ucontext_param->u.perf_counter.name,
1301 sizeof(ucontext_param->u.perf_counter.name));
1302 }
1303
1304 ret = lttng_abi_add_context(file,
1305 ucontext_param,
1306 &channel->ctx, channel->session);
1307
1308old_ctx_error_free_old_param:
1309 kfree(old_ucontext_param);
1310old_ctx_error_free_param:
1311 kfree(ucontext_param);
1312old_ctx_end:
1313 return ret;
1314 }
8070f5c0 1315 case LTTNG_KERNEL_CONTEXT:
6dccd6c1
JD
1316 {
1317 struct lttng_kernel_context ucontext_param;
1318
1319 if (copy_from_user(&ucontext_param,
8070f5c0 1320 (struct lttng_kernel_context __user *) arg,
6dccd6c1
JD
1321 sizeof(ucontext_param)))
1322 return -EFAULT;
1323 return lttng_abi_add_context(file,
1324 &ucontext_param,
8070f5c0 1325 &channel->ctx, channel->session);
6dccd6c1
JD
1326 }
1327 case LTTNG_KERNEL_OLD_ENABLE:
e64957da 1328 case LTTNG_KERNEL_ENABLE:
a90917c3 1329 return lttng_channel_enable(channel);
6dccd6c1 1330 case LTTNG_KERNEL_OLD_DISABLE:
e64957da 1331 case LTTNG_KERNEL_DISABLE:
a90917c3 1332 return lttng_channel_disable(channel);
12e579db
MD
1333 case LTTNG_KERNEL_SYSCALL_MASK:
1334 return lttng_channel_syscall_mask(channel,
1335 (struct lttng_kernel_syscall_mask __user *) arg);
baf20995
MD
1336 default:
1337 return -ENOIOCTLCMD;
1338 }
6dccd6c1 1339
baf20995
MD
1340}
1341
5dbbdb43
MD
1342/**
1343 * lttng_metadata_ioctl - lttng syscall through ioctl
1344 *
1345 * @file: the file
1346 * @cmd: the command
1347 * @arg: command arg
1348 *
1349 * This ioctl implements lttng commands:
38d024ae 1350 * LTTNG_KERNEL_STREAM
5dbbdb43
MD
1351 * Returns an event stream file descriptor or failure.
1352 *
1353 * Channel and event file descriptors also hold a reference on the session.
1354 */
1355static
1356long lttng_metadata_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
1357{
1358 switch (cmd) {
6dccd6c1 1359 case LTTNG_KERNEL_OLD_STREAM:
38d024ae 1360 case LTTNG_KERNEL_STREAM:
d83004aa 1361 return lttng_abi_open_metadata_stream(file);
5dbbdb43
MD
1362 default:
1363 return -ENOIOCTLCMD;
1364 }
1365}
1366
653fe716
MD
1367/**
1368 * lttng_channel_poll - lttng stream addition/removal monitoring
1369 *
c0e31d2e 1370 * @file: the file
653fe716
MD
1371 * @wait: poll table
1372 */
c0e31d2e 1373unsigned int lttng_channel_poll(struct file *file, poll_table *wait)
653fe716 1374{
a90917c3 1375 struct lttng_channel *channel = file->private_data;
653fe716
MD
1376 unsigned int mask = 0;
1377
c0e31d2e 1378 if (file->f_mode & FMODE_READ) {
a33e44a6 1379 poll_wait_set_exclusive(wait);
24cedcfe
MD
1380 poll_wait(file, channel->ops->get_hp_wait_queue(channel->chan),
1381 wait);
653fe716 1382
254ec7bc
MD
1383 if (channel->ops->is_disabled(channel->chan))
1384 return POLLERR;
24cedcfe 1385 if (channel->ops->is_finalized(channel->chan))
653fe716 1386 return POLLHUP;
f71ecafa 1387 if (channel->ops->buffer_has_read_closed_stream(channel->chan))
653fe716 1388 return POLLIN | POLLRDNORM;
f71ecafa 1389 return 0;
653fe716
MD
1390 }
1391 return mask;
1392
1393}
1394
0a84a57f
MD
1395static
1396int lttng_channel_release(struct inode *inode, struct file *file)
1397{
a90917c3 1398 struct lttng_channel *channel = file->private_data;
c269fff4
MD
1399
1400 if (channel)
1401 fput(channel->session->file);
0a84a57f
MD
1402 return 0;
1403}
1404
d83004aa
JD
1405static
1406int lttng_metadata_channel_release(struct inode *inode, struct file *file)
1407{
1408 struct lttng_channel *channel = file->private_data;
1409
1410 if (channel) {
d83004aa 1411 fput(channel->session->file);
a3381417 1412 lttng_metadata_channel_destroy(channel);
d83004aa
JD
1413 }
1414
1415 return 0;
1416}
1417
ad1c05e1 1418static const struct file_operations lttng_channel_fops = {
a33c9927 1419 .owner = THIS_MODULE,
03037b98 1420 .release = lttng_channel_release,
653fe716 1421 .poll = lttng_channel_poll,
ad1c05e1 1422 .unlocked_ioctl = lttng_channel_ioctl,
baf20995 1423#ifdef CONFIG_COMPAT
03037b98 1424 .compat_ioctl = lttng_channel_ioctl,
baf20995 1425#endif
11b5a3c2 1426};
baf20995 1427
5dbbdb43 1428static const struct file_operations lttng_metadata_fops = {
a33c9927 1429 .owner = THIS_MODULE,
d83004aa 1430 .release = lttng_metadata_channel_release,
5dbbdb43
MD
1431 .unlocked_ioctl = lttng_metadata_ioctl,
1432#ifdef CONFIG_COMPAT
1433 .compat_ioctl = lttng_metadata_ioctl,
1434#endif
1435};
1436
8070f5c0
MD
1437/**
1438 * lttng_event_ioctl - lttng syscall through ioctl
1439 *
1440 * @file: the file
1441 * @cmd: the command
1442 * @arg: command arg
1443 *
1444 * This ioctl implements lttng commands:
8070f5c0
MD
1445 * LTTNG_KERNEL_CONTEXT
1446 * Prepend a context field to each record of this event
e64957da
MD
1447 * LTTNG_KERNEL_ENABLE
1448 * Enable recording for this event (weak enable)
1449 * LTTNG_KERNEL_DISABLE
1450 * Disable recording for this event (strong disable)
8070f5c0
MD
1451 */
1452static
1453long lttng_event_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
1454{
3c997079
MD
1455 struct lttng_event *event;
1456 struct lttng_enabler *enabler;
1457 enum lttng_event_type *evtype = file->private_data;
8070f5c0
MD
1458
1459 switch (cmd) {
6dccd6c1
JD
1460 case LTTNG_KERNEL_OLD_CONTEXT:
1461 {
3c997079
MD
1462 /* Not implemented */
1463 return -ENOSYS;
6dccd6c1 1464 }
8070f5c0 1465 case LTTNG_KERNEL_CONTEXT:
6dccd6c1 1466 {
3c997079
MD
1467 /* Not implemented */
1468 return -ENOSYS;
6dccd6c1
JD
1469 }
1470 case LTTNG_KERNEL_OLD_ENABLE:
e64957da 1471 case LTTNG_KERNEL_ENABLE:
3c997079
MD
1472 switch (*evtype) {
1473 case LTTNG_TYPE_EVENT:
1474 event = file->private_data;
1475 return lttng_event_enable(event);
1476 case LTTNG_TYPE_ENABLER:
1477 enabler = file->private_data;
1478 return lttng_enabler_enable(enabler);
1479 default:
1480 WARN_ON_ONCE(1);
1481 return -ENOSYS;
1482 }
6dccd6c1 1483 case LTTNG_KERNEL_OLD_DISABLE:
e64957da 1484 case LTTNG_KERNEL_DISABLE:
3c997079
MD
1485 switch (*evtype) {
1486 case LTTNG_TYPE_EVENT:
1487 event = file->private_data;
1488 return lttng_event_disable(event);
1489 case LTTNG_TYPE_ENABLER:
1490 enabler = file->private_data;
1491 return lttng_enabler_disable(enabler);
1492 default:
1493 WARN_ON_ONCE(1);
1494 return -ENOSYS;
1495 }
07dfc1d0
MD
1496 case LTTNG_KERNEL_FILTER:
1497 switch (*evtype) {
1498 case LTTNG_TYPE_EVENT:
1499 return -EINVAL;
1500 case LTTNG_TYPE_ENABLER:
1501 {
1502 enabler = file->private_data;
1503 return lttng_enabler_attach_bytecode(enabler,
1504 (struct lttng_kernel_filter_bytecode __user *) arg);
1505 }
1506
1507 }
8070f5c0
MD
1508 default:
1509 return -ENOIOCTLCMD;
1510 }
1511}
1512
0a84a57f
MD
1513static
1514int lttng_event_release(struct inode *inode, struct file *file)
1515{
3c997079
MD
1516 struct lttng_event *event;
1517 struct lttng_enabler *enabler;
1518 enum lttng_event_type *evtype = file->private_data;
1519
1520 if (!evtype)
1521 return 0;
1522
1523 switch (*evtype) {
1524 case LTTNG_TYPE_EVENT:
1525 event = file->private_data;
1526 if (event)
1527 fput(event->chan->file);
1528 break;
1529 case LTTNG_TYPE_ENABLER:
1530 enabler = file->private_data;
1531 if (enabler)
1532 fput(enabler->chan->file);
1533 break;
1534 default:
1535 WARN_ON_ONCE(1);
1536 break;
1537 }
c269fff4 1538
0a84a57f
MD
1539 return 0;
1540}
1541
3b923e5b 1542/* TODO: filter control ioctl */
0a84a57f 1543static const struct file_operations lttng_event_fops = {
a33c9927 1544 .owner = THIS_MODULE,
0a84a57f 1545 .release = lttng_event_release,
8070f5c0
MD
1546 .unlocked_ioctl = lttng_event_ioctl,
1547#ifdef CONFIG_COMPAT
1548 .compat_ioctl = lttng_event_ioctl,
1549#endif
11b5a3c2 1550};
0a84a57f 1551
3b731ab1
JD
1552static int put_u64(uint64_t val, unsigned long arg)
1553{
1554 return put_user(val, (uint64_t __user *) arg);
1555}
1556
ed8d02d6
JD
1557static long lttng_stream_ring_buffer_ioctl(struct file *filp,
1558 unsigned int cmd, unsigned long arg)
1559{
3b731ab1
JD
1560 struct lib_ring_buffer *buf = filp->private_data;
1561 struct channel *chan = buf->backend.chan;
1562 const struct lib_ring_buffer_config *config = &chan->backend.config;
dd5a0db3 1563 const struct lttng_channel_ops *ops = chan->backend.priv_ops;
3b731ab1
JD
1564 int ret;
1565
1566 if (atomic_read(&chan->record_disabled))
1567 return -EIO;
1568
ed8d02d6 1569 switch (cmd) {
3b731ab1
JD
1570 case LTTNG_RING_BUFFER_GET_TIMESTAMP_BEGIN:
1571 {
1572 uint64_t ts;
1573
dd5a0db3 1574 ret = ops->timestamp_begin(config, buf, &ts);
3b731ab1
JD
1575 if (ret < 0)
1576 goto error;
1577 return put_u64(ts, arg);
1578 }
1579 case LTTNG_RING_BUFFER_GET_TIMESTAMP_END:
1580 {
1581 uint64_t ts;
1582
dd5a0db3 1583 ret = ops->timestamp_end(config, buf, &ts);
3b731ab1
JD
1584 if (ret < 0)
1585 goto error;
1586 return put_u64(ts, arg);
1587 }
1588 case LTTNG_RING_BUFFER_GET_EVENTS_DISCARDED:
1589 {
1590 uint64_t ed;
1591
dd5a0db3 1592 ret = ops->events_discarded(config, buf, &ed);
3b731ab1
JD
1593 if (ret < 0)
1594 goto error;
1595 return put_u64(ed, arg);
1596 }
1597 case LTTNG_RING_BUFFER_GET_CONTENT_SIZE:
1598 {
1599 uint64_t cs;
1600
dd5a0db3 1601 ret = ops->content_size(config, buf, &cs);
3b731ab1
JD
1602 if (ret < 0)
1603 goto error;
1604 return put_u64(cs, arg);
1605 }
1606 case LTTNG_RING_BUFFER_GET_PACKET_SIZE:
1607 {
1608 uint64_t ps;
1609
dd5a0db3 1610 ret = ops->packet_size(config, buf, &ps);
3b731ab1
JD
1611 if (ret < 0)
1612 goto error;
1613 return put_u64(ps, arg);
1614 }
1615 case LTTNG_RING_BUFFER_GET_STREAM_ID:
1616 {
1617 uint64_t si;
1618
dd5a0db3 1619 ret = ops->stream_id(config, buf, &si);
3b731ab1
JD
1620 if (ret < 0)
1621 goto error;
1622 return put_u64(si, arg);
1623 }
2348ca17
JD
1624 case LTTNG_RING_BUFFER_GET_CURRENT_TIMESTAMP:
1625 {
1626 uint64_t ts;
1627
dd5a0db3 1628 ret = ops->current_timestamp(config, buf, &ts);
2348ca17
JD
1629 if (ret < 0)
1630 goto error;
1631 return put_u64(ts, arg);
1632 }
5b3cf4f9
JD
1633 case LTTNG_RING_BUFFER_GET_SEQ_NUM:
1634 {
1635 uint64_t seq;
1636
1637 ret = ops->sequence_number(config, buf, &seq);
1638 if (ret < 0)
1639 goto error;
1640 return put_u64(seq, arg);
1641 }
5594698f
JD
1642 case LTTNG_RING_BUFFER_INSTANCE_ID:
1643 {
1644 uint64_t id;
1645
1646 ret = ops->instance_id(config, buf, &id);
1647 if (ret < 0)
1648 goto error;
1649 return put_u64(id, arg);
1650 }
3b731ab1
JD
1651 default:
1652 return lib_ring_buffer_file_operations.unlocked_ioctl(filp,
1653 cmd, arg);
ed8d02d6 1654 }
3b731ab1
JD
1655
1656error:
1657 return -ENOSYS;
ed8d02d6
JD
1658}
1659
1660#ifdef CONFIG_COMPAT
1661static long lttng_stream_ring_buffer_compat_ioctl(struct file *filp,
1662 unsigned int cmd, unsigned long arg)
1663{
3b731ab1
JD
1664 struct lib_ring_buffer *buf = filp->private_data;
1665 struct channel *chan = buf->backend.chan;
1666 const struct lib_ring_buffer_config *config = &chan->backend.config;
dd5a0db3 1667 const struct lttng_channel_ops *ops = chan->backend.priv_ops;
3b731ab1
JD
1668 int ret;
1669
1670 if (atomic_read(&chan->record_disabled))
1671 return -EIO;
1672
ed8d02d6 1673 switch (cmd) {
3b731ab1
JD
1674 case LTTNG_RING_BUFFER_COMPAT_GET_TIMESTAMP_BEGIN:
1675 {
1676 uint64_t ts;
1677
dd5a0db3 1678 ret = ops->timestamp_begin(config, buf, &ts);
3b731ab1
JD
1679 if (ret < 0)
1680 goto error;
1681 return put_u64(ts, arg);
1682 }
1683 case LTTNG_RING_BUFFER_COMPAT_GET_TIMESTAMP_END:
1684 {
1685 uint64_t ts;
1686
dd5a0db3 1687 ret = ops->timestamp_end(config, buf, &ts);
3b731ab1
JD
1688 if (ret < 0)
1689 goto error;
1690 return put_u64(ts, arg);
1691 }
1692 case LTTNG_RING_BUFFER_COMPAT_GET_EVENTS_DISCARDED:
1693 {
1694 uint64_t ed;
1695
dd5a0db3 1696 ret = ops->events_discarded(config, buf, &ed);
3b731ab1
JD
1697 if (ret < 0)
1698 goto error;
1699 return put_u64(ed, arg);
ed8d02d6 1700 }
3b731ab1
JD
1701 case LTTNG_RING_BUFFER_COMPAT_GET_CONTENT_SIZE:
1702 {
1703 uint64_t cs;
1704
dd5a0db3 1705 ret = ops->content_size(config, buf, &cs);
3b731ab1
JD
1706 if (ret < 0)
1707 goto error;
1708 return put_u64(cs, arg);
1709 }
1710 case LTTNG_RING_BUFFER_COMPAT_GET_PACKET_SIZE:
1711 {
1712 uint64_t ps;
1713
dd5a0db3 1714 ret = ops->packet_size(config, buf, &ps);
3b731ab1
JD
1715 if (ret < 0)
1716 goto error;
1717 return put_u64(ps, arg);
1718 }
1719 case LTTNG_RING_BUFFER_COMPAT_GET_STREAM_ID:
1720 {
1721 uint64_t si;
1722
dd5a0db3 1723 ret = ops->stream_id(config, buf, &si);
3b731ab1
JD
1724 if (ret < 0)
1725 goto error;
1726 return put_u64(si, arg);
1727 }
2348ca17
JD
1728 case LTTNG_RING_BUFFER_GET_CURRENT_TIMESTAMP:
1729 {
1730 uint64_t ts;
1731
dd5a0db3 1732 ret = ops->current_timestamp(config, buf, &ts);
2348ca17
JD
1733 if (ret < 0)
1734 goto error;
1735 return put_u64(ts, arg);
1736 }
5b3cf4f9
JD
1737 case LTTNG_RING_BUFFER_COMPAT_GET_SEQ_NUM:
1738 {
1739 uint64_t seq;
1740
1741 ret = ops->sequence_number(config, buf, &seq);
1742 if (ret < 0)
1743 goto error;
1744 return put_u64(seq, arg);
1745 }
5594698f
JD
1746 case LTTNG_RING_BUFFER_COMPAT_INSTANCE_ID:
1747 {
1748 uint64_t id;
1749
1750 ret = ops->instance_id(config, buf, &id);
1751 if (ret < 0)
1752 goto error;
1753 return put_u64(id, arg);
1754 }
3b731ab1
JD
1755 default:
1756 return lib_ring_buffer_file_operations.compat_ioctl(filp,
1757 cmd, arg);
1758 }
1759
1760error:
1761 return -ENOSYS;
ed8d02d6
JD
1762}
1763#endif /* CONFIG_COMPAT */
1764
1765static void lttng_stream_override_ring_buffer_fops(void)
1766{
1767 lttng_stream_ring_buffer_file_operations.owner = THIS_MODULE;
1768 lttng_stream_ring_buffer_file_operations.open =
1769 lib_ring_buffer_file_operations.open;
1770 lttng_stream_ring_buffer_file_operations.release =
1771 lib_ring_buffer_file_operations.release;
1772 lttng_stream_ring_buffer_file_operations.poll =
1773 lib_ring_buffer_file_operations.poll;
1774 lttng_stream_ring_buffer_file_operations.splice_read =
1775 lib_ring_buffer_file_operations.splice_read;
1776 lttng_stream_ring_buffer_file_operations.mmap =
1777 lib_ring_buffer_file_operations.mmap;
1778 lttng_stream_ring_buffer_file_operations.unlocked_ioctl =
1779 lttng_stream_ring_buffer_ioctl;
1780 lttng_stream_ring_buffer_file_operations.llseek =
1781 lib_ring_buffer_file_operations.llseek;
1782#ifdef CONFIG_COMPAT
1783 lttng_stream_ring_buffer_file_operations.compat_ioctl =
1784 lttng_stream_ring_buffer_compat_ioctl;
1785#endif
1786}
1787
80996790 1788int __init lttng_abi_init(void)
baf20995
MD
1789{
1790 int ret = 0;
1791
6d2a620c 1792 wrapper_vmalloc_sync_all();
2754583e 1793 lttng_clock_ref();
140a62b0
JD
1794
1795 ret = lttng_tp_mempool_init();
1796 if (ret) {
1797 goto error;
1798 }
1799
d29348f7 1800 lttng_proc_dentry = proc_create_data("lttng", S_IRUSR | S_IWUSR, NULL,
e6a17f26
MD
1801 &lttng_fops, NULL);
1802
255e52a4 1803 if (!lttng_proc_dentry) {
baf20995
MD
1804 printk(KERN_ERR "Error creating LTTng control file\n");
1805 ret = -ENOMEM;
1806 goto error;
1807 }
ed8d02d6 1808 lttng_stream_override_ring_buffer_fops();
2754583e 1809 return 0;
ed8d02d6 1810
baf20995 1811error:
140a62b0 1812 lttng_tp_mempool_destroy();
2754583e 1813 lttng_clock_unref();
baf20995
MD
1814 return ret;
1815}
1816
e6e65fcd
MD
1817/* No __exit annotation because used by init error path too. */
1818void lttng_abi_exit(void)
baf20995 1819{
140a62b0 1820 lttng_tp_mempool_destroy();
2754583e 1821 lttng_clock_unref();
e6a17f26
MD
1822 if (lttng_proc_dentry)
1823 remove_proc_entry("lttng", NULL);
baf20995 1824}
This page took 0.121711 seconds and 5 git commands to generate.