+static
+int lttng_enumerate_block_devices(struct lttng_session *session)
+{
+ struct class *ptr_block_class;
+ struct device_type *ptr_disk_type;
+ struct class_dev_iter iter;
+ struct device *dev;
+
+ ptr_block_class = wrapper_get_block_class();
+ if (!ptr_block_class)
+ return -ENOSYS;
+ ptr_disk_type = wrapper_get_disk_type();
+ if (!ptr_disk_type) {
+ return -ENOSYS;
+ }
+ class_dev_iter_init(&iter, ptr_block_class, NULL, ptr_disk_type);
+ while ((dev = class_dev_iter_next(&iter))) {
+ struct disk_part_iter piter;
+ struct gendisk *disk = dev_to_disk(dev);
+ struct hd_struct *part;
+
+ /*
+ * Don't show empty devices or things that have been
+ * suppressed
+ */
+ if (get_capacity(disk) == 0 ||
+ (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))) {
+ 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) {
+ disk_part_iter_exit(&piter);
+ class_dev_iter_exit(&iter);
+ return -ENOSYS;
+ }
+ trace_lttng_statedump_block_device(session,
+ part_devt(part), name_buf);
+ }
+ disk_part_iter_exit(&piter);
+ }
+ class_dev_iter_exit(&iter);
+ return 0;
+}
+