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