blob: 2e7a1e032c71a91e6a9dff98a0b637d621932a25 [file] [log] [blame]
Simon Kagstrom456b5652009-10-16 14:09:18 +02001/*
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 Dunlapac562242011-06-15 15:08:17 -070015#include <linux/errno.h>
Simon Kagstrom456b5652009-10-16 14:09:18 +020016#include <linux/list.h>
17
Matthew Garrettc22ab332012-03-05 14:59:10 -080018/*
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 Kagstrom456b5652009-10-16 14:09:18 +020023enum kmsg_dump_reason {
Kay Sieverse2ae7152012-06-15 14:07:51 +020024 KMSG_DUMP_UNDEF,
Simon Kagstrom456b5652009-10-16 14:09:18 +020025 KMSG_DUMP_PANIC,
Matthew Garrettc22ab332012-03-05 14:59:10 -080026 KMSG_DUMP_OOPS,
27 KMSG_DUMP_EMERG,
Seiji Aguchi04c68622011-01-12 16:59:30 -080028 KMSG_DUMP_RESTART,
29 KMSG_DUMP_HALT,
30 KMSG_DUMP_POWEROFF,
Simon Kagstrom456b5652009-10-16 14:09:18 +020031};
32
33/**
34 * struct kmsg_dumper - kernel crash message dumper structure
Simon Kagstrom456b5652009-10-16 14:09:18 +020035 * @list: Entry in the dumper list (private)
Kay Sieverse2ae7152012-06-15 14:07:51 +020036 * @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 Kagstrom456b5652009-10-16 14:09:18 +020039 * @registered: Flag that specifies if this is already registered
40 */
41struct kmsg_dumper {
Simon Kagstrom456b5652009-10-16 14:09:18 +020042 struct list_head list;
Kay Sieverse2ae7152012-06-15 14:07:51 +020043 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 Kagstrom456b5652009-10-16 14:09:18 +020053};
54
Randy Dunlap595dd3d2009-12-01 10:52:02 -080055#ifdef CONFIG_PRINTK
Simon Kagstrom456b5652009-10-16 14:09:18 +020056void kmsg_dump(enum kmsg_dump_reason reason);
57
Anton Vorontsov533827c2012-07-20 17:28:07 -070058bool kmsg_dump_get_line_nolock(struct kmsg_dumper *dumper, bool syslog,
59 char *line, size_t size, size_t *len);
60
Kay Sieverse2ae7152012-06-15 14:07:51 +020061bool kmsg_dump_get_line(struct kmsg_dumper *dumper, bool syslog,
62 char *line, size_t size, size_t *len);
63
64bool kmsg_dump_get_buffer(struct kmsg_dumper *dumper, bool syslog,
65 char *buf, size_t size, size_t *len);
66
Anton Vorontsov533827c2012-07-20 17:28:07 -070067void kmsg_dump_rewind_nolock(struct kmsg_dumper *dumper);
68
Kay Sieverse2ae7152012-06-15 14:07:51 +020069void kmsg_dump_rewind(struct kmsg_dumper *dumper);
70
Simon Kagstrom456b5652009-10-16 14:09:18 +020071int kmsg_dump_register(struct kmsg_dumper *dumper);
72
73int kmsg_dump_unregister(struct kmsg_dumper *dumper);
Randy Dunlap595dd3d2009-12-01 10:52:02 -080074#else
75static inline void kmsg_dump(enum kmsg_dump_reason reason)
76{
77}
78
Anton Vorontsov533827c2012-07-20 17:28:07 -070079static 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 Sievers246f6f22012-06-19 00:32:57 +020086static inline bool kmsg_dump_get_line(struct kmsg_dumper *dumper, bool syslog,
87 const char *line, size_t size, size_t *len)
Kay Sieverse2ae7152012-06-15 14:07:51 +020088{
89 return false;
90}
91
Kay Sievers246f6f22012-06-19 00:32:57 +020092static inline bool kmsg_dump_get_buffer(struct kmsg_dumper *dumper, bool syslog,
93 char *buf, size_t size, size_t *len)
Kay Sieverse2ae7152012-06-15 14:07:51 +020094{
95 return false;
96}
97
Anton Vorontsov533827c2012-07-20 17:28:07 -070098static inline void kmsg_dump_rewind_nolock(struct kmsg_dumper *dumper)
99{
100}
101
Kay Sievers246f6f22012-06-19 00:32:57 +0200102static inline void kmsg_dump_rewind(struct kmsg_dumper *dumper)
Kay Sieverse2ae7152012-06-15 14:07:51 +0200103{
104}
105
Randy Dunlap595dd3d2009-12-01 10:52:02 -0800106static inline int kmsg_dump_register(struct kmsg_dumper *dumper)
107{
108 return -EINVAL;
109}
110
111static inline int kmsg_dump_unregister(struct kmsg_dumper *dumper)
112{
113 return -EINVAL;
114}
115#endif
Simon Kagstrom456b5652009-10-16 14:09:18 +0200116
117#endif /* _LINUX_KMSG_DUMP_H */