From: Michael Jeanson Date: Thu, 15 Apr 2021 17:56:24 +0000 (-0400) Subject: fix backport: block: add a disk_uevent helper (v5.12) X-Git-Tag: v2.11.9~9 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=35696e5af99e0922f71f8a619334a2b134917683;p=lttng-modules.git fix backport: block: add a disk_uevent helper (v5.12) Signed-off-by: Michael Jeanson Signed-off-by: Mathieu Desnoyers Change-Id: I717162069990577abe78e5e7fed28816f32b2c84 --- diff --git a/src/wrapper/genhd.c b/src/wrapper/genhd.c deleted file mode 100644 index a5a6c410..00000000 --- a/src/wrapper/genhd.c +++ /dev/null @@ -1,111 +0,0 @@ -/* SPDX-License-Identifier: (GPL-2.0-only OR LGPL-2.1-only) - * - * wrapper/genhd.c - * - * Wrapper around disk_part_iter_(init|next|exit). Using KALLSYMS to get the - * addresses when available, else we need to have a kernel that exports this - * function to GPL modules. This export was removed in 5.12. - * - * Copyright (C) 2021 Michael Jeanson - */ - -#include -#include -#include - -#if (defined(CONFIG_KALLSYMS) && \ - (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(5,12,0))) - -#include - -static -void (*disk_part_iter_init_sym)(struct disk_part_iter *piter, struct gendisk *disk, - unsigned int flags); - -static -LTTNG_DISK_PART_TYPE *(*disk_part_iter_next_sym)(struct disk_part_iter *piter); - -static -void (*disk_part_iter_exit_sym)(struct disk_part_iter *piter); - -/* - * This wrapper has an 'int' return type instead of the original 'void', to be - * able to report the symbol lookup failure to the caller. - * - * Return 0 on success, -1 on error. - */ -int wrapper_disk_part_iter_init(struct disk_part_iter *piter, struct gendisk *disk, - unsigned int flags) -{ - if (!disk_part_iter_init_sym) - disk_part_iter_init_sym = (void *) kallsyms_lookup_funcptr("disk_part_iter_init"); - - if (disk_part_iter_init_sym) { - disk_part_iter_init_sym(piter, disk, flags); - } else { - printk_once(KERN_WARNING "LTTng: disk_part_iter_init symbol lookup failed.\n"); - return -1; - } - return 0; -} -EXPORT_SYMBOL_GPL(wrapper_disk_part_iter_init); - -LTTNG_DISK_PART_TYPE *wrapper_disk_part_iter_next(struct disk_part_iter *piter) -{ - if (!disk_part_iter_next_sym) - disk_part_iter_next_sym = (void *) kallsyms_lookup_funcptr("disk_part_iter_next"); - - if (disk_part_iter_next_sym) { - return disk_part_iter_next_sym(piter); - } else { - printk_once(KERN_WARNING "LTTng: disk_part_iter_next symbol lookup failed.\n"); - return NULL; - } -} -EXPORT_SYMBOL_GPL(wrapper_disk_part_iter_next); - -/* - * We don't return an error on symbol lookup failure here because there is - * nothing the caller can do to cleanup the iterator. - */ -void wrapper_disk_part_iter_exit(struct disk_part_iter *piter) -{ - if (!disk_part_iter_exit_sym) - disk_part_iter_exit_sym = (void *) kallsyms_lookup_funcptr("disk_part_iter_exit"); - - if (disk_part_iter_exit_sym) { - disk_part_iter_exit_sym(piter); - } else { - printk_once(KERN_WARNING "LTTng: disk_part_iter_exit symbol lookup failed.\n"); - } -} -EXPORT_SYMBOL_GPL(wrapper_disk_part_iter_exit); - -#else - -/* - * This wrapper has an 'int' return type instead of the original 'void', so the - * kallsyms variant can report the symbol lookup failure to the caller. - * - * This variant always succeeds and returns 0. - */ -int wrapper_disk_part_iter_init(struct disk_part_iter *piter, struct gendisk *disk, - unsigned int flags) -{ - disk_part_iter_init(piter, disk, flags); - return 0; -} -EXPORT_SYMBOL_GPL(wrapper_disk_part_iter_init); - -LTTNG_DISK_PART_TYPE *wrapper_disk_part_iter_next(struct disk_part_iter *piter) -{ - return disk_part_iter_next(piter); -} -EXPORT_SYMBOL_GPL(wrapper_disk_part_iter_next); - -void wrapper_disk_part_iter_exit(struct disk_part_iter *piter) -{ - disk_part_iter_exit(piter); -} -EXPORT_SYMBOL_GPL(wrapper_disk_part_iter_exit); -#endif diff --git a/wrapper/genhd.c b/wrapper/genhd.c new file mode 100644 index 00000000..cbec06f7 --- /dev/null +++ b/wrapper/genhd.c @@ -0,0 +1,111 @@ +/* SPDX-License-Identifier: (GPL-2.0-only OR LGPL-2.1-only) + * + * wrapper/genhd.c + * + * Wrapper around disk_part_iter_(init|next|exit). Using KALLSYMS to get the + * addresses when available, else we need to have a kernel that exports this + * function to GPL modules. This export was removed in 5.12. + * + * Copyright (C) 2021 Michael Jeanson + */ + +#include +#include +#include + +#if (defined(CONFIG_KALLSYMS) && \ + (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(5,12,0))) + +#include + +static +void (*disk_part_iter_init_sym)(struct disk_part_iter *piter, struct gendisk *disk, + unsigned int flags); + +static +LTTNG_DISK_PART_TYPE *(*disk_part_iter_next_sym)(struct disk_part_iter *piter); + +static +void (*disk_part_iter_exit_sym)(struct disk_part_iter *piter); + +/* + * This wrapper has an 'int' return type instead of the original 'void', to be + * able to report the symbol lookup failure to the caller. + * + * Return 0 on success, -1 on error. + */ +int wrapper_disk_part_iter_init(struct disk_part_iter *piter, struct gendisk *disk, + unsigned int flags) +{ + if (!disk_part_iter_init_sym) + disk_part_iter_init_sym = (void *) kallsyms_lookup_funcptr("disk_part_iter_init"); + + if (disk_part_iter_init_sym) { + disk_part_iter_init_sym(piter, disk, flags); + } else { + printk_once(KERN_WARNING "LTTng: disk_part_iter_init symbol lookup failed.\n"); + return -1; + } + return 0; +} +EXPORT_SYMBOL_GPL(wrapper_disk_part_iter_init); + +LTTNG_DISK_PART_TYPE *wrapper_disk_part_iter_next(struct disk_part_iter *piter) +{ + if (!disk_part_iter_next_sym) + disk_part_iter_next_sym = (void *) kallsyms_lookup_funcptr("disk_part_iter_next"); + + if (disk_part_iter_next_sym) { + return disk_part_iter_next_sym(piter); + } else { + printk_once(KERN_WARNING "LTTng: disk_part_iter_next symbol lookup failed.\n"); + return NULL; + } +} +EXPORT_SYMBOL_GPL(wrapper_disk_part_iter_next); + +/* + * We don't return an error on symbol lookup failure here because there is + * nothing the caller can do to cleanup the iterator. + */ +void wrapper_disk_part_iter_exit(struct disk_part_iter *piter) +{ + if (!disk_part_iter_exit_sym) + disk_part_iter_exit_sym = (void *) kallsyms_lookup_funcptr("disk_part_iter_exit"); + + if (disk_part_iter_exit_sym) { + disk_part_iter_exit_sym(piter); + } else { + printk_once(KERN_WARNING "LTTng: disk_part_iter_exit symbol lookup failed.\n"); + } +} +EXPORT_SYMBOL_GPL(wrapper_disk_part_iter_exit); + +#else + +/* + * This wrapper has an 'int' return type instead of the original 'void', so the + * kallsyms variant can report the symbol lookup failure to the caller. + * + * This variant always succeeds and returns 0. + */ +int wrapper_disk_part_iter_init(struct disk_part_iter *piter, struct gendisk *disk, + unsigned int flags) +{ + disk_part_iter_init(piter, disk, flags); + return 0; +} +EXPORT_SYMBOL_GPL(wrapper_disk_part_iter_init); + +LTTNG_DISK_PART_TYPE *wrapper_disk_part_iter_next(struct disk_part_iter *piter) +{ + return disk_part_iter_next(piter); +} +EXPORT_SYMBOL_GPL(wrapper_disk_part_iter_next); + +void wrapper_disk_part_iter_exit(struct disk_part_iter *piter) +{ + disk_part_iter_exit(piter); +} +EXPORT_SYMBOL_GPL(wrapper_disk_part_iter_exit); +#endif diff --git a/wrapper/genhd.h b/wrapper/genhd.h index 6bae239d..1b4a4201 100644 --- a/wrapper/genhd.h +++ b/wrapper/genhd.h @@ -13,7 +13,7 @@ #define _LTTNG_WRAPPER_GENHD_H #include -#include +#include #if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(5,11,0)) #define LTTNG_DISK_PART_TYPE struct block_device