Commit | Line | Data |
---|---|---|
9f36eaed MJ |
1 | /* SPDX-License-Identifier: (GPL-2.0 or LGPL-2.1) |
2 | * | |
f0dbdefb HD |
3 | * wrapper/genhd.h |
4 | * | |
5 | * wrapper around block layer functions and data structures. Using | |
6 | * KALLSYMS to get its address when available, else we need to have a | |
7 | * kernel that exports this function to GPL modules. | |
8 | * | |
9 | * Copyright (C) 2011-2014 Mathieu Desnoyers <mathieu.desnoyers@efficios.com> | |
f0dbdefb HD |
10 | */ |
11 | ||
9f36eaed MJ |
12 | #ifndef _LTTNG_WRAPPER_GENHD_H |
13 | #define _LTTNG_WRAPPER_GENHD_H | |
14 | ||
f0dbdefb HD |
15 | #include <linux/genhd.h> |
16 | ||
17 | #ifdef CONFIG_KALLSYMS | |
18 | ||
19 | #include <linux/kallsyms.h> | |
5a2f5e92 | 20 | #include <wrapper/kallsyms.h> |
f0dbdefb HD |
21 | |
22 | static inline | |
23 | char *wrapper_disk_name(struct gendisk *hd, int partno, char *buf) | |
24 | { | |
25 | char *(*disk_name_sym)(struct gendisk *hd, int partno, char *buf); | |
26 | ||
27 | disk_name_sym = (void *) kallsyms_lookup_funcptr("disk_name"); | |
28 | if (disk_name_sym) { | |
29 | return disk_name_sym(hd, partno, buf); | |
30 | } else { | |
e36de50d | 31 | printk_once(KERN_WARNING "LTTng: disk_name symbol lookup failed.\n"); |
f0dbdefb HD |
32 | return NULL; |
33 | } | |
34 | } | |
35 | ||
36 | #else | |
37 | ||
38 | static inline | |
39 | char *wrapper_disk_name(struct gendisk *hd, int partno, char *buf) | |
40 | { | |
41 | return disk_name(hd, partno, buf); | |
42 | } | |
43 | ||
44 | #endif | |
45 | ||
46 | #ifdef CONFIG_KALLSYMS_ALL | |
47 | ||
48 | static inline | |
49 | struct class *wrapper_get_block_class(void) | |
50 | { | |
51 | struct class *ptr_block_class; | |
52 | ||
53 | ptr_block_class = (struct class *) kallsyms_lookup_dataptr("block_class"); | |
54 | if (!ptr_block_class) { | |
e36de50d | 55 | printk_once(KERN_WARNING "LTTng: block_class symbol lookup failed.\n"); |
f0dbdefb HD |
56 | return NULL; |
57 | } | |
58 | return ptr_block_class; | |
59 | } | |
60 | ||
61 | static inline | |
62 | struct device_type *wrapper_get_disk_type(void) | |
63 | { | |
64 | struct device_type *ptr_disk_type; | |
65 | ||
66 | ptr_disk_type = (struct device_type *) kallsyms_lookup_dataptr("disk_type"); | |
67 | if (!ptr_disk_type) { | |
e36de50d | 68 | printk_once(KERN_WARNING "LTTng: disk_type symbol lookup failed.\n"); |
f0dbdefb HD |
69 | return NULL; |
70 | } | |
71 | return ptr_disk_type; | |
72 | } | |
73 | ||
74 | #else | |
75 | ||
76 | static inline | |
77 | struct class *wrapper_get_block_class(void) | |
78 | { | |
79 | /* | |
80 | * Symbol block_class is not exported. | |
81 | * TODO: return &block_class; | |
82 | */ | |
83 | /* Feature currently unavailable without KALLSYMS_ALL */ | |
84 | return NULL; | |
85 | } | |
86 | ||
87 | static inline | |
88 | struct device_type *wrapper_get_disk_type(void) | |
89 | { | |
90 | /* | |
91 | * Symbol disk_type is not exported. | |
92 | * TODO: return &disk_type; | |
93 | */ | |
94 | /* Feature currently unavailable without KALLSYMS_ALL */ | |
95 | return NULL; | |
96 | } | |
97 | ||
98 | #endif | |
99 | ||
100 | #endif /* _LTTNG_WRAPPER_GENHD_H */ |