fix: jbd2 upper bound for v5.10.163
[lttng-modules.git] / lttng-statedump-impl.c
index 60b937c98b77f22ab5a1cac6eb331f4900eedbf2..a33759d43d34f1b2362c20b031e405a021e3ded7 100644 (file)
 #include <linux/file.h>
 #include <linux/interrupt.h>
 #include <linux/irqnr.h>
-#include <linux/cpu.h>
 #include <linux/netdevice.h>
 #include <linux/inetdevice.h>
-#include <linux/sched.h>
 #include <linux/mm.h>
 #include <linux/swap.h>
 #include <linux/wait.h>
 #include <linux/mutex.h>
 #include <linux/device.h>
 
+#include <linux/blkdev.h>
+
 #include <lttng-events.h>
 #include <lttng-tracer.h>
+#include <wrapper/cpu.h>
 #include <wrapper/irqdesc.h>
 #include <wrapper/fdtable.h>
 #include <wrapper/namespace.h>
@@ -43,6 +44,7 @@
 #include <wrapper/genhd.h>
 #include <wrapper/file.h>
 #include <wrapper/fdtable.h>
+#include <wrapper/sched.h>
 
 #ifdef CONFIG_LTTNG_HAS_LIST_IRQ
 #include <linux/irq.h>
@@ -243,6 +245,61 @@ dev_t lttng_get_part_devt(struct hd_struct *part)
 }
 #endif
 
+#if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(5,12,0))
+static
+int lttng_statedump_each_block_device(struct lttng_session *session, struct gendisk *disk)
+{
+       struct block_device *part;
+       unsigned long idx;
+       int ret = 0;
+
+       /* Include partition 0 */
+       idx = 0;
+
+       rcu_read_lock();
+       xa_for_each(&disk->part_tbl, idx, part) {
+               char name_buf[BDEVNAME_SIZE];
+
+               /* Exclude non-partitions bdev and empty partitions. */
+               if (bdev_is_partition(part) && !bdev_nr_sectors(part))
+                       continue;
+
+               if (lttng_get_part_name(disk, part, name_buf) == -ENOSYS) {
+                       ret = -ENOSYS;
+                       goto end;
+               }
+               trace_lttng_statedump_block_device(session, lttng_get_part_devt(part),
+                               name_buf);
+       }
+end:
+       rcu_read_unlock();
+       return ret;
+}
+#else
+static
+int lttng_statedump_each_block_device(struct lttng_session *session, struct gendisk *disk)
+{
+       struct disk_part_iter piter;
+       LTTNG_PART_STRUCT_TYPE *part;
+
+       disk_part_iter_init(&piter, disk, DISK_PITER_INCL_PART0);
+
+       while ((part = 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);
+                       return -ENOSYS;
+               }
+               trace_lttng_statedump_block_device(session, lttng_get_part_devt(part),
+                               name_buf);
+       }
+       disk_part_iter_exit(&piter);
+
+       return 0;
+}
+#endif
+
 static
 int lttng_enumerate_block_devices(struct lttng_session *session)
 {
@@ -250,44 +307,35 @@ int lttng_enumerate_block_devices(struct lttng_session *session)
        struct device_type *ptr_disk_type;
        struct class_dev_iter iter;
        struct device *dev;
+       int ret = 0;
 
        ptr_block_class = wrapper_get_block_class();
-       if (!ptr_block_class)
-               return -ENOSYS;
+       if (!ptr_block_class) {
+               ret = -ENOSYS;
+               goto end;
+       }
        ptr_disk_type = wrapper_get_disk_type();
        if (!ptr_disk_type) {
-               return -ENOSYS;
+               ret = -ENOSYS;
+               goto end;
        }
        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);
-               LTTNG_PART_STRUCT_TYPE *part;
 
                /*
                 * Don't show empty devices or things that have been
                 * suppressed
                 */
                if (get_capacity(disk) == 0 ||
-                   (disk->flags & GENHD_FL_SUPPRESS_PARTITION_INFO))
+                   (disk->flags & LTTNG_GENHD_FL_HIDDEN))
                        continue;
 
-               disk_part_iter_init(&piter, disk, DISK_PITER_INCL_PART0);
-               while ((part = 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);
-                               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);
+               ret = lttng_statedump_each_block_device(session, disk);
        }
        class_dev_iter_exit(&iter);
-       return 0;
+end:
+       return ret;
 }
 
 #ifdef CONFIG_INET
@@ -605,7 +653,7 @@ int lttng_enumerate_process_states(struct lttng_session *session)
                                status = LTTNG_ZOMBIE;
                        else if (p->exit_state == EXIT_DEAD)
                                status = LTTNG_DEAD;
-                       else if (p->state == TASK_RUNNING) {
+                       else if (lttng_task_is_running(p)) {
                                /* Is this a forked child that has not run yet? */
                                if (list_empty(&p->rt.run_list))
                                        status = LTTNG_WAIT_FORK;
@@ -616,7 +664,7 @@ int lttng_enumerate_process_states(struct lttng_session *session)
                                         * was really running at this time.
                                         */
                                        status = LTTNG_WAIT_CPU;
-                       } else if (p->state &
+                       } else if (lttng_get_task_state(p) &
                                (TASK_INTERRUPTIBLE | TASK_UNINTERRUPTIBLE)) {
                                /* Task is waiting for something to complete */
                                status = LTTNG_WAIT;
@@ -714,7 +762,7 @@ int do_lttng_statedump(struct lttng_session *session)
         * is to guarantee that each CPU has been in a state where is was in
         * syscall mode (i.e. not in a trap, an IRQ or a soft IRQ).
         */
-       get_online_cpus();
+       lttng_cpus_read_lock();
        atomic_set(&kernel_threads_to_run, num_online_cpus());
        for_each_online_cpu(cpu) {
                INIT_DELAYED_WORK(&cpu_work[cpu], lttng_statedump_work_func);
@@ -722,7 +770,7 @@ int do_lttng_statedump(struct lttng_session *session)
        }
        /* Wait for all threads to run */
        __wait_event(statedump_wq, (atomic_read(&kernel_threads_to_run) == 0));
-       put_online_cpus();
+       lttng_cpus_read_unlock();
        /* Our work is done */
        trace_lttng_statedump_end(session);
        return 0;
This page took 0.029152 seconds and 4 git commands to generate.