diff options
author | LOLi <[email protected]> | 2017-07-07 19:39:53 +0200 |
---|---|---|
committer | Brian Behlendorf <[email protected]> | 2017-07-07 10:39:53 -0700 |
commit | 92e43c17188d47f47b69318e4884096dec380e36 (patch) | |
tree | 7bdc7d283ccab78569c4084794c6dfc2b4c363c0 /tests | |
parent | 0ea05c64f8d08c20439dd2a06e949a2aa4115101 (diff) |
Fix 'zpool clear' on readonly pools
Illumos 4080 inadvertently allows 'zpool clear' on readonly pools: fix
this by reintroducing a check (POOL_CHECK_READONLY) in zfs_ioc_clear
registration code.
Signed-off-by: Giuseppe Di Natale <[email protected]>
Signed-off-by: Brian Behlendorf <[email protected]>
Signed-off-by: loli10K <[email protected]>
Closes #6306
Diffstat (limited to 'tests')
3 files changed, 75 insertions, 2 deletions
diff --git a/tests/runfiles/linux.run b/tests/runfiles/linux.run index e10ec4dc2..c7eb9cf81 100644 --- a/tests/runfiles/linux.run +++ b/tests/runfiles/linux.run @@ -200,7 +200,8 @@ tests = ['zpool_add_001_pos', 'zpool_add_002_pos', 'zpool_add_003_pos', tests = ['zpool_attach_001_neg', 'attach-o_ashift'] [tests/functional/cli_root/zpool_clear] -tests = ['zpool_clear_001_pos', 'zpool_clear_002_neg', 'zpool_clear_003_neg'] +tests = ['zpool_clear_001_pos', 'zpool_clear_002_neg', 'zpool_clear_003_neg', + 'zpool_clear_readonly'] [tests/functional/cli_root/zpool_create] tests = ['zpool_create_001_pos', 'zpool_create_002_pos', diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_clear/Makefile.am b/tests/zfs-tests/tests/functional/cli_root/zpool_clear/Makefile.am index 1d9a719f0..cfd4534c9 100644 --- a/tests/zfs-tests/tests/functional/cli_root/zpool_clear/Makefile.am +++ b/tests/zfs-tests/tests/functional/cli_root/zpool_clear/Makefile.am @@ -5,4 +5,5 @@ dist_pkgdata_SCRIPTS = \ cleanup.ksh \ zpool_clear_001_pos.ksh \ zpool_clear_002_neg.ksh \ - zpool_clear_003_neg.ksh + zpool_clear_003_neg.ksh \ + zpool_clear_readonly.ksh diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_clear/zpool_clear_readonly.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool_clear/zpool_clear_readonly.ksh new file mode 100755 index 000000000..9eb2a3608 --- /dev/null +++ b/tests/zfs-tests/tests/functional/cli_root/zpool_clear/zpool_clear_readonly.ksh @@ -0,0 +1,71 @@ +#!/bin/ksh -p +# +# CDDL HEADER START +# +# The contents of this file are subject to the terms of the +# Common Development and Distribution License (the "License"). +# You may not use this file except in compliance with the License. +# +# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE +# or http://www.opensolaris.org/os/licensing. +# See the License for the specific language governing permissions +# and limitations under the License. +# +# When distributing Covered Code, include this CDDL HEADER in each +# file and include the License file at usr/src/OPENSOLARIS.LICENSE. +# If applicable, add the following below this CDDL HEADER, with the +# fields enclosed by brackets "[]" replaced with your own identifying +# information: Portions Copyright [yyyy] [name of copyright owner] +# +# CDDL HEADER END +# + +# +# Copyright 2017, loli10K <[email protected]>. All rights reserved. +# + +. $STF_SUITE/include/libtest.shlib +. $STF_SUITE/tests/functional/cli_root/zpool_clear/zpool_clear.cfg + +# +# DESCRIPTION: +# Verify 'zpool clear' cannot be used on readonly pools. +# +# STRATEGY: +# 1. Create a pool. +# 2. Export the pool and import it readonly. +# 3. Verify 'zpool clear' on the pool (and each device) returns an error. +# + +verify_runnable "global" + +function cleanup +{ + destroy_pool $TESTPOOL1 + rm -f $TESTDIR/file.* +} + +log_assert "Verify 'zpool clear' cannot be used on readonly pools." +log_onexit cleanup + +# 1. Create a pool. +log_must truncate -s $FILESIZE $TESTDIR/file.{1,2,3} +log_must zpool create $TESTPOOL1 raidz $TESTDIR/file.* + +# 2. Export the pool and import it readonly. +log_must zpool export $TESTPOOL1 +log_must zpool import -d $TESTDIR -o readonly=on $TESTPOOL1 +if [[ "$(get_pool_prop readonly $TESTPOOL1)" != 'on' ]]; then + log_fail "Pool $TESTPOOL1 was not imported readonly." +fi + +# 3. Verify 'zpool clear' on the pool (and each device) returns an error. +log_mustnot zpool clear $TESTPOOL1 +for i in {1..3}; do + # Device must be online + log_must check_state $TESTPOOL1 $TESTDIR/file.$i 'online' + # Device cannot be cleared if the pool was imported readonly + log_mustnot zpool clear $TESTPOOL1 $TESTDIR/file.$i +done + +log_pass "'zpool clear' fails on readonly pools as expected." |