Commit | Line | Data |
---|---|---|
baf20995 MD |
1 | /* |
2 | * ltt-debugfs-abi.c | |
3 | * | |
4 | * Copyright 2010 (c) - Mathieu Desnoyers <mathieu.desnoyers@efficios.com> | |
5 | * | |
6 | * LTTng debugfs ABI | |
7 | * | |
8 | * Mimic system calls for: | |
9 | * - session creation, returns a file descriptor or failure. | |
ad1c05e1 MD |
10 | * - channel creation, returns a file descriptor or failure. |
11 | * - Operates on a session file descriptor | |
12 | * - Takes all channel options as parameters. | |
13 | * - stream get, returns a file descriptor or failure. | |
14 | * - Operates on a channel file descriptor. | |
15 | * - stream notifier get, returns a file descriptor or failure. | |
16 | * - Operates on a channel file descriptor. | |
17 | * - event creation, returns a file descriptor or failure. | |
18 | * - Operates on a channel file descriptor | |
19 | * - Takes an event name as parameter | |
20 | * - Takes an instrumentation source as parameter | |
21 | * - e.g. tracepoints, dynamic_probes... | |
22 | * - Takes instrumentation source specific arguments. | |
17baffe2 MD |
23 | * |
24 | * Dual LGPL v2.1/GPL v2 license. | |
baf20995 MD |
25 | */ |
26 | ||
11b5a3c2 | 27 | #include <linux/module.h> |
baf20995 | 28 | #include <linux/debugfs.h> |
11b5a3c2 MD |
29 | #include <linux/anon_inodes.h> |
30 | #include <linux/file.h> | |
31 | #include <linux/uaccess.h> | |
32 | #include <linux/slab.h> | |
b13f3ebe | 33 | #include "wrapper/vmalloc.h" /* for wrapper_vmalloc_sync_all() */ |
f3bc08c5 | 34 | #include "wrapper/ringbuffer/vfs.h" |
11b5a3c2 | 35 | #include "ltt-debugfs-abi.h" |
ad1c05e1 | 36 | #include "ltt-events.h" |
80c16bcf | 37 | #include "ltt-tracer.h" |
baf20995 MD |
38 | |
39 | /* | |
40 | * This is LTTng's own personal way to create a system call as an external | |
41 | * module. We use ioctl() on /sys/kernel/debug/lttng. | |
42 | */ | |
43 | ||
44 | static struct dentry *lttng_dentry; | |
ad1c05e1 MD |
45 | static const struct file_operations lttng_fops; |
46 | static const struct file_operations lttng_session_fops; | |
47 | static const struct file_operations lttng_channel_fops; | |
5dbbdb43 | 48 | static const struct file_operations lttng_metadata_fops; |
305d3e42 | 49 | static const struct file_operations lttng_event_fops; |
baf20995 | 50 | |
5dbbdb43 MD |
51 | enum channel_type { |
52 | PER_CPU_CHANNEL, | |
5dbbdb43 MD |
53 | METADATA_CHANNEL, |
54 | }; | |
55 | ||
ad1c05e1 | 56 | static |
baf20995 MD |
57 | int lttng_abi_create_session(void) |
58 | { | |
59 | struct ltt_session *session; | |
c0e31d2e | 60 | struct file *session_file; |
11b5a3c2 | 61 | int session_fd, ret; |
baf20995 | 62 | |
653fe716 | 63 | session = ltt_session_create(); |
baf20995 MD |
64 | if (!session) |
65 | return -ENOMEM; | |
1c25284c | 66 | session_fd = get_unused_fd(); |
baf20995 MD |
67 | if (session_fd < 0) { |
68 | ret = session_fd; | |
69 | goto fd_error; | |
70 | } | |
c0e31d2e | 71 | session_file = anon_inode_getfile("[lttng_session]", |
ad1c05e1 | 72 | <tng_session_fops, |
baf20995 | 73 | session, O_RDWR); |
c0e31d2e MD |
74 | if (IS_ERR(session_file)) { |
75 | ret = PTR_ERR(session_file); | |
baf20995 MD |
76 | goto file_error; |
77 | } | |
c0e31d2e MD |
78 | session->file = session_file; |
79 | fd_install(session_fd, session_file); | |
baf20995 MD |
80 | return session_fd; |
81 | ||
82 | file_error: | |
83 | put_unused_fd(session_fd); | |
84 | fd_error: | |
85 | ltt_session_destroy(session); | |
86 | return ret; | |
87 | } | |
88 | ||
271b6681 MD |
89 | static |
90 | int lttng_abi_tracepoint_list(void) | |
91 | { | |
92 | struct file *tracepoint_list_file; | |
93 | int file_fd, ret; | |
94 | ||
95 | file_fd = get_unused_fd(); | |
96 | if (file_fd < 0) { | |
97 | ret = file_fd; | |
98 | goto fd_error; | |
99 | } | |
30f18bf0 | 100 | |
271b6681 MD |
101 | tracepoint_list_file = anon_inode_getfile("[lttng_session]", |
102 | <tng_tracepoint_list_fops, | |
103 | NULL, O_RDWR); | |
104 | if (IS_ERR(tracepoint_list_file)) { | |
105 | ret = PTR_ERR(tracepoint_list_file); | |
106 | goto file_error; | |
107 | } | |
30f18bf0 MD |
108 | ret = lttng_tracepoint_list_fops.open(NULL, tracepoint_list_file); |
109 | if (ret < 0) | |
110 | goto open_error; | |
271b6681 | 111 | fd_install(file_fd, tracepoint_list_file); |
30f18bf0 MD |
112 | if (file_fd < 0) { |
113 | ret = file_fd; | |
114 | goto fd_error; | |
115 | } | |
271b6681 MD |
116 | return file_fd; |
117 | ||
30f18bf0 MD |
118 | open_error: |
119 | fput(tracepoint_list_file); | |
271b6681 MD |
120 | file_error: |
121 | put_unused_fd(file_fd); | |
122 | fd_error: | |
123 | return ret; | |
124 | } | |
125 | ||
80c16bcf MD |
126 | static |
127 | long lttng_abi_tracer_version(struct file *file, | |
128 | struct lttng_kernel_tracer_version __user *uversion_param) | |
129 | { | |
130 | struct lttng_kernel_tracer_version v; | |
131 | ||
132 | v.version = LTTNG_VERSION; | |
133 | v.patchlevel = LTTNG_PATCHLEVEL; | |
134 | v.sublevel = LTTNG_SUBLEVEL; | |
135 | ||
136 | if (copy_to_user(uversion_param, &v, sizeof(v))) | |
137 | return -EFAULT; | |
138 | return 0; | |
139 | } | |
140 | ||
8070f5c0 MD |
141 | static |
142 | long lttng_abi_add_context(struct file *file, | |
143 | struct lttng_kernel_context __user *ucontext_param, | |
144 | struct lttng_ctx **ctx, struct ltt_session *session) | |
145 | { | |
146 | struct lttng_kernel_context context_param; | |
147 | ||
148 | if (session->been_active) | |
149 | return -EPERM; | |
150 | ||
151 | if (copy_from_user(&context_param, ucontext_param, sizeof(context_param))) | |
152 | return -EFAULT; | |
153 | ||
154 | switch (context_param.ctx) { | |
12a313a5 | 155 | case LTTNG_KERNEL_CONTEXT_PID: |
8070f5c0 | 156 | return lttng_add_pid_to_ctx(ctx); |
a8ad3613 MD |
157 | case LTTNG_KERNEL_CONTEXT_PRIO: |
158 | return lttng_add_prio_to_ctx(ctx); | |
53f1f0ca MD |
159 | case LTTNG_KERNEL_CONTEXT_NICE: |
160 | return lttng_add_nice_to_ctx(ctx); | |
12a313a5 | 161 | case LTTNG_KERNEL_CONTEXT_PERF_COUNTER: |
c24a0d71 MD |
162 | context_param.u.perf_counter.name[LTTNG_SYM_NAME_LEN - 1] = '\0'; |
163 | return lttng_add_perf_counter_to_ctx(context_param.u.perf_counter.type, | |
164 | context_param.u.perf_counter.config, | |
165 | context_param.u.perf_counter.name, | |
166 | ctx); | |
25b2f99a MD |
167 | case LTTNG_KERNEL_CONTEXT_COMM: |
168 | return lttng_add_comm_to_ctx(ctx); | |
8070f5c0 MD |
169 | default: |
170 | return -EINVAL; | |
171 | } | |
172 | } | |
173 | ||
ad1c05e1 MD |
174 | /** |
175 | * lttng_ioctl - lttng syscall through ioctl | |
176 | * | |
c0e31d2e | 177 | * @file: the file |
ad1c05e1 MD |
178 | * @cmd: the command |
179 | * @arg: command arg | |
180 | * | |
181 | * This ioctl implements lttng commands: | |
38d024ae | 182 | * LTTNG_KERNEL_SESSION |
ad1c05e1 | 183 | * Returns a LTTng trace session file descriptor |
271b6681 MD |
184 | * LTTNG_KERNEL_TRACER_VERSION |
185 | * Returns the LTTng kernel tracer version | |
186 | * LTTNG_KERNEL_TRACEPOINT_LIST | |
187 | * Returns a file descriptor listing available tracepoints | |
ad1c05e1 MD |
188 | * |
189 | * The returned session will be deleted when its file descriptor is closed. | |
190 | */ | |
191 | static | |
c0e31d2e | 192 | long lttng_ioctl(struct file *file, unsigned int cmd, unsigned long arg) |
ad1c05e1 MD |
193 | { |
194 | switch (cmd) { | |
38d024ae | 195 | case LTTNG_KERNEL_SESSION: |
ad1c05e1 | 196 | return lttng_abi_create_session(); |
80c16bcf MD |
197 | case LTTNG_KERNEL_TRACER_VERSION: |
198 | return lttng_abi_tracer_version(file, | |
199 | (struct lttng_kernel_tracer_version __user *) arg); | |
271b6681 MD |
200 | case LTTNG_KERNEL_TRACEPOINT_LIST: |
201 | return lttng_abi_tracepoint_list(); | |
ad1c05e1 MD |
202 | default: |
203 | return -ENOIOCTLCMD; | |
204 | } | |
205 | } | |
206 | ||
ad1c05e1 MD |
207 | static const struct file_operations lttng_fops = { |
208 | .unlocked_ioctl = lttng_ioctl, | |
209 | #ifdef CONFIG_COMPAT | |
03037b98 | 210 | .compat_ioctl = lttng_ioctl, |
ad1c05e1 | 211 | #endif |
11b5a3c2 | 212 | }; |
ad1c05e1 | 213 | |
5dbbdb43 MD |
214 | /* |
215 | * We tolerate no failure in this function (if one happens, we print a dmesg | |
216 | * error, but cannot return any error, because the channel information is | |
217 | * invariant. | |
218 | */ | |
219 | static | |
220 | void lttng_metadata_create_events(struct file *channel_file) | |
221 | { | |
222 | struct ltt_channel *channel = channel_file->private_data; | |
e70a4758 | 223 | static struct lttng_kernel_event metadata_params = { |
ab2277d6 | 224 | .instrumentation = LTTNG_KERNEL_TRACEPOINT, |
e70a4758 MD |
225 | .name = "lttng_metadata", |
226 | }; | |
5dbbdb43 MD |
227 | struct ltt_event *event; |
228 | int ret; | |
5dbbdb43 | 229 | |
5dbbdb43 MD |
230 | /* |
231 | * We tolerate no failure path after event creation. It will stay | |
232 | * invariant for the rest of the session. | |
233 | */ | |
30bdb6e4 | 234 | event = ltt_event_create(channel, &metadata_params, NULL); |
5dbbdb43 | 235 | if (!event) { |
588e6a7f | 236 | ret = -EINVAL; |
271b6681 | 237 | goto create_error; |
5dbbdb43 MD |
238 | } |
239 | return; | |
240 | ||
85a9ca7f | 241 | create_error: |
5dbbdb43 MD |
242 | WARN_ON(1); |
243 | return; /* not allowed to return error */ | |
244 | } | |
245 | ||
246 | static | |
c0e31d2e | 247 | int lttng_abi_create_channel(struct file *session_file, |
38d024ae | 248 | struct lttng_kernel_channel __user *uchan_param, |
5dbbdb43 | 249 | enum channel_type channel_type) |
baf20995 | 250 | { |
c0e31d2e | 251 | struct ltt_session *session = session_file->private_data; |
5dbbdb43 MD |
252 | const struct file_operations *fops; |
253 | const char *transport_name; | |
baf20995 | 254 | struct ltt_channel *chan; |
c0e31d2e | 255 | struct file *chan_file; |
38d024ae | 256 | struct lttng_kernel_channel chan_param; |
baf20995 | 257 | int chan_fd; |
ad1c05e1 | 258 | int ret = 0; |
baf20995 | 259 | |
653fe716 | 260 | if (copy_from_user(&chan_param, uchan_param, sizeof(chan_param))) |
baf20995 | 261 | return -EFAULT; |
1c25284c | 262 | chan_fd = get_unused_fd(); |
baf20995 MD |
263 | if (chan_fd < 0) { |
264 | ret = chan_fd; | |
265 | goto fd_error; | |
266 | } | |
c0e31d2e | 267 | chan_file = anon_inode_getfile("[lttng_channel]", |
ad1c05e1 | 268 | <tng_channel_fops, |
03037b98 | 269 | NULL, O_RDWR); |
c0e31d2e MD |
270 | if (IS_ERR(chan_file)) { |
271 | ret = PTR_ERR(chan_file); | |
baf20995 MD |
272 | goto file_error; |
273 | } | |
5dbbdb43 MD |
274 | switch (channel_type) { |
275 | case PER_CPU_CHANNEL: | |
276 | transport_name = chan_param.overwrite ? | |
277 | "relay-overwrite" : "relay-discard"; | |
278 | fops = <tng_channel_fops; | |
279 | break; | |
5dbbdb43 | 280 | case METADATA_CHANNEL: |
881833e3 | 281 | transport_name = "relay-metadata"; |
5dbbdb43 MD |
282 | fops = <tng_metadata_fops; |
283 | break; | |
284 | default: | |
285 | transport_name = "<unknown>"; | |
286 | break; | |
287 | } | |
03037b98 MD |
288 | /* |
289 | * We tolerate no failure path after channel creation. It will stay | |
290 | * invariant for the rest of the session. | |
291 | */ | |
5dbbdb43 | 292 | chan = ltt_channel_create(session, transport_name, NULL, |
11b5a3c2 MD |
293 | chan_param.subbuf_size, |
294 | chan_param.num_subbuf, | |
295 | chan_param.switch_timer_interval, | |
296 | chan_param.read_timer_interval); | |
03037b98 | 297 | if (!chan) { |
f3d01b96 | 298 | ret = -EINVAL; |
03037b98 MD |
299 | goto chan_error; |
300 | } | |
11b5a3c2 | 301 | chan->file = chan_file; |
c0e31d2e MD |
302 | chan_file->private_data = chan; |
303 | fd_install(chan_fd, chan_file); | |
cd4bd11f | 304 | if (channel_type == METADATA_CHANNEL) { |
cd4bd11f | 305 | session->metadata = chan; |
4f1c3952 | 306 | lttng_metadata_create_events(chan_file); |
cd4bd11f | 307 | } |
5dbbdb43 | 308 | |
ad1c05e1 | 309 | /* The channel created holds a reference on the session */ |
b0caa15a | 310 | atomic_long_inc(&session_file->f_count); |
ad1c05e1 | 311 | |
baf20995 MD |
312 | return chan_fd; |
313 | ||
03037b98 | 314 | chan_error: |
c0e31d2e | 315 | fput(chan_file); |
baf20995 MD |
316 | file_error: |
317 | put_unused_fd(chan_fd); | |
318 | fd_error: | |
baf20995 MD |
319 | return ret; |
320 | } | |
321 | ||
322 | /** | |
ad1c05e1 | 323 | * lttng_session_ioctl - lttng session fd ioctl |
baf20995 | 324 | * |
c0e31d2e | 325 | * @file: the file |
baf20995 MD |
326 | * @cmd: the command |
327 | * @arg: command arg | |
328 | * | |
329 | * This ioctl implements lttng commands: | |
38d024ae | 330 | * LTTNG_KERNEL_CHANNEL |
baf20995 | 331 | * Returns a LTTng channel file descriptor |
8070f5c0 MD |
332 | * LTTNG_KERNEL_SESSION_START |
333 | * Starts tracing session | |
334 | * LTTNG_KERNEL_SESSION_STOP | |
335 | * Stops tracing session | |
336 | * LTTNG_KERNEL_METADATA | |
337 | * Returns a LTTng metadata file descriptor | |
ad1c05e1 MD |
338 | * |
339 | * The returned channel will be deleted when its file descriptor is closed. | |
340 | */ | |
341 | static | |
c0e31d2e | 342 | long lttng_session_ioctl(struct file *file, unsigned int cmd, unsigned long arg) |
ad1c05e1 | 343 | { |
c0e31d2e MD |
344 | struct ltt_session *session = file->private_data; |
345 | ||
ad1c05e1 | 346 | switch (cmd) { |
38d024ae | 347 | case LTTNG_KERNEL_CHANNEL: |
5dbbdb43 | 348 | return lttng_abi_create_channel(file, |
38d024ae | 349 | (struct lttng_kernel_channel __user *) arg, |
5dbbdb43 | 350 | PER_CPU_CHANNEL); |
38d024ae | 351 | case LTTNG_KERNEL_SESSION_START: |
c0e31d2e | 352 | return ltt_session_start(session); |
38d024ae | 353 | case LTTNG_KERNEL_SESSION_STOP: |
c0e31d2e | 354 | return ltt_session_stop(session); |
38d024ae | 355 | case LTTNG_KERNEL_METADATA: |
5dbbdb43 | 356 | return lttng_abi_create_channel(file, |
38d024ae | 357 | (struct lttng_kernel_channel __user *) arg, |
5dbbdb43 | 358 | METADATA_CHANNEL); |
ad1c05e1 MD |
359 | default: |
360 | return -ENOIOCTLCMD; | |
361 | } | |
362 | } | |
363 | ||
03037b98 MD |
364 | /* |
365 | * Called when the last file reference is dropped. | |
366 | * | |
367 | * Big fat note: channels and events are invariant for the whole session after | |
368 | * their creation. So this session destruction also destroys all channel and | |
369 | * event structures specific to this session (they are not destroyed when their | |
370 | * individual file is released). | |
371 | */ | |
ad1c05e1 | 372 | static |
03037b98 | 373 | int lttng_session_release(struct inode *inode, struct file *file) |
ad1c05e1 | 374 | { |
03037b98 | 375 | struct ltt_session *session = file->private_data; |
c269fff4 MD |
376 | |
377 | if (session) | |
378 | ltt_session_destroy(session); | |
11b5a3c2 | 379 | return 0; |
ad1c05e1 | 380 | } |
ad1c05e1 MD |
381 | |
382 | static const struct file_operations lttng_session_fops = { | |
03037b98 | 383 | .release = lttng_session_release, |
ad1c05e1 MD |
384 | .unlocked_ioctl = lttng_session_ioctl, |
385 | #ifdef CONFIG_COMPAT | |
03037b98 | 386 | .compat_ioctl = lttng_session_ioctl, |
ad1c05e1 | 387 | #endif |
11b5a3c2 | 388 | }; |
ad1c05e1 MD |
389 | |
390 | static | |
c0e31d2e | 391 | int lttng_abi_open_stream(struct file *channel_file) |
ad1c05e1 | 392 | { |
c0e31d2e | 393 | struct ltt_channel *channel = channel_file->private_data; |
ad1c05e1 MD |
394 | struct lib_ring_buffer *buf; |
395 | int stream_fd, ret; | |
11b5a3c2 | 396 | struct file *stream_file; |
ad1c05e1 | 397 | |
11b5a3c2 | 398 | buf = channel->ops->buffer_read_open(channel->chan); |
ad1c05e1 MD |
399 | if (!buf) |
400 | return -ENOENT; | |
401 | ||
1c25284c | 402 | stream_fd = get_unused_fd(); |
ad1c05e1 MD |
403 | if (stream_fd < 0) { |
404 | ret = stream_fd; | |
405 | goto fd_error; | |
406 | } | |
c0e31d2e | 407 | stream_file = anon_inode_getfile("[lttng_stream]", |
7f57c73c | 408 | &lib_ring_buffer_file_operations, |
ad1c05e1 | 409 | buf, O_RDWR); |
c0e31d2e MD |
410 | if (IS_ERR(stream_file)) { |
411 | ret = PTR_ERR(stream_file); | |
ad1c05e1 MD |
412 | goto file_error; |
413 | } | |
409453cb MD |
414 | /* |
415 | * OPEN_FMODE, called within anon_inode_getfile/alloc_file, don't honor | |
416 | * FMODE_LSEEK, FMODE_PREAD nor FMODE_PWRITE. We need to read from this | |
417 | * file descriptor, so we set FMODE_PREAD here. | |
418 | */ | |
d7b6f197 | 419 | stream_file->f_mode |= FMODE_PREAD; |
c0e31d2e | 420 | fd_install(stream_fd, stream_file); |
dda6a249 MD |
421 | /* |
422 | * The stream holds a reference to the channel within the generic ring | |
423 | * buffer library, so no need to hold a refcount on the channel and | |
424 | * session files here. | |
425 | */ | |
ad1c05e1 MD |
426 | return stream_fd; |
427 | ||
428 | file_error: | |
429 | put_unused_fd(stream_fd); | |
430 | fd_error: | |
11b5a3c2 | 431 | channel->ops->buffer_read_close(buf); |
ad1c05e1 MD |
432 | return ret; |
433 | } | |
434 | ||
653fe716 | 435 | static |
c0e31d2e | 436 | int lttng_abi_create_event(struct file *channel_file, |
38d024ae | 437 | struct lttng_kernel_event __user *uevent_param) |
653fe716 | 438 | { |
c0e31d2e | 439 | struct ltt_channel *channel = channel_file->private_data; |
653fe716 | 440 | struct ltt_event *event; |
38d024ae | 441 | struct lttng_kernel_event event_param; |
653fe716 | 442 | int event_fd, ret; |
11b5a3c2 | 443 | struct file *event_file; |
653fe716 MD |
444 | |
445 | if (copy_from_user(&event_param, uevent_param, sizeof(event_param))) | |
446 | return -EFAULT; | |
30bdb6e4 | 447 | event_param.name[LTTNG_SYM_NAME_LEN - 1] = '\0'; |
e0a7a7c4 | 448 | switch (event_param.instrumentation) { |
ab2277d6 | 449 | case LTTNG_KERNEL_KPROBE: |
e0a7a7c4 MD |
450 | event_param.u.kprobe.symbol_name[LTTNG_SYM_NAME_LEN - 1] = '\0'; |
451 | break; | |
ab2277d6 | 452 | case LTTNG_KERNEL_FUNCTION: |
e0a7a7c4 MD |
453 | event_param.u.ftrace.symbol_name[LTTNG_SYM_NAME_LEN - 1] = '\0'; |
454 | break; | |
455 | default: | |
456 | break; | |
457 | } | |
1c25284c | 458 | event_fd = get_unused_fd(); |
653fe716 MD |
459 | if (event_fd < 0) { |
460 | ret = event_fd; | |
461 | goto fd_error; | |
462 | } | |
c0e31d2e | 463 | event_file = anon_inode_getfile("[lttng_event]", |
3b923e5b | 464 | <tng_event_fops, |
03037b98 | 465 | NULL, O_RDWR); |
c0e31d2e MD |
466 | if (IS_ERR(event_file)) { |
467 | ret = PTR_ERR(event_file); | |
653fe716 MD |
468 | goto file_error; |
469 | } | |
03037b98 MD |
470 | /* |
471 | * We tolerate no failure path after event creation. It will stay | |
472 | * invariant for the rest of the session. | |
473 | */ | |
30bdb6e4 | 474 | event = ltt_event_create(channel, &event_param, NULL); |
03037b98 | 475 | if (!event) { |
271b6681 | 476 | ret = -EINVAL; |
d6d808f3 | 477 | goto event_error; |
03037b98 | 478 | } |
c0e31d2e MD |
479 | event_file->private_data = event; |
480 | fd_install(event_fd, event_file); | |
653fe716 | 481 | /* The event holds a reference on the channel */ |
b0caa15a | 482 | atomic_long_inc(&channel_file->f_count); |
653fe716 MD |
483 | return event_fd; |
484 | ||
03037b98 | 485 | event_error: |
c0e31d2e | 486 | fput(event_file); |
653fe716 MD |
487 | file_error: |
488 | put_unused_fd(event_fd); | |
489 | fd_error: | |
653fe716 MD |
490 | return ret; |
491 | } | |
ad1c05e1 MD |
492 | |
493 | /** | |
494 | * lttng_channel_ioctl - lttng syscall through ioctl | |
495 | * | |
c0e31d2e | 496 | * @file: the file |
ad1c05e1 MD |
497 | * @cmd: the command |
498 | * @arg: command arg | |
499 | * | |
500 | * This ioctl implements lttng commands: | |
38d024ae | 501 | * LTTNG_KERNEL_STREAM |
ad1c05e1 MD |
502 | * Returns an event stream file descriptor or failure. |
503 | * (typically, one event stream records events from one CPU) | |
38d024ae | 504 | * LTTNG_KERNEL_EVENT |
ad1c05e1 | 505 | * Returns an event file descriptor or failure. |
8070f5c0 MD |
506 | * LTTNG_KERNEL_CONTEXT |
507 | * Prepend a context field to each event in the channel | |
baf20995 | 508 | * |
baf20995 MD |
509 | * Channel and event file descriptors also hold a reference on the session. |
510 | */ | |
ad1c05e1 | 511 | static |
c0e31d2e | 512 | long lttng_channel_ioctl(struct file *file, unsigned int cmd, unsigned long arg) |
baf20995 | 513 | { |
8070f5c0 MD |
514 | struct ltt_channel *channel = file->private_data; |
515 | ||
baf20995 | 516 | switch (cmd) { |
38d024ae | 517 | case LTTNG_KERNEL_STREAM: |
c0e31d2e | 518 | return lttng_abi_open_stream(file); |
38d024ae MD |
519 | case LTTNG_KERNEL_EVENT: |
520 | return lttng_abi_create_event(file, (struct lttng_kernel_event __user *) arg); | |
8070f5c0 MD |
521 | case LTTNG_KERNEL_CONTEXT: |
522 | return lttng_abi_add_context(file, | |
523 | (struct lttng_kernel_context __user *) arg, | |
524 | &channel->ctx, channel->session); | |
baf20995 MD |
525 | default: |
526 | return -ENOIOCTLCMD; | |
527 | } | |
528 | } | |
529 | ||
5dbbdb43 MD |
530 | /** |
531 | * lttng_metadata_ioctl - lttng syscall through ioctl | |
532 | * | |
533 | * @file: the file | |
534 | * @cmd: the command | |
535 | * @arg: command arg | |
536 | * | |
537 | * This ioctl implements lttng commands: | |
38d024ae | 538 | * LTTNG_KERNEL_STREAM |
5dbbdb43 MD |
539 | * Returns an event stream file descriptor or failure. |
540 | * | |
541 | * Channel and event file descriptors also hold a reference on the session. | |
542 | */ | |
543 | static | |
544 | long lttng_metadata_ioctl(struct file *file, unsigned int cmd, unsigned long arg) | |
545 | { | |
546 | switch (cmd) { | |
38d024ae | 547 | case LTTNG_KERNEL_STREAM: |
5dbbdb43 MD |
548 | return lttng_abi_open_stream(file); |
549 | default: | |
550 | return -ENOIOCTLCMD; | |
551 | } | |
552 | } | |
553 | ||
3b923e5b MD |
554 | /* TODO: poll */ |
555 | #if 0 | |
653fe716 MD |
556 | /** |
557 | * lttng_channel_poll - lttng stream addition/removal monitoring | |
558 | * | |
c0e31d2e | 559 | * @file: the file |
653fe716 MD |
560 | * @wait: poll table |
561 | */ | |
c0e31d2e | 562 | unsigned int lttng_channel_poll(struct file *file, poll_table *wait) |
653fe716 | 563 | { |
c0e31d2e | 564 | struct ltt_channel *channel = file->private_data; |
653fe716 MD |
565 | unsigned int mask = 0; |
566 | ||
c0e31d2e | 567 | if (file->f_mode & FMODE_READ) { |
653fe716 | 568 | poll_wait_set_exclusive(wait); |
c0e31d2e | 569 | poll_wait(file, &channel->notify_wait, wait); |
653fe716 MD |
570 | |
571 | /* TODO: identify when the channel is being finalized. */ | |
572 | if (finalized) | |
573 | return POLLHUP; | |
574 | else | |
575 | return POLLIN | POLLRDNORM; | |
576 | } | |
577 | return mask; | |
578 | ||
579 | } | |
3b923e5b | 580 | #endif //0 |
653fe716 | 581 | |
0a84a57f MD |
582 | static |
583 | int lttng_channel_release(struct inode *inode, struct file *file) | |
584 | { | |
585 | struct ltt_channel *channel = file->private_data; | |
c269fff4 MD |
586 | |
587 | if (channel) | |
588 | fput(channel->session->file); | |
0a84a57f MD |
589 | return 0; |
590 | } | |
591 | ||
ad1c05e1 | 592 | static const struct file_operations lttng_channel_fops = { |
03037b98 | 593 | .release = lttng_channel_release, |
3b923e5b MD |
594 | /* TODO */ |
595 | #if 0 | |
653fe716 | 596 | .poll = lttng_channel_poll, |
3b923e5b | 597 | #endif //0 |
ad1c05e1 | 598 | .unlocked_ioctl = lttng_channel_ioctl, |
baf20995 | 599 | #ifdef CONFIG_COMPAT |
03037b98 | 600 | .compat_ioctl = lttng_channel_ioctl, |
baf20995 | 601 | #endif |
11b5a3c2 | 602 | }; |
baf20995 | 603 | |
5dbbdb43 MD |
604 | static const struct file_operations lttng_metadata_fops = { |
605 | .release = lttng_channel_release, | |
606 | .unlocked_ioctl = lttng_metadata_ioctl, | |
607 | #ifdef CONFIG_COMPAT | |
608 | .compat_ioctl = lttng_metadata_ioctl, | |
609 | #endif | |
610 | }; | |
611 | ||
8070f5c0 MD |
612 | /** |
613 | * lttng_event_ioctl - lttng syscall through ioctl | |
614 | * | |
615 | * @file: the file | |
616 | * @cmd: the command | |
617 | * @arg: command arg | |
618 | * | |
619 | * This ioctl implements lttng commands: | |
620 | * LTTNG_KERNEL_STREAM | |
621 | * Returns an event stream file descriptor or failure. | |
622 | * (typically, one event stream records events from one CPU) | |
623 | * LTTNG_KERNEL_EVENT | |
624 | * Returns an event file descriptor or failure. | |
625 | * LTTNG_KERNEL_CONTEXT | |
626 | * Prepend a context field to each record of this event | |
627 | */ | |
628 | static | |
629 | long lttng_event_ioctl(struct file *file, unsigned int cmd, unsigned long arg) | |
630 | { | |
631 | struct ltt_event *event = file->private_data; | |
632 | ||
633 | switch (cmd) { | |
634 | case LTTNG_KERNEL_CONTEXT: | |
635 | return lttng_abi_add_context(file, | |
636 | (struct lttng_kernel_context __user *) arg, | |
637 | &event->ctx, event->chan->session); | |
638 | default: | |
639 | return -ENOIOCTLCMD; | |
640 | } | |
641 | } | |
642 | ||
0a84a57f MD |
643 | static |
644 | int lttng_event_release(struct inode *inode, struct file *file) | |
645 | { | |
646 | struct ltt_event *event = file->private_data; | |
c269fff4 | 647 | |
aa7c23a9 | 648 | if (event) |
c269fff4 | 649 | fput(event->chan->file); |
0a84a57f MD |
650 | return 0; |
651 | } | |
652 | ||
3b923e5b | 653 | /* TODO: filter control ioctl */ |
0a84a57f MD |
654 | static const struct file_operations lttng_event_fops = { |
655 | .release = lttng_event_release, | |
8070f5c0 MD |
656 | .unlocked_ioctl = lttng_event_ioctl, |
657 | #ifdef CONFIG_COMPAT | |
658 | .compat_ioctl = lttng_event_ioctl, | |
659 | #endif | |
11b5a3c2 | 660 | }; |
0a84a57f | 661 | |
1c25284c | 662 | int __init ltt_debugfs_abi_init(void) |
baf20995 MD |
663 | { |
664 | int ret = 0; | |
665 | ||
6d2a620c | 666 | wrapper_vmalloc_sync_all(); |
11b5a3c2 | 667 | lttng_dentry = debugfs_create_file("lttng", S_IWUSR, NULL, NULL, |
f3d01b96 | 668 | <tng_fops); |
11b5a3c2 | 669 | if (IS_ERR(lttng_dentry) || !lttng_dentry) { |
baf20995 MD |
670 | printk(KERN_ERR "Error creating LTTng control file\n"); |
671 | ret = -ENOMEM; | |
672 | goto error; | |
673 | } | |
674 | error: | |
675 | return ret; | |
676 | } | |
677 | ||
1c25284c | 678 | void __exit ltt_debugfs_abi_exit(void) |
baf20995 | 679 | { |
11b5a3c2 | 680 | debugfs_remove(lttng_dentry); |
baf20995 | 681 | } |