]>
Commit | Line | Data |
---|---|---|
a1d477c2 MA |
1 | #! /bin/ksh -p |
2 | # | |
3 | # CDDL HEADER START | |
4 | # | |
5 | # This file and its contents are supplied under the terms of the | |
6 | # Common Development and Distribution License ("CDDL"), version 1.0. | |
7 | # You may only use this file in accordance with the terms of version | |
8 | # 1.0 of the CDDL. | |
9 | # | |
10 | # A full copy of the text of the CDDL should have accompanied this | |
11 | # source. A copy of the CDDL is also available via the Internet at | |
12 | # http://www.illumos.org/license/CDDL. | |
13 | # | |
14 | # CDDL HEADER END | |
15 | # | |
16 | ||
17 | # | |
18 | # Copyright (c) 2015, 2016 by Delphix. All rights reserved. | |
19 | # | |
20 | ||
21 | . $STF_SUITE/include/libtest.shlib | |
22 | . $STF_SUITE/tests/functional/removal/removal.kshlib | |
23 | ||
6e91a72f BB |
24 | # N.B. The 'zfs remap' command has been disabled and may be removed. |
25 | export ZFS_REMAP_ENABLED=YES | |
26 | ||
a1d477c2 MA |
27 | default_setup_noexit "$DISKS" |
28 | ||
29 | ||
30 | function cleanup | |
31 | { | |
32 | set_tunable64 zfs_condense_min_mapping_bytes 131072 | |
33 | default_cleanup_noexit | |
34 | } | |
35 | ||
36 | log_onexit cleanup | |
37 | ||
38 | log_must set_tunable64 zfs_condense_min_mapping_bytes 1 | |
39 | ||
40 | log_must zfs set recordsize=512 $TESTPOOL/$TESTFS | |
41 | ||
42 | # | |
43 | # Create a large file so that we know some of the blocks will be on the | |
44 | # removed device, and hence eligible for remapping. | |
45 | # | |
46 | log_must dd if=/dev/urandom of=$TESTDIR/file bs=$((2**12)) count=$((2**9)) | |
47 | ||
48 | # | |
49 | # Randomly rewrite some of blocks in the file so that there will be holes and | |
50 | # we will not be able to remap the entire file in a few huge chunks. | |
51 | # | |
52 | for i in $(seq $((2**12))); do | |
53 | # | |
54 | # We have to sync periodically so that all the writes don't end up in | |
55 | # the same txg. If they were all in the same txg, only the last write | |
56 | # would go through and we would not have as many allocations to | |
57 | # fragment the file. | |
58 | # | |
59 | ((i % 100 > 0 )) || sync_pool || log_fail "Could not sync." | |
60 | random_write $TESTDIR/file $((2**9)) || \ | |
61 | log_fail "Could not random write." | |
62 | done | |
63 | ||
64 | # | |
65 | # Remap should quietly succeed as a noop before a removal. | |
66 | # | |
67 | log_must zfs remap $TESTPOOL/$TESTFS | |
68 | remaptxg_before=$(zfs get -H -o value remaptxg $TESTPOOL/$TESTFS) | |
69 | (( $? == 0 )) || log_fail "Could not get remaptxg." | |
70 | [[ $remaptxg_before == "-" ]] || \ | |
71 | log_fail "remaptxg ($remaptxg_before) had value before a removal" | |
72 | ||
73 | log_must zpool remove $TESTPOOL $REMOVEDISK | |
74 | log_must wait_for_removal $TESTPOOL | |
75 | log_mustnot vdevs_in_pool $TESTPOOL $REMOVEDISK | |
76 | ||
77 | # | |
78 | # remaptxg should not be set if we haven't done a remap. | |
79 | # | |
80 | remaptxg_before=$(zfs get -H -o value remaptxg $TESTPOOL/$TESTFS) | |
81 | (( $? == 0 )) || log_fail "Could not get remaptxg." | |
82 | [[ $remaptxg_before == "-" ]] || \ | |
83 | log_fail "remaptxg ($remaptxg_before) had value before a removal" | |
84 | ||
85 | mapping_size_before=$(indirect_vdev_mapping_size $TESTPOOL) | |
86 | log_must zfs remap $TESTPOOL/$TESTFS | |
87 | ||
88 | # Try to wait for a condense to finish. | |
89 | for i in {1..5}; do | |
90 | sleep 5 | |
91 | sync_pool | |
92 | done | |
93 | mapping_size_after=$(indirect_vdev_mapping_size $TESTPOOL) | |
94 | ||
95 | # | |
96 | # After the remap, there should not be very many blocks referenced. The reason | |
97 | # why our threshold is as high as 512 is because our ratio of metadata to | |
98 | # user data is relatively high, with only 64M of user data on the file system. | |
99 | # | |
100 | (( mapping_size_after < mapping_size_before )) || \ | |
101 | log_fail "Mapping size did not decrease after remap: " \ | |
102 | "$mapping_size_before before to $mapping_size_after after." | |
103 | (( mapping_size_after < 512 )) || \ | |
104 | log_fail "Mapping size not small enough after remap: " \ | |
105 | "$mapping_size_before before to $mapping_size_after after." | |
106 | ||
107 | # | |
108 | # After a remap, the remaptxg should be set to a non-zero value. | |
109 | # | |
110 | remaptxg_after=$(zfs get -H -o value remaptxg $TESTPOOL/$TESTFS) | |
111 | (( $? == 0 )) || log_fail "Could not get remaptxg." | |
112 | log_note "remap txg after remap is $remaptxg_after" | |
113 | (( remaptxg_after > 0 )) || log_fail "remaptxg not increased" | |
114 | ||
115 | # | |
116 | # Remap should quietly succeed as a noop if there have been no removals since | |
117 | # the last remap. | |
118 | # | |
119 | log_must zfs remap $TESTPOOL/$TESTFS | |
120 | remaptxg_again=$(zfs get -H -o value remaptxg $TESTPOOL/$TESTFS) | |
121 | (( $? == 0 )) || log_fail "Could not get remaptxg." | |
122 | log_note "remap txg after second remap is $remaptxg_again" | |
123 | (( remaptxg_again == remaptxg_after )) || \ | |
124 | log_fail "remap not noop if there has been no removal" | |
125 | ||
126 | log_pass "Remapping a fs caused mapping size to decrease." |