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# Suspending and resuming trimming works.
28#
29# STRATEGY:
30# 1. Create a one-disk pool.
31# 2. Start trimming and verify that trimming is active.
32# 3. Wait 3 seconds, then suspend trimming and verify that the progress
33#    reporting says so.
34# 4. Wait 3 seconds and ensure trimming progress doesn't advance.
35# 5. Restart trimming and verify that the progress doesn't regress.
36#
37
38function cleanup
39{
40	if poolexists $TESTPOOL; then
41		destroy_pool $TESTPOOL
42	fi
43
44	if [[ -d "$TESTDIR" ]]; then
45		rm -rf "$TESTDIR"
46	fi
47}
48
49LARGEFILE="$TESTDIR/largefile"
50
51log_must mkdir "$TESTDIR"
52log_must truncate -s 10G "$LARGEFILE"
53log_must zpool create -f $TESTPOOL $LARGEFILE
54
55log_must zpool trim -r 256M $TESTPOOL
56sleep 2
57
58[[ -z "$(trim_progress $TESTPOOL $LARGEFILE)" ]] && \
59    log_fail "Trimming did not start"
60
61sleep 3
62log_must zpool trim -s $TESTPOOL
63log_must eval "trim_prog_line $TESTPOOL $LARGEFILE | grep suspended"
64progress="$(trim_progress $TESTPOOL $LARGEFILE)"
65
66sleep 3
67[[ "$progress" -eq "$(trim_progress $TESTPOOL $LARGEFILE)" ]] || \
68	log_fail "Trimming progress advanced while suspended"
69
70log_must zpool trim $TESTPOOL $LARGEFILE
71[[ "$progress" -le "$(trim_progress $TESTPOOL $LARGEFILE)" ]] ||
72	log_fail "Trimming progress regressed after resuming"
73
74log_pass "Suspend + resume trimming works as expected"
75