1084fd14fSBrian Behlendorf#!/bin/ksh -p 2084fd14fSBrian Behlendorf# 3084fd14fSBrian Behlendorf# CDDL HEADER START 4084fd14fSBrian Behlendorf# 5084fd14fSBrian Behlendorf# This file and its contents are supplied under the terms of the 6084fd14fSBrian Behlendorf# Common Development and Distribution License ("CDDL"), version 1.0. 7084fd14fSBrian Behlendorf# You may only use this file in accordance with the terms of version 8084fd14fSBrian Behlendorf# 1.0 of the CDDL. 9084fd14fSBrian Behlendorf# 10084fd14fSBrian Behlendorf# A full copy of the text of the CDDL should have accompanied this 11084fd14fSBrian Behlendorf# source. A copy of the CDDL is also available via the Internet at 12084fd14fSBrian Behlendorf# http://www.illumos.org/license/CDDL. 13084fd14fSBrian Behlendorf# 14084fd14fSBrian Behlendorf# CDDL HEADER END 15084fd14fSBrian Behlendorf# 16084fd14fSBrian Behlendorf 17084fd14fSBrian Behlendorf# 18084fd14fSBrian Behlendorf# Copyright (c) 2019 by Tim Chase. All rights reserved. 19084fd14fSBrian Behlendorf# Copyright (c) 2019 Lawrence Livermore National Security, LLC. 20084fd14fSBrian Behlendorf# Copyright 2019 Joyent, Inc. 21084fd14fSBrian Behlendorf# 22084fd14fSBrian Behlendorf 23084fd14fSBrian Behlendorf. $STF_SUITE/include/libtest.shlib 24084fd14fSBrian Behlendorf. $STF_SUITE/tests/functional/trim/trim.kshlib 25084fd14fSBrian Behlendorf. $STF_SUITE/tests/functional/trim/trim.cfg 26084fd14fSBrian Behlendorf 27084fd14fSBrian Behlendorf# 28084fd14fSBrian Behlendorf# DESCRIPTION: 29084fd14fSBrian Behlendorf# Verify automatic trim and manual trim coexist correctly. 30084fd14fSBrian Behlendorf# 31084fd14fSBrian Behlendorf# STRATEGY: 32084fd14fSBrian Behlendorf# 1. Create a pool on sparse file vdevs to trim. 33084fd14fSBrian Behlendorf# 2. Set autotrim=on to enable asynchronous pool trimming. 34084fd14fSBrian Behlendorf# 3. Generate some interesting pool data which can be trimmed. 35084fd14fSBrian Behlendorf# 4. While generating data issue manual trims. 36084fd14fSBrian Behlendorf# 4. Verify trim IOs of the expected type were issued for the pool. 37084fd14fSBrian Behlendorf# 5. Verify data integrity of the pool after trim. 38084fd14fSBrian Behlendorf# 6. Repeat test for striped, mirrored, and RAIDZ pools. 39084fd14fSBrian Behlendorf 40084fd14fSBrian Behlendorfverify_runnable "global" 41084fd14fSBrian Behlendorf 42084fd14fSBrian Behlendorflog_assert "Set 'autotrim=on', run 'zpool trim' and verify pool data integrity" 43084fd14fSBrian Behlendorf 44084fd14fSBrian Behlendorffunction cleanup 45084fd14fSBrian Behlendorf{ 46084fd14fSBrian Behlendorf if poolexists $TESTPOOL; then 47084fd14fSBrian Behlendorf destroy_pool $TESTPOOL 48084fd14fSBrian Behlendorf fi 49084fd14fSBrian Behlendorf 50084fd14fSBrian Behlendorf log_must rm -f $TRIM_VDEVS 51084fd14fSBrian Behlendorf 52084fd14fSBrian Behlendorf log_must set_tunable32 zfs_trim_extent_bytes_min $trim_extent_bytes_min 53084fd14fSBrian Behlendorf log_must set_tunable32 zfs_trim_txg_batch $trim_txg_batch 54084fd14fSBrian Behlendorf} 55084fd14fSBrian Behlendorflog_onexit cleanup 56084fd14fSBrian Behlendorf 57084fd14fSBrian Behlendorf# Minimum trim size is decreased to verify all trim sizes. 58084fd14fSBrian Behlendorftypeset trim_extent_bytes_min=$(get_tunable zfs_trim_extent_bytes_min) 59084fd14fSBrian Behlendorflog_must set_tunable32 zfs_trim_extent_bytes_min 4096 60084fd14fSBrian Behlendorf 61084fd14fSBrian Behlendorf# Reduced zfs_trim_txg_batch to make trimming more frequent. 62084fd14fSBrian Behlendorftypeset trim_txg_batch=$(get_tunable zfs_trim_txg_batch) 63084fd14fSBrian Behlendorflog_must set_tunable32 zfs_trim_txg_batch 8 64084fd14fSBrian Behlendorf 65084fd14fSBrian Behlendorffor type in "" "mirror" "raidz" "raidz2" "raidz3"; do 66084fd14fSBrian Behlendorf log_must truncate -s 1G $TRIM_VDEVS 67084fd14fSBrian Behlendorf 68084fd14fSBrian Behlendorf log_must zpool create -f $TESTPOOL $type $TRIM_VDEVS 69084fd14fSBrian Behlendorf log_must zpool set autotrim=on $TESTPOOL 70084fd14fSBrian Behlendorf 71084fd14fSBrian Behlendorf # Add and remove data from the pool in a random fashion in order 72084fd14fSBrian Behlendorf # to generate a variety of interesting ranges to be auto trimmed. 73084fd14fSBrian Behlendorf for n in {0..10}; do 74084fd14fSBrian Behlendorf dir="/$TESTPOOL/autotrim-$((RANDOM % 5))" 75084fd14fSBrian Behlendorf filesize=$((4096 + ((RANDOM * 691) % 131072) )) 76084fd14fSBrian Behlendorf log_must rm -rf $dir 77084fd14fSBrian Behlendorf log_must fill_fs $dir 10 10 $filesize 1 R 78*09fbbb7dSAllan Jude sync_all_pools 79084fd14fSBrian Behlendorf 80084fd14fSBrian Behlendorf if [[ $((n % 4)) -eq 0 ]]; then 81084fd14fSBrian Behlendorf log_must zpool trim $TESTPOOL 82084fd14fSBrian Behlendorf wait_trim $TESTPOOL $TRIM_VDEVS 83084fd14fSBrian Behlendorf fi 84084fd14fSBrian Behlendorf done 85084fd14fSBrian Behlendorf log_must du -hs /$TESTPOOL 86084fd14fSBrian Behlendorf 87084fd14fSBrian Behlendorf verify_trim_io $TESTPOOL "ind" 10 88084fd14fSBrian Behlendorf verify_pool $TESTPOOL 89084fd14fSBrian Behlendorf 90084fd14fSBrian Behlendorf log_must zpool destroy $TESTPOOL 91084fd14fSBrian Behlendorf log_must rm -f $TRIM_VDEVS 92084fd14fSBrian Behlendorfdone 93084fd14fSBrian Behlendorf 94084fd14fSBrian Behlendorflog_pass "Automatic trim and manual trim coexistence successfully validated" 95