Commit | Line | Data |
---|---|---|
b7cdc182 | 1 | /* SPDX-License-Identifier: (GPL-2.0-only or LGPL-2.1-only) |
9f36eaed | 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 | 15 | #include <linux/genhd.h> |
7633c773 MJ |
16 | #include <lttng/kernel-version.h> |
17 | ||
18 | #if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(5,11,0)) | |
19 | #define LTTNG_DISK_PART_TYPE struct block_device | |
20 | #else | |
21 | #define LTTNG_DISK_PART_TYPE struct hd_struct | |
22 | #endif | |
f0dbdefb | 23 | |
ff04d185 | 24 | #ifdef CONFIG_KALLSYMS_ALL |
f0dbdefb HD |
25 | |
26 | #include <linux/kallsyms.h> | |
5a2f5e92 | 27 | #include <wrapper/kallsyms.h> |
f0dbdefb | 28 | |
f0dbdefb HD |
29 | static inline |
30 | struct class *wrapper_get_block_class(void) | |
31 | { | |
32 | struct class *ptr_block_class; | |
33 | ||
34 | ptr_block_class = (struct class *) kallsyms_lookup_dataptr("block_class"); | |
35 | if (!ptr_block_class) { | |
e36de50d | 36 | printk_once(KERN_WARNING "LTTng: block_class symbol lookup failed.\n"); |
f0dbdefb HD |
37 | return NULL; |
38 | } | |
39 | return ptr_block_class; | |
40 | } | |
41 | ||
3dfec228 MJ |
42 | /* |
43 | * Canary function to check for 'block_class' at compile time. | |
44 | * | |
45 | * From 'include/linux/genhd.h': | |
46 | * | |
47 | * extern struct class block_class; | |
48 | */ | |
49 | static inline | |
50 | struct class *__canary__get_block_class(void) | |
51 | { | |
52 | return &block_class; | |
53 | } | |
54 | ||
f0dbdefb HD |
55 | static inline |
56 | struct device_type *wrapper_get_disk_type(void) | |
57 | { | |
58 | struct device_type *ptr_disk_type; | |
59 | ||
60 | ptr_disk_type = (struct device_type *) kallsyms_lookup_dataptr("disk_type"); | |
61 | if (!ptr_disk_type) { | |
e36de50d | 62 | printk_once(KERN_WARNING "LTTng: disk_type symbol lookup failed.\n"); |
f0dbdefb HD |
63 | return NULL; |
64 | } | |
65 | return ptr_disk_type; | |
66 | } | |
67 | ||
3dfec228 MJ |
68 | /* |
69 | * No canary for 'disk_type', it's only defined in 'block/genhd.c'. | |
70 | * | |
71 | * static inline | |
72 | * struct device_type *__canary__get_disk_type(void) | |
73 | * { | |
74 | * return &disk_type; | |
75 | * } | |
76 | */ | |
77 | ||
f0dbdefb HD |
78 | #else |
79 | ||
80 | static inline | |
81 | struct class *wrapper_get_block_class(void) | |
82 | { | |
83 | /* | |
84 | * Symbol block_class is not exported. | |
85 | * TODO: return &block_class; | |
86 | */ | |
87 | /* Feature currently unavailable without KALLSYMS_ALL */ | |
88 | return NULL; | |
89 | } | |
90 | ||
91 | static inline | |
92 | struct device_type *wrapper_get_disk_type(void) | |
93 | { | |
94 | /* | |
95 | * Symbol disk_type is not exported. | |
96 | * TODO: return &disk_type; | |
97 | */ | |
98 | /* Feature currently unavailable without KALLSYMS_ALL */ | |
99 | return NULL; | |
100 | } | |
101 | ||
102 | #endif | |
103 | ||
7633c773 MJ |
104 | /* |
105 | * This wrapper has an 'int' return type instead of the original 'void', to be | |
106 | * able to report the symbol lookup failure to the caller. | |
107 | * | |
108 | * Return 0 on success, -1 on error. | |
109 | */ | |
110 | int wrapper_disk_part_iter_init(struct disk_part_iter *piter, struct gendisk *disk, | |
111 | unsigned int flags); | |
112 | LTTNG_DISK_PART_TYPE *wrapper_disk_part_iter_next(struct disk_part_iter *piter); | |
113 | void wrapper_disk_part_iter_exit(struct disk_part_iter *piter); | |
114 | ||
115 | /* | |
116 | * Canary function to check for 'disk_part_iter_init()' at compile time. | |
117 | * | |
118 | * From 'include/linux/genhd.h': | |
119 | * | |
120 | * extern void disk_part_iter_init(struct disk_part_iter *piter, | |
121 | * struct gendisk *disk, unsigned int flags); | |
122 | * | |
123 | */ | |
124 | static inline | |
125 | void __canary__disk_part_iter_init(struct disk_part_iter *piter, struct gendisk *disk, | |
126 | unsigned int flags) | |
127 | { | |
128 | disk_part_iter_init(piter, disk, flags); | |
129 | } | |
130 | ||
131 | /* | |
132 | * Canary function to check for 'disk_part_iter_next()' at compile time. | |
133 | * | |
134 | * From 'include/linux/genhd.h': | |
135 | * | |
136 | * struct block_device *disk_part_iter_next(struct disk_part_iter *piter); | |
137 | * | |
138 | */ | |
139 | static inline | |
140 | LTTNG_DISK_PART_TYPE *__canary__disk_part_iter_next(struct disk_part_iter *piter) | |
141 | { | |
142 | return disk_part_iter_next(piter); | |
143 | } | |
144 | ||
145 | /* | |
146 | * Canary function to check for 'disk_part_iter_exit()' at compile time. | |
147 | * | |
148 | * From 'include/linux/genhd.h': | |
149 | * | |
150 | * extern void disk_part_iter_exit(struct disk_part_iter *piter); | |
151 | * | |
152 | */ | |
153 | static inline | |
154 | void __canary__disk_part_iter_exit(struct disk_part_iter *piter) | |
155 | { | |
156 | return disk_part_iter_exit(piter); | |
157 | } | |
158 | ||
f0dbdefb | 159 | #endif /* _LTTNG_WRAPPER_GENHD_H */ |