diff options
author | Yuri Pankov <[email protected]> | 2017-01-13 09:25:15 -0800 |
---|---|---|
committer | Brian Behlendorf <[email protected]> | 2017-04-11 09:54:39 -0700 |
commit | dbb38f660509073f43284c6c745a4449ffd46385 (patch) | |
tree | a980a446a446b1e1d1291010653719f5b21fbf9c /tests | |
parent | 047187c1bd4a893e7a89e8795fa8f4ecc3eb0732 (diff) |
OpenZFS 6865 - want zfs-tests cases for zpool labelclear command
Authored by: Yuri Pankov <[email protected]>
Reviewed by: Matthew Ahrens <[email protected]>
Reviewed by: John Kennedy <[email protected]>
Approved by: Robert Mustacchi <[email protected]>
Reviewed-by: loli10K <[email protected]>
Ported-by: Brian Behlendorf <[email protected]>
Porting Notes:
- Updated 'zpool labelclear' and 'zdb -l' such that they attempt
to find a vdev given solely its short name. This behavior is
consistent with the upstream OpenZFS code and the test cases
depend on it. The actual implementation differs slightly due
to device naming conventions on Linux.
- auto_online_001_pos, auto_replace_001_pos and add-o_ashift
test cases updated to expect failure when no label exists.
- read_efi_label() and zpool_label_disk_check() are read-only
operations and should use O_RDONLY at open time to enforce this.
- zpool_label_disk() and zpool_relabel_disk() write the partition
information using O_DIRECT an fsync() and page cache invalidation
to ensure a consistent view of the device.
- dump_label() in zdb should invalidate the page cache in order
to get the authoritative label from disk.
OpenZFS-issue: https://www.illumos.org/issues/6865
OpenZFS-commit: https://github.com/openzfs/openzfs/commit/c95076c
Closes #5981
Diffstat (limited to 'tests')
9 files changed, 182 insertions, 3 deletions
diff --git a/tests/runfiles/linux.run b/tests/runfiles/linux.run index f28b18139..a358b5578 100644 --- a/tests/runfiles/linux.run +++ b/tests/runfiles/linux.run @@ -308,6 +308,11 @@ tests = ['zpool_import_001_pos', 'zpool_import_missing_002_pos', 'zpool_import_missing_003_pos', 'zpool_import_rename_001_pos'] +[tests/functional/cli_root/zpool_labelclear] +tests = ['zpool_labelclear_active', 'zpool_labelclear_exported'] +pre = +post = + [tests/functional/cli_root/zpool_offline] tests = ['zpool_offline_001_pos', 'zpool_offline_002_neg'] diff --git a/tests/zfs-tests/tests/functional/cli_root/Makefile.am b/tests/zfs-tests/tests/functional/cli_root/Makefile.am index 5dc72de16..f2e3fd0df 100644 --- a/tests/zfs-tests/tests/functional/cli_root/Makefile.am +++ b/tests/zfs-tests/tests/functional/cli_root/Makefile.am @@ -37,6 +37,7 @@ SUBDIRS = \ zpool_get \ zpool_history \ zpool_import \ + zpool_labelclear \ zpool_offline \ zpool_online \ zpool_remove \ diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_add/add-o_ashift.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool_add/add-o_ashift.ksh index be415f137..6998a50cf 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zpool_add/add-o_ashift.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zpool_add/add-o_ashift.ksh @@ -100,7 +100,7 @@ do log_mustnot zpool add -o ashift="$badval" $disk2 log_must zpool destroy $TESTPOOL log_must zpool labelclear $disk1 - log_must zpool labelclear $disk2 + log_mustnot zpool labelclear $disk2 done log_pass "zpool add -o ashift=<n>' works with different ashift values" diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_labelclear/Makefile.am b/tests/zfs-tests/tests/functional/cli_root/zpool_labelclear/Makefile.am new file mode 100644 index 000000000..a8bea6864 --- /dev/null +++ b/tests/zfs-tests/tests/functional/cli_root/zpool_labelclear/Makefile.am @@ -0,0 +1,5 @@ +pkgdatadir = $(datadir)/@PACKAGE@/zfs-tests/tests/functional/cli_root/zpool_labelclear +dist_pkgdata_SCRIPTS = \ + labelclear.cfg \ + zpool_labelclear_active.ksh \ + zpool_labelclear_exported.ksh diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_labelclear/labelclear.cfg b/tests/zfs-tests/tests/functional/cli_root/zpool_labelclear/labelclear.cfg new file mode 100644 index 000000000..62d39b05f --- /dev/null +++ b/tests/zfs-tests/tests/functional/cli_root/zpool_labelclear/labelclear.cfg @@ -0,0 +1,26 @@ +#!/bin/ksh -p +# +# +# This file and its contents are supplied under the terms of the +# Common Development and Distribution License ("CDDL"), version 1.0. +# You may only use this file in accordance with the terms of version +# 1.0 of the CDDL. +# +# A full copy of the text of the CDDL should have accompanied this +# source. A copy of the CDDL is also available via the Internet at +# http://www.illumos.org/license/CDDL. +# + +# +# Copyright 2016 Nexenta Systems, Inc. +# + +. $STF_SUITE/include/libtest.shlib + +typeset LABELCLEAR="zpool labelclear" +typeset LABELREAD="zdb -lq" + +typeset disks=(${DISKS[*]}) +typeset disk1=${disks[0]} +typeset disk2=${disks[1]} +typeset disk3=${disks[2]} diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_labelclear/zpool_labelclear_active.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool_labelclear/zpool_labelclear_active.ksh new file mode 100755 index 000000000..8a30d1a42 --- /dev/null +++ b/tests/zfs-tests/tests/functional/cli_root/zpool_labelclear/zpool_labelclear_active.ksh @@ -0,0 +1,68 @@ +#!/bin/ksh -p +# +# +# This file and its contents are supplied under the terms of the +# Common Development and Distribution License ("CDDL"), version 1.0. +# You may only use this file in accordance with the terms of version +# 1.0 of the CDDL. +# +# A full copy of the text of the CDDL should have accompanied this +# source. A copy of the CDDL is also available via the Internet at +# http://www.illumos.org/license/CDDL. +# + +# +# Copyright 2016 Nexenta Systems, Inc. +# + +. $STF_SUITE/tests/functional/cli_root/zpool_labelclear/labelclear.cfg + +# DESCRIPTION: +# Check that zpool labelclear will refuse to clear the label +# (with or without -f) on any vdevs of the imported pool. +# +# STRATEGY: +# 1. Create the pool with log device. +# 2. Try clearing the label on data and log devices. +# 3. Add auxilary (cache/spare) vdevs. +# 4. Try clearing the label on auxilary vdevs. +# 5. Check that zpool labelclear will return non-zero and +# labels are intact. + +verify_runnable "global" + +function cleanup +{ + poolexists $TESTPOOL && destroy_pool $TESTPOOL +} + +log_onexit cleanup +log_assert "zpool labelclear will fail on all vdevs of imported pool" + +# Create simple pool, skip any mounts +log_must zpool create -O mountpoint=none -f $TESTPOOL $disk1 log $disk2 + +# Check that labelclear [-f] will fail on ACTIVE pool vdevs +log_mustnot $LABELCLEAR $disk1 +log_must $LABELREAD $disk1 +log_mustnot $LABELCLEAR -f $disk1 +log_must $LABELREAD $disk1 +log_mustnot $LABELCLEAR $disk2 +log_must $LABELREAD $disk2 +log_mustnot $LABELCLEAR -f $disk2 +log_must $LABELREAD $disk2 + +# Add a cache/spare to the pool, check that labelclear [-f] will fail +# on the vdev and will succeed once it's removed from pool config +for vdevtype in "cache" "spare"; do + log_must zpool add $TESTPOOL $vdevtype $disk3 + log_mustnot $LABELCLEAR $disk3 + log_must $LABELREAD $disk3 + log_mustnot $LABELCLEAR -f $disk3 + log_must $LABELREAD $disk3 + log_must zpool remove $TESTPOOL $disk3 + log_must $LABELCLEAR $disk3 + log_mustnot $LABELREAD $disk3 +done + +log_pass "zpool labelclear will fail on all vdevs of imported pool" diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_labelclear/zpool_labelclear_exported.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool_labelclear/zpool_labelclear_exported.ksh new file mode 100755 index 000000000..98385c9b7 --- /dev/null +++ b/tests/zfs-tests/tests/functional/cli_root/zpool_labelclear/zpool_labelclear_exported.ksh @@ -0,0 +1,74 @@ +#!/bin/ksh -p +# +# +# This file and its contents are supplied under the terms of the +# Common Development and Distribution License ("CDDL"), version 1.0. +# You may only use this file in accordance with the terms of version +# 1.0 of the CDDL. +# +# A full copy of the text of the CDDL should have accompanied this +# source. A copy of the CDDL is also available via the Internet at +# http://www.illumos.org/license/CDDL. +# + +# +# Copyright 2016 Nexenta Systems, Inc. +# + +. $STF_SUITE/tests/functional/cli_root/zpool_labelclear/labelclear.cfg + +# DESCRIPTION: +# Check that zpool labelclear will refuse to clear the label +# on ACTIVE vdevs of exported pool without -f, and will succeeded with -f. +# +# STRATEGY: +# 1. Create a pool with log device. +# 2. Export the pool. +# 3. Check that zpool labelclear returns non-zero when trying to +# clear the label on ACTIVE vdevs, and succeeds with -f. +# 4. Add auxilary vdevs (cache/spare). +# 5. Check that zpool labelclear succeeds on auxilary vdevs of +# exported pool. + +verify_runnable "global" + +function cleanup +{ + poolexists $TESTPOOL && destroy_pool $TESTPOOL +} + +log_onexit cleanup +log_assert "zpool labelclear will fail on ACTIVE vdevs of exported pool and" \ + "succeed with -f" + +for vdevtype in "" "cache" "spare"; do + # Create simple pool, skip any mounts + log_must zpool create -O mountpoint=none -f $TESTPOOL $disk1 log $disk2 + # Add auxilary vdevs (cache/spare) + if [[ -n $vdevtype ]]; then + log_must zpool add $TESTPOOL $vdevtype $disk3 + fi + # Export the pool + log_must zpool export $TESTPOOL + + # Check that labelclear will fail without -f + log_mustnot $LABELCLEAR $disk1 + log_must $LABELREAD $disk1 + log_mustnot $LABELCLEAR $disk2 + log_must $LABELREAD $disk2 + + # Check that labelclear will succeed with -f + log_must $LABELCLEAR -f $disk1 + log_mustnot $LABELREAD $disk1 + log_must $LABELCLEAR -f $disk2 + log_mustnot $LABELREAD $disk2 + + # Check that labelclear on auxilary vdevs will succeed + if [[ -n $vdevtype ]]; then + log_must $LABELCLEAR $disk3 + log_mustnot $LABELREAD $disk3 + fi +done + +log_pass "zpool labelclear will fail on ACTIVE vdevs of exported pool and" \ + "succeed with -f" diff --git a/tests/zfs-tests/tests/functional/fault/auto_online_001_pos.ksh b/tests/zfs-tests/tests/functional/fault/auto_online_001_pos.ksh index aa7ab76e7..bf09816bc 100755 --- a/tests/zfs-tests/tests/functional/fault/auto_online_001_pos.ksh +++ b/tests/zfs-tests/tests/functional/fault/auto_online_001_pos.ksh @@ -76,7 +76,7 @@ fi # Clear disk labels for i in {0..2} do - log_must zpool labelclear -f /dev/disk/by-id/"${devs_id[i]}" + zpool labelclear -f /dev/disk/by-id/"${devs_id[i]}" done if is_loop_device $DISK1; then diff --git a/tests/zfs-tests/tests/functional/fault/auto_replace_001_pos.ksh b/tests/zfs-tests/tests/functional/fault/auto_replace_001_pos.ksh index d784f06a6..24f128c3d 100755 --- a/tests/zfs-tests/tests/functional/fault/auto_replace_001_pos.ksh +++ b/tests/zfs-tests/tests/functional/fault/auto_replace_001_pos.ksh @@ -87,7 +87,7 @@ log_onexit cleanup # Clear disk labels for i in {0..2} do - log_must zpool labelclear -f /dev/disk/by-id/"${devs_id[i]}" + zpool labelclear -f /dev/disk/by-id/"${devs_id[i]}" done setup |