OpenZFS 6736 - ZFS per-vdev ZAPs

6736 ZFS per-vdev ZAPs
Reviewed by: Matthew Ahrens <mahrens@delphix.com>
Reviewed by: John Kennedy <john.kennedy@delphix.com>
Reviewed by: George Wilson <george.wilson@delphix.com>
Reviewed by: Don Brady <don.brady@intel.com>
Reviewed by: Dan McDonald <danmcd@omniti.com>

References:
  https://www.illumos.org/issues/6736
  https://github.com/openzfs/openzfs/commit/215198a

Ported-by: Don Brady <don.brady@intel.com>
Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Closes #4515
This commit is contained in:
Joe Stein
2016-04-11 16:16:57 -04:00
committed by Brian Behlendorf
parent 4cd77889b6
commit e0ab3ab553
24 changed files with 980 additions and 75 deletions
+7
View File
@@ -614,6 +614,13 @@ tests = [
'userquota_008_pos', 'userquota_009_pos',
'userquota_011_pos', 'userquota_012_neg']
# DISABLED:
# vdev_zaps_007_pos -- fails due to a pre-existing issue with zpool split
#
[tests/functional/vdev_zaps]
tests = ['vdev_zaps_001_pos', 'vdev_zaps_002_pos', 'vdev_zaps_003_pos',
'vdev_zaps_004_pos', 'vdev_zaps_005_pos', 'vdev_zaps_006_pos']
# DISABLED:
# write_dirs_002_pos - needs investigation
[tests/functional/write_dirs]
@@ -50,6 +50,7 @@ SUBDIRS = \
threadsappend \
truncate \
userquota \
vdev_zaps \
write_dirs \
xattr \
zvol
@@ -0,0 +1,12 @@
pkgdatadir = $(datadir)/@PACKAGE@/zfs-tests/tests/functional/vdev_zaps
dist_pkgdata_SCRIPTS = \
setup.ksh \
cleanup.ksh \
vdev_zaps_001_pos.ksh \
vdev_zaps_002_pos.ksh \
vdev_zaps_003_pos.ksh \
vdev_zaps_004_pos.ksh \
vdev_zaps_005_pos.ksh \
vdev_zaps_006_pos.ksh \
vdev_zaps_007_pos.ksh \
vdev_zaps.kshlib
+20
View File
@@ -0,0 +1,20 @@
#!/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 (c) 2015 by Delphix. All rights reserved.
#
. $STF_SUITE/include/libtest.shlib
default_cleanup
+21
View File
@@ -0,0 +1,21 @@
#!/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 (c) 2015 by Delphix. All rights reserved.
#
. $STF_SUITE/include/libtest.shlib
rm -rf $TESTDIR || log_fail Could not remove $TESTDIR
mkdir -p $TESTDIR || log_fail Could not create $TESTDIR
@@ -0,0 +1,114 @@
#
# CDDL HEADER START
#
# 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.
#
# CDDL HEADER END
#
#
# Copyright (c) 2015 by Delphix. All rights reserved.
#
function get_conf_section # regex conf
{
typeset dsk_line next_vd_line conf section
typeset regex="$1"
typeset conf="$2"
dsk_line=$(grep -n "$regex" "$conf" | awk -F: '{print $1}')
if [[ -z "$dsk_line" ]]; then
return
fi
next_vd_line=$(tail -n +$dsk_line "$conf" | \
grep -n "children\[" | awk -F: '{print $1}' | head -n 1)
if [[ -n "$next_vd_line" ]]; then
section=$(cat "$conf" | sed "1,${dsk_line}d" | head -n \
$(($next_vd_line - 2)))
else
section=$(tail -n +$dsk_line "$conf")
fi
echo "$section"
}
function get_leaf_vd_zap # dsk conf
{
typeset section=$(get_conf_section "$1" "$2")
echo "$section" | egrep \
"com.delphix:vdev_zap_leaf: [0-9]+" | awk '{print $2}'
}
function get_top_vd_zap # dsk conf
{
typeset section=$(get_conf_section "$1" "$2")
echo "$section" | egrep \
"com.delphix:vdev_zap_top: [0-9]+" | awk '{print $2}'
}
function assert_has_sentinel # conf
{
res=$(grep "com.delphix:has_per_vdev_zaps" "$1")
[[ -z "$res" ]] && log_fail "Pool missing ZAP feature sentinel value"
}
function assert_zap_common # pool vd lvl zapobj
{
typeset pool=$1
typeset vd="$2"
typeset lvl=$3
typeset zapobj=$4
if [[ -z "$zapobj" ]]; then
log_fail "$vd on $pool has no $lvl ZAP in config"
elif [[ -z "$(zdb -d $pool $zapobj | grep 'zap')" ]]; then
log_fail "$vd on $pool has no $lvl ZAP in MOS"
fi
}
function assert_top_zap # pool vd conf
{
typeset pool=$1
typeset vd="$2"
typeset conf=$3
top_zap=$(get_top_vd_zap "$vd" $conf)
assert_zap_common $pool "$vd" "top" $top_zap
}
function assert_leaf_zap # pool vd conf
{
typeset pool=$1
typeset vd="$2"
typeset conf=$3
leaf_zap=$(get_leaf_vd_zap "$vd" $conf)
assert_zap_common $pool "$vd" "leaf" $leaf_zap
}
#
# Code common to setup/teardown for each test.
#
function cleanup
{
if datasetexists $TESTPOOL ; then
log_must zpool destroy -f $TESTPOOL
fi
if [[ -e $conf ]]; then
log_must $RM -f "$conf"
fi
if [[ -e $POOL2 ]]; then
log_must zpool destroy -f $POOL2
fi
}
log_onexit cleanup
@@ -0,0 +1,42 @@
#!/bin/ksh
#
# 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 (c) 2015 by Delphix. All rights reserved.
#
#
# Description:
# Verify that per-vdev ZAPs are created with one vdev.
#
# Strategy:
# 1. Create a pool with one disk.
# 2. Verify that the disk has a top and leaf ZAP in its config and the MOS.
#
. $STF_SUITE/include/libtest.shlib
. $STF_SUITE/tests/functional/vdev_zaps/vdev_zaps.kshlib
log_assert "Per-vdev ZAPs are created on pool creation with one disk."
DISK=${DISKS%% *}
log_must zpool create -f $TESTPOOL $DISK
conf="$TESTDIR/vz001"
log_must zdb -PC $TESTPOOL > $conf
assert_top_zap $TESTPOOL $DISK "$conf"
assert_leaf_zap $TESTPOOL $DISK "$conf"
assert_has_sentinel "$conf"
log_pass "Per-vdev ZAPs are created in a one-disk pool."
@@ -0,0 +1,44 @@
#!/bin/ksh
#
# 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 (c) 2015 by Delphix. All rights reserved.
#
#
# Description:
# Verify that per-vdev ZAPs are created with multiple vdevs.
#
# Strategy:
# 1. Create a pool with multiple disks.
# 2. Verify that each has both a top and leaf zap.
# 3. Verify that each of those ZAPs exists in the MOS.
#
. $STF_SUITE/include/libtest.shlib
. $STF_SUITE/tests/functional/vdev_zaps/vdev_zaps.kshlib
log_assert "Per-vdev ZAPs are created on pool creation with many disks."
log_must zpool create -f $TESTPOOL $DISKS
conf="$TESTDIR/vz002"
log_must zdb -PC $TESTPOOL > $conf
assert_has_sentinel "$conf"
for DISK in $DISKS; do
assert_top_zap $TESTPOOL $DISK "$conf"
assert_leaf_zap $TESTPOOL $DISK "$conf"
done
log_pass
@@ -0,0 +1,47 @@
#!/bin/ksh
#
# 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 (c) 2015 by Delphix. All rights reserved.
#
#
# Description:
# Verify that per-vdev ZAPs are created with multi-level vdev tree.
#
# Strategy:
# 1. Create a pool with a multi-disk mirror.
# 2. Verify that mirror has top ZAP but no leaf ZAP.
# 3. Verify that each disk has a leaf ZAP but no top ZAP.
#
. $STF_SUITE/include/libtest.shlib
. $STF_SUITE/tests/functional/vdev_zaps/vdev_zaps.kshlib
log_assert "Per-vdev ZAPs are created on pool creation with multi-level vdev "\
"trees."
log_must zpool create -f $TESTPOOL mirror $DISKS
conf="$TESTDIR/vz003"
log_must zdb -PC $TESTPOOL > $conf
assert_has_sentinel "$conf"
assert_top_zap $TESTPOOL "type: 'mirror'" "$conf"
for DISK in $DISKS; do
assert_leaf_zap $TESTPOOL $DISK "$conf"
top_zap=$(get_top_vd_zap $DISK "$conf")
[[ -n "$top_zap" ]] && log_fail "Leaf vdev $DISK has top-level ZAP."
done
log_pass
@@ -0,0 +1,94 @@
#!/bin/ksh
#
# 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 (c) 2015 by Delphix. All rights reserved.
#
#
# Description:
# Verify that per-vdev ZAPs are properly transferred on attach/detach.
#
# Strategy:
# 1. Create a pool with one disk. Verify that it has a top and leaf ZAP.
# 2. Attach a disk.
# 3. Verify that top-level and leaf-level ZAPs were transferred properly.
# 4. Verify that the newly-attached disk has a leaf ZAP.
# 5. Detach the original disk.
# 6. Verify that top-level and leaf-level ZAPs were transferred properly.
#
. $STF_SUITE/include/libtest.shlib
. $STF_SUITE/tests/functional/vdev_zaps/vdev_zaps.kshlib
log_assert "Per-vdev ZAPs are transferred properly on attach/detach"
DISK=${DISKS%% *}
log_must zpool create -f $TESTPOOL $DISK
# Make the pool.
conf="$TESTDIR/vz004"
log_must zdb -PC $TESTPOOL > $conf
assert_has_sentinel "$conf"
orig_top=$(get_top_vd_zap $DISK $conf)
orig_leaf=$(get_leaf_vd_zap $DISK $conf)
assert_zap_common $TESTPOOL $DISK "top" $orig_top
#
# Attach a disk.
#
disk2=$(echo $DISKS | awk '{print $2}')
log_must zpool attach $TESTPOOL $DISK $disk2
log_must zdb -PC $TESTPOOL > $conf
# Ensure top-level ZAP was transferred successfully.
new_top=$(get_top_vd_zap "type: 'mirror'" $conf)
if [[ "$new_top" -ne "$orig_top" ]]; then
log_fail "Top-level ZAP wasn't transferred successfully on attach."
fi
# Ensure leaf ZAP of original disk was transferred successfully.
new_leaf=$(get_leaf_vd_zap $DISK $conf)
if [[ "$new_leaf" -ne "$orig_leaf" ]]; then
log_fail "$DISK used to have leaf-level ZAP $orig_leaf, now has "\
"$new_leaf"
fi
# Ensure original disk no longer has top-level ZAP.
dsk1_top=$(get_top_vd_zap $DISK $conf)
[[ -n "$dsk1_top" ]] && log_fail "$DISK has top-level ZAP, but is only leaf."
# Ensure attached disk got a leaf-level ZAP but not a top-level ZAP.
dsk2_top=$(get_top_vd_zap $disk2 $conf)
dsk2_leaf=$(get_leaf_vd_zap $disk2 $conf)
[[ -n "$dsk2_top" ]] && log_fail "Attached disk $disk2 has top ZAP."
[[ -z "$dsk2_leaf" ]] && log_fail "Attached disk $disk2 has no leaf ZAP."
#
# Detach original disk.
#
log_must zpool detach $TESTPOOL $DISK
log_must zdb -PC $TESTPOOL > $conf
final_top=$(get_top_vd_zap $disk2 $conf)
final_leaf=$(get_leaf_vd_zap $disk2 $conf)
# Make sure top ZAP was successfully transferred.
[[ "$final_top" -ne "$orig_top" ]] && log_fail "Lost top-level ZAP when "\
"promoting $disk2 (expected $orig_top, found $final_top)"
# Make sure leaf ZAP was successfully transferred.
[[ "$final_leaf" -ne "$dsk2_leaf" ]] && log_fail "$disk2 lost its leaf ZAP "\
"on promotion (expected $dsk2_leaf, got $final_leaf)"
log_pass
@@ -0,0 +1,62 @@
#!/bin/ksh
#
# 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 (c) 2015 by Delphix. All rights reserved.
#
#
# Description:
# Verify that per-vdev ZAPs persist when the pool is exported and imported.
#
# Strategy:
# 1. Create a pool with a disk.
# 2. Export the pool and re-import it.
# 3. Verify that the ZAPs aren't different.
#
. $STF_SUITE/include/libtest.shlib
. $STF_SUITE/tests/functional/vdev_zaps/vdev_zaps.kshlib
log_assert "Per-vdev ZAPs persist across export/import."
DISK=${DISKS%% *}
log_must zpool create -f $TESTPOOL $DISK
# Make the pool.
conf="$TESTDIR/vz005"
log_must zdb -PC $TESTPOOL > $conf
assert_has_sentinel "$conf"
orig_top=$(get_top_vd_zap $DISK $conf)
orig_leaf=$(get_leaf_vd_zap $DISK $conf)
assert_zap_common $TESTPOOL $DISK "top" $orig_top
assert_zap_common $TESTPOOL $DISK "leaf" $orig_leaf
# Export the pool.
log_must zpool export $TESTPOOL
# Import the pool.
log_must zpool import $TESTPOOL
# Verify that ZAPs persisted.
log_must zdb -PC $TESTPOOL > $conf
new_top=$(get_top_vd_zap $DISK $conf)
new_leaf=$(get_leaf_vd_zap $DISK $conf)
[[ "$new_top" -ne "$orig_top" ]] && log_fail "Top ZAP ($new_top) after "\
"import does not match top ZAP before export ($orig_top)"
[[ "$new_leaf" -ne "$orig_leaf" ]] && log_fail "Leaf ZAP ($new_leaf) after "\
"import does not match leaf ZAP before export ($orig_leaf)"
log_pass
@@ -0,0 +1,46 @@
#!/bin/ksh
#
# 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 (c) 2015, 2016 by Delphix. All rights reserved.
#
#
# Description:
# Verify that top-level per-vdev ZAPs are created for added devices
#
# Strategy:
# 1. Create a pool with one disk.
# 2. Add a disk.
# 3. Verify its ZAPs were created.
#
. $STF_SUITE/include/libtest.shlib
. $STF_SUITE/tests/functional/vdev_zaps/vdev_zaps.kshlib
DISK_ARR=($DISKS)
DISK=${DISK_ARR[0]}
log_must zpool create -f $TESTPOOL $DISK
log_assert "Per-vdev ZAPs are created for added vdevs."
log_must zpool add -f $TESTPOOL ${DISK_ARR[1]}
conf="$TESTDIR/vz006"
log_must zdb -PC $TESTPOOL > $conf
assert_has_sentinel "$conf"
orig_top=$(get_top_vd_zap ${DISK_ARR[1]} $conf)
assert_zap_common $TESTPOOL ${DISK_ARR[1]} "top" $orig_top
assert_leaf_zap $TESTPOOL ${DISK_ARR[1]} "$conf"
log_pass
@@ -0,0 +1,74 @@
#!/bin/ksh
#
# 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 (c) 2015 by Delphix. All rights reserved.
#
#
# Description:
# Verify that ZAPs are handled properly during mirror pool splitting.
#
# Strategy:
# 1. Create a pool with a two-way mirror.
# 2. Split the pool.
# 3. Verify that the ZAPs in the old pool persisted.
# 4. Import the new pool.
# 5. Verify that the ZAPs in the new pool persisted.
#
. $STF_SUITE/include/libtest.shlib
. $STF_SUITE/tests/functional/vdev_zaps/vdev_zaps.kshlib
DISK_ARR=($DISKS)
POOL2=${TESTPOOL}2
log_must zpool create -f $TESTPOOL mirror ${DISK_ARR[0]} ${DISK_ARR[1]}
log_assert "Per-vdev ZAPs persist correctly on the original pool after split."
conf="$TESTDIR/vz007"
log_must zdb -PC $TESTPOOL > $conf
assert_has_sentinel "$conf"
orig_top=$(get_top_vd_zap "type: 'mirror'" $conf)
orig_leaf0=$(get_leaf_vd_zap ${DISK_ARR[0]} $conf)
orig_leaf1=$(get_leaf_vd_zap ${DISK_ARR[1]} $conf)
assert_zap_common $TESTPOOL "type: 'mirror'" "top" $orig_top
assert_zap_common $TESTPOOL ${DISK_ARR[0]} "leaf" $orig_leaf0
assert_zap_common $TESTPOOL ${DISK_ARR[1]} "leaf" $orig_leaf1
log_must zpool split $TESTPOOL $POOL2 ${DISK_ARR[1]}
# Make sure old pool's ZAPs are consistent.
log_must zdb -PC $TESTPOOL > $conf
new_leaf0=$(get_leaf_vd_zap ${DISK_ARR[0]} $conf)
new_top_s0=$(get_top_vd_zap ${DISK_ARR[0]} $conf)
[[ "$new_leaf0" -ne "$orig_leaf0" ]] && log_fail "Leaf ZAP in original pool "\
"didn't persist (expected $orig_leaf0, got $new_leaf0)"
[[ "$new_top_s0" -ne "$orig_top" ]] && log_fail "Top ZAP in original pool "\
"didn't persist (expected $orig_top, got $new_top_s0)"
log_assert "Per-vdev ZAPs persist on the new pool after import."
# Import the split pool.
log_must zpool import $POOL2
log_must zdb -PC $TESTPOOL > $conf
new_leaf1=$(get_leaf_vd_zap ${DISK_ARR[1]} $conf)
new_top_s1=$(get_top_vd_zap ${DISK_ARR[1]} $conf)
[[ "$new_leaf1" -ne "$orig_leaf1" ]] && log_fail "Leaf ZAP in new pool "\
"didn't persist (expected $orig_leaf1, got $new_leaf1)"
[[ "$new_top_s1" -ne "$orig_top" ]] && log_fail "Top ZAP in new pool "\
"didn't persist (expected $orig_top, got $new_top_s1)"
log_pass