]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - tests/zfs-tests/tests/functional/cli_root/zfs_destroy/zfs_clone_livelist_condense_and_disable.ksh
Vendor import of openzfs master @ 184df27eef0abdc7ab2105b21257f753834b936b
[FreeBSD/FreeBSD.git] / tests / zfs-tests / tests / functional / cli_root / zfs_destroy / zfs_clone_livelist_condense_and_disable.ksh
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 zfs destroy test for clones with the livelist feature
19 # enabled.
20
21 # STRATEGY
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
25 #         after the delete
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
31
32 . $STF_SUITE/include/libtest.shlib
33 . $STF_SUITE/tests/functional/cli_root/zfs_destroy/zfs_destroy_common.kshlib
34
35 function cleanup
36 {
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
42 }
43
44 function check_ll_len
45 {
46     string="$(zdb -vvvvv $TESTPOOL | grep "Livelist")"
47     substring="$1"
48     msg=$2
49     if test "${string#*$substring}" != "$string"; then
50         return 0    # $substring is in $string
51     else
52         log_note $string
53         log_fail "$msg" # $substring is not in $string
54     fi
55 }
56
57 function test_condense
58 {
59         # set the max livelist entries to a small value to more easily
60         # trigger a condense
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
65
66         # sync between each write to make sure a new entry is created
67         for i in {0..4}; do
68             log_must mkfile 5m /$TESTPOOL/$TESTCLONE/testfile$i
69             log_must zpool sync $TESTPOOL
70         done
71
72         check_ll_len "5 entries" "Unexpected livelist size"
73
74         # sync between each write to allow for a condense of the previous entry
75         for i in {0..4}; do
76             log_must mkfile 5m /$TESTPOOL/$TESTCLONE/testfile$i
77             log_must zpool sync $TESTPOOL
78         done
79
80         check_ll_len "6 entries" "Condense did not occur"
81
82         log_must zfs destroy $TESTPOOL/$TESTCLONE
83         check_livelist_gone
84 }
85
86 function test_deactivated
87 {
88         # Threshold set to 50 percent
89         set_tunable32 LIVELIST_MIN_PERCENT_SHARED 50
90         clone_dataset $TESTFS1 snap $TESTCLONE
91
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
96         check_livelist_gone
97         log_must zfs destroy -R $TESTPOOL/$TESTCLONE
98
99         # Threshold set to 20 percent
100         set_tunable32 LIVELIST_MIN_PERCENT_SHARED 20
101         clone_dataset $TESTFS1 snap $TESTCLONE
102
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
111         check_livelist_gone
112         log_must zfs destroy -R $TESTPOOL/$TESTCLONE
113 }
114
115 ORIGINAL_MAX=$(get_tunable LIVELIST_MAX_ENTRIES)
116 ORIGINAL_MIN=$(get_tunable LIVELIST_MIN_PERCENT_SHARED)
117
118 log_onexit cleanup
119 log_must zfs create $TESTPOOL/$TESTFS1
120 log_must mkfile 5m /$TESTPOOL/$TESTFS1/atestfile
121 log_must zfs snapshot $TESTPOOL/$TESTFS1@snap
122 test_condense
123 test_deactivated
124
125 log_pass "Clone's livelist condenses and disables as expected."