8477 Assertion failed in vdev_state_dirty(): spa_writeable(spa)
[unleashed.git] / usr / src / test / zfs-tests / tests / functional / cli_root / zpool_clear / zpool_clear_readonly.ksh
blob9eb2a3608f170bcbfb5194252e1aa47fe3859708
1 #!/bin/ksh -p
3 # CDDL HEADER START
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.
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.
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]
20 # CDDL HEADER END
24 # Copyright 2017, loli10K <ezomori.nozomu@gmail.com>. All rights reserved.
27 . $STF_SUITE/include/libtest.shlib
28 . $STF_SUITE/tests/functional/cli_root/zpool_clear/zpool_clear.cfg
31 # DESCRIPTION:
32 # Verify 'zpool clear' cannot be used on readonly pools.
34 # STRATEGY:
35 # 1. Create a pool.
36 # 2. Export the pool and import it readonly.
37 # 3. Verify 'zpool clear' on the pool (and each device) returns an error.
40 verify_runnable "global"
42 function cleanup
44 destroy_pool $TESTPOOL1
45 rm -f $TESTDIR/file.*
48 log_assert "Verify 'zpool clear' cannot be used on readonly pools."
49 log_onexit cleanup
51 # 1. Create a pool.
52 log_must truncate -s $FILESIZE $TESTDIR/file.{1,2,3}
53 log_must zpool create $TESTPOOL1 raidz $TESTDIR/file.*
55 # 2. Export the pool and import it readonly.
56 log_must zpool export $TESTPOOL1
57 log_must zpool import -d $TESTDIR -o readonly=on $TESTPOOL1
58 if [[ "$(get_pool_prop readonly $TESTPOOL1)" != 'on' ]]; then
59 log_fail "Pool $TESTPOOL1 was not imported readonly."
62 # 3. Verify 'zpool clear' on the pool (and each device) returns an error.
63 log_mustnot zpool clear $TESTPOOL1
64 for i in {1..3}; do
65 # Device must be online
66 log_must check_state $TESTPOOL1 $TESTDIR/file.$i 'online'
67 # Device cannot be cleared if the pool was imported readonly
68 log_mustnot zpool clear $TESTPOOL1 $TESTDIR/file.$i
69 done
71 log_pass "'zpool clear' fails on readonly pools as expected."