Add event notifier and event notifier enabler
[lttng-modules.git] / src / lttng-abi.c
CommitLineData
b7cdc182 1/* SPDX-License-Identifier: (GPL-2.0-only or LGPL-2.1-only)
9f36eaed 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>
263b6c88 33#include <wrapper/vmalloc.h> /* for wrapper_vmalloc_sync_mappings() */
24591303
MD
34#include <ringbuffer/vfs.h>
35#include <ringbuffer/backend.h>
36#include <ringbuffer/frontend.h>
241ae9a8
MD
37#include <wrapper/poll.h>
38#include <wrapper/file.h>
39#include <wrapper/kref.h>
2df37e95
MD
40#include <lttng/string-utils.h>
41#include <lttng/abi.h>
42#include <lttng/abi-old.h>
43#include <lttng/events.h>
44#include <lttng/tracer.h>
45#include <lttng/tp-mempool.h>
24591303 46#include <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;
059de147
MJ
54
55#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5,6,0))
56static const struct proc_ops lttng_proc_ops;
57#else
58static const struct file_operations lttng_proc_ops;
59#endif
60
ad1c05e1 61static const struct file_operations lttng_session_fops;
750b05f2 62static const struct file_operations lttng_event_notifier_group_fops;
ad1c05e1 63static const struct file_operations lttng_channel_fops;
5dbbdb43 64static const struct file_operations lttng_metadata_fops;
305d3e42 65static const struct file_operations lttng_event_fops;
ed8d02d6 66static struct file_operations lttng_stream_ring_buffer_file_operations;
baf20995 67
9616f0bf 68static int put_u64(uint64_t val, unsigned long arg);
8b97fd42 69static int put_u32(uint32_t val, unsigned long arg);
9616f0bf 70
a33c9927
MD
71/*
72 * Teardown management: opened file descriptors keep a refcount on the module,
73 * so it can only exit when all file descriptors are closed.
74 */
75
ad1c05e1 76static
baf20995
MD
77int lttng_abi_create_session(void)
78{
a90917c3 79 struct lttng_session *session;
c0e31d2e 80 struct file *session_file;
11b5a3c2 81 int session_fd, ret;
baf20995 82
a90917c3 83 session = lttng_session_create();
baf20995
MD
84 if (!session)
85 return -ENOMEM;
4ac10b76 86 session_fd = lttng_get_unused_fd();
baf20995
MD
87 if (session_fd < 0) {
88 ret = session_fd;
89 goto fd_error;
90 }
c0e31d2e 91 session_file = anon_inode_getfile("[lttng_session]",
ad1c05e1 92 &lttng_session_fops,
baf20995 93 session, O_RDWR);
c0e31d2e
MD
94 if (IS_ERR(session_file)) {
95 ret = PTR_ERR(session_file);
baf20995
MD
96 goto file_error;
97 }
c0e31d2e
MD
98 session->file = session_file;
99 fd_install(session_fd, session_file);
baf20995
MD
100 return session_fd;
101
102file_error:
103 put_unused_fd(session_fd);
104fd_error:
a90917c3 105 lttng_session_destroy(session);
baf20995
MD
106 return ret;
107}
108
750b05f2
FD
109static
110int lttng_abi_create_event_notifier_group(void)
111{
112 struct lttng_event_notifier_group *event_notifier_group;
113 struct file *event_notifier_group_file;
114 int event_notifier_group_fd, ret;
115
116 event_notifier_group = lttng_event_notifier_group_create();
117 if (!event_notifier_group)
118 return -ENOMEM;
119
120 event_notifier_group_fd = lttng_get_unused_fd();
121 if (event_notifier_group_fd < 0) {
122 ret = event_notifier_group_fd;
123 goto fd_error;
124 }
125 event_notifier_group_file = anon_inode_getfile("[lttng_event_notifier_group]",
126 &lttng_event_notifier_group_fops,
127 event_notifier_group, O_RDWR);
128 if (IS_ERR(event_notifier_group_file)) {
129 ret = PTR_ERR(event_notifier_group_file);
130 goto file_error;
131 }
132
133 event_notifier_group->file = event_notifier_group_file;
134 fd_install(event_notifier_group_fd, event_notifier_group_file);
135 return event_notifier_group_fd;
136
137file_error:
138 put_unused_fd(event_notifier_group_fd);
139fd_error:
140 lttng_event_notifier_group_destroy(event_notifier_group);
141 return ret;
142}
143
271b6681
MD
144static
145int lttng_abi_tracepoint_list(void)
146{
147 struct file *tracepoint_list_file;
148 int file_fd, ret;
149
4ac10b76 150 file_fd = lttng_get_unused_fd();
271b6681
MD
151 if (file_fd < 0) {
152 ret = file_fd;
153 goto fd_error;
154 }
30f18bf0 155
8ee099b6 156 tracepoint_list_file = anon_inode_getfile("[lttng_tracepoint_list]",
271b6681
MD
157 &lttng_tracepoint_list_fops,
158 NULL, O_RDWR);
159 if (IS_ERR(tracepoint_list_file)) {
160 ret = PTR_ERR(tracepoint_list_file);
161 goto file_error;
162 }
30f18bf0
MD
163 ret = lttng_tracepoint_list_fops.open(NULL, tracepoint_list_file);
164 if (ret < 0)
165 goto open_error;
271b6681
MD
166 fd_install(file_fd, tracepoint_list_file);
167 return file_fd;
168
30f18bf0
MD
169open_error:
170 fput(tracepoint_list_file);
271b6681
MD
171file_error:
172 put_unused_fd(file_fd);
173fd_error:
174 return ret;
175}
176
f127e61e
MD
177#ifndef CONFIG_HAVE_SYSCALL_TRACEPOINTS
178static inline
179int lttng_abi_syscall_list(void)
180{
181 return -ENOSYS;
182}
183#else
184static
185int lttng_abi_syscall_list(void)
186{
187 struct file *syscall_list_file;
188 int file_fd, ret;
189
190 file_fd = lttng_get_unused_fd();
191 if (file_fd < 0) {
192 ret = file_fd;
193 goto fd_error;
194 }
195
196 syscall_list_file = anon_inode_getfile("[lttng_syscall_list]",
197 &lttng_syscall_list_fops,
198 NULL, O_RDWR);
199 if (IS_ERR(syscall_list_file)) {
200 ret = PTR_ERR(syscall_list_file);
201 goto file_error;
202 }
203 ret = lttng_syscall_list_fops.open(NULL, syscall_list_file);
204 if (ret < 0)
205 goto open_error;
206 fd_install(file_fd, syscall_list_file);
f127e61e
MD
207 return file_fd;
208
209open_error:
210 fput(syscall_list_file);
211file_error:
212 put_unused_fd(file_fd);
213fd_error:
214 return ret;
215}
216#endif
217
80c16bcf 218static
6dccd6c1 219void lttng_abi_tracer_version(struct lttng_kernel_tracer_version *v)
80c16bcf 220{
6dccd6c1
JD
221 v->major = LTTNG_MODULES_MAJOR_VERSION;
222 v->minor = LTTNG_MODULES_MINOR_VERSION;
223 v->patchlevel = LTTNG_MODULES_PATCHLEVEL_VERSION;
80c16bcf
MD
224}
225
42cabb80
MD
226static
227void lttng_abi_tracer_abi_version(struct lttng_kernel_tracer_abi_version *v)
228{
229 v->major = LTTNG_MODULES_ABI_MAJOR_VERSION;
230 v->minor = LTTNG_MODULES_ABI_MINOR_VERSION;
231}
232
8070f5c0
MD
233static
234long lttng_abi_add_context(struct file *file,
6dccd6c1 235 struct lttng_kernel_context *context_param,
a90917c3 236 struct lttng_ctx **ctx, struct lttng_session *session)
8070f5c0 237{
8070f5c0
MD
238
239 if (session->been_active)
240 return -EPERM;
241
6dccd6c1 242 switch (context_param->ctx) {
12a313a5 243 case LTTNG_KERNEL_CONTEXT_PID:
8070f5c0 244 return lttng_add_pid_to_ctx(ctx);
a8ad3613
MD
245 case LTTNG_KERNEL_CONTEXT_PRIO:
246 return lttng_add_prio_to_ctx(ctx);
53f1f0ca
MD
247 case LTTNG_KERNEL_CONTEXT_NICE:
248 return lttng_add_nice_to_ctx(ctx);
b64bc438
MD
249 case LTTNG_KERNEL_CONTEXT_VPID:
250 return lttng_add_vpid_to_ctx(ctx);
251 case LTTNG_KERNEL_CONTEXT_TID:
252 return lttng_add_tid_to_ctx(ctx);
253 case LTTNG_KERNEL_CONTEXT_VTID:
254 return lttng_add_vtid_to_ctx(ctx);
255 case LTTNG_KERNEL_CONTEXT_PPID:
256 return lttng_add_ppid_to_ctx(ctx);
257 case LTTNG_KERNEL_CONTEXT_VPPID:
258 return lttng_add_vppid_to_ctx(ctx);
12a313a5 259 case LTTNG_KERNEL_CONTEXT_PERF_COUNTER:
6dccd6c1
JD
260 context_param->u.perf_counter.name[LTTNG_KERNEL_SYM_NAME_LEN - 1] = '\0';
261 return lttng_add_perf_counter_to_ctx(context_param->u.perf_counter.type,
262 context_param->u.perf_counter.config,
263 context_param->u.perf_counter.name,
c24a0d71 264 ctx);
a2563e83
MD
265 case LTTNG_KERNEL_CONTEXT_PROCNAME:
266 return lttng_add_procname_to_ctx(ctx);
975da2c0
JD
267 case LTTNG_KERNEL_CONTEXT_HOSTNAME:
268 return lttng_add_hostname_to_ctx(ctx);
b3699d90
MD
269 case LTTNG_KERNEL_CONTEXT_CPU_ID:
270 return lttng_add_cpu_id_to_ctx(ctx);
79150a49
JD
271 case LTTNG_KERNEL_CONTEXT_INTERRUPTIBLE:
272 return lttng_add_interruptible_to_ctx(ctx);
273 case LTTNG_KERNEL_CONTEXT_NEED_RESCHEDULE:
274 return lttng_add_need_reschedule_to_ctx(ctx);
275 case LTTNG_KERNEL_CONTEXT_PREEMPTIBLE:
276 return lttng_add_preemptible_to_ctx(ctx);
277 case LTTNG_KERNEL_CONTEXT_MIGRATABLE:
278 return lttng_add_migratable_to_ctx(ctx);
2fa2d39a
FG
279 case LTTNG_KERNEL_CONTEXT_CALLSTACK_KERNEL:
280 case LTTNG_KERNEL_CONTEXT_CALLSTACK_USER:
281 return lttng_add_callstack_to_ctx(ctx, context_param->ctx);
a6cf40a4
MJ
282 case LTTNG_KERNEL_CONTEXT_CGROUP_NS:
283 return lttng_add_cgroup_ns_to_ctx(ctx);
284 case LTTNG_KERNEL_CONTEXT_IPC_NS:
285 return lttng_add_ipc_ns_to_ctx(ctx);
286 case LTTNG_KERNEL_CONTEXT_MNT_NS:
287 return lttng_add_mnt_ns_to_ctx(ctx);
288 case LTTNG_KERNEL_CONTEXT_NET_NS:
289 return lttng_add_net_ns_to_ctx(ctx);
290 case LTTNG_KERNEL_CONTEXT_PID_NS:
291 return lttng_add_pid_ns_to_ctx(ctx);
292 case LTTNG_KERNEL_CONTEXT_USER_NS:
293 return lttng_add_user_ns_to_ctx(ctx);
294 case LTTNG_KERNEL_CONTEXT_UTS_NS:
295 return lttng_add_uts_ns_to_ctx(ctx);
dc923e75
MJ
296 case LTTNG_KERNEL_CONTEXT_UID:
297 return lttng_add_uid_to_ctx(ctx);
298 case LTTNG_KERNEL_CONTEXT_EUID:
299 return lttng_add_euid_to_ctx(ctx);
300 case LTTNG_KERNEL_CONTEXT_SUID:
301 return lttng_add_suid_to_ctx(ctx);
302 case LTTNG_KERNEL_CONTEXT_GID:
303 return lttng_add_gid_to_ctx(ctx);
304 case LTTNG_KERNEL_CONTEXT_EGID:
305 return lttng_add_egid_to_ctx(ctx);
306 case LTTNG_KERNEL_CONTEXT_SGID:
307 return lttng_add_sgid_to_ctx(ctx);
308 case LTTNG_KERNEL_CONTEXT_VUID:
309 return lttng_add_vuid_to_ctx(ctx);
310 case LTTNG_KERNEL_CONTEXT_VEUID:
311 return lttng_add_veuid_to_ctx(ctx);
312 case LTTNG_KERNEL_CONTEXT_VSUID:
313 return lttng_add_vsuid_to_ctx(ctx);
314 case LTTNG_KERNEL_CONTEXT_VGID:
315 return lttng_add_vgid_to_ctx(ctx);
316 case LTTNG_KERNEL_CONTEXT_VEGID:
317 return lttng_add_vegid_to_ctx(ctx);
318 case LTTNG_KERNEL_CONTEXT_VSGID:
319 return lttng_add_vsgid_to_ctx(ctx);
876e2e92
MJ
320 case LTTNG_KERNEL_CONTEXT_TIME_NS:
321 return lttng_add_time_ns_to_ctx(ctx);
8070f5c0
MD
322 default:
323 return -EINVAL;
324 }
325}
326
ad1c05e1
MD
327/**
328 * lttng_ioctl - lttng syscall through ioctl
329 *
c0e31d2e 330 * @file: the file
ad1c05e1
MD
331 * @cmd: the command
332 * @arg: command arg
333 *
334 * This ioctl implements lttng commands:
38d024ae 335 * LTTNG_KERNEL_SESSION
ad1c05e1 336 * Returns a LTTng trace session file descriptor
271b6681
MD
337 * LTTNG_KERNEL_TRACER_VERSION
338 * Returns the LTTng kernel tracer version
339 * LTTNG_KERNEL_TRACEPOINT_LIST
340 * Returns a file descriptor listing available tracepoints
360f38ea
MD
341 * LTTNG_KERNEL_WAIT_QUIESCENT
342 * Returns after all previously running probes have completed
42cabb80
MD
343 * LTTNG_KERNEL_TRACER_ABI_VERSION
344 * Returns the LTTng kernel tracer ABI version
750b05f2
FD
345 * LTTNG_KERNEL_EVENT_NOTIFIER_GROUP_CREATE
346 * Returns a LTTng event notifier group file descriptor
ad1c05e1
MD
347 *
348 * The returned session will be deleted when its file descriptor is closed.
349 */
350static
c0e31d2e 351long lttng_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
ad1c05e1
MD
352{
353 switch (cmd) {
6dccd6c1 354 case LTTNG_KERNEL_OLD_SESSION:
38d024ae 355 case LTTNG_KERNEL_SESSION:
ad1c05e1 356 return lttng_abi_create_session();
750b05f2
FD
357 case LTTNG_KERNEL_EVENT_NOTIFIER_GROUP_CREATE:
358 return lttng_abi_create_event_notifier_group();
6dccd6c1
JD
359 case LTTNG_KERNEL_OLD_TRACER_VERSION:
360 {
361 struct lttng_kernel_tracer_version v;
362 struct lttng_kernel_old_tracer_version oldv;
363 struct lttng_kernel_old_tracer_version *uversion =
364 (struct lttng_kernel_old_tracer_version __user *) arg;
365
366 lttng_abi_tracer_version(&v);
367 oldv.major = v.major;
368 oldv.minor = v.minor;
369 oldv.patchlevel = v.patchlevel;
370
371 if (copy_to_user(uversion, &oldv, sizeof(oldv)))
372 return -EFAULT;
373 return 0;
374 }
80c16bcf 375 case LTTNG_KERNEL_TRACER_VERSION:
6dccd6c1
JD
376 {
377 struct lttng_kernel_tracer_version version;
378 struct lttng_kernel_tracer_version *uversion =
379 (struct lttng_kernel_tracer_version __user *) arg;
380
381 lttng_abi_tracer_version(&version);
42cabb80
MD
382
383 if (copy_to_user(uversion, &version, sizeof(version)))
384 return -EFAULT;
385 return 0;
386 }
387 case LTTNG_KERNEL_TRACER_ABI_VERSION:
388 {
389 struct lttng_kernel_tracer_abi_version version;
390 struct lttng_kernel_tracer_abi_version *uversion =
391 (struct lttng_kernel_tracer_abi_version __user *) arg;
392
393 lttng_abi_tracer_abi_version(&version);
394
6dccd6c1
JD
395 if (copy_to_user(uversion, &version, sizeof(version)))
396 return -EFAULT;
397 return 0;
398 }
399 case LTTNG_KERNEL_OLD_TRACEPOINT_LIST:
271b6681
MD
400 case LTTNG_KERNEL_TRACEPOINT_LIST:
401 return lttng_abi_tracepoint_list();
2d2464bd
MD
402 case LTTNG_KERNEL_SYSCALL_LIST:
403 return lttng_abi_syscall_list();
6dccd6c1 404 case LTTNG_KERNEL_OLD_WAIT_QUIESCENT:
5f7f9078
MD
405 case LTTNG_KERNEL_WAIT_QUIESCENT:
406 synchronize_trace();
407 return 0;
6dccd6c1
JD
408 case LTTNG_KERNEL_OLD_CALIBRATE:
409 {
410 struct lttng_kernel_old_calibrate __user *ucalibrate =
411 (struct lttng_kernel_old_calibrate __user *) arg;
412 struct lttng_kernel_old_calibrate old_calibrate;
413 struct lttng_kernel_calibrate calibrate;
414 int ret;
415
416 if (copy_from_user(&old_calibrate, ucalibrate, sizeof(old_calibrate)))
417 return -EFAULT;
418 calibrate.type = old_calibrate.type;
419 ret = lttng_calibrate(&calibrate);
420 if (copy_to_user(ucalibrate, &old_calibrate, sizeof(old_calibrate)))
421 return -EFAULT;
422 return ret;
423 }
57105fc2
MD
424 case LTTNG_KERNEL_CALIBRATE:
425 {
3db41b2c
MD
426 struct lttng_kernel_calibrate __user *ucalibrate =
427 (struct lttng_kernel_calibrate __user *) arg;
428 struct lttng_kernel_calibrate calibrate;
57105fc2
MD
429 int ret;
430
431 if (copy_from_user(&calibrate, ucalibrate, sizeof(calibrate)))
432 return -EFAULT;
433 ret = lttng_calibrate(&calibrate);
434 if (copy_to_user(ucalibrate, &calibrate, sizeof(calibrate)))
435 return -EFAULT;
436 return ret;
437 }
ad1c05e1
MD
438 default:
439 return -ENOIOCTLCMD;
440 }
441}
442
059de147
MJ
443#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5,6,0))
444static const struct proc_ops lttng_proc_ops = {
445 .proc_ioctl = lttng_ioctl,
446#ifdef CONFIG_COMPAT
447 .proc_compat_ioctl = lttng_ioctl,
448#endif /* CONFIG_COMPAT */
449};
450#else
451static const struct file_operations lttng_proc_ops = {
a33c9927 452 .owner = THIS_MODULE,
ad1c05e1
MD
453 .unlocked_ioctl = lttng_ioctl,
454#ifdef CONFIG_COMPAT
03037b98 455 .compat_ioctl = lttng_ioctl,
059de147 456#endif /* CONFIG_COMPAT */
11b5a3c2 457};
059de147 458#endif
ad1c05e1 459
5dbbdb43 460static
c0e31d2e 461int lttng_abi_create_channel(struct file *session_file,
6dccd6c1 462 struct lttng_kernel_channel *chan_param,
5dbbdb43 463 enum channel_type channel_type)
baf20995 464{
a90917c3 465 struct lttng_session *session = session_file->private_data;
88dfd899 466 const struct file_operations *fops = NULL;
5dbbdb43 467 const char *transport_name;
a90917c3 468 struct lttng_channel *chan;
c0e31d2e 469 struct file *chan_file;
baf20995 470 int chan_fd;
ad1c05e1 471 int ret = 0;
baf20995 472
4ac10b76 473 chan_fd = lttng_get_unused_fd();
baf20995
MD
474 if (chan_fd < 0) {
475 ret = chan_fd;
476 goto fd_error;
477 }
88dfd899
MD
478 switch (channel_type) {
479 case PER_CPU_CHANNEL:
480 fops = &lttng_channel_fops;
481 break;
482 case METADATA_CHANNEL:
483 fops = &lttng_metadata_fops;
484 break;
485 }
2470a237 486
c0e31d2e 487 chan_file = anon_inode_getfile("[lttng_channel]",
88dfd899 488 fops,
03037b98 489 NULL, O_RDWR);
c0e31d2e
MD
490 if (IS_ERR(chan_file)) {
491 ret = PTR_ERR(chan_file);
baf20995
MD
492 goto file_error;
493 }
5dbbdb43
MD
494 switch (channel_type) {
495 case PER_CPU_CHANNEL:
6dccd6c1
JD
496 if (chan_param->output == LTTNG_KERNEL_SPLICE) {
497 transport_name = chan_param->overwrite ?
96ba7208 498 "relay-overwrite" : "relay-discard";
6dccd6c1
JD
499 } else if (chan_param->output == LTTNG_KERNEL_MMAP) {
500 transport_name = chan_param->overwrite ?
96ba7208
JD
501 "relay-overwrite-mmap" : "relay-discard-mmap";
502 } else {
503 return -EINVAL;
504 }
5dbbdb43 505 break;
5dbbdb43 506 case METADATA_CHANNEL:
6dccd6c1 507 if (chan_param->output == LTTNG_KERNEL_SPLICE)
96ba7208 508 transport_name = "relay-metadata";
6dccd6c1 509 else if (chan_param->output == LTTNG_KERNEL_MMAP)
96ba7208
JD
510 transport_name = "relay-metadata-mmap";
511 else
512 return -EINVAL;
5dbbdb43
MD
513 break;
514 default:
515 transport_name = "<unknown>";
516 break;
517 }
98d7281c
MJ
518 if (!atomic_long_add_unless(&session_file->f_count, 1, LONG_MAX)) {
519 ret = -EOVERFLOW;
9c1f4643
MD
520 goto refcount_error;
521 }
03037b98
MD
522 /*
523 * We tolerate no failure path after channel creation. It will stay
524 * invariant for the rest of the session.
525 */
a90917c3 526 chan = lttng_channel_create(session, transport_name, NULL,
6dccd6c1
JD
527 chan_param->subbuf_size,
528 chan_param->num_subbuf,
529 chan_param->switch_timer_interval,
d83004aa
JD
530 chan_param->read_timer_interval,
531 channel_type);
03037b98 532 if (!chan) {
f3d01b96 533 ret = -EINVAL;
03037b98
MD
534 goto chan_error;
535 }
11b5a3c2 536 chan->file = chan_file;
c0e31d2e
MD
537 chan_file->private_data = chan;
538 fd_install(chan_fd, chan_file);
ad1c05e1 539
baf20995
MD
540 return chan_fd;
541
03037b98 542chan_error:
9c1f4643
MD
543 atomic_long_dec(&session_file->f_count);
544refcount_error:
c0e31d2e 545 fput(chan_file);
baf20995
MD
546file_error:
547 put_unused_fd(chan_fd);
548fd_error:
baf20995
MD
549 return ret;
550}
551
7f859fbf
JR
552static
553int lttng_abi_session_set_name(struct lttng_session *session,
554 struct lttng_kernel_session_name *name)
555{
556 size_t len;
557
558 len = strnlen(name->name, LTTNG_KERNEL_SESSION_NAME_LEN);
559
560 if (len == LTTNG_KERNEL_SESSION_NAME_LEN) {
561 /* Name is too long/malformed */
562 return -EINVAL;
563 }
564
565 strcpy(session->name, name->name);
566 return 0;
567}
568
1c88f269
JR
569static
570int lttng_abi_session_set_creation_time(struct lttng_session *session,
571 struct lttng_kernel_session_creation_time *time)
572{
573 size_t len;
574
575 len = strnlen(time->iso8601, LTTNG_KERNEL_SESSION_CREATION_TIME_ISO8601_LEN);
576
577 if (len == LTTNG_KERNEL_SESSION_CREATION_TIME_ISO8601_LEN) {
578 /* Time is too long/malformed */
579 return -EINVAL;
580 }
581
582 strcpy(session->creation_time, time->iso8601);
583 return 0;
584}
585
d1f652f8
MD
586static
587enum tracker_type get_tracker_type(struct lttng_kernel_tracker_args *tracker)
588{
589 switch (tracker->type) {
590 case LTTNG_KERNEL_TRACKER_PID:
591 return TRACKER_PID;
592 case LTTNG_KERNEL_TRACKER_VPID:
593 return TRACKER_VPID;
594 case LTTNG_KERNEL_TRACKER_UID:
595 return TRACKER_UID;
596 case LTTNG_KERNEL_TRACKER_VUID:
597 return TRACKER_VUID;
598 case LTTNG_KERNEL_TRACKER_GID:
599 return TRACKER_GID;
600 case LTTNG_KERNEL_TRACKER_VGID:
601 return TRACKER_VGID;
602 default:
603 return TRACKER_UNKNOWN;
604 }
605}
606
baf20995 607/**
ad1c05e1 608 * lttng_session_ioctl - lttng session fd ioctl
baf20995 609 *
c0e31d2e 610 * @file: the file
baf20995
MD
611 * @cmd: the command
612 * @arg: command arg
613 *
614 * This ioctl implements lttng commands:
38d024ae 615 * LTTNG_KERNEL_CHANNEL
baf20995 616 * Returns a LTTng channel file descriptor
e64957da
MD
617 * LTTNG_KERNEL_ENABLE
618 * Enables tracing for a session (weak enable)
619 * LTTNG_KERNEL_DISABLE
620 * Disables tracing for a session (strong disable)
8070f5c0
MD
621 * LTTNG_KERNEL_METADATA
622 * Returns a LTTng metadata file descriptor
e0130fab 623 * LTTNG_KERNEL_SESSION_TRACK_PID
d1f652f8 624 * Add PID to session PID tracker
e0130fab 625 * LTTNG_KERNEL_SESSION_UNTRACK_PID
d1f652f8
MD
626 * Remove PID from session PID tracker
627 * LTTNG_KERNEL_SESSION_TRACK_ID
628 * Add ID to tracker
629 * LTTNG_KERNEL_SESSION_UNTRACK_ID
630 * Remove ID from tracker
ad1c05e1
MD
631 *
632 * The returned channel will be deleted when its file descriptor is closed.
633 */
634static
c0e31d2e 635long lttng_session_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
ad1c05e1 636{
a90917c3 637 struct lttng_session *session = file->private_data;
2d4c4d15
MD
638 struct lttng_kernel_channel chan_param;
639 struct lttng_kernel_old_channel old_chan_param;
c0e31d2e 640
ad1c05e1 641 switch (cmd) {
6dccd6c1
JD
642 case LTTNG_KERNEL_OLD_CHANNEL:
643 {
6dccd6c1
JD
644 if (copy_from_user(&old_chan_param,
645 (struct lttng_kernel_old_channel __user *) arg,
646 sizeof(struct lttng_kernel_old_channel)))
647 return -EFAULT;
648 chan_param.overwrite = old_chan_param.overwrite;
649 chan_param.subbuf_size = old_chan_param.subbuf_size;
650 chan_param.num_subbuf = old_chan_param.num_subbuf;
651 chan_param.switch_timer_interval = old_chan_param.switch_timer_interval;
652 chan_param.read_timer_interval = old_chan_param.read_timer_interval;
653 chan_param.output = old_chan_param.output;
654
655 return lttng_abi_create_channel(file, &chan_param,
656 PER_CPU_CHANNEL);
657 }
38d024ae 658 case LTTNG_KERNEL_CHANNEL:
6dccd6c1 659 {
6dccd6c1 660 if (copy_from_user(&chan_param,
38d024ae 661 (struct lttng_kernel_channel __user *) arg,
6dccd6c1
JD
662 sizeof(struct lttng_kernel_channel)))
663 return -EFAULT;
664 return lttng_abi_create_channel(file, &chan_param,
5dbbdb43 665 PER_CPU_CHANNEL);
6dccd6c1
JD
666 }
667 case LTTNG_KERNEL_OLD_SESSION_START:
668 case LTTNG_KERNEL_OLD_ENABLE:
38d024ae 669 case LTTNG_KERNEL_SESSION_START:
e64957da 670 case LTTNG_KERNEL_ENABLE:
a90917c3 671 return lttng_session_enable(session);
6dccd6c1
JD
672 case LTTNG_KERNEL_OLD_SESSION_STOP:
673 case LTTNG_KERNEL_OLD_DISABLE:
38d024ae 674 case LTTNG_KERNEL_SESSION_STOP:
e64957da 675 case LTTNG_KERNEL_DISABLE:
a90917c3 676 return lttng_session_disable(session);
6dccd6c1
JD
677 case LTTNG_KERNEL_OLD_METADATA:
678 {
6dccd6c1
JD
679 if (copy_from_user(&old_chan_param,
680 (struct lttng_kernel_old_channel __user *) arg,
681 sizeof(struct lttng_kernel_old_channel)))
682 return -EFAULT;
683 chan_param.overwrite = old_chan_param.overwrite;
684 chan_param.subbuf_size = old_chan_param.subbuf_size;
685 chan_param.num_subbuf = old_chan_param.num_subbuf;
686 chan_param.switch_timer_interval = old_chan_param.switch_timer_interval;
687 chan_param.read_timer_interval = old_chan_param.read_timer_interval;
688 chan_param.output = old_chan_param.output;
689
690 return lttng_abi_create_channel(file, &chan_param,
691 METADATA_CHANNEL);
692 }
38d024ae 693 case LTTNG_KERNEL_METADATA:
6dccd6c1 694 {
6dccd6c1
JD
695 if (copy_from_user(&chan_param,
696 (struct lttng_kernel_channel __user *) arg,
697 sizeof(struct lttng_kernel_channel)))
698 return -EFAULT;
699 return lttng_abi_create_channel(file, &chan_param,
5dbbdb43 700 METADATA_CHANNEL);
6dccd6c1 701 }
e0130fab 702 case LTTNG_KERNEL_SESSION_TRACK_PID:
d1f652f8 703 return lttng_session_track_id(session, TRACKER_PID, (int) arg);
e0130fab 704 case LTTNG_KERNEL_SESSION_UNTRACK_PID:
d1f652f8
MD
705 return lttng_session_untrack_id(session, TRACKER_PID, (int) arg);
706 case LTTNG_KERNEL_SESSION_TRACK_ID:
707 {
708 struct lttng_kernel_tracker_args tracker;
709 enum tracker_type tracker_type;
710
711 if (copy_from_user(&tracker,
712 (struct lttng_kernel_tracker_args __user *) arg,
713 sizeof(struct lttng_kernel_tracker_args)))
714 return -EFAULT;
715 tracker_type = get_tracker_type(&tracker);
716 if (tracker_type == TRACKER_UNKNOWN)
717 return -EINVAL;
718 return lttng_session_track_id(session, tracker_type, tracker.id);
719 }
720 case LTTNG_KERNEL_SESSION_UNTRACK_ID:
721 {
722 struct lttng_kernel_tracker_args tracker;
723 enum tracker_type tracker_type;
724
725 if (copy_from_user(&tracker,
726 (struct lttng_kernel_tracker_args __user *) arg,
727 sizeof(struct lttng_kernel_tracker_args)))
728 return -EFAULT;
729 tracker_type = get_tracker_type(&tracker);
730 if (tracker_type == TRACKER_UNKNOWN)
731 return -EINVAL;
732 return lttng_session_untrack_id(session, tracker_type,
733 tracker.id);
734 }
7e6f9ef6 735 case LTTNG_KERNEL_SESSION_LIST_TRACKER_PIDS:
d1f652f8
MD
736 return lttng_session_list_tracker_ids(session, TRACKER_PID);
737 case LTTNG_KERNEL_SESSION_LIST_TRACKER_IDS:
738 {
739 struct lttng_kernel_tracker_args tracker;
740 enum tracker_type tracker_type;
741
742 if (copy_from_user(&tracker,
743 (struct lttng_kernel_tracker_args __user *) arg,
744 sizeof(struct lttng_kernel_tracker_args)))
745 return -EFAULT;
746 tracker_type = get_tracker_type(&tracker);
747 if (tracker_type == TRACKER_UNKNOWN)
748 return -EINVAL;
749 return lttng_session_list_tracker_ids(session, tracker_type);
750 }
9616f0bf
JD
751 case LTTNG_KERNEL_SESSION_METADATA_REGEN:
752 return lttng_session_metadata_regenerate(session);
601252cf
MD
753 case LTTNG_KERNEL_SESSION_STATEDUMP:
754 return lttng_session_statedump(session);
7f859fbf
JR
755 case LTTNG_KERNEL_SESSION_SET_NAME:
756 {
757 struct lttng_kernel_session_name name;
758
759 if (copy_from_user(&name,
760 (struct lttng_kernel_session_name __user *) arg,
761 sizeof(struct lttng_kernel_session_name)))
762 return -EFAULT;
763 return lttng_abi_session_set_name(session, &name);
764 }
1c88f269
JR
765 case LTTNG_KERNEL_SESSION_SET_CREATION_TIME:
766 {
767 struct lttng_kernel_session_creation_time time;
768
769 if (copy_from_user(&time,
770 (struct lttng_kernel_session_creation_time __user *) arg,
771 sizeof(struct lttng_kernel_session_creation_time)))
772 return -EFAULT;
773 return lttng_abi_session_set_creation_time(session, &time);
774 }
ad1c05e1
MD
775 default:
776 return -ENOIOCTLCMD;
777 }
778}
779
03037b98
MD
780/*
781 * Called when the last file reference is dropped.
782 *
783 * Big fat note: channels and events are invariant for the whole session after
784 * their creation. So this session destruction also destroys all channel and
785 * event structures specific to this session (they are not destroyed when their
786 * individual file is released).
787 */
ad1c05e1 788static
03037b98 789int lttng_session_release(struct inode *inode, struct file *file)
ad1c05e1 790{
a90917c3 791 struct lttng_session *session = file->private_data;
c269fff4
MD
792
793 if (session)
a90917c3 794 lttng_session_destroy(session);
11b5a3c2 795 return 0;
ad1c05e1 796}
ad1c05e1
MD
797
798static const struct file_operations lttng_session_fops = {
a33c9927 799 .owner = THIS_MODULE,
03037b98 800 .release = lttng_session_release,
ad1c05e1
MD
801 .unlocked_ioctl = lttng_session_ioctl,
802#ifdef CONFIG_COMPAT
03037b98 803 .compat_ioctl = lttng_session_ioctl,
ad1c05e1 804#endif
11b5a3c2 805};
ad1c05e1 806
d83004aa
JD
807/**
808 * lttng_metadata_ring_buffer_poll - LTTng ring buffer poll file operation
809 * @filp: the file
810 * @wait: poll table
811 *
812 * Handles the poll operations for the metadata channels.
813 */
ad1c05e1 814static
d83004aa
JD
815unsigned int lttng_metadata_ring_buffer_poll(struct file *filp,
816 poll_table *wait)
817{
818 struct lttng_metadata_stream *stream = filp->private_data;
819 struct lib_ring_buffer *buf = stream->priv;
820 int finalized;
821 unsigned int mask = 0;
822
823 if (filp->f_mode & FMODE_READ) {
824 poll_wait_set_exclusive(wait);
825 poll_wait(filp, &stream->read_wait, wait);
826
827 finalized = stream->finalized;
828
829 /*
830 * lib_ring_buffer_is_finalized() contains a smp_rmb()
831 * ordering finalized load before offsets loads.
832 */
833 WARN_ON(atomic_long_read(&buf->active_readers) != 1);
834
835 if (finalized)
836 mask |= POLLHUP;
837
92d9f5e6 838 mutex_lock(&stream->metadata_cache->lock);
d83004aa 839 if (stream->metadata_cache->metadata_written >
f613e3e6 840 stream->metadata_out)
d83004aa 841 mask |= POLLIN;
92d9f5e6 842 mutex_unlock(&stream->metadata_cache->lock);
d83004aa
JD
843 }
844
845 return mask;
846}
847
f613e3e6
MD
848static
849void lttng_metadata_ring_buffer_ioctl_put_next_subbuf(struct file *filp,
850 unsigned int cmd, unsigned long arg)
851{
852 struct lttng_metadata_stream *stream = filp->private_data;
853
854 stream->metadata_out = stream->metadata_in;
855}
856
d1344afa
JD
857/*
858 * Reset the counter of how much metadata has been consumed to 0. That way,
859 * the consumer receives the content of the metadata cache unchanged. This is
860 * different from the metadata_regenerate where the offset from epoch is
861 * resampled, here we want the exact same content as the last time the metadata
862 * was generated. This command is only possible if all the metadata written
863 * in the cache has been output to the metadata stream to avoid corrupting the
864 * metadata file.
865 *
866 * Return 0 on success, a negative value on error.
867 */
868static
869int lttng_metadata_cache_dump(struct lttng_metadata_stream *stream)
870{
871 int ret;
872 struct lttng_metadata_cache *cache = stream->metadata_cache;
873
874 mutex_lock(&cache->lock);
875 if (stream->metadata_out != cache->metadata_written) {
876 ret = -EBUSY;
877 goto end;
878 }
879 stream->metadata_out = 0;
880 stream->metadata_in = 0;
881 wake_up_interruptible(&stream->read_wait);
882 ret = 0;
883
884end:
885 mutex_unlock(&cache->lock);
886 return ret;
887}
888
d83004aa
JD
889static
890long lttng_metadata_ring_buffer_ioctl(struct file *filp,
891 unsigned int cmd, unsigned long arg)
892{
893 int ret;
894 struct lttng_metadata_stream *stream = filp->private_data;
895 struct lib_ring_buffer *buf = stream->priv;
8b97fd42
MD
896 unsigned int rb_cmd;
897 bool coherent;
898
899 if (cmd == RING_BUFFER_GET_NEXT_SUBBUF_METADATA_CHECK)
900 rb_cmd = RING_BUFFER_GET_NEXT_SUBBUF;
901 else
902 rb_cmd = cmd;
d83004aa
JD
903
904 switch (cmd) {
d83004aa
JD
905 case RING_BUFFER_GET_NEXT_SUBBUF:
906 {
35097f36
JD
907 struct lttng_metadata_stream *stream = filp->private_data;
908 struct lib_ring_buffer *buf = stream->priv;
909 struct channel *chan = buf->backend.chan;
910
8b97fd42 911 ret = lttng_metadata_output_channel(stream, chan, NULL);
35097f36
JD
912 if (ret > 0) {
913 lib_ring_buffer_switch_slow(buf, SWITCH_ACTIVE);
914 ret = 0;
915 } else if (ret < 0)
d83004aa
JD
916 goto err;
917 break;
918 }
f613e3e6
MD
919 case RING_BUFFER_GET_SUBBUF:
920 {
921 /*
922 * Random access is not allowed for metadata channel.
923 */
924 return -ENOSYS;
925 }
c6f05468 926 case RING_BUFFER_FLUSH_EMPTY: /* Fall-through. */
35097f36
JD
927 case RING_BUFFER_FLUSH:
928 {
929 struct lttng_metadata_stream *stream = filp->private_data;
930 struct lib_ring_buffer *buf = stream->priv;
931 struct channel *chan = buf->backend.chan;
932
933 /*
934 * Before doing the actual ring buffer flush, write up to one
935 * packet of metadata in the ring buffer.
936 */
8b97fd42 937 ret = lttng_metadata_output_channel(stream, chan, NULL);
35097f36
JD
938 if (ret < 0)
939 goto err;
940 break;
941 }
9616f0bf
JD
942 case RING_BUFFER_GET_METADATA_VERSION:
943 {
944 struct lttng_metadata_stream *stream = filp->private_data;
945
946 return put_u64(stream->version, arg);
947 }
d1344afa
JD
948 case RING_BUFFER_METADATA_CACHE_DUMP:
949 {
950 struct lttng_metadata_stream *stream = filp->private_data;
951
952 return lttng_metadata_cache_dump(stream);
953 }
8b97fd42
MD
954 case RING_BUFFER_GET_NEXT_SUBBUF_METADATA_CHECK:
955 {
956 struct lttng_metadata_stream *stream = filp->private_data;
957 struct lib_ring_buffer *buf = stream->priv;
958 struct channel *chan = buf->backend.chan;
959
960 ret = lttng_metadata_output_channel(stream, chan, &coherent);
961 if (ret > 0) {
962 lib_ring_buffer_switch_slow(buf, SWITCH_ACTIVE);
963 ret = 0;
964 } else if (ret < 0) {
965 goto err;
966 }
967 break;
968 }
d83004aa
JD
969 default:
970 break;
971 }
f613e3e6
MD
972 /* PUT_SUBBUF is the one from lib ring buffer, unmodified. */
973
d83004aa 974 /* Performing lib ring buffer ioctl after our own. */
8b97fd42 975 ret = lib_ring_buffer_ioctl(filp, rb_cmd, arg, buf);
f613e3e6
MD
976 if (ret < 0)
977 goto err;
d83004aa 978
f613e3e6
MD
979 switch (cmd) {
980 case RING_BUFFER_PUT_NEXT_SUBBUF:
981 {
982 lttng_metadata_ring_buffer_ioctl_put_next_subbuf(filp,
983 cmd, arg);
984 break;
985 }
8b97fd42
MD
986 case RING_BUFFER_GET_NEXT_SUBBUF_METADATA_CHECK:
987 {
988 return put_u32(coherent, arg);
989 }
f613e3e6
MD
990 default:
991 break;
992 }
d83004aa
JD
993err:
994 return ret;
995}
996
aeb9064d 997#ifdef CONFIG_COMPAT
d83004aa
JD
998static
999long lttng_metadata_ring_buffer_compat_ioctl(struct file *filp,
1000 unsigned int cmd, unsigned long arg)
1001{
1002 int ret;
1003 struct lttng_metadata_stream *stream = filp->private_data;
1004 struct lib_ring_buffer *buf = stream->priv;
8b97fd42
MD
1005 unsigned int rb_cmd;
1006 bool coherent;
1007
1008 if (cmd == RING_BUFFER_GET_NEXT_SUBBUF_METADATA_CHECK)
1009 rb_cmd = RING_BUFFER_GET_NEXT_SUBBUF;
1010 else
1011 rb_cmd = cmd;
d83004aa
JD
1012
1013 switch (cmd) {
d83004aa
JD
1014 case RING_BUFFER_GET_NEXT_SUBBUF:
1015 {
35097f36
JD
1016 struct lttng_metadata_stream *stream = filp->private_data;
1017 struct lib_ring_buffer *buf = stream->priv;
1018 struct channel *chan = buf->backend.chan;
1019
8b97fd42 1020 ret = lttng_metadata_output_channel(stream, chan, NULL);
35097f36
JD
1021 if (ret > 0) {
1022 lib_ring_buffer_switch_slow(buf, SWITCH_ACTIVE);
1023 ret = 0;
1024 } else if (ret < 0)
d83004aa
JD
1025 goto err;
1026 break;
1027 }
f613e3e6
MD
1028 case RING_BUFFER_GET_SUBBUF:
1029 {
1030 /*
1031 * Random access is not allowed for metadata channel.
1032 */
1033 return -ENOSYS;
1034 }
c6f05468 1035 case RING_BUFFER_FLUSH_EMPTY: /* Fall-through. */
96c55c2f
MD
1036 case RING_BUFFER_FLUSH:
1037 {
1038 struct lttng_metadata_stream *stream = filp->private_data;
1039 struct lib_ring_buffer *buf = stream->priv;
1040 struct channel *chan = buf->backend.chan;
1041
1042 /*
1043 * Before doing the actual ring buffer flush, write up to one
1044 * packet of metadata in the ring buffer.
1045 */
8b97fd42 1046 ret = lttng_metadata_output_channel(stream, chan, NULL);
96c55c2f
MD
1047 if (ret < 0)
1048 goto err;
1049 break;
1050 }
1051 case RING_BUFFER_GET_METADATA_VERSION:
1052 {
1053 struct lttng_metadata_stream *stream = filp->private_data;
1054
1055 return put_u64(stream->version, arg);
1056 }
d1344afa
JD
1057 case RING_BUFFER_METADATA_CACHE_DUMP:
1058 {
1059 struct lttng_metadata_stream *stream = filp->private_data;
1060
1061 return lttng_metadata_cache_dump(stream);
1062 }
8b97fd42
MD
1063 case RING_BUFFER_GET_NEXT_SUBBUF_METADATA_CHECK:
1064 {
1065 struct lttng_metadata_stream *stream = filp->private_data;
1066 struct lib_ring_buffer *buf = stream->priv;
1067 struct channel *chan = buf->backend.chan;
1068
1069 ret = lttng_metadata_output_channel(stream, chan, &coherent);
1070 if (ret > 0) {
1071 lib_ring_buffer_switch_slow(buf, SWITCH_ACTIVE);
1072 ret = 0;
1073 } else if (ret < 0) {
1074 goto err;
1075 }
1076 break;
1077 }
d83004aa
JD
1078 default:
1079 break;
1080 }
f613e3e6
MD
1081 /* PUT_SUBBUF is the one from lib ring buffer, unmodified. */
1082
d83004aa 1083 /* Performing lib ring buffer ioctl after our own. */
8b97fd42 1084 ret = lib_ring_buffer_compat_ioctl(filp, rb_cmd, arg, buf);
f613e3e6
MD
1085 if (ret < 0)
1086 goto err;
d83004aa 1087
f613e3e6
MD
1088 switch (cmd) {
1089 case RING_BUFFER_PUT_NEXT_SUBBUF:
1090 {
1091 lttng_metadata_ring_buffer_ioctl_put_next_subbuf(filp,
1092 cmd, arg);
1093 break;
1094 }
8b97fd42
MD
1095 case RING_BUFFER_GET_NEXT_SUBBUF_METADATA_CHECK:
1096 {
1097 return put_u32(coherent, arg);
1098 }
f613e3e6
MD
1099 default:
1100 break;
1101 }
d83004aa
JD
1102err:
1103 return ret;
1104}
aeb9064d 1105#endif
d83004aa 1106
b3b8072b
MD
1107/*
1108 * This is not used by anonymous file descriptors. This code is left
1109 * there if we ever want to implement an inode with open() operation.
1110 */
d83004aa
JD
1111static
1112int lttng_metadata_ring_buffer_open(struct inode *inode, struct file *file)
1113{
1114 struct lttng_metadata_stream *stream = inode->i_private;
1115 struct lib_ring_buffer *buf = stream->priv;
1116
1117 file->private_data = buf;
b3b8072b
MD
1118 /*
1119 * Since life-time of metadata cache differs from that of
1120 * session, we need to keep our own reference on the transport.
1121 */
1122 if (!try_module_get(stream->transport->owner)) {
5a15f70c 1123 printk(KERN_WARNING "LTTng: Can't lock transport module.\n");
b3b8072b
MD
1124 return -EBUSY;
1125 }
d83004aa
JD
1126 return lib_ring_buffer_open(inode, file, buf);
1127}
1128
1129static
1130int lttng_metadata_ring_buffer_release(struct inode *inode, struct file *file)
1131{
1132 struct lttng_metadata_stream *stream = file->private_data;
1133 struct lib_ring_buffer *buf = stream->priv;
1134
92143b2c
MD
1135 mutex_lock(&stream->metadata_cache->lock);
1136 list_del(&stream->list);
1137 mutex_unlock(&stream->metadata_cache->lock);
d83004aa 1138 kref_put(&stream->metadata_cache->refcount, metadata_cache_destroy);
b3b8072b 1139 module_put(stream->transport->owner);
92143b2c 1140 kfree(stream);
d83004aa
JD
1141 return lib_ring_buffer_release(inode, file, buf);
1142}
1143
1144static
1145ssize_t lttng_metadata_ring_buffer_splice_read(struct file *in, loff_t *ppos,
1146 struct pipe_inode_info *pipe, size_t len,
1147 unsigned int flags)
1148{
1149 struct lttng_metadata_stream *stream = in->private_data;
1150 struct lib_ring_buffer *buf = stream->priv;
1151
1152 return lib_ring_buffer_splice_read(in, ppos, pipe, len,
1153 flags, buf);
1154}
1155
1156static
1157int lttng_metadata_ring_buffer_mmap(struct file *filp,
1158 struct vm_area_struct *vma)
1159{
1160 struct lttng_metadata_stream *stream = filp->private_data;
1161 struct lib_ring_buffer *buf = stream->priv;
1162
1163 return lib_ring_buffer_mmap(filp, vma, buf);
1164}
1165
1166static
1167const struct file_operations lttng_metadata_ring_buffer_file_operations = {
1168 .owner = THIS_MODULE,
1169 .open = lttng_metadata_ring_buffer_open,
1170 .release = lttng_metadata_ring_buffer_release,
1171 .poll = lttng_metadata_ring_buffer_poll,
1172 .splice_read = lttng_metadata_ring_buffer_splice_read,
1173 .mmap = lttng_metadata_ring_buffer_mmap,
1174 .unlocked_ioctl = lttng_metadata_ring_buffer_ioctl,
1175 .llseek = vfs_lib_ring_buffer_no_llseek,
1176#ifdef CONFIG_COMPAT
1177 .compat_ioctl = lttng_metadata_ring_buffer_compat_ioctl,
1178#endif
1179};
1180
1181static
1182int lttng_abi_create_stream_fd(struct file *channel_file, void *stream_priv,
a3fcd499 1183 const struct file_operations *fops, const char *name)
ad1c05e1 1184{
ad1c05e1 1185 int stream_fd, ret;
11b5a3c2 1186 struct file *stream_file;
ad1c05e1 1187
4ac10b76 1188 stream_fd = lttng_get_unused_fd();
ad1c05e1
MD
1189 if (stream_fd < 0) {
1190 ret = stream_fd;
1191 goto fd_error;
1192 }
a3fcd499 1193 stream_file = anon_inode_getfile(name, fops, stream_priv, O_RDWR);
c0e31d2e
MD
1194 if (IS_ERR(stream_file)) {
1195 ret = PTR_ERR(stream_file);
ad1c05e1
MD
1196 goto file_error;
1197 }
409453cb
MD
1198 /*
1199 * OPEN_FMODE, called within anon_inode_getfile/alloc_file, don't honor
1200 * FMODE_LSEEK, FMODE_PREAD nor FMODE_PWRITE. We need to read from this
1201 * file descriptor, so we set FMODE_PREAD here.
1202 */
d7b6f197 1203 stream_file->f_mode |= FMODE_PREAD;
c0e31d2e 1204 fd_install(stream_fd, stream_file);
dda6a249
MD
1205 /*
1206 * The stream holds a reference to the channel within the generic ring
1207 * buffer library, so no need to hold a refcount on the channel and
1208 * session files here.
1209 */
ad1c05e1
MD
1210 return stream_fd;
1211
1212file_error:
1213 put_unused_fd(stream_fd);
d83004aa
JD
1214fd_error:
1215 return ret;
1216}
1217
1218static
1219int lttng_abi_open_stream(struct file *channel_file)
1220{
1221 struct lttng_channel *channel = channel_file->private_data;
1222 struct lib_ring_buffer *buf;
1223 int ret;
1224 void *stream_priv;
1225
1226 buf = channel->ops->buffer_read_open(channel->chan);
1227 if (!buf)
1228 return -ENOENT;
1229
1230 stream_priv = buf;
1231 ret = lttng_abi_create_stream_fd(channel_file, stream_priv,
a3fcd499
MD
1232 &lttng_stream_ring_buffer_file_operations,
1233 "[lttng_stream]");
d83004aa
JD
1234 if (ret < 0)
1235 goto fd_error;
1236
1237 return ret;
1238
1239fd_error:
1240 channel->ops->buffer_read_close(buf);
1241 return ret;
1242}
1243
1244static
1245int lttng_abi_open_metadata_stream(struct file *channel_file)
1246{
1247 struct lttng_channel *channel = channel_file->private_data;
1248 struct lttng_session *session = channel->session;
1249 struct lib_ring_buffer *buf;
1250 int ret;
1251 struct lttng_metadata_stream *metadata_stream;
1252 void *stream_priv;
1253
1254 buf = channel->ops->buffer_read_open(channel->chan);
1255 if (!buf)
1256 return -ENOENT;
1257
1258 metadata_stream = kzalloc(sizeof(struct lttng_metadata_stream),
1259 GFP_KERNEL);
b3b8072b
MD
1260 if (!metadata_stream) {
1261 ret = -ENOMEM;
1262 goto nomem;
1263 }
d83004aa
JD
1264 metadata_stream->metadata_cache = session->metadata_cache;
1265 init_waitqueue_head(&metadata_stream->read_wait);
1266 metadata_stream->priv = buf;
1267 stream_priv = metadata_stream;
b3b8072b 1268 metadata_stream->transport = channel->transport;
8b97fd42
MD
1269 /* Initial state is an empty metadata, considered as incoherent. */
1270 metadata_stream->coherent = false;
b3b8072b
MD
1271
1272 /*
1273 * Since life-time of metadata cache differs from that of
1274 * session, we need to keep our own reference on the transport.
1275 */
1276 if (!try_module_get(metadata_stream->transport->owner)) {
5a15f70c 1277 printk(KERN_WARNING "LTTng: Can't lock transport module.\n");
b3b8072b
MD
1278 ret = -EINVAL;
1279 goto notransport;
1280 }
1281
901aaa5f
FD
1282 if (!lttng_kref_get(&session->metadata_cache->refcount)) {
1283 ret = -EOVERFLOW;
9c1f4643 1284 goto kref_error;
901aaa5f
FD
1285 }
1286
d83004aa 1287 ret = lttng_abi_create_stream_fd(channel_file, stream_priv,
a3fcd499
MD
1288 &lttng_metadata_ring_buffer_file_operations,
1289 "[lttng_metadata_stream]");
d83004aa
JD
1290 if (ret < 0)
1291 goto fd_error;
1292
92143b2c 1293 mutex_lock(&session->metadata_cache->lock);
d83004aa
JD
1294 list_add(&metadata_stream->list,
1295 &session->metadata_cache->metadata_stream);
92143b2c 1296 mutex_unlock(&session->metadata_cache->lock);
d83004aa
JD
1297 return ret;
1298
ad1c05e1 1299fd_error:
9c1f4643
MD
1300 kref_put(&session->metadata_cache->refcount, metadata_cache_destroy);
1301kref_error:
b3b8072b
MD
1302 module_put(metadata_stream->transport->owner);
1303notransport:
1304 kfree(metadata_stream);
1305nomem:
11b5a3c2 1306 channel->ops->buffer_read_close(buf);
ad1c05e1
MD
1307 return ret;
1308}
1309
badfe9f5
MD
1310static
1311int lttng_abi_validate_event_param(struct lttng_kernel_event *event_param)
1312{
1313 /* Limit ABI to implemented features. */
1314 switch (event_param->instrumentation) {
1315 case LTTNG_KERNEL_SYSCALL:
1316 switch (event_param->u.syscall.entryexit) {
1317 case LTTNG_KERNEL_SYSCALL_ENTRYEXIT:
1318 break;
1319 default:
1320 return -EINVAL;
1321 }
1322 switch (event_param->u.syscall.abi) {
1323 case LTTNG_KERNEL_SYSCALL_ABI_ALL:
1324 break;
1325 default:
1326 return -EINVAL;
1327 }
1328 switch (event_param->u.syscall.match) {
1329 case LTTNG_SYSCALL_MATCH_NAME:
1330 break;
1331 default:
1332 return -EINVAL;
1333 }
1334 break;
1335
1336 case LTTNG_KERNEL_TRACEPOINT: /* Fallthrough */
1337 case LTTNG_KERNEL_KPROBE: /* Fallthrough */
1338 case LTTNG_KERNEL_KRETPROBE: /* Fallthrough */
1339 case LTTNG_KERNEL_NOOP: /* Fallthrough */
1340 case LTTNG_KERNEL_UPROBE:
1341 break;
1342
1343 case LTTNG_KERNEL_FUNCTION: /* Fallthrough */
1344 default:
1345 return -EINVAL;
1346 }
1347 return 0;
1348}
1349
653fe716 1350static
c0e31d2e 1351int lttng_abi_create_event(struct file *channel_file,
6dccd6c1 1352 struct lttng_kernel_event *event_param)
653fe716 1353{
a90917c3 1354 struct lttng_channel *channel = channel_file->private_data;
653fe716 1355 int event_fd, ret;
11b5a3c2 1356 struct file *event_file;
3c997079 1357 void *priv;
653fe716 1358
6dccd6c1
JD
1359 event_param->name[LTTNG_KERNEL_SYM_NAME_LEN - 1] = '\0';
1360 switch (event_param->instrumentation) {
7371f44c 1361 case LTTNG_KERNEL_KRETPROBE:
6dccd6c1 1362 event_param->u.kretprobe.symbol_name[LTTNG_KERNEL_SYM_NAME_LEN - 1] = '\0';
7371f44c 1363 break;
ab2277d6 1364 case LTTNG_KERNEL_KPROBE:
6dccd6c1 1365 event_param->u.kprobe.symbol_name[LTTNG_KERNEL_SYM_NAME_LEN - 1] = '\0';
e0a7a7c4 1366 break;
ab2277d6 1367 case LTTNG_KERNEL_FUNCTION:
e884017c
MD
1368 WARN_ON_ONCE(1);
1369 /* Not implemented. */
e0a7a7c4
MD
1370 break;
1371 default:
1372 break;
1373 }
33a39a3c
MD
1374 event_fd = lttng_get_unused_fd();
1375 if (event_fd < 0) {
1376 ret = event_fd;
1377 goto fd_error;
1378 }
1379 event_file = anon_inode_getfile("[lttng_event]",
1380 &lttng_event_fops,
1381 NULL, O_RDWR);
1382 if (IS_ERR(event_file)) {
1383 ret = PTR_ERR(event_file);
1384 goto file_error;
1385 }
9c1f4643 1386 /* The event holds a reference on the channel */
98d7281c 1387 if (!atomic_long_add_unless(&channel_file->f_count, 1, LONG_MAX)) {
0d2c717f 1388 ret = -EOVERFLOW;
9c1f4643
MD
1389 goto refcount_error;
1390 }
badfe9f5
MD
1391 ret = lttng_abi_validate_event_param(event_param);
1392 if (ret)
1393 goto event_error;
33a39a3c
MD
1394 if (event_param->instrumentation == LTTNG_KERNEL_TRACEPOINT
1395 || event_param->instrumentation == LTTNG_KERNEL_SYSCALL) {
b2bc0bc8 1396 struct lttng_event_enabler *event_enabler;
33a39a3c 1397
4993071a
PP
1398 if (strutils_is_star_glob_pattern(event_param->name)) {
1399 /*
1400 * If the event name is a star globbing pattern,
1401 * we create the special star globbing enabler.
1402 */
b2bc0bc8 1403 event_enabler = lttng_event_enabler_create(LTTNG_ENABLER_FORMAT_STAR_GLOB,
33a39a3c 1404 event_param, channel);
3c997079 1405 } else {
b2bc0bc8 1406 event_enabler = lttng_event_enabler_create(LTTNG_ENABLER_FORMAT_NAME,
33a39a3c 1407 event_param, channel);
1ec65de1 1408 }
b2bc0bc8 1409 priv = event_enabler;
33a39a3c
MD
1410 } else {
1411 struct lttng_event *event;
4ee2453d 1412
33a39a3c
MD
1413 /*
1414 * We tolerate no failure path after event creation. It
1415 * will stay invariant for the rest of the session.
1416 */
1417 event = lttng_event_create(channel, event_param,
1418 NULL, NULL,
1419 event_param->instrumentation);
1420 WARN_ON_ONCE(!event);
1421 if (IS_ERR(event)) {
1422 ret = PTR_ERR(event);
1423 goto event_error;
80f87dd2 1424 }
33a39a3c 1425 priv = event;
03037b98 1426 }
33a39a3c
MD
1427 event_file->private_data = priv;
1428 fd_install(event_fd, event_file);
653fe716
MD
1429 return event_fd;
1430
03037b98 1431event_error:
9c1f4643
MD
1432 atomic_long_dec(&channel_file->f_count);
1433refcount_error:
c0e31d2e 1434 fput(event_file);
653fe716
MD
1435file_error:
1436 put_unused_fd(event_fd);
1437fd_error:
653fe716
MD
1438 return ret;
1439}
ad1c05e1 1440
dffef45d
FD
1441static
1442long lttng_event_notifier_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
1443{
1444 struct lttng_event_notifier_enabler *event_notifier_enabler;
1445 enum lttng_event_type *evtype = file->private_data;
1446
1447 switch (cmd) {
1448 case LTTNG_KERNEL_ENABLE:
1449 switch (*evtype) {
1450 case LTTNG_TYPE_EVENT:
1451 return -EINVAL;
1452 case LTTNG_TYPE_ENABLER:
1453 event_notifier_enabler = file->private_data;
1454 return lttng_event_notifier_enabler_enable(event_notifier_enabler);
1455 default:
1456 WARN_ON_ONCE(1);
1457 return -ENOSYS;
1458 }
1459 case LTTNG_KERNEL_DISABLE:
1460 switch (*evtype) {
1461 case LTTNG_TYPE_EVENT:
1462 return -EINVAL;
1463 case LTTNG_TYPE_ENABLER:
1464 event_notifier_enabler = file->private_data;
1465 return lttng_event_notifier_enabler_disable(event_notifier_enabler);
1466 default:
1467 WARN_ON_ONCE(1);
1468 return -ENOSYS;
1469 }
1470 case LTTNG_KERNEL_FILTER:
1471 switch (*evtype) {
1472 case LTTNG_TYPE_EVENT:
1473 return -EINVAL;
1474 case LTTNG_TYPE_ENABLER:
1475 event_notifier_enabler = file->private_data;
1476 return lttng_event_notifier_enabler_attach_bytecode(event_notifier_enabler,
1477 (struct lttng_kernel_filter_bytecode __user *) arg);
1478 default:
1479 WARN_ON_ONCE(1);
1480 return -ENOSYS;
1481 }
1482 default:
1483 return -ENOIOCTLCMD;
1484 }
1485}
1486
1487static
1488int lttng_event_notifier_release(struct inode *inode, struct file *file)
1489{
1490 struct lttng_event_notifier *event_notifier;
1491 struct lttng_event_notifier_enabler *event_notifier_enabler;
1492 enum lttng_event_type *evtype = file->private_data;
1493
1494 if (!evtype)
1495 return 0;
1496
1497 switch (*evtype) {
1498 case LTTNG_TYPE_EVENT:
1499 event_notifier = file->private_data;
1500 if (event_notifier)
1501 fput(event_notifier->group->file);
1502 break;
1503 case LTTNG_TYPE_ENABLER:
1504 event_notifier_enabler = file->private_data;
1505 if (event_notifier_enabler)
1506 fput(event_notifier_enabler->group->file);
1507 break;
1508 default:
1509 WARN_ON_ONCE(1);
1510 break;
1511 }
1512
1513 return 0;
1514}
1515
1516static const struct file_operations lttng_event_notifier_fops = {
1517 .owner = THIS_MODULE,
1518 .release = lttng_event_notifier_release,
1519 .unlocked_ioctl = lttng_event_notifier_ioctl,
1520#ifdef CONFIG_COMPAT
1521 .compat_ioctl = lttng_event_notifier_ioctl,
1522#endif
1523};
1524
1525static
1526int lttng_abi_create_event_notifier(struct file *event_notifier_group_file,
1527 struct lttng_kernel_event_notifier *event_notifier_param)
1528{
1529 struct lttng_event_notifier_group *event_notifier_group =
1530 event_notifier_group_file->private_data;
1531 int event_notifier_fd, ret;
1532 struct file *event_notifier_file;
1533 void *priv;
1534
1535 switch (event_notifier_param->event.instrumentation) {
1536 case LTTNG_KERNEL_TRACEPOINT:
1537 case LTTNG_KERNEL_KPROBE:
1538 case LTTNG_KERNEL_UPROBE:
1539 case LTTNG_KERNEL_KRETPROBE:
1540 case LTTNG_KERNEL_FUNCTION:
1541 case LTTNG_KERNEL_NOOP:
1542 case LTTNG_KERNEL_SYSCALL:
1543 default:
1544 ret = -EINVAL;
1545 goto inval_instr;
1546 }
1547
1548 event_notifier_param->event.name[LTTNG_KERNEL_SYM_NAME_LEN - 1] = '\0';
1549
1550 event_notifier_fd = lttng_get_unused_fd();
1551 if (event_notifier_fd < 0) {
1552 ret = event_notifier_fd;
1553 goto fd_error;
1554 }
1555
1556 event_notifier_file = anon_inode_getfile("[lttng_event_notifier]",
1557 &lttng_event_notifier_fops,
1558 NULL, O_RDWR);
1559 if (IS_ERR(event_notifier_file)) {
1560 ret = PTR_ERR(event_notifier_file);
1561 goto file_error;
1562 }
1563
1564 /* The event notifier holds a reference on the event notifier group. */
1565 if (!atomic_long_add_unless(&event_notifier_group_file->f_count, 1, LONG_MAX)) {
1566 ret = -EOVERFLOW;
1567 goto refcount_error;
1568 }
1569
1570 if (event_notifier_param->event.instrumentation == LTTNG_KERNEL_TRACEPOINT
1571 || event_notifier_param->event.instrumentation == LTTNG_KERNEL_SYSCALL) {
1572 struct lttng_event_notifier_enabler *enabler;
1573
1574 if (strutils_is_star_glob_pattern(event_notifier_param->event.name)) {
1575 /*
1576 * If the event name is a star globbing pattern,
1577 * we create the special star globbing enabler.
1578 */
1579 enabler = lttng_event_notifier_enabler_create(
1580 event_notifier_group,
1581 LTTNG_ENABLER_FORMAT_STAR_GLOB,
1582 event_notifier_param);
1583 } else {
1584 enabler = lttng_event_notifier_enabler_create(
1585 event_notifier_group,
1586 LTTNG_ENABLER_FORMAT_NAME,
1587 event_notifier_param);
1588 }
1589 priv = enabler;
1590 } else {
1591 struct lttng_event_notifier *event_notifier;
1592
1593 /*
1594 * We tolerate no failure path after event notifier creation.
1595 * It will stay invariant for the rest of the session.
1596 */
1597 event_notifier = lttng_event_notifier_create(NULL,
1598 event_notifier_param->event.token, event_notifier_group,
1599 event_notifier_param, NULL,
1600 event_notifier_param->event.instrumentation);
1601 WARN_ON_ONCE(!event_notifier);
1602 if (IS_ERR(event_notifier)) {
1603 ret = PTR_ERR(event_notifier);
1604 goto event_notifier_error;
1605 }
1606 priv = event_notifier;
1607 }
1608 event_notifier_file->private_data = priv;
1609 fd_install(event_notifier_fd, event_notifier_file);
1610 return event_notifier_fd;
1611
1612event_notifier_error:
1613 atomic_long_dec(&event_notifier_group_file->f_count);
1614refcount_error:
1615 fput(event_notifier_file);
1616file_error:
1617 put_unused_fd(event_notifier_fd);
1618fd_error:
1619inval_instr:
1620 return ret;
1621}
1622
750b05f2
FD
1623static
1624long lttng_event_notifier_group_ioctl(struct file *file, unsigned int cmd,
1625 unsigned long arg)
1626{
1627 switch (cmd) {
dffef45d
FD
1628 case LTTNG_KERNEL_EVENT_NOTIFIER_CREATE:
1629 {
1630 struct lttng_kernel_event_notifier uevent_notifier_param;
1631
1632 if (copy_from_user(&uevent_notifier_param,
1633 (struct lttng_kernel_event_notifier __user *) arg,
1634 sizeof(uevent_notifier_param)))
1635 return -EFAULT;
1636 return lttng_abi_create_event_notifier(file, &uevent_notifier_param);
1637 }
750b05f2
FD
1638 default:
1639 return -ENOIOCTLCMD;
1640 }
1641 return 0;
1642}
1643
1644static
1645int lttng_event_notifier_group_release(struct inode *inode, struct file *file)
1646{
1647 struct lttng_event_notifier_group *event_notifier_group =
1648 file->private_data;
1649
1650 if (event_notifier_group)
1651 lttng_event_notifier_group_destroy(event_notifier_group);
1652 return 0;
1653}
1654
1655static const struct file_operations lttng_event_notifier_group_fops = {
1656 .owner = THIS_MODULE,
1657 .release = lttng_event_notifier_group_release,
1658 .unlocked_ioctl = lttng_event_notifier_group_ioctl,
1659#ifdef CONFIG_COMPAT
1660 .compat_ioctl = lttng_event_notifier_group_ioctl,
1661#endif
1662};
1663
ad1c05e1
MD
1664/**
1665 * lttng_channel_ioctl - lttng syscall through ioctl
1666 *
c0e31d2e 1667 * @file: the file
ad1c05e1
MD
1668 * @cmd: the command
1669 * @arg: command arg
1670 *
1671 * This ioctl implements lttng commands:
38d024ae 1672 * LTTNG_KERNEL_STREAM
ad1c05e1
MD
1673 * Returns an event stream file descriptor or failure.
1674 * (typically, one event stream records events from one CPU)
38d024ae 1675 * LTTNG_KERNEL_EVENT
ad1c05e1 1676 * Returns an event file descriptor or failure.
8070f5c0
MD
1677 * LTTNG_KERNEL_CONTEXT
1678 * Prepend a context field to each event in the channel
e64957da
MD
1679 * LTTNG_KERNEL_ENABLE
1680 * Enable recording for events in this channel (weak enable)
1681 * LTTNG_KERNEL_DISABLE
1682 * Disable recording for events in this channel (strong disable)
baf20995 1683 *
baf20995
MD
1684 * Channel and event file descriptors also hold a reference on the session.
1685 */
ad1c05e1 1686static
c0e31d2e 1687long lttng_channel_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
baf20995 1688{
a90917c3 1689 struct lttng_channel *channel = file->private_data;
8070f5c0 1690
baf20995 1691 switch (cmd) {
6dccd6c1 1692 case LTTNG_KERNEL_OLD_STREAM:
38d024ae 1693 case LTTNG_KERNEL_STREAM:
c0e31d2e 1694 return lttng_abi_open_stream(file);
6dccd6c1
JD
1695 case LTTNG_KERNEL_OLD_EVENT:
1696 {
1697 struct lttng_kernel_event *uevent_param;
1698 struct lttng_kernel_old_event *old_uevent_param;
1699 int ret;
1700
1701 uevent_param = kmalloc(sizeof(struct lttng_kernel_event),
1702 GFP_KERNEL);
1703 if (!uevent_param) {
1704 ret = -ENOMEM;
1705 goto old_event_end;
1706 }
1707 old_uevent_param = kmalloc(
1708 sizeof(struct lttng_kernel_old_event),
1709 GFP_KERNEL);
1710 if (!old_uevent_param) {
1711 ret = -ENOMEM;
1712 goto old_event_error_free_param;
1713 }
1714 if (copy_from_user(old_uevent_param,
1715 (struct lttng_kernel_old_event __user *) arg,
1716 sizeof(struct lttng_kernel_old_event))) {
1717 ret = -EFAULT;
1718 goto old_event_error_free_old_param;
1719 }
1720
1721 memcpy(uevent_param->name, old_uevent_param->name,
1722 sizeof(uevent_param->name));
1723 uevent_param->instrumentation =
1724 old_uevent_param->instrumentation;
1725
1726 switch (old_uevent_param->instrumentation) {
1727 case LTTNG_KERNEL_KPROBE:
1728 uevent_param->u.kprobe.addr =
1729 old_uevent_param->u.kprobe.addr;
1730 uevent_param->u.kprobe.offset =
1731 old_uevent_param->u.kprobe.offset;
1732 memcpy(uevent_param->u.kprobe.symbol_name,
1733 old_uevent_param->u.kprobe.symbol_name,
1734 sizeof(uevent_param->u.kprobe.symbol_name));
1735 break;
1736 case LTTNG_KERNEL_KRETPROBE:
1737 uevent_param->u.kretprobe.addr =
1738 old_uevent_param->u.kretprobe.addr;
1739 uevent_param->u.kretprobe.offset =
1740 old_uevent_param->u.kretprobe.offset;
1741 memcpy(uevent_param->u.kretprobe.symbol_name,
1742 old_uevent_param->u.kretprobe.symbol_name,
1743 sizeof(uevent_param->u.kretprobe.symbol_name));
1744 break;
1745 case LTTNG_KERNEL_FUNCTION:
e884017c
MD
1746 WARN_ON_ONCE(1);
1747 /* Not implemented. */
6dccd6c1
JD
1748 break;
1749 default:
1750 break;
1751 }
1752 ret = lttng_abi_create_event(file, uevent_param);
1753
1754old_event_error_free_old_param:
1755 kfree(old_uevent_param);
1756old_event_error_free_param:
1757 kfree(uevent_param);
1758old_event_end:
1759 return ret;
1760 }
38d024ae 1761 case LTTNG_KERNEL_EVENT:
6dccd6c1
JD
1762 {
1763 struct lttng_kernel_event uevent_param;
1764
1765 if (copy_from_user(&uevent_param,
1766 (struct lttng_kernel_event __user *) arg,
1767 sizeof(uevent_param)))
1768 return -EFAULT;
1769 return lttng_abi_create_event(file, &uevent_param);
1770 }
1771 case LTTNG_KERNEL_OLD_CONTEXT:
1772 {
1773 struct lttng_kernel_context *ucontext_param;
1774 struct lttng_kernel_old_context *old_ucontext_param;
1775 int ret;
1776
1777 ucontext_param = kmalloc(sizeof(struct lttng_kernel_context),
1778 GFP_KERNEL);
1779 if (!ucontext_param) {
1780 ret = -ENOMEM;
1781 goto old_ctx_end;
1782 }
1783 old_ucontext_param = kmalloc(sizeof(struct lttng_kernel_old_context),
1784 GFP_KERNEL);
1785 if (!old_ucontext_param) {
1786 ret = -ENOMEM;
1787 goto old_ctx_error_free_param;
1788 }
1789
1790 if (copy_from_user(old_ucontext_param,
1791 (struct lttng_kernel_old_context __user *) arg,
1792 sizeof(struct lttng_kernel_old_context))) {
1793 ret = -EFAULT;
1794 goto old_ctx_error_free_old_param;
1795 }
1796 ucontext_param->ctx = old_ucontext_param->ctx;
1797 memcpy(ucontext_param->padding, old_ucontext_param->padding,
1798 sizeof(ucontext_param->padding));
1799 /* only type that uses the union */
1800 if (old_ucontext_param->ctx == LTTNG_KERNEL_CONTEXT_PERF_COUNTER) {
1801 ucontext_param->u.perf_counter.type =
1802 old_ucontext_param->u.perf_counter.type;
1803 ucontext_param->u.perf_counter.config =
1804 old_ucontext_param->u.perf_counter.config;
1805 memcpy(ucontext_param->u.perf_counter.name,
1806 old_ucontext_param->u.perf_counter.name,
1807 sizeof(ucontext_param->u.perf_counter.name));
1808 }
1809
1810 ret = lttng_abi_add_context(file,
1811 ucontext_param,
1812 &channel->ctx, channel->session);
1813
1814old_ctx_error_free_old_param:
1815 kfree(old_ucontext_param);
1816old_ctx_error_free_param:
1817 kfree(ucontext_param);
1818old_ctx_end:
1819 return ret;
1820 }
8070f5c0 1821 case LTTNG_KERNEL_CONTEXT:
6dccd6c1
JD
1822 {
1823 struct lttng_kernel_context ucontext_param;
1824
1825 if (copy_from_user(&ucontext_param,
8070f5c0 1826 (struct lttng_kernel_context __user *) arg,
6dccd6c1
JD
1827 sizeof(ucontext_param)))
1828 return -EFAULT;
1829 return lttng_abi_add_context(file,
1830 &ucontext_param,
8070f5c0 1831 &channel->ctx, channel->session);
6dccd6c1
JD
1832 }
1833 case LTTNG_KERNEL_OLD_ENABLE:
e64957da 1834 case LTTNG_KERNEL_ENABLE:
a90917c3 1835 return lttng_channel_enable(channel);
6dccd6c1 1836 case LTTNG_KERNEL_OLD_DISABLE:
e64957da 1837 case LTTNG_KERNEL_DISABLE:
a90917c3 1838 return lttng_channel_disable(channel);
12e579db
MD
1839 case LTTNG_KERNEL_SYSCALL_MASK:
1840 return lttng_channel_syscall_mask(channel,
1841 (struct lttng_kernel_syscall_mask __user *) arg);
baf20995
MD
1842 default:
1843 return -ENOIOCTLCMD;
1844 }
1845}
1846
5dbbdb43
MD
1847/**
1848 * lttng_metadata_ioctl - lttng syscall through ioctl
1849 *
1850 * @file: the file
1851 * @cmd: the command
1852 * @arg: command arg
1853 *
1854 * This ioctl implements lttng commands:
38d024ae 1855 * LTTNG_KERNEL_STREAM
5dbbdb43
MD
1856 * Returns an event stream file descriptor or failure.
1857 *
1858 * Channel and event file descriptors also hold a reference on the session.
1859 */
1860static
1861long lttng_metadata_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
1862{
1863 switch (cmd) {
6dccd6c1 1864 case LTTNG_KERNEL_OLD_STREAM:
38d024ae 1865 case LTTNG_KERNEL_STREAM:
d83004aa 1866 return lttng_abi_open_metadata_stream(file);
5dbbdb43
MD
1867 default:
1868 return -ENOIOCTLCMD;
1869 }
1870}
1871
653fe716
MD
1872/**
1873 * lttng_channel_poll - lttng stream addition/removal monitoring
1874 *
c0e31d2e 1875 * @file: the file
653fe716
MD
1876 * @wait: poll table
1877 */
c0e31d2e 1878unsigned int lttng_channel_poll(struct file *file, poll_table *wait)
653fe716 1879{
a90917c3 1880 struct lttng_channel *channel = file->private_data;
653fe716
MD
1881 unsigned int mask = 0;
1882
c0e31d2e 1883 if (file->f_mode & FMODE_READ) {
a33e44a6 1884 poll_wait_set_exclusive(wait);
24cedcfe
MD
1885 poll_wait(file, channel->ops->get_hp_wait_queue(channel->chan),
1886 wait);
653fe716 1887
254ec7bc
MD
1888 if (channel->ops->is_disabled(channel->chan))
1889 return POLLERR;
24cedcfe 1890 if (channel->ops->is_finalized(channel->chan))
653fe716 1891 return POLLHUP;
f71ecafa 1892 if (channel->ops->buffer_has_read_closed_stream(channel->chan))
653fe716 1893 return POLLIN | POLLRDNORM;
f71ecafa 1894 return 0;
653fe716
MD
1895 }
1896 return mask;
1897
1898}
1899
0a84a57f
MD
1900static
1901int lttng_channel_release(struct inode *inode, struct file *file)
1902{
a90917c3 1903 struct lttng_channel *channel = file->private_data;
c269fff4
MD
1904
1905 if (channel)
1906 fput(channel->session->file);
0a84a57f
MD
1907 return 0;
1908}
1909
d83004aa
JD
1910static
1911int lttng_metadata_channel_release(struct inode *inode, struct file *file)
1912{
1913 struct lttng_channel *channel = file->private_data;
1914
1915 if (channel) {
d83004aa 1916 fput(channel->session->file);
a3381417 1917 lttng_metadata_channel_destroy(channel);
d83004aa
JD
1918 }
1919
1920 return 0;
1921}
1922
ad1c05e1 1923static const struct file_operations lttng_channel_fops = {
a33c9927 1924 .owner = THIS_MODULE,
03037b98 1925 .release = lttng_channel_release,
653fe716 1926 .poll = lttng_channel_poll,
ad1c05e1 1927 .unlocked_ioctl = lttng_channel_ioctl,
baf20995 1928#ifdef CONFIG_COMPAT
03037b98 1929 .compat_ioctl = lttng_channel_ioctl,
baf20995 1930#endif
11b5a3c2 1931};
baf20995 1932
5dbbdb43 1933static const struct file_operations lttng_metadata_fops = {
a33c9927 1934 .owner = THIS_MODULE,
d83004aa 1935 .release = lttng_metadata_channel_release,
5dbbdb43
MD
1936 .unlocked_ioctl = lttng_metadata_ioctl,
1937#ifdef CONFIG_COMPAT
1938 .compat_ioctl = lttng_metadata_ioctl,
1939#endif
1940};
1941
8070f5c0
MD
1942/**
1943 * lttng_event_ioctl - lttng syscall through ioctl
1944 *
1945 * @file: the file
1946 * @cmd: the command
1947 * @arg: command arg
1948 *
1949 * This ioctl implements lttng commands:
8070f5c0
MD
1950 * LTTNG_KERNEL_CONTEXT
1951 * Prepend a context field to each record of this event
e64957da
MD
1952 * LTTNG_KERNEL_ENABLE
1953 * Enable recording for this event (weak enable)
1954 * LTTNG_KERNEL_DISABLE
1955 * Disable recording for this event (strong disable)
8070f5c0
MD
1956 */
1957static
1958long lttng_event_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
1959{
3c997079 1960 struct lttng_event *event;
b2bc0bc8 1961 struct lttng_event_enabler *event_enabler;
3c997079 1962 enum lttng_event_type *evtype = file->private_data;
8070f5c0
MD
1963
1964 switch (cmd) {
6dccd6c1
JD
1965 case LTTNG_KERNEL_OLD_CONTEXT:
1966 {
3c997079
MD
1967 /* Not implemented */
1968 return -ENOSYS;
6dccd6c1 1969 }
8070f5c0 1970 case LTTNG_KERNEL_CONTEXT:
6dccd6c1 1971 {
3c997079
MD
1972 /* Not implemented */
1973 return -ENOSYS;
6dccd6c1
JD
1974 }
1975 case LTTNG_KERNEL_OLD_ENABLE:
e64957da 1976 case LTTNG_KERNEL_ENABLE:
3c997079
MD
1977 switch (*evtype) {
1978 case LTTNG_TYPE_EVENT:
1979 event = file->private_data;
1980 return lttng_event_enable(event);
1981 case LTTNG_TYPE_ENABLER:
b2bc0bc8
FD
1982 event_enabler = file->private_data;
1983 return lttng_event_enabler_enable(event_enabler);
3c997079
MD
1984 default:
1985 WARN_ON_ONCE(1);
1986 return -ENOSYS;
1987 }
6dccd6c1 1988 case LTTNG_KERNEL_OLD_DISABLE:
e64957da 1989 case LTTNG_KERNEL_DISABLE:
3c997079
MD
1990 switch (*evtype) {
1991 case LTTNG_TYPE_EVENT:
1992 event = file->private_data;
1993 return lttng_event_disable(event);
1994 case LTTNG_TYPE_ENABLER:
b2bc0bc8
FD
1995 event_enabler = file->private_data;
1996 return lttng_event_enabler_disable(event_enabler);
3c997079
MD
1997 default:
1998 WARN_ON_ONCE(1);
1999 return -ENOSYS;
2000 }
07dfc1d0
MD
2001 case LTTNG_KERNEL_FILTER:
2002 switch (*evtype) {
2003 case LTTNG_TYPE_EVENT:
2004 return -EINVAL;
2005 case LTTNG_TYPE_ENABLER:
2006 {
b2bc0bc8
FD
2007 event_enabler = file->private_data;
2008 return lttng_event_enabler_attach_bytecode(event_enabler,
07dfc1d0
MD
2009 (struct lttng_kernel_filter_bytecode __user *) arg);
2010 }
0586316f
MD
2011 default:
2012 WARN_ON_ONCE(1);
2013 return -ENOSYS;
07dfc1d0 2014 }
3aed4dca
FD
2015 case LTTNG_KERNEL_ADD_CALLSITE:
2016 switch (*evtype) {
2017 case LTTNG_TYPE_EVENT:
2018 event = file->private_data;
2019 return lttng_event_add_callsite(event,
2020 (struct lttng_kernel_event_callsite __user *) arg);
2021 case LTTNG_TYPE_ENABLER:
2022 return -EINVAL;
64c147c0
MD
2023 default:
2024 WARN_ON_ONCE(1);
2025 return -ENOSYS;
3aed4dca 2026 }
8070f5c0
MD
2027 default:
2028 return -ENOIOCTLCMD;
2029 }
2030}
2031
0a84a57f
MD
2032static
2033int lttng_event_release(struct inode *inode, struct file *file)
2034{
3c997079 2035 struct lttng_event *event;
b2bc0bc8 2036 struct lttng_event_enabler *event_enabler;
3c997079
MD
2037 enum lttng_event_type *evtype = file->private_data;
2038
2039 if (!evtype)
2040 return 0;
2041
2042 switch (*evtype) {
2043 case LTTNG_TYPE_EVENT:
2044 event = file->private_data;
2045 if (event)
2046 fput(event->chan->file);
2047 break;
2048 case LTTNG_TYPE_ENABLER:
b2bc0bc8
FD
2049 event_enabler = file->private_data;
2050 if (event_enabler)
2051 fput(event_enabler->chan->file);
3c997079
MD
2052 break;
2053 default:
2054 WARN_ON_ONCE(1);
2055 break;
2056 }
c269fff4 2057
0a84a57f
MD
2058 return 0;
2059}
2060
3b923e5b 2061/* TODO: filter control ioctl */
0a84a57f 2062static const struct file_operations lttng_event_fops = {
a33c9927 2063 .owner = THIS_MODULE,
0a84a57f 2064 .release = lttng_event_release,
8070f5c0
MD
2065 .unlocked_ioctl = lttng_event_ioctl,
2066#ifdef CONFIG_COMPAT
2067 .compat_ioctl = lttng_event_ioctl,
2068#endif
11b5a3c2 2069};
0a84a57f 2070
3b731ab1
JD
2071static int put_u64(uint64_t val, unsigned long arg)
2072{
2073 return put_user(val, (uint64_t __user *) arg);
2074}
2075
8b97fd42
MD
2076static int put_u32(uint32_t val, unsigned long arg)
2077{
2078 return put_user(val, (uint32_t __user *) arg);
2079}
2080
ed8d02d6
JD
2081static long lttng_stream_ring_buffer_ioctl(struct file *filp,
2082 unsigned int cmd, unsigned long arg)
2083{
3b731ab1
JD
2084 struct lib_ring_buffer *buf = filp->private_data;
2085 struct channel *chan = buf->backend.chan;
2086 const struct lib_ring_buffer_config *config = &chan->backend.config;
dd5a0db3 2087 const struct lttng_channel_ops *ops = chan->backend.priv_ops;
3b731ab1
JD
2088 int ret;
2089
2090 if (atomic_read(&chan->record_disabled))
2091 return -EIO;
2092
ed8d02d6 2093 switch (cmd) {
3b731ab1
JD
2094 case LTTNG_RING_BUFFER_GET_TIMESTAMP_BEGIN:
2095 {
2096 uint64_t ts;
2097
dd5a0db3 2098 ret = ops->timestamp_begin(config, buf, &ts);
3b731ab1
JD
2099 if (ret < 0)
2100 goto error;
2101 return put_u64(ts, arg);
2102 }
2103 case LTTNG_RING_BUFFER_GET_TIMESTAMP_END:
2104 {
2105 uint64_t ts;
2106
dd5a0db3 2107 ret = ops->timestamp_end(config, buf, &ts);
3b731ab1
JD
2108 if (ret < 0)
2109 goto error;
2110 return put_u64(ts, arg);
2111 }
2112 case LTTNG_RING_BUFFER_GET_EVENTS_DISCARDED:
2113 {
2114 uint64_t ed;
2115
dd5a0db3 2116 ret = ops->events_discarded(config, buf, &ed);
3b731ab1
JD
2117 if (ret < 0)
2118 goto error;
2119 return put_u64(ed, arg);
2120 }
2121 case LTTNG_RING_BUFFER_GET_CONTENT_SIZE:
2122 {
2123 uint64_t cs;
2124
dd5a0db3 2125 ret = ops->content_size(config, buf, &cs);
3b731ab1
JD
2126 if (ret < 0)
2127 goto error;
2128 return put_u64(cs, arg);
2129 }
2130 case LTTNG_RING_BUFFER_GET_PACKET_SIZE:
2131 {
2132 uint64_t ps;
2133
dd5a0db3 2134 ret = ops->packet_size(config, buf, &ps);
3b731ab1
JD
2135 if (ret < 0)
2136 goto error;
2137 return put_u64(ps, arg);
2138 }
2139 case LTTNG_RING_BUFFER_GET_STREAM_ID:
2140 {
2141 uint64_t si;
2142
dd5a0db3 2143 ret = ops->stream_id(config, buf, &si);
3b731ab1
JD
2144 if (ret < 0)
2145 goto error;
2146 return put_u64(si, arg);
2147 }
2348ca17
JD
2148 case LTTNG_RING_BUFFER_GET_CURRENT_TIMESTAMP:
2149 {
2150 uint64_t ts;
2151
dd5a0db3 2152 ret = ops->current_timestamp(config, buf, &ts);
2348ca17
JD
2153 if (ret < 0)
2154 goto error;
2155 return put_u64(ts, arg);
2156 }
5b3cf4f9
JD
2157 case LTTNG_RING_BUFFER_GET_SEQ_NUM:
2158 {
2159 uint64_t seq;
2160
2161 ret = ops->sequence_number(config, buf, &seq);
2162 if (ret < 0)
2163 goto error;
2164 return put_u64(seq, arg);
2165 }
5594698f
JD
2166 case LTTNG_RING_BUFFER_INSTANCE_ID:
2167 {
2168 uint64_t id;
2169
2170 ret = ops->instance_id(config, buf, &id);
2171 if (ret < 0)
2172 goto error;
2173 return put_u64(id, arg);
2174 }
3b731ab1
JD
2175 default:
2176 return lib_ring_buffer_file_operations.unlocked_ioctl(filp,
2177 cmd, arg);
ed8d02d6 2178 }
3b731ab1
JD
2179
2180error:
2181 return -ENOSYS;
ed8d02d6
JD
2182}
2183
2184#ifdef CONFIG_COMPAT
2185static long lttng_stream_ring_buffer_compat_ioctl(struct file *filp,
2186 unsigned int cmd, unsigned long arg)
2187{
3b731ab1
JD
2188 struct lib_ring_buffer *buf = filp->private_data;
2189 struct channel *chan = buf->backend.chan;
2190 const struct lib_ring_buffer_config *config = &chan->backend.config;
dd5a0db3 2191 const struct lttng_channel_ops *ops = chan->backend.priv_ops;
3b731ab1
JD
2192 int ret;
2193
2194 if (atomic_read(&chan->record_disabled))
2195 return -EIO;
2196
ed8d02d6 2197 switch (cmd) {
3b731ab1
JD
2198 case LTTNG_RING_BUFFER_COMPAT_GET_TIMESTAMP_BEGIN:
2199 {
2200 uint64_t ts;
2201
dd5a0db3 2202 ret = ops->timestamp_begin(config, buf, &ts);
3b731ab1
JD
2203 if (ret < 0)
2204 goto error;
2205 return put_u64(ts, arg);
2206 }
2207 case LTTNG_RING_BUFFER_COMPAT_GET_TIMESTAMP_END:
2208 {
2209 uint64_t ts;
2210
dd5a0db3 2211 ret = ops->timestamp_end(config, buf, &ts);
3b731ab1
JD
2212 if (ret < 0)
2213 goto error;
2214 return put_u64(ts, arg);
2215 }
2216 case LTTNG_RING_BUFFER_COMPAT_GET_EVENTS_DISCARDED:
2217 {
2218 uint64_t ed;
2219
dd5a0db3 2220 ret = ops->events_discarded(config, buf, &ed);
3b731ab1
JD
2221 if (ret < 0)
2222 goto error;
2223 return put_u64(ed, arg);
ed8d02d6 2224 }
3b731ab1
JD
2225 case LTTNG_RING_BUFFER_COMPAT_GET_CONTENT_SIZE:
2226 {
2227 uint64_t cs;
2228
dd5a0db3 2229 ret = ops->content_size(config, buf, &cs);
3b731ab1
JD
2230 if (ret < 0)
2231 goto error;
2232 return put_u64(cs, arg);
2233 }
2234 case LTTNG_RING_BUFFER_COMPAT_GET_PACKET_SIZE:
2235 {
2236 uint64_t ps;
2237
dd5a0db3 2238 ret = ops->packet_size(config, buf, &ps);
3b731ab1
JD
2239 if (ret < 0)
2240 goto error;
2241 return put_u64(ps, arg);
2242 }
2243 case LTTNG_RING_BUFFER_COMPAT_GET_STREAM_ID:
2244 {
2245 uint64_t si;
2246
dd5a0db3 2247 ret = ops->stream_id(config, buf, &si);
3b731ab1
JD
2248 if (ret < 0)
2249 goto error;
2250 return put_u64(si, arg);
2251 }
2348ca17
JD
2252 case LTTNG_RING_BUFFER_GET_CURRENT_TIMESTAMP:
2253 {
2254 uint64_t ts;
2255
dd5a0db3 2256 ret = ops->current_timestamp(config, buf, &ts);
2348ca17
JD
2257 if (ret < 0)
2258 goto error;
2259 return put_u64(ts, arg);
2260 }
5b3cf4f9
JD
2261 case LTTNG_RING_BUFFER_COMPAT_GET_SEQ_NUM:
2262 {
2263 uint64_t seq;
2264
2265 ret = ops->sequence_number(config, buf, &seq);
2266 if (ret < 0)
2267 goto error;
2268 return put_u64(seq, arg);
2269 }
5594698f
JD
2270 case LTTNG_RING_BUFFER_COMPAT_INSTANCE_ID:
2271 {
2272 uint64_t id;
2273
2274 ret = ops->instance_id(config, buf, &id);
2275 if (ret < 0)
2276 goto error;
2277 return put_u64(id, arg);
2278 }
3b731ab1
JD
2279 default:
2280 return lib_ring_buffer_file_operations.compat_ioctl(filp,
2281 cmd, arg);
2282 }
2283
2284error:
2285 return -ENOSYS;
ed8d02d6
JD
2286}
2287#endif /* CONFIG_COMPAT */
2288
2289static void lttng_stream_override_ring_buffer_fops(void)
2290{
2291 lttng_stream_ring_buffer_file_operations.owner = THIS_MODULE;
2292 lttng_stream_ring_buffer_file_operations.open =
2293 lib_ring_buffer_file_operations.open;
2294 lttng_stream_ring_buffer_file_operations.release =
2295 lib_ring_buffer_file_operations.release;
2296 lttng_stream_ring_buffer_file_operations.poll =
2297 lib_ring_buffer_file_operations.poll;
2298 lttng_stream_ring_buffer_file_operations.splice_read =
2299 lib_ring_buffer_file_operations.splice_read;
2300 lttng_stream_ring_buffer_file_operations.mmap =
2301 lib_ring_buffer_file_operations.mmap;
2302 lttng_stream_ring_buffer_file_operations.unlocked_ioctl =
2303 lttng_stream_ring_buffer_ioctl;
2304 lttng_stream_ring_buffer_file_operations.llseek =
2305 lib_ring_buffer_file_operations.llseek;
2306#ifdef CONFIG_COMPAT
2307 lttng_stream_ring_buffer_file_operations.compat_ioctl =
2308 lttng_stream_ring_buffer_compat_ioctl;
2309#endif
2310}
2311
80996790 2312int __init lttng_abi_init(void)
baf20995
MD
2313{
2314 int ret = 0;
2315
263b6c88 2316 wrapper_vmalloc_sync_mappings();
2754583e 2317 lttng_clock_ref();
f771eda6
JD
2318
2319 ret = lttng_tp_mempool_init();
2320 if (ret) {
2321 goto error;
2322 }
2323
d29348f7 2324 lttng_proc_dentry = proc_create_data("lttng", S_IRUSR | S_IWUSR, NULL,
059de147 2325 &lttng_proc_ops, NULL);
2470a237 2326
255e52a4 2327 if (!lttng_proc_dentry) {
5a15f70c 2328 printk(KERN_ERR "LTTng: Error creating control file\n");
baf20995
MD
2329 ret = -ENOMEM;
2330 goto error;
2331 }
ed8d02d6 2332 lttng_stream_override_ring_buffer_fops();
2754583e 2333 return 0;
ed8d02d6 2334
baf20995 2335error:
f771eda6 2336 lttng_tp_mempool_destroy();
2754583e 2337 lttng_clock_unref();
baf20995
MD
2338 return ret;
2339}
2340
e6e65fcd
MD
2341/* No __exit annotation because used by init error path too. */
2342void lttng_abi_exit(void)
baf20995 2343{
f771eda6 2344 lttng_tp_mempool_destroy();
2754583e 2345 lttng_clock_unref();
e6a17f26
MD
2346 if (lttng_proc_dentry)
2347 remove_proc_entry("lttng", NULL);
baf20995 2348}
This page took 0.181297 seconds and 4 git commands to generate.