1#!/bin/ksh -p
2#
3# This file and its contents are supplied under the terms of the
4# Common Development and Distribution License ("CDDL"), version 1.0.
5# You may only use this file in accordance with the terms of version
6# 1.0 of the CDDL.
7#
8# A full copy of the text of the CDDL should have accompanied this
9# source.  A copy of the CDDL is also available via the Internet at
10# http://www.illumos.org/license/CDDL.
11#
12
13#
14# Copyright (c) 2018 by Delphix. All rights reserved.
15#
16
17# DESCRIPTION
18# Verify that livelists tracking remapped blocks can be
19# properly destroyed.
20
21# STRATEGY
22# 1. Create a pool with disk1 and create a filesystem, snapshot
23# and clone. Write several files to the clone.
24# 2. Add disk2 to the pool and then remove disk1, triggering a
25# remap of the blkptrs tracked in the livelist.
26# 3. Delete the clone
27
28. $STF_SUITE/include/libtest.shlib
29. $STF_SUITE/tests/functional/removal/removal.kshlib
30
31function cleanup
32{
33	poolexists $TESTPOOL2 && zpool destroy $TESTPOOL2
34	[[ -f $VIRTUAL_DISK1 ]] && log_must rm $VIRTUAL_DISK1
35	[[ -f $VIRTUAL_DISK2 ]] && log_must rm $VIRTUAL_DISK2
36}
37
38log_onexit cleanup
39
40VIRTUAL_DISK1=$TEST_BASE_DIR/disk1
41VIRTUAL_DISK2=$TEST_BASE_DIR/disk2
42log_must truncate -s $(($MINVDEVSIZE * 8)) $VIRTUAL_DISK1
43log_must truncate -s $(($MINVDEVSIZE * 16)) $VIRTUAL_DISK2
44
45log_must zpool create $TESTPOOL2 $VIRTUAL_DISK1
46log_must poolexists $TESTPOOL2
47
48log_must zfs create $TESTPOOL2/$TESTFS
49log_must mkfile 25m /$TESTPOOL2/$TESTFS/atestfile
50log_must zfs snapshot $TESTPOOL2/$TESTFS@snap
51
52log_must zfs clone $TESTPOOL2/$TESTFS@snap $TESTPOOL2/$TESTCLONE
53
54log_must mkfile 1m /$TESTPOOL2/$TESTCLONE/$TESTFILE0
55log_must mkfile 1m /$TESTPOOL2/$TESTCLONE/$TESTFILE1
56log_must mkfile 1m /$TESTPOOL2/$TESTCLONE/$TESTFILE2
57
58log_must zpool add $TESTPOOL2 $VIRTUAL_DISK2
59log_must zpool remove $TESTPOOL2 $VIRTUAL_DISK1
60wait_for_removal $TESTPOOL2
61
62log_must rm /$TESTPOOL2/$TESTCLONE/$TESTFILE0
63log_must rm /$TESTPOOL2/$TESTCLONE/$TESTFILE1
64
65log_must zfs destroy $TESTPOOL2/$TESTCLONE
66
67log_pass "Clone with the livelist feature and remapped blocks," \
68	"can be destroyed."
69