Commit | Line | Data |
---|---|---|
02119ee5 MD |
1 | /* |
2 | * ltt-probes.c | |
3 | * | |
4 | * Copyright 2010 (c) - Mathieu Desnoyers <mathieu.desnoyers@efficios.com> | |
5 | * | |
6 | * Holds LTTng probes registry. | |
17baffe2 MD |
7 | * |
8 | * Dual LGPL v2.1/GPL v2 license. | |
02119ee5 MD |
9 | */ |
10 | ||
11 | #include <linux/module.h> | |
12 | #include <linux/list.h> | |
13 | #include <linux/mutex.h> | |
271b6681 | 14 | #include <linux/seq_file.h> |
02119ee5 | 15 | |
85a9ca7f | 16 | #include "ltt-events.h" |
02119ee5 MD |
17 | |
18 | static LIST_HEAD(probe_list); | |
19 | static DEFINE_MUTEX(probe_mutex); | |
02119ee5 | 20 | |
85a9ca7f MD |
21 | static |
22 | const struct lttng_event_desc *find_event(const char *name) | |
02119ee5 | 23 | { |
85a9ca7f MD |
24 | struct lttng_probe_desc *probe_desc; |
25 | int i; | |
02119ee5 | 26 | |
85a9ca7f MD |
27 | list_for_each_entry(probe_desc, &probe_list, head) { |
28 | for (i = 0; i < probe_desc->nr_events; i++) { | |
29 | if (!strcmp(probe_desc->event_desc[i].name, name)) | |
30 | return &probe_desc->event_desc[i]; | |
31 | } | |
02119ee5 MD |
32 | } |
33 | return NULL; | |
34 | } | |
35 | ||
85a9ca7f | 36 | int ltt_probe_register(struct lttng_probe_desc *desc) |
02119ee5 | 37 | { |
02119ee5 | 38 | int ret = 0; |
85a9ca7f | 39 | int i; |
02119ee5 MD |
40 | |
41 | mutex_lock(&probe_mutex); | |
85a9ca7f MD |
42 | /* |
43 | * TODO: This is O(N^2). Turn into a hash table when probe registration | |
44 | * overhead becomes an issue. | |
45 | */ | |
46 | for (i = 0; i < desc->nr_events; i++) { | |
47 | if (find_event(desc->event_desc[i].name)) { | |
48 | ret = -EEXIST; | |
49 | goto end; | |
50 | } | |
02119ee5 | 51 | } |
85a9ca7f | 52 | list_add(&desc->head, &probe_list); |
02119ee5 MD |
53 | end: |
54 | mutex_unlock(&probe_mutex); | |
55 | return ret; | |
56 | } | |
57 | EXPORT_SYMBOL_GPL(ltt_probe_register); | |
58 | ||
85a9ca7f | 59 | void ltt_probe_unregister(struct lttng_probe_desc *desc) |
02119ee5 | 60 | { |
02119ee5 | 61 | mutex_lock(&probe_mutex); |
85a9ca7f | 62 | list_del(&desc->head); |
02119ee5 | 63 | mutex_unlock(&probe_mutex); |
02119ee5 MD |
64 | } |
65 | EXPORT_SYMBOL_GPL(ltt_probe_unregister); | |
66 | ||
85a9ca7f | 67 | const struct lttng_event_desc *ltt_event_get(const char *name) |
02119ee5 | 68 | { |
85a9ca7f | 69 | const struct lttng_event_desc *event; |
02119ee5 MD |
70 | int ret; |
71 | ||
72 | mutex_lock(&probe_mutex); | |
85a9ca7f | 73 | event = find_event(name); |
c099397a | 74 | mutex_unlock(&probe_mutex); |
85a9ca7f | 75 | if (!event) |
c099397a | 76 | return NULL; |
dc7f600a | 77 | ret = try_module_get(event->owner); |
02119ee5 | 78 | WARN_ON_ONCE(!ret); |
85a9ca7f | 79 | return event; |
02119ee5 | 80 | } |
85a9ca7f | 81 | EXPORT_SYMBOL_GPL(ltt_event_get); |
02119ee5 | 82 | |
85a9ca7f | 83 | void ltt_event_put(const struct lttng_event_desc *event) |
02119ee5 | 84 | { |
dc7f600a | 85 | module_put(event->owner); |
02119ee5 | 86 | } |
85a9ca7f | 87 | EXPORT_SYMBOL_GPL(ltt_event_put); |
271b6681 MD |
88 | |
89 | static | |
90 | void *tp_list_start(struct seq_file *m, loff_t *pos) | |
91 | { | |
92 | struct lttng_probe_desc *probe_desc; | |
93 | int iter = 0, i; | |
94 | ||
cbd4ecb2 | 95 | mutex_lock(&probe_mutex); |
271b6681 MD |
96 | list_for_each_entry(probe_desc, &probe_list, head) { |
97 | for (i = 0; i < probe_desc->nr_events; i++) { | |
98 | if (iter++ >= *pos) | |
99 | return (void *) &probe_desc->event_desc[i]; | |
100 | } | |
101 | } | |
102 | /* End of list */ | |
103 | return NULL; | |
104 | } | |
105 | ||
106 | static | |
107 | void *tp_list_next(struct seq_file *m, void *p, loff_t *ppos) | |
108 | { | |
109 | struct lttng_probe_desc *probe_desc; | |
110 | int iter = 0, i; | |
111 | ||
112 | (*ppos)++; | |
113 | list_for_each_entry(probe_desc, &probe_list, head) { | |
114 | for (i = 0; i < probe_desc->nr_events; i++) { | |
115 | if (iter++ >= *ppos) | |
116 | return (void *) &probe_desc->event_desc[i]; | |
117 | } | |
118 | } | |
119 | /* End of list */ | |
120 | return NULL; | |
121 | } | |
122 | ||
123 | static | |
124 | void tp_list_stop(struct seq_file *m, void *p) | |
125 | { | |
cbd4ecb2 | 126 | mutex_unlock(&probe_mutex); |
271b6681 MD |
127 | } |
128 | ||
129 | static | |
130 | int tp_list_show(struct seq_file *m, void *p) | |
131 | { | |
132 | const struct lttng_event_desc *probe_desc = p; | |
133 | ||
7516d0ea MD |
134 | /* |
135 | * Don't export lttng internal events (metadata). | |
136 | */ | |
137 | if (!strncmp(probe_desc->name, "lttng_", sizeof("lttng_") - 1)) | |
138 | return 0; | |
271b6681 MD |
139 | seq_printf(m, "event { name = %s; };\n", |
140 | probe_desc->name); | |
141 | return 0; | |
142 | } | |
143 | ||
144 | static | |
145 | const struct seq_operations lttng_tracepoint_list_seq_ops = { | |
146 | .start = tp_list_start, | |
147 | .next = tp_list_next, | |
148 | .stop = tp_list_stop, | |
149 | .show = tp_list_show, | |
150 | }; | |
151 | ||
152 | static | |
153 | int lttng_tracepoint_list_open(struct inode *inode, struct file *file) | |
154 | { | |
155 | return seq_open(file, <tng_tracepoint_list_seq_ops); | |
156 | } | |
157 | ||
158 | const struct file_operations lttng_tracepoint_list_fops = { | |
2e54c205 | 159 | .owner = THIS_MODULE, |
271b6681 MD |
160 | .open = lttng_tracepoint_list_open, |
161 | .read = seq_read, | |
162 | .llseek = seq_lseek, | |
a51729c7 | 163 | .release = seq_release, |
271b6681 | 164 | }; |