Simon Kagstrom | 456b565 | 2009-10-16 14:09:18 +0200 | [diff] [blame] | 1 | /* |
| 2 | * linux/include/kmsg_dump.h |
| 3 | * |
| 4 | * Copyright (C) 2009 Net Insight AB |
| 5 | * |
| 6 | * Author: Simon Kagstrom <simon.kagstrom@netinsight.net> |
| 7 | * |
| 8 | * This file is subject to the terms and conditions of the GNU General Public |
| 9 | * License. See the file COPYING in the main directory of this archive |
| 10 | * for more details. |
| 11 | */ |
| 12 | #ifndef _LINUX_KMSG_DUMP_H |
| 13 | #define _LINUX_KMSG_DUMP_H |
| 14 | |
Randy Dunlap | ac56224 | 2011-06-15 15:08:17 -0700 | [diff] [blame] | 15 | #include <linux/errno.h> |
Simon Kagstrom | 456b565 | 2009-10-16 14:09:18 +0200 | [diff] [blame] | 16 | #include <linux/list.h> |
| 17 | |
Matthew Garrett | c22ab332 | 2012-03-05 14:59:10 -0800 | [diff] [blame] | 18 | /* |
| 19 | * Keep this list arranged in rough order of priority. Anything listed after |
| 20 | * KMSG_DUMP_OOPS will not be logged by default unless printk.always_kmsg_dump |
| 21 | * is passed to the kernel. |
| 22 | */ |
Simon Kagstrom | 456b565 | 2009-10-16 14:09:18 +0200 | [diff] [blame] | 23 | enum kmsg_dump_reason { |
Kay Sievers | e2ae715 | 2012-06-15 14:07:51 +0200 | [diff] [blame] | 24 | KMSG_DUMP_UNDEF, |
Simon Kagstrom | 456b565 | 2009-10-16 14:09:18 +0200 | [diff] [blame] | 25 | KMSG_DUMP_PANIC, |
Matthew Garrett | c22ab332 | 2012-03-05 14:59:10 -0800 | [diff] [blame] | 26 | KMSG_DUMP_OOPS, |
| 27 | KMSG_DUMP_EMERG, |
Kees Cook | 6d3cf96 | 2020-05-15 11:05:43 -0700 | [diff] [blame] | 28 | KMSG_DUMP_SHUTDOWN, |
Pavel Tatashin | b1f6f16 | 2020-05-05 11:45:06 -0400 | [diff] [blame] | 29 | KMSG_DUMP_MAX |
Simon Kagstrom | 456b565 | 2009-10-16 14:09:18 +0200 | [diff] [blame] | 30 | }; |
| 31 | |
| 32 | /** |
| 33 | * struct kmsg_dumper - kernel crash message dumper structure |
Simon Kagstrom | 456b565 | 2009-10-16 14:09:18 +0200 | [diff] [blame] | 34 | * @list: Entry in the dumper list (private) |
Kay Sievers | e2ae715 | 2012-06-15 14:07:51 +0200 | [diff] [blame] | 35 | * @dump: Call into dumping code which will retrieve the data with |
| 36 | * through the record iterator |
| 37 | * @max_reason: filter for highest reason number that should be dumped |
Simon Kagstrom | 456b565 | 2009-10-16 14:09:18 +0200 | [diff] [blame] | 38 | * @registered: Flag that specifies if this is already registered |
| 39 | */ |
| 40 | struct kmsg_dumper { |
Simon Kagstrom | 456b565 | 2009-10-16 14:09:18 +0200 | [diff] [blame] | 41 | struct list_head list; |
Kay Sievers | e2ae715 | 2012-06-15 14:07:51 +0200 | [diff] [blame] | 42 | void (*dump)(struct kmsg_dumper *dumper, enum kmsg_dump_reason reason); |
| 43 | enum kmsg_dump_reason max_reason; |
| 44 | bool active; |
| 45 | bool registered; |
| 46 | |
| 47 | /* private state of the kmsg iterator */ |
| 48 | u32 cur_idx; |
| 49 | u32 next_idx; |
| 50 | u64 cur_seq; |
| 51 | u64 next_seq; |
Simon Kagstrom | 456b565 | 2009-10-16 14:09:18 +0200 | [diff] [blame] | 52 | }; |
| 53 | |
Randy Dunlap | 595dd3d | 2009-12-01 10:52:02 -0800 | [diff] [blame] | 54 | #ifdef CONFIG_PRINTK |
Simon Kagstrom | 456b565 | 2009-10-16 14:09:18 +0200 | [diff] [blame] | 55 | void kmsg_dump(enum kmsg_dump_reason reason); |
| 56 | |
Anton Vorontsov | 533827c | 2012-07-20 17:28:07 -0700 | [diff] [blame] | 57 | bool kmsg_dump_get_line_nolock(struct kmsg_dumper *dumper, bool syslog, |
| 58 | char *line, size_t size, size_t *len); |
| 59 | |
Kay Sievers | e2ae715 | 2012-06-15 14:07:51 +0200 | [diff] [blame] | 60 | bool kmsg_dump_get_line(struct kmsg_dumper *dumper, bool syslog, |
| 61 | char *line, size_t size, size_t *len); |
| 62 | |
| 63 | bool kmsg_dump_get_buffer(struct kmsg_dumper *dumper, bool syslog, |
| 64 | char *buf, size_t size, size_t *len); |
| 65 | |
Anton Vorontsov | 533827c | 2012-07-20 17:28:07 -0700 | [diff] [blame] | 66 | void kmsg_dump_rewind_nolock(struct kmsg_dumper *dumper); |
| 67 | |
Kay Sievers | e2ae715 | 2012-06-15 14:07:51 +0200 | [diff] [blame] | 68 | void kmsg_dump_rewind(struct kmsg_dumper *dumper); |
| 69 | |
Simon Kagstrom | 456b565 | 2009-10-16 14:09:18 +0200 | [diff] [blame] | 70 | int kmsg_dump_register(struct kmsg_dumper *dumper); |
| 71 | |
| 72 | int kmsg_dump_unregister(struct kmsg_dumper *dumper); |
Kees Cook | fb13cb8 | 2020-05-07 19:36:22 -0700 | [diff] [blame] | 73 | |
| 74 | const char *kmsg_dump_reason_str(enum kmsg_dump_reason reason); |
Randy Dunlap | 595dd3d | 2009-12-01 10:52:02 -0800 | [diff] [blame] | 75 | #else |
| 76 | static inline void kmsg_dump(enum kmsg_dump_reason reason) |
| 77 | { |
| 78 | } |
| 79 | |
Anton Vorontsov | 533827c | 2012-07-20 17:28:07 -0700 | [diff] [blame] | 80 | static inline bool kmsg_dump_get_line_nolock(struct kmsg_dumper *dumper, |
| 81 | bool syslog, const char *line, |
| 82 | size_t size, size_t *len) |
| 83 | { |
| 84 | return false; |
| 85 | } |
| 86 | |
Kay Sievers | 246f6f2 | 2012-06-19 00:32:57 +0200 | [diff] [blame] | 87 | static inline bool kmsg_dump_get_line(struct kmsg_dumper *dumper, bool syslog, |
| 88 | const char *line, size_t size, size_t *len) |
Kay Sievers | e2ae715 | 2012-06-15 14:07:51 +0200 | [diff] [blame] | 89 | { |
| 90 | return false; |
| 91 | } |
| 92 | |
Kay Sievers | 246f6f2 | 2012-06-19 00:32:57 +0200 | [diff] [blame] | 93 | static inline bool kmsg_dump_get_buffer(struct kmsg_dumper *dumper, bool syslog, |
| 94 | char *buf, size_t size, size_t *len) |
Kay Sievers | e2ae715 | 2012-06-15 14:07:51 +0200 | [diff] [blame] | 95 | { |
| 96 | return false; |
| 97 | } |
| 98 | |
Anton Vorontsov | 533827c | 2012-07-20 17:28:07 -0700 | [diff] [blame] | 99 | static inline void kmsg_dump_rewind_nolock(struct kmsg_dumper *dumper) |
| 100 | { |
| 101 | } |
| 102 | |
Kay Sievers | 246f6f2 | 2012-06-19 00:32:57 +0200 | [diff] [blame] | 103 | static inline void kmsg_dump_rewind(struct kmsg_dumper *dumper) |
Kay Sievers | e2ae715 | 2012-06-15 14:07:51 +0200 | [diff] [blame] | 104 | { |
| 105 | } |
| 106 | |
Randy Dunlap | 595dd3d | 2009-12-01 10:52:02 -0800 | [diff] [blame] | 107 | static inline int kmsg_dump_register(struct kmsg_dumper *dumper) |
| 108 | { |
| 109 | return -EINVAL; |
| 110 | } |
| 111 | |
| 112 | static inline int kmsg_dump_unregister(struct kmsg_dumper *dumper) |
| 113 | { |
| 114 | return -EINVAL; |
| 115 | } |
Kees Cook | fb13cb8 | 2020-05-07 19:36:22 -0700 | [diff] [blame] | 116 | |
| 117 | static inline const char *kmsg_dump_reason_str(enum kmsg_dump_reason reason) |
| 118 | { |
| 119 | return "Disabled"; |
| 120 | } |
Randy Dunlap | 595dd3d | 2009-12-01 10:52:02 -0800 | [diff] [blame] | 121 | #endif |
Simon Kagstrom | 456b565 | 2009-10-16 14:09:18 +0200 | [diff] [blame] | 122 | |
| 123 | #endif /* _LINUX_KMSG_DUMP_H */ |