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
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.
14 # Copyright (c) 2018 by Delphix. All rights reserved.
18 # Verify zfs destroy test for clones with the livelist feature
22 # 1. Clone where livelist is condensed
23 # - create clone, write several files, delete those files
24 # - check that the number of livelist entries decreases
26 # 2. Clone where livelist is deactivated
27 # - create clone, write files. Delete those files and the
28 # file in the filesystem when the snapshot was created
29 # so the clone and snapshot no longer share data
30 # - check that the livelist is destroyed
32 . $STF_SUITE/include/libtest.shlib
33 . $STF_SUITE/tests/functional/cli_root/zfs_destroy/zfs_destroy_common.kshlib
37 log_must zfs destroy -Rf $TESTPOOL/$TESTFS1
38 # reset the livelist sublist size to the original value
39 set_tunable64 LIVELIST_MAX_ENTRIES $ORIGINAL_MAX
40 # reset the minimum percent shared to 75
41 set_tunable32 LIVELIST_MIN_PERCENT_SHARED $ORIGINAL_MIN
46 string="$(zdb -vvvvv $TESTPOOL | grep "Livelist")"
49 if test "${string#*$substring}" != "$string"; then
50 return 0 # $substring is in $string
53 log_fail "$msg" # $substring is not in $string
57 function test_condense
59 # set the max livelist entries to a small value to more easily
61 set_tunable64 LIVELIST_MAX_ENTRIES 20
62 # set a small percent shared threshold so the livelist is not disabled
63 set_tunable32 LIVELIST_MIN_PERCENT_SHARED 10
64 clone_dataset $TESTFS1 snap $TESTCLONE
66 # sync between each write to make sure a new entry is created
68 log_must mkfile 5m /$TESTPOOL/$TESTCLONE/testfile$i
69 log_must zpool sync $TESTPOOL
72 check_ll_len "5 entries" "Unexpected livelist size"
74 # sync between each write to allow for a condense of the previous entry
76 log_must mkfile 5m /$TESTPOOL/$TESTCLONE/testfile$i
77 log_must zpool sync $TESTPOOL
80 check_ll_len "6 entries" "Condense did not occur"
82 log_must zfs destroy $TESTPOOL/$TESTCLONE
86 function test_deactivated
88 # Threshold set to 50 percent
89 set_tunable32 LIVELIST_MIN_PERCENT_SHARED 50
90 clone_dataset $TESTFS1 snap $TESTCLONE
92 log_must mkfile 5m /$TESTPOOL/$TESTCLONE/$TESTFILE0
93 log_must mkfile 5m /$TESTPOOL/$TESTCLONE/$TESTFILE1
94 log_must zpool sync $TESTPOOL
95 # snapshot and clone share 'atestfile', 33 percent
97 log_must zfs destroy -R $TESTPOOL/$TESTCLONE
99 # Threshold set to 20 percent
100 set_tunable32 LIVELIST_MIN_PERCENT_SHARED 20
101 clone_dataset $TESTFS1 snap $TESTCLONE
103 log_must mkfile 5m /$TESTPOOL/$TESTCLONE/$TESTFILE0
104 log_must mkfile 5m /$TESTPOOL/$TESTCLONE/$TESTFILE1
105 log_must mkfile 5m /$TESTPOOL/$TESTCLONE/$TESTFILE2
106 log_must zpool sync $TESTPOOL
107 # snapshot and clone share 'atestfile', 25 percent
108 check_livelist_exists $TESTCLONE
109 log_must rm /$TESTPOOL/$TESTCLONE/atestfile
110 # snapshot and clone share no files
112 log_must zfs destroy -R $TESTPOOL/$TESTCLONE
115 ORIGINAL_MAX=$(get_tunable LIVELIST_MAX_ENTRIES)
116 ORIGINAL_MIN=$(get_tunable LIVELIST_MIN_PERCENT_SHARED)
119 log_must zfs create $TESTPOOL/$TESTFS1
120 log_must mkfile 5m /$TESTPOOL/$TESTFS1/atestfile
121 log_must zfs snapshot $TESTPOOL/$TESTFS1@snap
125 log_pass "Clone's livelist condenses and disables as expected."