xref: /illumos-gate/usr/src/test/zfs-tests/tests/functional/trim/trim_integrity.ksh (revision 09fbbb7d1b5a956a9b81304070dcff318a4a158e)
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 manual trim pool data integrity.
30084fd14fSBrian Behlendorf#
31084fd14fSBrian Behlendorf# STRATEGY:
32084fd14fSBrian Behlendorf#	1. Create a pool on sparse file vdevs to trim.
33084fd14fSBrian Behlendorf#	2. Generate some interesting pool data which can be trimmed.
34084fd14fSBrian Behlendorf#	3. Manually trim the pool.
35084fd14fSBrian Behlendorf#	4. Verify trim IOs of the expected type were issued for the pool.
36084fd14fSBrian Behlendorf#	5. Verify data integrity of the pool after trim.
37084fd14fSBrian Behlendorf#	6. Repeat test for striped, mirrored, and RAIDZ pools.
38084fd14fSBrian Behlendorf
39084fd14fSBrian Behlendorfverify_runnable "global"
40084fd14fSBrian Behlendorf
41084fd14fSBrian Behlendorflog_assert "Run 'zpool trim' and verify pool data integrity"
42084fd14fSBrian Behlendorf
43084fd14fSBrian Behlendorffunction cleanup
44084fd14fSBrian Behlendorf{
45084fd14fSBrian Behlendorf	if poolexists $TESTPOOL; then
46084fd14fSBrian Behlendorf		destroy_pool $TESTPOOL
47084fd14fSBrian Behlendorf	fi
48084fd14fSBrian Behlendorf
49084fd14fSBrian Behlendorf	log_must rm -f $TRIM_VDEVS
50084fd14fSBrian Behlendorf
51084fd14fSBrian Behlendorf	log_must set_tunable32 zfs_trim_extent_bytes_min $trim_extent_bytes_min
52084fd14fSBrian Behlendorf	log_must set_tunable32 zfs_trim_txg_batch $trim_txg_batch
53084fd14fSBrian Behlendorf}
54084fd14fSBrian Behlendorflog_onexit cleanup
55084fd14fSBrian Behlendorf
56084fd14fSBrian Behlendorf# Minimum trim size is decreased to verify all trim sizes.
57084fd14fSBrian Behlendorftypeset trim_extent_bytes_min=$(get_tunable zfs_trim_extent_bytes_min)
58084fd14fSBrian Behlendorflog_must set_tunable32 zfs_trim_extent_bytes_min 4096
59084fd14fSBrian Behlendorf
60084fd14fSBrian Behlendorf# Reduced zfs_trim_txg_batch to make trimming more frequent.
61084fd14fSBrian Behlendorftypeset trim_txg_batch=$(get_tunable zfs_trim_txg_batch)
62084fd14fSBrian Behlendorflog_must set_tunable32 zfs_trim_txg_batch 8
63084fd14fSBrian Behlendorf
64084fd14fSBrian Behlendorffor type in "" "mirror" "raidz" "raidz2" "raidz3"; do
65084fd14fSBrian Behlendorf	log_must truncate -s 1G $TRIM_VDEVS
66084fd14fSBrian Behlendorf
67084fd14fSBrian Behlendorf	log_must zpool create -f $TESTPOOL $type $TRIM_VDEVS
68084fd14fSBrian Behlendorf
69084fd14fSBrian Behlendorf	# Add and remove data from the pool in a random fashion in order
70084fd14fSBrian Behlendorf	# to generate a variety of interesting ranges to be manually trimmed.
71084fd14fSBrian Behlendorf	for n in {0..10}; do
72084fd14fSBrian Behlendorf		dir="/$TESTPOOL/trim-$((RANDOM % 5))"
73084fd14fSBrian Behlendorf		filesize=$((4096 + ((RANDOM * 691) % 131072) ))
74084fd14fSBrian Behlendorf		log_must rm -rf $dir
75084fd14fSBrian Behlendorf		log_must fill_fs $dir 10 10 $filesize 1 R
76*09fbbb7dSAllan Jude		sync_all_pools
77084fd14fSBrian Behlendorf	done
78084fd14fSBrian Behlendorf	log_must du -hs /$TESTPOOL
79084fd14fSBrian Behlendorf
80084fd14fSBrian Behlendorf	log_must zpool trim $TESTPOOL
81084fd14fSBrian Behlendorf	wait_trim $TESTPOOL $TRIM_VDEVS
82084fd14fSBrian Behlendorf
83084fd14fSBrian Behlendorf	verify_trim_io $TESTPOOL "ind" 10
84084fd14fSBrian Behlendorf	verify_pool $TESTPOOL
85084fd14fSBrian Behlendorf
86084fd14fSBrian Behlendorf	log_must zpool destroy $TESTPOOL
87084fd14fSBrian Behlendorf	log_must rm -f $TRIM_VDEVS
88084fd14fSBrian Behlendorfdone
89084fd14fSBrian Behlendorf
90084fd14fSBrian Behlendorflog_pass "Manual trim successfully validated"
91