Use "unknown" for compat syscalls
[deliverable/lttng-modules.git] / ltt-probes.c
... / ...
CommitLineData
1/*
2 * ltt-probes.c
3 *
4 * Copyright 2010 (c) - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
5 *
6 * Holds LTTng probes registry.
7 *
8 * Dual LGPL v2.1/GPL v2 license.
9 */
10
11#include <linux/module.h>
12#include <linux/list.h>
13#include <linux/mutex.h>
14#include <linux/seq_file.h>
15
16#include "ltt-events.h"
17
18static LIST_HEAD(probe_list);
19static DEFINE_MUTEX(probe_mutex);
20
21static
22const struct lttng_event_desc *find_event(const char *name)
23{
24 struct lttng_probe_desc *probe_desc;
25 int i;
26
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 }
32 }
33 return NULL;
34}
35
36int ltt_probe_register(struct lttng_probe_desc *desc)
37{
38 int ret = 0;
39 int i;
40
41 mutex_lock(&probe_mutex);
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 }
51 }
52 list_add(&desc->head, &probe_list);
53end:
54 mutex_unlock(&probe_mutex);
55 return ret;
56}
57EXPORT_SYMBOL_GPL(ltt_probe_register);
58
59void ltt_probe_unregister(struct lttng_probe_desc *desc)
60{
61 mutex_lock(&probe_mutex);
62 list_del(&desc->head);
63 mutex_unlock(&probe_mutex);
64}
65EXPORT_SYMBOL_GPL(ltt_probe_unregister);
66
67const struct lttng_event_desc *ltt_event_get(const char *name)
68{
69 const struct lttng_event_desc *event;
70 int ret;
71
72 mutex_lock(&probe_mutex);
73 event = find_event(name);
74 mutex_unlock(&probe_mutex);
75 if (!event)
76 return NULL;
77 ret = try_module_get(event->owner);
78 WARN_ON_ONCE(!ret);
79 return event;
80}
81EXPORT_SYMBOL_GPL(ltt_event_get);
82
83void ltt_event_put(const struct lttng_event_desc *event)
84{
85 module_put(event->owner);
86}
87EXPORT_SYMBOL_GPL(ltt_event_put);
88
89static
90void *tp_list_start(struct seq_file *m, loff_t *pos)
91{
92 struct lttng_probe_desc *probe_desc;
93 int iter = 0, i;
94
95 mutex_lock(&probe_mutex);
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
106static
107void *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
123static
124void tp_list_stop(struct seq_file *m, void *p)
125{
126 mutex_unlock(&probe_mutex);
127}
128
129static
130int tp_list_show(struct seq_file *m, void *p)
131{
132 const struct lttng_event_desc *probe_desc = p;
133
134 /*
135 * Don't export lttng internal events (metadata).
136 */
137 if (!strncmp(probe_desc->name, "lttng_", sizeof("lttng_") - 1))
138 return 0;
139 seq_printf(m, "event { name = %s; };\n",
140 probe_desc->name);
141 return 0;
142}
143
144static
145const 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
152static
153int lttng_tracepoint_list_open(struct inode *inode, struct file *file)
154{
155 return seq_open(file, &lttng_tracepoint_list_seq_ops);
156}
157
158const struct file_operations lttng_tracepoint_list_fops = {
159 .owner = THIS_MODULE,
160 .open = lttng_tracepoint_list_open,
161 .read = seq_read,
162 .llseek = seq_lseek,
163 .release = seq_release,
164};
This page took 0.02527 seconds and 5 git commands to generate.