blob: 3f82b5cb2d82d83fdb193b54615bff861667b7a2 [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 Garrettc22ab3322012-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 Garrettc22ab3322012-03-05 14:59:10 -080026 KMSG_DUMP_OOPS,
27 KMSG_DUMP_EMERG,
Kees Cook6d3cf962020-05-15 11:05:43 -070028 KMSG_DUMP_SHUTDOWN,
Simon Kagstrom456b5652009-10-16 14:09:18 +020029};
30
31/**
32 * struct kmsg_dumper - kernel crash message dumper structure
Simon Kagstrom456b5652009-10-16 14:09:18 +020033 * @list: Entry in the dumper list (private)
Kay Sieverse2ae7152012-06-15 14:07:51 +020034 * @dump: Call into dumping code which will retrieve the data with
35 * through the record iterator
36 * @max_reason: filter for highest reason number that should be dumped
Simon Kagstrom456b5652009-10-16 14:09:18 +020037 * @registered: Flag that specifies if this is already registered
38 */
39struct kmsg_dumper {
Simon Kagstrom456b5652009-10-16 14:09:18 +020040 struct list_head list;
Kay Sieverse2ae7152012-06-15 14:07:51 +020041 void (*dump)(struct kmsg_dumper *dumper, enum kmsg_dump_reason reason);
42 enum kmsg_dump_reason max_reason;
43 bool active;
44 bool registered;
45
46 /* private state of the kmsg iterator */
47 u32 cur_idx;
48 u32 next_idx;
49 u64 cur_seq;
50 u64 next_seq;
Simon Kagstrom456b5652009-10-16 14:09:18 +020051};
52
Randy Dunlap595dd3d2009-12-01 10:52:02 -080053#ifdef CONFIG_PRINTK
Simon Kagstrom456b5652009-10-16 14:09:18 +020054void kmsg_dump(enum kmsg_dump_reason reason);
55
Anton Vorontsov533827c2012-07-20 17:28:07 -070056bool kmsg_dump_get_line_nolock(struct kmsg_dumper *dumper, bool syslog,
57 char *line, size_t size, size_t *len);
58
Kay Sieverse2ae7152012-06-15 14:07:51 +020059bool kmsg_dump_get_line(struct kmsg_dumper *dumper, bool syslog,
60 char *line, size_t size, size_t *len);
61
62bool kmsg_dump_get_buffer(struct kmsg_dumper *dumper, bool syslog,
63 char *buf, size_t size, size_t *len);
64
Anton Vorontsov533827c2012-07-20 17:28:07 -070065void kmsg_dump_rewind_nolock(struct kmsg_dumper *dumper);
66
Kay Sieverse2ae7152012-06-15 14:07:51 +020067void kmsg_dump_rewind(struct kmsg_dumper *dumper);
68
Simon Kagstrom456b5652009-10-16 14:09:18 +020069int kmsg_dump_register(struct kmsg_dumper *dumper);
70
71int kmsg_dump_unregister(struct kmsg_dumper *dumper);
Randy Dunlap595dd3d2009-12-01 10:52:02 -080072#else
73static inline void kmsg_dump(enum kmsg_dump_reason reason)
74{
75}
76
Anton Vorontsov533827c2012-07-20 17:28:07 -070077static inline bool kmsg_dump_get_line_nolock(struct kmsg_dumper *dumper,
78 bool syslog, const char *line,
79 size_t size, size_t *len)
80{
81 return false;
82}
83
Kay Sievers246f6f22012-06-19 00:32:57 +020084static inline bool kmsg_dump_get_line(struct kmsg_dumper *dumper, bool syslog,
85 const char *line, size_t size, size_t *len)
Kay Sieverse2ae7152012-06-15 14:07:51 +020086{
87 return false;
88}
89
Kay Sievers246f6f22012-06-19 00:32:57 +020090static inline bool kmsg_dump_get_buffer(struct kmsg_dumper *dumper, bool syslog,
91 char *buf, size_t size, size_t *len)
Kay Sieverse2ae7152012-06-15 14:07:51 +020092{
93 return false;
94}
95
Anton Vorontsov533827c2012-07-20 17:28:07 -070096static inline void kmsg_dump_rewind_nolock(struct kmsg_dumper *dumper)
97{
98}
99
Kay Sievers246f6f22012-06-19 00:32:57 +0200100static inline void kmsg_dump_rewind(struct kmsg_dumper *dumper)
Kay Sieverse2ae7152012-06-15 14:07:51 +0200101{
102}
103
Randy Dunlap595dd3d2009-12-01 10:52:02 -0800104static inline int kmsg_dump_register(struct kmsg_dumper *dumper)
105{
106 return -EINVAL;
107}
108
109static inline int kmsg_dump_unregister(struct kmsg_dumper *dumper)
110{
111 return -EINVAL;
112}
113#endif
Simon Kagstrom456b5652009-10-16 14:09:18 +0200114
115#endif /* _LINUX_KMSG_DUMP_H */