| .. | .. |
|---|
| 1 | 1 | // SPDX-License-Identifier: GPL-2.0 |
|---|
| 2 | 2 | #include <linux/kmsg_dump.h> |
|---|
| 3 | +#include <linux/spinlock.h> |
|---|
| 3 | 4 | #include <linux/console.h> |
|---|
| 4 | 5 | #include <shared/init.h> |
|---|
| 5 | 6 | #include <shared/kern.h> |
|---|
| 6 | 7 | #include <os.h> |
|---|
| 7 | 8 | |
|---|
| 8 | 9 | static void kmsg_dumper_stdout(struct kmsg_dumper *dumper, |
|---|
| 9 | | - enum kmsg_dump_reason reason) |
|---|
| 10 | + enum kmsg_dump_reason reason, |
|---|
| 11 | + struct kmsg_dumper_iter *iter) |
|---|
| 10 | 12 | { |
|---|
| 13 | + static DEFINE_SPINLOCK(lock); |
|---|
| 11 | 14 | static char line[1024]; |
|---|
| 12 | | - |
|---|
| 15 | + struct console *con; |
|---|
| 16 | + unsigned long flags; |
|---|
| 13 | 17 | size_t len = 0; |
|---|
| 14 | | - bool con_available = false; |
|---|
| 15 | 18 | |
|---|
| 16 | 19 | /* only dump kmsg when no console is available */ |
|---|
| 17 | 20 | if (!console_trylock()) |
|---|
| 18 | 21 | return; |
|---|
| 19 | 22 | |
|---|
| 20 | | - if (console_drivers != NULL) |
|---|
| 21 | | - con_available = true; |
|---|
| 23 | + for_each_console(con) |
|---|
| 24 | + break; |
|---|
| 22 | 25 | |
|---|
| 23 | 26 | console_unlock(); |
|---|
| 24 | 27 | |
|---|
| 25 | | - if (con_available == true) |
|---|
| 28 | + if (con) |
|---|
| 29 | + return; |
|---|
| 30 | + |
|---|
| 31 | + if (!spin_trylock_irqsave(&lock, flags)) |
|---|
| 26 | 32 | return; |
|---|
| 27 | 33 | |
|---|
| 28 | 34 | printf("kmsg_dump:\n"); |
|---|
| 29 | | - while (kmsg_dump_get_line(dumper, true, line, sizeof(line), &len)) { |
|---|
| 35 | + while (kmsg_dump_get_line(iter, true, line, sizeof(line), &len)) { |
|---|
| 30 | 36 | line[len] = '\0'; |
|---|
| 31 | 37 | printf("%s", line); |
|---|
| 32 | 38 | } |
|---|
| 39 | + |
|---|
| 40 | + spin_unlock_irqrestore(&lock, flags); |
|---|
| 33 | 41 | } |
|---|
| 34 | 42 | |
|---|
| 35 | 43 | static struct kmsg_dumper kmsg_dumper = { |
|---|