Merge tag 'xfs-6.4-rc1-fixes' of git://git.kernel.org/pub/scm/fs/xfs/xfs-linux
[linux-block.git] / include / linux / kmsg_dump.h
CommitLineData
456b565c
SK
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
ac562241 15#include <linux/errno.h>
456b565c
SK
16#include <linux/list.h>
17
c22ab332
MG
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 */
456b565c 23enum kmsg_dump_reason {
e2ae715d 24 KMSG_DUMP_UNDEF,
456b565c 25 KMSG_DUMP_PANIC,
c22ab332
MG
26 KMSG_DUMP_OOPS,
27 KMSG_DUMP_EMERG,
6d3cf962 28 KMSG_DUMP_SHUTDOWN,
b1f6f161 29 KMSG_DUMP_MAX
456b565c
SK
30};
31
f9f3f02d
JO
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
456b565c
SK
42/**
43 * struct kmsg_dumper - kernel crash message dumper structure
456b565c 44 * @list: Entry in the dumper list (private)
e2ae715d
KS
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
456b565c
SK
48 * @registered: Flag that specifies if this is already registered
49 */
50struct kmsg_dumper {
456b565c 51 struct list_head list;
e2ae715d
KS
52 void (*dump)(struct kmsg_dumper *dumper, enum kmsg_dump_reason reason);
53 enum kmsg_dump_reason max_reason;
e2ae715d 54 bool registered;
456b565c
SK
55};
56
595dd3d8 57#ifdef CONFIG_PRINTK
456b565c
SK
58void kmsg_dump(enum kmsg_dump_reason reason);
59
f9f3f02d 60bool kmsg_dump_get_line(struct kmsg_dump_iter *iter, bool syslog,
e2ae715d
KS
61 char *line, size_t size, size_t *len);
62
f9f3f02d 63bool kmsg_dump_get_buffer(struct kmsg_dump_iter *iter, bool syslog,
726b5097 64 char *buf, size_t size, size_t *len_out);
e2ae715d 65
f9f3f02d 66void kmsg_dump_rewind(struct kmsg_dump_iter *iter);
e2ae715d 67
456b565c
SK
68int kmsg_dump_register(struct kmsg_dumper *dumper);
69
70int kmsg_dump_unregister(struct kmsg_dumper *dumper);
fb13cb8a
KC
71
72const char *kmsg_dump_reason_str(enum kmsg_dump_reason reason);
595dd3d8
RD
73#else
74static inline void kmsg_dump(enum kmsg_dump_reason reason)
75{
76}
77
f9f3f02d 78static inline bool kmsg_dump_get_line(struct kmsg_dump_iter *iter, bool syslog,
246f6f2f 79 const char *line, size_t size, size_t *len)
e2ae715d
KS
80{
81 return false;
82}
83
f9f3f02d 84static inline bool kmsg_dump_get_buffer(struct kmsg_dump_iter *iter, bool syslog,
246f6f2f 85 char *buf, size_t size, size_t *len)
e2ae715d
KS
86{
87 return false;
88}
89
f9f3f02d 90static inline void kmsg_dump_rewind(struct kmsg_dump_iter *iter)
e2ae715d
KS
91{
92}
93
595dd3d8
RD
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}
fb13cb8a
KC
103
104static inline const char *kmsg_dump_reason_str(enum kmsg_dump_reason reason)
105{
106 return "Disabled";
107}
595dd3d8 108#endif
456b565c
SK
109
110#endif /* _LINUX_KMSG_DUMP_H */