| 1 | #ifndef _LTTNG_WRAPPER_GENHD_H |
| 2 | #define _LTTNG_WRAPPER_GENHD_H |
| 3 | |
| 4 | /* |
| 5 | * wrapper/genhd.h |
| 6 | * |
| 7 | * wrapper around block layer functions and data structures. Using |
| 8 | * KALLSYMS to get its address when available, else we need to have a |
| 9 | * kernel that exports this function to GPL modules. |
| 10 | * |
| 11 | * Copyright (C) 2011-2014 Mathieu Desnoyers <mathieu.desnoyers@efficios.com> |
| 12 | * |
| 13 | * This library is free software; you can redistribute it and/or |
| 14 | * modify it under the terms of the GNU Lesser General Public |
| 15 | * License as published by the Free Software Foundation; only |
| 16 | * version 2.1 of the License. |
| 17 | * |
| 18 | * This library is distributed in the hope that it will be useful, |
| 19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 21 | * Lesser General Public License for more details. |
| 22 | * |
| 23 | * You should have received a copy of the GNU Lesser General Public |
| 24 | * License along with this library; if not, write to the Free Software |
| 25 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 26 | */ |
| 27 | |
| 28 | #include <linux/genhd.h> |
| 29 | |
| 30 | #ifdef CONFIG_KALLSYMS |
| 31 | |
| 32 | #include <linux/kallsyms.h> |
| 33 | #include <wrapper/kallsyms.h> |
| 34 | |
| 35 | static inline |
| 36 | char *wrapper_disk_name(struct gendisk *hd, int partno, char *buf) |
| 37 | { |
| 38 | char *(*disk_name_sym)(struct gendisk *hd, int partno, char *buf); |
| 39 | |
| 40 | disk_name_sym = (void *) kallsyms_lookup_funcptr("disk_name"); |
| 41 | if (disk_name_sym) { |
| 42 | return disk_name_sym(hd, partno, buf); |
| 43 | } else { |
| 44 | printk(KERN_WARNING "LTTng: disk_name symbol lookup failed.\n"); |
| 45 | return NULL; |
| 46 | } |
| 47 | } |
| 48 | |
| 49 | #else |
| 50 | |
| 51 | static inline |
| 52 | char *wrapper_disk_name(struct gendisk *hd, int partno, char *buf) |
| 53 | { |
| 54 | return disk_name(hd, partno, buf); |
| 55 | } |
| 56 | |
| 57 | #endif |
| 58 | |
| 59 | #ifdef CONFIG_KALLSYMS_ALL |
| 60 | |
| 61 | static inline |
| 62 | struct class *wrapper_get_block_class(void) |
| 63 | { |
| 64 | struct class *ptr_block_class; |
| 65 | |
| 66 | ptr_block_class = (struct class *) kallsyms_lookup_dataptr("block_class"); |
| 67 | if (!ptr_block_class) { |
| 68 | printk(KERN_WARNING "LTTng: block_class symbol lookup failed.\n"); |
| 69 | return NULL; |
| 70 | } |
| 71 | return ptr_block_class; |
| 72 | } |
| 73 | |
| 74 | static inline |
| 75 | struct device_type *wrapper_get_disk_type(void) |
| 76 | { |
| 77 | struct device_type *ptr_disk_type; |
| 78 | |
| 79 | ptr_disk_type = (struct device_type *) kallsyms_lookup_dataptr("disk_type"); |
| 80 | if (!ptr_disk_type) { |
| 81 | printk(KERN_WARNING "LTTng: disk_type symbol lookup failed.\n"); |
| 82 | return NULL; |
| 83 | } |
| 84 | return ptr_disk_type; |
| 85 | } |
| 86 | |
| 87 | #else |
| 88 | |
| 89 | static inline |
| 90 | struct class *wrapper_get_block_class(void) |
| 91 | { |
| 92 | /* |
| 93 | * Symbol block_class is not exported. |
| 94 | * TODO: return &block_class; |
| 95 | */ |
| 96 | /* Feature currently unavailable without KALLSYMS_ALL */ |
| 97 | return NULL; |
| 98 | } |
| 99 | |
| 100 | static inline |
| 101 | struct device_type *wrapper_get_disk_type(void) |
| 102 | { |
| 103 | /* |
| 104 | * Symbol disk_type is not exported. |
| 105 | * TODO: return &disk_type; |
| 106 | */ |
| 107 | /* Feature currently unavailable without KALLSYMS_ALL */ |
| 108 | return NULL; |
| 109 | } |
| 110 | |
| 111 | #endif |
| 112 | |
| 113 | #endif /* _LTTNG_WRAPPER_GENHD_H */ |