|
| 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