1 /* 2 * linux/include/kmsg_dump.h 3 * 4 * Copyright (C) 2009 Net Insight AB 5 * 6 * Author: Simon Kagstrom <[email protected]> 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 15 #include <linux/errno.h> 16 #include <linux/list.h> 17 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 */ 23 enum kmsg_dump_reason { 24 KMSG_DUMP_UNDEF, 25 KMSG_DUMP_PANIC, 26 KMSG_DUMP_OOPS, 27 KMSG_DUMP_EMERG, 28 KMSG_DUMP_SHUTDOWN, 29 KMSG_DUMP_MAX 30 }; 31 32 /** 33 * struct kmsg_dumper - kernel crash message dumper structure 34 * @list: Entry in the dumper list (private) 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 38 * @registered: Flag that specifies if this is already registered 39 * @active: Flag that specifies if this is currently dumping 40 * @cur_seq: Points to the oldest message to dump 41 * @next_seq: Points after the newest message to dump 42 */ 43 struct kmsg_dumper { 44 struct list_head list; 45 void (*dump)(struct kmsg_dumper *dumper, enum kmsg_dump_reason reason); 46 enum kmsg_dump_reason max_reason; 47 bool active; 48 bool registered; 49 50 /* private state of the kmsg iterator */ 51 u64 cur_seq; 52 u64 next_seq; 53 }; 54 55 #ifdef CONFIG_PRINTK 56 void kmsg_dump(enum kmsg_dump_reason reason); 57 58 bool kmsg_dump_get_line_nolock(struct kmsg_dumper *dumper, bool syslog, 59 char *line, size_t size, size_t *len); 60 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 67 void kmsg_dump_rewind_nolock(struct kmsg_dumper *dumper); 68 69 void kmsg_dump_rewind(struct kmsg_dumper *dumper); 70 71 int kmsg_dump_register(struct kmsg_dumper *dumper); 72 73 int kmsg_dump_unregister(struct kmsg_dumper *dumper); 74 75 const char *kmsg_dump_reason_str(enum kmsg_dump_reason reason); 76 #else 77 static inline void kmsg_dump(enum kmsg_dump_reason reason) 78 { 79 } 80 81 static inline bool kmsg_dump_get_line_nolock(struct kmsg_dumper *dumper, 82 bool syslog, const char *line, 83 size_t size, size_t *len) 84 { 85 return false; 86 } 87 88 static inline bool kmsg_dump_get_line(struct kmsg_dumper *dumper, bool syslog, 89 const char *line, size_t size, size_t *len) 90 { 91 return false; 92 } 93 94 static inline bool kmsg_dump_get_buffer(struct kmsg_dumper *dumper, bool syslog, 95 char *buf, size_t size, size_t *len) 96 { 97 return false; 98 } 99 100 static inline void kmsg_dump_rewind_nolock(struct kmsg_dumper *dumper) 101 { 102 } 103 104 static inline void kmsg_dump_rewind(struct kmsg_dumper *dumper) 105 { 106 } 107 108 static inline int kmsg_dump_register(struct kmsg_dumper *dumper) 109 { 110 return -EINVAL; 111 } 112 113 static inline int kmsg_dump_unregister(struct kmsg_dumper *dumper) 114 { 115 return -EINVAL; 116 } 117 118 static inline const char *kmsg_dump_reason_str(enum kmsg_dump_reason reason) 119 { 120 return "Disabled"; 121 } 122 #endif 123 124 #endif /* _LINUX_KMSG_DUMP_H */ 125