kmsg_dump.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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_SHUTDOWN,
  27. KMSG_DUMP_MAX
  28. };
  29. /**
  30. * struct kmsg_dumper - kernel crash message dumper structure
  31. * @list: Entry in the dumper list (private)
  32. * @dump: Call into dumping code which will retrieve the data with
  33. * through the record iterator
  34. * @max_reason: filter for highest reason number that should be dumped
  35. * @registered: Flag that specifies if this is already registered
  36. */
  37. struct kmsg_dumper {
  38. struct list_head list;
  39. void (*dump)(struct kmsg_dumper *dumper, enum kmsg_dump_reason reason);
  40. enum kmsg_dump_reason max_reason;
  41. bool active;
  42. bool registered;
  43. /* private state of the kmsg iterator */
  44. u32 cur_idx;
  45. u32 next_idx;
  46. u64 cur_seq;
  47. u64 next_seq;
  48. };
  49. #ifdef CONFIG_PRINTK
  50. void kmsg_dump(enum kmsg_dump_reason reason);
  51. bool kmsg_dump_get_line_nolock(struct kmsg_dumper *dumper, bool syslog,
  52. char *line, size_t size, size_t *len);
  53. bool kmsg_dump_get_line(struct kmsg_dumper *dumper, bool syslog,
  54. char *line, size_t size, size_t *len);
  55. bool kmsg_dump_get_buffer(struct kmsg_dumper *dumper, bool syslog,
  56. char *buf, size_t size, size_t *len);
  57. void kmsg_dump_rewind_nolock(struct kmsg_dumper *dumper);
  58. void kmsg_dump_rewind(struct kmsg_dumper *dumper);
  59. int kmsg_dump_register(struct kmsg_dumper *dumper);
  60. int kmsg_dump_unregister(struct kmsg_dumper *dumper);
  61. const char *kmsg_dump_reason_str(enum kmsg_dump_reason reason);
  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. static inline const char *kmsg_dump_reason_str(enum kmsg_dump_reason reason)
  97. {
  98. return "Disabled";
  99. }
  100. #endif
  101. #endif /* _LINUX_KMSG_DUMP_H */