]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - tests/zfs-tests/tests/functional/cli_root/zpool_wait/zpool_wait_freeing.ksh
Vendor import of openzfs master @ 184df27eef0abdc7ab2105b21257f753834b936b
[FreeBSD/FreeBSD.git] / tests / zfs-tests / tests / functional / cli_root / zpool_wait / zpool_wait_freeing.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 . $STF_SUITE/include/libtest.shlib
18 . $STF_SUITE/tests/functional/cli_root/zpool_wait/zpool_wait.kshlib
19
20 #
21 # DESCRIPTION:
22 # 'zpool wait' works when waiting for background freeing to complete.
23 #
24 # STRATEGY:
25 # 1. Create a pool.
26 # 2. Modify tunables to make sure freeing is slow enough to observe.
27 # 3. Create a file system with some data.
28 # 4. Destroy the file system and call 'zpool wait'.
29 # 5. Monitor the waiting process to make sure it returns neither too soon nor
30 #    too late.
31 # 6. Repeat 3-5, except destroy a snapshot instead of a filesystem.
32 # 7. Repeat 3-5, except destroy a clone.
33 #
34
35 function cleanup
36 {
37         log_must set_tunable64 ASYNC_BLOCK_MAX_BLOCKS $default_async_block_max_blocks
38         log_must set_tunable64 LIVELIST_MAX_ENTRIES $default_max_livelist_entries
39         log_must set_tunable64 LIVELIST_MIN_PERCENT_SHARED $default_min_pct_shared
40
41         poolexists $TESTPOOL && destroy_pool $TESTPOOL
42         kill_if_running $pid
43 }
44
45 function test_wait
46 {
47         log_bkgrnd zpool wait -t free $TESTPOOL
48         pid=$!
49         check_while_waiting $pid '[[ $(get_pool_prop freeing $TESTPOOL) != "0" ]]'
50 }
51
52 typeset -r FS="$TESTPOOL/$TESTFS1"
53 typeset -r SNAP="$FS@snap1"
54 typeset -r CLONE="$TESTPOOL/clone"
55 typeset pid default_max_livelist_entries default_min_pct_shared
56 typeset default_async_block_max_blocks
57
58 log_onexit cleanup
59
60 log_must zpool create $TESTPOOL $DISK1
61
62 #
63 # Limit the number of blocks that can be freed in a single txg. This slows down
64 # freeing so that we actually have something to wait for.
65 #
66 default_async_block_max_blocks=$(get_tunable ASYNC_BLOCK_MAX_BLOCKS)
67 log_must set_tunable64 ASYNC_BLOCK_MAX_BLOCKS 8
68 #
69 # Space from clones gets freed one livelist per txg instead of being controlled
70 # by zfs_async_block_max_blocks. Limit the rate at which space is freed by
71 # limiting the size of livelists so that we end up with a number of them.
72 #
73 default_max_livelist_entries=$(get_tunable LIVELIST_MAX_ENTRIES)
74 log_must set_tunable64 LIVELIST_MAX_ENTRIES 16
75 # Don't disable livelists, no matter how much clone diverges from snapshot
76 default_min_pct_shared=$(get_tunable LIVELIST_MIN_PERCENT_SHARED)
77 log_must set_tunable64 LIVELIST_MIN_PERCENT_SHARED -1
78
79 #
80 # Test waiting for space from destroyed filesystem to be freed
81 #
82 log_must zfs create "$FS"
83 log_must dd if=/dev/zero of="/$FS/testfile" bs=1M count=128
84 log_must zfs destroy "$FS"
85 test_wait
86
87 #
88 # Test waiting for space from destroyed snapshot to be freed
89 #
90 log_must zfs create "$FS"
91 log_must dd if=/dev/zero of="/$FS/testfile" bs=1M count=128
92 log_must zfs snapshot "$SNAP"
93 # Make sure bulk of space is unique to snapshot
94 log_must rm "/$FS/testfile"
95 log_must zfs destroy "$SNAP"
96 test_wait
97
98 #
99 # Test waiting for space from destroyed clone to be freed
100 #
101 log_must zfs snapshot "$SNAP"
102 log_must zfs clone "$SNAP" "$CLONE"
103 # Add some data to the clone
104 for i in {1..50}; do
105         log_must dd if=/dev/urandom of="/$CLONE/testfile$i" bs=1k count=512
106         # Force each new file to be tracked by a new livelist
107         log_must zpool sync $TESTPOOL
108 done
109 log_must zfs destroy "$CLONE"
110 test_wait
111
112 log_pass "'zpool wait -t freeing' works."