blob: b93306912cf5ad3ba4bae2a14b6e40eb55544cf7 [file] [log] [blame]
Maya Erez60181552012-06-27 11:25:26 +03001/* Copyright (c) 2012, Code Aurora Forum. 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
20#ifndef _LINUX_TEST_IOSCHED_H
21#define _LINUX_TEST_IOSCHED_H
22
23/*
24 * Patterns definitions for read/write requests data
25 */
26#define TEST_PATTERN_SEQUENTIAL -1
27#define TEST_PATTERN_5A 0x5A5A5A5A
28#define TEST_PATTERN_FF 0xFFFFFFFF
29#define TEST_NO_PATTERN 0xDEADBEEF
30#define BIO_U32_SIZE 1024
31
32struct test_data;
33
34typedef int (prepare_test_fn) (struct test_data *);
35typedef int (run_test_fn) (struct test_data *);
36typedef int (check_test_result_fn) (struct test_data *);
37typedef int (post_test_fn) (struct test_data *);
38typedef char* (get_test_case_str_fn) (struct test_data *);
39typedef void (blk_dev_test_init_fn) (void);
40typedef void (blk_dev_test_exit_fn) (void);
41
42/**
43 * enum test_state - defines the state of the test
44 */
45enum test_state {
46 TEST_IDLE,
47 TEST_RUNNING,
48 TEST_COMPLETED,
49};
50
51/**
52 * enum test_results - defines the success orfailure of the test
53 */
54enum test_results {
55 TEST_NO_RESULT,
56 TEST_FAILED,
57 TEST_PASSED,
58 TEST_NOT_SUPPORTED,
59};
60
61/**
62 * enum req_unique_type - defines a unique request type
63 */
64enum req_unique_type {
65 REQ_UNIQUE_NONE,
66 REQ_UNIQUE_DISCARD,
67 REQ_UNIQUE_FLUSH,
Maya Erez22f7abf2012-07-18 21:52:33 +030068 REQ_UNIQUE_SANITIZE,
Maya Erez60181552012-06-27 11:25:26 +030069};
70
71/**
72 * struct test_debug - debugfs directories
73 * @debug_root: The test-iosched debugfs root directory
74 * @debug_utils_root: test-iosched debugfs utils root
75 * directory
76 * @debug_tests_root: test-iosched debugfs tests root
77 * directory
78 * @debug_test_result: Exposes the test result to the user
79 * space
80 * @start_sector: The start sector for read/write requests
81 */
82struct test_debug {
83 struct dentry *debug_root;
84 struct dentry *debug_utils_root;
85 struct dentry *debug_tests_root;
86 struct dentry *debug_test_result;
87 struct dentry *start_sector;
88};
89
90/**
91 * struct test_request - defines a test request
92 * @queuelist: The test requests list
93 * @bios_buffer: Write/read requests data buffer
94 * @buf_size: Write/read requests data buffer size (in
95 * bytes)
96 * @rq: A block request, to be dispatched
97 * @req_completed: A flag to indicate if the request was
98 * completed
99 * @req_result: Keeps the error code received in the
100 * request completion callback
101 * @is_err_expected: A flag to indicate if the request should
102 * fail
103 * @wr_rd_data_pattern: A pattern written to the write data
104 * buffer. Can be used in read requests to
105 * verify the data
106 * @req_id: A unique ID to identify a test request
107 * to ease the debugging of the test cases
108 */
109struct test_request {
110 struct list_head queuelist;
111 unsigned int *bios_buffer;
112 int buf_size;
113 struct request *rq;
114 bool req_completed;
115 int req_result;
116 int is_err_expected;
117 int wr_rd_data_pattern;
118 int req_id;
119};
120
121/**
122 * struct test_info - specific test information
123 * @testcase: The current running test case
124 * @timeout_msec: Test specific test timeout
125 * @buf_size: Write/read requests data buffer size (in
126 * bytes)
127 * @prepare_test_fn: Test specific test preparation callback
128 * @run_test_fn: Test specific test running callback
129 * @check_test_result_fn: Test specific test result checking
130 * callback
131 * @get_test_case_str_fn: Test specific function to get the test name
Lee Susmanf18263a2012-10-24 14:14:37 +0200132 * @test_duration: A jiffies value saved for timing
133 * calculations
Maya Erez60181552012-06-27 11:25:26 +0300134 * @data: Test specific private data
135 */
136struct test_info {
137 int testcase;
138 unsigned timeout_msec;
139 prepare_test_fn *prepare_test_fn;
140 run_test_fn *run_test_fn;
141 check_test_result_fn *check_test_result_fn;
142 post_test_fn *post_test_fn;
143 get_test_case_str_fn *get_test_case_str_fn;
Lee Susmanf18263a2012-10-24 14:14:37 +0200144 unsigned long test_duration;
Maya Erez60181552012-06-27 11:25:26 +0300145 void *data;
146};
147
148/**
149 * struct blk_dev_test_type - identifies block device test
150 * @list: list head pointer
151 * @init_fn: block device test init callback
152 * @exit_fn: block device test exit callback
153 */
154struct blk_dev_test_type {
155 struct list_head list;
156 blk_dev_test_init_fn *init_fn;
157 blk_dev_test_exit_fn *exit_fn;
158};
159
160/**
161 * struct test_data - global test iosched data
162 * @queue: The test IO scheduler requests list
163 * @test_queue: The test requests list
Lee Susman1199b4c2012-12-19 14:19:30 +0200164 * @dispatched_queue: The queue contains requests dispatched
165 * from @test_queue
166 * @reinsert_queue: The queue contains reinserted from underlying
167 * driver requests
168 * @urgent_queue: The queue contains requests for urgent delivery
169 * These requests will be delivered before @test_queue
170 * and @reinsert_queue requests
171 * @test_count: Number of requests in the @test_queue
172 * @dispatched_count: Number of requests in the @dispatched_queue
173 * @reinsert_count: Number of requests in the @reinsert_queue
174 * @urgent_count: Number of requests in the @urgent_queue
Maya Erez60181552012-06-27 11:25:26 +0300175 * @wait_q: A wait queue for waiting for the test
176 * requests completion
177 * @test_state: Indicates if there is a running test.
178 * Used for dispatch function
179 * @test_result: Indicates if the test passed or failed
180 * @debug: The test debugfs entries
181 * @req_q: The block layer request queue
182 * @num_of_write_bios: The number of write BIOs added to the test requests.
183 * Used to calcualte the sector number of
184 * new BIOs.
185 * @start_sector: The address of the first sector that can
186 * be accessed by the test
187 * @timeout_timer: A timer to verify test completion in
188 * case of non-completed requests
189 * @wr_rd_next_req_id: A unique ID to identify WRITE/READ
190 * request to ease the debugging of the
191 * test cases
192 * @unique_next_req_id: A unique ID to identify
193 * FLUSH/DISCARD/SANITIZE request to ease
194 * the debugging of the test cases
195 * @lock: A lock to verify running a single test
196 * at a time
197 * @test_info: A specific test data to be set by the
198 * test invokation function
199 * @ignore_round: A boolean variable indicating that a
200 * test round was disturbed by an external
201 * flush request, therefore disqualifying
202 * the results
203 */
204struct test_data {
205 struct list_head queue;
206 struct list_head test_queue;
Lee Susman1199b4c2012-12-19 14:19:30 +0200207 struct list_head dispatched_queue;
208 struct list_head reinsert_queue;
209 struct list_head urgent_queue;
210 unsigned int test_count;
211 unsigned int dispatched_count;
212 unsigned int reinsert_count;
213 unsigned int urgent_count;
Maya Erez60181552012-06-27 11:25:26 +0300214 wait_queue_head_t wait_q;
215 enum test_state test_state;
216 enum test_results test_result;
217 struct test_debug debug;
218 struct request_queue *req_q;
219 int num_of_write_bios;
220 u32 start_sector;
221 struct timer_list timeout_timer;
222 int wr_rd_next_req_id;
223 int unique_next_req_id;
224 spinlock_t lock;
225 struct test_info test_info;
226 bool fs_wr_reqs_during_test;
227 bool ignore_round;
228};
229
230extern int test_iosched_start_test(struct test_info *t_info);
231extern void test_iosched_mark_test_completion(void);
232extern int test_iosched_add_unique_test_req(int is_err_expcted,
233 enum req_unique_type req_unique,
234 int start_sec, int nr_sects, rq_end_io_fn *end_req_io);
235extern int test_iosched_add_wr_rd_test_req(int is_err_expcted,
236 int direction, int start_sec,
237 int num_bios, int pattern, rq_end_io_fn *end_req_io);
Lee Susman1199b4c2012-12-19 14:19:30 +0200238extern struct test_request *test_iosched_create_test_req(int is_err_expcted,
239 int direction, int start_sec,
240 int num_bios, int pattern, rq_end_io_fn *end_req_io);
Maya Erez60181552012-06-27 11:25:26 +0300241
242extern struct dentry *test_iosched_get_debugfs_tests_root(void);
243extern struct dentry *test_iosched_get_debugfs_utils_root(void);
244
245extern struct request_queue *test_iosched_get_req_queue(void);
246
247extern void test_iosched_set_test_result(int);
248
249void test_iosched_set_ignore_round(bool ignore_round);
250
251void test_iosched_register(struct blk_dev_test_type *bdt);
252
253void test_iosched_unregister(struct blk_dev_test_type *bdt);
254
Lee Susman1199b4c2012-12-19 14:19:30 +0200255extern struct test_data *test_get_test_data(void);
256
257void test_iosched_add_urgent_req(struct test_request *test_rq);
258
259int test_is_req_urgent(struct request *rq);
Maya Erez60181552012-06-27 11:25:26 +0300260#endif /* _LINUX_TEST_IOSCHED_H */