1#!/usr/local/bin/ksh93 -p
2#
3# CDDL HEADER START
4#
5# The contents of this file are subject to the terms of the
6# Common Development and Distribution License (the "License").
7# You may not use this file except in compliance with the License.
8#
9# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10# or http://www.opensolaris.org/os/licensing.
11# See the License for the specific language governing permissions
12# and limitations under the License.
13#
14# When distributing Covered Code, include this CDDL HEADER in each
15# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16# If applicable, add the following below this CDDL HEADER, with the
17# fields enclosed by brackets "[]" replaced with your own identifying
18# information: Portions Copyright [yyyy] [name of copyright owner]
19#
20# CDDL HEADER END
21#
22
23#
24# Copyright 2013 Spectra Logic Corp.  All rights reserved.
25# Use is subject to license terms.
26#
27#
28. $STF_SUITE/include/libtest.kshlib
29
30################################################################################
31#
32# __stc_assertion_start
33#
34# ID: zpool_clear_004_pos
35#
36# DESCRIPTION:
37# Verify 'zpool clear' can clear errors on spare devices.
38#
39# We don't need to check whether 'zpool clear' actually clears error counters.
40# zpool_clear_001_pos will do that.  We just need to check that it doesn't
41# return an error when used on a spare vdev.  This is really a test for whether
42# zpool_find_vdev() from libzfs can work on a spare vdev.  Note that we're
43# talking about he mirror-like "spare-0" vdev, not the leaf hotspare vdev.
44#
45# STRATEGY:
46# 1. Create a pool
47# 2. Activate a spare
48# 3. Verify that "zpool clear" on the spare returns no errors
49#
50# TESTABILITY: explicit
51#
52# TEST_AUTOMATION_LEVEL: automated
53#
54# CODING_STATUS: COMPLETED (2013-06-26)
55#
56# __stc_assertion_end
57#
58################################################################################
59
60verify_runnable "global"
61
62function cleanup
63{
64	destroy_pool $TESTPOOL1
65
66        for file in `$LS $TMPDIR/file.*`; do
67		log_must $RM -f $file
68        done
69
70	restart_zfsd
71}
72
73
74log_assert "Verify 'zpool clear' works on spare vdevs"
75log_onexit cleanup
76
77# Stop ZFSD so it won't interfere with our spare device.
78stop_zfsd
79
80#make raw files to create various configuration pools
81fbase=$TMPDIR/file
82log_must create_vdevs $fbase.0 $fbase.1 $fbase.2
83VDEV1=$fbase.0
84VDEV2=$fbase.1
85SDEV=$fbase.2
86typeset devlist="$VDEV1 $VDEV2 spare $SDEV"
87
88log_note "'zpool clear' clears leaf-device error."
89
90
91log_must $ZPOOL create -f $TESTPOOL1 $devlist
92log_must $ZPOOL replace $TESTPOOL1 $VDEV1 $SDEV
93log_must $ZPOOL clear $TESTPOOL1 "spare-0"
94
95log_pass "'zpool clear' works on spare vdevs"
96