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# Detaching/attaching, adding/removing data devices works with trimming.
28*084fd14fSBrian Behlendorf#
29*084fd14fSBrian Behlendorf# STRATEGY:
30*084fd14fSBrian Behlendorf# 1. Create a single-disk pool.
31*084fd14fSBrian Behlendorf# 2. Start trimming.
32*084fd14fSBrian Behlendorf# 3. Attach a second disk, ensure trimming continues.
33*084fd14fSBrian Behlendorf# 4. Detach the second disk, ensure trimming continues.
34*084fd14fSBrian Behlendorf# 5. Add a second disk, ensure trimming continues.
35*084fd14fSBrian Behlendorf# 6. Remove the first disk, ensure trimming stops.
36*084fd14fSBrian Behlendorf#
37*084fd14fSBrian Behlendorf
38*084fd14fSBrian BehlendorfDISK1="$(echo $DISKS | cut -d' ' -f1)"
39*084fd14fSBrian BehlendorfDISK2="$(echo $DISKS | cut -d' ' -f2)"
40*084fd14fSBrian Behlendorf
41*084fd14fSBrian Behlendorflog_must zpool create -f $TESTPOOL $DISK1
42*084fd14fSBrian Behlendorf
43*084fd14fSBrian Behlendorflog_must zpool trim -r 128M $TESTPOOL $DISK1
44*084fd14fSBrian Behlendorfprogress="$(trim_progress $TESTPOOL $DISK1)"
45*084fd14fSBrian Behlendorf[[ -z "$progress" ]] && log_fail "Trim did not start"
46*084fd14fSBrian Behlendorf
47*084fd14fSBrian Behlendorflog_must zpool attach $TESTPOOL $DISK1 $DISK2
48*084fd14fSBrian Behlendorfnew_progress="$(trim_progress $TESTPOOL $DISK1)"
49*084fd14fSBrian Behlendorf[[ "$progress" -le "$new_progress" ]] || \
50*084fd14fSBrian Behlendorf        log_fail "Lost trimming progress on demotion to child vdev"
51*084fd14fSBrian Behlendorfprogress="$new_progress"
52*084fd14fSBrian Behlendorf
53*084fd14fSBrian Behlendorflog_must zpool detach $TESTPOOL $DISK2
54*084fd14fSBrian Behlendorfnew_progress="$(trim_progress $TESTPOOL $DISK1)"
55*084fd14fSBrian Behlendorf[[ "$progress" -le "$new_progress" ]] || \
56*084fd14fSBrian Behlendorf        log_fail "Lost trimming progress on promotion to top vdev"
57*084fd14fSBrian Behlendorfprogress="$new_progress"
58*084fd14fSBrian Behlendorf
59*084fd14fSBrian Behlendorflog_must zpool add $TESTPOOL $DISK2
60*084fd14fSBrian Behlendorflog_must zpool remove $TESTPOOL $DISK1
61*084fd14fSBrian Behlendorf[[ -z "$(trim_prog_line $TESTPOOL $DISK1)" ]] || \
62*084fd14fSBrian Behlendorf        log_fail "Trimming continued after initiating removal"
63*084fd14fSBrian Behlendorf
64*084fd14fSBrian Behlendorflog_pass "Trimming worked as expected across attach/detach and add/remove"
65