]> git.proxmox.com Git - mirror_zfs-debian.git/blob - tests/zfs-tests/tests/functional/cli_root/zpool_clear/zpool_clear_readonly.ksh
New upstream version 0.7.2
[mirror_zfs-debian.git] / tests / zfs-tests / tests / functional / cli_root / zpool_clear / zpool_clear_readonly.ksh
1 #!/bin/ksh -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 2017, loli10K <ezomori.nozomu@gmail.com>. All rights reserved.
25 #
26
27 . $STF_SUITE/include/libtest.shlib
28 . $STF_SUITE/tests/functional/cli_root/zpool_clear/zpool_clear.cfg
29
30 #
31 # DESCRIPTION:
32 # Verify 'zpool clear' cannot be used on readonly pools.
33 #
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.
38 #
39
40 verify_runnable "global"
41
42 function cleanup
43 {
44 destroy_pool $TESTPOOL1
45 rm -f $TESTDIR/file.*
46 }
47
48 log_assert "Verify 'zpool clear' cannot be used on readonly pools."
49 log_onexit cleanup
50
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.*
54
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."
60 fi
61
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
70
71 log_pass "'zpool clear' fails on readonly pools as expected."