kmsg_dump.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /*
  2. * linux/include/kmsg_dump.h
  3. *
  4. * Copyright (C) 2009 Net Insight AB
  5. *
  6. * Author: Simon Kagstrom <[email protected]>
  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_dump_iter - iterator for retrieving kernel messages
  31. * @cur_seq: Points to the oldest message to dump
  32. * @next_seq: Points after the newest message to dump
  33. */
  34. struct kmsg_dump_iter {
  35. u64 cur_seq;
  36. u64 next_seq;
  37. };
  38. /**
  39. * struct kmsg_dumper - kernel crash message dumper structure
  40. * @list: Entry in the dumper list (private)
  41. * @dump: Call into dumping code which will retrieve the data with
  42. * through the record iterator
  43. * @max_reason: filter for highest reason number that should be dumped
  44. * @registered: Flag that specifies if this is already registered
  45. */
  46. struct kmsg_dumper {
  47. struct list_head list;
  48. void (*dump)(struct kmsg_dumper *dumper, enum kmsg_dump_reason reason);
  49. enum kmsg_dump_reason max_reason;
  50. bool registered;
  51. };
  52. #ifdef CONFIG_PRINTK
  53. void kmsg_dump(enum kmsg_dump_reason reason);
  54. bool kmsg_dump_get_line(struct kmsg_dump_iter *iter, bool syslog,
  55. char *line, size_t size, size_t *len);
  56. bool kmsg_dump_get_buffer(struct kmsg_dump_iter *iter, bool syslog,
  57. char *buf, size_t size, size_t *len_out);
  58. void kmsg_dump_rewind(struct kmsg_dump_iter *iter);
  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(struct kmsg_dump_iter *iter, bool syslog,
  67. const char *line, size_t size, size_t *len)
  68. {
  69. return false;
  70. }
  71. static inline bool kmsg_dump_get_buffer(struct kmsg_dump_iter *iter, bool syslog,
  72. char *buf, size_t size, size_t *len)
  73. {
  74. return false;
  75. }
  76. static inline void kmsg_dump_rewind(struct kmsg_dump_iter *iter)
  77. {
  78. }
  79. static inline int kmsg_dump_register(struct kmsg_dumper *dumper)
  80. {
  81. return -EINVAL;
  82. }
  83. static inline int kmsg_dump_unregister(struct kmsg_dumper *dumper)
  84. {
  85. return -EINVAL;
  86. }
  87. static inline const char *kmsg_dump_reason_str(enum kmsg_dump_reason reason)
  88. {
  89. return "Disabled";
  90. }
  91. #endif
  92. #endif /* _LINUX_KMSG_DUMP_H */