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