lib ring buffer must take private pointer copy before decrementing refcount
[lttng-modules.git] / ltt-probes.c
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
18 static LIST_HEAD(probe_list);
19 static DEFINE_MUTEX(probe_mutex);
20
21 static
22 const 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
36 int 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);
53 end:
54 mutex_unlock(&probe_mutex);
55 return ret;
56 }
57 EXPORT_SYMBOL_GPL(ltt_probe_register);
58
59 void 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 }
65 EXPORT_SYMBOL_GPL(ltt_probe_unregister);
66
67 const 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 }
81 EXPORT_SYMBOL_GPL(ltt_event_get);
82
83 void ltt_event_put(const struct lttng_event_desc *event)
84 {
85 module_put(event->owner);
86 }
87 EXPORT_SYMBOL_GPL(ltt_event_put);
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
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
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 {
126 mutex_unlock(&probe_mutex);
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
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
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, &lttng_tracepoint_list_seq_ops);
156 }
157
158 const 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.032035 seconds and 4 git commands to generate.