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 # N.B. The 'zfs remap' command has been disabled and may be removed.
25 export ZFS_REMAP_ENABLED
=YES
27 default_setup_noexit
"$DISKS"
32 set_tunable64 zfs_condense_min_mapping_bytes
131072
33 default_cleanup_noexit
38 log_must set_tunable64 zfs_condense_min_mapping_bytes
1
40 log_must zfs
set recordsize
=512 $TESTPOOL/$TESTFS
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.
46 log_must
dd if=/dev
/urandom of
=$TESTDIR/file bs
=$
((2**12)) count
=$
((2**9))
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.
52 for i
in $
(seq $
((2**12))); do
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
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."
65 # Remap should quietly succeed as a noop before a removal.
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"
73 log_must zpool remove
$TESTPOOL $REMOVEDISK
74 log_must wait_for_removal
$TESTPOOL
75 log_mustnot vdevs_in_pool
$TESTPOOL $REMOVEDISK
78 # remaptxg should not be set if we haven't done a remap.
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"
85 mapping_size_before
=$
(indirect_vdev_mapping_size
$TESTPOOL)
86 log_must zfs remap
$TESTPOOL/$TESTFS
88 # Try to wait for a condense to finish.
93 mapping_size_after
=$
(indirect_vdev_mapping_size
$TESTPOOL)
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.
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."
108 # After a remap, the remaptxg should be set to a non-zero value.
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"
116 # Remap should quietly succeed as a noop if there have been no removals since
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"
126 log_pass
"Remapping a fs caused mapping size to decrease."