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