lttng-dev.lists.lttng.org archive mirror
 help / color / mirror / Atom feed
* [lttng-dev] [PATCH lttng-modules] Fix: lttng-statedump-impl: wrap some helpers unexported in kernel
@ 2021-03-29 11:30 Yanfei Xu via lttng-dev
  0 siblings, 0 replies; only message in thread
From: Yanfei Xu via lttng-dev @ 2021-03-29 11:30 UTC (permalink / raw)
  To: lttng-dev

From: Yanfei Xu <yanfei.xu@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@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

_______________________________________________
lttng-dev mailing list
lttng-dev@lists.lttng.org
https://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-03-29 11:30 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-29 11:30 [lttng-dev] [PATCH lttng-modules] Fix: lttng-statedump-impl: wrap some helpers unexported in kernel Yanfei Xu via lttng-dev

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).