summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrian Behlendorf <behlendorf1@llnl.gov>2020-07-30 01:12:12 -0500
committerJason King <jason.king@joyent.com>2020-08-11 21:23:17 -0500
commit0ac8993002ee179cc3289243a0fc956ee0db04da (patch)
treea022bb414cfd4f6e41c2efe02b5f0eede12f3807
parent0904e7ecf266ebe6844dfc4b178441dc8d81296b (diff)
downloadillumos-joyent-0ac8993002ee179cc3289243a0fc956ee0db04da.tar.gz
13013 Port OpenZFS zpool label clear improvements
13012 zpool_read_label semantics should match OpenZFS Portions contributed by: Jason King <jason.king@joyent.com> Reviewed by: Matt Ahrens <mahrens@delphix.com> Reviewed by: Tim Chase <tim@chase2k.com> Reviewed by: Tony Hutter <hutter2@llnl.gov> Reviewed by: Andy Fiddaman <andy@omniosce.org> Reviewed by: Toomas Soome <tsoome@me.com> Approved by: Dan McDonald <danmcd@joyent.com>
-rw-r--r--usr/src/cmd/fs.d/zfs/fstyp/fstyp.c11
-rw-r--r--usr/src/lib/libzfs/common/libzfs_import.c49
-rw-r--r--usr/src/lib/libzutil/common/zutil_import.c11
-rw-r--r--usr/src/pkg/manifests/system-test-zfstest.mf6
-rw-r--r--usr/src/test/zfs-tests/runfiles/omnios.run3
-rw-r--r--usr/src/test/zfs-tests/runfiles/openindiana.run3
-rw-r--r--usr/src/test/zfs-tests/runfiles/smartos.run3
-rw-r--r--usr/src/test/zfs-tests/tests/functional/cli_root/zpool_attach/attach-o_ashift.ksh12
-rw-r--r--usr/src/test/zfs-tests/tests/functional/cli_root/zpool_labelclear/labelclear.cfg3
-rw-r--r--usr/src/test/zfs-tests/tests/functional/cli_root/zpool_labelclear/zpool_labelclear_active.ksh28
-rw-r--r--usr/src/test/zfs-tests/tests/functional/cli_root/zpool_labelclear/zpool_labelclear_exported.ksh20
-rwxr-xr-xusr/src/test/zfs-tests/tests/functional/cli_root/zpool_labelclear/zpool_labelclear_removed.ksh62
-rwxr-xr-xusr/src/test/zfs-tests/tests/functional/cli_root/zpool_labelclear/zpool_labelclear_valid.ksh92
-rw-r--r--usr/src/test/zfs-tests/tests/functional/cli_root/zpool_replace/replace-o_ashift.ksh15
-rw-r--r--usr/src/test/zfs-tests/tests/functional/cli_root/zpool_replace/replace_prop_ashift.ksh6
15 files changed, 260 insertions, 64 deletions
diff --git a/usr/src/cmd/fs.d/zfs/fstyp/fstyp.c b/usr/src/cmd/fs.d/zfs/fstyp/fstyp.c
index d49d998404..2e7d4d397d 100644
--- a/usr/src/cmd/fs.d/zfs/fstyp/fstyp.c
+++ b/usr/src/cmd/fs.d/zfs/fstyp/fstyp.c
@@ -31,6 +31,7 @@
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
+#include <sys/debug.h>
#include <sys/types.h>
#include <unistd.h>
#include <libintl.h>
@@ -89,11 +90,17 @@ fstyp_mod_ident(fstyp_mod_handle_t handle)
char *str;
uint64_t u64;
char buf[64];
+ int num_labels = 0;
- if (zpool_read_label(h->fd, &h->config, NULL) != 0) {
- return (FSTYP_ERR_NO_MATCH);
+ if (zpool_read_label(h->fd, &h->config, &num_labels) != 0) {
+ /* This is the only reason zpool_read_label() can fail */
+ VERIFY3S(errno, ==, ENOMEM);
+ return (FSTYP_ERR_NOMEM);
}
+ if (num_labels == 0)
+ return (FSTYP_ERR_NO_MATCH);
+
if (nvlist_lookup_uint64(h->config, ZPOOL_CONFIG_POOL_STATE,
&state) != 0 || state == POOL_STATE_DESTROYED) {
nvlist_free(h->config);
diff --git a/usr/src/lib/libzfs/common/libzfs_import.c b/usr/src/lib/libzfs/common/libzfs_import.c
index 706f08e6ec..dc15aca0c0 100644
--- a/usr/src/lib/libzfs/common/libzfs_import.c
+++ b/usr/src/lib/libzfs/common/libzfs_import.c
@@ -169,23 +169,66 @@ zpool_clear_label(int fd)
int l;
vdev_label_t *label;
uint64_t size;
+ int labels_cleared = 0;
if (fstat64(fd, &statbuf) == -1)
return (0);
+
size = P2ALIGN_TYPED(statbuf.st_size, sizeof (vdev_label_t), uint64_t);
if ((label = calloc(sizeof (vdev_label_t), 1)) == NULL)
return (-1);
for (l = 0; l < VDEV_LABELS; l++) {
- if (pwrite64(fd, label, sizeof (vdev_label_t),
+ uint64_t state, guid;
+ nvlist_t *config;
+
+ if (pread64(fd, label, sizeof (vdev_label_t),
label_offset(size, l)) != sizeof (vdev_label_t)) {
- free(label);
- return (-1);
+ continue;
+ }
+
+ if (nvlist_unpack(label->vl_vdev_phys.vp_nvlist,
+ sizeof (label->vl_vdev_phys.vp_nvlist), &config, 0) != 0) {
+ continue;
+ }
+
+ /* Skip labels which do not have a valid guid. */
+ if (nvlist_lookup_uint64(config, ZPOOL_CONFIG_GUID,
+ &guid) != 0 || guid == 0) {
+ nvlist_free(config);
+ continue;
+ }
+
+ /* Skip labels which are not in a known valid state. */
+ if (nvlist_lookup_uint64(config, ZPOOL_CONFIG_POOL_STATE,
+ &state) != 0 || state > POOL_STATE_L2CACHE) {
+ nvlist_free(config);
+ continue;
+ }
+
+ nvlist_free(config);
+
+ /*
+ * A valid label was found, overwrite this label's nvlist
+ * and uberblocks with zeros on disk. This is done to prevent
+ * system utilities, like blkid, from incorrectly detecting a
+ * partial label. The leading pad space is left untouched.
+ */
+ memset(label, 0, sizeof (vdev_label_t));
+ size_t label_size = sizeof (vdev_label_t) - (2 * VDEV_PAD_SIZE);
+
+ if (pwrite64(fd, label, label_size, label_offset(size, l) +
+ (2 * VDEV_PAD_SIZE)) == label_size) {
+ labels_cleared++;
}
}
free(label);
+
+ if (labels_cleared == 0)
+ return (-1);
+
return (0);
}
diff --git a/usr/src/lib/libzutil/common/zutil_import.c b/usr/src/lib/libzutil/common/zutil_import.c
index 961247c5c0..b4e6ccc0ca 100644
--- a/usr/src/lib/libzutil/common/zutil_import.c
+++ b/usr/src/lib/libzutil/common/zutil_import.c
@@ -25,6 +25,7 @@
* Copyright (c) 2012, 2018 by Delphix. All rights reserved.
* Copyright 2015 RackTop Systems.
* Copyright (c) 2016, Intel Corporation.
+ * Copyright 2020 Joyent, Inc.
*/
/*
@@ -913,8 +914,11 @@ zpool_read_label(int fd, nvlist_t **config, int *num_labels)
*config = NULL;
+ if (num_labels != NULL)
+ *num_labels = 0;
+
if (fstat64(fd, &statbuf) == -1)
- return (-1);
+ return (0);
size = P2ALIGN_TYPED(statbuf.st_size, sizeof (vdev_label_t), uint64_t);
if ((label = malloc(sizeof (vdev_label_t))) == NULL)
@@ -968,11 +972,6 @@ zpool_read_label(int fd, nvlist_t **config, int *num_labels)
free(label);
*config = expected_config;
- if (count == 0) {
- errno = ENOENT;
- return (-1);
- }
-
return (0);
}
diff --git a/usr/src/pkg/manifests/system-test-zfstest.mf b/usr/src/pkg/manifests/system-test-zfstest.mf
index eca36deda1..8174cd0af3 100644
--- a/usr/src/pkg/manifests/system-test-zfstest.mf
+++ b/usr/src/pkg/manifests/system-test-zfstest.mf
@@ -1884,6 +1884,12 @@ file \
file \
path=opt/zfs-tests/tests/functional/cli_root/zpool_labelclear/zpool_labelclear_exported \
mode=0555
+file \
+ path=opt/zfs-tests/tests/functional/cli_root/zpool_labelclear/zpool_labelclear_removed \
+ mode=0555
+file \
+ path=opt/zfs-tests/tests/functional/cli_root/zpool_labelclear/zpool_labelclear_valid \
+ mode=0555
file path=opt/zfs-tests/tests/functional/cli_root/zpool_offline/cleanup \
mode=0555
file path=opt/zfs-tests/tests/functional/cli_root/zpool_offline/setup \
diff --git a/usr/src/test/zfs-tests/runfiles/omnios.run b/usr/src/test/zfs-tests/runfiles/omnios.run
index 5693772b65..4c52926b16 100644
--- a/usr/src/test/zfs-tests/runfiles/omnios.run
+++ b/usr/src/test/zfs-tests/runfiles/omnios.run
@@ -339,7 +339,8 @@ tests = ['zpool_import_001_pos', 'zpool_import_002_pos',
'zpool_import_encrypted', 'zpool_import_encrypted_load']
[/opt/zfs-tests/tests/functional/cli_root/zpool_labelclear]
-tests = ['zpool_labelclear_active', 'zpool_labelclear_exported']
+tests = ['zpool_labelclear_active', 'zpool_labelclear_exported',
+ 'zpool_labelclear_removed', 'zpool_labelclear_valid']
pre =
post =
diff --git a/usr/src/test/zfs-tests/runfiles/openindiana.run b/usr/src/test/zfs-tests/runfiles/openindiana.run
index b004b2e96a..27697582ef 100644
--- a/usr/src/test/zfs-tests/runfiles/openindiana.run
+++ b/usr/src/test/zfs-tests/runfiles/openindiana.run
@@ -339,7 +339,8 @@ tests = ['zpool_import_001_pos', 'zpool_import_002_pos',
'zpool_import_encrypted', 'zpool_import_encrypted_load']
[/opt/zfs-tests/tests/functional/cli_root/zpool_labelclear]
-tests = ['zpool_labelclear_active', 'zpool_labelclear_exported']
+tests = ['zpool_labelclear_active', 'zpool_labelclear_exported',
+ 'zpool_labelclear_removed', 'zpool_labelclear_valid']
pre =
post =
diff --git a/usr/src/test/zfs-tests/runfiles/smartos.run b/usr/src/test/zfs-tests/runfiles/smartos.run
index e8f2a35b12..30e8efc0d3 100644
--- a/usr/src/test/zfs-tests/runfiles/smartos.run
+++ b/usr/src/test/zfs-tests/runfiles/smartos.run
@@ -289,7 +289,8 @@ tests = ['zpool_import_001_pos', 'zpool_import_002_pos',
'zpool_import_encrypted', 'zpool_import_encrypted_load']
[/opt/zfs-tests/tests/functional/cli_root/zpool_labelclear]
-tests = ['zpool_labelclear_active', 'zpool_labelclear_exported']
+tests = ['zpool_labelclear_active', 'zpool_labelclear_exported',
+ 'zpool_labelclear_removed', 'zpool_labelclear_valid']
pre =
post =
diff --git a/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_attach/attach-o_ashift.ksh b/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_attach/attach-o_ashift.ksh
index 58ab57db05..fd33fb9506 100644
--- a/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_attach/attach-o_ashift.ksh
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_attach/attach-o_ashift.ksh
@@ -51,8 +51,8 @@ log_onexit cleanup
disk1=$TEST_BASE_DIR/$FILEDISK0
disk2=$TEST_BASE_DIR/$FILEDISK1
-log_must mkfile $SIZE $disk1
-log_must mkfile $SIZE $disk2
+log_must truncate -s $SIZE $disk1
+log_must truncate -s $SIZE $disk2
typeset ashifts=("9" "10" "11" "12" "13" "14" "15" "16")
for ashift in ${ashifts[@]}
@@ -84,13 +84,7 @@ do
# clean things for the next run
log_must zpool destroy $TESTPOOL1
log_must zpool labelclear $disk1
- # depending on if we expect to have failed the 'zpool attach'
- if [[ $cmdval -le $ashift ]]
- then
- log_must zpool labelclear $disk2
- else
- log_mustnot zpool labelclear $disk2
- fi
+ log_must zpool labelclear $disk2
done
done
diff --git a/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_labelclear/labelclear.cfg b/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_labelclear/labelclear.cfg
index 6ae5395635..4d7edbb005 100644
--- a/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_labelclear/labelclear.cfg
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_labelclear/labelclear.cfg
@@ -17,9 +17,6 @@
. $STF_SUITE/include/libtest.shlib
-typeset LABELCLEAR="zpool labelclear"
-typeset LABELREAD="zdb -lq"
-
typeset disks=(${DISKS[*]})
typeset disk1=${disks[0]}
typeset disk2=${disks[1]}
diff --git a/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_labelclear/zpool_labelclear_active.ksh b/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_labelclear/zpool_labelclear_active.ksh
index a29c09095f..977a1806eb 100644
--- a/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_labelclear/zpool_labelclear_active.ksh
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_labelclear/zpool_labelclear_active.ksh
@@ -43,26 +43,26 @@ log_assert "zpool labelclear will fail on all vdevs of imported pool"
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
+log_mustnot zpool labelclear $disk1
+log_must zdb -lq $disk1
+log_mustnot zpool labelclear -f $disk1
+log_must zdb -lq $disk1
+log_mustnot zpool labelclear $disk2
+log_must zdb -lq $disk2
+log_mustnot zpool labelclear -f $disk2
+log_must zdb -lq $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_mustnot zpool labelclear $disk3
+ log_must zdb -lq $disk3
+ log_mustnot zpool labelclear -f $disk3
+ log_must zdb -lq $disk3
log_must zpool remove $TESTPOOL $disk3
- log_must $LABELCLEAR $disk3
- log_mustnot $LABELREAD $disk3
+ log_must zpool labelclear $disk3
+ log_mustnot zdb -lq $disk3
done
log_pass "zpool labelclear will fail on all vdevs of imported pool"
diff --git a/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_labelclear/zpool_labelclear_exported.ksh b/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_labelclear/zpool_labelclear_exported.ksh
index 82df8216eb..0a9016c471 100644
--- a/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_labelclear/zpool_labelclear_exported.ksh
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_labelclear/zpool_labelclear_exported.ksh
@@ -52,21 +52,21 @@ for vdevtype in "" "cache" "spare"; do
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
+ log_mustnot zpool labelclear $disk1
+ log_must zdb -lq $disk1
+ log_mustnot zpool labelclear $disk2
+ log_must zdb -lq $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
+ log_must zpool labelclear -f $disk1
+ log_mustnot zdb -lq $disk1
+ log_must zpool labelclear -f $disk2
+ log_mustnot zdb -lq $disk2
# Check that labelclear on auxilary vdevs will succeed
if [[ -n $vdevtype ]]; then
- log_must $LABELCLEAR $disk3
- log_mustnot $LABELREAD $disk3
+ log_must zpool labelclear $disk3
+ log_mustnot zdb -lq $disk3
fi
done
diff --git a/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_labelclear/zpool_labelclear_removed.ksh b/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_labelclear/zpool_labelclear_removed.ksh
new file mode 100755
index 0000000000..f93de6e224
--- /dev/null
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_labelclear/zpool_labelclear_removed.ksh
@@ -0,0 +1,62 @@
+#!/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` can clear labels on removed devices.
+#
+# STRATEGY:
+# 1. Create a pool with primary, log, spare and cache devices.
+# 2. Remove a top-level vdev, log, spare, and cache device.
+# 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"
diff --git a/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_labelclear/zpool_labelclear_valid.ksh b/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_labelclear/zpool_labelclear_valid.ksh
new file mode 100755
index 0000000000..9c0c4d07c8
--- /dev/null
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_labelclear/zpool_labelclear_valid.ksh
@@ -0,0 +1,92 @@
+#!/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.
+# Copyright 2020 Joyent, Inc.
+#
+
+. $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 device 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 dd if=$dev bs=1048576 count=4 | cmp -- - $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"
diff --git a/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_replace/replace-o_ashift.ksh b/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_replace/replace-o_ashift.ksh
index 77f85c6bea..ae415487c7 100644
--- a/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_replace/replace-o_ashift.ksh
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_replace/replace-o_ashift.ksh
@@ -51,8 +51,8 @@ log_onexit cleanup
disk1=$TEST_BASE_DIR/$FILEDISK0
disk2=$TEST_BASE_DIR/$FILEDISK1
-log_must mkfile $SIZE $disk1
-log_must mkfile $SIZE $disk2
+log_must truncate -s $SIZE $disk1
+log_must truncate -s $SIZE $disk2
typeset ashifts=("9" "10" "11" "12" "13" "14" "15" "16")
for ashift in ${ashifts[@]}
@@ -84,15 +84,8 @@ do
fi
# clean things for the next run
log_must zpool destroy $TESTPOOL1
- # depending on if we expect to have failed the 'zpool replace'
- if [[ $cmdval -le $ashift ]]
- then
- log_mustnot zpool labelclear $disk1
- log_must zpool labelclear $disk2
- else
- log_must zpool labelclear $disk1
- log_mustnot zpool labelclear $disk2
- fi
+ log_must zpool labelclear $disk1
+ log_must zpool labelclear $disk2
done
done
diff --git a/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_replace/replace_prop_ashift.ksh b/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_replace/replace_prop_ashift.ksh
index 714f1180f5..e740de133a 100644
--- a/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_replace/replace_prop_ashift.ksh
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_replace/replace_prop_ashift.ksh
@@ -52,8 +52,8 @@ log_onexit cleanup
disk1=$TEST_BASE_DIR/$FILEDISK0
disk2=$TEST_BASE_DIR/$FILEDISK1
-log_must mkfile $SIZE $disk1
-log_must mkfile $SIZE $disk2
+log_must truncate -s $SIZE $disk1
+log_must truncate -s $SIZE $disk2
typeset ashifts=("9" "10" "11" "12" "13" "14" "15" "16")
for ashift in ${ashifts[@]}
@@ -89,7 +89,7 @@ do
fi
# clean things for the next run
log_must zpool destroy $TESTPOOL1
- log_mustnot zpool labelclear $disk1
+ log_must zpool labelclear $disk1
log_must zpool labelclear $disk2
done
done