kmsg_dump.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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. #include <linux/errno.h>
  15. #include <linux/list.h>
  16. /*
  17. * Keep this list arranged in rough order of priority. Anything listed after
  18. * KMSG_DUMP_OOPS will not be logged by default unless printk.always_kmsg_dump
  19. * is passed to the kernel.
  20. */
  21. enum kmsg_dump_reason {
  22. KMSG_DUMP_UNDEF,
  23. KMSG_DUMP_PANIC,
  24. KMSG_DUMP_OOPS,
  25. KMSG_DUMP_EMERG,
  26. KMSG_DUMP_RESTART,
  27. KMSG_DUMP_HALT,
  28. KMSG_DUMP_POWEROFF,
  29. };
  30. /**
  31. * struct kmsg_dumper - kernel crash message dumper structure
  32. * @list: Entry in the dumper list (private)
  33. * @dump: Call into dumping code which will retrieve the data with
  34. * through the record iterator
  35. * @max_reason: filter for highest reason number that should be dumped
  36. * @registered: Flag that specifies if this is already registered
  37. */
  38. struct kmsg_dumper {
  39. struct list_head list;
  40. void (*dump)(struct kmsg_dumper *dumper, enum kmsg_dump_reason reason);
  41. enum kmsg_dump_reason max_reason;
  42. bool active;
  43. bool registered;
  44. /* private state of the kmsg iterator */
  45. u32 cur_idx;
  46. u32 next_idx;
  47. u64 cur_seq;
  48. u64 next_seq;
  49. };
  50. #ifdef CONFIG_PRINTK
  51. void kmsg_dump(enum kmsg_dump_reason reason);
  52. bool kmsg_dump_get_line_nolock(struct kmsg_dumper *dumper, bool syslog,
  53. char *line, size_t size, size_t *len);
  54. bool kmsg_dump_get_line(struct kmsg_dumper *dumper, bool syslog,
  55. char *line, size_t size, size_t *len);
  56. bool kmsg_dump_get_buffer(struct kmsg_dumper *dumper, bool syslog,
  57. char *buf, size_t size, size_t *len);
  58. void kmsg_dump_rewind_nolock(struct kmsg_dumper *dumper);
  59. void kmsg_dump_rewind(struct kmsg_dumper *dumper);
  60. int kmsg_dump_register(struct kmsg_dumper *dumper);
  61. int kmsg_dump_unregister(struct kmsg_dumper *dumper);
  62. #else
  63. static inline void kmsg_dump(enum kmsg_dump_reason reason)
  64. {
  65. }
  66. static inline bool kmsg_dump_get_line_nolock(struct kmsg_dumper *dumper,
  67. bool syslog, const char *line,
  68. size_t size, size_t *len)
  69. {
  70. return false;
  71. }
  72. static inline bool kmsg_dump_get_line(struct kmsg_dumper *dumper, bool syslog,
  73. const char *line, size_t size, size_t *len)
  74. {
  75. return false;
  76. }
  77. static inline bool kmsg_dump_get_buffer(struct kmsg_dumper *dumper, bool syslog,
  78. char *buf, size_t size, size_t *len)
  79. {
  80. return false;
  81. }
  82. static inline void kmsg_dump_rewind_nolock(struct kmsg_dumper *dumper)
  83. {
  84. }
  85. static inline void kmsg_dump_rewind(struct kmsg_dumper *dumper)
  86. {
  87. }
  88. static inline int kmsg_dump_register(struct kmsg_dumper *dumper)
  89. {
  90. return -EINVAL;
  91. }
  92. static inline int kmsg_dump_unregister(struct kmsg_dumper *dumper)
  93. {
  94. return -EINVAL;
  95. }
  96. #endif
  97. #endif /* _LINUX_KMSG_DUMP_H */