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: |
8070f5c0 | 162 | return -ENOSYS; |
25b2f99a MD |
163 | case LTTNG_KERNEL_CONTEXT_COMM: |
164 | return lttng_add_comm_to_ctx(ctx); | |
8070f5c0 MD |
165 | default: |
166 | return -EINVAL; | |
167 | } | |
168 | } | |
169 | ||
ad1c05e1 MD |
170 | /** |
171 | * lttng_ioctl - lttng syscall through ioctl | |
172 | * | |
c0e31d2e | 173 | * @file: the file |
ad1c05e1 MD |
174 | * @cmd: the command |
175 | * @arg: command arg | |
176 | * | |
177 | * This ioctl implements lttng commands: | |
38d024ae | 178 | * LTTNG_KERNEL_SESSION |
ad1c05e1 | 179 | * Returns a LTTng trace session file descriptor |
271b6681 MD |
180 | * LTTNG_KERNEL_TRACER_VERSION |
181 | * Returns the LTTng kernel tracer version | |
182 | * LTTNG_KERNEL_TRACEPOINT_LIST | |
183 | * Returns a file descriptor listing available tracepoints | |
ad1c05e1 MD |
184 | * |
185 | * The returned session will be deleted when its file descriptor is closed. | |
186 | */ | |
187 | static | |
c0e31d2e | 188 | long lttng_ioctl(struct file *file, unsigned int cmd, unsigned long arg) |
ad1c05e1 MD |
189 | { |
190 | switch (cmd) { | |
38d024ae | 191 | case LTTNG_KERNEL_SESSION: |
ad1c05e1 | 192 | return lttng_abi_create_session(); |
80c16bcf MD |
193 | case LTTNG_KERNEL_TRACER_VERSION: |
194 | return lttng_abi_tracer_version(file, | |
195 | (struct lttng_kernel_tracer_version __user *) arg); | |
271b6681 MD |
196 | case LTTNG_KERNEL_TRACEPOINT_LIST: |
197 | return lttng_abi_tracepoint_list(); | |
ad1c05e1 MD |
198 | default: |
199 | return -ENOIOCTLCMD; | |
200 | } | |
201 | } | |
202 | ||
ad1c05e1 MD |
203 | static const struct file_operations lttng_fops = { |
204 | .unlocked_ioctl = lttng_ioctl, | |
205 | #ifdef CONFIG_COMPAT | |
03037b98 | 206 | .compat_ioctl = lttng_ioctl, |
ad1c05e1 | 207 | #endif |
11b5a3c2 | 208 | }; |
ad1c05e1 | 209 | |
5dbbdb43 MD |
210 | /* |
211 | * We tolerate no failure in this function (if one happens, we print a dmesg | |
212 | * error, but cannot return any error, because the channel information is | |
213 | * invariant. | |
214 | */ | |
215 | static | |
216 | void lttng_metadata_create_events(struct file *channel_file) | |
217 | { | |
218 | struct ltt_channel *channel = channel_file->private_data; | |
e70a4758 | 219 | static struct lttng_kernel_event metadata_params = { |
ab2277d6 | 220 | .instrumentation = LTTNG_KERNEL_TRACEPOINT, |
e70a4758 MD |
221 | .name = "lttng_metadata", |
222 | }; | |
5dbbdb43 MD |
223 | struct ltt_event *event; |
224 | int ret; | |
5dbbdb43 | 225 | |
5dbbdb43 MD |
226 | /* |
227 | * We tolerate no failure path after event creation. It will stay | |
228 | * invariant for the rest of the session. | |
229 | */ | |
30bdb6e4 | 230 | event = ltt_event_create(channel, &metadata_params, NULL); |
5dbbdb43 | 231 | if (!event) { |
588e6a7f | 232 | ret = -EINVAL; |
271b6681 | 233 | goto create_error; |
5dbbdb43 MD |
234 | } |
235 | return; | |
236 | ||
85a9ca7f | 237 | create_error: |
5dbbdb43 MD |
238 | WARN_ON(1); |
239 | return; /* not allowed to return error */ | |
240 | } | |
241 | ||
242 | static | |
c0e31d2e | 243 | int lttng_abi_create_channel(struct file *session_file, |
38d024ae | 244 | struct lttng_kernel_channel __user *uchan_param, |
5dbbdb43 | 245 | enum channel_type channel_type) |
baf20995 | 246 | { |
c0e31d2e | 247 | struct ltt_session *session = session_file->private_data; |
5dbbdb43 MD |
248 | const struct file_operations *fops; |
249 | const char *transport_name; | |
baf20995 | 250 | struct ltt_channel *chan; |
c0e31d2e | 251 | struct file *chan_file; |
38d024ae | 252 | struct lttng_kernel_channel chan_param; |
baf20995 | 253 | int chan_fd; |
ad1c05e1 | 254 | int ret = 0; |
baf20995 | 255 | |
653fe716 | 256 | if (copy_from_user(&chan_param, uchan_param, sizeof(chan_param))) |
baf20995 | 257 | return -EFAULT; |
1c25284c | 258 | chan_fd = get_unused_fd(); |
baf20995 MD |
259 | if (chan_fd < 0) { |
260 | ret = chan_fd; | |
261 | goto fd_error; | |
262 | } | |
c0e31d2e | 263 | chan_file = anon_inode_getfile("[lttng_channel]", |
ad1c05e1 | 264 | <tng_channel_fops, |
03037b98 | 265 | NULL, O_RDWR); |
c0e31d2e MD |
266 | if (IS_ERR(chan_file)) { |
267 | ret = PTR_ERR(chan_file); | |
baf20995 MD |
268 | goto file_error; |
269 | } | |
5dbbdb43 MD |
270 | switch (channel_type) { |
271 | case PER_CPU_CHANNEL: | |
272 | transport_name = chan_param.overwrite ? | |
273 | "relay-overwrite" : "relay-discard"; | |
274 | fops = <tng_channel_fops; | |
275 | break; | |
5dbbdb43 | 276 | case METADATA_CHANNEL: |
881833e3 | 277 | transport_name = "relay-metadata"; |
5dbbdb43 MD |
278 | fops = <tng_metadata_fops; |
279 | break; | |
280 | default: | |
281 | transport_name = "<unknown>"; | |
282 | break; | |
283 | } | |
03037b98 MD |
284 | /* |
285 | * We tolerate no failure path after channel creation. It will stay | |
286 | * invariant for the rest of the session. | |
287 | */ | |
5dbbdb43 | 288 | chan = ltt_channel_create(session, transport_name, NULL, |
11b5a3c2 MD |
289 | chan_param.subbuf_size, |
290 | chan_param.num_subbuf, | |
291 | chan_param.switch_timer_interval, | |
292 | chan_param.read_timer_interval); | |
03037b98 | 293 | if (!chan) { |
f3d01b96 | 294 | ret = -EINVAL; |
03037b98 MD |
295 | goto chan_error; |
296 | } | |
11b5a3c2 | 297 | chan->file = chan_file; |
c0e31d2e MD |
298 | chan_file->private_data = chan; |
299 | fd_install(chan_fd, chan_file); | |
cd4bd11f | 300 | if (channel_type == METADATA_CHANNEL) { |
cd4bd11f | 301 | session->metadata = chan; |
4f1c3952 | 302 | lttng_metadata_create_events(chan_file); |
cd4bd11f | 303 | } |
5dbbdb43 | 304 | |
ad1c05e1 | 305 | /* The channel created holds a reference on the session */ |
b0caa15a | 306 | atomic_long_inc(&session_file->f_count); |
ad1c05e1 | 307 | |
baf20995 MD |
308 | return chan_fd; |
309 | ||
03037b98 | 310 | chan_error: |
c0e31d2e | 311 | fput(chan_file); |
baf20995 MD |
312 | file_error: |
313 | put_unused_fd(chan_fd); | |
314 | fd_error: | |
baf20995 MD |
315 | return ret; |
316 | } | |
317 | ||
318 | /** | |
ad1c05e1 | 319 | * lttng_session_ioctl - lttng session fd ioctl |
baf20995 | 320 | * |
c0e31d2e | 321 | * @file: the file |
baf20995 MD |
322 | * @cmd: the command |
323 | * @arg: command arg | |
324 | * | |
325 | * This ioctl implements lttng commands: | |
38d024ae | 326 | * LTTNG_KERNEL_CHANNEL |
baf20995 | 327 | * Returns a LTTng channel file descriptor |
8070f5c0 MD |
328 | * LTTNG_KERNEL_SESSION_START |
329 | * Starts tracing session | |
330 | * LTTNG_KERNEL_SESSION_STOP | |
331 | * Stops tracing session | |
332 | * LTTNG_KERNEL_METADATA | |
333 | * Returns a LTTng metadata file descriptor | |
ad1c05e1 MD |
334 | * |
335 | * The returned channel will be deleted when its file descriptor is closed. | |
336 | */ | |
337 | static | |
c0e31d2e | 338 | long lttng_session_ioctl(struct file *file, unsigned int cmd, unsigned long arg) |
ad1c05e1 | 339 | { |
c0e31d2e MD |
340 | struct ltt_session *session = file->private_data; |
341 | ||
ad1c05e1 | 342 | switch (cmd) { |
38d024ae | 343 | case LTTNG_KERNEL_CHANNEL: |
5dbbdb43 | 344 | return lttng_abi_create_channel(file, |
38d024ae | 345 | (struct lttng_kernel_channel __user *) arg, |
5dbbdb43 | 346 | PER_CPU_CHANNEL); |
38d024ae | 347 | case LTTNG_KERNEL_SESSION_START: |
c0e31d2e | 348 | return ltt_session_start(session); |
38d024ae | 349 | case LTTNG_KERNEL_SESSION_STOP: |
c0e31d2e | 350 | return ltt_session_stop(session); |
38d024ae | 351 | case LTTNG_KERNEL_METADATA: |
5dbbdb43 | 352 | return lttng_abi_create_channel(file, |
38d024ae | 353 | (struct lttng_kernel_channel __user *) arg, |
5dbbdb43 | 354 | METADATA_CHANNEL); |
ad1c05e1 MD |
355 | default: |
356 | return -ENOIOCTLCMD; | |
357 | } | |
358 | } | |
359 | ||
03037b98 MD |
360 | /* |
361 | * Called when the last file reference is dropped. | |
362 | * | |
363 | * Big fat note: channels and events are invariant for the whole session after | |
364 | * their creation. So this session destruction also destroys all channel and | |
365 | * event structures specific to this session (they are not destroyed when their | |
366 | * individual file is released). | |
367 | */ | |
ad1c05e1 | 368 | static |
03037b98 | 369 | int lttng_session_release(struct inode *inode, struct file *file) |
ad1c05e1 | 370 | { |
03037b98 | 371 | struct ltt_session *session = file->private_data; |
c269fff4 MD |
372 | |
373 | if (session) | |
374 | ltt_session_destroy(session); | |
11b5a3c2 | 375 | return 0; |
ad1c05e1 | 376 | } |
ad1c05e1 MD |
377 | |
378 | static const struct file_operations lttng_session_fops = { | |
03037b98 | 379 | .release = lttng_session_release, |
ad1c05e1 MD |
380 | .unlocked_ioctl = lttng_session_ioctl, |
381 | #ifdef CONFIG_COMPAT | |
03037b98 | 382 | .compat_ioctl = lttng_session_ioctl, |
ad1c05e1 | 383 | #endif |
11b5a3c2 | 384 | }; |
ad1c05e1 MD |
385 | |
386 | static | |
c0e31d2e | 387 | int lttng_abi_open_stream(struct file *channel_file) |
ad1c05e1 | 388 | { |
c0e31d2e | 389 | struct ltt_channel *channel = channel_file->private_data; |
ad1c05e1 MD |
390 | struct lib_ring_buffer *buf; |
391 | int stream_fd, ret; | |
11b5a3c2 | 392 | struct file *stream_file; |
ad1c05e1 | 393 | |
11b5a3c2 | 394 | buf = channel->ops->buffer_read_open(channel->chan); |
ad1c05e1 MD |
395 | if (!buf) |
396 | return -ENOENT; | |
397 | ||
1c25284c | 398 | stream_fd = get_unused_fd(); |
ad1c05e1 MD |
399 | if (stream_fd < 0) { |
400 | ret = stream_fd; | |
401 | goto fd_error; | |
402 | } | |
c0e31d2e | 403 | stream_file = anon_inode_getfile("[lttng_stream]", |
7f57c73c | 404 | &lib_ring_buffer_file_operations, |
ad1c05e1 | 405 | buf, O_RDWR); |
c0e31d2e MD |
406 | if (IS_ERR(stream_file)) { |
407 | ret = PTR_ERR(stream_file); | |
ad1c05e1 MD |
408 | goto file_error; |
409 | } | |
409453cb MD |
410 | /* |
411 | * OPEN_FMODE, called within anon_inode_getfile/alloc_file, don't honor | |
412 | * FMODE_LSEEK, FMODE_PREAD nor FMODE_PWRITE. We need to read from this | |
413 | * file descriptor, so we set FMODE_PREAD here. | |
414 | */ | |
d7b6f197 | 415 | stream_file->f_mode |= FMODE_PREAD; |
c0e31d2e | 416 | fd_install(stream_fd, stream_file); |
dda6a249 MD |
417 | /* |
418 | * The stream holds a reference to the channel within the generic ring | |
419 | * buffer library, so no need to hold a refcount on the channel and | |
420 | * session files here. | |
421 | */ | |
ad1c05e1 MD |
422 | return stream_fd; |
423 | ||
424 | file_error: | |
425 | put_unused_fd(stream_fd); | |
426 | fd_error: | |
11b5a3c2 | 427 | channel->ops->buffer_read_close(buf); |
ad1c05e1 MD |
428 | return ret; |
429 | } | |
430 | ||
653fe716 | 431 | static |
c0e31d2e | 432 | int lttng_abi_create_event(struct file *channel_file, |
38d024ae | 433 | struct lttng_kernel_event __user *uevent_param) |
653fe716 | 434 | { |
c0e31d2e | 435 | struct ltt_channel *channel = channel_file->private_data; |
653fe716 | 436 | struct ltt_event *event; |
38d024ae | 437 | struct lttng_kernel_event event_param; |
653fe716 | 438 | int event_fd, ret; |
11b5a3c2 | 439 | struct file *event_file; |
653fe716 MD |
440 | |
441 | if (copy_from_user(&event_param, uevent_param, sizeof(event_param))) | |
442 | return -EFAULT; | |
30bdb6e4 | 443 | event_param.name[LTTNG_SYM_NAME_LEN - 1] = '\0'; |
e0a7a7c4 | 444 | switch (event_param.instrumentation) { |
ab2277d6 | 445 | case LTTNG_KERNEL_KPROBE: |
e0a7a7c4 MD |
446 | event_param.u.kprobe.symbol_name[LTTNG_SYM_NAME_LEN - 1] = '\0'; |
447 | break; | |
ab2277d6 | 448 | case LTTNG_KERNEL_FUNCTION: |
e0a7a7c4 MD |
449 | event_param.u.ftrace.symbol_name[LTTNG_SYM_NAME_LEN - 1] = '\0'; |
450 | break; | |
451 | default: | |
452 | break; | |
453 | } | |
1c25284c | 454 | event_fd = get_unused_fd(); |
653fe716 MD |
455 | if (event_fd < 0) { |
456 | ret = event_fd; | |
457 | goto fd_error; | |
458 | } | |
c0e31d2e | 459 | event_file = anon_inode_getfile("[lttng_event]", |
3b923e5b | 460 | <tng_event_fops, |
03037b98 | 461 | NULL, O_RDWR); |
c0e31d2e MD |
462 | if (IS_ERR(event_file)) { |
463 | ret = PTR_ERR(event_file); | |
653fe716 MD |
464 | goto file_error; |
465 | } | |
03037b98 MD |
466 | /* |
467 | * We tolerate no failure path after event creation. It will stay | |
468 | * invariant for the rest of the session. | |
469 | */ | |
30bdb6e4 | 470 | event = ltt_event_create(channel, &event_param, NULL); |
03037b98 | 471 | if (!event) { |
271b6681 | 472 | ret = -EINVAL; |
d6d808f3 | 473 | goto event_error; |
03037b98 | 474 | } |
c0e31d2e MD |
475 | event_file->private_data = event; |
476 | fd_install(event_fd, event_file); | |
653fe716 | 477 | /* The event holds a reference on the channel */ |
b0caa15a | 478 | atomic_long_inc(&channel_file->f_count); |
653fe716 MD |
479 | return event_fd; |
480 | ||
03037b98 | 481 | event_error: |
c0e31d2e | 482 | fput(event_file); |
653fe716 MD |
483 | file_error: |
484 | put_unused_fd(event_fd); | |
485 | fd_error: | |
653fe716 MD |
486 | return ret; |
487 | } | |
ad1c05e1 MD |
488 | |
489 | /** | |
490 | * lttng_channel_ioctl - lttng syscall through ioctl | |
491 | * | |
c0e31d2e | 492 | * @file: the file |
ad1c05e1 MD |
493 | * @cmd: the command |
494 | * @arg: command arg | |
495 | * | |
496 | * This ioctl implements lttng commands: | |
38d024ae | 497 | * LTTNG_KERNEL_STREAM |
ad1c05e1 MD |
498 | * Returns an event stream file descriptor or failure. |
499 | * (typically, one event stream records events from one CPU) | |
38d024ae | 500 | * LTTNG_KERNEL_EVENT |
ad1c05e1 | 501 | * Returns an event file descriptor or failure. |
8070f5c0 MD |
502 | * LTTNG_KERNEL_CONTEXT |
503 | * Prepend a context field to each event in the channel | |
baf20995 | 504 | * |
baf20995 MD |
505 | * Channel and event file descriptors also hold a reference on the session. |
506 | */ | |
ad1c05e1 | 507 | static |
c0e31d2e | 508 | long lttng_channel_ioctl(struct file *file, unsigned int cmd, unsigned long arg) |
baf20995 | 509 | { |
8070f5c0 MD |
510 | struct ltt_channel *channel = file->private_data; |
511 | ||
baf20995 | 512 | switch (cmd) { |
38d024ae | 513 | case LTTNG_KERNEL_STREAM: |
c0e31d2e | 514 | return lttng_abi_open_stream(file); |
38d024ae MD |
515 | case LTTNG_KERNEL_EVENT: |
516 | return lttng_abi_create_event(file, (struct lttng_kernel_event __user *) arg); | |
8070f5c0 MD |
517 | case LTTNG_KERNEL_CONTEXT: |
518 | return lttng_abi_add_context(file, | |
519 | (struct lttng_kernel_context __user *) arg, | |
520 | &channel->ctx, channel->session); | |
baf20995 MD |
521 | default: |
522 | return -ENOIOCTLCMD; | |
523 | } | |
524 | } | |
525 | ||
5dbbdb43 MD |
526 | /** |
527 | * lttng_metadata_ioctl - lttng syscall through ioctl | |
528 | * | |
529 | * @file: the file | |
530 | * @cmd: the command | |
531 | * @arg: command arg | |
532 | * | |
533 | * This ioctl implements lttng commands: | |
38d024ae | 534 | * LTTNG_KERNEL_STREAM |
5dbbdb43 MD |
535 | * Returns an event stream file descriptor or failure. |
536 | * | |
537 | * Channel and event file descriptors also hold a reference on the session. | |
538 | */ | |
539 | static | |
540 | long lttng_metadata_ioctl(struct file *file, unsigned int cmd, unsigned long arg) | |
541 | { | |
542 | switch (cmd) { | |
38d024ae | 543 | case LTTNG_KERNEL_STREAM: |
5dbbdb43 MD |
544 | return lttng_abi_open_stream(file); |
545 | default: | |
546 | return -ENOIOCTLCMD; | |
547 | } | |
548 | } | |
549 | ||
3b923e5b MD |
550 | /* TODO: poll */ |
551 | #if 0 | |
653fe716 MD |
552 | /** |
553 | * lttng_channel_poll - lttng stream addition/removal monitoring | |
554 | * | |
c0e31d2e | 555 | * @file: the file |
653fe716 MD |
556 | * @wait: poll table |
557 | */ | |
c0e31d2e | 558 | unsigned int lttng_channel_poll(struct file *file, poll_table *wait) |
653fe716 | 559 | { |
c0e31d2e | 560 | struct ltt_channel *channel = file->private_data; |
653fe716 MD |
561 | unsigned int mask = 0; |
562 | ||
c0e31d2e | 563 | if (file->f_mode & FMODE_READ) { |
653fe716 | 564 | poll_wait_set_exclusive(wait); |
c0e31d2e | 565 | poll_wait(file, &channel->notify_wait, wait); |
653fe716 MD |
566 | |
567 | /* TODO: identify when the channel is being finalized. */ | |
568 | if (finalized) | |
569 | return POLLHUP; | |
570 | else | |
571 | return POLLIN | POLLRDNORM; | |
572 | } | |
573 | return mask; | |
574 | ||
575 | } | |
3b923e5b | 576 | #endif //0 |
653fe716 | 577 | |
0a84a57f MD |
578 | static |
579 | int lttng_channel_release(struct inode *inode, struct file *file) | |
580 | { | |
581 | struct ltt_channel *channel = file->private_data; | |
c269fff4 MD |
582 | |
583 | if (channel) | |
584 | fput(channel->session->file); | |
0a84a57f MD |
585 | return 0; |
586 | } | |
587 | ||
ad1c05e1 | 588 | static const struct file_operations lttng_channel_fops = { |
03037b98 | 589 | .release = lttng_channel_release, |
3b923e5b MD |
590 | /* TODO */ |
591 | #if 0 | |
653fe716 | 592 | .poll = lttng_channel_poll, |
3b923e5b | 593 | #endif //0 |
ad1c05e1 | 594 | .unlocked_ioctl = lttng_channel_ioctl, |
baf20995 | 595 | #ifdef CONFIG_COMPAT |
03037b98 | 596 | .compat_ioctl = lttng_channel_ioctl, |
baf20995 | 597 | #endif |
11b5a3c2 | 598 | }; |
baf20995 | 599 | |
5dbbdb43 MD |
600 | static const struct file_operations lttng_metadata_fops = { |
601 | .release = lttng_channel_release, | |
602 | .unlocked_ioctl = lttng_metadata_ioctl, | |
603 | #ifdef CONFIG_COMPAT | |
604 | .compat_ioctl = lttng_metadata_ioctl, | |
605 | #endif | |
606 | }; | |
607 | ||
8070f5c0 MD |
608 | /** |
609 | * lttng_event_ioctl - lttng syscall through ioctl | |
610 | * | |
611 | * @file: the file | |
612 | * @cmd: the command | |
613 | * @arg: command arg | |
614 | * | |
615 | * This ioctl implements lttng commands: | |
616 | * LTTNG_KERNEL_STREAM | |
617 | * Returns an event stream file descriptor or failure. | |
618 | * (typically, one event stream records events from one CPU) | |
619 | * LTTNG_KERNEL_EVENT | |
620 | * Returns an event file descriptor or failure. | |
621 | * LTTNG_KERNEL_CONTEXT | |
622 | * Prepend a context field to each record of this event | |
623 | */ | |
624 | static | |
625 | long lttng_event_ioctl(struct file *file, unsigned int cmd, unsigned long arg) | |
626 | { | |
627 | struct ltt_event *event = file->private_data; | |
628 | ||
629 | switch (cmd) { | |
630 | case LTTNG_KERNEL_CONTEXT: | |
631 | return lttng_abi_add_context(file, | |
632 | (struct lttng_kernel_context __user *) arg, | |
633 | &event->ctx, event->chan->session); | |
634 | default: | |
635 | return -ENOIOCTLCMD; | |
636 | } | |
637 | } | |
638 | ||
0a84a57f MD |
639 | static |
640 | int lttng_event_release(struct inode *inode, struct file *file) | |
641 | { | |
642 | struct ltt_event *event = file->private_data; | |
c269fff4 | 643 | |
aa7c23a9 | 644 | if (event) |
c269fff4 | 645 | fput(event->chan->file); |
0a84a57f MD |
646 | return 0; |
647 | } | |
648 | ||
3b923e5b | 649 | /* TODO: filter control ioctl */ |
0a84a57f MD |
650 | static const struct file_operations lttng_event_fops = { |
651 | .release = lttng_event_release, | |
8070f5c0 MD |
652 | .unlocked_ioctl = lttng_event_ioctl, |
653 | #ifdef CONFIG_COMPAT | |
654 | .compat_ioctl = lttng_event_ioctl, | |
655 | #endif | |
11b5a3c2 | 656 | }; |
0a84a57f | 657 | |
1c25284c | 658 | int __init ltt_debugfs_abi_init(void) |
baf20995 MD |
659 | { |
660 | int ret = 0; | |
661 | ||
6d2a620c | 662 | wrapper_vmalloc_sync_all(); |
11b5a3c2 | 663 | lttng_dentry = debugfs_create_file("lttng", S_IWUSR, NULL, NULL, |
f3d01b96 | 664 | <tng_fops); |
11b5a3c2 | 665 | if (IS_ERR(lttng_dentry) || !lttng_dentry) { |
baf20995 MD |
666 | printk(KERN_ERR "Error creating LTTng control file\n"); |
667 | ret = -ENOMEM; | |
668 | goto error; | |
669 | } | |
670 | error: | |
671 | return ret; | |
672 | } | |
673 | ||
1c25284c | 674 | void __exit ltt_debugfs_abi_exit(void) |
baf20995 | 675 | { |
11b5a3c2 | 676 | debugfs_remove(lttng_dentry); |
baf20995 | 677 | } |