4 * Copyright 2010 (c) - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
6 * Holds LTTng probes registry.
9 #include <linux/module.h>
10 #include <linux/list.h>
11 #include <linux/mutex.h>
12 #include <linux/slab.h>
17 struct list_head list
;
20 static LIST_HEAD(probe_list
);
21 static DEFINE_MUTEX(probe_mutex
);
22 static struct kmem_cache
*probe_cache
;
24 static void *find_probe(const char *name
)
26 struct ltt_probe
*probe
;
28 list_for_each_entry(probe
, &probe_list
, list
) {
29 if (!strcmp(probe
->name
, name
))
35 int ltt_probe_register(const char *name
, void *cb
)
37 struct ltt_probe
*probe
;
43 mutex_lock(&probe_mutex
);
44 if (find_probe(name
)) {
48 probe
= kmem_cache_zalloc(probe_cache
, GFP_KERNEL
);
55 list_add(&probe
->list
, &probe_list
);
57 mutex_unlock(&probe_mutex
);
60 EXPORT_SYMBOL_GPL(ltt_probe_register
);
62 void ltt_probe_unregister(const char *name
)
64 struct ltt_probe
*probe
;
66 mutex_lock(&probe_mutex
);
67 probe
= find_probe(name
);
69 list_del(&probe
->list
);
70 mutex_unlock(&probe_mutex
);
71 kmem_cache_free(probe_cache
, probe
);
73 EXPORT_SYMBOL_GPL(ltt_probe_unregister
);
75 void *ltt_probe_get(const char *name
)
77 struct ltt_probe
*probe
;
81 mutex_lock(&probe_mutex
);
82 probe
= find_probe(name
);
86 ret
= try_module_get(__module_text_address((unsigned long) cb
));
89 mutex_unlock(&probe_mutex
);
92 EXPORT_SYMBOL_GPL(ltt_probe_get
);
94 void ltt_probe_put(void *cb
)
96 module_put(__module_text_address((unsigned long) cb
));
98 EXPORT_SYMBOL_GPL(ltt_probe_put
);
100 int __init
ltt_probes_init(void)
102 probe_cache
= KMEM_CACHE(ltt_probe
, 0);
108 void __exit
ltt_probes_exit(void)
110 kmem_cache_destroy(probe_cache
);
This page took 0.037158 seconds and 4 git commands to generate.