[lttng-dev] [PATCH lttng-modules] Fix: lttng-statedump-impl: wrap some helpers unexported in kernel

yanfei.xu at windriver.com yanfei.xu at windriver.com
Mon Mar 29 07:30:32 EDT 2021


From: Yanfei Xu <yanfei.xu at windriver.com>

disk_part_iter_* helpers were unexported in the v5.11 kernel
by 'commit bc359d03c7ec("block: add a disk_uevent helper")'.
Thus we make some wrappers for them to avoid compile failed.

Signed-off-by: Yanfei Xu <yanfei.xu at windriver.com>
---
 include/wrapper/genhd.h    | 104 +++++++++++++++++++++++++++++++++++++
 src/lttng-statedump-impl.c |   9 ++--
 2 files changed, 108 insertions(+), 5 deletions(-)

diff --git a/include/wrapper/genhd.h b/include/wrapper/genhd.h
index 68980388..91159daf 100644
--- a/include/wrapper/genhd.h
+++ b/include/wrapper/genhd.h
@@ -94,4 +94,108 @@ struct device_type *wrapper_get_disk_type(void)
 
 #endif
 
+
+#if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(5,11,0))
+
+/**
+ * disk_part_iter_exit - finish up partition iteration
+ * @piter: iter of interest
+ *
+ * Called when iteration is over.  Cleans up @piter.
+ *
+ * CONTEXT:
+ * Don't care.
+ */
+static
+void wrapper_disk_part_iter_exit(struct disk_part_iter *piter)
+{
+        if (piter->part)
+                bdput(piter->part);
+        piter->part = NULL;
+}
+
+/**
+ * disk_part_iter_init - initialize partition iterator
+ * @piter: iterator to initialize
+ * @disk: disk to iterate over
+ * @flags: DISK_PITER_* flags
+ *
+ * Initialize @piter so that it iterates over partitions of @disk.
+ *
+ * CONTEXT:
+ * Don't care.
+ */
+static
+void wrapper_disk_part_iter_init(struct disk_part_iter *piter, struct gendisk *disk,
+		                                          unsigned int flags)
+{
+        piter->disk = disk;
+        piter->part = NULL;
+        if (flags & (DISK_PITER_INCL_PART0 | DISK_PITER_INCL_EMPTY_PART0))
+                piter->idx = 0;
+        else
+                piter->idx = 1;
+        piter->flags = flags;
+}
+
+/**
+ * disk_part_iter_next - proceed iterator to the next partition and return it
+ * @piter: iterator of interest
+ *
+ * Proceed @piter to the next partition and return it.
+ *
+ * CONTEXT:
+ * Don't care.
+ */
+static
+struct block_device *wrapper_disk_part_iter_next(struct disk_part_iter *piter)
+{
+        struct block_device *part;
+        unsigned long idx;
+
+        /* put the last partition */
+        wrapper_disk_part_iter_exit(piter);
+
+        rcu_read_lock();
+        xa_for_each_start(&piter->disk->part_tbl, idx, part, piter->idx) {
+                if (!bdev_nr_sectors(part) &&
+                    !(piter->flags & DISK_PITER_INCL_EMPTY) &&
+                    !(piter->flags & DISK_PITER_INCL_EMPTY_PART0 &&
+                      piter->idx == 0))
+                        continue;
+
+                piter->part = bdgrab(part);
+                if (!piter->part)
+                        continue;
+                piter->idx = idx + 1;
+                break;
+        }
+        rcu_read_unlock();
+
+        return piter->part;
+}
+
+#else
+
+static
+void wrapper_disk_part_iter_exit(struct disk_part_iter *piter)
+{
+        disk_part_iter_exit(piter);
+}
+
+static
+void wrapper_disk_part_iter_init(struct disk_part_iter *piter, struct gendisk *disk,
+		                                                          unsigned int flags)
+{
+        disk_part_iter_init(piter, disk, flags);
+}
+
+static
+struct block_device *wrapper_disk_part_iter_next(struct disk_part_iter *piter)
+{
+	return disk_part_iter_next(piter);
+}
+
+#endif
+
 #endif /* _LTTNG_WRAPPER_GENHD_H */
diff --git a/src/lttng-statedump-impl.c b/src/lttng-statedump-impl.c
index b3453bf5..90efe086 100644
--- a/src/lttng-statedump-impl.c
+++ b/src/lttng-statedump-impl.c
@@ -194,7 +194,6 @@ enum lttng_process_status {
 	LTTNG_DEAD = 7,
 };
 
-
 #if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(5,11,0))
 
 #define LTTNG_PART_STRUCT_TYPE struct block_device
@@ -278,19 +277,19 @@ int lttng_enumerate_block_devices(struct lttng_session *session)
 		    (disk->flags & GENHD_FL_SUPPRESS_PARTITION_INFO))
 			continue;
 
-		disk_part_iter_init(&piter, disk, DISK_PITER_INCL_PART0);
-		while ((part = disk_part_iter_next(&piter))) {
+		wrapper_disk_part_iter_init(&piter, disk, DISK_PITER_INCL_PART0);
+		while ((part = wrapper_disk_part_iter_next(&piter))) {
 			char name_buf[BDEVNAME_SIZE];
 
 			if (lttng_get_part_name(disk, part, name_buf) == -ENOSYS) {
-				disk_part_iter_exit(&piter);
+				wrapper_disk_part_iter_exit(&piter);
 				class_dev_iter_exit(&iter);
 				return -ENOSYS;
 			}
 			trace_lttng_statedump_block_device(session,
 					lttng_get_part_devt(part), name_buf);
 		}
-		disk_part_iter_exit(&piter);
+		wrapper_disk_part_iter_exit(&piter);
 	}
 	class_dev_iter_exit(&iter);
 	return 0;
-- 
2.27.0



More information about the lttng-dev mailing list