]> git.proxmox.com Git - mirror_zfs.git/blame - tests/zfs-tests/tests/functional/removal/removal_remap.ksh
Disable 'zfs remap' command
[mirror_zfs.git] / tests / zfs-tests / tests / functional / removal / removal_remap.ksh
CommitLineData
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.
25export ZFS_REMAP_ENABLED=YES
26
a1d477c2
MA
27default_setup_noexit "$DISKS"
28
29
30function cleanup
31{
32 set_tunable64 zfs_condense_min_mapping_bytes 131072
33 default_cleanup_noexit
34}
35
36log_onexit cleanup
37
38log_must set_tunable64 zfs_condense_min_mapping_bytes 1
39
40log_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#
46log_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#
52for 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."
62done
63
64#
65# Remap should quietly succeed as a noop before a removal.
66#
67log_must zfs remap $TESTPOOL/$TESTFS
68remaptxg_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
73log_must zpool remove $TESTPOOL $REMOVEDISK
74log_must wait_for_removal $TESTPOOL
75log_mustnot vdevs_in_pool $TESTPOOL $REMOVEDISK
76
77#
78# remaptxg should not be set if we haven't done a remap.
79#
80remaptxg_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
85mapping_size_before=$(indirect_vdev_mapping_size $TESTPOOL)
86log_must zfs remap $TESTPOOL/$TESTFS
87
88# Try to wait for a condense to finish.
89for i in {1..5}; do
90 sleep 5
91 sync_pool
92done
93mapping_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#
110remaptxg_after=$(zfs get -H -o value remaptxg $TESTPOOL/$TESTFS)
111(( $? == 0 )) || log_fail "Could not get remaptxg."
112log_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#
119log_must zfs remap $TESTPOOL/$TESTFS
120remaptxg_again=$(zfs get -H -o value remaptxg $TESTPOOL/$TESTFS)
121(( $? == 0 )) || log_fail "Could not get remaptxg."
122log_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
126log_pass "Remapping a fs caused mapping size to decrease."