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#
21
22. $STF_SUITE/include/libtest.shlib
23. $STF_SUITE/tests/functional/cli_root/zpool_trim/zpool_trim.kshlib
24
25#
26# DESCRIPTION:
27# Trimming does not cause file corruption.
28#
29# STRATEGY:
30# 1. Create a one-disk pool.
31# 2. Write data to the pool.
32# 3. Start trimming and verify that trimming is active.
33# 4. Write more data to the pool.
34# 5. Export the pool and use zdb to validate checksums.
35#
36
37function cleanup
38{
39	if poolexists $TESTPOOL; then
40		destroy_pool $TESTPOOL
41	fi
42
43	if [[ -d "$TESTDIR" ]]; then
44		rm -rf "$TESTDIR"
45	fi
46}
47log_onexit cleanup
48
49LARGESIZE=$((MINVDEVSIZE * 4))
50LARGEFILE="$TESTDIR/largefile"
51
52log_must mkdir "$TESTDIR"
53log_must truncate -s $LARGESIZE "$LARGEFILE"
54log_must zpool create $TESTPOOL "$LARGEFILE"
55
56log_must dd if=/dev/urandom of=/$TESTPOOL/file1 bs=1048576 count=64
57sync_all_pools
58log_must zpool trim $TESTPOOL
59
60[[ -z "$(trim_progress $TESTPOOL $DISK1)" ]] && \
61    log_fail "Trimming did not start"
62
63log_must dd if=/dev/urandom of=/$TESTPOOL/file2 bs=1048576 count=64
64sync_all_pools
65
66log_must zpool export $TESTPOOL
67log_must zdb -e -p "$TESTDIR" -cc $TESTPOOL
68
69log_pass "Trimming does not corrupt existing or new data"
70