Skip to content

Commit d68a9ab

Browse files
author
Paul Dagnelie
committed
Add leak test
Signed-off-by: Paul Dagnelie <[email protected]>
1 parent adecfd4 commit d68a9ab

File tree

3 files changed

+71
-1
lines changed

3 files changed

+71
-1
lines changed

tests/runfiles/common.run

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ tags = ['functional', 'cli_root', 'zfs_wait']
379379

380380
[tests/functional/cli_root/zhack]
381381
tests = ['zhack_label_repair_001', 'zhack_label_repair_002',
382-
'zhack_label_repair_003', 'zhack_label_repair_004']
382+
'zhack_label_repair_003', 'zhack_label_repair_004', 'zhack_metaslab_leak']
383383
pre =
384384
post =
385385
tags = ['functional', 'cli_root', 'zhack']

tests/zfs-tests/tests/Makefile.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1009,6 +1009,7 @@ nobase_dist_datadir_zfs_tests_tests_SCRIPTS += \
10091009
functional/cli_root/zhack/zhack_label_repair_002.ksh \
10101010
functional/cli_root/zhack/zhack_label_repair_003.ksh \
10111011
functional/cli_root/zhack/zhack_label_repair_004.ksh \
1012+
functional/cli_root/zhack/zhack_metaslab_leak.ksh \
10121013
functional/cli_root/zpool_add/add_nested_replacing_spare.ksh \
10131014
functional/cli_root/zpool_add/add-o_ashift.ksh \
10141015
functional/cli_root/zpool_add/add_prop_ashift.ksh \
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
#!/bin/ksh
2+
# SPDX-License-Identifier: CDDL-1.0
3+
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+
11+
#
12+
# Description:
13+
#
14+
# Test whether zhack metaslab leak functions correctly
15+
#
16+
# Strategy:
17+
#
18+
# 1. Create pool on a loopback device with some test data
19+
# 2. Gather pool capacity stats
20+
# 3. Generate fragmentation data with zdb
21+
# 4. Destroy the pool
22+
# 5. Create a new pool with the same configuration
23+
# 6. Export the pool
24+
# 7. Apply the fragmentation information with zhack metaslab leak
25+
# 8. Import the pool
26+
# 9. Verify that pool capacity stats match
27+
28+
. "$STF_SUITE"/include/libtest.shlib
29+
30+
verify_runnable "global"
31+
32+
function cleanup
33+
{
34+
zpool destroy $TESTPOOL
35+
rm $tmp
36+
}
37+
38+
log_assert "zhack metaslab leak leaks the right amount of space"
39+
40+
typeset tmp=$(mktemp)
41+
42+
log_must zpool create $TESTPOOL $DISKS
43+
for i in `seq 1 16`; do
44+
log_must dd if=/dev/urandom of=/$TESTPOOL/f$i bs=1M count=16
45+
log_must zpool sync $TESTPOOL
46+
done
47+
for i in `seq 2 2 16`; do
48+
log_must rm /$TESTPOOL/f$i
49+
done
50+
for i in `seq 1 16`; do
51+
log_must touch /$TESTPOOL/g$i
52+
log_must zpool sync $TESTPOOL
53+
done
54+
55+
alloc=$(zpool get -Hpo value alloc $TESTPOOL)
56+
log_must eval "zdb -m --allocated-map $TESTPOOL > $tmp"
57+
log_must zpool destroy $TESTPOOL
58+
59+
log_must zpool create $TESTPOOL $DISKS
60+
log_must zpool export $TESTPOOL
61+
log_must eval "zhack metaslab leak $TESTPOOL < $tmp"
62+
log_must zpool import $TESTPOOL
63+
64+
alloc2=$(zpool get -Hpo value alloc $TESTPOOL)
65+
66+
[[ $((alloc * 1.05)) -gt $alloc2 ]] && [[ $alloc -lt $alloc2 ]] || \
67+
log_fail "space usage changed too much: $alloc to $alloc2"
68+
69+
log_pass "zhack metaslab leak behaved correctly"

0 commit comments

Comments
 (0)