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# $FreeBSD$
24
25#
26# Copyright 2013 Spectra Logic Corp.  All rights reserved.
27# Use is subject to license terms.
28#
29#
30. $STF_SUITE/include/libtest.kshlib
31
32################################################################################
33#
34# __stc_assertion_start
35#
36# ID: zpool_clear_004_pos
37#
38# DESCRIPTION:
39# Verify 'zpool clear' can clear errors on spare devices.
40#
41# We don't need to check whether 'zpool clear' actually clears error counters.
42# zpool_clear_001_pos will do that.  We just need to check that it doesn't
43# return an error when used on a spare vdev.  This is really a test for whether
44# zpool_find_vdev() from libzfs can work on a spare vdev.  Note that we're
45# talking about he mirror-like "spare-0" vdev, not the leaf hotspare vdev.
46#
47# STRATEGY:
48# 1. Create a pool
49# 2. Activate a spare
50# 3. Verify that "zpool clear" on the spare returns no errors
51#
52# TESTABILITY: explicit
53#
54# TEST_AUTOMATION_LEVEL: automated
55#
56# CODING_STATUS: COMPLETED (2013-06-26)
57#
58# __stc_assertion_end
59#
60################################################################################
61
62verify_runnable "global"
63
64function cleanup
65{
66	destroy_pool $TESTPOOL1
67
68        for file in `$LS $TMPDIR/file.*`; do
69		log_must $RM -f $file
70        done
71
72	restart_zfsd
73}
74
75
76log_assert "Verify 'zpool clear' works on spare vdevs"
77log_onexit cleanup
78
79# Stop ZFSD so it won't interfere with our spare device.
80stop_zfsd
81
82#make raw files to create various configuration pools
83fbase=$TMPDIR/file
84log_must create_vdevs $fbase.0 $fbase.1 $fbase.2
85VDEV1=$fbase.0
86VDEV2=$fbase.1
87SDEV=$fbase.2
88typeset devlist="$VDEV1 $VDEV2 spare $SDEV"
89
90log_note "'zpool clear' clears leaf-device error."
91
92
93log_must $ZPOOL create -f $TESTPOOL1 $devlist
94log_must $ZPOOL replace $TESTPOOL1 $VDEV1 $SDEV
95log_must $ZPOOL clear $TESTPOOL1 "spare-0"
96
97log_pass "'zpool clear' works on spare vdevs"
98