aboutsummaryrefslogtreecommitdiff
path: root/sys/contrib/openzfs/tests/zfs-tests/tests/functional/trim/autotrim_integrity.ksh
blob: 6af877241d0dbeba4fa6bffad036e956c0ccaac9 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#!/bin/ksh -p
#
# CDDL HEADER START
#
# This file and its contents are supplied under the terms of the
# Common Development and Distribution License ("CDDL"), version 1.0.
# You may only use this file in accordance with the terms of version
# 1.0 of the CDDL.
#
# A full copy of the text of the CDDL should have accompanied this
# source.  A copy of the CDDL is also available via the Internet at
# http://www.illumos.org/license/CDDL.
#
# CDDL HEADER END
#

#
# Copyright (c) 2019 by Tim Chase. All rights reserved.
# Copyright (c) 2019 Lawrence Livermore National Security, LLC.
#

. $STF_SUITE/include/libtest.shlib
. $STF_SUITE/tests/functional/trim/trim.kshlib
. $STF_SUITE/tests/functional/trim/trim.cfg

#
# DESCRIPTION:
#	Verify automatic trim pool data integrity.
#
# STRATEGY:
#	1. Create a pool on sparse file vdevs to trim.
#	2. Set autotrim=on to enable asynchronous pool trimming.
#	3. Generate some interesting pool data which can be trimmed.
#	4. Verify trim IOs of the expected type were issued for the pool.
#	5. Verify data integrity of the pool after trim.
#	6. Repeat test for striped, mirrored, and RAIDZ pools.

verify_runnable "global"

log_assert "Set 'autotrim=on' pool property verify pool data integrity"

function cleanup
{
	if poolexists $TESTPOOL; then
		destroy_pool $TESTPOOL
	fi

	log_must rm -f $TRIM_VDEVS

	log_must set_tunable64 TRIM_EXTENT_BYTES_MIN $trim_extent_bytes_min
	log_must set_tunable64 TRIM_TXG_BATCH $trim_txg_batch
}
log_onexit cleanup

# Minimum trim size is decreased to verify all trim sizes.
typeset trim_extent_bytes_min=$(get_tunable TRIM_EXTENT_BYTES_MIN)
log_must set_tunable64 TRIM_EXTENT_BYTES_MIN 4096

# Reduced TRIM_TXG_BATCH to make trimming more frequent.
typeset trim_txg_batch=$(get_tunable TRIM_TXG_BATCH)
log_must set_tunable64 TRIM_TXG_BATCH 8

for type in "" "mirror" "raidz" "raidz2" "raidz3"; do
	log_must truncate -s 1G $TRIM_VDEVS

	log_must zpool create -f $TESTPOOL $type $TRIM_VDEVS
	log_must zpool set autotrim=on $TESTPOOL

	# Add and remove data from the pool in a random fashion in order
	# to generate a variety of interesting ranges to be auto trimmed.
	for n in {0..10}; do
		dir="/$TESTPOOL/autotrim-$((RANDOM % 5))"
		filesize=$((4096 + ((RANDOM * 691) % 131072) ))
		log_must rm -rf $dir
		log_must fill_fs $dir 10 10 $filesize 1 R
		zpool sync
	done
	log_must du -hs /$TESTPOOL

	verify_trim_io $TESTPOOL "ind" 10
	verify_pool $TESTPOOL

	log_must zpool destroy $TESTPOOL
	log_must rm -f $TRIM_VDEVS
done

log_pass "Automatic trim successfully validated"