Loading...
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
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 */
23enum 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 */
40struct kmsg_dumper {
41 struct list_head list;
42 void (*dump)(struct kmsg_dumper *dumper, enum kmsg_dump_reason reason);
43 enum kmsg_dump_reason max_reason;
44 bool active;
45 bool registered;
46
47 /* private state of the kmsg iterator */
48 u32 cur_idx;
49 u32 next_idx;
50 u64 cur_seq;
51 u64 next_seq;
52};
53
54#ifdef CONFIG_PRINTK
55void kmsg_dump(enum kmsg_dump_reason reason);
56
57bool kmsg_dump_get_line_nolock(struct kmsg_dumper *dumper, bool syslog,
58 char *line, size_t size, size_t *len);
59
60bool kmsg_dump_get_line(struct kmsg_dumper *dumper, bool syslog,
61 char *line, size_t size, size_t *len);
62
63bool kmsg_dump_get_buffer(struct kmsg_dumper *dumper, bool syslog,
64 char *buf, size_t size, size_t *len);
65
66void kmsg_dump_rewind_nolock(struct kmsg_dumper *dumper);
67
68void kmsg_dump_rewind(struct kmsg_dumper *dumper);
69
70int kmsg_dump_register(struct kmsg_dumper *dumper);
71
72int kmsg_dump_unregister(struct kmsg_dumper *dumper);
73
74const char *kmsg_dump_reason_str(enum kmsg_dump_reason reason);
75#else
76static inline void kmsg_dump(enum kmsg_dump_reason reason)
77{
78}
79
80static inline bool kmsg_dump_get_line_nolock(struct kmsg_dumper *dumper,
81 bool syslog, const char *line,
82 size_t size, size_t *len)
83{
84 return false;
85}
86
87static inline bool kmsg_dump_get_line(struct kmsg_dumper *dumper, bool syslog,
88 const char *line, size_t size, size_t *len)
89{
90 return false;
91}
92
93static inline bool kmsg_dump_get_buffer(struct kmsg_dumper *dumper, bool syslog,
94 char *buf, size_t size, size_t *len)
95{
96 return false;
97}
98
99static inline void kmsg_dump_rewind_nolock(struct kmsg_dumper *dumper)
100{
101}
102
103static inline void kmsg_dump_rewind(struct kmsg_dumper *dumper)
104{
105}
106
107static inline int kmsg_dump_register(struct kmsg_dumper *dumper)
108{
109 return -EINVAL;
110}
111
112static inline int kmsg_dump_unregister(struct kmsg_dumper *dumper)
113{
114 return -EINVAL;
115}
116
117static inline const char *kmsg_dump_reason_str(enum kmsg_dump_reason reason)
118{
119 return "Disabled";
120}
121#endif
122
123#endif /* _LINUX_KMSG_DUMP_H */
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
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 */
23enum 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_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 */
37struct kmsg_dump_iter {
38 u64 cur_seq;
39 u64 next_seq;
40};
41
42/**
43 * struct kmsg_dumper - kernel crash message dumper structure
44 * @list: Entry in the dumper list (private)
45 * @dump: Call into dumping code which will retrieve the data with
46 * through the record iterator
47 * @max_reason: filter for highest reason number that should be dumped
48 * @registered: Flag that specifies if this is already registered
49 */
50struct kmsg_dumper {
51 struct list_head list;
52 void (*dump)(struct kmsg_dumper *dumper, enum kmsg_dump_reason reason);
53 enum kmsg_dump_reason max_reason;
54 bool registered;
55};
56
57#ifdef CONFIG_PRINTK
58void kmsg_dump(enum kmsg_dump_reason reason);
59
60bool kmsg_dump_get_line(struct kmsg_dump_iter *iter, bool syslog,
61 char *line, size_t size, size_t *len);
62
63bool kmsg_dump_get_buffer(struct kmsg_dump_iter *iter, bool syslog,
64 char *buf, size_t size, size_t *len_out);
65
66void kmsg_dump_rewind(struct kmsg_dump_iter *iter);
67
68int kmsg_dump_register(struct kmsg_dumper *dumper);
69
70int kmsg_dump_unregister(struct kmsg_dumper *dumper);
71
72const char *kmsg_dump_reason_str(enum kmsg_dump_reason reason);
73#else
74static inline void kmsg_dump(enum kmsg_dump_reason reason)
75{
76}
77
78static inline bool kmsg_dump_get_line(struct kmsg_dump_iter *iter, bool syslog,
79 const char *line, size_t size, size_t *len)
80{
81 return false;
82}
83
84static inline bool kmsg_dump_get_buffer(struct kmsg_dump_iter *iter, bool syslog,
85 char *buf, size_t size, size_t *len)
86{
87 return false;
88}
89
90static inline void kmsg_dump_rewind(struct kmsg_dump_iter *iter)
91{
92}
93
94static inline int kmsg_dump_register(struct kmsg_dumper *dumper)
95{
96 return -EINVAL;
97}
98
99static inline int kmsg_dump_unregister(struct kmsg_dumper *dumper)
100{
101 return -EINVAL;
102}
103
104static inline const char *kmsg_dump_reason_str(enum kmsg_dump_reason reason)
105{
106 return "Disabled";
107}
108#endif
109
110#endif /* _LINUX_KMSG_DUMP_H */