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