]> git.proxmox.com Git - mirror_zfs.git/blob - tests/zfs-tests/tests/functional/features/async_destroy/async_destroy_001_pos.ksh
OpenZFS 7614, 9064 - zfs device evacuation/removal
[mirror_zfs.git] / tests / zfs-tests / tests / functional / features / async_destroy / async_destroy_001_pos.ksh
1 #!/bin/ksh -p
2 #
3 # CDDL HEADER START
4 #
5 # The contents of this file are subject to the terms of the
6 # Common Development and Distribution License (the "License").
7 # You may not use this file except in compliance with the License.
8 #
9 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 # or http://www.opensolaris.org/os/licensing.
11 # See the License for the specific language governing permissions
12 # and limitations under the License.
13 #
14 # When distributing Covered Code, include this CDDL HEADER in each
15 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 # If applicable, add the following below this CDDL HEADER, with the
17 # fields enclosed by brackets "[]" replaced with your own identifying
18 # information: Portions Copyright [yyyy] [name of copyright owner]
19 #
20 # CDDL HEADER END
21 #
22
23 #
24 # Copyright (c) 2013, 2016 by Delphix. All rights reserved.
25 #
26
27 . $STF_SUITE/include/libtest.shlib
28
29 #
30 # DESCRIPTION:
31 # Exercise the traversal suspend/resume code in async_destroy by
32 # destroying a file system that has more blocks than we can free
33 # in a single txg.
34 #
35 # STRATEGY:
36 # 1. Create a file system
37 # 2. Set recordsize to 512 to create the maximum number of blocks
38 # 3. Set compression to off to force zero-ed blocks to be written
39 # 4. dd a lot of data from /dev/zero to the file system
40 # 5. Destroy the file system
41 # 6. Wait for the freeing property to go to 0
42 # 7. Use zdb to check for leaked blocks
43 #
44
45 TEST_FS=$TESTPOOL/async_destroy
46
47 verify_runnable "both"
48
49 function cleanup
50 {
51 datasetexists $TEST_FS && log_must zfs destroy $TEST_FS
52 log_must set_tunable64 zfs_async_block_max_blocks 100000
53 }
54
55 log_onexit cleanup
56 log_assert "async_destroy can suspend and resume traversal"
57
58 log_must zfs create -o recordsize=1k -o compression=off $TEST_FS
59
60 # Fill with 128,000 blocks.
61 log_must dd bs=1024k count=128 if=/dev/zero of=/$TEST_FS/file
62
63 #
64 # Decrease the max blocks to free each txg, so that freeing takes
65 # long enough that we can observe it.
66 #
67 log_must set_tunable64 zfs_async_block_max_blocks 100
68
69 log_must sync
70 log_must zfs destroy $TEST_FS
71
72 #
73 # We monitor the freeing property, to verify we can see blocks being
74 # freed while the suspend/resume code is exercised.
75 #
76 t0=$SECONDS
77 count=0
78 while [[ $((SECONDS - t0)) -lt 10 ]]; do
79 [[ "0" != "$(zpool list -Ho freeing $TESTPOOL)" ]] && ((count++))
80 [[ $count -gt 1 ]] && break
81 sleep 1
82 done
83
84 [[ $count -eq 0 ]] && log_fail "Freeing property remained empty"
85
86 #
87 # After a bit, go back to allowing an unlimited amount of freeing
88 # per txg.
89 #
90 sleep 10
91 log_must set_tunable64 zfs_async_block_max_blocks 100000
92
93 # Wait for everything to be freed.
94 while [[ "0" != "$(zpool list -Ho freeing $TESTPOOL)" ]]; do
95 [[ $((SECONDS - t0)) -gt 180 ]] && \
96 log_fail "Timed out waiting for freeing to drop to zero"
97 done
98
99 # Check for leaked blocks.
100 log_must zdb -b $TESTPOOL
101
102 log_pass "async_destroy can suspend and resume traversal"