xref: /spdk/test/unit/lib/bdev/raid/bdev_raid.c/bdev_raid_ut.c (revision 4237d2d8cb14e5e52ede3ed9718019488b445afe)
1 /*-
2  *   BSD LICENSE
3  *
4  *   Copyright (c) Intel Corporation.
5  *   All rights reserved.
6  *
7  *   Redistribution and use in source and binary forms, with or without
8  *   modification, are permitted provided that the following conditions
9  *   are met:
10  *
11  *     * Redistributions of source code must retain the above copyright
12  *       notice, this list of conditions and the following disclaimer.
13  *     * Redistributions in binary form must reproduce the above copyright
14  *       notice, this list of conditions and the following disclaimer in
15  *       the documentation and/or other materials provided with the
16  *       distribution.
17  *     * Neither the name of Intel Corporation nor the names of its
18  *       contributors may be used to endorse or promote products derived
19  *       from this software without specific prior written permission.
20  *
21  *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24  *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25  *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26  *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27  *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28  *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29  *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30  *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31  *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  */
33 
34 #include "spdk/stdinc.h"
35 #include "spdk_cunit.h"
36 #include "spdk/env.h"
37 #include "spdk_internal/mock.h"
38 #include "bdev/raid/bdev_raid.c"
39 #include "bdev/raid/bdev_raid_rpc.c"
40 #include "bdev/raid/raid0.c"
41 #include "common/lib/ut_multithread.c"
42 
43 #define MAX_BASE_DRIVES 32
44 #define MAX_RAIDS 2
45 #define INVALID_IO_SUBMIT 0xFFFF
46 #define MAX_TEST_IO_RANGE (3 * 3 * 3 * (MAX_BASE_DRIVES + 5))
47 #define BLOCK_CNT (1024ul * 1024ul * 1024ul * 1024ul)
48 
49 struct spdk_bdev_channel {
50 	struct spdk_io_channel *channel;
51 };
52 
53 struct spdk_bdev_desc {
54 	struct spdk_bdev *bdev;
55 };
56 
57 /* Data structure to capture the output of IO for verification */
58 struct io_output {
59 	struct spdk_bdev_desc       *desc;
60 	struct spdk_io_channel      *ch;
61 	uint64_t                    offset_blocks;
62 	uint64_t                    num_blocks;
63 	spdk_bdev_io_completion_cb  cb;
64 	void                        *cb_arg;
65 	enum spdk_bdev_io_type      iotype;
66 };
67 
68 struct raid_io_ranges {
69 	uint64_t lba;
70 	uint64_t nblocks;
71 };
72 
73 /* Globals */
74 int g_bdev_io_submit_status;
75 struct io_output *g_io_output = NULL;
76 uint32_t g_io_output_index;
77 uint32_t g_io_comp_status;
78 bool g_child_io_status_flag;
79 void *g_rpc_req;
80 uint32_t g_rpc_req_size;
81 TAILQ_HEAD(bdev, spdk_bdev);
82 struct bdev g_bdev_list;
83 TAILQ_HEAD(waitq, spdk_bdev_io_wait_entry);
84 struct waitq g_io_waitq;
85 uint32_t g_block_len;
86 uint32_t g_strip_size;
87 uint32_t g_max_io_size;
88 uint8_t g_max_base_drives;
89 uint8_t g_max_raids;
90 uint8_t g_ignore_io_output;
91 uint8_t g_rpc_err;
92 char *g_get_raids_output[MAX_RAIDS];
93 uint32_t g_get_raids_count;
94 uint8_t g_json_decode_obj_err;
95 uint8_t g_json_decode_obj_create;
96 uint8_t g_config_level_create = 0;
97 uint8_t g_test_multi_raids;
98 struct raid_io_ranges g_io_ranges[MAX_TEST_IO_RANGE];
99 uint32_t g_io_range_idx;
100 uint64_t g_lba_offset;
101 struct spdk_io_channel g_io_channel;
102 
103 DEFINE_STUB_V(spdk_bdev_module_examine_done, (struct spdk_bdev_module *module));
104 DEFINE_STUB_V(spdk_bdev_module_list_add, (struct spdk_bdev_module *bdev_module));
105 DEFINE_STUB(spdk_bdev_register, int, (struct spdk_bdev *bdev), 0);
106 DEFINE_STUB(spdk_bdev_io_type_supported, bool, (struct spdk_bdev *bdev,
107 		enum spdk_bdev_io_type io_type), true);
108 DEFINE_STUB_V(spdk_bdev_close, (struct spdk_bdev_desc *desc));
109 DEFINE_STUB(spdk_bdev_flush_blocks, int, (struct spdk_bdev_desc *desc, struct spdk_io_channel *ch,
110 		uint64_t offset_blocks, uint64_t num_blocks, spdk_bdev_io_completion_cb cb,
111 		void *cb_arg), 0);
112 DEFINE_STUB(spdk_conf_next_section, struct spdk_conf_section *, (struct spdk_conf_section *sp),
113 	    NULL);
114 DEFINE_STUB_V(spdk_rpc_register_method, (const char *method, spdk_rpc_method_handler func,
115 		uint32_t state_mask));
116 DEFINE_STUB_V(spdk_rpc_register_alias_deprecated, (const char *method, const char *alias));
117 DEFINE_STUB_V(spdk_jsonrpc_end_result, (struct spdk_jsonrpc_request *request,
118 					struct spdk_json_write_ctx *w));
119 DEFINE_STUB(spdk_json_decode_string, int, (const struct spdk_json_val *val, void *out), 0);
120 DEFINE_STUB(spdk_json_decode_uint32, int, (const struct spdk_json_val *val, void *out), 0);
121 DEFINE_STUB(spdk_json_decode_array, int, (const struct spdk_json_val *values,
122 		spdk_json_decode_fn decode_func,
123 		void *out, size_t max_size, size_t *out_size, size_t stride), 0);
124 DEFINE_STUB(spdk_json_write_name, int, (struct spdk_json_write_ctx *w, const char *name), 0);
125 DEFINE_STUB(spdk_json_write_object_begin, int, (struct spdk_json_write_ctx *w), 0);
126 DEFINE_STUB(spdk_json_write_named_object_begin, int, (struct spdk_json_write_ctx *w,
127 		const char *name), 0);
128 DEFINE_STUB(spdk_json_write_object_end, int, (struct spdk_json_write_ctx *w), 0);
129 DEFINE_STUB(spdk_json_write_array_begin, int, (struct spdk_json_write_ctx *w), 0);
130 DEFINE_STUB(spdk_json_write_array_end, int, (struct spdk_json_write_ctx *w), 0);
131 DEFINE_STUB(spdk_json_write_named_array_begin, int, (struct spdk_json_write_ctx *w,
132 		const char *name), 0);
133 DEFINE_STUB(spdk_json_write_bool, int, (struct spdk_json_write_ctx *w, bool val), 0);
134 DEFINE_STUB(spdk_json_write_null, int, (struct spdk_json_write_ctx *w), 0);
135 DEFINE_STUB(spdk_strerror, const char *, (int errnum), NULL);
136 DEFINE_STUB(spdk_bdev_queue_io_wait, int, (struct spdk_bdev *bdev, struct spdk_io_channel *ch,
137 		struct spdk_bdev_io_wait_entry *entry), 0);
138 
139 struct spdk_io_channel *
140 spdk_bdev_get_io_channel(struct spdk_bdev_desc *desc)
141 {
142 	g_io_channel.thread = spdk_get_thread();
143 
144 	return &g_io_channel;
145 }
146 
147 static void
148 set_test_opts(void)
149 {
150 
151 	g_max_base_drives = MAX_BASE_DRIVES;
152 	g_max_raids = MAX_RAIDS;
153 	g_block_len = 4096;
154 	g_strip_size = 64;
155 	g_max_io_size = 1024;
156 
157 	printf("Test Options\n");
158 	printf("blocklen = %u, strip_size = %u, max_io_size = %u, g_max_base_drives = %u, "
159 	       "g_max_raids = %u\n",
160 	       g_block_len, g_strip_size, g_max_io_size, g_max_base_drives, g_max_raids);
161 }
162 
163 /* Set globals before every test run */
164 static void
165 set_globals(void)
166 {
167 	uint32_t max_splits;
168 
169 	g_bdev_io_submit_status = 0;
170 	if (g_max_io_size < g_strip_size) {
171 		max_splits = 2;
172 	} else {
173 		max_splits = (g_max_io_size / g_strip_size) + 1;
174 	}
175 	if (max_splits < g_max_base_drives) {
176 		max_splits = g_max_base_drives;
177 	}
178 
179 	g_io_output = calloc(max_splits, sizeof(struct io_output));
180 	SPDK_CU_ASSERT_FATAL(g_io_output != NULL);
181 	g_io_output_index = 0;
182 	memset(g_get_raids_output, 0, sizeof(g_get_raids_output));
183 	g_get_raids_count = 0;
184 	g_io_comp_status = 0;
185 	g_ignore_io_output = 0;
186 	g_config_level_create = 0;
187 	g_rpc_err = 0;
188 	g_test_multi_raids = 0;
189 	g_child_io_status_flag = true;
190 	TAILQ_INIT(&g_bdev_list);
191 	TAILQ_INIT(&g_io_waitq);
192 	g_rpc_req = NULL;
193 	g_rpc_req_size = 0;
194 	g_json_decode_obj_err = 0;
195 	g_json_decode_obj_create = 0;
196 	g_lba_offset = 0;
197 }
198 
199 static void
200 base_bdevs_cleanup(void)
201 {
202 	struct spdk_bdev *bdev;
203 	struct spdk_bdev *bdev_next;
204 
205 	if (!TAILQ_EMPTY(&g_bdev_list)) {
206 		TAILQ_FOREACH_SAFE(bdev, &g_bdev_list, internal.link, bdev_next) {
207 			free(bdev->name);
208 			TAILQ_REMOVE(&g_bdev_list, bdev, internal.link);
209 			free(bdev);
210 		}
211 	}
212 }
213 
214 static void
215 check_and_remove_raid_bdev(struct raid_bdev_config *raid_cfg)
216 {
217 	struct raid_bdev *raid_bdev;
218 	struct raid_base_bdev_info *base_info;
219 
220 	/* Get the raid structured allocated if exists */
221 	raid_bdev = raid_cfg->raid_bdev;
222 	if (raid_bdev == NULL) {
223 		return;
224 	}
225 
226 	assert(raid_bdev->base_bdev_info != NULL);
227 
228 	RAID_FOR_EACH_BASE_BDEV(raid_bdev, base_info) {
229 		if (base_info->bdev) {
230 			raid_bdev_free_base_bdev_resource(raid_bdev, base_info);
231 		}
232 	}
233 	assert(raid_bdev->num_base_bdevs_discovered == 0);
234 	raid_bdev_cleanup(raid_bdev);
235 }
236 
237 /* Reset globals */
238 static void
239 reset_globals(void)
240 {
241 	if (g_io_output) {
242 		free(g_io_output);
243 		g_io_output = NULL;
244 	}
245 	g_rpc_req = NULL;
246 	g_rpc_req_size = 0;
247 }
248 
249 void
250 spdk_bdev_io_get_buf(struct spdk_bdev_io *bdev_io, spdk_bdev_io_get_buf_cb cb,
251 		     uint64_t len)
252 {
253 	cb(bdev_io->internal.ch->channel, bdev_io, true);
254 }
255 
256 /* Store the IO completion status in global variable to verify by various tests */
257 void
258 spdk_bdev_io_complete(struct spdk_bdev_io *bdev_io, enum spdk_bdev_io_status status)
259 {
260 	g_io_comp_status = ((status == SPDK_BDEV_IO_STATUS_SUCCESS) ? true : false);
261 }
262 
263 static void
264 set_io_output(struct io_output *output,
265 	      struct spdk_bdev_desc *desc, struct spdk_io_channel *ch,
266 	      uint64_t offset_blocks, uint64_t num_blocks,
267 	      spdk_bdev_io_completion_cb cb, void *cb_arg,
268 	      enum spdk_bdev_io_type iotype)
269 {
270 	output->desc = desc;
271 	output->ch = ch;
272 	output->offset_blocks = offset_blocks;
273 	output->num_blocks = num_blocks;
274 	output->cb = cb;
275 	output->cb_arg = cb_arg;
276 	output->iotype = iotype;
277 }
278 
279 /* It will cache the split IOs for verification */
280 int
281 spdk_bdev_writev_blocks(struct spdk_bdev_desc *desc, struct spdk_io_channel *ch,
282 			struct iovec *iov, int iovcnt,
283 			uint64_t offset_blocks, uint64_t num_blocks,
284 			spdk_bdev_io_completion_cb cb, void *cb_arg)
285 {
286 	struct io_output *output = &g_io_output[g_io_output_index];
287 	struct spdk_bdev_io *child_io;
288 
289 	if (g_ignore_io_output) {
290 		return 0;
291 	}
292 
293 	if (g_max_io_size < g_strip_size) {
294 		SPDK_CU_ASSERT_FATAL(g_io_output_index < 2);
295 	} else {
296 		SPDK_CU_ASSERT_FATAL(g_io_output_index < (g_max_io_size / g_strip_size) + 1);
297 	}
298 	if (g_bdev_io_submit_status == 0) {
299 		set_io_output(output, desc, ch, offset_blocks, num_blocks, cb, cb_arg,
300 			      SPDK_BDEV_IO_TYPE_WRITE);
301 		g_io_output_index++;
302 
303 		child_io = calloc(1, sizeof(struct spdk_bdev_io));
304 		SPDK_CU_ASSERT_FATAL(child_io != NULL);
305 		cb(child_io, g_child_io_status_flag, cb_arg);
306 	}
307 
308 	return g_bdev_io_submit_status;
309 }
310 
311 int
312 spdk_bdev_reset(struct spdk_bdev_desc *desc, struct spdk_io_channel *ch,
313 		spdk_bdev_io_completion_cb cb, void *cb_arg)
314 {
315 	struct io_output *output = &g_io_output[g_io_output_index];
316 	struct spdk_bdev_io *child_io;
317 
318 	if (g_ignore_io_output) {
319 		return 0;
320 	}
321 
322 	if (g_bdev_io_submit_status == 0) {
323 		set_io_output(output, desc, ch, 0, 0, cb, cb_arg, SPDK_BDEV_IO_TYPE_RESET);
324 		g_io_output_index++;
325 
326 		child_io = calloc(1, sizeof(struct spdk_bdev_io));
327 		SPDK_CU_ASSERT_FATAL(child_io != NULL);
328 		cb(child_io, g_child_io_status_flag, cb_arg);
329 	}
330 
331 	return g_bdev_io_submit_status;
332 }
333 
334 int
335 spdk_bdev_unmap_blocks(struct spdk_bdev_desc *desc, struct spdk_io_channel *ch,
336 		       uint64_t offset_blocks, uint64_t num_blocks,
337 		       spdk_bdev_io_completion_cb cb, void *cb_arg)
338 {
339 	struct io_output *output = &g_io_output[g_io_output_index];
340 	struct spdk_bdev_io *child_io;
341 
342 	if (g_ignore_io_output) {
343 		return 0;
344 	}
345 
346 	if (g_bdev_io_submit_status == 0) {
347 		set_io_output(output, desc, ch, offset_blocks, num_blocks, cb, cb_arg,
348 			      SPDK_BDEV_IO_TYPE_UNMAP);
349 		g_io_output_index++;
350 
351 		child_io = calloc(1, sizeof(struct spdk_bdev_io));
352 		SPDK_CU_ASSERT_FATAL(child_io != NULL);
353 		cb(child_io, g_child_io_status_flag, cb_arg);
354 	}
355 
356 	return g_bdev_io_submit_status;
357 }
358 
359 void
360 spdk_bdev_unregister(struct spdk_bdev *bdev, spdk_bdev_unregister_cb cb_fn, void *cb_arg)
361 {
362 	bdev->fn_table->destruct(bdev->ctxt);
363 
364 	if (cb_fn) {
365 		cb_fn(cb_arg, 0);
366 	}
367 }
368 
369 int
370 spdk_bdev_open_ext(const char *bdev_name, bool write, spdk_bdev_event_cb_t event_cb,
371 		   void *event_ctx, struct spdk_bdev_desc **_desc)
372 {
373 	struct spdk_bdev *bdev;
374 
375 	bdev = spdk_bdev_get_by_name(bdev_name);
376 	if (bdev == NULL) {
377 		return -ENODEV;
378 	}
379 
380 	*_desc = (void *)bdev;
381 	return 0;
382 }
383 
384 struct spdk_bdev *
385 spdk_bdev_desc_get_bdev(struct spdk_bdev_desc *desc)
386 {
387 	return (void *)desc;
388 }
389 
390 char *
391 spdk_sprintf_alloc(const char *format, ...)
392 {
393 	return strdup(format);
394 }
395 
396 int spdk_json_write_named_uint32(struct spdk_json_write_ctx *w, const char *name, uint32_t val)
397 {
398 	struct rpc_bdev_raid_create *req = g_rpc_req;
399 	if (strcmp(name, "strip_size_kb") == 0) {
400 		CU_ASSERT(req->strip_size_kb == val);
401 	} else if (strcmp(name, "blocklen_shift") == 0) {
402 		CU_ASSERT(spdk_u32log2(g_block_len) == val);
403 	} else if (strcmp(name, "num_base_bdevs") == 0) {
404 		CU_ASSERT(req->base_bdevs.num_base_bdevs == val);
405 	} else if (strcmp(name, "state") == 0) {
406 		CU_ASSERT(val == RAID_BDEV_STATE_ONLINE);
407 	} else if (strcmp(name, "destruct_called") == 0) {
408 		CU_ASSERT(val == 0);
409 	} else if (strcmp(name, "num_base_bdevs_discovered") == 0) {
410 		CU_ASSERT(req->base_bdevs.num_base_bdevs == val);
411 	}
412 	return 0;
413 }
414 
415 int spdk_json_write_named_string(struct spdk_json_write_ctx *w, const char *name, const char *val)
416 {
417 	struct rpc_bdev_raid_create *req = g_rpc_req;
418 	if (strcmp(name, "raid_level") == 0) {
419 		CU_ASSERT(strcmp(val, raid_bdev_level_to_str(req->level)) == 0);
420 	}
421 	return 0;
422 }
423 
424 void
425 spdk_bdev_free_io(struct spdk_bdev_io *bdev_io)
426 {
427 	if (bdev_io) {
428 		free(bdev_io);
429 	}
430 }
431 
432 /* It will cache split IOs for verification */
433 int
434 spdk_bdev_readv_blocks(struct spdk_bdev_desc *desc, struct spdk_io_channel *ch,
435 		       struct iovec *iov, int iovcnt,
436 		       uint64_t offset_blocks, uint64_t num_blocks,
437 		       spdk_bdev_io_completion_cb cb, void *cb_arg)
438 {
439 	struct io_output *output = &g_io_output[g_io_output_index];
440 	struct spdk_bdev_io *child_io;
441 
442 	if (g_ignore_io_output) {
443 		return 0;
444 	}
445 
446 	SPDK_CU_ASSERT_FATAL(g_io_output_index <= (g_max_io_size / g_strip_size) + 1);
447 	if (g_bdev_io_submit_status == 0) {
448 		set_io_output(output, desc, ch, offset_blocks, num_blocks, cb, cb_arg,
449 			      SPDK_BDEV_IO_TYPE_READ);
450 		g_io_output_index++;
451 
452 		child_io = calloc(1, sizeof(struct spdk_bdev_io));
453 		SPDK_CU_ASSERT_FATAL(child_io != NULL);
454 		cb(child_io, g_child_io_status_flag, cb_arg);
455 	}
456 
457 	return g_bdev_io_submit_status;
458 }
459 
460 void
461 spdk_bdev_module_release_bdev(struct spdk_bdev *bdev)
462 {
463 	CU_ASSERT(bdev->internal.claim_module != NULL);
464 	bdev->internal.claim_module = NULL;
465 }
466 
467 int
468 spdk_bdev_module_claim_bdev(struct spdk_bdev *bdev, struct spdk_bdev_desc *desc,
469 			    struct spdk_bdev_module *module)
470 {
471 	if (bdev->internal.claim_module != NULL) {
472 		return -1;
473 	}
474 	bdev->internal.claim_module = module;
475 	return 0;
476 }
477 
478 int
479 spdk_json_decode_object(const struct spdk_json_val *values,
480 			const struct spdk_json_object_decoder *decoders, size_t num_decoders,
481 			void *out)
482 {
483 	struct rpc_bdev_raid_create *req, *_out;
484 	size_t i;
485 
486 	if (g_json_decode_obj_err) {
487 		return -1;
488 	} else if (g_json_decode_obj_create) {
489 		req = g_rpc_req;
490 		_out = out;
491 
492 		_out->name = strdup(req->name);
493 		SPDK_CU_ASSERT_FATAL(_out->name != NULL);
494 		_out->strip_size_kb = req->strip_size_kb;
495 		_out->level = req->level;
496 		_out->base_bdevs.num_base_bdevs = req->base_bdevs.num_base_bdevs;
497 		for (i = 0; i < req->base_bdevs.num_base_bdevs; i++) {
498 			_out->base_bdevs.base_bdevs[i] = strdup(req->base_bdevs.base_bdevs[i]);
499 			SPDK_CU_ASSERT_FATAL(_out->base_bdevs.base_bdevs[i]);
500 		}
501 	} else {
502 		memcpy(out, g_rpc_req, g_rpc_req_size);
503 	}
504 
505 	return 0;
506 }
507 
508 struct spdk_json_write_ctx *
509 spdk_jsonrpc_begin_result(struct spdk_jsonrpc_request *request)
510 {
511 	return (void *)1;
512 }
513 
514 int
515 spdk_json_write_string(struct spdk_json_write_ctx *w, const char *val)
516 {
517 	if (g_test_multi_raids) {
518 		g_get_raids_output[g_get_raids_count] = strdup(val);
519 		SPDK_CU_ASSERT_FATAL(g_get_raids_output[g_get_raids_count] != NULL);
520 		g_get_raids_count++;
521 	}
522 
523 	return 0;
524 }
525 
526 void
527 spdk_jsonrpc_send_error_response(struct spdk_jsonrpc_request *request,
528 				 int error_code, const char *msg)
529 {
530 	g_rpc_err = 1;
531 }
532 
533 void
534 spdk_jsonrpc_send_error_response_fmt(struct spdk_jsonrpc_request *request,
535 				     int error_code, const char *fmt, ...)
536 {
537 	g_rpc_err = 1;
538 }
539 
540 struct spdk_bdev *
541 spdk_bdev_get_by_name(const char *bdev_name)
542 {
543 	struct spdk_bdev *bdev;
544 
545 	if (!TAILQ_EMPTY(&g_bdev_list)) {
546 		TAILQ_FOREACH(bdev, &g_bdev_list, internal.link) {
547 			if (strcmp(bdev_name, bdev->name) == 0) {
548 				return bdev;
549 			}
550 		}
551 	}
552 
553 	return NULL;
554 }
555 
556 static void
557 bdev_io_cleanup(struct spdk_bdev_io *bdev_io)
558 {
559 	if (bdev_io->u.bdev.iovs) {
560 		if (bdev_io->u.bdev.iovs->iov_base) {
561 			free(bdev_io->u.bdev.iovs->iov_base);
562 		}
563 		free(bdev_io->u.bdev.iovs);
564 	}
565 	free(bdev_io);
566 }
567 
568 static void
569 bdev_io_initialize(struct spdk_bdev_io *bdev_io, struct spdk_io_channel *ch, struct spdk_bdev *bdev,
570 		   uint64_t lba, uint64_t blocks, int16_t iotype)
571 {
572 	struct spdk_bdev_channel *channel = spdk_io_channel_get_ctx(ch);
573 
574 	bdev_io->bdev = bdev;
575 	bdev_io->u.bdev.offset_blocks = lba;
576 	bdev_io->u.bdev.num_blocks = blocks;
577 	bdev_io->type = iotype;
578 
579 	if (bdev_io->type == SPDK_BDEV_IO_TYPE_UNMAP || bdev_io->type == SPDK_BDEV_IO_TYPE_FLUSH) {
580 		return;
581 	}
582 
583 	bdev_io->u.bdev.iovcnt = 1;
584 	bdev_io->u.bdev.iovs = calloc(1, sizeof(struct iovec));
585 	SPDK_CU_ASSERT_FATAL(bdev_io->u.bdev.iovs != NULL);
586 	bdev_io->u.bdev.iovs->iov_base = calloc(1, bdev_io->u.bdev.num_blocks * g_block_len);
587 	SPDK_CU_ASSERT_FATAL(bdev_io->u.bdev.iovs->iov_base != NULL);
588 	bdev_io->u.bdev.iovs->iov_len = bdev_io->u.bdev.num_blocks * g_block_len;
589 	bdev_io->internal.ch = channel;
590 }
591 
592 static void
593 verify_reset_io(struct spdk_bdev_io *bdev_io, uint8_t num_base_drives,
594 		struct raid_bdev_io_channel *ch_ctx, struct raid_bdev *raid_bdev, uint32_t io_status)
595 {
596 	uint8_t index = 0;
597 	struct io_output *output;
598 
599 	SPDK_CU_ASSERT_FATAL(raid_bdev != NULL);
600 	SPDK_CU_ASSERT_FATAL(num_base_drives != 0);
601 	SPDK_CU_ASSERT_FATAL(io_status != INVALID_IO_SUBMIT);
602 	SPDK_CU_ASSERT_FATAL(ch_ctx->base_channel != NULL);
603 
604 	CU_ASSERT(g_io_output_index == num_base_drives);
605 	for (index = 0; index < g_io_output_index; index++) {
606 		output = &g_io_output[index];
607 		CU_ASSERT(ch_ctx->base_channel[index] == output->ch);
608 		CU_ASSERT(raid_bdev->base_bdev_info[index].desc == output->desc);
609 		CU_ASSERT(bdev_io->type == output->iotype);
610 	}
611 	CU_ASSERT(g_io_comp_status == io_status);
612 }
613 
614 static void
615 verify_io(struct spdk_bdev_io *bdev_io, uint8_t num_base_drives,
616 	  struct raid_bdev_io_channel *ch_ctx, struct raid_bdev *raid_bdev, uint32_t io_status)
617 {
618 	uint32_t strip_shift = spdk_u32log2(g_strip_size);
619 	uint64_t start_strip = bdev_io->u.bdev.offset_blocks >> strip_shift;
620 	uint64_t end_strip = (bdev_io->u.bdev.offset_blocks + bdev_io->u.bdev.num_blocks - 1) >>
621 			     strip_shift;
622 	uint32_t splits_reqd = (end_strip - start_strip + 1);
623 	uint32_t strip;
624 	uint64_t pd_strip;
625 	uint8_t pd_idx;
626 	uint32_t offset_in_strip;
627 	uint64_t pd_lba;
628 	uint64_t pd_blocks;
629 	uint32_t index = 0;
630 	uint8_t *buf = bdev_io->u.bdev.iovs->iov_base;
631 	struct io_output *output;
632 
633 	if (io_status == INVALID_IO_SUBMIT) {
634 		CU_ASSERT(g_io_comp_status == false);
635 		return;
636 	}
637 	SPDK_CU_ASSERT_FATAL(raid_bdev != NULL);
638 	SPDK_CU_ASSERT_FATAL(num_base_drives != 0);
639 
640 	CU_ASSERT(splits_reqd == g_io_output_index);
641 	for (strip = start_strip; strip <= end_strip; strip++, index++) {
642 		pd_strip = strip / num_base_drives;
643 		pd_idx = strip % num_base_drives;
644 		if (strip == start_strip) {
645 			offset_in_strip = bdev_io->u.bdev.offset_blocks & (g_strip_size - 1);
646 			pd_lba = (pd_strip << strip_shift) + offset_in_strip;
647 			if (strip == end_strip) {
648 				pd_blocks = bdev_io->u.bdev.num_blocks;
649 			} else {
650 				pd_blocks = g_strip_size - offset_in_strip;
651 			}
652 		} else if (strip == end_strip) {
653 			pd_lba = pd_strip << strip_shift;
654 			pd_blocks = ((bdev_io->u.bdev.offset_blocks + bdev_io->u.bdev.num_blocks - 1) &
655 				     (g_strip_size - 1)) + 1;
656 		} else {
657 			pd_lba = pd_strip << raid_bdev->strip_size_shift;
658 			pd_blocks = raid_bdev->strip_size;
659 		}
660 		output = &g_io_output[index];
661 		CU_ASSERT(pd_lba == output->offset_blocks);
662 		CU_ASSERT(pd_blocks == output->num_blocks);
663 		CU_ASSERT(ch_ctx->base_channel[pd_idx] == output->ch);
664 		CU_ASSERT(raid_bdev->base_bdev_info[pd_idx].desc == output->desc);
665 		CU_ASSERT(bdev_io->type == output->iotype);
666 		buf += (pd_blocks << spdk_u32log2(g_block_len));
667 	}
668 	CU_ASSERT(g_io_comp_status == io_status);
669 }
670 
671 static void
672 verify_io_without_payload(struct spdk_bdev_io *bdev_io, uint8_t num_base_drives,
673 			  struct raid_bdev_io_channel *ch_ctx, struct raid_bdev *raid_bdev,
674 			  uint32_t io_status)
675 {
676 	uint32_t strip_shift = spdk_u32log2(g_strip_size);
677 	uint64_t start_offset_in_strip = bdev_io->u.bdev.offset_blocks % g_strip_size;
678 	uint64_t end_offset_in_strip = (bdev_io->u.bdev.offset_blocks + bdev_io->u.bdev.num_blocks - 1) %
679 				       g_strip_size;
680 	uint64_t start_strip = bdev_io->u.bdev.offset_blocks >> strip_shift;
681 	uint64_t end_strip = (bdev_io->u.bdev.offset_blocks + bdev_io->u.bdev.num_blocks - 1) >>
682 			     strip_shift;
683 	uint8_t n_disks_involved;
684 	uint64_t start_strip_disk_idx;
685 	uint64_t end_strip_disk_idx;
686 	uint64_t nblocks_in_start_disk;
687 	uint64_t offset_in_start_disk;
688 	uint8_t disk_idx;
689 	uint64_t base_io_idx;
690 	uint64_t sum_nblocks = 0;
691 	struct io_output *output;
692 
693 	if (io_status == INVALID_IO_SUBMIT) {
694 		CU_ASSERT(g_io_comp_status == false);
695 		return;
696 	}
697 	SPDK_CU_ASSERT_FATAL(raid_bdev != NULL);
698 	SPDK_CU_ASSERT_FATAL(num_base_drives != 0);
699 	SPDK_CU_ASSERT_FATAL(bdev_io->type != SPDK_BDEV_IO_TYPE_READ);
700 	SPDK_CU_ASSERT_FATAL(bdev_io->type != SPDK_BDEV_IO_TYPE_WRITE);
701 
702 	n_disks_involved = spdk_min(end_strip - start_strip + 1, num_base_drives);
703 	CU_ASSERT(n_disks_involved == g_io_output_index);
704 
705 	start_strip_disk_idx = start_strip % num_base_drives;
706 	end_strip_disk_idx = end_strip % num_base_drives;
707 
708 	offset_in_start_disk = g_io_output[0].offset_blocks;
709 	nblocks_in_start_disk = g_io_output[0].num_blocks;
710 
711 	for (base_io_idx = 0, disk_idx = start_strip_disk_idx; base_io_idx < n_disks_involved;
712 	     base_io_idx++, disk_idx++) {
713 		uint64_t start_offset_in_disk;
714 		uint64_t end_offset_in_disk;
715 
716 		output = &g_io_output[base_io_idx];
717 
718 		/* round disk_idx */
719 		if (disk_idx >= num_base_drives) {
720 			disk_idx %= num_base_drives;
721 		}
722 
723 		/* start_offset_in_disk aligned in strip check:
724 		 * The first base io has a same start_offset_in_strip with the whole raid io.
725 		 * Other base io should have aligned start_offset_in_strip which is 0.
726 		 */
727 		start_offset_in_disk = output->offset_blocks;
728 		if (base_io_idx == 0) {
729 			CU_ASSERT(start_offset_in_disk % g_strip_size == start_offset_in_strip);
730 		} else {
731 			CU_ASSERT(start_offset_in_disk % g_strip_size == 0);
732 		}
733 
734 		/* end_offset_in_disk aligned in strip check:
735 		 * Base io on disk at which end_strip is located, has a same end_offset_in_strip
736 		 * with the whole raid io.
737 		 * Other base io should have aligned end_offset_in_strip.
738 		 */
739 		end_offset_in_disk = output->offset_blocks + output->num_blocks - 1;
740 		if (disk_idx == end_strip_disk_idx) {
741 			CU_ASSERT(end_offset_in_disk % g_strip_size == end_offset_in_strip);
742 		} else {
743 			CU_ASSERT(end_offset_in_disk % g_strip_size == g_strip_size - 1);
744 		}
745 
746 		/* start_offset_in_disk compared with start_disk.
747 		 * 1. For disk_idx which is larger than start_strip_disk_idx: Its start_offset_in_disk
748 		 *    mustn't be larger than the start offset of start_offset_in_disk; And the gap
749 		 *    must be less than strip size.
750 		 * 2. For disk_idx which is less than start_strip_disk_idx, Its start_offset_in_disk
751 		 *    must be larger than the start offset of start_offset_in_disk; And the gap mustn't
752 		 *    be less than strip size.
753 		 */
754 		if (disk_idx > start_strip_disk_idx) {
755 			CU_ASSERT(start_offset_in_disk <= offset_in_start_disk);
756 			CU_ASSERT(offset_in_start_disk - start_offset_in_disk < g_strip_size);
757 		} else if (disk_idx < start_strip_disk_idx) {
758 			CU_ASSERT(start_offset_in_disk > offset_in_start_disk);
759 			CU_ASSERT(output->offset_blocks - offset_in_start_disk <= g_strip_size);
760 		}
761 
762 		/* nblocks compared with start_disk:
763 		 * The gap between them must be within a strip size.
764 		 */
765 		if (output->num_blocks <= nblocks_in_start_disk) {
766 			CU_ASSERT(nblocks_in_start_disk - output->num_blocks <= g_strip_size);
767 		} else {
768 			CU_ASSERT(output->num_blocks - nblocks_in_start_disk < g_strip_size);
769 		}
770 
771 		sum_nblocks += output->num_blocks;
772 
773 		CU_ASSERT(ch_ctx->base_channel[disk_idx] == output->ch);
774 		CU_ASSERT(raid_bdev->base_bdev_info[disk_idx].desc == output->desc);
775 		CU_ASSERT(bdev_io->type == output->iotype);
776 	}
777 
778 	/* Sum of each nblocks should be same with raid bdev_io */
779 	CU_ASSERT(bdev_io->u.bdev.num_blocks == sum_nblocks);
780 
781 	CU_ASSERT(g_io_comp_status == io_status);
782 }
783 
784 static void
785 verify_raid_config_present(const char *name, bool presence)
786 {
787 	struct raid_bdev_config *raid_cfg;
788 	bool cfg_found;
789 
790 	cfg_found = false;
791 
792 	TAILQ_FOREACH(raid_cfg, &g_raid_config.raid_bdev_config_head, link) {
793 		if (raid_cfg->name != NULL) {
794 			if (strcmp(name, raid_cfg->name) == 0) {
795 				cfg_found = true;
796 				break;
797 			}
798 		}
799 	}
800 
801 	if (presence == true) {
802 		CU_ASSERT(cfg_found == true);
803 	} else {
804 		CU_ASSERT(cfg_found == false);
805 	}
806 }
807 
808 static void
809 verify_raid_bdev_present(const char *name, bool presence)
810 {
811 	struct raid_bdev *pbdev;
812 	bool   pbdev_found;
813 
814 	pbdev_found = false;
815 	TAILQ_FOREACH(pbdev, &g_raid_bdev_list, global_link) {
816 		if (strcmp(pbdev->bdev.name, name) == 0) {
817 			pbdev_found = true;
818 			break;
819 		}
820 	}
821 	if (presence == true) {
822 		CU_ASSERT(pbdev_found == true);
823 	} else {
824 		CU_ASSERT(pbdev_found == false);
825 	}
826 }
827 static void
828 verify_raid_config(struct rpc_bdev_raid_create *r, bool presence)
829 {
830 	struct raid_bdev_config *raid_cfg = NULL;
831 	uint8_t i;
832 	int val;
833 
834 	TAILQ_FOREACH(raid_cfg, &g_raid_config.raid_bdev_config_head, link) {
835 		if (strcmp(r->name, raid_cfg->name) == 0) {
836 			if (presence == false) {
837 				break;
838 			}
839 			CU_ASSERT(raid_cfg->raid_bdev != NULL);
840 			CU_ASSERT(raid_cfg->strip_size == r->strip_size_kb);
841 			CU_ASSERT(raid_cfg->num_base_bdevs == r->base_bdevs.num_base_bdevs);
842 			CU_ASSERT(raid_cfg->level == r->level);
843 			if (raid_cfg->base_bdev != NULL) {
844 				for (i = 0; i < raid_cfg->num_base_bdevs; i++) {
845 					val = strcmp(raid_cfg->base_bdev[i].name,
846 						     r->base_bdevs.base_bdevs[i]);
847 					CU_ASSERT(val == 0);
848 				}
849 			}
850 			break;
851 		}
852 	}
853 
854 	if (presence == true) {
855 		CU_ASSERT(raid_cfg != NULL);
856 	} else {
857 		CU_ASSERT(raid_cfg == NULL);
858 	}
859 }
860 
861 static void
862 verify_raid_bdev(struct rpc_bdev_raid_create *r, bool presence, uint32_t raid_state)
863 {
864 	struct raid_bdev *pbdev;
865 	struct raid_base_bdev_info *base_info;
866 	struct spdk_bdev *bdev = NULL;
867 	bool   pbdev_found;
868 	uint64_t min_blockcnt = 0xFFFFFFFFFFFFFFFF;
869 
870 	pbdev_found = false;
871 	TAILQ_FOREACH(pbdev, &g_raid_bdev_list, global_link) {
872 		if (strcmp(pbdev->bdev.name, r->name) == 0) {
873 			pbdev_found = true;
874 			if (presence == false) {
875 				break;
876 			}
877 			CU_ASSERT(pbdev->config->raid_bdev == pbdev);
878 			CU_ASSERT(pbdev->base_bdev_info != NULL);
879 			CU_ASSERT(pbdev->strip_size == ((r->strip_size_kb * 1024) / g_block_len));
880 			CU_ASSERT(pbdev->strip_size_shift == spdk_u32log2(((r->strip_size_kb * 1024) /
881 					g_block_len)));
882 			CU_ASSERT(pbdev->blocklen_shift == spdk_u32log2(g_block_len));
883 			CU_ASSERT(pbdev->state == raid_state);
884 			CU_ASSERT(pbdev->num_base_bdevs == r->base_bdevs.num_base_bdevs);
885 			CU_ASSERT(pbdev->num_base_bdevs_discovered == r->base_bdevs.num_base_bdevs);
886 			CU_ASSERT(pbdev->level == r->level);
887 			CU_ASSERT(pbdev->destruct_called == false);
888 			CU_ASSERT(pbdev->base_bdev_info != NULL);
889 			RAID_FOR_EACH_BASE_BDEV(pbdev, base_info) {
890 				CU_ASSERT(base_info->bdev != NULL);
891 				bdev = spdk_bdev_get_by_name(base_info->bdev->name);
892 				CU_ASSERT(bdev != NULL);
893 				CU_ASSERT(base_info->remove_scheduled == false);
894 
895 				if (bdev && bdev->blockcnt < min_blockcnt) {
896 					min_blockcnt = bdev->blockcnt;
897 				}
898 			}
899 			CU_ASSERT((((min_blockcnt / (r->strip_size_kb * 1024 / g_block_len)) *
900 				    (r->strip_size_kb * 1024 / g_block_len)) *
901 				   r->base_bdevs.num_base_bdevs) == pbdev->bdev.blockcnt);
902 			CU_ASSERT(strcmp(pbdev->bdev.product_name, "Raid Volume") == 0);
903 			CU_ASSERT(pbdev->bdev.write_cache == 0);
904 			CU_ASSERT(pbdev->bdev.blocklen == g_block_len);
905 			if (pbdev->num_base_bdevs > 1) {
906 				CU_ASSERT(pbdev->bdev.optimal_io_boundary == pbdev->strip_size);
907 				CU_ASSERT(pbdev->bdev.split_on_optimal_io_boundary == true);
908 			} else {
909 				CU_ASSERT(pbdev->bdev.optimal_io_boundary == 0);
910 				CU_ASSERT(pbdev->bdev.split_on_optimal_io_boundary == false);
911 			}
912 			CU_ASSERT(pbdev->bdev.ctxt == pbdev);
913 			CU_ASSERT(pbdev->bdev.fn_table == &g_raid_bdev_fn_table);
914 			CU_ASSERT(pbdev->bdev.module == &g_raid_if);
915 			break;
916 		}
917 	}
918 	if (presence == true) {
919 		CU_ASSERT(pbdev_found == true);
920 	} else {
921 		CU_ASSERT(pbdev_found == false);
922 	}
923 	pbdev_found = false;
924 	if (raid_state == RAID_BDEV_STATE_ONLINE) {
925 		TAILQ_FOREACH(pbdev, &g_raid_bdev_configured_list, state_link) {
926 			if (strcmp(pbdev->bdev.name, r->name) == 0) {
927 				pbdev_found = true;
928 				break;
929 			}
930 		}
931 	} else if (raid_state == RAID_BDEV_STATE_CONFIGURING) {
932 		TAILQ_FOREACH(pbdev, &g_raid_bdev_configuring_list, state_link) {
933 			if (strcmp(pbdev->bdev.name, r->name) == 0) {
934 				pbdev_found = true;
935 				break;
936 			}
937 		}
938 	} else if (raid_state == RAID_BDEV_STATE_OFFLINE) {
939 		TAILQ_FOREACH(pbdev, &g_raid_bdev_offline_list, state_link) {
940 			if (strcmp(pbdev->bdev.name, r->name) == 0) {
941 				pbdev_found = true;
942 				break;
943 			}
944 		}
945 	}
946 	if (presence == true) {
947 		CU_ASSERT(pbdev_found == true);
948 	} else {
949 		CU_ASSERT(pbdev_found == false);
950 	}
951 }
952 
953 static void
954 verify_get_raids(struct rpc_bdev_raid_create *construct_req,
955 		 uint8_t g_max_raids,
956 		 char **g_get_raids_output, uint32_t g_get_raids_count)
957 {
958 	uint8_t i, j;
959 	bool found;
960 
961 	CU_ASSERT(g_max_raids == g_get_raids_count);
962 	if (g_max_raids == g_get_raids_count) {
963 		for (i = 0; i < g_max_raids; i++) {
964 			found = false;
965 			for (j = 0; j < g_max_raids; j++) {
966 				if (construct_req[i].name &&
967 				    strcmp(construct_req[i].name, g_get_raids_output[i]) == 0) {
968 					found = true;
969 					break;
970 				}
971 			}
972 			CU_ASSERT(found == true);
973 		}
974 	}
975 }
976 
977 static void
978 create_base_bdevs(uint32_t bbdev_start_idx)
979 {
980 	uint8_t i;
981 	struct spdk_bdev *base_bdev;
982 	char name[16];
983 
984 	for (i = 0; i < g_max_base_drives; i++, bbdev_start_idx++) {
985 		snprintf(name, 16, "%s%u%s", "Nvme", bbdev_start_idx, "n1");
986 		base_bdev = calloc(1, sizeof(struct spdk_bdev));
987 		SPDK_CU_ASSERT_FATAL(base_bdev != NULL);
988 		base_bdev->name = strdup(name);
989 		SPDK_CU_ASSERT_FATAL(base_bdev->name != NULL);
990 		base_bdev->blocklen = g_block_len;
991 		base_bdev->blockcnt = BLOCK_CNT;
992 		TAILQ_INSERT_TAIL(&g_bdev_list, base_bdev, internal.link);
993 	}
994 }
995 
996 static void
997 create_test_req(struct rpc_bdev_raid_create *r, const char *raid_name,
998 		uint8_t bbdev_start_idx, bool create_base_bdev)
999 {
1000 	uint8_t i;
1001 	char name[16];
1002 	uint8_t bbdev_idx = bbdev_start_idx;
1003 
1004 	r->name = strdup(raid_name);
1005 	SPDK_CU_ASSERT_FATAL(r->name != NULL);
1006 	r->strip_size_kb = (g_strip_size * g_block_len) / 1024;
1007 	r->level = RAID0;
1008 	r->base_bdevs.num_base_bdevs = g_max_base_drives;
1009 	for (i = 0; i < g_max_base_drives; i++, bbdev_idx++) {
1010 		snprintf(name, 16, "%s%u%s", "Nvme", bbdev_idx, "n1");
1011 		r->base_bdevs.base_bdevs[i] = strdup(name);
1012 		SPDK_CU_ASSERT_FATAL(r->base_bdevs.base_bdevs[i] != NULL);
1013 	}
1014 	if (create_base_bdev == true) {
1015 		create_base_bdevs(bbdev_start_idx);
1016 	}
1017 	g_rpc_req = r;
1018 	g_rpc_req_size = sizeof(*r);
1019 }
1020 
1021 static void
1022 create_raid_bdev_create_req(struct rpc_bdev_raid_create *r, const char *raid_name,
1023 			    uint8_t bbdev_start_idx, bool create_base_bdev,
1024 			    uint8_t json_decode_obj_err)
1025 {
1026 	create_test_req(r, raid_name, bbdev_start_idx, create_base_bdev);
1027 
1028 	g_rpc_err = 0;
1029 	g_json_decode_obj_create = 1;
1030 	g_json_decode_obj_err = json_decode_obj_err;
1031 	g_config_level_create = 0;
1032 	g_test_multi_raids = 0;
1033 }
1034 
1035 static void
1036 free_test_req(struct rpc_bdev_raid_create *r)
1037 {
1038 	uint8_t i;
1039 
1040 	free(r->name);
1041 	for (i = 0; i < r->base_bdevs.num_base_bdevs; i++) {
1042 		free(r->base_bdevs.base_bdevs[i]);
1043 	}
1044 }
1045 
1046 static void
1047 create_raid_bdev_delete_req(struct rpc_bdev_raid_delete *r, const char *raid_name,
1048 			    uint8_t json_decode_obj_err)
1049 {
1050 	r->name = strdup(raid_name);
1051 	SPDK_CU_ASSERT_FATAL(r->name != NULL);
1052 
1053 	g_rpc_req = r;
1054 	g_rpc_req_size = sizeof(*r);
1055 	g_rpc_err = 0;
1056 	g_json_decode_obj_create = 0;
1057 	g_json_decode_obj_err = json_decode_obj_err;
1058 	g_config_level_create = 0;
1059 	g_test_multi_raids = 0;
1060 }
1061 
1062 static void
1063 create_get_raids_req(struct rpc_bdev_raid_get_bdevs *r, const char *category,
1064 		     uint8_t json_decode_obj_err)
1065 {
1066 	r->category = strdup(category);
1067 	SPDK_CU_ASSERT_FATAL(r->category != NULL);
1068 
1069 	g_rpc_req = r;
1070 	g_rpc_req_size = sizeof(*r);
1071 	g_rpc_err = 0;
1072 	g_json_decode_obj_create = 0;
1073 	g_json_decode_obj_err = json_decode_obj_err;
1074 	g_config_level_create = 0;
1075 	g_test_multi_raids = 1;
1076 	g_get_raids_count = 0;
1077 }
1078 
1079 static void
1080 test_create_raid(void)
1081 {
1082 	struct rpc_bdev_raid_create req;
1083 	struct rpc_bdev_raid_delete delete_req;
1084 
1085 	set_globals();
1086 	CU_ASSERT(raid_bdev_init() == 0);
1087 
1088 	verify_raid_config_present("raid1", false);
1089 	verify_raid_bdev_present("raid1", false);
1090 	create_raid_bdev_create_req(&req, "raid1", 0, true, 0);
1091 	rpc_bdev_raid_create(NULL, NULL);
1092 	CU_ASSERT(g_rpc_err == 0);
1093 	verify_raid_config(&req, true);
1094 	verify_raid_bdev(&req, true, RAID_BDEV_STATE_ONLINE);
1095 	free_test_req(&req);
1096 
1097 	create_raid_bdev_delete_req(&delete_req, "raid1", 0);
1098 	rpc_bdev_raid_delete(NULL, NULL);
1099 	CU_ASSERT(g_rpc_err == 0);
1100 	raid_bdev_exit();
1101 	base_bdevs_cleanup();
1102 	reset_globals();
1103 }
1104 
1105 static void
1106 test_delete_raid(void)
1107 {
1108 	struct rpc_bdev_raid_create construct_req;
1109 	struct rpc_bdev_raid_delete delete_req;
1110 
1111 	set_globals();
1112 	CU_ASSERT(raid_bdev_init() == 0);
1113 
1114 	verify_raid_config_present("raid1", false);
1115 	verify_raid_bdev_present("raid1", false);
1116 	create_raid_bdev_create_req(&construct_req, "raid1", 0, true, 0);
1117 	rpc_bdev_raid_create(NULL, NULL);
1118 	CU_ASSERT(g_rpc_err == 0);
1119 	verify_raid_config(&construct_req, true);
1120 	verify_raid_bdev(&construct_req, true, RAID_BDEV_STATE_ONLINE);
1121 	free_test_req(&construct_req);
1122 
1123 	create_raid_bdev_delete_req(&delete_req, "raid1", 0);
1124 	rpc_bdev_raid_delete(NULL, NULL);
1125 	CU_ASSERT(g_rpc_err == 0);
1126 	verify_raid_config_present("raid1", false);
1127 	verify_raid_bdev_present("raid1", false);
1128 
1129 	raid_bdev_exit();
1130 	base_bdevs_cleanup();
1131 	reset_globals();
1132 }
1133 
1134 static void
1135 test_create_raid_invalid_args(void)
1136 {
1137 	struct rpc_bdev_raid_create req;
1138 	struct rpc_bdev_raid_delete destroy_req;
1139 	struct raid_bdev_config *raid_cfg;
1140 
1141 	set_globals();
1142 	CU_ASSERT(raid_bdev_init() == 0);
1143 
1144 	verify_raid_config_present("raid1", false);
1145 	verify_raid_bdev_present("raid1", false);
1146 	create_raid_bdev_create_req(&req, "raid1", 0, true, 0);
1147 	req.level = INVALID_RAID_LEVEL;
1148 	rpc_bdev_raid_create(NULL, NULL);
1149 	CU_ASSERT(g_rpc_err == 1);
1150 	free_test_req(&req);
1151 	verify_raid_config_present("raid1", false);
1152 	verify_raid_bdev_present("raid1", false);
1153 
1154 	create_raid_bdev_create_req(&req, "raid1", 0, false, 1);
1155 	rpc_bdev_raid_create(NULL, NULL);
1156 	CU_ASSERT(g_rpc_err == 1);
1157 	free_test_req(&req);
1158 	verify_raid_config_present("raid1", false);
1159 	verify_raid_bdev_present("raid1", false);
1160 
1161 	create_raid_bdev_create_req(&req, "raid1", 0, false, 0);
1162 	req.strip_size_kb = 1231;
1163 	rpc_bdev_raid_create(NULL, NULL);
1164 	CU_ASSERT(g_rpc_err == 1);
1165 	free_test_req(&req);
1166 	verify_raid_config_present("raid1", false);
1167 	verify_raid_bdev_present("raid1", false);
1168 
1169 	create_raid_bdev_create_req(&req, "raid1", 0, false, 0);
1170 	rpc_bdev_raid_create(NULL, NULL);
1171 	CU_ASSERT(g_rpc_err == 0);
1172 	verify_raid_config(&req, true);
1173 	verify_raid_bdev(&req, true, RAID_BDEV_STATE_ONLINE);
1174 	free_test_req(&req);
1175 
1176 	create_raid_bdev_create_req(&req, "raid1", 0, false, 0);
1177 	rpc_bdev_raid_create(NULL, NULL);
1178 	CU_ASSERT(g_rpc_err == 1);
1179 	free_test_req(&req);
1180 
1181 	create_raid_bdev_create_req(&req, "raid2", 0, false, 0);
1182 	rpc_bdev_raid_create(NULL, NULL);
1183 	CU_ASSERT(g_rpc_err == 1);
1184 	free_test_req(&req);
1185 	verify_raid_config_present("raid2", false);
1186 	verify_raid_bdev_present("raid2", false);
1187 
1188 	create_raid_bdev_create_req(&req, "raid2", g_max_base_drives, true, 0);
1189 	free(req.base_bdevs.base_bdevs[g_max_base_drives - 1]);
1190 	req.base_bdevs.base_bdevs[g_max_base_drives - 1] = strdup("Nvme0n1");
1191 	SPDK_CU_ASSERT_FATAL(req.base_bdevs.base_bdevs[g_max_base_drives - 1] != NULL);
1192 	rpc_bdev_raid_create(NULL, NULL);
1193 	CU_ASSERT(g_rpc_err == 1);
1194 	free_test_req(&req);
1195 	verify_raid_config_present("raid2", false);
1196 	verify_raid_bdev_present("raid2", false);
1197 
1198 	create_raid_bdev_create_req(&req, "raid2", g_max_base_drives, true, 0);
1199 	free(req.base_bdevs.base_bdevs[g_max_base_drives - 1]);
1200 	req.base_bdevs.base_bdevs[g_max_base_drives - 1] = strdup("Nvme100000n1");
1201 	SPDK_CU_ASSERT_FATAL(req.base_bdevs.base_bdevs[g_max_base_drives - 1] != NULL);
1202 	rpc_bdev_raid_create(NULL, NULL);
1203 	CU_ASSERT(g_rpc_err == 0);
1204 	free_test_req(&req);
1205 	verify_raid_config_present("raid2", true);
1206 	verify_raid_bdev_present("raid2", true);
1207 	raid_cfg = raid_bdev_config_find_by_name("raid2");
1208 	SPDK_CU_ASSERT_FATAL(raid_cfg != NULL);
1209 	check_and_remove_raid_bdev(raid_cfg);
1210 	raid_bdev_config_cleanup(raid_cfg);
1211 
1212 	create_raid_bdev_create_req(&req, "raid2", g_max_base_drives, false, 0);
1213 	rpc_bdev_raid_create(NULL, NULL);
1214 	CU_ASSERT(g_rpc_err == 0);
1215 	free_test_req(&req);
1216 	verify_raid_config_present("raid2", true);
1217 	verify_raid_bdev_present("raid2", true);
1218 	verify_raid_config_present("raid1", true);
1219 	verify_raid_bdev_present("raid1", true);
1220 
1221 	create_raid_bdev_delete_req(&destroy_req, "raid1", 0);
1222 	rpc_bdev_raid_delete(NULL, NULL);
1223 	create_raid_bdev_delete_req(&destroy_req, "raid2", 0);
1224 	rpc_bdev_raid_delete(NULL, NULL);
1225 	raid_bdev_exit();
1226 	base_bdevs_cleanup();
1227 	reset_globals();
1228 }
1229 
1230 static void
1231 test_delete_raid_invalid_args(void)
1232 {
1233 	struct rpc_bdev_raid_create construct_req;
1234 	struct rpc_bdev_raid_delete destroy_req;
1235 
1236 	set_globals();
1237 	CU_ASSERT(raid_bdev_init() == 0);
1238 
1239 	verify_raid_config_present("raid1", false);
1240 	verify_raid_bdev_present("raid1", false);
1241 	create_raid_bdev_create_req(&construct_req, "raid1", 0, true, 0);
1242 	rpc_bdev_raid_create(NULL, NULL);
1243 	CU_ASSERT(g_rpc_err == 0);
1244 	verify_raid_config(&construct_req, true);
1245 	verify_raid_bdev(&construct_req, true, RAID_BDEV_STATE_ONLINE);
1246 	free_test_req(&construct_req);
1247 
1248 	create_raid_bdev_delete_req(&destroy_req, "raid2", 0);
1249 	rpc_bdev_raid_delete(NULL, NULL);
1250 	CU_ASSERT(g_rpc_err == 1);
1251 
1252 	create_raid_bdev_delete_req(&destroy_req, "raid1", 1);
1253 	rpc_bdev_raid_delete(NULL, NULL);
1254 	CU_ASSERT(g_rpc_err == 1);
1255 	free(destroy_req.name);
1256 	verify_raid_config_present("raid1", true);
1257 	verify_raid_bdev_present("raid1", true);
1258 
1259 	create_raid_bdev_delete_req(&destroy_req, "raid1", 0);
1260 	rpc_bdev_raid_delete(NULL, NULL);
1261 	CU_ASSERT(g_rpc_err == 0);
1262 	verify_raid_config_present("raid1", false);
1263 	verify_raid_bdev_present("raid1", false);
1264 
1265 	raid_bdev_exit();
1266 	base_bdevs_cleanup();
1267 	reset_globals();
1268 }
1269 
1270 static void
1271 test_io_channel(void)
1272 {
1273 	struct rpc_bdev_raid_create req;
1274 	struct rpc_bdev_raid_delete destroy_req;
1275 	struct raid_bdev *pbdev;
1276 	struct raid_bdev_io_channel *ch_ctx;
1277 	uint8_t i;
1278 
1279 	set_globals();
1280 	CU_ASSERT(raid_bdev_init() == 0);
1281 
1282 	create_raid_bdev_create_req(&req, "raid1", 0, true, 0);
1283 	verify_raid_config_present("raid1", false);
1284 	verify_raid_bdev_present("raid1", false);
1285 	rpc_bdev_raid_create(NULL, NULL);
1286 	CU_ASSERT(g_rpc_err == 0);
1287 	verify_raid_config(&req, true);
1288 	verify_raid_bdev(&req, true, RAID_BDEV_STATE_ONLINE);
1289 
1290 	TAILQ_FOREACH(pbdev, &g_raid_bdev_list, global_link) {
1291 		if (strcmp(pbdev->bdev.name, "raid1") == 0) {
1292 			break;
1293 		}
1294 	}
1295 	CU_ASSERT(pbdev != NULL);
1296 	ch_ctx = calloc(1, sizeof(struct raid_bdev_io_channel));
1297 	SPDK_CU_ASSERT_FATAL(ch_ctx != NULL);
1298 
1299 	CU_ASSERT(raid_bdev_create_cb(pbdev, ch_ctx) == 0);
1300 	for (i = 0; i < req.base_bdevs.num_base_bdevs; i++) {
1301 		CU_ASSERT(ch_ctx->base_channel && ch_ctx->base_channel[i] == &g_io_channel);
1302 	}
1303 	raid_bdev_destroy_cb(pbdev, ch_ctx);
1304 	CU_ASSERT(ch_ctx->base_channel == NULL);
1305 	free_test_req(&req);
1306 
1307 	create_raid_bdev_delete_req(&destroy_req, "raid1", 0);
1308 	rpc_bdev_raid_delete(NULL, NULL);
1309 	CU_ASSERT(g_rpc_err == 0);
1310 	verify_raid_config_present("raid1", false);
1311 	verify_raid_bdev_present("raid1", false);
1312 
1313 	free(ch_ctx);
1314 	raid_bdev_exit();
1315 	base_bdevs_cleanup();
1316 	reset_globals();
1317 }
1318 
1319 static void
1320 test_write_io(void)
1321 {
1322 	struct rpc_bdev_raid_create req;
1323 	struct rpc_bdev_raid_delete destroy_req;
1324 	struct raid_bdev *pbdev;
1325 	struct spdk_io_channel *ch;
1326 	struct raid_bdev_io_channel *ch_ctx;
1327 	uint8_t i;
1328 	struct spdk_bdev_io *bdev_io;
1329 	uint64_t io_len;
1330 	uint64_t lba = 0;
1331 	struct spdk_io_channel *ch_b;
1332 	struct spdk_bdev_channel *ch_b_ctx;
1333 
1334 	set_globals();
1335 	CU_ASSERT(raid_bdev_init() == 0);
1336 
1337 	create_raid_bdev_create_req(&req, "raid1", 0, true, 0);
1338 	verify_raid_config_present("raid1", false);
1339 	verify_raid_bdev_present("raid1", false);
1340 	rpc_bdev_raid_create(NULL, NULL);
1341 	CU_ASSERT(g_rpc_err == 0);
1342 	verify_raid_config(&req, true);
1343 	verify_raid_bdev(&req, true, RAID_BDEV_STATE_ONLINE);
1344 	TAILQ_FOREACH(pbdev, &g_raid_bdev_list, global_link) {
1345 		if (strcmp(pbdev->bdev.name, "raid1") == 0) {
1346 			break;
1347 		}
1348 	}
1349 	CU_ASSERT(pbdev != NULL);
1350 	ch = calloc(1, sizeof(struct spdk_io_channel) + sizeof(struct raid_bdev_io_channel));
1351 	SPDK_CU_ASSERT_FATAL(ch != NULL);
1352 
1353 	ch_b = calloc(1, sizeof(struct spdk_io_channel) + sizeof(struct spdk_bdev_channel));
1354 	SPDK_CU_ASSERT_FATAL(ch_b != NULL);
1355 	ch_b_ctx = spdk_io_channel_get_ctx(ch_b);
1356 	ch_b_ctx->channel = ch;
1357 
1358 	ch_ctx = spdk_io_channel_get_ctx(ch);
1359 	SPDK_CU_ASSERT_FATAL(ch_ctx != NULL);
1360 
1361 	CU_ASSERT(raid_bdev_create_cb(pbdev, ch_ctx) == 0);
1362 	for (i = 0; i < req.base_bdevs.num_base_bdevs; i++) {
1363 		CU_ASSERT(ch_ctx->base_channel && ch_ctx->base_channel[i] == &g_io_channel);
1364 	}
1365 
1366 	/* test 2 IO sizes based on global strip size set earlier */
1367 	for (i = 0; i < 2; i++) {
1368 		bdev_io = calloc(1, sizeof(struct spdk_bdev_io) + sizeof(struct raid_bdev_io));
1369 		SPDK_CU_ASSERT_FATAL(bdev_io != NULL);
1370 		io_len = (g_strip_size / 2) << i;
1371 		bdev_io_initialize(bdev_io, ch_b, &pbdev->bdev, lba, io_len, SPDK_BDEV_IO_TYPE_WRITE);
1372 		lba += g_strip_size;
1373 		memset(g_io_output, 0, ((g_max_io_size / g_strip_size) + 1) * sizeof(struct io_output));
1374 		g_io_output_index = 0;
1375 		raid_bdev_submit_request(ch, bdev_io);
1376 		verify_io(bdev_io, req.base_bdevs.num_base_bdevs, ch_ctx, pbdev,
1377 			  g_child_io_status_flag);
1378 		bdev_io_cleanup(bdev_io);
1379 	}
1380 
1381 	free_test_req(&req);
1382 	raid_bdev_destroy_cb(pbdev, ch_ctx);
1383 	CU_ASSERT(ch_ctx->base_channel == NULL);
1384 	free(ch);
1385 	free(ch_b);
1386 	create_raid_bdev_delete_req(&destroy_req, "raid1", 0);
1387 	rpc_bdev_raid_delete(NULL, NULL);
1388 	CU_ASSERT(g_rpc_err == 0);
1389 	verify_raid_config_present("raid1", false);
1390 	verify_raid_bdev_present("raid1", false);
1391 
1392 	raid_bdev_exit();
1393 	base_bdevs_cleanup();
1394 	reset_globals();
1395 }
1396 
1397 static void
1398 test_read_io(void)
1399 {
1400 	struct rpc_bdev_raid_create req;
1401 	struct rpc_bdev_raid_delete destroy_req;
1402 	struct raid_bdev *pbdev;
1403 	struct spdk_io_channel *ch;
1404 	struct raid_bdev_io_channel *ch_ctx;
1405 	uint8_t i;
1406 	struct spdk_bdev_io *bdev_io;
1407 	uint64_t io_len;
1408 	uint64_t lba;
1409 	struct spdk_io_channel *ch_b;
1410 	struct spdk_bdev_channel *ch_b_ctx;
1411 
1412 	set_globals();
1413 	CU_ASSERT(raid_bdev_init() == 0);
1414 
1415 	verify_raid_config_present("raid1", false);
1416 	verify_raid_bdev_present("raid1", false);
1417 	create_raid_bdev_create_req(&req, "raid1", 0, true, 0);
1418 	rpc_bdev_raid_create(NULL, NULL);
1419 	CU_ASSERT(g_rpc_err == 0);
1420 	verify_raid_config(&req, true);
1421 	verify_raid_bdev(&req, true, RAID_BDEV_STATE_ONLINE);
1422 	TAILQ_FOREACH(pbdev, &g_raid_bdev_list, global_link) {
1423 		if (strcmp(pbdev->bdev.name, "raid1") == 0) {
1424 			break;
1425 		}
1426 	}
1427 	CU_ASSERT(pbdev != NULL);
1428 	ch = calloc(1, sizeof(struct spdk_io_channel) + sizeof(struct raid_bdev_io_channel));
1429 	SPDK_CU_ASSERT_FATAL(ch != NULL);
1430 
1431 	ch_b = calloc(1, sizeof(struct spdk_io_channel) + sizeof(struct spdk_bdev_channel));
1432 	SPDK_CU_ASSERT_FATAL(ch_b != NULL);
1433 	ch_b_ctx = spdk_io_channel_get_ctx(ch_b);
1434 	ch_b_ctx->channel = ch;
1435 
1436 	ch_ctx = spdk_io_channel_get_ctx(ch);
1437 	SPDK_CU_ASSERT_FATAL(ch_ctx != NULL);
1438 
1439 	CU_ASSERT(raid_bdev_create_cb(pbdev, ch_ctx) == 0);
1440 	for (i = 0; i < req.base_bdevs.num_base_bdevs; i++) {
1441 		CU_ASSERT(ch_ctx->base_channel && ch_ctx->base_channel[i] == &g_io_channel);
1442 	}
1443 	free_test_req(&req);
1444 
1445 	/* test 2 IO sizes based on global strip size set earlier */
1446 	lba = 0;
1447 	for (i = 0; i < 2; i++) {
1448 		bdev_io = calloc(1, sizeof(struct spdk_bdev_io) + sizeof(struct raid_bdev_io));
1449 		SPDK_CU_ASSERT_FATAL(bdev_io != NULL);
1450 		io_len = (g_strip_size / 2) << i;
1451 		bdev_io_initialize(bdev_io, ch_b, &pbdev->bdev, lba, io_len, SPDK_BDEV_IO_TYPE_READ);
1452 		lba += g_strip_size;
1453 		memset(g_io_output, 0, ((g_max_io_size / g_strip_size) + 1) * sizeof(struct io_output));
1454 		g_io_output_index = 0;
1455 		raid_bdev_submit_request(ch, bdev_io);
1456 		verify_io(bdev_io, req.base_bdevs.num_base_bdevs, ch_ctx, pbdev,
1457 			  g_child_io_status_flag);
1458 		bdev_io_cleanup(bdev_io);
1459 	}
1460 
1461 	raid_bdev_destroy_cb(pbdev, ch_ctx);
1462 	CU_ASSERT(ch_ctx->base_channel == NULL);
1463 	free(ch);
1464 	free(ch_b);
1465 	create_raid_bdev_delete_req(&destroy_req, "raid1", 0);
1466 	rpc_bdev_raid_delete(NULL, NULL);
1467 	CU_ASSERT(g_rpc_err == 0);
1468 	verify_raid_config_present("raid1", false);
1469 	verify_raid_bdev_present("raid1", false);
1470 
1471 	raid_bdev_exit();
1472 	base_bdevs_cleanup();
1473 	reset_globals();
1474 }
1475 
1476 static void
1477 raid_bdev_io_generate_by_strips(uint64_t n_strips)
1478 {
1479 	uint64_t lba;
1480 	uint64_t nblocks;
1481 	uint64_t start_offset;
1482 	uint64_t end_offset;
1483 	uint64_t offsets_in_strip[3];
1484 	uint64_t start_bdev_idx;
1485 	uint64_t start_bdev_offset;
1486 	uint64_t start_bdev_idxs[3];
1487 	int i, j, l;
1488 
1489 	/* 3 different situations of offset in strip */
1490 	offsets_in_strip[0] = 0;
1491 	offsets_in_strip[1] = g_strip_size >> 1;
1492 	offsets_in_strip[2] = g_strip_size - 1;
1493 
1494 	/* 3 different situations of start_bdev_idx */
1495 	start_bdev_idxs[0] = 0;
1496 	start_bdev_idxs[1] = g_max_base_drives >> 1;
1497 	start_bdev_idxs[2] = g_max_base_drives - 1;
1498 
1499 	/* consider different offset in strip */
1500 	for (i = 0; i < 3; i++) {
1501 		start_offset = offsets_in_strip[i];
1502 		for (j = 0; j < 3; j++) {
1503 			end_offset = offsets_in_strip[j];
1504 			if (n_strips == 1 && start_offset > end_offset) {
1505 				continue;
1506 			}
1507 
1508 			/* consider at which base_bdev lba is started. */
1509 			for (l = 0; l < 3; l++) {
1510 				start_bdev_idx = start_bdev_idxs[l];
1511 				start_bdev_offset = start_bdev_idx * g_strip_size;
1512 				lba = g_lba_offset + start_bdev_offset + start_offset;
1513 				nblocks = (n_strips - 1) * g_strip_size + end_offset - start_offset + 1;
1514 
1515 				g_io_ranges[g_io_range_idx].lba = lba;
1516 				g_io_ranges[g_io_range_idx].nblocks = nblocks;
1517 
1518 				SPDK_CU_ASSERT_FATAL(g_io_range_idx < MAX_TEST_IO_RANGE);
1519 				g_io_range_idx++;
1520 			}
1521 		}
1522 	}
1523 }
1524 
1525 static void
1526 raid_bdev_io_generate(void)
1527 {
1528 	uint64_t n_strips;
1529 	uint64_t n_strips_span = g_max_base_drives;
1530 	uint64_t n_strips_times[5] = {g_max_base_drives + 1, g_max_base_drives * 2 - 1,
1531 				      g_max_base_drives * 2, g_max_base_drives * 3,
1532 				      g_max_base_drives * 4
1533 				     };
1534 	uint32_t i;
1535 
1536 	g_io_range_idx = 0;
1537 
1538 	/* consider different number of strips from 1 to strips spanned base bdevs,
1539 	 * and even to times of strips spanned base bdevs
1540 	 */
1541 	for (n_strips = 1; n_strips < n_strips_span; n_strips++) {
1542 		raid_bdev_io_generate_by_strips(n_strips);
1543 	}
1544 
1545 	for (i = 0; i < SPDK_COUNTOF(n_strips_times); i++) {
1546 		n_strips = n_strips_times[i];
1547 		raid_bdev_io_generate_by_strips(n_strips);
1548 	}
1549 }
1550 
1551 static void
1552 test_unmap_io(void)
1553 {
1554 	struct rpc_bdev_raid_create req;
1555 	struct rpc_bdev_raid_delete destroy_req;
1556 	struct raid_bdev *pbdev;
1557 	struct spdk_io_channel *ch;
1558 	struct raid_bdev_io_channel *ch_ctx;
1559 	uint8_t i;
1560 	struct spdk_bdev_io *bdev_io;
1561 	uint32_t count;
1562 	uint64_t io_len;
1563 	uint64_t lba;
1564 
1565 	set_globals();
1566 	CU_ASSERT(raid_bdev_init() == 0);
1567 
1568 	verify_raid_config_present("raid1", false);
1569 	verify_raid_bdev_present("raid1", false);
1570 	create_raid_bdev_create_req(&req, "raid1", 0, true, 0);
1571 	rpc_bdev_raid_create(NULL, NULL);
1572 	CU_ASSERT(g_rpc_err == 0);
1573 	verify_raid_config(&req, true);
1574 	verify_raid_bdev(&req, true, RAID_BDEV_STATE_ONLINE);
1575 	TAILQ_FOREACH(pbdev, &g_raid_bdev_list, global_link) {
1576 		if (strcmp(pbdev->bdev.name, "raid1") == 0) {
1577 			break;
1578 		}
1579 	}
1580 	CU_ASSERT(pbdev != NULL);
1581 	ch = calloc(1, sizeof(struct spdk_io_channel) + sizeof(struct raid_bdev_io_channel));
1582 	SPDK_CU_ASSERT_FATAL(ch != NULL);
1583 	ch_ctx = spdk_io_channel_get_ctx(ch);
1584 	SPDK_CU_ASSERT_FATAL(ch_ctx != NULL);
1585 
1586 	CU_ASSERT(raid_bdev_create_cb(pbdev, ch_ctx) == 0);
1587 	for (i = 0; i < req.base_bdevs.num_base_bdevs; i++) {
1588 		SPDK_CU_ASSERT_FATAL(ch_ctx->base_channel && ch_ctx->base_channel[i] == &g_io_channel);
1589 	}
1590 
1591 	CU_ASSERT(raid_bdev_io_type_supported(pbdev, SPDK_BDEV_IO_TYPE_UNMAP) == true);
1592 	CU_ASSERT(raid_bdev_io_type_supported(pbdev, SPDK_BDEV_IO_TYPE_FLUSH) == true);
1593 
1594 	raid_bdev_io_generate();
1595 	for (count = 0; count < g_io_range_idx; count++) {
1596 		bdev_io = calloc(1, sizeof(struct spdk_bdev_io) + sizeof(struct raid_bdev_io));
1597 		SPDK_CU_ASSERT_FATAL(bdev_io != NULL);
1598 		io_len = g_io_ranges[count].nblocks;
1599 		lba = g_io_ranges[count].lba;
1600 		bdev_io_initialize(bdev_io, ch, &pbdev->bdev, lba, io_len, SPDK_BDEV_IO_TYPE_UNMAP);
1601 		memset(g_io_output, 0, g_max_base_drives * sizeof(struct io_output));
1602 		g_io_output_index = 0;
1603 		raid_bdev_submit_request(ch, bdev_io);
1604 		verify_io_without_payload(bdev_io, req.base_bdevs.num_base_bdevs, ch_ctx, pbdev,
1605 					  g_child_io_status_flag);
1606 		bdev_io_cleanup(bdev_io);
1607 	}
1608 	free_test_req(&req);
1609 
1610 	raid_bdev_destroy_cb(pbdev, ch_ctx);
1611 	CU_ASSERT(ch_ctx->base_channel == NULL);
1612 	free(ch);
1613 	create_raid_bdev_delete_req(&destroy_req, "raid1", 0);
1614 	rpc_bdev_raid_delete(NULL, NULL);
1615 	CU_ASSERT(g_rpc_err == 0);
1616 	verify_raid_config_present("raid1", false);
1617 	verify_raid_bdev_present("raid1", false);
1618 
1619 	raid_bdev_exit();
1620 	base_bdevs_cleanup();
1621 	reset_globals();
1622 }
1623 
1624 /* Test IO failures */
1625 static void
1626 test_io_failure(void)
1627 {
1628 	struct rpc_bdev_raid_create req;
1629 	struct rpc_bdev_raid_delete destroy_req;
1630 	struct raid_bdev *pbdev;
1631 	struct spdk_io_channel *ch;
1632 	struct raid_bdev_io_channel *ch_ctx;
1633 	uint8_t i;
1634 	struct spdk_bdev_io *bdev_io;
1635 	uint32_t count;
1636 	uint64_t io_len;
1637 	uint64_t lba;
1638 
1639 	set_globals();
1640 	CU_ASSERT(raid_bdev_init() == 0);
1641 
1642 	verify_raid_config_present("raid1", false);
1643 	verify_raid_bdev_present("raid1", false);
1644 	create_raid_bdev_create_req(&req, "raid1", 0, true, 0);
1645 	rpc_bdev_raid_create(NULL, NULL);
1646 	CU_ASSERT(g_rpc_err == 0);
1647 	verify_raid_config(&req, true);
1648 	verify_raid_bdev(&req, true, RAID_BDEV_STATE_ONLINE);
1649 	TAILQ_FOREACH(pbdev, &g_raid_bdev_list, global_link) {
1650 		if (strcmp(pbdev->bdev.name, req.name) == 0) {
1651 			break;
1652 		}
1653 	}
1654 	CU_ASSERT(pbdev != NULL);
1655 	ch = calloc(1, sizeof(struct spdk_io_channel) + sizeof(struct raid_bdev_io_channel));
1656 	SPDK_CU_ASSERT_FATAL(ch != NULL);
1657 	ch_ctx = spdk_io_channel_get_ctx(ch);
1658 	SPDK_CU_ASSERT_FATAL(ch_ctx != NULL);
1659 
1660 	CU_ASSERT(raid_bdev_create_cb(pbdev, ch_ctx) == 0);
1661 	for (i = 0; i < req.base_bdevs.num_base_bdevs; i++) {
1662 		CU_ASSERT(ch_ctx->base_channel && ch_ctx->base_channel[i] == &g_io_channel);
1663 	}
1664 	free_test_req(&req);
1665 
1666 	lba = 0;
1667 	for (count = 0; count < 1; count++) {
1668 		bdev_io = calloc(1, sizeof(struct spdk_bdev_io) + sizeof(struct raid_bdev_io));
1669 		SPDK_CU_ASSERT_FATAL(bdev_io != NULL);
1670 		io_len = (g_strip_size / 2) << count;
1671 		bdev_io_initialize(bdev_io, ch, &pbdev->bdev, lba, io_len, SPDK_BDEV_IO_TYPE_INVALID);
1672 		lba += g_strip_size;
1673 		memset(g_io_output, 0, ((g_max_io_size / g_strip_size) + 1) * sizeof(struct io_output));
1674 		g_io_output_index = 0;
1675 		raid_bdev_submit_request(ch, bdev_io);
1676 		verify_io(bdev_io, req.base_bdevs.num_base_bdevs, ch_ctx, pbdev,
1677 			  INVALID_IO_SUBMIT);
1678 		bdev_io_cleanup(bdev_io);
1679 	}
1680 
1681 
1682 	lba = 0;
1683 	g_child_io_status_flag = false;
1684 	for (count = 0; count < 1; count++) {
1685 		bdev_io = calloc(1, sizeof(struct spdk_bdev_io) + sizeof(struct raid_bdev_io));
1686 		SPDK_CU_ASSERT_FATAL(bdev_io != NULL);
1687 		io_len = (g_strip_size / 2) << count;
1688 		bdev_io_initialize(bdev_io, ch, &pbdev->bdev, lba, io_len, SPDK_BDEV_IO_TYPE_WRITE);
1689 		lba += g_strip_size;
1690 		memset(g_io_output, 0, ((g_max_io_size / g_strip_size) + 1) * sizeof(struct io_output));
1691 		g_io_output_index = 0;
1692 		raid_bdev_submit_request(ch, bdev_io);
1693 		verify_io(bdev_io, req.base_bdevs.num_base_bdevs, ch_ctx, pbdev,
1694 			  g_child_io_status_flag);
1695 		bdev_io_cleanup(bdev_io);
1696 	}
1697 
1698 	raid_bdev_destroy_cb(pbdev, ch_ctx);
1699 	CU_ASSERT(ch_ctx->base_channel == NULL);
1700 	free(ch);
1701 	create_raid_bdev_delete_req(&destroy_req, "raid1", 0);
1702 	rpc_bdev_raid_delete(NULL, NULL);
1703 	CU_ASSERT(g_rpc_err == 0);
1704 	verify_raid_config_present("raid1", false);
1705 	verify_raid_bdev_present("raid1", false);
1706 
1707 	raid_bdev_exit();
1708 	base_bdevs_cleanup();
1709 	reset_globals();
1710 }
1711 
1712 /* Test reset IO */
1713 static void
1714 test_reset_io(void)
1715 {
1716 	struct rpc_bdev_raid_create req;
1717 	struct rpc_bdev_raid_delete destroy_req;
1718 	struct raid_bdev *pbdev;
1719 	struct spdk_io_channel *ch;
1720 	struct raid_bdev_io_channel *ch_ctx;
1721 	uint8_t i;
1722 	struct spdk_bdev_io *bdev_io;
1723 
1724 	set_globals();
1725 	CU_ASSERT(raid_bdev_init() == 0);
1726 
1727 	verify_raid_config_present("raid1", false);
1728 	verify_raid_bdev_present("raid1", false);
1729 	create_raid_bdev_create_req(&req, "raid1", 0, true, 0);
1730 	rpc_bdev_raid_create(NULL, NULL);
1731 	CU_ASSERT(g_rpc_err == 0);
1732 	verify_raid_config(&req, true);
1733 	verify_raid_bdev(&req, true, RAID_BDEV_STATE_ONLINE);
1734 	TAILQ_FOREACH(pbdev, &g_raid_bdev_list, global_link) {
1735 		if (strcmp(pbdev->bdev.name, "raid1") == 0) {
1736 			break;
1737 		}
1738 	}
1739 	CU_ASSERT(pbdev != NULL);
1740 	ch = calloc(1, sizeof(struct spdk_io_channel) + sizeof(struct raid_bdev_io_channel));
1741 	SPDK_CU_ASSERT_FATAL(ch != NULL);
1742 	ch_ctx = spdk_io_channel_get_ctx(ch);
1743 	SPDK_CU_ASSERT_FATAL(ch_ctx != NULL);
1744 
1745 	SPDK_CU_ASSERT_FATAL(raid_bdev_create_cb(pbdev, ch_ctx) == 0);
1746 	for (i = 0; i < req.base_bdevs.num_base_bdevs; i++) {
1747 		CU_ASSERT(ch_ctx->base_channel && ch_ctx->base_channel[i] == &g_io_channel);
1748 	}
1749 	free_test_req(&req);
1750 
1751 	g_bdev_io_submit_status = 0;
1752 	g_child_io_status_flag = true;
1753 
1754 	CU_ASSERT(raid_bdev_io_type_supported(pbdev, SPDK_BDEV_IO_TYPE_RESET) == true);
1755 
1756 	bdev_io = calloc(1, sizeof(struct spdk_bdev_io) + sizeof(struct raid_bdev_io));
1757 	SPDK_CU_ASSERT_FATAL(bdev_io != NULL);
1758 	bdev_io_initialize(bdev_io, ch, &pbdev->bdev, 0, 1, SPDK_BDEV_IO_TYPE_RESET);
1759 	memset(g_io_output, 0, g_max_base_drives * sizeof(struct io_output));
1760 	g_io_output_index = 0;
1761 	raid_bdev_submit_request(ch, bdev_io);
1762 	verify_reset_io(bdev_io, req.base_bdevs.num_base_bdevs, ch_ctx, pbdev,
1763 			true);
1764 	bdev_io_cleanup(bdev_io);
1765 
1766 	raid_bdev_destroy_cb(pbdev, ch_ctx);
1767 	CU_ASSERT(ch_ctx->base_channel == NULL);
1768 	free(ch);
1769 	create_raid_bdev_delete_req(&destroy_req, "raid1", 0);
1770 	rpc_bdev_raid_delete(NULL, NULL);
1771 	CU_ASSERT(g_rpc_err == 0);
1772 	verify_raid_config_present("raid1", false);
1773 	verify_raid_bdev_present("raid1", false);
1774 
1775 	raid_bdev_exit();
1776 	base_bdevs_cleanup();
1777 	reset_globals();
1778 }
1779 
1780 /* Create multiple raids, destroy raids without IO, get_raids related tests */
1781 static void
1782 test_multi_raid_no_io(void)
1783 {
1784 	struct rpc_bdev_raid_create *construct_req;
1785 	struct rpc_bdev_raid_delete destroy_req;
1786 	struct rpc_bdev_raid_get_bdevs get_raids_req;
1787 	uint8_t i;
1788 	char name[16];
1789 	uint8_t bbdev_idx = 0;
1790 
1791 	set_globals();
1792 	construct_req = calloc(MAX_RAIDS, sizeof(struct rpc_bdev_raid_create));
1793 	SPDK_CU_ASSERT_FATAL(construct_req != NULL);
1794 	CU_ASSERT(raid_bdev_init() == 0);
1795 	for (i = 0; i < g_max_raids; i++) {
1796 		snprintf(name, 16, "%s%u", "raid", i);
1797 		verify_raid_config_present(name, false);
1798 		verify_raid_bdev_present(name, false);
1799 		create_raid_bdev_create_req(&construct_req[i], name, bbdev_idx, true, 0);
1800 		bbdev_idx += g_max_base_drives;
1801 		rpc_bdev_raid_create(NULL, NULL);
1802 		CU_ASSERT(g_rpc_err == 0);
1803 		verify_raid_config(&construct_req[i], true);
1804 		verify_raid_bdev(&construct_req[i], true, RAID_BDEV_STATE_ONLINE);
1805 	}
1806 
1807 	create_get_raids_req(&get_raids_req, "all", 0);
1808 	rpc_bdev_raid_get_bdevs(NULL, NULL);
1809 	CU_ASSERT(g_rpc_err == 0);
1810 	verify_get_raids(construct_req, g_max_raids, g_get_raids_output, g_get_raids_count);
1811 	for (i = 0; i < g_get_raids_count; i++) {
1812 		free(g_get_raids_output[i]);
1813 	}
1814 
1815 	create_get_raids_req(&get_raids_req, "online", 0);
1816 	rpc_bdev_raid_get_bdevs(NULL, NULL);
1817 	CU_ASSERT(g_rpc_err == 0);
1818 	verify_get_raids(construct_req, g_max_raids, g_get_raids_output, g_get_raids_count);
1819 	for (i = 0; i < g_get_raids_count; i++) {
1820 		free(g_get_raids_output[i]);
1821 	}
1822 
1823 	create_get_raids_req(&get_raids_req, "configuring", 0);
1824 	rpc_bdev_raid_get_bdevs(NULL, NULL);
1825 	CU_ASSERT(g_rpc_err == 0);
1826 	CU_ASSERT(g_get_raids_count == 0);
1827 
1828 	create_get_raids_req(&get_raids_req, "offline", 0);
1829 	rpc_bdev_raid_get_bdevs(NULL, NULL);
1830 	CU_ASSERT(g_rpc_err == 0);
1831 	CU_ASSERT(g_get_raids_count == 0);
1832 
1833 	create_get_raids_req(&get_raids_req, "invalid_category", 0);
1834 	rpc_bdev_raid_get_bdevs(NULL, NULL);
1835 	CU_ASSERT(g_rpc_err == 1);
1836 	CU_ASSERT(g_get_raids_count == 0);
1837 
1838 	create_get_raids_req(&get_raids_req, "all", 1);
1839 	rpc_bdev_raid_get_bdevs(NULL, NULL);
1840 	CU_ASSERT(g_rpc_err == 1);
1841 	free(get_raids_req.category);
1842 	CU_ASSERT(g_get_raids_count == 0);
1843 
1844 	create_get_raids_req(&get_raids_req, "all", 0);
1845 	rpc_bdev_raid_get_bdevs(NULL, NULL);
1846 	CU_ASSERT(g_rpc_err == 0);
1847 	CU_ASSERT(g_get_raids_count == g_max_raids);
1848 	for (i = 0; i < g_get_raids_count; i++) {
1849 		free(g_get_raids_output[i]);
1850 	}
1851 
1852 	for (i = 0; i < g_max_raids; i++) {
1853 		SPDK_CU_ASSERT_FATAL(construct_req[i].name != NULL);
1854 		snprintf(name, 16, "%s", construct_req[i].name);
1855 		create_raid_bdev_delete_req(&destroy_req, name, 0);
1856 		rpc_bdev_raid_delete(NULL, NULL);
1857 		CU_ASSERT(g_rpc_err == 0);
1858 		verify_raid_config_present(name, false);
1859 		verify_raid_bdev_present(name, false);
1860 	}
1861 	raid_bdev_exit();
1862 	for (i = 0; i < g_max_raids; i++) {
1863 		free_test_req(&construct_req[i]);
1864 	}
1865 	free(construct_req);
1866 	base_bdevs_cleanup();
1867 	reset_globals();
1868 }
1869 
1870 /* Create multiple raids, fire IOs on raids */
1871 static void
1872 test_multi_raid_with_io(void)
1873 {
1874 	struct rpc_bdev_raid_create *construct_req;
1875 	struct rpc_bdev_raid_delete destroy_req;
1876 	uint8_t i, j;
1877 	char name[16];
1878 	uint8_t bbdev_idx = 0;
1879 	struct raid_bdev *pbdev;
1880 	struct spdk_io_channel *ch;
1881 	struct raid_bdev_io_channel *ch_ctx = NULL;
1882 	struct spdk_bdev_io *bdev_io;
1883 	uint64_t io_len;
1884 	uint64_t lba = 0;
1885 	int16_t iotype;
1886 	struct spdk_io_channel *ch_b;
1887 	struct spdk_bdev_channel *ch_b_ctx;
1888 
1889 	set_globals();
1890 	construct_req = calloc(g_max_raids, sizeof(struct rpc_bdev_raid_create));
1891 	SPDK_CU_ASSERT_FATAL(construct_req != NULL);
1892 	CU_ASSERT(raid_bdev_init() == 0);
1893 	ch = calloc(g_max_raids, sizeof(struct spdk_io_channel) + sizeof(struct raid_bdev_io_channel));
1894 	SPDK_CU_ASSERT_FATAL(ch != NULL);
1895 
1896 	ch_b = calloc(1, sizeof(struct spdk_io_channel) + sizeof(struct spdk_bdev_channel));
1897 	SPDK_CU_ASSERT_FATAL(ch_b != NULL);
1898 	ch_b_ctx = spdk_io_channel_get_ctx(ch_b);
1899 	ch_b_ctx->channel = ch;
1900 
1901 	for (i = 0; i < g_max_raids; i++) {
1902 		snprintf(name, 16, "%s%u", "raid", i);
1903 		verify_raid_config_present(name, false);
1904 		verify_raid_bdev_present(name, false);
1905 		create_raid_bdev_create_req(&construct_req[i], name, bbdev_idx, true, 0);
1906 		bbdev_idx += g_max_base_drives;
1907 		rpc_bdev_raid_create(NULL, NULL);
1908 		CU_ASSERT(g_rpc_err == 0);
1909 		verify_raid_config(&construct_req[i], true);
1910 		verify_raid_bdev(&construct_req[i], true, RAID_BDEV_STATE_ONLINE);
1911 		TAILQ_FOREACH(pbdev, &g_raid_bdev_list, global_link) {
1912 			if (strcmp(pbdev->bdev.name, construct_req[i].name) == 0) {
1913 				break;
1914 			}
1915 		}
1916 		CU_ASSERT(pbdev != NULL);
1917 		ch_ctx = spdk_io_channel_get_ctx(&ch[i]);
1918 		SPDK_CU_ASSERT_FATAL(ch_ctx != NULL);
1919 		CU_ASSERT(raid_bdev_create_cb(pbdev, ch_ctx) == 0);
1920 		SPDK_CU_ASSERT_FATAL(ch_ctx->base_channel != NULL);
1921 		for (j = 0; j < construct_req[i].base_bdevs.num_base_bdevs; j++) {
1922 			CU_ASSERT(ch_ctx->base_channel[j] == &g_io_channel);
1923 		}
1924 	}
1925 
1926 	/* This will perform a write on the first raid and a read on the second. It can be
1927 	 * expanded in the future to perform r/w on each raid device in the event that
1928 	 * multiple raid levels are supported.
1929 	 */
1930 	for (i = 0; i < g_max_raids; i++) {
1931 		bdev_io = calloc(1, sizeof(struct spdk_bdev_io) + sizeof(struct raid_bdev_io));
1932 		SPDK_CU_ASSERT_FATAL(bdev_io != NULL);
1933 		io_len = g_strip_size;
1934 		iotype = (i) ? SPDK_BDEV_IO_TYPE_WRITE : SPDK_BDEV_IO_TYPE_READ;
1935 		memset(g_io_output, 0, ((g_max_io_size / g_strip_size) + 1) * sizeof(struct io_output));
1936 		g_io_output_index = 0;
1937 		TAILQ_FOREACH(pbdev, &g_raid_bdev_list, global_link) {
1938 			if (strcmp(pbdev->bdev.name, construct_req[i].name) == 0) {
1939 				break;
1940 			}
1941 		}
1942 		bdev_io_initialize(bdev_io, ch_b, &pbdev->bdev, lba, io_len, iotype);
1943 		CU_ASSERT(pbdev != NULL);
1944 		raid_bdev_submit_request(ch, bdev_io);
1945 		verify_io(bdev_io, g_max_base_drives, ch_ctx, pbdev,
1946 			  g_child_io_status_flag);
1947 		bdev_io_cleanup(bdev_io);
1948 	}
1949 
1950 	for (i = 0; i < g_max_raids; i++) {
1951 		TAILQ_FOREACH(pbdev, &g_raid_bdev_list, global_link) {
1952 			if (strcmp(pbdev->bdev.name, construct_req[i].name) == 0) {
1953 				break;
1954 			}
1955 		}
1956 		CU_ASSERT(pbdev != NULL);
1957 		ch_ctx = spdk_io_channel_get_ctx(&ch[i]);
1958 		SPDK_CU_ASSERT_FATAL(ch_ctx != NULL);
1959 		raid_bdev_destroy_cb(pbdev, ch_ctx);
1960 		CU_ASSERT(ch_ctx->base_channel == NULL);
1961 		snprintf(name, 16, "%s", construct_req[i].name);
1962 		create_raid_bdev_delete_req(&destroy_req, name, 0);
1963 		rpc_bdev_raid_delete(NULL, NULL);
1964 		CU_ASSERT(g_rpc_err == 0);
1965 		verify_raid_config_present(name, false);
1966 		verify_raid_bdev_present(name, false);
1967 	}
1968 	raid_bdev_exit();
1969 	for (i = 0; i < g_max_raids; i++) {
1970 		free_test_req(&construct_req[i]);
1971 	}
1972 	free(construct_req);
1973 	free(ch);
1974 	free(ch_b);
1975 	base_bdevs_cleanup();
1976 	reset_globals();
1977 }
1978 
1979 static void
1980 test_io_type_supported(void)
1981 {
1982 	CU_ASSERT(raid_bdev_io_type_supported(NULL, SPDK_BDEV_IO_TYPE_READ) == true);
1983 	CU_ASSERT(raid_bdev_io_type_supported(NULL, SPDK_BDEV_IO_TYPE_WRITE) == true);
1984 	CU_ASSERT(raid_bdev_io_type_supported(NULL, SPDK_BDEV_IO_TYPE_INVALID) == false);
1985 }
1986 
1987 static void
1988 test_raid_json_dump_info(void)
1989 {
1990 	struct rpc_bdev_raid_create req;
1991 	struct rpc_bdev_raid_delete destroy_req;
1992 	struct raid_bdev *pbdev;
1993 
1994 	set_globals();
1995 	CU_ASSERT(raid_bdev_init() == 0);
1996 
1997 	verify_raid_config_present("raid1", false);
1998 	verify_raid_bdev_present("raid1", false);
1999 	create_raid_bdev_create_req(&req, "raid1", 0, true, 0);
2000 	rpc_bdev_raid_create(NULL, NULL);
2001 	CU_ASSERT(g_rpc_err == 0);
2002 	verify_raid_bdev(&req, true, RAID_BDEV_STATE_ONLINE);
2003 
2004 	TAILQ_FOREACH(pbdev, &g_raid_bdev_list, global_link) {
2005 		if (strcmp(pbdev->bdev.name, "raid1") == 0) {
2006 			break;
2007 		}
2008 	}
2009 	CU_ASSERT(pbdev != NULL);
2010 
2011 	CU_ASSERT(raid_bdev_dump_info_json(pbdev, NULL) == 0);
2012 
2013 	free_test_req(&req);
2014 
2015 	create_raid_bdev_delete_req(&destroy_req, "raid1", 0);
2016 	rpc_bdev_raid_delete(NULL, NULL);
2017 	CU_ASSERT(g_rpc_err == 0);
2018 	verify_raid_config_present("raid1", false);
2019 	verify_raid_bdev_present("raid1", false);
2020 
2021 	raid_bdev_exit();
2022 	base_bdevs_cleanup();
2023 	reset_globals();
2024 }
2025 
2026 static void
2027 test_context_size(void)
2028 {
2029 	CU_ASSERT(raid_bdev_get_ctx_size() == sizeof(struct raid_bdev_io));
2030 }
2031 
2032 static void
2033 test_raid_level_conversions(void)
2034 {
2035 	const char *raid_str;
2036 
2037 	CU_ASSERT(raid_bdev_parse_raid_level("abcd123") == INVALID_RAID_LEVEL);
2038 	CU_ASSERT(raid_bdev_parse_raid_level("0") == RAID0);
2039 	CU_ASSERT(raid_bdev_parse_raid_level("raid0") == RAID0);
2040 	CU_ASSERT(raid_bdev_parse_raid_level("RAID0") == RAID0);
2041 
2042 	raid_str = raid_bdev_level_to_str(INVALID_RAID_LEVEL);
2043 	CU_ASSERT(raid_str != NULL && strlen(raid_str) == 0);
2044 	raid_str = raid_bdev_level_to_str(1234);
2045 	CU_ASSERT(raid_str != NULL && strlen(raid_str) == 0);
2046 	raid_str = raid_bdev_level_to_str(RAID0);
2047 	CU_ASSERT(raid_str != NULL && strcmp(raid_str, "raid0") == 0);
2048 }
2049 
2050 int main(int argc, char **argv)
2051 {
2052 	CU_pSuite       suite = NULL;
2053 	unsigned int    num_failures;
2054 
2055 	CU_set_error_action(CUEA_ABORT);
2056 	CU_initialize_registry();
2057 
2058 	suite = CU_add_suite("raid", NULL, NULL);
2059 
2060 	CU_ADD_TEST(suite, test_create_raid);
2061 	CU_ADD_TEST(suite, test_delete_raid);
2062 	CU_ADD_TEST(suite, test_create_raid_invalid_args);
2063 	CU_ADD_TEST(suite, test_delete_raid_invalid_args);
2064 	CU_ADD_TEST(suite, test_io_channel);
2065 	CU_ADD_TEST(suite, test_reset_io);
2066 	CU_ADD_TEST(suite, test_write_io);
2067 	CU_ADD_TEST(suite, test_read_io);
2068 	CU_ADD_TEST(suite, test_unmap_io);
2069 	CU_ADD_TEST(suite, test_io_failure);
2070 	CU_ADD_TEST(suite, test_multi_raid_no_io);
2071 	CU_ADD_TEST(suite, test_multi_raid_with_io);
2072 	CU_ADD_TEST(suite, test_io_type_supported);
2073 	CU_ADD_TEST(suite, test_raid_json_dump_info);
2074 	CU_ADD_TEST(suite, test_context_size);
2075 	CU_ADD_TEST(suite, test_raid_level_conversions);
2076 
2077 	allocate_threads(1);
2078 	set_thread(0);
2079 
2080 	CU_basic_set_mode(CU_BRM_VERBOSE);
2081 	set_test_opts();
2082 	CU_basic_run_tests();
2083 	num_failures = CU_get_number_of_failures();
2084 	CU_cleanup_registry();
2085 
2086 	free_threads();
2087 
2088 	return num_failures;
2089 }
2090