blktrace_api.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. #ifndef BLKTRACE_H
  2. #define BLKTRACE_H
  3. #include <linux/blkdev.h>
  4. #include <linux/relay.h>
  5. #include <linux/compat.h>
  6. #include <uapi/linux/blktrace_api.h>
  7. #include <linux/list.h>
  8. #if defined(CONFIG_BLK_DEV_IO_TRACE)
  9. #include <linux/sysfs.h>
  10. struct blk_trace {
  11. int trace_state;
  12. struct rchan *rchan;
  13. unsigned long __percpu *sequence;
  14. unsigned char __percpu *msg_data;
  15. u16 act_mask;
  16. u64 start_lba;
  17. u64 end_lba;
  18. u32 pid;
  19. u32 dev;
  20. struct dentry *dir;
  21. struct dentry *dropped_file;
  22. struct dentry *msg_file;
  23. struct list_head running_list;
  24. atomic_t dropped;
  25. };
  26. extern int blk_trace_ioctl(struct block_device *, unsigned, char __user *);
  27. extern void blk_trace_shutdown(struct request_queue *);
  28. extern int do_blk_trace_setup(struct request_queue *q, char *name,
  29. dev_t dev, struct block_device *bdev,
  30. struct blk_user_trace_setup *buts);
  31. extern __printf(2, 3)
  32. void __trace_note_message(struct blk_trace *, const char *fmt, ...);
  33. /**
  34. * blk_add_trace_msg - Add a (simple) message to the blktrace stream
  35. * @q: queue the io is for
  36. * @fmt: format to print message in
  37. * args... Variable argument list for format
  38. *
  39. * Description:
  40. * Records a (simple) message onto the blktrace stream.
  41. *
  42. * NOTE: BLK_TN_MAX_MSG characters are output at most.
  43. * NOTE: Can not use 'static inline' due to presence of var args...
  44. *
  45. **/
  46. #define blk_add_trace_msg(q, fmt, ...) \
  47. do { \
  48. struct blk_trace *bt = (q)->blk_trace; \
  49. if (unlikely(bt)) \
  50. __trace_note_message(bt, fmt, ##__VA_ARGS__); \
  51. } while (0)
  52. #define BLK_TN_MAX_MSG 128
  53. extern void blk_add_driver_data(struct request_queue *q, struct request *rq,
  54. void *data, size_t len);
  55. extern int blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
  56. struct block_device *bdev,
  57. char __user *arg);
  58. extern int blk_trace_startstop(struct request_queue *q, int start);
  59. extern int blk_trace_remove(struct request_queue *q);
  60. extern void blk_trace_remove_sysfs(struct device *dev);
  61. extern int blk_trace_init_sysfs(struct device *dev);
  62. extern struct attribute_group blk_trace_attr_group;
  63. #else /* !CONFIG_BLK_DEV_IO_TRACE */
  64. # define blk_trace_ioctl(bdev, cmd, arg) (-ENOTTY)
  65. # define blk_trace_shutdown(q) do { } while (0)
  66. # define do_blk_trace_setup(q, name, dev, bdev, buts) (-ENOTTY)
  67. # define blk_add_driver_data(q, rq, data, len) do {} while (0)
  68. # define blk_trace_setup(q, name, dev, bdev, arg) (-ENOTTY)
  69. # define blk_trace_startstop(q, start) (-ENOTTY)
  70. # define blk_trace_remove(q) (-ENOTTY)
  71. # define blk_add_trace_msg(q, fmt, ...) do { } while (0)
  72. # define blk_trace_remove_sysfs(dev) do { } while (0)
  73. static inline int blk_trace_init_sysfs(struct device *dev)
  74. {
  75. return 0;
  76. }
  77. #endif /* CONFIG_BLK_DEV_IO_TRACE */
  78. #ifdef CONFIG_COMPAT
  79. struct compat_blk_user_trace_setup {
  80. char name[BLKTRACE_BDEV_SIZE];
  81. u16 act_mask;
  82. u32 buf_size;
  83. u32 buf_nr;
  84. compat_u64 start_lba;
  85. compat_u64 end_lba;
  86. u32 pid;
  87. };
  88. #define BLKTRACESETUP32 _IOWR(0x12, 115, struct compat_blk_user_trace_setup)
  89. #endif
  90. #if defined(CONFIG_EVENT_TRACING) && defined(CONFIG_BLOCK)
  91. static inline int blk_cmd_buf_len(struct request *rq)
  92. {
  93. return (rq->cmd_type == REQ_TYPE_BLOCK_PC) ? rq->cmd_len * 3 : 1;
  94. }
  95. extern void blk_dump_cmd(char *buf, struct request *rq);
  96. extern void blk_fill_rwbs(char *rwbs, u32 rw, int bytes);
  97. #endif /* CONFIG_EVENT_TRACING && CONFIG_BLOCK */
  98. #endif