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) 2019 by Tim Chase. All rights reserved. 19# Copyright (c) 2019 Lawrence Livermore National Security, LLC. 20# Copyright 2019 Joyent, Inc. 21# 22 23. $STF_SUITE/include/libtest.shlib 24. $STF_SUITE/tests/functional/trim/trim.kshlib 25. $STF_SUITE/tests/functional/trim/trim.cfg 26 27# 28# DESCRIPTION: 29# Verify automatic trim and manual trim coexist correctly. 30# 31# STRATEGY: 32# 1. Create a pool on sparse file vdevs to trim. 33# 2. Set autotrim=on to enable asynchronous pool trimming. 34# 3. Generate some interesting pool data which can be trimmed. 35# 4. While generating data issue manual trims. 36# 4. Verify trim IOs of the expected type were issued for the pool. 37# 5. Verify data integrity of the pool after trim. 38# 6. Repeat test for striped, mirrored, and RAIDZ pools. 39 40verify_runnable "global" 41 42log_assert "Set 'autotrim=on', run 'zpool trim' and verify pool data integrity" 43 44function cleanup 45{ 46 if poolexists $TESTPOOL; then 47 destroy_pool $TESTPOOL 48 fi 49 50 log_must rm -f $TRIM_VDEVS 51 52 log_must set_tunable32 zfs_trim_extent_bytes_min $trim_extent_bytes_min 53 log_must set_tunable32 zfs_trim_txg_batch $trim_txg_batch 54} 55log_onexit cleanup 56 57# Minimum trim size is decreased to verify all trim sizes. 58typeset trim_extent_bytes_min=$(get_tunable zfs_trim_extent_bytes_min) 59log_must set_tunable32 zfs_trim_extent_bytes_min 4096 60 61# Reduced zfs_trim_txg_batch to make trimming more frequent. 62typeset trim_txg_batch=$(get_tunable zfs_trim_txg_batch) 63log_must set_tunable32 zfs_trim_txg_batch 8 64 65for type in "" "mirror" "raidz" "raidz2" "raidz3"; do 66 log_must truncate -s 1G $TRIM_VDEVS 67 68 log_must zpool create -f $TESTPOOL $type $TRIM_VDEVS 69 log_must zpool set autotrim=on $TESTPOOL 70 71 # Add and remove data from the pool in a random fashion in order 72 # to generate a variety of interesting ranges to be auto trimmed. 73 for n in {0..10}; do 74 dir="/$TESTPOOL/autotrim-$((RANDOM % 5))" 75 filesize=$((4096 + ((RANDOM * 691) % 131072) )) 76 log_must rm -rf $dir 77 log_must fill_fs $dir 10 10 $filesize 1 R 78 sync_all_pools 79 80 if [[ $((n % 4)) -eq 0 ]]; then 81 log_must zpool trim $TESTPOOL 82 wait_trim $TESTPOOL $TRIM_VDEVS 83 fi 84 done 85 log_must du -hs /$TESTPOOL 86 87 verify_trim_io $TESTPOOL "ind" 10 88 verify_pool $TESTPOOL 89 90 log_must zpool destroy $TESTPOOL 91 log_must rm -f $TRIM_VDEVS 92done 93 94log_pass "Automatic trim and manual trim coexistence successfully validated" 95