Back to home page

OSCL-LXR

 
 

    


0001 /*
0002  * linux/include/kmsg_dump.h
0003  *
0004  * Copyright (C) 2009 Net Insight AB
0005  *
0006  * Author: Simon Kagstrom <simon.kagstrom@netinsight.net>
0007  *
0008  * This file is subject to the terms and conditions of the GNU General Public
0009  * License.  See the file COPYING in the main directory of this archive
0010  * for more details.
0011  */
0012 #ifndef _LINUX_KMSG_DUMP_H
0013 #define _LINUX_KMSG_DUMP_H
0014 
0015 #include <linux/errno.h>
0016 #include <linux/list.h>
0017 
0018 /*
0019  * Keep this list arranged in rough order of priority. Anything listed after
0020  * KMSG_DUMP_OOPS will not be logged by default unless printk.always_kmsg_dump
0021  * is passed to the kernel.
0022  */
0023 enum kmsg_dump_reason {
0024     KMSG_DUMP_UNDEF,
0025     KMSG_DUMP_PANIC,
0026     KMSG_DUMP_OOPS,
0027     KMSG_DUMP_EMERG,
0028     KMSG_DUMP_SHUTDOWN,
0029     KMSG_DUMP_MAX
0030 };
0031 
0032 /**
0033  * struct kmsg_dump_iter - iterator for retrieving kernel messages
0034  * @cur_seq:    Points to the oldest message to dump
0035  * @next_seq:   Points after the newest message to dump
0036  */
0037 struct kmsg_dump_iter {
0038     u64 cur_seq;
0039     u64 next_seq;
0040 };
0041 
0042 /**
0043  * struct kmsg_dumper - kernel crash message dumper structure
0044  * @list:   Entry in the dumper list (private)
0045  * @dump:   Call into dumping code which will retrieve the data with
0046  *      through the record iterator
0047  * @max_reason: filter for highest reason number that should be dumped
0048  * @registered: Flag that specifies if this is already registered
0049  */
0050 struct kmsg_dumper {
0051     struct list_head list;
0052     void (*dump)(struct kmsg_dumper *dumper, enum kmsg_dump_reason reason);
0053     enum kmsg_dump_reason max_reason;
0054     bool registered;
0055 };
0056 
0057 #ifdef CONFIG_PRINTK
0058 void kmsg_dump(enum kmsg_dump_reason reason);
0059 
0060 bool kmsg_dump_get_line(struct kmsg_dump_iter *iter, bool syslog,
0061             char *line, size_t size, size_t *len);
0062 
0063 bool kmsg_dump_get_buffer(struct kmsg_dump_iter *iter, bool syslog,
0064               char *buf, size_t size, size_t *len_out);
0065 
0066 void kmsg_dump_rewind(struct kmsg_dump_iter *iter);
0067 
0068 int kmsg_dump_register(struct kmsg_dumper *dumper);
0069 
0070 int kmsg_dump_unregister(struct kmsg_dumper *dumper);
0071 
0072 const char *kmsg_dump_reason_str(enum kmsg_dump_reason reason);
0073 #else
0074 static inline void kmsg_dump(enum kmsg_dump_reason reason)
0075 {
0076 }
0077 
0078 static inline bool kmsg_dump_get_line(struct kmsg_dump_iter *iter, bool syslog,
0079                 const char *line, size_t size, size_t *len)
0080 {
0081     return false;
0082 }
0083 
0084 static inline bool kmsg_dump_get_buffer(struct kmsg_dump_iter *iter, bool syslog,
0085                     char *buf, size_t size, size_t *len)
0086 {
0087     return false;
0088 }
0089 
0090 static inline void kmsg_dump_rewind(struct kmsg_dump_iter *iter)
0091 {
0092 }
0093 
0094 static inline int kmsg_dump_register(struct kmsg_dumper *dumper)
0095 {
0096     return -EINVAL;
0097 }
0098 
0099 static inline int kmsg_dump_unregister(struct kmsg_dumper *dumper)
0100 {
0101     return -EINVAL;
0102 }
0103 
0104 static inline const char *kmsg_dump_reason_str(enum kmsg_dump_reason reason)
0105 {
0106     return "Disabled";
0107 }
0108 #endif
0109 
0110 #endif /* _LINUX_KMSG_DUMP_H */