|
| 1 | +#!/bin/ksh -p |
| 2 | +# CDDL HEADER START |
| 3 | +# |
| 4 | +# The contents of this file are subject to the terms of the |
| 5 | +# Common Development and Distribution License (the "License"). |
| 6 | +# You may not use this file except in compliance with the License. |
| 7 | +# |
| 8 | +# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE |
| 9 | +# or https://opensource.org/licenses/CDDL-1.0. |
| 10 | +# See the License for the specific language governing permissions |
| 11 | +# and limitations under the License. |
| 12 | +# |
| 13 | +# When distributing Covered Code, include this CDDL HEADER in each |
| 14 | +# file and include the License file at usr/src/OPENSOLARIS.LICENSE. |
| 15 | +# If applicable, add the following below this CDDL HEADER, with the |
| 16 | +# fields enclosed by brackets "[]" replaced with your own identifying |
| 17 | +# information: Portions Copyright [yyyy] [name of copyright owner] |
| 18 | +# |
| 19 | +# CDDL HEADER END |
| 20 | +# |
| 21 | + |
| 22 | +# |
| 23 | +# Copyright (c) 2025, Klara Inc. |
| 24 | +# |
| 25 | + |
| 26 | +# DESCRIPTION: |
| 27 | +# Verify that zpool ddtprune successfully reduces the number of entries |
| 28 | +# in the DDT. |
| 29 | +# |
| 30 | +# STRATEGY: |
| 31 | +# 1. Create a pool with dedup=on |
| 32 | +# 2. Add duplicate entries to the DDT |
| 33 | +# 3. Verify ddtprune doesn't remove duplicate entries |
| 34 | +# 4. Convert some entries to non-duplicate |
| 35 | +# 5. Verify ddtprune removes non-duplicate entries |
| 36 | +# |
| 37 | + |
| 38 | +. $STF_SUITE/include/libtest.shlib |
| 39 | +. $STF_SUITE/tests/functional/events/events_common.kshlib |
| 40 | + |
| 41 | +verify_runnable "both" |
| 42 | + |
| 43 | +log_assert "Verify DDT pruning correctly removes non-duplicate entries" |
| 44 | + |
| 45 | +# We set the dedup log txg interval to 1, to get a log flush every txg, |
| 46 | +# effectively disabling the log. Without this it's hard to predict when |
| 47 | +# entries appear in the DDT ZAP |
| 48 | +log_must save_tunable DEDUP_LOG_TXG_MAX |
| 49 | +log_must set_tunable32 DEDUP_LOG_TXG_MAX 1 |
| 50 | + |
| 51 | +function cleanup |
| 52 | +{ |
| 53 | + if poolexists $TESTPOOL ; then |
| 54 | + destroy_pool $TESTPOOL |
| 55 | + fi |
| 56 | + log_must restore_tunable DEDUP_LOG_TXG_MAX |
| 57 | +} |
| 58 | + |
| 59 | +function ddt_entries |
| 60 | +{ |
| 61 | + typeset -i entries=$(zpool status -D $TESTPOOL | \ |
| 62 | + grep "dedup: DDT entries" | awk '{print $4}') |
| 63 | + |
| 64 | + echo ${entries} |
| 65 | +} |
| 66 | + |
| 67 | +log_onexit cleanup |
| 68 | + |
| 69 | +log_must zpool create -f -o feature@block_cloning=disabled $TESTPOOL $DISKS |
| 70 | + |
| 71 | +log_must zfs create -o recordsize=512 -o dedup=on $TESTPOOL/$TESTFS |
| 72 | +typeset mountpoint=$(get_prop mountpoint $TESTPOOL/$TESTFS) |
| 73 | +log_must dd if=/dev/urandom of=$mountpoint/f1 bs=512k count=1 |
| 74 | +log_must cp $mountpoint/f1 $mountpoint/f2 |
| 75 | +sync_pool $TESTPOOL |
| 76 | +entries=$(ddt_entries) |
| 77 | +log_note "ddt entries before: $entries" |
| 78 | + |
| 79 | +log_must zpool ddtprune -p 100 $TESTPOOL |
| 80 | +sync_pool $TESTPOOL |
| 81 | +new_entries=$(ddt_entries) |
| 82 | +[[ "$entries" -eq "$new_entries" ]] || \ |
| 83 | + log_fail "DDT entries changed from $entries to $new_entries" |
| 84 | + |
| 85 | +log_must truncate -s 128k $mountpoint/f2 |
| 86 | +sync_pool $TESTPOOL |
| 87 | +sleep 1 |
| 88 | +log_must zpool ddtprune -p 100 $TESTPOOL |
| 89 | +sync_pool $TESTPOOL |
| 90 | + |
| 91 | +new_entries=$(ddt_entries) |
| 92 | +[[ "$((entries / 4))" -eq "$new_entries" ]] || \ |
| 93 | + log_fail "DDT entries did not shrink enough: $entries -> $new_entries" |
| 94 | + |
| 95 | + |
| 96 | +log_pass "DDT pruning correctly removes non-duplicate entries" |
0 commit comments