test-iosched.h 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. /* Copyright (c) 2012-2013, The Linux Foundation. All rights reserved.
  2. *
  3. * This program is free software; you can redistribute it and/or modify
  4. * it under the terms of the GNU General Public License version 2 and
  5. * only version 2 as published by the Free Software Foundation.
  6. *
  7. * This program is distributed in the hope that it will be useful,
  8. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. * GNU General Public License for more details.
  11. *
  12. * The test scheduler allows to test the block device by dispatching
  13. * specific requests according to the test case and declare PASS/FAIL
  14. * according to the requests completion error code.
  15. * Each test is exposed via debugfs and can be triggered by writing to
  16. * the debugfs file.
  17. *
  18. */
  19. #ifndef _LINUX_TEST_IOSCHED_H
  20. #define _LINUX_TEST_IOSCHED_H
  21. /*
  22. * Patterns definitions for read/write requests data
  23. */
  24. #define TEST_PATTERN_SEQUENTIAL 0x12345678
  25. #define TEST_PATTERN_5A 0x5A5A5A5A
  26. #define TEST_PATTERN_FF 0xFFFFFFFF
  27. #define TEST_NO_PATTERN 0xDEADBEEF
  28. #define BIO_U32_SIZE 1024
  29. struct test_data;
  30. typedef int (prepare_test_fn) (struct test_data *);
  31. typedef int (run_test_fn) (struct test_data *);
  32. typedef int (check_test_result_fn) (struct test_data *);
  33. typedef int (post_test_fn) (struct test_data *);
  34. typedef char* (get_test_case_str_fn) (struct test_data *);
  35. typedef void (blk_dev_test_init_fn) (void);
  36. typedef void (blk_dev_test_exit_fn) (void);
  37. typedef struct gendisk* (get_rq_disk_fn) (void);
  38. /**
  39. * enum test_state - defines the state of the test
  40. */
  41. enum test_state {
  42. TEST_IDLE,
  43. TEST_RUNNING,
  44. TEST_COMPLETED,
  45. };
  46. /**
  47. * enum test_results - defines the success orfailure of the test
  48. */
  49. enum test_results {
  50. TEST_NO_RESULT,
  51. TEST_FAILED,
  52. TEST_PASSED,
  53. TEST_NOT_SUPPORTED,
  54. };
  55. /**
  56. * enum req_unique_type - defines a unique request type
  57. */
  58. enum req_unique_type {
  59. REQ_UNIQUE_NONE,
  60. REQ_UNIQUE_DISCARD,
  61. REQ_UNIQUE_FLUSH,
  62. REQ_UNIQUE_SANITIZE,
  63. };
  64. /**
  65. * struct test_debug - debugfs directories
  66. * @debug_root: The test-iosched debugfs root directory
  67. * @debug_utils_root: test-iosched debugfs utils root
  68. * directory
  69. * @debug_tests_root: test-iosched debugfs tests root
  70. * directory
  71. * @debug_test_result: Exposes the test result to the user
  72. * space
  73. * @start_sector: The start sector for read/write requests
  74. */
  75. struct test_debug {
  76. struct dentry *debug_root;
  77. struct dentry *debug_utils_root;
  78. struct dentry *debug_tests_root;
  79. struct dentry *debug_test_result;
  80. struct dentry *start_sector;
  81. };
  82. /**
  83. * struct test_request - defines a test request
  84. * @queuelist: The test requests list
  85. * @bios_buffer: Write/read requests data buffer
  86. * @buf_size: Write/read requests data buffer size (in
  87. * bytes)
  88. * @rq: A block request, to be dispatched
  89. * @req_completed: A flag to indicate if the request was
  90. * completed
  91. * @req_result: Keeps the error code received in the
  92. * request completion callback
  93. * @is_err_expected: A flag to indicate if the request should
  94. * fail
  95. * @wr_rd_data_pattern: A pattern written to the write data
  96. * buffer. Can be used in read requests to
  97. * verify the data
  98. * @req_id: A unique ID to identify a test request
  99. * to ease the debugging of the test cases
  100. */
  101. struct test_request {
  102. struct list_head queuelist;
  103. unsigned int *bios_buffer;
  104. int buf_size;
  105. struct request *rq;
  106. bool req_completed;
  107. int req_result;
  108. int is_err_expected;
  109. int wr_rd_data_pattern;
  110. int req_id;
  111. };
  112. /**
  113. * struct test_info - specific test information
  114. * @testcase: The current running test case
  115. * @timeout_msec: Test specific test timeout
  116. * @buf_size: Write/read requests data buffer size (in
  117. * bytes)
  118. * @prepare_test_fn: Test specific test preparation callback
  119. * @run_test_fn: Test specific test running callback
  120. * @check_test_result_fn: Test specific test result checking
  121. * callback
  122. * @get_test_case_str_fn: Test specific function to get the test name
  123. * @test_duration: A ktime value saved for timing
  124. * calculations
  125. * @data: Test specific private data
  126. * @test_byte_count: Total number of bytes dispatched in
  127. * the test
  128. */
  129. struct test_info {
  130. int testcase;
  131. unsigned timeout_msec;
  132. prepare_test_fn *prepare_test_fn;
  133. run_test_fn *run_test_fn;
  134. check_test_result_fn *check_test_result_fn;
  135. post_test_fn *post_test_fn;
  136. get_test_case_str_fn *get_test_case_str_fn;
  137. ktime_t test_duration;
  138. get_rq_disk_fn *get_rq_disk_fn;
  139. void *data;
  140. unsigned long test_byte_count;
  141. };
  142. /**
  143. * struct blk_dev_test_type - identifies block device test
  144. * @list: list head pointer
  145. * @init_fn: block device test init callback
  146. * @exit_fn: block device test exit callback
  147. */
  148. struct blk_dev_test_type {
  149. struct list_head list;
  150. blk_dev_test_init_fn *init_fn;
  151. blk_dev_test_exit_fn *exit_fn;
  152. };
  153. /**
  154. * struct test_data - global test iosched data
  155. * @queue: The test IO scheduler requests list
  156. * @test_queue: The test requests list
  157. * @dispatched_queue: The queue contains requests dispatched
  158. * from @test_queue
  159. * @reinsert_queue: The queue contains reinserted from underlying
  160. * driver requests
  161. * @urgent_queue: The queue contains requests for urgent delivery
  162. * These requests will be delivered before @test_queue
  163. * and @reinsert_queue requests
  164. * @test_count: Number of requests in the @test_queue
  165. * @dispatched_count: Number of requests in the @dispatched_queue
  166. * @reinsert_count: Number of requests in the @reinsert_queue
  167. * @urgent_count: Number of requests in the @urgent_queue
  168. * @wait_q: A wait queue for waiting for the test
  169. * requests completion
  170. * @test_state: Indicates if there is a running test.
  171. * Used for dispatch function
  172. * @test_result: Indicates if the test passed or failed
  173. * @debug: The test debugfs entries
  174. * @req_q: The block layer request queue
  175. * @num_of_write_bios: The number of write BIOs added to the test requests.
  176. * Used to calcualte the sector number of
  177. * new BIOs.
  178. * @start_sector: The address of the first sector that can
  179. * be accessed by the test
  180. * @timeout_timer: A timer to verify test completion in
  181. * case of non-completed requests
  182. * @wr_rd_next_req_id: A unique ID to identify WRITE/READ
  183. * request to ease the debugging of the
  184. * test cases
  185. * @unique_next_req_id: A unique ID to identify
  186. * FLUSH/DISCARD/SANITIZE request to ease
  187. * the debugging of the test cases
  188. * @lock: A lock to verify running a single test
  189. * at a time
  190. * @test_info: A specific test data to be set by the
  191. * test invokation function
  192. * @ignore_round: A boolean variable indicating that a
  193. * test round was disturbed by an external
  194. * flush request, therefore disqualifying
  195. * the results
  196. */
  197. struct test_data {
  198. struct list_head queue;
  199. struct list_head test_queue;
  200. struct list_head dispatched_queue;
  201. struct list_head reinsert_queue;
  202. struct list_head urgent_queue;
  203. unsigned int test_count;
  204. unsigned int dispatched_count;
  205. unsigned int reinsert_count;
  206. unsigned int urgent_count;
  207. wait_queue_head_t wait_q;
  208. enum test_state test_state;
  209. enum test_results test_result;
  210. struct test_debug debug;
  211. struct request_queue *req_q;
  212. int num_of_write_bios;
  213. u32 start_sector;
  214. struct timer_list timeout_timer;
  215. int wr_rd_next_req_id;
  216. int unique_next_req_id;
  217. spinlock_t lock;
  218. struct test_info test_info;
  219. bool fs_wr_reqs_during_test;
  220. bool ignore_round;
  221. };
  222. extern int test_iosched_start_test(struct test_info *t_info);
  223. extern void test_iosched_mark_test_completion(void);
  224. extern void check_test_completion(void);
  225. extern int test_iosched_add_unique_test_req(int is_err_expcted,
  226. enum req_unique_type req_unique,
  227. int start_sec, int nr_sects, rq_end_io_fn *end_req_io);
  228. extern int test_iosched_add_wr_rd_test_req(int is_err_expcted,
  229. int direction, int start_sec,
  230. int num_bios, int pattern, rq_end_io_fn *end_req_io);
  231. extern struct test_request *test_iosched_create_test_req(int is_err_expcted,
  232. int direction, int start_sec,
  233. int num_bios, int pattern, rq_end_io_fn *end_req_io);
  234. extern struct dentry *test_iosched_get_debugfs_tests_root(void);
  235. extern struct dentry *test_iosched_get_debugfs_utils_root(void);
  236. extern struct request_queue *test_iosched_get_req_queue(void);
  237. extern void test_iosched_set_test_result(int);
  238. void test_iosched_set_ignore_round(bool ignore_round);
  239. void test_iosched_register(struct blk_dev_test_type *bdt);
  240. void test_iosched_unregister(struct blk_dev_test_type *bdt);
  241. extern struct test_data *test_get_test_data(void);
  242. void test_iosched_add_urgent_req(struct test_request *test_rq);
  243. int test_is_req_urgent(struct request *rq);
  244. void check_test_completion(void);
  245. #endif /* _LINUX_TEST_IOSCHED_H */