fix: block: merge struct block_device and struct hd_struct (v5.11)
authorMichael Jeanson <mjeanson@efficios.com>
Wed, 13 Jan 2021 19:27:41 +0000 (14:27 -0500)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Tue, 19 Jan 2021 20:26:30 +0000 (15:26 -0500)
See upstream commit :

  commit 0d02129e76edf91cf04fabf1efbc3a9a1f1d729a
  Author: Christoph Hellwig <hch@lst.de>
  Date:   Fri Nov 27 16:43:51 2020 +0100

    block: merge struct block_device and struct hd_struct

    Instead of having two structures that represent each block device with
    different life time rules, merge them into a single one.  This also
    greatly simplifies the reference counting rules, as we can use the inode
    reference count as the main reference count for the new struct
    block_device, with the device model reference front ending it for device
    model interaction.

Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Change-Id: Iaf663c689edb23905aeedc182d2aa268981f13dd

lttng-statedump-impl.c

index a8c32db5e83eea3ac0933b15f54e027b55687105..b5bfa9fb033a0c6682cfbc52f35c9b970f8adbae 100644 (file)
@@ -136,6 +136,61 @@ enum lttng_process_status {
        LTTNG_DEAD = 7,
 };
 
+
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5,11,0))
+
+#define LTTNG_PART_STRUCT_TYPE struct block_device
+
+static
+int lttng_get_part_name(struct gendisk *disk, struct block_device *part, char *name_buf)
+{
+       const char *p;
+
+       p = bdevname(part, name_buf);
+       if (!p)
+               return -ENOSYS;
+
+       return 0;
+}
+
+static
+dev_t lttng_get_part_devt(struct block_device *part)
+{
+       return part->bd_dev;
+}
+
+#else
+
+#define LTTNG_PART_STRUCT_TYPE struct hd_struct
+
+static
+int lttng_get_part_name(struct gendisk *disk, struct hd_struct *part, char *name_buf)
+{
+       const char *p;
+       struct block_device bdev;
+
+       /*
+        * Create a partial 'struct blockdevice' to use
+        * 'bdevname()' which is a simple wrapper over
+        * 'disk_name()' but has the honor to be EXPORT_SYMBOL.
+        */
+       bdev.bd_disk = disk;
+       bdev.bd_part = part;
+
+       p = bdevname(&bdev, name_buf);
+       if (!p)
+               return -ENOSYS;
+
+       return 0;
+}
+
+static
+dev_t lttng_get_part_devt(struct hd_struct *part)
+{
+       return part_devt(part);
+}
+#endif
+
 static
 int lttng_enumerate_block_devices(struct lttng_session *session)
 {
@@ -155,7 +210,7 @@ int lttng_enumerate_block_devices(struct lttng_session *session)
        while ((dev = class_dev_iter_next(&iter))) {
                struct disk_part_iter piter;
                struct gendisk *disk = dev_to_disk(dev);
-               struct hd_struct *part;
+               LTTNG_PART_STRUCT_TYPE *part;
 
                /*
                 * Don't show empty devices or things that have been
@@ -167,26 +222,15 @@ int lttng_enumerate_block_devices(struct lttng_session *session)
 
                disk_part_iter_init(&piter, disk, DISK_PITER_INCL_PART0);
                while ((part = disk_part_iter_next(&piter))) {
-                       struct block_device bdev;
                        char name_buf[BDEVNAME_SIZE];
-                       const char *p;
-
-                       /*
-                        * Create a partial 'struct blockdevice' to use
-                        * 'bdevname()' which is a simple wrapper over
-                        * 'disk_name()' but has the honor to be EXPORT_SYMBOL.
-                        */
-                       bdev.bd_disk = disk;
-                       bdev.bd_part = part;
 
-                       p = bdevname(&bdev, name_buf);
-                       if (!p) {
+                       if (lttng_get_part_name(disk, part, name_buf) == -ENOSYS) {
                                disk_part_iter_exit(&piter);
                                class_dev_iter_exit(&iter);
                                return -ENOSYS;
                        }
                        trace_lttng_statedump_block_device(session,
-                                       part_devt(part), name_buf);
+                                       lttng_get_part_devt(part), name_buf);
                }
                disk_part_iter_exit(&piter);
        }
This page took 0.028617 seconds and 4 git commands to generate.