Fix: update sched prev_state instrumentation for upstream kernel
[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
1c88f269
JR
473static
474int lttng_abi_session_set_creation_time(struct lttng_session *session,
475 struct lttng_kernel_session_creation_time *time)
476{
477 size_t len;
478
479 len = strnlen(time->iso8601, LTTNG_KERNEL_SESSION_CREATION_TIME_ISO8601_LEN);
480
481 if (len == LTTNG_KERNEL_SESSION_CREATION_TIME_ISO8601_LEN) {
482 /* Time is too long/malformed */
483 return -EINVAL;
484 }
485
486 strcpy(session->creation_time, time->iso8601);
487 return 0;
488}
489
baf20995 490/**
ad1c05e1 491 * lttng_session_ioctl - lttng session fd ioctl
baf20995 492 *
c0e31d2e 493 * @file: the file
baf20995
MD
494 * @cmd: the command
495 * @arg: command arg
496 *
497 * This ioctl implements lttng commands:
38d024ae 498 * LTTNG_KERNEL_CHANNEL
baf20995 499 * Returns a LTTng channel file descriptor
e64957da
MD
500 * LTTNG_KERNEL_ENABLE
501 * Enables tracing for a session (weak enable)
502 * LTTNG_KERNEL_DISABLE
503 * Disables tracing for a session (strong disable)
8070f5c0
MD
504 * LTTNG_KERNEL_METADATA
505 * Returns a LTTng metadata file descriptor
e0130fab
MD
506 * LTTNG_KERNEL_SESSION_TRACK_PID
507 * Add PID to session tracker
508 * LTTNG_KERNEL_SESSION_UNTRACK_PID
509 * Remove PID from session tracker
ad1c05e1
MD
510 *
511 * The returned channel will be deleted when its file descriptor is closed.
512 */
513static
c0e31d2e 514long lttng_session_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
ad1c05e1 515{
a90917c3 516 struct lttng_session *session = file->private_data;
2d4c4d15
MD
517 struct lttng_kernel_channel chan_param;
518 struct lttng_kernel_old_channel old_chan_param;
c0e31d2e 519
ad1c05e1 520 switch (cmd) {
6dccd6c1
JD
521 case LTTNG_KERNEL_OLD_CHANNEL:
522 {
6dccd6c1
JD
523 if (copy_from_user(&old_chan_param,
524 (struct lttng_kernel_old_channel __user *) arg,
525 sizeof(struct lttng_kernel_old_channel)))
526 return -EFAULT;
527 chan_param.overwrite = old_chan_param.overwrite;
528 chan_param.subbuf_size = old_chan_param.subbuf_size;
529 chan_param.num_subbuf = old_chan_param.num_subbuf;
530 chan_param.switch_timer_interval = old_chan_param.switch_timer_interval;
531 chan_param.read_timer_interval = old_chan_param.read_timer_interval;
532 chan_param.output = old_chan_param.output;
533
534 return lttng_abi_create_channel(file, &chan_param,
535 PER_CPU_CHANNEL);
536 }
38d024ae 537 case LTTNG_KERNEL_CHANNEL:
6dccd6c1 538 {
6dccd6c1 539 if (copy_from_user(&chan_param,
38d024ae 540 (struct lttng_kernel_channel __user *) arg,
6dccd6c1
JD
541 sizeof(struct lttng_kernel_channel)))
542 return -EFAULT;
543 return lttng_abi_create_channel(file, &chan_param,
5dbbdb43 544 PER_CPU_CHANNEL);
6dccd6c1
JD
545 }
546 case LTTNG_KERNEL_OLD_SESSION_START:
547 case LTTNG_KERNEL_OLD_ENABLE:
38d024ae 548 case LTTNG_KERNEL_SESSION_START:
e64957da 549 case LTTNG_KERNEL_ENABLE:
a90917c3 550 return lttng_session_enable(session);
6dccd6c1
JD
551 case LTTNG_KERNEL_OLD_SESSION_STOP:
552 case LTTNG_KERNEL_OLD_DISABLE:
38d024ae 553 case LTTNG_KERNEL_SESSION_STOP:
e64957da 554 case LTTNG_KERNEL_DISABLE:
a90917c3 555 return lttng_session_disable(session);
6dccd6c1
JD
556 case LTTNG_KERNEL_OLD_METADATA:
557 {
6dccd6c1
JD
558 if (copy_from_user(&old_chan_param,
559 (struct lttng_kernel_old_channel __user *) arg,
560 sizeof(struct lttng_kernel_old_channel)))
561 return -EFAULT;
562 chan_param.overwrite = old_chan_param.overwrite;
563 chan_param.subbuf_size = old_chan_param.subbuf_size;
564 chan_param.num_subbuf = old_chan_param.num_subbuf;
565 chan_param.switch_timer_interval = old_chan_param.switch_timer_interval;
566 chan_param.read_timer_interval = old_chan_param.read_timer_interval;
567 chan_param.output = old_chan_param.output;
568
569 return lttng_abi_create_channel(file, &chan_param,
570 METADATA_CHANNEL);
571 }
38d024ae 572 case LTTNG_KERNEL_METADATA:
6dccd6c1 573 {
6dccd6c1
JD
574 if (copy_from_user(&chan_param,
575 (struct lttng_kernel_channel __user *) arg,
576 sizeof(struct lttng_kernel_channel)))
577 return -EFAULT;
578 return lttng_abi_create_channel(file, &chan_param,
5dbbdb43 579 METADATA_CHANNEL);
6dccd6c1 580 }
e0130fab
MD
581 case LTTNG_KERNEL_SESSION_TRACK_PID:
582 return lttng_session_track_pid(session, (int) arg);
583 case LTTNG_KERNEL_SESSION_UNTRACK_PID:
584 return lttng_session_untrack_pid(session, (int) arg);
7e6f9ef6
MD
585 case LTTNG_KERNEL_SESSION_LIST_TRACKER_PIDS:
586 return lttng_session_list_tracker_pids(session);
9616f0bf
JD
587 case LTTNG_KERNEL_SESSION_METADATA_REGEN:
588 return lttng_session_metadata_regenerate(session);
601252cf
MD
589 case LTTNG_KERNEL_SESSION_STATEDUMP:
590 return lttng_session_statedump(session);
7f859fbf
JR
591 case LTTNG_KERNEL_SESSION_SET_NAME:
592 {
593 struct lttng_kernel_session_name name;
594
595 if (copy_from_user(&name,
596 (struct lttng_kernel_session_name __user *) arg,
597 sizeof(struct lttng_kernel_session_name)))
598 return -EFAULT;
599 return lttng_abi_session_set_name(session, &name);
600 }
1c88f269
JR
601 case LTTNG_KERNEL_SESSION_SET_CREATION_TIME:
602 {
603 struct lttng_kernel_session_creation_time time;
604
605 if (copy_from_user(&time,
606 (struct lttng_kernel_session_creation_time __user *) arg,
607 sizeof(struct lttng_kernel_session_creation_time)))
608 return -EFAULT;
609 return lttng_abi_session_set_creation_time(session, &time);
610 }
ad1c05e1
MD
611 default:
612 return -ENOIOCTLCMD;
613 }
614}
615
03037b98
MD
616/*
617 * Called when the last file reference is dropped.
618 *
619 * Big fat note: channels and events are invariant for the whole session after
620 * their creation. So this session destruction also destroys all channel and
621 * event structures specific to this session (they are not destroyed when their
622 * individual file is released).
623 */
ad1c05e1 624static
03037b98 625int lttng_session_release(struct inode *inode, struct file *file)
ad1c05e1 626{
a90917c3 627 struct lttng_session *session = file->private_data;
c269fff4
MD
628
629 if (session)
a90917c3 630 lttng_session_destroy(session);
11b5a3c2 631 return 0;
ad1c05e1 632}
ad1c05e1
MD
633
634static const struct file_operations lttng_session_fops = {
a33c9927 635 .owner = THIS_MODULE,
03037b98 636 .release = lttng_session_release,
ad1c05e1
MD
637 .unlocked_ioctl = lttng_session_ioctl,
638#ifdef CONFIG_COMPAT
03037b98 639 .compat_ioctl = lttng_session_ioctl,
ad1c05e1 640#endif
11b5a3c2 641};
ad1c05e1 642
d83004aa
JD
643/**
644 * lttng_metadata_ring_buffer_poll - LTTng ring buffer poll file operation
645 * @filp: the file
646 * @wait: poll table
647 *
648 * Handles the poll operations for the metadata channels.
649 */
ad1c05e1 650static
d83004aa
JD
651unsigned int lttng_metadata_ring_buffer_poll(struct file *filp,
652 poll_table *wait)
653{
654 struct lttng_metadata_stream *stream = filp->private_data;
655 struct lib_ring_buffer *buf = stream->priv;
656 int finalized;
657 unsigned int mask = 0;
658
659 if (filp->f_mode & FMODE_READ) {
660 poll_wait_set_exclusive(wait);
661 poll_wait(filp, &stream->read_wait, wait);
662
663 finalized = stream->finalized;
664
665 /*
666 * lib_ring_buffer_is_finalized() contains a smp_rmb()
667 * ordering finalized load before offsets loads.
668 */
669 WARN_ON(atomic_long_read(&buf->active_readers) != 1);
670
671 if (finalized)
672 mask |= POLLHUP;
673
92d9f5e6 674 mutex_lock(&stream->metadata_cache->lock);
d83004aa 675 if (stream->metadata_cache->metadata_written >
f613e3e6 676 stream->metadata_out)
d83004aa 677 mask |= POLLIN;
92d9f5e6 678 mutex_unlock(&stream->metadata_cache->lock);
d83004aa
JD
679 }
680
681 return mask;
682}
683
f613e3e6
MD
684static
685void lttng_metadata_ring_buffer_ioctl_put_next_subbuf(struct file *filp,
686 unsigned int cmd, unsigned long arg)
687{
688 struct lttng_metadata_stream *stream = filp->private_data;
689
690 stream->metadata_out = stream->metadata_in;
691}
692
d1344afa
JD
693/*
694 * Reset the counter of how much metadata has been consumed to 0. That way,
695 * the consumer receives the content of the metadata cache unchanged. This is
696 * different from the metadata_regenerate where the offset from epoch is
697 * resampled, here we want the exact same content as the last time the metadata
698 * was generated. This command is only possible if all the metadata written
699 * in the cache has been output to the metadata stream to avoid corrupting the
700 * metadata file.
701 *
702 * Return 0 on success, a negative value on error.
703 */
704static
705int lttng_metadata_cache_dump(struct lttng_metadata_stream *stream)
706{
707 int ret;
708 struct lttng_metadata_cache *cache = stream->metadata_cache;
709
710 mutex_lock(&cache->lock);
711 if (stream->metadata_out != cache->metadata_written) {
712 ret = -EBUSY;
713 goto end;
714 }
715 stream->metadata_out = 0;
716 stream->metadata_in = 0;
717 wake_up_interruptible(&stream->read_wait);
718 ret = 0;
719
720end:
721 mutex_unlock(&cache->lock);
722 return ret;
723}
724
d83004aa
JD
725static
726long lttng_metadata_ring_buffer_ioctl(struct file *filp,
727 unsigned int cmd, unsigned long arg)
728{
729 int ret;
730 struct lttng_metadata_stream *stream = filp->private_data;
731 struct lib_ring_buffer *buf = stream->priv;
732
733 switch (cmd) {
d83004aa
JD
734 case RING_BUFFER_GET_NEXT_SUBBUF:
735 {
35097f36
JD
736 struct lttng_metadata_stream *stream = filp->private_data;
737 struct lib_ring_buffer *buf = stream->priv;
738 struct channel *chan = buf->backend.chan;
739
740 ret = lttng_metadata_output_channel(stream, chan);
741 if (ret > 0) {
742 lib_ring_buffer_switch_slow(buf, SWITCH_ACTIVE);
743 ret = 0;
744 } else if (ret < 0)
d83004aa
JD
745 goto err;
746 break;
747 }
f613e3e6
MD
748 case RING_BUFFER_GET_SUBBUF:
749 {
750 /*
751 * Random access is not allowed for metadata channel.
752 */
753 return -ENOSYS;
754 }
c6f05468 755 case RING_BUFFER_FLUSH_EMPTY: /* Fall-through. */
35097f36
JD
756 case RING_BUFFER_FLUSH:
757 {
758 struct lttng_metadata_stream *stream = filp->private_data;
759 struct lib_ring_buffer *buf = stream->priv;
760 struct channel *chan = buf->backend.chan;
761
762 /*
763 * Before doing the actual ring buffer flush, write up to one
764 * packet of metadata in the ring buffer.
765 */
766 ret = lttng_metadata_output_channel(stream, chan);
767 if (ret < 0)
768 goto err;
769 break;
770 }
9616f0bf
JD
771 case RING_BUFFER_GET_METADATA_VERSION:
772 {
773 struct lttng_metadata_stream *stream = filp->private_data;
774
775 return put_u64(stream->version, arg);
776 }
d1344afa
JD
777 case RING_BUFFER_METADATA_CACHE_DUMP:
778 {
779 struct lttng_metadata_stream *stream = filp->private_data;
780
781 return lttng_metadata_cache_dump(stream);
782 }
d83004aa
JD
783 default:
784 break;
785 }
f613e3e6
MD
786 /* PUT_SUBBUF is the one from lib ring buffer, unmodified. */
787
d83004aa 788 /* Performing lib ring buffer ioctl after our own. */
f613e3e6
MD
789 ret = lib_ring_buffer_ioctl(filp, cmd, arg, buf);
790 if (ret < 0)
791 goto err;
d83004aa 792
f613e3e6
MD
793 switch (cmd) {
794 case RING_BUFFER_PUT_NEXT_SUBBUF:
795 {
796 lttng_metadata_ring_buffer_ioctl_put_next_subbuf(filp,
797 cmd, arg);
798 break;
799 }
800 default:
801 break;
802 }
d83004aa
JD
803err:
804 return ret;
805}
806
aeb9064d 807#ifdef CONFIG_COMPAT
d83004aa
JD
808static
809long lttng_metadata_ring_buffer_compat_ioctl(struct file *filp,
810 unsigned int cmd, unsigned long arg)
811{
812 int ret;
813 struct lttng_metadata_stream *stream = filp->private_data;
814 struct lib_ring_buffer *buf = stream->priv;
815
816 switch (cmd) {
d83004aa
JD
817 case RING_BUFFER_GET_NEXT_SUBBUF:
818 {
35097f36
JD
819 struct lttng_metadata_stream *stream = filp->private_data;
820 struct lib_ring_buffer *buf = stream->priv;
821 struct channel *chan = buf->backend.chan;
822
823 ret = lttng_metadata_output_channel(stream, chan);
824 if (ret > 0) {
825 lib_ring_buffer_switch_slow(buf, SWITCH_ACTIVE);
826 ret = 0;
827 } else if (ret < 0)
d83004aa
JD
828 goto err;
829 break;
830 }
f613e3e6
MD
831 case RING_BUFFER_GET_SUBBUF:
832 {
833 /*
834 * Random access is not allowed for metadata channel.
835 */
836 return -ENOSYS;
837 }
c6f05468 838 case RING_BUFFER_FLUSH_EMPTY: /* Fall-through. */
96c55c2f
MD
839 case RING_BUFFER_FLUSH:
840 {
841 struct lttng_metadata_stream *stream = filp->private_data;
842 struct lib_ring_buffer *buf = stream->priv;
843 struct channel *chan = buf->backend.chan;
844
845 /*
846 * Before doing the actual ring buffer flush, write up to one
847 * packet of metadata in the ring buffer.
848 */
849 ret = lttng_metadata_output_channel(stream, chan);
850 if (ret < 0)
851 goto err;
852 break;
853 }
854 case RING_BUFFER_GET_METADATA_VERSION:
855 {
856 struct lttng_metadata_stream *stream = filp->private_data;
857
858 return put_u64(stream->version, arg);
859 }
d1344afa
JD
860 case RING_BUFFER_METADATA_CACHE_DUMP:
861 {
862 struct lttng_metadata_stream *stream = filp->private_data;
863
864 return lttng_metadata_cache_dump(stream);
865 }
d83004aa
JD
866 default:
867 break;
868 }
f613e3e6
MD
869 /* PUT_SUBBUF is the one from lib ring buffer, unmodified. */
870
d83004aa 871 /* Performing lib ring buffer ioctl after our own. */
f613e3e6
MD
872 ret = lib_ring_buffer_compat_ioctl(filp, cmd, arg, buf);
873 if (ret < 0)
874 goto err;
d83004aa 875
f613e3e6
MD
876 switch (cmd) {
877 case RING_BUFFER_PUT_NEXT_SUBBUF:
878 {
879 lttng_metadata_ring_buffer_ioctl_put_next_subbuf(filp,
880 cmd, arg);
881 break;
882 }
883 default:
884 break;
885 }
d83004aa
JD
886err:
887 return ret;
888}
aeb9064d 889#endif
d83004aa 890
b3b8072b
MD
891/*
892 * This is not used by anonymous file descriptors. This code is left
893 * there if we ever want to implement an inode with open() operation.
894 */
d83004aa
JD
895static
896int lttng_metadata_ring_buffer_open(struct inode *inode, struct file *file)
897{
898 struct lttng_metadata_stream *stream = inode->i_private;
899 struct lib_ring_buffer *buf = stream->priv;
900
901 file->private_data = buf;
b3b8072b
MD
902 /*
903 * Since life-time of metadata cache differs from that of
904 * session, we need to keep our own reference on the transport.
905 */
906 if (!try_module_get(stream->transport->owner)) {
907 printk(KERN_WARNING "LTT : Can't lock transport module.\n");
908 return -EBUSY;
909 }
d83004aa
JD
910 return lib_ring_buffer_open(inode, file, buf);
911}
912
913static
914int lttng_metadata_ring_buffer_release(struct inode *inode, struct file *file)
915{
916 struct lttng_metadata_stream *stream = file->private_data;
917 struct lib_ring_buffer *buf = stream->priv;
918
919 kref_put(&stream->metadata_cache->refcount, metadata_cache_destroy);
b3b8072b 920 module_put(stream->transport->owner);
d83004aa
JD
921 return lib_ring_buffer_release(inode, file, buf);
922}
923
924static
925ssize_t lttng_metadata_ring_buffer_splice_read(struct file *in, loff_t *ppos,
926 struct pipe_inode_info *pipe, size_t len,
927 unsigned int flags)
928{
929 struct lttng_metadata_stream *stream = in->private_data;
930 struct lib_ring_buffer *buf = stream->priv;
931
932 return lib_ring_buffer_splice_read(in, ppos, pipe, len,
933 flags, buf);
934}
935
936static
937int lttng_metadata_ring_buffer_mmap(struct file *filp,
938 struct vm_area_struct *vma)
939{
940 struct lttng_metadata_stream *stream = filp->private_data;
941 struct lib_ring_buffer *buf = stream->priv;
942
943 return lib_ring_buffer_mmap(filp, vma, buf);
944}
945
946static
947const struct file_operations lttng_metadata_ring_buffer_file_operations = {
948 .owner = THIS_MODULE,
949 .open = lttng_metadata_ring_buffer_open,
950 .release = lttng_metadata_ring_buffer_release,
951 .poll = lttng_metadata_ring_buffer_poll,
952 .splice_read = lttng_metadata_ring_buffer_splice_read,
953 .mmap = lttng_metadata_ring_buffer_mmap,
954 .unlocked_ioctl = lttng_metadata_ring_buffer_ioctl,
955 .llseek = vfs_lib_ring_buffer_no_llseek,
956#ifdef CONFIG_COMPAT
957 .compat_ioctl = lttng_metadata_ring_buffer_compat_ioctl,
958#endif
959};
960
961static
962int lttng_abi_create_stream_fd(struct file *channel_file, void *stream_priv,
963 const struct file_operations *fops)
ad1c05e1 964{
ad1c05e1 965 int stream_fd, ret;
11b5a3c2 966 struct file *stream_file;
ad1c05e1 967
4ac10b76 968 stream_fd = lttng_get_unused_fd();
ad1c05e1
MD
969 if (stream_fd < 0) {
970 ret = stream_fd;
971 goto fd_error;
972 }
d83004aa
JD
973 stream_file = anon_inode_getfile("[lttng_stream]", fops,
974 stream_priv, O_RDWR);
c0e31d2e
MD
975 if (IS_ERR(stream_file)) {
976 ret = PTR_ERR(stream_file);
ad1c05e1
MD
977 goto file_error;
978 }
409453cb
MD
979 /*
980 * OPEN_FMODE, called within anon_inode_getfile/alloc_file, don't honor
981 * FMODE_LSEEK, FMODE_PREAD nor FMODE_PWRITE. We need to read from this
982 * file descriptor, so we set FMODE_PREAD here.
983 */
d7b6f197 984 stream_file->f_mode |= FMODE_PREAD;
c0e31d2e 985 fd_install(stream_fd, stream_file);
dda6a249
MD
986 /*
987 * The stream holds a reference to the channel within the generic ring
988 * buffer library, so no need to hold a refcount on the channel and
989 * session files here.
990 */
ad1c05e1
MD
991 return stream_fd;
992
993file_error:
994 put_unused_fd(stream_fd);
d83004aa
JD
995fd_error:
996 return ret;
997}
998
999static
1000int lttng_abi_open_stream(struct file *channel_file)
1001{
1002 struct lttng_channel *channel = channel_file->private_data;
1003 struct lib_ring_buffer *buf;
1004 int ret;
1005 void *stream_priv;
1006
1007 buf = channel->ops->buffer_read_open(channel->chan);
1008 if (!buf)
1009 return -ENOENT;
1010
1011 stream_priv = buf;
1012 ret = lttng_abi_create_stream_fd(channel_file, stream_priv,
ed8d02d6 1013 &lttng_stream_ring_buffer_file_operations);
d83004aa
JD
1014 if (ret < 0)
1015 goto fd_error;
1016
1017 return ret;
1018
1019fd_error:
1020 channel->ops->buffer_read_close(buf);
1021 return ret;
1022}
1023
1024static
1025int lttng_abi_open_metadata_stream(struct file *channel_file)
1026{
1027 struct lttng_channel *channel = channel_file->private_data;
1028 struct lttng_session *session = channel->session;
1029 struct lib_ring_buffer *buf;
1030 int ret;
1031 struct lttng_metadata_stream *metadata_stream;
1032 void *stream_priv;
1033
1034 buf = channel->ops->buffer_read_open(channel->chan);
1035 if (!buf)
1036 return -ENOENT;
1037
1038 metadata_stream = kzalloc(sizeof(struct lttng_metadata_stream),
1039 GFP_KERNEL);
b3b8072b
MD
1040 if (!metadata_stream) {
1041 ret = -ENOMEM;
1042 goto nomem;
1043 }
d83004aa
JD
1044 metadata_stream->metadata_cache = session->metadata_cache;
1045 init_waitqueue_head(&metadata_stream->read_wait);
1046 metadata_stream->priv = buf;
1047 stream_priv = metadata_stream;
b3b8072b
MD
1048 metadata_stream->transport = channel->transport;
1049
1050 /*
1051 * Since life-time of metadata cache differs from that of
1052 * session, we need to keep our own reference on the transport.
1053 */
1054 if (!try_module_get(metadata_stream->transport->owner)) {
1055 printk(KERN_WARNING "LTT : Can't lock transport module.\n");
1056 ret = -EINVAL;
1057 goto notransport;
1058 }
1059
901aaa5f
FD
1060 if (!lttng_kref_get(&session->metadata_cache->refcount)) {
1061 ret = -EOVERFLOW;
9c1f4643 1062 goto kref_error;
901aaa5f
FD
1063 }
1064
d83004aa
JD
1065 ret = lttng_abi_create_stream_fd(channel_file, stream_priv,
1066 &lttng_metadata_ring_buffer_file_operations);
1067 if (ret < 0)
1068 goto fd_error;
1069
d83004aa
JD
1070 list_add(&metadata_stream->list,
1071 &session->metadata_cache->metadata_stream);
1072 return ret;
1073
ad1c05e1 1074fd_error:
9c1f4643
MD
1075 kref_put(&session->metadata_cache->refcount, metadata_cache_destroy);
1076kref_error:
b3b8072b
MD
1077 module_put(metadata_stream->transport->owner);
1078notransport:
1079 kfree(metadata_stream);
1080nomem:
11b5a3c2 1081 channel->ops->buffer_read_close(buf);
ad1c05e1
MD
1082 return ret;
1083}
1084
653fe716 1085static
c0e31d2e 1086int lttng_abi_create_event(struct file *channel_file,
6dccd6c1 1087 struct lttng_kernel_event *event_param)
653fe716 1088{
a90917c3 1089 struct lttng_channel *channel = channel_file->private_data;
653fe716 1090 int event_fd, ret;
11b5a3c2 1091 struct file *event_file;
3c997079 1092 void *priv;
653fe716 1093
6dccd6c1
JD
1094 event_param->name[LTTNG_KERNEL_SYM_NAME_LEN - 1] = '\0';
1095 switch (event_param->instrumentation) {
7371f44c 1096 case LTTNG_KERNEL_KRETPROBE:
6dccd6c1 1097 event_param->u.kretprobe.symbol_name[LTTNG_KERNEL_SYM_NAME_LEN - 1] = '\0';
7371f44c 1098 break;
ab2277d6 1099 case LTTNG_KERNEL_KPROBE:
6dccd6c1 1100 event_param->u.kprobe.symbol_name[LTTNG_KERNEL_SYM_NAME_LEN - 1] = '\0';
e0a7a7c4 1101 break;
ab2277d6 1102 case LTTNG_KERNEL_FUNCTION:
6dccd6c1 1103 event_param->u.ftrace.symbol_name[LTTNG_KERNEL_SYM_NAME_LEN - 1] = '\0';
e0a7a7c4
MD
1104 break;
1105 default:
1106 break;
1107 }
33a39a3c
MD
1108 event_fd = lttng_get_unused_fd();
1109 if (event_fd < 0) {
1110 ret = event_fd;
1111 goto fd_error;
1112 }
1113 event_file = anon_inode_getfile("[lttng_event]",
1114 &lttng_event_fops,
1115 NULL, O_RDWR);
1116 if (IS_ERR(event_file)) {
1117 ret = PTR_ERR(event_file);
1118 goto file_error;
1119 }
9c1f4643 1120 /* The event holds a reference on the channel */
98d7281c 1121 if (!atomic_long_add_unless(&channel_file->f_count, 1, LONG_MAX)) {
0d2c717f 1122 ret = -EOVERFLOW;
9c1f4643
MD
1123 goto refcount_error;
1124 }
33a39a3c
MD
1125 if (event_param->instrumentation == LTTNG_KERNEL_TRACEPOINT
1126 || event_param->instrumentation == LTTNG_KERNEL_SYSCALL) {
1127 struct lttng_enabler *enabler;
1128
4993071a
PP
1129 if (strutils_is_star_glob_pattern(event_param->name)) {
1130 /*
1131 * If the event name is a star globbing pattern,
1132 * we create the special star globbing enabler.
1133 */
1134 enabler = lttng_enabler_create(LTTNG_ENABLER_STAR_GLOB,
33a39a3c 1135 event_param, channel);
3c997079 1136 } else {
33a39a3c
MD
1137 enabler = lttng_enabler_create(LTTNG_ENABLER_NAME,
1138 event_param, channel);
1ec65de1 1139 }
33a39a3c
MD
1140 priv = enabler;
1141 } else {
1142 struct lttng_event *event;
4ee2453d 1143
33a39a3c
MD
1144 /*
1145 * We tolerate no failure path after event creation. It
1146 * will stay invariant for the rest of the session.
1147 */
1148 event = lttng_event_create(channel, event_param,
1149 NULL, NULL,
1150 event_param->instrumentation);
1151 WARN_ON_ONCE(!event);
1152 if (IS_ERR(event)) {
1153 ret = PTR_ERR(event);
1154 goto event_error;
80f87dd2 1155 }
33a39a3c 1156 priv = event;
03037b98 1157 }
33a39a3c
MD
1158 event_file->private_data = priv;
1159 fd_install(event_fd, event_file);
653fe716
MD
1160 return event_fd;
1161
03037b98 1162event_error:
9c1f4643
MD
1163 atomic_long_dec(&channel_file->f_count);
1164refcount_error:
c0e31d2e 1165 fput(event_file);
653fe716
MD
1166file_error:
1167 put_unused_fd(event_fd);
1168fd_error:
653fe716
MD
1169 return ret;
1170}
ad1c05e1
MD
1171
1172/**
1173 * lttng_channel_ioctl - lttng syscall through ioctl
1174 *
c0e31d2e 1175 * @file: the file
ad1c05e1
MD
1176 * @cmd: the command
1177 * @arg: command arg
1178 *
1179 * This ioctl implements lttng commands:
38d024ae 1180 * LTTNG_KERNEL_STREAM
ad1c05e1
MD
1181 * Returns an event stream file descriptor or failure.
1182 * (typically, one event stream records events from one CPU)
38d024ae 1183 * LTTNG_KERNEL_EVENT
ad1c05e1 1184 * Returns an event file descriptor or failure.
8070f5c0
MD
1185 * LTTNG_KERNEL_CONTEXT
1186 * Prepend a context field to each event in the channel
e64957da
MD
1187 * LTTNG_KERNEL_ENABLE
1188 * Enable recording for events in this channel (weak enable)
1189 * LTTNG_KERNEL_DISABLE
1190 * Disable recording for events in this channel (strong disable)
baf20995 1191 *
baf20995
MD
1192 * Channel and event file descriptors also hold a reference on the session.
1193 */
ad1c05e1 1194static
c0e31d2e 1195long lttng_channel_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
baf20995 1196{
a90917c3 1197 struct lttng_channel *channel = file->private_data;
8070f5c0 1198
baf20995 1199 switch (cmd) {
6dccd6c1 1200 case LTTNG_KERNEL_OLD_STREAM:
38d024ae 1201 case LTTNG_KERNEL_STREAM:
c0e31d2e 1202 return lttng_abi_open_stream(file);
6dccd6c1
JD
1203 case LTTNG_KERNEL_OLD_EVENT:
1204 {
1205 struct lttng_kernel_event *uevent_param;
1206 struct lttng_kernel_old_event *old_uevent_param;
1207 int ret;
1208
1209 uevent_param = kmalloc(sizeof(struct lttng_kernel_event),
1210 GFP_KERNEL);
1211 if (!uevent_param) {
1212 ret = -ENOMEM;
1213 goto old_event_end;
1214 }
1215 old_uevent_param = kmalloc(
1216 sizeof(struct lttng_kernel_old_event),
1217 GFP_KERNEL);
1218 if (!old_uevent_param) {
1219 ret = -ENOMEM;
1220 goto old_event_error_free_param;
1221 }
1222 if (copy_from_user(old_uevent_param,
1223 (struct lttng_kernel_old_event __user *) arg,
1224 sizeof(struct lttng_kernel_old_event))) {
1225 ret = -EFAULT;
1226 goto old_event_error_free_old_param;
1227 }
1228
1229 memcpy(uevent_param->name, old_uevent_param->name,
1230 sizeof(uevent_param->name));
1231 uevent_param->instrumentation =
1232 old_uevent_param->instrumentation;
1233
1234 switch (old_uevent_param->instrumentation) {
1235 case LTTNG_KERNEL_KPROBE:
1236 uevent_param->u.kprobe.addr =
1237 old_uevent_param->u.kprobe.addr;
1238 uevent_param->u.kprobe.offset =
1239 old_uevent_param->u.kprobe.offset;
1240 memcpy(uevent_param->u.kprobe.symbol_name,
1241 old_uevent_param->u.kprobe.symbol_name,
1242 sizeof(uevent_param->u.kprobe.symbol_name));
1243 break;
1244 case LTTNG_KERNEL_KRETPROBE:
1245 uevent_param->u.kretprobe.addr =
1246 old_uevent_param->u.kretprobe.addr;
1247 uevent_param->u.kretprobe.offset =
1248 old_uevent_param->u.kretprobe.offset;
1249 memcpy(uevent_param->u.kretprobe.symbol_name,
1250 old_uevent_param->u.kretprobe.symbol_name,
1251 sizeof(uevent_param->u.kretprobe.symbol_name));
1252 break;
1253 case LTTNG_KERNEL_FUNCTION:
1254 memcpy(uevent_param->u.ftrace.symbol_name,
1255 old_uevent_param->u.ftrace.symbol_name,
1256 sizeof(uevent_param->u.ftrace.symbol_name));
1257 break;
1258 default:
1259 break;
1260 }
1261 ret = lttng_abi_create_event(file, uevent_param);
1262
1263old_event_error_free_old_param:
1264 kfree(old_uevent_param);
1265old_event_error_free_param:
1266 kfree(uevent_param);
1267old_event_end:
1268 return ret;
1269 }
38d024ae 1270 case LTTNG_KERNEL_EVENT:
6dccd6c1
JD
1271 {
1272 struct lttng_kernel_event uevent_param;
1273
1274 if (copy_from_user(&uevent_param,
1275 (struct lttng_kernel_event __user *) arg,
1276 sizeof(uevent_param)))
1277 return -EFAULT;
1278 return lttng_abi_create_event(file, &uevent_param);
1279 }
1280 case LTTNG_KERNEL_OLD_CONTEXT:
1281 {
1282 struct lttng_kernel_context *ucontext_param;
1283 struct lttng_kernel_old_context *old_ucontext_param;
1284 int ret;
1285
1286 ucontext_param = kmalloc(sizeof(struct lttng_kernel_context),
1287 GFP_KERNEL);
1288 if (!ucontext_param) {
1289 ret = -ENOMEM;
1290 goto old_ctx_end;
1291 }
1292 old_ucontext_param = kmalloc(sizeof(struct lttng_kernel_old_context),
1293 GFP_KERNEL);
1294 if (!old_ucontext_param) {
1295 ret = -ENOMEM;
1296 goto old_ctx_error_free_param;
1297 }
1298
1299 if (copy_from_user(old_ucontext_param,
1300 (struct lttng_kernel_old_context __user *) arg,
1301 sizeof(struct lttng_kernel_old_context))) {
1302 ret = -EFAULT;
1303 goto old_ctx_error_free_old_param;
1304 }
1305 ucontext_param->ctx = old_ucontext_param->ctx;
1306 memcpy(ucontext_param->padding, old_ucontext_param->padding,
1307 sizeof(ucontext_param->padding));
1308 /* only type that uses the union */
1309 if (old_ucontext_param->ctx == LTTNG_KERNEL_CONTEXT_PERF_COUNTER) {
1310 ucontext_param->u.perf_counter.type =
1311 old_ucontext_param->u.perf_counter.type;
1312 ucontext_param->u.perf_counter.config =
1313 old_ucontext_param->u.perf_counter.config;
1314 memcpy(ucontext_param->u.perf_counter.name,
1315 old_ucontext_param->u.perf_counter.name,
1316 sizeof(ucontext_param->u.perf_counter.name));
1317 }
1318
1319 ret = lttng_abi_add_context(file,
1320 ucontext_param,
1321 &channel->ctx, channel->session);
1322
1323old_ctx_error_free_old_param:
1324 kfree(old_ucontext_param);
1325old_ctx_error_free_param:
1326 kfree(ucontext_param);
1327old_ctx_end:
1328 return ret;
1329 }
8070f5c0 1330 case LTTNG_KERNEL_CONTEXT:
6dccd6c1
JD
1331 {
1332 struct lttng_kernel_context ucontext_param;
1333
1334 if (copy_from_user(&ucontext_param,
8070f5c0 1335 (struct lttng_kernel_context __user *) arg,
6dccd6c1
JD
1336 sizeof(ucontext_param)))
1337 return -EFAULT;
1338 return lttng_abi_add_context(file,
1339 &ucontext_param,
8070f5c0 1340 &channel->ctx, channel->session);
6dccd6c1
JD
1341 }
1342 case LTTNG_KERNEL_OLD_ENABLE:
e64957da 1343 case LTTNG_KERNEL_ENABLE:
a90917c3 1344 return lttng_channel_enable(channel);
6dccd6c1 1345 case LTTNG_KERNEL_OLD_DISABLE:
e64957da 1346 case LTTNG_KERNEL_DISABLE:
a90917c3 1347 return lttng_channel_disable(channel);
12e579db
MD
1348 case LTTNG_KERNEL_SYSCALL_MASK:
1349 return lttng_channel_syscall_mask(channel,
1350 (struct lttng_kernel_syscall_mask __user *) arg);
baf20995
MD
1351 default:
1352 return -ENOIOCTLCMD;
1353 }
1354}
1355
5dbbdb43
MD
1356/**
1357 * lttng_metadata_ioctl - lttng syscall through ioctl
1358 *
1359 * @file: the file
1360 * @cmd: the command
1361 * @arg: command arg
1362 *
1363 * This ioctl implements lttng commands:
38d024ae 1364 * LTTNG_KERNEL_STREAM
5dbbdb43
MD
1365 * Returns an event stream file descriptor or failure.
1366 *
1367 * Channel and event file descriptors also hold a reference on the session.
1368 */
1369static
1370long lttng_metadata_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
1371{
1372 switch (cmd) {
6dccd6c1 1373 case LTTNG_KERNEL_OLD_STREAM:
38d024ae 1374 case LTTNG_KERNEL_STREAM:
d83004aa 1375 return lttng_abi_open_metadata_stream(file);
5dbbdb43
MD
1376 default:
1377 return -ENOIOCTLCMD;
1378 }
1379}
1380
653fe716
MD
1381/**
1382 * lttng_channel_poll - lttng stream addition/removal monitoring
1383 *
c0e31d2e 1384 * @file: the file
653fe716
MD
1385 * @wait: poll table
1386 */
c0e31d2e 1387unsigned int lttng_channel_poll(struct file *file, poll_table *wait)
653fe716 1388{
a90917c3 1389 struct lttng_channel *channel = file->private_data;
653fe716
MD
1390 unsigned int mask = 0;
1391
c0e31d2e 1392 if (file->f_mode & FMODE_READ) {
a33e44a6 1393 poll_wait_set_exclusive(wait);
24cedcfe
MD
1394 poll_wait(file, channel->ops->get_hp_wait_queue(channel->chan),
1395 wait);
653fe716 1396
254ec7bc
MD
1397 if (channel->ops->is_disabled(channel->chan))
1398 return POLLERR;
24cedcfe 1399 if (channel->ops->is_finalized(channel->chan))
653fe716 1400 return POLLHUP;
f71ecafa 1401 if (channel->ops->buffer_has_read_closed_stream(channel->chan))
653fe716 1402 return POLLIN | POLLRDNORM;
f71ecafa 1403 return 0;
653fe716
MD
1404 }
1405 return mask;
1406
1407}
1408
0a84a57f
MD
1409static
1410int lttng_channel_release(struct inode *inode, struct file *file)
1411{
a90917c3 1412 struct lttng_channel *channel = file->private_data;
c269fff4
MD
1413
1414 if (channel)
1415 fput(channel->session->file);
0a84a57f
MD
1416 return 0;
1417}
1418
d83004aa
JD
1419static
1420int lttng_metadata_channel_release(struct inode *inode, struct file *file)
1421{
1422 struct lttng_channel *channel = file->private_data;
1423
1424 if (channel) {
d83004aa 1425 fput(channel->session->file);
a3381417 1426 lttng_metadata_channel_destroy(channel);
d83004aa
JD
1427 }
1428
1429 return 0;
1430}
1431
ad1c05e1 1432static const struct file_operations lttng_channel_fops = {
a33c9927 1433 .owner = THIS_MODULE,
03037b98 1434 .release = lttng_channel_release,
653fe716 1435 .poll = lttng_channel_poll,
ad1c05e1 1436 .unlocked_ioctl = lttng_channel_ioctl,
baf20995 1437#ifdef CONFIG_COMPAT
03037b98 1438 .compat_ioctl = lttng_channel_ioctl,
baf20995 1439#endif
11b5a3c2 1440};
baf20995 1441
5dbbdb43 1442static const struct file_operations lttng_metadata_fops = {
a33c9927 1443 .owner = THIS_MODULE,
d83004aa 1444 .release = lttng_metadata_channel_release,
5dbbdb43
MD
1445 .unlocked_ioctl = lttng_metadata_ioctl,
1446#ifdef CONFIG_COMPAT
1447 .compat_ioctl = lttng_metadata_ioctl,
1448#endif
1449};
1450
8070f5c0
MD
1451/**
1452 * lttng_event_ioctl - lttng syscall through ioctl
1453 *
1454 * @file: the file
1455 * @cmd: the command
1456 * @arg: command arg
1457 *
1458 * This ioctl implements lttng commands:
8070f5c0
MD
1459 * LTTNG_KERNEL_CONTEXT
1460 * Prepend a context field to each record of this event
e64957da
MD
1461 * LTTNG_KERNEL_ENABLE
1462 * Enable recording for this event (weak enable)
1463 * LTTNG_KERNEL_DISABLE
1464 * Disable recording for this event (strong disable)
8070f5c0
MD
1465 */
1466static
1467long lttng_event_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
1468{
3c997079
MD
1469 struct lttng_event *event;
1470 struct lttng_enabler *enabler;
1471 enum lttng_event_type *evtype = file->private_data;
8070f5c0
MD
1472
1473 switch (cmd) {
6dccd6c1
JD
1474 case LTTNG_KERNEL_OLD_CONTEXT:
1475 {
3c997079
MD
1476 /* Not implemented */
1477 return -ENOSYS;
6dccd6c1 1478 }
8070f5c0 1479 case LTTNG_KERNEL_CONTEXT:
6dccd6c1 1480 {
3c997079
MD
1481 /* Not implemented */
1482 return -ENOSYS;
6dccd6c1
JD
1483 }
1484 case LTTNG_KERNEL_OLD_ENABLE:
e64957da 1485 case LTTNG_KERNEL_ENABLE:
3c997079
MD
1486 switch (*evtype) {
1487 case LTTNG_TYPE_EVENT:
1488 event = file->private_data;
1489 return lttng_event_enable(event);
1490 case LTTNG_TYPE_ENABLER:
1491 enabler = file->private_data;
1492 return lttng_enabler_enable(enabler);
1493 default:
1494 WARN_ON_ONCE(1);
1495 return -ENOSYS;
1496 }
6dccd6c1 1497 case LTTNG_KERNEL_OLD_DISABLE:
e64957da 1498 case LTTNG_KERNEL_DISABLE:
3c997079
MD
1499 switch (*evtype) {
1500 case LTTNG_TYPE_EVENT:
1501 event = file->private_data;
1502 return lttng_event_disable(event);
1503 case LTTNG_TYPE_ENABLER:
1504 enabler = file->private_data;
1505 return lttng_enabler_disable(enabler);
1506 default:
1507 WARN_ON_ONCE(1);
1508 return -ENOSYS;
1509 }
07dfc1d0
MD
1510 case LTTNG_KERNEL_FILTER:
1511 switch (*evtype) {
1512 case LTTNG_TYPE_EVENT:
1513 return -EINVAL;
1514 case LTTNG_TYPE_ENABLER:
1515 {
1516 enabler = file->private_data;
1517 return lttng_enabler_attach_bytecode(enabler,
1518 (struct lttng_kernel_filter_bytecode __user *) arg);
1519 }
0586316f
MD
1520 default:
1521 WARN_ON_ONCE(1);
1522 return -ENOSYS;
07dfc1d0 1523 }
3aed4dca
FD
1524 case LTTNG_KERNEL_ADD_CALLSITE:
1525 switch (*evtype) {
1526 case LTTNG_TYPE_EVENT:
1527 event = file->private_data;
1528 return lttng_event_add_callsite(event,
1529 (struct lttng_kernel_event_callsite __user *) arg);
1530 case LTTNG_TYPE_ENABLER:
1531 return -EINVAL;
1532 }
8070f5c0
MD
1533 default:
1534 return -ENOIOCTLCMD;
1535 }
1536}
1537
0a84a57f
MD
1538static
1539int lttng_event_release(struct inode *inode, struct file *file)
1540{
3c997079
MD
1541 struct lttng_event *event;
1542 struct lttng_enabler *enabler;
1543 enum lttng_event_type *evtype = file->private_data;
1544
1545 if (!evtype)
1546 return 0;
1547
1548 switch (*evtype) {
1549 case LTTNG_TYPE_EVENT:
1550 event = file->private_data;
1551 if (event)
1552 fput(event->chan->file);
1553 break;
1554 case LTTNG_TYPE_ENABLER:
1555 enabler = file->private_data;
1556 if (enabler)
1557 fput(enabler->chan->file);
1558 break;
1559 default:
1560 WARN_ON_ONCE(1);
1561 break;
1562 }
c269fff4 1563
0a84a57f
MD
1564 return 0;
1565}
1566
3b923e5b 1567/* TODO: filter control ioctl */
0a84a57f 1568static const struct file_operations lttng_event_fops = {
a33c9927 1569 .owner = THIS_MODULE,
0a84a57f 1570 .release = lttng_event_release,
8070f5c0
MD
1571 .unlocked_ioctl = lttng_event_ioctl,
1572#ifdef CONFIG_COMPAT
1573 .compat_ioctl = lttng_event_ioctl,
1574#endif
11b5a3c2 1575};
0a84a57f 1576
3b731ab1
JD
1577static int put_u64(uint64_t val, unsigned long arg)
1578{
1579 return put_user(val, (uint64_t __user *) arg);
1580}
1581
ed8d02d6
JD
1582static long lttng_stream_ring_buffer_ioctl(struct file *filp,
1583 unsigned int cmd, unsigned long arg)
1584{
3b731ab1
JD
1585 struct lib_ring_buffer *buf = filp->private_data;
1586 struct channel *chan = buf->backend.chan;
1587 const struct lib_ring_buffer_config *config = &chan->backend.config;
dd5a0db3 1588 const struct lttng_channel_ops *ops = chan->backend.priv_ops;
3b731ab1
JD
1589 int ret;
1590
1591 if (atomic_read(&chan->record_disabled))
1592 return -EIO;
1593
ed8d02d6 1594 switch (cmd) {
3b731ab1
JD
1595 case LTTNG_RING_BUFFER_GET_TIMESTAMP_BEGIN:
1596 {
1597 uint64_t ts;
1598
dd5a0db3 1599 ret = ops->timestamp_begin(config, buf, &ts);
3b731ab1
JD
1600 if (ret < 0)
1601 goto error;
1602 return put_u64(ts, arg);
1603 }
1604 case LTTNG_RING_BUFFER_GET_TIMESTAMP_END:
1605 {
1606 uint64_t ts;
1607
dd5a0db3 1608 ret = ops->timestamp_end(config, buf, &ts);
3b731ab1
JD
1609 if (ret < 0)
1610 goto error;
1611 return put_u64(ts, arg);
1612 }
1613 case LTTNG_RING_BUFFER_GET_EVENTS_DISCARDED:
1614 {
1615 uint64_t ed;
1616
dd5a0db3 1617 ret = ops->events_discarded(config, buf, &ed);
3b731ab1
JD
1618 if (ret < 0)
1619 goto error;
1620 return put_u64(ed, arg);
1621 }
1622 case LTTNG_RING_BUFFER_GET_CONTENT_SIZE:
1623 {
1624 uint64_t cs;
1625
dd5a0db3 1626 ret = ops->content_size(config, buf, &cs);
3b731ab1
JD
1627 if (ret < 0)
1628 goto error;
1629 return put_u64(cs, arg);
1630 }
1631 case LTTNG_RING_BUFFER_GET_PACKET_SIZE:
1632 {
1633 uint64_t ps;
1634
dd5a0db3 1635 ret = ops->packet_size(config, buf, &ps);
3b731ab1
JD
1636 if (ret < 0)
1637 goto error;
1638 return put_u64(ps, arg);
1639 }
1640 case LTTNG_RING_BUFFER_GET_STREAM_ID:
1641 {
1642 uint64_t si;
1643
dd5a0db3 1644 ret = ops->stream_id(config, buf, &si);
3b731ab1
JD
1645 if (ret < 0)
1646 goto error;
1647 return put_u64(si, arg);
1648 }
2348ca17
JD
1649 case LTTNG_RING_BUFFER_GET_CURRENT_TIMESTAMP:
1650 {
1651 uint64_t ts;
1652
dd5a0db3 1653 ret = ops->current_timestamp(config, buf, &ts);
2348ca17
JD
1654 if (ret < 0)
1655 goto error;
1656 return put_u64(ts, arg);
1657 }
5b3cf4f9
JD
1658 case LTTNG_RING_BUFFER_GET_SEQ_NUM:
1659 {
1660 uint64_t seq;
1661
1662 ret = ops->sequence_number(config, buf, &seq);
1663 if (ret < 0)
1664 goto error;
1665 return put_u64(seq, arg);
1666 }
5594698f
JD
1667 case LTTNG_RING_BUFFER_INSTANCE_ID:
1668 {
1669 uint64_t id;
1670
1671 ret = ops->instance_id(config, buf, &id);
1672 if (ret < 0)
1673 goto error;
1674 return put_u64(id, arg);
1675 }
3b731ab1
JD
1676 default:
1677 return lib_ring_buffer_file_operations.unlocked_ioctl(filp,
1678 cmd, arg);
ed8d02d6 1679 }
3b731ab1
JD
1680
1681error:
1682 return -ENOSYS;
ed8d02d6
JD
1683}
1684
1685#ifdef CONFIG_COMPAT
1686static long lttng_stream_ring_buffer_compat_ioctl(struct file *filp,
1687 unsigned int cmd, unsigned long arg)
1688{
3b731ab1
JD
1689 struct lib_ring_buffer *buf = filp->private_data;
1690 struct channel *chan = buf->backend.chan;
1691 const struct lib_ring_buffer_config *config = &chan->backend.config;
dd5a0db3 1692 const struct lttng_channel_ops *ops = chan->backend.priv_ops;
3b731ab1
JD
1693 int ret;
1694
1695 if (atomic_read(&chan->record_disabled))
1696 return -EIO;
1697
ed8d02d6 1698 switch (cmd) {
3b731ab1
JD
1699 case LTTNG_RING_BUFFER_COMPAT_GET_TIMESTAMP_BEGIN:
1700 {
1701 uint64_t ts;
1702
dd5a0db3 1703 ret = ops->timestamp_begin(config, buf, &ts);
3b731ab1
JD
1704 if (ret < 0)
1705 goto error;
1706 return put_u64(ts, arg);
1707 }
1708 case LTTNG_RING_BUFFER_COMPAT_GET_TIMESTAMP_END:
1709 {
1710 uint64_t ts;
1711
dd5a0db3 1712 ret = ops->timestamp_end(config, buf, &ts);
3b731ab1
JD
1713 if (ret < 0)
1714 goto error;
1715 return put_u64(ts, arg);
1716 }
1717 case LTTNG_RING_BUFFER_COMPAT_GET_EVENTS_DISCARDED:
1718 {
1719 uint64_t ed;
1720
dd5a0db3 1721 ret = ops->events_discarded(config, buf, &ed);
3b731ab1
JD
1722 if (ret < 0)
1723 goto error;
1724 return put_u64(ed, arg);
ed8d02d6 1725 }
3b731ab1
JD
1726 case LTTNG_RING_BUFFER_COMPAT_GET_CONTENT_SIZE:
1727 {
1728 uint64_t cs;
1729
dd5a0db3 1730 ret = ops->content_size(config, buf, &cs);
3b731ab1
JD
1731 if (ret < 0)
1732 goto error;
1733 return put_u64(cs, arg);
1734 }
1735 case LTTNG_RING_BUFFER_COMPAT_GET_PACKET_SIZE:
1736 {
1737 uint64_t ps;
1738
dd5a0db3 1739 ret = ops->packet_size(config, buf, &ps);
3b731ab1
JD
1740 if (ret < 0)
1741 goto error;
1742 return put_u64(ps, arg);
1743 }
1744 case LTTNG_RING_BUFFER_COMPAT_GET_STREAM_ID:
1745 {
1746 uint64_t si;
1747
dd5a0db3 1748 ret = ops->stream_id(config, buf, &si);
3b731ab1
JD
1749 if (ret < 0)
1750 goto error;
1751 return put_u64(si, arg);
1752 }
2348ca17
JD
1753 case LTTNG_RING_BUFFER_GET_CURRENT_TIMESTAMP:
1754 {
1755 uint64_t ts;
1756
dd5a0db3 1757 ret = ops->current_timestamp(config, buf, &ts);
2348ca17
JD
1758 if (ret < 0)
1759 goto error;
1760 return put_u64(ts, arg);
1761 }
5b3cf4f9
JD
1762 case LTTNG_RING_BUFFER_COMPAT_GET_SEQ_NUM:
1763 {
1764 uint64_t seq;
1765
1766 ret = ops->sequence_number(config, buf, &seq);
1767 if (ret < 0)
1768 goto error;
1769 return put_u64(seq, arg);
1770 }
5594698f
JD
1771 case LTTNG_RING_BUFFER_COMPAT_INSTANCE_ID:
1772 {
1773 uint64_t id;
1774
1775 ret = ops->instance_id(config, buf, &id);
1776 if (ret < 0)
1777 goto error;
1778 return put_u64(id, arg);
1779 }
3b731ab1
JD
1780 default:
1781 return lib_ring_buffer_file_operations.compat_ioctl(filp,
1782 cmd, arg);
1783 }
1784
1785error:
1786 return -ENOSYS;
ed8d02d6
JD
1787}
1788#endif /* CONFIG_COMPAT */
1789
1790static void lttng_stream_override_ring_buffer_fops(void)
1791{
1792 lttng_stream_ring_buffer_file_operations.owner = THIS_MODULE;
1793 lttng_stream_ring_buffer_file_operations.open =
1794 lib_ring_buffer_file_operations.open;
1795 lttng_stream_ring_buffer_file_operations.release =
1796 lib_ring_buffer_file_operations.release;
1797 lttng_stream_ring_buffer_file_operations.poll =
1798 lib_ring_buffer_file_operations.poll;
1799 lttng_stream_ring_buffer_file_operations.splice_read =
1800 lib_ring_buffer_file_operations.splice_read;
1801 lttng_stream_ring_buffer_file_operations.mmap =
1802 lib_ring_buffer_file_operations.mmap;
1803 lttng_stream_ring_buffer_file_operations.unlocked_ioctl =
1804 lttng_stream_ring_buffer_ioctl;
1805 lttng_stream_ring_buffer_file_operations.llseek =
1806 lib_ring_buffer_file_operations.llseek;
1807#ifdef CONFIG_COMPAT
1808 lttng_stream_ring_buffer_file_operations.compat_ioctl =
1809 lttng_stream_ring_buffer_compat_ioctl;
1810#endif
1811}
1812
80996790 1813int __init lttng_abi_init(void)
baf20995
MD
1814{
1815 int ret = 0;
1816
6d2a620c 1817 wrapper_vmalloc_sync_all();
2754583e 1818 lttng_clock_ref();
f771eda6
JD
1819
1820 ret = lttng_tp_mempool_init();
1821 if (ret) {
1822 goto error;
1823 }
1824
d29348f7 1825 lttng_proc_dentry = proc_create_data("lttng", S_IRUSR | S_IWUSR, NULL,
e6a17f26 1826 &lttng_fops, NULL);
2470a237 1827
255e52a4 1828 if (!lttng_proc_dentry) {
baf20995
MD
1829 printk(KERN_ERR "Error creating LTTng control file\n");
1830 ret = -ENOMEM;
1831 goto error;
1832 }
ed8d02d6 1833 lttng_stream_override_ring_buffer_fops();
2754583e 1834 return 0;
ed8d02d6 1835
baf20995 1836error:
f771eda6 1837 lttng_tp_mempool_destroy();
2754583e 1838 lttng_clock_unref();
baf20995
MD
1839 return ret;
1840}
1841
e6e65fcd
MD
1842/* No __exit annotation because used by init error path too. */
1843void lttng_abi_exit(void)
baf20995 1844{
f771eda6 1845 lttng_tp_mempool_destroy();
2754583e 1846 lttng_clock_unref();
e6a17f26
MD
1847 if (lttng_proc_dentry)
1848 remove_proc_entry("lttng", NULL);
baf20995 1849}
This page took 0.126727 seconds and 4 git commands to generate.