-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1) As implemented the `zpool labelclear` command overwrites the calculated offsets of all four vdev labels even when only a single valid label is found. If the device as been repurposed but still contains a valid label this can result in space no longer owned by ZFS being zeroed. Prevent this by verifing every label removed is intact before it's overwritten. 2) Address a small bug in zpool_do_labelclear() which prevented labelclear from working on file vdevs. Only block devices support BLKFLSBUF, try the ioctl() but when it's reported as unsupported this should not be fatal. 3) Fix `zpool labelclear` so it can be run on vdevs which were removed from the pool with `zpool remove`. Additionally, allow intact but partial labels to be cleared as in the case of a failed `zpool attach` or `zpool replace`. 4) Remove LABELCLEAR and LABELREAD variables for test cases. Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov> Issue #6261
- Loading branch information
1 parent
ca6c7a9
commit 226aa4e
Showing
12 changed files
with
252 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 3 additions & 1 deletion
4
tests/zfs-tests/tests/functional/cli_root/zpool_labelclear/Makefile.am
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
pkgdatadir = $(datadir)/@PACKAGE@/zfs-tests/tests/functional/cli_root/zpool_labelclear | ||
dist_pkgdata_SCRIPTS = \ | ||
zpool_labelclear_active.ksh \ | ||
zpool_labelclear_exported.ksh | ||
zpool_labelclear_exported.ksh \ | ||
zpool_labelclear_removed.ksh \ | ||
zpool_labelclear_valid.ksh | ||
|
||
dist_pkgdata_DATA = \ | ||
labelclear.cfg |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
tests/zfs-tests/tests/functional/cli_root/zpool_labelclear/zpool_labelclear_removed.ksh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
#!/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. | ||
# Copyright (c) 2019 by Lawrence Livermore National Security, LLC. | ||
# | ||
|
||
. $STF_SUITE/tests/functional/cli_root/zpool_labelclear/labelclear.cfg | ||
|
||
# DESCRIPTION: | ||
# Check that `zpool labelclear` only clears valid labels. Expected | ||
# label offsets which do not contain intact labels are left untouched. | ||
# | ||
# STRATEGY: | ||
# 1. Create a pool with primary, log, spare and cache devices. | ||
# 2. Remove a top-level vdev, the log, space, and cache devices. | ||
# 3. Run `zpool labelclear` on the removed device. | ||
# 4. Verify the label has been removed. | ||
# | ||
|
||
verify_runnable "global" | ||
|
||
function cleanup | ||
{ | ||
poolexists $TESTPOOL && destroy_pool $TESTPOOL | ||
rm -f $DEVICE1 $DEVICE2 $DEVICE3 $DEVICE4 $DEVICE5 | ||
} | ||
|
||
log_onexit cleanup | ||
log_assert "zpool labelclear works for removed devices" | ||
|
||
DEVICE1="$TEST_BASE_DIR/device-1" | ||
DEVICE2="$TEST_BASE_DIR/device-2" | ||
DEVICE3="$TEST_BASE_DIR/device-3" | ||
DEVICE4="$TEST_BASE_DIR/device-4" | ||
DEVICE5="$TEST_BASE_DIR/device-5" | ||
|
||
log_must truncate -s $((SPA_MINDEVSIZE * 8)) $DEVICE1 | ||
log_must truncate -s $SPA_MINDEVSIZE $DEVICE2 $DEVICE3 $DEVICE4 $DEVICE5 | ||
|
||
log_must zpool create -f $TESTPOOL $DEVICE1 $DEVICE2 \ | ||
log $DEVICE3 cache $DEVICE4 spare $DEVICE5 | ||
log_must zpool sync | ||
|
||
# Remove each type of vdev and verify the label can be cleared. | ||
for dev in $DEVICE5 $DEVICE4 $DEVICE3 $DEVICE2; do | ||
log_must zpool remove $TESTPOOL $dev | ||
log_must zpool sync $TESTPOOL | ||
log_must zpool labelclear $dev | ||
log_mustnot zdb -lq $dev | ||
done | ||
|
||
log_pass "zpool labelclear works for removed devices" |
91 changes: 91 additions & 0 deletions
91
tests/zfs-tests/tests/functional/cli_root/zpool_labelclear/zpool_labelclear_valid.ksh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
#!/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. | ||
# Copyright (c) 2019 by Lawrence Livermore National Security, LLC. | ||
# | ||
|
||
. $STF_SUITE/tests/functional/cli_root/zpool_labelclear/labelclear.cfg | ||
|
||
# DESCRIPTION: | ||
# Check that `zpool labelclear` only clears valid labels. Expected | ||
# label offsets which do not contain intact labels are left untouched. | ||
# | ||
# STRATEGY: | ||
# 1. Create a pool with primary, log, spare and cache devices. | ||
# 2. Export the pool. | ||
# 3. Write a known pattern over the first two device labels. | ||
# 4. Verify with zdb that only the last two device labels are intact. | ||
# 5. Verify the pool could be imported using those labels. | ||
# 6. Run `zpool labelclear` to destroy those last two labels. | ||
# 7. Verify the pool can no longer be found; let alone imported. | ||
# 8. Verify the pattern is intact to confirm `zpool labelclear` did | ||
# not write to first two label offsets. | ||
# 9. Verify that no valid label remain. | ||
# | ||
|
||
verify_runnable "global" | ||
|
||
function cleanup | ||
{ | ||
poolexists $TESTPOOL && destroy_pool $TESTPOOL | ||
rm -f $PATTERN_FILE $DEVICE1 $DEVICE2 $DEVICE3 $DEVICE4 | ||
} | ||
|
||
log_onexit cleanup | ||
log_assert "zpool labelclear will only clear valid labels" | ||
|
||
PATTERN_FILE=$TEST_BASE_DIR/pattern | ||
|
||
DEVICE1="$TEST_BASE_DIR/device-1" | ||
DEVICE2="$TEST_BASE_DIR/device-2" | ||
DEVICE3="$TEST_BASE_DIR/device-3" | ||
DEVICE4="$TEST_BASE_DIR/device-4" | ||
|
||
log_must dd if=/dev/urandom of=$PATTERN_FILE bs=1048576 count=4 | ||
|
||
log_must truncate -s $SPA_MINDEVSIZE $DEVICE1 $DEVICE2 $DEVICE3 $DEVICE4 | ||
|
||
log_must zpool create -O mountpoint=none -f $TESTPOOL $DEVICE1 \ | ||
log $DEVICE2 cache $DEVICE3 spare $DEVICE4 | ||
log_must zpool export $TESTPOOL | ||
|
||
# Overwrite the first 4M of each devices and verify the expected labels. | ||
for dev in $DEVICE1 $DEVICE2 $DEVICE3 $DEVICE4; do | ||
dd if=$PATTERN_FILE of=$dev bs=1048576 conv=notrunc | ||
log_must eval "zdb -l $dev | grep 'labels = 2 3'" | ||
done | ||
|
||
# Verify the pool could be imported using those labels. | ||
log_must eval "zpool import -d $TEST_BASE_DIR | grep $TESTPOOL" | ||
|
||
# Verify the last two labels on each vdev can be cleared. | ||
for dev in $DEVICE1 $DEVICE2 $DEVICE3 $DEVICE4; do | ||
log_must zpool labelclear -f $dev | ||
done | ||
|
||
# Verify there is no longer a pool which can be imported. | ||
log_mustnot eval "zpool import -d $TEST_BASE_DIR | grep $TESTPOOL" | ||
|
||
# Verify the original pattern over the first two labels is intact | ||
for dev in $DEVICE1 $DEVICE2 $DEVICE3 $DEVICE4; do | ||
log_must cmp -n $((4 * 1048576)) $dev $PATTERN_FILE | ||
log_mustnot zdb -lq $dev | ||
done | ||
|
||
# Verify an error is reported when there are no labels to clear. | ||
for dev in $DEVICE1 $DEVICE2 $DEVICE3 $DEVICE4; do | ||
log_mustnot zpool labelclear -f $dev | ||
done | ||
|
||
log_pass "zpool labelclear will only clear valid labels" |
Oops, something went wrong.