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 | c22ab33 | 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 | c22ab33 | 2012-03-05 14:59:10 -0800 | [diff] [blame] | 26 | KMSG_DUMP_OOPS, |
| 27 | KMSG_DUMP_EMERG, |
Seiji Aguchi | 04c6862 | 2011-01-12 16:59:30 -0800 | [diff] [blame] | 28 | KMSG_DUMP_RESTART, |
| 29 | KMSG_DUMP_HALT, |
| 30 | KMSG_DUMP_POWEROFF, |
Simon Kagstrom | 456b565 | 2009-10-16 14:09:18 +0200 | [diff] [blame] | 31 | }; |
| 32 | |
| 33 | /** |
| 34 | * struct kmsg_dumper - kernel crash message dumper structure |
Simon Kagstrom | 456b565 | 2009-10-16 14:09:18 +0200 | [diff] [blame] | 35 | * @list: Entry in the dumper list (private) |
Kay Sievers | e2ae715 | 2012-06-15 14:07:51 +0200 | [diff] [blame] | 36 | * @dump: Call into dumping code which will retrieve the data with |
| 37 | * through the record iterator |
| 38 | * @max_reason: filter for highest reason number that should be dumped |
Simon Kagstrom | 456b565 | 2009-10-16 14:09:18 +0200 | [diff] [blame] | 39 | * @registered: Flag that specifies if this is already registered |
| 40 | */ |
| 41 | struct kmsg_dumper { |
Simon Kagstrom | 456b565 | 2009-10-16 14:09:18 +0200 | [diff] [blame] | 42 | struct list_head list; |
Kay Sievers | e2ae715 | 2012-06-15 14:07:51 +0200 | [diff] [blame] | 43 | void (*dump)(struct kmsg_dumper *dumper, enum kmsg_dump_reason reason); |
| 44 | enum kmsg_dump_reason max_reason; |
| 45 | bool active; |
| 46 | bool registered; |
| 47 | |
| 48 | /* private state of the kmsg iterator */ |
| 49 | u32 cur_idx; |
| 50 | u32 next_idx; |
| 51 | u64 cur_seq; |
| 52 | u64 next_seq; |
Simon Kagstrom | 456b565 | 2009-10-16 14:09:18 +0200 | [diff] [blame] | 53 | }; |
| 54 | |
Randy Dunlap | 595dd3d | 2009-12-01 10:52:02 -0800 | [diff] [blame] | 55 | #ifdef CONFIG_PRINTK |
Simon Kagstrom | 456b565 | 2009-10-16 14:09:18 +0200 | [diff] [blame] | 56 | void kmsg_dump(enum kmsg_dump_reason reason); |
| 57 | |
Anton Vorontsov | 533827c | 2012-07-20 17:28:07 -0700 | [diff] [blame] | 58 | bool kmsg_dump_get_line_nolock(struct kmsg_dumper *dumper, bool syslog, |
| 59 | char *line, size_t size, size_t *len); |
| 60 | |
Kay Sievers | e2ae715 | 2012-06-15 14:07:51 +0200 | [diff] [blame] | 61 | bool kmsg_dump_get_line(struct kmsg_dumper *dumper, bool syslog, |
| 62 | char *line, size_t size, size_t *len); |
| 63 | |
| 64 | bool kmsg_dump_get_buffer(struct kmsg_dumper *dumper, bool syslog, |
| 65 | char *buf, size_t size, size_t *len); |
| 66 | |
Anton Vorontsov | 533827c | 2012-07-20 17:28:07 -0700 | [diff] [blame] | 67 | void kmsg_dump_rewind_nolock(struct kmsg_dumper *dumper); |
| 68 | |
Kay Sievers | e2ae715 | 2012-06-15 14:07:51 +0200 | [diff] [blame] | 69 | void kmsg_dump_rewind(struct kmsg_dumper *dumper); |
| 70 | |
Simon Kagstrom | 456b565 | 2009-10-16 14:09:18 +0200 | [diff] [blame] | 71 | int kmsg_dump_register(struct kmsg_dumper *dumper); |
| 72 | |
| 73 | int kmsg_dump_unregister(struct kmsg_dumper *dumper); |
Randy Dunlap | 595dd3d | 2009-12-01 10:52:02 -0800 | [diff] [blame] | 74 | #else |
| 75 | static inline void kmsg_dump(enum kmsg_dump_reason reason) |
| 76 | { |
| 77 | } |
| 78 | |
Anton Vorontsov | 533827c | 2012-07-20 17:28:07 -0700 | [diff] [blame] | 79 | static inline bool kmsg_dump_get_line_nolock(struct kmsg_dumper *dumper, |
| 80 | bool syslog, const char *line, |
| 81 | size_t size, size_t *len) |
| 82 | { |
| 83 | return false; |
| 84 | } |
| 85 | |
Kay Sievers | 246f6f2 | 2012-06-19 00:32:57 +0200 | [diff] [blame] | 86 | static inline bool kmsg_dump_get_line(struct kmsg_dumper *dumper, bool syslog, |
| 87 | const char *line, size_t size, size_t *len) |
Kay Sievers | e2ae715 | 2012-06-15 14:07:51 +0200 | [diff] [blame] | 88 | { |
| 89 | return false; |
| 90 | } |
| 91 | |
Kay Sievers | 246f6f2 | 2012-06-19 00:32:57 +0200 | [diff] [blame] | 92 | static inline bool kmsg_dump_get_buffer(struct kmsg_dumper *dumper, bool syslog, |
| 93 | char *buf, size_t size, size_t *len) |
Kay Sievers | e2ae715 | 2012-06-15 14:07:51 +0200 | [diff] [blame] | 94 | { |
| 95 | return false; |
| 96 | } |
| 97 | |
Anton Vorontsov | 533827c | 2012-07-20 17:28:07 -0700 | [diff] [blame] | 98 | static inline void kmsg_dump_rewind_nolock(struct kmsg_dumper *dumper) |
| 99 | { |
| 100 | } |
| 101 | |
Kay Sievers | 246f6f2 | 2012-06-19 00:32:57 +0200 | [diff] [blame] | 102 | static inline void kmsg_dump_rewind(struct kmsg_dumper *dumper) |
Kay Sievers | e2ae715 | 2012-06-15 14:07:51 +0200 | [diff] [blame] | 103 | { |
| 104 | } |
| 105 | |
Randy Dunlap | 595dd3d | 2009-12-01 10:52:02 -0800 | [diff] [blame] | 106 | static inline int kmsg_dump_register(struct kmsg_dumper *dumper) |
| 107 | { |
| 108 | return -EINVAL; |
| 109 | } |
| 110 | |
| 111 | static inline int kmsg_dump_unregister(struct kmsg_dumper *dumper) |
| 112 | { |
| 113 | return -EINVAL; |
| 114 | } |
| 115 | #endif |
Simon Kagstrom | 456b565 | 2009-10-16 14:09:18 +0200 | [diff] [blame] | 116 | |
| 117 | #endif /* _LINUX_KMSG_DUMP_H */ |