kmsg_dump.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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(struct kmsg_dumper *dumper, bool syslog,
  53. char *line, size_t size, size_t *len);
  54. bool kmsg_dump_get_buffer(struct kmsg_dumper *dumper, bool syslog,
  55. char *buf, size_t size, size_t *len);
  56. void kmsg_dump_rewind(struct kmsg_dumper *dumper);
  57. int kmsg_dump_register(struct kmsg_dumper *dumper);
  58. int kmsg_dump_unregister(struct kmsg_dumper *dumper);
  59. #else
  60. static inline void kmsg_dump(enum kmsg_dump_reason reason)
  61. {
  62. }
  63. static inline bool kmsg_dump_get_line(struct kmsg_dumper *dumper, bool syslog,
  64. const char *line, size_t size, size_t *len)
  65. {
  66. return false;
  67. }
  68. static inline bool kmsg_dump_get_buffer(struct kmsg_dumper *dumper, bool syslog,
  69. char *buf, size_t size, size_t *len)
  70. {
  71. return false;
  72. }
  73. static inline void kmsg_dump_rewind(struct kmsg_dumper *dumper)
  74. {
  75. }
  76. static inline int kmsg_dump_register(struct kmsg_dumper *dumper)
  77. {
  78. return -EINVAL;
  79. }
  80. static inline int kmsg_dump_unregister(struct kmsg_dumper *dumper)
  81. {
  82. return -EINVAL;
  83. }
  84. #endif
  85. #endif /* _LINUX_KMSG_DUMP_H */