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" |
14a4b602 | 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; | |
14a4b602 | 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 | ||
14a4b602 | 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 | |
14a4b602 | 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 | |
ad1c05e1 MD |
426 | * |
427 | * The returned channel will be deleted when its file descriptor is closed. | |
428 | */ | |
429 | static | |
c0e31d2e | 430 | long lttng_session_ioctl(struct file *file, unsigned int cmd, unsigned long arg) |
ad1c05e1 | 431 | { |
a90917c3 | 432 | struct lttng_session *session = file->private_data; |
c0e31d2e | 433 | |
ad1c05e1 | 434 | switch (cmd) { |
6dccd6c1 JD |
435 | case LTTNG_KERNEL_OLD_CHANNEL: |
436 | { | |
437 | struct lttng_kernel_channel chan_param; | |
438 | struct lttng_kernel_old_channel old_chan_param; | |
439 | ||
440 | if (copy_from_user(&old_chan_param, | |
441 | (struct lttng_kernel_old_channel __user *) arg, | |
442 | sizeof(struct lttng_kernel_old_channel))) | |
443 | return -EFAULT; | |
444 | chan_param.overwrite = old_chan_param.overwrite; | |
445 | chan_param.subbuf_size = old_chan_param.subbuf_size; | |
446 | chan_param.num_subbuf = old_chan_param.num_subbuf; | |
447 | chan_param.switch_timer_interval = old_chan_param.switch_timer_interval; | |
448 | chan_param.read_timer_interval = old_chan_param.read_timer_interval; | |
449 | chan_param.output = old_chan_param.output; | |
450 | ||
451 | return lttng_abi_create_channel(file, &chan_param, | |
452 | PER_CPU_CHANNEL); | |
453 | } | |
38d024ae | 454 | case LTTNG_KERNEL_CHANNEL: |
6dccd6c1 JD |
455 | { |
456 | struct lttng_kernel_channel chan_param; | |
457 | ||
458 | if (copy_from_user(&chan_param, | |
38d024ae | 459 | (struct lttng_kernel_channel __user *) arg, |
6dccd6c1 JD |
460 | sizeof(struct lttng_kernel_channel))) |
461 | return -EFAULT; | |
462 | return lttng_abi_create_channel(file, &chan_param, | |
5dbbdb43 | 463 | PER_CPU_CHANNEL); |
6dccd6c1 JD |
464 | } |
465 | case LTTNG_KERNEL_OLD_SESSION_START: | |
466 | case LTTNG_KERNEL_OLD_ENABLE: | |
38d024ae | 467 | case LTTNG_KERNEL_SESSION_START: |
e64957da | 468 | case LTTNG_KERNEL_ENABLE: |
a90917c3 | 469 | return lttng_session_enable(session); |
6dccd6c1 JD |
470 | case LTTNG_KERNEL_OLD_SESSION_STOP: |
471 | case LTTNG_KERNEL_OLD_DISABLE: | |
38d024ae | 472 | case LTTNG_KERNEL_SESSION_STOP: |
e64957da | 473 | case LTTNG_KERNEL_DISABLE: |
a90917c3 | 474 | return lttng_session_disable(session); |
6dccd6c1 JD |
475 | case LTTNG_KERNEL_OLD_METADATA: |
476 | { | |
477 | struct lttng_kernel_channel chan_param; | |
478 | struct lttng_kernel_old_channel old_chan_param; | |
479 | ||
480 | if (copy_from_user(&old_chan_param, | |
481 | (struct lttng_kernel_old_channel __user *) arg, | |
482 | sizeof(struct lttng_kernel_old_channel))) | |
483 | return -EFAULT; | |
484 | chan_param.overwrite = old_chan_param.overwrite; | |
485 | chan_param.subbuf_size = old_chan_param.subbuf_size; | |
486 | chan_param.num_subbuf = old_chan_param.num_subbuf; | |
487 | chan_param.switch_timer_interval = old_chan_param.switch_timer_interval; | |
488 | chan_param.read_timer_interval = old_chan_param.read_timer_interval; | |
489 | chan_param.output = old_chan_param.output; | |
490 | ||
491 | return lttng_abi_create_channel(file, &chan_param, | |
492 | METADATA_CHANNEL); | |
493 | } | |
38d024ae | 494 | case LTTNG_KERNEL_METADATA: |
6dccd6c1 JD |
495 | { |
496 | struct lttng_kernel_channel chan_param; | |
497 | ||
498 | if (copy_from_user(&chan_param, | |
499 | (struct lttng_kernel_channel __user *) arg, | |
500 | sizeof(struct lttng_kernel_channel))) | |
501 | return -EFAULT; | |
502 | return lttng_abi_create_channel(file, &chan_param, | |
5dbbdb43 | 503 | METADATA_CHANNEL); |
6dccd6c1 | 504 | } |
ad1c05e1 MD |
505 | default: |
506 | return -ENOIOCTLCMD; | |
507 | } | |
508 | } | |
509 | ||
03037b98 MD |
510 | /* |
511 | * Called when the last file reference is dropped. | |
512 | * | |
513 | * Big fat note: channels and events are invariant for the whole session after | |
514 | * their creation. So this session destruction also destroys all channel and | |
515 | * event structures specific to this session (they are not destroyed when their | |
516 | * individual file is released). | |
517 | */ | |
ad1c05e1 | 518 | static |
03037b98 | 519 | int lttng_session_release(struct inode *inode, struct file *file) |
ad1c05e1 | 520 | { |
a90917c3 | 521 | struct lttng_session *session = file->private_data; |
c269fff4 MD |
522 | |
523 | if (session) | |
a90917c3 | 524 | lttng_session_destroy(session); |
11b5a3c2 | 525 | return 0; |
ad1c05e1 | 526 | } |
ad1c05e1 MD |
527 | |
528 | static const struct file_operations lttng_session_fops = { | |
a33c9927 | 529 | .owner = THIS_MODULE, |
03037b98 | 530 | .release = lttng_session_release, |
ad1c05e1 MD |
531 | .unlocked_ioctl = lttng_session_ioctl, |
532 | #ifdef CONFIG_COMPAT | |
03037b98 | 533 | .compat_ioctl = lttng_session_ioctl, |
ad1c05e1 | 534 | #endif |
11b5a3c2 | 535 | }; |
ad1c05e1 | 536 | |
d83004aa JD |
537 | /** |
538 | * lttng_metadata_ring_buffer_poll - LTTng ring buffer poll file operation | |
539 | * @filp: the file | |
540 | * @wait: poll table | |
541 | * | |
542 | * Handles the poll operations for the metadata channels. | |
543 | */ | |
ad1c05e1 | 544 | static |
d83004aa JD |
545 | unsigned int lttng_metadata_ring_buffer_poll(struct file *filp, |
546 | poll_table *wait) | |
547 | { | |
548 | struct lttng_metadata_stream *stream = filp->private_data; | |
549 | struct lib_ring_buffer *buf = stream->priv; | |
550 | int finalized; | |
551 | unsigned int mask = 0; | |
552 | ||
553 | if (filp->f_mode & FMODE_READ) { | |
554 | poll_wait_set_exclusive(wait); | |
555 | poll_wait(filp, &stream->read_wait, wait); | |
556 | ||
557 | finalized = stream->finalized; | |
558 | ||
559 | /* | |
560 | * lib_ring_buffer_is_finalized() contains a smp_rmb() | |
561 | * ordering finalized load before offsets loads. | |
562 | */ | |
563 | WARN_ON(atomic_long_read(&buf->active_readers) != 1); | |
564 | ||
565 | if (finalized) | |
566 | mask |= POLLHUP; | |
567 | ||
9a0aa3b1 | 568 | mutex_lock(&stream->metadata_cache->lock); |
d83004aa | 569 | if (stream->metadata_cache->metadata_written > |
f613e3e6 | 570 | stream->metadata_out) |
d83004aa | 571 | mask |= POLLIN; |
9a0aa3b1 | 572 | mutex_unlock(&stream->metadata_cache->lock); |
d83004aa JD |
573 | } |
574 | ||
575 | return mask; | |
576 | } | |
577 | ||
f613e3e6 MD |
578 | static |
579 | void lttng_metadata_ring_buffer_ioctl_put_next_subbuf(struct file *filp, | |
580 | unsigned int cmd, unsigned long arg) | |
581 | { | |
582 | struct lttng_metadata_stream *stream = filp->private_data; | |
583 | ||
584 | stream->metadata_out = stream->metadata_in; | |
585 | } | |
586 | ||
d83004aa JD |
587 | static |
588 | long lttng_metadata_ring_buffer_ioctl(struct file *filp, | |
589 | unsigned int cmd, unsigned long arg) | |
590 | { | |
591 | int ret; | |
592 | struct lttng_metadata_stream *stream = filp->private_data; | |
593 | struct lib_ring_buffer *buf = stream->priv; | |
594 | ||
595 | switch (cmd) { | |
d83004aa JD |
596 | case RING_BUFFER_GET_NEXT_SUBBUF: |
597 | { | |
35097f36 JD |
598 | struct lttng_metadata_stream *stream = filp->private_data; |
599 | struct lib_ring_buffer *buf = stream->priv; | |
600 | struct channel *chan = buf->backend.chan; | |
601 | ||
602 | ret = lttng_metadata_output_channel(stream, chan); | |
603 | if (ret > 0) { | |
604 | lib_ring_buffer_switch_slow(buf, SWITCH_ACTIVE); | |
605 | ret = 0; | |
606 | } else if (ret < 0) | |
d83004aa JD |
607 | goto err; |
608 | break; | |
609 | } | |
f613e3e6 MD |
610 | case RING_BUFFER_GET_SUBBUF: |
611 | { | |
612 | /* | |
613 | * Random access is not allowed for metadata channel. | |
614 | */ | |
615 | return -ENOSYS; | |
616 | } | |
35097f36 JD |
617 | case RING_BUFFER_FLUSH: |
618 | { | |
619 | struct lttng_metadata_stream *stream = filp->private_data; | |
620 | struct lib_ring_buffer *buf = stream->priv; | |
621 | struct channel *chan = buf->backend.chan; | |
622 | ||
623 | /* | |
624 | * Before doing the actual ring buffer flush, write up to one | |
625 | * packet of metadata in the ring buffer. | |
626 | */ | |
627 | ret = lttng_metadata_output_channel(stream, chan); | |
628 | if (ret < 0) | |
629 | goto err; | |
630 | break; | |
631 | } | |
d83004aa JD |
632 | default: |
633 | break; | |
634 | } | |
f613e3e6 MD |
635 | /* PUT_SUBBUF is the one from lib ring buffer, unmodified. */ |
636 | ||
d83004aa | 637 | /* Performing lib ring buffer ioctl after our own. */ |
f613e3e6 MD |
638 | ret = lib_ring_buffer_ioctl(filp, cmd, arg, buf); |
639 | if (ret < 0) | |
640 | goto err; | |
d83004aa | 641 | |
f613e3e6 MD |
642 | switch (cmd) { |
643 | case RING_BUFFER_PUT_NEXT_SUBBUF: | |
644 | { | |
645 | lttng_metadata_ring_buffer_ioctl_put_next_subbuf(filp, | |
646 | cmd, arg); | |
647 | break; | |
648 | } | |
649 | default: | |
650 | break; | |
651 | } | |
d83004aa JD |
652 | err: |
653 | return ret; | |
654 | } | |
655 | ||
aeb9064d | 656 | #ifdef CONFIG_COMPAT |
d83004aa JD |
657 | static |
658 | long lttng_metadata_ring_buffer_compat_ioctl(struct file *filp, | |
659 | unsigned int cmd, unsigned long arg) | |
660 | { | |
661 | int ret; | |
662 | struct lttng_metadata_stream *stream = filp->private_data; | |
663 | struct lib_ring_buffer *buf = stream->priv; | |
664 | ||
665 | switch (cmd) { | |
d83004aa JD |
666 | case RING_BUFFER_GET_NEXT_SUBBUF: |
667 | { | |
35097f36 JD |
668 | struct lttng_metadata_stream *stream = filp->private_data; |
669 | struct lib_ring_buffer *buf = stream->priv; | |
670 | struct channel *chan = buf->backend.chan; | |
671 | ||
672 | ret = lttng_metadata_output_channel(stream, chan); | |
673 | if (ret > 0) { | |
674 | lib_ring_buffer_switch_slow(buf, SWITCH_ACTIVE); | |
675 | ret = 0; | |
676 | } else if (ret < 0) | |
d83004aa JD |
677 | goto err; |
678 | break; | |
679 | } | |
f613e3e6 MD |
680 | case RING_BUFFER_GET_SUBBUF: |
681 | { | |
682 | /* | |
683 | * Random access is not allowed for metadata channel. | |
684 | */ | |
685 | return -ENOSYS; | |
686 | } | |
1150bcb5 MD |
687 | case RING_BUFFER_FLUSH: |
688 | { | |
689 | struct lttng_metadata_stream *stream = filp->private_data; | |
690 | struct lib_ring_buffer *buf = stream->priv; | |
691 | struct channel *chan = buf->backend.chan; | |
692 | ||
693 | /* | |
694 | * Before doing the actual ring buffer flush, write up to one | |
695 | * packet of metadata in the ring buffer. | |
696 | */ | |
697 | ret = lttng_metadata_output_channel(stream, chan); | |
698 | if (ret < 0) | |
699 | goto err; | |
700 | break; | |
701 | } | |
d83004aa JD |
702 | default: |
703 | break; | |
704 | } | |
f613e3e6 MD |
705 | /* PUT_SUBBUF is the one from lib ring buffer, unmodified. */ |
706 | ||
d83004aa | 707 | /* Performing lib ring buffer ioctl after our own. */ |
f613e3e6 MD |
708 | ret = lib_ring_buffer_compat_ioctl(filp, cmd, arg, buf); |
709 | if (ret < 0) | |
710 | goto err; | |
d83004aa | 711 | |
f613e3e6 MD |
712 | switch (cmd) { |
713 | case RING_BUFFER_PUT_NEXT_SUBBUF: | |
714 | { | |
715 | lttng_metadata_ring_buffer_ioctl_put_next_subbuf(filp, | |
716 | cmd, arg); | |
717 | break; | |
718 | } | |
719 | default: | |
720 | break; | |
721 | } | |
d83004aa JD |
722 | err: |
723 | return ret; | |
724 | } | |
aeb9064d | 725 | #endif |
d83004aa | 726 | |
b3b8072b MD |
727 | /* |
728 | * This is not used by anonymous file descriptors. This code is left | |
729 | * there if we ever want to implement an inode with open() operation. | |
730 | */ | |
d83004aa JD |
731 | static |
732 | int lttng_metadata_ring_buffer_open(struct inode *inode, struct file *file) | |
733 | { | |
734 | struct lttng_metadata_stream *stream = inode->i_private; | |
735 | struct lib_ring_buffer *buf = stream->priv; | |
736 | ||
737 | file->private_data = buf; | |
b3b8072b MD |
738 | /* |
739 | * Since life-time of metadata cache differs from that of | |
740 | * session, we need to keep our own reference on the transport. | |
741 | */ | |
742 | if (!try_module_get(stream->transport->owner)) { | |
743 | printk(KERN_WARNING "LTT : Can't lock transport module.\n"); | |
744 | return -EBUSY; | |
745 | } | |
d83004aa JD |
746 | return lib_ring_buffer_open(inode, file, buf); |
747 | } | |
748 | ||
749 | static | |
750 | int lttng_metadata_ring_buffer_release(struct inode *inode, struct file *file) | |
751 | { | |
752 | struct lttng_metadata_stream *stream = file->private_data; | |
753 | struct lib_ring_buffer *buf = stream->priv; | |
754 | ||
755 | kref_put(&stream->metadata_cache->refcount, metadata_cache_destroy); | |
b3b8072b | 756 | module_put(stream->transport->owner); |
d83004aa JD |
757 | return lib_ring_buffer_release(inode, file, buf); |
758 | } | |
759 | ||
760 | static | |
761 | ssize_t lttng_metadata_ring_buffer_splice_read(struct file *in, loff_t *ppos, | |
762 | struct pipe_inode_info *pipe, size_t len, | |
763 | unsigned int flags) | |
764 | { | |
765 | struct lttng_metadata_stream *stream = in->private_data; | |
766 | struct lib_ring_buffer *buf = stream->priv; | |
767 | ||
768 | return lib_ring_buffer_splice_read(in, ppos, pipe, len, | |
769 | flags, buf); | |
770 | } | |
771 | ||
772 | static | |
773 | int lttng_metadata_ring_buffer_mmap(struct file *filp, | |
774 | struct vm_area_struct *vma) | |
775 | { | |
776 | struct lttng_metadata_stream *stream = filp->private_data; | |
777 | struct lib_ring_buffer *buf = stream->priv; | |
778 | ||
779 | return lib_ring_buffer_mmap(filp, vma, buf); | |
780 | } | |
781 | ||
782 | static | |
783 | const struct file_operations lttng_metadata_ring_buffer_file_operations = { | |
784 | .owner = THIS_MODULE, | |
785 | .open = lttng_metadata_ring_buffer_open, | |
786 | .release = lttng_metadata_ring_buffer_release, | |
787 | .poll = lttng_metadata_ring_buffer_poll, | |
788 | .splice_read = lttng_metadata_ring_buffer_splice_read, | |
789 | .mmap = lttng_metadata_ring_buffer_mmap, | |
790 | .unlocked_ioctl = lttng_metadata_ring_buffer_ioctl, | |
791 | .llseek = vfs_lib_ring_buffer_no_llseek, | |
792 | #ifdef CONFIG_COMPAT | |
793 | .compat_ioctl = lttng_metadata_ring_buffer_compat_ioctl, | |
794 | #endif | |
795 | }; | |
796 | ||
797 | static | |
798 | int lttng_abi_create_stream_fd(struct file *channel_file, void *stream_priv, | |
799 | const struct file_operations *fops) | |
ad1c05e1 | 800 | { |
ad1c05e1 | 801 | int stream_fd, ret; |
11b5a3c2 | 802 | struct file *stream_file; |
ad1c05e1 | 803 | |
14a4b602 | 804 | stream_fd = lttng_get_unused_fd(); |
ad1c05e1 MD |
805 | if (stream_fd < 0) { |
806 | ret = stream_fd; | |
807 | goto fd_error; | |
808 | } | |
d83004aa JD |
809 | stream_file = anon_inode_getfile("[lttng_stream]", fops, |
810 | stream_priv, O_RDWR); | |
c0e31d2e MD |
811 | if (IS_ERR(stream_file)) { |
812 | ret = PTR_ERR(stream_file); | |
ad1c05e1 MD |
813 | goto file_error; |
814 | } | |
409453cb MD |
815 | /* |
816 | * OPEN_FMODE, called within anon_inode_getfile/alloc_file, don't honor | |
817 | * FMODE_LSEEK, FMODE_PREAD nor FMODE_PWRITE. We need to read from this | |
818 | * file descriptor, so we set FMODE_PREAD here. | |
819 | */ | |
d7b6f197 | 820 | stream_file->f_mode |= FMODE_PREAD; |
c0e31d2e | 821 | fd_install(stream_fd, stream_file); |
dda6a249 MD |
822 | /* |
823 | * The stream holds a reference to the channel within the generic ring | |
824 | * buffer library, so no need to hold a refcount on the channel and | |
825 | * session files here. | |
826 | */ | |
ad1c05e1 MD |
827 | return stream_fd; |
828 | ||
829 | file_error: | |
830 | put_unused_fd(stream_fd); | |
d83004aa JD |
831 | fd_error: |
832 | return ret; | |
833 | } | |
834 | ||
835 | static | |
836 | int lttng_abi_open_stream(struct file *channel_file) | |
837 | { | |
838 | struct lttng_channel *channel = channel_file->private_data; | |
839 | struct lib_ring_buffer *buf; | |
840 | int ret; | |
841 | void *stream_priv; | |
842 | ||
843 | buf = channel->ops->buffer_read_open(channel->chan); | |
844 | if (!buf) | |
845 | return -ENOENT; | |
846 | ||
847 | stream_priv = buf; | |
848 | ret = lttng_abi_create_stream_fd(channel_file, stream_priv, | |
ed8d02d6 | 849 | <tng_stream_ring_buffer_file_operations); |
d83004aa JD |
850 | if (ret < 0) |
851 | goto fd_error; | |
852 | ||
853 | return ret; | |
854 | ||
855 | fd_error: | |
856 | channel->ops->buffer_read_close(buf); | |
857 | return ret; | |
858 | } | |
859 | ||
860 | static | |
861 | int lttng_abi_open_metadata_stream(struct file *channel_file) | |
862 | { | |
863 | struct lttng_channel *channel = channel_file->private_data; | |
864 | struct lttng_session *session = channel->session; | |
865 | struct lib_ring_buffer *buf; | |
866 | int ret; | |
867 | struct lttng_metadata_stream *metadata_stream; | |
868 | void *stream_priv; | |
869 | ||
870 | buf = channel->ops->buffer_read_open(channel->chan); | |
871 | if (!buf) | |
872 | return -ENOENT; | |
873 | ||
874 | metadata_stream = kzalloc(sizeof(struct lttng_metadata_stream), | |
875 | GFP_KERNEL); | |
b3b8072b MD |
876 | if (!metadata_stream) { |
877 | ret = -ENOMEM; | |
878 | goto nomem; | |
879 | } | |
d83004aa JD |
880 | metadata_stream->metadata_cache = session->metadata_cache; |
881 | init_waitqueue_head(&metadata_stream->read_wait); | |
882 | metadata_stream->priv = buf; | |
883 | stream_priv = metadata_stream; | |
b3b8072b MD |
884 | metadata_stream->transport = channel->transport; |
885 | ||
886 | /* | |
887 | * Since life-time of metadata cache differs from that of | |
888 | * session, we need to keep our own reference on the transport. | |
889 | */ | |
890 | if (!try_module_get(metadata_stream->transport->owner)) { | |
891 | printk(KERN_WARNING "LTT : Can't lock transport module.\n"); | |
892 | ret = -EINVAL; | |
893 | goto notransport; | |
894 | } | |
895 | ||
d83004aa JD |
896 | ret = lttng_abi_create_stream_fd(channel_file, stream_priv, |
897 | <tng_metadata_ring_buffer_file_operations); | |
898 | if (ret < 0) | |
899 | goto fd_error; | |
900 | ||
901 | kref_get(&session->metadata_cache->refcount); | |
902 | list_add(&metadata_stream->list, | |
903 | &session->metadata_cache->metadata_stream); | |
904 | return ret; | |
905 | ||
ad1c05e1 | 906 | fd_error: |
b3b8072b MD |
907 | module_put(metadata_stream->transport->owner); |
908 | notransport: | |
909 | kfree(metadata_stream); | |
910 | nomem: | |
11b5a3c2 | 911 | channel->ops->buffer_read_close(buf); |
ad1c05e1 MD |
912 | return ret; |
913 | } | |
914 | ||
653fe716 | 915 | static |
c0e31d2e | 916 | int lttng_abi_create_event(struct file *channel_file, |
6dccd6c1 | 917 | struct lttng_kernel_event *event_param) |
653fe716 | 918 | { |
a90917c3 MD |
919 | struct lttng_channel *channel = channel_file->private_data; |
920 | struct lttng_event *event; | |
653fe716 | 921 | int event_fd, ret; |
11b5a3c2 | 922 | struct file *event_file; |
653fe716 | 923 | |
6dccd6c1 JD |
924 | event_param->name[LTTNG_KERNEL_SYM_NAME_LEN - 1] = '\0'; |
925 | switch (event_param->instrumentation) { | |
7371f44c | 926 | case LTTNG_KERNEL_KRETPROBE: |
6dccd6c1 | 927 | event_param->u.kretprobe.symbol_name[LTTNG_KERNEL_SYM_NAME_LEN - 1] = '\0'; |
7371f44c | 928 | break; |
ab2277d6 | 929 | case LTTNG_KERNEL_KPROBE: |
6dccd6c1 | 930 | event_param->u.kprobe.symbol_name[LTTNG_KERNEL_SYM_NAME_LEN - 1] = '\0'; |
e0a7a7c4 | 931 | break; |
ab2277d6 | 932 | case LTTNG_KERNEL_FUNCTION: |
6dccd6c1 | 933 | event_param->u.ftrace.symbol_name[LTTNG_KERNEL_SYM_NAME_LEN - 1] = '\0'; |
e0a7a7c4 MD |
934 | break; |
935 | default: | |
936 | break; | |
937 | } | |
6dccd6c1 | 938 | switch (event_param->instrumentation) { |
1ec65de1 | 939 | default: |
14a4b602 | 940 | event_fd = lttng_get_unused_fd(); |
1ec65de1 MD |
941 | if (event_fd < 0) { |
942 | ret = event_fd; | |
943 | goto fd_error; | |
944 | } | |
945 | event_file = anon_inode_getfile("[lttng_event]", | |
946 | <tng_event_fops, | |
947 | NULL, O_RDWR); | |
948 | if (IS_ERR(event_file)) { | |
949 | ret = PTR_ERR(event_file); | |
950 | goto file_error; | |
951 | } | |
952 | /* | |
953 | * We tolerate no failure path after event creation. It | |
954 | * will stay invariant for the rest of the session. | |
955 | */ | |
6dccd6c1 | 956 | event = lttng_event_create(channel, event_param, NULL, NULL); |
abc0446a MD |
957 | WARN_ON_ONCE(!event); |
958 | if (IS_ERR(event)) { | |
959 | ret = PTR_ERR(event); | |
1ec65de1 MD |
960 | goto event_error; |
961 | } | |
962 | event_file->private_data = event; | |
963 | fd_install(event_fd, event_file); | |
964 | /* The event holds a reference on the channel */ | |
965 | atomic_long_inc(&channel_file->f_count); | |
966 | break; | |
43880ee8 | 967 | case LTTNG_KERNEL_SYSCALL: |
1ec65de1 MD |
968 | ret = lttng_syscalls_register(channel, NULL); |
969 | if (ret) | |
970 | goto fd_error; | |
971 | event_fd = 0; | |
4ee2453d MD |
972 | if (event_param->u.syscall.enable) { |
973 | ret = lttng_syscall_filter_enable(channel, | |
80f87dd2 MD |
974 | event_param->name[0] == '\0' ? |
975 | NULL : event_param->name); | |
976 | if (ret) | |
977 | goto fd_error; | |
4ee2453d | 978 | |
80f87dd2 | 979 | } else { |
4ee2453d | 980 | ret = lttng_syscall_filter_disable(channel, |
80f87dd2 MD |
981 | event_param->name[0] == '\0' ? |
982 | NULL : event_param->name); | |
983 | if (ret) | |
984 | goto fd_error; | |
985 | } | |
1ec65de1 | 986 | break; |
03037b98 | 987 | } |
653fe716 MD |
988 | return event_fd; |
989 | ||
03037b98 | 990 | event_error: |
c0e31d2e | 991 | fput(event_file); |
653fe716 MD |
992 | file_error: |
993 | put_unused_fd(event_fd); | |
994 | fd_error: | |
653fe716 MD |
995 | return ret; |
996 | } | |
ad1c05e1 MD |
997 | |
998 | /** | |
999 | * lttng_channel_ioctl - lttng syscall through ioctl | |
1000 | * | |
c0e31d2e | 1001 | * @file: the file |
ad1c05e1 MD |
1002 | * @cmd: the command |
1003 | * @arg: command arg | |
1004 | * | |
1005 | * This ioctl implements lttng commands: | |
38d024ae | 1006 | * LTTNG_KERNEL_STREAM |
ad1c05e1 MD |
1007 | * Returns an event stream file descriptor or failure. |
1008 | * (typically, one event stream records events from one CPU) | |
38d024ae | 1009 | * LTTNG_KERNEL_EVENT |
ad1c05e1 | 1010 | * Returns an event file descriptor or failure. |
8070f5c0 MD |
1011 | * LTTNG_KERNEL_CONTEXT |
1012 | * Prepend a context field to each event in the channel | |
e64957da MD |
1013 | * LTTNG_KERNEL_ENABLE |
1014 | * Enable recording for events in this channel (weak enable) | |
1015 | * LTTNG_KERNEL_DISABLE | |
1016 | * Disable recording for events in this channel (strong disable) | |
baf20995 | 1017 | * |
baf20995 MD |
1018 | * Channel and event file descriptors also hold a reference on the session. |
1019 | */ | |
ad1c05e1 | 1020 | static |
c0e31d2e | 1021 | long lttng_channel_ioctl(struct file *file, unsigned int cmd, unsigned long arg) |
baf20995 | 1022 | { |
a90917c3 | 1023 | struct lttng_channel *channel = file->private_data; |
8070f5c0 | 1024 | |
baf20995 | 1025 | switch (cmd) { |
6dccd6c1 | 1026 | case LTTNG_KERNEL_OLD_STREAM: |
38d024ae | 1027 | case LTTNG_KERNEL_STREAM: |
c0e31d2e | 1028 | return lttng_abi_open_stream(file); |
6dccd6c1 JD |
1029 | case LTTNG_KERNEL_OLD_EVENT: |
1030 | { | |
1031 | struct lttng_kernel_event *uevent_param; | |
1032 | struct lttng_kernel_old_event *old_uevent_param; | |
1033 | int ret; | |
1034 | ||
1035 | uevent_param = kmalloc(sizeof(struct lttng_kernel_event), | |
1036 | GFP_KERNEL); | |
1037 | if (!uevent_param) { | |
1038 | ret = -ENOMEM; | |
1039 | goto old_event_end; | |
1040 | } | |
1041 | old_uevent_param = kmalloc( | |
1042 | sizeof(struct lttng_kernel_old_event), | |
1043 | GFP_KERNEL); | |
1044 | if (!old_uevent_param) { | |
1045 | ret = -ENOMEM; | |
1046 | goto old_event_error_free_param; | |
1047 | } | |
1048 | if (copy_from_user(old_uevent_param, | |
1049 | (struct lttng_kernel_old_event __user *) arg, | |
1050 | sizeof(struct lttng_kernel_old_event))) { | |
1051 | ret = -EFAULT; | |
1052 | goto old_event_error_free_old_param; | |
1053 | } | |
1054 | ||
1055 | memcpy(uevent_param->name, old_uevent_param->name, | |
1056 | sizeof(uevent_param->name)); | |
1057 | uevent_param->instrumentation = | |
1058 | old_uevent_param->instrumentation; | |
1059 | ||
1060 | switch (old_uevent_param->instrumentation) { | |
1061 | case LTTNG_KERNEL_KPROBE: | |
1062 | uevent_param->u.kprobe.addr = | |
1063 | old_uevent_param->u.kprobe.addr; | |
1064 | uevent_param->u.kprobe.offset = | |
1065 | old_uevent_param->u.kprobe.offset; | |
1066 | memcpy(uevent_param->u.kprobe.symbol_name, | |
1067 | old_uevent_param->u.kprobe.symbol_name, | |
1068 | sizeof(uevent_param->u.kprobe.symbol_name)); | |
1069 | break; | |
1070 | case LTTNG_KERNEL_KRETPROBE: | |
1071 | uevent_param->u.kretprobe.addr = | |
1072 | old_uevent_param->u.kretprobe.addr; | |
1073 | uevent_param->u.kretprobe.offset = | |
1074 | old_uevent_param->u.kretprobe.offset; | |
1075 | memcpy(uevent_param->u.kretprobe.symbol_name, | |
1076 | old_uevent_param->u.kretprobe.symbol_name, | |
1077 | sizeof(uevent_param->u.kretprobe.symbol_name)); | |
1078 | break; | |
1079 | case LTTNG_KERNEL_FUNCTION: | |
1080 | memcpy(uevent_param->u.ftrace.symbol_name, | |
1081 | old_uevent_param->u.ftrace.symbol_name, | |
1082 | sizeof(uevent_param->u.ftrace.symbol_name)); | |
1083 | break; | |
1084 | default: | |
1085 | break; | |
1086 | } | |
1087 | ret = lttng_abi_create_event(file, uevent_param); | |
1088 | ||
1089 | old_event_error_free_old_param: | |
1090 | kfree(old_uevent_param); | |
1091 | old_event_error_free_param: | |
1092 | kfree(uevent_param); | |
1093 | old_event_end: | |
1094 | return ret; | |
1095 | } | |
38d024ae | 1096 | case LTTNG_KERNEL_EVENT: |
6dccd6c1 JD |
1097 | { |
1098 | struct lttng_kernel_event uevent_param; | |
1099 | ||
1100 | if (copy_from_user(&uevent_param, | |
1101 | (struct lttng_kernel_event __user *) arg, | |
1102 | sizeof(uevent_param))) | |
1103 | return -EFAULT; | |
1104 | return lttng_abi_create_event(file, &uevent_param); | |
1105 | } | |
1106 | case LTTNG_KERNEL_OLD_CONTEXT: | |
1107 | { | |
1108 | struct lttng_kernel_context *ucontext_param; | |
1109 | struct lttng_kernel_old_context *old_ucontext_param; | |
1110 | int ret; | |
1111 | ||
1112 | ucontext_param = kmalloc(sizeof(struct lttng_kernel_context), | |
1113 | GFP_KERNEL); | |
1114 | if (!ucontext_param) { | |
1115 | ret = -ENOMEM; | |
1116 | goto old_ctx_end; | |
1117 | } | |
1118 | old_ucontext_param = kmalloc(sizeof(struct lttng_kernel_old_context), | |
1119 | GFP_KERNEL); | |
1120 | if (!old_ucontext_param) { | |
1121 | ret = -ENOMEM; | |
1122 | goto old_ctx_error_free_param; | |
1123 | } | |
1124 | ||
1125 | if (copy_from_user(old_ucontext_param, | |
1126 | (struct lttng_kernel_old_context __user *) arg, | |
1127 | sizeof(struct lttng_kernel_old_context))) { | |
1128 | ret = -EFAULT; | |
1129 | goto old_ctx_error_free_old_param; | |
1130 | } | |
1131 | ucontext_param->ctx = old_ucontext_param->ctx; | |
1132 | memcpy(ucontext_param->padding, old_ucontext_param->padding, | |
1133 | sizeof(ucontext_param->padding)); | |
1134 | /* only type that uses the union */ | |
1135 | if (old_ucontext_param->ctx == LTTNG_KERNEL_CONTEXT_PERF_COUNTER) { | |
1136 | ucontext_param->u.perf_counter.type = | |
1137 | old_ucontext_param->u.perf_counter.type; | |
1138 | ucontext_param->u.perf_counter.config = | |
1139 | old_ucontext_param->u.perf_counter.config; | |
1140 | memcpy(ucontext_param->u.perf_counter.name, | |
1141 | old_ucontext_param->u.perf_counter.name, | |
1142 | sizeof(ucontext_param->u.perf_counter.name)); | |
1143 | } | |
1144 | ||
1145 | ret = lttng_abi_add_context(file, | |
1146 | ucontext_param, | |
1147 | &channel->ctx, channel->session); | |
1148 | ||
1149 | old_ctx_error_free_old_param: | |
1150 | kfree(old_ucontext_param); | |
1151 | old_ctx_error_free_param: | |
1152 | kfree(ucontext_param); | |
1153 | old_ctx_end: | |
1154 | return ret; | |
1155 | } | |
8070f5c0 | 1156 | case LTTNG_KERNEL_CONTEXT: |
6dccd6c1 JD |
1157 | { |
1158 | struct lttng_kernel_context ucontext_param; | |
1159 | ||
1160 | if (copy_from_user(&ucontext_param, | |
8070f5c0 | 1161 | (struct lttng_kernel_context __user *) arg, |
6dccd6c1 JD |
1162 | sizeof(ucontext_param))) |
1163 | return -EFAULT; | |
1164 | return lttng_abi_add_context(file, | |
1165 | &ucontext_param, | |
8070f5c0 | 1166 | &channel->ctx, channel->session); |
6dccd6c1 JD |
1167 | } |
1168 | case LTTNG_KERNEL_OLD_ENABLE: | |
e64957da | 1169 | case LTTNG_KERNEL_ENABLE: |
a90917c3 | 1170 | return lttng_channel_enable(channel); |
6dccd6c1 | 1171 | case LTTNG_KERNEL_OLD_DISABLE: |
e64957da | 1172 | case LTTNG_KERNEL_DISABLE: |
a90917c3 | 1173 | return lttng_channel_disable(channel); |
12e579db MD |
1174 | case LTTNG_KERNEL_SYSCALL_MASK: |
1175 | return lttng_channel_syscall_mask(channel, | |
1176 | (struct lttng_kernel_syscall_mask __user *) arg); | |
baf20995 MD |
1177 | default: |
1178 | return -ENOIOCTLCMD; | |
1179 | } | |
6dccd6c1 | 1180 | |
baf20995 MD |
1181 | } |
1182 | ||
5dbbdb43 MD |
1183 | /** |
1184 | * lttng_metadata_ioctl - lttng syscall through ioctl | |
1185 | * | |
1186 | * @file: the file | |
1187 | * @cmd: the command | |
1188 | * @arg: command arg | |
1189 | * | |
1190 | * This ioctl implements lttng commands: | |
38d024ae | 1191 | * LTTNG_KERNEL_STREAM |
5dbbdb43 MD |
1192 | * Returns an event stream file descriptor or failure. |
1193 | * | |
1194 | * Channel and event file descriptors also hold a reference on the session. | |
1195 | */ | |
1196 | static | |
1197 | long lttng_metadata_ioctl(struct file *file, unsigned int cmd, unsigned long arg) | |
1198 | { | |
1199 | switch (cmd) { | |
6dccd6c1 | 1200 | case LTTNG_KERNEL_OLD_STREAM: |
38d024ae | 1201 | case LTTNG_KERNEL_STREAM: |
d83004aa | 1202 | return lttng_abi_open_metadata_stream(file); |
5dbbdb43 MD |
1203 | default: |
1204 | return -ENOIOCTLCMD; | |
1205 | } | |
1206 | } | |
1207 | ||
653fe716 MD |
1208 | /** |
1209 | * lttng_channel_poll - lttng stream addition/removal monitoring | |
1210 | * | |
c0e31d2e | 1211 | * @file: the file |
653fe716 MD |
1212 | * @wait: poll table |
1213 | */ | |
c0e31d2e | 1214 | unsigned int lttng_channel_poll(struct file *file, poll_table *wait) |
653fe716 | 1215 | { |
a90917c3 | 1216 | struct lttng_channel *channel = file->private_data; |
653fe716 MD |
1217 | unsigned int mask = 0; |
1218 | ||
c0e31d2e | 1219 | if (file->f_mode & FMODE_READ) { |
a33e44a6 | 1220 | poll_wait_set_exclusive(wait); |
24cedcfe MD |
1221 | poll_wait(file, channel->ops->get_hp_wait_queue(channel->chan), |
1222 | wait); | |
653fe716 | 1223 | |
254ec7bc MD |
1224 | if (channel->ops->is_disabled(channel->chan)) |
1225 | return POLLERR; | |
24cedcfe | 1226 | if (channel->ops->is_finalized(channel->chan)) |
653fe716 | 1227 | return POLLHUP; |
f71ecafa | 1228 | if (channel->ops->buffer_has_read_closed_stream(channel->chan)) |
653fe716 | 1229 | return POLLIN | POLLRDNORM; |
f71ecafa | 1230 | return 0; |
653fe716 MD |
1231 | } |
1232 | return mask; | |
1233 | ||
1234 | } | |
1235 | ||
0a84a57f MD |
1236 | static |
1237 | int lttng_channel_release(struct inode *inode, struct file *file) | |
1238 | { | |
a90917c3 | 1239 | struct lttng_channel *channel = file->private_data; |
c269fff4 MD |
1240 | |
1241 | if (channel) | |
1242 | fput(channel->session->file); | |
0a84a57f MD |
1243 | return 0; |
1244 | } | |
1245 | ||
d83004aa JD |
1246 | static |
1247 | int lttng_metadata_channel_release(struct inode *inode, struct file *file) | |
1248 | { | |
1249 | struct lttng_channel *channel = file->private_data; | |
1250 | ||
1251 | if (channel) { | |
d83004aa | 1252 | fput(channel->session->file); |
afbb7f1f | 1253 | lttng_metadata_channel_destroy(channel); |
d83004aa JD |
1254 | } |
1255 | ||
1256 | return 0; | |
1257 | } | |
1258 | ||
ad1c05e1 | 1259 | static const struct file_operations lttng_channel_fops = { |
a33c9927 | 1260 | .owner = THIS_MODULE, |
03037b98 | 1261 | .release = lttng_channel_release, |
653fe716 | 1262 | .poll = lttng_channel_poll, |
ad1c05e1 | 1263 | .unlocked_ioctl = lttng_channel_ioctl, |
baf20995 | 1264 | #ifdef CONFIG_COMPAT |
03037b98 | 1265 | .compat_ioctl = lttng_channel_ioctl, |
baf20995 | 1266 | #endif |
11b5a3c2 | 1267 | }; |
baf20995 | 1268 | |
5dbbdb43 | 1269 | static const struct file_operations lttng_metadata_fops = { |
a33c9927 | 1270 | .owner = THIS_MODULE, |
d83004aa | 1271 | .release = lttng_metadata_channel_release, |
5dbbdb43 MD |
1272 | .unlocked_ioctl = lttng_metadata_ioctl, |
1273 | #ifdef CONFIG_COMPAT | |
1274 | .compat_ioctl = lttng_metadata_ioctl, | |
1275 | #endif | |
1276 | }; | |
1277 | ||
8070f5c0 MD |
1278 | /** |
1279 | * lttng_event_ioctl - lttng syscall through ioctl | |
1280 | * | |
1281 | * @file: the file | |
1282 | * @cmd: the command | |
1283 | * @arg: command arg | |
1284 | * | |
1285 | * This ioctl implements lttng commands: | |
8070f5c0 MD |
1286 | * LTTNG_KERNEL_CONTEXT |
1287 | * Prepend a context field to each record of this event | |
e64957da MD |
1288 | * LTTNG_KERNEL_ENABLE |
1289 | * Enable recording for this event (weak enable) | |
1290 | * LTTNG_KERNEL_DISABLE | |
1291 | * Disable recording for this event (strong disable) | |
8070f5c0 MD |
1292 | */ |
1293 | static | |
1294 | long lttng_event_ioctl(struct file *file, unsigned int cmd, unsigned long arg) | |
1295 | { | |
a90917c3 | 1296 | struct lttng_event *event = file->private_data; |
8070f5c0 MD |
1297 | |
1298 | switch (cmd) { | |
6dccd6c1 JD |
1299 | case LTTNG_KERNEL_OLD_CONTEXT: |
1300 | { | |
1301 | struct lttng_kernel_context *ucontext_param; | |
1302 | struct lttng_kernel_old_context *old_ucontext_param; | |
1303 | int ret; | |
1304 | ||
1305 | ucontext_param = kmalloc(sizeof(struct lttng_kernel_context), | |
1306 | GFP_KERNEL); | |
1307 | if (!ucontext_param) { | |
1308 | ret = -ENOMEM; | |
1309 | goto old_ctx_end; | |
1310 | } | |
1311 | old_ucontext_param = kmalloc(sizeof(struct lttng_kernel_old_context), | |
1312 | GFP_KERNEL); | |
1313 | if (!old_ucontext_param) { | |
1314 | ret = -ENOMEM; | |
1315 | goto old_ctx_error_free_param; | |
1316 | } | |
1317 | ||
1318 | if (copy_from_user(old_ucontext_param, | |
1319 | (struct lttng_kernel_old_context __user *) arg, | |
1320 | sizeof(struct lttng_kernel_old_context))) { | |
1321 | ret = -EFAULT; | |
1322 | goto old_ctx_error_free_old_param; | |
1323 | } | |
1324 | ucontext_param->ctx = old_ucontext_param->ctx; | |
1325 | memcpy(ucontext_param->padding, old_ucontext_param->padding, | |
1326 | sizeof(ucontext_param->padding)); | |
1327 | /* only type that uses the union */ | |
1328 | if (old_ucontext_param->ctx == LTTNG_KERNEL_CONTEXT_PERF_COUNTER) { | |
1329 | ucontext_param->u.perf_counter.type = | |
1330 | old_ucontext_param->u.perf_counter.type; | |
1331 | ucontext_param->u.perf_counter.config = | |
1332 | old_ucontext_param->u.perf_counter.config; | |
1333 | memcpy(ucontext_param->u.perf_counter.name, | |
1334 | old_ucontext_param->u.perf_counter.name, | |
1335 | sizeof(ucontext_param->u.perf_counter.name)); | |
1336 | } | |
1337 | ||
1338 | ret = lttng_abi_add_context(file, | |
1339 | ucontext_param, | |
1340 | &event->ctx, event->chan->session); | |
1341 | ||
1342 | old_ctx_error_free_old_param: | |
1343 | kfree(old_ucontext_param); | |
1344 | old_ctx_error_free_param: | |
1345 | kfree(ucontext_param); | |
1346 | old_ctx_end: | |
1347 | return ret; | |
1348 | } | |
8070f5c0 | 1349 | case LTTNG_KERNEL_CONTEXT: |
6dccd6c1 JD |
1350 | { |
1351 | struct lttng_kernel_context ucontext_param; | |
1352 | ||
1353 | if (copy_from_user(&ucontext_param, | |
1354 | (struct lttng_kernel_context __user *) arg, | |
1355 | sizeof(ucontext_param))) | |
1356 | return -EFAULT; | |
8070f5c0 | 1357 | return lttng_abi_add_context(file, |
6dccd6c1 | 1358 | &ucontext_param, |
8070f5c0 | 1359 | &event->ctx, event->chan->session); |
6dccd6c1 JD |
1360 | } |
1361 | case LTTNG_KERNEL_OLD_ENABLE: | |
e64957da | 1362 | case LTTNG_KERNEL_ENABLE: |
a90917c3 | 1363 | return lttng_event_enable(event); |
6dccd6c1 | 1364 | case LTTNG_KERNEL_OLD_DISABLE: |
e64957da | 1365 | case LTTNG_KERNEL_DISABLE: |
a90917c3 | 1366 | return lttng_event_disable(event); |
8070f5c0 MD |
1367 | default: |
1368 | return -ENOIOCTLCMD; | |
1369 | } | |
1370 | } | |
1371 | ||
0a84a57f MD |
1372 | static |
1373 | int lttng_event_release(struct inode *inode, struct file *file) | |
1374 | { | |
a90917c3 | 1375 | struct lttng_event *event = file->private_data; |
c269fff4 | 1376 | |
aa7c23a9 | 1377 | if (event) |
c269fff4 | 1378 | fput(event->chan->file); |
0a84a57f MD |
1379 | return 0; |
1380 | } | |
1381 | ||
3b923e5b | 1382 | /* TODO: filter control ioctl */ |
0a84a57f | 1383 | static const struct file_operations lttng_event_fops = { |
a33c9927 | 1384 | .owner = THIS_MODULE, |
0a84a57f | 1385 | .release = lttng_event_release, |
8070f5c0 MD |
1386 | .unlocked_ioctl = lttng_event_ioctl, |
1387 | #ifdef CONFIG_COMPAT | |
1388 | .compat_ioctl = lttng_event_ioctl, | |
1389 | #endif | |
11b5a3c2 | 1390 | }; |
0a84a57f | 1391 | |
3b731ab1 JD |
1392 | static int put_u64(uint64_t val, unsigned long arg) |
1393 | { | |
1394 | return put_user(val, (uint64_t __user *) arg); | |
1395 | } | |
1396 | ||
ed8d02d6 JD |
1397 | static long lttng_stream_ring_buffer_ioctl(struct file *filp, |
1398 | unsigned int cmd, unsigned long arg) | |
1399 | { | |
3b731ab1 JD |
1400 | struct lib_ring_buffer *buf = filp->private_data; |
1401 | struct channel *chan = buf->backend.chan; | |
1402 | const struct lib_ring_buffer_config *config = &chan->backend.config; | |
dd5a0db3 | 1403 | const struct lttng_channel_ops *ops = chan->backend.priv_ops; |
3b731ab1 JD |
1404 | int ret; |
1405 | ||
1406 | if (atomic_read(&chan->record_disabled)) | |
1407 | return -EIO; | |
1408 | ||
ed8d02d6 | 1409 | switch (cmd) { |
3b731ab1 JD |
1410 | case LTTNG_RING_BUFFER_GET_TIMESTAMP_BEGIN: |
1411 | { | |
1412 | uint64_t ts; | |
1413 | ||
dd5a0db3 | 1414 | ret = ops->timestamp_begin(config, buf, &ts); |
3b731ab1 JD |
1415 | if (ret < 0) |
1416 | goto error; | |
1417 | return put_u64(ts, arg); | |
1418 | } | |
1419 | case LTTNG_RING_BUFFER_GET_TIMESTAMP_END: | |
1420 | { | |
1421 | uint64_t ts; | |
1422 | ||
dd5a0db3 | 1423 | ret = ops->timestamp_end(config, buf, &ts); |
3b731ab1 JD |
1424 | if (ret < 0) |
1425 | goto error; | |
1426 | return put_u64(ts, arg); | |
1427 | } | |
1428 | case LTTNG_RING_BUFFER_GET_EVENTS_DISCARDED: | |
1429 | { | |
1430 | uint64_t ed; | |
1431 | ||
dd5a0db3 | 1432 | ret = ops->events_discarded(config, buf, &ed); |
3b731ab1 JD |
1433 | if (ret < 0) |
1434 | goto error; | |
1435 | return put_u64(ed, arg); | |
1436 | } | |
1437 | case LTTNG_RING_BUFFER_GET_CONTENT_SIZE: | |
1438 | { | |
1439 | uint64_t cs; | |
1440 | ||
dd5a0db3 | 1441 | ret = ops->content_size(config, buf, &cs); |
3b731ab1 JD |
1442 | if (ret < 0) |
1443 | goto error; | |
1444 | return put_u64(cs, arg); | |
1445 | } | |
1446 | case LTTNG_RING_BUFFER_GET_PACKET_SIZE: | |
1447 | { | |
1448 | uint64_t ps; | |
1449 | ||
dd5a0db3 | 1450 | ret = ops->packet_size(config, buf, &ps); |
3b731ab1 JD |
1451 | if (ret < 0) |
1452 | goto error; | |
1453 | return put_u64(ps, arg); | |
1454 | } | |
1455 | case LTTNG_RING_BUFFER_GET_STREAM_ID: | |
1456 | { | |
1457 | uint64_t si; | |
1458 | ||
dd5a0db3 | 1459 | ret = ops->stream_id(config, buf, &si); |
3b731ab1 JD |
1460 | if (ret < 0) |
1461 | goto error; | |
1462 | return put_u64(si, arg); | |
1463 | } | |
2348ca17 JD |
1464 | case LTTNG_RING_BUFFER_GET_CURRENT_TIMESTAMP: |
1465 | { | |
1466 | uint64_t ts; | |
1467 | ||
dd5a0db3 | 1468 | ret = ops->current_timestamp(config, buf, &ts); |
2348ca17 JD |
1469 | if (ret < 0) |
1470 | goto error; | |
1471 | return put_u64(ts, arg); | |
1472 | } | |
3b731ab1 JD |
1473 | default: |
1474 | return lib_ring_buffer_file_operations.unlocked_ioctl(filp, | |
1475 | cmd, arg); | |
ed8d02d6 | 1476 | } |
3b731ab1 JD |
1477 | |
1478 | error: | |
1479 | return -ENOSYS; | |
ed8d02d6 JD |
1480 | } |
1481 | ||
1482 | #ifdef CONFIG_COMPAT | |
1483 | static long lttng_stream_ring_buffer_compat_ioctl(struct file *filp, | |
1484 | unsigned int cmd, unsigned long arg) | |
1485 | { | |
3b731ab1 JD |
1486 | struct lib_ring_buffer *buf = filp->private_data; |
1487 | struct channel *chan = buf->backend.chan; | |
1488 | const struct lib_ring_buffer_config *config = &chan->backend.config; | |
dd5a0db3 | 1489 | const struct lttng_channel_ops *ops = chan->backend.priv_ops; |
3b731ab1 JD |
1490 | int ret; |
1491 | ||
1492 | if (atomic_read(&chan->record_disabled)) | |
1493 | return -EIO; | |
1494 | ||
ed8d02d6 | 1495 | switch (cmd) { |
3b731ab1 JD |
1496 | case LTTNG_RING_BUFFER_COMPAT_GET_TIMESTAMP_BEGIN: |
1497 | { | |
1498 | uint64_t ts; | |
1499 | ||
dd5a0db3 | 1500 | ret = ops->timestamp_begin(config, buf, &ts); |
3b731ab1 JD |
1501 | if (ret < 0) |
1502 | goto error; | |
1503 | return put_u64(ts, arg); | |
1504 | } | |
1505 | case LTTNG_RING_BUFFER_COMPAT_GET_TIMESTAMP_END: | |
1506 | { | |
1507 | uint64_t ts; | |
1508 | ||
dd5a0db3 | 1509 | ret = ops->timestamp_end(config, buf, &ts); |
3b731ab1 JD |
1510 | if (ret < 0) |
1511 | goto error; | |
1512 | return put_u64(ts, arg); | |
1513 | } | |
1514 | case LTTNG_RING_BUFFER_COMPAT_GET_EVENTS_DISCARDED: | |
1515 | { | |
1516 | uint64_t ed; | |
1517 | ||
dd5a0db3 | 1518 | ret = ops->events_discarded(config, buf, &ed); |
3b731ab1 JD |
1519 | if (ret < 0) |
1520 | goto error; | |
1521 | return put_u64(ed, arg); | |
ed8d02d6 | 1522 | } |
3b731ab1 JD |
1523 | case LTTNG_RING_BUFFER_COMPAT_GET_CONTENT_SIZE: |
1524 | { | |
1525 | uint64_t cs; | |
1526 | ||
dd5a0db3 | 1527 | ret = ops->content_size(config, buf, &cs); |
3b731ab1 JD |
1528 | if (ret < 0) |
1529 | goto error; | |
1530 | return put_u64(cs, arg); | |
1531 | } | |
1532 | case LTTNG_RING_BUFFER_COMPAT_GET_PACKET_SIZE: | |
1533 | { | |
1534 | uint64_t ps; | |
1535 | ||
dd5a0db3 | 1536 | ret = ops->packet_size(config, buf, &ps); |
3b731ab1 JD |
1537 | if (ret < 0) |
1538 | goto error; | |
1539 | return put_u64(ps, arg); | |
1540 | } | |
1541 | case LTTNG_RING_BUFFER_COMPAT_GET_STREAM_ID: | |
1542 | { | |
1543 | uint64_t si; | |
1544 | ||
dd5a0db3 | 1545 | ret = ops->stream_id(config, buf, &si); |
3b731ab1 JD |
1546 | if (ret < 0) |
1547 | goto error; | |
1548 | return put_u64(si, arg); | |
1549 | } | |
2348ca17 JD |
1550 | case LTTNG_RING_BUFFER_GET_CURRENT_TIMESTAMP: |
1551 | { | |
1552 | uint64_t ts; | |
1553 | ||
dd5a0db3 | 1554 | ret = ops->current_timestamp(config, buf, &ts); |
2348ca17 JD |
1555 | if (ret < 0) |
1556 | goto error; | |
1557 | return put_u64(ts, arg); | |
1558 | } | |
3b731ab1 JD |
1559 | default: |
1560 | return lib_ring_buffer_file_operations.compat_ioctl(filp, | |
1561 | cmd, arg); | |
1562 | } | |
1563 | ||
1564 | error: | |
1565 | return -ENOSYS; | |
ed8d02d6 JD |
1566 | } |
1567 | #endif /* CONFIG_COMPAT */ | |
1568 | ||
1569 | static void lttng_stream_override_ring_buffer_fops(void) | |
1570 | { | |
1571 | lttng_stream_ring_buffer_file_operations.owner = THIS_MODULE; | |
1572 | lttng_stream_ring_buffer_file_operations.open = | |
1573 | lib_ring_buffer_file_operations.open; | |
1574 | lttng_stream_ring_buffer_file_operations.release = | |
1575 | lib_ring_buffer_file_operations.release; | |
1576 | lttng_stream_ring_buffer_file_operations.poll = | |
1577 | lib_ring_buffer_file_operations.poll; | |
1578 | lttng_stream_ring_buffer_file_operations.splice_read = | |
1579 | lib_ring_buffer_file_operations.splice_read; | |
1580 | lttng_stream_ring_buffer_file_operations.mmap = | |
1581 | lib_ring_buffer_file_operations.mmap; | |
1582 | lttng_stream_ring_buffer_file_operations.unlocked_ioctl = | |
1583 | lttng_stream_ring_buffer_ioctl; | |
1584 | lttng_stream_ring_buffer_file_operations.llseek = | |
1585 | lib_ring_buffer_file_operations.llseek; | |
1586 | #ifdef CONFIG_COMPAT | |
1587 | lttng_stream_ring_buffer_file_operations.compat_ioctl = | |
1588 | lttng_stream_ring_buffer_compat_ioctl; | |
1589 | #endif | |
1590 | } | |
1591 | ||
80996790 | 1592 | int __init lttng_abi_init(void) |
baf20995 MD |
1593 | { |
1594 | int ret = 0; | |
1595 | ||
6d2a620c | 1596 | wrapper_vmalloc_sync_all(); |
d29348f7 | 1597 | lttng_proc_dentry = proc_create_data("lttng", S_IRUSR | S_IWUSR, NULL, |
e6a17f26 MD |
1598 | <tng_fops, NULL); |
1599 | ||
255e52a4 | 1600 | if (!lttng_proc_dentry) { |
baf20995 MD |
1601 | printk(KERN_ERR "Error creating LTTng control file\n"); |
1602 | ret = -ENOMEM; | |
1603 | goto error; | |
1604 | } | |
ed8d02d6 JD |
1605 | lttng_stream_override_ring_buffer_fops(); |
1606 | ||
baf20995 MD |
1607 | error: |
1608 | return ret; | |
1609 | } | |
1610 | ||
e6e65fcd MD |
1611 | /* No __exit annotation because used by init error path too. */ |
1612 | void lttng_abi_exit(void) | |
baf20995 | 1613 | { |
e6a17f26 MD |
1614 | if (lttng_proc_dentry) |
1615 | remove_proc_entry("lttng", NULL); | |
baf20995 | 1616 | } |