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# Attempting to trim unsupported vdevs should fail.
28*084fd14fSBrian Behlendorf#
29*084fd14fSBrian Behlendorf# STRATEGY:
30*084fd14fSBrian Behlendorf# 1. Create a pool with the following configuration:
31*084fd14fSBrian Behlendorf#    root
32*084fd14fSBrian Behlendorf#      mirror
33*084fd14fSBrian Behlendorf#        vdev0
34*084fd14fSBrian Behlendorf#        vdev1 (offline)
35*084fd14fSBrian Behlendorf#      cache
36*084fd14fSBrian Behlendorf#        vdev2
37*084fd14fSBrian Behlendorf#      spare
38*084fd14fSBrian Behlendorf#        vdev3
39*084fd14fSBrian Behlendorf# 2. Try to trim vdev1, vdev2, and vdev3. Ensure that all 3 fail.
40*084fd14fSBrian Behlendorf#
41*084fd14fSBrian Behlendorffunction cleanup
42*084fd14fSBrian Behlendorf{
43*084fd14fSBrian Behlendorf        if datasetexists $TESTPOOL; then
44*084fd14fSBrian Behlendorf                destroy_pool $TESTPOOL
45*084fd14fSBrian Behlendorf        fi
46*084fd14fSBrian Behlendorf        if [[ -d $TESTDIR ]]; then
47*084fd14fSBrian Behlendorf                log_must rm -rf $TESTDIR
48*084fd14fSBrian Behlendorf        fi
49*084fd14fSBrian Behlendorf}
50*084fd14fSBrian Behlendorflog_onexit cleanup
51*084fd14fSBrian Behlendorf
52*084fd14fSBrian Behlendorflog_must mkdir $TESTDIR
53*084fd14fSBrian Behlendorfset -A FDISKS
54*084fd14fSBrian Behlendorffor n in {0..2}; do
55*084fd14fSBrian Behlendorf        log_must mkfile $MINVDEVSIZE $TESTDIR/vdev$n
56*084fd14fSBrian Behlendorf        FDISKS+=("$TESTDIR/vdev$n")
57*084fd14fSBrian Behlendorfdone
58*084fd14fSBrian BehlendorfFDISKS+=("${DISKS%% *}")
59*084fd14fSBrian Behlendorf
60*084fd14fSBrian Behlendorflog_must zpool create $TESTPOOL mirror ${FDISKS[0]} ${FDISKS[1]} \
61*084fd14fSBrian Behlendorf        spare ${FDISKS[2]} cache ${FDISKS[3]}
62*084fd14fSBrian Behlendorf
63*084fd14fSBrian Behlendorflog_must zpool offline $TESTPOOL ${FDISKS[1]}
64*084fd14fSBrian Behlendorf
65*084fd14fSBrian Behlendorflog_mustnot zpool trim $TESTPOOL mirror-0
66*084fd14fSBrian Behlendorffor n in {1..3}; do
67*084fd14fSBrian Behlendorf        log_mustnot zpool trim $TESTPOOL ${FDISKS[$n]}
68*084fd14fSBrian Behlendorfdone
69*084fd14fSBrian Behlendorf
70*084fd14fSBrian Behlendorflog_pass "Attempting to trim failed on unsupported devices"
71