xref: /spdk/test/unit/lib/lvol/lvol.c/lvol_ut.c (revision 1a9ed697f0c1696ba6b5819e27e68a3fbbf3b223)
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_cunit.h"
35 #include "spdk/blob.h"
36 #include "spdk/thread.h"
37 #include "spdk/util.h"
38 
39 #include "common/lib/ut_multithread.c"
40 
41 #include "lvol/lvol.c"
42 
43 #define DEV_BUFFER_SIZE (64 * 1024 * 1024)
44 #define DEV_BUFFER_BLOCKLEN (4096)
45 #define DEV_BUFFER_BLOCKCNT (DEV_BUFFER_SIZE / DEV_BUFFER_BLOCKLEN)
46 #define BS_CLUSTER_SIZE (1024 * 1024)
47 #define BS_FREE_CLUSTERS (DEV_BUFFER_SIZE / BS_CLUSTER_SIZE)
48 #define BS_PAGE_SIZE (4096)
49 
50 #define SPDK_BLOB_OPTS_CLUSTER_SZ (1024 * 1024)
51 #define SPDK_BLOB_OPTS_NUM_MD_PAGES UINT32_MAX
52 #define SPDK_BLOB_OPTS_MAX_MD_OPS 32
53 #define SPDK_BLOB_OPTS_MAX_CHANNEL_OPS 512
54 
55 #define SPDK_BLOB_THIN_PROV (1ULL << 0)
56 
57 const char *uuid = "828d9766-ae50-11e7-bd8d-001e67edf350";
58 
59 struct spdk_blob {
60 	spdk_blob_id		id;
61 	uint32_t		ref;
62 	struct spdk_blob_store *bs;
63 	int			close_status;
64 	int			open_status;
65 	int			load_status;
66 	TAILQ_ENTRY(spdk_blob)	link;
67 	char			uuid[SPDK_UUID_STRING_LEN];
68 	char			name[SPDK_LVS_NAME_MAX];
69 	bool			thin_provisioned;
70 };
71 
72 int g_lvserrno;
73 int g_close_super_status;
74 int g_resize_rc;
75 int g_inflate_rc;
76 int g_remove_rc;
77 bool g_lvs_rename_blob_open_error = false;
78 struct spdk_lvol_store *g_lvol_store;
79 struct spdk_lvol *g_lvol;
80 spdk_blob_id g_blobid = 1;
81 struct spdk_io_channel *g_io_channel;
82 
83 struct spdk_blob_store {
84 	struct spdk_bs_opts	bs_opts;
85 	spdk_blob_id		super_blobid;
86 	TAILQ_HEAD(, spdk_blob)	blobs;
87 	int			get_super_status;
88 };
89 
90 struct lvol_ut_bs_dev {
91 	struct spdk_bs_dev	bs_dev;
92 	int			init_status;
93 	int			load_status;
94 	struct spdk_blob_store	*bs;
95 };
96 
97 void spdk_bs_inflate_blob(struct spdk_blob_store *bs, struct spdk_io_channel *channel,
98 			  spdk_blob_id blobid, spdk_blob_op_complete cb_fn, void *cb_arg)
99 {
100 	cb_fn(cb_arg, g_inflate_rc);
101 }
102 
103 void spdk_bs_blob_decouple_parent(struct spdk_blob_store *bs, struct spdk_io_channel *channel,
104 				  spdk_blob_id blobid, spdk_blob_op_complete cb_fn, void *cb_arg)
105 {
106 	cb_fn(cb_arg, g_inflate_rc);
107 }
108 
109 void
110 spdk_bs_iter_next(struct spdk_blob_store *bs, struct spdk_blob *b,
111 		  spdk_blob_op_with_handle_complete cb_fn, void *cb_arg)
112 {
113 	struct spdk_blob *next;
114 	int _errno = 0;
115 
116 	next = TAILQ_NEXT(b, link);
117 	if (next == NULL) {
118 		_errno = -ENOENT;
119 	} else if (next->load_status != 0) {
120 		_errno = next->load_status;
121 	}
122 
123 	cb_fn(cb_arg, next, _errno);
124 }
125 
126 void
127 spdk_bs_iter_first(struct spdk_blob_store *bs,
128 		   spdk_blob_op_with_handle_complete cb_fn, void *cb_arg)
129 {
130 	struct spdk_blob *first;
131 	int _errno = 0;
132 
133 	first = TAILQ_FIRST(&bs->blobs);
134 	if (first == NULL) {
135 		_errno = -ENOENT;
136 	} else if (first->load_status != 0) {
137 		_errno = first->load_status;
138 	}
139 
140 	cb_fn(cb_arg, first, _errno);
141 }
142 
143 uint64_t spdk_blob_get_num_clusters(struct spdk_blob *blob)
144 {
145 	return 0;
146 }
147 
148 void
149 spdk_bs_get_super(struct spdk_blob_store *bs,
150 		  spdk_blob_op_with_id_complete cb_fn, void *cb_arg)
151 {
152 	if (bs->get_super_status != 0) {
153 		cb_fn(cb_arg, 0, bs->get_super_status);
154 	} else {
155 		cb_fn(cb_arg, bs->super_blobid, 0);
156 	}
157 }
158 
159 void
160 spdk_bs_set_super(struct spdk_blob_store *bs, spdk_blob_id blobid,
161 		  spdk_bs_op_complete cb_fn, void *cb_arg)
162 {
163 	bs->super_blobid = blobid;
164 	cb_fn(cb_arg, 0);
165 }
166 
167 void
168 spdk_bs_load(struct spdk_bs_dev *dev, struct spdk_bs_opts *opts,
169 	     spdk_bs_op_with_handle_complete cb_fn, void *cb_arg)
170 {
171 	struct lvol_ut_bs_dev *ut_dev = SPDK_CONTAINEROF(dev, struct lvol_ut_bs_dev, bs_dev);
172 	struct spdk_blob_store *bs = NULL;
173 
174 	if (ut_dev->load_status == 0) {
175 		bs = ut_dev->bs;
176 	}
177 
178 	cb_fn(cb_arg, bs, ut_dev->load_status);
179 }
180 
181 struct spdk_io_channel *spdk_bs_alloc_io_channel(struct spdk_blob_store *bs)
182 {
183 	if (g_io_channel == NULL) {
184 		g_io_channel = calloc(1, sizeof(struct spdk_io_channel));
185 		SPDK_CU_ASSERT_FATAL(g_io_channel != NULL);
186 	}
187 	g_io_channel->ref++;
188 	return g_io_channel;
189 }
190 
191 void spdk_bs_free_io_channel(struct spdk_io_channel *channel)
192 {
193 	g_io_channel->ref--;
194 	if (g_io_channel->ref == 0) {
195 		free(g_io_channel);
196 		g_io_channel = NULL;
197 	}
198 	return;
199 }
200 
201 int
202 spdk_blob_set_xattr(struct spdk_blob *blob, const char *name, const void *value,
203 		    uint16_t value_len)
204 {
205 	if (!strcmp(name, "uuid")) {
206 		CU_ASSERT(value_len == SPDK_UUID_STRING_LEN);
207 		memcpy(blob->uuid, value, SPDK_UUID_STRING_LEN);
208 	} else if (!strcmp(name, "name")) {
209 		CU_ASSERT(value_len <= SPDK_LVS_NAME_MAX);
210 		memcpy(blob->name, value, value_len);
211 	}
212 
213 	return 0;
214 }
215 
216 int
217 spdk_blob_get_xattr_value(struct spdk_blob *blob, const char *name,
218 			  const void **value, size_t *value_len)
219 {
220 	if (!strcmp(name, "uuid") && strnlen(blob->uuid, SPDK_UUID_STRING_LEN) != 0) {
221 		CU_ASSERT(strnlen(blob->uuid, SPDK_UUID_STRING_LEN) == (SPDK_UUID_STRING_LEN - 1));
222 		*value = blob->uuid;
223 		*value_len = SPDK_UUID_STRING_LEN;
224 		return 0;
225 	} else if (!strcmp(name, "name") && strnlen(blob->name, SPDK_LVS_NAME_MAX) != 0) {
226 		*value = blob->name;
227 		*value_len = strnlen(blob->name, SPDK_LVS_NAME_MAX) + 1;
228 		return 0;
229 	}
230 
231 	return -ENOENT;
232 }
233 
234 bool spdk_blob_is_thin_provisioned(struct spdk_blob *blob)
235 {
236 	return blob->thin_provisioned;
237 }
238 
239 DEFINE_STUB(spdk_blob_get_clones, int, (struct spdk_blob_store *bs, spdk_blob_id blobid,
240 					spdk_blob_id *ids, size_t *count), 0);
241 DEFINE_STUB(spdk_bs_get_page_size, uint64_t, (struct spdk_blob_store *bs), BS_PAGE_SIZE);
242 
243 int
244 spdk_bdev_notify_blockcnt_change(struct spdk_bdev *bdev, uint64_t size)
245 {
246 	bdev->blockcnt = size;
247 	return 0;
248 }
249 
250 static void
251 init_dev(struct lvol_ut_bs_dev *dev)
252 {
253 	memset(dev, 0, sizeof(*dev));
254 	dev->bs_dev.blockcnt = DEV_BUFFER_BLOCKCNT;
255 	dev->bs_dev.blocklen = DEV_BUFFER_BLOCKLEN;
256 }
257 
258 static void
259 free_dev(struct lvol_ut_bs_dev *dev)
260 {
261 	struct spdk_blob_store *bs = dev->bs;
262 	struct spdk_blob *blob, *tmp;
263 
264 	if (bs == NULL) {
265 		return;
266 	}
267 
268 	TAILQ_FOREACH_SAFE(blob, &bs->blobs, link, tmp) {
269 		TAILQ_REMOVE(&bs->blobs, blob, link);
270 		free(blob);
271 	}
272 
273 	free(bs);
274 	dev->bs = NULL;
275 }
276 
277 void
278 spdk_bs_init(struct spdk_bs_dev *dev, struct spdk_bs_opts *o,
279 	     spdk_bs_op_with_handle_complete cb_fn, void *cb_arg)
280 {
281 	struct lvol_ut_bs_dev *ut_dev = SPDK_CONTAINEROF(dev, struct lvol_ut_bs_dev, bs_dev);
282 	struct spdk_blob_store *bs;
283 
284 	bs = calloc(1, sizeof(*bs));
285 	SPDK_CU_ASSERT_FATAL(bs != NULL);
286 
287 	TAILQ_INIT(&bs->blobs);
288 
289 	ut_dev->bs = bs;
290 
291 	memcpy(&bs->bs_opts, o, sizeof(struct spdk_bs_opts));
292 
293 	cb_fn(cb_arg, bs, 0);
294 }
295 
296 void
297 spdk_bs_unload(struct spdk_blob_store *bs, spdk_bs_op_complete cb_fn, void *cb_arg)
298 {
299 	cb_fn(cb_arg, 0);
300 }
301 
302 void
303 spdk_bs_destroy(struct spdk_blob_store *bs, spdk_bs_op_complete cb_fn,
304 		void *cb_arg)
305 {
306 	free(bs);
307 
308 	cb_fn(cb_arg, 0);
309 }
310 
311 void
312 spdk_bs_delete_blob(struct spdk_blob_store *bs, spdk_blob_id blobid,
313 		    spdk_blob_op_complete cb_fn, void *cb_arg)
314 {
315 	struct spdk_blob *blob;
316 
317 	TAILQ_FOREACH(blob, &bs->blobs, link) {
318 		if (blob->id == blobid) {
319 			TAILQ_REMOVE(&bs->blobs, blob, link);
320 			free(blob);
321 			break;
322 		}
323 	}
324 
325 	cb_fn(cb_arg, g_remove_rc);
326 }
327 
328 spdk_blob_id
329 spdk_blob_get_id(struct spdk_blob *blob)
330 {
331 	return blob->id;
332 }
333 
334 void
335 spdk_bs_opts_init(struct spdk_bs_opts *opts)
336 {
337 	opts->cluster_sz = SPDK_BLOB_OPTS_CLUSTER_SZ;
338 	opts->num_md_pages = SPDK_BLOB_OPTS_NUM_MD_PAGES;
339 	opts->max_md_ops = SPDK_BLOB_OPTS_MAX_MD_OPS;
340 	opts->max_channel_ops = SPDK_BLOB_OPTS_MAX_CHANNEL_OPS;
341 	memset(&opts->bstype, 0, sizeof(opts->bstype));
342 }
343 
344 DEFINE_STUB(spdk_bs_get_cluster_size, uint64_t, (struct spdk_blob_store *bs), BS_CLUSTER_SIZE);
345 
346 void spdk_blob_close(struct spdk_blob *b, spdk_blob_op_complete cb_fn, void *cb_arg)
347 {
348 	b->ref--;
349 
350 	cb_fn(cb_arg, b->close_status);
351 }
352 
353 void
354 spdk_blob_resize(struct spdk_blob *blob, uint64_t sz, spdk_blob_op_complete cb_fn, void *cb_arg)
355 {
356 	if (g_resize_rc != 0) {
357 		return cb_fn(cb_arg, g_resize_rc);
358 	} else if (sz > DEV_BUFFER_SIZE / BS_CLUSTER_SIZE) {
359 		return cb_fn(cb_arg, -ENOMEM);
360 	}
361 	cb_fn(cb_arg, 0);
362 }
363 
364 DEFINE_STUB(spdk_blob_set_read_only, int, (struct spdk_blob *blob), 0);
365 
366 void
367 spdk_blob_sync_md(struct spdk_blob *blob, spdk_blob_op_complete cb_fn, void *cb_arg)
368 {
369 	cb_fn(cb_arg, 0);
370 }
371 
372 void
373 spdk_bs_open_blob_ext(struct spdk_blob_store *bs, spdk_blob_id blobid,
374 		      struct spdk_blob_open_opts *opts, spdk_blob_op_with_handle_complete cb_fn, void *cb_arg)
375 {
376 	spdk_bs_open_blob(bs, blobid, cb_fn, cb_arg);
377 }
378 
379 void
380 spdk_bs_open_blob(struct spdk_blob_store *bs, spdk_blob_id blobid,
381 		  spdk_blob_op_with_handle_complete cb_fn, void *cb_arg)
382 {
383 	struct spdk_blob *blob;
384 
385 	if (!g_lvs_rename_blob_open_error) {
386 		TAILQ_FOREACH(blob, &bs->blobs, link) {
387 			if (blob->id == blobid) {
388 				blob->ref++;
389 				cb_fn(cb_arg, blob, blob->open_status);
390 				return;
391 			}
392 		}
393 	}
394 
395 	cb_fn(cb_arg, NULL, -ENOENT);
396 }
397 
398 DEFINE_STUB(spdk_bs_free_cluster_count, uint64_t, (struct spdk_blob_store *bs), BS_FREE_CLUSTERS);
399 
400 void
401 spdk_blob_opts_init(struct spdk_blob_opts *opts)
402 {
403 	opts->num_clusters = 0;
404 	opts->thin_provision = false;
405 	opts->xattrs.count = 0;
406 	opts->xattrs.names = NULL;
407 	opts->xattrs.ctx = NULL;
408 	opts->xattrs.get_value = NULL;
409 }
410 
411 void
412 spdk_blob_open_opts_init(struct spdk_blob_open_opts *opts)
413 {
414 	opts->clear_method = BLOB_CLEAR_WITH_DEFAULT;
415 }
416 
417 void
418 spdk_bs_create_blob(struct spdk_blob_store *bs,
419 		    spdk_blob_op_with_id_complete cb_fn, void *cb_arg)
420 {
421 	spdk_bs_create_blob_ext(bs, NULL, cb_fn, cb_arg);
422 }
423 
424 void
425 spdk_bs_create_blob_ext(struct spdk_blob_store *bs, const struct spdk_blob_opts *opts,
426 			spdk_blob_op_with_id_complete cb_fn, void *cb_arg)
427 {
428 	struct spdk_blob *b;
429 
430 	if (opts && opts->num_clusters > DEV_BUFFER_SIZE / BS_CLUSTER_SIZE) {
431 		cb_fn(cb_arg, 0, -1);
432 		return;
433 	}
434 
435 	b = calloc(1, sizeof(*b));
436 	SPDK_CU_ASSERT_FATAL(b != NULL);
437 
438 	b->id = g_blobid++;
439 	if (opts != NULL && opts->thin_provision) {
440 		b->thin_provisioned = true;
441 	}
442 	b->bs = bs;
443 
444 	TAILQ_INSERT_TAIL(&bs->blobs, b, link);
445 	cb_fn(cb_arg, b->id, 0);
446 }
447 
448 void
449 spdk_bs_create_snapshot(struct spdk_blob_store *bs, spdk_blob_id blobid,
450 			const struct spdk_blob_xattr_opts *snapshot_xattrs,
451 			spdk_blob_op_with_id_complete cb_fn, void *cb_arg)
452 {
453 	spdk_bs_create_blob_ext(bs, NULL, cb_fn, cb_arg);
454 }
455 
456 void
457 spdk_bs_create_clone(struct spdk_blob_store *bs, spdk_blob_id blobid,
458 		     const struct spdk_blob_xattr_opts *clone_xattrs,
459 		     spdk_blob_op_with_id_complete cb_fn, void *cb_arg)
460 {
461 	spdk_bs_create_blob_ext(bs, NULL, cb_fn, cb_arg);
462 }
463 
464 static void
465 lvol_store_op_with_handle_complete(void *cb_arg, struct spdk_lvol_store *lvol_store, int lvserrno)
466 {
467 	g_lvol_store = lvol_store;
468 	g_lvserrno = lvserrno;
469 }
470 
471 static void
472 lvol_op_with_handle_complete(void *cb_arg, struct spdk_lvol *lvol, int lvserrno)
473 {
474 	g_lvol = lvol;
475 	g_lvserrno = lvserrno;
476 }
477 
478 static void
479 op_complete(void *cb_arg, int lvserrno)
480 {
481 	g_lvserrno = lvserrno;
482 }
483 
484 static void
485 lvs_init_unload_success(void)
486 {
487 	struct lvol_ut_bs_dev dev;
488 	struct spdk_lvs_opts opts;
489 	int rc = 0;
490 
491 	init_dev(&dev);
492 
493 	spdk_lvs_opts_init(&opts);
494 	snprintf(opts.name, sizeof(opts.name), "lvs");
495 
496 	g_lvserrno = -1;
497 
498 	CU_ASSERT(TAILQ_EMPTY(&g_lvol_stores));
499 	rc = spdk_lvs_init(&dev.bs_dev, &opts, lvol_store_op_with_handle_complete, NULL);
500 	CU_ASSERT(rc == 0);
501 	CU_ASSERT(g_lvserrno == 0);
502 	SPDK_CU_ASSERT_FATAL(g_lvol_store != NULL);
503 	CU_ASSERT(!TAILQ_EMPTY(&g_lvol_stores));
504 
505 	spdk_lvol_create(g_lvol_store, "lvol", 10, false, LVOL_CLEAR_WITH_DEFAULT,
506 			 lvol_op_with_handle_complete, NULL);
507 	CU_ASSERT(g_lvserrno == 0);
508 	SPDK_CU_ASSERT_FATAL(g_lvol != NULL);
509 
510 	/* Lvol store has an open lvol, this unload should fail. */
511 	g_lvserrno = -1;
512 	rc = spdk_lvs_unload(g_lvol_store, op_complete, NULL);
513 	CU_ASSERT(rc == -EBUSY);
514 	CU_ASSERT(g_lvserrno == -EBUSY);
515 	SPDK_CU_ASSERT_FATAL(g_lvol_store != NULL);
516 	CU_ASSERT(!TAILQ_EMPTY(&g_lvol_stores));
517 
518 	/* Lvol has to be closed (or destroyed) before unloading lvol store. */
519 	spdk_lvol_close(g_lvol, op_complete, NULL);
520 	CU_ASSERT(g_lvserrno == 0);
521 
522 	g_lvserrno = -1;
523 	rc = spdk_lvs_unload(g_lvol_store, op_complete, NULL);
524 	CU_ASSERT(rc == 0);
525 	CU_ASSERT(g_lvserrno == 0);
526 	g_lvol_store = NULL;
527 	CU_ASSERT(TAILQ_EMPTY(&g_lvol_stores));
528 
529 	free_dev(&dev);
530 }
531 
532 static void
533 lvs_init_destroy_success(void)
534 {
535 	struct lvol_ut_bs_dev dev;
536 	struct spdk_lvs_opts opts;
537 	int rc = 0;
538 
539 	init_dev(&dev);
540 
541 	spdk_lvs_opts_init(&opts);
542 	snprintf(opts.name, sizeof(opts.name), "lvs");
543 
544 	g_lvserrno = -1;
545 
546 	rc = spdk_lvs_init(&dev.bs_dev, &opts, lvol_store_op_with_handle_complete, NULL);
547 	CU_ASSERT(rc == 0);
548 	CU_ASSERT(g_lvserrno == 0);
549 	SPDK_CU_ASSERT_FATAL(g_lvol_store != NULL);
550 
551 	spdk_lvol_create(g_lvol_store, "lvol", 10, false, LVOL_CLEAR_WITH_DEFAULT,
552 			 lvol_op_with_handle_complete, NULL);
553 	CU_ASSERT(g_lvserrno == 0);
554 	SPDK_CU_ASSERT_FATAL(g_lvol != NULL);
555 
556 	/* Lvol store contains one lvol, this destroy should fail. */
557 	g_lvserrno = -1;
558 	rc = spdk_lvs_destroy(g_lvol_store, op_complete, NULL);
559 	CU_ASSERT(rc == -EBUSY);
560 	CU_ASSERT(g_lvserrno == -EBUSY);
561 	SPDK_CU_ASSERT_FATAL(g_lvol_store != NULL);
562 
563 	spdk_lvol_close(g_lvol, op_complete, NULL);
564 	CU_ASSERT(g_lvserrno == 0);
565 
566 	spdk_lvol_destroy(g_lvol, op_complete, NULL);
567 
568 	g_lvserrno = -1;
569 	rc = spdk_lvs_destroy(g_lvol_store, op_complete, NULL);
570 	CU_ASSERT(rc == 0);
571 	CU_ASSERT(g_lvserrno == 0);
572 	g_lvol_store = NULL;
573 }
574 
575 static void
576 lvs_init_opts_success(void)
577 {
578 	struct lvol_ut_bs_dev dev;
579 	struct spdk_lvs_opts opts;
580 	int rc = 0;
581 
582 	init_dev(&dev);
583 
584 	g_lvserrno = -1;
585 
586 	spdk_lvs_opts_init(&opts);
587 	snprintf(opts.name, sizeof(opts.name), "lvs");
588 	opts.cluster_sz = 8192;
589 	rc = spdk_lvs_init(&dev.bs_dev, &opts, lvol_store_op_with_handle_complete, NULL);
590 	CU_ASSERT(rc == 0);
591 	CU_ASSERT(g_lvserrno == 0);
592 	CU_ASSERT(dev.bs->bs_opts.cluster_sz == opts.cluster_sz);
593 	SPDK_CU_ASSERT_FATAL(g_lvol_store != NULL);
594 
595 	g_lvserrno = -1;
596 	rc = spdk_lvs_unload(g_lvol_store, op_complete, NULL);
597 	CU_ASSERT(rc == 0);
598 	CU_ASSERT(g_lvserrno == 0);
599 	g_lvol_store = NULL;
600 
601 	free_dev(&dev);
602 }
603 
604 static void
605 lvs_unload_lvs_is_null_fail(void)
606 {
607 	int rc = 0;
608 
609 	g_lvserrno = -1;
610 	rc = spdk_lvs_unload(NULL, op_complete, NULL);
611 	CU_ASSERT(rc == -ENODEV);
612 	CU_ASSERT(g_lvserrno == -1);
613 }
614 
615 static void
616 lvs_names(void)
617 {
618 	struct lvol_ut_bs_dev dev_x, dev_y, dev_x2;
619 	struct spdk_lvs_opts opts_none, opts_x, opts_y, opts_full;
620 	struct spdk_lvol_store *lvs_x, *lvs_y, *lvs_x2;
621 	int rc = 0;
622 
623 	init_dev(&dev_x);
624 	init_dev(&dev_y);
625 	init_dev(&dev_x2);
626 
627 	spdk_lvs_opts_init(&opts_none);
628 	spdk_lvs_opts_init(&opts_x);
629 	opts_x.name[0] = 'x';
630 	spdk_lvs_opts_init(&opts_y);
631 	opts_y.name[0] = 'y';
632 	spdk_lvs_opts_init(&opts_full);
633 	memset(opts_full.name, 'a', sizeof(opts_full.name));
634 
635 	/* Test that opts with no name fails spdk_lvs_init(). */
636 	CU_ASSERT(TAILQ_EMPTY(&g_lvol_stores));
637 	rc = spdk_lvs_init(&dev_x.bs_dev, &opts_none, lvol_store_op_with_handle_complete, NULL);
638 	CU_ASSERT(rc != 0);
639 	CU_ASSERT(g_lvol_store == NULL);
640 	CU_ASSERT(TAILQ_EMPTY(&g_lvol_stores));
641 
642 	/* Test that opts with no null terminator for name fails spdk_lvs_init(). */
643 	CU_ASSERT(TAILQ_EMPTY(&g_lvol_stores));
644 	rc = spdk_lvs_init(&dev_x.bs_dev, &opts_full, lvol_store_op_with_handle_complete, NULL);
645 	CU_ASSERT(rc != 0);
646 	CU_ASSERT(g_lvol_store == NULL);
647 	CU_ASSERT(TAILQ_EMPTY(&g_lvol_stores));
648 
649 	/* Test that we can create an lvolstore with name 'x'. */
650 	CU_ASSERT(TAILQ_EMPTY(&g_lvol_stores));
651 	g_lvol_store = NULL;
652 	rc = spdk_lvs_init(&dev_x.bs_dev, &opts_x, lvol_store_op_with_handle_complete, NULL);
653 	CU_ASSERT(rc == 0);
654 	CU_ASSERT(!TAILQ_EMPTY(&g_lvol_stores));
655 	SPDK_CU_ASSERT_FATAL(g_lvol_store != NULL);
656 	lvs_x = g_lvol_store;
657 
658 	/* Test that we can create an lvolstore with name 'y'. */
659 	g_lvol_store = NULL;
660 	rc = spdk_lvs_init(&dev_y.bs_dev, &opts_y, lvol_store_op_with_handle_complete, NULL);
661 	CU_ASSERT(rc == 0);
662 	SPDK_CU_ASSERT_FATAL(g_lvol_store != NULL);
663 	lvs_y = g_lvol_store;
664 
665 	/* Test that we cannot create another lvolstore with name 'x'. */
666 	rc = spdk_lvs_init(&dev_x2.bs_dev, &opts_x, lvol_store_op_with_handle_complete, NULL);
667 	CU_ASSERT(rc == -EEXIST);
668 
669 	/* Now destroy lvolstore 'x' and then confirm we can create a new lvolstore with name 'x'. */
670 	g_lvserrno = -1;
671 	rc = spdk_lvs_destroy(lvs_x, op_complete, NULL);
672 	CU_ASSERT(rc == 0);
673 	CU_ASSERT(g_lvserrno == 0);
674 	g_lvol_store = NULL;
675 	rc = spdk_lvs_init(&dev_x.bs_dev, &opts_x, lvol_store_op_with_handle_complete, NULL);
676 	CU_ASSERT(rc == 0);
677 	SPDK_CU_ASSERT_FATAL(g_lvol_store != NULL);
678 	lvs_x = g_lvol_store;
679 
680 	/*
681 	 * Unload lvolstore 'x'.  Then we should be able to create another lvolstore with name 'x'.
682 	 */
683 	g_lvserrno = -1;
684 	rc = spdk_lvs_unload(lvs_x, op_complete, NULL);
685 	CU_ASSERT(rc == 0);
686 	CU_ASSERT(g_lvserrno == 0);
687 	g_lvol_store = NULL;
688 	rc = spdk_lvs_init(&dev_x2.bs_dev, &opts_x, lvol_store_op_with_handle_complete, NULL);
689 	CU_ASSERT(rc == 0);
690 	SPDK_CU_ASSERT_FATAL(g_lvol_store != NULL);
691 	lvs_x2 = g_lvol_store;
692 
693 	/* Confirm that we cannot load the first lvolstore 'x'. */
694 	g_lvserrno = 0;
695 	spdk_lvs_load(&dev_x.bs_dev, lvol_store_op_with_handle_complete, NULL);
696 	CU_ASSERT(g_lvserrno != 0);
697 
698 	/* Destroy the second lvolstore 'x'.  Then we should be able to load the first lvolstore 'x'. */
699 	g_lvserrno = -1;
700 	rc = spdk_lvs_destroy(lvs_x2, op_complete, NULL);
701 	CU_ASSERT(rc == 0);
702 	CU_ASSERT(g_lvserrno == 0);
703 	g_lvserrno = -1;
704 	spdk_lvs_load(&dev_x.bs_dev, lvol_store_op_with_handle_complete, NULL);
705 	CU_ASSERT(g_lvserrno == 0);
706 	SPDK_CU_ASSERT_FATAL(g_lvol_store != NULL);
707 	lvs_x = g_lvol_store;
708 
709 	g_lvserrno = -1;
710 	rc = spdk_lvs_destroy(lvs_x, op_complete, NULL);
711 	CU_ASSERT(rc == 0);
712 	CU_ASSERT(g_lvserrno == 0);
713 
714 	g_lvserrno = -1;
715 	rc = spdk_lvs_destroy(lvs_y, op_complete, NULL);
716 	CU_ASSERT(rc == 0);
717 	CU_ASSERT(g_lvserrno == 0);
718 }
719 
720 static void
721 lvol_create_destroy_success(void)
722 {
723 	struct lvol_ut_bs_dev dev;
724 	struct spdk_lvs_opts opts;
725 	int rc = 0;
726 
727 	init_dev(&dev);
728 
729 	spdk_lvs_opts_init(&opts);
730 	snprintf(opts.name, sizeof(opts.name), "lvs");
731 
732 	g_lvserrno = -1;
733 	rc = spdk_lvs_init(&dev.bs_dev, &opts, lvol_store_op_with_handle_complete, NULL);
734 	CU_ASSERT(rc == 0);
735 	CU_ASSERT(g_lvserrno == 0);
736 	SPDK_CU_ASSERT_FATAL(g_lvol_store != NULL);
737 
738 	spdk_lvol_create(g_lvol_store, "lvol", 10, false, LVOL_CLEAR_WITH_DEFAULT,
739 			 lvol_op_with_handle_complete, NULL);
740 	CU_ASSERT(g_lvserrno == 0);
741 	SPDK_CU_ASSERT_FATAL(g_lvol != NULL);
742 
743 	spdk_lvol_close(g_lvol, op_complete, NULL);
744 	CU_ASSERT(g_lvserrno == 0);
745 	spdk_lvol_destroy(g_lvol, op_complete, NULL);
746 	CU_ASSERT(g_lvserrno == 0);
747 
748 	g_lvserrno = -1;
749 	rc = spdk_lvs_unload(g_lvol_store, op_complete, NULL);
750 	CU_ASSERT(rc == 0);
751 	CU_ASSERT(g_lvserrno == 0);
752 	g_lvol_store = NULL;
753 
754 	free_dev(&dev);
755 }
756 
757 static void
758 lvol_create_fail(void)
759 {
760 	struct lvol_ut_bs_dev dev;
761 	struct spdk_lvs_opts opts;
762 	int rc = 0;
763 
764 	init_dev(&dev);
765 
766 	spdk_lvs_opts_init(&opts);
767 	snprintf(opts.name, sizeof(opts.name), "lvs");
768 
769 	g_lvol_store = NULL;
770 	g_lvserrno = 0;
771 	rc = spdk_lvs_init(NULL, &opts, lvol_store_op_with_handle_complete, NULL);
772 	CU_ASSERT(rc != 0);
773 	CU_ASSERT(g_lvol_store == NULL);
774 
775 	rc = spdk_lvs_init(&dev.bs_dev, &opts, lvol_store_op_with_handle_complete, NULL);
776 	CU_ASSERT(rc == 0);
777 	SPDK_CU_ASSERT_FATAL(g_lvol_store != NULL);
778 
779 	g_lvol = NULL;
780 	rc = spdk_lvol_create(NULL, "lvol", 10, false, LVOL_CLEAR_WITH_DEFAULT,
781 			      lvol_op_with_handle_complete, NULL);
782 	CU_ASSERT(rc != 0);
783 	CU_ASSERT(g_lvol == NULL);
784 
785 	g_lvol = NULL;
786 	rc = spdk_lvol_create(g_lvol_store, "lvol", DEV_BUFFER_SIZE + 1, false, LVOL_CLEAR_WITH_DEFAULT,
787 			      lvol_op_with_handle_complete, NULL);
788 	CU_ASSERT(rc == 0);
789 	CU_ASSERT(g_lvserrno != 0);
790 	CU_ASSERT(g_lvol == NULL);
791 
792 	g_lvserrno = -1;
793 	rc = spdk_lvs_unload(g_lvol_store, op_complete, NULL);
794 	CU_ASSERT(rc == 0);
795 	CU_ASSERT(g_lvserrno == 0);
796 	g_lvol_store = NULL;
797 
798 	free_dev(&dev);
799 }
800 
801 static void
802 lvol_destroy_fail(void)
803 {
804 	struct lvol_ut_bs_dev dev;
805 	struct spdk_lvs_opts opts;
806 	int rc = 0;
807 
808 	init_dev(&dev);
809 
810 	spdk_lvs_opts_init(&opts);
811 	snprintf(opts.name, sizeof(opts.name), "lvs");
812 
813 	rc = spdk_lvs_init(&dev.bs_dev, &opts, lvol_store_op_with_handle_complete, NULL);
814 	CU_ASSERT(rc == 0);
815 	CU_ASSERT(g_lvserrno == 0);
816 	SPDK_CU_ASSERT_FATAL(g_lvol_store != NULL);
817 
818 	spdk_lvol_create(g_lvol_store, "lvol", 10, false, LVOL_CLEAR_WITH_DEFAULT,
819 			 lvol_op_with_handle_complete, NULL);
820 	CU_ASSERT(g_lvserrno == 0);
821 	SPDK_CU_ASSERT_FATAL(g_lvol != NULL);
822 
823 	spdk_lvol_close(g_lvol, op_complete, NULL);
824 	CU_ASSERT(g_lvserrno == 0);
825 	spdk_lvol_destroy(g_lvol, op_complete, NULL);
826 	CU_ASSERT(g_lvserrno == 0);
827 
828 	spdk_lvol_create(g_lvol_store, "lvol", 10, false, LVOL_CLEAR_WITH_DEFAULT,
829 			 lvol_op_with_handle_complete, NULL);
830 	CU_ASSERT(g_lvserrno == 0);
831 	SPDK_CU_ASSERT_FATAL(g_lvol != NULL);
832 
833 	spdk_lvol_close(g_lvol, op_complete, NULL);
834 	CU_ASSERT(g_lvserrno == 0);
835 
836 	g_remove_rc = -1;
837 	spdk_lvol_destroy(g_lvol, op_complete, NULL);
838 	CU_ASSERT(g_lvserrno != 0);
839 	CU_ASSERT(TAILQ_EMPTY(&g_lvol_store->lvols));
840 	g_remove_rc = 0;
841 
842 	g_lvserrno = -1;
843 	rc = spdk_lvs_unload(g_lvol_store, op_complete, NULL);
844 	CU_ASSERT(rc == 0);
845 	CU_ASSERT(g_lvserrno == 0);
846 	g_lvol_store = NULL;
847 
848 	free_dev(&dev);
849 }
850 
851 static void
852 lvol_close_fail(void)
853 {
854 	struct lvol_ut_bs_dev dev;
855 	struct spdk_lvs_opts opts;
856 	int rc = 0;
857 
858 	init_dev(&dev);
859 
860 	spdk_lvs_opts_init(&opts);
861 	snprintf(opts.name, sizeof(opts.name), "lvs");
862 
863 	rc = spdk_lvs_init(&dev.bs_dev, &opts, lvol_store_op_with_handle_complete, NULL);
864 	CU_ASSERT(rc == 0);
865 	CU_ASSERT(g_lvserrno == 0);
866 	SPDK_CU_ASSERT_FATAL(g_lvol_store != NULL);
867 
868 	spdk_lvol_create(g_lvol_store, "lvol", 10, false, LVOL_CLEAR_WITH_DEFAULT,
869 			 lvol_op_with_handle_complete, NULL);
870 	CU_ASSERT(g_lvserrno == 0);
871 	SPDK_CU_ASSERT_FATAL(g_lvol != NULL);
872 
873 	spdk_lvol_close(g_lvol, op_complete, NULL);
874 	CU_ASSERT(g_lvserrno == 0);
875 
876 	g_lvserrno = -1;
877 	rc = spdk_lvs_unload(g_lvol_store, op_complete, NULL);
878 	CU_ASSERT(rc == 0);
879 	CU_ASSERT(g_lvserrno == 0);
880 	g_lvol_store = NULL;
881 
882 	free_dev(&dev);
883 }
884 
885 static void
886 lvol_close_success(void)
887 {
888 	struct lvol_ut_bs_dev dev;
889 	struct spdk_lvs_opts opts;
890 	int rc = 0;
891 
892 	init_dev(&dev);
893 
894 	spdk_lvs_opts_init(&opts);
895 	snprintf(opts.name, sizeof(opts.name), "lvs");
896 
897 	g_lvserrno = -1;
898 	rc = spdk_lvs_init(&dev.bs_dev, &opts, lvol_store_op_with_handle_complete, NULL);
899 	CU_ASSERT(rc == 0);
900 	CU_ASSERT(g_lvserrno == 0);
901 	SPDK_CU_ASSERT_FATAL(g_lvol_store != NULL);
902 
903 	spdk_lvol_create(g_lvol_store, "lvol", 10, false, LVOL_CLEAR_WITH_DEFAULT,
904 			 lvol_op_with_handle_complete, NULL);
905 	CU_ASSERT(g_lvserrno == 0);
906 	SPDK_CU_ASSERT_FATAL(g_lvol != NULL);
907 
908 	spdk_lvol_close(g_lvol, op_complete, NULL);
909 	CU_ASSERT(g_lvserrno == 0);
910 
911 	g_lvserrno = -1;
912 	rc = spdk_lvs_unload(g_lvol_store, op_complete, NULL);
913 	CU_ASSERT(rc == 0);
914 	CU_ASSERT(g_lvserrno == 0);
915 	g_lvol_store = NULL;
916 
917 	free_dev(&dev);
918 }
919 
920 static void
921 lvol_resize(void)
922 {
923 	struct lvol_ut_bs_dev dev;
924 	struct spdk_lvs_opts opts;
925 	int rc = 0;
926 
927 	init_dev(&dev);
928 
929 	spdk_lvs_opts_init(&opts);
930 	snprintf(opts.name, sizeof(opts.name), "lvs");
931 
932 	g_resize_rc = 0;
933 	g_lvserrno = -1;
934 	rc = spdk_lvs_init(&dev.bs_dev, &opts, lvol_store_op_with_handle_complete, NULL);
935 	CU_ASSERT(rc == 0);
936 	CU_ASSERT(g_lvserrno == 0);
937 	SPDK_CU_ASSERT_FATAL(g_lvol_store != NULL);
938 
939 	spdk_lvol_create(g_lvol_store, "lvol", 10, false, LVOL_CLEAR_WITH_DEFAULT,
940 			 lvol_op_with_handle_complete, NULL);
941 	CU_ASSERT(g_lvserrno == 0);
942 	SPDK_CU_ASSERT_FATAL(g_lvol != NULL);
943 
944 	/* Resize to same size */
945 	spdk_lvol_resize(g_lvol, 10, op_complete, NULL);
946 	CU_ASSERT(g_lvserrno == 0);
947 
948 	/* Resize to smaller size */
949 	spdk_lvol_resize(g_lvol, 5, op_complete, NULL);
950 	CU_ASSERT(g_lvserrno == 0);
951 
952 	/* Resize to bigger size */
953 	spdk_lvol_resize(g_lvol, 15, op_complete, NULL);
954 	CU_ASSERT(g_lvserrno == 0);
955 
956 	/* Resize to size = 0 */
957 	spdk_lvol_resize(g_lvol, 0, op_complete, NULL);
958 	CU_ASSERT(g_lvserrno == 0);
959 
960 	/* Resize to bigger size than available */
961 	g_lvserrno = 0;
962 	spdk_lvol_resize(g_lvol, 0xFFFFFFFF, op_complete, NULL);
963 	CU_ASSERT(g_lvserrno != 0);
964 
965 	/* Fail resize */
966 	g_resize_rc = -1;
967 	g_lvserrno = 0;
968 	spdk_lvol_resize(g_lvol, 10, op_complete, NULL);
969 	CU_ASSERT(g_lvserrno != 0);
970 	g_resize_rc = 0;
971 
972 	g_resize_rc = 0;
973 	spdk_lvol_close(g_lvol, op_complete, NULL);
974 	CU_ASSERT(g_lvserrno == 0);
975 	spdk_lvol_destroy(g_lvol, op_complete, NULL);
976 	CU_ASSERT(g_lvserrno == 0);
977 
978 	g_lvserrno = -1;
979 	rc = spdk_lvs_unload(g_lvol_store, op_complete, NULL);
980 	CU_ASSERT(rc == 0);
981 	CU_ASSERT(g_lvserrno == 0);
982 	g_lvol_store = NULL;
983 
984 	free_dev(&dev);
985 }
986 
987 static void
988 lvol_set_read_only(void)
989 {
990 	struct lvol_ut_bs_dev dev;
991 	struct spdk_lvs_opts opts;
992 	int rc = 0;
993 	struct spdk_lvol *lvol, *clone;
994 
995 	init_dev(&dev);
996 
997 	spdk_lvs_opts_init(&opts);
998 	snprintf(opts.name, sizeof(opts.name), "lvs");
999 
1000 	g_lvserrno = -1;
1001 	rc = spdk_lvs_init(&dev.bs_dev, &opts, lvol_store_op_with_handle_complete, NULL);
1002 	CU_ASSERT(rc == 0);
1003 	CU_ASSERT(g_lvserrno == 0);
1004 	SPDK_CU_ASSERT_FATAL(g_lvol_store != NULL);
1005 
1006 	spdk_lvol_create(g_lvol_store, "lvol", 10, false, LVOL_CLEAR_WITH_DEFAULT,
1007 			 lvol_op_with_handle_complete, NULL);
1008 	CU_ASSERT(g_lvserrno == 0);
1009 	SPDK_CU_ASSERT_FATAL(g_lvol != NULL);
1010 	lvol = g_lvol;
1011 
1012 	/* Set lvol as read only */
1013 	spdk_lvol_set_read_only(lvol, op_complete, NULL);
1014 	CU_ASSERT(g_lvserrno == 0);
1015 
1016 	/* Create lvol clone from read only lvol */
1017 	spdk_lvol_create_clone(lvol, "clone", lvol_op_with_handle_complete, NULL);
1018 	CU_ASSERT(g_lvserrno == 0);
1019 	SPDK_CU_ASSERT_FATAL(g_lvol != NULL);
1020 	CU_ASSERT_STRING_EQUAL(g_lvol->name, "clone");
1021 	clone = g_lvol;
1022 
1023 	spdk_lvol_close(lvol, op_complete, NULL);
1024 	CU_ASSERT(g_lvserrno == 0);
1025 	spdk_lvol_close(clone, op_complete, NULL);
1026 	CU_ASSERT(g_lvserrno == 0);
1027 
1028 	g_lvserrno = -1;
1029 	rc = spdk_lvs_unload(g_lvol_store, op_complete, NULL);
1030 	CU_ASSERT(rc == 0);
1031 	CU_ASSERT(g_lvserrno == 0);
1032 	g_lvol_store = NULL;
1033 
1034 	free_dev(&dev);
1035 }
1036 
1037 static void
1038 null_cb(void *ctx, struct spdk_blob_store *bs, int bserrno)
1039 {
1040 	SPDK_CU_ASSERT_FATAL(bs != NULL);
1041 }
1042 
1043 static void
1044 lvs_load(void)
1045 {
1046 	int rc = -1;
1047 	struct lvol_ut_bs_dev dev;
1048 	struct spdk_lvs_with_handle_req *req;
1049 	struct spdk_bs_opts bs_opts = {};
1050 	struct spdk_blob *super_blob;
1051 
1052 	req = calloc(1, sizeof(*req));
1053 	SPDK_CU_ASSERT_FATAL(req != NULL);
1054 
1055 	init_dev(&dev);
1056 	spdk_bs_opts_init(&bs_opts);
1057 	snprintf(bs_opts.bstype.bstype, sizeof(bs_opts.bstype.bstype), "LVOLSTORE");
1058 	spdk_bs_init(&dev.bs_dev, &bs_opts, null_cb, NULL);
1059 	SPDK_CU_ASSERT_FATAL(dev.bs != NULL);
1060 
1061 	/* Fail on bs load */
1062 	dev.load_status = -1;
1063 	CU_ASSERT(TAILQ_EMPTY(&g_lvol_stores));
1064 	spdk_lvs_load(&dev.bs_dev, lvol_store_op_with_handle_complete, req);
1065 	CU_ASSERT(g_lvserrno != 0);
1066 	CU_ASSERT(g_lvol_store == NULL);
1067 	CU_ASSERT(TAILQ_EMPTY(&g_lvol_stores));
1068 
1069 	/* Fail on getting super blob */
1070 	dev.load_status = 0;
1071 	dev.bs->get_super_status = -1;
1072 	spdk_lvs_load(&dev.bs_dev, lvol_store_op_with_handle_complete, req);
1073 	CU_ASSERT(g_lvserrno == -ENODEV);
1074 	CU_ASSERT(g_lvol_store == NULL);
1075 	CU_ASSERT(TAILQ_EMPTY(&g_lvol_stores));
1076 
1077 	/* Fail on opening super blob */
1078 	g_lvserrno = 0;
1079 	super_blob = calloc(1, sizeof(*super_blob));
1080 	super_blob->id = 0x100;
1081 	super_blob->open_status = -1;
1082 	TAILQ_INSERT_TAIL(&dev.bs->blobs, super_blob, link);
1083 	dev.bs->super_blobid = 0x100;
1084 	dev.bs->get_super_status = 0;
1085 	spdk_lvs_load(&dev.bs_dev, lvol_store_op_with_handle_complete, req);
1086 	CU_ASSERT(g_lvserrno == -ENODEV);
1087 	CU_ASSERT(g_lvol_store == NULL);
1088 	CU_ASSERT(TAILQ_EMPTY(&g_lvol_stores));
1089 
1090 	/* Fail on getting uuid */
1091 	g_lvserrno = 0;
1092 	super_blob->open_status = 0;
1093 	spdk_lvs_load(&dev.bs_dev, lvol_store_op_with_handle_complete, req);
1094 	CU_ASSERT(g_lvserrno == -EINVAL);
1095 	CU_ASSERT(g_lvol_store == NULL);
1096 	CU_ASSERT(TAILQ_EMPTY(&g_lvol_stores));
1097 
1098 	/* Fail on getting name */
1099 	g_lvserrno = 0;
1100 	spdk_blob_set_xattr(super_blob, "uuid", uuid, SPDK_UUID_STRING_LEN);
1101 	spdk_lvs_load(&dev.bs_dev, lvol_store_op_with_handle_complete, req);
1102 	CU_ASSERT(g_lvserrno == -EINVAL);
1103 	CU_ASSERT(g_lvol_store == NULL);
1104 	CU_ASSERT(TAILQ_EMPTY(&g_lvol_stores));
1105 
1106 	/* Fail on closing super blob */
1107 	g_lvserrno = 0;
1108 	spdk_blob_set_xattr(super_blob, "name", "lvs", strnlen("lvs", SPDK_LVS_NAME_MAX) + 1);
1109 	super_blob->close_status = -1;
1110 	spdk_lvs_load(&dev.bs_dev, lvol_store_op_with_handle_complete, req);
1111 	CU_ASSERT(g_lvserrno == -ENODEV);
1112 	CU_ASSERT(g_lvol_store == NULL);
1113 	CU_ASSERT(TAILQ_EMPTY(&g_lvol_stores));
1114 
1115 	/* Load successfully */
1116 	g_lvserrno = 0;
1117 	super_blob->close_status = 0;
1118 	spdk_lvs_load(&dev.bs_dev, lvol_store_op_with_handle_complete, req);
1119 	CU_ASSERT(g_lvserrno == 0);
1120 	CU_ASSERT(g_lvol_store != NULL);
1121 	CU_ASSERT(!TAILQ_EMPTY(&g_lvol_stores));
1122 
1123 	g_lvserrno = -1;
1124 	rc = spdk_lvs_unload(g_lvol_store, op_complete, NULL);
1125 	CU_ASSERT(rc == 0);
1126 	CU_ASSERT(g_lvserrno == 0);
1127 	CU_ASSERT(TAILQ_EMPTY(&g_lvol_stores));
1128 
1129 	free(req);
1130 	free_dev(&dev);
1131 }
1132 
1133 static void
1134 lvols_load(void)
1135 {
1136 	int rc = -1;
1137 	struct lvol_ut_bs_dev dev;
1138 	struct spdk_lvs_with_handle_req *req;
1139 	struct spdk_bs_opts bs_opts;
1140 	struct spdk_blob *super_blob, *blob1, *blob2, *blob3;
1141 
1142 	req = calloc(1, sizeof(*req));
1143 	SPDK_CU_ASSERT_FATAL(req != NULL);
1144 
1145 	init_dev(&dev);
1146 	spdk_bs_opts_init(&bs_opts);
1147 	snprintf(bs_opts.bstype.bstype, sizeof(bs_opts.bstype.bstype), "LVOLSTORE");
1148 	spdk_bs_init(&dev.bs_dev, &bs_opts, null_cb, NULL);
1149 	super_blob = calloc(1, sizeof(*super_blob));
1150 	SPDK_CU_ASSERT_FATAL(super_blob != NULL);
1151 	super_blob->id = 0x100;
1152 	spdk_blob_set_xattr(super_blob, "uuid", uuid, SPDK_UUID_STRING_LEN);
1153 	spdk_blob_set_xattr(super_blob, "name", "lvs", strnlen("lvs", SPDK_LVS_NAME_MAX) + 1);
1154 	TAILQ_INSERT_TAIL(&dev.bs->blobs, super_blob, link);
1155 	dev.bs->super_blobid = 0x100;
1156 
1157 	/*
1158 	 * Create 3 blobs, write different char values to the last char in the UUID
1159 	 *  to make sure they are unique.
1160 	 */
1161 	blob1 = calloc(1, sizeof(*blob1));
1162 	SPDK_CU_ASSERT_FATAL(blob1 != NULL);
1163 	blob1->id = 0x1;
1164 	spdk_blob_set_xattr(blob1, "uuid", uuid, SPDK_UUID_STRING_LEN);
1165 	spdk_blob_set_xattr(blob1, "name", "lvol1", strnlen("lvol1", SPDK_LVOL_NAME_MAX) + 1);
1166 	blob1->uuid[SPDK_UUID_STRING_LEN - 2] = '1';
1167 
1168 	blob2 = calloc(1, sizeof(*blob2));
1169 	SPDK_CU_ASSERT_FATAL(blob2 != NULL);
1170 	blob2->id = 0x2;
1171 	spdk_blob_set_xattr(blob2, "uuid", uuid, SPDK_UUID_STRING_LEN);
1172 	spdk_blob_set_xattr(blob2, "name", "lvol2", strnlen("lvol2", SPDK_LVOL_NAME_MAX) + 1);
1173 	blob2->uuid[SPDK_UUID_STRING_LEN - 2] = '2';
1174 
1175 	blob3 = calloc(1, sizeof(*blob3));
1176 	SPDK_CU_ASSERT_FATAL(blob3 != NULL);
1177 	blob3->id = 0x2;
1178 	spdk_blob_set_xattr(blob3, "uuid", uuid, SPDK_UUID_STRING_LEN);
1179 	spdk_blob_set_xattr(blob3, "name", "lvol3", strnlen("lvol3", SPDK_LVOL_NAME_MAX) + 1);
1180 	blob3->uuid[SPDK_UUID_STRING_LEN - 2] = '3';
1181 
1182 	/* Load lvs with 0 blobs */
1183 	g_lvserrno = 0;
1184 	spdk_lvs_load(&dev.bs_dev, lvol_store_op_with_handle_complete, req);
1185 	CU_ASSERT(g_lvserrno == 0);
1186 	CU_ASSERT(g_lvol_store != NULL);
1187 	CU_ASSERT(g_lvserrno == 0);
1188 
1189 	g_lvserrno = -1;
1190 	rc = spdk_lvs_unload(g_lvol_store, op_complete, NULL);
1191 	CU_ASSERT(rc == 0);
1192 	CU_ASSERT(g_lvserrno == 0);
1193 
1194 	TAILQ_INSERT_TAIL(&dev.bs->blobs, blob1, link);
1195 	TAILQ_INSERT_TAIL(&dev.bs->blobs, blob2, link);
1196 	TAILQ_INSERT_TAIL(&dev.bs->blobs, blob3, link);
1197 
1198 	/* Load lvs again with 3 blobs, but fail on 1st one */
1199 	g_lvol_store = NULL;
1200 	g_lvserrno = 0;
1201 	blob1->load_status = -1;
1202 	spdk_lvs_load(&dev.bs_dev, lvol_store_op_with_handle_complete, req);
1203 	CU_ASSERT(g_lvserrno != 0);
1204 	CU_ASSERT(g_lvol_store == NULL);
1205 
1206 	/* Load lvs again with 3 blobs, but fail on 3rd one */
1207 	g_lvol_store = NULL;
1208 	g_lvserrno = 0;
1209 	blob1->load_status = 0;
1210 	blob2->load_status = 0;
1211 	blob3->load_status = -1;
1212 	spdk_lvs_load(&dev.bs_dev, lvol_store_op_with_handle_complete, req);
1213 	CU_ASSERT(g_lvserrno != 0);
1214 	CU_ASSERT(g_lvol_store == NULL);
1215 
1216 	/* Load lvs again with 3 blobs, with success */
1217 	g_lvol_store = NULL;
1218 	g_lvserrno = 0;
1219 	blob1->load_status = 0;
1220 	blob2->load_status = 0;
1221 	blob3->load_status = 0;
1222 	spdk_lvs_load(&dev.bs_dev, lvol_store_op_with_handle_complete, req);
1223 	CU_ASSERT(g_lvserrno == 0);
1224 	SPDK_CU_ASSERT_FATAL(g_lvol_store != NULL);
1225 	CU_ASSERT(!TAILQ_EMPTY(&g_lvol_store->lvols));
1226 
1227 	g_lvserrno = -1;
1228 	/* rc = */ spdk_lvs_unload(g_lvol_store, op_complete, NULL);
1229 	/*
1230 	 * Disable these two asserts for now.  lvolstore should allow unload as long
1231 	 *  as the lvols were not opened - but this is coming a future patch.
1232 	 */
1233 	/* CU_ASSERT(rc == 0); */
1234 	/* CU_ASSERT(g_lvserrno == 0); */
1235 
1236 	free(req);
1237 	free_dev(&dev);
1238 }
1239 
1240 static void
1241 lvol_open(void)
1242 {
1243 	struct lvol_ut_bs_dev dev;
1244 	struct spdk_lvs_with_handle_req *req;
1245 	struct spdk_bs_opts bs_opts;
1246 	struct spdk_blob *super_blob, *blob1, *blob2, *blob3;
1247 	struct spdk_lvol *lvol, *tmp;
1248 
1249 	req = calloc(1, sizeof(*req));
1250 	SPDK_CU_ASSERT_FATAL(req != NULL);
1251 
1252 	init_dev(&dev);
1253 	spdk_bs_opts_init(&bs_opts);
1254 	snprintf(bs_opts.bstype.bstype, sizeof(bs_opts.bstype.bstype), "LVOLSTORE");
1255 	spdk_bs_init(&dev.bs_dev, &bs_opts, null_cb, NULL);
1256 	super_blob = calloc(1, sizeof(*super_blob));
1257 	SPDK_CU_ASSERT_FATAL(super_blob != NULL);
1258 	super_blob->id = 0x100;
1259 	spdk_blob_set_xattr(super_blob, "uuid", uuid, SPDK_UUID_STRING_LEN);
1260 	spdk_blob_set_xattr(super_blob, "name", "lvs", strnlen("lvs", SPDK_LVS_NAME_MAX) + 1);
1261 	TAILQ_INSERT_TAIL(&dev.bs->blobs, super_blob, link);
1262 	dev.bs->super_blobid = 0x100;
1263 
1264 	/*
1265 	 * Create 3 blobs, write different char values to the last char in the UUID
1266 	 *  to make sure they are unique.
1267 	 */
1268 	blob1 = calloc(1, sizeof(*blob1));
1269 	SPDK_CU_ASSERT_FATAL(blob1 != NULL);
1270 	blob1->id = 0x1;
1271 	spdk_blob_set_xattr(blob1, "uuid", uuid, SPDK_UUID_STRING_LEN);
1272 	spdk_blob_set_xattr(blob1, "name", "lvol1", strnlen("lvol1", SPDK_LVOL_NAME_MAX) + 1);
1273 	blob1->uuid[SPDK_UUID_STRING_LEN - 2] = '1';
1274 
1275 	blob2 = calloc(1, sizeof(*blob2));
1276 	SPDK_CU_ASSERT_FATAL(blob2 != NULL);
1277 	blob2->id = 0x2;
1278 	spdk_blob_set_xattr(blob2, "uuid", uuid, SPDK_UUID_STRING_LEN);
1279 	spdk_blob_set_xattr(blob2, "name", "lvol2", strnlen("lvol2", SPDK_LVOL_NAME_MAX) + 1);
1280 	blob2->uuid[SPDK_UUID_STRING_LEN - 2] = '2';
1281 
1282 	blob3 = calloc(1, sizeof(*blob3));
1283 	SPDK_CU_ASSERT_FATAL(blob3 != NULL);
1284 	blob3->id = 0x2;
1285 	spdk_blob_set_xattr(blob3, "uuid", uuid, SPDK_UUID_STRING_LEN);
1286 	spdk_blob_set_xattr(blob3, "name", "lvol3", strnlen("lvol3", SPDK_LVOL_NAME_MAX) + 1);
1287 	blob3->uuid[SPDK_UUID_STRING_LEN - 2] = '3';
1288 
1289 	TAILQ_INSERT_TAIL(&dev.bs->blobs, blob1, link);
1290 	TAILQ_INSERT_TAIL(&dev.bs->blobs, blob2, link);
1291 	TAILQ_INSERT_TAIL(&dev.bs->blobs, blob3, link);
1292 
1293 	/* Load lvs with 3 blobs */
1294 	g_lvol_store = NULL;
1295 	g_lvserrno = 0;
1296 	spdk_lvs_load(&dev.bs_dev, lvol_store_op_with_handle_complete, req);
1297 	CU_ASSERT(g_lvserrno == 0);
1298 	SPDK_CU_ASSERT_FATAL(g_lvol_store != NULL);
1299 	SPDK_CU_ASSERT_FATAL(!TAILQ_EMPTY(&g_lvol_stores));
1300 
1301 	blob1->open_status = -1;
1302 	blob2->open_status = -1;
1303 	blob3->open_status = -1;
1304 
1305 	/* Fail opening all lvols */
1306 	TAILQ_FOREACH_SAFE(lvol, &g_lvol_store->lvols, link, tmp) {
1307 		spdk_lvol_open(lvol, lvol_op_with_handle_complete, NULL);
1308 		CU_ASSERT(g_lvserrno != 0);
1309 	}
1310 
1311 	blob1->open_status = 0;
1312 	blob2->open_status = 0;
1313 	blob3->open_status = 0;
1314 
1315 	/* Open all lvols */
1316 	TAILQ_FOREACH_SAFE(lvol, &g_lvol_store->lvols, link, tmp) {
1317 		spdk_lvol_open(lvol, lvol_op_with_handle_complete, NULL);
1318 		CU_ASSERT(g_lvserrno == 0);
1319 	}
1320 
1321 	/* Close all lvols */
1322 	TAILQ_FOREACH_SAFE(lvol, &g_lvol_store->lvols, link, tmp) {
1323 		spdk_lvol_close(lvol, op_complete, NULL);
1324 		CU_ASSERT(g_lvserrno == 0);
1325 	}
1326 
1327 	g_lvserrno = -1;
1328 	spdk_lvs_destroy(g_lvol_store, op_complete, NULL);
1329 
1330 	free(req);
1331 	free(blob1);
1332 	free(blob2);
1333 	free(blob3);
1334 }
1335 
1336 static void
1337 lvol_snapshot(void)
1338 {
1339 	struct lvol_ut_bs_dev dev;
1340 	struct spdk_lvol *lvol;
1341 	struct spdk_lvs_opts opts;
1342 	int rc = 0;
1343 
1344 	init_dev(&dev);
1345 
1346 	spdk_lvs_opts_init(&opts);
1347 	snprintf(opts.name, sizeof(opts.name), "lvs");
1348 
1349 	g_lvserrno = -1;
1350 	rc = spdk_lvs_init(&dev.bs_dev, &opts, lvol_store_op_with_handle_complete, NULL);
1351 	CU_ASSERT(rc == 0);
1352 	CU_ASSERT(g_lvserrno == 0);
1353 	SPDK_CU_ASSERT_FATAL(g_lvol_store != NULL);
1354 
1355 	spdk_lvol_create(g_lvol_store, "lvol", 10, true, LVOL_CLEAR_WITH_DEFAULT,
1356 			 lvol_op_with_handle_complete, NULL);
1357 	CU_ASSERT(g_lvserrno == 0);
1358 	SPDK_CU_ASSERT_FATAL(g_lvol != NULL);
1359 
1360 	lvol = g_lvol;
1361 
1362 	spdk_lvol_create_snapshot(lvol, "snap", lvol_op_with_handle_complete, NULL);
1363 	CU_ASSERT(g_lvserrno == 0);
1364 	SPDK_CU_ASSERT_FATAL(g_lvol != NULL);
1365 	CU_ASSERT_STRING_EQUAL(g_lvol->name, "snap");
1366 
1367 	/* Lvol has to be closed (or destroyed) before unloading lvol store. */
1368 	spdk_lvol_close(g_lvol, op_complete, NULL);
1369 	CU_ASSERT(g_lvserrno == 0);
1370 	g_lvserrno = -1;
1371 
1372 	spdk_lvol_close(lvol, op_complete, NULL);
1373 	CU_ASSERT(g_lvserrno == 0);
1374 	g_lvserrno = -1;
1375 
1376 	rc = spdk_lvs_unload(g_lvol_store, op_complete, NULL);
1377 	CU_ASSERT(rc == 0);
1378 	CU_ASSERT(g_lvserrno == 0);
1379 	g_lvol_store = NULL;
1380 
1381 	free_dev(&dev);
1382 }
1383 
1384 static void
1385 lvol_snapshot_fail(void)
1386 {
1387 	struct lvol_ut_bs_dev dev;
1388 	struct spdk_lvol *lvol, *snap;
1389 	struct spdk_lvs_opts opts;
1390 	int rc = 0;
1391 
1392 	init_dev(&dev);
1393 
1394 	spdk_lvs_opts_init(&opts);
1395 	snprintf(opts.name, sizeof(opts.name), "lvs");
1396 
1397 	g_lvserrno = -1;
1398 	rc = spdk_lvs_init(&dev.bs_dev, &opts, lvol_store_op_with_handle_complete, NULL);
1399 	CU_ASSERT(rc == 0);
1400 	CU_ASSERT(g_lvserrno == 0);
1401 	SPDK_CU_ASSERT_FATAL(g_lvol_store != NULL);
1402 
1403 	spdk_lvol_create(g_lvol_store, "lvol", 10, true, LVOL_CLEAR_WITH_DEFAULT,
1404 			 lvol_op_with_handle_complete, NULL);
1405 	CU_ASSERT(g_lvserrno == 0);
1406 	SPDK_CU_ASSERT_FATAL(g_lvol != NULL);
1407 
1408 	lvol = g_lvol;
1409 
1410 	spdk_lvol_create_snapshot(NULL, "snap", lvol_op_with_handle_complete, NULL);
1411 	CU_ASSERT(g_lvserrno < 0);
1412 	SPDK_CU_ASSERT_FATAL(g_lvol == NULL);
1413 
1414 	spdk_lvol_create_snapshot(lvol, "", lvol_op_with_handle_complete, NULL);
1415 	CU_ASSERT(g_lvserrno < 0);
1416 	SPDK_CU_ASSERT_FATAL(g_lvol == NULL);
1417 
1418 	spdk_lvol_create_snapshot(lvol, NULL, lvol_op_with_handle_complete, NULL);
1419 	CU_ASSERT(g_lvserrno < 0);
1420 	SPDK_CU_ASSERT_FATAL(g_lvol == NULL);
1421 
1422 	spdk_lvol_create_snapshot(lvol, "snap", lvol_op_with_handle_complete, NULL);
1423 	CU_ASSERT(g_lvserrno == 0);
1424 	SPDK_CU_ASSERT_FATAL(g_lvol != NULL);
1425 	CU_ASSERT_STRING_EQUAL(g_lvol->name, "snap");
1426 
1427 	snap = g_lvol;
1428 
1429 	spdk_lvol_create_snapshot(lvol, "snap", lvol_op_with_handle_complete, NULL);
1430 	CU_ASSERT(g_lvserrno < 0);
1431 
1432 	spdk_lvol_close(lvol, op_complete, NULL);
1433 	CU_ASSERT(g_lvserrno == 0);
1434 	g_lvserrno = -1;
1435 
1436 	spdk_lvol_close(snap, op_complete, NULL);
1437 	CU_ASSERT(g_lvserrno == 0);
1438 	g_lvserrno = -1;
1439 
1440 	rc = spdk_lvs_unload(g_lvol_store, op_complete, NULL);
1441 	CU_ASSERT(rc == 0);
1442 	CU_ASSERT(g_lvserrno == 0);
1443 	g_lvol_store = NULL;
1444 
1445 	free_dev(&dev);
1446 }
1447 
1448 static void
1449 lvol_clone(void)
1450 {
1451 	struct lvol_ut_bs_dev dev;
1452 	struct spdk_lvol *lvol;
1453 	struct spdk_lvol *snap;
1454 	struct spdk_lvs_opts opts;
1455 	int rc = 0;
1456 
1457 	init_dev(&dev);
1458 
1459 	spdk_lvs_opts_init(&opts);
1460 	snprintf(opts.name, sizeof(opts.name), "lvs");
1461 
1462 	g_lvserrno = -1;
1463 	rc = spdk_lvs_init(&dev.bs_dev, &opts, lvol_store_op_with_handle_complete, NULL);
1464 	CU_ASSERT(rc == 0);
1465 	CU_ASSERT(g_lvserrno == 0);
1466 	SPDK_CU_ASSERT_FATAL(g_lvol_store != NULL);
1467 
1468 	spdk_lvol_create(g_lvol_store, "lvol", 10, true, LVOL_CLEAR_WITH_DEFAULT,
1469 			 lvol_op_with_handle_complete, NULL);
1470 	CU_ASSERT(g_lvserrno == 0);
1471 	SPDK_CU_ASSERT_FATAL(g_lvol != NULL);
1472 
1473 	lvol = g_lvol;
1474 
1475 	spdk_lvol_create_snapshot(lvol, "snap", lvol_op_with_handle_complete, NULL);
1476 	CU_ASSERT(g_lvserrno == 0);
1477 	SPDK_CU_ASSERT_FATAL(g_lvol != NULL);
1478 	CU_ASSERT_STRING_EQUAL(g_lvol->name, "snap");
1479 
1480 	snap = g_lvol;
1481 
1482 	spdk_lvol_create_clone(snap, "clone", lvol_op_with_handle_complete, NULL);
1483 	CU_ASSERT(g_lvserrno == 0);
1484 	SPDK_CU_ASSERT_FATAL(g_lvol != NULL);
1485 	CU_ASSERT_STRING_EQUAL(g_lvol->name, "clone");
1486 
1487 	/* Lvol has to be closed (or destroyed) before unloading lvol store. */
1488 	spdk_lvol_close(g_lvol, op_complete, NULL);
1489 	CU_ASSERT(g_lvserrno == 0);
1490 	g_lvserrno = -1;
1491 
1492 	spdk_lvol_close(snap, op_complete, NULL);
1493 	CU_ASSERT(g_lvserrno == 0);
1494 	g_lvserrno = -1;
1495 
1496 	spdk_lvol_close(lvol, op_complete, NULL);
1497 	CU_ASSERT(g_lvserrno == 0);
1498 	g_lvserrno = -1;
1499 
1500 	rc = spdk_lvs_unload(g_lvol_store, op_complete, NULL);
1501 	CU_ASSERT(rc == 0);
1502 	CU_ASSERT(g_lvserrno == 0);
1503 	g_lvol_store = NULL;
1504 
1505 	free_dev(&dev);
1506 }
1507 
1508 static void
1509 lvol_clone_fail(void)
1510 {
1511 	struct lvol_ut_bs_dev dev;
1512 	struct spdk_lvol *lvol;
1513 	struct spdk_lvol *snap;
1514 	struct spdk_lvol *clone;
1515 	struct spdk_lvs_opts opts;
1516 	int rc = 0;
1517 
1518 	init_dev(&dev);
1519 
1520 	spdk_lvs_opts_init(&opts);
1521 	snprintf(opts.name, sizeof(opts.name), "lvs");
1522 
1523 	g_lvserrno = -1;
1524 	rc = spdk_lvs_init(&dev.bs_dev, &opts, lvol_store_op_with_handle_complete, NULL);
1525 	CU_ASSERT(rc == 0);
1526 	CU_ASSERT(g_lvserrno == 0);
1527 	SPDK_CU_ASSERT_FATAL(g_lvol_store != NULL);
1528 
1529 	spdk_lvol_create(g_lvol_store, "lvol", 10, true, LVOL_CLEAR_WITH_DEFAULT,
1530 			 lvol_op_with_handle_complete, NULL);
1531 	CU_ASSERT(g_lvserrno == 0);
1532 	SPDK_CU_ASSERT_FATAL(g_lvol != NULL);
1533 
1534 	lvol = g_lvol;
1535 
1536 	spdk_lvol_create_snapshot(lvol, "snap", lvol_op_with_handle_complete, NULL);
1537 	CU_ASSERT(g_lvserrno == 0);
1538 	SPDK_CU_ASSERT_FATAL(g_lvol != NULL);
1539 	CU_ASSERT_STRING_EQUAL(g_lvol->name, "snap");
1540 
1541 	snap = g_lvol;
1542 
1543 	spdk_lvol_create_clone(NULL, "clone", lvol_op_with_handle_complete, NULL);
1544 	CU_ASSERT(g_lvserrno < 0);
1545 
1546 	spdk_lvol_create_clone(snap, "", lvol_op_with_handle_complete, NULL);
1547 	CU_ASSERT(g_lvserrno < 0);
1548 
1549 	spdk_lvol_create_clone(snap, NULL, lvol_op_with_handle_complete, NULL);
1550 	CU_ASSERT(g_lvserrno < 0);
1551 
1552 	spdk_lvol_create_clone(snap, "clone", lvol_op_with_handle_complete, NULL);
1553 	CU_ASSERT(g_lvserrno == 0);
1554 	SPDK_CU_ASSERT_FATAL(g_lvol != NULL);
1555 	CU_ASSERT_STRING_EQUAL(g_lvol->name, "clone");
1556 
1557 	clone = g_lvol;
1558 
1559 	spdk_lvol_create_clone(snap, "clone", lvol_op_with_handle_complete, NULL);
1560 	CU_ASSERT(g_lvserrno < 0);
1561 
1562 	/* Lvol has to be closed (or destroyed) before unloading lvol store. */
1563 	spdk_lvol_close(clone, op_complete, NULL);
1564 	CU_ASSERT(g_lvserrno == 0);
1565 	g_lvserrno = -1;
1566 
1567 	spdk_lvol_close(snap, op_complete, NULL);
1568 	CU_ASSERT(g_lvserrno == 0);
1569 	g_lvserrno = -1;
1570 
1571 	spdk_lvol_close(lvol, op_complete, NULL);
1572 	CU_ASSERT(g_lvserrno == 0);
1573 	g_lvserrno = -1;
1574 
1575 	rc = spdk_lvs_unload(g_lvol_store, op_complete, NULL);
1576 	CU_ASSERT(rc == 0);
1577 	CU_ASSERT(g_lvserrno == 0);
1578 	g_lvol_store = NULL;
1579 
1580 	free_dev(&dev);
1581 }
1582 
1583 static void
1584 lvol_names(void)
1585 {
1586 	struct lvol_ut_bs_dev dev;
1587 	struct spdk_lvs_opts opts;
1588 	struct spdk_lvol_store *lvs;
1589 	struct spdk_lvol *lvol, *lvol2;
1590 	char fullname[SPDK_LVOL_NAME_MAX];
1591 	int rc = 0;
1592 
1593 	init_dev(&dev);
1594 
1595 	spdk_lvs_opts_init(&opts);
1596 	snprintf(opts.name, sizeof(opts.name), "lvs");
1597 
1598 	g_lvserrno = -1;
1599 	g_lvol_store = NULL;
1600 	rc = spdk_lvs_init(&dev.bs_dev, &opts, lvol_store_op_with_handle_complete, NULL);
1601 	CU_ASSERT(rc == 0);
1602 	CU_ASSERT(g_lvserrno == 0);
1603 	SPDK_CU_ASSERT_FATAL(g_lvol_store != NULL);
1604 	lvs = g_lvol_store;
1605 
1606 	rc = spdk_lvol_create(lvs, NULL, 1, false, LVOL_CLEAR_WITH_DEFAULT, lvol_op_with_handle_complete,
1607 			      NULL);
1608 	CU_ASSERT(rc == -EINVAL);
1609 
1610 	rc = spdk_lvol_create(lvs, "", 1, false, LVOL_CLEAR_WITH_DEFAULT, lvol_op_with_handle_complete,
1611 			      NULL);
1612 	CU_ASSERT(rc == -EINVAL);
1613 
1614 	memset(fullname, 'x', sizeof(fullname));
1615 	rc = spdk_lvol_create(lvs, fullname, 1, false, LVOL_CLEAR_WITH_DEFAULT,
1616 			      lvol_op_with_handle_complete, NULL);
1617 	CU_ASSERT(rc == -EINVAL);
1618 
1619 	g_lvserrno = -1;
1620 	rc = spdk_lvol_create(lvs, "lvol", 1, false, LVOL_CLEAR_WITH_DEFAULT, lvol_op_with_handle_complete,
1621 			      NULL);
1622 	CU_ASSERT(rc == 0);
1623 	CU_ASSERT(g_lvserrno == 0);
1624 	SPDK_CU_ASSERT_FATAL(g_lvol != NULL);
1625 	lvol = g_lvol;
1626 
1627 	rc = spdk_lvol_create(lvs, "lvol", 1, false, LVOL_CLEAR_WITH_DEFAULT, lvol_op_with_handle_complete,
1628 			      NULL);
1629 	CU_ASSERT(rc == -EEXIST);
1630 
1631 	g_lvserrno = -1;
1632 	rc = spdk_lvol_create(lvs, "lvol2", 1, false, LVOL_CLEAR_WITH_DEFAULT, lvol_op_with_handle_complete,
1633 			      NULL);
1634 	CU_ASSERT(rc == 0);
1635 	CU_ASSERT(g_lvserrno == 0);
1636 	SPDK_CU_ASSERT_FATAL(g_lvol != NULL);
1637 	lvol2 = g_lvol;
1638 
1639 	spdk_lvol_close(lvol, op_complete, NULL);
1640 	spdk_lvol_destroy(lvol, op_complete, NULL);
1641 
1642 	g_lvserrno = -1;
1643 	g_lvol = NULL;
1644 	rc = spdk_lvol_create(lvs, "lvol", 1, false, LVOL_CLEAR_WITH_DEFAULT, lvol_op_with_handle_complete,
1645 			      NULL);
1646 	CU_ASSERT(rc == 0);
1647 	CU_ASSERT(g_lvserrno == 0);
1648 	SPDK_CU_ASSERT_FATAL(g_lvol != NULL);
1649 	lvol = g_lvol;
1650 
1651 	spdk_lvol_close(lvol, op_complete, NULL);
1652 	spdk_lvol_destroy(lvol, op_complete, NULL);
1653 
1654 	spdk_lvol_close(lvol2, op_complete, NULL);
1655 	spdk_lvol_destroy(lvol2, op_complete, NULL);
1656 
1657 	/* Simulate creating two lvols with same name simultaneously. */
1658 	lvol = calloc(1, sizeof(*lvol));
1659 	SPDK_CU_ASSERT_FATAL(lvol != NULL);
1660 	snprintf(lvol->name, sizeof(lvol->name), "tmp_name");
1661 	TAILQ_INSERT_TAIL(&lvs->pending_lvols, lvol, link);
1662 	rc = spdk_lvol_create(lvs, "tmp_name", 1, false, LVOL_CLEAR_WITH_DEFAULT,
1663 			      lvol_op_with_handle_complete, NULL);
1664 	CU_ASSERT(rc == -EEXIST);
1665 
1666 	/* Remove name from temporary list and try again. */
1667 	TAILQ_REMOVE(&lvs->pending_lvols, lvol, link);
1668 	free(lvol);
1669 
1670 	rc = spdk_lvol_create(lvs, "tmp_name", 1, false, LVOL_CLEAR_WITH_DEFAULT,
1671 			      lvol_op_with_handle_complete, NULL);
1672 	CU_ASSERT(rc == 0);
1673 	CU_ASSERT(g_lvserrno == 0);
1674 	SPDK_CU_ASSERT_FATAL(g_lvol != NULL);
1675 	lvol = g_lvol;
1676 
1677 	spdk_lvol_close(lvol, op_complete, NULL);
1678 	spdk_lvol_destroy(lvol, op_complete, NULL);
1679 
1680 	g_lvserrno = -1;
1681 	rc = spdk_lvs_destroy(lvs, op_complete, NULL);
1682 	CU_ASSERT(rc == 0);
1683 	CU_ASSERT(g_lvserrno == 0);
1684 	g_lvol_store = NULL;
1685 }
1686 
1687 static void
1688 lvol_rename(void)
1689 {
1690 	struct lvol_ut_bs_dev dev;
1691 	struct spdk_lvs_opts opts;
1692 	struct spdk_lvol_store *lvs;
1693 	struct spdk_lvol *lvol, *lvol2;
1694 	int rc = 0;
1695 
1696 	init_dev(&dev);
1697 
1698 	spdk_lvs_opts_init(&opts);
1699 	snprintf(opts.name, sizeof(opts.name), "lvs");
1700 
1701 	g_lvserrno = -1;
1702 	g_lvol_store = NULL;
1703 	rc = spdk_lvs_init(&dev.bs_dev, &opts, lvol_store_op_with_handle_complete, NULL);
1704 	CU_ASSERT(rc == 0);
1705 	CU_ASSERT(g_lvserrno == 0);
1706 	SPDK_CU_ASSERT_FATAL(g_lvol_store != NULL);
1707 	lvs = g_lvol_store;
1708 
1709 	/* Trying to create new lvol */
1710 	g_lvserrno = -1;
1711 	rc = spdk_lvol_create(lvs, "lvol", 1, false, LVOL_CLEAR_WITH_DEFAULT, lvol_op_with_handle_complete,
1712 			      NULL);
1713 	CU_ASSERT(rc == 0);
1714 	CU_ASSERT(g_lvserrno == 0);
1715 	SPDK_CU_ASSERT_FATAL(g_lvol != NULL);
1716 	lvol = g_lvol;
1717 
1718 	/* Trying to create second lvol with existing lvol name */
1719 	g_lvserrno = -1;
1720 	g_lvol = NULL;
1721 	rc = spdk_lvol_create(lvs, "lvol", 1, false, LVOL_CLEAR_WITH_DEFAULT, lvol_op_with_handle_complete,
1722 			      NULL);
1723 	CU_ASSERT(rc == -EEXIST);
1724 	CU_ASSERT(g_lvserrno == -1);
1725 	SPDK_CU_ASSERT_FATAL(g_lvol == NULL);
1726 
1727 	/* Trying to create second lvol with non existing name */
1728 	g_lvserrno = -1;
1729 	rc = spdk_lvol_create(lvs, "lvol2", 1, false, LVOL_CLEAR_WITH_DEFAULT, lvol_op_with_handle_complete,
1730 			      NULL);
1731 	CU_ASSERT(rc == 0);
1732 	CU_ASSERT(g_lvserrno == 0);
1733 	SPDK_CU_ASSERT_FATAL(g_lvol != NULL);
1734 	lvol2 = g_lvol;
1735 
1736 	/* Trying to rename lvol with not existing name */
1737 	spdk_lvol_rename(lvol, "lvol_new", op_complete, NULL);
1738 	CU_ASSERT(g_lvserrno == 0);
1739 	CU_ASSERT_STRING_EQUAL(lvol->name, "lvol_new");
1740 
1741 	/* Trying to rename lvol with other lvol name */
1742 	spdk_lvol_rename(lvol2, "lvol_new", op_complete, NULL);
1743 	CU_ASSERT(g_lvserrno == -EEXIST);
1744 	CU_ASSERT_STRING_NOT_EQUAL(lvol2->name, "lvol_new");
1745 
1746 	spdk_lvol_close(lvol, op_complete, NULL);
1747 	spdk_lvol_destroy(lvol, op_complete, NULL);
1748 
1749 	spdk_lvol_close(lvol2, op_complete, NULL);
1750 	spdk_lvol_destroy(lvol2, op_complete, NULL);
1751 
1752 	g_lvserrno = -1;
1753 	rc = spdk_lvs_destroy(lvs, op_complete, NULL);
1754 	CU_ASSERT(rc == 0);
1755 	CU_ASSERT(g_lvserrno == 0);
1756 	g_lvol_store = NULL;
1757 }
1758 
1759 static void
1760 lvs_rename(void)
1761 {
1762 	struct lvol_ut_bs_dev dev;
1763 	struct spdk_lvs_opts opts;
1764 	struct spdk_lvol_store *lvs, *lvs2;
1765 	int rc = 0;
1766 
1767 	init_dev(&dev);
1768 
1769 	spdk_lvs_opts_init(&opts);
1770 	snprintf(opts.name, sizeof(opts.name), "lvs");
1771 	g_lvserrno = -1;
1772 	g_lvol_store = NULL;
1773 	rc = spdk_lvs_init(&dev.bs_dev, &opts, lvol_store_op_with_handle_complete, NULL);
1774 	CU_ASSERT(rc == 0);
1775 	CU_ASSERT(g_lvserrno == 0);
1776 	SPDK_CU_ASSERT_FATAL(g_lvol_store != NULL);
1777 	lvs = g_lvol_store;
1778 
1779 	spdk_lvs_opts_init(&opts);
1780 	snprintf(opts.name, sizeof(opts.name), "unimportant_lvs_name");
1781 	g_lvserrno = -1;
1782 	g_lvol_store = NULL;
1783 	rc = spdk_lvs_init(&dev.bs_dev, &opts, lvol_store_op_with_handle_complete, NULL);
1784 	CU_ASSERT(rc == 0);
1785 	CU_ASSERT(g_lvserrno == 0);
1786 	SPDK_CU_ASSERT_FATAL(g_lvol_store != NULL);
1787 	lvs2 = g_lvol_store;
1788 
1789 	/* Trying to rename lvs with new name */
1790 	spdk_lvs_rename(lvs, "new_lvs_name", op_complete, NULL);
1791 	CU_ASSERT(g_lvserrno == 0);
1792 	CU_ASSERT_STRING_EQUAL(lvs->name, "new_lvs_name");
1793 
1794 	/* Trying to rename lvs with name lvs already has */
1795 	spdk_lvs_rename(lvs, "new_lvs_name", op_complete, NULL);
1796 	CU_ASSERT(g_lvserrno == 0);
1797 	CU_ASSERT_STRING_EQUAL(lvs->name, "new_lvs_name");
1798 
1799 	/* Trying to rename lvs with name already existing */
1800 	spdk_lvs_rename(lvs2, "new_lvs_name", op_complete, NULL);
1801 	CU_ASSERT(g_lvserrno == -EEXIST);
1802 	CU_ASSERT_STRING_EQUAL(lvs2->name, "unimportant_lvs_name");
1803 
1804 	/* Trying to rename lvs with another rename process started with the same name */
1805 	/* Simulate renaming process in progress */
1806 	snprintf(lvs2->new_name, sizeof(lvs2->new_name), "another_new_lvs_name");
1807 	CU_ASSERT_STRING_EQUAL(lvs2->new_name, "another_new_lvs_name");
1808 	/* Start second process */
1809 	spdk_lvs_rename(lvs, "another_new_lvs_name", op_complete, NULL);
1810 	CU_ASSERT(g_lvserrno == -EEXIST);
1811 	CU_ASSERT_STRING_EQUAL(lvs->name, "new_lvs_name");
1812 	/* reverting lvs2 new name to proper value */
1813 	snprintf(lvs2->new_name, sizeof(lvs2->new_name), "unimportant_lvs_name");
1814 	CU_ASSERT_STRING_EQUAL(lvs2->new_name, "unimportant_lvs_name");
1815 
1816 	/* Simulate error while lvs rename */
1817 	g_lvs_rename_blob_open_error = true;
1818 	spdk_lvs_rename(lvs, "complete_new_lvs_name", op_complete, NULL);
1819 	CU_ASSERT(g_lvserrno != 0);
1820 	CU_ASSERT_STRING_EQUAL(lvs->name, "new_lvs_name");
1821 	CU_ASSERT_STRING_EQUAL(lvs->new_name, "new_lvs_name");
1822 	g_lvs_rename_blob_open_error = false;
1823 
1824 	g_lvserrno = -1;
1825 	rc = spdk_lvs_destroy(lvs, op_complete, NULL);
1826 	CU_ASSERT(rc == 0);
1827 	CU_ASSERT(g_lvserrno == 0);
1828 	g_lvol_store = NULL;
1829 
1830 	g_lvserrno = -1;
1831 	rc = spdk_lvs_destroy(lvs2, op_complete, NULL);
1832 	CU_ASSERT(rc == 0);
1833 	CU_ASSERT(g_lvserrno == 0);
1834 	g_lvol_store = NULL;
1835 }
1836 static void lvol_refcnt(void)
1837 {
1838 	struct lvol_ut_bs_dev dev;
1839 	struct spdk_lvs_opts opts;
1840 	struct spdk_lvol *lvol;
1841 	int rc = 0;
1842 
1843 	init_dev(&dev);
1844 
1845 	spdk_lvs_opts_init(&opts);
1846 	snprintf(opts.name, sizeof(opts.name), "lvs");
1847 
1848 	g_lvserrno = -1;
1849 	rc = spdk_lvs_init(&dev.bs_dev, &opts, lvol_store_op_with_handle_complete, NULL);
1850 	CU_ASSERT(rc == 0);
1851 	CU_ASSERT(g_lvserrno == 0);
1852 	SPDK_CU_ASSERT_FATAL(g_lvol_store != NULL);
1853 
1854 
1855 	spdk_lvol_create(g_lvol_store, "lvol", 10, false, LVOL_CLEAR_WITH_DEFAULT,
1856 			 lvol_op_with_handle_complete, NULL);
1857 
1858 	CU_ASSERT(g_lvserrno == 0);
1859 	SPDK_CU_ASSERT_FATAL(g_lvol != NULL);
1860 	CU_ASSERT(g_lvol->ref_count == 1);
1861 
1862 	lvol = g_lvol;
1863 	spdk_lvol_open(g_lvol, lvol_op_with_handle_complete, NULL);
1864 	SPDK_CU_ASSERT_FATAL(g_lvol != NULL);
1865 	CU_ASSERT(lvol->ref_count == 2);
1866 
1867 	/* Trying to destroy lvol while its open should fail */
1868 	spdk_lvol_destroy(lvol, op_complete, NULL);
1869 	CU_ASSERT(g_lvserrno != 0);
1870 
1871 	spdk_lvol_close(lvol, op_complete, NULL);
1872 	CU_ASSERT(lvol->ref_count == 1);
1873 	CU_ASSERT(g_lvserrno == 0);
1874 
1875 	spdk_lvol_close(lvol, op_complete, NULL);
1876 	CU_ASSERT(lvol->ref_count == 0);
1877 	CU_ASSERT(g_lvserrno == 0);
1878 
1879 	/* Try to close already closed lvol */
1880 	spdk_lvol_close(lvol, op_complete, NULL);
1881 	CU_ASSERT(lvol->ref_count == 0);
1882 	CU_ASSERT(g_lvserrno != 0);
1883 
1884 	g_lvserrno = -1;
1885 	rc = spdk_lvs_unload(g_lvol_store, op_complete, NULL);
1886 	CU_ASSERT(rc == 0);
1887 	CU_ASSERT(g_lvserrno == 0);
1888 	g_lvol_store = NULL;
1889 
1890 	CU_ASSERT(rc == 0);
1891 	CU_ASSERT(g_lvserrno == 0);
1892 	g_lvol_store = NULL;
1893 
1894 	free_dev(&dev);
1895 }
1896 
1897 static void
1898 lvol_create_thin_provisioned(void)
1899 {
1900 	struct lvol_ut_bs_dev dev;
1901 	struct spdk_lvs_opts opts;
1902 	int rc = 0;
1903 
1904 	init_dev(&dev);
1905 
1906 	spdk_lvs_opts_init(&opts);
1907 	snprintf(opts.name, sizeof(opts.name), "lvs");
1908 
1909 	g_lvserrno = -1;
1910 	rc = spdk_lvs_init(&dev.bs_dev, &opts, lvol_store_op_with_handle_complete, NULL);
1911 	CU_ASSERT(rc == 0);
1912 	CU_ASSERT(g_lvserrno == 0);
1913 	SPDK_CU_ASSERT_FATAL(g_lvol_store != NULL);
1914 
1915 	spdk_lvol_create(g_lvol_store, "lvol", 10, false, LVOL_CLEAR_WITH_DEFAULT,
1916 			 lvol_op_with_handle_complete, NULL);
1917 	CU_ASSERT(g_lvserrno == 0);
1918 	SPDK_CU_ASSERT_FATAL(g_lvol != NULL);
1919 
1920 	CU_ASSERT(g_lvol->blob->thin_provisioned == false);
1921 
1922 	spdk_lvol_close(g_lvol, op_complete, NULL);
1923 	CU_ASSERT(g_lvserrno == 0);
1924 	spdk_lvol_destroy(g_lvol, op_complete, NULL);
1925 	CU_ASSERT(g_lvserrno == 0);
1926 
1927 	spdk_lvol_create(g_lvol_store, "lvol", 10, true, LVOL_CLEAR_WITH_DEFAULT,
1928 			 lvol_op_with_handle_complete, NULL);
1929 	CU_ASSERT(g_lvserrno == 0);
1930 	SPDK_CU_ASSERT_FATAL(g_lvol != NULL);
1931 
1932 	CU_ASSERT(g_lvol->blob->thin_provisioned == true);
1933 
1934 	spdk_lvol_close(g_lvol, op_complete, NULL);
1935 	CU_ASSERT(g_lvserrno == 0);
1936 	spdk_lvol_destroy(g_lvol, op_complete, NULL);
1937 	CU_ASSERT(g_lvserrno == 0);
1938 
1939 	g_lvserrno = -1;
1940 	rc = spdk_lvs_unload(g_lvol_store, op_complete, NULL);
1941 	CU_ASSERT(rc == 0);
1942 	CU_ASSERT(g_lvserrno == 0);
1943 	g_lvol_store = NULL;
1944 
1945 	free_dev(&dev);
1946 }
1947 
1948 static void
1949 lvol_inflate(void)
1950 {
1951 	struct lvol_ut_bs_dev dev;
1952 	struct spdk_lvs_opts opts;
1953 	int rc = 0;
1954 
1955 	init_dev(&dev);
1956 
1957 	spdk_lvs_opts_init(&opts);
1958 	snprintf(opts.name, sizeof(opts.name), "lvs");
1959 
1960 	g_lvserrno = -1;
1961 	rc = spdk_lvs_init(&dev.bs_dev, &opts, lvol_store_op_with_handle_complete, NULL);
1962 	CU_ASSERT(rc == 0);
1963 	CU_ASSERT(g_lvserrno == 0);
1964 	SPDK_CU_ASSERT_FATAL(g_lvol_store != NULL);
1965 
1966 	spdk_lvol_create(g_lvol_store, "lvol", 10, false, LVOL_CLEAR_WITH_DEFAULT,
1967 			 lvol_op_with_handle_complete, NULL);
1968 	CU_ASSERT(g_lvserrno == 0);
1969 	SPDK_CU_ASSERT_FATAL(g_lvol != NULL);
1970 
1971 	g_inflate_rc = -1;
1972 	spdk_lvol_inflate(g_lvol, op_complete, NULL);
1973 	CU_ASSERT(g_lvserrno != 0);
1974 
1975 	g_inflate_rc = 0;
1976 	spdk_lvol_inflate(g_lvol, op_complete, NULL);
1977 	CU_ASSERT(g_lvserrno == 0);
1978 
1979 	spdk_lvol_close(g_lvol, op_complete, NULL);
1980 	CU_ASSERT(g_lvserrno == 0);
1981 	spdk_lvol_destroy(g_lvol, op_complete, NULL);
1982 	CU_ASSERT(g_lvserrno == 0);
1983 
1984 	g_lvserrno = -1;
1985 	rc = spdk_lvs_unload(g_lvol_store, op_complete, NULL);
1986 	CU_ASSERT(rc == 0);
1987 	CU_ASSERT(g_lvserrno == 0);
1988 	g_lvol_store = NULL;
1989 
1990 	free_dev(&dev);
1991 
1992 	/* Make sure that all references to the io_channel was closed after
1993 	 * inflate call
1994 	 */
1995 	CU_ASSERT(g_io_channel == NULL);
1996 }
1997 
1998 static void
1999 lvol_decouple_parent(void)
2000 {
2001 	struct lvol_ut_bs_dev dev;
2002 	struct spdk_lvs_opts opts;
2003 	int rc = 0;
2004 
2005 	init_dev(&dev);
2006 
2007 	spdk_lvs_opts_init(&opts);
2008 	snprintf(opts.name, sizeof(opts.name), "lvs");
2009 
2010 	g_lvserrno = -1;
2011 	rc = spdk_lvs_init(&dev.bs_dev, &opts, lvol_store_op_with_handle_complete, NULL);
2012 	CU_ASSERT(rc == 0);
2013 	CU_ASSERT(g_lvserrno == 0);
2014 	SPDK_CU_ASSERT_FATAL(g_lvol_store != NULL);
2015 
2016 	spdk_lvol_create(g_lvol_store, "lvol", 10, false, LVOL_CLEAR_WITH_DEFAULT,
2017 			 lvol_op_with_handle_complete, NULL);
2018 	CU_ASSERT(g_lvserrno == 0);
2019 	SPDK_CU_ASSERT_FATAL(g_lvol != NULL);
2020 
2021 	g_inflate_rc = -1;
2022 	spdk_lvol_decouple_parent(g_lvol, op_complete, NULL);
2023 	CU_ASSERT(g_lvserrno != 0);
2024 
2025 	g_inflate_rc = 0;
2026 	spdk_lvol_decouple_parent(g_lvol, op_complete, NULL);
2027 	CU_ASSERT(g_lvserrno == 0);
2028 
2029 	spdk_lvol_close(g_lvol, op_complete, NULL);
2030 	CU_ASSERT(g_lvserrno == 0);
2031 	spdk_lvol_destroy(g_lvol, op_complete, NULL);
2032 	CU_ASSERT(g_lvserrno == 0);
2033 
2034 	g_lvserrno = -1;
2035 	rc = spdk_lvs_unload(g_lvol_store, op_complete, NULL);
2036 	CU_ASSERT(rc == 0);
2037 	CU_ASSERT(g_lvserrno == 0);
2038 	g_lvol_store = NULL;
2039 
2040 	free_dev(&dev);
2041 
2042 	/* Make sure that all references to the io_channel was closed after
2043 	 * inflate call
2044 	 */
2045 	CU_ASSERT(g_io_channel == NULL);
2046 }
2047 
2048 int main(int argc, char **argv)
2049 {
2050 	CU_pSuite	suite = NULL;
2051 	unsigned int	num_failures;
2052 
2053 	CU_set_error_action(CUEA_ABORT);
2054 	CU_initialize_registry();
2055 
2056 	suite = CU_add_suite("lvol", NULL, NULL);
2057 
2058 	CU_ADD_TEST(suite, lvs_init_unload_success);
2059 	CU_ADD_TEST(suite, lvs_init_destroy_success);
2060 	CU_ADD_TEST(suite, lvs_init_opts_success);
2061 	CU_ADD_TEST(suite, lvs_unload_lvs_is_null_fail);
2062 	CU_ADD_TEST(suite, lvs_names);
2063 	CU_ADD_TEST(suite, lvol_create_destroy_success);
2064 	CU_ADD_TEST(suite, lvol_create_fail);
2065 	CU_ADD_TEST(suite, lvol_destroy_fail);
2066 	CU_ADD_TEST(suite, lvol_close_fail);
2067 	CU_ADD_TEST(suite, lvol_close_success);
2068 	CU_ADD_TEST(suite, lvol_resize);
2069 	CU_ADD_TEST(suite, lvol_set_read_only);
2070 	CU_ADD_TEST(suite, lvs_load);
2071 	CU_ADD_TEST(suite, lvols_load);
2072 	CU_ADD_TEST(suite, lvol_open);
2073 	CU_ADD_TEST(suite, lvol_snapshot);
2074 	CU_ADD_TEST(suite, lvol_snapshot_fail);
2075 	CU_ADD_TEST(suite, lvol_clone);
2076 	CU_ADD_TEST(suite, lvol_clone_fail);
2077 	CU_ADD_TEST(suite, lvol_refcnt);
2078 	CU_ADD_TEST(suite, lvol_names);
2079 	CU_ADD_TEST(suite, lvol_create_thin_provisioned);
2080 	CU_ADD_TEST(suite, lvol_rename);
2081 	CU_ADD_TEST(suite, lvs_rename);
2082 	CU_ADD_TEST(suite, lvol_inflate);
2083 	CU_ADD_TEST(suite, lvol_decouple_parent);
2084 
2085 	allocate_threads(1);
2086 	set_thread(0);
2087 
2088 	CU_basic_set_mode(CU_BRM_VERBOSE);
2089 	CU_basic_run_tests();
2090 	num_failures = CU_get_number_of_failures();
2091 	CU_cleanup_registry();
2092 
2093 	free_threads();
2094 
2095 	return num_failures;
2096 }
2097