1 /* SPDX-License-Identifier: (GPL-2.0-only OR LGPL-2.1-only)
5 * Wrapper around disk_part_iter_(init|next|exit). Using KALLSYMS to get the
6 * addresses when available, else we need to have a kernel that exports this
7 * function to GPL modules. This export was removed in 5.12.
9 * Copyright (C) 2021 Michael Jeanson <mjeanson@efficios.com>
12 #include <lttng/kernel-version.h>
13 #include <linux/module.h>
14 #include <wrapper/genhd.h>
16 #if (defined(CONFIG_KALLSYMS) && \
17 (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(5,12,0)))
19 #include <wrapper/kallsyms.h>
22 void (*disk_part_iter_init_sym
)(struct disk_part_iter
*piter
, struct gendisk
*disk
,
26 LTTNG_DISK_PART_TYPE
*(*disk_part_iter_next_sym
)(struct disk_part_iter
*piter
);
29 void (*disk_part_iter_exit_sym
)(struct disk_part_iter
*piter
);
32 * This wrapper has an 'int' return type instead of the original 'void', to be
33 * able to report the symbol lookup failure to the caller.
35 * Return 0 on success, -1 on error.
37 int wrapper_disk_part_iter_init(struct disk_part_iter
*piter
, struct gendisk
*disk
,
40 if (!disk_part_iter_init_sym
)
41 disk_part_iter_init_sym
= (void *) kallsyms_lookup_funcptr("disk_part_iter_init");
43 if (disk_part_iter_init_sym
) {
44 disk_part_iter_init_sym(piter
, disk
, flags
);
46 printk_once(KERN_WARNING
"LTTng: disk_part_iter_init symbol lookup failed.\n");
51 EXPORT_SYMBOL_GPL(wrapper_disk_part_iter_init
);
53 LTTNG_DISK_PART_TYPE
*wrapper_disk_part_iter_next(struct disk_part_iter
*piter
)
55 if (!disk_part_iter_next_sym
)
56 disk_part_iter_next_sym
= (void *) kallsyms_lookup_funcptr("disk_part_iter_next");
58 if (disk_part_iter_next_sym
) {
59 return disk_part_iter_next_sym(piter
);
61 printk_once(KERN_WARNING
"LTTng: disk_part_iter_next symbol lookup failed.\n");
65 EXPORT_SYMBOL_GPL(wrapper_disk_part_iter_next
);
68 * We don't return an error on symbol lookup failure here because there is
69 * nothing the caller can do to cleanup the iterator.
71 void wrapper_disk_part_iter_exit(struct disk_part_iter
*piter
)
73 if (!disk_part_iter_exit_sym
)
74 disk_part_iter_exit_sym
= (void *) kallsyms_lookup_funcptr("disk_part_iter_exit");
76 if (disk_part_iter_exit_sym
) {
77 disk_part_iter_exit_sym(piter
);
79 printk_once(KERN_WARNING
"LTTng: disk_part_iter_exit symbol lookup failed.\n");
82 EXPORT_SYMBOL_GPL(wrapper_disk_part_iter_exit
);
87 * This wrapper has an 'int' return type instead of the original 'void', so the
88 * kallsyms variant can report the symbol lookup failure to the caller.
90 * This variant always succeeds and returns 0.
92 int wrapper_disk_part_iter_init(struct disk_part_iter
*piter
, struct gendisk
*disk
,
95 disk_part_iter_init(piter
, disk
, flags
);
98 EXPORT_SYMBOL_GPL(wrapper_disk_part_iter_init
);
100 LTTNG_DISK_PART_TYPE
*wrapper_disk_part_iter_next(struct disk_part_iter
*piter
)
102 return disk_part_iter_next(piter
);
104 EXPORT_SYMBOL_GPL(wrapper_disk_part_iter_next
);
106 void wrapper_disk_part_iter_exit(struct disk_part_iter
*piter
)
108 disk_part_iter_exit(piter
);
110 EXPORT_SYMBOL_GPL(wrapper_disk_part_iter_exit
);