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