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 | ||
bf5a011d | 17 | #ifdef CONFIG_KALLSYMS_ALL |
f0dbdefb HD |
18 | |
19 | #include <linux/kallsyms.h> | |
5a2f5e92 | 20 | #include <wrapper/kallsyms.h> |
f0dbdefb | 21 | |
f0dbdefb HD |
22 | static inline |
23 | struct class *wrapper_get_block_class(void) | |
24 | { | |
25 | struct class *ptr_block_class; | |
26 | ||
27 | ptr_block_class = (struct class *) kallsyms_lookup_dataptr("block_class"); | |
28 | if (!ptr_block_class) { | |
e36de50d | 29 | printk_once(KERN_WARNING "LTTng: block_class symbol lookup failed.\n"); |
f0dbdefb HD |
30 | return NULL; |
31 | } | |
32 | return ptr_block_class; | |
33 | } | |
34 | ||
9e52289b MJ |
35 | /* |
36 | * Canary function to check for 'block_class' at compile time. | |
37 | * | |
38 | * From 'include/linux/genhd.h': | |
39 | * | |
40 | * extern struct class block_class; | |
41 | */ | |
42 | static inline | |
43 | struct class *__canary__get_block_class(void) | |
44 | { | |
45 | return &block_class; | |
46 | } | |
47 | ||
f0dbdefb HD |
48 | static inline |
49 | struct device_type *wrapper_get_disk_type(void) | |
50 | { | |
51 | struct device_type *ptr_disk_type; | |
52 | ||
53 | ptr_disk_type = (struct device_type *) kallsyms_lookup_dataptr("disk_type"); | |
54 | if (!ptr_disk_type) { | |
e36de50d | 55 | printk_once(KERN_WARNING "LTTng: disk_type symbol lookup failed.\n"); |
f0dbdefb HD |
56 | return NULL; |
57 | } | |
58 | return ptr_disk_type; | |
59 | } | |
60 | ||
9e52289b MJ |
61 | /* |
62 | * No canary for 'disk_type', it's only defined in 'block/genhd.c'. | |
63 | * | |
64 | * static inline | |
65 | * struct device_type *__canary__get_disk_type(void) | |
66 | * { | |
67 | * return &disk_type; | |
68 | * } | |
69 | */ | |
70 | ||
f0dbdefb HD |
71 | #else |
72 | ||
73 | static inline | |
74 | struct class *wrapper_get_block_class(void) | |
75 | { | |
76 | /* | |
77 | * Symbol block_class is not exported. | |
78 | * TODO: return &block_class; | |
79 | */ | |
80 | /* Feature currently unavailable without KALLSYMS_ALL */ | |
81 | return NULL; | |
82 | } | |
83 | ||
84 | static inline | |
85 | struct device_type *wrapper_get_disk_type(void) | |
86 | { | |
87 | /* | |
88 | * Symbol disk_type is not exported. | |
89 | * TODO: return &disk_type; | |
90 | */ | |
91 | /* Feature currently unavailable without KALLSYMS_ALL */ | |
92 | return NULL; | |
93 | } | |
94 | ||
95 | #endif | |
96 | ||
97 | #endif /* _LTTNG_WRAPPER_GENHD_H */ |