Commit | Line | Data |
---|---|---|
456b565c SK |
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 | ||
ac562241 | 15 | #include <linux/errno.h> |
456b565c SK |
16 | #include <linux/list.h> |
17 | ||
c22ab332 MG |
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 | */ | |
456b565c | 23 | enum kmsg_dump_reason { |
e2ae715d | 24 | KMSG_DUMP_UNDEF, |
456b565c | 25 | KMSG_DUMP_PANIC, |
c22ab332 MG |
26 | KMSG_DUMP_OOPS, |
27 | KMSG_DUMP_EMERG, | |
6d3cf962 | 28 | KMSG_DUMP_SHUTDOWN, |
b1f6f161 | 29 | KMSG_DUMP_MAX |
456b565c SK |
30 | }; |
31 | ||
f9f3f02d JO |
32 | /** |
33 | * struct kmsg_dump_iter - iterator for retrieving kernel messages | |
34 | * @cur_seq: Points to the oldest message to dump | |
35 | * @next_seq: Points after the newest message to dump | |
36 | */ | |
37 | struct kmsg_dump_iter { | |
38 | u64 cur_seq; | |
39 | u64 next_seq; | |
40 | }; | |
41 | ||
e1a261ba JF |
42 | /** |
43 | * struct kmsg_dump_detail - kernel crash detail | |
44 | * @reason: reason for the crash, see kmsg_dump_reason. | |
45 | * @description: optional short string, to provide additional information. | |
46 | */ | |
47 | ||
48 | struct kmsg_dump_detail { | |
49 | enum kmsg_dump_reason reason; | |
50 | const char *description; | |
51 | }; | |
52 | ||
456b565c SK |
53 | /** |
54 | * struct kmsg_dumper - kernel crash message dumper structure | |
456b565c | 55 | * @list: Entry in the dumper list (private) |
e2ae715d KS |
56 | * @dump: Call into dumping code which will retrieve the data with |
57 | * through the record iterator | |
58 | * @max_reason: filter for highest reason number that should be dumped | |
456b565c SK |
59 | * @registered: Flag that specifies if this is already registered |
60 | */ | |
61 | struct kmsg_dumper { | |
456b565c | 62 | struct list_head list; |
e1a261ba | 63 | void (*dump)(struct kmsg_dumper *dumper, struct kmsg_dump_detail *detail); |
e2ae715d | 64 | enum kmsg_dump_reason max_reason; |
e2ae715d | 65 | bool registered; |
456b565c SK |
66 | }; |
67 | ||
595dd3d8 | 68 | #ifdef CONFIG_PRINTK |
e1a261ba | 69 | void kmsg_dump_desc(enum kmsg_dump_reason reason, const char *desc); |
456b565c | 70 | |
f9f3f02d | 71 | bool kmsg_dump_get_line(struct kmsg_dump_iter *iter, bool syslog, |
e2ae715d KS |
72 | char *line, size_t size, size_t *len); |
73 | ||
f9f3f02d | 74 | bool kmsg_dump_get_buffer(struct kmsg_dump_iter *iter, bool syslog, |
726b5097 | 75 | char *buf, size_t size, size_t *len_out); |
e2ae715d | 76 | |
f9f3f02d | 77 | void kmsg_dump_rewind(struct kmsg_dump_iter *iter); |
e2ae715d | 78 | |
456b565c SK |
79 | int kmsg_dump_register(struct kmsg_dumper *dumper); |
80 | ||
81 | int kmsg_dump_unregister(struct kmsg_dumper *dumper); | |
fb13cb8a KC |
82 | |
83 | const char *kmsg_dump_reason_str(enum kmsg_dump_reason reason); | |
595dd3d8 | 84 | #else |
e1a261ba | 85 | static inline void kmsg_dump_desc(enum kmsg_dump_reason reason, const char *desc) |
595dd3d8 RD |
86 | { |
87 | } | |
88 | ||
f9f3f02d | 89 | static inline bool kmsg_dump_get_line(struct kmsg_dump_iter *iter, bool syslog, |
246f6f2f | 90 | const char *line, size_t size, size_t *len) |
e2ae715d KS |
91 | { |
92 | return false; | |
93 | } | |
94 | ||
f9f3f02d | 95 | static inline bool kmsg_dump_get_buffer(struct kmsg_dump_iter *iter, bool syslog, |
246f6f2f | 96 | char *buf, size_t size, size_t *len) |
e2ae715d KS |
97 | { |
98 | return false; | |
99 | } | |
100 | ||
f9f3f02d | 101 | static inline void kmsg_dump_rewind(struct kmsg_dump_iter *iter) |
e2ae715d KS |
102 | { |
103 | } | |
104 | ||
595dd3d8 RD |
105 | static inline int kmsg_dump_register(struct kmsg_dumper *dumper) |
106 | { | |
107 | return -EINVAL; | |
108 | } | |
109 | ||
110 | static inline int kmsg_dump_unregister(struct kmsg_dumper *dumper) | |
111 | { | |
112 | return -EINVAL; | |
113 | } | |
fb13cb8a KC |
114 | |
115 | static inline const char *kmsg_dump_reason_str(enum kmsg_dump_reason reason) | |
116 | { | |
117 | return "Disabled"; | |
118 | } | |
595dd3d8 | 119 | #endif |
456b565c | 120 | |
e1a261ba JF |
121 | static inline void kmsg_dump(enum kmsg_dump_reason reason) |
122 | { | |
123 | kmsg_dump_desc(reason, NULL); | |
124 | } | |
125 | ||
456b565c | 126 | #endif /* _LINUX_KMSG_DUMP_H */ |