3c6dbcbe41a386e6c0bfa593c6c3bf479009f399
[lttng-modules.git] / include / wrapper / genhd.h
1 /* SPDX-License-Identifier: (GPL-2.0-only or LGPL-2.1-only)
2 *
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>
10 */
11
12 #ifndef _LTTNG_WRAPPER_GENHD_H
13 #define _LTTNG_WRAPPER_GENHD_H
14
15 #include <linux/genhd.h>
16
17 #if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(5,17,0))
18 #define LTTNG_GENHD_FL_HIDDEN GENHD_FL_HIDDEN
19 #else
20 #define LTTNG_GENHD_FL_HIDDEN GENHD_FL_SUPPRESS_PARTITION_INFO
21 #endif
22
23 #ifdef CONFIG_KALLSYMS_ALL
24
25 #include <linux/kallsyms.h>
26 #include <wrapper/kallsyms.h>
27
28 static inline
29 struct class *wrapper_get_block_class(void)
30 {
31 struct class *ptr_block_class;
32
33 ptr_block_class = (struct class *) kallsyms_lookup_dataptr("block_class");
34 if (!ptr_block_class) {
35 printk_once(KERN_WARNING "LTTng: block_class symbol lookup failed.\n");
36 return NULL;
37 }
38 return ptr_block_class;
39 }
40
41 /*
42 * Canary function to check for 'block_class' at compile time.
43 *
44 * From 'include/linux/genhd.h':
45 *
46 * extern struct class block_class;
47 */
48 static inline
49 struct class *__canary__get_block_class(void)
50 {
51 return &block_class;
52 }
53
54 static inline
55 struct device_type *wrapper_get_disk_type(void)
56 {
57 struct device_type *ptr_disk_type;
58
59 ptr_disk_type = (struct device_type *) kallsyms_lookup_dataptr("disk_type");
60 if (!ptr_disk_type) {
61 printk_once(KERN_WARNING "LTTng: disk_type symbol lookup failed.\n");
62 return NULL;
63 }
64 return ptr_disk_type;
65 }
66
67 /*
68 * No canary for 'disk_type', it's only defined in 'block/genhd.c'.
69 *
70 * static inline
71 * struct device_type *__canary__get_disk_type(void)
72 * {
73 * return &disk_type;
74 * }
75 */
76
77 #else
78
79 static inline
80 struct class *wrapper_get_block_class(void)
81 {
82 /*
83 * Symbol block_class is not exported.
84 * TODO: return &block_class;
85 */
86 /* Feature currently unavailable without KALLSYMS_ALL */
87 return NULL;
88 }
89
90 static inline
91 struct device_type *wrapper_get_disk_type(void)
92 {
93 /*
94 * Symbol disk_type is not exported.
95 * TODO: return &disk_type;
96 */
97 /* Feature currently unavailable without KALLSYMS_ALL */
98 return NULL;
99 }
100
101 #endif
102
103 #endif /* _LTTNG_WRAPPER_GENHD_H */
This page took 0.03063 seconds and 3 git commands to generate.