1*084fd14fSBrian Behlendorf#!/bin/ksh -p
2*084fd14fSBrian Behlendorf#
3*084fd14fSBrian Behlendorf# CDDL HEADER START
4*084fd14fSBrian Behlendorf#
5*084fd14fSBrian Behlendorf# This file and its contents are supplied under the terms of the
6*084fd14fSBrian Behlendorf# Common Development and Distribution License ("CDDL"), version 1.0.
7*084fd14fSBrian Behlendorf# You may only use this file in accordance with the terms of version
8*084fd14fSBrian Behlendorf# 1.0 of the CDDL.
9*084fd14fSBrian Behlendorf#
10*084fd14fSBrian Behlendorf# A full copy of the text of the CDDL should have accompanied this
11*084fd14fSBrian Behlendorf# source.  A copy of the CDDL is also available via the Internet at
12*084fd14fSBrian Behlendorf# http://www.illumos.org/license/CDDL.
13*084fd14fSBrian Behlendorf#
14*084fd14fSBrian Behlendorf# CDDL HEADER END
15*084fd14fSBrian Behlendorf#
16*084fd14fSBrian Behlendorf
17*084fd14fSBrian Behlendorf#
18*084fd14fSBrian Behlendorf# Copyright (c) 2019 by Tim Chase. All rights reserved.
19*084fd14fSBrian Behlendorf# Copyright (c) 2019 Lawrence Livermore National Security, LLC.
20*084fd14fSBrian Behlendorf#
21*084fd14fSBrian Behlendorf
22*084fd14fSBrian Behlendorf. $STF_SUITE/include/libtest.shlib
23*084fd14fSBrian Behlendorf. $STF_SUITE/tests/functional/cli_root/zpool_trim/zpool_trim.kshlib
24*084fd14fSBrian Behlendorf
25*084fd14fSBrian Behlendorf#
26*084fd14fSBrian Behlendorf# DESCRIPTION:
27*084fd14fSBrian Behlendorf# Trimming automatically resumes across offline/online.
28*084fd14fSBrian Behlendorf#
29*084fd14fSBrian Behlendorf# STRATEGY:
30*084fd14fSBrian Behlendorf# 1. Create a pool with a two-way mirror.
31*084fd14fSBrian Behlendorf# 2. Start trimming one of the disks and verify that trimming is active.
32*084fd14fSBrian Behlendorf# 3. Offline the disk.
33*084fd14fSBrian Behlendorf# 4. Online the disk.
34*084fd14fSBrian Behlendorf# 5. Verify that trimming resumes and progress does not regress.
35*084fd14fSBrian Behlendorf# 6. Suspend trimming.
36*084fd14fSBrian Behlendorf# 7. Repeat steps 3-4 and verify that trimming does not resume.
37*084fd14fSBrian Behlendorf#
38*084fd14fSBrian Behlendorf
39*084fd14fSBrian BehlendorfDISK1=${DISKS%% *}
40*084fd14fSBrian BehlendorfDISK2="$(echo $DISKS | cut -d' ' -f2)"
41*084fd14fSBrian Behlendorf
42*084fd14fSBrian Behlendorflog_must zpool create -f $TESTPOOL mirror $DISK1 $DISK2
43*084fd14fSBrian Behlendorflog_must zpool trim -r 128M $TESTPOOL $DISK1
44*084fd14fSBrian Behlendorf
45*084fd14fSBrian Behlendorflog_must zpool offline $TESTPOOL $DISK1
46*084fd14fSBrian Behlendorf
47*084fd14fSBrian Behlendorfprogress="$(trim_progress $TESTPOOL $DISK1)"
48*084fd14fSBrian Behlendorf[[ -z "$progress" ]] && log_fail "Trimming did not start"
49*084fd14fSBrian Behlendorf
50*084fd14fSBrian Behlendorflog_must zpool online $TESTPOOL $DISK1
51*084fd14fSBrian Behlendorf
52*084fd14fSBrian Behlendorfnew_progress="$(trim_progress $TESTPOOL $DISK1)"
53*084fd14fSBrian Behlendorf[[ -z "$new_progress" ]] && \
54*084fd14fSBrian Behlendorf    log_fail "Trimming did not restart after onlining"
55*084fd14fSBrian Behlendorf[[ "$progress" -le "$new_progress" ]] || \
56*084fd14fSBrian Behlendorf    log_fail "Trimming lost progress after onlining"
57*084fd14fSBrian Behlendorflog_mustnot eval "trim_prog_line $TESTPOOL $DISK1 | grep suspended"
58*084fd14fSBrian Behlendorf
59*084fd14fSBrian Behlendorflog_must zpool trim -s $TESTPOOL $DISK1
60*084fd14fSBrian Behlendorfaction_date="$(trim_prog_line $TESTPOOL $DISK1 | \
61*084fd14fSBrian Behlendorf    sed 's/.*ed at \(.*\)).*/\1/g')"
62*084fd14fSBrian Behlendorflog_must zpool offline $TESTPOOL $DISK1
63*084fd14fSBrian Behlendorflog_must zpool online $TESTPOOL $DISK1
64*084fd14fSBrian Behlendorfnew_action_date=$(trim_prog_line $TESTPOOL $DISK1 | \
65*084fd14fSBrian Behlendorf    sed 's/.*ed at \(.*\)).*/\1/g')
66*084fd14fSBrian Behlendorf[[ "$action_date" != "$new_action_date" ]] && \
67*084fd14fSBrian Behlendorf    log_fail "Trimming action date did not persist across offline/online"
68*084fd14fSBrian Behlendorflog_must eval "trim_prog_line $TESTPOOL $DISK1 | grep suspended"
69*084fd14fSBrian Behlendorf
70*084fd14fSBrian Behlendorflog_pass "Trimming performs as expected across offline/online"
71