2 * Copyright (C) 2008 Mathieu Desnoyers
4 * Dual LGPL v2.1/GPL v2 license.
7 #include <linux/module.h>
8 #include <linux/marker.h>
9 #include <linux/uaccess.h>
10 #include <linux/gfp.h>
12 #include <linux/debugfs.h>
13 #include <linux/slab.h>
15 #include "ltt-type-serializer.h"
17 #define LTT_WRITE_EVENT_FILE "write_event"
19 DEFINE_MARKER(userspace
, event
, "string %s");
20 static struct dentry
*ltt_event_file
;
23 * write_event - write a userspace string into the trace system
25 * @user_buf: user string
26 * @count: length to copy, including the final NULL
29 * Copy a string into a trace event, in channel "userspace", event "event".
30 * Copies until either \n or \0 is reached.
31 * On success, returns the number of bytes copied from the source, including the
32 * \n or \0 character (if there was one in the count range). It cannot return
34 * Inspired from tracing_mark_write implementation from Steven Rostedt and
38 ssize_t
write_event(struct file
*file
, const char __user
*user_buf
,
39 size_t count
, loff_t
*ppos
)
41 struct marker
*marker
;
46 buf
= kmalloc(count
+ 1, GFP_KERNEL
);
51 copycount
= strncpy_from_user(buf
, user_buf
, count
);
56 /* Cut from the first nil or newline. */
57 buf
[copycount
] = '\0';
58 end
= strchr(buf
, '\n');
61 copycount
= end
- buf
;
63 /* Add final \0 to copycount */
65 marker
= &GET_MARKER(userspace
, event
);
66 ltt_specialized_trace(marker
, marker
->single
.probe_private
, buf
,
67 copycount
, sizeof(char));
68 /* If there is no \0 nor \n in count, do not return a larger value */
69 ret
= min_t(size_t, copycount
, count
);
76 static const struct file_operations ltt_userspace_operations
= {
80 static int __init
ltt_userspace_init(void)
82 struct dentry
*ltt_root_dentry
;
85 ltt_root_dentry
= get_ltt_root();
86 if (!ltt_root_dentry
) {
91 ltt_event_file
= debugfs_create_file(LTT_WRITE_EVENT_FILE
,
95 <t_userspace_operations
);
96 if (IS_ERR(ltt_event_file
) || !ltt_event_file
) {
98 "ltt_userspace_init: failed to create file %s\n",
99 LTT_WRITE_EVENT_FILE
);
111 static void __exit
ltt_userspace_exit(void)
113 debugfs_remove(ltt_event_file
);
117 module_init(ltt_userspace_init
);
118 module_exit(ltt_userspace_exit
);
120 MODULE_LICENSE("GPL and additional rights");
121 MODULE_AUTHOR("Mathieu Desnoyers <mathieu.desnoyers@polymtl.ca>");
122 MODULE_DESCRIPTION("Linux Trace Toolkit Userspace Event");