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