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
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.
18 # Copyright (c) 2015, 2016 by Delphix. All rights reserved.
21 .
$STF_SUITE/include
/libtest.shlib
22 .
$STF_SUITE/tests
/functional
/removal
/removal.kshlib
24 default_setup_noexit
"$DISKS"
29 set_tunable64 zfs_condense_min_mapping_bytes
131072
30 default_cleanup_noexit
35 log_must set_tunable64 zfs_condense_min_mapping_bytes
1
37 log_must zfs
set recordsize
=512 $TESTPOOL/$TESTFS
40 # Create a large file so that we know some of the blocks will be on the
41 # removed device, and hence eligible for remapping.
43 log_must
dd if=/dev
/urandom of
=$TESTDIR/file bs
=$
((2**12)) count
=$
((2**9))
46 # Randomly rewrite some of blocks in the file so that there will be holes and
47 # we will not be able to remap the entire file in a few huge chunks.
49 for i
in $
(seq $
((2**12))); do
51 # We have to sync periodically so that all the writes don't end up in
52 # the same txg. If they were all in the same txg, only the last write
53 # would go through and we would not have as many allocations to
56 ((i
% 100 > 0 )) || sync_pool || log_fail
"Could not sync."
57 random_write
$TESTDIR/file $
((2**9)) || \
58 log_fail
"Could not random write."
62 # Remap should quietly succeed as a noop before a removal.
64 log_must zfs remap
$TESTPOOL/$TESTFS
65 remaptxg_before
=$
(zfs get
-H -o value remaptxg
$TESTPOOL/$TESTFS)
66 (( $?
== 0 )) || log_fail
"Could not get remaptxg."
67 [[ $remaptxg_before == "-" ]] || \
68 log_fail
"remaptxg ($remaptxg_before) had value before a removal"
70 log_must zpool remove
$TESTPOOL $REMOVEDISK
71 log_must wait_for_removal
$TESTPOOL
72 log_mustnot vdevs_in_pool
$TESTPOOL $REMOVEDISK
75 # remaptxg should not be set if we haven't done a remap.
77 remaptxg_before
=$
(zfs get
-H -o value remaptxg
$TESTPOOL/$TESTFS)
78 (( $?
== 0 )) || log_fail
"Could not get remaptxg."
79 [[ $remaptxg_before == "-" ]] || \
80 log_fail
"remaptxg ($remaptxg_before) had value before a removal"
82 mapping_size_before
=$
(indirect_vdev_mapping_size
$TESTPOOL)
83 log_must zfs remap
$TESTPOOL/$TESTFS
85 # Try to wait for a condense to finish.
90 mapping_size_after
=$
(indirect_vdev_mapping_size
$TESTPOOL)
93 # After the remap, there should not be very many blocks referenced. The reason
94 # why our threshold is as high as 512 is because our ratio of metadata to
95 # user data is relatively high, with only 64M of user data on the file system.
97 (( mapping_size_after
< mapping_size_before
)) || \
98 log_fail
"Mapping size did not decrease after remap: " \
99 "$mapping_size_before before to $mapping_size_after after."
100 (( mapping_size_after
< 512 )) || \
101 log_fail
"Mapping size not small enough after remap: " \
102 "$mapping_size_before before to $mapping_size_after after."
105 # After a remap, the remaptxg should be set to a non-zero value.
107 remaptxg_after
=$
(zfs get
-H -o value remaptxg
$TESTPOOL/$TESTFS)
108 (( $?
== 0 )) || log_fail
"Could not get remaptxg."
109 log_note
"remap txg after remap is $remaptxg_after"
110 (( remaptxg_after
> 0 )) || log_fail
"remaptxg not increased"
113 # Remap should quietly succeed as a noop if there have been no removals since
116 log_must zfs remap
$TESTPOOL/$TESTFS
117 remaptxg_again
=$
(zfs get
-H -o value remaptxg
$TESTPOOL/$TESTFS)
118 (( $?
== 0 )) || log_fail
"Could not get remaptxg."
119 log_note
"remap txg after second remap is $remaptxg_again"
120 (( remaptxg_again
== remaptxg_after
)) || \
121 log_fail
"remap not noop if there has been no removal"
123 log_pass
"Remapping a fs caused mapping size to decrease."