4 * Copyright 2010 (c) - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
8 * Mimic system calls for:
9 * - session creation, returns a file descriptor or failure.
10 * - channel creation, returns a file descriptor or failure.
11 * - Takes a session file descriptor parameter
12 * - Takes all channel options as parameters.
13 * - event creation, returns a file descriptor or failure.
14 * - Takes an event name as parameter
15 * - Takes an instrumentation source as parameter
16 * - e.g. tracepoints, dynamic_probes...
17 * - Takes instrumentation source specific arguments.
20 #include <linux/debugfs.h>
23 * This is LTTng's own personal way to create a system call as an external
24 * module. We use ioctl() on /sys/kernel/debug/lttng.
27 static struct dentry
*lttng_dentry
;
30 * LTTng DebugFS ABI structures.
33 struct lttng_channel
{
34 int session
; /* Session file descriptor */
35 int overwrite
; /* 1: overwrite, 0: discard */
38 unsigned int switch_timer_interval
;
39 unsigned int read_timer_interval
;
43 int channel
; /* Channel file descriptor */
44 enum instrum_type itype
;
48 int lttng_abi_create_session(void)
50 struct ltt_session
*session
;
51 struct file
*session_file
;
54 session
= ltt_session_create()
57 session_fd
= get_unused_fd_flags(O_RDWR
);
62 session_file
= anon_inode_getfile("[lttng_session]",
65 if (IS_ERR(session_file
)) {
66 ret
= PTR_ERR(session_file
);
72 put_unused_fd(session_fd
);
74 ltt_session_destroy(session
);
78 int lttng_abi_create_channel(struct lttng_channel __user
*uchan_param
)
80 struct ltt_channel
*chan
;
81 struct file
*chan_file
;
82 struct lttng_channel chan_param
;
85 if (copy_from_user(&chan_param
, ucham_param
, sizeof(chan_param
)))
87 /* TODO: fetch session pointer from file descriptor */
88 chan
= ltt_channel_create();
91 chan_fd
= get_unused_fd_flags(O_RDWR
);
96 chan_file
= anon_inode_getfile("[lttng_channel]",
99 if (IS_ERR(chan_file
)) {
100 ret
= PTR_ERR(chan_file
);
106 put_unused_fd(chan_fd
);
108 ltt_channel_destroy(chan
);
113 * lttng_ioctl - lttng syscall through ioctl
119 * This ioctl implements lttng commands:
121 * Returns a LTTng trace session file descriptor
123 * Returns a LTTng channel file descriptor
125 * Returns a file descriptor or failure.
127 * The returned session will be deleted when its file descriptor is closed.
128 * Channel and event file descriptors also hold a reference on the session.
130 long lttng_ioctl(struct file
*filp
, unsigned int cmd
, unsigned long arg
)
132 struct inode
*inode
= filp
->f_dentry
->d_inode
;
136 return lttng_abi_create_session();
138 return lttng_abi_create_channel((struct lttng_channel __user
*)arg
);
140 return lttng_abi_create_event((struct lttng_event __user
*)arg
);
147 long lttng_compat_ioctl(struct file
*filp
, unsigned int cmd
, unsigned long arg
)
149 struct inode
*inode
= filp
->f_dentry
->d_inode
;
153 return lttng_abi_create_session();
155 return lttng_abi_create_channel((struct lttng_channel __user
*)arg
);
157 return lttng_abi_create_event((struct lttng_event __user
*)arg
);
164 const struct file_operations lttng_file_operations
= {
165 .unlocked_ioctl
= lttng_ioctl
,
167 .compat_ioctl
= lttng_compat_ioctl
,
171 static int __init
ltt_debugfs_abi_init(void)
175 lttng_dentry
= debugfs_create_file("lttng", NULL
);
176 if (IS_ERR(lttng_dentry
) || !lttng_dentry
)
177 printk(KERN_ERR
"Error creating LTTng control file\n");
185 static void __exit
ltt_debugfs_abi_exit(void)
187 debugfs_remote(lttng_dentry
);