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.
17 . $STF_SUITE/include/libtest.shlib
18 . $STF_SUITE/tests/functional/cli_root/zpool_wait/zpool_wait.kshlib
22 # 'zpool wait' works when waiting for background freeing to complete.
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
31 # 6. Repeat 3-5, except destroy a snapshot instead of a filesystem.
32 # 7. Repeat 3-5, except destroy a clone.
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
41 poolexists $TESTPOOL && destroy_pool $TESTPOOL
47 log_bkgrnd zpool wait -t free $TESTPOOL
49 check_while_waiting $pid '[[ $(get_pool_prop freeing $TESTPOOL) != "0" ]]'
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
60 log_must zpool create $TESTPOOL $DISK1
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.
66 default_async_block_max_blocks=$(get_tunable ASYNC_BLOCK_MAX_BLOCKS)
67 log_must set_tunable64 ASYNC_BLOCK_MAX_BLOCKS 8
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.
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
80 # Test waiting for space from destroyed filesystem to be freed
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"
88 # Test waiting for space from destroyed snapshot to be freed
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"
99 # Test waiting for space from destroyed clone to be freed
101 log_must zfs snapshot "$SNAP"
102 log_must zfs clone "$SNAP" "$CLONE"
103 # Add some data to the clone
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
109 log_must zfs destroy "$CLONE"
112 log_pass "'zpool wait -t freeing' works."