fix backport: block: add a disk_uevent helper (v5.12)
[lttng-modules.git] / wrapper / genhd.h
index a44198a7eb138f6698c7495ccb059a0370a91026..1b4a420167ef4c7d34b436fc9b64c56903b17c13 100644 (file)
 #define _LTTNG_WRAPPER_GENHD_H
 
 #include <linux/genhd.h>
+#include <lttng-kernel-version.h>
 
-#ifdef CONFIG_KALLSYMS
-
-#include <linux/kallsyms.h>
-#include <wrapper/kallsyms.h>
-
-static inline
-char *wrapper_disk_name(struct gendisk *hd, int partno, char *buf)
-{
-       char *(*disk_name_sym)(struct gendisk *hd, int partno, char *buf);
-
-       disk_name_sym = (void *) kallsyms_lookup_funcptr("disk_name");
-       if (disk_name_sym) {
-               return disk_name_sym(hd, partno, buf);
-       } else {
-               printk_once(KERN_WARNING "LTTng: disk_name symbol lookup failed.\n");
-               return NULL;
-       }
-}
-
+#if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(5,11,0))
+#define LTTNG_DISK_PART_TYPE struct block_device
 #else
-
-static inline
-char *wrapper_disk_name(struct gendisk *hd, int partno, char *buf)
-{
-       return disk_name(hd, partno, buf);
-}
-
+#define LTTNG_DISK_PART_TYPE struct hd_struct
 #endif
 
 #ifdef CONFIG_KALLSYMS_ALL
 
+#include <linux/kallsyms.h>
+#include <wrapper/kallsyms.h>
+
 static inline
 struct class *wrapper_get_block_class(void)
 {
@@ -58,6 +39,19 @@ struct class *wrapper_get_block_class(void)
        return ptr_block_class;
 }
 
+/*
+ * Canary function to check for 'block_class' at compile time.
+ *
+ * From 'include/linux/genhd.h':
+ *
+ *   extern struct class block_class;
+ */
+static inline
+struct class *__canary__get_block_class(void)
+{
+       return &block_class;
+}
+
 static inline
 struct device_type *wrapper_get_disk_type(void)
 {
@@ -71,6 +65,16 @@ struct device_type *wrapper_get_disk_type(void)
        return ptr_disk_type;
 }
 
+/*
+ * No canary for 'disk_type', it's only defined in 'block/genhd.c'.
+ *
+ * static inline
+ * struct device_type *__canary__get_disk_type(void)
+ * {
+ *     return &disk_type;
+ * }
+ */
+
 #else
 
 static inline
@@ -97,4 +101,59 @@ struct device_type *wrapper_get_disk_type(void)
 
 #endif
 
+/*
+ * 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);
+LTTNG_DISK_PART_TYPE *wrapper_disk_part_iter_next(struct disk_part_iter *piter);
+void wrapper_disk_part_iter_exit(struct disk_part_iter *piter);
+
+/*
+ * Canary function to check for 'disk_part_iter_init()' at compile time.
+ *
+ * From 'include/linux/genhd.h':
+ *
+ *   extern void disk_part_iter_init(struct disk_part_iter *piter,
+ *                                   struct gendisk *disk, unsigned int flags);
+ *
+ */
+static inline
+void __canary__disk_part_iter_init(struct disk_part_iter *piter, struct gendisk *disk,
+               unsigned int flags)
+{
+       disk_part_iter_init(piter, disk, flags);
+}
+
+/*
+ * Canary function to check for 'disk_part_iter_next()' at compile time.
+ *
+ * From 'include/linux/genhd.h':
+ *
+ *   struct block_device *disk_part_iter_next(struct disk_part_iter *piter);
+ *
+ */
+static inline
+LTTNG_DISK_PART_TYPE *__canary__disk_part_iter_next(struct disk_part_iter *piter)
+{
+       return disk_part_iter_next(piter);
+}
+
+/*
+ * Canary function to check for 'disk_part_iter_exit()' at compile time.
+ *
+ * From 'include/linux/genhd.h':
+ *
+ *   extern void disk_part_iter_exit(struct disk_part_iter *piter);
+ *
+ */
+static inline
+void __canary__disk_part_iter_exit(struct disk_part_iter *piter)
+{
+       return disk_part_iter_exit(piter);
+}
+
 #endif /* _LTTNG_WRAPPER_GENHD_H */
This page took 0.023666 seconds and 4 git commands to generate.